/[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 1489 by schoenebeck, Mon Nov 19 03:29:57 2007 UTC revision 3385 by capela, Fri Dec 1 19:23:47 2017 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-2016, 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 28  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    
41  ChannelForm::ChannelForm(QWidget* parent) : QDialog(parent) {  //-------------------------------------------------------------------------
42      ui.setupUi(this);  // QSampler::Channelform -- Channel form implementation.
43    //
44    
45    ChannelForm::ChannelForm ( QWidget* pParent )
46            : QDialog(pParent)
47    {
48            m_ui.setupUi(this);
49    
50          // Initialize locals.          // Initialize locals.
51          m_pChannel = NULL;          m_pChannel = NULL;
# Line 44  ChannelForm::ChannelForm(QWidget* parent Line 53  ChannelForm::ChannelForm(QWidget* parent
53          m_iDirtySetup = 0;          m_iDirtySetup = 0;
54          m_iDirtyCount = 0;          m_iDirtyCount = 0;
55    
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 = NULL;
60    
61            const int iRowHeight = m_ui.AudioRoutingTable->fontMetrics().height() + 4;
62            m_ui.AudioRoutingTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
63            m_ui.AudioRoutingTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
64    
65            m_ui.AudioRoutingTable->setModel(&m_routingModel);
66            m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate);
67    #if QT_VERSION >= 0x050000
68            m_ui.AudioRoutingTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
69    #else
70            m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
71    #endif
72    //      m_ui.AudioRoutingTable->verticalHeader()->hide();
73    
74            // This goes initially hidden, and will be shown
75            // on setup() for currently existing channels...
76            m_ui.AudioRoutingTable->hide();
77    
78          // Try to restore normal window positioning.          // Try to restore normal window positioning.
79          adjustSize();          adjustSize();
80    
81          ui.AudioRoutingTable->setModel(&routingModel);          QObject::connect(m_ui.EngineNameComboBox,
         ui.AudioRoutingTable->setItemDelegate(&routingDelegate);  
         ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);  
   
         QObject::connect(ui.EngineNameComboBox,  
82                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
83                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
84          QObject::connect(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(ui.InstrumentFileToolButton,          QObject::connect(m_ui.InstrumentFileToolButton,
91                  SIGNAL(clicked()),                  SIGNAL(clicked()),
92                  SLOT(openInstrumentFile()));                  SLOT(openInstrumentFile()));
93          QObject::connect(ui.InstrumentNrComboBox,          QObject::connect(m_ui.InstrumentNrComboBox,
94                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
95                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
96          QObject::connect(ui.MidiDriverComboBox,          QObject::connect(m_ui.MidiDriverComboBox,
97                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
98                  SLOT(selectMidiDriver(const QString&)));                  SLOT(selectMidiDriver(const QString&)));
99          QObject::connect(ui.MidiDeviceComboBox,          QObject::connect(m_ui.MidiDeviceComboBox,
100                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
101                  SLOT(selectMidiDevice(int)));                  SLOT(selectMidiDevice(int)));
102          QObject::connect(ui.MidiPortSpinBox,          QObject::connect(m_ui.MidiPortSpinBox,
103                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
104                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
105          QObject::connect(ui.MidiChannelComboBox,          QObject::connect(m_ui.MidiChannelComboBox,
106                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
107                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
108          QObject::connect(ui.MidiMapComboBox,          QObject::connect(m_ui.MidiMapComboBox,
109                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
110                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
111          QObject::connect(ui.AudioDriverComboBox,          QObject::connect(m_ui.AudioDriverComboBox,
112                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
113                  SLOT(selectAudioDriver(const QString&)));                  SLOT(selectAudioDriver(const QString&)));
114          QObject::connect(ui.AudioDeviceComboBox,          QObject::connect(m_ui.AudioDeviceComboBox,
115                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
116                  SLOT(selectAudioDevice(int)));                  SLOT(selectAudioDevice(int)));
117          QObject::connect(ui.OkPushButton,          QObject::connect(m_ui.DialogButtonBox,
118                  SIGNAL(clicked()),                  SIGNAL(accepted()),
119                  SLOT(accept()));                  SLOT(accept()));
120          QObject::connect(ui.CancelPushButton,          QObject::connect(m_ui.DialogButtonBox,
121                  SIGNAL(clicked()),                  SIGNAL(rejected()),
122                  SLOT(reject()));                  SLOT(reject()));
123          QObject::connect(ui.MidiDeviceToolButton,          QObject::connect(m_ui.MidiDeviceToolButton,
124                  SIGNAL(clicked()),                  SIGNAL(clicked()),
125                  SLOT(setupMidiDevice()));                  SLOT(setupMidiDevice()));
126          QObject::connect(ui.AudioDeviceToolButton,          QObject::connect(m_ui.AudioDeviceToolButton,
127                  SIGNAL(clicked()),                  SIGNAL(clicked()),
128                  SLOT(setupAudioDevice()));                  SLOT(setupAudioDevice()));
129          QObject::connect(&routingModel,  
130            QObject::connect(&m_routingModel,
131                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
132                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
133          QObject::connect(&routingModel,          QObject::connect(&m_routingModel,
134                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
135                  SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));                  SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));
136          QObject::connect(&routingModel,          QObject::connect(&m_routingModel,
137                  SIGNAL(modelReset()),                  SIGNAL(modelReset()),
138                  SLOT(updateTableCellRenderers()));                  SLOT(updateTableCellRenderers()));
139  }  }
140    
141  ChannelForm::~ChannelForm() {  ChannelForm::~ChannelForm()
142    {
143          if (m_pDeviceForm)          if (m_pDeviceForm)
144                  delete m_pDeviceForm;                  delete m_pDeviceForm;
145          m_pDeviceForm = NULL;          m_pDeviceForm = NULL;
146    
147            qDeleteAll(m_midiDevices);
148            m_midiDevices.clear();
149    
150            qDeleteAll(m_audioDevices);
151            m_audioDevices.clear();
152  }  }
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    
# Line 131  void ChannelForm::setup ( qsamplerChanne Line 164  void ChannelForm::setup ( qsamplerChanne
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          setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName());          setWindowTitle(QSAMPLER_TITLE ": " + 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();
# Line 141  void ChannelForm::setup ( qsamplerChanne Line 174  void ChannelForm::setup ( qsamplerChanne
174          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
175                  return;                  return;
176    
177          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
178          if (pOptions == NULL)          if (pOptions == NULL)
179                  return;                  return;
180    
# Line 149  void ChannelForm::setup ( qsamplerChanne Line 182  void ChannelForm::setup ( qsamplerChanne
182          m_iDirtySetup++;          m_iDirtySetup++;
183    
184          // Load combo box history...          // Load combo box history...
185          pOptions->loadComboBoxHistory(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());
199          if (ppszEngines) {          if (ppszEngines) {
200                  ui.EngineNameComboBox->clear();                  m_ui.EngineNameComboBox->clear();
201                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
202                          ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));                          m_ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));
203          }          }
204          else m_pChannel->appendMessagesClient("lscp_list_available_engines");          else m_pChannel->appendMessagesClient("lscp_list_available_engines");
205    
206          // Populate Audio output type list.          // Populate Audio output type list.
207          ui.AudioDriverComboBox->clear();          m_ui.AudioDriverComboBox->clear();
208          ui.AudioDriverComboBox->insertStringList(          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          ui.MidiDriverComboBox->clear();          m_ui.MidiDriverComboBox->clear();
213          ui.MidiDriverComboBox->insertStringList(          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          ui.MidiMapComboBox->clear();          m_ui.MidiMapComboBox->clear();
218          ui.MidiMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_ui.MidiMapComboBox->insertItems(0,
219                    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 182  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 (ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
231                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
232                  ui.EngineNameComboBox->addItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
233          }          }
234          ui.EngineNameComboBox->setCurrentIndex(          m_ui.EngineNameComboBox->setCurrentIndex(
235                  ui.EngineNameComboBox->findText(sEngineName,                  m_ui.EngineNameComboBox->findText(sEngineName,
236                          Qt::MatchExactly | Qt::MatchCaseSensitive));                          Qt::MatchExactly | Qt::MatchCaseSensitive));
237    
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          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
243          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
244          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
245                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  Channel::getInstrumentList(sInstrumentFile,
246                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
247          ui.InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());          int iInstrumentNr = pChannel->instrumentNr();
248            if (iInstrumentNr < 0)
249                    iInstrumentNr = 0;
250            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)
257                  sMidiDriver = pOptions->sMidiDriver.upper();                  sMidiDriver = pOptions->sMidiDriver.toUpper();
258          if (!sMidiDriver.isEmpty()) {          if (!sMidiDriver.isEmpty()) {
259                  if (ui.MidiDriverComboBox->findText(sMidiDriver,                  if (m_ui.MidiDriverComboBox->findText(sMidiDriver,
260                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
261                          ui.MidiDriverComboBox->insertItem(sMidiDriver);                          m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
262                  }                  }
263                  ui.MidiDriverComboBox->setCurrentText(sMidiDriver);                  m_ui.MidiDriverComboBox->setCurrentIndex(
264                            m_ui.MidiDriverComboBox->findText(sMidiDriver,
265                                    Qt::MatchExactly | Qt::MatchCaseSensitive)
266                    );
267          }          }
268          selectMidiDriverItem(sMidiDriver);          selectMidiDriverItem(sMidiDriver);
269          if (!bNew)          if (!bNew) {
270                  ui.MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());                  m_ui.MidiDeviceComboBox->setItemText(
271          selectMidiDeviceItem(ui.MidiDeviceComboBox->currentItem());                          m_ui.MidiDeviceComboBox->currentIndex(),
272                            midiDevice.deviceName());
273            }
274            selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());
275          // MIDI input port...          // MIDI input port...
276          ui.MidiPortSpinBox->setValue(pChannel->midiPort());          m_ui.MidiPortSpinBox->setValue(pChannel->midiPort());
277          // MIDI input channel...          // MIDI input channel...
278          int iMidiChannel = pChannel->midiChannel();          int iMidiChannel = pChannel->midiChannel();
279          // When new, try to suggest a sensible MIDI channel...          // When new, try to suggest a sensible MIDI channel...
280          if (iMidiChannel < 0)          if (iMidiChannel < 0)
281                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);
282          ui.MidiChannelComboBox->setCurrentItem(iMidiChannel);          m_ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
283          // MIDI instrument map...          // MIDI instrument map...
284          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());
285          // When new, try to suggest a sensible MIDI map...          // When new, try to suggest a sensible MIDI map...
286          if (iMidiMap < 0)          if (iMidiMap < 0)
287                  iMidiMap = 0;                  iMidiMap = 0;
288          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);          const QString& sMapName = Instrument::getMapName(iMidiMap);
289          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
290                  ui.MidiMapComboBox->setCurrentText(sMapName);                  m_ui.MidiMapComboBox->setItemText(
291                            m_ui.MidiMapComboBox->currentIndex(),
292                            sMapName);
293            }
294          // It might be no maps around...          // It might be no maps around...
295          bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0);          const bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);
296          ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);          m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
297          ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);          m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
298    
299          // Audio output device...          // Audio output device...
300          qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice());          const Device audioDevice(Device::Audio, m_pChannel->audioDevice());
301          // Audio output driver...          // Audio output driver...
302          QString sAudioDriver = audioDevice.driverName();          QString sAudioDriver = audioDevice.driverName();
303          if (sAudioDriver.isEmpty() || bNew)          if (sAudioDriver.isEmpty() || bNew)
304                  sAudioDriver = pOptions->sAudioDriver.upper();                  sAudioDriver = pOptions->sAudioDriver.toUpper();
305          if (!sAudioDriver.isEmpty()) {          if (!sAudioDriver.isEmpty()) {
306                  if (ui.AudioDriverComboBox->findText(sAudioDriver,                  if (m_ui.AudioDriverComboBox->findText(sAudioDriver,
307                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
308                          ui.AudioDriverComboBox->insertItem(sAudioDriver);                          m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
309                  }                  }
310                  ui.AudioDriverComboBox->setCurrentText(sAudioDriver);                  m_ui.AudioDriverComboBox->setCurrentIndex(
311                            m_ui.AudioDriverComboBox->findText(sAudioDriver,
312                                    Qt::MatchExactly | Qt::MatchCaseSensitive)
313                    );
314          }          }
315          selectAudioDriverItem(sAudioDriver);          selectAudioDriverItem(sAudioDriver);
316          if (!bNew)          if (!bNew) {
317                  ui.AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());                  m_ui.AudioDeviceComboBox->setItemText(
318          selectAudioDeviceItem(ui.AudioDeviceComboBox->currentItem());                          m_ui.AudioDeviceComboBox->currentIndex(),
319                            audioDevice.deviceName());
320            }
321            selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());
322    
323            // Let the audio routing table see the light,
324            // if we're editing an existing sampler channel...
325            m_ui.AudioRoutingTable->setVisible(!bNew);
326    
327            const QString sInstrumentNrToolTip =
328                    (pOptions->bInstrumentNames) ?
329                            tr("Select an instrument of the file") :
330                            tr("You might want to enable instrument name retrieval in the "
331                            "settings dialog");
332            m_ui.InstrumentNrComboBox->setToolTip(
333                    QObject::tr(sInstrumentNrToolTip.toUtf8().data())
334            );
335    
336    #if 0
337          // As convenient, make it ready on stabilizeForm() for          // As convenient, make it ready on stabilizeForm() for
338          // prompt acceptance, if we got the minimum required...          // prompt acceptance, if we got the minimum required...
339  /*      if (sEngineName != qsamplerChannel::noEngineName() &&          if (sEngineName != Channel::noEngineName() &&
340                  sInstrumentFile != qsamplerChannel::noInstrumentName())                  sInstrumentFile != Channel::noInstrumentName())
341                  m_iDirtyCount++; */                  m_iDirtyCount++;
342    #endif
343    
344          // Done.          // Done.
345          m_iDirtySetup--;          m_iDirtySetup--;
346          stabilizeForm();          stabilizeForm();
# Line 280  void ChannelForm::accept (void) Line 359  void ChannelForm::accept (void)
359          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
360                  return;                  return;
361    
362          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
363          if (pOptions == NULL)          if (pOptions == NULL)
364                  return;                  return;
365    
366          // Flush any pending editing...          // Flush any pending editing...
367          //ui.AudioRoutingTable->flush();          //m_ui.AudioRoutingTable->flush();
368    
369          // We'll go for it!          // We'll go for it!
370          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
# Line 295  void ChannelForm::accept (void) Line 374  void ChannelForm::accept (void)
374                          iErrors++;                          iErrors++;
375                  // Accept Audio driver or device selection...                  // Accept Audio driver or device selection...
376                  if (m_audioDevices.isEmpty()) {                  if (m_audioDevices.isEmpty()) {
377                          if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText()))                          if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))
378                                  iErrors++;                                  iErrors++;
379                  } else {                  } else {
380                          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());                          Device *pDevice = NULL;
381                          qsamplerChannelRoutingMap routingMap = routingModel.routingMap();                          const int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
382                            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
383                                    pDevice = m_audioDevices.at(iAudioItem);
384                            ChannelRoutingMap routingMap = m_routingModel.routingMap();
385                          if (pDevice == NULL)                          if (pDevice == NULL)
386                                  iErrors++;                                  iErrors++;
387                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
388                                  iErrors++;                                  iErrors++;
389                          else if (!routingMap.isEmpty()) {                          else if (!routingMap.isEmpty()) {
390                                  // Set the audio route changes...                                  // Set the audio route changes...
391                                  qsamplerChannelRoutingMap::ConstIterator iter;                                  ChannelRoutingMap::ConstIterator iter;
392                                  for (iter = routingMap.begin();                                  for (iter = routingMap.begin();
393                                                  iter != routingMap.end(); ++iter) {                                                  iter != routingMap.end(); ++iter) {
394                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
395                                                  iErrors++;                                                  iErrors++;
396                                  }                                  }
397                          }                          }
398                  }                  }
399                  // Accept MIDI driver or device selection...                  // Accept MIDI driver or device selection...
400                  if (m_midiDevices.isEmpty()) {                  if (m_midiDevices.isEmpty()) {
401                          if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText()))                          if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))
402                                  iErrors++;                                  iErrors++;
403                  } else {                  } else {
404                          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());                          Device *pDevice = NULL;
405                            const int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
406                            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
407                                    pDevice = m_midiDevices.at(iMidiItem);
408                          if (pDevice == NULL)                          if (pDevice == NULL)
409                                  iErrors++;                                  iErrors++;
410                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
411                                  iErrors++;                                  iErrors++;
412                  }                  }
413                  // MIDI input port number...                  // MIDI input port number...
414                  if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value()))                  if (!m_pChannel->setMidiPort(m_ui.MidiPortSpinBox->value()))
415                          iErrors++;                          iErrors++;
416                  // MIDI input channel...                  // MIDI input channel...
417                  if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentItem()))                  if (!m_pChannel->setMidiChannel(m_ui.MidiChannelComboBox->currentIndex()))
418                          iErrors++;                          iErrors++;
419                  // Engine name...                  // Engine name...
420                  if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText()))                  if (!m_pChannel->loadEngine(m_ui.EngineNameComboBox->currentText()))
421                          iErrors++;                          iErrors++;
422                  // Instrument file and index...                  // Instrument file and index...
423                  const QString& sPath = ui.InstrumentFileComboBox->currentText();                  const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
424                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
425                          if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentItem()))                          if (!m_pChannel->loadInstrument(sPath, m_ui.InstrumentNrComboBox->currentIndex()))
426                                  iErrors++;                                  iErrors++;
427                  }                  }
428                  // MIDI intrument map...                  // MIDI intrument map...
429                  if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentItem()))                  if (!m_pChannel->setMidiMap(m_ui.MidiMapComboBox->currentIndex()))
430                          iErrors++;                          iErrors++;
431                  // Show error messages?                  // Show error messages?
432                  if (iErrors > 0)                  if (iErrors > 0) {
433                          m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));                          m_pChannel->appendMessagesError(
434                                    tr("Some channel settings could not be set.\n\nSorry."));
435                    }
436          }          }
437    
438          // Save default engine name, instrument directory and history...          // Save default engine name, instrument directory and history...
439          pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true);          pOptions->sInstrumentDir = QFileInfo(
440          pOptions->sEngineName  = ui.EngineNameComboBox->currentText();                  m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
441          pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText();          pOptions->sEngineName  = m_ui.EngineNameComboBox->currentText();
442          pOptions->sMidiDriver  = ui.MidiDriverComboBox->currentText();          pOptions->sAudioDriver = m_ui.AudioDriverComboBox->currentText();
443          pOptions->iMidiMap     = ui.MidiMapComboBox->currentItem();          pOptions->sMidiDriver  = m_ui.MidiDriverComboBox->currentText();
444          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->iMidiMap     = m_ui.MidiMapComboBox->currentIndex();
445            pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox);
446    
447          // Just go with dialog acceptance.          // Just go with dialog acceptance.
448          QDialog::accept();          QDialog::accept();
# Line 367  void ChannelForm::reject (void) Line 455  void ChannelForm::reject (void)
455          bool bReject = true;          bool bReject = true;
456    
457          // Check if there's any pending changes...          // Check if there's any pending changes...
458          if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0) {
459                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
460                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
461                          tr("Some channel settings have been changed.\n\n"                          tr("Some channel settings have been changed.\n\n"
462                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
463                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
464                  case 0:     // Apply...                          QMessageBox::Discard |
465                            QMessageBox::Cancel)) {
466                    case QMessageBox::Apply:
467                          accept();                          accept();
468                          return;                          return;
469                  case 1:     // Discard                  case QMessageBox::Discard:
470                          break;                          break;
471                  default:    // Cancel.                  default:    // Cancel.
472                          bReject = false;                          bReject = false;
# Line 398  void ChannelForm::openInstrumentFile (vo Line 488  void ChannelForm::openInstrumentFile (vo
488          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
489                  return;                  return;
490    
491          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
492          if (pOptions == NULL)          if (pOptions == NULL)
493                  return;                  return;
494    
495          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
496          // depending on the current engine.          // depending on the current engine.
497          QString sInstrumentFile = QFileDialog::getOpenFileName(          QStringList filters;
498                  pOptions->sInstrumentDir,                   // Start here.          const QString& sEngineName = m_ui.EngineNameComboBox->currentText().toUpper();
499                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)          if (sEngineName.contains("GIG"))
500                  this, 0,                                    // Parent and name (none)                  filters << tr("GIG Instrument files") + " (*.gig *.dls)";
501                  QSAMPLER_TITLE ": " + tr("Instrument files")    // Caption.          if (sEngineName.contains("SFZ"))
502                    filters << tr("SFZ Instrument files") + " (*.sfz)";
503            if (sEngineName.contains("SF2"))
504                    filters << tr("SF2 Instrument files") + " (*.sf2)";
505            filters << tr("All files") + " (*.*)";
506            const QString& filter = filters.join(";;");
507    
508            QString sInstrumentFile = QFileDialog::getOpenFileName(this,
509                    QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
510                    pOptions->sInstrumentDir, // Start here.
511                    filter                    // File filter.
512          );          );
513    
514          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
515                  return;                  return;
516    
517          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
518          updateInstrumentName();          updateInstrumentName();
519  }  }
520    
# Line 428  void ChannelForm::updateInstrumentName ( Line 528  void ChannelForm::updateInstrumentName (
528          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
529                  return;                  return;
530    
531          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
532          if (pOptions == NULL)          if (pOptions == NULL)
533                  return;                  return;
534    
535          // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
536          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
537          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
538          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
539                  qsamplerChannel::getInstrumentList(                  Channel::getInstrumentList(
540                          ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
541                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
542          );          );
543    
# Line 446  void ChannelForm::updateInstrumentName ( Line 546  void ChannelForm::updateInstrumentName (
546    
547    
548  // Show device options dialog.  // Show device options dialog.
549  void ChannelForm::setupDevice ( qsamplerDevice *pDevice,  void ChannelForm::setupDevice ( Device *pDevice,
550          qsamplerDevice::qsamplerDeviceType deviceTypeMode,          Device::DeviceType deviceTypeMode,
551          const QString& sDriverName )          const QString& sDriverName )
552  {  {
553          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 459  void ChannelForm::setupDevice ( qsampler Line 559  void ChannelForm::setupDevice ( qsampler
559          // Create the device form if not already...          // Create the device form if not already...
560          if (m_pDeviceForm == NULL) {          if (m_pDeviceForm == NULL) {
561                  m_pDeviceForm = new DeviceForm(this, Qt::Dialog);                  m_pDeviceForm = new DeviceForm(this, Qt::Dialog);
562          m_pDeviceForm->setAttribute(Qt::WA_ShowModal);                  m_pDeviceForm->setAttribute(Qt::WA_ShowModal);
563                  QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),                  QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
564                          this, SLOT(updateDevices()));                          this, SLOT(updateDevices()));
565          }          }
# Line 484  void ChannelForm::selectMidiDriverItem ( Line 584  void ChannelForm::selectMidiDriverItem (
584          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
585                  return;                  return;
586    
587          const QString sDriverName = sMidiDriver.upper();          const QString sDriverName = sMidiDriver.toUpper();
588    
589          // Save current device id.          // Save current device id.
590          int iDeviceID = 0;          int iDeviceID = 0;
591          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());          Device *pDevice = NULL;
592            int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
593            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
594                    pDevice = m_midiDevices.at(iMidiItem);
595          if (pDevice)          if (pDevice)
596                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
597    
598          // Clean maplist.          // Clean maplist.
599          ui.MidiDeviceComboBox->clear();          m_ui.MidiDeviceComboBox->clear();
600            qDeleteAll(m_midiDevices);
601          m_midiDevices.clear();          m_midiDevices.clear();
602    
603          // Populate with the current ones...          // Populate with the current ones...
604          const QPixmap midiPixmap(":/icons/midi2.png");          const QPixmap midiPixmap(":/images/midi2.png");
605          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = Device::getDevices(pMainForm->client(), Device::Midi);
                 qsamplerDevice::Midi);  
