28 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
29 |
#include "qsamplerInstrument.h" |
#include "qsamplerInstrument.h" |
30 |
|
|
31 |
#include <qvalidator.h> |
#include <QValidator> |
32 |
#include <qmessagebox.h> |
#include <QMessageBox> |
33 |
#include <qfiledialog.h> |
#include <QFileDialog> |
34 |
#include <qfileinfo.h> |
#include <QFileInfo> |
35 |
|
|
36 |
|
#include <QHeaderView> |
37 |
|
|
38 |
|
|
39 |
namespace QSampler { |
namespace QSampler { |
40 |
|
|
47 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
48 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
49 |
|
|
50 |
m_midiDevices.setAutoDelete(true); |
// m_midiDevices.setAutoDelete(true); |
51 |
m_audioDevices.setAutoDelete(true); |
// m_audioDevices.setAutoDelete(true); |
52 |
|
|
53 |
m_pDeviceForm = NULL; |
m_pDeviceForm = NULL; |
54 |
|
|
55 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
56 |
adjustSize(); |
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() { |
ChannelForm::~ChannelForm() |
119 |
|
{ |
120 |
if (m_pDeviceForm) |
if (m_pDeviceForm) |
121 |
delete m_pDeviceForm; |
delete m_pDeviceForm; |
122 |
m_pDeviceForm = NULL; |
m_pDeviceForm = NULL; |
123 |
|
|
124 |
|
qDeleteAll(m_midiDevices); |
125 |
|
m_midiDevices.clear(); |
126 |
|
|
127 |
|
qDeleteAll(m_audioDevices); |
128 |
|
m_audioDevices.clear(); |
129 |
} |
} |
130 |
|
|
131 |
|
|
142 |
|
|
143 |
// It can be a brand new channel, remember? |
// It can be a brand new channel, remember? |
144 |
bool bNew = (m_pChannel->channelID() < 0); |
bool bNew = (m_pChannel->channelID() < 0); |
145 |
setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName()); |
setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName()); |
146 |
|
|
147 |
// Check if we're up and connected. |
// Check if we're up and connected. |
148 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
161 |
// Load combo box history... |
// Load combo box history... |
162 |
pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); |
163 |
|
|
|
// Notify.that we've just changed one audio route. |
|
|
QObject::connect(ui.AudioRoutingTable, SIGNAL(valueChanged(int,int)), |
|
|
this, SLOT(changeAudioRouting(int,int))); |
|
|
|
|
164 |
// Populate Engines list. |
// Populate Engines list. |
165 |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
166 |
if (ppszEngines) { |
if (ppszEngines) { |
167 |
ui.EngineNameComboBox->clear(); |
ui.EngineNameComboBox->clear(); |
168 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
169 |
ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]); |
ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine])); |
170 |
} |
} |
171 |
else m_pChannel->appendMessagesClient("lscp_list_available_engines"); |
else m_pChannel->appendMessagesClient("lscp_list_available_engines"); |
172 |
|
|
173 |
// Populate Audio output type list. |
// Populate Audio output type list. |
174 |
ui.AudioDriverComboBox->clear(); |
ui.AudioDriverComboBox->clear(); |
175 |
ui.AudioDriverComboBox->insertStringList( |
ui.AudioDriverComboBox->insertItems(0, |
176 |
qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio)); |
qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio)); |
177 |
|
|
178 |
// Populate MIDI input type list. |
// Populate MIDI input type list. |
179 |
ui.MidiDriverComboBox->clear(); |
ui.MidiDriverComboBox->clear(); |
180 |
ui.MidiDriverComboBox->insertStringList( |
ui.MidiDriverComboBox->insertItems(0, |
181 |
qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi)); |
qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi)); |
182 |
|
|
183 |
// Populate Maps list. |
// Populate Maps list. |
184 |
ui.MidiMapComboBox->clear(); |
ui.MidiMapComboBox->clear(); |
185 |
ui.MidiMapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
ui.MidiMapComboBox->insertItems(0, |
186 |
|
qsamplerInstrument::getMapNames()); |
187 |
|
|
188 |
// Read proper channel information, |
// Read proper channel information, |
189 |
// and populate the channel form fields. |
// and populate the channel form fields. |
195 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
196 |
sEngineName = qsamplerChannel::noEngineName(); |
sEngineName = qsamplerChannel::noEngineName(); |
197 |
if (ui.EngineNameComboBox->findText(sEngineName, |
if (ui.EngineNameComboBox->findText(sEngineName, |
198 |
Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
199 |
ui.EngineNameComboBox->insertItem(sEngineName); |
ui.EngineNameComboBox->addItem(sEngineName); |
200 |
} |
} |
201 |
ui.EngineNameComboBox->setCurrentText(sEngineName); |
ui.EngineNameComboBox->setCurrentIndex( |
202 |
|
ui.EngineNameComboBox->findText(sEngineName, |
203 |
|
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
204 |
|
|
205 |
// Instrument filename and index... |
// Instrument filename and index... |
206 |
QString sInstrumentFile = pChannel->instrumentFile(); |
QString sInstrumentFile = pChannel->instrumentFile(); |
207 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
208 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
209 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
210 |
ui.InstrumentNrComboBox->clear(); |
ui.InstrumentNrComboBox->clear(); |
211 |
ui.InstrumentNrComboBox->insertStringList( |
ui.InstrumentNrComboBox->insertItems(0, |
212 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
213 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
214 |
ui.InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); |
ui.InstrumentNrComboBox->setCurrentIndex(pChannel->instrumentNr()); |
215 |
|
|
216 |
// MIDI input device... |
// MIDI input device... |
217 |
qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice()); |
qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice()); |
218 |
// MIDI input driver... |
// MIDI input driver... |
219 |
QString sMidiDriver = midiDevice.driverName(); |
QString sMidiDriver = midiDevice.driverName(); |
220 |
if (sMidiDriver.isEmpty() || bNew) |
if (sMidiDriver.isEmpty() || bNew) |
221 |
sMidiDriver = pOptions->sMidiDriver.upper(); |
sMidiDriver = pOptions->sMidiDriver.toUpper(); |
222 |
if (!sMidiDriver.isEmpty()) { |
if (!sMidiDriver.isEmpty()) { |
223 |
if (ui.MidiDriverComboBox->findText(sMidiDriver, |
if (ui.MidiDriverComboBox->findText(sMidiDriver, |
224 |
Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
225 |
ui.MidiDriverComboBox->insertItem(sMidiDriver); |
ui.MidiDriverComboBox->insertItem(0, sMidiDriver); |
226 |
} |
} |
227 |
ui.MidiDriverComboBox->setCurrentText(sMidiDriver); |
ui.MidiDriverComboBox->setItemText( |
228 |
|
ui.MidiDriverComboBox->currentIndex(), |
229 |
|
sMidiDriver); |
230 |
} |
} |
231 |
selectMidiDriverItem(sMidiDriver); |
selectMidiDriverItem(sMidiDriver); |
232 |
if (!bNew) |
if (!bNew) { |
233 |
ui.MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); |
ui.MidiDeviceComboBox->setItemText( |
234 |
selectMidiDeviceItem(ui.MidiDeviceComboBox->currentItem()); |
ui.MidiDeviceComboBox->currentIndex(), |
235 |
|
midiDevice.deviceName()); |
236 |
|
} |
237 |
|
selectMidiDeviceItem(ui.MidiDeviceComboBox->currentIndex()); |
238 |
// MIDI input port... |
// MIDI input port... |
239 |
ui.MidiPortSpinBox->setValue(pChannel->midiPort()); |
ui.MidiPortSpinBox->setValue(pChannel->midiPort()); |
240 |
// MIDI input channel... |
// MIDI input channel... |
242 |
// When new, try to suggest a sensible MIDI channel... |
// When new, try to suggest a sensible MIDI channel... |
243 |
if (iMidiChannel < 0) |
if (iMidiChannel < 0) |
244 |
iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16); |
iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16); |
245 |
ui.MidiChannelComboBox->setCurrentItem(iMidiChannel); |
ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel); |
246 |
// MIDI instrument map... |
// MIDI instrument map... |
247 |
int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap()); |
int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap()); |
248 |
// When new, try to suggest a sensible MIDI map... |
// When new, try to suggest a sensible MIDI map... |
249 |
if (iMidiMap < 0) |
if (iMidiMap < 0) |
250 |
iMidiMap = 0; |
iMidiMap = 0; |
251 |
const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap); |
const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap); |
252 |
if (!sMapName.isEmpty()) |
if (!sMapName.isEmpty()) { |
253 |
ui.MidiMapComboBox->setCurrentText(sMapName); |
ui.MidiMapComboBox->setItemText( |
254 |
|
ui.MidiMapComboBox->currentIndex(), |
255 |
|
sMapName); |
256 |
|
} |
257 |
// It might be no maps around... |
// It might be no maps around... |
258 |
bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0); |
bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0); |
259 |
ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled); |
ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled); |
264 |
// Audio output driver... |
// Audio output driver... |
265 |
QString sAudioDriver = audioDevice.driverName(); |
QString sAudioDriver = audioDevice.driverName(); |
266 |
if (sAudioDriver.isEmpty() || bNew) |
if (sAudioDriver.isEmpty() || bNew) |
267 |
sAudioDriver = pOptions->sAudioDriver.upper(); |
sAudioDriver = pOptions->sAudioDriver.toUpper(); |
268 |
if (!sAudioDriver.isEmpty()) { |
if (!sAudioDriver.isEmpty()) { |
269 |
if (ui.AudioDriverComboBox->findText(sAudioDriver, |
if (ui.AudioDriverComboBox->findText(sAudioDriver, |
270 |
Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
271 |
ui.AudioDriverComboBox->insertItem(sAudioDriver); |
ui.AudioDriverComboBox->insertItem(0, sAudioDriver); |
272 |
} |
} |
273 |
ui.AudioDriverComboBox->setCurrentText(sAudioDriver); |
ui.AudioDriverComboBox->setItemText( |
274 |
|
ui.AudioDriverComboBox->currentIndex(), |
275 |
|
sAudioDriver); |
276 |
} |
} |
277 |
selectAudioDriverItem(sAudioDriver); |
selectAudioDriverItem(sAudioDriver); |
278 |
if (!bNew) |
if (!bNew) { |
279 |
ui.AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); |
ui.AudioDeviceComboBox->setItemText( |
280 |
selectAudioDeviceItem(ui.AudioDeviceComboBox->currentItem()); |
ui.AudioDeviceComboBox->currentIndex(), |
281 |
|
audioDevice.deviceName()); |
282 |
|
} |
283 |
|
selectAudioDeviceItem(ui.AudioDeviceComboBox->currentIndex()); |
284 |
|
|
285 |
// As convenient, make it ready on stabilizeForm() for |
// As convenient, make it ready on stabilizeForm() for |
286 |
// prompt acceptance, if we got the minimum required... |
// prompt acceptance, if we got the minimum required... |
323 |
if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText())) |
if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText())) |
324 |
iErrors++; |
iErrors++; |
325 |
} else { |
} else { |
326 |
qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()); |
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) |
if (pDevice == NULL) |
332 |
iErrors++; |
iErrors++; |
333 |
else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) |
else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) |
334 |
iErrors++; |
iErrors++; |
335 |
else if (!m_audioRouting.isEmpty()) { |
else if (!routingMap.isEmpty()) { |
336 |
// Set the audio route changes... |
// Set the audio route changes... |
337 |
qsamplerChannelRoutingMap::ConstIterator iter; |
qsamplerChannelRoutingMap::ConstIterator iter; |
338 |
for (iter = m_audioRouting.begin(); |
for (iter = routingMap.begin(); |
339 |
iter != m_audioRouting.end(); ++iter) { |
iter != routingMap.end(); ++iter) { |
340 |
if (!m_pChannel->setAudioChannel(iter.key(), iter.data())) |
if (!m_pChannel->setAudioChannel(iter.key(), iter.value())) |
341 |
iErrors++; |
iErrors++; |
342 |
} |
} |
343 |
} |
} |
347 |
if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText())) |
if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText())) |
348 |
iErrors++; |
iErrors++; |
349 |
} else { |
} else { |
350 |
qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()); |
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) |
if (pDevice == NULL) |
355 |
iErrors++; |
iErrors++; |
356 |
else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) |
else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) |
360 |
if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value())) |
if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value())) |
361 |
iErrors++; |
iErrors++; |
362 |
// MIDI input channel... |
// MIDI input channel... |
363 |
if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentItem())) |
if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentIndex())) |
364 |
iErrors++; |
iErrors++; |
365 |
// Engine name... |
// Engine name... |
366 |
if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText())) |
if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText())) |
368 |
// Instrument file and index... |
// Instrument file and index... |
369 |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
370 |
if (!sPath.isEmpty() && QFileInfo(sPath).exists()) { |
if (!sPath.isEmpty() && QFileInfo(sPath).exists()) { |
371 |
if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentItem())) |
if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentIndex())) |
372 |
iErrors++; |
iErrors++; |
373 |
} |
} |
374 |
// MIDI intrument map... |
// MIDI intrument map... |
375 |
if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentItem())) |
if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentIndex())) |
376 |
iErrors++; |
iErrors++; |
377 |
// Show error messages? |
// Show error messages? |
378 |
if (iErrors > 0) |
if (iErrors > 0) |
380 |
} |
} |
381 |
|
|
382 |
// Save default engine name, instrument directory and history... |
// Save default engine name, instrument directory and history... |
383 |
pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); |
pOptions->sInstrumentDir = QFileInfo( |
384 |
|
ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); |
385 |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
386 |
pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText(); |
pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText(); |
387 |
pOptions->sMidiDriver = ui.MidiDriverComboBox->currentText(); |
pOptions->sMidiDriver = ui.MidiDriverComboBox->currentText(); |
388 |
pOptions->iMidiMap = ui.MidiMapComboBox->currentItem(); |
pOptions->iMidiMap = ui.MidiMapComboBox->currentIndex(); |
389 |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
390 |
|
|
391 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
436 |
|
|
437 |
// FIXME: the instrument file filters should be restricted, |
// FIXME: the instrument file filters should be restricted, |
438 |
// depending on the current engine. |
// depending on the current engine. |
439 |
QString sInstrumentFile = QFileDialog::getOpenFileName( |
QString sInstrumentFile = QFileDialog::getOpenFileName(this, |
440 |
pOptions->sInstrumentDir, // Start here. |
QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption. |
441 |
tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) |
pOptions->sInstrumentDir, // Start here. |
442 |
this, 0, // Parent and name (none) |
tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files) |
|
QSAMPLER_TITLE ": " + tr("Instrument files") // Caption. |
|
443 |
); |
); |
444 |
|
|
445 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
446 |
return; |
return; |
447 |
|
|
448 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
449 |
updateInstrumentName(); |
updateInstrumentName(); |
450 |
} |
} |
451 |
|
|
466 |
// Finally this better idea would be to use libgig |
// Finally this better idea would be to use libgig |
467 |
// to retrieve the REAL instrument names. |
// to retrieve the REAL instrument names. |
468 |
ui.InstrumentNrComboBox->clear(); |
ui.InstrumentNrComboBox->clear(); |
469 |
ui.InstrumentNrComboBox->insertStringList( |
ui.InstrumentNrComboBox->insertItems(0, |
470 |
qsamplerChannel::getInstrumentList( |
qsamplerChannel::getInstrumentList( |
471 |
ui.InstrumentFileComboBox->currentText(), |
ui.InstrumentFileComboBox->currentText(), |
472 |
pOptions->bInstrumentNames) |
pOptions->bInstrumentNames) |
481 |
qsamplerDevice::qsamplerDeviceType deviceTypeMode, |
qsamplerDevice::qsamplerDeviceType deviceTypeMode, |
482 |
const QString& sDriverName ) |
const QString& sDriverName ) |
483 |
{ |
{ |
484 |
|
if (pDevice == NULL) |
485 |
|
return; |
486 |
|
|
487 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
488 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
489 |
return; |
return; |
518 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
519 |
return; |
return; |
520 |
|
|
521 |
const QString sDriverName = sMidiDriver.upper(); |
const QString sDriverName = sMidiDriver.toUpper(); |
522 |
|
|
523 |
// Save current device id. |
// Save current device id. |
524 |
|
// Save current device id. |
525 |
int iDeviceID = 0; |
int iDeviceID = 0; |
526 |
qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()); |
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) |
if (pDevice) |
531 |
iDeviceID = pDevice->deviceID(); |
iDeviceID = pDevice->deviceID(); |
532 |
|
|
533 |
// Clean maplist. |
// Clean maplist. |
534 |
ui.MidiDeviceComboBox->clear(); |
ui.MidiDeviceComboBox->clear(); |
535 |
|
qDeleteAll(m_midiDevices); |
536 |
m_midiDevices.clear(); |
m_midiDevices.clear(); |
537 |
|
|
538 |
// Populate with the current ones... |
// Populate with the current ones... |
539 |
const QPixmap midiPixmap(":/qsampler/pixmaps/midi2.png"); |
const QPixmap midiPixmap(":/icons/midi2.png"); |
540 |
int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
541 |
qsamplerDevice::Midi); |
qsamplerDevice::Midi); |
542 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
543 |
pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]); |
pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]); |
544 |
if (pDevice->driverName().upper() == sDriverName) { |
if (pDevice->driverName().toUpper() == sDriverName) { |
545 |
ui.MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); |
ui.MidiDeviceComboBox->insertItem(0, midiPixmap, pDevice->deviceName()); |
546 |
m_midiDevices.append(pDevice); |
m_midiDevices.append(pDevice); |
547 |
} else { |
} else { |
548 |
delete pDevice; |
delete pDevice; |
553 |
bool bEnabled = !m_midiDevices.isEmpty(); |
bool bEnabled = !m_midiDevices.isEmpty(); |
554 |
if (bEnabled) { |
if (bEnabled) { |
555 |
// Select the previous current device... |
// Select the previous current device... |
556 |
int iMidiItem = 0; |
iMidiItem = 0; |
557 |
for (pDevice = m_midiDevices.first(); |
QListIterator<qsamplerDevice *> iter(m_midiDevices); |
558 |
pDevice; |
while (iter.hasNext()) { |
559 |
pDevice = m_midiDevices.next()) { |
pDevice = iter.next(); |
560 |
if (pDevice->deviceID() == iDeviceID) { |
if (pDevice->deviceID() == iDeviceID) { |
561 |
ui.MidiDeviceComboBox->setCurrentItem(iMidiItem); |
ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem); |
562 |
selectMidiDeviceItem(iMidiItem); |
selectMidiDeviceItem(iMidiItem); |
563 |
break; |
break; |
564 |
} |
} |
565 |
iMidiItem++; |
iMidiItem++; |
566 |
} |
} |
567 |
} else { |
} else { |
568 |
ui.MidiDeviceComboBox->insertItem( |
ui.MidiDeviceComboBox->insertItem(0, |
569 |
tr("(New MIDI %1 device)").arg(sMidiDriver)); |
tr("(New MIDI %1 device)").arg(sMidiDriver)); |
570 |
} |
} |
571 |
ui.MidiDeviceTextLabel->setEnabled(bEnabled); |
ui.MidiDeviceTextLabel->setEnabled(bEnabled); |
587 |
// Select MIDI device item. |
// Select MIDI device item. |
588 |
void ChannelForm::selectMidiDeviceItem ( int iMidiItem ) |
void ChannelForm::selectMidiDeviceItem ( int iMidiItem ) |
589 |
{ |
{ |
590 |
qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem); |
qsamplerDevice *pDevice = NULL; |
591 |
|
if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) |
592 |
|
pDevice = m_midiDevices.at(iMidiItem); |
593 |
if (pDevice) { |
if (pDevice) { |
594 |
const qsamplerDeviceParamMap& params = pDevice->params(); |
const qsamplerDeviceParamMap& params = pDevice->params(); |
595 |
int iPorts = params["PORTS"].value.toInt(); |
int iPorts = params["PORTS"].value.toInt(); |
596 |
ui.MidiPortTextLabel->setEnabled(iPorts > 0); |
ui.MidiPortTextLabel->setEnabled(iPorts > 0); |
597 |
ui.MidiPortSpinBox->setEnabled(iPorts > 0); |
ui.MidiPortSpinBox->setEnabled(iPorts > 0); |
598 |
if (iPorts > 0) |
if (iPorts > 0) |
599 |
ui.MidiPortSpinBox->setMaxValue(iPorts - 1); |
ui.MidiPortSpinBox->setMaximum(iPorts - 1); |
600 |
} |
} |
601 |
} |
} |
602 |
|
|
615 |
// MIDI device options. |
// MIDI device options. |
616 |
void ChannelForm::setupMidiDevice (void) |
void ChannelForm::setupMidiDevice (void) |
617 |
{ |
{ |
618 |
setupDevice(m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()), |
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()); |
qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText()); |
624 |
} |
} |
625 |
|
|
633 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
634 |
return; |
return; |
635 |
|
|
636 |
const QString sDriverName = sAudioDriver.upper(); |
const QString sDriverName = sAudioDriver.toUpper(); |
637 |
|
|
638 |
// Save current device id. |
// Save current device id. |
639 |
int iDeviceID = 0; |
int iDeviceID = 0; |
640 |
qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()); |
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) |
if (pDevice) |
645 |
iDeviceID = pDevice->deviceID(); |
iDeviceID = pDevice->deviceID(); |
646 |
|
|
647 |
// Clean maplist. |
// Clean maplist. |
648 |
ui.AudioDeviceComboBox->clear(); |
ui.AudioDeviceComboBox->clear(); |
649 |
|
qDeleteAll(m_audioDevices); |
650 |
m_audioDevices.clear(); |
m_audioDevices.clear(); |
651 |
|
|
652 |
// Populate with the current ones... |
// Populate with the current ones... |
653 |
const QPixmap audioPixmap(":/qsampler/pixmaps/audio2.png"); |
const QPixmap audioPixmap(":/icons/audio2.png"); |
654 |
int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
655 |
qsamplerDevice::Audio); |
qsamplerDevice::Audio); |
656 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
657 |
pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]); |
pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]); |
658 |
if (pDevice->driverName().upper() == sDriverName) { |
if (pDevice->driverName().toUpper() == sDriverName) { |
659 |
ui.AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); |
ui.AudioDeviceComboBox->insertItem(0, audioPixmap, pDevice->deviceName()); |
660 |
m_audioDevices.append(pDevice); |
m_audioDevices.append(pDevice); |
661 |
} else { |
} else { |
662 |
delete pDevice; |
delete pDevice; |
667 |
bool bEnabled = !m_audioDevices.isEmpty(); |
bool bEnabled = !m_audioDevices.isEmpty(); |
668 |
if (bEnabled) { |
if (bEnabled) { |
669 |
// Select the previous current device... |
// Select the previous current device... |
670 |
int iAudioItem = 0; |
iAudioItem = 0; |
671 |
for (pDevice = m_audioDevices.first(); |
QListIterator<qsamplerDevice *> iter(m_audioDevices); |
672 |
pDevice; |
while (iter.hasNext()) { |
673 |
pDevice = m_audioDevices.next()) { |
pDevice = iter.next(); |
674 |
if (pDevice->deviceID() == iDeviceID) { |
if (pDevice->deviceID() == iDeviceID) { |
675 |
ui.AudioDeviceComboBox->setCurrentItem(iAudioItem); |
ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem); |
676 |
selectAudioDeviceItem(iAudioItem); |
selectAudioDeviceItem(iAudioItem); |
677 |
break; |
break; |
678 |
} |
} |
679 |
iAudioItem++; |
iAudioItem++; |
680 |
} |
} |
681 |
} else { |
} else { |
682 |
ui.AudioDeviceComboBox->insertItem( |
ui.AudioDeviceComboBox->insertItem(0, |
683 |
tr("(New Audio %1 device)").arg(sAudioDriver)); |
tr("(New Audio %1 device)").arg(sAudioDriver)); |
684 |
//ui.AudioRoutingTable->setNumRows(0); |
//ui.AudioRoutingTable->setNumRows(0); |
685 |
} |
} |
703 |
// Select Audio device item. |
// Select Audio device item. |
704 |
void ChannelForm::selectAudioDeviceItem ( int iAudioItem ) |
void ChannelForm::selectAudioDeviceItem ( int iAudioItem ) |
705 |
{ |
{ |
706 |
qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem); |
qsamplerDevice *pDevice = NULL; |
707 |
|
if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) |
708 |
|
pDevice = m_audioDevices.at(iAudioItem); |
709 |
if (pDevice) { |
if (pDevice) { |
710 |
// Refresh the audio routing table. |
// Refresh the audio routing table. |
711 |
routingModel.refresh(pDevice, m_pChannel->audioRouting()); |
routingModel.refresh(pDevice, m_pChannel->audioRouting()); |
712 |
// Reset routing change map. |
// Reset routing change map. |
713 |
m_audioRouting.clear(); |
routingModel.clear(); |
714 |
} |
} |
715 |
} |
} |
716 |
|
|
729 |
// Audio device options. |
// Audio device options. |
730 |
void ChannelForm::setupAudioDevice (void) |
void ChannelForm::setupAudioDevice (void) |
731 |
{ |
{ |
732 |
setupDevice(m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()), |
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()); |
qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText()); |
738 |
} |
} |
739 |
|
|
|
|
|
|
// Audio routing change slot. |
|
|
void ChannelForm::changeAudioRouting ( int iRow, int iCol ) |
|
|
{ |
|
|
#if 0 |
|
|
if (m_iDirtySetup > 0) |
|
|
return; |
|
|
if (iRow < 0 || iCol < 0) |
|
|
return; |
|
|
|
|
|
// Verify that this is a QComboTableItem (magic rtti == 1) |
|
|
QTableItem *pItem = ui.AudioRoutingTable->item(iRow, iCol); |
|
|
if (pItem == NULL) |
|
|
return; |
|
|
qsamplerChannelRoutingComboBox *pComboItem = |
|
|
static_cast<qsamplerChannelRoutingComboBox*> (pItem); |
|
|
// FIXME: Its not garanteed that we must have |
|
|
// iAudioOut == iRow on all times forth! |
|
|
m_audioRouting[iRow] = pComboItem->currentItem(); |
|
|
|
|
|
// And let's get dirty... |
|
|
optionsChanged(); |
|
|
#endif |
|
|
} |
|
|
|
|
|
|
|
740 |
// UPdate all device lists slot. |
// UPdate all device lists slot. |
741 |
void ChannelForm::updateDevices (void) |
void ChannelForm::updateDevices (void) |
742 |
{ |
{ |
771 |
ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
772 |
} |
} |
773 |
|
|
774 |
|
void ChannelForm::updateTableCellRenderers() { |
775 |
|
const int rows = routingModel.rowCount(); |
776 |
|
const int cols = routingModel.columnCount(); |
777 |
|
updateTableCellRenderers(routingModel.index(0,0),routingModel.index(rows-1,cols-1)); |
778 |
|
} |
779 |
|
|
780 |
|
void ChannelForm::updateTableCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) { |
781 |
|
for (int r = topLeft.row(); r <= bottomRight.row(); r++) { |
782 |
|
for (int c = topLeft.column(); c <= bottomRight.column(); c++) { |
783 |
|
const QModelIndex index = routingModel.index(r,c); |
784 |
|
ui.AudioRoutingTable->openPersistentEditor(index); |
785 |
|
} |
786 |
|
} |
787 |
|
} |
788 |
|
|
789 |
} // namespace QSampler |
} // namespace QSampler |
790 |
|
|