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