/[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 961 by capela, Sun Dec 3 18:26:13 2006 UTC revision 1489 by schoenebeck, Mon Nov 19 03:29:57 2007 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 19  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerUtilities.h"
24  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
25  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
26    
# Line 34  Line 36 
36    
37  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    using namespace QSampler;
40    
41  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
42  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 53  qsamplerChannel::qsamplerChannel ( int i Line 56  qsamplerChannel::qsamplerChannel ( int i
56          m_iMidiDevice       = -1;          m_iMidiDevice       = -1;
57          m_iMidiPort         = -1;          m_iMidiPort         = -1;
58          m_iMidiChannel      = -1;          m_iMidiChannel      = -1;
59            m_iMidiMap          = -1;
60          m_sAudioDriver      = "ALSA";          m_sAudioDriver      = "ALSA";
61          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
62          m_fVolume           = 0.0;          m_fVolume           = 0.0;
# Line 69  qsamplerChannel::~qsamplerChannel (void) Line 73  qsamplerChannel::~qsamplerChannel (void)
73  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
74  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
75  {  {
76          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
77          if (pMainForm == NULL)          if (pMainForm == NULL)
78                  return false;                  return false;
79          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 94  bool qsamplerChannel::addChannel (void) Line 98  bool qsamplerChannel::addChannel (void)
98  // Remove sampler channel.  // Remove sampler channel.
99  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
100  {  {
101          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
102          if (pMainForm == NULL)          if (pMainForm == NULL)
103                  return false;                  return false;
104          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 144  const QString& qsamplerChannel::engineNa Line 148  const QString& qsamplerChannel::engineNa
148    
149  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
150  {  {
151          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
152          if (pMainForm == NULL)          if (pMainForm == NULL)
153                  return false;                  return false;
154          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 191  int qsamplerChannel::instrumentStatus (v Line 195  int qsamplerChannel::instrumentStatus (v
195  // Instrument file loader.  // Instrument file loader.
196  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
197  {  {
198          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
199          if (pMainForm == NULL)          if (pMainForm == NULL)
200                  return false;                  return false;
201          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 201  bool qsamplerChannel::loadInstrument ( c Line 205  bool qsamplerChannel::loadInstrument ( c
205          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
206                  return true;                  return true;
207    
208          if (::lscp_load_instrument_non_modal(pMainForm->client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (
209                    ::lscp_load_instrument_non_modal(
210                            pMainForm->client(),
211                            qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),
212                            iInstrumentNr, m_iChannelID
213                    ) != LSCP_OK
214            ) {
215                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
216                  return false;                  return false;
217          }          }
# Line 237  const QString& qsamplerChannel::midiDriv Line 247  const QString& qsamplerChannel::midiDriv
247    
248  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
249  {  {
250          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
251          if (pMainForm == NULL)          if (pMainForm == NULL)
252                  return false;                  return false;
253          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 265  int qsamplerChannel::midiDevice (void) c Line 275  int qsamplerChannel::midiDevice (void) c
275    
276  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
277  {  {
278          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
279          if (pMainForm == NULL)          if (pMainForm == NULL)
280                  return false;                  return false;
281          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 293  int qsamplerChannel::midiPort (void) con Line 303  int qsamplerChannel::midiPort (void) con
303    
304  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
305  {  {
306          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
307          if (pMainForm == NULL)          if (pMainForm == NULL)
308                  return false;                  return false;
309          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 321  int qsamplerChannel::midiChannel (void) Line 331  int qsamplerChannel::midiChannel (void)
331    
332  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
333  {  {
334          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
335          if (pMainForm == NULL)          if (pMainForm == NULL)
336                  return false;                  return false;
337          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 341  bool qsamplerChannel::setMidiChannel ( i Line 351  bool qsamplerChannel::setMidiChannel ( i
351  }  }
352    
353    
354    // MIDI instrument map accessor.
355    int qsamplerChannel::midiMap (void) const
356    {
357            return m_iMidiMap;
358    }
359    
360    bool qsamplerChannel::setMidiMap ( int iMidiMap )
361    {
362            MainForm *pMainForm = MainForm::getInstance();
363            if (pMainForm == NULL)
364                    return false;
365            if (pMainForm->client() == NULL || m_iChannelID < 0)
366                    return false;
367            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
368                    return true;
369    #ifdef CONFIG_MIDI_INSTRUMENT
370            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
371                    appendMessagesClient("lscp_set_channel_midi_map");
372                    return false;
373            }
374    #endif
375            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
376    
377            m_iMidiMap = iMidiMap;
378            return true;
379    }
380    
381    
382  // Audio device accessor.  // Audio device accessor.
383  int qsamplerChannel::audioDevice (void) const  int qsamplerChannel::audioDevice (void) const
384  {  {
# Line 349  int qsamplerChannel::audioDevice (void) Line 387  int qsamplerChannel::audioDevice (void)
387    
388  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
389  {  {
390          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
391          if (pMainForm == NULL)          if (pMainForm == NULL)
392                  return false;                  return false;
393          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 377  const QString& qsamplerChannel::audioDri Line 415  const QString& qsamplerChannel::audioDri
415    
416  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
417  {  {
418          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
419          if (pMainForm == NULL)          if (pMainForm == NULL)
420                  return false;                  return false;
421          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 405  float qsamplerChannel::volume (void) con Line 443  float qsamplerChannel::volume (void) con
443    
444  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
445  {  {
446          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
447          if (pMainForm == NULL)          if (pMainForm == NULL)
448                  return false;                  return false;
449          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 433  bool qsamplerChannel::channelMute (void) Line 471  bool qsamplerChannel::channelMute (void)
471    
472  bool qsamplerChannel::setChannelMute ( bool bMute )  bool qsamplerChannel::setChannelMute ( bool bMute )
473  {  {
474          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
475          if (pMainForm == NULL)          if (pMainForm == NULL)
476                  return false;                  return false;
477          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 463  bool qsamplerChannel::channelSolo (void) Line 501  bool qsamplerChannel::channelSolo (void)
501    
502  bool qsamplerChannel::setChannelSolo ( bool bSolo )  bool qsamplerChannel::setChannelSolo ( bool bSolo )
503  {  {
504          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
505          if (pMainForm == NULL)          if (pMainForm == NULL)
506                  return false;                  return false;
507          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 493  int qsamplerChannel::audioChannel ( int Line 531  int qsamplerChannel::audioChannel ( int
531    
532  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
533  {  {
534          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
535          if (pMainForm == NULL)          if (pMainForm == NULL)
536                  return false;                  return false;
537          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 535  void qsamplerChannel::updateInstrumentNa Line 573  void qsamplerChannel::updateInstrumentNa
573  // Update whole channel info state.  // Update whole channel info state.
574  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
575  {  {
576          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
577          if (pMainForm == NULL)          if (pMainForm == NULL)
578                  return false;                  return false;
579          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 551  bool qsamplerChannel::updateChannelInfo Line 589  bool qsamplerChannel::updateChannelInfo
589    
590  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
591          // We got all actual instrument datum...          // We got all actual instrument datum...
592          m_sInstrumentFile = pChannelInfo->instrument_file;          m_sInstrumentFile =
593                    qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
594          m_iInstrumentNr   = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
595          m_sInstrumentName = pChannelInfo->instrument_name;          m_sInstrumentName =
596                    qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
597  #else  #else
598          // First, check if intrument name has changed,          // First, check if intrument name has changed,
599          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
# Line 571  bool qsamplerChannel::updateChannelInfo Line 611  bool qsamplerChannel::updateChannelInfo
611          m_iMidiDevice       = pChannelInfo->midi_device;          m_iMidiDevice       = pChannelInfo->midi_device;
612          m_iMidiPort         = pChannelInfo->midi_port;          m_iMidiPort         = pChannelInfo->midi_port;
613          m_iMidiChannel      = pChannelInfo->midi_channel;          m_iMidiChannel      = pChannelInfo->midi_channel;
614    #ifdef CONFIG_MIDI_INSTRUMENT
615            m_iMidiMap          = pChannelInfo->midi_map;
616    #endif
617          m_iAudioDevice      = pChannelInfo->audio_device;          m_iAudioDevice      = pChannelInfo->audio_device;
618          m_fVolume           = pChannelInfo->volume;          m_fVolume           = pChannelInfo->volume;
619  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
# Line 607  bool qsamplerChannel::updateChannelInfo Line 650  bool qsamplerChannel::updateChannelInfo
650    
651          // Set the audio routing map.          // Set the audio routing map.
652          m_audioRouting.clear();          m_audioRouting.clear();
653          char **ppszRouting = pChannelInfo->audio_routing;  #ifdef CONFIG_AUDIO_ROUTING
654          for (int i = 0; ppszRouting && ppszRouting[i]; i++) {          int *piAudioRouting = pChannelInfo->audio_routing;
655                  m_audioRouting[i] = ::atoi(ppszRouting[i]);          for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
656          }                  m_audioRouting[i] = piAudioRouting[i];
657    #else
658            char **ppszAudioRouting = pChannelInfo->audio_routing;
659            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
660                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
661    #endif
662    
663          return true;          return true;
664  }  }
# Line 619  bool qsamplerChannel::updateChannelInfo Line 667  bool qsamplerChannel::updateChannelInfo
667  // Reset channel method.  // Reset channel method.
668  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
669  {  {
670          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
671          if (pMainForm == NULL)          if (pMainForm == NULL)
672                  return false;                  return false;
673          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 636  bool qsamplerChannel::channelReset (void Line 684  bool qsamplerChannel::channelReset (void
684  }  }
685    
686    
687    // Spawn instrument editor method.
688    bool qsamplerChannel::editChannel (void)
689    {
690    #ifdef CONFIG_EDIT_INSTRUMENT
691    
692            MainForm *pMainForm = MainForm::getInstance();
693            if (pMainForm == NULL)
694                    return false;
695            if (pMainForm->client() == NULL || m_iChannelID < 0)
696                    return false;
697    
698            if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
699                    != LSCP_OK) {
700                    appendMessagesClient("lscp_edit_channel_instrument");
701                    appendMessagesError(QObject::tr(
702                            "Could not launch an appropriate instrument editor "
703                            "for the given instrument!\n"
704                            "Make sure you have an appropriate "
705                            "instrument editor like 'gigedit' installed\n"
706                            "and that it placed its mandatory DLL file "
707                            "into the sampler's plugin directory.")
708                    );
709                    return false;
710            }
711    
712            appendMessages(QObject::tr("edit instrument."));
713    
714            return true;
715    
716    #else
717    
718            appendMessagesError(QObject::tr(
719                    "Sorry, QSampler was compiled for a version of liblscp "
720                    "which lacks this feature.\n"
721                    "You may want to update liblscp and recompile QSampler afterwards.")
722            );
723    
724            return false;
725    
726    #endif
727    }
728    
729    
730  // Channel setup dialog form.  // Channel setup dialog form.
731  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
732  {  {
733          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
734          if (pMainForm == NULL)          if (pMainForm == NULL)
735                  return false;                  return false;
736    
# Line 647  bool qsamplerChannel::channelSetup ( QWi Line 738  bool qsamplerChannel::channelSetup ( QWi
738    
739          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
740    
741          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
742          if (pChannelForm) {          if (pChannelForm) {
743                  pChannelForm->setup(this);                  pChannelForm->setup(this);
744                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 661  bool qsamplerChannel::channelSetup ( QWi Line 752  bool qsamplerChannel::channelSetup ( QWi
752  // Redirected messages output methods.  // Redirected messages output methods.
753  void qsamplerChannel::appendMessages( const QString& s ) const  void qsamplerChannel::appendMessages( const QString& s ) const
754  {  {
755          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
756          if (pMainForm)          if (pMainForm)
757                  pMainForm->appendMessages(channelName() + ' ' + s);                  pMainForm->appendMessages(channelName() + ' ' + s);
758  }  }
# Line 669  void qsamplerChannel::appendMessages( co Line 760  void qsamplerChannel::appendMessages( co
760  void qsamplerChannel::appendMessagesColor( const QString& s,  void qsamplerChannel::appendMessagesColor( const QString& s,
761          const QString& c ) const          const QString& c ) const
762  {  {
763          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
764          if (pMainForm)          if (pMainForm)
765                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
766  }  }
767    
768  void qsamplerChannel::appendMessagesText( const QString& s ) const  void qsamplerChannel::appendMessagesText( const QString& s ) const
769  {  {
770          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
771          if (pMainForm)          if (pMainForm)
772                  pMainForm->appendMessagesText(channelName() + ' ' + s);                  pMainForm->appendMessagesText(channelName() + ' ' + s);
773  }  }
774    
775  void qsamplerChannel::appendMessagesError( const QString& s ) const  void qsamplerChannel::appendMessagesError( const QString& s ) const
776  {  {
777          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
778          if (pMainForm)          if (pMainForm)
779                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);
780  }  }
781    
782  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void qsamplerChannel::appendMessagesClient( const QString& s ) const
783  {  {
784          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
785          if (pMainForm)          if (pMainForm)
786                  pMainForm->appendMessagesClient(channelName() + ' ' + s);                  pMainForm->appendMessagesClient(channelName() + ' ' + s);
787  }  }
# Line 699  void qsamplerChannel::appendMessagesClie Line 790  void qsamplerChannel::appendMessagesClie
790  // Context menu event handler.  // Context menu event handler.
791  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
792  {  {
793          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
794          if (pMainForm)          if (pMainForm)
795                  pMainForm->contextMenuEvent(pEvent);                  pMainForm->contextMenuEvent(pEvent);
796  }  }
# Line 806  QString qsamplerChannel::loadingInstrume Line 897  QString qsamplerChannel::loadingInstrume
897  }  }
898    
899    
   
900  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
901  // qsamplerChannelRoutingTable - Channel routing table.  // ChannelRoutingModel - data model for audio routing (used for QTableView)
902  //  //
903    
904  // Constructor.  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
 qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (  
         QWidget *pParent, const char *pszName )  
         : QTable(pParent, pszName)  
 {  
         // Set fixed number of columns.  
         QTable::setNumCols(2);  
         QTable::setShowGrid(false);  
         QTable::setSorting(false);  
         QTable::setFocusStyle(QTable::FollowStyle);  
         QTable::setSelectionMode(QTable::NoSelection);  
         // No vertical header.  
         QTable::verticalHeader()->hide();  
         QTable::setLeftMargin(0);  
         // Initialize the fixed table column headings.  
         QHeader *pHeader = QTable::horizontalHeader();  
         pHeader->setLabel(0, tr("Sampler Channel"));  
         pHeader->setLabel(1, tr("Device Channel"));  
         // Set read-onlyness of each column  
         QTable::setColumnReadOnly(0, true);  
 //      QTable::setColumnReadOnly(1, false); -- of course not.  
         QTable::setColumnStretchable(1, true);  
905  }  }
906    
907  // Default destructor.  int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
908  qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)      return routing.size();
 {  
909  }  }
910    
911    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
912        return 1;
913    }
914    
915  // Routing map table renderer.  Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {
916  void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
917          const qsamplerChannelRoutingMap& routing )  }
918  {  
919          if (pDevice == NULL)  bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
920                  return;      if (!index.isValid()) {
921            return false;
922        }
923    
924          // Always (re)start it empty.      routing[index.row()] = value.toInt();
925          QTable::setUpdatesEnabled(false);  
926          QTable::setNumRows(0);      emit dataChanged(index, index);
927        return true;
         // The common device port item list.  
         QStringList opts;  
         qsamplerDevicePortList& ports = pDevice->ports();  
         qsamplerDevicePort *pPort;  
         for (pPort = ports.first(); pPort; pPort = ports.next()) {  
                 opts.append(pDevice->deviceTypeName()  
                         + ' ' + pDevice->driverName()  
                         + ' ' + pPort->portName());  
         }  
   
         // Those items shall have a proper pixmap...  
         QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");  
         QPixmap pmDevice;  
         switch (pDevice->deviceType()) {  
         case qsamplerDevice::Audio:  
                 pmDevice = QPixmap::fromMimeSource("audio2.png");  
                 break;  
         case qsamplerDevice::Midi:  
                 pmDevice = QPixmap::fromMimeSource("midi2.png");  
                 break;  
         case qsamplerDevice::None:  
                 break;  
         }  
   
         // Fill the routing table...  
         QTable::insertRows(0, routing.count());  
         int iRow = 0;  
         qsamplerChannelRoutingMap::ConstIterator iter;  
         for (iter = routing.begin(); iter != routing.end(); ++iter) {  
                 QTable::setPixmap(iRow, 0, pmChannel);  
                 QTable::setText(iRow, 0, pDevice->deviceTypeName()  
                         + ' ' + QString::number(iter.key()));  
                 qsamplerChannelRoutingComboBox *pComboItem =  
                         new qsamplerChannelRoutingComboBox(this, opts, pmDevice);  
                 pComboItem->setCurrentItem(iter.data());  
                 QTable::setItem(iRow, 1, pComboItem);  
                 ++iRow;  
         }  
   
         // Adjust optimal column widths.  
         QTable::adjustColumn(0);  
         QTable::adjustColumn(1);  
   
         QTable::setUpdatesEnabled(true);  
         QTable::updateContents();  
928  }  }
929    
930    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
931        if (!index.isValid())
932            return QVariant();
933        if (role != Qt::DisplayRole)
934            return QVariant();
935        if (index.column() != 0)
936            return QVariant();
937    
938        ChannelRoutingItem item;
939    
940  // Commit any pending editing.      // The common device port item list.
941  void qsamplerChannelRoutingTable::flush (void)      qsamplerDevicePortList& ports = pDevice->ports();
942        qsamplerDevicePort* pPort;
943        for (pPort = ports.first(); pPort; pPort = ports.next()) {
944            item.options.append(
945                pDevice->deviceTypeName()
946                + ' ' + pDevice->driverName()
947                + ' ' + pPort->portName()
948            );
949        }
950    
951        item.selection = routing[index.row()];
952    
953        return QVariant::fromValue(item);
954    }
955    
956    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
957        if (role != Qt::DisplayRole) return QVariant();
958    
959        switch (orientation) {
960            case Qt::Horizontal:
961                return QObject::tr("-> Device Channel");
962            case Qt::Vertical:
963                return QObject::tr("Sampler Channel ") +
964                       QString::number(section) + " ->";
965            default:
966                return QVariant();
967        }
968    }
969    
970    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
971            const qsamplerChannelRoutingMap& routing )
972  {  {
973          if (QTable::isEditing())      this->pDevice = pDevice;
974              QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);      this->routing = routing;
975        // inform the outer world (QTableView) that our data changed
976        QAbstractTableModel::reset();
977  }  }
978    
979    
980  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
981  // qsamplerChannelRoutingComboBox - Custom combo box for routing table.  // ChannelRoutingDelegate - table cell renderer for audio routing
982  //  //
983    
984  // Constructor.  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
 qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (  
         QTable *pTable, const QStringList& list, const QPixmap& pixmap )  
         : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),  
         m_list(list)  
 {  
         m_iCurrentItem = 0;  
985  }  }
986    
987  // Public accessors.  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
988  void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )          const QStyleOptionViewItem & option ,
989            const QModelIndex& index) const
990  {  {
991          m_iCurrentItem = iCurrentItem;      if (!index.isValid()) {
992            return NULL;
993        }
994    
995        if (index.column() != 0) {
996            return NULL;
997        }
998    
999          QTableItem::setText(m_list[iCurrentItem]);      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1000    
1001        QComboBox* pComboBox = new QComboBox(parent);
1002        pComboBox->addItems(item.options);
1003        pComboBox->setCurrentIndex(item.selection);
1004        pComboBox->setEnabled(true);
1005        pComboBox->setGeometry(option.rect);
1006        return pComboBox;
1007  }  }
1008    
1009  int qsamplerChannelRoutingComboBox::currentItem (void) const  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1010  {      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1011          return m_iCurrentItem;      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1012        comboBox->setCurrentIndex(item.selection);
1013  }  }
1014    
1015  // Virtual implemetations.  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1016  QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1017  {      model->setData(index, comboBox->currentIndex());
         QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());  
         QObject::connect(pComboBox, SIGNAL(activated(int)),  
                 QTableItem::table(), SLOT(doValueChanged()));  
         for (QStringList::ConstIterator iter = m_list.begin();  
                         iter != m_list.end(); iter++) {  
                 pComboBox->insertItem(QTableItem::pixmap(), *iter);  
         }  
         pComboBox->setCurrentItem(m_iCurrentItem);  
         return pComboBox;  
1018  }  }
1019    
1020  void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )  void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1021            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1022  {  {
1023          if (pWidget->inherits("QComboBox")) {      editor->setGeometry(option.rect);
                 QComboBox *pComboBox = (QComboBox *) pWidget;  
                 m_iCurrentItem = pComboBox->currentItem();  
                 QTableItem::setText(pComboBox->currentText());  
         }  
         else QTableItem::setContentFromEditor(pWidget);  
1024  }  }
1025    
   
1026  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

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

  ViewVC Help
Powered by ViewVC