/[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 748 by capela, Wed Aug 17 23:03:26 2005 UTC revision 961 by capela, Sun Dec 3 18:26:13 2006 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-2006, 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 "qsamplerAbout.h"
23  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
24    
25  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
26  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
27    
 #include "config.h"  
   
28  #include <qfileinfo.h>  #include <qfileinfo.h>
29    #include <qcombobox.h>
30    
31  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
32  #include "gig.h"  #include "gig.h"
33  #endif  #endif
34    
35  #define QSAMPLER_INSTRUMENT_MAX 8  #define QSAMPLER_INSTRUMENT_MAX 100
36    
37    
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 40  Line 40 
40  //  //
41    
42  // Constructor.  // Constructor.
43  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( int iChannelID )
44  {  {
         m_pMainForm  = pMainForm;  
45          m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
46    
47  //  m_sEngineName       = noEngineName();  //  m_sEngineName       = noEngineName();
# Line 57  qsamplerChannel::qsamplerChannel ( qsamp Line 56  qsamplerChannel::qsamplerChannel ( qsamp
56          m_sAudioDriver      = "ALSA";          m_sAudioDriver      = "ALSA";
57          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
58          m_fVolume           = 0.0;          m_fVolume           = 0.0;
59            m_bMute             = false;
60            m_bSolo             = false;
61  }  }
62    
63  // Default destructor.  // Default destructor.
# Line 66  qsamplerChannel::~qsamplerChannel (void) Line 66  qsamplerChannel::~qsamplerChannel (void)
66  }  }
67    
68    
 // Main application form accessor.  
 qsamplerMainForm *qsamplerChannel::mainForm(void) const  
 {  
         return m_pMainForm;  
 }  
   
   
 // The global options settings delegated property.  
 qsamplerOptions *qsamplerChannel::options (void) const  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->options();  
 }  
   
   
 // The client descriptor delegated property.  
 lscp_client_t *qsamplerChannel::client (void) const  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->client();  
 }  
   
   
