/[svn]/qsampler/trunk/src/qsamplerDeviceForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDeviceForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2074 by capela, Mon Mar 29 17:00:30 2010 UTC revision 3833 by capela, Thu Oct 22 16:51:16 2020 UTC
# Line 1  Line 1 
1  // qsamplerDeviceForm.cpp  // qsamplerDeviceForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, 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
# Line 28  Line 28 
28  #include <QHeaderView>  #include <QHeaderView>
29  #include <QMessageBox>  #include <QMessageBox>
30    
31    #include <QCheckBox>
32    
33    
34  namespace QSampler {  namespace QSampler {
35    
# Line 45  DeviceForm::DeviceForm ( QWidget *pParen Line 47  DeviceForm::DeviceForm ( QWidget *pParen
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    
# Line 60  DeviceForm::DeviceForm ( QWidget *pParen Line 62  DeviceForm::DeviceForm ( QWidget *pParen
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 >= QT_VERSION_CHECK(5, 0, 0)
66            m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
67    #else
68          m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);          m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
69    #endif
70          m_ui.DeviceParamTable->verticalHeader()->hide();          m_ui.DeviceParamTable->verticalHeader()->hide();
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 >= QT_VERSION_CHECK(5, 0, 0)
75            m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
76    #else
77          m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);          m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
78    #endif
79          m_ui.DevicePortParamTable->verticalHeader()->hide();          m_ui.DevicePortParamTable->verticalHeader()->hide();
80    
81          // Initial contents.          // Initial contents.
# Line 83  DeviceForm::DeviceForm ( QWidget *pParen Line 93  DeviceForm::DeviceForm ( QWidget *pParen
93                  SIGNAL(clicked()),                  SIGNAL(clicked()),
94                  SLOT(refreshDevices()));                  SLOT(refreshDevices()));
95          QObject::connect(m_ui.DriverNameComboBox,          QObject::connect(m_ui.DriverNameComboBox,
96                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(int)),
97                  SLOT(selectDriver(const QString&)));                  SLOT(selectDriver(int)));
98          QObject::connect(m_ui.DevicePortComboBox,          QObject::connect(m_ui.DevicePortComboBox,
99                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
100                  SLOT(selectDevicePort(int)));                  SLOT(selectDevicePort(int)));
# Line 182  void DeviceForm::setDevice ( Device *pDe Line 192  void DeviceForm::setDevice ( Device *pDe
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;
# Line 195  void DeviceForm::setDevice ( Device *pDe Line 205  void DeviceForm::setDevice ( Device *pDe
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          }          }
# Line 223  void DeviceForm::setDevice ( Device *pDe Line 233  void DeviceForm::setDevice ( Device *pDe
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;
# Line 261  void DeviceForm::createDevice (void) Line 271  void DeviceForm::createDevice (void)
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();
# Line 273  void DeviceForm::deleteDevice (void) Line 283  void DeviceForm::deleteDevice (void)
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 = 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;                          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;
308                    if (cbox.isChecked())
309                            pOptions->bConfirmRemove = false;
310            #endif
311          }          }
312    
313          // Go and destroy...          // Go and destroy...
# Line 299  void DeviceForm::deleteDevice (void) Line 325  void DeviceForm::deleteDevice (void)
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.
# Line 308  void DeviceForm::refreshDevices (void) Line 334  void DeviceForm::refreshDevices (void)
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;
# Line 354  void DeviceForm::refreshDevices (void) Line 380  void DeviceForm::refreshDevices (void)
380    
381    
382  // Driver selection slot.  // Driver selection slot.
383  void DeviceForm::selectDriver ( const QString& sDriverName )  void DeviceForm::selectDriver ( int iDriver )
384  {  {
385          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
386                  return;                  return;
# Line 362  void DeviceForm::selectDriver ( const QS Line 388  void DeviceForm::selectDriver ( const QS
388          //          //
389          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
390          //          //
391            const QString& sDriverName
392                    = m_ui.DriverNameComboBox->itemText(iDriver);
393            if (sDriverName.isEmpty())
394                    return;
395    
396          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
397          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
398                  return;                  return;
399    
400          Device& device = ((DeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
# Line 385  void DeviceForm::selectDriver ( const QS Line 415  void DeviceForm::selectDriver ( const QS
415  void DeviceForm::selectDevice ()  void DeviceForm::selectDevice ()
416  {  {
417          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
418          if (pMainForm == NULL)          if (pMainForm == nullptr)
419                  return;                  return;
420    
421          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
# Line 396  void DeviceForm::selectDevice () Line 426  void DeviceForm::selectDevice ()
426          //          //
427    
428          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
429          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM) {
430                  m_deviceType = Device::None;                  m_deviceType = Device::None;
431                  m_ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString());
432                  m_deviceParamModel.clear();                  m_deviceParamModel.clear();
433                  m_ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
434                  m_devicePortParamModel.clear();                  m_devicePortParamModel.clear();
# Line 494  void DeviceForm::selectDevicePort ( int Line 524  void DeviceForm::selectDevicePort ( int
524          //          //
525    
526          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
527          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
528                  return;                  return;
529    
530          Device& device = ((DeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
531          DevicePort *pPort = NULL;          DevicePort *pPort = nullptr;
532          if (iPort >= 0 && iPort < device.ports().count())          if (iPort >= 0 && iPort < device.ports().count())
533                  pPort = device.ports().at(iPort);                  pPort = device.ports().at(iPort);
534          if (pPort) {          if (pPort) {
# Line 525  void DeviceForm::changeDeviceParam ( int Line 555  void DeviceForm::changeDeviceParam ( int
555    
556  /* we do that in the model class now ...  /* we do that in the model class now ...
557          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
558          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
559                  return;                  return;
560    
561          Device& device = ((DeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
# Line 564  void DeviceForm::changeDevicePortParam ( Line 594  void DeviceForm::changeDevicePortParam (
594    
595  /* we do that in the model class now ...  /* we do that in the model class now ...
596          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
597          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
598                  return;                  return;
599    
600          Device& device = ((DeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
601    
602          int iPort = m_ui.DevicePortComboBox->currentIndex();          int iPort = m_ui.DevicePortComboBox->currentIndex();
603          DevicePort *pPort = NULL;          DevicePort *pPort = nullptr;
604          if (iPort >= 0 && iPort < device.ports().count())          if (iPort >= 0 && iPort < device.ports().count())
605                  pPort = device.ports().at(iPort);                  pPort = device.ports().at(iPort);
606          if (pPort == NULL)          if (pPort == nullptr)
607                  return;                  return;
608    
609          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
# Line 600  void DeviceForm::changeDevicePortParam ( Line 630  void DeviceForm::changeDevicePortParam (
630  void DeviceForm::deviceListViewContextMenu ( const QPoint& pos )  void DeviceForm::deviceListViewContextMenu ( const QPoint& pos )
631  {  {
632          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
633          if (pMainForm == NULL)          if (pMainForm == nullptr)
634                  return;                  return;
635    
636          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
637          if (pItem == NULL)          if (pItem == nullptr)
638                  return;                  return;
639    
640          // Build the device context menu...          // Build the device context menu...
641          QMenu menu(this);          QMenu menu(this);
642          QAction *pAction;          QAction *pAction;
643    
644          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != nullptr);
645          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != nullptr);
646          pAction = menu.addAction(          pAction = menu.addAction(
647                  QIcon(":/images/deviceCreate.png"),                  QIcon(":/images/deviceCreate.png"),
648                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
# Line 636  void DeviceForm::stabilizeForm (void) Line 666  void DeviceForm::stabilizeForm (void)
666  {  {
667          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
668          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
669          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != nullptr);
670          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != nullptr);
671          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
672          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
673          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);

Legend:
Removed from v.2074  
changed lines
  Added in v.3833

  ViewVC Help
Powered by ViewVC