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