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 |
|
|
40 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
41 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
42 |
|
|
43 |
|
m_midiDevices.setAutoDelete(true); |
44 |
|
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 |
|
|
98 |
else m_pChannel->appendMessagesClient("lscp_get_available_engines"); |
else m_pChannel->appendMessagesClient("lscp_get_available_engines"); |
99 |
|
|
100 |
// Populate Audio output type list. |
// Populate Audio output type list. |
101 |
const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client()); |
AudioDriverComboBox->clear(); |
102 |
if (ppszAudioDrivers) { |
AudioDriverComboBox->insertStringList( |
103 |
AudioDriverComboBox->clear(); |
qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio)); |
|
for (int iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) |
|
|
AudioDriverComboBox->insertItem(ppszAudioDrivers[iAudioDriver]); |
|
|
} |
|
|
else m_pChannel->appendMessagesClient("lscp_get_available_audio_drivers"); |
|
104 |
|
|
105 |
// Populate MIDI input type list. |
// Populate MIDI input type list. |
106 |
const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client()); |
MidiDriverComboBox->clear(); |
107 |
if (ppszMidiDrivers) { |
MidiDriverComboBox->insertStringList( |
108 |
MidiDriverComboBox->clear(); |
qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi)); |
|
for (int iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) |
|
|
MidiDriverComboBox->insertItem(ppszMidiDrivers[iMidiDriver]); |
|
|
} |
|
|
else m_pChannel->appendMessagesClient("lscp_get_available_midi_drivers"); |
|
109 |
|
|
110 |
// Read proper channel information, |
// Read proper channel information, |
111 |
// and populate the channel form fields. |
// and populate the channel form fields. |
112 |
|
|
113 |
// Engine name... |
// Engine name... |
114 |
QString sEngineName = pChannel->engineName(); |
QString sEngineName = pChannel->engineName(); |
115 |
if (sEngineName.isEmpty() && bNew) |
if (sEngineName.isEmpty() || bNew) |
116 |
sEngineName = pOptions->sEngineName; |
sEngineName = pOptions->sEngineName; |
117 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
118 |
sEngineName = tr("(No engine)"); |
sEngineName = qsamplerChannel::noEngineName(); |
119 |
if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) |
if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) |
120 |
EngineNameComboBox->insertItem(sEngineName); |
EngineNameComboBox->insertItem(sEngineName); |
121 |
EngineNameComboBox->setCurrentText(sEngineName); |
EngineNameComboBox->setCurrentText(sEngineName); |
122 |
// Instrument filename and index... |
// Instrument filename and index... |
123 |
QString sInstrumentFile = pChannel->instrumentFile(); |
QString sInstrumentFile = pChannel->instrumentFile(); |
124 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
125 |
sInstrumentFile = tr("(No instrument)"); |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
126 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
127 |
InstrumentNrComboBox->clear(); |
InstrumentNrComboBox->clear(); |
128 |
InstrumentNrComboBox->insertStringList( |
InstrumentNrComboBox->insertStringList( |
129 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
130 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
131 |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
132 |
|
|
133 |
|
// MIDI input device... |
134 |
|
qsamplerDevice midiDevice(m_pChannel->mainForm(), |
135 |
|
qsamplerDevice::Midi, m_pChannel->midiDevice()); |
136 |
// MIDI input driver... |
// MIDI input driver... |
137 |
QString sMidiDriver = pChannel->midiDriver(); |
QString sMidiDriver = midiDevice.driverName(); |
138 |
if (sMidiDriver.isEmpty() || bNew) |
if (sMidiDriver.isEmpty() || bNew) |
139 |
sMidiDriver = pOptions->sMidiDriver; |
sMidiDriver = pOptions->sMidiDriver; |
140 |
if (!sMidiDriver.isEmpty()) { |
if (!sMidiDriver.isEmpty()) { |
141 |
if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) |
if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) |
142 |
MidiDriverComboBox->insertItem(sMidiDriver); |
MidiDriverComboBox->insertItem(sMidiDriver); |
143 |
MidiDriverComboBox->setCurrentText(sMidiDriver); |
MidiDriverComboBox->setCurrentText(sMidiDriver); |
144 |
} |
} |
145 |
|
selectMidiDriver(sMidiDriver); |
146 |
|
if (!bNew) |
147 |
|
MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); |
148 |
|
selectMidiDevice(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... |
154 |
if (iMidiChannel < 0) |
if (iMidiChannel < 0) |
155 |
iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16); |
iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16); |
156 |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
157 |
// Audio output driver... |
|
158 |
QString sAudioDriver = pChannel->audioDriver(); |
// Audio output device... |
159 |
if (sAudioDriver.isEmpty() || bNew) |
qsamplerDevice audioDevice(m_pChannel->mainForm(), |
160 |
sAudioDriver = pOptions->sAudioDriver; |
qsamplerDevice::Audio, m_pChannel->audioDevice()); |
161 |
if (!sAudioDriver.isEmpty()) { |
// Audio output driver... |
162 |
if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) |
QString sAudioDriver = audioDevice.driverName(); |
163 |
AudioDriverComboBox->insertItem(sAudioDriver); |
if (sAudioDriver.isEmpty() || bNew) |
164 |
AudioDriverComboBox->setCurrentText(sAudioDriver); |
sAudioDriver = pOptions->sAudioDriver; |
165 |
} |
if (!sAudioDriver.isEmpty()) { |
166 |
|
if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) |
167 |
|
AudioDriverComboBox->insertItem(sAudioDriver); |
168 |
|
AudioDriverComboBox->setCurrentText(sAudioDriver); |
169 |
|
} |
170 |
|
selectAudioDriver(sAudioDriver); |
171 |
|
if (!bNew) |
172 |
|
AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); |
173 |
|
selectAudioDevice(AudioDeviceComboBox->currentItem()); |
174 |
|
|
175 |
|
// As convenient, make it ready on stabilizeForm() for |
176 |
|
// prompt acceptance, if we got the minimum required... |
177 |
|
if (sEngineName != qsamplerChannel::noEngineName() && |
178 |
|
sInstrumentFile != qsamplerChannel::noInstrumentName()) |
179 |
|
m_iDirtyCount++; |
180 |
// Done. |
// Done. |
181 |
m_iDirtySetup--; |
m_iDirtySetup--; |
182 |
stabilizeForm(); |
stabilizeForm(); |
199 |
// Are we a new channel? |
// Are we a new channel? |
200 |
if (!m_pChannel->addChannel()) |
if (!m_pChannel->addChannel()) |
201 |
iErrors++; |
iErrors++; |
202 |
// Audio output driver type... |
// Accept Audio driver or device selection... |
203 |
if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) |
if (m_audioDevices.isEmpty()) { |
204 |
iErrors++; |
if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) |
205 |
// MIDI input driver type... |
iErrors++; |
206 |
if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) |
} else { |
207 |
iErrors++; |
qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem()); |
208 |
|
if (pDevice == NULL) |
209 |
|
iErrors++; |
210 |
|
else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) |
211 |
|
iErrors++; |
212 |
|
} |
213 |
|
// Accept MIDI driver or device selection... |
214 |
|
if (m_midiDevices.isEmpty()) { |
215 |
|
if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) |
216 |
|
iErrors++; |
217 |
|
} else { |
218 |
|
qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem()); |
219 |
|
if (pDevice == NULL) |
220 |
|
iErrors++; |
221 |
|
else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) |
222 |
|
iErrors++; |
223 |
|
} |
224 |
// MIDI input port number... |
// MIDI input port number... |
225 |
if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) |
if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) |
226 |
iErrors++; |
iErrors++; |
318 |
optionsChanged(); |
optionsChanged(); |
319 |
} |
} |
320 |
|
|
321 |
|
// Show device options dialog. |
322 |
|
void qsamplerChannelForm::setupDevice ( qsamplerDevice *pDevice ) |
323 |
|
{ |
324 |
|
if (pDevice == NULL) |
325 |
|
return; |
326 |
|
|
327 |
|
// Create the device form if not already... |
328 |
|
if (m_pDeviceForm == NULL) { |
329 |
|
m_pDeviceForm = new qsamplerDeviceForm(this, 0, |
330 |
|
WType_Dialog | WShowModal); |
331 |
|
m_pDeviceForm->setMainForm(m_pChannel->mainForm()); |
332 |
|
m_pDeviceForm->move(QDialog::pos() + QPoint(32, 32)); |
333 |
|
} |
334 |
|
|
335 |
|
// Refresh the device form with selected data. |
336 |
|
if (m_pDeviceForm) { |
337 |
|
m_pDeviceForm->setClient(m_pChannel->client()); // <-- refreshDevices(). |
338 |
|
m_pDeviceForm->setDevice(pDevice->deviceType(), |
339 |
|
pDevice->deviceID()); |
340 |
|
m_pDeviceForm->show(); |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
|
// Refresh MIDI device options. |
346 |
|
void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver ) |
347 |
|
{ |
348 |
|
const QString sDriverName = sMidiDriver.upper(); |
349 |
|
|
350 |
|
MidiDeviceComboBox->clear(); |
351 |
|
m_audioDevices.clear(); |
352 |
|
|
353 |
|
const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png"); |
354 |
|
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
355 |
|
qsamplerDevice::Midi); |
356 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
357 |
|
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->mainForm(), |
358 |
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
359 |
|
if (pDevice->driverName().upper() == sDriverName) { |
360 |
|
MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); |
361 |
|
m_midiDevices.append(pDevice); |
362 |
|
} else { |
363 |
|
delete pDevice; |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
|
bool bEnabled = !m_midiDevices.isEmpty(); |
368 |
|
if (!bEnabled) |
369 |
|
MidiDeviceComboBox->insertItem(tr("(New MIDI device)")); |
370 |
|
MidiDeviceTextLabel->setEnabled(bEnabled); |
371 |
|
MidiDeviceComboBox->setEnabled(bEnabled); |
372 |
|
MidiDevicePushButton->setEnabled(bEnabled); |
373 |
|
optionsChanged(); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
// Select MIDI device options. |
378 |
|
void qsamplerChannelForm::selectMidiDevice ( int iMidiItem ) |
379 |
|
{ |
380 |
|
qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem); |
381 |
|
if (pDevice) { |
382 |
|
const qsamplerDeviceParamMap& params = pDevice->params(); |
383 |
|
int iPorts = params["PORTS"].value.toInt(); |
384 |
|
MidiPortTextLabel->setEnabled(iPorts > 0); |
385 |
|
MidiPortSpinBox->setEnabled(iPorts > 0); |
386 |
|
if (iPorts > 0) |
387 |
|
MidiPortSpinBox->setMaxValue(iPorts - 1); |
388 |
|
} |
389 |
|
optionsChanged(); |
390 |
|
} |
391 |
|
|
392 |
|
|
393 |
|
// MIDI device options. |
394 |
|
void qsamplerChannelForm::setupMidiDevice (void) |
395 |
|
{ |
396 |
|
setupDevice(m_midiDevices.at(MidiDeviceComboBox->currentItem())); |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
// Refresh Audio device options. |
401 |
|
void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver ) |
402 |
|
{ |
403 |
|
const QString sDriverName = sAudioDriver.upper(); |
404 |
|
|
405 |
|
AudioDeviceComboBox->clear(); |
406 |
|
m_audioDevices.clear(); |
407 |
|
|
408 |
|
const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png"); |
409 |
|
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
410 |
|
qsamplerDevice::Audio); |
411 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
412 |
|
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->mainForm(), |
413 |
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
414 |
|
if (pDevice->driverName().upper() == sDriverName) { |
415 |
|
AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); |
416 |
|
m_audioDevices.append(pDevice); |
417 |
|
} else { |
418 |
|
delete pDevice; |
419 |
|
} |
420 |
|
} |
421 |
|
|
422 |
|
bool bEnabled = !m_audioDevices.isEmpty(); |
423 |
|
if (!bEnabled) |
424 |
|
AudioDeviceComboBox->insertItem(tr("(New Audio device)")); |
425 |
|
AudioDeviceTextLabel->setEnabled(bEnabled); |
426 |
|
AudioDeviceComboBox->setEnabled(bEnabled); |
427 |
|
AudioDevicePushButton->setEnabled(bEnabled); |
428 |
|
optionsChanged(); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
// Select Audio device options. |
433 |
|
void qsamplerChannelForm::selectAudioDevice ( int iAudioItem ) |
434 |
|
{ |
435 |
|
qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem); |
436 |
|
if (pDevice) { |
437 |
|
// Is there anything to do here? |
438 |
|
} |
439 |
|
optionsChanged(); |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
|
// Audio device options. |
444 |
|
void qsamplerChannelForm::setupAudioDevice (void) |
445 |
|
{ |
446 |
|
setupDevice(m_audioDevices.at(AudioDeviceComboBox->currentItem())); |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
// Dirty up settings. |
// Dirty up settings. |