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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2387 - (hide 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 capela 1464 // qsamplerChannelForm.cpp
2     //
3     /****************************************************************************
4 capela 2387 Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1710 Copyright (C) 2007, 2008 Christian Schoenebeck
6 capela 1464
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21     *****************************************************************************/
22    
23 schoenebeck 1461 #include "qsamplerChannelForm.h"
24    
25     #include "qsamplerAbout.h"
26     #include "qsamplerDeviceForm.h"
27    
28     #include "qsamplerMainForm.h"
29     #include "qsamplerInstrument.h"
30    
31 capela 1499 #include <QValidator>
32     #include <QMessageBox>
33     #include <QFileDialog>
34     #include <QFileInfo>
35 schoenebeck 1461
36 capela 1499 #include <QHeaderView>
37    
38    
39 schoenebeck 1461 namespace QSampler {
40    
41 capela 1558 //-------------------------------------------------------------------------
42     // QSampler::Channelform -- Channel form implementation.
43     //
44    
45 capela 1509 ChannelForm::ChannelForm ( QWidget* pParent )
46     : QDialog(pParent)
47     {
48 capela 1510 m_ui.setupUi(this);
49 schoenebeck 1461
50     // Initialize locals.
51     m_pChannel = NULL;
52    
53     m_iDirtySetup = 0;
54     m_iDirtyCount = 0;
55    
56 capela 1499 // m_midiDevices.setAutoDelete(true);
57     // m_audioDevices.setAutoDelete(true);
58 schoenebeck 1461
59     m_pDeviceForm = NULL;
60    
61 capela 1519 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 capela 1509 m_ui.AudioRoutingTable->setModel(&m_routingModel);
66     m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate);
67 capela 2387 #if QT_VERSION < 0x050000
68 capela 1509 m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
69 capela 2387 #endif
70 capela 1509 // m_ui.AudioRoutingTable->verticalHeader()->hide();
71    
72     // This goes initially hidden, and will be shown
73 capela 1510 // on setup() for currently existing channels...
74 capela 1509 m_ui.AudioRoutingTable->hide();
75    
76 schoenebeck 1461 // Try to restore normal window positioning.
77     adjustSize();
78 capela 1466
79 capela 1509 QObject::connect(m_ui.EngineNameComboBox,
80 capela 1466 SIGNAL(activated(int)),
81     SLOT(optionsChanged()));
82 capela 1509 QObject::connect(m_ui.InstrumentFileComboBox,
83 schoenebeck 1474 SIGNAL(activated(const QString&)),
84 capela 1466 SLOT(updateInstrumentName()));
85 capela 1509 QObject::connect(m_ui.InstrumentFileToolButton,
86 capela 1466 SIGNAL(clicked()),
87     SLOT(openInstrumentFile()));
88 capela 1509 QObject::connect(m_ui.InstrumentNrComboBox,
89 capela 1466 SIGNAL(activated(int)),
90     SLOT(optionsChanged()));
91 capela 1509 QObject::connect(m_ui.MidiDriverComboBox,
92 schoenebeck 1474 SIGNAL(activated(const QString&)),
93     SLOT(selectMidiDriver(const QString&)));
94 capela 1509 QObject::connect(m_ui.MidiDeviceComboBox,
95 capela 1466 SIGNAL(activated(int)),
96     SLOT(selectMidiDevice(int)));
97 capela 1509 QObject::connect(m_ui.MidiPortSpinBox,
98 capela 1466 SIGNAL(valueChanged(int)),
99     SLOT(optionsChanged()));
100 capela 1509 QObject::connect(m_ui.MidiChannelComboBox,
101 capela 1466 SIGNAL(activated(int)),
102     SLOT(optionsChanged()));
103 capela 1509 QObject::connect(m_ui.MidiMapComboBox,
104 capela 1466 SIGNAL(activated(int)),
105     SLOT(optionsChanged()));
106 capela 1509 QObject::connect(m_ui.AudioDriverComboBox,
107 schoenebeck 1474 SIGNAL(activated(const QString&)),
108     SLOT(selectAudioDriver(const QString&)));
109 capela 1509 QObject::connect(m_ui.AudioDeviceComboBox,
110 capela 1466 SIGNAL(activated(int)),
111     SLOT(selectAudioDevice(int)));
112 capela 2107 QObject::connect(m_ui.DialogButtonBox,
113     SIGNAL(accepted()),
114 capela 1466 SLOT(accept()));
115 capela 2107 QObject::connect(m_ui.DialogButtonBox,
116     SIGNAL(rejected()),
117 capela 1466 SLOT(reject()));
118 capela 1509 QObject::connect(m_ui.MidiDeviceToolButton,
119 capela 1466 SIGNAL(clicked()),
120     SLOT(setupMidiDevice()));
121 capela 1509 QObject::connect(m_ui.AudioDeviceToolButton,
122 capela 1466 SIGNAL(clicked()),
123     SLOT(setupAudioDevice()));
124 capela 1509 QObject::connect(&m_routingModel,
125 schoenebeck 1489 SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
126     SLOT(optionsChanged()));
127 capela 1509 QObject::connect(&m_routingModel,
128 schoenebeck 1489 SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
129     SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));
130 capela 1509 QObject::connect(&m_routingModel,
131 schoenebeck 1489 SIGNAL(modelReset()),
132     SLOT(updateTableCellRenderers()));
133 schoenebeck 1461 }
134    
135 capela 1499 ChannelForm::~ChannelForm()
136     {
137 schoenebeck 1461 if (m_pDeviceForm)
138     delete m_pDeviceForm;
139     m_pDeviceForm = NULL;
140 capela 1499
141     qDeleteAll(m_midiDevices);
142     m_midiDevices.clear();
143    
144     qDeleteAll(m_audioDevices);
145     m_audioDevices.clear();
146 schoenebeck 1461 }
147    
148    
149     // Channel dialog setup formal initializer.
150 capela 1558 void ChannelForm::setup ( Channel *pChannel )
151 schoenebeck 1461 {
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 schoenebeck 1710 const bool bNew = (m_pChannel->channelID() < 0);
162 capela 1499 setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName());
163 schoenebeck 1461
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 capela 1558 Options *pOptions = pMainForm->options();
172 schoenebeck 1461 if (pOptions == NULL)
173     return;
174    
175     // Avoid nested changes.
176     m_iDirtySetup++;
177    
178     // Load combo box history...
179 capela 1509 pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);
180 schoenebeck 1461
181     // Populate Engines list.
182     const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
183     if (ppszEngines) {
184 capela 1509 m_ui.EngineNameComboBox->clear();
185 schoenebeck 1461 for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
186 capela 1509 m_ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));
187 schoenebeck 1461 }
188     else m_pChannel->appendMessagesClient("lscp_list_available_engines");
189    
190     // Populate Audio output type list.
191 capela 1509 m_ui.AudioDriverComboBox->clear();
192     m_ui.AudioDriverComboBox->insertItems(0,
193 capela 1558 Device::getDrivers(pMainForm->client(), Device::Audio));
194 schoenebeck 1461
195     // Populate MIDI input type list.
196 capela 1509 m_ui.MidiDriverComboBox->clear();
197     m_ui.MidiDriverComboBox->insertItems(0,
198 capela 1558 Device::getDrivers(pMainForm->client(), Device::Midi));
199 schoenebeck 1461
200     // Populate Maps list.
201 capela 1509 m_ui.MidiMapComboBox->clear();
202     m_ui.MidiMapComboBox->insertItems(0,
203 capela 1558 Instrument::getMapNames());
204 schoenebeck 1461
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 capela 1558 sEngineName = Channel::noEngineName();
214 capela 1509 if (m_ui.EngineNameComboBox->findText(sEngineName,
215 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
216 capela 1509 m_ui.EngineNameComboBox->addItem(sEngineName);
217 schoenebeck 1461 }
218 capela 1509 m_ui.EngineNameComboBox->setCurrentIndex(
219     m_ui.EngineNameComboBox->findText(sEngineName,
220 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive));
221 capela 1504
222 schoenebeck 1461 // Instrument filename and index...
223     QString sInstrumentFile = pChannel->instrumentFile();
224     if (sInstrumentFile.isEmpty())
225 capela 1558 sInstrumentFile = Channel::noInstrumentName();
226 capela 1509 m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
227     m_ui.InstrumentNrComboBox->clear();
228     m_ui.InstrumentNrComboBox->insertItems(0,
229 capela 1558 Channel::getInstrumentList(sInstrumentFile,
230 schoenebeck 1461 pOptions->bInstrumentNames));
231 capela 1510 int iInstrumentNr = pChannel->instrumentNr();
232     if (iInstrumentNr < 0)
233     iInstrumentNr = 0;
234     m_ui.InstrumentNrComboBox->setCurrentIndex(iInstrumentNr);
235 schoenebeck 1461
236     // MIDI input device...
237 capela 1558 Device midiDevice(Device::Midi, m_pChannel->midiDevice());
238 schoenebeck 1461 // MIDI input driver...
239     QString sMidiDriver = midiDevice.driverName();
240     if (sMidiDriver.isEmpty() || bNew)
241 capela 1499 sMidiDriver = pOptions->sMidiDriver.toUpper();
242 schoenebeck 1461 if (!sMidiDriver.isEmpty()) {
243 capela 1509 if (m_ui.MidiDriverComboBox->findText(sMidiDriver,
244 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
245 capela 1509 m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
246 schoenebeck 1461 }
247 schoenebeck 1710 m_ui.MidiDriverComboBox->setCurrentIndex(
248     m_ui.MidiDriverComboBox->findText(sMidiDriver,
249     Qt::MatchExactly | Qt::MatchCaseSensitive)
250     );
251 schoenebeck 1461 }
252     selectMidiDriverItem(sMidiDriver);
253 capela 1499 if (!bNew) {
254 capela 1509 m_ui.MidiDeviceComboBox->setItemText(
255     m_ui.MidiDeviceComboBox->currentIndex(),
256 capela 1499 midiDevice.deviceName());
257     }
258 capela 1509 selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());
259 schoenebeck 1461 // MIDI input port...
260 capela 1509 m_ui.MidiPortSpinBox->setValue(pChannel->midiPort());
261 schoenebeck 1461 // 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 capela 1509 m_ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
267 schoenebeck 1461 // 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 capela 1558 const QString& sMapName = Instrument::getMapName(iMidiMap);
273 capela 1499 if (!sMapName.isEmpty()) {
274 capela 1509 m_ui.MidiMapComboBox->setItemText(
275     m_ui.MidiMapComboBox->currentIndex(),
276 capela 1499 sMapName);
277     }
278 schoenebeck 1461 // It might be no maps around...
279 capela 1509 bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);
280     m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
281     m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
282 schoenebeck 1461
283     // Audio output device...
284 capela 1558 Device audioDevice(Device::Audio, m_pChannel->audioDevice());
285 schoenebeck 1461 // Audio output driver...
286     QString sAudioDriver = audioDevice.driverName();
287     if (sAudioDriver.isEmpty() || bNew)
288 capela 1499 sAudioDriver = pOptions->sAudioDriver.toUpper();
289 schoenebeck 1461 if (!sAudioDriver.isEmpty()) {
290 capela 1509 if (m_ui.AudioDriverComboBox->findText(sAudioDriver,
291 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
292 capela 1509 m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
293 schoenebeck 1461 }
294 schoenebeck 1710 m_ui.AudioDriverComboBox->setCurrentIndex(
295     m_ui.AudioDriverComboBox->findText(sAudioDriver,
296     Qt::MatchExactly | Qt::MatchCaseSensitive)
297     );
298 schoenebeck 1461 }
299     selectAudioDriverItem(sAudioDriver);
300 capela 1499 if (!bNew) {
301 capela 1509 m_ui.AudioDeviceComboBox->setItemText(
302     m_ui.AudioDeviceComboBox->currentIndex(),
303 capela 1499 audioDevice.deviceName());
304     }
305 capela 1509 selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());
306 schoenebeck 1461
307 capela 1509 // 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 schoenebeck 1527 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 schoenebeck 1461 // As convenient, make it ready on stabilizeForm() for
321     // prompt acceptance, if we got the minimum required...
322 capela 1558 /* if (sEngineName != Channel::noEngineName() &&
323     sInstrumentFile != Channel::noInstrumentName())
324 schoenebeck 1461 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 capela 1558 Options *pOptions = pMainForm->options();
344 schoenebeck 1461 if (pOptions == NULL)
345     return;
346    
347     // Flush any pending editing...
348 capela 1509 //m_ui.AudioRoutingTable->flush();
349 schoenebeck 1461
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 capela 1509 if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))
359 schoenebeck 1461 iErrors++;
360     } else {
361 capela 1558 Device *pDevice = NULL;
362 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
363 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
364     pDevice = m_audioDevices.at(iAudioItem);
365 capela 1558 ChannelRoutingMap routingMap = m_routingModel.routingMap();
366 schoenebeck 1461 if (pDevice == NULL)
367     iErrors++;
368     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
369     iErrors++;
370 schoenebeck 1489 else if (!routingMap.isEmpty()) {
371 schoenebeck 1461 // Set the audio route changes...
372 capela 1558 ChannelRoutingMap::ConstIterator iter;
373 schoenebeck 1489 for (iter = routingMap.begin();
374     iter != routingMap.end(); ++iter) {
375 capela 1499 if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
376 schoenebeck 1461 iErrors++;
377     }
378     }
379     }
380     // Accept MIDI driver or device selection...
381     if (m_midiDevices.isEmpty()) {
382 capela 1509 if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))
383 schoenebeck 1461 iErrors++;
384     } else {
385 capela 1558 Device *pDevice = NULL;
386 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
387 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
388     pDevice = m_midiDevices.at(iMidiItem);
389 schoenebeck 1461 if (pDevice == NULL)
390     iErrors++;
391     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
392     iErrors++;
393     }
394     // MIDI input port number...
395 capela 1509 if (!m_pChannel->setMidiPort(m_ui.MidiPortSpinBox->value()))
396 schoenebeck 1461 iErrors++;
397     // MIDI input channel...
398 capela 1509 if (!m_pChannel->setMidiChannel(m_ui.MidiChannelComboBox->currentIndex()))
399 schoenebeck 1461 iErrors++;
400     // Engine name...
401 capela 1509 if (!m_pChannel->loadEngine(m_ui.EngineNameComboBox->currentText()))
402 schoenebeck 1461 iErrors++;
403     // Instrument file and index...
404 capela 1509 const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
405 schoenebeck 1461 if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
406 capela 1509 if (!m_pChannel->loadInstrument(sPath, m_ui.InstrumentNrComboBox->currentIndex()))
407 schoenebeck 1461 iErrors++;
408     }
409     // MIDI intrument map...
410 capela 1509 if (!m_pChannel->setMidiMap(m_ui.MidiMapComboBox->currentIndex()))
411 schoenebeck 1461 iErrors++;
412     // Show error messages?
413 capela 1510 if (iErrors > 0) {
414     m_pChannel->appendMessagesError(
415     tr("Some channel settings could not be set.\n\nSorry."));
416     }
417 schoenebeck 1461 }
418    
419     // Save default engine name, instrument directory and history...
420 capela 1499 pOptions->sInstrumentDir = QFileInfo(
421 capela 1509 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 schoenebeck 1461
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 capela 2107 if (m_iDirtyCount > 0) {
440 schoenebeck 1461 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 capela 1840 QMessageBox::Apply |
445     QMessageBox::Discard |
446     QMessageBox::Cancel)) {
447     case QMessageBox::Apply:
448 schoenebeck 1461 accept();
449     return;
450 capela 1840 case QMessageBox::Discard:
451 schoenebeck 1461 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 capela 1558 Options *pOptions = pMainForm->options();
473 schoenebeck 1461 if (pOptions == NULL)
474     return;
475    
476     // FIXME: the instrument file filters should be restricted,
477     // depending on the current engine.
478 capela 2108 QStringList filters;
479 capela 2110 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 capela 2108 filters << tr("All files") + " (*.*)";
487     const QString& filter = filters.join(";;");
488    
489 capela 1499 QString sInstrumentFile = QFileDialog::getOpenFileName(this,
490     QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
491 capela 2108 pOptions->sInstrumentDir, // Start here.
492     filter // File filter.
493 schoenebeck 1461 );
494    
495     if (sInstrumentFile.isEmpty())
496     return;
497    
498 capela 1509 m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
499 schoenebeck 1461 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 capela 1558 Options *pOptions = pMainForm->options();
513 schoenebeck 1461 if (pOptions == NULL)
514     return;
515    
516     // Finally this better idea would be to use libgig
517     // to retrieve the REAL instrument names.
518 capela 1509 m_ui.InstrumentNrComboBox->clear();
519     m_ui.InstrumentNrComboBox->insertItems(0,
520 capela 1558 Channel::getInstrumentList(
521 capela 1509 m_ui.InstrumentFileComboBox->currentText(),
522 schoenebeck 1461 pOptions->bInstrumentNames)
523     );
524    
525     optionsChanged();
526     }
527    
528    
529     // Show device options dialog.
530 capela 1558 void ChannelForm::setupDevice ( Device *pDevice,
531     Device::DeviceType deviceTypeMode,
532 schoenebeck 1461 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 capela 1510 m_pDeviceForm->setAttribute(Qt::WA_ShowModal);
544 schoenebeck 1461 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 capela 1499 const QString sDriverName = sMidiDriver.toUpper();
569 schoenebeck 1461
570     // Save current device id.
571 capela 1504 // Save current device id.
572 schoenebeck 1461 int iDeviceID = 0;
573 capela 1558 Device *pDevice = NULL;
574 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
575 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
576     pDevice = m_midiDevices.at(iMidiItem);
577 schoenebeck 1461 if (pDevice)
578     iDeviceID = pDevice->deviceID();
579    
580     // Clean maplist.
581 capela 1509 m_ui.MidiDeviceComboBox->clear();
582 capela 1499 qDeleteAll(m_midiDevices);
583 schoenebeck 1461 m_midiDevices.clear();
584    
585     // Populate with the current ones...
586 capela 2074 const QPixmap midiPixmap(":/images/midi2.png");
587 capela 1558 int *piDeviceIDs = Device::getDevices(pMainForm->client(),
588     Device::Midi);
589 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
590 capela 1558 pDevice = new Device(Device::Midi, piDeviceIDs[i]);
591 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
592 capela 1510 m_ui.MidiDeviceComboBox->insertItem(0,
593     midiPixmap, pDevice->deviceName());
594 schoenebeck 1461 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 capela 1504 iMidiItem = 0;
605 capela 1558 QListIterator<Device *> iter(m_midiDevices);
606 capela 1499 while (iter.hasNext()) {
607     pDevice = iter.next();
608 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
609 capela 1509 m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
610 schoenebeck 1461 selectMidiDeviceItem(iMidiItem);
611     break;
612     }
613     iMidiItem++;
614     }
615     } else {
616 capela 1509 m_ui.MidiDeviceComboBox->insertItem(0,
617 schoenebeck 1461 tr("(New MIDI %1 device)").arg(sMidiDriver));
618     }
619 capela 1509 m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);
620     m_ui.MidiDeviceComboBox->setEnabled(bEnabled);
621 schoenebeck 1461 }
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 capela 1558 Device *pDevice = NULL;
639 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
640     pDevice = m_midiDevices.at(iMidiItem);
641 schoenebeck 1461 if (pDevice) {
642 capela 1558 const DeviceParamMap& params = pDevice->params();
643 schoenebeck 1461 int iPorts = params["PORTS"].value.toInt();
644 capela 1509 m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);
645     m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);
646 schoenebeck 1461 if (iPorts > 0)
647 capela 1509 m_ui.MidiPortSpinBox->setMaximum(iPorts - 1);
648 schoenebeck 1461 }
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 capela 1558 Device *pDevice = NULL;
667 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
668 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
669     pDevice = m_midiDevices.at(iMidiItem);
670     setupDevice(pDevice,
671 capela 1558 Device::Midi, m_ui.MidiDriverComboBox->currentText());
672 schoenebeck 1461 }
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 capela 1499 const QString sDriverName = sAudioDriver.toUpper();
685 schoenebeck 1461
686     // Save current device id.
687     int iDeviceID = 0;
688 capela 1558 Device *pDevice = NULL;
689 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
690 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
691     pDevice = m_audioDevices.at(iAudioItem);
692 schoenebeck 1461 if (pDevice)
693     iDeviceID = pDevice->deviceID();
694    
695     // Clean maplist.
696 capela 1509 m_ui.AudioDeviceComboBox->clear();
697 capela 1499 qDeleteAll(m_audioDevices);
698 schoenebeck 1461 m_audioDevices.clear();
699    
700     // Populate with the current ones...
701 capela 2074 const QPixmap audioPixmap(":/images/audio2.png");
702 capela 1558 int *piDeviceIDs = Device::getDevices(pMainForm->client(),
703     Device::Audio);
704 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
705 capela 1558 pDevice = new Device(Device::Audio, piDeviceIDs[i]);
706 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
707 capela 1510 m_ui.AudioDeviceComboBox->insertItem(0,
708     audioPixmap, pDevice->deviceName());
709 schoenebeck 1461 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 capela 1504 iAudioItem = 0;
720 capela 1558 QListIterator<Device *> iter(m_audioDevices);
721 capela 1499 while (iter.hasNext()) {
722     pDevice = iter.next();
723 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
724 capela 1509 m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
725 schoenebeck 1461 selectAudioDeviceItem(iAudioItem);
726     break;
727     }
728     iAudioItem++;
729     }
730     } else {
731 capela 1509 m_ui.AudioDeviceComboBox->insertItem(0,
732 schoenebeck 1461 tr("(New Audio %1 device)").arg(sAudioDriver));
733 capela 1509 //m_ui.AudioRoutingTable->setNumRows(0);
734 schoenebeck 1461 }
735 capela 1509 m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);
736     m_ui.AudioDeviceComboBox->setEnabled(bEnabled);
737     m_ui.AudioRoutingTable->setEnabled(bEnabled);
738 schoenebeck 1461 }
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 capela 1558 Device *pDevice = NULL;
756 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
757     pDevice = m_audioDevices.at(iAudioItem);
758 schoenebeck 1461 if (pDevice) {
759     // Refresh the audio routing table.
760 capela 1509 m_routingModel.refresh(pDevice, m_pChannel->audioRouting());
761 schoenebeck 1461 // Reset routing change map.
762 capela 1509 m_routingModel.clear();
763 schoenebeck 1461 }
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 capela 1558 Device *pDevice = NULL;
782 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
783 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
784     pDevice = m_audioDevices.at(iAudioItem);
785     setupDevice(pDevice,
786 capela 1558 Device::Audio, m_ui.AudioDriverComboBox->currentText());
787 schoenebeck 1461 }
788    
789     // UPdate all device lists slot.
790     void ChannelForm::updateDevices (void)
791     {
792     if (m_iDirtySetup > 0)
793     return;
794    
795 capela 1509 selectMidiDriverItem(m_ui.MidiDriverComboBox->currentText());
796     selectAudioDriverItem(m_ui.AudioDriverComboBox->currentText());
797 schoenebeck 1461 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 schoenebeck 1506 const bool bValid =
816 capela 1509 m_ui.EngineNameComboBox->currentIndex() >= 0 &&
817 capela 1510 m_ui.EngineNameComboBox->currentText()
818 capela 1558 != Channel::noEngineName();
819 schoenebeck 1461 #if 0
820     const QString& sPath = InstrumentFileComboBox->currentText();
821     bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
822     #endif
823 capela 2107 m_ui.DialogButtonBox->button(
824     QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid);
825 schoenebeck 1461 }
826    
827 capela 1509
828     void ChannelForm::updateTableCellRenderers (void)
829     {
830 capela 1510 const int rows = m_routingModel.rowCount();
831     const int cols = m_routingModel.columnCount();
832     updateTableCellRenderers(
833 capela 1509 m_routingModel.index(0, 0),
834     m_routingModel.index(rows - 1, cols - 1));
835 schoenebeck 1489 }
836 schoenebeck 1461
837 capela 1509
838     void ChannelForm::updateTableCellRenderers (
839     const QModelIndex& topLeft, const QModelIndex& bottomRight )
840     {
841 capela 1510 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 schoenebeck 1489 }
848    
849 schoenebeck 1461 } // namespace QSampler
850 capela 1464
851    
852     // end of qsamplerChannelForm.cpp

  ViewVC Help
Powered by ViewVC