606          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
607                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);                  pDevice = new Device(Device::Midi, piDeviceIDs[i]);
608                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
609                          ui.MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());                          m_ui.MidiDeviceComboBox->insertItem(0,
610                                    midiPixmap, pDevice->deviceName());
611                          m_midiDevices.append(pDevice);                          m_midiDevices.append(pDevice);
612                  } else {                  } else {
613                          delete pDevice;                          delete pDevice;
# Line 511  void ChannelForm::selectMidiDriverItem ( Line 615  void ChannelForm::selectMidiDriverItem (
615          }          }
616    
617          // Do proper enabling...          // Do proper enabling...
618          bool bEnabled = !m_midiDevices.isEmpty();          const bool bEnabled = !m_midiDevices.isEmpty();
619          if (bEnabled) {          if (bEnabled) {
620                  // Select the previous current device...                  // Select the previous current device...
621                  int iMidiItem = 0;                  iMidiItem = 0;
622                  for (pDevice = m_midiDevices.first();                  QListIterator<Device *> iter(m_midiDevices);
623                                  pDevice;                  while (iter.hasNext()) {
624                                          pDevice = m_midiDevices.next()) {                          pDevice = iter.next();
625                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
626                                  ui.MidiDeviceComboBox->setCurrentItem(iMidiItem);                                  m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
627                                  selectMidiDeviceItem(iMidiItem);                                  selectMidiDeviceItem(iMidiItem);
628                                  break;                                  break;
629                          }                          }
630                          iMidiItem++;                          iMidiItem++;
631                  }                  }
632          } else {          } else {
633                  ui.MidiDeviceComboBox->insertItem(                  m_ui.MidiDeviceComboBox->insertItem(0,
634                          tr("(New MIDI %1 device)").arg(sMidiDriver));                          tr("(New MIDI %1 device)").arg(sMidiDriver));
635          }          }
636          ui.MidiDeviceTextLabel->setEnabled(bEnabled);          m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);
637          ui.MidiDeviceComboBox->setEnabled(bEnabled);          m_ui.MidiDeviceComboBox->setEnabled(bEnabled);
638  }  }
639    
640    
# Line 548  void ChannelForm::selectMidiDriver ( con Line 652  void ChannelForm::selectMidiDriver ( con
652  // Select MIDI device item.  // Select MIDI device item.
653  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
654  {  {
655          qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);          Device *pDevice = NULL;
656            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
657                    pDevice = m_midiDevices.at(iMidiItem);
658          if (pDevice) {          if (pDevice) {
659                  const qsamplerDeviceParamMap& params = pDevice->params();                  const DeviceParamMap& params = pDevice->params();
660                  int iPorts = params["PORTS"].value.toInt();                  const int iPorts = params["PORTS"].value.toInt();
661                  ui.MidiPortTextLabel->setEnabled(iPorts > 0);                  m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);
662                  ui.MidiPortSpinBox->setEnabled(iPorts > 0);                  m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);
663                  if (iPorts > 0)                  if (iPorts > 0)
664                          ui.MidiPortSpinBox->setMaxValue(iPorts - 1);                          m_ui.MidiPortSpinBox->setMaximum(iPorts - 1);
665          }          }
666  }  }
667    
# Line 574  void ChannelForm::selectMidiDevice ( int Line 680  void ChannelForm::selectMidiDevice ( int
680  // MIDI device options.  // MIDI device options.
681  void ChannelForm::setupMidiDevice (void)  void ChannelForm::setupMidiDevice (void)
682  {  {
683          setupDevice(m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()),          Device *pDevice = NULL;
684                  qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText());          const int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
685            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
686                    pDevice = m_midiDevices.at(iMidiItem);
687            setupDevice(pDevice,
688                    Device::Midi, m_ui.MidiDriverComboBox->currentText());
689  }  }
690    
691    
# Line 588  void ChannelForm::selectAudioDriverItem Line 698  void ChannelForm::selectAudioDriverItem
698          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
699                  return;                  return;
700    
701          const QString sDriverName = sAudioDriver.upper();          const QString sDriverName = sAudioDriver.toUpper();
702    
703          // Save current device id.          // Save current device id.
704          int iDeviceID = 0;          int iDeviceID = 0;
705          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());          Device *pDevice = NULL;
706            int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
707            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
708                    pDevice = m_audioDevices.at(iAudioItem);
709          if (pDevice)          if (pDevice)
710                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
711    
712          // Clean maplist.          // Clean maplist.
713          ui.AudioDeviceComboBox->clear();          m_ui.AudioDeviceComboBox->clear();
714            qDeleteAll(m_audioDevices);
715          m_audioDevices.clear();          m_audioDevices.clear();
716    
717          // Populate with the current ones...          // Populate with the current ones...
718          const QPixmap audioPixmap(":/icons/audio2.png");          const QPixmap audioPixmap(":/images/audio2.png");
719          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = Device::getDevices(pMainForm->client(),
720                  qsamplerDevice::Audio);                  Device::Audio);
721          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
722                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);                  pDevice = new Device(Device::Audio, piDeviceIDs[i]);
723                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
724                          ui.AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());                          m_ui.AudioDeviceComboBox->insertItem(0,
725                                    audioPixmap, pDevice->deviceName());
726                          m_audioDevices.append(pDevice);                          m_audioDevices.append(pDevice);
727                  } else {                  } else {
728                          delete pDevice;                          delete pDevice;
# Line 615  void ChannelForm::selectAudioDriverItem Line 730  void ChannelForm::selectAudioDriverItem
730          }          }
731    
732          // Do proper enabling...          // Do proper enabling...
733          bool bEnabled = !m_audioDevices.isEmpty();          const bool bEnabled = !m_audioDevices.isEmpty();
734          if (bEnabled) {          if (bEnabled) {
735                  // Select the previous current device...                  // Select the previous current device...
736                  int iAudioItem = 0;                  iAudioItem = 0;
737                  for (pDevice = m_audioDevices.first();                  QListIterator<Device *> iter(m_audioDevices);
738                                  pDevice;                  while (iter.hasNext()) {
739                                          pDevice = m_audioDevices.next()) {                          pDevice = iter.next();
740                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
741                                  ui.AudioDeviceComboBox->setCurrentItem(iAudioItem);                                  m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
742                                  selectAudioDeviceItem(iAudioItem);                                  selectAudioDeviceItem(iAudioItem);
743                                  break;                                  break;
744                          }                          }
745                          iAudioItem++;                          iAudioItem++;
746                  }                  }
747          } else {          } else {
748                  ui.AudioDeviceComboBox->insertItem(                  m_ui.AudioDeviceComboBox->insertItem(0,
749                          tr("(New Audio %1 device)").arg(sAudioDriver));                          tr("(New Audio %1 device)").arg(sAudioDriver));
750                  //ui.AudioRoutingTable->setNumRows(0);                  //m_ui.AudioRoutingTable->setNumRows(0);
751          }          }
752          ui.AudioDeviceTextLabel->setEnabled(bEnabled);          m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);
753          ui.AudioDeviceComboBox->setEnabled(bEnabled);          m_ui.AudioDeviceComboBox->setEnabled(bEnabled);
754          ui.AudioRoutingTable->setEnabled(bEnabled);          m_ui.AudioRoutingTable->setEnabled(bEnabled);
755  }  }
756    
757    
# Line 654  void ChannelForm::selectAudioDriver ( co Line 769  void ChannelForm::selectAudioDriver ( co
769  // Select Audio device item.  // Select Audio device item.
770  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
771  {  {
772          qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);          Device *pDevice = NULL;
773            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
774                    pDevice = m_audioDevices.at(iAudioItem);
775          if (pDevice) {          if (pDevice) {
776                  // Refresh the audio routing table.                  // Refresh the audio routing table.
777                  routingModel.refresh(pDevice, m_pChannel->audioRouting());                  m_routingModel.refresh(pDevice, m_pChannel->audioRouting());
778                  // Reset routing change map.                  // Reset routing change map.
779                  routingModel.clear();                  m_routingModel.clear();
780          }          }
781  }  }
782    
# Line 678  void ChannelForm::selectAudioDevice ( in Line 795  void ChannelForm::selectAudioDevice ( in
795  // Audio device options.  // Audio device options.
796  void ChannelForm::setupAudioDevice (void)  void ChannelForm::setupAudioDevice (void)
797  {  {
798          setupDevice(m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()),          Device *pDevice = NULL;
799                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());          const int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
800            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
801                    pDevice = m_audioDevices.at(iAudioItem);
802            setupDevice(pDevice,
803                    Device::Audio, m_ui.AudioDriverComboBox->currentText());
804  }  }
805    
806  // UPdate all device lists slot.  // UPdate all device lists slot.
# Line 688  void ChannelForm::updateDevices (void) Line 809  void ChannelForm::updateDevices (void)
809          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
810                  return;                  return;
811    
812          selectMidiDriverItem(ui.MidiDriverComboBox->currentText());          selectMidiDriverItem(m_ui.MidiDriverComboBox->currentText());
813          selectAudioDriverItem(ui.AudioDriverComboBox->currentText());          selectAudioDriverItem(m_ui.AudioDriverComboBox->currentText());
814          optionsChanged();          optionsChanged();
815  }  }
816    
# Line 708  void ChannelForm::optionsChanged (void) Line 829  void ChannelForm::optionsChanged (void)
829  // Stabilize current form state.  // Stabilize current form state.
830  void ChannelForm::stabilizeForm (void)  void ChannelForm::stabilizeForm (void)
831  {  {
832          bool bValid = true;          bool bValid = m_ui.EngineNameComboBox->currentIndex() >= 0 &&
833  #if 0                  m_ui.EngineNameComboBox->currentText() != Channel::noEngineName();
834          const QString& sPath = InstrumentFileComboBox->currentText();  
835            const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
836          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
837  #endif  
838          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          m_ui.DialogButtonBox->button(
839                    QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid);
840    }
841    
842    
843    void ChannelForm::updateTableCellRenderers (void)
844    {
845            const int rows = m_routingModel.rowCount();
846            const int cols = m_routingModel.columnCount();
847            updateTableCellRenderers(
848                    m_routingModel.index(0, 0),
849                    m_routingModel.index(rows - 1, cols - 1));
850  }  }
851    
852  void ChannelForm::updateTableCellRenderers() {  
853      const int rows = routingModel.rowCount();  void ChannelForm::updateTableCellRenderers (
854      const int cols = routingModel.columnCount();          const QModelIndex& topLeft, const QModelIndex& bottomRight )
855      updateTableCellRenderers(routingModel.index(0,0),routingModel.index(rows-1,cols-1));  {
856  }          for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
857                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
858  void ChannelForm::updateTableCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {                          const QModelIndex index = m_routingModel.index(r, c);
859      for (int r = topLeft.row(); r <= bottomRight.row(); r++) {                          m_ui.AudioRoutingTable->openPersistentEditor(index);
860          for (int c = topLeft.column(); c <= bottomRight.column(); c++) {                  }
861              const QModelIndex index = routingModel.index(r,c);          }
             ui.AudioRoutingTable->openPersistentEditor(index);  
         }  
     }  
862  }  }
863    
864  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC