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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1510 - (show annotations) (download)
Thu Nov 22 14:17:24 2007 UTC (16 years, 4 months ago) by capela
File size: 23825 byte(s)
- Qt4 migration: code cleanup, personal standards beautification :)

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

  ViewVC Help
Powered by ViewVC