1 |
// qsamplerDevice.cpp |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
6 |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
8 |
as published by the Free Software Foundation; either version 2 |
9 |
of the License, or (at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
20 |
*****************************************************************************/ |
21 |
|
22 |
#include "qsamplerDevice.h" |
23 |
|
24 |
#include <qspinbox.h> |
25 |
#include <qlineedit.h> |
26 |
|
27 |
#include "qsamplerMainForm.h" |
28 |
#include "qsamplerDeviceForm.h" |
29 |
|
30 |
#include "config.h" |
31 |
|
32 |
|
33 |
//------------------------------------------------------------------------- |
34 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
35 |
// |
36 |
|
37 |
// Constructors. |
38 |
qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo, |
39 |
const char *pszValue ) |
40 |
{ |
41 |
setParam(pParamInfo, pszValue); |
42 |
} |
43 |
|
44 |
|
45 |
// Default destructor. |
46 |
qsamplerDeviceParam::~qsamplerDeviceParam (void) |
47 |
{ |
48 |
} |
49 |
|
50 |
|
51 |
// Initializer. |
52 |
void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
53 |
const char *pszValue ) |
54 |
{ |
55 |
if (pParamInfo == NULL) |
56 |
return; |
57 |
|
58 |
// Info structure field members. |
59 |
|
60 |
type = pParamInfo->type; |
61 |
|
62 |
if (pParamInfo->description) |
63 |
description = pParamInfo->description; |
64 |
else |
65 |
description = QString::null; |
66 |
|
67 |
mandatory = (bool) pParamInfo->multiplicity; |
68 |
fix = (bool) pParamInfo->fix; |
69 |
multiplicity = (bool) pParamInfo->multiplicity; |
70 |
|
71 |
depends.clear(); |
72 |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
73 |
depends.append(pParamInfo->depends[i]); |
74 |
|
75 |
if (pParamInfo->defaultv) |
76 |
defaultv = pParamInfo->defaultv; |
77 |
else |
78 |
defaultv = QString::null; |
79 |
|
80 |
if (pParamInfo->range_min) |
81 |
range_min = pParamInfo->range_min; |
82 |
else |
83 |
range_min = QString::null; |
84 |
|
85 |
if (pParamInfo->range_max) |
86 |
range_max = pParamInfo->range_max; |
87 |
else |
88 |
range_max = QString::null; |
89 |
|
90 |
possibilities.clear(); |
91 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
92 |
possibilities.append(pParamInfo->possibilities[i]); |
93 |
|
94 |
// The current parameter value. |
95 |
if (pszValue) |
96 |
value = pszValue; |
97 |
else |
98 |
value = QString::null; |
99 |
} |
100 |
|
101 |
|
102 |
//------------------------------------------------------------------------- |
103 |
// qsamplerDevice - MIDI/Audio Device structure. |
104 |
// |
105 |
|
106 |
// Constructor. |
107 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
108 |
qsamplerDeviceType deviceType, int iDeviceID ) |
109 |
{ |
110 |
m_ports.setAutoDelete(true); |
111 |
|
112 |
setDevice(pClient, deviceType, iDeviceID); |
113 |
} |
114 |
|
115 |
// Default destructor. |
116 |
qsamplerDevice::~qsamplerDevice (void) |
117 |
{ |
118 |
} |
119 |
|
120 |
|
121 |
// Initializer. |
122 |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
123 |
qsamplerDeviceType deviceType, int iDeviceID ) |
124 |
{ |
125 |
// Device id and type should be always set. |
126 |
m_iDeviceID = iDeviceID; |
127 |
m_deviceType = deviceType; |
128 |
|
129 |
// Reset device parameters and ports anyway. |
130 |
m_params.clear(); |
131 |
m_ports.clear(); |
132 |
|
133 |
// Retrieve device info, if any. |
134 |
lscp_device_info_t *pDeviceInfo = NULL; |
135 |
switch (deviceType) { |
136 |
case qsamplerDevice::Audio: |
137 |
m_sDeviceType = QObject::tr("Audio"); |
138 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
139 |
break; |
140 |
case qsamplerDevice::Midi: |
141 |
m_sDeviceType = QObject::tr("MIDI"); |
142 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
143 |
break; |
144 |
case qsamplerDevice::None: |
145 |
m_sDeviceType = QString::null; |
146 |
break; |
147 |
} |
148 |
|
149 |
// If we're bogus, bail out... |
150 |
if (pDeviceInfo == NULL) { |
151 |
m_sDriverName = QString::null; |
152 |
m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType); |
153 |
return; |
154 |
} |
155 |
|
156 |
// Other device properties... |
157 |
m_sDriverName = pDeviceInfo->driver; |
158 |
m_sDeviceName = m_sDriverName + ' ' |
159 |
+ QObject::tr("Device %1").arg(m_iDeviceID); |
160 |
|
161 |
// Grab device parameters... |
162 |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
163 |
const QString sParam = pDeviceInfo->params[i].key; |
164 |
lscp_param_info_t *pParamInfo = NULL; |
165 |
switch (deviceType) { |
166 |
case qsamplerDevice::Audio: |
167 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
168 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
169 |
break; |
170 |
case qsamplerDevice::Midi: |
171 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
172 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
173 |
break; |
174 |
case qsamplerDevice::None: |
175 |
break; |
176 |
} |
177 |
if (pParamInfo) { |
178 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
179 |
pDeviceInfo->params[i].value); |
180 |
} |
181 |
} |
182 |
|
183 |
// Refresh parameter dependencies... |
184 |
refreshParams(pClient); |
185 |
// Set port/channel list... |
186 |
refreshPorts(pClient); |
187 |
} |
188 |
|
189 |
|
190 |
// Driver name initializer/settler. |
191 |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
192 |
const QString& sDriverName ) |
193 |
{ |
194 |
// Valid only for scratch devices. |
195 |
if (m_sDriverName == sDriverName) |
196 |
return; |
197 |
|
198 |
// Reset device parameters and ports anyway. |
199 |
m_params.clear(); |
200 |
m_ports.clear(); |
201 |
|
202 |
// Retrieve driver info, if any. |
203 |
lscp_driver_info_t *pDriverInfo = NULL; |
204 |
switch (m_deviceType) { |
205 |
case qsamplerDevice::Audio: |
206 |
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
207 |
sDriverName.latin1()); |
208 |
break; |
209 |
case qsamplerDevice::Midi: |
210 |
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
211 |
sDriverName.latin1()); |
212 |
break; |
213 |
case qsamplerDevice::None: |
214 |
break; |
215 |
} |
216 |
|
217 |
// If we're bogus, bail out... |
218 |
if (pDriverInfo == NULL) |
219 |
return; |
220 |
|
221 |
// Remember device parameters... |
222 |
m_sDriverName = sDriverName; |
223 |
|
224 |
// Grab driver parameters... |
225 |
for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) { |
226 |
const QString sParam = pDriverInfo->parameters[i]; |
227 |
lscp_param_info_t *pParamInfo = NULL; |
228 |
switch (m_deviceType) { |
229 |
case qsamplerDevice::Audio: |
230 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
231 |
sDriverName.latin1(), sParam.latin1(), NULL); |
232 |
break; |
233 |
case qsamplerDevice::Midi: |
234 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
235 |
sDriverName.latin1(), sParam.latin1(), NULL); |
236 |
break; |
237 |
case qsamplerDevice::None: |
238 |
break; |
239 |
} |
240 |
if (pParamInfo) { |
241 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
242 |
pParamInfo->defaultv); |
243 |
} |
244 |
} |
245 |
|
246 |
// Refresh parameter dependencies... |
247 |
refreshParams(pClient); |
248 |
// Set port/channel list... |
249 |
refreshPorts(pClient); |
250 |
} |
251 |
|
252 |
|
253 |
// Device property accessors. |
254 |
int qsamplerDevice::deviceID (void) const |
255 |
{ |
256 |
return m_iDeviceID; |
257 |
} |
258 |
|
259 |
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
260 |
{ |
261 |
return m_deviceType; |
262 |
} |
263 |
|
264 |
const QString& qsamplerDevice::deviceTypeName (void) const |
265 |
{ |
266 |
return m_sDeviceType; |
267 |
} |
268 |
|
269 |
const QString& qsamplerDevice::driverName (void) const |
270 |
{ |
271 |
return m_sDriverName; |
272 |
} |
273 |
|
274 |
const QString& qsamplerDevice::deviceName (void) const |
275 |
{ |
276 |
return m_sDeviceName; |
277 |
} |
278 |
|
279 |
|
280 |
// Set the proper device parameter value. |
281 |
void qsamplerDevice::setParam ( const QString& sParam, |
282 |
const QString& sValue ) |
283 |
{ |
284 |
m_params[sParam.upper()].value = sValue; |
285 |
} |
286 |
|
287 |
|
288 |
// Device parameter accessor. |
289 |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
290 |
{ |
291 |
return m_params; |
292 |
} |
293 |
|
294 |
|
295 |
// Device port/channel list accessor. |
296 |
qsamplerDevicePortList& qsamplerDevice::ports (void) |
297 |
{ |
298 |
return m_ports; |
299 |
} |
300 |
|
301 |
|
302 |
// Device parameter dependencies refreshner. |
303 |
int qsamplerDevice::refreshParams ( lscp_client_t *pClient ) |
304 |
{ |
305 |
// This should only make sense for scratch devices... |
306 |
if (m_iDeviceID >= 0) |
307 |
return 0; |
308 |
// Refresh all parameters that have dependencies... |
309 |
int iParams = 0; |
310 |
qsamplerDeviceParamMap::ConstIterator iter; |
311 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
312 |
iParams += refreshParam(pClient, iter.key()); |
313 |
// Return how many parameters have been refreshed... |
314 |
return iParams; |
315 |
} |
316 |
|
317 |
|
318 |
// Device port/channel list refreshner. |
319 |
int qsamplerDevice::refreshPorts ( lscp_client_t *pClient ) |
320 |
{ |
321 |
// This should only make sense for actual devices... |
322 |
if (m_iDeviceID < 0) |
323 |
return 0; |
324 |
// Port/channel count determination... |
325 |
int iPorts = 0; |
326 |
switch (m_deviceType) { |
327 |
case qsamplerDevice::Audio: |
328 |
iPorts = m_params["CHANNELS"].value.toInt(); |
329 |
break; |
330 |
case qsamplerDevice::Midi: |
331 |
iPorts = m_params["PORTS"].value.toInt(); |
332 |
break; |
333 |
case qsamplerDevice::None: |
334 |
break; |
335 |
} |
336 |
// Retrieve port/channel information... |
337 |
m_ports.clear(); |
338 |
for (int iPort = 0; iPort < iPorts; iPort++) |
339 |
m_ports.append(new qsamplerDevicePort(pClient, *this, iPort)); |
340 |
// Return how many ports have been refreshed... |
341 |
return iPorts; |
342 |
} |
343 |
|
344 |
|
345 |
// Refresh/set dependencies given that some parameter has changed. |
346 |
int qsamplerDevice::refreshDepends ( lscp_client_t *pClient, |
347 |
const QString& sParam ) |
348 |
{ |
349 |
// This should only make sense for scratch devices... |
350 |
if (m_iDeviceID >= 0) |
351 |
return 0; |
352 |
// Refresh all parameters that depend on this one... |
353 |
int iDepends = 0; |
354 |
qsamplerDeviceParamMap::ConstIterator iter; |
355 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
356 |
const QStringList& depends = iter.data().depends; |
357 |
if (depends.find(sParam) != depends.end()) |
358 |
iDepends += refreshParam(pClient, iter.key()); |
359 |
} |
360 |
// Return how many dependencies have been refreshed... |
361 |
return iDepends; |
362 |
} |
363 |
|
364 |
|
365 |
// Refresh/set given parameter based on driver supplied dependencies. |
366 |
int qsamplerDevice::refreshParam ( lscp_client_t *pClient, |
367 |
const QString& sParam ) |
368 |
{ |
369 |
// Check if we have dependencies... |
370 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
371 |
if (param.depends.isEmpty()) |
372 |
return 0; |
373 |
|
374 |
int iRefresh = 0; |
375 |
|
376 |
// Build dependency list... |
377 |
lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1]; |
378 |
int iDepend = 0; |
379 |
QStringList::ConstIterator iter; |
380 |
for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) { |
381 |
const QString& sDepend = *iter; |
382 |
pDepends[iDepend].key = (char *) sDepend.latin1(); |
383 |
pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1(); |
384 |
++iDepend; |
385 |
} |
386 |
// Null terminated. |
387 |
pDepends[iDepend].key = NULL; |
388 |
pDepends[iDepend].value = NULL; |
389 |
|
390 |
// FIXME: Some parameter dependencies (e.g.ALSA CARD) |
391 |
// are blocking for no reason, causing potential timeout-crashes. |
392 |
// hopefully this gets mitigated if this dependency hell is only |
393 |
// carried out for scratch devices... |
394 |
|
395 |
// Retrieve some modern parameters... |
396 |
lscp_param_info_t *pParamInfo = NULL; |
397 |
switch (m_deviceType) { |
398 |
case qsamplerDevice::Audio: |
399 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
400 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
401 |
break; |
402 |
case qsamplerDevice::Midi: |
403 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
404 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
405 |
break; |
406 |
case qsamplerDevice::None: |
407 |
break; |
408 |
} |
409 |
if (pParamInfo) { |
410 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
411 |
iRefresh++; |
412 |
} |
413 |
|
414 |
// Free used parameter array. |
415 |
delete pDepends; |
416 |
|
417 |
// Return whether the parameters has been changed... |
418 |
return iRefresh; |
419 |
} |
420 |
|
421 |
|
422 |
// Device ids enumerator. |
423 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
424 |
qsamplerDeviceType deviceType ) |
425 |
{ |
426 |
int *piDeviceIDs = NULL; |
427 |
switch (deviceType) { |
428 |
case qsamplerDevice::Audio: |
429 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
430 |
break; |
431 |
case qsamplerDevice::Midi: |
432 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
433 |
break; |
434 |
case qsamplerDevice::None: |
435 |
break; |
436 |
} |
437 |
return piDeviceIDs; |
438 |
} |
439 |
|
440 |
|
441 |
// Driver names enumerator. |
442 |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
443 |
qsamplerDeviceType deviceType ) |
444 |
{ |
445 |
QStringList drivers; |
446 |
|
447 |
const char **ppszDrivers = NULL; |
448 |
switch (deviceType) { |
449 |
case qsamplerDevice::Audio: |
450 |
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
451 |
break; |
452 |
case qsamplerDevice::Midi: |
453 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
454 |
break; |
455 |
case qsamplerDevice::None: |
456 |
break; |
457 |
} |
458 |
|
459 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
460 |
drivers.append(ppszDrivers[iDriver]); |
461 |
|
462 |
return drivers; |
463 |
} |
464 |
|
465 |
|
466 |
//------------------------------------------------------------------------- |
467 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
468 |
// |
469 |
|
470 |
// Constructor. |
471 |
qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient, |
472 |
const qsamplerDevice& device, int iPortID ) |
473 |
{ |
474 |
setDevicePort(pClient, device, iPortID); |
475 |
} |
476 |
|
477 |
// Default destructor. |
478 |
qsamplerDevicePort::~qsamplerDevicePort (void) |
479 |
{ |
480 |
} |
481 |
|
482 |
|
483 |
// Initializer. |
484 |
void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient, |
485 |
const qsamplerDevice& device, int iPortID ) |
486 |
{ |
487 |
// Device port id should be always set. |
488 |
m_iPortID = iPortID; |
489 |
|
490 |
// Reset port parameters anyway. |
491 |
m_params.clear(); |
492 |
|
493 |
// Retrieve device port/channel info, if any. |
494 |
QString sPrefix = device.driverName() + ' '; |
495 |
lscp_device_port_info_t *pPortInfo = NULL; |
496 |
switch (device.deviceType()) { |
497 |
case qsamplerDevice::Audio: |
498 |
sPrefix += QObject::tr("Channel"); |
499 |
pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID); |
500 |
break; |
501 |
case qsamplerDevice::Midi: |
502 |
sPrefix += QObject::tr("Port"); |
503 |
pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID); |
504 |
break; |
505 |
case qsamplerDevice::None: |
506 |
break; |
507 |
} |
508 |
|
509 |
// If we're bogus, bail out... |
510 |
if (pPortInfo == NULL) { |
511 |
m_sPortName = QString::null; |
512 |
return; |
513 |
} |
514 |
|
515 |
// Set device port/channel properties... |
516 |
sPrefix += " %1:"; |
517 |
m_sPortName = sPrefix.arg(m_iPortID) + ' ' + pPortInfo->name; |
518 |
|
519 |
// Grab device port/channel parameters... |
520 |
m_params.clear(); |
521 |
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
522 |
const QString sParam = pPortInfo->params[i].key; |
523 |
lscp_param_info_t *pParamInfo = NULL; |
524 |
switch (device.deviceType()) { |
525 |
case qsamplerDevice::Audio: |
526 |
pParamInfo = ::lscp_get_audio_channel_param_info(pClient, |
527 |
device.deviceID(), iPortID, sParam.latin1()); |
528 |
break; |
529 |
case qsamplerDevice::Midi: |
530 |
pParamInfo = ::lscp_get_midi_port_param_info(pClient, |
531 |
device.deviceID(), iPortID, sParam.latin1()); |
532 |
break; |
533 |
case qsamplerDevice::None: |
534 |
break; |
535 |
} |
536 |
if (pParamInfo) { |
537 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
538 |
pPortInfo->params[i].value); |
539 |
} |
540 |
} |
541 |
} |
542 |
|
543 |
|
544 |
// Device port/channel property accessors. |
545 |
int qsamplerDevicePort::portID (void) const |
546 |
{ |
547 |
return m_iPortID; |
548 |
} |
549 |
|
550 |
const QString& qsamplerDevicePort::portName (void) const |
551 |
{ |
552 |
return m_sPortName; |
553 |
} |
554 |
|
555 |
// Device port/channel parameter accessor. |
556 |
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
557 |
{ |
558 |
return m_params; |
559 |
} |
560 |
|
561 |
|
562 |
// Set the proper device port/channel parameter value. |
563 |
void qsamplerDevicePort::setParam ( const QString& sParam, |
564 |
const QString& sValue ) |
565 |
{ |
566 |
m_params[sParam.upper()].value = sValue; |
567 |
} |
568 |
|
569 |
|
570 |
//------------------------------------------------------------------------- |
571 |
// qsamplerDeviceItem - QListView device item. |
572 |
// |
573 |
|
574 |
// Constructors. |
575 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
576 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
577 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
578 |
{ |
579 |
switch(m_device.deviceType()) { |
580 |
case qsamplerDevice::Audio: |
581 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
582 |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
583 |
break; |
584 |
case qsamplerDevice::Midi: |
585 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
586 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
587 |
break; |
588 |
case qsamplerDevice::None: |
589 |
break; |
590 |
} |
591 |
} |
592 |
|
593 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
594 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
595 |
int iDeviceID ) |
596 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
597 |
{ |
598 |
switch(m_device.deviceType()) { |
599 |
case qsamplerDevice::Audio: |
600 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
601 |
break; |
602 |
case qsamplerDevice::Midi: |
603 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
604 |
break; |
605 |
case qsamplerDevice::None: |
606 |
break; |
607 |
} |
608 |
|
609 |
QListViewItem::setText(0, m_device.deviceName()); |
610 |
} |
611 |
|
612 |
// Default destructor. |
613 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
614 |
{ |
615 |
} |
616 |
|
617 |
// Instance accessors. |
618 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
619 |
{ |
620 |
return m_device; |
621 |
} |
622 |
|
623 |
// To virtually distinguish between list view items. |
624 |
int qsamplerDeviceItem::rtti() const |
625 |
{ |
626 |
return QSAMPLER_DEVICE_ITEM; |
627 |
} |
628 |
|
629 |
|
630 |
|
631 |
//------------------------------------------------------------------------- |
632 |
// qsamplerDeviceParamTable - Device parameter view table. |
633 |
// |
634 |
|
635 |
// Constructor. |
636 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
637 |
const char *pszName ) |
638 |
: QTable(pParent, pszName) |
639 |
{ |
640 |
// Set fixed number of columns. |
641 |
QTable::setNumCols(3); |
642 |
QTable::setShowGrid(false); |
643 |
QTable::setSorting(false); |
644 |
QTable::setFocusStyle(QTable::FollowStyle); |
645 |
QTable::setSelectionMode(QTable::NoSelection); |
646 |
// No vertical header. |
647 |
QTable::verticalHeader()->hide(); |
648 |
QTable::setLeftMargin(0); |
649 |
// Initialize the fixed table column headings. |
650 |
QHeader *pHeader = QTable::horizontalHeader(); |
651 |
pHeader->setLabel(0, tr("Parameter")); |
652 |
pHeader->setLabel(1, tr("Description")); |
653 |
pHeader->setLabel(2, tr("Value")); |
654 |
// Set read-onlyness of each column |
655 |
QTable::setColumnReadOnly(0, true); |
656 |
QTable::setColumnReadOnly(1, true); |
657 |
// QTable::setColumnReadOnly(2, false); -- of course not. |
658 |
QTable::setColumnStretchable(1, true); |
659 |
} |
660 |
|
661 |
// Default destructor. |
662 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
663 |
{ |
664 |
} |
665 |
|
666 |
|
667 |
// Common parameter table renderer. |
668 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
669 |
bool bEditable ) |
670 |
{ |
671 |
// Always (re)start it empty. |
672 |
QTable::setUpdatesEnabled(false); |
673 |
QTable::setNumRows(0); |
674 |
|
675 |
// Fill the parameter table... |
676 |
QTable::insertRows(0, params.count()); |
677 |
int iRow = 0; |
678 |
qsamplerDeviceParamMap::ConstIterator iter; |
679 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
680 |
const qsamplerDeviceParam& param = iter.data(); |
681 |
bool bEnabled = (bEditable || !param.fix); |
682 |
QTable::setText(iRow, 0, iter.key()); |
683 |
QTable::setText(iRow, 1, param.description); |
684 |
if (param.type == LSCP_TYPE_BOOL) { |
685 |
QStringList opts; |
686 |
opts.append(tr("false")); |
687 |
opts.append(tr("true")); |
688 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
689 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
690 |
pComboItem->setEnabled(bEnabled); |
691 |
QTable::setItem(iRow, 2, pComboItem); |
692 |
} else if (param.possibilities.count() > 0 && bEnabled) { |
693 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
694 |
param.possibilities); |
695 |
pComboItem->setCurrentItem(param.value); |
696 |
pComboItem->setEnabled(bEnabled); |
697 |
pComboItem->setEditable(bEnabled && param.multiplicity); |
698 |
QTable::setItem(iRow, 2, pComboItem); |
699 |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
700 |
&& !param.range_min.isEmpty() |
701 |
&& !param.range_max.isEmpty()) { |
702 |
qsamplerDeviceParamTableSpinBox *pSpinItem = |
703 |
new qsamplerDeviceParamTableSpinBox(this, |
704 |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
705 |
param.value); |
706 |
pSpinItem->setMinValue(param.range_min.toInt()); |
707 |
pSpinItem->setMaxValue(param.range_max.toInt()); |
708 |
QTable::setItem(iRow, 2, pSpinItem); |
709 |
} else { |
710 |
qsamplerDeviceParamTableEditBox *pEditItem = |
711 |
new qsamplerDeviceParamTableEditBox(this, |
712 |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
713 |
param.value); |
714 |
QTable::setItem(iRow, 2, pEditItem); |
715 |
} |
716 |
++iRow; |
717 |
} |
718 |
|
719 |
// Adjust optimal column widths. |
720 |
QTable::adjustColumn(0); |
721 |
QTable::adjustColumn(2); |
722 |
|
723 |
QTable::setUpdatesEnabled(true); |
724 |
QTable::updateContents(); |
725 |
} |
726 |
|
727 |
|
728 |
//------------------------------------------------------------------------- |
729 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
730 |
// |
731 |
|
732 |
// Constructor. |
733 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
734 |
QTable *pTable, EditType editType, const QString& sText ) |
735 |
: QTableItem(pTable, editType, sText) |
736 |
{ |
737 |
m_iValue = sText.toInt(); |
738 |
m_iMinValue = m_iMaxValue = 0; |
739 |
} |
740 |
|
741 |
// Public accessors. |
742 |
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
743 |
{ |
744 |
m_iValue = iValue; |
745 |
QTableItem::setText(QString::number(m_iValue)); |
746 |
} |
747 |
|
748 |
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
749 |
{ |
750 |
m_iMinValue = iMinValue; |
751 |
} |
752 |
|
753 |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
754 |
{ |
755 |
m_iMaxValue = iMaxValue; |
756 |
} |
757 |
|
758 |
// Virtual implemetations. |
759 |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
760 |
{ |
761 |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
762 |
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
763 |
QTableItem::table(), SLOT(doValueChanged())); |
764 |
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
765 |
pSpinBox->setMinValue(m_iMinValue); |
766 |
pSpinBox->setMaxValue(m_iMaxValue); |
767 |
} |
768 |
pSpinBox->setValue(m_iValue); |
769 |
return pSpinBox; |
770 |
} |
771 |
|
772 |
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
773 |
{ |
774 |
if (pWidget->inherits("QSpinBox")) |
775 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
776 |
else |
777 |
QTableItem::setContentFromEditor(pWidget); |
778 |
} |
779 |
|
780 |
|
781 |
//------------------------------------------------------------------------- |
782 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
783 |
// |
784 |
|
785 |
// Constructor. |
786 |
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
787 |
QTable *pTable, EditType editType, const QString& sText ) |
788 |
: QTableItem(pTable, editType, sText) |
789 |
{ |
790 |
} |
791 |
|
792 |
// Virtual implemetations. |
793 |
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
794 |
{ |
795 |
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
796 |
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
797 |
QTableItem::table(), SLOT(doValueChanged())); |
798 |
pEditBox->setText(QTableItem::text()); |
799 |
return pEditBox; |
800 |
} |
801 |
|
802 |
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
803 |
{ |
804 |
if (pWidget->inherits("QLineEdit")) |
805 |
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
806 |
else |
807 |
QTableItem::setContentFromEditor(pWidget); |
808 |
} |
809 |
|
810 |
|
811 |
// end of qsamplerDevice.cpp |