/[svn]/qsampler/trunk/src/qsamplerChannelForm.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannelForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1474 - (hide annotations) (download)
Mon Nov 5 20:47:38 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 21270 byte(s)
* Qt4 migration: fixed another bunch of ghost connections, fixed engine
  combo box in channel form, fixed stdout ouptut in message window (a lot
  of white lines were shown), show channel strip on the work space (and not
  in the nirvana of the desktop universe)

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

  ViewVC Help
Powered by ViewVC