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