/[svn]/qsampler/trunk/src/qsamplerChannel.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 344 by capela, Tue Jan 18 13:53:04 2005 UTC revision 1465 by capela, Thu Nov 1 17:49:27 2007 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerUtilities.h"
24    #include "qsamplerAbout.h"
25  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
29    
 #include "config.h"  
   
30  #include <qfileinfo.h>  #include <qfileinfo.h>
31    #include <qcombobox.h>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
35  #endif  #endif
36    
37  #define QSAMPLER_INSTRUMENT_MAX 8  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    using namespace QSampler;
40    
41  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
42  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
43  //  //
44    
45  // Constructor.  // Constructor.
46  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( int iChannelID )
47  {  {
48      m_pMainForm  = pMainForm;          m_iChannelID = iChannelID;
     m_iChannelID = iChannelID;  
49    
50  //  m_sEngineName       = QObject::tr("(No engine)");  //  m_sEngineName       = noEngineName();
51  //  m_sInstrumentName   = QObject::tr("(No instrument)");  //  m_sInstrumentName   = noInstrumentName();
52  //  m_sInstrumentFile   = m_sInstrumentName;  //  m_sInstrumentFile   = m_sInstrumentName;
53      m_iInstrumentNr     = -1;          m_iInstrumentNr     = -1;
54      m_iInstrumentStatus = -1;          m_iInstrumentStatus = -1;
55      m_sMidiDriver       = "Alsa";   // DEPRECATED.          m_sMidiDriver       = "ALSA";
56      m_iMidiDevice       = -1;          m_iMidiDevice       = -1;
57      m_iMidiPort         = -1;          m_iMidiPort         = -1;
58      m_iMidiChannel      = -1;          m_iMidiChannel      = -1;
59      m_sAudioDriver      = "Alsa";   // DEPRECATED.          m_iMidiMap          = -1;
60      m_iAudioDevice      = -1;          m_sAudioDriver      = "ALSA";
61      m_fVolume           = 0.0;          m_iAudioDevice      = -1;
62            m_fVolume           = 0.0;
63            m_bMute             = false;
64            m_bSolo             = false;
65  }  }
66    
67  // Default destructor.  // Default destructor.
# Line 66  qsamplerChannel::~qsamplerChannel (void) Line 70  qsamplerChannel::~qsamplerChannel (void)
70  }  }
71    
72    
 // The global options settings delegated property.  
 qsamplerOptions *qsamplerChannel::options (void)  
 {  
     if (m_pMainForm == NULL)  
         return NULL;  
   
     return m_pMainForm->options();  
 }  
   
   
 // The client descriptor delegated property.  
 lscp_client_t *qsamplerChannel::client (void)  
 {  
     if (m_pMainForm == NULL)  
         return NULL;  
   
     return m_pMainForm->client();  
 }  
   
   
73  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
74  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
75  {  {
76      if (client() == NULL)          MainForm* pMainForm = MainForm::getInstance();
77          return false;          if (pMainForm == NULL)
78                    return false;
79      // Are we a new channel?          if (pMainForm->client() == NULL)
80      if (m_iChannelID < 0) {                  return false;
81          m_iChannelID = ::lscp_add_channel(client());  
82          if (m_iChannelID < 0) {          // Are we a new channel?
83              appendMessagesClient("lscp_add_channel");          if (m_iChannelID < 0) {
84              appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));                  m_iChannelID = ::lscp_add_channel(pMainForm->client());
85          }   // Otherwise it's created...                  if (m_iChannelID < 0) {
86          else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));                          appendMessagesClient("lscp_add_channel");
87      }                          appendMessagesError(
88                                    QObject::tr("Could not add channel.\n\nSorry."));
89                    }   // Otherwise it's created...
90                    else appendMessages(QObject::tr("added."));
91            }
92    
93      // Return whether we're a valid channel...          // Return whether we're a valid channel...
94      return (m_iChannelID >= 0);          return (m_iChannelID >= 0);
95  }  }
96    
97    
98  // Remove sampler channel.  // Remove sampler channel.
99  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
100  {  {
101      if (client() == NULL)          MainForm *pMainForm = MainForm::getInstance();
102          return false;          if (pMainForm == NULL)
103                    return false;
104            if (pMainForm->client() == NULL)
105                    return false;
106    
107            // Are we an existing channel?
108            if (m_iChannelID >= 0) {
109                    if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
110                            appendMessagesClient("lscp_remove_channel");
111                            appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
112                    } else {
113                            // Otherwise it's removed.
114                            appendMessages(QObject::tr("removed."));
115                            m_iChannelID = -1;
116                    }
117            }
118    
119      // Are we an existing channel?          // Return whether we've removed the channel...
120      if (m_iChannelID >= 0) {          return (m_iChannelID < 0);
         if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {  
             appendMessagesClient("lscp_remove_channel");  
             appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));  
         } else {  
             // Otherwise it's removed.  
             appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));  
             m_iChannelID = -1;  
         }  
     }  
       
     // Return whether we've removed the channel...  
     return (m_iChannelID < 0);  
