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