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 |
50 |
const char *pszValue ) |
const char *pszValue ) |
51 |
{ |
{ |
52 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
53 |
return; |
return; |
54 |
|
|
55 |
// Info structure field members. |
// Info structure field members. |
56 |
|
|
57 |
type = pParamInfo->type; |
type = pParamInfo->type; |
58 |
|
|
59 |
if (pParamInfo->description) |
if (pParamInfo->description) |
60 |
description = pParamInfo->description; |
description = pParamInfo->description; |
61 |
else |
else |
62 |
description = QString::null; |
description = QString::null; |
63 |
|
|
64 |
mandatory = (bool) pParamInfo->multiplicity; |
mandatory = (bool) pParamInfo->multiplicity; |
65 |
fix = (bool) pParamInfo->fix; |
fix = (bool) pParamInfo->fix; |
66 |
multiplicity = (bool) pParamInfo->multiplicity; |
multiplicity = (bool) pParamInfo->multiplicity; |
67 |
|
|
68 |
depends.clear(); |
depends.clear(); |
69 |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
70 |
depends.append(pParamInfo->depends[i]); |
depends.append(pParamInfo->depends[i]); |
71 |
|
|
72 |
if (pParamInfo->defaultv) |
if (pParamInfo->defaultv) |
73 |
defaultv = pParamInfo->defaultv; |
defaultv = pParamInfo->defaultv; |
74 |
else |
else |
75 |
defaultv = QString::null; |
defaultv = QString::null; |
76 |
|
|
77 |
if (pParamInfo->range_min) |
if (pParamInfo->range_min) |
78 |
range_min = pParamInfo->range_min; |
range_min = pParamInfo->range_min; |
79 |
else |
else |
80 |
range_min = QString::null; |
range_min = QString::null; |
81 |
|
|
82 |
if (pParamInfo->range_max) |
if (pParamInfo->range_max) |
83 |
range_max = pParamInfo->range_max; |
range_max = pParamInfo->range_max; |
84 |
else |
else |
85 |
range_max = QString::null; |
range_max = QString::null; |
86 |
|
|
87 |
possibilities.clear(); |
possibilities.clear(); |
88 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
89 |
possibilities.append(pParamInfo->possibilities[i]); |
possibilities.append(pParamInfo->possibilities[i]); |
90 |
|
|
91 |
// The current parameter value. |
// The current parameter value. |
92 |
if (pszValue) |
if (pszValue) |
93 |
value = pszValue; |
value = pszValue; |
94 |
else |
else |
95 |
value = QString::null; |
value = QString::null; |
96 |
} |
} |
117 |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
118 |
qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDeviceType deviceType, int iDeviceID ) |
119 |
{ |
{ |
120 |
if (pClient == NULL || iDeviceID < 0) |
// Device id and type should be always set. |
121 |
return; |
m_iDeviceID = iDeviceID; |
122 |
|
m_deviceType = deviceType; |
123 |
|
|
124 |
|
// Retrieve device info, if any. |
125 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
126 |
switch (deviceType) { |
switch (deviceType) { |
127 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
128 |
m_sDeviceName = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
129 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
130 |
break; |
break; |
131 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
132 |
m_sDeviceName = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
133 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
134 |
break; |
break; |
135 |
|
case qsamplerDevice::None: |
136 |
|
m_sDeviceType = QString::null; |
137 |
|
break; |
138 |
} |
} |
|
if (pDeviceInfo == NULL) |
|
|
return; |
|
139 |
|
|
140 |
// Device properties... |
// If we're bogus, bail out... |
141 |
m_iDeviceID = iDeviceID; |
if (pDeviceInfo == NULL) { |
142 |
m_deviceType = deviceType; |
m_sDriverName = QString::null; |
143 |
|
m_sDeviceName = QObject::tr("New device"); |
144 |
|
return; |
145 |
|
} |
146 |
|
|
147 |
|
// Other device properties... |
148 |
m_sDriverName = pDeviceInfo->driver; |
m_sDriverName = pDeviceInfo->driver; |
149 |
|
m_sDeviceName = m_sDriverName + ' ' |
150 |
// Complete fake device name... |
+ QObject::tr("Device %1").arg(m_iDeviceID); |
|
m_sDeviceName += ' ' + m_sDriverName + ' '; |
|
|
m_sDeviceName += QObject::tr("Device %1").arg(m_iDeviceID); |
|
151 |
|
|
152 |
// Grab device/driver parameters... |
// Grab device parameters... |
153 |
m_params.clear(); |
m_params.clear(); |
154 |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) { |
155 |
const char *pszParam = pDeviceInfo->params[i].key; |
const char *pszParam = pDeviceInfo->params[i].key; |
156 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
157 |
switch (deviceType) { |
switch (deviceType) { |
158 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
159 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
160 |
m_sDriverName.latin1(), pszParam, NULL); |
m_sDriverName.latin1(), pszParam, NULL); |
161 |
break; |
break; |
162 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
163 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
164 |
m_sDriverName.latin1(), pszParam, NULL); |
m_sDriverName.latin1(), pszParam, NULL); |
165 |
break; |
break; |
166 |
|
case qsamplerDevice::None: |
167 |
|
break; |
168 |
|
} |
169 |
|
if (pParamInfo) { |
170 |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, |
171 |
|
pDeviceInfo->params[i].value); |
172 |
|
} |
173 |
|
} |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
// Driver name initializer. |
178 |
|
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
179 |
|
const QString& sDriverName ) |
180 |
|
{ |
181 |
|
// Valid only for scratch devices. |
182 |
|
if (m_sDriverName == sDriverName) |
183 |
|
return; |
184 |
|
|
185 |
|
// Retrieve driver info, if any. |
186 |
|
lscp_driver_info_t *pDriverInfo = NULL; |
187 |
|
switch (m_deviceType) { |
188 |
|
case qsamplerDevice::Audio: |
189 |
|
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
190 |
|
sDriverName.latin1()); |
191 |
|
break; |
192 |
|
case qsamplerDevice::Midi: |
193 |
|
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
194 |
|
sDriverName.latin1()); |
195 |
|
break; |
196 |
|
case qsamplerDevice::None: |
197 |
|
break; |
198 |
|
} |
199 |
|
|
200 |
|
// If we're bogus, bail out... |
201 |
|
if (pDriverInfo == NULL) |
202 |
|
return; |
203 |
|
|
204 |
|
// Remember device parameters... |
205 |
|
m_sDriverName = sDriverName; |
206 |
|
|
207 |
|
// Grab driver parameters... |
208 |
|
m_params.clear(); |
209 |
|
for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) { |
210 |
|
const char *pszParam = pDriverInfo->parameters[i]; |
211 |
|
lscp_param_info_t *pParamInfo = NULL; |
212 |
|
switch (m_deviceType) { |
213 |
|
case qsamplerDevice::Audio: |
214 |
|
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
215 |
|
sDriverName.latin1(), pszParam, NULL); |
216 |
|
break; |
217 |
|
case qsamplerDevice::Midi: |
218 |
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
219 |
|
sDriverName.latin1(), pszParam, NULL); |
220 |
|
break; |
221 |
|
case qsamplerDevice::None: |
222 |
|
break; |
223 |
} |
} |
224 |
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pDeviceInfo->params[i].value); |
if (pParamInfo) |
225 |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pParamInfo->defaultv); |
226 |
} |
} |
227 |
} |
} |
228 |
|
|
238 |
return m_deviceType; |
return m_deviceType; |
239 |
} |
} |
240 |
|
|
241 |
|
const QString& qsamplerDevice::deviceTypeName (void) const |
242 |
|
{ |
243 |
|
return m_sDeviceType; |
244 |
|
} |
245 |
|
|
246 |
const QString& qsamplerDevice::driverName (void) const |
const QString& qsamplerDevice::driverName (void) const |
247 |
{ |
{ |
248 |
return m_sDriverName; |
return m_sDriverName; |
265 |
{ |
{ |
266 |
} |
} |
267 |
|
|
268 |
// Device enumerator. |
// Device ids enumerator. |
269 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
270 |
qsamplerDeviceType deviceType ) |
qsamplerDeviceType deviceType ) |
271 |
{ |
{ |
272 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
273 |
switch (deviceType) { |
switch (deviceType) { |
274 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
275 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
276 |
break; |
break; |
277 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
278 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
279 |
|
break; |
280 |
|
case qsamplerDevice::None: |
281 |
break; |
break; |
282 |
} |
} |
283 |
return piDeviceIDs; |
return piDeviceIDs; |
284 |
} |
} |
285 |
|
|
286 |
|
|
287 |
|
// Driver names enumerator. |
288 |
|
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
289 |
|
qsamplerDeviceType deviceType ) |
290 |
|
{ |
291 |
|
QStringList drivers; |
292 |
|
|
293 |
|
const char **ppszDrivers = NULL; |
294 |
|
switch (deviceType) { |
295 |
|
case qsamplerDevice::Audio: |
296 |
|
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
297 |
|
break; |
298 |
|
case qsamplerDevice::Midi: |
299 |
|
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
300 |
|
break; |
301 |
|
case qsamplerDevice::None: |
302 |
|
break; |
303 |
|
} |
304 |
|
|
305 |
|
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
306 |
|
drivers.append(ppszDrivers[iDriver]); |
307 |
|
|
308 |
|
return drivers; |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
313 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QListView device item. |
314 |
// |
// |
315 |
|
|
316 |
// Constructors. |
// Constructors. |
317 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
318 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
319 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
: QListViewItem(pListView), m_device(pClient, deviceType) |
320 |
{ |
{ |
321 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
322 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
323 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
324 |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
325 |
break; |
break; |
326 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
327 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
328 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
329 |
break; |
break; |
330 |
|
case qsamplerDevice::None: |
331 |
|
break; |
332 |
} |
} |
333 |
} |
} |
334 |
|
|
335 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
336 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
337 |
|
int iDeviceID ) |
338 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
339 |
{ |
{ |
340 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
341 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
342 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
343 |
break; |
break; |
344 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
345 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
346 |
break; |
break; |
347 |
|
case qsamplerDevice::None: |
348 |
|
break; |
349 |
} |
} |
350 |
|
|
351 |
QListViewItem::setText(0, m_device.deviceName()); |
QListViewItem::setText(0, m_device.deviceName()); |
357 |
} |
} |
358 |
|
|
359 |
// Instance accessors. |
// Instance accessors. |
360 |
const qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device (void) |
361 |
{ |
{ |
362 |
return m_device; |
return m_device; |
363 |
} |
} |
375 |
// |
// |
376 |
|
|
377 |
// Constructor. |
// Constructor. |
378 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, const char *pszName ) |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
379 |
|
const char *pszName ) |
380 |
: QTable(pParent, pszName) |
: QTable(pParent, pszName) |
381 |
{ |
{ |
|
m_pClient = NULL; |
|
|
m_iDeviceID = -1; |
|
|
|
|
382 |
// Set fixed number of columns. |
// Set fixed number of columns. |
383 |
QTable::setNumCols(3); |
QTable::setNumCols(3); |
384 |
QTable::setShowGrid(false); |
QTable::setShowGrid(false); |
397 |
QTable::setColumnReadOnly(0, true); |
QTable::setColumnReadOnly(0, true); |
398 |
QTable::setColumnReadOnly(1, true); |
QTable::setColumnReadOnly(1, true); |
399 |
// QTable::setColumnReadOnly(2, true); -- of course not. |
// QTable::setColumnReadOnly(2, true); -- of course not. |
400 |
|
QTable::setColumnStretchable(1, true); |
401 |
} |
} |
402 |
|
|
403 |
// Default destructor. |
// Default destructor. |
406 |
} |
} |
407 |
|
|
408 |
|
|
|
// Client/device descriptor selector. |
|
|
void qsamplerDeviceParamTable::setDevice ( lscp_client_t *pClient, |
|
|
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID ) |
|
|
{ |
|
|
if (m_pClient |
|
|
&& m_pClient == pClient |
|
|
&& m_deviceType == deviceType |
|
|
&& m_iDeviceID == iDeviceID) |
|
|
return; |
|
|
|
|
|
m_pClient = pClient; |
|
|
m_deviceType = deviceType; |
|
|
m_iDeviceID = iDeviceID; |
|
|
|
|
|
refresh(); |
|
|
} |
|
|
|
|
|
|
|
|
// Client/device descriptor accessors. |
|
|
lscp_client_t *qsamplerDeviceParamTable::client (void) |
|
|
{ |
|
|
return m_pClient; |
|
|
} |
|
|
|
|
|
int qsamplerDeviceParamTable::deviceID (void) |
|
|
{ |
|
|
return m_iDeviceID; |
|
|
} |
|
|
|
|
|
|
|
409 |
// The main table refresher. |
// The main table refresher. |
410 |
void qsamplerDeviceParamTable::refresh (void) |
void qsamplerDeviceParamTable::refresh ( qsamplerDevice& device ) |
411 |
{ |
{ |
412 |
// Always (re)start it empty. |
// Always (re)start it empty. |
413 |
|
QTable::setUpdatesEnabled(false); |
414 |
QTable::setNumRows(0); |
QTable::setNumRows(0); |
415 |
|
|
|
if (m_pClient == NULL) |
|
|
return; |
|
|
|
|
|
// Construct the local device object here. |
|
|
qsamplerDevice device(m_pClient, m_deviceType, m_iDeviceID); |
|
|
|
|
|
|
|
416 |
// Now fill the parameter table... |
// Now fill the parameter table... |
417 |
QHeader *pHeader = QTable::verticalHeader(); |
qsamplerDeviceParamMap& params = device.params(); |
|
qsamplerDeviceParamMap& params = device.params(); |
|
418 |
QTable::insertRows(0, params.count()); |
QTable::insertRows(0, params.count()); |
419 |
int iRow = 0; |
int iRow = 0; |
420 |
qsamplerDeviceParamMap::Iterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
421 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
for (iter = params.begin(); iter != params.end(); ++iter) { |
422 |
QTable::setText(iRow, 0, iter.key()); |
const qsamplerDeviceParam& param = iter.data(); |
423 |
QTable::setText(iRow, 1, iter.data().description); |
bool fEnabled = (device.deviceID() < 0 || !param.fix); |
424 |
QTable::setText(iRow, 2, iter.data().value); |
QTable::setText(iRow, 0, iter.key()); |
425 |
++iRow; |
QTable::setText(iRow, 1, param.description); |
426 |
|
if (param.type == LSCP_TYPE_BOOL) { |
427 |
|
QStringList opts; |
428 |
|
opts.append(tr("false")); |
429 |
|
opts.append(tr("true")); |
430 |
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
431 |
|
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
432 |
|
pComboItem->setEnabled(fEnabled); |
433 |
|
QTable::setItem(iRow, 2, pComboItem); |
434 |
|
} else if (param.possibilities.count() > 0 && !param.multiplicity) { |
435 |
|
QComboTableItem *pComboItem = new QComboTableItem(this, |
436 |
|
param.possibilities); |
437 |
|
pComboItem->setCurrentItem(param.value); |
438 |
|
pComboItem->setEnabled(fEnabled); |
439 |
|
QTable::setItem(iRow, 2, pComboItem); |
440 |
|
} else { |
441 |
|
QTableItem* pTableItem = new QTableItem(this, |
442 |
|
fEnabled ? QTableItem::OnTyping : QTableItem::Never, |
443 |
|
param.value); |
444 |
|
QTable::setItem(iRow, 2, pTableItem); |
445 |
|
} |
446 |
|
++iRow; |
447 |
} |
} |
448 |
|
|
449 |
// Adjust optimal column width. |
// Adjust optimal column widths. |
450 |
for (int iCol = 0; iCol < QTable::numCols(); iCol++) |
QTable::adjustColumn(0); |
451 |
QTable::adjustColumn(iCol); |
QTable::adjustColumn(2); |
452 |
|
|
453 |
|
QTable::setUpdatesEnabled(true); |
454 |
|
QTable::updateContents(); |
455 |
} |
} |
456 |
|
|
457 |
|
|