/[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 1486 by schoenebeck, Sat Nov 17 02:02:28 2007 UTC revision 2388 by capela, Sat Dec 29 19:12:58 2012 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-2012, 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 25  Line 25 
25  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28    #include <QHeaderView>
29    #include <QMessageBox>
30    
31    
32  namespace QSampler {  namespace QSampler {
33    
34  DeviceForm::DeviceForm(QWidget* parent, Qt::WFlags f) : QDialog(parent, f) {  //-------------------------------------------------------------------------
35      ui.setupUi(this);  // QSampler::DeviceForm -- Device form implementation.
36    //
37    
38    DeviceForm::DeviceForm ( QWidget *pParent, Qt::WindowFlags wflags )
39            : QDialog(pParent, wflags)
40    {
41            m_ui.setupUi(this);
42    
43          // Initialize locals.          // Initialize locals.
44          m_iDirtySetup = 0;          m_iDirtySetup = 0;
45          m_iDirtyCount = 0;          m_iDirtyCount = 0;
46          m_bNewDevice  = false;          m_bNewDevice  = false;
47          m_deviceType  = qsamplerDevice::None;          m_deviceType  = Device::None;
48          m_pAudioItems = NULL;          m_pAudioItems = NULL;
49          m_pMidiItems  = NULL;          m_pMidiItems  = NULL;
50          // No exclusive mode as default.          // No exclusive mode as default.
51          m_deviceTypeMode = qsamplerDevice::None;          m_deviceTypeMode = Device::None;
52    
53          ui.DeviceListView->header()->hide();          m_ui.DeviceListView->header()->hide();
54    
55          ui.DeviceParamTable->setModel(&deviceParamModel);          int iRowHeight = m_ui.DeviceParamTable->fontMetrics().height() + 4;
56          ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate);          m_ui.DeviceParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
57          ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);          m_ui.DevicePortParamTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
58            m_ui.DeviceParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
59          ui.DevicePortParamTable->setModel(&devicePortParamModel);          m_ui.DevicePortParamTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
60          ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate);  
61          ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);          m_ui.DeviceParamTable->setModel(&m_deviceParamModel);
62            m_ui.DeviceParamTable->setItemDelegate(&m_deviceParamDelegate);
63    #if QT_VERSION >= 0x050000
64            m_ui.DeviceParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
65    #else
66            m_ui.DeviceParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
67    #endif
68            m_ui.DeviceParamTable->verticalHeader()->hide();
69    
70            m_ui.DevicePortParamTable->setModel(&m_devicePortParamModel);
71            m_ui.DevicePortParamTable->setItemDelegate(&m_devicePortParamDelegate);
72    #if QT_VERSION >= 0x050000
73            m_ui.DevicePortParamTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
74    #else
75            m_ui.DevicePortParamTable->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
76    #endif
77            m_ui.DevicePortParamTable->verticalHeader()->hide();
78    
79          // Initial contents.          // Initial contents.
80          refreshDevices();          refreshDevices();
81          // Try to restore normal window positioning.          // Try to restore normal window positioning.
82          adjustSize();          adjustSize();
83    
84          QObject::connect(ui.DeviceListView,          QObject::connect(m_ui.DeviceListView,
85                  SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),                  SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
86                  SLOT(selectDevice()));                  SLOT(selectDevice()));
87          QObject::connect(ui.DeviceListView,          QObject::connect(m_ui.DeviceListView,
88                  SIGNAL(customContextMenuRequested(const QPoint&)),                  SIGNAL(customContextMenuRequested(const QPoint&)),
89                  SLOT(deviceListViewContextMenu(const QPoint&)));                  SLOT(deviceListViewContextMenu(const QPoint&)));
90          QObject::connect(ui.RefreshDevicesPushButton,          QObject::connect(m_ui.RefreshDevicesPushButton,
91                  SIGNAL(clicked()),                  SIGNAL(clicked()),
92                  SLOT(refreshDevices()));                  SLOT(refreshDevices()));
93          QObject::connect(ui.DriverNameComboBox,          QObject::connect(m_ui.DriverNameComboBox,
94                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
95                  SLOT(selectDriver(const QString&)));                  SLOT(selectDriver(const QString&)));
96          QObject::connect(ui.DevicePortComboBox,          QObject::connect(m_ui.DevicePortComboBox,
97                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
98                  SLOT(selectDevicePort(int)));                  SLOT(selectDevicePort(int)));
99          QObject::connect(ui.CreateDevicePushButton,          QObject::connect(m_ui.CreateDevicePushButton,
100                  SIGNAL(clicked()),                  SIGNAL(clicked()),
101                  SLOT(createDevice()));                  SLOT(createDevice()));
102          QObject::connect(ui.DeleteDevicePushButton,          QObject::connect(m_ui.DeleteDevicePushButton,
103                  SIGNAL(clicked()),                  SIGNAL(clicked()),
104                  SLOT(deleteDevice()));                  SLOT(deleteDevice()));
105          QObject::connect(ui.ClosePushButton,          QObject::connect(m_ui.ClosePushButton,
106                  SIGNAL(clicked()),                  SIGNAL(clicked()),
107                  SLOT(close()));                  SLOT(close()));
108          QObject::connect(&deviceParamModel,          QObject::connect(&m_deviceParamModel,
109                  SIGNAL(modelReset()),                  SIGNAL(modelReset()),
110                  SLOT(updateCellRenderers()));                  SLOT(updateCellRenderers()));
111          QObject::connect(&deviceParamModel,          QObject::connect(&m_deviceParamModel,
112                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
113                  SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));                  SLOT(updateCellRenderers(const QModelIndex&, const QModelIndex&)));
114          QObject::connect(&devicePortParamModel,          QObject::connect(&m_devicePortParamModel,
115                  SIGNAL(modelReset()),                  SIGNAL(modelReset()),
116                  SLOT(updatePortCellRenderers()));                  SLOT(updatePortCellRenderers()));
117          QObject::connect(&devicePortParamModel,          QObject::connect(&m_devicePortParamModel,
118                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),                  SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
119                  SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));                  SLOT(updatePortCellRenderers(const QModelIndex&, const QModelIndex&)));
120  }  }
121    
122  DeviceForm::~DeviceForm() {  
123    DeviceForm::~DeviceForm (void)
124    {
125  }  }
126    
127    
# Line 104  void DeviceForm::showEvent ( QShowEvent Line 132  void DeviceForm::showEvent ( QShowEvent
132          if (pMainForm)          if (pMainForm)
133                  pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
134    
         stabilizeForm();  
   
