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

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

  ViewVC Help
Powered by ViewVC