/[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 3555 by capela, Tue Aug 13 10:19:32 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 )
51  {  {
52          if (pParamInfo == NULL)          if (pParamInfo == nullptr)
53                  return;                  return;
54    
55          // Info structure field members.          // Info structure field members.
# 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 137  Device::Device ( const Device& device ) Line 131  Device::Device ( const Device& device )
131  void Device::setDevice ( DeviceType deviceType, int iDeviceID )  void Device::setDevice ( DeviceType deviceType, int iDeviceID )
132  {  {
133          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
134          if (pMainForm == NULL)          if (pMainForm == nullptr)
135                  return;                  return;
136          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
137                  return;                  return;
138    
139          // Device id and type should be always set.          // Device id and type should be always set.
# Line 152  void Device::setDevice ( DeviceType devi Line 146  void Device::setDevice ( DeviceType devi
146          m_ports.clear();          m_ports.clear();
147    
148          // Retrieve device info, if any.          // Retrieve device info, if any.
149          lscp_device_info_t *pDeviceInfo = NULL;          lscp_device_info_t *pDeviceInfo = nullptr;
150          switch (deviceType) {          switch (deviceType) {
151          case Device::Audio:          case Device::Audio:
152                  m_sDeviceType = QObject::tr("Audio");                  m_sDeviceType = QObject::tr("Audio");
153                  if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info(                  if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info(
154                                  pMainForm->client(), m_iDeviceID)) == NULL)                                  pMainForm->client(), m_iDeviceID)) == nullptr)
155                          appendMessagesClient("lscp_get_audio_device_info");                          appendMessagesClient("lscp_get_audio_device_info");
156                  break;                  break;
157          case Device::Midi:          case Device::Midi:
158                  m_sDeviceType = QObject::tr("MIDI");                  m_sDeviceType = QObject::tr("MIDI");
159                  if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info(                  if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info(
160                                  pMainForm->client(), m_iDeviceID)) == NULL)                                  pMainForm->client(), m_iDeviceID)) == nullptr)
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 == nullptr) {
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 185  void Device::setDevice ( DeviceType devi Line 179  void Device::setDevice ( DeviceType devi
179          // Grab device parameters...          // Grab device parameters...
180          for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) {          for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) {
181                  const QString sParam = pDeviceInfo->params[i].key;                  const QString sParam = pDeviceInfo->params[i].key;
182                  lscp_param_info_t *pParamInfo = NULL;                  lscp_param_info_t *pParamInfo = nullptr;
183                  switch (deviceType) {                  switch (deviceType) {
184                  case Device::Audio:                  case Device::Audio:
185                          if ((pParamInfo = ::lscp_get_audio_driver_param_info(                          if ((pParamInfo = ::lscp_get_audio_driver_param_info(
186                                          pMainForm->client(), m_sDriverName.toUtf8().constData(),                                          pMainForm->client(), m_sDriverName.toUtf8().constData(),
187                                          sParam.toUtf8().constData(), NULL)) == NULL)                                          sParam.toUtf8().constData(), nullptr)) == nullptr)
188                                  appendMessagesClient("lscp_get_audio_driver_param_info");                                  appendMessagesClient("lscp_get_audio_driver_param_info");
189                          break;                          break;
190                  case Device::Midi:                  case Device::Midi:
191                          if ((pParamInfo = ::lscp_get_midi_driver_param_info(                          if ((pParamInfo = ::lscp_get_midi_driver_param_info(
192                                          pMainForm->client(), m_sDriverName.toUtf8().constData(),                                          pMainForm->client(), m_sDriverName.toUtf8().constData(),
193                                          sParam.toUtf8().constData(), NULL)) == NULL)                                          sParam.toUtf8().constData(), nullptr)) == nullptr)
194                                  appendMessagesClient("lscp_get_midi_driver_param_info");                                  appendMessagesClient("lscp_get_midi_driver_param_info");
195                          break;                          break;
196                  case Device::None:                  case Device::None:
# Line 219  void Device::setDevice ( DeviceType devi Line 213  void Device::setDevice ( DeviceType devi
213  void Device::setDriver ( const QString& sDriverName )  void Device::setDriver ( const QString& sDriverName )
214  {  {
215          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
216          if (pMainForm == NULL)          if (pMainForm == nullptr)
217                  return;                  return;
218          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
219                  return;                  return;
220    
221          // Valid only for scratch devices.          // Valid only for scratch devices.
# Line 234  void Device::setDriver ( const QString& Line 228  void Device::setDriver ( const QString&
228          m_ports.clear();          m_ports.clear();
229    
230          // Retrieve driver info, if any.          // Retrieve driver info, if any.
231          lscp_driver_info_t *pDriverInfo = NULL;          lscp_driver_info_t *pDriverInfo = nullptr;
232          switch (m_deviceType) {          switch (m_deviceType) {
233          case Device::Audio:          case Device::Audio:
234                  if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(),                  if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(),
235                                  sDriverName.toUtf8().constData())) == NULL)                                  sDriverName.toUtf8().constData())) == nullptr)
236                          appendMessagesClient("lscp_get_audio_driver_info");                          appendMessagesClient("lscp_get_audio_driver_info");
237                  break;                  break;
238          case Device::Midi:          case Device::Midi:
239                  if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(),                  if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(),
240                                  sDriverName.toUtf8().constData())) == NULL)                                  sDriverName.toUtf8().constData())) == nullptr)
241                          appendMessagesClient("lscp_get_midi_driver_info");                          appendMessagesClient("lscp_get_midi_driver_info");
242                  break;                  break;
243          case Device::None:          case Device::None:
# Line 251  void Device::setDriver ( const QString& Line 245  void Device::setDriver ( const QString&
245          }          }
246    
247          // If we're bogus, bail out...          // If we're bogus, bail out...
248          if (pDriverInfo == NULL)          if (pDriverInfo == nullptr)
249                  return;                  return;
250    
251          // Remember device parameters...          // Remember device parameters...
# Line 260  void Device::setDriver ( const QString& Line 254  void Device::setDriver ( const QString&
254          // Grab driver parameters...          // Grab driver parameters...
255          for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) {          for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) {
256                  const QString sParam = pDriverInfo->parameters[i];                  const QString sParam = pDriverInfo->parameters[i];
257                  lscp_param_info_t *pParamInfo = NULL;                  lscp_param_info_t *pParamInfo = nullptr;
258                  switch (m_deviceType) {                  switch (m_deviceType) {
259                  case Device::Audio:                  case Device::Audio:
260                          if ((pParamInfo = ::lscp_get_audio_driver_param_info(                          if ((pParamInfo = ::lscp_get_audio_driver_param_info(
261                                          pMainForm->client(), sDriverName.toUtf8().constData(),                                          pMainForm->client(), sDriverName.toUtf8().constData(),
262                                          sParam.toUtf8().constData(), NULL)) == NULL)                                          sParam.toUtf8().constData(), nullptr)) == nullptr)
263                                  appendMessagesClient("lscp_get_audio_driver_param_info");                                  appendMessagesClient("lscp_get_audio_driver_param_info");
264                          break;                          break;
265                  case Device::Midi:                  case Device::Midi:
266                          if ((pParamInfo = ::lscp_get_midi_driver_param_info(                          if ((pParamInfo = ::lscp_get_midi_driver_param_info(
267                                          pMainForm->client(), sDriverName.toUtf8().constData(),                                          pMainForm->client(), sDriverName.toUtf8().constData(),
268                                          sParam.toUtf8().constData(), NULL)) == NULL)                                          sParam.toUtf8().constData(), nullptr)) == nullptr)
269                                  appendMessagesClient("lscp_get_midi_driver_param_info");                                  appendMessagesClient("lscp_get_midi_driver_param_info");
270                          break;                          break;
271                  case Device::None:                  case Device::None:
# Line 326  bool Device::setParam ( const QString& s Line 320  bool Device::setParam ( const QString& s
320          const QString& sValue )          const QString& sValue )
321  {  {
322          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
323          if (pMainForm == NULL)          if (pMainForm == nullptr)
324                  return false;                  return false;
325          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
326                  return false;                  return false;
327    
328          // Set proper device parameter.          // Set proper device parameter.
# 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 403  DevicePortList& Device::ports (void) Line 397  DevicePortList& Device::ports (void)
397  bool Device::createDevice (void)  bool Device::createDevice (void)
398  {  {
399          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
400          if (pMainForm == NULL)          if (pMainForm == nullptr)
401                  return false;                  return false;
402          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
403                  return false;                  return false;
404    
405          // we need temporary lists with the final strings, because i.e.          // we need temporary lists with the final strings, because i.e.
# 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 431  bool Device::createDevice (void) Line 425  bool Device::createDevice (void)
425                  pParams[iParam].value = (char *) finalVals[iParam].constData();                  pParams[iParam].value = (char *) finalVals[iParam].constData();
426          }          }
427          // Null terminated.          // Null terminated.
428          pParams[iParam].key   = NULL;          pParams[iParam].key   = nullptr;
429          pParams[iParam].value = NULL;          pParams[iParam].value = nullptr;
430    
431          // Now it depends on the device type...          // Now it depends on the device type...
432          switch (m_deviceType) {          switch (m_deviceType) {
# 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 471  bool Device::createDevice (void) Line 465  bool Device::createDevice (void)
465  bool Device::deleteDevice (void)  bool Device::deleteDevice (void)
466  {  {
467          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
468          if (pMainForm == NULL)          if (pMainForm == nullptr)
469                  return false;                  return false;
470          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
471                  return false;                  return false;
472    
473          // Now it depends on the device type...          // Now it depends on the device type...
# Line 573  int Device::refreshDepends ( const QStri Line 567  int Device::refreshDepends ( const QStri
567  int Device::refreshParam ( const QString& sParam )  int Device::refreshParam ( const QString& sParam )
568  {  {
569          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
570          if (pMainForm == NULL)          if (pMainForm == nullptr)
571                  return 0;                  return 0;
572          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
573                  return 0;                  return 0;
574    
575          // Check if we have dependencies...          // Check if we have dependencies...
# Line 606  int Device::refreshParam ( const QString Line 600  int Device::refreshParam ( const QString
600                  ++iDepend;                  ++iDepend;
601          }          }
602          // Null terminated.          // Null terminated.
603          pDepends[iDepend].key   = NULL;          pDepends[iDepend].key   = nullptr;
604          pDepends[iDepend].value = NULL;          pDepends[iDepend].value = nullptr;
605    
606          // FIXME: Some parameter dependencies (e.g.ALSA CARD)          // FIXME: Some parameter dependencies (e.g.ALSA CARD)
607          // are blocking for no reason, causing potential timeout-crashes.          // are blocking for no reason, causing potential timeout-crashes.
# Line 615  int Device::refreshParam ( const QString Line 609  int Device::refreshParam ( const QString
609          // carried out for scratch devices...          // carried out for scratch devices...
610    
611          // Retrieve some modern parameters...          // Retrieve some modern parameters...
612          lscp_param_info_t *pParamInfo = NULL;          lscp_param_info_t *pParamInfo = nullptr;
613          switch (m_deviceType) {          switch (m_deviceType) {
614          case Device::Audio:          case Device::Audio:
615                  if ((pParamInfo = ::lscp_get_audio_driver_param_info(                  if ((pParamInfo = ::lscp_get_audio_driver_param_info(
616                                  pMainForm->client(), m_sDriverName.toUtf8().constData(),                                  pMainForm->client(), m_sDriverName.toUtf8().constData(),
617                                  sParam.toUtf8().constData(), pDepends)) == NULL)                                  sParam.toUtf8().constData(), pDepends)) == nullptr)
618                          appendMessagesClient("lscp_get_audio_driver_param_info");                          appendMessagesClient("lscp_get_audio_driver_param_info");
619                  break;                  break;
620          case Device::Midi:          case Device::Midi:
621                  if ((pParamInfo = ::lscp_get_midi_driver_param_info(                  if ((pParamInfo = ::lscp_get_midi_driver_param_info(
622                                  pMainForm->client(), m_sDriverName.toUtf8().constData(),                                  pMainForm->client(), m_sDriverName.toUtf8().constData(),
623                                  sParam.toUtf8().constData(), pDepends)) == NULL)                                  sParam.toUtf8().constData(), pDepends)) == nullptr)
624                          appendMessagesClient("lscp_get_midi_driver_param_info");                          appendMessagesClient("lscp_get_midi_driver_param_info");
625                  break;                  break;
626          case Device::None:          case Device::None:
# Line 634  int Device::refreshParam ( const QString Line 628  int Device::refreshParam ( const QString
628          }          }
629          if (pParamInfo) {          if (pParamInfo) {
630                  param = DeviceParam(pParamInfo,                  param = DeviceParam(pParamInfo,
631                          param.value.isEmpty() ? NULL : param.value.toUtf8().constData());                          param.value.isEmpty() ? nullptr : param.value.toUtf8().constData());
632                  iRefresh++;                  iRefresh++;
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 688  void Device::appendMessagesClient( const Line 682  void Device::appendMessagesClient( const
682  int *Device::getDevices ( lscp_client_t *pClient,  int *Device::getDevices ( lscp_client_t *pClient,
683          DeviceType deviceType )          DeviceType deviceType )
684  {  {
685          int *piDeviceIDs = NULL;          int *piDeviceIDs = nullptr;
686          switch (deviceType) {          switch (deviceType) {
687          case Device::Audio:          case Device::Audio:
688                  piDeviceIDs = ::lscp_list_audio_devices(pClient);                  piDeviceIDs = ::lscp_list_audio_devices(pClient);
# 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 709  QStringList Device::getDrivers ( lscp_cl Line 714  QStringList Device::getDrivers ( lscp_cl
714  {  {
715          QStringList drivers;          QStringList drivers;
716    
717          const char **ppszDrivers = NULL;          const char **ppszDrivers = nullptr;
718          switch (deviceType) {          switch (deviceType) {
719          case Device::Audio:          case Device::Audio:
720                  ppszDrivers = ::lscp_list_available_audio_drivers(pClient);                  ppszDrivers = ::lscp_list_available_audio_drivers(pClient);
# Line 749  DevicePort::~DevicePort (void) Line 754  DevicePort::~DevicePort (void)
754  void DevicePort::setDevicePort ( int iPortID )  void DevicePort::setDevicePort ( int iPortID )
755  {  {
756          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
757          if (pMainForm == NULL)          if (pMainForm == nullptr)
758                  return;                  return;
759          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
760                  return;                  return;
761    
762          // Device port id should be always set.          // Device port id should be always set.
# Line 761  void DevicePort::setDevicePort ( int iPo Line 766  void DevicePort::setDevicePort ( int iPo
766          m_params.clear();          m_params.clear();
767    
768          // Retrieve device port/channel info, if any.          // Retrieve device port/channel info, if any.
769          lscp_device_port_info_t *pPortInfo = NULL;          lscp_device_port_info_t *pPortInfo = nullptr;
770          switch (m_device.deviceType()) {          switch (m_device.deviceType()) {
771          case Device::Audio:          case Device::Audio:
772                  if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(),                  if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(),
773                                  m_device.deviceID(), m_iPortID)) == NULL)                                  m_device.deviceID(), m_iPortID)) == nullptr)
774                          m_device.appendMessagesClient("lscp_get_audio_channel_info");                          m_device.appendMessagesClient("lscp_get_audio_channel_info");
775                  break;                  break;
776          case Device::Midi:          case Device::Midi:
777                  if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(),                  if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(),
778                                  m_device.deviceID(), m_iPortID)) == NULL)                                  m_device.deviceID(), m_iPortID)) == nullptr)
779                          m_device.appendMessagesClient("lscp_get_midi_port_info");                          m_device.appendMessagesClient("lscp_get_midi_port_info");
780                  break;                  break;
781          case Device::None:          case Device::None:
# Line 778  void DevicePort::setDevicePort ( int iPo Line 783  void DevicePort::setDevicePort ( int iPo
783          }          }
784    
785          // If we're bogus, bail out...          // If we're bogus, bail out...
786          if (pPortInfo == NULL) {          if (pPortInfo == nullptr) {
787                  m_sPortName = QString::null;                  m_sPortName.clear();
788                  return;                  return;
789          }          }
790    
# Line 790  void DevicePort::setDevicePort ( int iPo Line 795  void DevicePort::setDevicePort ( int iPo
795          m_params.clear();          m_params.clear();
796          for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {          for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {
797                  const QString sParam = pPortInfo->params[i].key;                  const QString sParam = pPortInfo->params[i].key;
798                  lscp_param_info_t *pParamInfo = NULL;                  lscp_param_info_t *pParamInfo = nullptr;
799                  switch (m_device.deviceType()) {                  switch (m_device.deviceType()) {
800                  case Device::Audio:                  case Device::Audio:
801                          if ((pParamInfo = ::lscp_get_audio_channel_param_info(                          if ((pParamInfo = ::lscp_get_audio_channel_param_info(
802                                          pMainForm->client(), m_device.deviceID(),                                          pMainForm->client(), m_device.deviceID(),
803                                          m_iPortID, sParam.toUtf8().constData())) == NULL)                                          m_iPortID, sParam.toUtf8().constData())) == nullptr)
804                                  m_device.appendMessagesClient("lscp_get_audio_channel_param_info");                                  m_device.appendMessagesClient("lscp_get_audio_channel_param_info");
805                          break;                          break;
806                  case Device::Midi:                  case Device::Midi:
807                          if ((pParamInfo = ::lscp_get_midi_port_param_info(                          if ((pParamInfo = ::lscp_get_midi_port_param_info(
808                                          pMainForm->client(), m_device.deviceID(),                                          pMainForm->client(), m_device.deviceID(),
809                                          m_iPortID, sParam.toUtf8().constData())) == NULL)                                          m_iPortID, sParam.toUtf8().constData())) == nullptr)
810                                  m_device.appendMessagesClient("lscp_get_midi_port_param_info");                                  m_device.appendMessagesClient("lscp_get_midi_port_param_info");
811                          break;                          break;
812                  case Device::None:                  case Device::None:
# Line 838  bool DevicePort::setParam ( const QStrin Line 843  bool DevicePort::setParam ( const QStrin
843          const QString& sValue )          const QString& sValue )
844  {  {
845          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
846          if (pMainForm == NULL)          if (pMainForm == nullptr)
847                  return false;                  return false;
848          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
849                  return false;                  return false;
850    
851          // Set proper port/channel parameter.          // Set proper port/channel parameter.
# 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 959  Device& DeviceItem::device () Line 964  Device& DeviceItem::device ()
964  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )
965          : QAbstractTableModel(pParent), m_bEditable(false)          : QAbstractTableModel(pParent), m_bEditable(false)
966  {  {
967          m_pParams = NULL;          m_pParams = nullptr;
968  }  }
969    
970    
# 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    
1024  void AbstractDeviceParamModel::clear (void)  void AbstractDeviceParamModel::clear (void)
1025  {  {
1026          m_pParams = NULL;          m_pParams = nullptr;
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 1026  void AbstractDeviceParamModel::clear (vo Line 1041  void AbstractDeviceParamModel::clear (vo
1041  DeviceParamModel::DeviceParamModel ( QObject *pParent )  DeviceParamModel::DeviceParamModel ( QObject *pParent )
1042          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1043  {  {
1044          m_pDevice = NULL;          m_pDevice = nullptr;
1045  }  }
1046    
1047  QVariant DeviceParamModel::data (  QVariant DeviceParamModel::data (
# Line 1071  void DeviceParamModel::refresh ( Device* Line 1086  void DeviceParamModel::refresh ( Device*
1086  void DeviceParamModel::clear (void)  void DeviceParamModel::clear (void)
1087  {  {
1088          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1089          m_pDevice = NULL;          m_pDevice = nullptr;
1090  }  }
1091    
1092    
# Line 1082  void DeviceParamModel::clear (void) Line 1097  void DeviceParamModel::clear (void)
1097  PortParamModel::PortParamModel ( QObject *pParent)  PortParamModel::PortParamModel ( QObject *pParent)
1098          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1099  {  {
1100          m_pPort = NULL;          m_pPort = nullptr;
1101  }  }
1102    
1103  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const
# Line 1126  void PortParamModel::refresh ( DevicePor Line 1141  void PortParamModel::refresh ( DevicePor
1141  void PortParamModel::clear (void)  void PortParamModel::clear (void)
1142  {  {
1143          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1144          m_pPort = NULL;          m_pPort = nullptr;
1145  }  }
1146    
1147    
# Line 1144  QWidget* DeviceParamDelegate::createEdit Line 1159  QWidget* DeviceParamDelegate::createEdit
1159          const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const          const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const
1160  {  {
1161          if (!index.isValid())          if (!index.isValid())
1162                  return NULL;                  return nullptr;
1163    
1164          DeviceParameterRow r = index.model()->data(index,          DeviceParameterRow r = index.model()->data(index,
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);
# Line 1198  QWidget* DeviceParamDelegate::createEdit Line 1218  QWidget* DeviceParamDelegate::createEdit
1218                  case 2:                  case 2:
1219                          return new QLabel(r.param.description, pParent);                          return new QLabel(r.param.description, pParent);
1220                  default:                  default:
1221                          return NULL;                          return nullptr;
1222          }          }
1223  }  }
1224    

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

  ViewVC Help
Powered by ViewVC