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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (hide annotations) (download)
Thu Dec 6 09:35:33 2007 UTC (16 years, 4 months ago) by capela
File size: 24077 byte(s)
* Qt4 migration: complete QSampler namespace overhaul.

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 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     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 capela 1509 m_ui.MidiDriverComboBox->setItemText(
246     m_ui.MidiDriverComboBox->currentIndex(),
247 capela 1499 sMidiDriver);
248 schoenebeck 1461 }
249     selectMidiDriverItem(sMidiDriver);
250 capela 1499 if (!bNew) {
251 capela 1509 m_ui.MidiDeviceComboBox->setItemText(
252     m_ui.MidiDeviceComboBox->currentIndex(),
253 capela 1499 midiDevice.deviceName());
254     }
255 capela 1509 selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());
256 schoenebeck 1461 // MIDI input port...
257 capela 1509 m_ui.MidiPortSpinBox->setValue(pChannel->midiPort());
258 schoenebeck 1461 // MIDI input channel...
259     int iMidiChannel = pChannel->midiChannel();
260     // When new, try to suggest a sensible MIDI channel...
261     if (iMidiChannel < 0)
262     iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);
263 capela 1509 m_ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
264 schoenebeck 1461 // MIDI instrument map...
265     int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());
266     // When new, try to suggest a sensible MIDI map...
267     if (iMidiMap < 0)
268     iMidiMap = 0;
269 capela 1558 const QString& sMapName = Instrument::getMapName(iMidiMap);
270 capela 1499 if (!sMapName.isEmpty()) {
271 capela 1509 m_ui.MidiMapComboBox->setItemText(
272     m_ui.MidiMapComboBox->currentIndex(),
273 capela 1499 sMapName);
274     }
275 schoenebeck 1461 // It might be no maps around...
276 capela 1509 bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);
277     m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
278     m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
279 schoenebeck 1461
280     // Audio output device...
281 capela 1558 Device audioDevice(Device::Audio, m_pChannel->audioDevice());
282 schoenebeck 1461 // Audio output driver...
283     QString sAudioDriver = audioDevice.driverName();
284     if (sAudioDriver.isEmpty() || bNew)
285 capela 1499 sAudioDriver = pOptions->sAudioDriver.toUpper();
286 schoenebeck 1461 if (!sAudioDriver.isEmpty()) {
287 capela 1509 if (m_ui.AudioDriverComboBox->findText(sAudioDriver,
288 schoenebeck 1474 Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
289 capela 1509 m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
290 schoenebeck 1461 }
291 capela 1509 m_ui.AudioDriverComboBox->setItemText(
292     m_ui.AudioDriverComboBox->currentIndex(),
293 capela 1499 sAudioDriver);
294 schoenebeck 1461 }
295     selectAudioDriverItem(sAudioDriver);
296 capela 1499 if (!bNew) {
297 capela 1509 m_ui.AudioDeviceComboBox->setItemText(
298     m_ui.AudioDeviceComboBox->currentIndex(),
299 capela 1499 audioDevice.deviceName());
300     }
301 capela 1509 selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());
302 schoenebeck 1461
303 capela 1509 // Let the audio routing table see the light,
304     // if we're editing an existing sampler channel...
305     m_ui.AudioRoutingTable->setVisible(!bNew);
306    
307 schoenebeck 1527 const QString sInstrumentNrToolTip =
308     (pOptions->bInstrumentNames) ?
309     "Select an instrument of the file" :
310     "You might want to enable instrument name retrieval in the "
311     "settings dialog";
312     m_ui.InstrumentNrComboBox->setToolTip(
313     QObject::tr(sInstrumentNrToolTip.toUtf8().data())
314     );
315    
316 schoenebeck 1461 // As convenient, make it ready on stabilizeForm() for
317     // prompt acceptance, if we got the minimum required...
318 capela 1558 /* if (sEngineName != Channel::noEngineName() &&
319     sInstrumentFile != Channel::noInstrumentName())
320 schoenebeck 1461 m_iDirtyCount++; */
321     // Done.
322     m_iDirtySetup--;
323     stabilizeForm();
324     }
325    
326    
327     // Accept settings (OK button slot).
328     void ChannelForm::accept (void)
329     {
330     if (m_pChannel == NULL)
331     return;
332    
333     MainForm *pMainForm = MainForm::getInstance();
334     if (pMainForm == NULL)
335     return;
336     if (pMainForm->client() == NULL)
337     return;
338    
339 capela 1558 Options *pOptions = pMainForm->options();
340 schoenebeck 1461 if (pOptions == NULL)
341     return;
342    
343     // Flush any pending editing...
344 capela 1509 //m_ui.AudioRoutingTable->flush();
345 schoenebeck 1461
346     // We'll go for it!
347     if (m_iDirtyCount > 0) {
348     int iErrors = 0;
349     // Are we a new channel?
350     if (!m_pChannel->addChannel())
351     iErrors++;
352     // Accept Audio driver or device selection...
353     if (m_audioDevices.isEmpty()) {
354 capela 1509 if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))
355 schoenebeck 1461 iErrors++;
356     } else {
357 capela 1558 Device *pDevice = NULL;
358 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
359 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
360     pDevice = m_audioDevices.at(iAudioItem);
361 capela 1558 ChannelRoutingMap routingMap = m_routingModel.routingMap();
362 schoenebeck 1461 if (pDevice == NULL)
363     iErrors++;
364     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
365     iErrors++;
366 schoenebeck 1489 else if (!routingMap.isEmpty()) {
367 schoenebeck 1461 // Set the audio route changes...
368 capela 1558 ChannelRoutingMap::ConstIterator iter;
369 schoenebeck 1489 for (iter = routingMap.begin();
370     iter != routingMap.end(); ++iter) {
371 capela 1499 if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
372 schoenebeck 1461 iErrors++;
373     }
374     }
375     }
376     // Accept MIDI driver or device selection...
377     if (m_midiDevices.isEmpty()) {
378 capela 1509 if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))
379 schoenebeck 1461 iErrors++;
380     } else {
381 capela 1558 Device *pDevice = NULL;
382 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
383 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
384     pDevice = m_midiDevices.at(iMidiItem);
385 schoenebeck 1461 if (pDevice == NULL)
386     iErrors++;
387     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
388     iErrors++;
389     }
390     // MIDI input port number...
391 capela 1509 if (!m_pChannel->setMidiPort(m_ui.MidiPortSpinBox->value()))
392 schoenebeck 1461 iErrors++;
393     // MIDI input channel...
394 capela 1509 if (!m_pChannel->setMidiChannel(m_ui.MidiChannelComboBox->currentIndex()))
395 schoenebeck 1461 iErrors++;
396     // Engine name...
397 capela 1509 if (!m_pChannel->loadEngine(m_ui.EngineNameComboBox->currentText()))
398 schoenebeck 1461 iErrors++;
399     // Instrument file and index...
400 capela 1509 const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
401 schoenebeck 1461 if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
402 capela 1509 if (!m_pChannel->loadInstrument(sPath, m_ui.InstrumentNrComboBox->currentIndex()))
403 schoenebeck 1461 iErrors++;
404     }
405     // MIDI intrument map...
406 capela 1509 if (!m_pChannel->setMidiMap(m_ui.MidiMapComboBox->currentIndex()))
407 schoenebeck 1461 iErrors++;
408     // Show error messages?
409 capela 1510 if (iErrors > 0) {
410     m_pChannel->appendMessagesError(
411     tr("Some channel settings could not be set.\n\nSorry."));
412     }
413 schoenebeck 1461 }
414    
415     // Save default engine name, instrument directory and history...
416 capela 1499 pOptions->sInstrumentDir = QFileInfo(
417 capela 1509 m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
418     pOptions->sEngineName = m_ui.EngineNameComboBox->currentText();
419     pOptions->sAudioDriver = m_ui.AudioDriverComboBox->currentText();
420     pOptions->sMidiDriver = m_ui.MidiDriverComboBox->currentText();
421     pOptions->iMidiMap = m_ui.MidiMapComboBox->currentIndex();
422     pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox);
423 schoenebeck 1461
424     // Just go with dialog acceptance.
425     QDialog::accept();
426     }
427    
428    
429     // Reject settings (Cancel button slot).
430     void ChannelForm::reject (void)
431     {
432     bool bReject = true;
433    
434     // Check if there's any pending changes...
435 capela 1509 if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) {
436 schoenebeck 1461 switch (QMessageBox::warning(this,
437     QSAMPLER_TITLE ": " + tr("Warning"),
438     tr("Some channel settings have been changed.\n\n"
439     "Do you want to apply the changes?"),
440     tr("Apply"), tr("Discard"), tr("Cancel"))) {
441     case 0: // Apply...
442     accept();
443     return;
444     case 1: // Discard
445     break;
446     default: // Cancel.
447     bReject = false;
448     break;
449     }
450     }
451    
452     if (bReject)
453     QDialog::reject();
454     }
455    
456    
457     // Browse and open an instrument file.
458     void ChannelForm::openInstrumentFile (void)
459     {
460     MainForm *pMainForm = MainForm::getInstance();
461     if (pMainForm == NULL)
462     return;
463     if (pMainForm->client() == NULL)
464     return;
465    
466 capela 1558 Options *pOptions = pMainForm->options();
467 schoenebeck 1461 if (pOptions == NULL)
468     return;
469    
470     // FIXME: the instrument file filters should be restricted,
471     // depending on the current engine.
472 capela 1499 QString sInstrumentFile = QFileDialog::getOpenFileName(this,
473     QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
474     pOptions->sInstrumentDir, // Start here.
475     tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
476 schoenebeck 1461 );
477    
478     if (sInstrumentFile.isEmpty())
479     return;
480    
481 capela 1509 m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
482 schoenebeck 1461 updateInstrumentName();
483     }
484    
485    
486     // Refresh the actual instrument name.
487     void ChannelForm::updateInstrumentName (void)
488     {
489     MainForm *pMainForm = MainForm::getInstance();
490     if (pMainForm == NULL)
491     return;
492     if (pMainForm->client() == NULL)
493     return;
494    
495 capela 1558 Options *pOptions = pMainForm->options();
496 schoenebeck 1461 if (pOptions == NULL)
497     return;
498    
499     // Finally this better idea would be to use libgig
500     // to retrieve the REAL instrument names.
501 capela 1509 m_ui.InstrumentNrComboBox->clear();
502     m_ui.InstrumentNrComboBox->insertItems(0,
503 capela 1558 Channel::getInstrumentList(
504 capela 1509 m_ui.InstrumentFileComboBox->currentText(),
505 schoenebeck 1461 pOptions->bInstrumentNames)
506     );
507    
508     optionsChanged();
509     }
510    
511    
512     // Show device options dialog.
513 capela 1558 void ChannelForm::setupDevice ( Device *pDevice,
514     Device::DeviceType deviceTypeMode,
515 schoenebeck 1461 const QString& sDriverName )
516     {
517     MainForm *pMainForm = MainForm::getInstance();
518     if (pMainForm == NULL)
519     return;
520     if (pMainForm->client() == NULL)
521     return;
522    
523     // Create the device form if not already...
524     if (m_pDeviceForm == NULL) {
525     m_pDeviceForm = new DeviceForm(this, Qt::Dialog);
526 capela 1510 m_pDeviceForm->setAttribute(Qt::WA_ShowModal);
527 schoenebeck 1461 QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
528     this, SLOT(updateDevices()));
529     }
530    
531     // Refresh the device form with selected data.
532     if (m_pDeviceForm) {
533     m_pDeviceForm->setDeviceTypeMode(deviceTypeMode);
534     m_pDeviceForm->refreshDevices();
535     m_pDeviceForm->setDevice(pDevice);
536     m_pDeviceForm->setDriverName(sDriverName);
537     m_pDeviceForm->show();
538     }
539     }
540    
541    
542     // Refresh MIDI driver item devices.
543     void ChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
544     {
545     MainForm *pMainForm = MainForm::getInstance();
546     if (pMainForm == NULL)
547     return;
548     if (pMainForm->client() == NULL)
549     return;
550    
551 capela 1499 const QString sDriverName = sMidiDriver.toUpper();
552 schoenebeck 1461
553     // Save current device id.
554 capela 1504 // Save current device id.
555 schoenebeck 1461 int iDeviceID = 0;
556 capela 1558 Device *pDevice = NULL;
557 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
558 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
559     pDevice = m_midiDevices.at(iMidiItem);
560 schoenebeck 1461 if (pDevice)
561     iDeviceID = pDevice->deviceID();
562    
563     // Clean maplist.
564 capela 1509 m_ui.MidiDeviceComboBox->clear();
565 capela 1499 qDeleteAll(m_midiDevices);
566 schoenebeck 1461 m_midiDevices.clear();
567    
568     // Populate with the current ones...
569 schoenebeck 1489 const QPixmap midiPixmap(":/icons/midi2.png");
570 capela 1558 int *piDeviceIDs = Device::getDevices(pMainForm->client(),
571     Device::Midi);
572 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
573 capela 1558 pDevice = new Device(Device::Midi, piDeviceIDs[i]);
574 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
575 capela 1510 m_ui.MidiDeviceComboBox->insertItem(0,
576     midiPixmap, pDevice->deviceName());
577 schoenebeck 1461 m_midiDevices.append(pDevice);
578     } else {
579     delete pDevice;
580     }
581     }
582    
583     // Do proper enabling...
584     bool bEnabled = !m_midiDevices.isEmpty();
585     if (bEnabled) {
586     // Select the previous current device...
587 capela 1504 iMidiItem = 0;
588 capela 1558 QListIterator<Device *> iter(m_midiDevices);
589 capela 1499 while (iter.hasNext()) {
590     pDevice = iter.next();
591 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
592 capela 1509 m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
593 schoenebeck 1461 selectMidiDeviceItem(iMidiItem);
594     break;
595     }
596     iMidiItem++;
597     }
598     } else {
599 capela 1509 m_ui.MidiDeviceComboBox->insertItem(0,
600 schoenebeck 1461 tr("(New MIDI %1 device)").arg(sMidiDriver));
601     }
602 capela 1509 m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);
603     m_ui.MidiDeviceComboBox->setEnabled(bEnabled);
604 schoenebeck 1461 }
605    
606    
607     // Refresh MIDI device options slot.
608     void ChannelForm::selectMidiDriver ( const QString& sMidiDriver )
609     {
610     if (m_iDirtySetup > 0)
611     return;
612    
613     selectMidiDriverItem(sMidiDriver);
614     optionsChanged();
615     }
616    
617    
618     // Select MIDI device item.
619     void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
620     {
621 capela 1558 Device *pDevice = NULL;
622 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
623     pDevice = m_midiDevices.at(iMidiItem);
624 schoenebeck 1461 if (pDevice) {
625 capela 1558 const DeviceParamMap& params = pDevice->params();
626 schoenebeck 1461 int iPorts = params["PORTS"].value.toInt();
627 capela 1509 m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);
628     m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);
629 schoenebeck 1461 if (iPorts > 0)
630 capela 1509 m_ui.MidiPortSpinBox->setMaximum(iPorts - 1);
631 schoenebeck 1461 }
632     }
633    
634    
635     // Select MIDI device options slot.
636     void ChannelForm::selectMidiDevice ( int iMidiItem )
637     {
638     if (m_iDirtySetup > 0)
639     return;
640    
641     selectMidiDeviceItem(iMidiItem);
642     optionsChanged();
643     }
644    
645    
646     // MIDI device options.
647     void ChannelForm::setupMidiDevice (void)
648     {
649 capela 1558 Device *pDevice = NULL;
650 capela 1509 int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
651 capela 1504 if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
652     pDevice = m_midiDevices.at(iMidiItem);
653     setupDevice(pDevice,
654 capela 1558 Device::Midi, m_ui.MidiDriverComboBox->currentText());
655 schoenebeck 1461 }
656    
657    
658     // Refresh Audio driver item devices.
659     void ChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
660     {
661     MainForm *pMainForm = MainForm::getInstance();
662     if (pMainForm == NULL)
663     return;
664     if (pMainForm->client() == NULL)
665     return;
666    
667 capela 1499 const QString sDriverName = sAudioDriver.toUpper();
668 schoenebeck 1461
669     // Save current device id.
670     int iDeviceID = 0;
671 capela 1558 Device *pDevice = NULL;
672 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
673 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
674     pDevice = m_audioDevices.at(iAudioItem);
675 schoenebeck 1461 if (pDevice)
676     iDeviceID = pDevice->deviceID();
677    
678     // Clean maplist.
679 capela 1509 m_ui.AudioDeviceComboBox->clear();
680 capela 1499 qDeleteAll(m_audioDevices);
681 schoenebeck 1461 m_audioDevices.clear();
682    
683     // Populate with the current ones...
684 schoenebeck 1489 const QPixmap audioPixmap(":/icons/audio2.png");
685 capela 1558 int *piDeviceIDs = Device::getDevices(pMainForm->client(),
686     Device::Audio);
687 schoenebeck 1461 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
688 capela 1558 pDevice = new Device(Device::Audio, piDeviceIDs[i]);
689 capela 1499 if (pDevice->driverName().toUpper() == sDriverName) {
690 capela 1510 m_ui.AudioDeviceComboBox->insertItem(0,
691     audioPixmap, pDevice->deviceName());
692 schoenebeck 1461 m_audioDevices.append(pDevice);
693     } else {
694     delete pDevice;
695     }
696     }
697    
698     // Do proper enabling...
699     bool bEnabled = !m_audioDevices.isEmpty();
700     if (bEnabled) {
701     // Select the previous current device...
702 capela 1504 iAudioItem = 0;
703 capela 1558 QListIterator<Device *> iter(m_audioDevices);
704 capela 1499 while (iter.hasNext()) {
705     pDevice = iter.next();
706 schoenebeck 1461 if (pDevice->deviceID() == iDeviceID) {
707 capela 1509 m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
708 schoenebeck 1461 selectAudioDeviceItem(iAudioItem);
709     break;
710     }
711     iAudioItem++;
712     }
713     } else {
714 capela 1509 m_ui.AudioDeviceComboBox->insertItem(0,
715 schoenebeck 1461 tr("(New Audio %1 device)").arg(sAudioDriver));
716 capela 1509 //m_ui.AudioRoutingTable->setNumRows(0);
717 schoenebeck 1461 }
718 capela 1509 m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);
719     m_ui.AudioDeviceComboBox->setEnabled(bEnabled);
720     m_ui.AudioRoutingTable->setEnabled(bEnabled);
721 schoenebeck 1461 }
722    
723    
724     // Refresh Audio device options slot.
725     void ChannelForm::selectAudioDriver ( const QString& sAudioDriver )
726     {
727     if (m_iDirtySetup > 0)
728     return;
729    
730     selectAudioDriverItem(sAudioDriver);
731     optionsChanged();
732     }
733    
734    
735     // Select Audio device item.
736     void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
737     {
738 capela 1558 Device *pDevice = NULL;
739 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
740     pDevice = m_audioDevices.at(iAudioItem);
741 schoenebeck 1461 if (pDevice) {
742     // Refresh the audio routing table.
743 capela 1509 m_routingModel.refresh(pDevice, m_pChannel->audioRouting());
744 schoenebeck 1461 // Reset routing change map.
745 capela 1509 m_routingModel.clear();
746 schoenebeck 1461 }
747     }
748    
749    
750     // Select Audio device options slot.
751     void ChannelForm::selectAudioDevice ( int iAudioItem )
752     {
753     if (m_iDirtySetup > 0)
754     return;
755    
756     selectAudioDeviceItem(iAudioItem);
757     optionsChanged();
758     }
759    
760    
761     // Audio device options.
762     void ChannelForm::setupAudioDevice (void)
763     {
764 capela 1558 Device *pDevice = NULL;
765 capela 1509 int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
766 capela 1504 if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
767     pDevice = m_audioDevices.at(iAudioItem);
768     setupDevice(pDevice,
769 capela 1558 Device::Audio, m_ui.AudioDriverComboBox->currentText());
770 schoenebeck 1461 }
771    
772     // UPdate all device lists slot.
773     void ChannelForm::updateDevices (void)
774     {
775     if (m_iDirtySetup > 0)
776     return;
777    
778 capela 1509 selectMidiDriverItem(m_ui.MidiDriverComboBox->currentText());
779     selectAudioDriverItem(m_ui.AudioDriverComboBox->currentText());
780 schoenebeck 1461 optionsChanged();
781     }
782    
783    
784     // Dirty up settings.
785     void ChannelForm::optionsChanged (void)
786     {
787     if (m_iDirtySetup > 0)
788     return;
789    
790     m_iDirtyCount++;
791     stabilizeForm();
792     }
793    
794    
795     // Stabilize current form state.
796     void ChannelForm::stabilizeForm (void)
797     {
798 schoenebeck 1506 const bool bValid =
799 capela 1509 m_ui.EngineNameComboBox->currentIndex() >= 0 &&
800 capela 1510 m_ui.EngineNameComboBox->currentText()
801 capela 1558 != Channel::noEngineName();
802 schoenebeck 1461 #if 0
803     const QString& sPath = InstrumentFileComboBox->currentText();
804     bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
805     #endif
806 capela 1509 m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
807 schoenebeck 1461 }
808    
809 capela 1509
810     void ChannelForm::updateTableCellRenderers (void)
811     {
812 capela 1510 const int rows = m_routingModel.rowCount();
813     const int cols = m_routingModel.columnCount();
814     updateTableCellRenderers(
815 capela 1509 m_routingModel.index(0, 0),
816     m_routingModel.index(rows - 1, cols - 1));
817 schoenebeck 1489 }
818 schoenebeck 1461
819 capela 1509
820     void ChannelForm::updateTableCellRenderers (
821     const QModelIndex& topLeft, const QModelIndex& bottomRight )
822     {
823 capela 1510 for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
824     for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
825     const QModelIndex index = m_routingModel.index(r, c);
826     m_ui.AudioRoutingTable->openPersistentEditor(index);
827     }
828     }
829 schoenebeck 1489 }
830    
831 schoenebeck 1461 } // namespace QSampler
832 capela 1464
833    
834     // end of qsamplerChannelForm.cpp

  ViewVC Help
Powered by ViewVC