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

Legend:
Removed from v.1474  
changed lines
  Added in v.2387

  ViewVC Help
Powered by ViewVC