1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
21 |
|
|
22 |
#include "qsamplerDevice.h" |
#include "qsamplerDevice.h" |
23 |
|
|
24 |
|
#include <qspinbox.h> |
25 |
|
#include <qlineedit.h> |
26 |
|
|
27 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
28 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
29 |
|
|
53 |
const char *pszValue ) |
const char *pszValue ) |
54 |
{ |
{ |
55 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
56 |
return; |
return; |
57 |
|
|
58 |
// Info structure field members. |
// Info structure field members. |
59 |
|
|
60 |
type = pParamInfo->type; |
type = pParamInfo->type; |
61 |
|
|
62 |
if (pParamInfo->description) |
if (pParamInfo->description) |
63 |
description = pParamInfo->description; |
description = pParamInfo->description; |
64 |
else |
else |
65 |
description = QString::null; |
description = QString::null; |
66 |
|
|
67 |
mandatory = (bool) pParamInfo->multiplicity; |
mandatory = (bool) pParamInfo->multiplicity; |
68 |
fix = (bool) pParamInfo->fix; |
fix = (bool) pParamInfo->fix; |
69 |
multiplicity = (bool) pParamInfo->multiplicity; |
multiplicity = (bool) pParamInfo->multiplicity; |
70 |
|
|
71 |
depends.clear(); |
depends.clear(); |
72 |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
73 |
depends.append(pParamInfo->depends[i]); |
depends.append(pParamInfo->depends[i]); |
74 |
|
|
75 |
if (pParamInfo->defaultv) |
if (pParamInfo->defaultv) |
76 |
defaultv = pParamInfo->defaultv; |
defaultv = pParamInfo->defaultv; |
77 |
else |
else |
78 |
defaultv = QString::null; |
defaultv = QString::null; |
79 |
|
|
80 |
if (pParamInfo->range_min) |
if (pParamInfo->range_min) |
81 |
range_min = pParamInfo->range_min; |
range_min = pParamInfo->range_min; |
82 |
else |
else |
83 |
range_min = QString::null; |
range_min = QString::null; |
84 |
|
|
85 |
if (pParamInfo->range_max) |
if (pParamInfo->range_max) |
86 |
range_max = pParamInfo->range_max; |
range_max = pParamInfo->range_max; |
87 |
else |
else |
88 |
range_max = QString::null; |
range_max = QString::null; |
89 |
|
|
90 |
possibilities.clear(); |
possibilities.clear(); |
91 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
92 |
possibilities.append(pParamInfo->possibilities[i]); |
possibilities.append(pParamInfo->possibilities[i]); |
93 |
|
|
94 |
// The current parameter value. |
// The current parameter value. |
95 |
if (pszValue) |
if (pszValue) |
96 |
value = pszValue; |
value = pszValue; |
97 |
else |
else |
98 |
value = QString::null; |
value = QString::null; |
99 |
} |
} |
107 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
108 |
qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDeviceType deviceType, int iDeviceID ) |
109 |
{ |
{ |
110 |
|
m_ports.setAutoDelete(true); |
111 |
|
|
112 |
setDevice(pClient, deviceType, iDeviceID); |
setDevice(pClient, deviceType, iDeviceID); |
113 |
} |
} |
114 |
|
|
122 |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
123 |
qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDeviceType deviceType, int iDeviceID ) |
124 |
{ |
{ |
125 |
if (pClient == NULL || iDeviceID < 0) |
// Device id and type should be always set. |
126 |
return; |
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; |
lscp_device_info_t *pDeviceInfo = NULL; |
135 |
switch (deviceType) { |
switch (deviceType) { |
136 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
137 |
m_sDeviceName = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
138 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
139 |
break; |
break; |
140 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
141 |
m_sDeviceName = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
142 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
143 |
break; |
break; |
144 |
|
case qsamplerDevice::None: |
145 |
|
m_sDeviceType = QString::null; |
146 |
|
break; |
147 |
} |
} |
|
if (pDeviceInfo == NULL) |
|
|
return; |
|
148 |
|
|
149 |
// Device properties... |
// If we're bogus, bail out... |
150 |
m_iDeviceID = iDeviceID; |
if (pDeviceInfo == NULL) { |
151 |
m_deviceType = deviceType; |
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; |
m_sDriverName = pDeviceInfo->driver; |
158 |
|
m_sDeviceName = m_sDriverName + ' ' |
159 |
// Complete fake device name... |
+ QObject::tr("Device %1").arg(m_iDeviceID); |
|
m_sDeviceName += ' ' + m_sDriverName + ' '; |
|
|
m_sDeviceName += QObject::tr("Device %1").arg(m_iDeviceID); |
|
160 |
|
|
161 |
// Grab device/driver parameters... |
// Grab device parameters... |
|
m_params.clear(); |
|
162 |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
163 |
const char *pszParam = pDeviceInfo->params[i].key; |
const QString sParam = pDeviceInfo->params[i].key; |
164 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
165 |
switch (deviceType) { |
switch (deviceType) { |
166 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
167 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
168 |
m_sDriverName.latin1(), pszParam, NULL); |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
169 |
break; |
break; |
170 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
171 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
172 |
m_sDriverName.latin1(), pszParam, NULL); |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
173 |
break; |
break; |
174 |
|
case qsamplerDevice::None: |
175 |
|
break; |
176 |
|
} |
177 |
|
if (pParamInfo) { |
178 |
|
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
179 |
|
pDeviceInfo->params[i].value); |
180 |
} |
} |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pDeviceInfo->params[i].value); |
|
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 |
|
|
261 |
return m_deviceType; |
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 |
const QString& qsamplerDevice::driverName (void) const |
270 |
{ |
{ |
271 |
return m_sDriverName; |
return m_sDriverName; |
276 |
return m_sDeviceName; |
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. |
// Device parameter accessor. |
289 |
qsamplerDeviceParamMap& qsamplerDevice::params (void) |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
290 |
{ |
{ |
291 |
return m_params; |
return m_params; |
292 |
} |
} |
293 |
|
|
294 |
|
|
295 |
// Update/refresh device/driver data. |
// Device port/channel list accessor. |
296 |
void qsamplerDevice::refresh (void) |
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 |
// Device enumerator. |
|
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, |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
424 |
qsamplerDeviceType deviceType ) |
qsamplerDeviceType deviceType ) |
425 |
{ |
{ |
426 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
427 |
switch (deviceType) { |
switch (deviceType) { |
428 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
429 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
430 |
break; |
break; |
431 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
432 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
433 |
|
break; |
434 |
|
case qsamplerDevice::None: |
435 |
break; |
break; |
436 |
} |
} |
437 |
return piDeviceIDs; |
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. |
// qsamplerDeviceItem - QListView device item. |
572 |
// |
// |
573 |
|
|
574 |
// Constructors. |
// Constructors. |
575 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
576 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
577 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
: QListViewItem(pListView), m_device(pClient, deviceType) |
578 |
{ |
{ |
579 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
580 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
581 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
582 |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
583 |
break; |
break; |
584 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
585 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
586 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
587 |
break; |
break; |
588 |
|
case qsamplerDevice::None: |
589 |
|
break; |
590 |
} |
} |
591 |
} |
} |
592 |
|
|
593 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
594 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
595 |
|
int iDeviceID ) |
596 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
597 |
{ |
{ |
598 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
599 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
600 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
601 |
break; |
break; |
602 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
603 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
604 |
break; |
break; |
605 |
|
case qsamplerDevice::None: |
606 |
|
break; |
607 |
} |
} |
608 |
|
|
609 |
QListViewItem::setText(0, m_device.deviceName()); |
QListViewItem::setText(0, m_device.deviceName()); |
615 |
} |
} |
616 |
|
|
617 |
// Instance accessors. |
// Instance accessors. |
618 |
const qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device (void) |
619 |
{ |
{ |
620 |
return m_device; |
return m_device; |
621 |
} |
} |
633 |
// |
// |
634 |
|
|
635 |
// Constructor. |
// Constructor. |
636 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, const char *pszName ) |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
637 |
|
const char *pszName ) |
638 |
: QTable(pParent, pszName) |
: QTable(pParent, pszName) |
639 |
{ |
{ |
|
m_pClient = NULL; |
|
|
m_iDeviceID = -1; |
|
|
|
|
640 |
// Set fixed number of columns. |
// Set fixed number of columns. |
641 |
QTable::setNumCols(3); |
QTable::setNumCols(3); |
642 |
QTable::setShowGrid(false); |
QTable::setShowGrid(false); |
654 |
// Set read-onlyness of each column |
// Set read-onlyness of each column |
655 |
QTable::setColumnReadOnly(0, true); |
QTable::setColumnReadOnly(0, true); |
656 |
QTable::setColumnReadOnly(1, true); |
QTable::setColumnReadOnly(1, true); |
657 |
// QTable::setColumnReadOnly(2, true); -- of course not. |
// QTable::setColumnReadOnly(2, false); -- of course not. |
658 |
|
QTable::setColumnStretchable(1, true); |
659 |
} |
} |
660 |
|
|
661 |
// Default destructor. |
// Default destructor. |
664 |
} |
} |
665 |
|
|
666 |
|
|
667 |
// Client/device descriptor selector. |
// Common parameter table renderer. |
668 |
void qsamplerDeviceParamTable::setDevice ( lscp_client_t *pClient, |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
669 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID ) |
bool bEditable ) |
670 |
{ |
{ |
671 |
if (m_pClient |
// Always (re)start it empty. |
672 |
&& m_pClient == pClient |
QTable::setUpdatesEnabled(false); |
673 |
&& m_deviceType == deviceType |
QTable::setNumRows(0); |
674 |
&& m_iDeviceID == iDeviceID) |
|
675 |
return; |
// Fill the parameter table... |
676 |
|
QTable::insertRows(0, params.count()); |
677 |
m_pClient = pClient; |
int iRow = 0; |
678 |
m_deviceType = deviceType; |
qsamplerDeviceParamMap::ConstIterator iter; |
679 |
m_iDeviceID = iDeviceID; |
for (iter = params.begin(); iter != params.end(); ++iter) { |
680 |
|
const qsamplerDeviceParam& param = iter.data(); |
681 |
refresh(); |
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 |
// Client/device descriptor accessors. |
//------------------------------------------------------------------------- |
729 |
lscp_client_t *qsamplerDeviceParamTable::client (void) |
// 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 |
return m_pClient; |
m_iValue = sText.toInt(); |
738 |
|
m_iMinValue = m_iMaxValue = 0; |
739 |
} |
} |
740 |
|
|
741 |
int qsamplerDeviceParamTable::deviceID (void) |
// Public accessors. |
742 |
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
743 |
{ |
{ |
744 |
return m_iDeviceID; |
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 |
// The main table refresher. |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
|
void qsamplerDeviceParamTable::refresh (void) |
|
754 |
{ |
{ |
755 |
// Always (re)start it empty. |
m_iMaxValue = iMaxValue; |
756 |
QTable::setNumRows(0); |
} |
757 |
|
|
758 |
if (m_pClient == NULL) |
// Virtual implemetations. |
759 |
return; |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
760 |
|
{ |
761 |
// Construct the local device object here. |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
762 |
qsamplerDevice device(m_pClient, m_deviceType, m_iDeviceID); |
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 |
|
|
|
// Now fill the parameter table... |
|
|
QHeader *pHeader = QTable::verticalHeader(); |
|
|
qsamplerDeviceParamMap& params = device.params(); |
|
|
QTable::insertRows(0, params.count()); |
|
|
int iRow = 0; |
|
|
qsamplerDeviceParamMap::Iterator iter; |
|
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
|
|
QTable::setText(iRow, 0, iter.key()); |
|
|
QTable::setText(iRow, 1, iter.data().description); |
|
|
QTable::setText(iRow, 2, iter.data().value); |
|
|
++iRow; |
|
|
} |
|
780 |
|
|
781 |
// Adjust optimal column width. |
//------------------------------------------------------------------------- |
782 |
for (int iCol = 0; iCol < QTable::numCols(); iCol++) |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
783 |
QTable::adjustColumn(iCol); |
// |
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 |
|
|