1 |
// qsamplerChannelForm.ui.h |
2 |
// |
3 |
// 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. |
6 |
|
7 |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
9 |
as published by the Free Software Foundation; either version 2 |
10 |
of the License, or (at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
21 |
*****************************************************************************/ |
22 |
|
23 |
#include <qvalidator.h> |
24 |
#include <qmessagebox.h> |
25 |
#include <qfiledialog.h> |
26 |
#include <qfileinfo.h> |
27 |
#include <qlistbox.h> |
28 |
|
29 |
#include "config.h" |
30 |
|
31 |
|
32 |
// Kind of constructor. |
33 |
void qsamplerChannelForm::init (void) |
34 |
{ |
35 |
// Initialize locals. |
36 |
m_pChannel = NULL; |
37 |
|
38 |
m_iDirtySetup = 0; |
39 |
m_iDirtyCount = 0; |
40 |
|
41 |
m_midiDevices.setAutoDelete(true); |
42 |
m_audioDevices.setAutoDelete(true); |
43 |
|
44 |
// Try to restore normal window positioning. |
45 |
adjustSize(); |
46 |
} |
47 |
|
48 |
|
49 |
// Kind of destructor. |
50 |
void qsamplerChannelForm::destroy (void) |
51 |
{ |
52 |
} |
53 |
|
54 |
|
55 |
// Channel dialog setup formal initializer. |
56 |
void qsamplerChannelForm::setup ( qsamplerChannel *pChannel ) |
57 |
{ |
58 |
m_pChannel = pChannel; |
59 |
|
60 |
m_iDirtySetup = 0; |
61 |
m_iDirtyCount = 0; |
62 |
|
63 |
if (m_pChannel == NULL) |
64 |
return; |
65 |
|
66 |
// 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. |
71 |
if (m_pChannel->client() == NULL) |
72 |
return; |
73 |
|
74 |
qsamplerOptions *pOptions = m_pChannel->options(); |
75 |
if (pOptions == NULL) |
76 |
return; |
77 |
|
78 |
// Avoid nested changes. |
79 |
m_iDirtySetup++; |
80 |
|
81 |
// Load combo box history... |
82 |
pOptions->loadComboBoxHistory(InstrumentFileComboBox); |
83 |
|
84 |
// Populate Engines list. |
85 |
const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client()); |
86 |
if (ppszEngines) { |
87 |
EngineNameComboBox->clear(); |
88 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
89 |
EngineNameComboBox->insertItem(ppszEngines[iEngine]); |
90 |
} |
91 |
else m_pChannel->appendMessagesClient("lscp_get_available_engines"); |
92 |
|
93 |
// Populate Audio output type list. |
94 |
AudioDriverComboBox->clear(); |
95 |
AudioDriverComboBox->insertStringList( |
96 |
qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio)); |
97 |
|
98 |
// Populate MIDI input type list. |
99 |
MidiDriverComboBox->clear(); |
100 |
MidiDriverComboBox->insertStringList( |
101 |
qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi)); |
102 |
|
103 |
// Read proper channel information, |
104 |
// and populate the channel form fields. |
105 |
|
106 |
// Engine name... |
107 |
QString sEngineName = pChannel->engineName(); |
108 |
if (sEngineName.isEmpty() || bNew) |
109 |
sEngineName = pOptions->sEngineName; |
110 |
if (sEngineName.isEmpty()) |
111 |
sEngineName = qsamplerChannel::noEngineName(); |
112 |
if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) |
113 |
EngineNameComboBox->insertItem(sEngineName); |
114 |
EngineNameComboBox->setCurrentText(sEngineName); |
115 |
// Instrument filename and index... |
116 |
QString sInstrumentFile = pChannel->instrumentFile(); |
117 |
if (sInstrumentFile.isEmpty()) |
118 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
119 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
120 |
InstrumentNrComboBox->clear(); |
121 |
InstrumentNrComboBox->insertStringList( |
122 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
123 |
pOptions->bInstrumentNames)); |
124 |
InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
125 |
|
126 |
// 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()); |
143 |
// MIDI input channel... |
144 |
int iMidiChannel = pChannel->midiChannel(); |
145 |
// When new, try to suggest a sensible MIDI channel... |
146 |
if (iMidiChannel < 0) |
147 |
iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16); |
148 |
MidiChannelComboBox->setCurrentItem(iMidiChannel); |
149 |
|
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. |
175 |
m_iDirtySetup--; |
176 |
stabilizeForm(); |
177 |
} |
178 |
|
179 |
|
180 |
// Accept settings (OK button slot). |
181 |
void qsamplerChannelForm::accept (void) |
182 |
{ |
183 |
if (m_pChannel == NULL) |
184 |
return; |
185 |
|
186 |
qsamplerOptions *pOptions = m_pChannel->options(); |
187 |
if (pOptions == NULL) |
188 |
return; |
189 |
|
190 |
// We'll go for it! |
191 |
if (m_iDirtyCount > 0) { |
192 |
int iErrors = 0; |
193 |
// Are we a new channel? |
194 |
if (!m_pChannel->addChannel()) |
195 |
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... |
219 |
if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) |
220 |
iErrors++; |
221 |
// MIDI input channel... |
222 |
if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem())) |
223 |
iErrors++; |
224 |
// Engine name... |
225 |
if (!m_pChannel->loadEngine(EngineNameComboBox->currentText())) |
226 |
iErrors++; |
227 |
// Instrument file and index... |
228 |
if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem())) |
229 |
iErrors++; |
230 |
// Show error messages? |
231 |
if (iErrors > 0) |
232 |
m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry.")); |
233 |
} |
234 |
|
235 |
// Save default engine name, instrument directory and history... |
236 |
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); |
241 |
|
242 |
// Just go with dialog acceptance. |
243 |
QDialog::accept(); |
244 |
} |
245 |
|
246 |
|
247 |
// Reject settings (Cancel button slot). |
248 |
void qsamplerChannelForm::reject (void) |
249 |
{ |
250 |
bool bReject = true; |
251 |
|
252 |
// Check if there's any pending changes... |
253 |
if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) { |
254 |
switch (QMessageBox::warning(this, tr("Warning"), |
255 |
tr("Some channel settings have been changed.\n\n" |
256 |
"Do you want to apply the changes?"), |
257 |
tr("Apply"), tr("Discard"), tr("Cancel"))) { |
258 |
case 0: // Apply... |
259 |
accept(); |
260 |
return; |
261 |
case 1: // Discard |
262 |
break; |
263 |
default: // Cancel. |
264 |
bReject = false; |
265 |
} |
266 |
} |
267 |
|
268 |
if (bReject) |
269 |
QDialog::reject(); |
270 |
} |
271 |
|
272 |
|
273 |
// Browse and open an instrument file. |
274 |
void qsamplerChannelForm::openInstrumentFile (void) |
275 |
{ |
276 |
qsamplerOptions *pOptions = m_pChannel->options(); |
277 |
if (pOptions == NULL) |
278 |
return; |
279 |
|
280 |
// FIXME: the instrument file filters should be restricted, |
281 |
// depending on the current engine. |
282 |
QString sInstrumentFile = QFileDialog::getOpenFileName( |
283 |
pOptions->sInstrumentDir, // Start here. |
284 |
tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) |
285 |
this, 0, // Parent and name (none) |
286 |
tr("Instrument files") // Caption. |
287 |
); |
288 |
|
289 |
if (sInstrumentFile.isEmpty()) |
290 |
return; |
291 |
|
292 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
293 |
} |
294 |
|
295 |
|
296 |
// Refresh the actual instrument name. |
297 |
void qsamplerChannelForm::updateInstrumentName (void) |
298 |
{ |
299 |
qsamplerOptions *pOptions = m_pChannel->options(); |
300 |
if (pOptions == NULL) |
301 |
return; |
302 |
|
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(); |
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. |
371 |
void qsamplerChannelForm::optionsChanged (void) |
372 |
{ |
373 |
if (m_iDirtySetup > 0) |
374 |
return; |
375 |
|
376 |
m_iDirtyCount++; |
377 |
stabilizeForm(); |
378 |
} |
379 |
|
380 |
|
381 |
// Stabilize current form state. |
382 |
void qsamplerChannelForm::stabilizeForm (void) |
383 |
{ |
384 |
const QString& sFilename = InstrumentFileComboBox->currentText(); |
385 |
OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists()); |
386 |
} |
387 |
|
388 |
|
389 |
// end of qsamplerChannelForm.ui.h |
390 |
|