121  }  }
122    
123    
124  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
125  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void) const
126  {  {
127      return m_iChannelID;          return m_iChannelID;
128  }  }
129    
130  void qsamplerChannel::setChannelID ( int iChannelID )  void qsamplerChannel::setChannelID ( int iChannelID )
131  {  {
132      m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
133  }  }
134    
135    
136  // Readable channel name.  // Readable channel name.
137  QString qsamplerChannel::channelName (void)  QString qsamplerChannel::channelName (void) const
138  {  {
139      return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));          return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
140  }  }
141    
142    
143  // Engine name accessors.  // Engine name accessors.
144  QString& qsamplerChannel::engineName (void)  const QString& qsamplerChannel::engineName (void) const
145  {  {
146      return m_sEngineName;          return m_sEngineName;
147  }  }
148    
149  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
150  {  {
151      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
152          return false;          if (pMainForm == NULL)
153                    return false;
154            if (pMainForm->client() == NULL || m_iChannelID < 0)
155                    return false;
156            if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
157                    return true;
158    
159            if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
160                    appendMessagesClient("lscp_load_engine");
161                    return false;
162            }
163    
164      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
         appendMessagesClient("lscp_load_engine");  
         return false;  
     }  
165    
166      m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
167      return true;          return true;
168  }  }
169    
170    
171  // Instrument name accessor.  // Instrument filename accessor.
172  QString& qsamplerChannel::instrumentName (void)  const QString& qsamplerChannel::instrumentFile (void) const
173  {  {
174      return m_sInstrumentName;          return m_sInstrumentFile;
175  }  }
176    
177  // Instrument filename accessor.  // Instrument index accessor.
178  QString& qsamplerChannel::instrumentFile (void)  int qsamplerChannel::instrumentNr (void) const
179  {  {
180      return m_sInstrumentFile;          return m_iInstrumentNr;
181  }  }
182    
183  // Instrument index accessor.  // Instrument name accessor.
184  int qsamplerChannel::instrumentNr (void)  const QString& qsamplerChannel::instrumentName (void) const
185  {  {
186      return m_iInstrumentNr;          return m_sInstrumentName;
187  }  }
188    
189  // Instrument status accessor.  // Instrument status accessor.
190  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void) const
191  {  {
192      return m_iInstrumentStatus;          return m_iInstrumentStatus;
193  }  }
194    
195  // Instrument file loader.  // Instrument file loader.
196  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
197  {  {
198      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
199          return false;          if (pMainForm == NULL)
200                    return false;
201            if (pMainForm->client() == NULL || m_iChannelID < 0)
202                    return false;
203            if (!isInstrumentFile(sInstrumentFile))
204                    return false;
205            if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
206                    return true;
207    
208            if (
209                    ::lscp_load_instrument_non_modal(
210                            pMainForm->client(),
211                            qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),
212                            iInstrumentNr, m_iChannelID
213                    ) != LSCP_OK
214            ) {
215                    appendMessagesClient("lscp_load_instrument");
216                    return false;
217            }
218    
219            appendMessages(QObject::tr("Instrument: \"%1\" (%2).")
220                    .arg(sInstrumentFile).arg(iInstrumentNr));
221    
222            return setInstrument(sInstrumentFile, iInstrumentNr);
223    }
224    
     if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {  
         appendMessagesClient("lscp_load_instrument");  
         return false;  
     }  
225    
226      m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);  // Special instrument file/name/number settler.
227      m_sInstrumentFile = sInstrumentFile;  bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
228      m_iInstrumentNr = iInstrumentNr;  {
229      m_iInstrumentStatus = 0;          m_sInstrumentFile = sInstrumentFile;
230            m_iInstrumentNr = iInstrumentNr;
231    #ifdef CONFIG_INSTRUMENT_NAME
232            m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...
233    #else
234            m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
235    #endif
236            m_iInstrumentStatus = 0;
237    
238      return true;          return true;
239  }  }
240    
241    
242  // MIDI driver type accessors (DEPRECATED).  // MIDI driver type accessors (DEPRECATED).
243  QString& qsamplerChannel::midiDriver (void)  const QString& qsamplerChannel::midiDriver (void) const
244  {  {
245      return m_sMidiDriver;          return m_sMidiDriver;
246  }  }
247    
248  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
249  {  {
250      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
251          return false;          if (pMainForm == NULL)
252                    return false;
253            if (pMainForm->client() == NULL || m_iChannelID < 0)
254                    return false;
255            if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
256                    return true;
257    
258            if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
259                    appendMessagesClient("lscp_set_channel_midi_type");
260                    return false;
261            }
262    
263      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          appendMessages(QObject::tr("MIDI driver: %1.").arg(sMidiDriver));
         appendMessagesClient("lscp_set_channel_midi_type");  
         return false;  
     }  
264    
265      m_sMidiDriver = sMidiDriver;          m_sMidiDriver = sMidiDriver;
266      return true;          return true;
267  }  }
268    
269    
270  // MIDI device accessors.  // MIDI device accessors.
271  int qsamplerChannel::midiDevice (void)  int qsamplerChannel::midiDevice (void) const
272  {  {
273      return m_iMidiDevice;          return m_iMidiDevice;
274  }  }
275    
276  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
277  {  {
278      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
279          return false;          if (pMainForm == NULL)
280                    return false;
281            if (pMainForm->client() == NULL || m_iChannelID < 0)
282                    return false;
283            if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
284                    return true;
285    
286            if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
287                    appendMessagesClient("lscp_set_channel_midi_device");
288                    return false;
289            }
290    
291      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {          appendMessages(QObject::tr("MIDI device: %1.").arg(iMidiDevice));
         appendMessagesClient("lscp_set_channel_midi_device");  
         return false;  
     }  
292    
293      m_iMidiDevice = iMidiDevice;          m_iMidiDevice = iMidiDevice;
294      return true;          return true;
295  }  }
296    
297    
298  // MIDI port number accessor.  // MIDI port number accessor.
299  int qsamplerChannel::midiPort (void)  int qsamplerChannel::midiPort (void) const
300  {  {
301      return m_iMidiPort;          return m_iMidiPort;
302  }  }
303    
304  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
305  {  {
306      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
307          return false;          if (pMainForm == NULL)
308                    return false;
309            if (pMainForm->client() == NULL || m_iChannelID < 0)
310                    return false;
311            if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
312                    return true;
313    
314            if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) {
315                    appendMessagesClient("lscp_set_channel_midi_port");
316                    return false;
317            }
318    
319      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {          appendMessages(QObject::tr("MIDI port: %1.").arg(iMidiPort));
         appendMessagesClient("lscp_set_channel_midi_port");  
         return false;  
     }  
320    
321      m_iMidiPort = iMidiPort;          m_iMidiPort = iMidiPort;
322      return true;          return true;
323  }  }
324    
325    
326  // MIDI channel accessor.  // MIDI channel accessor.
327  int qsamplerChannel::midiChannel (void)  int qsamplerChannel::midiChannel (void) const
328  {  {
329      return m_iMidiChannel;          return m_iMidiChannel;
330  }  }
331    
332  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
333  {  {
334      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
335          return false;          if (pMainForm == NULL)
336                    return false;
337            if (pMainForm->client() == NULL || m_iChannelID < 0)
338                    return false;
339            if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
340                    return true;
341    
342            if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
343                    appendMessagesClient("lscp_set_channel_midi_channel");
344                    return false;
345            }
346    
347      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {          appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel));
         appendMessagesClient("lscp_set_channel_midi_channel");  
         return false;  
     }  
348    
349      m_iMidiChannel = iMidiChannel;          m_iMidiChannel = iMidiChannel;
350      return true;          return true;
351    }
352    
353    
354    // MIDI instrument map accessor.
355    int qsamplerChannel::midiMap (void) const
356    {
357            return m_iMidiMap;
358    }
359    
360    bool qsamplerChannel::setMidiMap ( int iMidiMap )
361    {
362            MainForm *pMainForm = MainForm::getInstance();
363            if (pMainForm == NULL)
364                    return false;
365            if (pMainForm->client() == NULL || m_iChannelID < 0)
366                    return false;
367            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
368                    return true;
369    #ifdef CONFIG_MIDI_INSTRUMENT
370            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
371                    appendMessagesClient("lscp_set_channel_midi_map");
372                    return false;
373            }
374    #endif
375            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
376    
377            m_iMidiMap = iMidiMap;
378            return true;
379  }  }
380    
381    
382  // Audio device accessor.  // Audio device accessor.
383  int qsamplerChannel::audioDevice (void)  int qsamplerChannel::audioDevice (void) const
384  {  {
385      return m_iAudioDevice;          return m_iAudioDevice;
386  }  }
387    
388  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
389  {  {
390      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
391          return false;          if (pMainForm == NULL)
392                    return false;
393            if (pMainForm->client() == NULL || m_iChannelID < 0)
394                    return false;
395            if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
396                    return true;
397    
398            if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
399                    appendMessagesClient("lscp_set_channel_audio_device");
400                    return false;
401            }
402    
403      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {          appendMessages(QObject::tr("Audio device: %1.").arg(iAudioDevice));
         appendMessagesClient("lscp_set_channel_audio_device");  
         return false;  
     }  
404    
405      m_iAudioDevice = iAudioDevice;          m_iAudioDevice = iAudioDevice;
406      return true;          return true;
407  }  }
408    
409    
410  // Audio driver type accessors (DEPRECATED).  // Audio driver type accessors (DEPRECATED).
411  QString& qsamplerChannel::audioDriver (void)  const QString& qsamplerChannel::audioDriver (void) const
412  {  {
413      return m_sAudioDriver;          return m_sAudioDriver;
414  }  }
415    
416  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
417  {  {
418      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
419          return false;          if (pMainForm == NULL)
420                    return false;
421            if (pMainForm->client() == NULL || m_iChannelID < 0)
422                    return false;
423            if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
424                    return true;
425    
426            if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
427                    appendMessagesClient("lscp_set_channel_audio_type");
428                    return false;
429            }
430    
431      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          appendMessages(QObject::tr("Audio driver: %1.").arg(sAudioDriver));
         appendMessagesClient("lscp_set_channel_audio_type");  
         return false;  
     }  
