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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1505 - (hide annotations) (download)
Wed Nov 21 18:37:40 2007 UTC (16 years, 4 months ago) by capela
File size: 23058 byte(s)
- Qt4 migration: small step to squash bug leftovers,
  plenty still in the horizon.

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 1505 ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
210 schoenebeck 1461 ui.InstrumentNrComboBox->clear();
211 capela 1499 ui.InstrumentNrComboBox->insertItems(0,
212 schoenebeck 1461 qsamplerChannel::getInstrumentList(sInstrumentFile,
213     pOptions->bInstrumentNames));
214 capela 1499 ui.InstrumentNrComboBox->setCurrentIndex(pChannel->instrumentNr());
215 schoenebeck 1461
216     // MIDI input device...
217     qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());
218     // MIDI input driver...
219     QString sMidiDriver = midiDevice.driverName();
220     if (sMidiDriver.isEmpty() || bNew)
221 capela 1499 sMidiDriver = pOptions->sMidiDriver.toUpper();
222 schoenebeck 1461 if (!sMidiDriver.isEmpty()) {
223     if (ui.MidiDriverComboBox->findText(sMidiDriver,
224 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
225 capela 1499 ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
226 schoenebeck 1461 }
227 capela 1499 ui.MidiDriverComboBox->setItemText(
228     ui.MidiDriverComboBox->currentIndex(),
229     sMidiDriver);
230 schoenebeck 1461 }
231     selectMidiDriverItem(sMidiDriver);
232 capela 1499 if (!bNew) {
233     ui.MidiDeviceComboBox->setItemText(
234     ui.MidiDeviceComboBox->currentIndex(),
235     midiDevice.deviceName());
236     }
237     selectMidiDeviceItem(ui.MidiDeviceComboBox->currentIndex());
238 schoenebeck 1461 // MIDI input port...
239     ui.MidiPortSpinBox->setValue(pChannel->midiPort());
240     // MIDI input channel...
241     int iMidiChannel = pChannel->midiChannel();
242     // When new, try to suggest a sensible MIDI channel...
243     if (iMidiChannel < 0)
244     iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);
245 capela 1499 ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
246 schoenebeck 1461 // MIDI instrument map...
247     int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());
248     // When new, try to suggest a sensible MIDI map...
249     if (iMidiMap < 0)
250     iMidiMap = 0;
251     const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);
252 capela 1499 if (!sMapName.isEmpty()) {
253     ui.MidiMapComboBox->setItemText(
254     ui.MidiMapComboBox->currentIndex(),
255     sMapName);
256     }
257 schoenebeck 1461 // It might be no maps around...
258     bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0);
259     ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
260     ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
261    
262     // Audio output device...
263     qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice());
264     // Audio output driver...
265     QString sAudioDriver = audioDevice.driverName();
266     if (sAudioDriver.isEmpty() || bNew)
267 capela 1499 sAudioDriver = pOptions->sAudioDriver.toUpper();
268 schoenebeck 1461 if (!sAudioDriver.isEmpty()) {
269     if (ui.AudioDriverComboBox->findText(sAudioDriver,
270 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
271 capela 1499 ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
272 schoenebeck 1461 }
273 capela 1499 ui.AudioDriverComboBox->setItemText(
274     ui.AudioDriverComboBox->currentIndex(),
275     sAudioDriver);
276 schoenebeck 1461 }
277     selectAudioDriverItem(sAudioDriver);
278 capela 1499 if (!bNew) {
279     ui.AudioDeviceComboBox->setItemText(
280     ui.AudioDeviceComboBox->currentIndex(),
281     audioDevice.deviceName());
282     }
283     selectAudioDeviceItem(ui.AudioDeviceComboBox->currentIndex());
284 schoenebeck 1461
285     // As convenient, make it ready on stabilizeForm() for
286     // prompt acceptance, if we got the minimum required...
287     /* if (sEngineName != qsamplerChannel::noEngineName() &&
288     sInstrumentFile != qsamplerChannel::noInstrumentName())
289     m_iDirtyCount++; */
290     // Done.
291     m_iDirtySetup--;
292     stabilizeForm();
293     }
294    
295    
296     // Accept settings (OK button slot).
297     void ChannelForm::accept (void)
298     {
299     if (m_pChannel == NULL)
300     return;
301    
302     MainForm *pMainForm = MainForm::getInstance();
303     if (pMainForm == NULL)
304     return;
305     if (pMainForm->client() == NULL)
306     return;
307    
308     qsamplerOptions *pOptions = pMainForm->options();
309     if (pOptions == NULL)
310     return;
311    
312     // Flush any pending editing...
313     //ui.AudioRoutingTable->flush();
314    
315     // We'll go for it!
316     if (m_iDirtyCount > 0) {
317     int iErrors = 0;
318     // Are we a new channel?
319     if (!m_pChannel->addChannel())
320     iErrors++;
321     // Accept Audio driver or device selection...
322     if (m_audioDevices.isEmpty()) {
323     if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText()))
324     iErrors++;
325     } else {
326 capela 1504 qsamplerDevice *pDevice = NULL;
327     int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
328     if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
329     pDevice = m_audioDevices.at(iAudioItem);
330 schoenebeck 1489 qsamplerChannelRoutingMap routingMap = routingModel.routingMap();
331 schoenebeck 1461 if (pDevice == NULL)
332     iErrors++;
333     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
334     iErrors++;
335 schoenebeck 1489 else if (!routingMap.isEmpty()) {
336 schoenebeck 1461 // Set the audio route changes...
337     qsamplerChannelRoutingMap::ConstIterator iter;
338 schoenebeck 1489 for (iter = routingMap.begin();
339     iter != routingMap.end(); ++iter) {
340 capela 1499 if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
341 schoenebeck 1461 iErrors++;
342     }
343     }
344     }
345     // Accept MIDI driver or device selection...
346     if (m_midiDevices.isEmpty()) {
347     if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText()))
348     iErrors++;
349     } else {
350 capela 1504 qsamplerDevice *pDevice = NULL;
351     int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
352     if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
353     pDevice = m_midiDevices.at(iMidiItem);
354 schoenebeck 1461 if (pDevice == NULL)
355     iErrors++;
356     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
357     iErrors++;
358     }
359     // MIDI input port number...
360     if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value()))
361     iErrors++;
362     // MIDI input channel...
363 capela 1499 if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentIndex()))
364 schoenebeck 1461 iErrors++;
365     // Engine name...
366     if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText()))
367     iErrors++;
368     // Instrument file and index...
369     const QString& sPath = ui.InstrumentFileComboBox->currentText();
370     if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
371 capela 1499 if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentIndex()))
372 schoenebeck 1461 iErrors++;
373     }
374     // MIDI intrument map...
375 capela 1499 if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentIndex()))
376 schoenebeck 1461 iErrors++;
377     // Show error messages?
378     if (iErrors > 0)
379     m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
380     }
381    
382     // Save default engine name, instrument directory and history...
383 capela 1499 pOptions->sInstrumentDir = QFileInfo(
384     ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
385 schoenebeck 1461 pOptions->sEngineName = ui.EngineNameComboBox->currentText();
386     pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText();
387     pOptions->sMidiDriver = ui.MidiDriverComboBox->currentText();
388 capela 1499 pOptions->iMidiMap = ui.MidiMapComboBox->currentIndex();
389 schoenebeck 1461 pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);
390    
391     // Just go with dialog acceptance.
392     QDialog::accept();
393     }
394    
395    
396     // Reject settings (Cancel button slot).
397     void ChannelForm::reject (void)
398     {
399     bool bReject = true;
400    
401     // Check if there's any pending changes...
402     if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) {
403     switch (QMessageBox::warning(this,
404     QSAMPLER_TITLE ": " + tr("Warning"),
405     tr("Some channel settings have been changed.\n\n"
406     "Do you want to apply the changes?"),
407     tr("Apply"), tr("Discard"), tr("Cancel"))) {
408     case 0: // Apply...
409     accept();
410     return;
411     case 1: // Discard
412     break;
413     default: // Cancel.
414     bReject = false;
415     break;
416     }
417     }
418    
419     if (bReject)
420     QDialog::reject();
421     }
422    
423    
424     // Browse and open an instrument file.
425     void ChannelForm::openInstrumentFile (void)
426     {
427     MainForm *pMainForm = MainForm::getInstance();
428     if (pMainForm == NULL)
429     return;
430     if (pMainForm->client() == NULL)
431     return;
432    
433     qsamplerOptions *pOptions = pMainForm->options();
434     if (pOptions == NULL)
435     return;
436    
437     // FIXME: the instrument file filters should be restricted,
438     // depending on the current engine.
439 capela 1499 QString sInstrumentFile = QFileDialog::getOpenFileName(this,
440     QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
441     pOptions->sInstrumentDir, // Start here.
442     tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
443 schoenebeck 1461 );
444    
445     if (sInstrumentFile.isEmpty())
446     return;
447    
448 capela 1505 ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
449 schoenebeck 1461 updateInstrumentName();
450     }
451    
452    
453     // Refresh the actual instrument name.
454     void ChannelForm::updateInstrumentName (void)
455     {
456     MainForm *pMainForm = MainForm::getInstance();
457     if (pMainForm == NULL)
458     return;
459     if (pMainForm->client() == NULL)
460     return;
461    
462     qsamplerOptions *pOptions = pMainForm->options();
463     if (pOptions == NULL)
464     return;
465    
466     // Finally this better idea would be to use libgig
467     // to retrieve the REAL instrument names.
468     ui.InstrumentNrComboBox->clear();
469 capela 1499 ui.InstrumentNrComboBox->insertItems(0,
470 schoenebeck 1461 qsamplerChannel::getInstrumentList(
471     ui.InstrumentFileComboBox->currentText(),
472     pOptions->bInstrumentNames)
473     );
474    
475     optionsChanged();
476     }
477    
478    
479     // Show device options dialog.
480     void ChannelForm::setupDevice ( qsamplerDevice *pDevice,
481     qsamplerDevice::qsamplerDeviceType deviceTypeMode,
482     const QString& sDriverName )
483     {
484 capela 1504 if (pDevice == NULL)
485     return;
486    
487 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
488     if (pMainForm == NULL)
489     return;
490     if (pMainForm->client() == NULL)
491     return;
492    
493     // Create the device form if not already...
494     if (m_pDeviceForm == NULL) {
495     m_pDeviceForm = new DeviceForm(this, Qt::Dialog);
496     m_pDeviceForm->setAttribute(Qt::WA_ShowModal);
497     QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
498     this, SLOT(updateDevices()));
499     }
500    
501     // Refresh the device form with selected data.
502     if (m_pDeviceForm) {
503     m_pDeviceForm->setDeviceTypeMode(deviceTypeMode);
504     m_pDeviceForm->refreshDevices();
505     m_pDeviceForm->setDevice(pDevice);
506     m_pDeviceForm->setDriverName(sDriverName);
507     m_pDeviceForm->show();
508     }
509     }
510    
511    
512     // Refresh MIDI driver item devices.
513     void ChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
514     {
515     MainForm *pMainForm = MainForm::getInstance();
516     if (pMainForm == NULL)
517     return;
518     if (pMainForm->client() == NULL)
519     return;
520    
521 capela 1499 const QString sDriverName = sMidiDriver.toUpper();
522 schoenebeck 1461
523     // Save current device id.
524 capela 1504 // Save current device id.
525 schoenebeck 1461 int iDeviceID = 0;
526 capela 1504 qsamplerDevice *pDevice = NULL;
527     int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
528     if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
529     pDevice = m_midiDevices.at(iMidiItem);
530 schoenebeck 1461 if (pDevice)
531     iDeviceID = pDevice->deviceID();
532    
533     // Clean maplist.
534     ui.MidiDeviceComboBox->clear();
535 capela 1499 qDeleteAll(m_midiDevices);
536 schoenebeck 1461 m_midiDevices.clear();
537    
538     // Populate with the current ones...
539 schoenebeck 1489 const QPixmap midiPixmap(":/icons/midi2.png");
540 schoenebeck 1461 int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
541     qsamplerDevice::Midi);
542     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
543     pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);
544 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
545     ui.MidiDeviceComboBox->insertItem(0, midiPixmap, pDevice->deviceName());
546 schoenebeck 1461 m_midiDevices.append(pDevice);
547     } else {
548     delete pDevice;
549     }
550     }
551    
552     // Do proper enabling...
553     bool bEnabled = !m_midiDevices.isEmpty();
554     if (bEnabled) {
555     // Select the previous current device...
556 capela 1504 iMidiItem = 0;
557 capela 1499 QListIterator<qsamplerDevice *> iter(m_midiDevices);
558     while (iter.hasNext()) {
559     pDevice = iter.next();
560 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
561 capela 1499 ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
562 schoenebeck 1461 selectMidiDeviceItem(iMidiItem);
563     break;
564     }
565     iMidiItem++;
566     }
567     } else {
568 capela 1499 ui.MidiDeviceComboBox->insertItem(0,
569 schoenebeck 1461 tr("(New MIDI %1 device)").arg(sMidiDriver));
570     }
571     ui.MidiDeviceTextLabel->setEnabled(bEnabled);
572     ui.MidiDeviceComboBox->setEnabled(bEnabled);
573     }
574    
575    
576     // Refresh MIDI device options slot.
577     void ChannelForm::selectMidiDriver ( const QString& sMidiDriver )
578     {
579     if (m_iDirtySetup > 0)
580     return;
581    
582     selectMidiDriverItem(sMidiDriver);
583     optionsChanged();
584     }
585    
586    
587     // Select MIDI device item.
588     void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
589     {
590 capela 1504 qsamplerDevice *pDevice = NULL;
591     if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
592     pDevice = m_midiDevices.at(iMidiItem);
593 schoenebeck 1461 if (pDevice) {
594     const qsamplerDeviceParamMap& params = pDevice->params();
595     int iPorts = params["PORTS"].value.toInt();
596     ui.MidiPortTextLabel->setEnabled(iPorts > 0);
597     ui.MidiPortSpinBox->setEnabled(iPorts > 0);
598     if (iPorts > 0)
599 capela 1499 ui.MidiPortSpinBox->setMaximum(iPorts - 1);
600 schoenebeck 1461 }
601     }
602    
603    
604     // Select MIDI device options slot.
605     void ChannelForm::selectMidiDevice ( int iMidiItem )
606     {
607     if (m_iDirtySetup > 0)
608     return;
609    
610     selectMidiDeviceItem(iMidiItem);
611     optionsChanged();
612     }
613    
614    
615     // MIDI device options.
616     void ChannelForm::setupMidiDevice (void)
617     {
618 capela 1504 qsamplerDevice *pDevice = NULL;
619     int iMidiItem = ui.MidiDeviceComboBox->currentIndex();
620     if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
621     pDevice = m_midiDevices.at(iMidiItem);
622     setupDevice(pDevice,
623 schoenebeck 1461 qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText());
624     }
625    
626    
627     // Refresh Audio driver item devices.
628     void ChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
629     {
630     MainForm *pMainForm = MainForm::getInstance();
631     if (pMainForm == NULL)
632     return;
633     if (pMainForm->client() == NULL)
634     return;
635    
636 capela 1499 const QString sDriverName = sAudioDriver.toUpper();
637 schoenebeck 1461
638     // Save current device id.
639     int iDeviceID = 0;
640 capela 1504 qsamplerDevice *pDevice = NULL;
641     int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
642     if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
643     pDevice = m_audioDevices.at(iAudioItem);
644 schoenebeck 1461 if (pDevice)
645     iDeviceID = pDevice->deviceID();
646    
647     // Clean maplist.
648     ui.AudioDeviceComboBox->clear();
649 capela 1499 qDeleteAll(m_audioDevices);
650 schoenebeck 1461 m_audioDevices.clear();
651    
652     // Populate with the current ones...
653 schoenebeck 1489 const QPixmap audioPixmap(":/icons/audio2.png");
654 schoenebeck 1461 int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
655     qsamplerDevice::Audio);
656     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
657     pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);
658 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
659     ui.AudioDeviceComboBox->insertItem(0, audioPixmap, pDevice->deviceName());
660 schoenebeck 1461 m_audioDevices.append(pDevice);
661     } else {
662     delete pDevice;
663     }
664     }
665    
666     // Do proper enabling...
667     bool bEnabled = !m_audioDevices.isEmpty();
668     if (bEnabled) {
669     // Select the previous current device...
670 capela 1504 iAudioItem = 0;
671 capela 1499 QListIterator<qsamplerDevice *> iter(m_audioDevices);
672     while (iter.hasNext()) {
673     pDevice = iter.next();
674 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
675 capela 1499 ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
676 schoenebeck 1461 selectAudioDeviceItem(iAudioItem);
677     break;
678     }
679     iAudioItem++;
680     }
681     } else {
682 capela 1499 ui.AudioDeviceComboBox->insertItem(0,
683 schoenebeck 1461 tr("(New Audio %1 device)").arg(sAudioDriver));
684     //ui.AudioRoutingTable->setNumRows(0);
685     }
686     ui.AudioDeviceTextLabel->setEnabled(bEnabled);
687     ui.AudioDeviceComboBox->setEnabled(bEnabled);
688     ui.AudioRoutingTable->setEnabled(bEnabled);
689     }
690    
691    
692     // Refresh Audio device options slot.
693     void ChannelForm::selectAudioDriver ( const QString& sAudioDriver )
694     {
695     if (m_iDirtySetup > 0)
696     return;
697    
698     selectAudioDriverItem(sAudioDriver);
699     optionsChanged();
700     }
701    
702    
703     // Select Audio device item.
704     void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
705     {
706 capela 1504 qsamplerDevice *pDevice = NULL;
707     if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
708     pDevice = m_audioDevices.at(iAudioItem);
709 schoenebeck 1461 if (pDevice) {
710     // Refresh the audio routing table.
711     routingModel.refresh(pDevice, m_pChannel->audioRouting());
712     // Reset routing change map.
713 schoenebeck 1489 routingModel.clear();
714 schoenebeck 1461 }
715     }
716    
717    
718     // Select Audio device options slot.
719     void ChannelForm::selectAudioDevice ( int iAudioItem )
720     {
721     if (m_iDirtySetup > 0)
722     return;
723    
724     selectAudioDeviceItem(iAudioItem);
725     optionsChanged();
726     }
727    
728    
729     // Audio device options.
730     void ChannelForm::setupAudioDevice (void)
731     {
732 capela 1504 qsamplerDevice *pDevice = NULL;
733     int iAudioItem = ui.AudioDeviceComboBox->currentIndex();
734     if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
735     pDevice = m_audioDevices.at(iAudioItem);
736     setupDevice(pDevice,
737 schoenebeck 1461 qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());
738     }
739    
740     // UPdate all device lists slot.
741     void ChannelForm::updateDevices (void)
742     {
743     if (m_iDirtySetup > 0)
744     return;
745    
746     selectMidiDriverItem(ui.MidiDriverComboBox->currentText());
747     selectAudioDriverItem(ui.AudioDriverComboBox->currentText());
748     optionsChanged();
749     }
750    
751    
752     // Dirty up settings.
753     void ChannelForm::optionsChanged (void)
754     {
755     if (m_iDirtySetup > 0)
756     return;
757    
758     m_iDirtyCount++;
759     stabilizeForm();
760     }
761    
762    
763     // Stabilize current form state.
764     void ChannelForm::stabilizeForm (void)
765     {
766     bool bValid = true;
767     #if 0
768     const QString& sPath = InstrumentFileComboBox->currentText();
769     bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
770     #endif
771     ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
772     }
773    
774 schoenebeck 1489 void ChannelForm::updateTableCellRenderers() {
775     const int rows = routingModel.rowCount();
776     const int cols = routingModel.columnCount();
777     updateTableCellRenderers(routingModel.index(0,0),routingModel.index(rows-1,cols-1));
778     }
779 schoenebeck 1461
780 schoenebeck 1489 void ChannelForm::updateTableCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
781     for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
782     for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
783     const QModelIndex index = routingModel.index(r,c);
784     ui.AudioRoutingTable->openPersistentEditor(index);
785     }
786     }
787     }
788    
789 schoenebeck 1461 } // namespace QSampler
790 capela 1464
791    
792     // end of qsamplerChannelForm.cpp

  ViewVC Help
Powered by ViewVC