/[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 1464 by capela, Thu Nov 1 17:14:21 2007 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-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2019, 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
# Line 23  Line 23 
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    #include <QCheckBox>
32    
33    
34  namespace QSampler {  namespace QSampler {
35    
36  DeviceForm::DeviceForm(QWidget* parent, Qt::WFlags f) : QDialog(parent, f) {  //-------------------------------------------------------------------------
37      ui.setupUi(this);  // QSampler::DeviceForm -- Device form implementation.
38    //
39    
40    DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags )
41            : QDialog(pParent, wflags)
42    {
43            m_ui.setupUi(this);
44    
45          // Initialize locals.          // Initialize locals.
46          m_iDirtySetup = 0;          m_iDirtySetup = 0;
47          m_iDirtyCount = 0;          m_iDirtyCount = 0;
48          m_bNewDevice  = false;          m_bNewDevice  = false;
49          m_deviceType  = qsamplerDevice::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 = qsamplerDevice::None;          m_deviceTypeMode = Device::None;
   
         ui.DeviceParamTable->setModel(&deviceParamModel);  
         ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);  
54    
55          ui.DevicePortParamTable->setModel(&devicePortParamModel);          m_ui.DeviceListView->header()->hide();
         ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);  
56    
57          // This an outsider (from designer), but rather important.          int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
58          //QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
59          //      this, SLOT(changeDeviceParam(int,int)));          m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
60          //QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),          m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
61          //      this, SLOT(changeDevicePortParam(int,int)));          m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
62    
63            m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
64            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);
69    #endif
70            m_ui.DeviceParamTable->verticalHeader()->hide();
71    
72            m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
73            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);
78    #endif
79            m_ui.DevicePortParamTable->verticalHeader()->hide();
80    
81          // Initial contents.          // Initial contents.
82          refreshDevices();          refreshDevices();
83          // Try to restore normal window positioning.          // Try to restore normal window positioning.
84          adjustSize();          adjustSize();
85    
86            QObject::connect(m_ui.DeviceListView,
87                    SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
88                    SLOT(selectDevice()));
89            QObject::connect(m_ui.DeviceListView,
90                    SIGNAL(customContextMenuRequested(const QPoint&)),
91                    SLOT(deviceListViewContextMenu(const QPoint&)));
92            QObject::connect(m_ui.RefreshDevicesPushButton,
93                    SIGNAL(clicked()),
94                    SLOT(refreshDevices()));
95            QObject::connect(m_ui.DriverNameComboBox,
96                    SIGNAL(activated(const QString&)),
97                    SLOT(selectDriver(const QString&)));
98            QObject::connect(m_ui.DevicePortComboBox,
99                    SIGNAL(activated(int)),
100                    SLOT(selectDevicePort(int)));
101            QObject::connect(m_ui.CreateDevicePushButton,
102                    SIGNAL(clicked()),
103                    SLOT(createDevice()));
104            QObject::connect(m_ui.DeleteDevicePushButton,
105                    SIGNAL(clicked()),
106                    SLOT(deleteDevice()));
107            QObject::connect(m_ui.ClosePushButton,
108                    SIGNAL(clicked()),
109                    SLOT(close()));
110            QObject::connect(&m_deviceParamModel,
111                    SIGNAL(modelReset()),
112                    SLOT(updateCellRenderers()));
113            QObject::connect(&m_deviceParamModel,
114                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
115                    SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
116            QObject::connect(&m_devicePortParamModel,
117                    SIGNAL(modelReset()),
118                    SLOT(updatePortCellRenderers()));
119            QObject::connect(&m_devicePortParamModel,
120                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
121                    SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
122  }  }
123    
124  DeviceForm::~DeviceForm() {  
125    DeviceForm::~DeviceForm (void)
126    {
127  }  }
128    
129    
# Line 68  void DeviceForm::showEvent ( QShowEvent Line 134  void DeviceForm::showEvent ( QShowEvent
134          if (pMainForm)          if (pMainForm)
135                  pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
136    
         stabilizeForm();  
   
