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