/[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 1366 by schoenebeck, Mon Oct 1 18:26:06 2007 UTC revision 1490 by schoenebeck, Mon Nov 19 04:09:30 2007 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, 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    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41    using namespace QSampler;
42    
43  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
44  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 70  qsamplerChannel::~qsamplerChannel (void) Line 75  qsamplerChannel::~qsamplerChannel (void)
75  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
76  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
77  {  {
78          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
79          if (pMainForm == NULL)          if (pMainForm == NULL)
80                  return false;                  return false;
81          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 95  bool qsamplerChannel::addChannel (void) Line 100  bool qsamplerChannel::addChannel (void)
100  // Remove sampler channel.  // Remove sampler channel.
101  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
102  {  {
103          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
104          if (pMainForm == NULL)          if (pMainForm == NULL)
105                  return false;                  return false;
106          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 145  const QString& qsamplerChannel::engineNa Line 150  const QString& qsamplerChannel::engineNa
150    
151  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
152  {  {
153          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
154          if (pMainForm == NULL)          if (pMainForm == NULL)
155                  return false;                  return false;
156          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 192  int qsamplerChannel::instrumentStatus (v Line 197  int qsamplerChannel::instrumentStatus (v
197  // Instrument file loader.  // Instrument file loader.
198  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
199  {  {
200          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
201          if (pMainForm == NULL)          if (pMainForm == NULL)
202                  return false;                  return false;
203          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 202  bool qsamplerChannel::loadInstrument ( c Line 207  bool qsamplerChannel::loadInstrument ( c
207          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
208                  return true;                  return true;
209    
210          if (::lscp_load_instrument_non_modal(pMainForm->client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (
211                    ::lscp_load_instrument_non_modal(
212                            pMainForm->client(),
213                            qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),
214                            iInstrumentNr, m_iChannelID
215                    ) != LSCP_OK
216            ) {
217                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
218                  return false;                  return false;
219          }          }
# Line 238  const QString& qsamplerChannel::midiDriv Line 249  const QString& qsamplerChannel::midiDriv
249    
250  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
251  {  {
252          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
253          if (pMainForm == NULL)          if (pMainForm == NULL)
254                  return false;                  return false;
255          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 266  int qsamplerChannel::midiDevice (void) c Line 277  int qsamplerChannel::midiDevice (void) c
277    
278  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
279  {  {
280          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
281          if (pMainForm == NULL)          if (pMainForm == NULL)
282                  return false;                  return false;
283          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 294  int qsamplerChannel::midiPort (void) con Line 305  int qsamplerChannel::midiPort (void) con
305    
306  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
307  {  {
308          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
309          if (pMainForm == NULL)          if (pMainForm == NULL)
310                  return false;                  return false;
311          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 322  int qsamplerChannel::midiChannel (void) Line 333  int qsamplerChannel::midiChannel (void)
333    
334  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
335  {  {
336          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
337          if (pMainForm == NULL)          if (pMainForm == NULL)
338                  return false;                  return false;
339          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 350  int qsamplerChannel::midiMap (void) cons Line 361  int qsamplerChannel::midiMap (void) cons
361    
362  bool qsamplerChannel::setMidiMap ( int iMidiMap )  bool qsamplerChannel::setMidiMap ( int iMidiMap )
363  {  {
364          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
365          if (pMainForm == NULL)          if (pMainForm == NULL)
366                  return false;                  return false;
367          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 378  int qsamplerChannel::audioDevice (void) Line 389  int qsamplerChannel::audioDevice (void)
389    
390  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
391  {  {
392          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
393          if (pMainForm == NULL)          if (pMainForm == NULL)
394                  return false;                  return false;
395          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 406  const QString& qsamplerChannel::audioDri Line 417  const QString& qsamplerChannel::audioDri
417    
418  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
419  {  {
420          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
421          if (pMainForm == NULL)          if (pMainForm == NULL)
422                  return false;                  return false;
423          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 434  float qsamplerChannel::volume (void) con Line 445  float qsamplerChannel::volume (void) con
445    
446  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
447  {  {
448          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
449          if (pMainForm == NULL)          if (pMainForm == NULL)
450                  return false;                  return false;
451          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 462  bool qsamplerChannel::channelMute (void) Line 473  bool qsamplerChannel::channelMute (void)
473    
474  bool qsamplerChannel::setChannelMute ( bool bMute )  bool qsamplerChannel::setChannelMute ( bool bMute )
475  {  {
476          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
477          if (pMainForm == NULL)          if (pMainForm == NULL)
478                  return false;                  return false;
479          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 492  bool qsamplerChannel::channelSolo (void) Line 503  bool qsamplerChannel::channelSolo (void)
503    
504  bool qsamplerChannel::setChannelSolo ( bool bSolo )  bool qsamplerChannel::setChannelSolo ( bool bSolo )
505  {  {
506          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
507          if (pMainForm == NULL)          if (pMainForm == NULL)
508                  return false;                  return false;
509          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 522  int qsamplerChannel::audioChannel ( int Line 533  int qsamplerChannel::audioChannel ( int
533    
534  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
535  {  {
536          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
537          if (pMainForm == NULL)          if (pMainForm == NULL)
538                  return false;                  return false;
539          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 564  void qsamplerChannel::updateInstrumentNa Line 575  void qsamplerChannel::updateInstrumentNa
575  // Update whole channel info state.  // Update whole channel info state.
576  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
577  {  {
578          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
579          if (pMainForm == NULL)          if (pMainForm == NULL)
580                  return false;                  return false;
581          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 580  bool qsamplerChannel::updateChannelInfo Line 591  bool qsamplerChannel::updateChannelInfo
591    
592  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
593          // We got all actual instrument datum...          // We got all actual instrument datum...
594          m_sInstrumentFile = pChannelInfo->instrument_file;          m_sInstrumentFile =
595                    qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
596          m_iInstrumentNr   = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
597          m_sInstrumentName = pChannelInfo->instrument_name;          m_sInstrumentName =
598                    qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
599  #else  #else
600          // First, check if intrument name has changed,          // First, check if intrument name has changed,
601          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
# Line 656  bool qsamplerChannel::updateChannelInfo Line 669  bool qsamplerChannel::updateChannelInfo
669  // Reset channel method.  // Reset channel method.
670  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
671  {  {
672          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
673          if (pMainForm == NULL)          if (pMainForm == NULL)
674                  return false;                  return false;
675          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 677  bool qsamplerChannel::channelReset (void Line 690  bool qsamplerChannel::channelReset (void
690  bool qsamplerChannel::editChannel (void)  bool qsamplerChannel::editChannel (void)
691  {  {
692  #ifdef CONFIG_EDIT_INSTRUMENT  #ifdef CONFIG_EDIT_INSTRUMENT
693          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();  
694            MainForm *pMainForm = MainForm::getInstance();
695          if (pMainForm == NULL)          if (pMainForm == NULL)
696                  return false;                  return false;
697          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
698                  return false;                  return false;
699    
700          if (::lscp_edit_instrument(pMainForm->client(), m_iChannelID) != LSCP_OK) {          if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
701                  appendMessagesClient("lscp_edit_instrument");                  != LSCP_OK) {
702                  appendMessagesError(                  appendMessagesClient("lscp_edit_channel_instrument");
703                          "Could not launch an appropriate instrument editor for the\n"                  appendMessagesError(QObject::tr(
704                          "given instrument! Make sure you have an appropriate\n"                          "Could not launch an appropriate instrument editor "
705                          "instrument editor like 'gigedit' installed and that it placed\n"                          "for the given instrument!\n"
706                          "its mandatory DLL file into the sampler's plugin directory."                          "Make sure you have an appropriate "
707                            "instrument editor like 'gigedit' installed\n"
708                            "and that it placed its mandatory DLL file "
709                            "into the sampler's plugin directory.")
710                  );                  );
711                  return false;                  return false;
712          }          }
# Line 697  bool qsamplerChannel::editChannel (void) Line 714  bool qsamplerChannel::editChannel (void)
714          appendMessages(QObject::tr("edit instrument."));          appendMessages(QObject::tr("edit instrument."));
715    
716          return true;          return true;
717    
718  #else  #else
719          appendMessagesError(  
720                  "Sorry, QSampler was compiled for a version of liblscp which lacks\n"          appendMessagesError(QObject::tr(
721                  "this feature. You may want to update liblscp and recompile\n"                  "Sorry, QSampler was compiled for a version of liblscp "
722                  "QSampler afterwards."                  "which lacks this feature.\n"
723                    "You may want to update liblscp and recompile QSampler afterwards.")
724          );          );
725    
726          return false;          return false;
727    
728  #endif  #endif
729  }  }
730    
# Line 711  bool qsamplerChannel::editChannel (void) Line 732  bool qsamplerChannel::editChannel (void)
732  // Channel setup dialog form.  // Channel setup dialog form.
733  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
734  {  {
735          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
736          if (pMainForm == NULL)          if (pMainForm == NULL)
737                  return false;                  return false;
738    
# Line 719  bool qsamplerChannel::channelSetup ( QWi Line 740  bool qsamplerChannel::channelSetup ( QWi
740    
741          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
742    
743          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
744          if (pChannelForm) {          if (pChannelForm) {
745                  pChannelForm->setup(this);                  pChannelForm->setup(this);
746                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 733  bool qsamplerChannel::channelSetup ( QWi Line 754  bool qsamplerChannel::channelSetup ( QWi
754  // Redirected messages output methods.  // Redirected messages output methods.
755  void qsamplerChannel::appendMessages( const QString& s ) const  void qsamplerChannel::appendMessages( const QString& s ) const
756  {  {
757          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
758          if (pMainForm)          if (pMainForm)
759                  pMainForm->appendMessages(channelName() + ' ' + s);                  pMainForm->appendMessages(channelName() + ' ' + s);
760  }  }
# Line 741  void qsamplerChannel::appendMessages( co Line 762  void qsamplerChannel::appendMessages( co
762  void qsamplerChannel::appendMessagesColor( const QString& s,  void qsamplerChannel::appendMessagesColor( const QString& s,
763          const QString& c ) const          const QString& c ) const
764  {  {
765          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
766          if (pMainForm)          if (pMainForm)
767                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
768  }  }
769    
770  void qsamplerChannel::appendMessagesText( const QString& s ) const  void qsamplerChannel::appendMessagesText( const QString& s ) const
771  {  {
772          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
773          if (pMainForm)          if (pMainForm)
774                  pMainForm->appendMessagesText(channelName() + ' ' + s);                  pMainForm->appendMessagesText(channelName() + ' ' + s);
775  }  }
776    
777  void qsamplerChannel::appendMessagesError( const QString& s ) const  void qsamplerChannel::appendMessagesError( const QString& s ) const
778  {  {
779          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
780          if (pMainForm)          if (pMainForm)
781                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);
782  }  }
783    
784  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void qsamplerChannel::appendMessagesClient( const QString& s ) const
785  {  {
786          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
787          if (pMainForm)          if (pMainForm)
788                  pMainForm->appendMessagesClient(channelName() + ' ' + s);                  pMainForm->appendMessagesClient(channelName() + ' ' + s);
789  }  }
# Line 771  void qsamplerChannel::appendMessagesClie Line 792  void qsamplerChannel::appendMessagesClie
792  // Context menu event handler.  // Context menu event handler.
793  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
794  {  {
795          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
796          if (pMainForm)          if (pMainForm)
797                  pMainForm->contextMenuEvent(pEvent);                  pMainForm->contextMenuEvent(pEvent);
798  }  }
# Line 878  QString qsamplerChannel::loadingInstrume Line 899  QString qsamplerChannel::loadingInstrume
899  }  }
900    
901    
   
902  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
903  // qsamplerChannelRoutingTable - Channel routing table.  // ChannelRoutingModel - data model for audio routing (used for QTableView)
904  //  //
905    
906  // 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);  
907  }  }
908    
909  // Default destructor.  int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
910  qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)      return routing.size();
 {  
911  }  }
912    
913    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
914        return 1;
915    }
916    
917  // Routing map table renderer.  Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {
918  void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
919          const qsamplerChannelRoutingMap& routing )  }
920  {  
921          if (pDevice == NULL)  bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
922                  return;      if (!index.isValid()) {
923            return false;
924        }
925    
926        routing[index.row()] = value.toInt();
927    
928        emit dataChanged(index, index);
929        return true;
930    }
931    
932    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
933        if (!index.isValid())
934            return QVariant();
935        if (role != Qt::DisplayRole)
936            return QVariant();
937        if (index.column() != 0)
938            return QVariant();
939    
940        ChannelRoutingItem item;
941    
942        // The common device port item list.
943        qsamplerDevicePortList& ports = pDevice->ports();
944        qsamplerDevicePort* pPort;
945        for (pPort = ports.first(); pPort; pPort = ports.next()) {
946            item.options.append(
947                pDevice->deviceTypeName()
948                + ' ' + pDevice->driverName()
949                + ' ' + pPort->portName()
950            );
951        }
952    
953        item.selection = routing[index.row()];
954    
955          // Always (re)start it empty.      return QVariant::fromValue(item);
         QTable::setUpdatesEnabled(false);  
         QTable::setNumRows(0);  
   
         // 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();  
956  }  }
957    
958    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
959        if (role != Qt::DisplayRole) return QVariant();
960    
961  // Commit any pending editing.      switch (orientation) {
962  void qsamplerChannelRoutingTable::flush (void)          case Qt::Horizontal:
963                return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
964            case Qt::Vertical:
965                return QObject::tr("Sampler Channel ") +
966                       QString::number(section) + " " + UNICODE_RIGHT_ARROW;
967            default:
968                return QVariant();
969        }
970    }
971    
972    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
973            const qsamplerChannelRoutingMap& routing )
974  {  {
975          if (QTable::isEditing())      this->pDevice = pDevice;
976              QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);      this->routing = routing;
977        // inform the outer world (QTableView) that our data changed
978        QAbstractTableModel::reset();
979  }  }
980    
981    
982  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
983  // qsamplerChannelRoutingComboBox - Custom combo box for routing table.  // ChannelRoutingDelegate - table cell renderer for audio routing
984  //  //
985    
986  // 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;  
987  }  }
988    
989  // Public accessors.  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
990  void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )          const QStyleOptionViewItem & option ,
991            const QModelIndex& index) const
992  {  {
993          m_iCurrentItem = iCurrentItem;      if (!index.isValid()) {
994            return NULL;
995        }
996    
997        if (index.column() != 0) {
998            return NULL;
999        }
1000    
1001          QTableItem::setText(m_list[iCurrentItem]);      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1002    
1003        QComboBox* pComboBox = new QComboBox(parent);
1004        pComboBox->addItems(item.options);
1005        pComboBox->setCurrentIndex(item.selection);
1006        pComboBox->setEnabled(true);
1007        pComboBox->setGeometry(option.rect);
1008        return pComboBox;
1009  }  }
1010    
1011  int qsamplerChannelRoutingComboBox::currentItem (void) const  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1012  {      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1013          return m_iCurrentItem;      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1014        comboBox->setCurrentIndex(item.selection);
1015  }  }
1016    
1017  // Virtual implemetations.  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1018  QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1019  {      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;  
1020  }  }
1021    
1022  void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )  void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1023            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1024  {  {
1025          if (pWidget->inherits("QComboBox")) {      editor->setGeometry(option.rect);
                 QComboBox *pComboBox = (QComboBox *) pWidget;  
                 m_iCurrentItem = pComboBox->currentItem();  
                 QTableItem::setText(pComboBox->currentText());  
         }  
         else QTableItem::setContentFromEditor(pWidget);  
1026  }  }
1027    
   
1028  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.1366  
changed lines
  Added in v.1490

  ViewVC Help
Powered by ViewVC