2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, 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 |
|
|
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 |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
111 |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
112 |
} |
} |
113 |
|
|
114 |
DeviceForm::~DeviceForm() { |
|
115 |
|
DeviceForm::~DeviceForm (void) |
116 |
|
{ |
117 |
} |
} |
118 |
|
|
119 |
|
|
124 |
if (pMainForm) |
if (pMainForm) |
125 |
pMainForm->stabilizeForm(); |
pMainForm->stabilizeForm(); |
126 |
|
|
|
stabilizeForm(); |
|
|
|
|
127 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
128 |
|
|
129 |
|
refreshDevices(); |
130 |
} |
} |
131 |
|
|
132 |
|
|
149 |
|
|
150 |
// Set device type spacial exclusive mode. |
// Set device type spacial exclusive mode. |
151 |
void DeviceForm::setDeviceTypeMode ( |
void DeviceForm::setDeviceTypeMode ( |
152 |
qsamplerDevice::DeviceType deviceTypeMode ) |
Device::DeviceType deviceTypeMode ) |
153 |
{ |
{ |
154 |
// If it has not changed, do nothing. |
// If it has not changed, do nothing. |
155 |
if (m_deviceTypeMode == deviceTypeMode) |
if (m_deviceTypeMode == deviceTypeMode) |
174 |
|
|
175 |
|
|
176 |
// Set current selected device by type and id. |
// Set current selected device by type and id. |
177 |
void DeviceForm::setDevice ( qsamplerDevice *pDevice ) |
void DeviceForm::setDevice ( Device *pDevice ) |
178 |
{ |
{ |
179 |
// In case no device is given... |
// In case no device is given... |
180 |
qsamplerDevice::DeviceType deviceType = m_deviceTypeMode; |
Device::DeviceType deviceType = m_deviceTypeMode; |
181 |
if (pDevice) |
if (pDevice) |
182 |
deviceType = pDevice->deviceType(); |
deviceType = pDevice->deviceType(); |
183 |
|
|
184 |
// Get the device view root item... |
// Get the device view root item... |
185 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
186 |
switch (deviceType) { |
switch (deviceType) { |
187 |
case qsamplerDevice::Audio: |
case Device::Audio: |
188 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
189 |
break; |
break; |
190 |
case qsamplerDevice::Midi: |
case Device::Midi: |
191 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
192 |
break; |
break; |
193 |
case qsamplerDevice::None: |
case Device::None: |
194 |
break; |
break; |
195 |
} |
} |
196 |
|
|
206 |
|
|
207 |
// For each child, test for identity... |
// For each child, test for identity... |
208 |
for (int i = 0; i < pRootItem->childCount(); i++) { |
for (int i = 0; i < pRootItem->childCount(); i++) { |
209 |
qsamplerDeviceItem* pDeviceItem = |
DeviceItem* pDeviceItem = |
210 |
(qsamplerDeviceItem*) pRootItem->child(i); |
(DeviceItem*) pRootItem->child(i); |
211 |
|
|
212 |
// If identities match, select as current device item. |
// If identities match, select as current device item. |
213 |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
231 |
return; |
return; |
232 |
|
|
233 |
// About a brand new device instance... |
// About a brand new device instance... |
234 |
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
Device device(((DeviceItem *) pItem)->device()); |
235 |
if (device.createDevice()) { |
if (device.createDevice()) { |
236 |
// Now it depends on the device type... |
// Now it depends on the device type... |
237 |
qsamplerDeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = NULL; |
238 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
239 |
case qsamplerDevice::Audio: |
case Device::Audio: |
240 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
241 |
break; |
break; |
242 |
case qsamplerDevice::Midi: |
case Device::Midi: |
243 |
pRootItem = m_pMidiItems; |
pRootItem = m_pMidiItems; |
244 |
break; |
break; |
245 |
case qsamplerDevice::None: |
case Device::None: |
246 |
break; |
break; |
247 |
} |
} |
248 |
// Append the new device item. |
// Append the new device item. |
249 |
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
DeviceItem *pDeviceItem = new DeviceItem(pRootItem, |
250 |
device.deviceType(), device.deviceID()); |
device.deviceType(), device.deviceID()); |
251 |
// Just make it the new selection... |
// Just make it the new selection... |
252 |
pDeviceItem->setSelected(true); |
pDeviceItem->setSelected(true); |
268 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
269 |
return; |
return; |
270 |
|
|
271 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
272 |
|
|
273 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
274 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
275 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
276 |
if (QMessageBox::warning(this, |
if (QMessageBox::warning(this, |
277 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
278 |
tr("Delete device:\n\n" |
tr("About to delete device:\n\n" |
279 |
"%1\n\n" |
"%1\n\n" |
280 |
"Are you sure?") |
"Are you sure?") |
281 |
.arg(device.deviceName()), |
.arg(device.deviceName()), |
313 |
if (pMainForm->client()) { |
if (pMainForm->client()) { |
314 |
int *piDeviceIDs; |
int *piDeviceIDs; |
315 |
// Grab and pop Audio devices... |
// Grab and pop Audio devices... |
316 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
317 |
m_deviceTypeMode == qsamplerDevice::Audio) { |
m_deviceTypeMode == Device::Audio) { |
318 |
m_pAudioItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pAudioItems = new DeviceItem(m_ui.DeviceListView, |
319 |
qsamplerDevice::Audio); |
Device::Audio); |
320 |
} |
} |
321 |
if (m_pAudioItems) { |
if (m_pAudioItems) { |
322 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
323 |
qsamplerDevice::Audio); |
Device::Audio); |
324 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
325 |
new qsamplerDeviceItem(m_pAudioItems, |
new DeviceItem(m_pAudioItems, |
326 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
Device::Audio, piDeviceIDs[i]); |
327 |
} |
} |
328 |
m_pAudioItems->setExpanded(true); |
m_pAudioItems->setExpanded(true); |
329 |
} |
} |
330 |
// Grab and pop MIDI devices... |
// Grab and pop MIDI devices... |
331 |
if (m_deviceTypeMode == qsamplerDevice::None || |
if (m_deviceTypeMode == Device::None || |
332 |
m_deviceTypeMode == qsamplerDevice::Midi) { |
m_deviceTypeMode == Device::Midi) { |
333 |
m_pMidiItems = new qsamplerDeviceItem(m_ui.DeviceListView, |
m_pMidiItems = new DeviceItem(m_ui.DeviceListView, |
334 |
qsamplerDevice::Midi); |
Device::Midi); |
335 |
} |
} |
336 |
if (m_pMidiItems) { |
if (m_pMidiItems) { |
337 |
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
piDeviceIDs = Device::getDevices(pMainForm->client(), |
338 |
qsamplerDevice::Midi); |
Device::Midi); |
339 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
340 |
new qsamplerDeviceItem(m_pMidiItems, |
new DeviceItem(m_pMidiItems, |
341 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
Device::Midi, piDeviceIDs[i]); |
342 |
} |
} |
343 |
m_pMidiItems->setExpanded(true); |
m_pMidiItems->setExpanded(true); |
344 |
} |
} |
366 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
367 |
return; |
return; |
368 |
|
|
369 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
370 |
|
|
371 |
// Driver change is only valid for scratch devices... |
// Driver change is only valid for scratch devices... |
372 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
396 |
|
|
397 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
398 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
399 |
m_deviceType = qsamplerDevice::None; |
m_deviceType = Device::None; |
400 |
m_ui.DeviceNameTextLabel->setText(QString::null); |
m_ui.DeviceNameTextLabel->setText(QString::null); |
401 |
m_deviceParamModel.clear(); |
m_deviceParamModel.clear(); |
402 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
408 |
return; |
return; |
409 |
} |
} |
410 |
|
|
411 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
412 |
|
|
413 |
m_iDirtySetup++; |
m_iDirtySetup++; |
414 |
// Flag whether this is a new device. |
// Flag whether this is a new device. |
420 |
if (device.deviceType() != m_deviceType) { |
if (device.deviceType() != m_deviceType) { |
421 |
m_ui.DriverNameComboBox->clear(); |
m_ui.DriverNameComboBox->clear(); |
422 |
m_ui.DriverNameComboBox->insertItems(0, |
m_ui.DriverNameComboBox->insertItems(0, |
423 |
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
Device::getDrivers(pMainForm->client(), device.deviceType())); |
424 |
m_deviceType = device.deviceType(); |
m_deviceType = device.deviceType(); |
425 |
} |
} |
426 |
// Do we need a driver name? |
// Do we need a driver name? |
433 |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
m_deviceParamModel.refresh(&device, m_bNewDevice); |
434 |
// And now the device port/channel parameter table... |
// And now the device port/channel parameter table... |
435 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
436 |
case qsamplerDevice::Audio: |
case Device::Audio: |
437 |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
m_ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
438 |
break; |
break; |
439 |
case qsamplerDevice::Midi: |
case Device::Midi: |
440 |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
m_ui.DevicePortTextLabel->setText(tr("P&ort:")); |
441 |
break; |
break; |
442 |
case qsamplerDevice::None: |
case Device::None: |
443 |
break; |
break; |
444 |
} |
} |
445 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
451 |
} else { |
} else { |
452 |
QPixmap pixmap; |
QPixmap pixmap; |
453 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
454 |
case qsamplerDevice::Audio: |
case Device::Audio: |
455 |
pixmap = QPixmap(":/icons/audio2.png"); |
pixmap = QPixmap(":/icons/audio2.png"); |
456 |
break; |
break; |
457 |
case qsamplerDevice::Midi: |
case Device::Midi: |
458 |
pixmap = QPixmap(":/icons/midi2.png"); |
pixmap = QPixmap(":/icons/midi2.png"); |
459 |
break; |
break; |
460 |
case qsamplerDevice::None: |
case Device::None: |
461 |
break; |
break; |
462 |
} |
} |
463 |
qsamplerDevicePortList& ports = device.ports(); |
DevicePortList& ports = device.ports(); |
464 |
QListIterator<qsamplerDevicePort *> iter(ports); |
QListIterator<DevicePort *> iter(ports); |
465 |
while (iter.hasNext()) { |
while (iter.hasNext()) { |
466 |
qsamplerDevicePort *pPort = iter.next(); |
DevicePort *pPort = iter.next(); |
467 |
m_ui.DevicePortComboBox->addItem(pixmap, |
m_ui.DevicePortComboBox->addItem(pixmap, |
468 |
device.deviceTypeName() |
device.deviceTypeName() |
469 |
+ ' ' + device.driverName() |
+ ' ' + device.driverName() |
496 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
497 |
return; |
return; |
498 |
|
|
499 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
500 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
501 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
502 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
503 |
if (pPort) { |
if (pPort) { |
527 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
528 |
return; |
return; |
529 |
|
|
530 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
531 |
|
|
532 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
533 |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
//const QString sParam = m_ui.DeviceParamTable->text(iRow, 0); |
566 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
567 |
return; |
return; |
568 |
|
|
569 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
570 |
|
|
571 |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
572 |
qsamplerDevicePort *pPort = NULL; |
DevicePort *pPort = NULL; |
573 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
574 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
575 |
if (pPort == NULL) |
if (pPort == NULL) |
613 |
bool bClient = (pMainForm->client() != NULL); |
bool bClient = (pMainForm->client() != NULL); |
614 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
615 |
pAction = menu.addAction( |
pAction = menu.addAction( |
616 |
QIcon(":/qsampler/pixmaps/deviceCreate.png"), |
QIcon(":/icons/deviceCreate.png"), |
617 |
tr("&Create device"), this, SLOT(createDevice())); |
tr("&Create device"), this, SLOT(createDevice())); |
618 |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
619 |
pAction = menu.addAction( |
pAction = menu.addAction( |
620 |
QIcon(":/qsampler/pixmaps/deviceDelete.png"), |
QIcon(":/icons/deviceDelete.png"), |
621 |
tr("&Delete device"), this, SLOT(deleteDevice())); |
tr("&Delete device"), this, SLOT(deleteDevice())); |
622 |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
623 |
menu.addSeparator(); |
menu.addSeparator(); |
624 |
pAction = menu.addAction( |
pAction = menu.addAction( |
625 |
QIcon(":/qsampler/pixmaps/formRefresh.png"), |
QIcon(":/icons/formRefresh.png"), |
626 |
tr("&Refresh"), this, SLOT(refreshDevices())); |
tr("&Refresh"), this, SLOT(refreshDevices())); |
627 |
pAction->setEnabled(bClient); |
pAction->setEnabled(bClient); |
628 |
|
|