1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerDevice.h" |
#include "qsamplerDevice.h" |
25 |
|
|
|
#include <qspinbox.h> |
|
|
#include <qlineedit.h> |
|
|
|
|
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
28 |
|
|
29 |
#include "config.h" |
#include <qspinbox.h> |
30 |
|
#include <qlineedit.h> |
31 |
|
|
32 |
|
using namespace QSampler; |
33 |
|
|
34 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
35 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
55 |
{ |
{ |
56 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
57 |
return; |
return; |
58 |
|
|
59 |
// Info structure field members. |
// Info structure field members. |
60 |
|
|
61 |
type = pParamInfo->type; |
type = pParamInfo->type; |
62 |
|
|
63 |
if (pParamInfo->description) |
if (pParamInfo->description) |
64 |
description = pParamInfo->description; |
description = pParamInfo->description; |
65 |
else |
else |
66 |
description = QString::null; |
description = QString::null; |
67 |
|
|
68 |
mandatory = (bool) pParamInfo->multiplicity; |
mandatory = (bool) pParamInfo->mandatory; |
69 |
fix = (bool) pParamInfo->fix; |
fix = (bool) pParamInfo->fix; |
70 |
multiplicity = (bool) pParamInfo->multiplicity; |
multiplicity = (bool) pParamInfo->multiplicity; |
71 |
|
|
72 |
depends.clear(); |
depends.clear(); |
73 |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
74 |
depends.append(pParamInfo->depends[i]); |
depends.append(pParamInfo->depends[i]); |
75 |
|
|
76 |
if (pParamInfo->defaultv) |
if (pParamInfo->defaultv) |
77 |
defaultv = pParamInfo->defaultv; |
defaultv = pParamInfo->defaultv; |
78 |
else |
else |
79 |
defaultv = QString::null; |
defaultv = QString::null; |
80 |
|
|
81 |
if (pParamInfo->range_min) |
if (pParamInfo->range_min) |
82 |
range_min = pParamInfo->range_min; |
range_min = pParamInfo->range_min; |
83 |
else |
else |
84 |
range_min = QString::null; |
range_min = QString::null; |
85 |
|
|
86 |
if (pParamInfo->range_max) |
if (pParamInfo->range_max) |
87 |
range_max = pParamInfo->range_max; |
range_max = pParamInfo->range_max; |
88 |
else |
else |
89 |
range_max = QString::null; |
range_max = QString::null; |
90 |
|
|
91 |
possibilities.clear(); |
possibilities.clear(); |
92 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
93 |
possibilities.append(pParamInfo->possibilities[i]); |
possibilities.append(pParamInfo->possibilities[i]); |
94 |
|
|
95 |
// The current parameter value. |
// The current parameter value. |
96 |
if (pszValue) |
if (pszValue) |
97 |
value = pszValue; |
value = pszValue; |
105 |
// |
// |
106 |
|
|
107 |
// Constructor. |
// Constructor. |
108 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType deviceType, int iDeviceID ) |
|
109 |
{ |
{ |
110 |
m_ports.setAutoDelete(true); |
m_ports.setAutoDelete(true); |
111 |
|
|
112 |
setDevice(pClient, deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
113 |
} |
} |
114 |
|
|
115 |
// Default destructor. |
// Default destructor. |
117 |
{ |
{ |
118 |
} |
} |
119 |
|
|
120 |
|
// Copy constructor. |
121 |
|
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
122 |
|
: m_params(device.m_params), m_ports(m_ports) |
123 |
|
{ |
124 |
|
m_iDeviceID = device.m_iDeviceID; |
125 |
|
m_deviceType = device.m_deviceType; |
126 |
|
m_sDeviceType = device.m_sDeviceType; |
127 |
|
m_sDriverName = device.m_sDriverName; |
128 |
|
m_sDeviceName = device.m_sDeviceName; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
// Initializer. |
// Initializer. |
133 |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType deviceType, int iDeviceID ) |
|
134 |
{ |
{ |
135 |
|
MainForm *pMainForm = MainForm::getInstance(); |
136 |
|
if (pMainForm == NULL) |
137 |
|
return; |
138 |
|
if (pMainForm->client() == NULL) |
139 |
|
return; |
140 |
|
|
141 |
// Device id and type should be always set. |
// Device id and type should be always set. |
142 |
m_iDeviceID = iDeviceID; |
m_iDeviceID = iDeviceID; |
143 |
m_deviceType = deviceType; |
m_deviceType = deviceType; |
144 |
|
|
145 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
146 |
m_params.clear(); |
m_params.clear(); |
147 |
m_ports.clear(); |
m_ports.clear(); |
151 |
switch (deviceType) { |
switch (deviceType) { |
152 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
153 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
154 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
155 |
|
pMainForm->client(), m_iDeviceID)) == NULL) |
156 |
|
appendMessagesClient("lscp_get_audio_device_info"); |
157 |
break; |
break; |
158 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
159 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
160 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
161 |
|
pMainForm->client(), m_iDeviceID)) == NULL) |
162 |
|
appendMessagesClient("lscp_get_midi_device_info"); |
163 |
break; |
break; |
164 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
165 |
m_sDeviceType = QString::null; |
m_sDeviceType = QString::null; |
166 |
break; |
break; |
167 |
} |
} |
|
|
|
168 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
169 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
170 |
m_sDriverName = QString::null; |
m_sDriverName = QString::null; |
183 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
184 |
switch (deviceType) { |
switch (deviceType) { |
185 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
186 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
187 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
188 |
|
appendMessagesClient("lscp_get_audio_driver_param_info"); |
189 |
break; |
break; |
190 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
191 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
193 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
194 |
break; |
break; |
195 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
196 |
break; |
break; |
202 |
} |
} |
203 |
|
|
204 |
// Refresh parameter dependencies... |
// Refresh parameter dependencies... |
205 |
refreshParams(pClient); |
refreshParams(); |
206 |
// Set port/channel list... |
// Set port/channel list... |
207 |
refreshPorts(pClient); |
refreshPorts(); |
208 |
} |
} |
209 |
|
|
210 |
|
|
211 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
212 |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
|
const QString& sDriverName ) |
|
213 |
{ |
{ |
214 |
|
MainForm *pMainForm = MainForm::getInstance(); |
215 |
|
if (pMainForm == NULL) |
216 |
|
return; |
217 |
|
if (pMainForm->client() == NULL) |
218 |
|
return; |
219 |
|
|
220 |
// Valid only for scratch devices. |
// Valid only for scratch devices. |
221 |
if (m_sDriverName == sDriverName) |
if (m_sDriverName == sDriverName) |
222 |
return; |
return; |
229 |
lscp_driver_info_t *pDriverInfo = NULL; |
lscp_driver_info_t *pDriverInfo = NULL; |
230 |
switch (m_deviceType) { |
switch (m_deviceType) { |
231 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
232 |
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
233 |
sDriverName.latin1()); |
sDriverName.latin1())) == NULL) |
234 |
|
appendMessagesClient("lscp_get_audio_driver_info"); |
235 |
break; |
break; |
236 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
237 |
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
238 |
sDriverName.latin1()); |
sDriverName.latin1())) == NULL) |
239 |
|
appendMessagesClient("lscp_get_midi_driver_info"); |
240 |
break; |
break; |
241 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
242 |
break; |
break; |
255 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
256 |
switch (m_deviceType) { |
switch (m_deviceType) { |
257 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
258 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
259 |
sDriverName.latin1(), sParam.latin1(), NULL); |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
260 |
|
appendMessagesClient("lscp_get_audio_driver_param_info"); |
261 |
break; |
break; |
262 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
263 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
264 |
sDriverName.latin1(), sParam.latin1(), NULL); |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
265 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
266 |
break; |
break; |
267 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
268 |
break; |
break; |
274 |
} |
} |
275 |
|
|
276 |
// Refresh parameter dependencies... |
// Refresh parameter dependencies... |
277 |
refreshParams(pClient); |
refreshParams(); |
278 |
// Set port/channel list... |
// Set port/channel list... |
279 |
refreshPorts(pClient); |
refreshPorts(); |
280 |
} |
} |
281 |
|
|
282 |
|
|
301 |
return m_sDriverName; |
return m_sDriverName; |
302 |
} |
} |
303 |
|
|
304 |
const QString& qsamplerDevice::deviceName (void) const |
// Special device name formatter. |
305 |
|
QString qsamplerDevice::deviceName (void) const |
306 |
{ |
{ |
307 |
return m_sDeviceName; |
QString sPrefix; |
308 |
|
if (m_iDeviceID >= 0) |
309 |
|
sPrefix += m_sDeviceType + ' '; |
310 |
|
return sPrefix + m_sDeviceName; |
311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
// Set the proper device parameter value. |
// Set the proper device parameter value. |
315 |
void qsamplerDevice::setParam ( const QString& sParam, |
bool qsamplerDevice::setParam ( const QString& sParam, |
316 |
const QString& sValue ) |
const QString& sValue ) |
317 |
{ |
{ |
318 |
|
MainForm *pMainForm = MainForm::getInstance(); |
319 |
|
if (pMainForm == NULL) |
320 |
|
return false; |
321 |
|
if (pMainForm->client() == NULL) |
322 |
|
return false; |
323 |
|
|
324 |
|
// Set proper device parameter. |
325 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.upper()].value = sValue; |
326 |
|
|
327 |
|
// If the device already exists, things get immediate... |
328 |
|
int iRefresh = 0; |
329 |
|
if (m_iDeviceID >= 0) { |
330 |
|
// Prepare parameter struct. |
331 |
|
lscp_param_t param; |
332 |
|
param.key = (char *) sParam.latin1(); |
333 |
|
param.value = (char *) sValue.latin1(); |
334 |
|
// Now it depends on the device type... |
335 |
|
lscp_status_t ret = LSCP_FAILED; |
336 |
|
switch (m_deviceType) { |
337 |
|
case qsamplerDevice::Audio: |
338 |
|
if (sParam == "CHANNELS") iRefresh++; |
339 |
|
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
340 |
|
m_iDeviceID, ¶m)) != LSCP_OK) |
341 |
|
appendMessagesClient("lscp_set_audio_device_param"); |
342 |
|
break; |
343 |
|
case qsamplerDevice::Midi: |
344 |
|
if (sParam == "PORTS") iRefresh++; |
345 |
|
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
346 |
|
m_iDeviceID, ¶m)) != LSCP_OK) |
347 |
|
appendMessagesClient("lscp_set_midi_device_param"); |
348 |
|
break; |
349 |
|
case qsamplerDevice::None: |
350 |
|
break; |
351 |
|
} |
352 |
|
// Show result. |
353 |
|
if (ret == LSCP_OK) { |
354 |
|
appendMessages(QString("%1: %2.").arg(sParam).arg(sValue)); |
355 |
|
// Special care for specific parameter changes... |
356 |
|
if (iRefresh > 0) |
357 |
|
iRefresh += refreshPorts(); |
358 |
|
iRefresh += refreshDepends(sParam); |
359 |
|
} else { |
360 |
|
// Oops... |
361 |
|
appendMessagesError( |
362 |
|
QObject::tr("Could not set device parameter value.\n\nSorry.")); |
363 |
|
} |
364 |
|
} |
365 |
|
|
366 |
|
// Return whether we're need a view refresh. |
367 |
|
return (iRefresh > 0); |
368 |
} |
} |
369 |
|
|
370 |
|
|
382 |
} |
} |
383 |
|
|
384 |
|
|
385 |
|
// Create a new device, as a copy of this current one. |
386 |
|
bool qsamplerDevice::createDevice (void) |
387 |
|
{ |
388 |
|
MainForm *pMainForm = MainForm::getInstance(); |
389 |
|
if (pMainForm == NULL) |
390 |
|
return false; |
391 |
|
if (pMainForm->client() == NULL) |
392 |
|
return false; |
393 |
|
|
394 |
|
// Build the parameter list... |
395 |
|
lscp_param_t *pParams = new lscp_param_t [m_params.count() + 1]; |
396 |
|
int iParam = 0; |
397 |
|
qsamplerDeviceParamMap::ConstIterator iter; |
398 |
|
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
399 |
|
pParams[iParam].key = (char *) iter.key().latin1(); |
400 |
|
pParams[iParam].value = (char *) iter.data().value.latin1(); |
401 |
|
++iParam; |
402 |
|
} |
403 |
|
// Null terminated. |
404 |
|
pParams[iParam].key = NULL; |
405 |
|
pParams[iParam].value = NULL; |
406 |
|
|
407 |
|
// Now it depends on the device type... |
408 |
|
switch (m_deviceType) { |
409 |
|
case qsamplerDevice::Audio: |
410 |
|
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
411 |
|
m_sDriverName.latin1(), pParams)) < 0) |
412 |
|
appendMessagesClient("lscp_create_audio_device"); |
413 |
|
break; |
414 |
|
case qsamplerDevice::Midi: |
415 |
|
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
416 |
|
m_sDriverName.latin1(), pParams)) < 0) |
417 |
|
appendMessagesClient("lscp_create_midi_device"); |
418 |
|
break; |
419 |
|
case qsamplerDevice::None: |
420 |
|
break; |
421 |
|
} |
422 |
|
|
423 |
|
// Free used parameter array. |
424 |
|
delete pParams; |
425 |
|
|
426 |
|
// Show result. |
427 |
|
if (m_iDeviceID >= 0) { |
428 |
|
// Refresh our own stuff... |
429 |
|
setDevice(m_deviceType, m_iDeviceID); |
430 |
|
appendMessages(QObject::tr("created.")); |
431 |
|
} else { |
432 |
|
appendMessagesError(QObject::tr("Could not create device.\n\nSorry.")); |
433 |
|
} |
434 |
|
|
435 |
|
// Return whether we're a valid device... |
436 |
|
return (m_iDeviceID >= 0); |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
|
// Destroy existing device. |
441 |
|
bool qsamplerDevice::deleteDevice (void) |
442 |
|
{ |
443 |
|
MainForm *pMainForm = MainForm::getInstance(); |
444 |
|
if (pMainForm == NULL) |
445 |
|
return false; |
446 |
|
if (pMainForm->client() == NULL) |
447 |
|
return false; |
448 |
|
|
449 |
|
// Now it depends on the device type... |
450 |
|
lscp_status_t ret = LSCP_FAILED; |
451 |
|
switch (m_deviceType) { |
452 |
|
case qsamplerDevice::Audio: |
453 |
|
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
454 |
|
m_iDeviceID)) != LSCP_OK) |
455 |
|
appendMessagesClient("lscp_destroy_audio_device"); |
456 |
|
break; |
457 |
|
case qsamplerDevice::Midi: |
458 |
|
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
459 |
|
m_iDeviceID)) != LSCP_OK) |
460 |
|
appendMessagesClient("lscp_destroy_midi_device"); |
461 |
|
break; |
462 |
|
case qsamplerDevice::None: |
463 |
|
break; |
464 |
|
} |
465 |
|
|
466 |
|
// Show result. |
467 |
|
if (ret == LSCP_OK) { |
468 |
|
appendMessages(QObject::tr("deleted.")); |
469 |
|
m_iDeviceID = -1; |
470 |
|
} else { |
471 |
|
appendMessagesError(QObject::tr("Could not delete device.\n\nSorry.")); |
472 |
|
} |
473 |
|
|
474 |
|
// Return whether we've done it.. |
475 |
|
return (ret == LSCP_OK); |
476 |
|
} |
477 |
|
|
478 |
|
|
479 |
// Device parameter dependencies refreshner. |
// Device parameter dependencies refreshner. |
480 |
int qsamplerDevice::refreshParams ( lscp_client_t *pClient ) |
int qsamplerDevice::refreshParams (void) |
481 |
{ |
{ |
482 |
|
// This should only make sense for scratch devices... |
483 |
|
if (m_iDeviceID >= 0) |
484 |
|
return 0; |
485 |
// Refresh all parameters that have dependencies... |
// Refresh all parameters that have dependencies... |
486 |
int iParams = 0; |
int iParams = 0; |
487 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
488 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
489 |
iParams += refreshParam(pClient, iter.key()); |
iParams += refreshParam(iter.key()); |
490 |
// Return how many parameters have been refreshed... |
// Return how many parameters have been refreshed... |
491 |
return iParams; |
return iParams; |
492 |
} |
} |
493 |
|
|
494 |
|
|
495 |
// Device port/channel list refreshner. |
// Device port/channel list refreshner. |
496 |
int qsamplerDevice::refreshPorts ( lscp_client_t *pClient ) |
int qsamplerDevice::refreshPorts (void) |
497 |
{ |
{ |
498 |
|
// This should only make sense for actual devices... |
499 |
|
if (m_iDeviceID < 0) |
500 |
|
return 0; |
501 |
// Port/channel count determination... |
// Port/channel count determination... |
502 |
int iPorts = 0; |
int iPorts = 0; |
503 |
switch (m_deviceType) { |
switch (m_deviceType) { |
513 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
514 |
m_ports.clear(); |
m_ports.clear(); |
515 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
516 |
m_ports.append(new qsamplerDevicePort(pClient, *this, iPort)); |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
517 |
// Return how many ports have been refreshed... |
// Return how many ports have been refreshed... |
518 |
return iPorts; |
return iPorts; |
519 |
} |
} |
520 |
|
|
521 |
|
|
522 |
// Refresh/set dependencies given that some parameter has changed. |
// Refresh/set dependencies given that some parameter has changed. |
523 |
int qsamplerDevice::refreshDepends ( lscp_client_t *pClient, |
int qsamplerDevice::refreshDepends ( const QString& sParam ) |
|
const QString& sParam ) |
|
524 |
{ |
{ |
525 |
|
// This should only make sense for scratch devices... |
526 |
|
if (m_iDeviceID >= 0) |
527 |
|
return 0; |
528 |
// Refresh all parameters that depend on this one... |
// Refresh all parameters that depend on this one... |
529 |
int iDepends = 0; |
int iDepends = 0; |
530 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
531 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
532 |
const QStringList& depends = iter.data().depends; |
const QStringList& depends = iter.data().depends; |
533 |
if (depends.find(sParam) != depends.end()) |
if (depends.find(sParam) != depends.end()) |
534 |
iDepends += refreshParam(pClient, iter.key()); |
iDepends += refreshParam(iter.key()); |
535 |
} |
} |
536 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
537 |
return iDepends; |
return iDepends; |
539 |
|
|
540 |
|
|
541 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
542 |
int qsamplerDevice::refreshParam ( lscp_client_t *pClient, |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
|
const QString& sParam ) |
|
543 |
{ |
{ |
544 |
|
MainForm *pMainForm = MainForm::getInstance(); |
545 |
|
if (pMainForm == NULL) |
546 |
|
return 0; |
547 |
|
if (pMainForm->client() == NULL) |
548 |
|
return 0; |
549 |
|
|
550 |
// Check if we have dependencies... |
// Check if we have dependencies... |
551 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
552 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
568 |
pDepends[iDepend].key = NULL; |
pDepends[iDepend].key = NULL; |
569 |
pDepends[iDepend].value = NULL; |
pDepends[iDepend].value = NULL; |
570 |
|
|
|
#if 0 |
|
571 |
// FIXME: Some parameter dependencies (e.g.ALSA CARD) |
// FIXME: Some parameter dependencies (e.g.ALSA CARD) |
572 |
// are blocking for no reason, causing timeout-crashes. |
// are blocking for no reason, causing potential timeout-crashes. |
573 |
|
// hopefully this gets mitigated if this dependency hell is only |
574 |
|
// carried out for scratch devices... |
575 |
|
|
576 |
// Retrieve some modern parameters... |
// Retrieve some modern parameters... |
577 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
578 |
switch (m_deviceType) { |
switch (m_deviceType) { |
579 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
580 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
581 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
582 |
|
appendMessagesClient("lscp_get_audio_driver_param_info"); |
583 |
break; |
break; |
584 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
585 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
586 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
587 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
588 |
break; |
break; |
589 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
590 |
break; |
break; |
593 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
594 |
iRefresh++; |
iRefresh++; |
595 |
} |
} |
596 |
#endif |
|
597 |
// Free used parameter array. |
// Free used parameter array. |
598 |
delete pDepends; |
delete pDepends; |
599 |
|
|
602 |
} |
} |
603 |
|
|
604 |
|
|
605 |
|
// Redirected messages output methods. |
606 |
|
void qsamplerDevice::appendMessages( const QString& s ) const |
607 |
|
{ |
608 |
|
MainForm *pMainForm = MainForm::getInstance(); |
609 |
|
if (pMainForm) |
610 |
|
pMainForm->appendMessages(deviceName() + ' ' + s); |
611 |
|
} |
612 |
|
|
613 |
|
void qsamplerDevice::appendMessagesColor( const QString& s, |
614 |
|
const QString& c ) const |
615 |
|
{ |
616 |
|
MainForm *pMainForm = MainForm::getInstance(); |
617 |
|
if (pMainForm) |
618 |
|
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
619 |
|
} |
620 |
|
|
621 |
|
void qsamplerDevice::appendMessagesText( const QString& s ) const |
622 |
|
{ |
623 |
|
MainForm *pMainForm = MainForm::getInstance(); |
624 |
|
if (pMainForm) |
625 |
|
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
626 |
|
} |
627 |
|
|
628 |
|
void qsamplerDevice::appendMessagesError( const QString& s ) const |
629 |
|
{ |
630 |
|
MainForm *pMainForm = MainForm::getInstance(); |
631 |
|
if (pMainForm) |
632 |
|
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
633 |
|
} |
634 |
|
|
635 |
|
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
636 |
|
{ |
637 |
|
MainForm *pMainForm = MainForm::getInstance(); |
638 |
|
if (pMainForm) |
639 |
|
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
// Device ids enumerator. |
// Device ids enumerator. |
644 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
645 |
qsamplerDeviceType deviceType ) |
qsamplerDeviceType deviceType ) |
664 |
qsamplerDeviceType deviceType ) |
qsamplerDeviceType deviceType ) |
665 |
{ |
{ |
666 |
QStringList drivers; |
QStringList drivers; |
667 |
|
|
668 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
669 |
switch (deviceType) { |
switch (deviceType) { |
670 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
671 |
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
672 |
break; |
break; |
673 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
674 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
675 |
break; |
break; |
676 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
677 |
break; |
break; |
678 |
} |
} |
679 |
|
|
680 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
681 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
682 |
|
|
683 |
return drivers; |
return drivers; |
689 |
// |
// |
690 |
|
|
691 |
// Constructor. |
// Constructor. |
692 |
qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient, |
qsamplerDevicePort::qsamplerDevicePort ( qsamplerDevice& device, |
693 |
const qsamplerDevice& device, int iPortID ) |
int iPortID ) : m_device(device) |
694 |
{ |
{ |
695 |
setDevicePort(pClient, device, iPortID); |
setDevicePort(iPortID); |
696 |
} |
} |
697 |
|
|
698 |
// Default destructor. |
// Default destructor. |
702 |
|
|
703 |
|
|
704 |
// Initializer. |
// Initializer. |
705 |
void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient, |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
|
const qsamplerDevice& device, int iPortID ) |
|
706 |
{ |
{ |
707 |
|
MainForm *pMainForm = MainForm::getInstance(); |
708 |
|
if (pMainForm == NULL) |
709 |
|
return; |
710 |
|
if (pMainForm->client() == NULL) |
711 |
|
return; |
712 |
|
|
713 |
// Device port id should be always set. |
// Device port id should be always set. |
714 |
m_iPortID = iPortID; |
m_iPortID = iPortID; |
715 |
|
|
717 |
m_params.clear(); |
m_params.clear(); |
718 |
|
|
719 |
// Retrieve device port/channel info, if any. |
// Retrieve device port/channel info, if any. |
|
QString sPrefix = device.driverName() + ' '; |
|
720 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
721 |
switch (device.deviceType()) { |
switch (m_device.deviceType()) { |
722 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
723 |
sPrefix += QObject::tr("Channel"); |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
724 |
pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID); |
m_device.deviceID(), m_iPortID)) == NULL) |
725 |
|
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
726 |
break; |
break; |
727 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
728 |
sPrefix += QObject::tr("Port"); |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
729 |
pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID); |
m_device.deviceID(), m_iPortID)) == NULL) |
730 |
|
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
731 |
break; |
break; |
732 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
733 |
break; |
break; |
740 |
} |
} |
741 |
|
|
742 |
// Set device port/channel properties... |
// Set device port/channel properties... |
743 |
sPrefix += " %1:"; |
m_sPortName = pPortInfo->name; |
|
m_sPortName = sPrefix.arg(m_iPortID) + ' ' + pPortInfo->name; |
|
744 |
|
|
745 |
// Grab device port/channel parameters... |
// Grab device port/channel parameters... |
746 |
m_params.clear(); |
m_params.clear(); |
747 |
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
748 |
const QString sParam = pPortInfo->params[i].key; |
const QString sParam = pPortInfo->params[i].key; |
749 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
750 |
switch (device.deviceType()) { |
switch (m_device.deviceType()) { |
751 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
752 |
pParamInfo = ::lscp_get_audio_channel_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
753 |
device.deviceID(), iPortID, sParam.latin1()); |
pMainForm->client(), m_device.deviceID(), |
754 |
|
m_iPortID, sParam.latin1())) == NULL) |
755 |
|
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
756 |
break; |
break; |
757 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
758 |
pParamInfo = ::lscp_get_midi_port_param_info(pClient, |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
759 |
device.deviceID(), iPortID, sParam.latin1()); |
pMainForm->client(), m_device.deviceID(), |
760 |
|
m_iPortID, sParam.latin1())) == NULL) |
761 |
|
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
762 |
break; |
break; |
763 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
764 |
break; |
break; |
790 |
|
|
791 |
|
|
792 |
// Set the proper device port/channel parameter value. |
// Set the proper device port/channel parameter value. |
793 |
void qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
794 |
const QString& sValue ) |
const QString& sValue ) |
795 |
{ |
{ |
796 |
|
MainForm *pMainForm = MainForm::getInstance(); |
797 |
|
if (pMainForm == NULL) |
798 |
|
return false; |
799 |
|
if (pMainForm->client() == NULL) |
800 |
|
return false; |
801 |
|
|
802 |
|
// Set proper port/channel parameter. |
803 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.upper()].value = sValue; |
804 |
|
|
805 |
|
// If the device already exists, things get immediate... |
806 |
|
int iRefresh = 0; |
807 |
|
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
808 |
|
// Prepare parameter struct. |
809 |
|
lscp_param_t param; |
810 |
|
param.key = (char *) sParam.latin1(); |
811 |
|
param.value = (char *) sValue.latin1(); |
812 |
|
// Now it depends on the device type... |
813 |
|
lscp_status_t ret = LSCP_FAILED; |
814 |
|
switch (m_device.deviceType()) { |
815 |
|
case qsamplerDevice::Audio: |
816 |
|
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
817 |
|
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
818 |
|
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
819 |
|
break; |
820 |
|
case qsamplerDevice::Midi: |
821 |
|
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
822 |
|
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
823 |
|
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
824 |
|
break; |
825 |
|
case qsamplerDevice::None: |
826 |
|
break; |
827 |
|
} |
828 |
|
// Show result. |
829 |
|
if (ret == LSCP_OK) { |
830 |
|
m_device.appendMessages(m_sPortName |
831 |
|
+ ' ' + QString("%1: %2.").arg(sParam).arg(sValue)); |
832 |
|
iRefresh++; |
833 |
|
} else { |
834 |
|
m_device.appendMessagesError( |
835 |
|
QObject::tr("Could not set %1 parameter value.\n\n" |
836 |
|
"Sorry.").arg(m_sPortName)); |
837 |
|
} |
838 |
|
} |
839 |
|
|
840 |
|
// Return whether we're need a view refresh. |
841 |
|
return (iRefresh > 0); |
842 |
} |
} |
843 |
|
|
844 |
|
|
845 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
846 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
847 |
// |
// |
848 |
|
|
849 |
// Constructors. |
// Constructors. |
850 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
851 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::qsamplerDeviceType deviceType ) |
852 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
853 |
|
m_device(deviceType) |
854 |
{ |
{ |
855 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
856 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
857 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio1.png")); |
858 |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
setText(1, QObject::tr("Audio Devices")); |
859 |
break; |
break; |
860 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
861 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi1.png")); |
862 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
setText(1, QObject::tr("MIDI Devices")); |
863 |
break; |
break; |
864 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
865 |
break; |
break; |
866 |
} |
} |
867 |
} |
} |
868 |
|
|
869 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
870 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::qsamplerDeviceType deviceType, |
871 |
int iDeviceID ) |
int iDeviceID ) |
872 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
873 |
|
m_device(deviceType, iDeviceID) |
874 |
{ |
{ |
875 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
876 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
877 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio2.png")); |
878 |
break; |
break; |
879 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
880 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi2.png")); |
881 |
break; |
break; |
882 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
883 |
break; |
break; |
884 |
} |
} |
885 |
|
|
886 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(1, m_device.deviceName()); |
887 |
} |
} |
888 |
|
|
889 |
// Default destructor. |
// Default destructor. |
897 |
return m_device; |
return m_device; |
898 |
} |
} |
899 |
|
|
|
// To virtually distinguish between list view items. |
|
|
int qsamplerDeviceItem::rtti() const |
|
|
{ |
|
|
return QSAMPLER_DEVICE_ITEM; |
|
|
} |
|
|
|
|
900 |
|
|
901 |
|
|
902 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
903 |
// qsamplerDeviceParamTable - Device parameter view table. |
// qsamplerDeviceParamTable - Device parameter view table. |
904 |
// |
// |
905 |
|
#if 0 |
906 |
// Constructor. |
// Constructor. |
907 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
908 |
const char *pszName ) |
const char *pszName ) |
925 |
// Set read-onlyness of each column |
// Set read-onlyness of each column |
926 |
QTable::setColumnReadOnly(0, true); |
QTable::setColumnReadOnly(0, true); |
927 |
QTable::setColumnReadOnly(1, true); |
QTable::setColumnReadOnly(1, true); |
928 |
// QTable::setColumnReadOnly(2, true); -- of course not. |
// QTable::setColumnReadOnly(2, false); -- of course not. |
929 |
QTable::setColumnStretchable(1, true); |
QTable::setColumnStretchable(1, true); |
930 |
} |
} |
931 |
|
|
961 |
pComboItem->setEnabled(bEnabled); |
pComboItem->setEnabled(bEnabled); |
962 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
963 |
} else if (param.possibilities.count() > 0 && bEnabled) { |
} else if (param.possibilities.count() > 0 && bEnabled) { |
964 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
QStringList opts = param.possibilities; |
965 |
param.possibilities); |
if (param.multiplicity) |
966 |
pComboItem->setCurrentItem(param.value); |
opts.prepend(tr("(none)")); |
967 |
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
968 |
|
if (param.value.isEmpty()) |
969 |
|
pComboItem->setCurrentItem(0); |
970 |
|
else |
971 |
|
pComboItem->setCurrentItem(param.value); |
972 |
pComboItem->setEnabled(bEnabled); |
pComboItem->setEnabled(bEnabled); |
|
pComboItem->setEditable(bEnabled && param.multiplicity); |
|
973 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
974 |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
975 |
&& !param.range_min.isEmpty() |
&& !param.range_min.isEmpty() |
998 |
QTable::setUpdatesEnabled(true); |
QTable::setUpdatesEnabled(true); |
999 |
QTable::updateContents(); |
QTable::updateContents(); |
1000 |
} |
} |
1001 |
|
#endif |
1002 |
|
|
1003 |
|
DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
1004 |
|
} |
1005 |
|
|
1006 |
|
int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
1007 |
|
return params.size(); |
1008 |
|
} |
1009 |
|
|
1010 |
|
int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
1011 |
|
return 3; |
1012 |
|
} |
1013 |
|
|
1014 |
|
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
1015 |
|
if (!index.isValid()) |
1016 |
|
return QVariant(); |
1017 |
|
if (role != Qt::DisplayRole) |
1018 |
|
return QVariant(); |
1019 |
|
|
1020 |
|
DeviceParameterRow item; |
1021 |
|
item.name = params.keys()[index.row()]; |
1022 |
|
item.param = params[item.name]; |
1023 |
|
|
1024 |
|
return QVariant::fromValue(item); |
1025 |
|
} |
1026 |
|
|
1027 |
|
QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
1028 |
|
if (role != Qt::DisplayRole) return QVariant(); |
1029 |
|
|
1030 |
|
if (orientation == Qt::Horizontal) { |
1031 |
|
switch (section) { |
1032 |
|
case 0: return tr("Parameter"); |
1033 |
|
case 1: return tr("Value"); |
1034 |
|
case 2: return tr("Description"); |
1035 |
|
default: return QVariant(); |
1036 |
|
} |
1037 |
|
} |
1038 |
|
|
1039 |
|
return QVariant(); |
1040 |
|
} |
1041 |
|
|
1042 |
|
void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable) |
1043 |
|
{ |
1044 |
|
this->params = params; |
1045 |
|
this->bEditable = bEditable; |
1046 |
|
} |
1047 |
|
|
1048 |
|
void DeviceParamModel::clear() { |
1049 |
|
params.clear(); |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
|
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
1054 |
|
} |
1055 |
|
|
1056 |
|
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
1057 |
|
const QStyleOptionViewItem &/* option */, |
1058 |
|
const QModelIndex& index) const |
1059 |
|
{ |
1060 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1061 |
|
|
1062 |
|
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1063 |
|
|
1064 |
|
switch (index.column()) { |
1065 |
|
case 0: |
1066 |
|
return new QLabel(r.name, parent); |
1067 |
|
case 1: { |
1068 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1069 |
|
QCheckBox* pCheckBox = new QCheckBox(parent); |
1070 |
|
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1071 |
|
pCheckBox->setEnabled(bEnabled); |
1072 |
|
return pCheckBox; |
1073 |
|
} else if (r.param.possibilities.count() > 0 && bEnabled) { |
1074 |
|
QStringList opts = r.param.possibilities; |
1075 |
|
if (r.param.multiplicity) |
1076 |
|
opts.prepend(tr("(none)")); |
1077 |
|
QComboBox* pComboBox = new QComboBox(parent); |
1078 |
|
pComboBox->addItems(opts); |
1079 |
|
if (r.param.value.isEmpty()) |
1080 |
|
pComboBox->setCurrentIndex(0); |
1081 |
|
else |
1082 |
|
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1083 |
|
pComboBox->setEnabled(bEnabled); |
1084 |
|
return pComboBox; |
1085 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled |
1086 |
|
&& !r.param.range_min.isEmpty() |
1087 |
|
&& !r.param.range_max.isEmpty()) { |
1088 |
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
1089 |
|
pSpinBox->setValue(r.param.value.toInt()); |
1090 |
|
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1091 |
|
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1092 |
|
return pSpinBox; |
1093 |
|
} else { |
1094 |
|
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1095 |
|
return pLineEdit; |
1096 |
|
} |
1097 |
|
} |
1098 |
|
case 2: |
1099 |
|
return new QLabel(r.param.description, parent); |
1100 |
|
default: |
1101 |
|
return NULL; |
1102 |
|
} |
1103 |
|
} |
1104 |
|
|
1105 |
|
void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1106 |
|
/* |
1107 |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1108 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1109 |
|
comboBox->setCurrentIndex(item.selection); |
1110 |
|
*/ |
1111 |
|
} |
1112 |
|
|
1113 |
|
void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
1114 |
|
/* |
1115 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1116 |
|
model->setData(index, comboBox->currentIndex()); |
1117 |
|
*/ |
1118 |
|
} |
1119 |
|
|
1120 |
|
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1121 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1122 |
|
{ |
1123 |
|
if (editor) editor->setGeometry(option.rect); |
1124 |
|
} |
1125 |
|
|
1126 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1127 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
1128 |
// |
// |
1129 |
|
|
1130 |
|
#if 0 |
1131 |
// Constructor. |
// Constructor. |
1132 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
1133 |
QTable *pTable, EditType editType, const QString& sText ) |
QTable *pTable, EditType editType, const QString& sText ) |
1205 |
else |
else |
1206 |
QTableItem::setContentFromEditor(pWidget); |
QTableItem::setContentFromEditor(pWidget); |
1207 |
} |
} |
1208 |
|
#endif |
1209 |
|
|
1210 |
|
|
1211 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |