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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC