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

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

  ViewVC Help
Powered by ViewVC