/[svn]/qsampler/trunk/src/qsamplerChannelForm.ui.h
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerChannelForm.ui.h

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

revision 344 by capela, Tue Jan 18 13:53:04 2005 UTC revision 767 by capela, Tue Aug 30 09:52:46 2005 UTC
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24    #include "qsamplerDeviceForm.h"
25    
26  #include <qvalidator.h>  #include <qvalidator.h>
27  #include <qmessagebox.h>  #include <qmessagebox.h>
28  #include <qfiledialog.h>  #include <qfiledialog.h>
29  #include <qfileinfo.h>  #include <qfileinfo.h>
30  #include <qlistbox.h>  #include <qlistbox.h>
31    
 #include "config.h"  
   
32    
33  // Kind of constructor.  // Kind of constructor.
34  void qsamplerChannelForm::init (void)  void qsamplerChannelForm::init (void)
35  {  {
36      // Initialize locals.          // Initialize locals.
37      m_pChannel = NULL;          m_pChannel = NULL;
38    
39            m_iDirtySetup = 0;
40            m_iDirtyCount = 0;
41    
42            m_midiDevices.setAutoDelete(true);
43            m_audioDevices.setAutoDelete(true);
44    
45      m_iDirtySetup = 0;          m_pDeviceForm = NULL;
     m_iDirtyCount = 0;  
46    
47      // Try to restore normal window positioning.          // Try to restore normal window positioning.
48      adjustSize();          adjustSize();
49  }  }
50    
51    
52  // Kind of destructor.  // Kind of destructor.
53  void qsamplerChannelForm::destroy (void)  void qsamplerChannelForm::destroy (void)
54  {  {
55            if (m_pDeviceForm)
56                    delete m_pDeviceForm;
57            m_pDeviceForm = NULL;
58  }  }
59    
60    
61  // Channel dialog setup formal initializer.  // Channel dialog setup formal initializer.
62  void qsamplerChannelForm::setup ( qsamplerChannel *pChannel )  void qsamplerChannelForm::setup ( qsamplerChannel *pChannel )
63  {  {
64      m_pChannel = pChannel;          m_pChannel = pChannel;
65    
66      m_iDirtySetup = 0;          m_iDirtySetup = 0;
67      m_iDirtyCount = 0;          m_iDirtyCount = 0;
68    
69      if (m_pChannel == NULL)          if (m_pChannel == NULL)
70          return;                  return;
71    
72      // It can be a brand new channel, remember?          // It can be a brand new channel, remember?
73      bool bNew = (m_pChannel->channelID() < 0);          bool bNew = (m_pChannel->channelID() < 0);
74      setCaption(m_pChannel->channelName());          setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName());
75    
76      // Check if we're up and connected.          // Check if we're up and connected.
77      if (m_pChannel->client() == NULL)          if (m_pChannel->client() == NULL)
78          return;                  return;
79    
80      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
81      if (pOptions == NULL)          if (pOptions == NULL)
82          return;                  return;
83    
84      // Avoid nested changes.          // Avoid nested changes.
85      m_iDirtySetup++;          m_iDirtySetup++;
86    
87      // Load combo box history...          // Load combo box history...
88      pOptions->loadComboBoxHistory(InstrumentFileComboBox);          pOptions->loadComboBoxHistory(InstrumentFileComboBox);
89    
90      // Populate Engines list.          // Notify.that we've just changed one audio route.
91      const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client());          QObject::connect(AudioRoutingTable, SIGNAL(valueChanged(int,int)),
92      if (ppszEngines) {                  this, SLOT(changeAudioRouting(int,int)));
93          EngineNameComboBox->clear();  
94          for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)          // Populate Engines list.
95              EngineNameComboBox->insertItem(ppszEngines[iEngine]);          const char **ppszEngines = ::lscp_list_available_engines(m_pChannel->client());
96      }          if (ppszEngines) {
97      else m_pChannel->appendMessagesClient("lscp_get_available_engines");                  EngineNameComboBox->clear();
98                    for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
99      // Populate Audio output type list.                          EngineNameComboBox->insertItem(ppszEngines[iEngine]);
100      const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client());          }
101      if (ppszAudioDrivers) {          else m_pChannel->appendMessagesClient("lscp_list_available_engines");
102          AudioDriverComboBox->clear();  
103          for (int iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++)          // Populate Audio output type list.
104              AudioDriverComboBox->insertItem(ppszAudioDrivers[iAudioDriver]);          AudioDriverComboBox->clear();
105      }          AudioDriverComboBox->insertStringList(
106      else m_pChannel->appendMessagesClient("lscp_get_available_audio_drivers");                  qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio));
107    
108      // Populate MIDI input type list.          // Populate MIDI input type list.
109      const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client());          MidiDriverComboBox->clear();
110      if (ppszMidiDrivers) {          MidiDriverComboBox->insertStringList(
111          MidiDriverComboBox->clear();                  qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi));
112          for (int iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++)  
113              MidiDriverComboBox->insertItem(ppszMidiDrivers[iMidiDriver]);          // Read proper channel information,
114      }          // and populate the channel form fields.
115      else m_pChannel->appendMessagesClient("lscp_get_available_midi_drivers");  
116            // Engine name...
117      // Read proper channel information,          QString sEngineName = pChannel->engineName();
118      // and populate the channel form fields.          if (sEngineName.isEmpty() || bNew)
119                    sEngineName = pOptions->sEngineName;
120      // Engine name...          if (sEngineName.isEmpty())
121      QString sEngineName = pChannel->engineName();                  sEngineName = qsamplerChannel::noEngineName();
122      if (sEngineName.isEmpty() && bNew)          if (EngineNameComboBox->listBox()->findItem(sEngineName,
123          sEngineName = pOptions->sEngineName;                          Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
124      if (sEngineName.isEmpty())                  EngineNameComboBox->insertItem(sEngineName);
125          sEngineName = tr("(No engine)");          }
126      if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL)          EngineNameComboBox->setCurrentText(sEngineName);
127          EngineNameComboBox->insertItem(sEngineName);          // Instrument filename and index...
128      EngineNameComboBox->setCurrentText(sEngineName);          QString sInstrumentFile = pChannel->instrumentFile();
129      // Instrument filename and index...          if (sInstrumentFile.isEmpty())
130      QString sInstrumentFile = pChannel->instrumentFile();                  sInstrumentFile = qsamplerChannel::noInstrumentName();
131      if (sInstrumentFile.isEmpty())          InstrumentFileComboBox->setCurrentText(sInstrumentFile);
132          sInstrumentFile = tr("(No instrument)");          InstrumentNrComboBox->clear();
133      InstrumentFileComboBox->setCurrentText(sInstrumentFile);          InstrumentNrComboBox->insertStringList(
     InstrumentNrComboBox->clear();  
     InstrumentNrComboBox->insertStringList(  
134                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  qsamplerChannel::getInstrumentList(sInstrumentFile,
135                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
136      InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());          InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());
137      // MIDI input driver...  
138      QString sMidiDriver = pChannel->midiDriver();          // MIDI input device...
139      if (sMidiDriver.isEmpty() || bNew)          qsamplerDevice midiDevice(m_pChannel->mainForm(),
140          sMidiDriver = pOptions->sMidiDriver;                  qsamplerDevice::Midi, m_pChannel->midiDevice());
141      if (!sMidiDriver.isEmpty()) {          // MIDI input driver...
142          if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL)          QString sMidiDriver = midiDevice.driverName();
143              MidiDriverComboBox->insertItem(sMidiDriver);          if (sMidiDriver.isEmpty() || bNew)
144          MidiDriverComboBox->setCurrentText(sMidiDriver);                  sMidiDriver = pOptions->sMidiDriver.upper();
145      }          if (!sMidiDriver.isEmpty()) {
146      // MIDI input port...                  if (MidiDriverComboBox->listBox()->findItem(sMidiDriver,
147      MidiPortSpinBox->setValue(pChannel->midiPort());                                  Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
148      // MIDI input channel...                          MidiDriverComboBox->insertItem(sMidiDriver);
149      int iMidiChannel = pChannel->midiChannel();                  }
150      // When new, try to suggest a sensible MIDI channel...                  MidiDriverComboBox->setCurrentText(sMidiDriver);
151      if (iMidiChannel < 0)          }
152          iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);          selectMidiDriverItem(sMidiDriver);
153      MidiChannelComboBox->setCurrentItem(iMidiChannel);          if (!bNew)
154      // Audio output driver...                  MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());
155      QString sAudioDriver = pChannel->audioDriver();          selectMidiDeviceItem(MidiDeviceComboBox->currentItem());
156      if (sAudioDriver.isEmpty() || bNew)          // MIDI input port...
157          sAudioDriver = pOptions->sAudioDriver;          MidiPortSpinBox->setValue(pChannel->midiPort());
158      if (!sAudioDriver.isEmpty()) {          // MIDI input channel...
159          if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)          int iMidiChannel = pChannel->midiChannel();
160              AudioDriverComboBox->insertItem(sAudioDriver);          // When new, try to suggest a sensible MIDI channel...
161          AudioDriverComboBox->setCurrentText(sAudioDriver);          if (iMidiChannel < 0)
162      }                  iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);
163      // Done.          MidiChannelComboBox->setCurrentItem(iMidiChannel);
164      m_iDirtySetup--;  
165      stabilizeForm();          // Audio output device...
166            qsamplerDevice audioDevice(m_pChannel->mainForm(),
167                    qsamplerDevice::Audio, m_pChannel->audioDevice());
168            // Audio output driver...
169            QString sAudioDriver = audioDevice.driverName();
170            if (sAudioDriver.isEmpty() || bNew)
171                    sAudioDriver = pOptions->sAudioDriver.upper();
172            if (!sAudioDriver.isEmpty()) {
173                    if (AudioDriverComboBox->listBox()->findItem(sAudioDriver,
174                                    Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
175                            AudioDriverComboBox->insertItem(sAudioDriver);
176                    }
177                    AudioDriverComboBox->setCurrentText(sAudioDriver);
178            }
179            selectAudioDriverItem(sAudioDriver);
180            if (!bNew)
181                    AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());
182            selectAudioDeviceItem(AudioDeviceComboBox->currentItem());
183    
184            // As convenient, make it ready on stabilizeForm() for
185            // prompt acceptance, if we got the minimum required...
186    /*      if (sEngineName != qsamplerChannel::noEngineName() &&
187                    sInstrumentFile != qsamplerChannel::noInstrumentName())
188                    m_iDirtyCount++; */
189            // Done.
190            m_iDirtySetup--;
191            stabilizeForm();
192  }  }
193    
194    
195  // Accept settings (OK button slot).  // Accept settings (OK button slot).
196  void qsamplerChannelForm::accept (void)  void qsamplerChannelForm::accept (void)
197  {  {
198      if (m_pChannel == NULL)          if (m_pChannel == NULL)
199          return;                  return;
200    
201      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
202      if (pOptions == NULL)          if (pOptions == NULL)
203          return;                  return;
204    
205      // We'll go for it!          // Flush any pending editing...
206      if (m_iDirtyCount > 0) {          AudioRoutingTable->flush();
207          int iErrors = 0;  
208          // Are we a new channel?          // We'll go for it!
209          if (!m_pChannel->addChannel())          if (m_iDirtyCount > 0) {
210              iErrors++;                  int iErrors = 0;
211          // Audio output driver type...                  // Are we a new channel?
212          if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))                  if (!m_pChannel->addChannel())
213              iErrors++;                          iErrors++;
214          // MIDI input driver type...                  // Accept Audio driver or device selection...
215          if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))                  if (m_audioDevices.isEmpty()) {
216              iErrors++;                          if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
217          // MIDI input port number...                                  iErrors++;
218          if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))                  } else {
219              iErrors++;                          qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
220          // MIDI input channel...                          if (pDevice == NULL)
221          if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))                                  iErrors++;
222              iErrors++;                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
223          // Engine name...                                  iErrors++;
224          if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))                          else if (!m_audioRouting.isEmpty()) {
225              iErrors++;                                  // Set the audio route changes...
226          // Instrument file and index...                                  qsamplerChannelRoutingMap::ConstIterator iter;
227          if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))                                  for (iter = m_audioRouting.begin();
228              iErrors++;                                                  iter != m_audioRouting.end(); ++iter) {
229          // Show error messages?                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))
230          if (iErrors > 0)                                                  iErrors++;
231              m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));                                  }
232      }                          }
233                    }
234      // Save default engine name, instrument directory and history...                  // Accept MIDI driver or device selection...
235      pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);                  if (m_midiDevices.isEmpty()) {
236      pOptions->sEngineName  = EngineNameComboBox->currentText();                          if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
237      pOptions->sAudioDriver = AudioDriverComboBox->currentText();                                  iErrors++;
238      pOptions->sMidiDriver  = MidiDriverComboBox->currentText();                  } else {
239      pOptions->saveComboBoxHistory(InstrumentFileComboBox);                          qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
240                            if (pDevice == NULL)
241                                    iErrors++;
242                            else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
243                                    iErrors++;
244                    }
245                    // MIDI input port number...
246                    if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
247                            iErrors++;
248                    // MIDI input channel...
249                    if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
250                            iErrors++;
251                    // Engine name...
252                    if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
253                            iErrors++;
254                    // Instrument file and index...
255                    if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
256                            iErrors++;
257                    // Show error messages?
258                    if (iErrors > 0)
259                            m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
260            }
261    
262            // Save default engine name, instrument directory and history...
263            pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
264            pOptions->sEngineName  = EngineNameComboBox->currentText();
265            pOptions->sAudioDriver = AudioDriverComboBox->currentText();
266            pOptions->sMidiDriver  = MidiDriverComboBox->currentText();
267            pOptions->saveComboBoxHistory(InstrumentFileComboBox);
268    
269      // Just go with dialog acceptance.          // Just go with dialog acceptance.
270      QDialog::accept();          QDialog::accept();
271  }  }
272    
273    
274  // Reject settings (Cancel button slot).  // Reject settings (Cancel button slot).
275  void qsamplerChannelForm::reject (void)  void qsamplerChannelForm::reject (void)
276  {  {
277      bool bReject = true;          bool bReject = true;
278    
279      // Check if there's any pending changes...          // Check if there's any pending changes...
280      if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
281          switch (QMessageBox::warning(this, tr("Warning"),                  switch (QMessageBox::warning(this,
282              tr("Some channel settings have been changed.\n\n"                          QSAMPLER_TITLE ": " + tr("Warning"),
283                 "Do you want to apply the changes?"),                          tr("Some channel settings have been changed.\n\n"
284              tr("Apply"), tr("Discard"), tr("Cancel"))) {                          "Do you want to apply the changes?"),
285          case 0:     // Apply...                          tr("Apply"), tr("Discard"), tr("Cancel"))) {
286              accept();                  case 0:     // Apply...
287              return;                          accept();
288          case 1:     // Discard                          return;
289              break;                  case 1:     // Discard
290          default:    // Cancel.                          break;
291              bReject = false;                  default:    // Cancel.
292          }                          bReject = false;
293      }                  }
294            }
295    
296      if (bReject)          if (bReject)
297          QDialog::reject();                  QDialog::reject();
298  }  }
299    
300    
301  // Browse and open an instrument file.  // Browse and open an instrument file.
302  void qsamplerChannelForm::openInstrumentFile (void)  void qsamplerChannelForm::openInstrumentFile (void)
303  {  {
304      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
305      if (pOptions == NULL)          if (pOptions == NULL)
306          return;                  return;
307    
308      // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
309      // depending on the current engine.          // depending on the current engine.
310      QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(
311              pOptions->sInstrumentDir,                   // Start here.                  pOptions->sInstrumentDir,                   // Start here.
312              tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)
313              this, 0,                                    // Parent and name (none)                  this, 0,                                    // Parent and name (none)
314              tr("Instrument files")                      // Caption.                  QSAMPLER_TITLE ": " + tr("Instrument files")    // Caption.
315      );          );
316    
317      if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
318          return;                  return;
319    
320      InstrumentFileComboBox->setCurrentText(sInstrumentFile);          InstrumentFileComboBox->setCurrentText(sInstrumentFile);
321            updateInstrumentName();
322  }  }
323    
324    
325  // Refresh the actual instrument name.  // Refresh the actual instrument name.
326  void qsamplerChannelForm::updateInstrumentName (void)  void qsamplerChannelForm::updateInstrumentName (void)
327  {  {
328      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
329      if (pOptions == NULL)          if (pOptions == NULL)
330          return;                  return;
331    
332      // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
333      // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
334      InstrumentNrComboBox->clear();          InstrumentNrComboBox->clear();
335      InstrumentNrComboBox->insertStringList(          InstrumentNrComboBox->insertStringList(
336          qsamplerChannel::getInstrumentList(                  qsamplerChannel::getInstrumentList(
337                          InstrumentFileComboBox->currentText(),                          InstrumentFileComboBox->currentText(),
338                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
339      );          );
340    
341            optionsChanged();
342    }
343    
344    // Show device options dialog.
345    void qsamplerChannelForm::setupDevice ( qsamplerDevice *pDevice,
346            qsamplerDevice::qsamplerDeviceType deviceTypeMode,
347            const QString& sDriverName )
348    {
349            // Create the device form if not already...
350            if (m_pDeviceForm == NULL) {
351                    m_pDeviceForm = new qsamplerDeviceForm(this, 0,
352                            WType_Dialog | WShowModal);
353                    m_pDeviceForm->setMainForm(m_pChannel->mainForm());
354                    QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
355                            this, SLOT(updateDevices()));
356            }
357    
358            // Refresh the device form with selected data.
359            if (m_pDeviceForm) {
360                    m_pDeviceForm->setDeviceTypeMode(deviceTypeMode);
361                    m_pDeviceForm->setClient(m_pChannel->client()); // -> refreshDevices();
362                    m_pDeviceForm->setDevice(pDevice);
363                    m_pDeviceForm->setDriverName(sDriverName);
364                    m_pDeviceForm->show();
365            }
366    }
367    
368    
369    // Refresh MIDI driver item devices.
370    void qsamplerChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
371    {
372            const QString sDriverName = sMidiDriver.upper();
373    
374            // Save current device id.
375            int iDeviceID = 0;
376            qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
377            if (pDevice)
378                    iDeviceID = pDevice->deviceID();
379    
380            // Clean maplist.
381            MidiDeviceComboBox->clear();
382            m_midiDevices.clear();
383    
384            // Populate with the current ones...
385            const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png");
386            int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
387                    qsamplerDevice::Midi);
388            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
389                    pDevice = new qsamplerDevice(m_pChannel->mainForm(),
390                            qsamplerDevice::Midi, piDeviceIDs[i]);
391                    if (pDevice->driverName().upper() == sDriverName) {
392                            MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());
393                            m_midiDevices.append(pDevice);
394                    } else {
395                            delete pDevice;
396                    }
397            }
398    
399            // Do proper enabling...
400            bool bEnabled = !m_midiDevices.isEmpty();
401            if (bEnabled) {
402                    // Select the previous current device...
403                    int iMidiItem = 0;
404                    for (pDevice = m_midiDevices.first();
405                                    pDevice;
406                                            pDevice = m_midiDevices.next()) {
407                            if (pDevice->deviceID() == iDeviceID) {
408                                    MidiDeviceComboBox->setCurrentItem(iMidiItem);
409                                    selectMidiDeviceItem(iMidiItem);
410                                    break;
411                            }
412                            iMidiItem++;
413                    }
414            } else {
415                    MidiDeviceComboBox->insertItem(
416                            tr("(New MIDI %1 device)").arg(sMidiDriver));
417            }
418            MidiDeviceTextLabel->setEnabled(bEnabled);
419            MidiDeviceComboBox->setEnabled(bEnabled);
420    }
421    
422    
423    // Refresh MIDI device options slot.
424    void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver )
425    {
426            if (m_iDirtySetup > 0)
427                    return;
428    
429            selectMidiDriverItem(sMidiDriver);
430            optionsChanged();
431    }
432    
433    
434    // Select MIDI device item.
435    void qsamplerChannelForm::selectMidiDeviceItem ( int iMidiItem )
436    {
437            qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);
438            if (pDevice) {
439                    const qsamplerDeviceParamMap& params = pDevice->params();
440                    int iPorts = params["PORTS"].value.toInt();
441                    MidiPortTextLabel->setEnabled(iPorts > 0);
442                    MidiPortSpinBox->setEnabled(iPorts > 0);
443                    if (iPorts > 0)
444                            MidiPortSpinBox->setMaxValue(iPorts - 1);
445            }
446    }
447    
448    
449    // Select MIDI device options slot.
450    void qsamplerChannelForm::selectMidiDevice ( int iMidiItem )
451    {
452            if (m_iDirtySetup > 0)
453                    return;
454    
455            selectMidiDeviceItem(iMidiItem);
456            optionsChanged();
457    }
458    
459    
460    // MIDI device options.
461    void qsamplerChannelForm::setupMidiDevice (void)
462    {
463            setupDevice(m_midiDevices.at(MidiDeviceComboBox->currentItem()),
464                    qsamplerDevice::Midi, MidiDriverComboBox->currentText());
465    }
466    
467    
468    // Refresh Audio driver item devices.
469    void qsamplerChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
470    {
471            const QString sDriverName = sAudioDriver.upper();
472    
473            // Save current device id.
474            int iDeviceID = 0;
475            qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
476            if (pDevice)
477                    iDeviceID = pDevice->deviceID();
478    
479            // Clean maplist.
480            AudioDeviceComboBox->clear();
481            m_audioDevices.clear();
482    
483            // Populate with the current ones...
484            const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png");
485            int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
486                    qsamplerDevice::Audio);
487            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
488                    pDevice = new qsamplerDevice(m_pChannel->mainForm(),
489                            qsamplerDevice::Audio, piDeviceIDs[i]);
490                    if (pDevice->driverName().upper() == sDriverName) {
491                            AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());
492                            m_audioDevices.append(pDevice);
493                    } else {
494                            delete pDevice;
495                    }
496            }
497    
498            // Do proper enabling...
499            bool bEnabled = !m_audioDevices.isEmpty();
500            if (bEnabled) {
501                    // Select the previous current device...
502                    int iAudioItem = 0;
503                    for (pDevice = m_audioDevices.first();
504                                    pDevice;
505                                            pDevice = m_audioDevices.next()) {
506                            if (pDevice->deviceID() == iDeviceID) {
507                                    AudioDeviceComboBox->setCurrentItem(iAudioItem);
508                                    selectAudioDeviceItem(iAudioItem);
509                                    break;
510                            }
511                            iAudioItem++;
512                    }
513            } else {
514                    AudioDeviceComboBox->insertItem(
515                            tr("(New Audio %1 device)").arg(sAudioDriver));
516                    AudioRoutingTable->setNumRows(0);
517            }
518            AudioDeviceTextLabel->setEnabled(bEnabled);
519            AudioDeviceComboBox->setEnabled(bEnabled);
520            AudioRoutingTable->setEnabled(bEnabled);
521    }
522    
523    
524    // Refresh Audio device options slot.
525    void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver )
526    {
527            if (m_iDirtySetup > 0)
528                    return;
529    
530            selectAudioDriverItem(sAudioDriver);
531            optionsChanged();
532    }
533    
534    
535    // Select Audio device item.
536    void qsamplerChannelForm::selectAudioDeviceItem ( int iAudioItem )
537    {
538            qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);
539            if (pDevice) {
540                    // Refresh the audio routing table.
541                    AudioRoutingTable->refresh(pDevice, m_pChannel->audioRouting());
542                    // Reset routing change map.
543                    m_audioRouting.clear();
544            }
545    }
546    
547    
548      optionsChanged();  // Select Audio device options slot.
549    void qsamplerChannelForm::selectAudioDevice ( int iAudioItem )
550    {
551            if (m_iDirtySetup > 0)
552                    return;
553    
554            selectAudioDeviceItem(iAudioItem);
555            optionsChanged();
556    }
557    
558    
559    // Audio device options.
560    void qsamplerChannelForm::setupAudioDevice (void)
561    {
562            setupDevice(m_audioDevices.at(AudioDeviceComboBox->currentItem()),
563                    qsamplerDevice::Audio, AudioDriverComboBox->currentText());
564    }
565    
566    
567    // Audio routing change slot.
568    void qsamplerChannelForm::changeAudioRouting ( int iRow, int iCol )
569    {
570            if (m_iDirtySetup > 0)
571                    return;
572            if (iRow < 0 || iCol < 0)
573                    return;
574    
575            // Verify that this is a QComboTableItem (magic rtti == 1)
576            QTableItem *pItem = AudioRoutingTable->item(iRow, iCol);
577            if (pItem == NULL)
578                    return;
579            qsamplerChannelRoutingComboBox *pComboItem =
580                    static_cast<qsamplerChannelRoutingComboBox*> (pItem);
581            // FIXME: Its not garanteed that we must have
582            // iAudioOut == iRow on all times forth!
583            m_audioRouting[iRow] = pComboItem->currentItem();
584    
585            // And let's get dirty...
586            optionsChanged();
587  }  }
588    
589    
590    // UPdate all device lists slot.
591    void qsamplerChannelForm::updateDevices (void)
592    {
593            if (m_iDirtySetup > 0)
594                    return;
595    
596            selectMidiDriverItem(MidiDriverComboBox->currentText());
597            selectAudioDriverItem(AudioDriverComboBox->currentText());
598            optionsChanged();
599    }
600    
601    
602  // Dirty up settings.  // Dirty up settings.
603  void qsamplerChannelForm::optionsChanged (void)  void qsamplerChannelForm::optionsChanged (void)
604  {  {
605      if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
606          return;                  return;
607    
608      m_iDirtyCount++;          m_iDirtyCount++;
609      stabilizeForm();          stabilizeForm();
610  }  }
611    
612    
613  // Stabilize current form state.  // Stabilize current form state.
614  void qsamplerChannelForm::stabilizeForm (void)  void qsamplerChannelForm::stabilizeForm (void)
615  {  {
616      const QString& sFilename = InstrumentFileComboBox->currentText();          const QString& sFilename = InstrumentFileComboBox->currentText();
617      OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());          OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
618  }  }
619    
620    
621  // end of qsamplerChannelForm.ui.h  // end of qsamplerChannelForm.ui.h
   

Legend:
Removed from v.344  
changed lines
  Added in v.767

  ViewVC Help
Powered by ViewVC