26 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
27 |
#include <qlistbox.h> |
#include <qlistbox.h> |
28 |
|
|
29 |
|
#include "qsamplerDeviceForm.h" |
30 |
|
|
31 |
#include "config.h" |
#include "config.h" |
32 |
|
|
33 |
|
|
43 |
m_midiDevices.setAutoDelete(true); |
m_midiDevices.setAutoDelete(true); |
44 |
m_audioDevices.setAutoDelete(true); |
m_audioDevices.setAutoDelete(true); |
45 |
|
|
46 |
|
m_pDeviceForm = NULL; |
47 |
|
|
48 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
49 |
adjustSize(); |
adjustSize(); |
50 |
} |
} |
53 |
// Kind of destructor. |
// Kind of destructor. |
54 |
void qsamplerChannelForm::destroy (void) |
void qsamplerChannelForm::destroy (void) |
55 |
{ |
{ |
56 |
|
if (m_pDeviceForm) |
57 |
|
delete m_pDeviceForm; |
58 |
|
m_pDeviceForm = NULL; |
59 |
} |
} |
60 |
|
|
61 |
|
|
131 |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
132 |
|
|
133 |
// MIDI input device... |
// MIDI input device... |
134 |
qsamplerDevice midiDevice(m_pChannel->client(), |
qsamplerDevice midiDevice(m_pChannel->mainForm(), |
135 |
qsamplerDevice::Midi, m_pChannel->midiDevice()); |
qsamplerDevice::Midi, m_pChannel->midiDevice()); |
136 |
// MIDI input driver... |
// MIDI input driver... |
137 |
QString sMidiDriver = midiDevice.driverName(); |
QString sMidiDriver = midiDevice.driverName(); |
142 |
MidiDriverComboBox->insertItem(sMidiDriver); |
MidiDriverComboBox->insertItem(sMidiDriver); |
143 |
MidiDriverComboBox->setCurrentText(sMidiDriver); |
MidiDriverComboBox->setCurrentText(sMidiDriver); |
144 |
} |
} |
145 |
selectMidiDriver(sMidiDriver); |
selectMidiDriverItem(sMidiDriver); |
146 |
if (!bNew) |
if (!bNew) |
147 |
MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); |
MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); |
148 |
selectMidiDevice(MidiDeviceComboBox->currentItem()); |
selectMidiDeviceItem(MidiDeviceComboBox->currentItem()); |
149 |
// MIDI input port... |
// MIDI input port... |
150 |
MidiPortSpinBox->setValue(pChannel->midiPort()); |
MidiPortSpinBox->setValue(pChannel->midiPort()); |
151 |
// MIDI input channel... |
// MIDI input channel... |
156 |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
157 |
|
|
158 |
// Audio output device... |
// Audio output device... |
159 |
qsamplerDevice audioDevice(m_pChannel->client(), |
qsamplerDevice audioDevice(m_pChannel->mainForm(), |
160 |
qsamplerDevice::Audio, m_pChannel->audioDevice()); |
qsamplerDevice::Audio, m_pChannel->audioDevice()); |
161 |
// Audio output driver... |
// Audio output driver... |
162 |
QString sAudioDriver = audioDevice.driverName(); |
QString sAudioDriver = audioDevice.driverName(); |
167 |
AudioDriverComboBox->insertItem(sAudioDriver); |
AudioDriverComboBox->insertItem(sAudioDriver); |
168 |
AudioDriverComboBox->setCurrentText(sAudioDriver); |
AudioDriverComboBox->setCurrentText(sAudioDriver); |
169 |
} |
} |
170 |
selectAudioDriver(sAudioDriver); |
selectAudioDriverItem(sAudioDriver); |
171 |
if (!bNew) |
if (!bNew) |
172 |
AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); |
AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); |
173 |
selectAudioDevice(AudioDeviceComboBox->currentItem()); |
selectAudioDeviceItem(AudioDeviceComboBox->currentItem()); |
174 |
|
|
175 |
// As convenient, make it ready on stabilizeForm() for |
// As convenient, make it ready on stabilizeForm() for |
176 |
// prompt acceptance, if we got the minimum required... |
// prompt acceptance, if we got the minimum required... |
318 |
optionsChanged(); |
optionsChanged(); |
319 |
} |
} |
320 |
|
|
321 |
|
// Show device options dialog. |
322 |
|
void qsamplerChannelForm::setupDevice ( qsamplerDevice *pDevice ) |
323 |
|
{ |
324 |
|
// Create the device form if not already... |
325 |
|
if (m_pDeviceForm == NULL) { |
326 |
|
m_pDeviceForm = new qsamplerDeviceForm(this, 0, |
327 |
|
WType_Dialog | WShowModal); |
328 |
|
m_pDeviceForm->setMainForm(m_pChannel->mainForm()); |
329 |
|
QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()), |
330 |
|
this, SLOT(updateDevices())); |
331 |
|
} |
332 |
|
|
333 |
|
// Refresh the device form with selected data. |
334 |
|
if (m_pDeviceForm) { |
335 |
|
m_pDeviceForm->setClient(m_pChannel->client()); // <-- refreshDevices(). |
336 |
|
if (pDevice) |
337 |
|
m_pDeviceForm->setDevice(pDevice->deviceType(), pDevice->deviceID()); |
338 |
|
m_pDeviceForm->show(); |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
// Refresh MIDI device options. |
|
343 |
void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver ) |
// Refresh MIDI driver item devices. |
344 |
|
void qsamplerChannelForm::selectMidiDriverItem ( const QString& sMidiDriver ) |
345 |
{ |
{ |
346 |
const QString sDriverName = sMidiDriver.upper(); |
const QString sDriverName = sMidiDriver.upper(); |
347 |
|
|
348 |
|
// Save current device id. |
349 |
|
int iDeviceID = -1; |
350 |
|
qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem()); |
351 |
|
if (pDevice) |
352 |
|
iDeviceID = pDevice->deviceID(); |
353 |
|
|
354 |
|
// Clean maplist. |
355 |
MidiDeviceComboBox->clear(); |
MidiDeviceComboBox->clear(); |
356 |
m_audioDevices.clear(); |
m_midiDevices.clear(); |
357 |
|
|
358 |
|
// Populate with the current ones... |
359 |
const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png"); |
const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png"); |
360 |
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
361 |
qsamplerDevice::Midi); |
qsamplerDevice::Midi); |
362 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
363 |
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), |
pDevice = new qsamplerDevice(m_pChannel->mainForm(), |
364 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
qsamplerDevice::Midi, piDeviceIDs[i]); |
365 |
if (pDevice->driverName().upper() == sDriverName) { |
if (pDevice->driverName().upper() == sDriverName) { |
366 |
MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); |
MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); |
370 |
} |
} |
371 |
} |
} |
372 |
|
|
373 |
|
// Do proper enabling... |
374 |
bool bEnabled = !m_midiDevices.isEmpty(); |
bool bEnabled = !m_midiDevices.isEmpty(); |
375 |
if (!bEnabled) |
if (!bEnabled) |
376 |
MidiDeviceComboBox->insertItem(tr("(New MIDI device)")); |
MidiDeviceComboBox->insertItem(tr("(New MIDI device)")); |
377 |
|
else if (iDeviceID >= 0) { |
378 |
|
// Select the previous current device... |
379 |
|
int iMidiItem = 0; |
380 |
|
for (pDevice = m_midiDevices.first(); |
381 |
|
pDevice; |
382 |
|
pDevice = m_midiDevices.next()) { |
383 |
|
if (pDevice->deviceID() == iDeviceID) { |
384 |
|
MidiDeviceComboBox->setCurrentItem(iMidiItem); |
385 |
|
// selectMidiDeviceItem(iMidiItem); |
386 |
|
break; |
387 |
|
} |
388 |
|
iMidiItem++; |
389 |
|
} |
390 |
|
} |
391 |
MidiDeviceTextLabel->setEnabled(bEnabled); |
MidiDeviceTextLabel->setEnabled(bEnabled); |
392 |
MidiDeviceComboBox->setEnabled(bEnabled); |
MidiDeviceComboBox->setEnabled(bEnabled); |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
|
// Refresh MIDI device options slot. |
397 |
|
void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver ) |
398 |
|
{ |
399 |
|
if (m_iDirtySetup > 0) |
400 |
|
return; |
401 |
|
|
402 |
|
selectMidiDriverItem(sMidiDriver); |
403 |
optionsChanged(); |
optionsChanged(); |
404 |
} |
} |
405 |
|
|
406 |
|
|
407 |
// Select MIDI device options. |
// Select MIDI device item. |
408 |
void qsamplerChannelForm::selectMidiDevice ( int iMidiItem ) |
void qsamplerChannelForm::selectMidiDeviceItem ( int iMidiItem ) |
409 |
{ |
{ |
410 |
qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem); |
qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem); |
411 |
if (pDevice) { |
if (pDevice) { |
416 |
if (iPorts > 0) |
if (iPorts > 0) |
417 |
MidiPortSpinBox->setMaxValue(iPorts - 1); |
MidiPortSpinBox->setMaxValue(iPorts - 1); |
418 |
} |
} |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
|
// Select MIDI device options slot. |
423 |
|
void qsamplerChannelForm::selectMidiDevice ( int iMidiItem ) |
424 |
|
{ |
425 |
|
if (m_iDirtySetup > 0) |
426 |
|
return; |
427 |
|
|
428 |
|
selectMidiDeviceItem(iMidiItem); |
429 |
optionsChanged(); |
optionsChanged(); |
430 |
} |
} |
431 |
|
|
432 |
|
|
433 |
// Refresh Audio device options. |
// MIDI device options. |
434 |
void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver ) |
void qsamplerChannelForm::setupMidiDevice (void) |
435 |
|
{ |
436 |
|
setupDevice(m_midiDevices.at(MidiDeviceComboBox->currentItem())); |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
|
// Refresh Audio driver item devices. |
441 |
|
void qsamplerChannelForm::selectAudioDriverItem ( const QString& sAudioDriver ) |
442 |
{ |
{ |
443 |
const QString sDriverName = sAudioDriver.upper(); |
const QString sDriverName = sAudioDriver.upper(); |
444 |
|
|
445 |
|
// Save current device id. |
446 |
|
int iDeviceID = -1; |
447 |
|
qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem()); |
448 |
|
if (pDevice) |
449 |
|
iDeviceID = pDevice->deviceID(); |
450 |
|
|
451 |
|
// Clean maplist. |
452 |
AudioDeviceComboBox->clear(); |
AudioDeviceComboBox->clear(); |
453 |
m_audioDevices.clear(); |
m_audioDevices.clear(); |
454 |
|
|
455 |
|
// Populate with the current ones... |
456 |
const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png"); |
const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png"); |
457 |
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
458 |
qsamplerDevice::Audio); |
qsamplerDevice::Audio); |
459 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
460 |
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), |
pDevice = new qsamplerDevice(m_pChannel->mainForm(), |
461 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
qsamplerDevice::Audio, piDeviceIDs[i]); |
462 |
if (pDevice->driverName().upper() == sDriverName) { |
if (pDevice->driverName().upper() == sDriverName) { |
463 |
AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); |
AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); |
467 |
} |
} |
468 |
} |
} |
469 |
|
|
470 |
|
// Do proper enabling... |
471 |
bool bEnabled = !m_audioDevices.isEmpty(); |
bool bEnabled = !m_audioDevices.isEmpty(); |
472 |
if (!bEnabled) |
if (!bEnabled) |
473 |
AudioDeviceComboBox->insertItem(tr("(New Audio device)")); |
AudioDeviceComboBox->insertItem(tr("(New Audio device)")); |
474 |
|
else if (iDeviceID >= 0) { |
475 |
|
// Select the previous current device... |
476 |
|
int iAudioItem = 0; |
477 |
|
for (pDevice = m_audioDevices.first(); |
478 |
|
pDevice; |
479 |
|
pDevice = m_audioDevices.next()) { |
480 |
|
if (pDevice->deviceID() == iDeviceID) { |
481 |
|
AudioDeviceComboBox->setCurrentItem(iAudioItem); |
482 |
|
// selectAudioDeviceItem(iAudioItem); |
483 |
|
break; |
484 |
|
} |
485 |
|
iAudioItem++; |
486 |
|
} |
487 |
|
} |
488 |
AudioDeviceTextLabel->setEnabled(bEnabled); |
AudioDeviceTextLabel->setEnabled(bEnabled); |
489 |
AudioDeviceComboBox->setEnabled(bEnabled); |
AudioDeviceComboBox->setEnabled(bEnabled); |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
// Refresh Audio device options slot. |
494 |
|
void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver ) |
495 |
|
{ |
496 |
|
if (m_iDirtySetup > 0) |
497 |
|
return; |
498 |
|
|
499 |
|
selectAudioDriverItem(sAudioDriver); |
500 |
optionsChanged(); |
optionsChanged(); |
501 |
} |
} |
502 |
|
|
503 |
|
|
504 |
// Select Audio device options. |
// Select Audio device item. |
505 |
void qsamplerChannelForm::selectAudioDevice ( int iAudioItem ) |
void qsamplerChannelForm::selectAudioDeviceItem ( int iAudioItem ) |
506 |
{ |
{ |
507 |
qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem); |
qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem); |
508 |
if (pDevice) { |
if (pDevice) { |
509 |
// Is there anything to do here? |
// Is there anything to do here? |
510 |
} |
} |
511 |
|
} |
512 |
|
|
513 |
|
|
514 |
|
// Select Audio device options slot. |
515 |
|
void qsamplerChannelForm::selectAudioDevice ( int iAudioItem ) |
516 |
|
{ |
517 |
|
if (m_iDirtySetup > 0) |
518 |
|
return; |
519 |
|
|
520 |
|
selectAudioDeviceItem(iAudioItem); |
521 |
|
optionsChanged(); |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
|
// Audio device options. |
526 |
|
void qsamplerChannelForm::setupAudioDevice (void) |
527 |
|
{ |
528 |
|
setupDevice(m_audioDevices.at(AudioDeviceComboBox->currentItem())); |
529 |
|
} |
530 |
|
|
531 |
|
|
532 |
|
// UPdate all device lists slot. |
533 |
|
void qsamplerChannelForm::updateDevices (void) |
534 |
|
{ |
535 |
|
if (m_iDirtySetup > 0) |
536 |
|
return; |
537 |
|
|
538 |
|
selectMidiDriverItem(MidiDriverComboBox->currentText()); |
539 |
|
selectAudioDriverItem(AudioDriverComboBox->currentText()); |
540 |
optionsChanged(); |
optionsChanged(); |
541 |
} |
} |
542 |
|
|