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

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

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

revision 1461 by schoenebeck, Sun Oct 28 23:30:36 2007 UTC revision 1489 by schoenebeck, Mon Nov 19 03:29:57 2007 UTC
# Line 1  Line 1 
1    // qsamplerChannelForm.cpp
2    //
3    /****************************************************************************
4       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
8       modify it under the terms of the GNU General Public License
9       as published by the Free Software Foundation; either version 2
10       of the License, or (at your option) any later version.
11    
12       This program is distributed in the hope that it will be useful,
13       but WITHOUT ANY WARRANTY; without even the implied warranty of
14       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15       GNU General Public License for more details.
16    
17       You should have received a copy of the GNU General Public License along
18       with this program; if not, write to the Free Software Foundation, Inc.,
19       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21    *****************************************************************************/
22    
23  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
24    
25  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
# Line 29  ChannelForm::ChannelForm(QWidget* parent Line 51  ChannelForm::ChannelForm(QWidget* parent
51    
52          // Try to restore normal window positioning.          // Try to restore normal window positioning.
53          adjustSize();          adjustSize();
54    
55            ui.AudioRoutingTable->setModel(&routingModel);
56            ui.AudioRoutingTable->setItemDelegate(&routingDelegate);
57            ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
58    
59            QObject::connect(ui.EngineNameComboBox,
60                    SIGNAL(activated(int)),
61                    SLOT(optionsChanged()));
62            QObject::connect(ui.InstrumentFileComboBox,
63                    SIGNAL(activated(const QString&)),
64                    SLOT(updateInstrumentName()));
65            QObject::connect(ui.InstrumentFileToolButton,
66                    SIGNAL(clicked()),
67                    SLOT(openInstrumentFile()));
68            QObject::connect(ui.InstrumentNrComboBox,
69                    SIGNAL(activated(int)),
70                    SLOT(optionsChanged()));
71            QObject::connect(ui.MidiDriverComboBox,
72                    SIGNAL(activated(const QString&)),
73                    SLOT(selectMidiDriver(const QString&)));
74            QObject::connect(ui.MidiDeviceComboBox,
75                    SIGNAL(activated(int)),
76                    SLOT(selectMidiDevice(int)));
77            QObject::connect(ui.MidiPortSpinBox,
78                    SIGNAL(valueChanged(int)),
79                    SLOT(optionsChanged()));
80            QObject::connect(ui.MidiChannelComboBox,
81                    SIGNAL(activated(int)),
82                    SLOT(optionsChanged()));
83            QObject::connect(ui.MidiMapComboBox,
84                    SIGNAL(activated(int)),
85                    SLOT(optionsChanged()));
86            QObject::connect(ui.AudioDriverComboBox,
87                    SIGNAL(activated(const QString&)),
88                    SLOT(selectAudioDriver(const QString&)));
89            QObject::connect(ui.AudioDeviceComboBox,
90                    SIGNAL(activated(int)),
91                    SLOT(selectAudioDevice(int)));
92            QObject::connect(ui.OkPushButton,
93                    SIGNAL(clicked()),
94                    SLOT(accept()));
95            QObject::connect(ui.CancelPushButton,
96                    SIGNAL(clicked()),
97                    SLOT(reject()));
98            QObject::connect(ui.MidiDeviceToolButton,
99                    SIGNAL(clicked()),
100                    SLOT(setupMidiDevice()));
101            QObject::connect(ui.AudioDeviceToolButton,
102                    SIGNAL(clicked()),
103                    SLOT(setupAudioDevice()));
104            QObject::connect(&routingModel,
105                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
106                    SLOT(optionsChanged()));
107            QObject::connect(&routingModel,
108                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
109                    SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));
110            QObject::connect(&routingModel,
111                    SIGNAL(modelReset()),
112                    SLOT(updateTableCellRenderers()));
113  }  }
114    
115  ChannelForm::~ChannelForm() {  ChannelForm::~ChannelForm() {
# Line 70  void ChannelForm::setup ( qsamplerChanne Line 151  void ChannelForm::setup ( qsamplerChanne
151          // Load combo box history...          // Load combo box history...
152          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);
153    
         // Notify.that we've just changed one audio route.  
         QObject::connect(ui.AudioRoutingTable, SIGNAL(valueChanged(int,int)),  
                 this, SLOT(changeAudioRouting(int,int)));  
   
154          // Populate Engines list.          // Populate Engines list.
155          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
156          if (ppszEngines) {          if (ppszEngines) {
157                  ui.EngineNameComboBox->clear();                  ui.EngineNameComboBox->clear();
158                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
159                          ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]);                          ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));
160          }          }
161          else m_pChannel->appendMessagesClient("lscp_list_available_engines");          else m_pChannel->appendMessagesClient("lscp_list_available_engines");
162    
# Line 107  void ChannelForm::setup ( qsamplerChanne Line 184  void ChannelForm::setup ( qsamplerChanne
184          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
185                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = qsamplerChannel::noEngineName();
186          if (ui.EngineNameComboBox->findText(sEngineName,          if (ui.EngineNameComboBox->findText(sEngineName,
187                          Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
188                  ui.EngineNameComboBox->insertItem(sEngineName);                  ui.EngineNameComboBox->addItem(sEngineName);
189          }          }
190          ui.EngineNameComboBox->setCurrentText(sEngineName);          ui.EngineNameComboBox->setCurrentIndex(
191                    ui.EngineNameComboBox->findText(sEngineName,
192                            Qt::MatchExactly | Qt::MatchCaseSensitive));
193          // Instrument filename and index...          // Instrument filename and index...
194          QString sInstrumentFile = pChannel->instrumentFile();          QString sInstrumentFile = pChannel->instrumentFile();
195          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
# Line 130  void ChannelForm::setup ( qsamplerChanne Line 209  void ChannelForm::setup ( qsamplerChanne
209                  sMidiDriver = pOptions->sMidiDriver.upper();                  sMidiDriver = pOptions->sMidiDriver.upper();
210          if (!sMidiDriver.isEmpty()) {          if (!sMidiDriver.isEmpty()) {
211                  if (ui.MidiDriverComboBox->findText(sMidiDriver,                  if (ui.MidiDriverComboBox->findText(sMidiDriver,
212                                  Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
213                          ui.MidiDriverComboBox->insertItem(sMidiDriver);                          ui.MidiDriverComboBox->insertItem(sMidiDriver);
214                  }                  }
215                  ui.MidiDriverComboBox->setCurrentText(sMidiDriver);                  ui.MidiDriverComboBox->setCurrentText(sMidiDriver);
# Line 168  void ChannelForm::setup ( qsamplerChanne Line 247  void ChannelForm::setup ( qsamplerChanne
247                  sAudioDriver = pOptions->sAudioDriver.upper();                  sAudioDriver = pOptions->sAudioDriver.upper();
248          if (!sAudioDriver.isEmpty()) {          if (!sAudioDriver.isEmpty()) {
249                  if (ui.AudioDriverComboBox->findText(sAudioDriver,                  if (ui.AudioDriverComboBox->findText(sAudioDriver,
250                                  Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
251                          ui.AudioDriverComboBox->insertItem(sAudioDriver);                          ui.AudioDriverComboBox->insertItem(sAudioDriver);
252                  }                  }
253                  ui.AudioDriverComboBox->setCurrentText(sAudioDriver);                  ui.AudioDriverComboBox->setCurrentText(sAudioDriver);
# Line 220  void ChannelForm::accept (void) Line 299  void ChannelForm::accept (void)
299                                  iErrors++;                                  iErrors++;
300                  } else {                  } else {
301                          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());                          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());
302                            qsamplerChannelRoutingMap routingMap = routingModel.routingMap();
303                          if (pDevice == NULL)                          if (pDevice == NULL)
304                                  iErrors++;                                  iErrors++;
305                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
306                                  iErrors++;                                  iErrors++;
307                          else if (!m_audioRouting.isEmpty()) {                          else if (!routingMap.isEmpty()) {
308                                  // Set the audio route changes...                                  // Set the audio route changes...
309                                  qsamplerChannelRoutingMap::ConstIterator iter;                                  qsamplerChannelRoutingMap::ConstIterator iter;
310                                  for (iter = m_audioRouting.begin();                                  for (iter = routingMap.begin();
311                                                  iter != m_audioRouting.end(); ++iter) {                                                  iter != routingMap.end(); ++iter) {
312                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))
313                                                  iErrors++;                                                  iErrors++;
314                                  }                                  }
# Line 417  void ChannelForm::selectMidiDriverItem ( Line 497  void ChannelForm::selectMidiDriverItem (
497          m_midiDevices.clear();          m_midiDevices.clear();
498    
499          // Populate with the current ones...          // Populate with the current ones...
500          const QPixmap midiPixmap(":/qsampler/pixmaps/midi2.png");          const QPixmap midiPixmap(":/icons/midi2.png");
501          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
502                  qsamplerDevice::Midi);                  qsamplerDevice::Midi);
503          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
# Line 521  void ChannelForm::selectAudioDriverItem Line 601  void ChannelForm::selectAudioDriverItem
601          m_audioDevices.clear();          m_audioDevices.clear();
602    
603          // Populate with the current ones...          // Populate with the current ones...
604          const QPixmap audioPixmap(":/qsampler/pixmaps/audio2.png");          const QPixmap audioPixmap(":/icons/audio2.png");
605          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
606                  qsamplerDevice::Audio);                  qsamplerDevice::Audio);
607          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
# Line 579  void ChannelForm::selectAudioDeviceItem Line 659  void ChannelForm::selectAudioDeviceItem
659                  // Refresh the audio routing table.                  // Refresh the audio routing table.
660                  routingModel.refresh(pDevice, m_pChannel->audioRouting());                  routingModel.refresh(pDevice, m_pChannel->audioRouting());
661                  // Reset routing change map.                  // Reset routing change map.
662                  m_audioRouting.clear();                  routingModel.clear();
663          }          }
664  }  }
665    
# Line 602  void ChannelForm::setupAudioDevice (void Line 682  void ChannelForm::setupAudioDevice (void
682                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());
683  }  }
684    
   
 // Audio routing change slot.  
 void ChannelForm::changeAudioRouting ( int iRow, int iCol )  
 {  
 #if 0  
         if (m_iDirtySetup > 0)  
                 return;  
         if (iRow < 0 || iCol < 0)  
                 return;  
   
         // Verify that this is a QComboTableItem (magic rtti == 1)  
         QTableItem *pItem = ui.AudioRoutingTable->item(iRow, iCol);  
         if (pItem == NULL)  
                 return;  
         qsamplerChannelRoutingComboBox *pComboItem =  
                 static_cast<qsamplerChannelRoutingComboBox*> (pItem);  
         // FIXME: Its not garanteed that we must have  
         // iAudioOut == iRow on all times forth!  
         m_audioRouting[iRow] = pComboItem->currentItem();  
   
         // And let's get dirty...  
         optionsChanged();  
 #endif  
 }  
   
   
685  // UPdate all device lists slot.  // UPdate all device lists slot.
686  void ChannelForm::updateDevices (void)  void ChannelForm::updateDevices (void)
687  {  {
# Line 662  void ChannelForm::stabilizeForm (void) Line 716  void ChannelForm::stabilizeForm (void)
716          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
717  }  }
718    
719    void ChannelForm::updateTableCellRenderers() {
720        const int rows = routingModel.rowCount();
721        const int cols = routingModel.columnCount();
722        updateTableCellRenderers(routingModel.index(0,0),routingModel.index(rows-1,cols-1));
723    }
724    
725    void ChannelForm::updateTableCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
726        for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
727            for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
728                const QModelIndex index = routingModel.index(r,c);
729                ui.AudioRoutingTable->openPersistentEditor(index);
730            }
731        }
732    }
733    
734  } // namespace QSampler  } // namespace QSampler
735    
736    
737    // end of qsamplerChannelForm.cpp

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

  ViewVC Help
Powered by ViewVC