23 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
24 |
|
|
25 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
26 |
|
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
|
#include <QHeaderView> |
29 |
|
#include <QMessageBox> |
30 |
|
|
31 |
|
|
32 |
namespace QSampler { |
namespace QSampler { |
33 |
|
|
44 |
// No exclusive mode as default. |
// No exclusive mode as default. |
45 |
m_deviceTypeMode = qsamplerDevice::None; |
m_deviceTypeMode = qsamplerDevice::None; |
46 |
|
|
47 |
|
ui.DeviceListView->header()->hide(); |
48 |
|
|
49 |
ui.DeviceParamTable->setModel(&deviceParamModel); |
ui.DeviceParamTable->setModel(&deviceParamModel); |
50 |
ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate); |
ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate); |
51 |
|
ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
52 |
|
|
53 |
ui.DevicePortParamTable->setModel(&devicePortParamModel); |
ui.DevicePortParamTable->setModel(&devicePortParamModel); |
54 |
ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate); |
ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate); |
55 |
|
ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
|
// This an outsider (from designer), but rather important. |
|
|
//QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), |
|
|
// this, SLOT(changeDeviceParam(int,int))); |
|
|
//QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)), |
|
|
// this, SLOT(changeDevicePortParam(int,int))); |
|
56 |
|
|
57 |
// Initial contents. |
// Initial contents. |
58 |
refreshDevices(); |
refreshDevices(); |
60 |
adjustSize(); |
adjustSize(); |
61 |
|
|
62 |
QObject::connect(ui.DeviceListView, |
QObject::connect(ui.DeviceListView, |
63 |
SIGNAL(itemSelectionChanged()), |
SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), |
64 |
SLOT(selectDevice())); |
SLOT(selectDevice())); |
65 |
QObject::connect(ui.DeviceListView, |
QObject::connect(ui.DeviceListView, |
66 |
SIGNAL(customContextMenuRequested(const QPoint&)), |
SIGNAL(customContextMenuRequested(const QPoint&)), |
83 |
QObject::connect(ui.ClosePushButton, |
QObject::connect(ui.ClosePushButton, |
84 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
85 |
SLOT(close())); |
SLOT(close())); |
86 |
|
QObject::connect(&deviceParamModel, |
87 |
|
SIGNAL(modelReset()), |
88 |
|
SLOT(updateCellRenderers())); |
89 |
|
QObject::connect(&deviceParamModel, |
90 |
|
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
91 |
|
SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&))); |
92 |
|
QObject::connect(&devicePortParamModel, |
93 |
|
SIGNAL(modelReset()), |
94 |
|
SLOT(updatePortCellRenderers())); |
95 |
|
QObject::connect(&devicePortParamModel, |
96 |
|
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
97 |
|
SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&))); |
98 |
} |
} |
99 |
|
|
100 |
DeviceForm::~DeviceForm() { |
DeviceForm::~DeviceForm() { |
149 |
// Device driver name setup formal initializer. |
// Device driver name setup formal initializer. |
150 |
void DeviceForm::setDriverName ( const QString& sDriverName ) |
void DeviceForm::setDriverName ( const QString& sDriverName ) |
151 |
{ |
{ |
152 |
if (ui.DriverNameComboBox->findText(sDriverName) == 0) { |
if (ui.DriverNameComboBox->findText(sDriverName) < 0) |
153 |
ui.DriverNameComboBox->insertItem(sDriverName); |
ui.DriverNameComboBox->insertItem(0, sDriverName); |
154 |
} |
ui.DriverNameComboBox->setItemText( |
155 |
ui.DriverNameComboBox->setCurrentText(sDriverName); |
ui.DriverNameComboBox->currentIndex(), |
156 |
|
sDriverName); |
157 |
} |
} |
158 |
|
|
159 |
|
|
356 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
357 |
m_iDirtySetup++; |
m_iDirtySetup++; |
358 |
device.setDriver(sDriverName); |
device.setDriver(sDriverName); |
359 |
deviceParamModel.refresh(device.params(), m_bNewDevice); |
deviceParamModel.refresh(&device, m_bNewDevice); |
360 |
m_iDirtySetup--; |
m_iDirtySetup--; |
361 |
// Done. |
// Done. |
362 |
stabilizeForm(); |
stabilizeForm(); |
365 |
|
|
366 |
|
|
367 |
// Device selection slot. |
// Device selection slot. |
368 |
void DeviceForm::selectDevice (void) |
void DeviceForm::selectDevice () |
369 |
{ |
{ |
370 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
371 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
403 |
// The driver combobox is only rebuilt if device type has changed... |
// The driver combobox is only rebuilt if device type has changed... |
404 |
if (device.deviceType() != m_deviceType) { |
if (device.deviceType() != m_deviceType) { |
405 |
ui.DriverNameComboBox->clear(); |
ui.DriverNameComboBox->clear(); |
406 |
ui.DriverNameComboBox->insertStringList( |
ui.DriverNameComboBox->insertItems(0, |
407 |
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
408 |
m_deviceType = device.deviceType(); |
m_deviceType = device.deviceType(); |
409 |
} |
} |
414 |
ui.DriverNameTextLabel->setEnabled(m_bNewDevice); |
ui.DriverNameTextLabel->setEnabled(m_bNewDevice); |
415 |
ui.DriverNameComboBox->setEnabled(m_bNewDevice); |
ui.DriverNameComboBox->setEnabled(m_bNewDevice); |
416 |
// Fill the device parameter table... |
// Fill the device parameter table... |
417 |
deviceParamModel.refresh(device.params(), m_bNewDevice); |
deviceParamModel.refresh(&device, m_bNewDevice); |
418 |
// And now the device port/channel parameter table... |
// And now the device port/channel parameter table... |
419 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
420 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
436 |
QPixmap pixmap; |
QPixmap pixmap; |
437 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
438 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
439 |
pixmap = QPixmap(":/qsampler/pixmaps/audio2.png"); |
pixmap = QPixmap(":/icons/audio2.png"); |
440 |
break; |
break; |
441 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
442 |
pixmap = QPixmap(":/qsampler/pixmaps/midi2.png"); |
pixmap = QPixmap(":/icons/midi2.png"); |
443 |
break; |
break; |
444 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
445 |
break; |
break; |
446 |
} |
} |
447 |
qsamplerDevicePortList& ports = device.ports(); |
qsamplerDevicePortList& ports = device.ports(); |
448 |
qsamplerDevicePort *pPort; |
QListIterator<qsamplerDevicePort *> iter(ports); |
449 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
while (iter.hasNext()) { |
450 |
ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName() |
qsamplerDevicePort *pPort = iter.next(); |
451 |
|
ui.DevicePortComboBox->addItem(pixmap, |
452 |
|
device.deviceTypeName() |
453 |
+ ' ' + device.driverName() |
+ ' ' + device.driverName() |
454 |
+ ' ' + pPort->portName()); |
+ ' ' + pPort->portName()); |
455 |
} |
} |
462 |
m_iDirtySetup--; |
m_iDirtySetup--; |
463 |
|
|
464 |
// Make the device port/channel selection effective. |
// Make the device port/channel selection effective. |
465 |
selectDevicePort(ui.DevicePortComboBox->currentItem()); |
selectDevicePort(ui.DevicePortComboBox->currentIndex()); |
466 |
} |
} |
467 |
|
|
468 |
|
|
481 |
return; |
return; |
482 |
|
|
483 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
484 |
qsamplerDevicePort *pPort = device.ports().at(iPort); |
qsamplerDevicePort *pPort = NULL; |
485 |
|
if (iPort >= 0 && iPort < device.ports().count()) |
486 |
|
pPort = device.ports().at(iPort); |
487 |
if (pPort) { |
if (pPort) { |
488 |
m_iDirtySetup++; |
m_iDirtySetup++; |
489 |
devicePortParamModel.refresh(pPort->params(), false); |
devicePortParamModel.refresh(pPort, false); |
490 |
m_iDirtySetup--; |
m_iDirtySetup--; |
491 |
} |
} |
492 |
// Done. |
// Done. |
506 |
// Device parameter change... |
// Device parameter change... |
507 |
// |
// |
508 |
|
|
509 |
|
/* we do that in the model class now ... |
510 |
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
511 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
512 |
return; |
return; |
524 |
} else { |
} else { |
525 |
stabilizeForm(); |
stabilizeForm(); |
526 |
} |
} |
527 |
|
*/ |
528 |
|
|
529 |
// Main session should be dirtier... |
// Main session should be dirtier... |
530 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
545 |
// Device port/channel parameter change... |
// Device port/channel parameter change... |
546 |
// |
// |
547 |
|
|
548 |
|
/* we do that in the model class now ... |
549 |
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
550 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
551 |
return; |
return; |
552 |
|
|
553 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
554 |
|
|
555 |
int iPort = ui.DevicePortComboBox->currentItem(); |
int iPort = ui.DevicePortComboBox->currentIndex(); |
556 |
qsamplerDevicePort *pPort = device.ports().at(iPort); |
qsamplerDevicePort *pPort = NULL; |
557 |
|
if (iPort >= 0 && iPort < device.ports().count()) |
558 |
|
pPort = device.ports().at(iPort); |
559 |
if (pPort == NULL) |
if (pPort == NULL) |
560 |
return; |
return; |
561 |
|
|
567 |
|
|
568 |
// Set the local device port/channel parameter value. |
// Set the local device port/channel parameter value. |
569 |
pPort->setParam(sParam, sValue); |
pPort->setParam(sParam, sValue); |
570 |
|
*/ |
571 |
|
|
572 |
// Done. |
// Done. |
573 |
stabilizeForm(); |
stabilizeForm(); |
574 |
|
|
590 |
if (pItem == NULL) |
if (pItem == NULL) |
591 |
return; |
return; |
592 |
|
|
|
int iItemID; |
|
|
|
|
593 |
// Build the device context menu... |
// Build the device context menu... |
594 |
QMenu* pContextMenu = new QMenu(this); |
QMenu menu(this); |
595 |
|
QAction *pAction; |
596 |
|
|
597 |
bool bClient = (pMainForm->client() != NULL); |
bool bClient = (pMainForm->client() != NULL); |
598 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
599 |
iItemID = pContextMenu->insertItem( |
pAction = menu.addAction( |
600 |
QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")), |
QIcon(":/qsampler/pixmaps/deviceCreate.png"), |
601 |
tr("&Create device"), this, SLOT(createDevice())); |
tr("&Create device"), this, SLOT(createDevice())); |
602 |
pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice)); |
pAction->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
603 |
iItemID = pContextMenu->insertItem( |
pAction = menu.addAction( |
604 |
QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")), |
QIcon(":/qsampler/pixmaps/deviceDelete.png"), |
605 |
tr("&Delete device"), this, SLOT(deleteDevice())); |
tr("&Delete device"), this, SLOT(deleteDevice())); |
606 |
pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice); |
pAction->setEnabled(bEnabled && !m_bNewDevice); |
607 |
pContextMenu->insertSeparator(); |
menu.addSeparator(); |
608 |
iItemID = pContextMenu->insertItem( |
pAction = menu.addAction( |
609 |
QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")), |
QIcon(":/qsampler/pixmaps/formRefresh.png"), |
610 |
tr("&Refresh"), this, SLOT(refreshDevices())); |
tr("&Refresh"), this, SLOT(refreshDevices())); |
611 |
pContextMenu->setItemEnabled(iItemID, bClient); |
pAction->setEnabled(bClient); |
|
|
|
|
pContextMenu->exec(pos); |
|
612 |
|
|
613 |
delete pContextMenu; |
menu.exec(pos); |
614 |
} |
} |
615 |
|
|
616 |
|
|
630 |
ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
631 |
} |
} |
632 |
|
|
633 |
|
void DeviceForm::updateCellRenderers() { |
634 |
|
const int rows = deviceParamModel.rowCount(); |
635 |
|
const int cols = deviceParamModel.columnCount(); |
636 |
|
updateCellRenderers(deviceParamModel.index(0,0),deviceParamModel.index(rows-1,cols-1)); |
637 |
|
} |
638 |
|
|
639 |
|
void DeviceForm::updateCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) { |
640 |
|
for (int r = topLeft.row(); r <= bottomRight.row(); r++) { |
641 |
|
for (int c = topLeft.column(); c <= bottomRight.column(); c++) { |
642 |
|
const QModelIndex index = deviceParamModel.index(r,c); |
643 |
|
ui.DeviceParamTable->openPersistentEditor(index); |
644 |
|
} |
645 |
|
} |
646 |
|
} |
647 |
|
|
648 |
|
void DeviceForm::updatePortCellRenderers() { |
649 |
|
const int rows = devicePortParamModel.rowCount(); |
650 |
|
const int cols = devicePortParamModel.columnCount(); |
651 |
|
updatePortCellRenderers(devicePortParamModel.index(0,0),devicePortParamModel.index(rows-1,cols-1)); |
652 |
|
} |
653 |
|
|
654 |
|
void DeviceForm::updatePortCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) { |
655 |
|
for (int r = topLeft.row(); r <= bottomRight.row(); r++) { |
656 |
|
for (int c = topLeft.column(); c <= bottomRight.column(); c++) { |
657 |
|
const QModelIndex index = devicePortParamModel.index(r,c); |
658 |
|
ui.DevicePortParamTable->openPersistentEditor(index); |
659 |
|
} |
660 |
|
} |
661 |
|
} |
662 |
|
|
663 |
} // namespace QSampler |
} // namespace QSampler |
664 |
|
|
665 |
|
|