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