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