/[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 758 by capela, Sun Aug 28 00:31:34 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!          // We'll go for it!
206      if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
207          int iErrors = 0;                  int iErrors = 0;
208          // Are we a new channel?                  // Are we a new channel?
209          if (!m_pChannel->addChannel())                  if (!m_pChannel->addChannel())
210              iErrors++;                          iErrors++;
211          // Audio output driver type...                  // Accept Audio driver or device selection...
212          if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))                  if (m_audioDevices.isEmpty()) {
213              iErrors++;                          if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
214          // MIDI input driver type...                                  iErrors++;
215          if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))                  } else {
216              iErrors++;                          qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
217          // MIDI input port number...                          if (pDevice == NULL)
218          if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))                                  iErrors++;
219              iErrors++;                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
220          // MIDI input channel...                                  iErrors++;
221          if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))                          else if (!m_audioRouting.isEmpty()) {
222              iErrors++;                                  // Set the audio route changes...
223          // Engine name...                                  qsamplerChannelRoutingMap::ConstIterator iter;
224          if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))                                  for (iter = m_audioRouting.begin();
225              iErrors++;                                                  iter != m_audioRouting.end(); ++iter) {
226          // Instrument file and index...                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))
227          if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))                                                  iErrors++;
228              iErrors++;                                  }
229          // Show error messages?                          }
230          if (iErrors > 0)                  }
231              m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));                  // Accept MIDI driver or device selection...
232      }                  if (m_midiDevices.isEmpty()) {
233                            if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
234      // Save default engine name, instrument directory and history...                                  iErrors++;
235      pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);                  } else {
236      pOptions->sEngineName  = EngineNameComboBox->currentText();                          qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
237      pOptions->sAudioDriver = AudioDriverComboBox->currentText();                          if (pDevice == NULL)
238      pOptions->sMidiDriver  = MidiDriverComboBox->currentText();                                  iErrors++;
239      pOptions->saveComboBoxHistory(InstrumentFileComboBox);                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
240                                    iErrors++;
241                    }
242                    // MIDI input port number...
243                    if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
244                            iErrors++;
245                    // MIDI input channel...
246                    if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
247                            iErrors++;
248                    // Engine name...
249                    if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
250                            iErrors++;
251                    // Instrument file and index...
252                    if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
253                            iErrors++;
254                    // Show error messages?
255                    if (iErrors > 0)
256                            m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
257            }
258    
259            // Save default engine name, instrument directory and history...
260            pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
261            pOptions->sEngineName  = EngineNameComboBox->currentText();
262            pOptions->sAudioDriver = AudioDriverComboBox->currentText();
263            pOptions->sMidiDriver  = MidiDriverComboBox->currentText();
264            pOptions->saveComboBoxHistory(InstrumentFileComboBox);
265    
266      // Just go with dialog acceptance.          // Just go with dialog acceptance.
267      QDialog::accept();          QDialog::accept();
268  }  }
269    
270    
271  // Reject settings (Cancel button slot).  // Reject settings (Cancel button slot).
272  void qsamplerChannelForm::reject (void)  void qsamplerChannelForm::reject (void)
273  {  {
274      bool bReject = true;          bool bReject = true;
275    
276      // Check if there's any pending changes...          // Check if there's any pending changes...
277      if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
278          switch (QMessageBox::warning(this, tr("Warning"),                  switch (QMessageBox::warning(this,
279              tr("Some channel settings have been changed.\n\n"                          QSAMPLER_TITLE ": " + tr("Warning"),
280                 "Do you want to apply the changes?"),                          tr("Some channel settings have been changed.\n\n"
281              tr("Apply"), tr("Discard"), tr("Cancel"))) {                          "Do you want to apply the changes?"),
282          case 0:     // Apply...                          tr("Apply"), tr("Discard"), tr("Cancel"))) {
283              accept();                  case 0:     // Apply...
284              return;                          accept();
285          case 1:     // Discard                          return;
286              break;                  case 1:     // Discard
287          default:    // Cancel.                          break;
288              bReject = false;                  default:    // Cancel.
289          }                          bReject = false;
290      }                  }
291            }
292    
293      if (bReject)          if (bReject)
294          QDialog::reject();                  QDialog::reject();
295  }  }
296    
297    
298  // Browse and open an instrument file.  // Browse and open an instrument file.
299  void qsamplerChannelForm::openInstrumentFile (void)  void qsamplerChannelForm::openInstrumentFile (void)
300  {  {
301      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
302      if (pOptions == NULL)          if (pOptions == NULL)
303          return;                  return;
304    
305      // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
306      // depending on the current engine.          // depending on the current engine.
307      QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(
308              pOptions->sInstrumentDir,                   // Start here.                  pOptions->sInstrumentDir,                   // Start here.
309              tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)
310              this, 0,                                    // Parent and name (none)                  this, 0,                                    // Parent and name (none)
311              tr("Instrument files")                      // Caption.                  QSAMPLER_TITLE ": " + tr("Instrument files")    // Caption.
312      );          );
313    
314      if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
315          return;                  return;
316    
317      InstrumentFileComboBox->setCurrentText(sInstrumentFile);          InstrumentFileComboBox->setCurrentText(sInstrumentFile);
318            updateInstrumentName();
319  }  }
320    
321    
322  // Refresh the actual instrument name.  // Refresh the actual instrument name.
323  void qsamplerChannelForm::updateInstrumentName (void)  void qsamplerChannelForm::updateInstrumentName (void)
324  {  {
325      qsamplerOptions *pOptions = m_pChannel->options();          qsamplerOptions *pOptions = m_pChannel->options();
326      if (pOptions == NULL)          if (pOptions == NULL)
327          return;                  return;
328    
329      // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
330      // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
331      InstrumentNrComboBox->clear();          InstrumentNrComboBox->clear();
332      InstrumentNrComboBox->insertStringList(          InstrumentNrComboBox->insertStringList(
333          qsamplerChannel::getInstrumentList(                  qsamplerChannel::getInstrumentList(
334                          InstrumentFileComboBox->currentText(),                          InstrumentFileComboBox->currentText(),
335                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
336      );          );
337    
338            optionsChanged();
339    }
340    
341    // Show device options dialog.
342    void qsamplerChannelForm::setupDevice ( qsamplerDevice *pDevice,
343            qsamplerDevice::qsamplerDeviceType deviceTypeMode,
344            const QString& sDriverName )
345    {
346            // Create the device form if not already...
347            if (m_pDeviceForm == NULL) {
348                    m_pDeviceForm = new qsamplerDeviceForm(this, 0,
349                            WType_Dialog | WShowModal);
350                    m_pDeviceForm->setMainForm(m_pChannel->mainForm());
351                    QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
352                            this, SLOT(updateDevices()));
353            }
354    
355            // Refresh the device form with selected data.
356            if (m_pDeviceForm) {
357                    m_pDeviceForm->setDeviceTypeMode(deviceTypeMode);
358                    m_pDeviceForm->setClient(m_pChannel->client()); // -> refreshDevices();
359                    m_pDeviceForm->setDevice(pDevice);
360                    m_pDeviceForm->setDriverName(sDriverName);
361                    m_pDeviceForm->show();
362            }
363    }
364    
365    
366    // Refresh MIDI driver item devices.
367    void qsamplerChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
368    {
369            const QString sDriverName = sMidiDriver.upper();
370    
371            // Save current device id.
372            int iDeviceID = -1;
373            qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
374            if (pDevice)
375                    iDeviceID = pDevice->deviceID();
376    
377            // Clean maplist.
378            MidiDeviceComboBox->clear();
379            m_midiDevices.clear();
380    
381            // Populate with the current ones...
382            const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png");
383            int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
384                    qsamplerDevice::Midi);
385            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
386                    pDevice = new qsamplerDevice(m_pChannel->mainForm(),
387                            qsamplerDevice::Midi, piDeviceIDs[i]);
388                    if (pDevice->driverName().upper() == sDriverName) {
389                            MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());
390                            m_midiDevices.append(pDevice);
391                    } else {
392                            delete pDevice;
393                    }
394            }
395    
396            // Do proper enabling...
397            bool bEnabled = !m_midiDevices.isEmpty();
398            if (!bEnabled) {
399                    MidiDeviceComboBox->insertItem(
400                            tr("(New MIDI %1 device)").arg(sMidiDriver));
401            } else if (iDeviceID >= 0) {
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            }
415            MidiDeviceTextLabel->setEnabled(bEnabled);
416            MidiDeviceComboBox->setEnabled(bEnabled);
417    }
418    
419    
420      optionsChanged();  // Refresh MIDI device options slot.
421    void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver )
422    {
423            if (m_iDirtySetup > 0)
424                    return;
425    
426            selectMidiDriverItem(sMidiDriver);
427            optionsChanged();
428    }
429    
430    
431    // Select MIDI device item.
432    void qsamplerChannelForm::selectMidiDeviceItem ( int iMidiItem )
433    {
434            qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);
435            if (pDevice) {
436                    const qsamplerDeviceParamMap& params = pDevice->params();
437                    int iPorts = params["PORTS"].value.toInt();
438                    MidiPortTextLabel->setEnabled(iPorts > 0);
439                    MidiPortSpinBox->setEnabled(iPorts > 0);
440                    if (iPorts > 0)
441                            MidiPortSpinBox->setMaxValue(iPorts - 1);
442            }
443    }
444    
445    
446    // Select MIDI device options slot.
447    void qsamplerChannelForm::selectMidiDevice ( int iMidiItem )
448    {
449            if (m_iDirtySetup > 0)
450                    return;
451    
452            selectMidiDeviceItem(iMidiItem);
453            optionsChanged();
454    }
455    
456    
457    // MIDI device options.
458    void qsamplerChannelForm::setupMidiDevice (void)
459    {
460            setupDevice(m_midiDevices.at(MidiDeviceComboBox->currentItem()),
461                    qsamplerDevice::Midi, MidiDriverComboBox->currentText());
462  }  }
463    
464    
465    // Refresh Audio driver item devices.
466    void qsamplerChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
467    {
468            const QString sDriverName = sAudioDriver.upper();
469    
470            // Save current device id.
471            int iDeviceID = -1;
472            qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
473            if (pDevice)
474                    iDeviceID = pDevice->deviceID();
475    
476            // Clean maplist.
477            AudioDeviceComboBox->clear();
478            m_audioDevices.clear();
479    
480            // Populate with the current ones...
481            const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png");
482            int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
483                    qsamplerDevice::Audio);
484            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
485                    pDevice = new qsamplerDevice(m_pChannel->mainForm(),
486                            qsamplerDevice::Audio, piDeviceIDs[i]);
487                    if (pDevice->driverName().upper() == sDriverName) {
488                            AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());
489                            m_audioDevices.append(pDevice);
490                    } else {
491                            delete pDevice;
492                    }
493            }
494    
495            // Do proper enabling...
496            bool bEnabled = !m_audioDevices.isEmpty();
497            if (!bEnabled) {
498                    AudioDeviceComboBox->insertItem(
499                            tr("(New Audio %1 device)").arg(sAudioDriver));
500            } else if (iDeviceID >= 0) {
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            }
514            AudioDeviceTextLabel->setEnabled(bEnabled);
515            AudioDeviceComboBox->setEnabled(bEnabled);
516            AudioRoutingTable->setEnabled(bEnabled);
517            if (!bEnabled)
518                    AudioRoutingTable->setNumRows(0);
519    }
520    
521    
522    // Refresh Audio device options slot.
523    void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver )
524    {
525            if (m_iDirtySetup > 0)
526                    return;
527    
528            selectAudioDriverItem(sAudioDriver);
529            optionsChanged();
530    }
531    
532    
533    // Select Audio device item.
534    void qsamplerChannelForm::selectAudioDeviceItem ( int iAudioItem )
535    {
536            qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);
537            if (pDevice) {
538                    // Refresh the audio routing table.
539                    AudioRoutingTable->refresh(pDevice, m_pChannel->audioRouting());
540                    // Reset routing change map.
541                    m_audioRouting.clear();
542            }
543    }
544    
545    
546    // Select Audio device options slot.
547    void qsamplerChannelForm::selectAudioDevice ( int iAudioItem )
548    {
549            if (m_iDirtySetup > 0)
550                    return;
551    
552            selectAudioDeviceItem(iAudioItem);
553            optionsChanged();
554    }
555    
556    
557    // Audio device options.
558    void qsamplerChannelForm::setupAudioDevice (void)
559    {
560            setupDevice(m_audioDevices.at(AudioDeviceComboBox->currentItem()),
561                    qsamplerDevice::Audio, AudioDriverComboBox->currentText());
562    }
563    
564    
565    // Audio routing change slot.
566    void qsamplerChannelForm::changeAudioRouting ( int iRow, int iCol )
567    {
568            if (m_iDirtySetup > 0)
569                    return;
570            if (iRow < 0 || iCol < 0)
571                    return;
572    
573            // Verify that this is a QComboTableItem (magic rtti == 1)
574            QTableItem *pItem = AudioRoutingTable->item(iRow, iCol);
575            if (pItem == NULL)
576                    return;
577            if (pItem->rtti() == 1) {       // 1 == QComboTableItem
578                    QComboTableItem *pComboItem = (QComboTableItem *) pItem;
579                    // FIXME: Its not garanteed that we must have
580                    // iAudioOut == iRow on all times forth!
581                    m_audioRouting[iRow] = pComboItem->currentItem();
582                    // And let's get dirty...
583                    m_iDirtyCount++;
584            }
585    }
586    
587    
588    // UPdate all device lists slot.
589    void qsamplerChannelForm::updateDevices (void)
590    {
591            if (m_iDirtySetup > 0)
592                    return;
593    
594            selectMidiDriverItem(MidiDriverComboBox->currentText());
595            selectAudioDriverItem(AudioDriverComboBox->currentText());
596            optionsChanged();
597    }
598    
599    
600  // Dirty up settings.  // Dirty up settings.
601  void qsamplerChannelForm::optionsChanged (void)  void qsamplerChannelForm::optionsChanged (void)
602  {  {
603      if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
604          return;                  return;
605    
606      m_iDirtyCount++;          m_iDirtyCount++;
607      stabilizeForm();          stabilizeForm();
608  }  }
609    
610    
611  // Stabilize current form state.  // Stabilize current form state.
612  void qsamplerChannelForm::stabilizeForm (void)  void qsamplerChannelForm::stabilizeForm (void)
613  {  {
614      const QString& sFilename = InstrumentFileComboBox->currentText();          const QString& sFilename = InstrumentFileComboBox->currentText();
615      OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());          OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
616  }  }
617    
618    
619  // end of qsamplerChannelForm.ui.h  // end of qsamplerChannelForm.ui.h
   

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

  ViewVC Help
Powered by ViewVC