1 |
// qsamplerDeviceForm.cpp |
// qsamplerDeviceForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, 2008 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 |
28 |
#include <QHeaderView> |
#include <QHeaderView> |
29 |
#include <QMessageBox> |
#include <QMessageBox> |
30 |
|
|
31 |
|
#include <QCheckBox> |
32 |
|
|
33 |
|
|
34 |
namespace QSampler { |
namespace QSampler { |
35 |
|
|
47 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
48 |
m_bNewDevice = false; |
m_bNewDevice = false; |
49 |
m_deviceType = Device::None; |
m_deviceType = Device::None; |
50 |
m_pAudioItems = NULL; |
m_pAudioItems = nullptr; |
51 |
m_pMidiItems = NULL; |
m_pMidiItems = nullptr; |
52 |
// No exclusive mode as default. |
// No exclusive mode as default. |
53 |
m_deviceTypeMode = Device::None; |
m_deviceTypeMode = Device::None; |
54 |
|
|
62 |
|
|
63 |
m_ui.DeviceParamTable->setModel(&m_deviceParamModel); |
m_ui.DeviceParamTable->setModel(&m_deviceParamModel); |
64 |
m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate); |
m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate); |
65 |
#if QT_VERSION >= 0x050000 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
66 |
m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
67 |
#else |
#else |
68 |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
71 |
|
|
72 |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel); |
73 |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate); |
74 |
#if QT_VERSION >= 0x050000 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
75 |
m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); |
76 |
#else |
#else |
77 |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch); |
192 |
deviceType = pDevice->deviceType(); |
deviceType = pDevice->deviceType(); |
193 |
|
|
194 |
// Get the device view root item... |
// Get the device view root item... |
195 |
DeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = nullptr; |
196 |
switch (deviceType) { |
switch (deviceType) { |
197 |
case Device::Audio: |
case Device::Audio: |
198 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
205 |
} |
} |
206 |
|
|
207 |
// Is the root present? |
// Is the root present? |
208 |
if (pRootItem == NULL) |
if (pRootItem == nullptr) |
209 |
return; |
return; |
210 |
|
|
211 |
// So there's no device huh? |
// So there's no device huh? |
212 |
if (pDevice == NULL) { |
if (pDevice == nullptr) { |
213 |
m_ui.DeviceListView->setCurrentItem(pRootItem); |
m_ui.DeviceListView->setCurrentItem(pRootItem); |
214 |
return; |
return; |
215 |
} |
} |
233 |
void DeviceForm::createDevice (void) |
void DeviceForm::createDevice (void) |
234 |
{ |
{ |
235 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
236 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
237 |
return; |
return; |
238 |
|
|
239 |
QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem(); |
240 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
241 |
return; |
return; |
242 |
|
|
243 |
// About a brand new device instance... |
// About a brand new device instance... |
244 |
Device device(((DeviceItem *) pItem)->device()); |
Device device(((DeviceItem *) pItem)->device()); |
245 |
if (device.createDevice()) { |
if (device.createDevice()) { |
246 |
// Now it depends on the device type... |
// Now it depends on the device type... |
247 |
DeviceItem *pRootItem = NULL; |
DeviceItem *pRootItem = nullptr; |
248 |
switch (device.deviceType()) { |
switch (device.deviceType()) { |
249 |
case Device::Audio: |
case Device::Audio: |
250 |
pRootItem = m_pAudioItems; |
pRootItem = m_pAudioItems; |
271 |
void DeviceForm::deleteDevice (void) |
void DeviceForm::deleteDevice (void) |
272 |
{ |
{ |
273 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
274 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
275 |
return; |
return; |
276 |
|
|
277 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
278 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
279 |
return; |
return; |
280 |
|
|
281 |
Device& device = ((DeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
283 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
284 |
Options *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
285 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
286 |
if (QMessageBox::warning(this, |
const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning"); |
287 |
QSAMPLER_TITLE ": " + tr("Warning"), |
const QString& sText = tr( |
288 |
tr("About to delete device:\n\n" |
"About to delete device:\n\n" |
289 |
"%1\n\n" |
"%1\n\n" |
290 |
"Are you sure?") |
"Are you sure?") |
291 |
.arg(device.deviceName()), |
.arg(device.deviceName()); |
292 |
QMessageBox::Ok | QMessageBox::Cancel) |
#if 0 |
293 |
== QMessageBox::Cancel) |
if (QMessageBox::warning(this, sTitle, sText, |
294 |
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) |
295 |
|
return; |
296 |
|
#else |
297 |
|
QMessageBox mbox(this); |
298 |
|
mbox.setIcon(QMessageBox::Warning); |
299 |
|
mbox.setWindowTitle(sTitle); |
300 |
|
mbox.setText(sText); |
301 |
|
mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
302 |
|
QCheckBox cbox(tr("Don't ask this again")); |
303 |
|
cbox.setChecked(false); |
304 |
|
cbox.blockSignals(true); |
305 |
|
mbox.addButton(&cbox, QMessageBox::ActionRole); |
306 |
|
if (mbox.exec() == QMessageBox::Cancel) |
307 |
return; |
return; |
308 |
|
if (cbox.isChecked()) |
309 |
|
pOptions->bConfirmRemove = false; |
310 |
|
#endif |
311 |
} |
} |
312 |
|
|
313 |
// Go and destroy... |
// Go and destroy... |
325 |
void DeviceForm::refreshDevices (void) |
void DeviceForm::refreshDevices (void) |
326 |
{ |
{ |
327 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
328 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
329 |
return; |
return; |
330 |
|
|
331 |
// Avoid nested changes. |
// Avoid nested changes. |
334 |
// |
// |
335 |
// (Re)Load complete device configuration data ... |
// (Re)Load complete device configuration data ... |
336 |
// |
// |
337 |
m_pAudioItems = NULL; |
m_pAudioItems = nullptr; |
338 |
m_pMidiItems = NULL; |
m_pMidiItems = nullptr; |
339 |
m_ui.DeviceListView->clear(); |
m_ui.DeviceListView->clear(); |
340 |
if (pMainForm->client()) { |
if (pMainForm->client()) { |
341 |
int *piDeviceIDs; |
int *piDeviceIDs; |
390 |
// |
// |
391 |
|
|
392 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
393 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
394 |
return; |
return; |
395 |
|
|
396 |
Device& device = ((DeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
411 |
void DeviceForm::selectDevice () |
void DeviceForm::selectDevice () |
412 |
{ |
{ |
413 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
414 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
415 |
return; |
return; |
416 |
|
|
417 |
if (m_iDirtySetup > 0) |
if (m_iDirtySetup > 0) |
422 |
// |
// |
423 |
|
|
424 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
425 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
426 |
m_deviceType = Device::None; |
m_deviceType = Device::None; |
427 |
m_ui.DeviceNameTextLabel->setText(QString::null); |
m_ui.DeviceNameTextLabel->setText(QString()); |
428 |
m_deviceParamModel.clear(); |
m_deviceParamModel.clear(); |
429 |
m_ui.DevicePortComboBox->clear(); |
m_ui.DevicePortComboBox->clear(); |
430 |
m_devicePortParamModel.clear(); |
m_devicePortParamModel.clear(); |
520 |
// |
// |
521 |
|
|
522 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
523 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
524 |
return; |
return; |
525 |
|
|
526 |
Device& device = ((DeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
527 |
DevicePort *pPort = NULL; |
DevicePort *pPort = nullptr; |
528 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
529 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
530 |
if (pPort) { |
if (pPort) { |
551 |
|
|
552 |
/* we do that in the model class now ... |
/* we do that in the model class now ... |
553 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
554 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
555 |
return; |
return; |
556 |
|
|
557 |
Device& device = ((DeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
590 |
|
|
591 |
/* we do that in the model class now ... |
/* we do that in the model class now ... |
592 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
593 |
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) |
594 |
return; |
return; |
595 |
|
|
596 |
Device& device = ((DeviceItem *) pItem)->device(); |
Device& device = ((DeviceItem *) pItem)->device(); |
597 |
|
|
598 |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
int iPort = m_ui.DevicePortComboBox->currentIndex(); |
599 |
DevicePort *pPort = NULL; |
DevicePort *pPort = nullptr; |
600 |
if (iPort >= 0 && iPort < device.ports().count()) |
if (iPort >= 0 && iPort < device.ports().count()) |
601 |
pPort = device.ports().at(iPort); |
pPort = device.ports().at(iPort); |
602 |
if (pPort == NULL) |
if (pPort == nullptr) |
603 |
return; |
return; |
604 |
|
|
605 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
626 |
void DeviceForm::deviceListViewContextMenu ( const QPoint& pos ) |
void DeviceForm::deviceListViewContextMenu ( const QPoint& pos ) |
627 |
{ |
{ |
628 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
629 |
if (pMainForm == NULL) |
if (pMainForm == nullptr) |
630 |
return; |
return; |
631 |
|
|
632 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos); |
633 |
if (pItem == NULL) |
if (pItem == nullptr) |
634 |
return; |
return; |
635 |
|
|
636 |
// Build the device context menu... |
// Build the device context menu... |
637 |
QMenu menu(this); |
QMenu menu(this); |
638 |
QAction *pAction; |
QAction *pAction; |
639 |
|
|
640 |
bool bClient = (pMainForm->client() != NULL); |
bool bClient = (pMainForm->client() != nullptr); |
641 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != nullptr); |
642 |
pAction = menu.addAction( |
pAction = menu.addAction( |
643 |
QIcon(":/images/deviceCreate.png"), |
QIcon(":/images/deviceCreate.png"), |
644 |
tr("&Create device"), this, SLOT(createDevice())); |
tr("&Create device"), this, SLOT(createDevice())); |
662 |
{ |
{ |
663 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
664 |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem(); |
665 |
bool bClient = (pMainForm && pMainForm->client() != NULL); |
bool bClient = (pMainForm && pMainForm->client() != nullptr); |
666 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != nullptr); |
667 |
m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
668 |
m_ui.DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
m_ui.DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
669 |
m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |