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

Legend:
Removed from v.299  
changed lines
  Added in v.980

  ViewVC Help
Powered by ViewVC