/[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 2388 by capela, Sat Dec 29 19:12:58 2012 UTC revision 3555 by capela, Tue Aug 13 10:19:32 2019 UTC
# Line 1  Line 1 
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
# 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 >= 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);
# Line 69  DeviceForm::DeviceForm ( QWidget *pParen Line 71  DeviceForm::DeviceForm ( QWidget *pParen
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);
# Line 190  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 203  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 231  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 269  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 281  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 = 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...
# Line 307  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 316  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 372  void DeviceForm::selectDriver ( const QS Line 390  void DeviceForm::selectDriver ( const QS
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();
# Line 393  void DeviceForm::selectDriver ( const QS Line 411  void DeviceForm::selectDriver ( const QS
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)
# Line 404  void DeviceForm::selectDevice () Line 422  void DeviceForm::selectDevice ()
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();
# Line 502  void DeviceForm::selectDevicePort ( int Line 520  void DeviceForm::selectDevicePort ( int
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) {
# Line 533  void DeviceForm::changeDeviceParam ( int Line 551  void DeviceForm::changeDeviceParam ( int
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();
# Line 572  void DeviceForm::changeDevicePortParam ( Line 590  void DeviceForm::changeDevicePortParam (
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;
# Line 608  void DeviceForm::changeDevicePortParam ( Line 626  void DeviceForm::changeDevicePortParam (
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()));
# Line 644  void DeviceForm::stabilizeForm (void) Line 662  void DeviceForm::stabilizeForm (void)
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);

Legend:
Removed from v.2388  
changed lines
  Added in v.3555

  ViewVC Help
Powered by ViewVC