135          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
136    
137            refreshDevices();
138  }  }
139    
140    
# Line 129  void DeviceForm::hideEvent ( QHideEvent Line 157  void DeviceForm::hideEvent ( QHideEvent
157    
158  // Set device type spacial exclusive mode.  // Set device type spacial exclusive mode.
159  void DeviceForm::setDeviceTypeMode (  void DeviceForm::setDeviceTypeMode (
160          qsamplerDevice::qsamplerDeviceType deviceTypeMode )          Device::DeviceType deviceTypeMode )
161  {  {
162          // If it has not changed, do nothing.          // If it has not changed, do nothing.
163          if (m_deviceTypeMode == deviceTypeMode)          if (m_deviceTypeMode == deviceTypeMode)
# Line 145  void DeviceForm::setDeviceTypeMode ( Line 173  void DeviceForm::setDeviceTypeMode (
173  // Device driver name setup formal initializer.  // Device driver name setup formal initializer.
174  void DeviceForm::setDriverName ( const QString& sDriverName )  void DeviceForm::setDriverName ( const QString& sDriverName )
175  {  {
176          if (ui.DriverNameComboBox->findText(sDriverName) < 0) {          if (m_ui.DriverNameComboBox->findText(sDriverName) < 0)
177                  ui.DriverNameComboBox->insertItem(sDriverName);                  m_ui.DriverNameComboBox->insertItem(0, sDriverName);
178          }          m_ui.DriverNameComboBox->setItemText(
179          ui.DriverNameComboBox->setCurrentText(sDriverName);                  m_ui.DriverNameComboBox->currentIndex(),
180                    sDriverName);
181  }  }
182    
183    
184  // Set current selected device by type and id.  // Set current selected device by type and id.
185  void DeviceForm::setDevice ( qsamplerDevice *pDevice )  void DeviceForm::setDevice ( Device *pDevice )
186  {  {
187          // In case no device is given...          // In case no device is given...
188          qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;          Device::DeviceType deviceType = m_deviceTypeMode;
189          if (pDevice)          if (pDevice)
190                  deviceType = pDevice->deviceType();                  deviceType = pDevice->deviceType();
191    
192          // Get the device view root item...          // Get the device view root item...
193          qsamplerDeviceItem *pRootItem = NULL;          DeviceItem *pRootItem = NULL;
194          switch (deviceType) {          switch (deviceType) {
195          case qsamplerDevice::Audio:          case Device::Audio:
196                  pRootItem = m_pAudioItems;                  pRootItem = m_pAudioItems;
197                  break;                  break;
198          case qsamplerDevice::Midi:          case Device::Midi:
199                  pRootItem = m_pMidiItems;                  pRootItem = m_pMidiItems;
200                  break;                  break;
201          case qsamplerDevice::None:          case Device::None:
202                  break;                  break;
203          }          }
204    
# Line 179  void DeviceForm::setDevice ( qsamplerDev Line 208  void DeviceForm::setDevice ( qsamplerDev
208    
209          // So there's no device huh?          // So there's no device huh?
210          if (pDevice == NULL) {          if (pDevice == NULL) {
211                  ui.DeviceListView->setCurrentItem(pRootItem);                  m_ui.DeviceListView->setCurrentItem(pRootItem);
212                  return;                  return;
213          }          }
214    
215          // For each child, test for identity...          // For each child, test for identity...
216          for (int i = 0; i < pRootItem->childCount(); i++) {          for (int i = 0; i < pRootItem->childCount(); i++) {
217                  qsamplerDeviceItem* pDeviceItem =                  DeviceItem* pDeviceItem =
218                          (qsamplerDeviceItem*) pRootItem->child(i);                          (DeviceItem*) pRootItem->child(i);
219    
220                  // If identities match, select as current device item.                  // If identities match, select as current device item.
221                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {                  if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
# Line 205  void DeviceForm::createDevice (void) Line 234  void DeviceForm::createDevice (void)
234          if (pMainForm == NULL)          if (pMainForm == NULL)
235                  return;                  return;
236    
237          QTreeWidgetItem *pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem *pItem = m_ui.DeviceListView->currentItem();
238          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
239                  return;                  return;
240    
241          // About a brand new device instance...          // About a brand new device instance...
242          qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device());          Device device(((DeviceItem *) pItem)->device());
243          if (device.createDevice()) {          if (device.createDevice()) {
244                  // Now it depends on the device type...                  // Now it depends on the device type...
245                  qsamplerDeviceItem *pRootItem = NULL;                  DeviceItem *pRootItem = NULL;
246                  switch (device.deviceType()) {                  switch (device.deviceType()) {
247                  case qsamplerDevice::Audio:                  case Device::Audio:
248                          pRootItem = m_pAudioItems;                          pRootItem = m_pAudioItems;
249                          break;                          break;
250                  case qsamplerDevice::Midi:                  case Device::Midi:
251                          pRootItem = m_pMidiItems;                          pRootItem = m_pMidiItems;
252                          break;                          break;
253                  case qsamplerDevice::None:                  case Device::None:
254                          break;                          break;
255                  }                  }
256                  // Append the new device item.                  // Append the new device item.
257                  qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,                  DeviceItem *pDeviceItem = new DeviceItem(pRootItem,
258                          device.deviceType(), device.deviceID());                          device.deviceType(), device.deviceID());
259                  // Just make it the new selection...                  // Just make it the new selection...
260                  pDeviceItem->setSelected(true);                  pDeviceItem->setSelected(true);
# Line 243  void DeviceForm::deleteDevice (void) Line 272  void DeviceForm::deleteDevice (void)
272          if (pMainForm == NULL)          if (pMainForm == NULL)
273                  return;                  return;
274    
275          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
276          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
277                  return;                  return;
278    
279          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
280    
281          // Prompt user if this is for real...          // Prompt user if this is for real...
282          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
283          if (pOptions && pOptions->bConfirmRemove) {          if (pOptions && pOptions->bConfirmRemove) {
284                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
285                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
286                          tr("Delete device:\n\n"                          tr("About to delete device:\n\n"
287                          "%1\n\n"                          "%1\n\n"
288                          "Are you sure?")                          "Are you sure?")
289                          .arg(device.deviceName()),                          .arg(device.deviceName()),
290                          tr("OK"), tr("Cancel")) > 0)                          QMessageBox::Ok | QMessageBox::Cancel)
291                            == QMessageBox::Cancel)
292                          return;                          return;
293          }          }
294    
# Line 288  void DeviceForm::refreshDevices (void) Line 318  void DeviceForm::refreshDevices (void)
318          //          //
319          m_pAudioItems = NULL;          m_pAudioItems = NULL;
320          m_pMidiItems = NULL;          m_pMidiItems = NULL;
321          ui.DeviceListView->clear();          m_ui.DeviceListView->clear();
322          if (pMainForm->client()) {          if (pMainForm->client()) {
323                  int *piDeviceIDs;                  int *piDeviceIDs;
324                  // Grab and pop Audio devices...                  // Grab and pop Audio devices...
325                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
326                          m_deviceTypeMode == qsamplerDevice::Audio) {                          m_deviceTypeMode == Device::Audio) {
327                          m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pAudioItems = new DeviceItem(m_ui.DeviceListView,
328                                  qsamplerDevice::Audio);                                  Device::Audio);
329                  }                  }
330                  if (m_pAudioItems) {                  if (m_pAudioItems) {
331                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
332                                  qsamplerDevice::Audio);                                  Device::Audio);
333                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
334                                  new qsamplerDeviceItem(m_pAudioItems,                                  new DeviceItem(m_pAudioItems,
335                                          qsamplerDevice::Audio, piDeviceIDs[i]);                                          Device::Audio, piDeviceIDs[i]);
336                          }                          }
337                          m_pAudioItems->setExpanded(true);                          m_pAudioItems->setExpanded(true);
338                  }                  }
339                  // Grab and pop MIDI devices...                  // Grab and pop MIDI devices...
340                  if (m_deviceTypeMode == qsamplerDevice::None ||                  if (m_deviceTypeMode == Device::None ||
341                          m_deviceTypeMode == qsamplerDevice::Midi) {                          m_deviceTypeMode == Device::Midi) {
342                          m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView,                          m_pMidiItems = new DeviceItem(m_ui.DeviceListView,
343                                  qsamplerDevice::Midi);                                  Device::Midi);
344                  }                  }
345                  if (m_pMidiItems) {                  if (m_pMidiItems) {
346                          piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),                          piDeviceIDs = Device::getDevices(pMainForm->client(),
347                                  qsamplerDevice::Midi);                                  Device::Midi);
348                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
349                                  new qsamplerDeviceItem(m_pMidiItems,                                  new DeviceItem(m_pMidiItems,
350                                          qsamplerDevice::Midi, piDeviceIDs[i]);                                          Device::Midi, piDeviceIDs[i]);
351                          }                          }
352                          m_pMidiItems->setExpanded(true);                          m_pMidiItems->setExpanded(true);
353                  }                  }
# Line 341  void DeviceForm::selectDriver ( const QS Line 371  void DeviceForm::selectDriver ( const QS
371          //  Driver name has changed for a new device...          //  Driver name has changed for a new device...
372          //          //
373    
374          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
375          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
376                  return;                  return;
377    
378          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
379    
380          // Driver change is only valid for scratch devices...          // Driver change is only valid for scratch devices...
381          if (m_bNewDevice) {          if (m_bNewDevice) {
382                  m_iDirtySetup++;                  m_iDirtySetup++;
383                  device.setDriver(sDriverName);                  device.setDriver(sDriverName);
384                  deviceParamModel.refresh(&device, m_bNewDevice);                  m_deviceParamModel.refresh(&device, m_bNewDevice);
385                  m_iDirtySetup--;                  m_iDirtySetup--;
386                  // Done.                  // Done.
387                  stabilizeForm();                  stabilizeForm();
# Line 373  void DeviceForm::selectDevice () Line 403  void DeviceForm::selectDevice ()
403          //  Device selection has changed...          //  Device selection has changed...
404          //          //
405    
406          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
407          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) {
408                  m_deviceType = qsamplerDevice::None;                  m_deviceType = Device::None;
409                  ui.DeviceNameTextLabel->setText(QString::null);                  m_ui.DeviceNameTextLabel->setText(QString::null);
410                  deviceParamModel.clear();                  m_deviceParamModel.clear();
411                  ui.DevicePortComboBox->clear();                  m_ui.DevicePortComboBox->clear();
412                  devicePortParamModel.clear();                  m_devicePortParamModel.clear();
413                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
414                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
415                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
416                  stabilizeForm();                  stabilizeForm();
417                  return;                  return;
418          }          }
419    
420          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
421    
422          m_iDirtySetup++;          m_iDirtySetup++;
423          // Flag whether this is a new device.          // Flag whether this is a new device.
424          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
425    
426          // Fill the device/driver heading...          // Fill the device/driver heading...
427          ui.DeviceNameTextLabel->setText(device.deviceName());          m_ui.DeviceNameTextLabel->setText(device.deviceName());
428          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
429          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
430                  ui.DriverNameComboBox->clear();                  m_ui.DriverNameComboBox->clear();
431                  ui.DriverNameComboBox->insertStringList(                  m_ui.DriverNameComboBox->insertItems(0,
432                          qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));                          Device::getDrivers(pMainForm->client(), device.deviceType()));
433                  m_deviceType = device.deviceType();                  m_deviceType = device.deviceType();
434          }          }
435          // Do we need a driver name?          // Do we need a driver name?
436          if (m_bNewDevice || device.driverName().isEmpty())          if (m_bNewDevice || device.driverName().isEmpty())
437                  device.setDriver(ui.DriverNameComboBox->currentText());                  device.setDriver(m_ui.DriverNameComboBox->currentText());
438          setDriverName(device.driverName());          setDriverName(device.driverName());
439          ui.DriverNameTextLabel->setEnabled(m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(m_bNewDevice);
440          ui.DriverNameComboBox->setEnabled(m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(m_bNewDevice);
441          // Fill the device parameter table...          // Fill the device parameter table...
442          deviceParamModel.refresh(&device, m_bNewDevice);          m_deviceParamModel.refresh(&device, m_bNewDevice);
443          // And now the device port/channel parameter table...          // And now the device port/channel parameter table...
444          switch (device.deviceType()) {          switch (device.deviceType()) {
445          case qsamplerDevice::Audio:          case Device::Audio:
446                  ui.DevicePortTextLabel->setText(tr("Ch&annel:"));                  m_ui.DevicePortTextLabel->setText(tr("Ch&annel:"));
447                  break;                  break;
448          case qsamplerDevice::Midi:          case Device::Midi:
449                  ui.DevicePortTextLabel->setText(tr("P&ort:"));                  m_ui.DevicePortTextLabel->setText(tr("P&ort:"));
450                  break;                  break;
451          case qsamplerDevice::None:          case Device::None:
452                  break;                  break;
453          }          }
454          ui.DevicePortComboBox->clear();          m_ui.DevicePortComboBox->clear();
455          devicePortParamModel.clear();          m_devicePortParamModel.clear();
456          if (m_bNewDevice) {          if (m_bNewDevice) {
457                  ui.DevicePortTextLabel->setEnabled(false);                  m_ui.DevicePortTextLabel->setEnabled(false);
458                  ui.DevicePortComboBox->setEnabled(false);                  m_ui.DevicePortComboBox->setEnabled(false);
459                  ui.DevicePortParamTable->setEnabled(false);                  m_ui.DevicePortParamTable->setEnabled(false);
460          } else {          } else {
461                  QPixmap pixmap;                  QPixmap pixmap;
462                  switch (device.deviceType()) {                  switch (device.deviceType()) {
463                  case qsamplerDevice::Audio:                  case Device::Audio:
464                          pixmap = QPixmap(":/icons/audio2.png");                          pixmap = QPixmap(":/images/audio2.png");
465                          break;                          break;
466                  case qsamplerDevice::Midi:                  case Device::Midi:
467                          pixmap = QPixmap(":/icons/midi2.png");                          pixmap = QPixmap(":/images/midi2.png");
468                          break;                          break;
469                  case qsamplerDevice::None:                  case Device::None:
470                          break;                          break;
471                  }                  }
472                  qsamplerDevicePortList& ports = device.ports();                  DevicePortList& ports = device.ports();
473                  qsamplerDevicePort *pPort;                  QListIterator<DevicePort *> iter(ports);
474                  for (pPort = ports.first(); pPort; pPort = ports.next()) {                  while (iter.hasNext()) {
475                          ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()                          DevicePort *pPort = iter.next();
476                            m_ui.DevicePortComboBox->addItem(pixmap,
477                                    device.deviceTypeName()
478                                  + ' ' + device.driverName()                                  + ' ' + device.driverName()
479                                  + ' ' + pPort->portName());                                  + ' ' + pPort->portName());
480                  }                  }
481                  bool bEnabled = (ports.count() > 0);                  bool bEnabled = (ports.count() > 0);
482                  ui.DevicePortTextLabel->setEnabled(bEnabled);                  m_ui.DevicePortTextLabel->setEnabled(bEnabled);
483                  ui.DevicePortComboBox->setEnabled(bEnabled);                  m_ui.DevicePortComboBox->setEnabled(bEnabled);
484                  ui.DevicePortParamTable->setEnabled(bEnabled);                  m_ui.DevicePortParamTable->setEnabled(bEnabled);
485          }          }
486          // Done.          // Done.
487          m_iDirtySetup--;          m_iDirtySetup--;
488    
489          // Make the device port/channel selection effective.          // Make the device port/channel selection effective.
490          selectDevicePort(ui.DevicePortComboBox->currentItem());          selectDevicePort(m_ui.DevicePortComboBox->currentIndex());
491  }  }
492    
493    
# Line 469  void DeviceForm::selectDevicePort ( int Line 501  void DeviceForm::selectDevicePort ( int
501          //  Device port/channel selection has changed...          //  Device port/channel selection has changed...
502          //          //
503    
504          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
505          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
506                  return;                  return;
507    
508          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
509          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = NULL;
510            if (iPort >= 0 && iPort < device.ports().count())
511                    pPort = device.ports().at(iPort);
512          if (pPort) {          if (pPort) {
513                  m_iDirtySetup++;                  m_iDirtySetup++;
514                  devicePortParamModel.refresh(pPort, false);                  m_devicePortParamModel.refresh(pPort, false);
515                  m_iDirtySetup--;                  m_iDirtySetup--;
516          }          }
517          // Done.          // Done.
# Line 498  void DeviceForm::changeDeviceParam ( int Line 532  void DeviceForm::changeDeviceParam ( int
532          //          //
533    
534  /* we do that in the model class now ...  /* we do that in the model class now ...
535          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
536          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
537                  return;                  return;
538    
539          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
540    
541          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
542          //const QString sParam = ui.DeviceParamTable->text(iRow, 0);          //const QString sParam = m_ui.DeviceParamTable->text(iRow, 0);
543          //const QString sValue = ui.DeviceParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DeviceParamTable->text(iRow, iCol);
544          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;
545          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;
546          // Set the local device parameter value.          // Set the local device parameter value.
547          if (device.setParam(sParam, sValue)) {          if (device.setParam(sParam, sValue)) {
548                  selectDevice();                  selectDevice();
# Line 537  void DeviceForm::changeDevicePortParam ( Line 571  void DeviceForm::changeDevicePortParam (
571          //          //
572    
573  /* we do that in the model class now ...  /* we do that in the model class now ...
574          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
575          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM)
576                  return;                  return;
577    
578          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          Device& device = ((DeviceItem *) pItem)->device();
579    
580          int iPort = ui.DevicePortComboBox->currentItem();          int iPort = m_ui.DevicePortComboBox->currentIndex();
581          qsamplerDevicePort *pPort = device.ports().at(iPort);          DevicePort *pPort = NULL;
582            if (iPort >= 0 && iPort < device.ports().count())
583                    pPort = device.ports().at(iPort);
584          if (pPort == NULL)          if (pPort == NULL)
585                  return;                  return;
586    
587          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
588          //const QString sParam = ui.DevicePortParamTable->text(iRow, 0);          //const QString sParam = m_ui.DevicePortParamTable->text(iRow, 0);
589          //const QString sValue = ui.DevicePortParamTable->text(iRow, iCol);          //const QString sValue = m_ui.DevicePortParamTable->text(iRow, iCol);
590          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;
591          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;
592    
593          // Set the local device port/channel parameter value.          // Set the local device port/channel parameter value.
594          pPort->setParam(sParam, sValue);          pPort->setParam(sParam, sValue);
# Line 575  void DeviceForm::deviceListViewContextMe Line 611  void DeviceForm::deviceListViewContextMe
611          if (pMainForm == NULL)          if (pMainForm == NULL)
612                  return;                  return;
613    
614          QTreeWidgetItem* pItem = ui.DeviceListView->itemAt(pos);          QTreeWidgetItem* pItem = m_ui.DeviceListView->itemAt(pos);
615          if (pItem == NULL)          if (pItem == NULL)
616                  return;                  return;
617    
         int iItemID;  
   
618          // Build the device context menu...          // Build the device context menu...
619          QMenu* pContextMenu = new QMenu(this);          QMenu menu(this);
620            QAction *pAction;
621    
622          bool bClient = (pMainForm->client() != NULL);          bool bClient = (pMainForm->client() != NULL);
623          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
624          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
625                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")),                  QIcon(":/images/deviceCreate.png"),
626                  tr("&Create device"), this, SLOT(createDevice()));                  tr("&Create device"), this, SLOT(createDevice()));
627          pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));          pAction->setEnabled(bEnabled || (bClient && m_bNewDevice));
628          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
629                  QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")),                  QIcon(":/images/deviceDelete.png"),
630                  tr("&Delete device"), this, SLOT(deleteDevice()));                  tr("&Delete device"), this, SLOT(deleteDevice()));
631          pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);          pAction->setEnabled(bEnabled && !m_bNewDevice);
632          pContextMenu->insertSeparator();          menu.addSeparator();
633          iItemID = pContextMenu->insertItem(          pAction = menu.addAction(
634                  QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")),                  QIcon(":/images/formRefresh.png"),
635                  tr("&Refresh"), this, SLOT(refreshDevices()));                  tr("&Refresh"), this, SLOT(refreshDevices()));
636          pContextMenu->setItemEnabled(iItemID, bClient);          pAction->setEnabled(bClient);
637    
638          pContextMenu->exec(pos);          menu.exec(pos);
   
         delete pContextMenu;  
639  }  }
640    
641    
# Line 610  void DeviceForm::deviceListViewContextMe Line 643  void DeviceForm::deviceListViewContextMe
643  void DeviceForm::stabilizeForm (void)  void DeviceForm::stabilizeForm (void)
644  {  {
645          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
646          QTreeWidgetItem* pItem = ui.DeviceListView->currentItem();          QTreeWidgetItem* pItem = m_ui.DeviceListView->currentItem();
647          bool bClient = (pMainForm && pMainForm->client() != NULL);          bool bClient = (pMainForm && pMainForm->client() != NULL);
648          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
649          ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
650          ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          m_ui.DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
651          ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          m_ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
652          ui.DeviceParamTable->setEnabled(bEnabled);          m_ui.DeviceParamTable->setEnabled(bEnabled);
653          ui.RefreshDevicesPushButton->setEnabled(bClient);          m_ui.RefreshDevicesPushButton->setEnabled(bClient);
654          ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));          m_ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
655          ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          m_ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
656  }  }
657    
658  void DeviceForm::updateCellRenderers() {  
659      const int rows = deviceParamModel.rowCount();  void DeviceForm::updateCellRenderers (void)
660      const int cols = deviceParamModel.columnCount();  {
661      updateCellRenderers(deviceParamModel.index(0,0),deviceParamModel.index(rows-1,cols-1));          const int rows = m_deviceParamModel.rowCount();
662  }          const int cols = m_deviceParamModel.columnCount();
663            updateCellRenderers(
664  void DeviceForm::updateCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {                  m_deviceParamModel.index(0, 0),
665      for (int r = topLeft.row(); r <= bottomRight.row(); r++) {                  m_deviceParamModel.index(rows - 1, cols - 1));
666          for (int c = topLeft.column(); c <= bottomRight.column(); c++) {  }
667              const QModelIndex index = deviceParamModel.index(r,c);  
668              ui.DeviceParamTable->openPersistentEditor(index);  
669          }  void DeviceForm::updateCellRenderers (
670      }          const QModelIndex& topLeft, const QModelIndex& bottomRight )
671  }  {
672            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
673  void DeviceForm::updatePortCellRenderers() {                  for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
674      const int rows = devicePortParamModel.rowCount();                          const QModelIndex index = m_deviceParamModel.index(r, c);
675      const int cols = devicePortParamModel.columnCount();                          m_ui.DeviceParamTable->openPersistentEditor(index);
676      updatePortCellRenderers(devicePortParamModel.index(0,0),devicePortParamModel.index(rows-1,cols-1));                  }
677  }          }
678    }
679  void DeviceForm::updatePortCellRenderers(const QModelIndex& topLeft, const QModelIndex& bottomRight) {  
680      for (int r = topLeft.row(); r <= bottomRight.row(); r++) {  
681          for (int c = topLeft.column(); c <= bottomRight.column(); c++) {  void DeviceForm::updatePortCellRenderers (void)
682              const QModelIndex index = devicePortParamModel.index(r,c);  {
683              ui.DevicePortParamTable->openPersistentEditor(index);          const int rows = m_devicePortParamModel.rowCount();
684          }          const int cols = m_devicePortParamModel.columnCount();
685      }          updatePortCellRenderers(
686                    m_devicePortParamModel.index(0, 0),
687                    m_devicePortParamModel.index(rows - 1, cols - 1));
688    }
689    
690    
691    void DeviceForm::updatePortCellRenderers (
692            const QModelIndex& topLeft, const QModelIndex& bottomRight )
693    {
694            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
695                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
696                            const QModelIndex index = m_devicePortParamModel.index(r, c);
697                            m_ui.DevicePortParamTable->openPersistentEditor(index);
698                    }
699            }
700  }  }
701    
702  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC