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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC