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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1509 - (hide annotations) (download)
Thu Nov 22 11:10:44 2007 UTC (16 years, 4 months ago) by capela
File size: 23781 byte(s)
* Audio routing table is initially hidden in the dialog, when
  creating a new sampler channel.

* README requirements and configuration notes update.

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

  ViewVC Help
Powered by ViewVC