/[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 1504 by capela, Wed Nov 21 11:46:40 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 6  Line 28 
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
30    
31  #include <qvalidator.h>  #include <QValidator>
32  #include <qmessagebox.h>  #include <QMessageBox>
33  #include <qfiledialog.h>  #include <QFileDialog>
34  #include <qfileinfo.h>  #include <QFileInfo>
35    
36    #include <QHeaderView>
37    
38    
39  namespace QSampler {  namespace QSampler {
40    
# Line 22  ChannelForm::ChannelForm(QWidget* parent Line 47  ChannelForm::ChannelForm(QWidget* parent
47          m_iDirtySetup = 0;          m_iDirtySetup = 0;
48          m_iDirtyCount = 0;          m_iDirtyCount = 0;
49    
50          m_midiDevices.setAutoDelete(true);  //      m_midiDevices.setAutoDelete(true);
51          m_audioDevices.setAutoDelete(true);  //      m_audioDevices.setAutoDelete(true);
52    
53          m_pDeviceForm = NULL;          m_pDeviceForm = NULL;
54    
55          // Try to restore normal window positioning.          // Try to restore normal window positioning.
56          adjustSize();          adjustSize();
57    
58            ui.AudioRoutingTable->setModel(&routingModel);
59            ui.AudioRoutingTable->setItemDelegate(&routingDelegate);
60            ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
61    
62            QObject::connect(ui.EngineNameComboBox,
63                    SIGNAL(activated(int)),
64                    SLOT(optionsChanged()));
65            QObject::connect(ui.InstrumentFileComboBox,
66                    SIGNAL(activated(const QString&)),
67                    SLOT(updateInstrumentName()));
68            QObject::connect(ui.InstrumentFileToolButton,
69                    SIGNAL(clicked()),
70                    SLOT(openInstrumentFile()));
71            QObject::connect(ui.InstrumentNrComboBox,
72                    SIGNAL(activated(int)),
73                    SLOT(optionsChanged()));
74            QObject::connect(ui.MidiDriverComboBox,
75                    SIGNAL(activated(const QString&)),
76                    SLOT(selectMidiDriver(const QString&)));
77            QObject::connect(ui.MidiDeviceComboBox,
78                    SIGNAL(activated(int)),
79                    SLOT(selectMidiDevice(int)));
80            QObject::connect(ui.MidiPortSpinBox,
81                    SIGNAL(valueChanged(int)),
82                    SLOT(optionsChanged()));
83            QObject::connect(ui.MidiChannelComboBox,
84                    SIGNAL(activated(int)),
85                    SLOT(optionsChanged()));
86            QObject::connect(ui.MidiMapComboBox,
87                    SIGNAL(activated(int)),
88                    SLOT(optionsChanged()));
89            QObject::connect(ui.AudioDriverComboBox,
90                    SIGNAL(activated(const QString&)),
91                    SLOT(selectAudioDriver(const QString&)));
92            QObject::connect(ui.AudioDeviceComboBox,
93                    SIGNAL(activated(int)),
94                    SLOT(selectAudioDevice(int)));
95            QObject::connect(ui.OkPushButton,
96                    SIGNAL(clicked()),
97                    SLOT(accept()));
98            QObject::connect(ui.CancelPushButton,
99                    SIGNAL(clicked()),
100                    SLOT(reject()));
101            QObject::connect(ui.MidiDeviceToolButton,
102                    SIGNAL(clicked()),
103                    SLOT(setupMidiDevice()));
104            QObject::connect(ui.AudioDeviceToolButton,
105                    SIGNAL(clicked()),
106                    SLOT(setupAudioDevice()));
107            QObject::connect(&routingModel,
108                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
109                    SLOT(optionsChanged()));
110            QObject::connect(&routingModel,
111                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
112                    SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));
113            QObject::connect(&routingModel,
114                    SIGNAL(modelReset()),
115                    SLOT(updateTableCellRenderers()));
116  }  }
117    
118  ChannelForm::~ChannelForm() {  ChannelForm::~ChannelForm()
119    {
120          if (m_pDeviceForm)          if (m_pDeviceForm)
121                  delete m_pDeviceForm;                  delete m_pDeviceForm;
122          m_pDeviceForm = NULL;          m_pDeviceForm = NULL;
123    
124            qDeleteAll(m_midiDevices);
125            m_midiDevices.clear();
126    
127            qDeleteAll(m_audioDevices);
128            m_audioDevices.clear();
129  }  }
130    
131    
# Line 51  void ChannelForm::setup ( qsamplerChanne Line 142  void ChannelForm::setup ( qsamplerChanne
142    
143          // It can be a brand new channel, remember?          // It can be a brand new channel, remember?
144          bool bNew = (m_pChannel->channelID() < 0);          bool bNew = (m_pChannel->channelID() < 0);
145          setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName());          setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName());
146    
147          // Check if we're up and connected.          // Check if we're up and connected.
148          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 70  void ChannelForm::setup ( qsamplerChanne Line 161  void ChannelForm::setup ( qsamplerChanne
161          // Load combo box history...          // Load combo box history...
162          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);
163    
         // Notify.that we've just changed one audio route.  
         QObject::connect(ui.AudioRoutingTable, SIGNAL(valueChanged(int,int)),  
                 this, SLOT(changeAudioRouting(int,int)));  
   
164          // Populate Engines list.          // Populate Engines list.
165          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
166          if (ppszEngines) {          if (ppszEngines) {
167                  ui.EngineNameComboBox->clear();                  ui.EngineNameComboBox->clear();
168                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
169                          ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]);                          ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));
170          }          }
171          else m_pChannel->appendMessagesClient("lscp_list_available_engines");          else m_pChannel->appendMessagesClient("lscp_list_available_engines");
172    
173          // Populate Audio output type list.          // Populate Audio output type list.
174          ui.AudioDriverComboBox->clear();          ui.AudioDriverComboBox->clear();
175          ui.AudioDriverComboBox->insertStringList(          ui.AudioDriverComboBox->insertItems(0,
176                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio));                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio));
177    
178          // Populate MIDI input type list.          // Populate MIDI input type list.
179          ui.MidiDriverComboBox->clear();          ui.MidiDriverComboBox->clear();
180          ui.MidiDriverComboBox->insertStringList(          ui.MidiDriverComboBox->insertItems(0,
181                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi));                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi));
182    
183          // Populate Maps list.          // Populate Maps list.
184          ui.MidiMapComboBox->clear();          ui.MidiMapComboBox->clear();
185          ui.MidiMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          ui.MidiMapComboBox->insertItems(0,
186                    qsamplerInstrument::getMapNames());
187    
188          // Read proper channel information,          // Read proper channel information,
189          // and populate the channel form fields.          // and populate the channel form fields.
# Line 107  void ChannelForm::setup ( qsamplerChanne Line 195  void ChannelForm::setup ( qsamplerChanne
195          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
196                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = qsamplerChannel::noEngineName();
197          if (ui.EngineNameComboBox->findText(sEngineName,          if (ui.EngineNameComboBox->findText(sEngineName,
198                          Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
199                  ui.EngineNameComboBox->insertItem(sEngineName);                  ui.EngineNameComboBox->addItem(sEngineName);
200          }          }
201          ui.EngineNameComboBox->setCurrentText(sEngineName);          ui.EngineNameComboBox->setCurrentIndex(
202                    ui.EngineNameComboBox->findText(sEngineName,
203                            Qt::MatchExactly | Qt::MatchCaseSensitive));
204    
205          // Instrument filename and index...          // Instrument filename and index...
206          QString sInstrumentFile = pChannel->instrumentFile();          QString sInstrumentFile = pChannel->instrumentFile();
207          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
208                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = qsamplerChannel::noInstrumentName();
209          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          ui.InstrumentFileComboBox->setItemText(
210                    ui.InstrumentFileComboBox->currentIndex(),
211                    sInstrumentFile);
212          ui.InstrumentNrComboBox->clear();          ui.InstrumentNrComboBox->clear();
213          ui.InstrumentNrComboBox->insertStringList(          ui.InstrumentNrComboBox->insertItems(0,
214                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  qsamplerChannel::getInstrumentList(sInstrumentFile,
215                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
216          ui.InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());          ui.InstrumentNrComboBox->setCurrentIndex(pChannel->instrumentNr());
217    
218          // MIDI input device...          // MIDI input device...
219          qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());          qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());
220          // MIDI input driver...          // MIDI input driver...
221          QString sMidiDriver = midiDevice.driverName();          QString sMidiDriver = midiDevice.driverName();
222          if (sMidiDriver.isEmpty() || bNew)          if (sMidiDriver.isEmpty() || bNew)
223                  sMidiDriver = pOptions->sMidiDriver.upper();                  sMidiDriver = pOptions->sMidiDriver.toUpper();
224          if (!sMidiDriver.isEmpty()) {          if (!sMidiDriver.isEmpty()) {
225                  if (ui.MidiDriverComboBox->findText(sMidiDriver,                  if (ui.MidiDriverComboBox->findText(sMidiDriver,
226                                  Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
227                          ui.MidiDriverComboBox->insertItem(sMidiDriver);                          ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
228                  }                  }
229                  ui.MidiDriverComboBox->setCurrentText(sMidiDriver);                  ui.MidiDriverComboBox->setItemText(
230                            ui.MidiDriverComboBox->currentIndex(),
231                            sMidiDriver);
232          }          }
233          selectMidiDriverItem(sMidiDriver);          selectMidiDriverItem(sMidiDriver);
234          if (!bNew)          if (!bNew) {
235                  ui.MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());                  ui.MidiDeviceComboBox->setItemText(
236          selectMidiDeviceItem(ui.MidiDeviceComboBox->currentItem());                          ui.MidiDeviceComboBox->currentIndex(),
237                            midiDevice.deviceName());
238            }
239            selectMidiDeviceItem(ui.MidiDeviceComboBox->currentIndex());
240          // MIDI input port...          // MIDI input port...
241          ui.MidiPortSpinBox->setValue(pChannel->midiPort());          ui.MidiPortSpinBox->setValue(pChannel->midiPort());
242          // MIDI input channel...          // MIDI input channel...
# Line 146  void ChannelForm::setup ( qsamplerChanne Line 244  void ChannelForm::setup ( qsamplerChanne
244          // When new, try to suggest a sensible MIDI channel...          // When new, try to suggest a sensible MIDI channel...
245          if (iMidiChannel < 0)          if (iMidiChannel < 0)
246                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);
247          ui.MidiChannelComboBox->setCurrentItem(iMidiChannel);          ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
248          // MIDI instrument map...          // MIDI instrument map...
249          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());
250          // When new, try to suggest a sensible MIDI map...          // When new, try to suggest a sensible MIDI map...
251          if (iMidiMap < 0)          if (iMidiMap < 0)
252                  iMidiMap = 0;                  iMidiMap = 0;
253          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);
254          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
255                  ui.MidiMapComboBox->setCurrentText(sMapName);                  ui.MidiMapComboBox->setItemText(
256                            ui.MidiMapComboBox->currentIndex(),
257                            sMapName);
258            }
259          // It might be no maps around...          // It might be no maps around...
260          bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0);          bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0);
261          ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);          ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
# Line 165  void ChannelForm::setup ( qsamplerChanne Line 266  void ChannelForm::setup ( qsamplerChanne
266          // Audio output driver...          // Audio output driver...
267          QString sAudioDriver = audioDevice.driverName();          QString sAudioDriver = audioDevice.driverName();
268          if (sAudioDriver.isEmpty() || bNew)          if (sAudioDriver.isEmpty() || bNew)
269                  sAudioDriver = pOptions->sAudioDriver.upper();                  sAudioDriver = pOptions->sAudioDriver.toUpper();
270          if (!sAudioDriver.isEmpty()) {          if (!sAudioDriver.isEmpty()) {
271                  if (ui.AudioDriverComboBox->findText(sAudioDriver,                  if (ui.AudioDriverComboBox->findText(sAudioDriver,
272                                  Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
273                          ui.AudioDriverComboBox->insertItem(sAudioDriver);                          ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
274                  }                  }
275                  ui.AudioDriverComboBox->setCurrentText(sAudioDriver);                  ui.AudioDriverComboBox->setItemText(
276                            ui.AudioDriverComboBox->currentIndex(),
277                            sAudioDriver);
278          }          }
279          selectAudioDriverItem(sAudioDriver);          selectAudioDriverItem(sAudioDriver);
280          if (!bNew)          if (!bNew) {
281                  ui.AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());                  ui.AudioDeviceComboBox->setItemText(
282          selectAudioDeviceItem(ui.AudioDeviceComboBox->currentItem());                          ui.AudioDeviceComboBox->currentIndex(),
283                            audioDevice.deviceName());
284            }
285            selectAudioDeviceItem(ui.AudioDeviceComboBox->currentIndex());
286    
287          // As convenient, make it ready on stabilizeForm() for          // As convenient, make it ready on stabilizeForm() for
288          // prompt acceptance, if we got the minimum required...          // prompt acceptance, if we got the minimum required...
# Line 219  void ChannelForm::accept (void) Line 325  void ChannelForm::accept (void)
325                          if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText()))                          if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText()))
326                                  iErrors++;                                  iErrors++;
327                  } else {                  } else {
328                          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());                          qsamplerDevice *pDevice = NULL;
329                            int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
330                            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
331                                    pDevice = m_audioDevices.at(iAudioItem);
332                            qsamplerChannelRoutingMap routingMap = routingModel.routingMap();
333                          if (pDevice == NULL)                          if (pDevice == NULL)
334                                  iErrors++;                                  iErrors++;
335                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
336                                  iErrors++;                                  iErrors++;
337                          else if (!m_audioRouting.isEmpty()) {                          else if (!routingMap.isEmpty()) {
338                                  // Set the audio route changes...                                  // Set the audio route changes...
339                                  qsamplerChannelRoutingMap::ConstIterator iter;                                  qsamplerChannelRoutingMap::ConstIterator iter;
340                                  for (iter = m_audioRouting.begin();                                  for (iter = routingMap.begin();
341                                                  iter != m_audioRouting.end(); ++iter) {                                                  iter != routingMap.end(); ++iter) {
342                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
343                                                  iErrors++;                                                  iErrors++;
344                                  }                                  }
345                          }                          }
# Line 239  void ChannelForm::accept (void) Line 349  void ChannelForm::accept (void)
349                          if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText()))                          if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText()))
350                                  iErrors++;                                  iErrors++;
351                  } else {                  } else {
352                          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());                          qsamplerDevice *pDevice = NULL;
353                            int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
354                            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
355                                    pDevice = m_midiDevices.at(iMidiItem);
356                          if (pDevice == NULL)                          if (pDevice == NULL)
357                                  iErrors++;                                  iErrors++;
358                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
# Line 249  void ChannelForm::accept (void) Line 362  void ChannelForm::accept (void)
362                  if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value()))                  if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value()))
363                          iErrors++;                          iErrors++;
364                  // MIDI input channel...                  // MIDI input channel...
365                  if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentItem()))                  if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentIndex()))
366                          iErrors++;                          iErrors++;
367                  // Engine name...                  // Engine name...
368                  if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText()))                  if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText()))
# Line 257  void ChannelForm::accept (void) Line 370  void ChannelForm::accept (void)
370                  // Instrument file and index...                  // Instrument file and index...
371                  const QString& sPath = ui.InstrumentFileComboBox->currentText();                  const QString& sPath = ui.InstrumentFileComboBox->currentText();
372                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
373                          if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentItem()))                          if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentIndex()))
374                                  iErrors++;                                  iErrors++;
375                  }                  }
376                  // MIDI intrument map...                  // MIDI intrument map...
377                  if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentItem()))                  if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentIndex()))
378                          iErrors++;                          iErrors++;
379                  // Show error messages?                  // Show error messages?
380                  if (iErrors > 0)                  if (iErrors > 0)
# Line 269  void ChannelForm::accept (void) Line 382  void ChannelForm::accept (void)
382          }          }
383    
384          // Save default engine name, instrument directory and history...          // Save default engine name, instrument directory and history...
385          pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true);          pOptions->sInstrumentDir = QFileInfo(
386                    ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
387          pOptions->sEngineName  = ui.EngineNameComboBox->currentText();          pOptions->sEngineName  = ui.EngineNameComboBox->currentText();
388          pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText();          pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText();
389          pOptions->sMidiDriver  = ui.MidiDriverComboBox->currentText();          pOptions->sMidiDriver  = ui.MidiDriverComboBox->currentText();
390          pOptions->iMidiMap     = ui.MidiMapComboBox->currentItem();          pOptions->iMidiMap     = ui.MidiMapComboBox->currentIndex();
391          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);
392    
393          // Just go with dialog acceptance.          // Just go with dialog acceptance.
# Line 324  void ChannelForm::openInstrumentFile (vo Line 438  void ChannelForm::openInstrumentFile (vo
438    
439          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
440          // depending on the current engine.          // depending on the current engine.
441          QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
442                  pOptions->sInstrumentDir,                   // Start here.                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
443                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  pOptions->sInstrumentDir,                 // Start here.
444                  this, 0,                                    // Parent and name (none)                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
                 QSAMPLER_TITLE ": " + tr("Instrument files")    // Caption.  