137          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
138    
139            refreshDevices();
140  }  }
141    
142    
# Line 93  void DeviceForm::hideEvent ( QHideEvent Line 159  void DeviceForm::hideEvent ( QHideEvent
159    
160  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
161  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
162          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          Device::DeviceType deviceTypeMode )
163  {  {
164          // If it has not changed, do nothing.          // If it has not changed, do nothing.
165          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 109  void DeviceForm::setDeviceTypeMode ( Line 175  void DeviceForm::setDeviceTypeMode (
175  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
176  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
177  {  {
178          if (ui.DriverNameComboBox->findText(sDriverName) == 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
179                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
180          }          m_ui.DriverNameComboBox->setItemText(
181          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
182                    sDriverName);
183  }  }
184    
185    
186  // Set current selected device by type and id.  // Set current selected device by type and id.
187  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( Device *pDevice )
188  {  {
189          // In case no device is given...          // In case no device is given...
190          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          Device::DeviceType deviceType = m_deviceTypeMode;
191          if (pDevice)          if (pDevice)
192                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
193    
194          // Get the device view root item...          // Get the device view root item...
195          qsamplerDeviceItem *pRootItem = NULL;          DeviceItem *pRootItem = nullptr;
196          switch (deviceType) {          switch (deviceType) {
197          case qsamplerDevice::Audio:          case Device::Audio:
198                  pRootItem = m_pAudioItems;                  pRootItem = m_pAudioItems;
199                  break;                  break;
200          case qsamplerDevice::Midi:          case Device::Midi:
201                  pRootItem = m_pMidiItems;                  pRootItem = m_pMidiItems;
202                  break;                  break;
203          case qsamplerDevice::None:          case Device::None:
204                  break;                  break;
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                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
214                  return;                  return;
215          }          }
216    
217          // For each child, test for identity...          // For each child, test for identity...
218          for (int i = 0; i < pRootItem->childCount(); i++) {          for (int i = 0; i < pRootItem->childCount(); i++) {
219                  qsamplerDeviceItem* pDeviceItem =                  DeviceItem* pDeviceItem =
220                          (qsamplerDeviceItem*) pRootItem->child(i);                          (DeviceItem*) pRootItem->child(i);
221    
222                  // If identities match, select as current device item.                  // If identities match, select as current device item.
223                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
# Line 166  void DeviceForm::setDevice ( qsamplerDev Line 233  void DeviceForm::setDevice ( qsamplerDev
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 = 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          qsamplerDevice device(((qsamplerDeviceItem *) 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                  qsamplerDeviceItem *pRootItem = NULL;                  DeviceItem *pRootItem = nullptr;
248                  switch (device.deviceType()) {                  switch (device.deviceType()) {
249                  case qsamplerDevice::Audio:                  case Device::Audio:
250                          pRootItem = m_pAudioItems;                          pRootItem = m_pAudioItems;
251                          break;                          break;
252                  case qsamplerDevice::Midi:                  case Device::Midi:
253                          pRootItem = m_pMidiItems;                          pRootItem = m_pMidiItems;
254                          break;                          break;
255                  case qsamplerDevice::None:                  case Device::None:
256                          break;                          break;
257                  }                  }
258                  // Append the new device item.                  // Append the new device item.
259                  qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,                  DeviceItem *pDeviceItem = new DeviceItem(pRootItem,
260                          device.deviceType(), device.deviceID());                          device.deviceType(), device.deviceID());
261                  // Just make it the new selection...                  // Just make it the new selection...
262                  pDeviceItem->setSelected(true);                  pDeviceItem->setSelected(true);
# Line 204  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 = 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          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
282    
283          // Prompt user if this is for real...          // Prompt user if this is for real...
284          qsamplerOptions *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("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                          tr("OK"), tr("Cancel")) > 0)          #if 0
293                    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 241  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 250  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          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
340          if (pMainForm->client()) {          if (pMainForm->client()) {
341                  int *piDeviceIDs;                  int *piDeviceIDs;
342                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
343                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
344                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == Device::Audio) {
345                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new DeviceItem(m_ui.DeviceListView,
346                                  qsamplerDevice::Audio);                                  Device::Audio);
347                  }                  }
348                  if (m_pAudioItems) {                  if (m_pAudioItems) {
349                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
350                                  qsamplerDevice::Audio);                                  Device::Audio);
351                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
352                                  new qsamplerDeviceItem(m_pAudioItems,                                  new DeviceItem(m_pAudioItems,
353                                          qsamplerDevice::Audio, piDeviceIDs[i]);                                          Device::Audio, piDeviceIDs[i]);
354                          }                          }
355                          m_pAudioItems->setExpanded(true);                          m_pAudioItems->setExpanded(true);
356                  }                  }
357                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
358                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
359                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == Device::Midi) {
360                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new DeviceItem(m_ui.DeviceListView,
361                                  qsamplerDevice::Midi);                                  Device::Midi);
362                  }                  }
363                  if (m_pMidiItems) {                  if (m_pMidiItems) {
364                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
365                                  qsamplerDevice::Midi);                                  Device::Midi);
366                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
367                                  new qsamplerDeviceItem(m_pMidiItems,                                  new DeviceItem(m_pMidiItems,
368                                          qsamplerDevice::Midi, piDeviceIDs[i]);                                          Device::Midi, piDeviceIDs[i]);
369                          }                          }
370                          m_pMidiItems->setExpanded(true);                          m_pMidiItems->setExpanded(true);
371                  }                  }
# Line 305  void DeviceForm::selectDriver ( const QS Line 389  void DeviceForm::selectDriver ( const QS
389          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
390          //          //
391    
392          QTreeWidgetItem* pItem = 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          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
397    
398          // Driver change is only valid for scratch devices...          // Driver change is only valid for scratch devices...
399          if (m_bNewDevice) {          if (m_bNewDevice) {
400                  m_iDirtySetup++;                  m_iDirtySetup++;
401                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
402                  deviceParamModel.refresh(device.params(), m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
403                  m_iDirtySetup--;                  m_iDirtySetup--;
404                  // Done.                  // Done.
405                  stabilizeForm();                  stabilizeForm();
# Line 324  void DeviceForm::selectDriver ( const QS Line 408  void DeviceForm::selectDriver ( const QS
408    
409    
410  // Device selection slot.  // Device selection slot.
411  void DeviceForm::selectDevice (void)  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 337  void DeviceForm::selectDevice (void) Line 421  void DeviceForm::selectDevice (void)
421          //  Device selection has changed...          //  Device selection has changed...
422          //          //
423    
424          QTreeWidgetItem* pItem = 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 = qsamplerDevice::None;                  m_deviceType = Device::None;
427                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString());
428                  deviceParamModel.clear();                  m_deviceParamModel.clear();
429                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
430                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
431                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
432                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
433                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
434                  stabilizeForm();                  stabilizeForm();
435                  return;                  return;
436          }          }
437    
438          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
439    
440          m_iDirtySetup++;          m_iDirtySetup++;
441          // Flag whether this is a new device.          // Flag whether this is a new device.
442          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
443    
444          // Fill the device/driver heading...          // Fill the device/driver heading...
445          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
446          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
447          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
448                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
449                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
450                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          Device::getDrivers(pMainForm->client(), device.deviceType()));
451                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
452          }          }
453          // Do we need a driver name?          // Do we need a driver name?
454          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
455                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
456          setDriverName(device.driverName());          setDriverName(device.driverName());
457          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
458          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
459          // Fill the device parameter table...          // Fill the device parameter table...
460          deviceParamModel.refresh(device.params(), m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
461          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
462          switch (device.deviceType()) {          switch (device.deviceType()) {
463          case qsamplerDevice::Audio:          case Device::Audio:
464                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
465                  break;                  break;
466          case qsamplerDevice::Midi:          case Device::Midi:
467                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
468                  break;                  break;
469          case qsamplerDevice::None:          case Device::None:
470                  break;                  break;
471          }          }
472          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
473          devicePortParamModel.clear();          m_devicePortParamModel.clear();
474          if (m_bNewDevice) {          if (m_bNewDevice) {
475                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
476                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
477                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
478          } else {          } else {
479                  QPixmap pixmap;                  QPixmap pixmap;
480                  switch (device.deviceType()) {                  switch (device.deviceType()) {
481                  case qsamplerDevice::Audio:                  case Device::Audio:
482                          pixmap = QPixmap(":/qsampler/pixmaps/audio2.png");                          pixmap = QPixmap(":/images/audio2.png");
483                          break;                          break;
484                  case qsamplerDevice::Midi:                  case Device::Midi:
485                          pixmap = QPixmap(":/qsampler/pixmaps/midi2.png");                          pixmap = QPixmap(":/images/midi2.png");
486                          break;                          break;
487                  case qsamplerDevice::None:                  case Device::None:
488                          break;                          break;
489                  }                  }
490                  qsamplerDevicePortList& ports = device.ports();                  DevicePortList& ports = device.ports();
491                  qsamplerDevicePort *pPort;                  QListIterator<DevicePort *> iter(ports);
492                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
493                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          DevicePort *pPort = iter.next();
494                            m_ui.DevicePortComboBox->addItem(pixmap,
495                                    device.deviceTypeName()
496                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
497                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
498                  }                  }
499                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
500                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
501                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
502                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
503          }          }
504          // Done.          // Done.
505          m_iDirtySetup--;          m_iDirtySetup--;
506    
507          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
508          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
509  }  }
510    
511    
# Line 433  void DeviceForm::selectDevicePort ( int Line 519  void DeviceForm::selectDevicePort ( int
519          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
520          //          //
521    
522          QTreeWidgetItem* pItem = 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          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
527          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = nullptr;
528            if (iPort >= 0 && iPort < device.ports().count())
529                    pPort = device.ports().at(iPort);
530          if (pPort) {          if (pPort) {
531                  m_iDirtySetup++;                  m_iDirtySetup++;
532                  devicePortParamModel.refresh(pPort->params(), false);                  m_devicePortParamModel.refresh(pPort, false);
533                  m_iDirtySetup--;                  m_iDirtySetup--;
534          }          }
535          // Done.          // Done.
# Line 461  void DeviceForm::changeDeviceParam ( int Line 549  void DeviceForm::changeDeviceParam ( int
549          //  Device parameter change...          //  Device parameter change...
550          //          //
551    
552          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
553          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
554            if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
555                  return;                  return;
556    
557          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
558    
559          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
560          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
561          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
562          const QString sParam = deviceParamModel.data(deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;          const QString sParam = m_deviceParamModel.data(m_deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
563          const QString sValue = deviceParamModel.data(deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;          const QString sValue = m_deviceParamModel.data(m_deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
564          // Set the local device parameter value.          // Set the local device parameter value.
565          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
566                  selectDevice();                  selectDevice();
567          } else {          } else {
568                  stabilizeForm();                  stabilizeForm();
569          }          }
570    */
571    
572          // Main session should be dirtier...          // Main session should be dirtier...
573          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 498  void DeviceForm::changeDevicePortParam ( Line 588  void DeviceForm::changeDevicePortParam (
588          //  Device port/channel parameter change...          //  Device port/channel parameter change...
589          //          //
590    
591          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();  /* we do that in the model class now ...
592          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
593            if (pItem == nullptr || pItem->type() != QSAMPLER_DEVICE_ITEM)
594                  return;                  return;
595    
596          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
597    
598          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
599          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = nullptr;
600          if (pPort == NULL)          if (iPort >= 0 && iPort < device.ports().count())
601                    pPort = device.ports().at(iPort);
602            if (pPort == nullptr)
603                  return;                  return;
604    
605          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
606          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
607          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
608          const QString sParam = devicePortParamModel.data(devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;          const QString sParam = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name;
609          const QString sValue = devicePortParamModel.data(devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;          const QString sValue = m_devicePortParamModel.data(m_devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value;
610    
611          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
612          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
613    */
614    
615          // Done.          // Done.
616          stabilizeForm();          stabilizeForm();
617    
# Line 528  void DeviceForm::changeDevicePortParam ( Line 623  void DeviceForm::changeDevicePortParam (
623    
624    
625  // Device list view context menu handler.  // Device list view context menu handler.
626  void DeviceForm::contextMenu ( QTreeWidgetItem* pItem, const QPoint& pos, int )  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          int iItemID;          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
633            if (pItem == nullptr)
634                    return;
635    
636          // Build the device context menu...          // Build the device context menu...
637          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
638            QAction *pAction;
639    
640          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != nullptr);
641          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != nullptr);
642          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
643                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/images/deviceCreate.png"),
644                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
645          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
646          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
647                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/images/deviceDelete.png"),
648                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
649          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
650          pContextMenu->insertSeparator();          menu.addSeparator();
651          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
652                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/images/formRefresh.png"),
653                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
654          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
   
         pContextMenu->exec(pos);  
655    
656          delete pContextMenu;          menu.exec(pos);
657  }  }
658    
659    
# Line 565  void DeviceForm::contextMenu ( QTreeWidg Line 661  void DeviceForm::contextMenu ( QTreeWidg
661  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
662  {  {
663          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
664          QTreeWidgetItem* pItem = 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          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
668          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
669          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
670          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
671          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
672          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
673          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
674    }
675    
676    
677    void DeviceForm::updateCellRenderers (void)
678    {
679            const int rows = m_deviceParamModel.rowCount();
680            const int cols = m_deviceParamModel.columnCount();
681            updateCellRenderers(
682                    m_deviceParamModel.index(0, 0),
683                    m_deviceParamModel.index(rows - 1, cols - 1));
684    }
685    
686    
687    void DeviceForm::updateCellRenderers (
688            const QModelIndex& topLeft, const QModelIndex& bottomRight )
689    {
690            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
691                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
692                            const QModelIndex index = m_deviceParamModel.index(r, c);
693                            m_ui.DeviceParamTable->openPersistentEditor(index);
694                    }
695            }
696    }
697    
698    
699    void DeviceForm::updatePortCellRenderers (void)
700    {
701            const int rows = m_devicePortParamModel.rowCount();
702            const int cols = m_devicePortParamModel.columnCount();
703            updatePortCellRenderers(
704                    m_devicePortParamModel.index(0, 0),
705                    m_devicePortParamModel.index(rows - 1, cols - 1));
706    }
707    
708    
709    void DeviceForm::updatePortCellRenderers (
710            const QModelIndex& topLeft, const QModelIndex& bottomRight )
711    {
712            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
713                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
714                            const QModelIndex index = m_devicePortParamModel.index(r, c);
715                            m_ui.DevicePortParamTable->openPersistentEditor(index);
716                    }
717            }
718  }  }
719    
720  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC