1 |
// qsamplerDeviceForm.cpp |
// qsamplerDeviceForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, 2008 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
31 |
|
|
32 |
namespace QSampler { |
namespace QSampler { |
33 |
|
|
34 |
|
//------------------------------------------------------------------------- |
35 |
|
// QSampler::DeviceForm -- Device form implementation. |
36 |
|
// |
37 |
|
|
38 |
DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags ) |
DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags ) |
39 |
: QDialog(pParent, wflags) |
: QDialog(pParent, wflags) |
40 |
{ |
{ |
44 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
45 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
46 |
m_bNewDevice = false; |
m_bNewDevice = false; |
47 |
m_deviceType = qsamplerDevice::None; |
m_deviceType = Device::None; |
48 |
m_pAudioItems = NULL; |
m_pAudioItems = NULL; |
49 |
m_pMidiItems = NULL; |
m_pMidiItems = NULL; |
50 |
// No exclusive mode as default. |
// No exclusive mode as default. |
51 |
m_deviceTypeMode = qsamplerDevice::None; |
m_deviceTypeMode = Device::None; |
52 |
|
|
53 |
m_ui.DeviceListView->header()->hide(); |
m_ui.DeviceListView->header()->hide(); |
54 |
|
|
60 |
|
|
61 |
m_ui.DeviceParamTable->setModel(&m_deviceParamModel); |
m_ui.DeviceParamTable->setModel(&m_deviceParamModel); |
62 |
m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate); |
m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate); |
63 |
|
#if QT_VERSION >= 0x050000 |
64 |
|
m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
65 |
|
#else |
66 |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
67 |
|
#endif |
68 |
m_ui.DeviceParamTable->verticalHeader()->hide(); |
m_ui.DeviceParamTable->verticalHeader()->hide(); |
69 |
|
|
70 |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
71 |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
72 |
|
#if QT_VERSION >= 0x050000 |
73 |
|
m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
74 |
|
#else |
75 |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
76 |
|
#endif |
77 |
m_ui.DevicePortParamTable->verticalHeader()->hide(); |
m_ui.DevicePortParamTable->verticalHeader()->hide(); |
78 |
|
|
79 |
// Initial contents. |
// Initial contents. |
119 |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
120 |
} |
} |
121 |
|
|
122 |
DeviceForm::~DeviceForm() { |
|
123 |
|
DeviceForm::~DeviceForm (void) |
124 |
|
{ |
125 |
} |
} |
126 |
|
|
127 |
|
|
132 |
if (pMainForm) |
if (pMainForm) |
133 |
pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
134 |
|
|
|
stabilizeForm(); |
|
|
|
|
135 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
136 |
|
|
137 |
|
refreshDevices(); |
138 |
} |
} |
139 |
|
|
140 |
|
|
157 |
|
|
158 |
// Set device type spacial exclusive mode. |
// Set device type spacial exclusive mode. |
159 |
void DeviceForm::setDeviceTypeMode ( |
void DeviceForm::setDeviceTypeMode ( |
160 |
qsamplerDevice::DeviceType deviceTypeMode ) |
Device::DeviceType deviceTypeMode ) |
161 |
{ |
{ |
162 |
// If it has not changed, do nothing. |
// If it has not changed, do nothing. |
163 |
if (m_deviceTypeMode == deviceTypeMode) |
if (m_deviceTypeMode == deviceTypeMode) |
182 |
|
|
183 |
|
|
184 |
// Set current selected device by type and id. |
// Set current selected device by type and id. |
185 |
void DeviceForm::setDevice ( qsamplerDevice *pDevice ) |
void DeviceForm::setDevice ( Device *pDevice ) |
186 |
{ |
{ |
187 |
// In case no device is given... |
// In case no device is given... |
188 |
qsamplerDevice::DeviceType deviceType = m_deviceTypeMode; |
Device::DeviceType deviceType = m_deviceTypeMode; |
189 |
if (pDevice) |
if (pDevice) |
190 |
deviceType = pDevice->deviceType(); |
deviceType = pDevice->deviceType(); |
191 |
|
|
192 |
// Get the device view root item... |
// Get the device view root item... |
193 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
194 |
switch (deviceType) { |
switch (deviceType) { |
195 |
case qsamplerDevice::Audio: |
case Device::Audio: |
196 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
197 |
break; |
break; |
198 |
case qsamplerDevice::Midi: |
case Device::Midi: |
199 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
200 |
break; |
break; |
201 |
case qsamplerDevice::None: |
case Device::None: |
202 |
break; |
break; |
203 |
} |
} |
204 |
|
|
214 |
|
|
215 |
// For each child, test for identity... |
// For each child, test for identity... |
216 |
for (int i = 0; i < pRootItem->childCount(); i++) { |
for (int i = 0; i < pRootItem->childCount(); i++) { |
217 |
qsamplerDeviceItem* pDeviceItem = |
DeviceItem* pDeviceItem = |
218 |
(qsamplerDeviceItem*) pRootItem->child(i); |
(DeviceItem*) pRootItem->child(i); |
219 |
|
|
220 |
// If identities match, select as current device item. |
// If identities match, select as current device item. |
221 |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
239 |
return; |
return; |
240 |
|
|
241 |
// About a brand new device instance... |
// About a brand new device instance... |
242 |
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
Device device(((DeviceItem *) pItem)->device()); |
243 |
if (device.createDevice()) { |
if (device.createDevice()) { |
244 |
// Now it depends on the device type... |
// Now it depends on the device type... |
245 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
246 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
247 |
case qsamplerDevice::Audio: |
case Device::Audio: |
248 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
249 |
break; |
break; |
250 |
case qsamplerDevice::Midi: |
case Device::Midi: |
251 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
252 |
break; |
break; |
253 |
case qsamplerDevice::None: |
case Device::None: |
254 |
break; |
break; |
255 |
} |
} |
256 |
// Append the new device item. |
// Append the new device item. |
257 |
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
DeviceItem *pDeviceItem = new DeviceItem(pRootItem, |
258 |
device.deviceType(), device.deviceID()); |
device.deviceType(), device.deviceID()); |
259 |
// Just make it the new selection... |
// Just make it the new selection... |
260 |
pDeviceItem->setSelected(true); |
pDeviceItem->setSelected(true); |
276 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
277 |
return; |
return; |
278 |
|
|
279 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
280 |
|
|
281 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
282 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
283 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
284 |
if (QMessageBox::warning(this, |
if (QMessageBox::warning(this, |
285 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
286 |
tr("Delete device:\n\n" |
tr("About to delete device:\n\n" |
287 |
"%1\n\n" |
"%1\n\n" |
288 |
"Are you sure?") |
"Are you sure?") |
289 |
.arg(device.deviceName()), |
.arg(device.deviceName()), |
290 |
tr("OK"), tr("Cancel")) > 0) |
QMessageBox::Ok | QMessageBox::Cancel) |
291 |
|
== QMessageBox::Cancel) |
292 |
return; |
return; |
293 |
} |
} |
294 |
|
|
322 |
if (pMainForm->client()) { |
if (pMainForm->client()) { |
323 |
int *piDeviceIDs; |
int *piDeviceIDs; |
324 |
// Grab and pop Audio devices... |
// Grab and pop Audio devices... |
325 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
326 |
m_deviceTypeMode == qsamplerDevice::Audio) { |
m_deviceTypeMode == Device::Audio) { |
327 |
m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pAudioItems = new DeviceItem(m_ui.DeviceListView, |
328 |
qsamplerDevice::Audio); |
Device::Audio); |
329 |
} |
} |
330 |
if (m_pAudioItems) { |
if (m_pAudioItems) { |
331 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
332 |
qsamplerDevice::Audio); |
Device::Audio); |
333 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
334 |
new qsamplerDeviceItem(m_pAudioItems, |
new DeviceItem(m_pAudioItems, |
335 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
Device::Audio, piDeviceIDs[i]); |
336 |
} |
} |
337 |
m_pAudioItems->setExpanded(true); |
m_pAudioItems->setExpanded(true); |
338 |
} |
} |
339 |
// Grab and pop MIDI devices... |
// Grab and pop MIDI devices... |
340 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
341 |
m_deviceTypeMode == qsamplerDevice::Midi) { |
m_deviceTypeMode == Device::Midi) { |
342 |
m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pMidiItems = new DeviceItem(m_ui.DeviceListView, |
343 |
qsamplerDevice::Midi); |
Device::Midi); |
344 |
} |
} |
345 |
if (m_pMidiItems) { |
if (m_pMidiItems) { |
346 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
347 |
qsamplerDevice::Midi); |
Device::Midi); |
348 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
349 |
new qsamplerDeviceItem(m_pMidiItems, |
new DeviceItem(m_pMidiItems, |
350 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
Device::Midi, piDeviceIDs[i]); |
351 |
} |
} |
352 |
m_pMidiItems->setExpanded(true); |
m_pMidiItems->setExpanded(true); |
353 |
} |
} |
375 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
376 |
return; |
return; |
377 |
|
|
378 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
379 |
|
|
380 |
// Driver change is only valid for scratch devices... |
// Driver change is only valid for scratch devices... |
381 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
405 |
|
|
406 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
407 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
408 |
m_deviceType = qsamplerDevice::None; |
m_deviceType = Device::None; |
409 |
m_ui.DeviceNameTextLabel->setText(QString::null); |
m_ui.DeviceNameTextLabel->setText(QString::null); |
410 |
m_deviceParamModel.clear(); |
m_deviceParamModel.clear(); |
411 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
417 |
return; |
return; |
418 |
} |
} |
419 |
|
|
420 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
421 |
|
|
422 |
m_iDirtySetup++; |
m_iDirtySetup++; |
423 |
// Flag whether this is a new device. |
// Flag whether this is a new device. |
429 |
if (device.deviceType() != m_deviceType) { |
if (device.deviceType() != m_deviceType) { |
430 |
m_ui.DriverNameComboBox->clear(); |
m_ui.DriverNameComboBox->clear(); |
431 |
m_ui.DriverNameComboBox->insertItems(0, |
m_ui.DriverNameComboBox->insertItems(0, |
432 |
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
Device::getDrivers(pMainForm->client(), device.deviceType())); |
433 |
m_deviceType = device.deviceType(); |
m_deviceType = device.deviceType(); |
434 |
} |
} |
435 |
// Do we need a driver name? |
// Do we need a driver name? |
442 |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
443 |
// And now the device port/channel parameter table... |
// And now the device port/channel parameter table... |
444 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
445 |
case qsamplerDevice::Audio: |
case Device::Audio: |
446 |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
447 |
break; |
break; |
448 |
case qsamplerDevice::Midi: |
case Device::Midi: |
449 |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
450 |
break; |
break; |
451 |
case qsamplerDevice::None: |
case Device::None: |
452 |
break; |
break; |
453 |
} |
} |
454 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
460 |
} else { |
} else { |
461 |
QPixmap pixmap; |
QPixmap pixmap; |
462 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
463 |
case qsamplerDevice::Audio: |
case Device::Audio: |
464 |
pixmap = QPixmap(":/icons/audio2.png"); |
pixmap = QPixmap(":/images/audio2.png"); |
465 |
break; |
break; |
466 |
case qsamplerDevice::Midi: |
case Device::Midi: |
467 |
pixmap = QPixmap(":/icons/midi2.png"); |
pixmap = QPixmap(":/images/midi2.png"); |
468 |
break; |
break; |
469 |
case qsamplerDevice::None: |
case Device::None: |
470 |
break; |
break; |
471 |
} |
} |
472 |
qsamplerDevicePortList& ports = device.ports(); |
DevicePortList& ports = device.ports(); |
473 |
QListIterator<qsamplerDevicePort *> iter(ports); |
QListIterator<DevicePort *> iter(ports); |
474 |
while (iter.hasNext()) { |
while (iter.hasNext()) { |
475 |
qsamplerDevicePort *pPort = iter.next(); |
DevicePort *pPort = iter.next(); |
476 |
m_ui.DevicePortComboBox->addItem(pixmap, |
m_ui.DevicePortComboBox->addItem(pixmap, |
477 |
device.deviceTypeName() |
device.deviceTypeName() |
478 |
+ ' ' + device.driverName() |
+ ' ' + device.driverName() |
505 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
506 |
return; |
return; |
507 |
|
|
508 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
509 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
510 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
511 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
512 |
if (pPort) { |
if (pPort) { |
536 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
537 |
return; |
return; |
538 |
|
|
539 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
540 |
|
|
541 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
542 |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
575 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
576 |
return; |
return; |
577 |
|
|
578 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
579 |
|
|
580 |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
581 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
582 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
583 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
584 |
if (pPort == NULL) |
if (pPort == NULL) |
622 |
bool bClient = (pMainForm->client() != NULL); |
bool bClient = (pMainForm->client() != NULL); |
623 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
624 |
pAction = menu.addAction( |
pAction = menu.addAction( |
625 |
QIcon(":/qsampler/pixmaps/deviceCreate.png"), |
QIcon(":/images/deviceCreate.png"), |
626 |
tr("&Create device"), this, SLOT(createDevice())); |
tr("&Create device"), this, SLOT(createDevice())); |
627 |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
628 |
pAction = menu.addAction( |
pAction = menu.addAction( |
629 |
QIcon(":/qsampler/pixmaps/deviceDelete.png"), |
QIcon(":/images/deviceDelete.png"), |
630 |
tr("&Delete device"), this, SLOT(deleteDevice())); |
tr("&Delete device"), this, SLOT(deleteDevice())); |
631 |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
632 |
menu.addSeparator(); |
menu.addSeparator(); |
633 |
pAction = menu.addAction( |
pAction = menu.addAction( |
634 |
QIcon(":/qsampler/pixmaps/formRefresh.png"), |
QIcon(":/images/formRefresh.png"), |
635 |
tr("&Refresh"), this, SLOT(refreshDevices())); |
tr("&Refresh"), this, SLOT(refreshDevices())); |
636 |
pAction->setEnabled(bClient); |
pAction->setEnabled(bClient); |
637 |
|
|