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