1 |
capela |
426 |
// qsamplerDevice.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
430 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
capela |
426 |
|
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 |
capela |
442 |
#include <qspinbox.h> |
25 |
|
|
#include <qlineedit.h> |
26 |
|
|
|
27 |
capela |
426 |
#include "qsamplerMainForm.h" |
28 |
|
|
#include "qsamplerDeviceForm.h" |
29 |
|
|
|
30 |
|
|
#include "config.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
//------------------------------------------------------------------------- |
34 |
capela |
429 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
35 |
capela |
426 |
// |
36 |
|
|
|
37 |
capela |
429 |
// 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 |
capela |
431 |
return; |
57 |
|
|
|
58 |
|
|
// Info structure field members. |
59 |
|
|
|
60 |
capela |
429 |
type = pParamInfo->type; |
61 |
capela |
431 |
|
62 |
capela |
429 |
if (pParamInfo->description) |
63 |
|
|
description = pParamInfo->description; |
64 |
|
|
else |
65 |
|
|
description = QString::null; |
66 |
capela |
431 |
|
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 |
capela |
429 |
if (pParamInfo->defaultv) |
76 |
|
|
defaultv = pParamInfo->defaultv; |
77 |
|
|
else |
78 |
|
|
defaultv = QString::null; |
79 |
capela |
431 |
|
80 |
capela |
429 |
if (pParamInfo->range_min) |
81 |
capela |
431 |
range_min = pParamInfo->range_min; |
82 |
capela |
429 |
else |
83 |
|
|
range_min = QString::null; |
84 |
capela |
431 |
|
85 |
capela |
429 |
if (pParamInfo->range_max) |
86 |
capela |
431 |
range_max = pParamInfo->range_max; |
87 |
capela |
429 |
else |
88 |
|
|
range_max = QString::null; |
89 |
capela |
431 |
|
90 |
capela |
429 |
possibilities.clear(); |
91 |
capela |
431 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
92 |
|
|
possibilities.append(pParamInfo->possibilities[i]); |
93 |
|
|
|
94 |
|
|
// The current parameter value. |
95 |
capela |
429 |
if (pszValue) |
96 |
capela |
431 |
value = pszValue; |
97 |
capela |
429 |
else |
98 |
|
|
value = QString::null; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
|
102 |
|
|
//------------------------------------------------------------------------- |
103 |
|
|
// qsamplerDevice - MIDI/Audio Device structure. |
104 |
|
|
// |
105 |
|
|
|
106 |
capela |
426 |
// Constructor. |
107 |
capela |
429 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
108 |
|
|
qsamplerDeviceType deviceType, int iDeviceID ) |
109 |
|
|
{ |
110 |
capela |
463 |
m_ports.setAutoDelete(true); |
111 |
|
|
|
112 |
capela |
429 |
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 |
capela |
430 |
// Device id and type should be always set. |
126 |
capela |
462 |
m_iDeviceID = iDeviceID; |
127 |
|
|
m_deviceType = deviceType; |
128 |
capela |
463 |
|
129 |
|
|
// Reset device parameters and ports anyway. |
130 |
|
|
m_params.clear(); |
131 |
|
|
m_ports.clear(); |
132 |
capela |
430 |
|
133 |
|
|
// Retrieve device info, if any. |
134 |
capela |
429 |
lscp_device_info_t *pDeviceInfo = NULL; |
135 |
|
|
switch (deviceType) { |
136 |
capela |
431 |
case qsamplerDevice::Audio: |
137 |
capela |
433 |
m_sDeviceType = QObject::tr("Audio"); |
138 |
capela |
431 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
139 |
|
|
break; |
140 |
|
|
case qsamplerDevice::Midi: |
141 |
capela |
433 |
m_sDeviceType = QObject::tr("MIDI"); |
142 |
capela |
429 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
143 |
|
|
break; |
144 |
capela |
436 |
case qsamplerDevice::None: |
145 |
capela |
433 |
m_sDeviceType = QString::null; |
146 |
|
|
break; |
147 |
capela |
429 |
} |
148 |
capela |
431 |
|
149 |
capela |
430 |
// If we're bogus, bail out... |
150 |
|
|
if (pDeviceInfo == NULL) { |
151 |
|
|
m_sDriverName = QString::null; |
152 |
capela |
452 |
m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType); |
153 |
capela |
431 |
return; |
154 |
capela |
430 |
} |
155 |
capela |
431 |
|
156 |
capela |
430 |
// Other device properties... |
157 |
capela |
429 |
m_sDriverName = pDeviceInfo->driver; |
158 |
capela |
430 |
m_sDeviceName = m_sDriverName + ' ' |
159 |
|
|
+ QObject::tr("Device %1").arg(m_iDeviceID); |
160 |
capela |
429 |
|
161 |
capela |
431 |
// Grab device parameters... |
162 |
capela |
429 |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
163 |
capela |
463 |
const QString sParam = pDeviceInfo->params[i].key; |
164 |
capela |
429 |
lscp_param_info_t *pParamInfo = NULL; |
165 |
|
|
switch (deviceType) { |
166 |
capela |
431 |
case qsamplerDevice::Audio: |
167 |
|
|
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
168 |
capela |
463 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
169 |
capela |
431 |
break; |
170 |
|
|
case qsamplerDevice::Midi: |
171 |
|
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
172 |
capela |
463 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
173 |
capela |
429 |
break; |
174 |
capela |
436 |
case qsamplerDevice::None: |
175 |
|
|
break; |
176 |
capela |
429 |
} |
177 |
capela |
436 |
if (pParamInfo) { |
178 |
capela |
463 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
179 |
capela |
433 |
pDeviceInfo->params[i].value); |
180 |
capela |
436 |
} |
181 |
capela |
429 |
} |
182 |
capela |
463 |
|
183 |
|
|
// Grab port/channel list... |
184 |
|
|
refresh(pClient); |
185 |
capela |
429 |
} |
186 |
|
|
|
187 |
|
|
|
188 |
capela |
462 |
// Driver name initializer/settler. |
189 |
capela |
431 |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
190 |
|
|
const QString& sDriverName ) |
191 |
|
|
{ |
192 |
|
|
// Valid only for scratch devices. |
193 |
|
|
if (m_sDriverName == sDriverName) |
194 |
|
|
return; |
195 |
|
|
|
196 |
capela |
463 |
// Reset device parameters and ports anyway. |
197 |
|
|
m_params.clear(); |
198 |
|
|
m_ports.clear(); |
199 |
|
|
|
200 |
capela |
431 |
// Retrieve driver info, if any. |
201 |
|
|
lscp_driver_info_t *pDriverInfo = NULL; |
202 |
|
|
switch (m_deviceType) { |
203 |
|
|
case qsamplerDevice::Audio: |
204 |
|
|
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
205 |
|
|
sDriverName.latin1()); |
206 |
|
|
break; |
207 |
|
|
case qsamplerDevice::Midi: |
208 |
|
|
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
209 |
|
|
sDriverName.latin1()); |
210 |
|
|
break; |
211 |
capela |
436 |
case qsamplerDevice::None: |
212 |
|
|
break; |
213 |
capela |
431 |
} |
214 |
|
|
|
215 |
|
|
// If we're bogus, bail out... |
216 |
|
|
if (pDriverInfo == NULL) |
217 |
|
|
return; |
218 |
|
|
|
219 |
|
|
// Remember device parameters... |
220 |
|
|
m_sDriverName = sDriverName; |
221 |
|
|
|
222 |
|
|
// Grab driver parameters... |
223 |
|
|
for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) { |
224 |
capela |
463 |
const QString sParam = pDriverInfo->parameters[i]; |
225 |
capela |
431 |
lscp_param_info_t *pParamInfo = NULL; |
226 |
|
|
switch (m_deviceType) { |
227 |
|
|
case qsamplerDevice::Audio: |
228 |
|
|
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
229 |
capela |
463 |
sDriverName.latin1(), sParam.latin1(), NULL); |
230 |
capela |
431 |
break; |
231 |
|
|
case qsamplerDevice::Midi: |
232 |
|
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
233 |
capela |
463 |
sDriverName.latin1(), sParam.latin1(), NULL); |
234 |
capela |
431 |
break; |
235 |
capela |
436 |
case qsamplerDevice::None: |
236 |
|
|
break; |
237 |
capela |
431 |
} |
238 |
capela |
463 |
if (pParamInfo) { |
239 |
|
|
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
240 |
|
|
pParamInfo->defaultv); |
241 |
|
|
} |
242 |
capela |
431 |
} |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
|
246 |
capela |
429 |
// Device property accessors. |
247 |
|
|
int qsamplerDevice::deviceID (void) const |
248 |
|
|
{ |
249 |
|
|
return m_iDeviceID; |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
253 |
|
|
{ |
254 |
|
|
return m_deviceType; |
255 |
|
|
} |
256 |
|
|
|
257 |
capela |
433 |
const QString& qsamplerDevice::deviceTypeName (void) const |
258 |
|
|
{ |
259 |
|
|
return m_sDeviceType; |
260 |
|
|
} |
261 |
|
|
|
262 |
capela |
429 |
const QString& qsamplerDevice::driverName (void) const |
263 |
|
|
{ |
264 |
|
|
return m_sDriverName; |
265 |
|
|
} |
266 |
|
|
|
267 |
|
|
const QString& qsamplerDevice::deviceName (void) const |
268 |
|
|
{ |
269 |
|
|
return m_sDeviceName; |
270 |
|
|
} |
271 |
|
|
|
272 |
capela |
463 |
|
273 |
|
|
// Set the proper device parameter value. |
274 |
|
|
void qsamplerDevice::setParam ( const QString& sParam, |
275 |
|
|
const QString& sValue ) |
276 |
|
|
{ |
277 |
|
|
m_params[sParam.upper()].value = sValue; |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
|
281 |
capela |
429 |
// Device parameter accessor. |
282 |
capela |
462 |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
283 |
capela |
429 |
{ |
284 |
|
|
return m_params; |
285 |
|
|
} |
286 |
|
|
|
287 |
|
|
|
288 |
capela |
463 |
// Device port/channel list accessor. |
289 |
|
|
qsamplerDevicePortList& qsamplerDevice::ports (void) |
290 |
capela |
429 |
{ |
291 |
capela |
463 |
return m_ports; |
292 |
capela |
429 |
} |
293 |
|
|
|
294 |
capela |
462 |
|
295 |
capela |
463 |
// Device port/channel list refreshner. |
296 |
|
|
void qsamplerDevice::refresh ( lscp_client_t *pClient ) |
297 |
|
|
{ |
298 |
|
|
// Port/channel count determination... |
299 |
|
|
int iPorts = 0; |
300 |
|
|
switch (m_deviceType) { |
301 |
|
|
case qsamplerDevice::Audio: |
302 |
|
|
iPorts = m_params["CHANNELS"].value.toInt(); |
303 |
|
|
break; |
304 |
|
|
case qsamplerDevice::Midi: |
305 |
|
|
iPorts = m_params["PORTS"].value.toInt(); |
306 |
|
|
break; |
307 |
|
|
case qsamplerDevice::None: |
308 |
|
|
break; |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
// Retrieve port/channel information... |
312 |
|
|
m_ports.clear(); |
313 |
|
|
for (int iPort = 0; iPort < iPorts; iPort++) |
314 |
|
|
m_ports.append(new qsamplerDevicePort(pClient, *this, iPort)); |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
|
318 |
capela |
430 |
// Device ids enumerator. |
319 |
capela |
429 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
320 |
|
|
qsamplerDeviceType deviceType ) |
321 |
|
|
{ |
322 |
|
|
int *piDeviceIDs = NULL; |
323 |
|
|
switch (deviceType) { |
324 |
capela |
431 |
case qsamplerDevice::Audio: |
325 |
|
|
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
326 |
capela |
429 |
break; |
327 |
capela |
431 |
case qsamplerDevice::Midi: |
328 |
|
|
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
329 |
|
|
break; |
330 |
capela |
436 |
case qsamplerDevice::None: |
331 |
|
|
break; |
332 |
capela |
429 |
} |
333 |
|
|
return piDeviceIDs; |
334 |
|
|
} |
335 |
|
|
|
336 |
capela |
430 |
|
337 |
|
|
// Driver names enumerator. |
338 |
|
|
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
339 |
|
|
qsamplerDeviceType deviceType ) |
340 |
|
|
{ |
341 |
|
|
QStringList drivers; |
342 |
|
|
|
343 |
|
|
const char **ppszDrivers = NULL; |
344 |
|
|
switch (deviceType) { |
345 |
capela |
431 |
case qsamplerDevice::Audio: |
346 |
|
|
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
347 |
capela |
430 |
break; |
348 |
capela |
431 |
case qsamplerDevice::Midi: |
349 |
|
|
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
350 |
|
|
break; |
351 |
capela |
436 |
case qsamplerDevice::None: |
352 |
|
|
break; |
353 |
capela |
430 |
} |
354 |
|
|
|
355 |
capela |
431 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
356 |
|
|
drivers.append(ppszDrivers[iDriver]); |
357 |
capela |
430 |
|
358 |
|
|
return drivers; |
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
|
362 |
capela |
429 |
//------------------------------------------------------------------------- |
363 |
capela |
462 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
364 |
|
|
// |
365 |
|
|
|
366 |
|
|
// Constructor. |
367 |
|
|
qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient, |
368 |
|
|
const qsamplerDevice& device, int iPortID ) |
369 |
|
|
{ |
370 |
|
|
setDevicePort(pClient, device, iPortID); |
371 |
|
|
} |
372 |
|
|
|
373 |
|
|
// Default destructor. |
374 |
|
|
qsamplerDevicePort::~qsamplerDevicePort (void) |
375 |
|
|
{ |
376 |
|
|
} |
377 |
|
|
|
378 |
|
|
|
379 |
|
|
// Initializer. |
380 |
|
|
void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient, |
381 |
|
|
const qsamplerDevice& device, int iPortID ) |
382 |
|
|
{ |
383 |
|
|
// Device port id should be always set. |
384 |
|
|
m_iPortID = iPortID; |
385 |
|
|
|
386 |
capela |
463 |
// Reset port parameters anyway. |
387 |
|
|
m_params.clear(); |
388 |
|
|
|
389 |
capela |
462 |
// Retrieve device port/channel info, if any. |
390 |
capela |
463 |
QString sPrefix = device.driverName() + ' '; |
391 |
capela |
462 |
lscp_device_port_info_t *pPortInfo = NULL; |
392 |
|
|
switch (device.deviceType()) { |
393 |
|
|
case qsamplerDevice::Audio: |
394 |
capela |
463 |
sPrefix += QObject::tr("Channel"); |
395 |
capela |
462 |
pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID); |
396 |
|
|
break; |
397 |
|
|
case qsamplerDevice::Midi: |
398 |
capela |
463 |
sPrefix += QObject::tr("Port"); |
399 |
capela |
462 |
pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID); |
400 |
|
|
break; |
401 |
|
|
case qsamplerDevice::None: |
402 |
|
|
break; |
403 |
|
|
} |
404 |
|
|
|
405 |
|
|
// If we're bogus, bail out... |
406 |
|
|
if (pPortInfo == NULL) { |
407 |
|
|
m_sPortName = QString::null; |
408 |
|
|
return; |
409 |
|
|
} |
410 |
|
|
|
411 |
|
|
// Set device port/channel properties... |
412 |
capela |
463 |
sPrefix += " %1:"; |
413 |
|
|
m_sPortName = sPrefix.arg(m_iPortID) + ' ' + pPortInfo->name; |
414 |
capela |
462 |
|
415 |
|
|
// Grab device port/channel parameters... |
416 |
|
|
m_params.clear(); |
417 |
|
|
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
418 |
capela |
463 |
const QString sParam = pPortInfo->params[i].key; |
419 |
capela |
462 |
lscp_param_info_t *pParamInfo = NULL; |
420 |
|
|
switch (device.deviceType()) { |
421 |
|
|
case qsamplerDevice::Audio: |
422 |
|
|
pParamInfo = ::lscp_get_audio_channel_param_info(pClient, |
423 |
capela |
463 |
device.deviceID(), iPortID, sParam.latin1()); |
424 |
capela |
462 |
break; |
425 |
|
|
case qsamplerDevice::Midi: |
426 |
|
|
pParamInfo = ::lscp_get_midi_port_param_info(pClient, |
427 |
capela |
463 |
device.deviceID(), iPortID, sParam.latin1()); |
428 |
capela |
462 |
break; |
429 |
|
|
case qsamplerDevice::None: |
430 |
|
|
break; |
431 |
|
|
} |
432 |
|
|
if (pParamInfo) { |
433 |
capela |
463 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
434 |
capela |
462 |
pPortInfo->params[i].value); |
435 |
|
|
} |
436 |
|
|
} |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
|
440 |
|
|
// Device port/channel property accessors. |
441 |
|
|
int qsamplerDevicePort::portID (void) const |
442 |
|
|
{ |
443 |
|
|
return m_iPortID; |
444 |
|
|
} |
445 |
|
|
|
446 |
|
|
const QString& qsamplerDevicePort::portName (void) const |
447 |
|
|
{ |
448 |
|
|
return m_sPortName; |
449 |
|
|
} |
450 |
|
|
|
451 |
|
|
// Device port/channel parameter accessor. |
452 |
|
|
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
453 |
|
|
{ |
454 |
|
|
return m_params; |
455 |
|
|
} |
456 |
|
|
|
457 |
|
|
|
458 |
|
|
// Set the proper device port/channel parameter value. |
459 |
|
|
void qsamplerDevicePort::setParam ( const QString& sParam, |
460 |
|
|
const QString& sValue ) |
461 |
|
|
{ |
462 |
capela |
463 |
m_params[sParam.upper()].value = sValue; |
463 |
capela |
462 |
} |
464 |
|
|
|
465 |
|
|
|
466 |
|
|
//------------------------------------------------------------------------- |
467 |
capela |
429 |
// qsamplerDeviceItem - QListView device item. |
468 |
|
|
// |
469 |
|
|
|
470 |
|
|
// Constructors. |
471 |
capela |
433 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
472 |
|
|
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
473 |
capela |
429 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
474 |
|
|
{ |
475 |
|
|
switch(m_device.deviceType()) { |
476 |
capela |
431 |
case qsamplerDevice::Audio: |
477 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
478 |
|
|
QListViewItem::setText(0, QObject::tr("Audio devices")); |
479 |
|
|
break; |
480 |
capela |
431 |
case qsamplerDevice::Midi: |
481 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
482 |
|
|
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
483 |
|
|
break; |
484 |
capela |
436 |
case qsamplerDevice::None: |
485 |
|
|
break; |
486 |
capela |
429 |
} |
487 |
|
|
} |
488 |
|
|
|
489 |
capela |
433 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
490 |
|
|
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
491 |
|
|
int iDeviceID ) |
492 |
capela |
429 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
493 |
|
|
{ |
494 |
|
|
switch(m_device.deviceType()) { |
495 |
capela |
431 |
case qsamplerDevice::Audio: |
496 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
497 |
|
|
break; |
498 |
capela |
431 |
case qsamplerDevice::Midi: |
499 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
500 |
|
|
break; |
501 |
capela |
436 |
case qsamplerDevice::None: |
502 |
|
|
break; |
503 |
capela |
429 |
} |
504 |
|
|
|
505 |
|
|
QListViewItem::setText(0, m_device.deviceName()); |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
// Default destructor. |
509 |
|
|
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
510 |
|
|
{ |
511 |
|
|
} |
512 |
|
|
|
513 |
|
|
// Instance accessors. |
514 |
capela |
431 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
515 |
capela |
429 |
{ |
516 |
|
|
return m_device; |
517 |
|
|
} |
518 |
|
|
|
519 |
|
|
// To virtually distinguish between list view items. |
520 |
|
|
int qsamplerDeviceItem::rtti() const |
521 |
|
|
{ |
522 |
|
|
return QSAMPLER_DEVICE_ITEM; |
523 |
|
|
} |
524 |
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
//------------------------------------------------------------------------- |
528 |
|
|
// qsamplerDeviceParamTable - Device parameter view table. |
529 |
|
|
// |
530 |
|
|
|
531 |
|
|
// Constructor. |
532 |
capela |
433 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
533 |
|
|
const char *pszName ) |
534 |
capela |
426 |
: QTable(pParent, pszName) |
535 |
|
|
{ |
536 |
capela |
428 |
// Set fixed number of columns. |
537 |
capela |
429 |
QTable::setNumCols(3); |
538 |
capela |
428 |
QTable::setShowGrid(false); |
539 |
|
|
QTable::setSorting(false); |
540 |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
541 |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
542 |
|
|
// No vertical header. |
543 |
|
|
QTable::verticalHeader()->hide(); |
544 |
|
|
QTable::setLeftMargin(0); |
545 |
|
|
// Initialize the fixed table column headings. |
546 |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
547 |
capela |
436 |
pHeader->setLabel(0, tr("Parameter")); |
548 |
|
|
pHeader->setLabel(1, tr("Description")); |
549 |
|
|
pHeader->setLabel(2, tr("Value")); |
550 |
capela |
428 |
// Set read-onlyness of each column |
551 |
|
|
QTable::setColumnReadOnly(0, true); |
552 |
capela |
436 |
QTable::setColumnReadOnly(1, true); |
553 |
|
|
// QTable::setColumnReadOnly(2, true); -- of course not. |
554 |
|
|
QTable::setColumnStretchable(1, true); |
555 |
capela |
426 |
} |
556 |
|
|
|
557 |
|
|
// Default destructor. |
558 |
capela |
429 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
559 |
capela |
426 |
{ |
560 |
|
|
} |
561 |
|
|
|
562 |
|
|
|
563 |
capela |
462 |
// Common parameter table renderer. |
564 |
|
|
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
565 |
|
|
bool bEditable ) |
566 |
capela |
429 |
{ |
567 |
|
|
// Always (re)start it empty. |
568 |
capela |
433 |
QTable::setUpdatesEnabled(false); |
569 |
capela |
429 |
QTable::setNumRows(0); |
570 |
|
|
|
571 |
capela |
462 |
// Fill the parameter table... |
572 |
capela |
429 |
QTable::insertRows(0, params.count()); |
573 |
|
|
int iRow = 0; |
574 |
capela |
431 |
qsamplerDeviceParamMap::ConstIterator iter; |
575 |
capela |
429 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
576 |
capela |
432 |
const qsamplerDeviceParam& param = iter.data(); |
577 |
capela |
462 |
bool bEnabled = (bEditable || !param.fix); |
578 |
capela |
436 |
QTable::setText(iRow, 0, iter.key()); |
579 |
|
|
QTable::setText(iRow, 1, param.description); |
580 |
capela |
462 |
if (param.type == LSCP_TYPE_BOOL) { |
581 |
capela |
432 |
QStringList opts; |
582 |
capela |
463 |
opts.append(tr("false")); |
583 |
|
|
opts.append(tr("true")); |
584 |
capela |
432 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
585 |
capela |
448 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
586 |
|
|
pComboItem->setEnabled(bEnabled); |
587 |
capela |
436 |
QTable::setItem(iRow, 2, pComboItem); |
588 |
capela |
451 |
} else if (param.possibilities.count() > 0 && bEnabled) { |
589 |
capela |
432 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
590 |
|
|
param.possibilities); |
591 |
capela |
448 |
pComboItem->setCurrentItem(param.value); |
592 |
|
|
pComboItem->setEnabled(bEnabled); |
593 |
|
|
pComboItem->setEditable(bEnabled && param.multiplicity); |
594 |
capela |
436 |
QTable::setItem(iRow, 2, pComboItem); |
595 |
capela |
451 |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
596 |
capela |
448 |
&& !param.range_min.isEmpty() |
597 |
|
|
&& !param.range_max.isEmpty()) { |
598 |
|
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
599 |
capela |
442 |
new qsamplerDeviceParamTableSpinBox(this, |
600 |
capela |
448 |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
601 |
capela |
447 |
param.value); |
602 |
capela |
448 |
pSpinItem->setMinValue(param.range_min.toInt()); |
603 |
|
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
604 |
capela |
442 |
QTable::setItem(iRow, 2, pSpinItem); |
605 |
capela |
432 |
} else { |
606 |
capela |
448 |
qsamplerDeviceParamTableEditBox *pEditItem = |
607 |
capela |
442 |
new qsamplerDeviceParamTableEditBox(this, |
608 |
capela |
448 |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
609 |
capela |
442 |
param.value); |
610 |
|
|
QTable::setItem(iRow, 2, pEditItem); |
611 |
capela |
432 |
} |
612 |
capela |
431 |
++iRow; |
613 |
capela |
429 |
} |
614 |
|
|
|
615 |
capela |
433 |
// Adjust optimal column widths. |
616 |
capela |
436 |
QTable::adjustColumn(0); |
617 |
capela |
433 |
QTable::adjustColumn(2); |
618 |
capela |
436 |
|
619 |
capela |
433 |
QTable::setUpdatesEnabled(true); |
620 |
|
|
QTable::updateContents(); |
621 |
capela |
429 |
} |
622 |
|
|
|
623 |
|
|
|
624 |
capela |
442 |
//------------------------------------------------------------------------- |
625 |
|
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
626 |
|
|
// |
627 |
|
|
|
628 |
|
|
// Constructor. |
629 |
|
|
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
630 |
capela |
447 |
QTable *pTable, EditType editType, const QString& sText ) |
631 |
|
|
: QTableItem(pTable, editType, sText) |
632 |
capela |
442 |
{ |
633 |
capela |
448 |
m_iValue = sText.toInt(); |
634 |
|
|
m_iMinValue = m_iMaxValue = 0; |
635 |
capela |
442 |
} |
636 |
|
|
|
637 |
|
|
// Public accessors. |
638 |
|
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
639 |
|
|
{ |
640 |
|
|
m_iValue = iValue; |
641 |
|
|
QTableItem::setText(QString::number(m_iValue)); |
642 |
|
|
} |
643 |
|
|
|
644 |
|
|
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
645 |
|
|
{ |
646 |
|
|
m_iMinValue = iMinValue; |
647 |
|
|
} |
648 |
|
|
|
649 |
|
|
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
650 |
|
|
{ |
651 |
|
|
m_iMaxValue = iMaxValue; |
652 |
|
|
} |
653 |
|
|
|
654 |
|
|
// Virtual implemetations. |
655 |
|
|
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
656 |
|
|
{ |
657 |
|
|
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
658 |
|
|
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
659 |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
660 |
|
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
661 |
|
|
pSpinBox->setMinValue(m_iMinValue); |
662 |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
663 |
|
|
} |
664 |
|
|
pSpinBox->setValue(m_iValue); |
665 |
|
|
return pSpinBox; |
666 |
|
|
} |
667 |
|
|
|
668 |
|
|
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
669 |
|
|
{ |
670 |
|
|
if (pWidget->inherits("QSpinBox")) |
671 |
capela |
448 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
672 |
capela |
442 |
else |
673 |
capela |
448 |
QTableItem::setContentFromEditor(pWidget); |
674 |
capela |
442 |
} |
675 |
|
|
|
676 |
|
|
|
677 |
|
|
//------------------------------------------------------------------------- |
678 |
|
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
679 |
|
|
// |
680 |
|
|
|
681 |
|
|
// Constructor. |
682 |
|
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
683 |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
684 |
|
|
: QTableItem(pTable, editType, sText) |
685 |
|
|
{ |
686 |
|
|
} |
687 |
|
|
|
688 |
|
|
// Virtual implemetations. |
689 |
|
|
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
690 |
|
|
{ |
691 |
|
|
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
692 |
|
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
693 |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
694 |
|
|
pEditBox->setText(QTableItem::text()); |
695 |
|
|
return pEditBox; |
696 |
|
|
} |
697 |
|
|
|
698 |
|
|
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
699 |
|
|
{ |
700 |
|
|
if (pWidget->inherits("QLineEdit")) |
701 |
capela |
448 |
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
702 |
capela |
442 |
else |
703 |
capela |
448 |
QTableItem::setContentFromEditor(pWidget); |
704 |
capela |
442 |
} |
705 |
|
|
|
706 |
|
|
|
707 |
capela |
426 |
// end of qsamplerDevice.cpp |