432    
433      m_sAudioDriver = sAudioDriver;          m_sAudioDriver = sAudioDriver;
434      return true;          return true;
435  }  }
436    
437    
438  // Channel volume accessors.  // Channel volume accessors.
439  float qsamplerChannel::volume (void)  float qsamplerChannel::volume (void) const
440  {  {
441      return m_fVolume;          return m_fVolume;
442  }  }
443    
444  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
445  {  {
446      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
447          return false;          if (pMainForm == NULL)
448                    return false;
449            if (pMainForm->client() == NULL || m_iChannelID < 0)
450                    return false;
451            if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
452                    return true;
453    
454            if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
455                    appendMessagesClient("lscp_set_channel_volume");
456                    return false;
457            }
458    
459      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          appendMessages(QObject::tr("Volume: %1.").arg(fVolume));
460          appendMessagesClient("lscp_set_channel_volume");  
461          return false;          m_fVolume = fVolume;
462      }          return true;
463    }
464    
465    
466    // Sampler channel mute state.
467    bool qsamplerChannel::channelMute (void) const
468    {
469            return m_bMute;
470    }
471    
472    bool qsamplerChannel::setChannelMute ( bool bMute )
473    {
474            MainForm *pMainForm = MainForm::getInstance();
475            if (pMainForm == NULL)
476                    return false;
477            if (pMainForm->client() == NULL || m_iChannelID < 0)
478                    return false;
479            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
480                    return true;
481    
482    #ifdef CONFIG_MUTE_SOLO
483            if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
484                    appendMessagesClient("lscp_set_channel_mute");
485                    return false;
486            }
487            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
488            m_bMute = bMute;
489            return true;
490    #else
491            return false;
492    #endif
493    }
494    
495    
496    // Sampler channel solo state.
497    bool qsamplerChannel::channelSolo (void) const
498    {
499            return m_bSolo;
500    }
501    
502    bool qsamplerChannel::setChannelSolo ( bool bSolo )
503    {
504            MainForm *pMainForm = MainForm::getInstance();
505            if (pMainForm == NULL)
506                    return false;
507            if (pMainForm->client() == NULL || m_iChannelID < 0)
508                    return false;
509            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
510                    return true;
511    
512    #ifdef CONFIG_MUTE_SOLO
513            if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
514                    appendMessagesClient("lscp_set_channel_solo");
515                    return false;
516            }
517            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
518            m_bSolo = bSolo;
519            return true;
520    #else
521            return false;
522    #endif
523    }
524    
525    
526    // Audio routing accessors.
527    int qsamplerChannel::audioChannel ( int iAudioOut ) const
528    {
529            return m_audioRouting[iAudioOut];
530    }
531    
532    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
533    {
534            MainForm *pMainForm = MainForm::getInstance();
535            if (pMainForm == NULL)
536                    return false;
537            if (pMainForm->client() == NULL || m_iChannelID < 0)
538                    return false;
539            if (m_iInstrumentStatus == 100 &&
540                            m_audioRouting[iAudioOut] == iAudioIn)
541                    return true;
542    
543            if (::lscp_set_channel_audio_channel(pMainForm->client(),
544                            m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
545                    appendMessagesClient("lscp_set_channel_audio_channel");
546                    return false;
547            }
548    
549            appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
550                    .arg(iAudioOut).arg(iAudioIn));
551    
552            m_audioRouting[iAudioOut] = iAudioIn;
553            return true;
554    }
555    
556    // The audio routing map itself.
557    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
558    {
559            return m_audioRouting;
560    }
561    
562      m_fVolume = fVolume;  
563      return true;  // Istrument name remapper.
564    void qsamplerChannel::updateInstrumentName (void)
565    {
566    #ifndef CONFIG_INSTRUMENT_NAME
567            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
568                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
569    #endif
570  }  }
571    
572    
573  // Update whole channel info state.  // Update whole channel info state.
574  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
575  {  {
576      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
577          return false;          if (pMainForm == NULL)
578                    return false;
579            if (pMainForm->client() == NULL || m_iChannelID < 0)
580                    return false;
581    
582            // Read channel information.
583            lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
584            if (pChannelInfo == NULL) {
585                    appendMessagesClient("lscp_get_channel_info");
586                    appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
587                    return false;
588            }
589    
590      // Read channel information.  #ifdef CONFIG_INSTRUMENT_NAME
591      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);          // We got all actual instrument datum...
592      if (pChannelInfo == NULL) {          m_sInstrumentFile =
593          appendMessagesClient("lscp_get_channel_info");                  qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
594          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));          m_iInstrumentNr   = pChannelInfo->instrument_nr;
595          return false;          m_sInstrumentName =
596      }                  qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
597    #else
598            // First, check if intrument name has changed,
599            // taking care that instrument name lookup might be expensive,
600            // so we better make it only once and when really needed...
601            if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
602                    (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
603                    m_sInstrumentFile = pChannelInfo->instrument_file;
604                    m_iInstrumentNr   = pChannelInfo->instrument_nr;
605                    updateInstrumentName();
606            }
607    #endif
608            // Cache in other channel information.
609            m_sEngineName       = pChannelInfo->engine_name;
610            m_iInstrumentStatus = pChannelInfo->instrument_status;
611            m_iMidiDevice       = pChannelInfo->midi_device;
612            m_iMidiPort         = pChannelInfo->midi_port;
613            m_iMidiChannel      = pChannelInfo->midi_channel;
614    #ifdef CONFIG_MIDI_INSTRUMENT
615            m_iMidiMap          = pChannelInfo->midi_map;
616    #endif
617            m_iAudioDevice      = pChannelInfo->audio_device;
618            m_fVolume           = pChannelInfo->volume;
619    #ifdef CONFIG_MUTE_SOLO
620            m_bMute             = pChannelInfo->mute;
621            m_bSolo             = pChannelInfo->solo;
622    #endif
623            // Some sanity checks.
624            if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
625                    m_sEngineName = QString::null;
626            if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
627                    m_sInstrumentFile = QString::null;
628                    m_sInstrumentName = QString::null;
629            }
630    
631      // First, check if intrument name has changed,          // Time for device info grabbing...
632      // taking care that instrument name lookup might be expensive,          lscp_device_info_t *pDeviceInfo;
633      // so we better make it only once and when really needed...          const QString sNone = QObject::tr("(none)");
634      if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||          // Audio device driver type.
635          (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
636          m_sInstrumentFile = pChannelInfo->instrument_file;          if (pDeviceInfo == NULL) {
637          m_iInstrumentNr   = pChannelInfo->instrument_nr;                  appendMessagesClient("lscp_get_audio_device_info");
638                  m_sInstrumentName = getInstrumentName(m_sInstrumentFile,                  m_sAudioDriver = sNone;
639                          m_iInstrumentNr, (options() && options()->bInstrumentNames));          } else {
640          }                  m_sAudioDriver = pDeviceInfo->driver;
641      // Cache in other channel information.          }
642      m_sEngineName       = pChannelInfo->engine_name;          // MIDI device driver type.
643      m_iInstrumentStatus = pChannelInfo->instrument_status;          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
644      m_iMidiDevice       = pChannelInfo->midi_device;          if (pDeviceInfo == NULL) {
645      m_iMidiPort         = pChannelInfo->midi_port;                  appendMessagesClient("lscp_get_midi_device_info");
646      m_iMidiChannel      = pChannelInfo->midi_channel;                  m_sMidiDriver = sNone;
647      m_iAudioDevice      = pChannelInfo->audio_device;          } else {
648      m_fVolume           = pChannelInfo->volume;                  m_sMidiDriver = pDeviceInfo->driver;
     // Some sanity checks.  
     if (m_sEngineName == "NONE")  
         m_sEngineName = QString::null;  
     if (m_sInstrumentFile == "NONE") {  
         m_sInstrumentFile = QString::null;  
         m_sInstrumentName = QString::null;  
649          }          }
650    
651      return true;          // Set the audio routing map.
652            m_audioRouting.clear();
653    #ifdef CONFIG_AUDIO_ROUTING
654            int *piAudioRouting = pChannelInfo->audio_routing;
655            for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
656                    m_audioRouting[i] = piAudioRouting[i];
657    #else
658            char **ppszAudioRouting = pChannelInfo->audio_routing;
659            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
660                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
661    #endif
662    
663            return true;
664  }  }
665    
666    
667  // Reset channel method.  // Reset channel method.
668  bool qsamplerChannel::resetChannel (void)  bool qsamplerChannel::channelReset (void)
669  {  {
670      if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
671          return false;          if (pMainForm == NULL)
672                    return false;
673            if (pMainForm->client() == NULL || m_iChannelID < 0)
674                    return false;
675    
676            if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
677                    appendMessagesClient("lscp_reset_channel");
678                    return false;
679            }
680    
681      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          appendMessages(QObject::tr("reset."));
682          appendMessagesClient("lscp_reset_channel");  
683          return false;          return true;
684      }  }
685    
686    
687    // Spawn instrument editor method.
688    bool qsamplerChannel::editChannel (void)
689    {
690    #ifdef CONFIG_EDIT_INSTRUMENT
691    
692            MainForm *pMainForm = MainForm::getInstance();
693            if (pMainForm == NULL)
694                    return false;
695            if (pMainForm->client() == NULL || m_iChannelID < 0)
696                    return false;
697    
698            if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
699                    != LSCP_OK) {
700                    appendMessagesClient("lscp_edit_channel_instrument");
701                    appendMessagesError(QObject::tr(
702                            "Could not launch an appropriate instrument editor "
703                            "for the given instrument!\n"
704                            "Make sure you have an appropriate "
705                            "instrument editor like 'gigedit' installed\n"
706                            "and that it placed its mandatory DLL file "
707                            "into the sampler's plugin directory.")
708                    );
709                    return false;
710            }
711    
712            appendMessages(QObject::tr("edit instrument."));
713    
714            return true;
715    
716    #else
717    
718            appendMessagesError(QObject::tr(
719                    "Sorry, QSampler was compiled for a version of liblscp "
720                    "which lacks this feature.\n"
721                    "You may want to update liblscp and recompile QSampler afterwards.")
722            );
723    
724      appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));          return false;
725      return true;  
726    #endif
727  }  }
728    
729    
730  // Channel setup dialog form.  // Channel setup dialog form.
731  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
732  {  {
733      bool bResult = false;          MainForm *pMainForm = MainForm::getInstance();
734            if (pMainForm == NULL)
735      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);                  return false;
736      if (pChannelForm) {  
737          pChannelForm->setup(this);          bool bResult = false;
738          bResult = pChannelForm->exec();  
739          delete pChannelForm;          appendMessages(QObject::tr("setup..."));
740      }  
741            ChannelForm *pChannelForm = new ChannelForm(pParent);
742            if (pChannelForm) {
743                    pChannelForm->setup(this);
744                    bResult = pChannelForm->exec();
745                    delete pChannelForm;
746            }
747    
748      return bResult;          return bResult;
749  }  }
750    
751    
752  // Redirected messages output methods.  // Redirected messages output methods.
753  void qsamplerChannel::appendMessages( const QString& s )  void qsamplerChannel::appendMessages( const QString& s ) const
754  {  {
755      if (m_pMainForm) m_pMainForm->appendMessages(s);          MainForm *pMainForm = MainForm::getInstance();
756            if (pMainForm)
757                    pMainForm->appendMessages(channelName() + ' ' + s);
758  }  }
759    
760  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )  void qsamplerChannel::appendMessagesColor( const QString& s,
761            const QString& c ) const
762  {  {
763      if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c);          MainForm *pMainForm = MainForm::getInstance();
764            if (pMainForm)
765                    pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
766  }  }
767    
768  void qsamplerChannel::appendMessagesText( const QString& s )  void qsamplerChannel::appendMessagesText( const QString& s ) const
769  {  {
770      if (m_pMainForm) m_pMainForm->appendMessagesText(s);          MainForm *pMainForm = MainForm::getInstance();
771            if (pMainForm)
772                    pMainForm->appendMessagesText(channelName() + ' ' + s);
773  }  }
774    
775  void qsamplerChannel::appendMessagesError( const QString& s )  void qsamplerChannel::appendMessagesError( const QString& s ) const
776  {  {
777      if (m_pMainForm) m_pMainForm->appendMessagesError(s);          MainForm *pMainForm = MainForm::getInstance();
778            if (pMainForm)
779                    pMainForm->appendMessagesError(channelName() + "\n\n" + s);
780  }  }
781    
782  void qsamplerChannel::appendMessagesClient( const QString& s )  void qsamplerChannel::appendMessagesClient( const QString& s ) const
783  {  {
784      if (m_pMainForm) m_pMainForm->appendMessagesClient(s);          MainForm *pMainForm = MainForm::getInstance();
785            if (pMainForm)
786                    pMainForm->appendMessagesClient(channelName() + ' ' + s);
787  }  }
788    
789    
790  // Context menu event handler.  // Context menu event handler.
791  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
792  {  {
793      if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent);          MainForm *pMainForm = MainForm::getInstance();
794            if (pMainForm)
795                    pMainForm->contextMenuEvent(pEvent);
796    }
797    
798    
799    // FIXME: Check whether a given file is an instrument file.
800    bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
801    {
802            bool bResult = false;
803    
804            QFile file(sInstrumentFile);
805            if (file.open(IO_ReadOnly)) {
806                    char achHeader[16];
807                    if (file.readBlock(achHeader, 16)) {
808                            bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
809                                            && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
810                    }
811                    file.close();
812            }
813    
814            return bResult;
815  }  }
816    
817    
# Line 475  void qsamplerChannel::contextMenuEvent( Line 819  void qsamplerChannel::contextMenuEvent(
819  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
820          bool bInstrumentNames )          bool bInstrumentNames )
821  {  {
822      QFileInfo fileinfo(sInstrumentFile);          QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();
823      QString sInstrumentName = fileinfo.fileName();          QStringList instlist;
     QStringList instlist;  
824    
825      if (fileinfo.exists()) {          if (isInstrumentFile(sInstrumentFile)) {
826  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
827                  if (bInstrumentNames) {                  if (bInstrumentNames) {
828                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
829                  gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
830                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
831                  while (pInstrument) {                          while (pInstrument) {
832                      instlist.append((pInstrument->pInfo)->Name.c_str());                                  instlist.append((pInstrument->pInfo)->Name.c_str());
833                      pInstrument = pGig->GetNextInstrument();                                  pInstrument = pGig->GetNextInstrument();
834                  }                          }
835                  delete pGig;                          delete pGig;
836                  delete pRiff;                          delete pRiff;
837                  }                  }
838                  else                  else
839  #endif  #endif
840          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)                  for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
841              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");                          instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
842      }          }
843      else instlist.append(sInstrumentName);          else instlist.append(noInstrumentName());
844    
845      return instlist;          return instlist;
846  }  }
847    
848    
# Line 507  QStringList qsamplerChannel::getInstrume Line 850  QStringList qsamplerChannel::getInstrume
850  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
851          int iInstrumentNr, bool bInstrumentNames )          int iInstrumentNr, bool bInstrumentNames )
852  {  {
853      QFileInfo fileinfo(sInstrumentFile);          QString sInstrumentName;
     QString sInstrumentName = fileinfo.fileName();  
854    
855      if (fileinfo.exists()) {          if (isInstrumentFile(sInstrumentFile)) {
856                    sInstrumentName = QFileInfo(sInstrumentFile).fileName();
857  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
858                  if (bInstrumentNames) {                  if (bInstrumentNames) {
859                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
860                  gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
861                  int iIndex = 0;                          int iIndex = 0;
862                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
863                  while (pInstrument) {                          while (pInstrument) {
864                      if (iIndex == iInstrumentNr) {                                  if (iIndex == iInstrumentNr) {
865                          sInstrumentName = (pInstrument->pInfo)->Name.c_str();                                          sInstrumentName = (pInstrument->pInfo)->Name.c_str();
866                          break;                                          break;
867                      }                                  }
868                      iIndex++;                                  iIndex++;
869                      pInstrument = pGig->GetNextInstrument();                                  pInstrument = pGig->GetNextInstrument();
870                  }                          }
871                  delete pGig;                          delete pGig;
872                  delete pRiff;                          delete pRiff;
873                  }                  }
874                  else                  else
875  #endif  #endif
876          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
877            }
878            else sInstrumentName = noInstrumentName();
879    
880            return sInstrumentName;
881    }
882    
883    
884    // Common invalid name-helpers.
885    QString qsamplerChannel::noEngineName (void)
886    {
887            return QObject::tr("(No engine)");
888    }
889    
890    QString qsamplerChannel::noInstrumentName (void)
891    {
892            return QObject::tr("(No instrument)");
893    }
894    
895    QString qsamplerChannel::loadingInstrument (void) {
896            return QObject::tr("(Loading instrument...)");
897    }
898    
899    
900    
901    //-------------------------------------------------------------------------
902    // qsamplerChannelRoutingTable - Channel routing table.
903    //
904    #if 0
905    // Constructor.
906    qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
907            QWidget *pParent, const char *pszName )
908            : QTable(pParent, pszName)
909    {
910            // Set fixed number of columns.
911            QTable::setNumCols(2);
912            QTable::setShowGrid(false);
913            QTable::setSorting(false);
914            QTable::setFocusStyle(QTable::FollowStyle);
915            QTable::setSelectionMode(QTable::NoSelection);
916            // No vertical header.
917            QTable::verticalHeader()->hide();
918            QTable::setLeftMargin(0);
919            // Initialize the fixed table column headings.
920            QHeader *pHeader = QTable::horizontalHeader();
921            pHeader->setLabel(0, tr("Sampler Channel"));
922            pHeader->setLabel(1, tr("Device Channel"));
923            // Set read-onlyness of each column
924            QTable::setColumnReadOnly(0, true);
925    //      QTable::setColumnReadOnly(1, false); -- of course not.
926            QTable::setColumnStretchable(1, true);
927    }
928    
929    // Default destructor.
930    qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)
931    {
932    }
933    
934    
935    // Routing map table renderer.
936    void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,
937            const qsamplerChannelRoutingMap& routing )
938    {
939            if (pDevice == NULL)
940                    return;
941    
942            // Always (re)start it empty.
943            QTable::setUpdatesEnabled(false);
944            QTable::setNumRows(0);
945    
946            // The common device port item list.
947            QStringList opts;
948            qsamplerDevicePortList& ports = pDevice->ports();
949            qsamplerDevicePort *pPort;
950            for (pPort = ports.first(); pPort; pPort = ports.next()) {
951                    opts.append(pDevice->deviceTypeName()
952                            + ' ' + pDevice->driverName()
953                            + ' ' + pPort->portName());
954            }
955    
956            // Those items shall have a proper pixmap...
957            QPixmap pmChannel = QPixmap(":/icons/qsamplerChannel.png");
958            QPixmap pmDevice;
959            switch (pDevice->deviceType()) {
960            case qsamplerDevice::Audio:
961                    pmDevice = QPixmap(":/icons/audio2.png");
962                    break;
963            case qsamplerDevice::Midi:
964                    pmDevice = QPixmap(":/icons/midi2.png");
965                    break;
966            case qsamplerDevice::None:
967                    break;
968            }
969    
970            // Fill the routing table...
971            QTable::insertRows(0, routing.count());
972            int iRow = 0;
973            qsamplerChannelRoutingMap::ConstIterator iter;
974            for (iter = routing.begin(); iter != routing.end(); ++iter) {
975                    QTable::setPixmap(iRow, 0, pmChannel);
976                    QTable::setText(iRow, 0, pDevice->deviceTypeName()
977                            + ' ' + QString::number(iter.key()));
978                    qsamplerChannelRoutingComboBox *pComboItem =
979                            new qsamplerChannelRoutingComboBox(this, opts, pmDevice);
980                    pComboItem->setCurrentItem(iter.data());
981                    QTable::setItem(iRow, 1, pComboItem);
982                    ++iRow;
983            }
984    
985            // Adjust optimal column widths.
986            QTable::adjustColumn(0);
987            QTable::adjustColumn(1);
988    
989            QTable::setUpdatesEnabled(true);
990            QTable::updateContents();
991    }
992    
993    
994    // Commit any pending editing.
995    void qsamplerChannelRoutingTable::flush (void)
996    {
997            if (QTable::isEditing())
998                QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);
999    }
1000    #endif
1001    
1002    ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
1003    }
1004    
1005    int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
1006        return routing.size();
1007    }
1008    
1009    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
1010        return 1;
1011    }
1012    
1013    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
1014        if (!index.isValid())
1015            return QVariant();
1016        if (role != Qt::DisplayRole)
1017            return QVariant();
1018    
1019        ChannelRoutingItem item;
1020    
1021        // The common device port item list.
1022        qsamplerDevicePortList& ports = pDevice->ports();
1023        qsamplerDevicePort* pPort;
1024        for (pPort = ports.first(); pPort; pPort = ports.next()) {
1025            item.options.append(
1026                pDevice->deviceTypeName()
1027                + ' ' + pDevice->driverName()
1028                + ' ' + pPort->portName()
1029            );
1030      }      }
1031    
1032      return sInstrumentName;      item.selection = routing[index.column()];
1033    
1034        return QVariant::fromValue(item);
1035    }
1036    
1037    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
1038        if (role != Qt::DisplayRole) return QVariant();
1039    
1040        if (orientation == Qt::Horizontal)
1041            return QObject::tr("Device Channel");
1042    
1043        if (orientation == Qt::Vertical)
1044            return QObject::tr("Sampler Channel Output ") +
1045                   QString(section);
1046    
1047        return QVariant();
1048    }
1049    
1050    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
1051            const qsamplerChannelRoutingMap& routing )
1052    {
1053        this->pDevice = pDevice;
1054        this->routing = routing;
1055    }
1056    
1057    
1058    
1059    
1060    ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
1061    }
1062    
1063    QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
1064            const QStyleOptionViewItem &/* option */,
1065            const QModelIndex& index) const
1066    {
1067        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1068    
1069        QComboBox* editor = new QComboBox(parent);
1070        editor->addItems(item.options);
1071        editor->setCurrentIndex(item.selection);
1072        editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this));
1073        return editor;
1074    }
1075    
1076    void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1077        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1078        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1079        comboBox->setCurrentIndex(item.selection);
1080    }
1081    
1082    void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
1083        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1084        model->setData(index, comboBox->currentIndex());
1085  }  }
1086    
1087    void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1088            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1089    {
1090        editor->setGeometry(option.rect);
1091    }
1092    
1093    
1094    
1095    //-------------------------------------------------------------------------
1096    // qsamplerChannelRoutingComboBox - Custom combo box for routing table.
1097    //
1098    
1099    #if 0
1100    // Constructor.
1101    qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (
1102            QTable *pTable, const QStringList& list, const QPixmap& pixmap )
1103            : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),
1104            m_list(list)
1105    {
1106            m_iCurrentItem = 0;
1107    }
1108    
1109    // Public accessors.
1110    void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )
1111    {
1112            m_iCurrentItem = iCurrentItem;
1113    
1114            QTableItem::setText(m_list[iCurrentItem]);
1115    }
1116    
1117    int qsamplerChannelRoutingComboBox::currentItem (void) const
1118    {
1119            return m_iCurrentItem;
1120    }
1121    
1122    // Virtual implemetations.
1123    QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const
1124    {
1125            QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());
1126            QObject::connect(pComboBox, SIGNAL(activated(int)),
1127                    QTableItem::table(), SLOT(doValueChanged()));
1128            for (QStringList::ConstIterator iter = m_list.begin();
1129                            iter != m_list.end(); iter++) {
1130                    pComboBox->insertItem(QTableItem::pixmap(), *iter);
1131            }
1132            pComboBox->setCurrentItem(m_iCurrentItem);
1133            return pComboBox;
1134    }
1135    
1136    void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )
1137    {
1138            if (pWidget->inherits("QComboBox")) {
1139                    QComboBox *pComboBox = (QComboBox *) pWidget;
1140                    m_iCurrentItem = pComboBox->currentItem();
1141                    QTableItem::setText(pComboBox->currentText());
1142            }
1143            else QTableItem::setContentFromEditor(pWidget);
1144    }
1145    
1146    #endif
1147    
1148    
1149  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.344  
changed lines
  Added in v.1465

  ViewVC Help
Powered by ViewVC