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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3402 - (hide annotations) (download)
Wed Jan 3 13:01:00 2018 UTC (6 years, 2 months ago) by schoenebeck
File size: 33976 byte(s)
* Fixed device management dialog not responding to user changes.

1 capela 426 // qsamplerDevice.cpp
2     //
3     /****************************************************************************
4 capela 2387 Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1698 Copyright (C) 2007, 2008 Christian Schoenebeck
6 capela 426
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17 capela 920 You should have received a copy of the GNU General Public License along
18     with this program; if not, write to the Free Software Foundation, Inc.,
19     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 capela 426
21     *****************************************************************************/
22    
23 capela 759 #include "qsamplerAbout.h"
24 capela 426 #include "qsamplerDevice.h"
25    
26     #include "qsamplerMainForm.h"
27     #include "qsamplerDeviceForm.h"
28    
29 capela 1499 #include <QCheckBox>
30     #include <QSpinBox>
31     #include <QLineEdit>
32 capela 426
33 capela 1499
34 capela 1558 namespace QSampler {
35 capela 426
36     //-------------------------------------------------------------------------
37 capela 1558 // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
38 capela 426 //
39    
40 capela 429 // Constructors.
41 capela 1558 DeviceParam::DeviceParam ( lscp_param_info_t *pParamInfo,
42 capela 429 const char *pszValue )
43     {
44     setParam(pParamInfo, pszValue);
45     }
46    
47    
48     // Default destructor.
49 capela 1558 DeviceParam::~DeviceParam (void)
50 capela 429 {
51     }
52    
53    
54     // Initializer.
55 capela 1558 void DeviceParam::setParam ( lscp_param_info_t *pParamInfo,
56 capela 429 const char *pszValue )
57     {
58     if (pParamInfo == NULL)
59 capela 431 return;
60 capela 490
61 capela 431 // Info structure field members.
62 capela 490
63 capela 429 type = pParamInfo->type;
64 capela 490
65 capela 429 if (pParamInfo->description)
66     description = pParamInfo->description;
67     else
68     description = QString::null;
69 capela 490
70 capela 482 mandatory = (bool) pParamInfo->mandatory;
71 capela 431 fix = (bool) pParamInfo->fix;
72     multiplicity = (bool) pParamInfo->multiplicity;
73 capela 490
74 capela 431 depends.clear();
75     for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++)
76     depends.append(pParamInfo->depends[i]);
77 capela 490
78 capela 429 if (pParamInfo->defaultv)
79     defaultv = pParamInfo->defaultv;
80     else
81     defaultv = QString::null;
82 capela 490
83 capela 429 if (pParamInfo->range_min)
84 capela 431 range_min = pParamInfo->range_min;
85 capela 429 else
86     range_min = QString::null;
87 capela 490
88 capela 429 if (pParamInfo->range_max)
89 capela 431 range_max = pParamInfo->range_max;
90 capela 429 else
91     range_max = QString::null;
92 capela 490
93 capela 429 possibilities.clear();
94 capela 431 for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++)
95     possibilities.append(pParamInfo->possibilities[i]);
96 capela 490
97 capela 431 // The current parameter value.
98 capela 429 if (pszValue)
99 capela 431 value = pszValue;
100 capela 429 else
101     value = QString::null;
102     }
103    
104    
105     //-------------------------------------------------------------------------
106 capela 1558 // QSampler::Device - MIDI/Audio Device structure.
107 capela 429 //
108    
109 capela 426 // Constructor.
110 capela 1558 Device::Device ( DeviceType deviceType, int iDeviceID )
111 capela 429 {
112 capela 1499 // m_ports.setAutoDelete(true);
113 capela 490
114 capela 484 setDevice(deviceType, iDeviceID);
115 capela 429 }
116    
117     // Default destructor.
118 capela 1558 Device::~Device (void)
119 capela 429 {
120 capela 1499 qDeleteAll(m_ports);
121     m_ports.clear();
122 capela 429 }
123    
124 capela 484 // Copy constructor.
125 capela 1558 Device::Device ( const Device& device )
126 capela 1499 : m_params(device.m_params), m_ports(device.m_ports)
127 capela 484 {
128     m_iDeviceID = device.m_iDeviceID;
129     m_deviceType = device.m_deviceType;
130     m_sDeviceType = device.m_sDeviceType;
131     m_sDriverName = device.m_sDriverName;
132     m_sDeviceName = device.m_sDeviceName;
133     }
134 capela 429
135 capela 484
136 capela 429 // Initializer.
137 capela 1558 void Device::setDevice ( DeviceType deviceType, int iDeviceID )
138 capela 429 {
139 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
140 capela 961 if (pMainForm == NULL)
141     return;
142     if (pMainForm->client() == NULL)
143     return;
144    
145 capela 430 // Device id and type should be always set.
146 capela 462 m_iDeviceID = iDeviceID;
147     m_deviceType = deviceType;
148 capela 490
149 capela 463 // Reset device parameters and ports anyway.
150 capela 467 m_params.clear();
151 capela 1499 qDeleteAll(m_ports);
152 capela 467 m_ports.clear();
153 capela 430
154     // Retrieve device info, if any.
155 capela 429 lscp_device_info_t *pDeviceInfo = NULL;
156     switch (deviceType) {
157 capela 1558 case Device::Audio:
158 capela 433 m_sDeviceType = QObject::tr("Audio");
159 capela 484 if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info(
160 capela 961 pMainForm->client(), m_iDeviceID)) == NULL)
161 capela 484 appendMessagesClient("lscp_get_audio_device_info");
162 capela 431 break;
163 capela 1558 case Device::Midi:
164 capela 433 m_sDeviceType = QObject::tr("MIDI");
165 capela 484 if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info(
166 capela 961 pMainForm->client(), m_iDeviceID)) == NULL)
167 capela 484 appendMessagesClient("lscp_get_midi_device_info");
168 capela 429 break;
169 capela 1558 case Device::None:
170 capela 433 m_sDeviceType = QString::null;
171     break;
172 capela 429 }
173 capela 430 // If we're bogus, bail out...
174     if (pDeviceInfo == NULL) {
175     m_sDriverName = QString::null;
176 capela 452 m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType);
177 capela 431 return;
178 capela 430 }
179 capela 431
180 capela 430 // Other device properties...
181 capela 429 m_sDriverName = pDeviceInfo->driver;
182 capela 430 m_sDeviceName = m_sDriverName + ' '
183     + QObject::tr("Device %1").arg(m_iDeviceID);
184 capela 429
185 capela 431 // Grab device parameters...
186 capela 429 for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) {
187 capela 463 const QString sParam = pDeviceInfo->params[i].key;
188 capela 429 lscp_param_info_t *pParamInfo = NULL;
189     switch (deviceType) {
190 capela 1558 case Device::Audio:
191 capela 1499 if ((pParamInfo = ::lscp_get_audio_driver_param_info(
192     pMainForm->client(), m_sDriverName.toUtf8().constData(),
193     sParam.toUtf8().constData(), NULL)) == NULL)
194 capela 484 appendMessagesClient("lscp_get_audio_driver_param_info");
195 capela 431 break;
196 capela 1558 case Device::Midi:
197 capela 1499 if ((pParamInfo = ::lscp_get_midi_driver_param_info(
198     pMainForm->client(), m_sDriverName.toUtf8().constData(),
199     sParam.toUtf8().constData(), NULL)) == NULL)
200 capela 484 appendMessagesClient("lscp_get_midi_driver_param_info");
201 capela 429 break;
202 capela 1558 case Device::None:
203 capela 436 break;
204 capela 429 }
205 capela 436 if (pParamInfo) {
206 capela 1558 m_params[sParam.toUpper()] = DeviceParam(pParamInfo,
207 capela 433 pDeviceInfo->params[i].value);
208 capela 436 }
209 capela 429 }
210 capela 463
211 capela 467 // Refresh parameter dependencies...
212 capela 484 refreshParams();
213 capela 467 // Set port/channel list...
214 capela 484 refreshPorts();
215 capela 429 }
216    
217    
218 capela 462 // Driver name initializer/settler.
219 capela 1558 void Device::setDriver ( const QString& sDriverName )
220 capela 431 {
221 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
222 capela 961 if (pMainForm == NULL)
223     return;
224     if (pMainForm->client() == NULL)
225     return;
226    
227 capela 431 // Valid only for scratch devices.
228     if (m_sDriverName == sDriverName)
229     return;
230    
231 capela 463 // Reset device parameters and ports anyway.
232 capela 467 m_params.clear();
233 capela 1499 qDeleteAll(m_ports);
234 capela 467 m_ports.clear();
235 capela 463
236 capela 431 // Retrieve driver info, if any.
237     lscp_driver_info_t *pDriverInfo = NULL;
238     switch (m_deviceType) {
239 capela 1558 case Device::Audio:
240 capela 961 if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(),
241 capela 1499 sDriverName.toUtf8().constData())) == NULL)
242 capela 484 appendMessagesClient("lscp_get_audio_driver_info");
243 capela 431 break;
244 capela 1558 case Device::Midi:
245 capela 961 if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(),
246 capela 1499 sDriverName.toUtf8().constData())) == NULL)
247 capela 484 appendMessagesClient("lscp_get_midi_driver_info");
248 capela 431 break;
249 capela 1558 case Device::None:
250 capela 436 break;
251 capela 431 }
252    
253     // If we're bogus, bail out...
254     if (pDriverInfo == NULL)
255     return;
256    
257     // Remember device parameters...
258     m_sDriverName = sDriverName;
259    
260     // Grab driver parameters...
261     for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) {
262 capela 463 const QString sParam = pDriverInfo->parameters[i];
263 capela 431 lscp_param_info_t *pParamInfo = NULL;
264     switch (m_deviceType) {
265 capela 1558 case Device::Audio:
266 capela 1499 if ((pParamInfo = ::lscp_get_audio_driver_param_info(
267     pMainForm->client(), sDriverName.toUtf8().constData(),
268     sParam.toUtf8().constData(), NULL)) == NULL)
269 capela 484 appendMessagesClient("lscp_get_audio_driver_param_info");
270 capela 431 break;
271 capela 1558 case Device::Midi:
272 capela 1499 if ((pParamInfo = ::lscp_get_midi_driver_param_info(
273     pMainForm->client(), sDriverName.toUtf8().constData(),
274     sParam.toUtf8().constData(), NULL)) == NULL)
275 capela 484 appendMessagesClient("lscp_get_midi_driver_param_info");
276 capela 431 break;
277 capela 1558 case Device::None:
278 capela 436 break;
279 capela 431 }
280 capela 463 if (pParamInfo) {
281 capela 1558 m_params[sParam.toUpper()] = DeviceParam(pParamInfo,
282 capela 463 pParamInfo->defaultv);
283     }
284 capela 431 }
285 capela 467
286     // Refresh parameter dependencies...
287 capela 484 refreshParams();
288 capela 467 // Set port/channel list...
289 capela 484 refreshPorts();
290 capela 431 }
291    
292    
293 capela 429 // Device property accessors.
294 capela 1558 int Device::deviceID (void) const
295 capela 429 {
296     return m_iDeviceID;
297     }
298    
299 capela 1558 Device::DeviceType Device::deviceType (void) const
300 capela 429 {
301     return m_deviceType;
302     }
303    
304 capela 1558 const QString& Device::deviceTypeName (void) const
305 capela 433 {
306     return m_sDeviceType;
307     }
308    
309 capela 1558 const QString& Device::driverName (void) const
310 capela 429 {
311     return m_sDriverName;
312     }
313    
314 capela 484 // Special device name formatter.
315 capela 1558 QString Device::deviceName (void) const
316 capela 429 {
317 capela 484 QString sPrefix;
318     if (m_iDeviceID >= 0)
319 capela 1509 sPrefix += m_sDeviceType + ' ';
320 capela 484 return sPrefix + m_sDeviceName;
321 capela 429 }
322    
323 capela 463
324     // Set the proper device parameter value.
325 capela 1558 bool Device::setParam ( const QString& sParam,
326 capela 463 const QString& sValue )
327     {
328 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
329 capela 961 if (pMainForm == NULL)
330     return false;
331     if (pMainForm->client() == NULL)
332     return false;
333    
334 capela 484 // Set proper device parameter.
335 capela 1499 m_params[sParam.toUpper()].value = sValue;
336 capela 490
337 capela 484 // If the device already exists, things get immediate...
338     int iRefresh = 0;
339 schoenebeck 1486 if (m_iDeviceID >= 0 && sValue != QString::null) {
340 schoenebeck 1508
341     // we need temporary byte arrrays with the final strings, because
342     // i.e. QString::toUtf8() only returns a temporary object and the
343     // C-style char* pointers for liblscp would immediately be invalidated
344     QByteArray finalParamKey = sParam.toUtf8();
345     QByteArray finalParamVal = sValue.toUtf8();
346    
347 capela 484 // Prepare parameter struct.
348     lscp_param_t param;
349 schoenebeck 1508 param.key = (char *) finalParamKey.constData();
350     param.value = (char *) finalParamVal.constData();
351 capela 484 // Now it depends on the device type...
352     lscp_status_t ret = LSCP_FAILED;
353     switch (m_deviceType) {
354 capela 1558 case Device::Audio:
355 capela 1509 if (sParam == "CHANNELS") iRefresh++;
356 capela 961 if ((ret = ::lscp_set_audio_device_param(pMainForm->client(),
357 capela 484 m_iDeviceID, &param)) != LSCP_OK)
358     appendMessagesClient("lscp_set_audio_device_param");
359     break;
360 capela 1558 case Device::Midi:
361 capela 1509 if (sParam == "PORTS") iRefresh++;
362 capela 961 if ((ret = ::lscp_set_midi_device_param(pMainForm->client(),
363 capela 484 m_iDeviceID, &param)) != LSCP_OK)
364     appendMessagesClient("lscp_set_midi_device_param");
365     break;
366 capela 1558 case Device::None:
367 capela 484 break;
368     }
369     // Show result.
370     if (ret == LSCP_OK) {
371     appendMessages(QString("%1: %2.").arg(sParam).arg(sValue));
372     // Special care for specific parameter changes...
373     if (iRefresh > 0)
374     iRefresh += refreshPorts();
375     iRefresh += refreshDepends(sParam);
376     } else {
377     // Oops...
378     appendMessagesError(
379     QObject::tr("Could not set device parameter value.\n\nSorry."));
380     }
381     }
382 capela 490
383 capela 484 // Return whether we're need a view refresh.
384     return (iRefresh > 0);
385 capela 463 }
386    
387    
388 capela 429 // Device parameter accessor.
389 capela 1558 const DeviceParamMap& Device::params (void) const
390 capela 429 {
391     return m_params;
392     }
393    
394    
395 capela 463 // Device port/channel list accessor.
396 capela 1558 DevicePortList& Device::ports (void)
397 capela 429 {
398 capela 463 return m_ports;
399 capela 429 }
400    
401 capela 462
402 capela 484 // Create a new device, as a copy of this current one.
403 capela 1558 bool Device::createDevice (void)
404 capela 484 {
405 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
406 capela 961 if (pMainForm == NULL)
407 capela 484 return false;
408 capela 961 if (pMainForm->client() == NULL)
409     return false;
410 capela 484
411 schoenebeck 1508 // we need temporary lists with the final strings, because i.e.
412     // QString::toUtf8() only returns a temporary object and the
413     // C-style char* pointers for liblscp would immediately be invalidated
414     QList<QByteArray> finalKeys;
415     QList<QByteArray> finalVals;
416    
417 capela 1558 DeviceParamMap::ConstIterator iter;
418 capela 484 for (iter = m_params.begin(); iter != m_params.end(); ++iter) {
419 capela 1499 if (iter.value().value == QString::null) continue;
420 schoenebeck 1508 finalKeys.push_back(iter.key().toUtf8());
421     finalVals.push_back(iter.value().value.toUtf8());
422 capela 484 }
423 schoenebeck 1508
424     // yeah, we DO HAVE to do the two loops separately !
425    
426     // Build the parameter list...
427     lscp_param_t *pParams = new lscp_param_t [finalKeys.count() + 1];
428     int iParam;
429     for (iParam = 0; iParam < finalKeys.count(); iParam++) {
430     pParams[iParam].key = (char *) finalKeys[iParam].constData();
431     pParams[iParam].value = (char *) finalVals[iParam].constData();
432     }
433 capela 484 // Null terminated.
434     pParams[iParam].key = NULL;
435     pParams[iParam].value = NULL;
436    
437     // Now it depends on the device type...
438     switch (m_deviceType) {
439 capela 1558 case Device::Audio:
440 capela 961 if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(),
441 capela 1499 m_sDriverName.toUtf8().constData(), pParams)) < 0)
442 capela 484 appendMessagesClient("lscp_create_audio_device");
443     break;
444 capela 1558 case Device::Midi:
445 capela 961 if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(),
446 capela 1499 m_sDriverName.toUtf8().constData(), pParams)) < 0)
447 capela 484 appendMessagesClient("lscp_create_midi_device");
448     break;
449 capela 1558 case Device::None:
450 capela 484 break;
451     }
452    
453     // Free used parameter array.
454     delete pParams;
455    
456     // Show result.
457     if (m_iDeviceID >= 0) {
458 capela 490 // Refresh our own stuff...
459     setDevice(m_deviceType, m_iDeviceID);
460 capela 484 appendMessages(QObject::tr("created."));
461     } else {
462     appendMessagesError(QObject::tr("Could not create device.\n\nSorry."));
463     }
464 capela 490
465 capela 484 // Return whether we're a valid device...
466     return (m_iDeviceID >= 0);
467     }
468    
469    
470     // Destroy existing device.
471 capela 1558 bool Device::deleteDevice (void)
472 capela 484 {
473 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
474 capela 961 if (pMainForm == NULL)
475     return false;
476     if (pMainForm->client() == NULL)
477     return false;
478    
479 capela 484 // Now it depends on the device type...
480     lscp_status_t ret = LSCP_FAILED;
481     switch (m_deviceType) {
482 capela 1558 case Device::Audio:
483 capela 961 if ((ret = ::lscp_destroy_audio_device(pMainForm->client(),
484 capela 484 m_iDeviceID)) != LSCP_OK)
485     appendMessagesClient("lscp_destroy_audio_device");
486     break;
487 capela 1558 case Device::Midi:
488 capela 961 if ((ret = ::lscp_destroy_midi_device(pMainForm->client(),
489 capela 484 m_iDeviceID)) != LSCP_OK)
490     appendMessagesClient("lscp_destroy_midi_device");
491     break;
492 capela 1558 case Device::None:
493 capela 484 break;
494     }
495    
496     // Show result.
497     if (ret == LSCP_OK) {
498     appendMessages(QObject::tr("deleted."));
499     m_iDeviceID = -1;
500     } else {
501     appendMessagesError(QObject::tr("Could not delete device.\n\nSorry."));
502     }
503 capela 490
504 capela 484 // Return whether we've done it..
505     return (ret == LSCP_OK);
506     }
507    
508    
509 capela 467 // Device parameter dependencies refreshner.
510 capela 1558 int Device::refreshParams (void)
511 capela 467 {
512 capela 468 // This should only make sense for scratch devices...
513     if (m_iDeviceID >= 0)
514 capela 1509 return 0;
515 capela 467 // Refresh all parameters that have dependencies...
516     int iParams = 0;
517 capela 1558 DeviceParamMap::ConstIterator iter;
518 capela 467 for (iter = m_params.begin(); iter != m_params.end(); ++iter)
519 capela 484 iParams += refreshParam(iter.key());
520 capela 467 // Return how many parameters have been refreshed...
521     return iParams;
522     }
523    
524    
525 capela 463 // Device port/channel list refreshner.
526 capela 1558 int Device::refreshPorts (void)
527 capela 463 {
528 capela 468 // This should only make sense for actual devices...
529     if (m_iDeviceID < 0)
530 capela 1509 return 0;
531 capela 463 // Port/channel count determination...
532     int iPorts = 0;
533     switch (m_deviceType) {
534 capela 1558 case Device::Audio:
535 capela 463 iPorts = m_params["CHANNELS"].value.toInt();
536     break;
537 capela 1558 case Device::Midi:
538 capela 463 iPorts = m_params["PORTS"].value.toInt();
539     break;
540 capela 1558 case Device::None:
541 capela 463 break;
542     }
543     // Retrieve port/channel information...
544 capela 1499 qDeleteAll(m_ports);
545 capela 463 m_ports.clear();
546     for (int iPort = 0; iPort < iPorts; iPort++)
547 capela 1558 m_ports.append(new DevicePort(*this, iPort));
548 capela 467 // Return how many ports have been refreshed...
549     return iPorts;
550 capela 463 }
551    
552    
553 capela 467 // Refresh/set dependencies given that some parameter has changed.
554 capela 1558 int Device::refreshDepends ( const QString& sParam )
555 capela 467 {
556 capela 468 // This should only make sense for scratch devices...
557     if (m_iDeviceID >= 0)
558 capela 1509 return 0;
559 capela 467 // Refresh all parameters that depend on this one...
560     int iDepends = 0;
561 capela 1558 DeviceParamMap::ConstIterator iter;
562 capela 467 for (iter = m_params.begin(); iter != m_params.end(); ++iter) {
563 capela 1499 const QStringList& depends = iter.value().depends;
564     if (depends.indexOf(sParam) >= 0)
565 capela 484 iDepends += refreshParam(iter.key());
566 capela 467 }
567     // Return how many dependencies have been refreshed...
568     return iDepends;
569     }
570    
571    
572     // Refresh/set given parameter based on driver supplied dependencies.
573 capela 1558 int Device::refreshParam ( const QString& sParam )
574 capela 467 {
575 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
576 capela 961 if (pMainForm == NULL)
577     return 0;
578     if (pMainForm->client() == NULL)
579     return 0;
580    
581 capela 467 // Check if we have dependencies...
582 capela 1558 DeviceParam& param = m_params[sParam.toUpper()];
583 capela 467 if (param.depends.isEmpty())
584     return 0;
585    
586     int iRefresh = 0;
587    
588     // Build dependency list...
589     lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1];
590     int iDepend = 0;
591 schoenebeck 1508
592     // we need temporary lists with the final strings, because i.e.
593     // QString::toUtf8() only returns a temporary object and the
594     // C-style char* pointers for liblscp would immediately be invalidated
595     QList<QByteArray> finalKeys;
596     QList<QByteArray> finalVals;
597     for (int i = 0; i < param.depends.count(); i++) {
598     const QString& sDepend = param.depends[i];
599     finalKeys.push_back(sDepend.toUtf8());
600     finalVals.push_back(m_params[sDepend.toUpper()].value.toUtf8());
601     }
602     // yeah, we DO HAVE to do those two loops separately !
603     for (int i = 0; i < param.depends.count(); i++) {
604     pDepends[iDepend].key = (char *) finalKeys[i].constData();
605     pDepends[iDepend].value = (char *) finalVals[i].constData();
606 capela 467 ++iDepend;
607     }
608     // Null terminated.
609     pDepends[iDepend].key = NULL;
610     pDepends[iDepend].value = NULL;
611    
612     // FIXME: Some parameter dependencies (e.g.ALSA CARD)
613 capela 468 // are blocking for no reason, causing potential timeout-crashes.
614     // hopefully this gets mitigated if this dependency hell is only
615     // carried out for scratch devices...
616 capela 467
617     // Retrieve some modern parameters...
618     lscp_param_info_t *pParamInfo = NULL;
619     switch (m_deviceType) {
620 capela 1558 case Device::Audio:
621 capela 1499 if ((pParamInfo = ::lscp_get_audio_driver_param_info(
622     pMainForm->client(), m_sDriverName.toUtf8().constData(),
623     sParam.toUtf8().constData(), pDepends)) == NULL)
624 capela 484 appendMessagesClient("lscp_get_audio_driver_param_info");
625 capela 467 break;
626 capela 1558 case Device::Midi:
627 capela 1499 if ((pParamInfo = ::lscp_get_midi_driver_param_info(
628     pMainForm->client(), m_sDriverName.toUtf8().constData(),
629     sParam.toUtf8().constData(), pDepends)) == NULL)
630 capela 484 appendMessagesClient("lscp_get_midi_driver_param_info");
631 capela 467 break;
632 capela 1558 case Device::None:
633 capela 467 break;
634     }
635     if (pParamInfo) {
636 capela 1558 param = DeviceParam(pParamInfo,
637 capela 1499 param.value.isEmpty() ? NULL : param.value.toUtf8().constData());
638 capela 467 iRefresh++;
639     }
640 capela 468
641 capela 467 // Free used parameter array.
642     delete pDepends;
643    
644     // Return whether the parameters has been changed...
645     return iRefresh;
646     }
647    
648    
649 capela 484 // Redirected messages output methods.
650 capela 1558 void Device::appendMessages( const QString& s ) const
651 capela 484 {
652 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
653 capela 961 if (pMainForm)
654     pMainForm->appendMessages(deviceName() + ' ' + s);
655 capela 484 }
656    
657 capela 1558 void Device::appendMessagesColor( const QString& s,
658 capela 484 const QString& c ) const
659     {
660 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
661 capela 961 if (pMainForm)
662     pMainForm->appendMessagesColor(deviceName() + ' ' + s, c);
663 capela 484 }
664    
665 capela 1558 void Device::appendMessagesText( const QString& s ) const
666 capela 484 {
667 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
668 capela 961 if (pMainForm)
669     pMainForm->appendMessagesText(deviceName() + ' ' + s);
670 capela 484 }
671    
672 capela 1558 void Device::appendMessagesError( const QString& s ) const
673 capela 484 {
674 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
675 capela 961 if (pMainForm)
676     pMainForm->appendMessagesError(deviceName() + "\n\n" + s);
677 capela 484 }
678    
679 capela 1558 void Device::appendMessagesClient( const QString& s ) const
680 capela 484 {
681 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
682 capela 961 if (pMainForm)
683     pMainForm->appendMessagesClient(deviceName() + ' ' + s);
684 capela 484 }
685    
686    
687 capela 430 // Device ids enumerator.
688 capela 1558 int *Device::getDevices ( lscp_client_t *pClient,
689 capela 1509 DeviceType deviceType )
690 capela 429 {
691     int *piDeviceIDs = NULL;
692     switch (deviceType) {
693 capela 1558 case Device::Audio:
694 capela 431 piDeviceIDs = ::lscp_list_audio_devices(pClient);
695 capela 429 break;
696 capela 1558 case Device::Midi:
697 capela 431 piDeviceIDs = ::lscp_list_midi_devices(pClient);
698     break;
699 capela 1558 case Device::None:
700 capela 436 break;
701 capela 429 }
702     return piDeviceIDs;
703     }
704    
705 schoenebeck 1698 std::set<int> Device::getDeviceIDs(lscp_client_t *pClient,
706     DeviceType deviceType)
707     {
708     std::set<int> result;
709     int* piDeviceIDs = getDevices(pClient, deviceType);
710     if (!piDeviceIDs) return result;
711     for (int i = 0; piDeviceIDs[i] != -1; ++i)
712     result.insert(piDeviceIDs[i]);
713     return result;
714     }
715 capela 430
716 schoenebeck 1698
717 capela 430 // Driver names enumerator.
718 capela 1558 QStringList Device::getDrivers ( lscp_client_t *pClient,
719 capela 1509 DeviceType deviceType )
720 capela 430 {
721     QStringList drivers;
722 capela 490
723 capela 430 const char **ppszDrivers = NULL;
724     switch (deviceType) {
725 capela 1558 case Device::Audio:
726 capela 525 ppszDrivers = ::lscp_list_available_audio_drivers(pClient);
727 capela 430 break;
728 capela 1558 case Device::Midi:
729 capela 525 ppszDrivers = ::lscp_list_available_midi_drivers(pClient);
730 capela 431 break;
731 capela 1558 case Device::None:
732 capela 436 break;
733 capela 430 }
734 capela 490
735 capela 980 for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++)
736 capela 431 drivers.append(ppszDrivers[iDriver]);
737 capela 430
738     return drivers;
739     }
740    
741    
742 capela 429 //-------------------------------------------------------------------------
743 capela 1558 // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
744 capela 462 //
745    
746     // Constructor.
747 capela 1558 DevicePort::DevicePort ( Device& device,
748 capela 484 int iPortID ) : m_device(device)
749 capela 462 {
750 capela 484 setDevicePort(iPortID);
751 capela 462 }
752    
753     // Default destructor.
754 capela 1558 DevicePort::~DevicePort (void)
755 capela 462 {
756     }
757    
758    
759     // Initializer.
760 capela 1558 void DevicePort::setDevicePort ( int iPortID )
761 capela 462 {
762 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
763 capela 961 if (pMainForm == NULL)
764     return;
765     if (pMainForm->client() == NULL)
766     return;
767    
768 capela 462 // Device port id should be always set.
769     m_iPortID = iPortID;
770    
771 capela 463 // Reset port parameters anyway.
772 capela 467 m_params.clear();
773 capela 463
774 capela 462 // Retrieve device port/channel info, if any.
775     lscp_device_port_info_t *pPortInfo = NULL;
776 capela 484 switch (m_device.deviceType()) {
777 capela 1558 case Device::Audio:
778 capela 961 if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(),
779 capela 484 m_device.deviceID(), m_iPortID)) == NULL)
780     m_device.appendMessagesClient("lscp_get_audio_channel_info");
781 capela 462 break;
782 capela 1558 case Device::Midi:
783 capela 961 if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(),
784 capela 484 m_device.deviceID(), m_iPortID)) == NULL)
785     m_device.appendMessagesClient("lscp_get_midi_port_info");
786 capela 462 break;
787 capela 1558 case Device::None:
788 capela 462 break;
789     }
790    
791     // If we're bogus, bail out...
792     if (pPortInfo == NULL) {
793     m_sPortName = QString::null;
794     return;
795     }
796    
797     // Set device port/channel properties...
798 capela 484 m_sPortName = pPortInfo->name;
799 capela 462
800     // Grab device port/channel parameters...
801     m_params.clear();
802     for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {
803 capela 463 const QString sParam = pPortInfo->params[i].key;
804 capela 462 lscp_param_info_t *pParamInfo = NULL;
805 capela 484 switch (m_device.deviceType()) {
806 capela 1558 case Device::Audio:
807 capela 484 if ((pParamInfo = ::lscp_get_audio_channel_param_info(
808 capela 961 pMainForm->client(), m_device.deviceID(),
809 capela 1499 m_iPortID, sParam.toUtf8().constData())) == NULL)
810 capela 484 m_device.appendMessagesClient("lscp_get_audio_channel_param_info");
811 capela 462 break;
812 capela 1558 case Device::Midi:
813 capela 484 if ((pParamInfo = ::lscp_get_midi_port_param_info(
814 capela 961 pMainForm->client(), m_device.deviceID(),
815 capela 1499 m_iPortID, sParam.toUtf8().constData())) == NULL)
816 capela 484 m_device.appendMessagesClient("lscp_get_midi_port_param_info");
817 capela 462 break;
818 capela 1558 case Device::None:
819 capela 462 break;
820     }
821     if (pParamInfo) {
822 capela 1558 m_params[sParam.toUpper()] = DeviceParam(pParamInfo,
823 capela 462 pPortInfo->params[i].value);
824     }
825     }
826     }
827    
828    
829     // Device port/channel property accessors.
830 capela 1558 int DevicePort::portID (void) const
831 capela 462 {
832     return m_iPortID;
833     }
834    
835 capela 1558 const QString& DevicePort::portName (void) const
836 capela 462 {
837     return m_sPortName;
838     }
839    
840     // Device port/channel parameter accessor.
841 capela 1558 const DeviceParamMap& DevicePort::params (void) const
842 capela 462 {
843     return m_params;
844     }
845    
846    
847     // Set the proper device port/channel parameter value.
848 capela 1558 bool DevicePort::setParam ( const QString& sParam,
849 capela 462 const QString& sValue )
850     {
851 schoenebeck 1461 MainForm *pMainForm = MainForm::getInstance();
852 capela 961 if (pMainForm == NULL)
853     return false;
854     if (pMainForm->client() == NULL)
855     return false;
856    
857 capela 484 // Set proper port/channel parameter.
858 capela 1499 m_params[sParam.toUpper()].value = sValue;
859 capela 484
860     // If the device already exists, things get immediate...
861     int iRefresh = 0;
862     if (m_device.deviceID() >= 0 && m_iPortID >= 0) {
863 schoenebeck 1508
864     // we need temporary byte arrrays with the final strings, because
865     // i.e. QString::toUtf8() only returns a temporary object and the
866     // C-style char* pointers for liblscp would immediately be invalidated
867     QByteArray finalParamKey = sParam.toUtf8();
868     QByteArray finalParamVal = sValue.toUtf8();
869    
870 capela 484 // Prepare parameter struct.
871     lscp_param_t param;
872 schoenebeck 1508 param.key = (char *) finalParamKey.constData();
873     param.value = (char *) finalParamVal.constData();
874 capela 484 // Now it depends on the device type...
875     lscp_status_t ret = LSCP_FAILED;
876     switch (m_device.deviceType()) {
877 capela 1558 case Device::Audio:
878 capela 961 if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(),
879 capela 484 m_device.deviceID(), m_iPortID, &param)) != LSCP_OK)
880     m_device.appendMessagesClient("lscp_set_audio_channel_param");
881     break;
882 capela 1558 case Device::Midi:
883 capela 961 if ((ret = ::lscp_set_midi_port_param(pMainForm->client(),
884 capela 484 m_device.deviceID(), m_iPortID, &param)) != LSCP_OK)
885     m_device.appendMessagesClient("lscp_set_midi_port_param");
886     break;
887 capela 1558 case Device::None:
888 capela 484 break;
889     }
890     // Show result.
891     if (ret == LSCP_OK) {
892     m_device.appendMessages(m_sPortName
893     + ' ' + QString("%1: %2.").arg(sParam).arg(sValue));
894     iRefresh++;
895     } else {
896     m_device.appendMessagesError(
897     QObject::tr("Could not set %1 parameter value.\n\n"
898     "Sorry.").arg(m_sPortName));
899     }
900     }
901    
902     // Return whether we're need a view refresh.
903     return (iRefresh > 0);
904 capela 462 }
905    
906    
907     //-------------------------------------------------------------------------
908 capela 1558 // QSampler::DeviceItem - QTreeWidget device item.
909 capela 429 //
910    
911     // Constructors.
912 capela 1558 DeviceItem::DeviceItem ( QTreeWidget* pTreeWidget,
913     Device::DeviceType deviceType )
914 schoenebeck 1461 : QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM),
915 capela 1559 m_device(deviceType)
916 capela 429 {
917     switch(m_device.deviceType()) {
918 capela 1558 case Device::Audio:
919 capela 2074 setIcon(0, QPixmap(":/images/audio1.png"));
920 schoenebeck 1477 setText(0, QObject::tr("Audio Devices"));
921 capela 429 break;
922 capela 1558 case Device::Midi:
923 capela 2074 setIcon(0, QPixmap(":/images/midi1.png"));
924 schoenebeck 1477 setText(0, QObject::tr("MIDI Devices"));
925 capela 429 break;
926 capela 1558 case Device::None:
927 capela 436 break;
928 capela 429 }
929 capela 1558
930     // Root items are not selectable...
931     setFlags(flags() & ~Qt::ItemIsSelectable);
932 capela 429 }
933    
934 capela 1558 DeviceItem::DeviceItem ( QTreeWidgetItem* pItem,
935     Device::DeviceType deviceType,
936 capela 433 int iDeviceID )
937 schoenebeck 1461 : QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM),
938 capela 1559 m_device(deviceType, iDeviceID)
939 capela 429 {
940     switch(m_device.deviceType()) {
941 capela 1558 case Device::Audio:
942 capela 2074 setIcon(0, QPixmap(":/images/audio2.png"));
943 capela 429 break;
944 capela 1558 case Device::Midi:
945 capela 2074 setIcon(0, QPixmap(":/images/midi2.png"));
946 capela 429 break;
947 capela 1558 case Device::None:
948 capela 436 break;
949 capela 429 }
950    
951 schoenebeck 1486 setText(0, m_device.deviceName());
952 capela 429 }
953    
954     // Default destructor.
955 capela 1558 DeviceItem::~DeviceItem ()
956 capela 429 {
957     }
958    
959     // Instance accessors.
960 capela 1558 Device& DeviceItem::device ()
961 capela 429 {
962     return m_device;
963     }
964    
965    
966     //-------------------------------------------------------------------------
967 capela 1558 // QSampler::AbstractDeviceParamModel - data model base class for device parameters
968 capela 429 //
969 capela 426
970 capela 1509 AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent )
971     : QAbstractTableModel(pParent), m_bEditable(false)
972     {
973 capela 1510 m_pParams = NULL;
974 capela 426 }
975    
976 capela 1509
977     int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const
978     {
979     //std::cout << "model size=" << params.size() << "\n" << std::flush;
980 capela 1510 return (m_pParams ? m_pParams->size() : 0);
981 capela 429 }
982    
983 capela 1509
984     int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const
985     {
986     return 3;
987 schoenebeck 1461 }
988 capela 429
989 capela 1509
990     Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const
991     {
992 schoenebeck 1518 return Qt::ItemIsEditable | Qt::ItemIsEnabled;
993 schoenebeck 1461 }
994    
995    
996 capela 1509 QVariant AbstractDeviceParamModel::headerData (
997     int section, Qt::Orientation orientation, int role) const
998     {
999     if (role != Qt::DisplayRole)
1000     return QVariant();
1001 schoenebeck 1461
1002 capela 1509 if (orientation == Qt::Horizontal) {
1003     switch (section) {
1004     case 0: return tr("Parameter");
1005     case 1: return tr("Value");
1006     case 2: return tr("Description");
1007     default: return QVariant();
1008     }
1009     }
1010    
1011     return QVariant();
1012 schoenebeck 1461 }
1013    
1014 capela 1509
1015     void AbstractDeviceParamModel::refresh (
1016 capela 1558 const DeviceParamMap* pParams, bool bEditable )
1017 capela 1509 {
1018 capela 1510 m_pParams = pParams;
1019 capela 1509 m_bEditable = bEditable;
1020     // inform the outer world (QTableView) that our data changed
1021 capela 2387 #if QT_VERSION < 0x050000
1022 capela 1509 QAbstractTableModel::reset();
1023 capela 2387 #else
1024     QAbstractTableModel::beginResetModel();
1025     QAbstractTableModel::endResetModel();
1026     #endif
1027 schoenebeck 1461 }
1028    
1029 capela 1509
1030     void AbstractDeviceParamModel::clear (void)
1031     {
1032 capela 1510 m_pParams = NULL;
1033 capela 1509 // inform the outer world (QTableView) that our data changed
1034 capela 2387 #if QT_VERSION < 0x050000
1035 capela 1509 QAbstractTableModel::reset();
1036 capela 2387 #else
1037     QAbstractTableModel::beginResetModel();
1038     QAbstractTableModel::endResetModel();
1039     #endif
1040 schoenebeck 1486 }
1041    
1042    
1043     //-------------------------------------------------------------------------
1044 capela 1558 // QSampler::DeviceParamModel - data model for device parameters
1045     // (used for QTableView)
1046 schoenebeck 1486
1047 capela 1509 DeviceParamModel::DeviceParamModel ( QObject *pParent )
1048     : AbstractDeviceParamModel(pParent)
1049     {
1050 capela 1510 m_pDevice = NULL;
1051 schoenebeck 1486 }
1052    
1053 capela 1509 QVariant DeviceParamModel::data (
1054     const QModelIndex &index, int role) const
1055     {
1056     if (!index.isValid())
1057     return QVariant();
1058 schoenebeck 1508
1059 capela 1509 if (role != Qt::DisplayRole)
1060     return QVariant();
1061 schoenebeck 1508
1062 capela 1509 DeviceParameterRow item;
1063 capela 1510 item.name = m_pParams->keys()[index.row()];
1064     item.param = (*m_pParams)[item.name];
1065     item.alive = (m_pDevice && m_pDevice->deviceID() >= 0);
1066 capela 1509
1067     return QVariant::fromValue(item);
1068 schoenebeck 1508 }
1069    
1070 capela 1509
1071     bool DeviceParamModel::setData (
1072     const QModelIndex& index, const QVariant& value, int /*role*/)
1073     {
1074     if (!index.isValid())
1075     return false;
1076    
1077 capela 1510 QString key = m_pParams->keys()[index.row()];
1078     //m_pParams[key].value = value.toString();
1079     m_pDevice->setParam(key, value.toString());
1080 capela 1509 emit dataChanged(index, index);
1081     return true;
1082 schoenebeck 1486 }
1083    
1084 capela 1509
1085 capela 1558 void DeviceParamModel::refresh ( Device* pDevice, bool bEditable )
1086 capela 1509 {
1087 capela 1510 m_pDevice = pDevice;
1088 capela 1509 AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable);
1089 schoenebeck 1486 }
1090    
1091 capela 1509
1092     void DeviceParamModel::clear (void)
1093     {
1094     AbstractDeviceParamModel::clear();
1095 capela 1510 m_pDevice = NULL;
1096 schoenebeck 1461 }
1097    
1098    
1099 schoenebeck 1486 //-------------------------------------------------------------------------
1100 capela 1558 // QSampler::PortParamModel - data model for port parameters
1101     // (used for QTableView)
1102 schoenebeck 1486
1103 capela 1509 PortParamModel::PortParamModel ( QObject *pParent)
1104     : AbstractDeviceParamModel(pParent)
1105     {
1106 capela 1510 m_pPort = NULL;
1107 schoenebeck 1486 }
1108    
1109 capela 1509 QVariant PortParamModel::data ( const QModelIndex &index, int role ) const
1110     {
1111     if (!index.isValid())
1112     return QVariant();
1113 schoenebeck 1508
1114 capela 1509 if (role != Qt::DisplayRole)
1115     return QVariant();
1116 schoenebeck 1508
1117 capela 1509 DeviceParameterRow item;
1118 capela 1510 item.name = m_pParams->keys()[index.row()];
1119     item.param = (*m_pParams)[item.name];
1120     item.alive = (m_pPort && m_pPort->portID() >= 0);
1121 capela 1509
1122     return QVariant::fromValue(item);
1123 schoenebeck 1508 }
1124    
1125 capela 1509
1126     bool PortParamModel::setData (
1127     const QModelIndex& index, const QVariant& value, int /*role*/)
1128     {
1129     if (!index.isValid())
1130     return false;
1131    
1132 capela 1510 QString key = m_pParams->keys()[index.row()];
1133 capela 1509 //params[key].value = value.toString();
1134 capela 1510 m_pPort->setParam(key, value.toString());
1135 capela 1509 emit dataChanged(index, index);
1136     return true;
1137 schoenebeck 1486 }
1138    
1139 capela 1509
1140 capela 1558 void PortParamModel::refresh ( DevicePort* pPort, bool bEditable )
1141 capela 1509 {
1142 capela 1510 m_pPort = pPort;
1143     AbstractDeviceParamModel::refresh(&pPort->params(), bEditable);
1144 schoenebeck 1486 }
1145    
1146 capela 1509
1147     void PortParamModel::clear (void)
1148     {
1149     AbstractDeviceParamModel::clear();
1150 capela 1510 m_pPort = NULL;
1151 schoenebeck 1486 }
1152    
1153    
1154     //-------------------------------------------------------------------------
1155 capela 1558 // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
1156 schoenebeck 1486 //
1157    
1158 capela 1509 DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent)
1159     : QItemDelegate(pParent)
1160     {
1161 schoenebeck 1461 }
1162    
1163 capela 1509
1164     QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent,
1165     const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const
1166 schoenebeck 1461 {
1167 capela 1509 if (!index.isValid())
1168     return NULL;
1169 schoenebeck 1486
1170 capela 1509 DeviceParameterRow r = index.model()->data(index,
1171     Qt::DisplayRole).value<DeviceParameterRow>();
1172 schoenebeck 1461
1173 capela 1509 const bool bEnabled = (r.alive) ? !r.param.fix : true;
1174 schoenebeck 3402 const bool bFix = r.param.fix;
1175 schoenebeck 1461
1176 capela 1509 QString val = (r.alive) ? r.param.value : r.param.defaultv;
1177 schoenebeck 1508
1178 capela 1509 switch (index.column()) {
1179     case 0:
1180     return new QLabel(r.name, pParent);
1181     case 1: {
1182     if (r.param.type == LSCP_TYPE_BOOL) {
1183 capela 1510 QCheckBox *pCheckBox = new QCheckBox(pParent);
1184 capela 1509 if (val != QString::null)
1185     pCheckBox->setChecked(val.toLower() == "true");
1186     pCheckBox->setEnabled(bEnabled);
1187 schoenebeck 3402 pCheckBox->setCheckable(!bFix);
1188 capela 1509 return pCheckBox;
1189     } else if (r.param.possibilities.count() > 0) {
1190     QStringList opts = r.param.possibilities;
1191     if (r.param.multiplicity)
1192     opts.prepend(tr("(none)"));
1193 capela 1510 QComboBox *pComboBox = new QComboBox(pParent);
1194 capela 1509 pComboBox->addItems(opts);
1195     if (r.param.value.isEmpty())
1196     pComboBox->setCurrentIndex(0);
1197     else
1198     pComboBox->setCurrentIndex(pComboBox->findText(val));
1199     pComboBox->setEnabled(bEnabled);
1200 schoenebeck 3402 pComboBox->setEditable(!bFix);
1201 capela 1509 return pComboBox;
1202     } else if (r.param.type == LSCP_TYPE_INT && bEnabled) {
1203 capela 1510 QSpinBox *pSpinBox = new QSpinBox(pParent);
1204 capela 1509 pSpinBox->setMinimum(
1205     (!r.param.range_min.isEmpty()) ?
1206     r.param.range_min.toInt() : 0 // or better a negative default min value ?
1207     );
1208     pSpinBox->setMaximum(
1209     (!r.param.range_max.isEmpty()) ?
1210 capela 2059 r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ?
1211 capela 1509 );
1212     pSpinBox->setValue(val.toInt());
1213 schoenebeck 3402 pSpinBox->setReadOnly(bFix);
1214 capela 1509 return pSpinBox;
1215     } else if (bEnabled) {
1216 capela 1510 QLineEdit *pLineEdit = new QLineEdit(val, pParent);
1217 schoenebeck 3402 pLineEdit->setReadOnly(bFix);
1218 capela 1509 return pLineEdit;
1219     } else {
1220 capela 1510 QLabel *pLabel = new QLabel(val, pParent);
1221 capela 1509 return pLabel;
1222     }
1223     }
1224     case 2:
1225     return new QLabel(r.param.description, pParent);
1226     default:
1227     return NULL;
1228     }
1229 schoenebeck 1461 }
1230    
1231 capela 1509
1232     void DeviceParamDelegate::setEditorData (
1233     QWidget* /*pEditor*/, const QModelIndex& /*index*/) const
1234     {
1235     // Unused, since we set the editor data already in createEditor()
1236 schoenebeck 1461 }
1237    
1238 capela 1509
1239     void DeviceParamDelegate::setModelData ( QWidget *pEditor,
1240 capela 1510 QAbstractItemModel *pModel, const QModelIndex& index ) const
1241 capela 1509 {
1242     if (index.column() == 1) {
1243     DeviceParameterRow r = index.model()->data(index,
1244     Qt::DisplayRole).value<DeviceParameterRow> ();
1245 schoenebeck 1511 if (pEditor->metaObject()->className() == QString("QCheckBox")) {
1246 capela 1559 QCheckBox *pCheckBox = static_cast<QCheckBox *> (pEditor);
1247 capela 1510 pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked));
1248 schoenebeck 1511 } else if (pEditor->metaObject()->className() == QString("QComboBox")) {
1249 capela 1559 QComboBox *pComboBox = static_cast<QComboBox *> (pEditor);
1250 capela 1510 pModel->setData(index, pComboBox->currentText());
1251 schoenebeck 1511 } else if (pEditor->metaObject()->className() == QString("QSpinBox")) {
1252 capela 1559 QSpinBox *pSpinBox = static_cast<QSpinBox *> (pEditor);
1253 capela 1510 pModel->setData(index, pSpinBox->value());
1254 schoenebeck 1511 } else if (pEditor->metaObject()->className() == QString("QLineEdit")) {
1255 capela 1559 QLineEdit *pLineEdit = static_cast<QLineEdit *> (pEditor);
1256 capela 1510 pModel->setData(index, pLineEdit->text());
1257 schoenebeck 1511 } else if (pEditor->metaObject()->className() == QString("QLabel")) {
1258 capela 1559 QLabel *pLabel = static_cast<QLabel *> (pEditor);
1259 capela 1510 pModel->setData(index, pLabel->text());
1260 capela 1509 }
1261     }
1262 schoenebeck 1461 }
1263    
1264 capela 1509 void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor,
1265 schoenebeck 1461 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1266     {
1267 capela 1509 if (pEditor)
1268     pEditor->setGeometry(option.rect);
1269 schoenebeck 1461 }
1270    
1271 capela 1558 } // namespace QSampler
1272    
1273 capela 426 // end of qsamplerDevice.cpp

  ViewVC Help
Powered by ViewVC