/[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 2074 by capela, Mon Mar 29 17:00:30 2010 UTC revision 3788 by capela, Thu Jun 11 16:59:09 2020 UTC
# Line 1  Line 1 
1  // qsamplerDevice.cpp  // qsamplerDevice.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 2008 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
# 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 654  void Device::appendMessages( const QStri Line 648  void Device::appendMessages( const QStri
648                  pMainForm->appendMessages(deviceName() + ' ' + s);                  pMainForm->appendMessages(deviceName() + ' ' + s);
649  }  }
650    
651  void Device::appendMessagesColor( const QString& s,  void Device::appendMessagesColor( const QString& s,     const QColor& rgb ) const
         const QString& c ) const  
652  {  {
653          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
654          if (pMainForm)          if (pMainForm)
655                  pMainForm->appendMessagesColor(deviceName() + ' ' + s, c);                  pMainForm->appendMessagesColor(deviceName() + ' ' + s, rgb);
656  }  }
657    
658  void Device::appendMessagesText( const QString& s ) const  void Device::appendMessagesText( const QString& s ) const
# Line 688  void Device::appendMessagesClient( const Line 681  void Device::appendMessagesClient( const
681  int *Device::getDevices ( lscp_client_t *pClient,  int *Device::getDevices ( lscp_client_t *pClient,
682          DeviceType deviceType )          DeviceType deviceType )
683  {  {
684          int *piDeviceIDs = NULL;          int *piDeviceIDs = nullptr;
685          switch (deviceType) {          switch (deviceType) {
686          case Device::Audio:          case Device::Audio:
687                  piDeviceIDs = ::lscp_list_audio_devices(pClient);                  piDeviceIDs = ::lscp_list_audio_devices(pClient);
# Line 720  QStringList Device::getDrivers ( lscp_cl Line 713  QStringList Device::getDrivers ( lscp_cl
713  {  {
714          QStringList drivers;          QStringList drivers;
715    
716          const char **ppszDrivers = NULL;          const char **ppszDrivers = nullptr;
717          switch (deviceType) {          switch (deviceType) {
718          case Device::Audio:          case Device::Audio:
719                  ppszDrivers = ::lscp_list_available_audio_drivers(pClient);                  ppszDrivers = ::lscp_list_available_audio_drivers(pClient);
# Line 760  DevicePort::~DevicePort (void) Line 753  DevicePort::~DevicePort (void)
753  void DevicePort::setDevicePort ( int iPortID )  void DevicePort::setDevicePort ( int iPortID )
754  {  {
755          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
756          if (pMainForm == NULL)          if (pMainForm == nullptr)
757                  return;                  return;
758          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
759                  return;                  return;
760    
761          // Device port id should be always set.          // Device port id should be always set.
# Line 772  void DevicePort::setDevicePort ( int iPo Line 765  void DevicePort::setDevicePort ( int iPo
765          m_params.clear();          m_params.clear();
766    
767          // Retrieve device port/channel info, if any.          // Retrieve device port/channel info, if any.
768          lscp_device_port_info_t *pPortInfo = NULL;          lscp_device_port_info_t *pPortInfo = nullptr;
769          switch (m_device.deviceType()) {          switch (m_device.deviceType()) {
770          case Device::Audio:          case Device::Audio:
771                  if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(),                  if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(),
772                                  m_device.deviceID(), m_iPortID)) == NULL)                                  m_device.deviceID(), m_iPortID)) == nullptr)
773                          m_device.appendMessagesClient("lscp_get_audio_channel_info");                          m_device.appendMessagesClient("lscp_get_audio_channel_info");
774                  break;                  break;
775          case Device::Midi:          case Device::Midi:
776                  if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(),                  if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(),
777                                  m_device.deviceID(), m_iPortID)) == NULL)                                  m_device.deviceID(), m_iPortID)) == nullptr)
778                          m_device.appendMessagesClient("lscp_get_midi_port_info");                          m_device.appendMessagesClient("lscp_get_midi_port_info");
779                  break;                  break;
780          case Device::None:          case Device::None:
# Line 789  void DevicePort::setDevicePort ( int iPo Line 782  void DevicePort::setDevicePort ( int iPo
782          }          }
783    
784          // If we're bogus, bail out...          // If we're bogus, bail out...
785          if (pPortInfo == NULL) {          if (pPortInfo == nullptr) {
786                  m_sPortName = QString::null;                  m_sPortName.clear();
787                  return;                  return;
788          }          }
789    
# Line 801  void DevicePort::setDevicePort ( int iPo Line 794  void DevicePort::setDevicePort ( int iPo
794          m_params.clear();          m_params.clear();
795          for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {          for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {
796                  const QString sParam = pPortInfo->params[i].key;                  const QString sParam = pPortInfo->params[i].key;
797                  lscp_param_info_t *pParamInfo = NULL;                  lscp_param_info_t *pParamInfo = nullptr;
798                  switch (m_device.deviceType()) {                  switch (m_device.deviceType()) {
799                  case Device::Audio:                  case Device::Audio:
800                          if ((pParamInfo = ::lscp_get_audio_channel_param_info(                          if ((pParamInfo = ::lscp_get_audio_channel_param_info(
801                                          pMainForm->client(), m_device.deviceID(),                                          pMainForm->client(), m_device.deviceID(),
802                                          m_iPortID, sParam.toUtf8().constData())) == NULL)                                          m_iPortID, sParam.toUtf8().constData())) == nullptr)
803                                  m_device.appendMessagesClient("lscp_get_audio_channel_param_info");                                  m_device.appendMessagesClient("lscp_get_audio_channel_param_info");
804                          break;                          break;
805                  case Device::Midi:                  case Device::Midi:
806                          if ((pParamInfo = ::lscp_get_midi_port_param_info(                          if ((pParamInfo = ::lscp_get_midi_port_param_info(
807                                          pMainForm->client(), m_device.deviceID(),                                          pMainForm->client(), m_device.deviceID(),
808                                          m_iPortID, sParam.toUtf8().constData())) == NULL)                                          m_iPortID, sParam.toUtf8().constData())) == nullptr)
809                                  m_device.appendMessagesClient("lscp_get_midi_port_param_info");                                  m_device.appendMessagesClient("lscp_get_midi_port_param_info");
810                          break;                          break;
811                  case Device::None:                  case Device::None:
# Line 849  bool DevicePort::setParam ( const QStrin Line 842  bool DevicePort::setParam ( const QStrin
842          const QString& sValue )          const QString& sValue )
843  {  {
844          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
845          if (pMainForm == NULL)          if (pMainForm == nullptr)
846                  return false;                  return false;
847          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
848                  return false;                  return false;
849    
850          // Set proper port/channel parameter.          // Set proper port/channel parameter.
# Line 970  Device& DeviceItem::device () Line 963  Device& DeviceItem::device ()
963  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )  AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )
964          : QAbstractTableModel(pParent), m_bEditable(false)          : QAbstractTableModel(pParent), m_bEditable(false)
965  {  {
966          m_pParams = NULL;          m_pParams = nullptr;
967  }  }
968    
969    
# Line 1018  void AbstractDeviceParamModel::refresh ( Line 1011  void AbstractDeviceParamModel::refresh (
1011          m_pParams   = pParams;          m_pParams   = pParams;
1012          m_bEditable = bEditable;          m_bEditable = bEditable;
1013          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1014    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1015          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1016    #else
1017            QAbstractTableModel::beginResetModel();
1018            QAbstractTableModel::endResetModel();
1019    #endif
1020  }  }
1021    
1022    
1023  void AbstractDeviceParamModel::clear (void)  void AbstractDeviceParamModel::clear (void)
1024  {  {
1025          m_pParams = NULL;          m_pParams = nullptr;
1026          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1027    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1028          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1029    #else
1030            QAbstractTableModel::beginResetModel();
1031            QAbstractTableModel::endResetModel();
1032    #endif
1033  }  }
1034    
1035    
# Line 1037  void AbstractDeviceParamModel::clear (vo Line 1040  void AbstractDeviceParamModel::clear (vo
1040  DeviceParamModel::DeviceParamModel ( QObject *pParent )  DeviceParamModel::DeviceParamModel ( QObject *pParent )
1041          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1042  {  {
1043          m_pDevice = NULL;          m_pDevice = nullptr;
1044  }  }
1045    
1046  QVariant DeviceParamModel::data (  QVariant DeviceParamModel::data (
# Line 1082  void DeviceParamModel::refresh ( Device* Line 1085  void DeviceParamModel::refresh ( Device*
1085  void DeviceParamModel::clear (void)  void DeviceParamModel::clear (void)
1086  {  {
1087          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1088          m_pDevice = NULL;          m_pDevice = nullptr;
1089  }  }
1090    
1091    
# Line 1093  void DeviceParamModel::clear (void) Line 1096  void DeviceParamModel::clear (void)
1096  PortParamModel::PortParamModel ( QObject *pParent)  PortParamModel::PortParamModel ( QObject *pParent)
1097          : AbstractDeviceParamModel(pParent)          : AbstractDeviceParamModel(pParent)
1098  {  {
1099          m_pPort = NULL;          m_pPort = nullptr;
1100  }  }
1101    
1102  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const  QVariant PortParamModel::data ( const QModelIndex &index, int role ) const
# Line 1137  void PortParamModel::refresh ( DevicePor Line 1140  void PortParamModel::refresh ( DevicePor
1140  void PortParamModel::clear (void)  void PortParamModel::clear (void)
1141  {  {
1142          AbstractDeviceParamModel::clear();          AbstractDeviceParamModel::clear();
1143          m_pPort = NULL;          m_pPort = nullptr;
1144  }  }
1145    
1146    
# Line 1155  QWidget* DeviceParamDelegate::createEdit Line 1158  QWidget* DeviceParamDelegate::createEdit
1158          const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const          const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const
1159  {  {
1160          if (!index.isValid())          if (!index.isValid())
1161                  return NULL;                  return nullptr;
1162    
1163          DeviceParameterRow r = index.model()->data(index,          DeviceParameterRow r = index.model()->data(index,
1164                  Qt::DisplayRole).value<DeviceParameterRow>();                  Qt::DisplayRole).value<DeviceParameterRow>();
1165    
1166          const bool bEnabled = (r.alive) ? !r.param.fix : true;          const bool bEnabled = (r.alive) ? !r.param.fix : true;
1167            const bool bFix = r.param.fix;
1168    
1169          QString val = (r.alive) ? r.param.value : r.param.defaultv;          QString val = (r.alive) ? r.param.value : r.param.defaultv;
1170    
# Line 1170  QWidget* DeviceParamDelegate::createEdit Line 1174  QWidget* DeviceParamDelegate::createEdit
1174                  case 1: {                  case 1: {
1175                          if (r.param.type == LSCP_TYPE_BOOL) {                          if (r.param.type == LSCP_TYPE_BOOL) {
1176                                  QCheckBox *pCheckBox = new QCheckBox(pParent);                                  QCheckBox *pCheckBox = new QCheckBox(pParent);
1177                                  if (val != QString::null)                                  if (!val.isEmpty())
1178                                          pCheckBox->setChecked(val.toLower() == "true");                                          pCheckBox->setChecked(val.toLower() == "true");
1179                                  pCheckBox->setEnabled(bEnabled);                                  pCheckBox->setEnabled(bEnabled);
1180                                    pCheckBox->setCheckable(!bFix);
1181                                  return pCheckBox;                                  return pCheckBox;
1182                          } else if (r.param.possibilities.count() > 0) {                          } else if (r.param.possibilities.count() > 0) {
1183                                  QStringList opts = r.param.possibilities;                                  QStringList opts = r.param.possibilities;
# Line 1185  QWidget* DeviceParamDelegate::createEdit Line 1190  QWidget* DeviceParamDelegate::createEdit
1190                                  else                                  else
1191                                          pComboBox->setCurrentIndex(pComboBox->findText(val));                                          pComboBox->setCurrentIndex(pComboBox->findText(val));
1192                                  pComboBox->setEnabled(bEnabled);                                  pComboBox->setEnabled(bEnabled);
1193                                    pComboBox->setEditable(!bFix);
1194                                  return pComboBox;                                  return pComboBox;
1195                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {                          } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
1196                                  QSpinBox *pSpinBox = new QSpinBox(pParent);                                  QSpinBox *pSpinBox = new QSpinBox(pParent);
# Line 1197  QWidget* DeviceParamDelegate::createEdit Line 1203  QWidget* DeviceParamDelegate::createEdit
1203                                                  r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ?                                                  r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ?
1204                                  );                                  );
1205                                  pSpinBox->setValue(val.toInt());                                  pSpinBox->setValue(val.toInt());
1206                                    pSpinBox->setReadOnly(bFix);
1207                                  return pSpinBox;                                  return pSpinBox;
1208                          } else if (bEnabled) {                          } else if (bEnabled) {
1209                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);                                  QLineEdit *pLineEdit = new QLineEdit(val, pParent);
1210                                    pLineEdit->setReadOnly(bFix);
1211                                  return pLineEdit;                                  return pLineEdit;
1212                          } else {                          } else {
1213                                  QLabel *pLabel = new QLabel(val, pParent);                                  QLabel *pLabel = new QLabel(val, pParent);
# Line 1209  QWidget* DeviceParamDelegate::createEdit Line 1217  QWidget* DeviceParamDelegate::createEdit
1217                  case 2:                  case 2:
1218                          return new QLabel(r.param.description, pParent);                          return new QLabel(r.param.description, pParent);
1219                  default:                  default:
1220                          return NULL;                          return nullptr;
1221          }          }
1222  }  }
1223    

Legend:
Removed from v.2074  
changed lines
  Added in v.3788

  ViewVC Help
Powered by ViewVC