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 |
|
|
#include "qsamplerMainForm.h" |
25 |
|
|
#include "qsamplerDeviceForm.h" |
26 |
|
|
|
27 |
|
|
#include "config.h" |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
//------------------------------------------------------------------------- |
31 |
capela |
429 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
32 |
capela |
426 |
// |
33 |
|
|
|
34 |
capela |
429 |
// Constructors. |
35 |
|
|
qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo, |
36 |
|
|
const char *pszValue ) |
37 |
|
|
{ |
38 |
|
|
setParam(pParamInfo, pszValue); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
// Default destructor. |
43 |
|
|
qsamplerDeviceParam::~qsamplerDeviceParam (void) |
44 |
|
|
{ |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
// Initializer. |
49 |
|
|
void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
50 |
|
|
const char *pszValue ) |
51 |
|
|
{ |
52 |
|
|
if (pParamInfo == NULL) |
53 |
capela |
431 |
return; |
54 |
|
|
|
55 |
|
|
// Info structure field members. |
56 |
|
|
|
57 |
capela |
429 |
type = pParamInfo->type; |
58 |
capela |
431 |
|
59 |
capela |
429 |
if (pParamInfo->description) |
60 |
|
|
description = pParamInfo->description; |
61 |
|
|
else |
62 |
|
|
description = QString::null; |
63 |
capela |
431 |
|
64 |
|
|
mandatory = (bool) pParamInfo->multiplicity; |
65 |
|
|
fix = (bool) pParamInfo->fix; |
66 |
|
|
multiplicity = (bool) pParamInfo->multiplicity; |
67 |
|
|
|
68 |
|
|
depends.clear(); |
69 |
|
|
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
70 |
|
|
depends.append(pParamInfo->depends[i]); |
71 |
|
|
|
72 |
capela |
429 |
if (pParamInfo->defaultv) |
73 |
|
|
defaultv = pParamInfo->defaultv; |
74 |
|
|
else |
75 |
|
|
defaultv = QString::null; |
76 |
capela |
431 |
|
77 |
capela |
429 |
if (pParamInfo->range_min) |
78 |
capela |
431 |
range_min = pParamInfo->range_min; |
79 |
capela |
429 |
else |
80 |
|
|
range_min = QString::null; |
81 |
capela |
431 |
|
82 |
capela |
429 |
if (pParamInfo->range_max) |
83 |
capela |
431 |
range_max = pParamInfo->range_max; |
84 |
capela |
429 |
else |
85 |
|
|
range_max = QString::null; |
86 |
capela |
431 |
|
87 |
capela |
429 |
possibilities.clear(); |
88 |
capela |
431 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
89 |
|
|
possibilities.append(pParamInfo->possibilities[i]); |
90 |
|
|
|
91 |
|
|
// The current parameter value. |
92 |
capela |
429 |
if (pszValue) |
93 |
capela |
431 |
value = pszValue; |
94 |
capela |
429 |
else |
95 |
|
|
value = QString::null; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
//------------------------------------------------------------------------- |
100 |
|
|
// qsamplerDevice - MIDI/Audio Device structure. |
101 |
|
|
// |
102 |
|
|
|
103 |
capela |
426 |
// Constructor. |
104 |
capela |
429 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
105 |
|
|
qsamplerDeviceType deviceType, int iDeviceID ) |
106 |
|
|
{ |
107 |
|
|
setDevice(pClient, deviceType, iDeviceID); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
// Default destructor. |
111 |
|
|
qsamplerDevice::~qsamplerDevice (void) |
112 |
|
|
{ |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
|
116 |
|
|
// Initializer. |
117 |
|
|
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
118 |
|
|
qsamplerDeviceType deviceType, int iDeviceID ) |
119 |
|
|
{ |
120 |
capela |
430 |
// Device id and type should be always set. |
121 |
|
|
m_iDeviceID = iDeviceID; |
122 |
|
|
m_deviceType = deviceType; |
123 |
|
|
|
124 |
|
|
// Retrieve device info, if any. |
125 |
capela |
429 |
lscp_device_info_t *pDeviceInfo = NULL; |
126 |
|
|
switch (deviceType) { |
127 |
capela |
431 |
case qsamplerDevice::Audio: |
128 |
capela |
433 |
m_sDeviceType = QObject::tr("Audio"); |
129 |
capela |
431 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
130 |
|
|
break; |
131 |
|
|
case qsamplerDevice::Midi: |
132 |
capela |
433 |
m_sDeviceType = QObject::tr("MIDI"); |
133 |
capela |
429 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
134 |
|
|
break; |
135 |
capela |
433 |
default: |
136 |
|
|
m_sDeviceType = QString::null; |
137 |
|
|
break; |
138 |
capela |
429 |
} |
139 |
capela |
431 |
|
140 |
capela |
430 |
// If we're bogus, bail out... |
141 |
|
|
if (pDeviceInfo == NULL) { |
142 |
|
|
m_sDriverName = QString::null; |
143 |
capela |
433 |
m_sDeviceName = QObject::tr("New device"); |
144 |
capela |
431 |
return; |
145 |
capela |
430 |
} |
146 |
capela |
431 |
|
147 |
capela |
430 |
// Other device properties... |
148 |
capela |
429 |
m_sDriverName = pDeviceInfo->driver; |
149 |
capela |
430 |
m_sDeviceName = m_sDriverName + ' ' |
150 |
|
|
+ QObject::tr("Device %1").arg(m_iDeviceID); |
151 |
capela |
429 |
|
152 |
capela |
431 |
// Grab device parameters... |
153 |
capela |
429 |
m_params.clear(); |
154 |
|
|
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
155 |
|
|
const char *pszParam = pDeviceInfo->params[i].key; |
156 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
157 |
|
|
switch (deviceType) { |
158 |
capela |
431 |
case qsamplerDevice::Audio: |
159 |
|
|
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
160 |
capela |
429 |
m_sDriverName.latin1(), pszParam, NULL); |
161 |
capela |
431 |
break; |
162 |
|
|
case qsamplerDevice::Midi: |
163 |
|
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
164 |
capela |
429 |
m_sDriverName.latin1(), pszParam, NULL); |
165 |
|
|
break; |
166 |
|
|
} |
167 |
capela |
433 |
if (pParamInfo) |
168 |
|
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, |
169 |
|
|
pDeviceInfo->params[i].value); |
170 |
capela |
429 |
} |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
|
174 |
capela |
431 |
// Driver name initializer. |
175 |
|
|
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
176 |
|
|
const QString& sDriverName ) |
177 |
|
|
{ |
178 |
|
|
// Valid only for scratch devices. |
179 |
|
|
if (m_sDriverName == sDriverName) |
180 |
|
|
return; |
181 |
|
|
|
182 |
|
|
// Retrieve driver info, if any. |
183 |
|
|
lscp_driver_info_t *pDriverInfo = NULL; |
184 |
|
|
switch (m_deviceType) { |
185 |
|
|
case qsamplerDevice::Audio: |
186 |
|
|
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
187 |
|
|
sDriverName.latin1()); |
188 |
|
|
break; |
189 |
|
|
case qsamplerDevice::Midi: |
190 |
|
|
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
191 |
|
|
sDriverName.latin1()); |
192 |
|
|
break; |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
// If we're bogus, bail out... |
196 |
|
|
if (pDriverInfo == NULL) |
197 |
|
|
return; |
198 |
|
|
|
199 |
|
|
// Remember device parameters... |
200 |
|
|
m_sDriverName = sDriverName; |
201 |
|
|
|
202 |
|
|
// Grab driver parameters... |
203 |
|
|
m_params.clear(); |
204 |
|
|
for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) { |
205 |
|
|
const char *pszParam = pDriverInfo->parameters[i]; |
206 |
|
|
lscp_param_info_t *pParamInfo = NULL; |
207 |
|
|
switch (m_deviceType) { |
208 |
|
|
case qsamplerDevice::Audio: |
209 |
|
|
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
210 |
|
|
sDriverName.latin1(), pszParam, NULL); |
211 |
|
|
break; |
212 |
|
|
case qsamplerDevice::Midi: |
213 |
|
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
214 |
|
|
sDriverName.latin1(), pszParam, NULL); |
215 |
|
|
break; |
216 |
|
|
} |
217 |
|
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pParamInfo->defaultv); |
218 |
|
|
} |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
|
222 |
capela |
429 |
// Device property accessors. |
223 |
|
|
int qsamplerDevice::deviceID (void) const |
224 |
|
|
{ |
225 |
|
|
return m_iDeviceID; |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
229 |
|
|
{ |
230 |
|
|
return m_deviceType; |
231 |
|
|
} |
232 |
|
|
|
233 |
capela |
433 |
const QString& qsamplerDevice::deviceTypeName (void) const |
234 |
|
|
{ |
235 |
|
|
return m_sDeviceType; |
236 |
|
|
} |
237 |
|
|
|
238 |
capela |
429 |
const QString& qsamplerDevice::driverName (void) const |
239 |
|
|
{ |
240 |
|
|
return m_sDriverName; |
241 |
|
|
} |
242 |
|
|
|
243 |
|
|
const QString& qsamplerDevice::deviceName (void) const |
244 |
|
|
{ |
245 |
|
|
return m_sDeviceName; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
// Device parameter accessor. |
249 |
|
|
qsamplerDeviceParamMap& qsamplerDevice::params (void) |
250 |
|
|
{ |
251 |
|
|
return m_params; |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
|
255 |
|
|
// Update/refresh device/driver data. |
256 |
|
|
void qsamplerDevice::refresh (void) |
257 |
|
|
{ |
258 |
|
|
} |
259 |
|
|
|
260 |
capela |
430 |
// Device ids enumerator. |
261 |
capela |
429 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
262 |
|
|
qsamplerDeviceType deviceType ) |
263 |
|
|
{ |
264 |
|
|
int *piDeviceIDs = NULL; |
265 |
|
|
switch (deviceType) { |
266 |
capela |
431 |
case qsamplerDevice::Audio: |
267 |
|
|
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
268 |
capela |
429 |
break; |
269 |
capela |
431 |
case qsamplerDevice::Midi: |
270 |
|
|
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
271 |
|
|
break; |
272 |
capela |
429 |
} |
273 |
|
|
return piDeviceIDs; |
274 |
|
|
} |
275 |
|
|
|
276 |
capela |
430 |
|
277 |
|
|
// Driver names enumerator. |
278 |
|
|
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
279 |
|
|
qsamplerDeviceType deviceType ) |
280 |
|
|
{ |
281 |
|
|
QStringList drivers; |
282 |
|
|
|
283 |
|
|
const char **ppszDrivers = NULL; |
284 |
|
|
switch (deviceType) { |
285 |
capela |
431 |
case qsamplerDevice::Audio: |
286 |
|
|
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
287 |
capela |
430 |
break; |
288 |
capela |
431 |
case qsamplerDevice::Midi: |
289 |
|
|
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
290 |
|
|
break; |
291 |
capela |
430 |
} |
292 |
|
|
|
293 |
capela |
431 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
294 |
|
|
drivers.append(ppszDrivers[iDriver]); |
295 |
capela |
430 |
|
296 |
|
|
return drivers; |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
|
300 |
capela |
429 |
//------------------------------------------------------------------------- |
301 |
|
|
// qsamplerDeviceItem - QListView device item. |
302 |
|
|
// |
303 |
|
|
|
304 |
|
|
// Constructors. |
305 |
capela |
433 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
306 |
|
|
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
307 |
capela |
429 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
308 |
|
|
{ |
309 |
|
|
switch(m_device.deviceType()) { |
310 |
capela |
431 |
case qsamplerDevice::Audio: |
311 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
312 |
|
|
QListViewItem::setText(0, QObject::tr("Audio devices")); |
313 |
|
|
break; |
314 |
capela |
431 |
case qsamplerDevice::Midi: |
315 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
316 |
|
|
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
317 |
|
|
break; |
318 |
|
|
} |
319 |
|
|
} |
320 |
|
|
|
321 |
capela |
433 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
322 |
|
|
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
323 |
|
|
int iDeviceID ) |
324 |
capela |
429 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
325 |
|
|
{ |
326 |
|
|
switch(m_device.deviceType()) { |
327 |
capela |
431 |
case qsamplerDevice::Audio: |
328 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
329 |
|
|
break; |
330 |
capela |
431 |
case qsamplerDevice::Midi: |
331 |
capela |
429 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
332 |
|
|
break; |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
QListViewItem::setText(0, m_device.deviceName()); |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
// Default destructor. |
339 |
|
|
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
340 |
|
|
{ |
341 |
|
|
} |
342 |
|
|
|
343 |
|
|
// Instance accessors. |
344 |
capela |
431 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
345 |
capela |
429 |
{ |
346 |
|
|
return m_device; |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
// To virtually distinguish between list view items. |
350 |
|
|
int qsamplerDeviceItem::rtti() const |
351 |
|
|
{ |
352 |
|
|
return QSAMPLER_DEVICE_ITEM; |
353 |
|
|
} |
354 |
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
|
|
//------------------------------------------------------------------------- |
358 |
|
|
// qsamplerDeviceParamTable - Device parameter view table. |
359 |
|
|
// |
360 |
|
|
|
361 |
|
|
// Constructor. |
362 |
capela |
433 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
363 |
|
|
const char *pszName ) |
364 |
capela |
426 |
: QTable(pParent, pszName) |
365 |
|
|
{ |
366 |
capela |
428 |
// Set fixed number of columns. |
367 |
capela |
429 |
QTable::setNumCols(3); |
368 |
capela |
428 |
QTable::setShowGrid(false); |
369 |
|
|
QTable::setSorting(false); |
370 |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
371 |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
372 |
|
|
// No vertical header. |
373 |
|
|
QTable::verticalHeader()->hide(); |
374 |
|
|
QTable::setLeftMargin(0); |
375 |
|
|
// Initialize the fixed table column headings. |
376 |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
377 |
capela |
432 |
pHeader->setLabel(0, tr("Description")); |
378 |
capela |
431 |
pHeader->setLabel(1, tr("Value")); |
379 |
capela |
432 |
pHeader->setLabel(2, tr("Parameter")); |
380 |
capela |
428 |
// Set read-onlyness of each column |
381 |
|
|
QTable::setColumnReadOnly(0, true); |
382 |
capela |
431 |
// QTable::setColumnReadOnly(1, true); -- of course not. |
383 |
|
|
QTable::setColumnReadOnly(2, true); |
384 |
capela |
432 |
QTable::setColumnStretchable(0, true); |
385 |
capela |
426 |
} |
386 |
|
|
|
387 |
|
|
// Default destructor. |
388 |
capela |
429 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
389 |
capela |
426 |
{ |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
|
393 |
capela |
429 |
// The main table refresher. |
394 |
capela |
431 |
void qsamplerDeviceParamTable::refresh ( qsamplerDevice& device ) |
395 |
capela |
429 |
{ |
396 |
|
|
// Always (re)start it empty. |
397 |
capela |
433 |
QTable::setUpdatesEnabled(false); |
398 |
capela |
429 |
QTable::setNumRows(0); |
399 |
|
|
|
400 |
|
|
// Now fill the parameter table... |
401 |
capela |
431 |
qsamplerDeviceParamMap& params = device.params(); |
402 |
capela |
429 |
QTable::insertRows(0, params.count()); |
403 |
|
|
int iRow = 0; |
404 |
capela |
431 |
qsamplerDeviceParamMap::ConstIterator iter; |
405 |
capela |
429 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
406 |
capela |
432 |
const qsamplerDeviceParam& param = iter.data(); |
407 |
capela |
434 |
bool fEnabled = (device.deviceID() < 0 || !param.fix); |
408 |
capela |
432 |
QTable::setText(iRow, 0, param.description); |
409 |
|
|
if (param.type == LSCP_TYPE_BOOL) { |
410 |
|
|
QStringList opts; |
411 |
|
|
opts.append(tr("false")); |
412 |
|
|
opts.append(tr("true")); |
413 |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
414 |
|
|
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
415 |
capela |
433 |
pComboItem->setEnabled(fEnabled); |
416 |
capela |
432 |
QTable::setItem(iRow, 1, pComboItem); |
417 |
capela |
433 |
} else if (param.possibilities.count() > 0 && !param.multiplicity) { |
418 |
capela |
432 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
419 |
|
|
param.possibilities); |
420 |
|
|
pComboItem->setCurrentItem(param.value); |
421 |
capela |
433 |
pComboItem->setEnabled(fEnabled); |
422 |
capela |
432 |
QTable::setItem(iRow, 1, pComboItem); |
423 |
|
|
} else { |
424 |
|
|
QTableItem* pTableItem = new QTableItem(this, |
425 |
capela |
433 |
fEnabled ? QTableItem::Never : QTableItem::OnTyping, |
426 |
capela |
432 |
param.value); |
427 |
|
|
QTable::setItem(iRow, 1, pTableItem); |
428 |
|
|
} |
429 |
|
|
QTable::setText(iRow, 2, iter.key()); |
430 |
capela |
431 |
++iRow; |
431 |
capela |
429 |
} |
432 |
|
|
|
433 |
capela |
433 |
// Adjust optimal column widths. |
434 |
|
|
QTable::adjustColumn(1); |
435 |
|
|
QTable::adjustColumn(2); |
436 |
|
|
|
437 |
|
|
QTable::setUpdatesEnabled(true); |
438 |
|
|
QTable::updateContents(); |
439 |
capela |
429 |
} |
440 |
|
|
|
441 |
|
|
|
442 |
capela |
426 |
// end of qsamplerDevice.cpp |