445          );          );
446    
447          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
448                  return;                  return;
449    
450          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          ui.InstrumentFileComboBox->setItemText(
451                    ui.InstrumentFileComboBox->currentIndex(),
452                    sInstrumentFile);
453    
454          updateInstrumentName();          updateInstrumentName();
455  }  }
456    
# Line 355  void ChannelForm::updateInstrumentName ( Line 471  void ChannelForm::updateInstrumentName (
471          // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
472          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
473          ui.InstrumentNrComboBox->clear();          ui.InstrumentNrComboBox->clear();
474          ui.InstrumentNrComboBox->insertStringList(          ui.InstrumentNrComboBox->insertItems(0,
475                  qsamplerChannel::getInstrumentList(                  qsamplerChannel::getInstrumentList(
476                          ui.InstrumentFileComboBox->currentText(),                          ui.InstrumentFileComboBox->currentText(),
477                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
# Line 370  void ChannelForm::setupDevice ( qsampler Line 486  void ChannelForm::setupDevice ( qsampler
486          qsamplerDevice::qsamplerDeviceType deviceTypeMode,          qsamplerDevice::qsamplerDeviceType deviceTypeMode,
487          const QString& sDriverName )          const QString& sDriverName )
488  {  {
489            if (pDevice == NULL)
490                    return;
491    
492          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
493          if (pMainForm == NULL)          if (pMainForm == NULL)
494                  return;                  return;
# Line 404  void ChannelForm::selectMidiDriverItem ( Line 523  void ChannelForm::selectMidiDriverItem (
523          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
524                  return;                  return;
525    
526          const QString sDriverName = sMidiDriver.upper();          const QString sDriverName = sMidiDriver.toUpper();
527    
528          // Save current device id.          // Save current device id.
529            // Save current device id.
530          int iDeviceID = 0;          int iDeviceID = 0;
531          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());          qsamplerDevice *pDevice = NULL;
532            int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
533            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
534                    pDevice = m_midiDevices.at(iMidiItem);
535          if (pDevice)          if (pDevice)
536                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
537    
538          // Clean maplist.          // Clean maplist.
539          ui.MidiDeviceComboBox->clear();          ui.MidiDeviceComboBox->clear();
540            qDeleteAll(m_midiDevices);
541          m_midiDevices.clear();          m_midiDevices.clear();
542    
543          // Populate with the current ones...          // Populate with the current ones...
544          const QPixmap midiPixmap(":/qsampler/pixmaps/midi2.png");          const QPixmap midiPixmap(":/icons/midi2.png");
545          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
546                  qsamplerDevice::Midi);                  qsamplerDevice::Midi);
547          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
548                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);
549                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
550                          ui.MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());                          ui.MidiDeviceComboBox->insertItem(0, midiPixmap, pDevice->deviceName());
551                          m_midiDevices.append(pDevice);                          m_midiDevices.append(pDevice);
552                  } else {                  } else {
553                          delete pDevice;                          delete pDevice;
# Line 434  void ChannelForm::selectMidiDriverItem ( Line 558  void ChannelForm::selectMidiDriverItem (
558          bool bEnabled = !m_midiDevices.isEmpty();          bool bEnabled = !m_midiDevices.isEmpty();
559          if (bEnabled) {          if (bEnabled) {
560                  // Select the previous current device...                  // Select the previous current device...
561                  int iMidiItem = 0;                  iMidiItem = 0;
562                  for (pDevice = m_midiDevices.first();                  QListIterator<qsamplerDevice *> iter(m_midiDevices);
563                                  pDevice;                  while (iter.hasNext()) {
564                                          pDevice = m_midiDevices.next()) {                          pDevice = iter.next();
565                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
566                                  ui.MidiDeviceComboBox->setCurrentItem(iMidiItem);                                  ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
567                                  selectMidiDeviceItem(iMidiItem);                                  selectMidiDeviceItem(iMidiItem);
568                                  break;                                  break;
569                          }                          }
570                          iMidiItem++;                          iMidiItem++;
571                  }                  }
572          } else {          } else {
573                  ui.MidiDeviceComboBox->insertItem(                  ui.MidiDeviceComboBox->insertItem(0,
574                          tr("(New MIDI %1 device)").arg(sMidiDriver));                          tr("(New MIDI %1 device)").arg(sMidiDriver));
575          }          }
576          ui.MidiDeviceTextLabel->setEnabled(bEnabled);          ui.MidiDeviceTextLabel->setEnabled(bEnabled);
# Line 468  void ChannelForm::selectMidiDriver ( con Line 592  void ChannelForm::selectMidiDriver ( con
592  // Select MIDI device item.  // Select MIDI device item.
593  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
594  {  {
595          qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);          qsamplerDevice *pDevice = NULL;
596            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
597                    pDevice = m_midiDevices.at(iMidiItem);
598          if (pDevice) {          if (pDevice) {
599                  const qsamplerDeviceParamMap& params = pDevice->params();                  const qsamplerDeviceParamMap& params = pDevice->params();
600                  int iPorts = params["PORTS"].value.toInt();                  int iPorts = params["PORTS"].value.toInt();
601                  ui.MidiPortTextLabel->setEnabled(iPorts > 0);                  ui.MidiPortTextLabel->setEnabled(iPorts > 0);
602                  ui.MidiPortSpinBox->setEnabled(iPorts > 0);                  ui.MidiPortSpinBox->setEnabled(iPorts > 0);
603                  if (iPorts > 0)                  if (iPorts > 0)
604                          ui.MidiPortSpinBox->setMaxValue(iPorts - 1);                          ui.MidiPortSpinBox->setMaximum(iPorts - 1);
605          }          }
606  }  }
607    
# Line 494  void ChannelForm::selectMidiDevice ( int Line 620  void ChannelForm::selectMidiDevice ( int
620  // MIDI device options.  // MIDI device options.
621  void ChannelForm::setupMidiDevice (void)  void ChannelForm::setupMidiDevice (void)
622  {  {
623          setupDevice(m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()),          qsamplerDevice *pDevice = NULL;
624            int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
625            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
626                    pDevice = m_midiDevices.at(iMidiItem);
627            setupDevice(pDevice,
628                  qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText());                  qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText());
629  }  }
630    
# Line 508  void ChannelForm::selectAudioDriverItem Line 638  void ChannelForm::selectAudioDriverItem
638          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
639                  return;                  return;
640    
641          const QString sDriverName = sAudioDriver.upper();          const QString sDriverName = sAudioDriver.toUpper();
642    
643          // Save current device id.          // Save current device id.
644          int iDeviceID = 0;          int iDeviceID = 0;
645          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());          qsamplerDevice *pDevice = NULL;
646            int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
647            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
648                    pDevice = m_audioDevices.at(iAudioItem);
649          if (pDevice)          if (pDevice)
650                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
651    
652          // Clean maplist.          // Clean maplist.
653          ui.AudioDeviceComboBox->clear();          ui.AudioDeviceComboBox->clear();
654            qDeleteAll(m_audioDevices);
655          m_audioDevices.clear();          m_audioDevices.clear();
656    
657          // Populate with the current ones...          // Populate with the current ones...
658          const QPixmap audioPixmap(":/qsampler/pixmaps/audio2.png");          const QPixmap audioPixmap(":/icons/audio2.png");
659          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
660                  qsamplerDevice::Audio);                  qsamplerDevice::Audio);
661          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
662                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);
663                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
664                          ui.AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());                          ui.AudioDeviceComboBox->insertItem(0, audioPixmap, pDevice->deviceName());
665                          m_audioDevices.append(pDevice);                          m_audioDevices.append(pDevice);
666                  } else {                  } else {
667                          delete pDevice;                          delete pDevice;
# Line 538  void ChannelForm::selectAudioDriverItem Line 672  void ChannelForm::selectAudioDriverItem
672          bool bEnabled = !m_audioDevices.isEmpty();          bool bEnabled = !m_audioDevices.isEmpty();
673          if (bEnabled) {          if (bEnabled) {
674                  // Select the previous current device...                  // Select the previous current device...
675                  int iAudioItem = 0;                  iAudioItem = 0;
676                  for (pDevice = m_audioDevices.first();                  QListIterator<qsamplerDevice *> iter(m_audioDevices);
677                                  pDevice;                  while (iter.hasNext()) {
678                                          pDevice = m_audioDevices.next()) {                          pDevice = iter.next();
679                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
680                                  ui.AudioDeviceComboBox->setCurrentItem(iAudioItem);                                  ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
681                                  selectAudioDeviceItem(iAudioItem);                                  selectAudioDeviceItem(iAudioItem);
682                                  break;                                  break;
683                          }                          }
684                          iAudioItem++;                          iAudioItem++;
685                  }                  }
686          } else {          } else {
687                  ui.AudioDeviceComboBox->insertItem(                  ui.AudioDeviceComboBox->insertItem(0,
688                          tr("(New Audio %1 device)").arg(sAudioDriver));                          tr("(New Audio %1 device)").arg(sAudioDriver));
689                  //ui.AudioRoutingTable->setNumRows(0);                  //ui.AudioRoutingTable->setNumRows(0);
690          }          }
# Line 574  void ChannelForm::selectAudioDriver ( co Line 708  void ChannelForm::selectAudioDriver ( co
708  // Select Audio device item.  // Select Audio device item.
709  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
710  {  {
711          qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);          qsamplerDevice *pDevice = NULL;
712            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
713                    pDevice = m_audioDevices.at(iAudioItem);
714          if (pDevice) {          if (pDevice) {
715                  // Refresh the audio routing table.                  // Refresh the audio routing table.
716                  routingModel.refresh(pDevice, m_pChannel->audioRouting());                  routingModel.refresh(pDevice, m_pChannel->audioRouting());
717                  // Reset routing change map.                  // Reset routing change map.
718                  m_audioRouting.clear();                  routingModel.clear();
719          }          }
720  }  }
721    
# Line 598  void ChannelForm::selectAudioDevice ( in Line 734  void ChannelForm::selectAudioDevice ( in
734  // Audio device options.  // Audio device options.
735  void ChannelForm::setupAudioDevice (void)  void ChannelForm::setupAudioDevice (void)
736  {  {
737          setupDevice(m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()),          qsamplerDevice *pDevice = NULL;
738            int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
739            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
740                    pDevice = m_audioDevices.at(iAudioItem);
741            setupDevice(pDevice,
742                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());
743  }  }
744    
   
 // 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  
 }  
   
   
745  // UPdate all device lists slot.  // UPdate all device lists slot.
746  void ChannelForm::updateDevices (void)  void ChannelForm::updateDevices (void)
747  {  {
# Line 662  void ChannelForm::stabilizeForm (void) Line 776  void ChannelForm::stabilizeForm (void)
776          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
777  }  }
778    
779    void ChannelForm::updateTableCellRenderers() {
780        const int rows = routingModel.rowCount();
781        const int cols = routingModel.columnCount();
782        updateTableCellRenderers(routingModel.index(0,0),routingModel.index(rows-1,cols-1));
783    }
784    
785    void ChannelForm::updateTableCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
786        for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
787            for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
788                const QModelIndex index = routingModel.index(r,c);
789                ui.AudioRoutingTable->openPersistentEditor(index);
790            }
791        }
792    }
793    
794  } // namespace QSampler  } // namespace QSampler
795    
796    
797    // end of qsamplerChannelForm.cpp

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

  ViewVC Help
Powered by ViewVC