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

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

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

revision 1559 by capela, Thu Dec 6 14:23:39 2007 UTC revision 3520 by capela, Mon Jul 1 10:53:41 2019 UTC
# Line 1  Line 1 
1  // qsamplerDevice.cpp  // qsamplerDevice.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 45  DeviceParam::DeviceParam ( lscp_param_in Line 45  DeviceParam::DeviceParam ( lscp_param_in
45  }  }
46    
47    
 // Default destructor.  
 DeviceParam::~DeviceParam (void)  
 {  
 }  
   
   
48  // Initializer.  // Initializer.
49  void DeviceParam::setParam ( lscp_param_info_t *pParamInfo,  void DeviceParam::setParam ( lscp_param_info_t *pParamInfo,
50          const char *pszValue )          const char *pszValue )
# Line 65  void DeviceParam::setParam ( lscp_param_ Line 59  void DeviceParam::setParam ( lscp_param_
59          if (pParamInfo->description)          if (pParamInfo->description)
60                  description = pParamInfo->description;                  description = pParamInfo->description;
61          else          else
62                  description = QString::null;                  description.clear();
63    
64          mandatory = (bool) pParamInfo->mandatory;          mandatory = bool(pParamInfo->mandatory);
65          fix = (bool) pParamInfo->fix;          fix = bool(pParamInfo->fix);
66          multiplicity = (bool) pParamInfo->multiplicity;          multiplicity = bool(pParamInfo->multiplicity);
67    
68          depends.clear();          depends.clear();
69          for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++)          for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++)
# Line 78  void DeviceParam::setParam ( lscp_param_ Line 72  void DeviceParam::setParam ( lscp_param_
72          if (pParamInfo->defaultv)          if (pParamInfo->defaultv)
73                  defaultv = pParamInfo->defaultv;                  defaultv = pParamInfo->defaultv;
74          else          else
75                  defaultv = QString::null;                  defaultv.clear();
76    
77          if (pParamInfo->range_min)          if (pParamInfo->range_min)
78                  range_min = pParamInfo->range_min;                  range_min = pParamInfo->range_min;
79          else          else
80                  range_min = QString::null;                  range_min.clear();
81    
82          if (pParamInfo->range_max)          if (pParamInfo->range_max)
83                  range_max = pParamInfo->range_max;                  range_max = pParamInfo->range_max;
84          else          else
85                  range_max = QString::null;                  range_max.clear();
86    
87          possibilities.clear();          possibilities.clear();
88          for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++)          for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++)
# Line 98  void DeviceParam::setParam ( lscp_param_ Line 92  void DeviceParam::setParam ( lscp_param_
92          if (pszValue)          if (pszValue)
93                  value = pszValue;                  value = pszValue;
94          else          else
95                  value = QString::null;                  value.clear();
96  }  }
97    
98    
# Line 167  void Device::setDevice ( DeviceType devi Line 161  void Device::setDevice ( DeviceType devi
161                          appendMessagesClient("lscp_get_midi_device_info");                          appendMessagesClient("lscp_get_midi_device_info");
162                  break;                  break;
163          case Device::None:          case Device::None:
164                  m_sDeviceType = QString::null;                  m_sDeviceType.clear();
165                  break;                  break;
166          }          }
167          // If we're bogus, bail out...          // If we're bogus, bail out...
168          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
169                  m_sDriverName = QString::null;                  m_sDriverName.clear();
170                  m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType);                  m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType);
171                  return;                  return;
172          }          }
# Line 336  bool Device::setParam ( const QString& s Line 330  bool Device::setParam ( const QString& s
330    
331          // If the device already exists, things get immediate...          // If the device already exists, things get immediate...
332          int iRefresh = 0;          int iRefresh = 0;
333          if (m_iDeviceID >= 0 && sValue != QString::null) {          if (m_iDeviceID >= 0 && !sValue.isEmpty()) {
334    
335                  // we need temporary byte arrrays with the final strings, because                  // we need temporary byte arrrays with the final strings, because
336                  // i.e. QString::toUtf8() only returns a temporary object and the                  // i.e. QString::toUtf8() only returns a temporary object and the
# Line 416  bool Device::createDevice (void) Line 410  bool Device::createDevice (void)
410    
411          DeviceParamMap::ConstIterator iter;          DeviceParamMap::ConstIterator iter;
412          for (iter = m_params.begin(); iter != m_params.end(); ++iter) {          for (iter = m_params.begin(); iter != m_params.end(); ++iter) {
413                  if (iter.value().value == QString::null) continue;                  if (iter.value().value.isEmpty()) continue;
414                  finalKeys.push_back(iter.key().toUtf8());                  finalKeys.push_back(iter.key().toUtf8());
415                  finalVals.push_back(iter.value().value.toUtf8());                  finalVals.push_back(iter.value().value.toUtf8());
416          }          }
# Line 451  bool Device::createDevice (void) Line 445  bool Device::createDevice (void)
445          }          }
446    
447          // Free used parameter array.          // Free used parameter array.
448          delete pParams;          delete[] pParams;
449    
450          // Show result.          // Show result.
451          if (m_iDeviceID >= 0) {          if (m_iDeviceID >= 0) {
# Line 639  int Device::refreshParam ( const QString Line 633  int Device::refreshParam ( const QString
633          }          }
634    
635          // Free used parameter array.          // Free used parameter array.
636          delete pDepends;          delete[] pDepends;
637    
638          // Return whether the parameters has been changed...          // Return whether the parameters has been changed...
639          return iRefresh;          return iRefresh;
# Line 702  int *Device::getDevices ( lscp_client_t Line 696  int *Device::getDevices ( lscp_client_t
696          return piDeviceIDs;          return piDeviceIDs;
697  }  }
698    
699    std::set<int> Device::getDeviceIDs(lscp_client_t *pClient,
700            DeviceType deviceType)
701    {
702            std::set<int> result;
703            int* piDeviceIDs = getDevices(pClient, deviceType);
704            if (!piDeviceIDs) return result;
705            for (int i = 0; piDeviceIDs[i] != -1; ++i)
706                    result.insert(piDeviceIDs[i]);
707            return result;
708    }
709    
710    
711  // Driver names enumerator.  // Driver names enumerator.
712  QStringList Device::getDrivers ( lscp_client_t *pClient,  QStringList Device::getDrivers ( lscp_client_t *pClient,
# Line 779  void DevicePort::setDevicePort ( int iPo Line 784  void DevicePort::setDevicePort ( int iPo
784    
785          // If we're bogus, bail out...          // If we're bogus, bail out...
786          if (pPortInfo == NULL) {          if (pPortInfo == NULL) {
787                  m_sPortName = QString::null;                  m_sPortName.clear();
788                  return;                  return;
789          }          }
790    
# Line 905  DeviceItem::DeviceItem ( QTreeWidget* pT Line 910  DeviceItem::DeviceItem ( QTreeWidget* pT
910  {  {
911          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
912          case Device::Audio:          case Device::Audio:
913                  setIcon(0, QPixmap(":/icons/audio1.png"));                  setIcon(0, QPixmap(":/images/audio1.png"));
914                  setText(0, QObject::tr("Audio Devices"));                  setText(0, QObject::tr("Audio Devices"));
915                  break;                  break;
916          case Device::Midi:          case Device::Midi:
917                  setIcon(0, QPixmap(":/icons/midi1.png"));                  setIcon(0, QPixmap(":/images/midi1.png"));
918                  setText(0, QObject::tr("MIDI Devices"));                  setText(0, QObject::tr("MIDI Devices"));
919                  break;                  break;
920          case Device::None:          case Device::None:
# Line 928  DeviceItem::DeviceItem ( QTreeWidgetItem Line 933  DeviceItem::DeviceItem ( QTreeWidgetItem
933  {  {
934          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
935          case Device::Audio:          case Device::Audio:
936                  setIcon(0, QPixmap(":/icons/audio2.png"));                  setIcon(0, QPixmap(":/images/audio2.png"));
937                  break;                  break;
938          case Device::Midi:          case Device::Midi:
939                  setIcon(0, QPixmap(":/icons/midi2.png"));                  setIcon(0, QPixmap(":/images/midi2.png"));
940                  break;                  break;
941          case Device::None:          case Device::None:
942                  break;                  break;
# Line 1007  void AbstractDeviceParamModel::refresh ( Line 1012  void AbstractDeviceParamModel::refresh (
1012          m_pParams   = pParams;          m_pParams   = pParams;
1013          m_bEditable = bEditable;          m_bEditable = bEditable;
1014          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1015    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1016          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1017    #else
1018            QAbstractTableModel::beginResetModel();
1019            QAbstractTableModel::endResetModel();
1020    #endif
1021  }  }
1022    
1023    
# Line 1015  void AbstractDeviceParamModel::clear (vo Line 1025  void AbstractDeviceParamModel::clear (vo
1025  {  {
1026          m_pParams = NULL;          m_pParams = NULL;
1027          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1028    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1029          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1030    #else
1031            QAbstractTableModel::beginResetModel();
1032            QAbstractTableModel::endResetModel();
1033    #endif
1034  }  }
1035    
1036    
# Line 1150  QWidget* DeviceParamDelegate::createEdit Line 1165  QWidget* DeviceParamDelegate::createEdit
1165                  Qt::DisplayRole).value<DeviceParameterRow>();                  Qt::DisplayRole).value<DeviceParameterRow>();
1166    
1167          const bool bEnabled = (r.alive) ? !r.param.fix : true;          const bool bEnabled = (r.alive) ? !r.param.fix : true;
1168            const bool bFix = r.param.fix;
1169    
1170          QString val = (r.alive) ? r.param.value : r.param.defaultv;          QString val = (r.alive) ? r.param.value : r.param.defaultv;
1171    
# Line 1159  QWidget* DeviceParamDelegate::createEdit Line 1175  QWidget* DeviceParamDelegate::createEdit
1175                  case 1: {                  case 1: {
1176                          if (r.param.type == LSCP_TYPE_BOOL) {                          if (r.param.type == LSCP_TYPE_BOOL) {
1177                                  QCheckBox *pCheckBox = new QCheckBox(pParent);                                  QCheckBox *pCheckBox = new QCheckBox(pParent);
1178                                  if (val != QString::null)                                  if (!val.isEmpty())
1179                                          pCheckBox->setChecked(val.toLower() == "true");                                          pCheckBox->setChecked(val.toLower() == "true");
1180                                  pCheckBox->setEnabled(bEnabled);                                  pCheckBox->setEnabled(bEnabled);
1181                                    pCheckBox->setCheckable(!bFix);
1182                                  return pCheckBox;                                  return pCheckBox;
1183                          } else if (r.param.possibilities.count() > 0) {                          } else if (r.param.possibilities.count() > 0) {
1184                                  QStringList opts = r.param.possibilities;                                  QStringList opts = r.param.possibilities;
# Line 1174  QWidget* DeviceParamDelegate::createEdit Line 1191  QWidget* DeviceParamDelegate::createEdit
1191                                  else                                  else
1192                                          pComboBox->setCurrentIndex(pComboBox->findText(val));                                          pComboBox->setCurrentIndex(pComboBox->findText(val));
1193                                  pComboBox->setEnabled(bEnabled);                                  pComboBox->setEnabled(bEnabled);
1194                                    pComboBox->setEditable(!bFix);
1195                                  return pComboBox;                                  return pComboBox;
1196                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
1197                                  QSpinBox *pSpinBox = new QSpinBox(pParent);                                  QSpinBox *pSpinBox = new QSpinBox(pParent);
# Line 1183  QWidget* DeviceParamDelegate::createEdit Line 1201  QWidget* DeviceParamDelegate::createEdit
1201                                  );                                  );
1202                                  pSpinBox->setMaximum(                                  pSpinBox->setMaximum(
1203                                          (!r.param.range_max.isEmpty()) ?                                          (!r.param.range_max.isEmpty()) ?
1204                                                  r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ?                                                  r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ?
1205                                  );                                  );
1206                                  pSpinBox->setValue(val.toInt());                                  pSpinBox->setValue(val.toInt());
1207                                    pSpinBox->setReadOnly(bFix);
1208                                  return pSpinBox;                                  return pSpinBox;
1209                          } else if (bEnabled) {                          } else if (bEnabled) {
1210                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);
1211                                    pLineEdit->setReadOnly(bFix);
1212                                  return pLineEdit;                                  return pLineEdit;
1213                          } else {                          } else {
1214                                  QLabel *pLabel = new QLabel(val, pParent);                                  QLabel *pLabel = new QLabel(val, pParent);

Legend:
Removed from v.1559  
changed lines
  Added in v.3520

  ViewVC Help
Powered by ViewVC