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 |
{ |
{ |
41 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
42 |
|
|
43 |
// Initialize locals. |
// Initialize locals. |
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 |
|
|
55 |
|
int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4; |
56 |
|
m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight); |
57 |
|
m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight); |
58 |
|
m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); |
59 |
|
m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); |
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()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
65 |
|
#endif |
66 |
m_ui.DeviceParamTable->verticalHeader()->hide(); |
m_ui.DeviceParamTable->verticalHeader()->hide(); |
67 |
|
|
68 |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
69 |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
70 |
|
#if QT_VERSION < 0x050000 |
71 |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
72 |
|
#endif |
73 |
m_ui.DevicePortParamTable->verticalHeader()->hide(); |
m_ui.DevicePortParamTable->verticalHeader()->hide(); |
74 |
|
|
75 |
// Initial contents. |
// Initial contents. |
115 |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
116 |
} |
} |
117 |
|
|
118 |
DeviceForm::~DeviceForm() { |
|
119 |
|
DeviceForm::~DeviceForm (void) |
120 |
|
{ |
121 |
} |
} |
122 |
|
|
123 |
|
|
128 |
if (pMainForm) |
if (pMainForm) |
129 |
pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
130 |
|
|
|
stabilizeForm(); |
|
|
|
|
131 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
132 |
|
|
133 |
|
refreshDevices(); |
134 |
} |
} |
135 |
|
|
136 |
|
|
153 |
|
|
154 |
// Set device type spacial exclusive mode. |
// Set device type spacial exclusive mode. |
155 |
void DeviceForm::setDeviceTypeMode ( |
void DeviceForm::setDeviceTypeMode ( |
156 |
qsamplerDevice::DeviceType deviceTypeMode ) |
Device::DeviceType deviceTypeMode ) |
157 |
{ |
{ |
158 |
// If it has not changed, do nothing. |
// If it has not changed, do nothing. |
159 |
if (m_deviceTypeMode == deviceTypeMode) |
if (m_deviceTypeMode == deviceTypeMode) |
178 |
|
|
179 |
|
|
180 |
// Set current selected device by type and id. |
// Set current selected device by type and id. |
181 |
void DeviceForm::setDevice ( qsamplerDevice *pDevice ) |
void DeviceForm::setDevice ( Device *pDevice ) |
182 |
{ |
{ |
183 |
// In case no device is given... |
// In case no device is given... |
184 |
qsamplerDevice::DeviceType deviceType = m_deviceTypeMode; |
Device::DeviceType deviceType = m_deviceTypeMode; |
185 |
if (pDevice) |
if (pDevice) |
186 |
deviceType = pDevice->deviceType(); |
deviceType = pDevice->deviceType(); |
187 |
|
|
188 |
// Get the device view root item... |
// Get the device view root item... |
189 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
190 |
switch (deviceType) { |
switch (deviceType) { |
191 |
case qsamplerDevice::Audio: |
case Device::Audio: |
192 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
193 |
break; |
break; |
194 |
case qsamplerDevice::Midi: |
case Device::Midi: |
195 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
196 |
break; |
break; |
197 |
case qsamplerDevice::None: |
case Device::None: |
198 |
break; |
break; |
199 |
} |
} |
200 |
|
|
210 |
|
|
211 |
// For each child, test for identity... |
// For each child, test for identity... |
212 |
for (int i = 0; i < pRootItem->childCount(); i++) { |
for (int i = 0; i < pRootItem->childCount(); i++) { |
213 |
qsamplerDeviceItem* pDeviceItem = |
DeviceItem* pDeviceItem = |
214 |
(qsamplerDeviceItem*) pRootItem->child(i); |
(DeviceItem*) pRootItem->child(i); |
215 |
|
|
216 |
// If identities match, select as current device item. |
// If identities match, select as current device item. |
217 |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
235 |
return; |
return; |
236 |
|
|
237 |
// About a brand new device instance... |
// About a brand new device instance... |
238 |
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
Device device(((DeviceItem *) pItem)->device()); |
239 |
if (device.createDevice()) { |
if (device.createDevice()) { |
240 |
// Now it depends on the device type... |
// Now it depends on the device type... |
241 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
242 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
243 |
case qsamplerDevice::Audio: |
case Device::Audio: |
244 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
245 |
break; |
break; |
246 |
case qsamplerDevice::Midi: |
case Device::Midi: |
247 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
248 |
break; |
break; |
249 |
case qsamplerDevice::None: |
case Device::None: |
250 |
break; |
break; |
251 |
} |
} |
252 |
// Append the new device item. |
// Append the new device item. |
253 |
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
DeviceItem *pDeviceItem = new DeviceItem(pRootItem, |
254 |
device.deviceType(), device.deviceID()); |
device.deviceType(), device.deviceID()); |
255 |
// Just make it the new selection... |
// Just make it the new selection... |
256 |
pDeviceItem->setSelected(true); |
pDeviceItem->setSelected(true); |
272 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
273 |
return; |
return; |
274 |
|
|
275 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
276 |
|
|
277 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
278 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
279 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
280 |
if (QMessageBox::warning(this, |
if (QMessageBox::warning(this, |
281 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
282 |
tr("Delete device:\n\n" |
tr("About to delete device:\n\n" |
283 |
"%1\n\n" |
"%1\n\n" |
284 |
"Are you sure?") |
"Are you sure?") |
285 |
.arg(device.deviceName()), |
.arg(device.deviceName()), |
286 |
tr("OK"), tr("Cancel")) > 0) |
QMessageBox::Ok | QMessageBox::Cancel) |
287 |
|
== QMessageBox::Cancel) |
288 |
return; |
return; |
289 |
} |
} |
290 |
|
|
318 |
if (pMainForm->client()) { |
if (pMainForm->client()) { |
319 |
int *piDeviceIDs; |
int *piDeviceIDs; |
320 |
// Grab and pop Audio devices... |
// Grab and pop Audio devices... |
321 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
322 |
m_deviceTypeMode == qsamplerDevice::Audio) { |
m_deviceTypeMode == Device::Audio) { |
323 |
m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pAudioItems = new DeviceItem(m_ui.DeviceListView, |
324 |
qsamplerDevice::Audio); |
Device::Audio); |
325 |
} |
} |
326 |
if (m_pAudioItems) { |
if (m_pAudioItems) { |
327 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
328 |
qsamplerDevice::Audio); |
Device::Audio); |
329 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
330 |
new qsamplerDeviceItem(m_pAudioItems, |
new DeviceItem(m_pAudioItems, |
331 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
Device::Audio, piDeviceIDs[i]); |
332 |
} |
} |
333 |
m_pAudioItems->setExpanded(true); |
m_pAudioItems->setExpanded(true); |
334 |
} |
} |
335 |
// Grab and pop MIDI devices... |
// Grab and pop MIDI devices... |
336 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
337 |
m_deviceTypeMode == qsamplerDevice::Midi) { |
m_deviceTypeMode == Device::Midi) { |
338 |
m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pMidiItems = new DeviceItem(m_ui.DeviceListView, |
339 |
qsamplerDevice::Midi); |
Device::Midi); |
340 |
} |
} |
341 |
if (m_pMidiItems) { |
if (m_pMidiItems) { |
342 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
343 |
qsamplerDevice::Midi); |
Device::Midi); |
344 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
345 |
new qsamplerDeviceItem(m_pMidiItems, |
new DeviceItem(m_pMidiItems, |
346 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
Device::Midi, piDeviceIDs[i]); |
347 |
} |
} |
348 |
m_pMidiItems->setExpanded(true); |
m_pMidiItems->setExpanded(true); |
349 |
} |
} |
371 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
372 |
return; |
return; |
373 |
|
|
374 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
375 |
|
|
376 |
// Driver change is only valid for scratch devices... |
// Driver change is only valid for scratch devices... |
377 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
401 |
|
|
402 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
403 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
404 |
m_deviceType = qsamplerDevice::None; |
m_deviceType = Device::None; |
405 |
m_ui.DeviceNameTextLabel->setText(QString::null); |
m_ui.DeviceNameTextLabel->setText(QString::null); |
406 |
m_deviceParamModel.clear(); |
m_deviceParamModel.clear(); |
407 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
413 |
return; |
return; |
414 |
} |
} |
415 |
|
|
416 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
417 |
|
|
418 |
m_iDirtySetup++; |
m_iDirtySetup++; |
419 |
// Flag whether this is a new device. |
// Flag whether this is a new device. |
425 |
if (device.deviceType() != m_deviceType) { |
if (device.deviceType() != m_deviceType) { |
426 |
m_ui.DriverNameComboBox->clear(); |
m_ui.DriverNameComboBox->clear(); |
427 |
m_ui.DriverNameComboBox->insertItems(0, |
m_ui.DriverNameComboBox->insertItems(0, |
428 |
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
Device::getDrivers(pMainForm->client(), device.deviceType())); |
429 |
m_deviceType = device.deviceType(); |
m_deviceType = device.deviceType(); |
430 |
} |
} |
431 |
// Do we need a driver name? |
// Do we need a driver name? |
438 |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
439 |
// And now the device port/channel parameter table... |
// And now the device port/channel parameter table... |
440 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
441 |
case qsamplerDevice::Audio: |
case Device::Audio: |
442 |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
443 |
break; |
break; |
444 |
case qsamplerDevice::Midi: |
case Device::Midi: |
445 |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
446 |
break; |
break; |
447 |
case qsamplerDevice::None: |
case Device::None: |
448 |
break; |
break; |
449 |
} |
} |
450 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
456 |
} else { |
} else { |
457 |
QPixmap pixmap; |
QPixmap pixmap; |
458 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
459 |
case qsamplerDevice::Audio: |
case Device::Audio: |
460 |
pixmap = QPixmap(":/icons/audio2.png"); |
pixmap = QPixmap(":/images/audio2.png"); |
461 |
break; |
break; |
462 |
case qsamplerDevice::Midi: |
case Device::Midi: |
463 |
pixmap = QPixmap(":/icons/midi2.png"); |
pixmap = QPixmap(":/images/midi2.png"); |
464 |
break; |
break; |
465 |
case qsamplerDevice::None: |
case Device::None: |
466 |
break; |
break; |
467 |
} |
} |
468 |
qsamplerDevicePortList& ports = device.ports(); |
DevicePortList& ports = device.ports(); |
469 |
QListIterator<qsamplerDevicePort *> iter(ports); |
QListIterator<DevicePort *> iter(ports); |
470 |
while (iter.hasNext()) { |
while (iter.hasNext()) { |
471 |
qsamplerDevicePort *pPort = iter.next(); |
DevicePort *pPort = iter.next(); |
472 |
m_ui.DevicePortComboBox->addItem(pixmap, |
m_ui.DevicePortComboBox->addItem(pixmap, |
473 |
device.deviceTypeName() |
device.deviceTypeName() |
474 |
+ ' ' + device.driverName() |
+ ' ' + device.driverName() |
501 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
502 |
return; |
return; |
503 |
|
|
504 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
505 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
506 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
507 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
508 |
if (pPort) { |
if (pPort) { |
532 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
533 |
return; |
return; |
534 |
|
|
535 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
536 |
|
|
537 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
538 |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
571 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
572 |
return; |
return; |
573 |
|
|
574 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
575 |
|
|
576 |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
577 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
578 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
579 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
580 |
if (pPort == NULL) |
if (pPort == NULL) |
618 |
bool bClient = (pMainForm->client() != NULL); |
bool bClient = (pMainForm->client() != NULL); |
619 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
620 |
pAction = menu.addAction( |
pAction = menu.addAction( |
621 |
QIcon(":/qsampler/pixmaps/deviceCreate.png"), |
QIcon(":/images/deviceCreate.png"), |
622 |
tr("&Create device"), this, SLOT(createDevice())); |
tr("&Create device"), this, SLOT(createDevice())); |
623 |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
624 |
pAction = menu.addAction( |
pAction = menu.addAction( |
625 |
QIcon(":/qsampler/pixmaps/deviceDelete.png"), |
QIcon(":/images/deviceDelete.png"), |
626 |
tr("&Delete device"), this, SLOT(deleteDevice())); |
tr("&Delete device"), this, SLOT(deleteDevice())); |
627 |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
628 |
menu.addSeparator(); |
menu.addSeparator(); |
629 |
pAction = menu.addAction( |
pAction = menu.addAction( |
630 |
QIcon(":/qsampler/pixmaps/formRefresh.png"), |
QIcon(":/images/formRefresh.png"), |
631 |
tr("&Refresh"), this, SLOT(refreshDevices())); |
tr("&Refresh"), this, SLOT(refreshDevices())); |
632 |
pAction->setEnabled(bClient); |
pAction->setEnabled(bClient); |
633 |
|
|