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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1710 - (hide annotations) (download)
Tue Feb 26 16:00:00 2008 UTC (16 years, 1 month ago) by schoenebeck
File size: 24179 byte(s)
* bugfix in sampler channel dialog: driver combo boxes' content were
  screwed
* bumped version to 0.2.1.13

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

  ViewVC Help
Powered by ViewVC