69  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
70  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
71  {  {
72          if (client() == NULL)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
73            if (pMainForm == NULL)
74                    return false;
75            if (pMainForm->client() == NULL)
76                  return false;                  return false;
77    
78          // Are we a new channel?          // Are we a new channel?
79          if (m_iChannelID < 0) {          if (m_iChannelID < 0) {
80                  m_iChannelID = ::lscp_add_channel(client());                  m_iChannelID = ::lscp_add_channel(pMainForm->client());
81                  if (m_iChannelID < 0) {                  if (m_iChannelID < 0) {
82                          appendMessagesClient("lscp_add_channel");                          appendMessagesClient("lscp_add_channel");
83                          appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));                          appendMessagesError(
84                                    QObject::tr("Could not add channel.\n\nSorry."));
85                  }   // Otherwise it's created...                  }   // Otherwise it's created...
86                  else appendMessages(QObject::tr("added."));                  else appendMessages(QObject::tr("added."));
87          }          }
# Line 117  bool qsamplerChannel::addChannel (void) Line 94  bool qsamplerChannel::addChannel (void)
94  // Remove sampler channel.  // Remove sampler channel.
95  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
96  {  {
97          if (client() == NULL)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
98            if (pMainForm == NULL)
99                    return false;
100            if (pMainForm->client() == NULL)
101                  return false;                  return false;
102    
103          // Are we an existing channel?          // Are we an existing channel?
104          if (m_iChannelID >= 0) {          if (m_iChannelID >= 0) {
105                  if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {                  if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
106                          appendMessagesClient("lscp_remove_channel");                          appendMessagesClient("lscp_remove_channel");
107                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
108                  } else {                  } else {
# Line 164  const QString& qsamplerChannel::engineNa Line 144  const QString& qsamplerChannel::engineNa
144    
145  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
146  {  {
147          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
148            if (pMainForm == NULL)
149                    return false;
150            if (pMainForm->client() == NULL || m_iChannelID < 0)
151                  return false;                  return false;
152          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
153                  return true;                  return true;
154    
155          if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
156                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
157                  return false;                  return false;
158          }          }
159    
160          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
161    
162          m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
# Line 207  int qsamplerChannel::instrumentStatus (v Line 191  int qsamplerChannel::instrumentStatus (v
191  // Instrument file loader.  // Instrument file loader.
192  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
193  {  {
194          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
195            if (pMainForm == NULL)
196                    return false;
197            if (pMainForm->client() == NULL || m_iChannelID < 0)
198                  return false;                  return false;
199          if (!isInstrumentFile(sInstrumentFile))          if (!isInstrumentFile(sInstrumentFile))
200                  return false;                  return false;
201          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
202                  return true;                  return true;
203    
204          if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (::lscp_load_instrument_non_modal(pMainForm->client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
205                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
206                  return false;                  return false;
207          }          }
# Line 250  const QString& qsamplerChannel::midiDriv Line 237  const QString& qsamplerChannel::midiDriv
237    
238  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
239  {  {
240          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
241            if (pMainForm == NULL)
242                    return false;
243            if (pMainForm->client() == NULL || m_iChannelID < 0)
244                  return false;                  return false;
245          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
246                  return true;                  return true;
247    
248          if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
249                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
250                  return false;                  return false;
251          }          }
# Line 275  int qsamplerChannel::midiDevice (void) c Line 265  int qsamplerChannel::midiDevice (void) c
265    
266  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
267  {  {
268          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
269            if (pMainForm == NULL)
270                    return false;
271            if (pMainForm->client() == NULL || m_iChannelID < 0)
272                  return false;                  return false;
273          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
274                  return true;                  return true;
275    
276          if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {          if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
277                  appendMessagesClient("lscp_set_channel_midi_device");                  appendMessagesClient("lscp_set_channel_midi_device");
278                  return false;                  return false;
279          }          }
# Line 300  int qsamplerChannel::midiPort (void) con Line 293  int qsamplerChannel::midiPort (void) con
293    
294  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
295  {  {
296          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
297            if (pMainForm == NULL)
298                    return false;
299            if (pMainForm->client() == NULL || m_iChannelID < 0)
300                  return false;                  return false;
301          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
302                  return true;                  return true;
303    
304          if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {          if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) {
305                  appendMessagesClient("lscp_set_channel_midi_port");                  appendMessagesClient("lscp_set_channel_midi_port");
306                  return false;                  return false;
307          }          }
# Line 325  int qsamplerChannel::midiChannel (void) Line 321  int qsamplerChannel::midiChannel (void)
321    
322  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
323  {  {
324          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
325            if (pMainForm == NULL)
326                    return false;
327            if (pMainForm->client() == NULL || m_iChannelID < 0)
328                  return false;                  return false;
329          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
330                  return true;                  return true;
331    
332          if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {          if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
333                  appendMessagesClient("lscp_set_channel_midi_channel");                  appendMessagesClient("lscp_set_channel_midi_channel");
334                  return false;                  return false;
335          }          }
# Line 350  int qsamplerChannel::audioDevice (void) Line 349  int qsamplerChannel::audioDevice (void)
349    
350  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
351  {  {
352          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
353            if (pMainForm == NULL)
354                    return false;
355            if (pMainForm->client() == NULL || m_iChannelID < 0)
356                  return false;                  return false;
357          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
358                  return true;                  return true;
359    
360          if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {          if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
361                  appendMessagesClient("lscp_set_channel_audio_device");                  appendMessagesClient("lscp_set_channel_audio_device");
362                  return false;                  return false;
363          }          }
# Line 375  const QString& qsamplerChannel::audioDri Line 377  const QString& qsamplerChannel::audioDri
377    
378  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
379  {  {
380          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
381            if (pMainForm == NULL)
382                    return false;
383            if (pMainForm->client() == NULL || m_iChannelID < 0)
384                  return false;                  return false;
385          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
386                  return true;                  return true;
387    
388          if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
389                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
390                  return false;                  return false;
391          }          }
# Line 400  float qsamplerChannel::volume (void) con Line 405  float qsamplerChannel::volume (void) con
405    
406  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
407  {  {
408          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
409            if (pMainForm == NULL)
410                    return false;
411            if (pMainForm->client() == NULL || m_iChannelID < 0)
412                  return false;                  return false;
413          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
414                  return true;                  return true;
415    
416          if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
417                  appendMessagesClient("lscp_set_channel_volume");                  appendMessagesClient("lscp_set_channel_volume");
418                  return false;                  return false;
419          }          }
# Line 417  bool qsamplerChannel::setVolume ( float Line 425  bool qsamplerChannel::setVolume ( float
425  }  }
426    
427    
428    // Sampler channel mute state.
429    bool qsamplerChannel::channelMute (void) const
430    {
431            return m_bMute;
432    }
433    
434    bool qsamplerChannel::setChannelMute ( bool bMute )
435    {
436            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
437            if (pMainForm == NULL)
438                    return false;
439            if (pMainForm->client() == NULL || m_iChannelID < 0)
440                    return false;
441            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
442                    return true;
443    
444    #ifdef CONFIG_MUTE_SOLO
445            if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
446                    appendMessagesClient("lscp_set_channel_mute");
447                    return false;
448            }
449            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
450            m_bMute = bMute;
451            return true;
452    #else
453            return false;
454    #endif
455    }
456    
457    
458    // Sampler channel solo state.
459    bool qsamplerChannel::channelSolo (void) const
460    {
461            return m_bSolo;
462    }
463    
464    bool qsamplerChannel::setChannelSolo ( bool bSolo )
465    {
466            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
467            if (pMainForm == NULL)
468                    return false;
469            if (pMainForm->client() == NULL || m_iChannelID < 0)
470                    return false;
471            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
472                    return true;
473    
474    #ifdef CONFIG_MUTE_SOLO
475            if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
476                    appendMessagesClient("lscp_set_channel_solo");
477                    return false;
478            }
479            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
480            m_bSolo = bSolo;
481            return true;
482    #else
483            return false;
484    #endif
485    }
486    
487    
488    // Audio routing accessors.
489    int qsamplerChannel::audioChannel ( int iAudioOut ) const
490    {
491            return m_audioRouting[iAudioOut];
492    }
493    
494    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
495    {
496            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
497            if (pMainForm == NULL)
498                    return false;
499            if (pMainForm->client() == NULL || m_iChannelID < 0)
500                    return false;
501            if (m_iInstrumentStatus == 100 &&
502                            m_audioRouting[iAudioOut] == iAudioIn)
503                    return true;
504    
505            if (::lscp_set_channel_audio_channel(pMainForm->client(),
506                            m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
507                    appendMessagesClient("lscp_set_channel_audio_channel");
508                    return false;
509            }
510    
511            appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
512                    .arg(iAudioOut).arg(iAudioIn));
513    
514            m_audioRouting[iAudioOut] = iAudioIn;
515            return true;
516    }
517    
518    // The audio routing map itself.
519    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
520    {
521            return m_audioRouting;
522    }
523    
524    
525  // Istrument name remapper.  // Istrument name remapper.
526  void qsamplerChannel::updateInstrumentName (void)  void qsamplerChannel::updateInstrumentName (void)
527  {  {
# Line 430  void qsamplerChannel::updateInstrumentNa Line 535  void qsamplerChannel::updateInstrumentNa
535  // Update whole channel info state.  // Update whole channel info state.
536  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
537  {  {
538          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
539            if (pMainForm == NULL)
540                    return false;
541            if (pMainForm->client() == NULL || m_iChannelID < 0)
542                  return false;                  return false;
543    
544          // Read channel information.          // Read channel information.
545          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
546          if (pChannelInfo == NULL) {          if (pChannelInfo == NULL) {
547                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
548                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
# Line 465  bool qsamplerChannel::updateChannelInfo Line 573  bool qsamplerChannel::updateChannelInfo
573          m_iMidiChannel      = pChannelInfo->midi_channel;          m_iMidiChannel      = pChannelInfo->midi_channel;
574          m_iAudioDevice      = pChannelInfo->audio_device;          m_iAudioDevice      = pChannelInfo->audio_device;
575          m_fVolume           = pChannelInfo->volume;          m_fVolume           = pChannelInfo->volume;
576    #ifdef CONFIG_MUTE_SOLO
577            m_bMute             = pChannelInfo->mute;
578            m_bSolo             = pChannelInfo->solo;
579    #endif
580          // Some sanity checks.          // Some sanity checks.
581          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
582                  m_sEngineName = QString::null;                  m_sEngineName = QString::null;
# Line 477  bool qsamplerChannel::updateChannelInfo Line 589  bool qsamplerChannel::updateChannelInfo
589          lscp_device_info_t *pDeviceInfo;          lscp_device_info_t *pDeviceInfo;
590          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
591          // Audio device driver type.          // Audio device driver type.
592          pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
593          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
594                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
595                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
# Line 485  bool qsamplerChannel::updateChannelInfo Line 597  bool qsamplerChannel::updateChannelInfo
597                  m_sAudioDriver = pDeviceInfo->driver;                  m_sAudioDriver = pDeviceInfo->driver;
598          }          }
599          // MIDI device driver type.          // MIDI device driver type.
600          pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
601          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
602                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
603                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
# Line 493  bool qsamplerChannel::updateChannelInfo Line 605  bool qsamplerChannel::updateChannelInfo
605                  m_sMidiDriver = pDeviceInfo->driver;                  m_sMidiDriver = pDeviceInfo->driver;
606          }          }
607    
608            // Set the audio routing map.
609            m_audioRouting.clear();
610            char **ppszRouting = pChannelInfo->audio_routing;
611            for (int i = 0; ppszRouting && ppszRouting[i]; i++) {
612                    m_audioRouting[i] = ::atoi(ppszRouting[i]);
613            }
614    
615          return true;          return true;
616  }  }
617    
# Line 500  bool qsamplerChannel::updateChannelInfo Line 619  bool qsamplerChannel::updateChannelInfo
619  // Reset channel method.  // Reset channel method.
620  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
621  {  {
622          if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
623            if (pMainForm == NULL)
624                    return false;
625            if (pMainForm->client() == NULL || m_iChannelID < 0)
626                  return false;                  return false;
627    
628          if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
629                  appendMessagesClient("lscp_reset_channel");                  appendMessagesClient("lscp_reset_channel");
630                  return false;                  return false;
631          }          }
# Line 517  bool qsamplerChannel::channelReset (void Line 639  bool qsamplerChannel::channelReset (void
639  // Channel setup dialog form.  // Channel setup dialog form.
640  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
641  {  {
642            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
643            if (pMainForm == NULL)
644                    return false;
645    
646          bool bResult = false;          bool bResult = false;
647    
648          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
# Line 535  bool qsamplerChannel::channelSetup ( QWi Line 661  bool qsamplerChannel::channelSetup ( QWi
661  // Redirected messages output methods.  // Redirected messages output methods.
662  void qsamplerChannel::appendMessages( const QString& s ) const  void qsamplerChannel::appendMessages( const QString& s ) const
663  {  {
664          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
665                  m_pMainForm->appendMessages(channelName() + ' ' + s);          if (pMainForm)
666                    pMainForm->appendMessages(channelName() + ' ' + s);
667  }  }
668    
669  void qsamplerChannel::appendMessagesColor( const QString& s,  void qsamplerChannel::appendMessagesColor( const QString& s,
670          const QString& c ) const          const QString& c ) const
671  {  {
672          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
673                  m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);          if (pMainForm)
674                    pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
675  }  }
676    
677  void qsamplerChannel::appendMessagesText( const QString& s ) const  void qsamplerChannel::appendMessagesText( const QString& s ) const
678  {  {
679          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
680                  m_pMainForm->appendMessagesText(channelName() + ' ' + s);          if (pMainForm)
681                    pMainForm->appendMessagesText(channelName() + ' ' + s);
682  }  }
683    
684  void qsamplerChannel::appendMessagesError( const QString& s ) const  void qsamplerChannel::appendMessagesError( const QString& s ) const
685  {  {
686          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
687                  m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);          if (pMainForm)
688                    pMainForm->appendMessagesError(channelName() + "\n\n" + s);
689  }  }
690    
691  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void qsamplerChannel::appendMessagesClient( const QString& s ) const
692  {  {
693          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
694                  m_pMainForm->appendMessagesClient(channelName() + ' ' + s);          if (pMainForm)
695                    pMainForm->appendMessagesClient(channelName() + ' ' + s);
696  }  }
697    
698    
699  // Context menu event handler.  // Context menu event handler.
700  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
701  {  {
702          if (m_pMainForm)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
703                  m_pMainForm->contextMenuEvent(pEvent);          if (pMainForm)
704                    pMainForm->contextMenuEvent(pEvent);
705  }  }
706    
707    
# Line 674  QString qsamplerChannel::loadingInstrume Line 806  QString qsamplerChannel::loadingInstrume
806  }  }
807    
808    
809    
810    //-------------------------------------------------------------------------
811    // qsamplerChannelRoutingTable - Channel routing table.
812    //
813    
814    // Constructor.
815    qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
816            QWidget *pParent, const char *pszName )
817            : QTable(pParent, pszName)
818    {
819            // Set fixed number of columns.
820            QTable::setNumCols(2);
821            QTable::setShowGrid(false);
822            QTable::setSorting(false);
823            QTable::setFocusStyle(QTable::FollowStyle);
824            QTable::setSelectionMode(QTable::NoSelection);
825            // No vertical header.
826            QTable::verticalHeader()->hide();
827            QTable::setLeftMargin(0);
828            // Initialize the fixed table column headings.
829            QHeader *pHeader = QTable::horizontalHeader();
830            pHeader->setLabel(0, tr("Sampler Channel"));
831            pHeader->setLabel(1, tr("Device Channel"));
832            // Set read-onlyness of each column
833            QTable::setColumnReadOnly(0, true);
834    //      QTable::setColumnReadOnly(1, false); -- of course not.
835            QTable::setColumnStretchable(1, true);
836    }
837    
838    // Default destructor.
839    qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)
840    {
841    }
842    
843    
844    // Routing map table renderer.
845    void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,
846            const qsamplerChannelRoutingMap& routing )
847    {
848            if (pDevice == NULL)
849                    return;
850    
851            // Always (re)start it empty.
852            QTable::setUpdatesEnabled(false);
853            QTable::setNumRows(0);
854    
855            // The common device port item list.
856            QStringList opts;
857            qsamplerDevicePortList& ports = pDevice->ports();
858            qsamplerDevicePort *pPort;
859            for (pPort = ports.first(); pPort; pPort = ports.next()) {
860                    opts.append(pDevice->deviceTypeName()
861                            + ' ' + pDevice->driverName()
862                            + ' ' + pPort->portName());
863            }
864    
865            // Those items shall have a proper pixmap...
866            QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");
867            QPixmap pmDevice;
868            switch (pDevice->deviceType()) {
869            case qsamplerDevice::Audio:
870                    pmDevice = QPixmap::fromMimeSource("audio2.png");
871                    break;
872            case qsamplerDevice::Midi:
873                    pmDevice = QPixmap::fromMimeSource("midi2.png");
874                    break;
875            case qsamplerDevice::None:
876                    break;
877            }
878    
879            // Fill the routing table...
880            QTable::insertRows(0, routing.count());
881            int iRow = 0;
882            qsamplerChannelRoutingMap::ConstIterator iter;
883            for (iter = routing.begin(); iter != routing.end(); ++iter) {
884                    QTable::setPixmap(iRow, 0, pmChannel);
885                    QTable::setText(iRow, 0, pDevice->deviceTypeName()
886                            + ' ' + QString::number(iter.key()));
887                    qsamplerChannelRoutingComboBox *pComboItem =
888                            new qsamplerChannelRoutingComboBox(this, opts, pmDevice);
889                    pComboItem->setCurrentItem(iter.data());
890                    QTable::setItem(iRow, 1, pComboItem);
891                    ++iRow;
892            }
893    
894            // Adjust optimal column widths.
895            QTable::adjustColumn(0);
896            QTable::adjustColumn(1);
897    
898            QTable::setUpdatesEnabled(true);
899            QTable::updateContents();
900    }
901    
902    
903    // Commit any pending editing.
904    void qsamplerChannelRoutingTable::flush (void)
905    {
906            if (QTable::isEditing())
907                QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);
908    }
909    
910    
911    //-------------------------------------------------------------------------
912    // qsamplerChannelRoutingComboBox - Custom combo box for routing table.
913    //
914    
915    // Constructor.
916    qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (
917            QTable *pTable, const QStringList& list, const QPixmap& pixmap )
918            : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),
919            m_list(list)
920    {
921            m_iCurrentItem = 0;
922    }
923    
924    // Public accessors.
925    void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )
926    {
927            m_iCurrentItem = iCurrentItem;
928    
929            QTableItem::setText(m_list[iCurrentItem]);
930    }
931    
932    int qsamplerChannelRoutingComboBox::currentItem (void) const
933    {
934            return m_iCurrentItem;
935    }
936    
937    // Virtual implemetations.
938    QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const
939    {
940            QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());
941            QObject::connect(pComboBox, SIGNAL(activated(int)),
942                    QTableItem::table(), SLOT(doValueChanged()));
943            for (QStringList::ConstIterator iter = m_list.begin();
944                            iter != m_list.end(); iter++) {
945                    pComboBox->insertItem(QTableItem::pixmap(), *iter);
946            }
947            pComboBox->setCurrentItem(m_iCurrentItem);
948            return pComboBox;
949    }
950    
951    void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )
952    {
953            if (pWidget->inherits("QComboBox")) {
954                    QComboBox *pComboBox = (QComboBox *) pWidget;
955                    m_iCurrentItem = pComboBox->currentItem();
956                    QTableItem::setText(pComboBox->currentText());
957            }
958            else QTableItem::setContentFromEditor(pWidget);
959    }
960    
961    
962  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.748  
changed lines
  Added in v.961

  ViewVC Help
Powered by ViewVC