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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1489 - (hide annotations) (download)
Mon Nov 19 03:29:57 2007 UTC (16 years, 4 months ago) by schoenebeck
File size: 21710 byte(s)
* Qt4 migration: finished channel setup dialog
* cosmetical fixes of channel strip

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

  ViewVC Help
Powered by ViewVC