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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1527 - (show annotations) (download)
Mon Nov 26 16:00:21 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 24316 byte(s)
* Added recent new support of libgig for retrieving instrument names in a
  very fast way. If libgig provides this feature, then the respective
  name retrieval setting in qsampler is enabled by default.

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

  ViewVC Help
Powered by ViewVC