2 |
// |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
/**************************************************************************** |
5 |
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
26 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
27 |
#include <qlistbox.h> |
#include <qlistbox.h> |
28 |
|
|
|
#include "qsamplerOptions.h" |
|
|
#include "qsamplerChannelStrip.h" |
|
|
|
|
29 |
#include "config.h" |
#include "config.h" |
30 |
|
|
31 |
|
|
38 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
39 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
40 |
|
|
41 |
|
m_midiDevices.setAutoDelete(true); |
42 |
|
m_audioDevices.setAutoDelete(true); |
43 |
|
|
44 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
45 |
adjustSize(); |
adjustSize(); |
46 |
} |
} |
53 |
|
|
54 |
|
|
55 |
// Channel dialog setup formal initializer. |
// Channel dialog setup formal initializer. |
56 |
void qsamplerChannelForm::setup ( qsamplerChannelStrip *pChannel ) |
void qsamplerChannelForm::setup ( qsamplerChannel *pChannel ) |
57 |
{ |
{ |
58 |
m_pChannel = pChannel; |
m_pChannel = pChannel; |
59 |
|
|
63 |
if (m_pChannel == NULL) |
if (m_pChannel == NULL) |
64 |
return; |
return; |
65 |
|
|
66 |
setCaption(m_pChannel->caption()); |
// It can be a brand new channel, remember? |
67 |
|
bool bNew = (m_pChannel->channelID() < 0); |
68 |
|
setCaption(m_pChannel->channelName()); |
69 |
|
|
70 |
// Check if we're up and connected. |
// Check if we're up and connected. |
71 |
if (m_pChannel->client() == NULL) |
if (m_pChannel->client() == NULL) |
91 |
else m_pChannel->appendMessagesClient("lscp_get_available_engines"); |
else m_pChannel->appendMessagesClient("lscp_get_available_engines"); |
92 |
|
|
93 |
// Populate Audio output type list. |
// Populate Audio output type list. |
94 |
const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client()); |
AudioDriverComboBox->clear(); |
95 |
if (ppszAudioDrivers) { |
AudioDriverComboBox->insertStringList( |
96 |
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"); |
|
97 |
|
|
98 |
// Populate MIDI input type list. |
// Populate MIDI input type list. |
99 |
const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client()); |
MidiDriverComboBox->clear(); |
100 |
if (ppszMidiDrivers) { |
MidiDriverComboBox->insertStringList( |
101 |
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"); |
|
102 |
|
|
103 |
// Read proper channel information, |
// Read proper channel information, |
104 |
// and populate the channel form fields. |
// and populate the channel form fields. |
105 |
|
|
106 |
// Engine name... |
// Engine name... |
107 |
QString sEngineName = pChannel->engineName(); |
QString sEngineName = pChannel->engineName(); |
108 |
|
if (sEngineName.isEmpty() || bNew) |
109 |
|
sEngineName = pOptions->sEngineName; |
110 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
111 |
sEngineName = tr("(No engine)"); |
sEngineName = qsamplerChannel::noEngineName(); |
112 |
if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) |
if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) |
113 |
EngineNameComboBox->insertItem(sEngineName); |
EngineNameComboBox->insertItem(sEngineName); |
114 |
EngineNameComboBox->setCurrentText(sEngineName); |
EngineNameComboBox->setCurrentText(sEngineName); |
115 |
// Instrument filename and index... |
// Instrument filename and index... |
116 |
QString sInstrumentFile = pChannel->instrumentFile(); |
QString sInstrumentFile = pChannel->instrumentFile(); |
117 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
118 |
sInstrumentFile = tr("(No instrument)"); |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
119 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
120 |
InstrumentNrSpinBox->setValue(pChannel->instrumentNr()); |
InstrumentNrComboBox->clear(); |
121 |
// MIDI input... |
InstrumentNrComboBox->insertStringList( |
122 |
const QString& sMidiDriver = pChannel->midiDriver(); |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
123 |
if (!sMidiDriver.isEmpty()) { |
pOptions->bInstrumentNames)); |
124 |
if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
125 |
MidiDriverComboBox->insertItem(sMidiDriver); |
|
126 |
MidiDriverComboBox->setCurrentText(sMidiDriver); |
// MIDI input device... |
127 |
} |
qsamplerDevice midiDevice(m_pChannel->client(), |
128 |
|
qsamplerDevice::Midi, m_pChannel->midiDevice()); |
129 |
|
// MIDI input driver... |
130 |
|
QString sMidiDriver = midiDevice.driverName(); |
131 |
|
if (sMidiDriver.isEmpty() || bNew) |
132 |
|
sMidiDriver = pOptions->sMidiDriver; |
133 |
|
if (!sMidiDriver.isEmpty()) { |
134 |
|
if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) |
135 |
|
MidiDriverComboBox->insertItem(sMidiDriver); |
136 |
|
MidiDriverComboBox->setCurrentText(sMidiDriver); |
137 |
|
} |
138 |
|
selectMidiDriver(sMidiDriver); |
139 |
|
if (!bNew) |
140 |
|
MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); |
141 |
|
// MIDI input port... |
142 |
MidiPortSpinBox->setValue(pChannel->midiPort()); |
MidiPortSpinBox->setValue(pChannel->midiPort()); |
143 |
MidiChannelSpinBox->setValue(pChannel->midiChannel()); |
// MIDI input channel... |
144 |
// Audio output... |
int iMidiChannel = pChannel->midiChannel(); |
145 |
const QString& sAudioDriver = pChannel->audioDriver(); |
// When new, try to suggest a sensible MIDI channel... |
146 |
if (!sAudioDriver.isEmpty()) { |
if (iMidiChannel < 0) |
147 |
if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) |
iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16); |
148 |
AudioDriverComboBox->insertItem(sAudioDriver); |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
149 |
AudioDriverComboBox->setCurrentText(sAudioDriver); |
|
150 |
} |
// Audio output device... |
151 |
|
qsamplerDevice audioDevice(m_pChannel->client(), |
152 |
|
qsamplerDevice::Audio, m_pChannel->audioDevice()); |
153 |
|
// Audio output driver... |
154 |
|
QString sAudioDriver = audioDevice.driverName(); |
155 |
|
if (sAudioDriver.isEmpty() || bNew) |
156 |
|
sAudioDriver = pOptions->sAudioDriver; |
157 |
|
if (!sAudioDriver.isEmpty()) { |
158 |
|
if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) |
159 |
|
AudioDriverComboBox->insertItem(sAudioDriver); |
160 |
|
AudioDriverComboBox->setCurrentText(sAudioDriver); |
161 |
|
} |
162 |
|
selectAudioDriver(sAudioDriver); |
163 |
|
if (!bNew) |
164 |
|
AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); |
165 |
|
|
166 |
|
// As convenient, make it ready on stabilizeForm() for |
167 |
|
// prompt acceptance, if we got the minimum required... |
168 |
|
if (sEngineName != qsamplerChannel::noEngineName() && |
169 |
|
sInstrumentFile != qsamplerChannel::noInstrumentName()) |
170 |
|
m_iDirtyCount++; |
171 |
|
// FIXME: These are better leave diabled... |
172 |
|
MidiPortTextLabel->setEnabled(false); |
173 |
|
MidiPortSpinBox->setEnabled(false); |
174 |
// Done. |
// Done. |
175 |
m_iDirtySetup--; |
m_iDirtySetup--; |
176 |
stabilizeForm(); |
stabilizeForm(); |
190 |
// We'll go for it! |
// We'll go for it! |
191 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
192 |
int iErrors = 0; |
int iErrors = 0; |
193 |
// Audio output driver type... |
// Are we a new channel? |
194 |
if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) |
if (!m_pChannel->addChannel()) |
|
iErrors++; |
|
|
// MIDI input driver type... |
|
|
if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) |
|
195 |
iErrors++; |
iErrors++; |
196 |
|
// Accept Audio driver or device selection... |
197 |
|
if (m_audioDevices.isEmpty()) { |
198 |
|
if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) |
199 |
|
iErrors++; |
200 |
|
} else { |
201 |
|
qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem()); |
202 |
|
if (pDevice == NULL) |
203 |
|
iErrors++; |
204 |
|
else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) |
205 |
|
iErrors++; |
206 |
|
} |
207 |
|
// Accept MIDI driver or device selection... |
208 |
|
if (m_midiDevices.isEmpty()) { |
209 |
|
if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) |
210 |
|
iErrors++; |
211 |
|
} else { |
212 |
|
qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem()); |
213 |
|
if (pDevice == NULL) |
214 |
|
iErrors++; |
215 |
|
else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) |
216 |
|
iErrors++; |
217 |
|
} |
218 |
// MIDI input port number... |
// MIDI input port number... |
219 |
if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) |
if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) |
220 |
iErrors++; |
iErrors++; |
221 |
// MIDI input channel... |
// MIDI input channel... |
222 |
if (!m_pChannel->setMidiChannel(MidiChannelSpinBox->value())) |
if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem())) |
223 |
iErrors++; |
iErrors++; |
224 |
// Engine name... |
// Engine name... |
225 |
if (!m_pChannel->loadEngine(EngineNameComboBox->currentText())) |
if (!m_pChannel->loadEngine(EngineNameComboBox->currentText())) |
226 |
iErrors++; |
iErrors++; |
227 |
// Instrument file and index... |
// Instrument file and index... |
228 |
if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrSpinBox->value())) |
if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem())) |
229 |
iErrors++; |
iErrors++; |
230 |
// Show error messages? |
// Show error messages? |
231 |
if (iErrors > 0) |
if (iErrors > 0) |
232 |
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.")); |
233 |
} |
} |
234 |
|
|
235 |
// Save default instrument directory and history... |
// Save default engine name, instrument directory and history... |
236 |
pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); |
pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); |
237 |
|
pOptions->sEngineName = EngineNameComboBox->currentText(); |
238 |
|
pOptions->sAudioDriver = AudioDriverComboBox->currentText(); |
239 |
|
pOptions->sMidiDriver = MidiDriverComboBox->currentText(); |
240 |
pOptions->saveComboBoxHistory(InstrumentFileComboBox); |
pOptions->saveComboBoxHistory(InstrumentFileComboBox); |
241 |
|
|
242 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
250 |
bool bReject = true; |
bool bReject = true; |
251 |
|
|
252 |
// Check if there's any pending changes... |
// Check if there's any pending changes... |
253 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) { |
254 |
switch (QMessageBox::warning(this, tr("Warning"), |
switch (QMessageBox::warning(this, tr("Warning"), |
255 |
tr("Some channel settings have been changed.\n\n" |
tr("Some channel settings have been changed.\n\n" |
256 |
"Do you want to apply the changes?"), |
"Do you want to apply the changes?"), |
296 |
// Refresh the actual instrument name. |
// Refresh the actual instrument name. |
297 |
void qsamplerChannelForm::updateInstrumentName (void) |
void qsamplerChannelForm::updateInstrumentName (void) |
298 |
{ |
{ |
299 |
// FIXME: A better idea would be to use libgig |
qsamplerOptions *pOptions = m_pChannel->options(); |
300 |
// to retrieve the REAL instrument name. |
if (pOptions == NULL) |
301 |
InstrumentNameTextLabel->setText(QFileInfo(InstrumentFileComboBox->currentText()).fileName() |
return; |
302 |
+ " [" + QString::number(InstrumentNrSpinBox->value()) + "]"); |
|
303 |
|
// Finally this better idea would be to use libgig |
304 |
|
// to retrieve the REAL instrument names. |
305 |
|
InstrumentNrComboBox->clear(); |
306 |
|
InstrumentNrComboBox->insertStringList( |
307 |
|
qsamplerChannel::getInstrumentList( |
308 |
|
InstrumentFileComboBox->currentText(), |
309 |
|
pOptions->bInstrumentNames) |
310 |
|
); |
311 |
|
|
312 |
optionsChanged(); |
optionsChanged(); |
313 |
} |
} |
314 |
|
|
315 |
|
|
316 |
|
// Refresh MIDI device options. |
317 |
|
void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver ) |
318 |
|
{ |
319 |
|
MidiDeviceComboBox->clear(); |
320 |
|
m_audioDevices.clear(); |
321 |
|
|
322 |
|
const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png"); |
323 |
|
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
324 |
|
qsamplerDevice::Midi); |
325 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
326 |
|
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), |
327 |
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
328 |
|
if (pDevice->driverName() == sMidiDriver) { |
329 |
|
MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); |
330 |
|
m_midiDevices.append(pDevice); |
331 |
|
} else { |
332 |
|
delete pDevice; |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
|
bool bEnabled = !m_midiDevices.isEmpty(); |
337 |
|
MidiDeviceTextLabel->setEnabled(bEnabled); |
338 |
|
MidiDeviceComboBox->setEnabled(bEnabled); |
339 |
|
optionsChanged(); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
// Refresh Audio device options. |
344 |
|
void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver ) |
345 |
|
{ |
346 |
|
AudioDeviceComboBox->clear(); |
347 |
|
m_audioDevices.clear(); |
348 |
|
|
349 |
|
const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png"); |
350 |
|
int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), |
351 |
|
qsamplerDevice::Audio); |
352 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
353 |
|
qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), |
354 |
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
355 |
|
if (pDevice->driverName() == sAudioDriver) { |
356 |
|
AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); |
357 |
|
m_audioDevices.append(pDevice); |
358 |
|
} else { |
359 |
|
delete pDevice; |
360 |
|
} |
361 |
|
} |
362 |
|
|
363 |
|
bool bEnabled = !m_audioDevices.isEmpty(); |
364 |
|
AudioDeviceTextLabel->setEnabled(bEnabled); |
365 |
|
AudioDeviceComboBox->setEnabled(bEnabled); |
366 |
|
optionsChanged(); |
367 |
|
} |
368 |
|
|
369 |
|
|
370 |
// Dirty up settings. |
// Dirty up settings. |
371 |
void qsamplerChannelForm::optionsChanged (void) |
void qsamplerChannelForm::optionsChanged (void) |