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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1504 - (hide annotations) (download)
Wed Nov 21 11:46:40 2007 UTC (16 years, 5 months ago) by capela
File size: 23155 byte(s)
* Qt4 migration: Qt3Support is now scrapped.

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

  ViewVC Help
Powered by ViewVC