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