/[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 1527 by schoenebeck, Mon Nov 26 16:00:21 2007 UTC revision 3559 by capela, Thu Aug 22 18:58:38 2019 UTC
# Line 1  Line 1 
1  // qsamplerChannelForm.cpp  // qsamplerChannelForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008 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 38  Line 38 
38    
39  namespace QSampler {  namespace QSampler {
40    
41    //-------------------------------------------------------------------------
42    // QSampler::Channelform -- Channel form implementation.
43    //
44    
45  ChannelForm::ChannelForm ( QWidget* pParent )  ChannelForm::ChannelForm ( QWidget* pParent )
46          : QDialog(pParent)          : QDialog(pParent)
47  {  {
48          m_ui.setupUi(this);          m_ui.setupUi(this);
49    
50          // Initialize locals.          // Initialize locals.
51          m_pChannel = NULL;          m_pChannel = nullptr;
52    
53          m_iDirtySetup = 0;          m_iDirtySetup = 0;
54          m_iDirtyCount = 0;          m_iDirtyCount = 0;
# Line 52  ChannelForm::ChannelForm ( QWidget* pPar Line 56  ChannelForm::ChannelForm ( QWidget* pPar
56  //      m_midiDevices.setAutoDelete(true);  //      m_midiDevices.setAutoDelete(true);
57  //      m_audioDevices.setAutoDelete(true);  //      m_audioDevices.setAutoDelete(true);
58    
59          m_pDeviceForm = NULL;          m_pDeviceForm = nullptr;
60    
61          int iRowHeight = m_ui.AudioRoutingTable->fontMetrics().height() + 4;          const int iRowHeight = m_ui.AudioRoutingTable->fontMetrics().height() + 4;
62          m_ui.AudioRoutingTable->verticalHeader()->setDefaultSectionSize(iRowHeight);          m_ui.AudioRoutingTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
63          m_ui.AudioRoutingTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);          m_ui.AudioRoutingTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
64    
65          m_ui.AudioRoutingTable->setModel(&m_routingModel);          m_ui.AudioRoutingTable->setModel(&m_routingModel);
66          m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate);          m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate);
67    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
68            m_ui.AudioRoutingTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
69    #else
70          m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);          m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
71    #endif
72  //      m_ui.AudioRoutingTable->verticalHeader()->hide();  //      m_ui.AudioRoutingTable->verticalHeader()->hide();
73    
74          // This goes initially hidden, and will be shown          // This goes initially hidden, and will be shown
# Line 74  ChannelForm::ChannelForm ( QWidget* pPar Line 82  ChannelForm::ChannelForm ( QWidget* pPar
82                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
83                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
84          QObject::connect(m_ui.InstrumentFileComboBox,          QObject::connect(m_ui.InstrumentFileComboBox,
85                    SIGNAL(editTextChanged(const QString&)),
86                    SLOT(updateInstrumentName()));
87            QObject::connect(m_ui.InstrumentFileComboBox,
88                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
89                  SLOT(updateInstrumentName()));                  SLOT(updateInstrumentName()));
90          QObject::connect(m_ui.InstrumentFileToolButton,          QObject::connect(m_ui.InstrumentFileToolButton,
# Line 103  ChannelForm::ChannelForm ( QWidget* pPar Line 114  ChannelForm::ChannelForm ( QWidget* pPar
114          QObject::connect(m_ui.AudioDeviceComboBox,          QObject::connect(m_ui.AudioDeviceComboBox,
115                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
116                  SLOT(selectAudioDevice(int)));                  SLOT(selectAudioDevice(int)));
117          QObject::connect(m_ui.OkPushButton,          QObject::connect(m_ui.DialogButtonBox,
118                  SIGNAL(clicked()),                  SIGNAL(accepted()),
119                  SLOT(accept()));                  SLOT(accept()));
120          QObject::connect(m_ui.CancelPushButton,          QObject::connect(m_ui.DialogButtonBox,
121                  SIGNAL(clicked()),                  SIGNAL(rejected()),
122                  SLOT(reject()));                  SLOT(reject()));
123          QObject::connect(m_ui.MidiDeviceToolButton,          QObject::connect(m_ui.MidiDeviceToolButton,
124                  SIGNAL(clicked()),                  SIGNAL(clicked()),
# Line 115  ChannelForm::ChannelForm ( QWidget* pPar Line 126  ChannelForm::ChannelForm ( QWidget* pPar
126          QObject::connect(m_ui.AudioDeviceToolButton,          QObject::connect(m_ui.AudioDeviceToolButton,
127                  SIGNAL(clicked()),                  SIGNAL(clicked()),
128                  SLOT(setupAudioDevice()));                  SLOT(setupAudioDevice()));
129    
130          QObject::connect(&m_routingModel,          QObject::connect(&m_routingModel,
131                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
132                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
# Line 130  ChannelForm::~ChannelForm() Line 142  ChannelForm::~ChannelForm()
142  {  {
143          if (m_pDeviceForm)          if (m_pDeviceForm)
144                  delete m_pDeviceForm;                  delete m_pDeviceForm;
145          m_pDeviceForm = NULL;          m_pDeviceForm = nullptr;
146    
147          qDeleteAll(m_midiDevices);          qDeleteAll(m_midiDevices);
148          m_midiDevices.clear();          m_midiDevices.clear();
# Line 141  ChannelForm::~ChannelForm() Line 153  ChannelForm::~ChannelForm()
153    
154    
155  // Channel dialog setup formal initializer.  // Channel dialog setup formal initializer.
156  void ChannelForm::setup ( qsamplerChannel *pChannel )  void ChannelForm::setup ( Channel *pChannel )
157  {  {
158          m_pChannel = pChannel;          m_pChannel = pChannel;
159    
160          m_iDirtySetup = 0;          m_iDirtySetup = 0;
161          m_iDirtyCount = 0;          m_iDirtyCount = 0;
162    
163          if (m_pChannel == NULL)          if (m_pChannel == nullptr)
164                  return;                  return;
165    
166          // It can be a brand new channel, remember?          // It can be a brand new channel, remember?
167          bool bNew = (m_pChannel->channelID() < 0);          const bool bNew = (m_pChannel->channelID() < 0);
168          setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName());          setWindowTitle(m_pChannel->channelName());
169    
170          // Check if we're up and connected.          // Check if we're up and connected.
171          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
172          if (pMainForm == NULL)          if (pMainForm == nullptr)
173                  return;                  return;
174          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
175                  return;                  return;
176    
177          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
178          if (pOptions == NULL)          if (pOptions == nullptr)
179                  return;                  return;
180    
181          // Avoid nested changes.          // Avoid nested changes.
# Line 171  void ChannelForm::setup ( qsamplerChanne Line 183  void ChannelForm::setup ( qsamplerChanne
183    
184          // Load combo box history...          // Load combo box history...
185          pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);
186            // Remove non-existant instrument file-paths...
187            int i = m_ui.InstrumentFileComboBox->count() - 1;
188            while (i >= 0) {
189                    const QString& sInstrumentFile
190                            = m_ui.InstrumentFileComboBox->itemText(i);
191                    if (sInstrumentFile.isEmpty()
192                            || !QFileInfo(sInstrumentFile).exists())
193                            m_ui.InstrumentFileComboBox->removeItem(i);
194                    --i;
195            }
196    
197          // Populate Engines list.          // Populate Engines list.
198          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
# Line 184  void ChannelForm::setup ( qsamplerChanne Line 206  void ChannelForm::setup ( qsamplerChanne
206          // Populate Audio output type list.          // Populate Audio output type list.
207          m_ui.AudioDriverComboBox->clear();          m_ui.AudioDriverComboBox->clear();
208          m_ui.AudioDriverComboBox->insertItems(0,          m_ui.AudioDriverComboBox->insertItems(0,
209                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio));                  Device::getDrivers(pMainForm->client(), Device::Audio));
210    
211          // Populate MIDI input type list.          // Populate MIDI input type list.
212          m_ui.MidiDriverComboBox->clear();          m_ui.MidiDriverComboBox->clear();
213          m_ui.MidiDriverComboBox->insertItems(0,          m_ui.MidiDriverComboBox->insertItems(0,
214                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi));                  Device::getDrivers(pMainForm->client(), Device::Midi));
215    
216          // Populate Maps list.          // Populate Maps list.
217          m_ui.MidiMapComboBox->clear();          m_ui.MidiMapComboBox->clear();
218          m_ui.MidiMapComboBox->insertItems(0,          m_ui.MidiMapComboBox->insertItems(0,
219                  qsamplerInstrument::getMapNames());                  Instrument::getMapNames());
220    
221          // Read proper channel information,          // Read proper channel information,
222          // and populate the channel form fields.          // and populate the channel form fields.
# Line 204  void ChannelForm::setup ( qsamplerChanne Line 226  void ChannelForm::setup ( qsamplerChanne
226          if (sEngineName.isEmpty() || bNew)          if (sEngineName.isEmpty() || bNew)
227                  sEngineName = pOptions->sEngineName;                  sEngineName = pOptions->sEngineName;
228          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
229                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = Channel::noEngineName();
230          if (m_ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
231                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
232                  m_ui.EngineNameComboBox->addItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
# Line 216  void ChannelForm::setup ( qsamplerChanne Line 238  void ChannelForm::setup ( qsamplerChanne
238          // Instrument filename and index...          // Instrument filename and index...
239          QString sInstrumentFile = pChannel->instrumentFile();          QString sInstrumentFile = pChannel->instrumentFile();
240          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
241                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = Channel::noInstrumentName();
242          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
243          m_ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
244          m_ui.InstrumentNrComboBox->insertItems(0,          m_ui.InstrumentNrComboBox->insertItems(0,
245                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  Channel::getInstrumentList(sInstrumentFile,
246                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
247          int iInstrumentNr = pChannel->instrumentNr();          int iInstrumentNr = pChannel->instrumentNr();
248          if (iInstrumentNr < 0)          if (iInstrumentNr < 0)
# Line 228  void ChannelForm::setup ( qsamplerChanne Line 250  void ChannelForm::setup ( qsamplerChanne
250          m_ui.InstrumentNrComboBox->setCurrentIndex(iInstrumentNr);          m_ui.InstrumentNrComboBox->setCurrentIndex(iInstrumentNr);
251    
252          // MIDI input device...          // MIDI input device...
253          qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());          const Device midiDevice(Device::Midi, m_pChannel->midiDevice());
254          // MIDI input driver...          // MIDI input driver...
255          QString sMidiDriver = midiDevice.driverName();          QString sMidiDriver = midiDevice.driverName();
256          if (sMidiDriver.isEmpty() || bNew)          if (sMidiDriver.isEmpty() || bNew)
# Line 238  void ChannelForm::setup ( qsamplerChanne Line 260  void ChannelForm::setup ( qsamplerChanne
260                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
261                          m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver);                          m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
262                  }                  }
263                  m_ui.MidiDriverComboBox->setItemText(                  m_ui.MidiDriverComboBox->setCurrentIndex(
264                          m_ui.MidiDriverComboBox->currentIndex(),                          m_ui.MidiDriverComboBox->findText(sMidiDriver,
265                          sMidiDriver);                                  Qt::MatchExactly | Qt::MatchCaseSensitive)
266                    );
267          }          }
268          selectMidiDriverItem(sMidiDriver);          selectMidiDriverItem(sMidiDriver);
269          if (!bNew) {          if (!bNew) {
270                  m_ui.MidiDeviceComboBox->setItemText(                  m_ui.MidiDeviceComboBox->setCurrentIndex(
271                          m_ui.MidiDeviceComboBox->currentIndex(),                          m_ui.MidiDeviceComboBox->findData(midiDevice.deviceID()));
                         midiDevice.deviceName());  
272          }          }
273          selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());          selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());
274          // MIDI input port...          // MIDI input port...
# Line 262  void ChannelForm::setup ( qsamplerChanne Line 284  void ChannelForm::setup ( qsamplerChanne
284          // When new, try to suggest a sensible MIDI map...          // When new, try to suggest a sensible MIDI map...
285          if (iMidiMap < 0)          if (iMidiMap < 0)
286                  iMidiMap = 0;                  iMidiMap = 0;
287          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);          const QString& sMapName = Instrument::getMapName(iMidiMap);
288          if (!sMapName.isEmpty()) {          if (!sMapName.isEmpty()) {
289                  m_ui.MidiMapComboBox->setItemText(                  m_ui.MidiMapComboBox->setItemText(
290                          m_ui.MidiMapComboBox->currentIndex(),                          m_ui.MidiMapComboBox->currentIndex(),
291                          sMapName);                          sMapName);
292          }          }
293          // It might be no maps around...          // It might be no maps around...
294          bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);          const bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);
295          m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);          m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
296          m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);          m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
297    
298          // Audio output device...          // Audio output device...
299          qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice());          const Device audioDevice(Device::Audio, m_pChannel->audioDevice());
300          // Audio output driver...          // Audio output driver...
301          QString sAudioDriver = audioDevice.driverName();          QString sAudioDriver = audioDevice.driverName();
302          if (sAudioDriver.isEmpty() || bNew)          if (sAudioDriver.isEmpty() || bNew)
# Line 284  void ChannelForm::setup ( qsamplerChanne Line 306  void ChannelForm::setup ( qsamplerChanne
306                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
307                          m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);                          m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
308                  }                  }
309                  m_ui.AudioDriverComboBox->setItemText(                  m_ui.AudioDriverComboBox->setCurrentIndex(
310                          m_ui.AudioDriverComboBox->currentIndex(),                          m_ui.AudioDriverComboBox->findText(sAudioDriver,
311                          sAudioDriver);                                  Qt::MatchExactly | Qt::MatchCaseSensitive)
312                    );
313          }          }
314          selectAudioDriverItem(sAudioDriver);          selectAudioDriverItem(sAudioDriver);
315          if (!bNew) {          if (!bNew) {
316                  m_ui.AudioDeviceComboBox->setItemText(                  m_ui.AudioDeviceComboBox->setCurrentIndex(
317                          m_ui.AudioDeviceComboBox->currentIndex(),                          m_ui.AudioDeviceComboBox->findData(audioDevice.deviceID()));
                         audioDevice.deviceName());  
318          }          }
319          selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());          selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());
320    
# Line 302  void ChannelForm::setup ( qsamplerChanne Line 324  void ChannelForm::setup ( qsamplerChanne
324    
325          const QString sInstrumentNrToolTip =          const QString sInstrumentNrToolTip =
326                  (pOptions->bInstrumentNames) ?                  (pOptions->bInstrumentNames) ?
327                          "Select an instrument of the file" :                          tr("Select an instrument of the file") :
328                          "You might want to enable instrument name retrieval in the "                          tr("You might want to enable instrument name retrieval in the "
329                          "settings dialog";                          "settings dialog");
330          m_ui.InstrumentNrComboBox->setToolTip(          m_ui.InstrumentNrComboBox->setToolTip(
331                  QObject::tr(sInstrumentNrToolTip.toUtf8().data())                  QObject::tr(sInstrumentNrToolTip.toUtf8().data())
332          );          );
333    
334    #if 0
335          // As convenient, make it ready on stabilizeForm() for          // As convenient, make it ready on stabilizeForm() for
336          // prompt acceptance, if we got the minimum required...          // prompt acceptance, if we got the minimum required...
337  /*      if (sEngineName != qsamplerChannel::noEngineName() &&          if (sEngineName != Channel::noEngineName() &&
338                  sInstrumentFile != qsamplerChannel::noInstrumentName())                  sInstrumentFile != Channel::noInstrumentName())
339                  m_iDirtyCount++; */                  m_iDirtyCount++;
340    #endif
341    
342          // Done.          // Done.
343          m_iDirtySetup--;          m_iDirtySetup--;
344          stabilizeForm();          stabilizeForm();
# Line 323  void ChannelForm::setup ( qsamplerChanne Line 348  void ChannelForm::setup ( qsamplerChanne
348  // Accept settings (OK button slot).  // Accept settings (OK button slot).
349  void ChannelForm::accept (void)  void ChannelForm::accept (void)
350  {  {
351          if (m_pChannel == NULL)          if (m_pChannel == nullptr)
352                  return;                  return;
353    
354          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
355          if (pMainForm == NULL)          if (pMainForm == nullptr)
356                  return;                  return;
357          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
358                  return;                  return;
359    
360          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
361          if (pOptions == NULL)          if (pOptions == nullptr)
362                  return;                  return;
363    
364          // Flush any pending editing...          // Flush any pending editing...
# Line 350  void ChannelForm::accept (void) Line 375  void ChannelForm::accept (void)
375                          if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))                          if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))
376                                  iErrors++;                                  iErrors++;
377                  } else {                  } else {
378                          qsamplerDevice *pDevice = NULL;                          Device *pDevice = nullptr;
379                          int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();                          const int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
380                          if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())                          if (iAudioItem >= 0) {
381                                  pDevice = m_audioDevices.at(iAudioItem);                                  const int iAudioDevice
382                          qsamplerChannelRoutingMap routingMap = m_routingModel.routingMap();                                          = m_ui.AudioDeviceComboBox->itemData(iAudioItem).toInt();
383                          if (pDevice == NULL)                                  pDevice = m_audioDevices.value(iAudioDevice, nullptr);
384                            }
385                            ChannelRoutingMap routingMap = m_routingModel.routingMap();
386                            if (pDevice == nullptr)
387                                  iErrors++;                                  iErrors++;
388                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
389                                  iErrors++;                                  iErrors++;
390                          else if (!routingMap.isEmpty()) {                          else if (!routingMap.isEmpty()) {
391                                  // Set the audio route changes...                                  // Set the audio route changes...
392                                  qsamplerChannelRoutingMap::ConstIterator iter;                                  ChannelRoutingMap::ConstIterator iter;
393                                  for (iter = routingMap.begin();                                  for (iter = routingMap.begin();
394                                                  iter != routingMap.end(); ++iter) {                                                  iter != routingMap.end(); ++iter) {
395                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
# Line 374  void ChannelForm::accept (void) Line 402  void ChannelForm::accept (void)
402                          if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))                          if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))
403                                  iErrors++;                                  iErrors++;
404                  } else {                  } else {
405                          qsamplerDevice *pDevice = NULL;                          Device *pDevice = nullptr;
406                          int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();                          const int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
407                          if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())                          if (iMidiItem >= 0) {
408                                  pDevice = m_midiDevices.at(iMidiItem);                                  const int iMidiDevice
409                          if (pDevice == NULL)                                          = m_ui.MidiDeviceComboBox->itemData(iMidiItem).toInt();
410                                    pDevice = m_midiDevices.value(iMidiDevice, nullptr);
411                            }
412                            if (pDevice == nullptr)
413                                  iErrors++;                                  iErrors++;
414                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
415                                  iErrors++;                                  iErrors++;
# Line 428  void ChannelForm::reject (void) Line 459  void ChannelForm::reject (void)
459          bool bReject = true;          bool bReject = true;
460    
461          // Check if there's any pending changes...          // Check if there's any pending changes...
462          if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0) {
463                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
464                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
465                          tr("Some channel settings have been changed.\n\n"                          tr("Some channel settings have been changed.\n\n"
466                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
467                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
468                  case 0:     // Apply...                          QMessageBox::Discard |
469                            QMessageBox::Cancel)) {
470                    case QMessageBox::Apply:
471                          accept();                          accept();
472                          return;                          return;
473                  case 1:     // Discard                  case QMessageBox::Discard:
474                          break;                          break;
475                  default:    // Cancel.                  default:    // Cancel.
476                          bReject = false;                          bReject = false;
# Line 454  void ChannelForm::reject (void) Line 487  void ChannelForm::reject (void)
487  void ChannelForm::openInstrumentFile (void)  void ChannelForm::openInstrumentFile (void)
488  {  {
489          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
490          if (pMainForm == NULL)          if (pMainForm == nullptr)
491                  return;                  return;
492          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
493                  return;                  return;
494    
495          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
496          if (pOptions == NULL)          if (pOptions == nullptr)
497                  return;                  return;
498    
499          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
500          // depending on the current engine.          // depending on the current engine.
501            QStringList filters;
502            const QString& sEngineName = m_ui.EngineNameComboBox->currentText().toUpper();
503            if (sEngineName.contains("GIG"))
504                    filters << tr("GIG Instrument files") + " (*.gig *.dls)";
505            if (sEngineName.contains("SFZ"))
506                    filters << tr("SFZ Instrument files") + " (*.sfz)";
507            if (sEngineName.contains("SF2"))
508                    filters << tr("SF2 Instrument files") + " (*.sf2)";
509            filters << tr("All files") + " (*.*)";
510            const QString& filter = filters.join(";;");
511    
512          QString sInstrumentFile = QFileDialog::getOpenFileName(this,          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
513                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.                  tr("Instrument files"),   // Caption.
514                  pOptions->sInstrumentDir,                 // Start here.                  pOptions->sInstrumentDir, // Start here.
515                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)                  filter                    // File filter.
516          );          );
517    
518          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
# Line 483  void ChannelForm::openInstrumentFile (vo Line 527  void ChannelForm::openInstrumentFile (vo
527  void ChannelForm::updateInstrumentName (void)  void ChannelForm::updateInstrumentName (void)
528  {  {
529          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
530          if (pMainForm == NULL)          if (pMainForm == nullptr)
531                  return;                  return;
532          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
533                  return;                  return;
534    
535          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
536          if (pOptions == NULL)          if (pOptions == nullptr)
537                  return;                  return;
538    
539          // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
540          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
541          m_ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
542          m_ui.InstrumentNrComboBox->insertItems(0,          m_ui.InstrumentNrComboBox->insertItems(0,
543                  qsamplerChannel::getInstrumentList(                  Channel::getInstrumentList(
544                          m_ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
545                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
546          );          );
# Line 506  void ChannelForm::updateInstrumentName ( Line 550  void ChannelForm::updateInstrumentName (
550    
551    
552  // Show device options dialog.  // Show device options dialog.
553  void ChannelForm::setupDevice ( qsamplerDevice *pDevice,  void ChannelForm::setupDevice ( Device *pDevice,
554          qsamplerDevice::DeviceType deviceTypeMode,          Device::DeviceType deviceTypeMode,
555          const QString& sDriverName )          const QString& sDriverName )
556  {  {
557          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
558          if (pMainForm == NULL)          if (pMainForm == nullptr)
559                  return;                  return;
560          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
561                  return;                  return;
562    
563          // Create the device form if not already...          // Create the device form if not already...
564          if (m_pDeviceForm == NULL) {          if (m_pDeviceForm == nullptr) {
565                  m_pDeviceForm = new DeviceForm(this, Qt::Dialog);                  m_pDeviceForm = new DeviceForm(this, Qt::Dialog);
566                  m_pDeviceForm->setAttribute(Qt::WA_ShowModal);                  m_pDeviceForm->setAttribute(Qt::WA_ShowModal);
567                  QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),                  QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
# Line 539  void ChannelForm::setupDevice ( qsampler Line 583  void ChannelForm::setupDevice ( qsampler
583  void ChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )  void ChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
584  {  {
585          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
586          if (pMainForm == NULL)          if (pMainForm == nullptr)
587                  return;                  return;
588          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
589                  return;                  return;
590    
591          const QString sDriverName = sMidiDriver.toUpper();          const QString sDriverName = sMidiDriver.toUpper();
592    
593          // Save current device id.          // Save current device id.
         // Save current device id.  
594          int iDeviceID = 0;          int iDeviceID = 0;
         qsamplerDevice *pDevice = NULL;  
595          int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();          int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
596          if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())          if (iMidiItem >= 0)
597                  pDevice = m_midiDevices.at(iMidiItem);                  iDeviceID = m_ui.MidiDeviceComboBox->itemData(iMidiItem).toInt();
         if (pDevice)  
                 iDeviceID = pDevice->deviceID();  
598    
599          // Clean maplist.          // Clean maplist.
600          m_ui.MidiDeviceComboBox->clear();          m_ui.MidiDeviceComboBox->clear();
# Line 562  void ChannelForm::selectMidiDriverItem ( Line 602  void ChannelForm::selectMidiDriverItem (
602          m_midiDevices.clear();          m_midiDevices.clear();
603    
604          // Populate with the current ones...          // Populate with the current ones...
605          const QPixmap midiPixmap(":/icons/midi2.png");          Device *pDevice = nullptr;
606          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          const QPixmap midiPixmap(":/images/midi2.png");
607                  qsamplerDevice::Midi);          int *piDeviceIDs = Device::getDevices(pMainForm->client(), Device::Midi);
608          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
609                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);                  pDevice = new Device(Device::Midi, piDeviceIDs[i]);
610                  if (pDevice->driverName().toUpper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
611                          m_ui.MidiDeviceComboBox->insertItem(0,                          const int iMidiDevice = pDevice->deviceID();
612                            m_ui.MidiDeviceComboBox->addItem(
613                                  midiPixmap, pDevice->deviceName());                                  midiPixmap, pDevice->deviceName());
614                          m_midiDevices.append(pDevice);                          m_ui.MidiDeviceComboBox->setItemData(i, iMidiDevice);
615                            m_midiDevices.insert(iMidiDevice, pDevice);
616                            if (iMidiDevice == iDeviceID)
617                                    iMidiItem = i;
618                  } else {                  } else {
619                          delete pDevice;                          delete pDevice;
620                  }                  }
621          }          }
622    
623          // Do proper enabling...          // Do proper enabling...
624          bool bEnabled = !m_midiDevices.isEmpty();          const bool bEnabled = !m_midiDevices.isEmpty();
625          if (bEnabled) {          if (bEnabled) {
626                  // Select the previous current device...                  // Select the previous current device...
627                  iMidiItem = 0;                  m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
628                  QListIterator<qsamplerDevice *> iter(m_midiDevices);                  selectMidiDeviceItem(iMidiItem);
                 while (iter.hasNext()) {  
                         pDevice = iter.next();  
                         if (pDevice->deviceID() == iDeviceID) {  
                                 m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);  
                                 selectMidiDeviceItem(iMidiItem);  
                                 break;  
                         }  
                         iMidiItem++;  
                 }  
629          } else {          } else {
630                  m_ui.MidiDeviceComboBox->insertItem(0,                  m_ui.MidiDeviceComboBox->insertItem(0,
631                          tr("(New MIDI %1 device)").arg(sMidiDriver));                          tr("(New MIDI %1 device)").arg(sMidiDriver));
632                    m_ui.MidiDeviceComboBox->setItemData(0, -1);
633          }          }
634          m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);  //      m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);
635          m_ui.MidiDeviceComboBox->setEnabled(bEnabled);  //      m_ui.MidiDeviceComboBox->setEnabled(bEnabled);
636  }  }
637    
638    
# Line 614  void ChannelForm::selectMidiDriver ( con Line 650  void ChannelForm::selectMidiDriver ( con
650  // Select MIDI device item.  // Select MIDI device item.
651  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
652  {  {
653          qsamplerDevice *pDevice = NULL;          Device *pDevice = nullptr;
654          if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())          if (iMidiItem >= 0) {
655                  pDevice = m_midiDevices.at(iMidiItem);                  const int iMidiDevice
656                            = m_ui.MidiDeviceComboBox->itemData(iMidiItem).toInt();
657                    pDevice = m_midiDevices.value(iMidiDevice, nullptr);
658            }
659          if (pDevice) {          if (pDevice) {
660                  const qsamplerDeviceParamMap& params = pDevice->params();                  const DeviceParamMap& params = pDevice->params();
661                  int iPorts = params["PORTS"].value.toInt();                  const int iPorts = params["PORTS"].value.toInt();
662                  m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);                  m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);
663                  m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);                  m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);
664                  if (iPorts > 0)                  if (iPorts > 0)
# Line 642  void ChannelForm::selectMidiDevice ( int Line 681  void ChannelForm::selectMidiDevice ( int
681  // MIDI device options.  // MIDI device options.
682  void ChannelForm::setupMidiDevice (void)  void ChannelForm::setupMidiDevice (void)
683  {  {
684          qsamplerDevice *pDevice = NULL;          Device *pDevice = nullptr;
685          int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();          const int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
686          if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())          if (iMidiItem >= 0) {
687                  pDevice = m_midiDevices.at(iMidiItem);                  const int iMidiDevice
688                            = m_ui.MidiDeviceComboBox->itemData(iMidiItem).toInt();
689                    pDevice = m_midiDevices.value(iMidiDevice, nullptr);
690            }
691          setupDevice(pDevice,          setupDevice(pDevice,
692                  qsamplerDevice::Midi, m_ui.MidiDriverComboBox->currentText());                  Device::Midi, m_ui.MidiDriverComboBox->currentText());
693  }  }
694    
695    
# Line 655  void ChannelForm::setupMidiDevice (void) Line 697  void ChannelForm::setupMidiDevice (void)
697  void ChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )  void ChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
698  {  {
699          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
700          if (pMainForm == NULL)          if (pMainForm == nullptr)
701                  return;                  return;
702          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
703                  return;                  return;
704    
705          const QString sDriverName = sAudioDriver.toUpper();          const QString sDriverName = sAudioDriver.toUpper();
706    
707          // Save current device id.          // Save current device id.
708          int iDeviceID = 0;          int iDeviceID = 0;
         qsamplerDevice *pDevice = NULL;  
709          int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();          int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
710          if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())          if (iAudioItem >= 0)
711                  pDevice = m_audioDevices.at(iAudioItem);                  iDeviceID = m_ui.AudioDeviceComboBox->itemData(iAudioItem).toInt();
         if (pDevice)  
                 iDeviceID = pDevice->deviceID();  
712    
713          // Clean maplist.          // Clean maplist.
714          m_ui.AudioDeviceComboBox->clear();          m_ui.AudioDeviceComboBox->clear();
# Line 677  void ChannelForm::selectAudioDriverItem Line 716  void ChannelForm::selectAudioDriverItem
716          m_audioDevices.clear();          m_audioDevices.clear();
717    
718          // Populate with the current ones...          // Populate with the current ones...
719          const QPixmap audioPixmap(":/icons/audio2.png");          Device *pDevice = nullptr;
720          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          const QPixmap audioPixmap(":/images/audio2.png");
721                  qsamplerDevice::Audio);          int *piDeviceIDs = Device::getDevices(pMainForm->client(), Device::Audio);
722          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
723                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);                  pDevice = new Device(Device::Audio, piDeviceIDs[i]);
724                  if (pDevice->driverName().toUpper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
725                          m_ui.AudioDeviceComboBox->insertItem(0,                          const int iAudioDevice = pDevice->deviceID();
726                            m_ui.AudioDeviceComboBox->addItem(
727                                  audioPixmap, pDevice->deviceName());                                  audioPixmap, pDevice->deviceName());
728                          m_audioDevices.append(pDevice);                          m_ui.AudioDeviceComboBox->setItemData(i, iAudioDevice);
729                            m_audioDevices.insert(iAudioDevice, pDevice);
730                            if (iAudioDevice == iDeviceID)
731                                    iAudioItem = i;
732                  } else {                  } else {
733                          delete pDevice;                          delete pDevice;
734                  }                  }
735          }          }
736    
737          // Do proper enabling...          // Do proper enabling...
738          bool bEnabled = !m_audioDevices.isEmpty();          const bool bEnabled = !m_audioDevices.isEmpty();
739          if (bEnabled) {          if (bEnabled) {
740                  // Select the previous current device...                  // Select the previous current device...
741                  iAudioItem = 0;                  m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
742                  QListIterator<qsamplerDevice *> iter(m_audioDevices);                  selectAudioDeviceItem(iAudioItem);
                 while (iter.hasNext()) {  
                         pDevice = iter.next();  
                         if (pDevice->deviceID() == iDeviceID) {  
                                 m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);  
                                 selectAudioDeviceItem(iAudioItem);  
                                 break;  
                         }  
                         iAudioItem++;  
                 }  
743          } else {          } else {
744                  m_ui.AudioDeviceComboBox->insertItem(0,                  m_ui.AudioDeviceComboBox->insertItem(0,
745                          tr("(New Audio %1 device)").arg(sAudioDriver));                          tr("(New Audio %1 device)").arg(sAudioDriver));
746                  //m_ui.AudioRoutingTable->setNumRows(0);                  m_ui.AudioDeviceComboBox->setItemData(0, -1);
747          }          }
748          m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);  //      m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);
749          m_ui.AudioDeviceComboBox->setEnabled(bEnabled);  //      m_ui.AudioDeviceComboBox->setEnabled(bEnabled);
750          m_ui.AudioRoutingTable->setEnabled(bEnabled);          m_ui.AudioRoutingTable->setEnabled(bEnabled);
751  }  }
752    
# Line 731  void ChannelForm::selectAudioDriver ( co Line 765  void ChannelForm::selectAudioDriver ( co
765  // Select Audio device item.  // Select Audio device item.
766  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
767  {  {
768          qsamplerDevice *pDevice = NULL;          Device *pDevice = nullptr;
769          if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())          if (iAudioItem >= 0) {
770                  pDevice = m_audioDevices.at(iAudioItem);                  const int iAudioDevice
771                            = m_ui.AudioDeviceComboBox->itemData(iAudioItem).toInt();
772                    pDevice = m_audioDevices.value(iAudioDevice, nullptr);
773            }
774          if (pDevice) {          if (pDevice) {
775                  // Refresh the audio routing table.                  // Refresh the audio routing table.
776                  m_routingModel.refresh(pDevice, m_pChannel->audioRouting());                  m_routingModel.refresh(pDevice, m_pChannel->audioRouting());
# Line 757  void ChannelForm::selectAudioDevice ( in Line 794  void ChannelForm::selectAudioDevice ( in
794  // Audio device options.  // Audio device options.
795  void ChannelForm::setupAudioDevice (void)  void ChannelForm::setupAudioDevice (void)
796  {  {
797          qsamplerDevice *pDevice = NULL;          Device *pDevice = nullptr;
798          int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();          const int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
799          if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())          if (iAudioItem >= 0) {
800                  pDevice = m_audioDevices.at(iAudioItem);                  const int iAudioDevice
801                            = m_ui.AudioDeviceComboBox->itemData(iAudioItem).toInt();
802                    pDevice = m_audioDevices.value(iAudioDevice, nullptr);
803            }
804          setupDevice(pDevice,          setupDevice(pDevice,
805                  qsamplerDevice::Audio, m_ui.AudioDriverComboBox->currentText());                  Device::Audio, m_ui.AudioDriverComboBox->currentText());
806  }  }
807    
808  // UPdate all device lists slot.  // UPdate all device lists slot.
# Line 791  void ChannelForm::optionsChanged (void) Line 831  void ChannelForm::optionsChanged (void)
831  // Stabilize current form state.  // Stabilize current form state.
832  void ChannelForm::stabilizeForm (void)  void ChannelForm::stabilizeForm (void)
833  {  {
834          const bool bValid =          bool bValid = m_ui.EngineNameComboBox->currentIndex() >= 0 &&
835                  m_ui.EngineNameComboBox->currentIndex() >= 0 &&                  m_ui.EngineNameComboBox->currentText() != Channel::noEngineName();
836                  m_ui.EngineNameComboBox->currentText()  
837                          != qsamplerChannel::noEngineName();          const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
 #if 0  
         const QString& sPath = InstrumentFileComboBox->currentText();  
838          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
839  #endif  
840          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          m_ui.DialogButtonBox->button(
841                    QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid);
842  }  }
843    
844    

Legend:
Removed from v.1527  
changed lines
  Added in v.3559

  ViewVC Help
Powered by ViewVC