1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, 2008 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 |
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
28 |
|
|
29 |
#include <qspinbox.h> |
#include <QCheckBox> |
30 |
#include <qlineedit.h> |
#include <QSpinBox> |
31 |
|
#include <QLineEdit> |
32 |
|
|
33 |
using namespace QSampler; |
|
34 |
|
namespace QSampler { |
35 |
|
|
36 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
37 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// QSampler::DeviceParam - MIDI/Audio Device parameter structure. |
38 |
// |
// |
39 |
|
|
40 |
// Constructors. |
// Constructors. |
41 |
qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo, |
DeviceParam::DeviceParam ( lscp_param_info_t *pParamInfo, |
42 |
const char *pszValue ) |
const char *pszValue ) |
43 |
{ |
{ |
44 |
setParam(pParamInfo, pszValue); |
setParam(pParamInfo, pszValue); |
45 |
} |
} |
46 |
|
|
47 |
|
|
|
// Default destructor. |
|
|
qsamplerDeviceParam::~qsamplerDeviceParam (void) |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
48 |
// Initializer. |
// Initializer. |
49 |
void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
void DeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
50 |
const char *pszValue ) |
const char *pszValue ) |
51 |
{ |
{ |
52 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
59 |
if (pParamInfo->description) |
if (pParamInfo->description) |
60 |
description = pParamInfo->description; |
description = pParamInfo->description; |
61 |
else |
else |
62 |
description = QString::null; |
description.clear(); |
63 |
|
|
64 |
mandatory = (bool) pParamInfo->mandatory; |
mandatory = bool(pParamInfo->mandatory); |
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++) |
72 |
if (pParamInfo->defaultv) |
if (pParamInfo->defaultv) |
73 |
defaultv = pParamInfo->defaultv; |
defaultv = pParamInfo->defaultv; |
74 |
else |
else |
75 |
defaultv = QString::null; |
defaultv.clear(); |
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.clear(); |
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.clear(); |
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++) |
92 |
if (pszValue) |
if (pszValue) |
93 |
value = pszValue; |
value = pszValue; |
94 |
else |
else |
95 |
value = QString::null; |
value.clear(); |
96 |
} |
} |
97 |
|
|
98 |
|
|
99 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
100 |
// qsamplerDevice - MIDI/Audio Device structure. |
// QSampler::Device - MIDI/Audio Device structure. |
101 |
// |
// |
102 |
|
|
103 |
// Constructor. |
// Constructor. |
104 |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
Device::Device ( DeviceType deviceType, int iDeviceID ) |
105 |
{ |
{ |
106 |
m_ports.setAutoDelete(true); |
// m_ports.setAutoDelete(true); |
107 |
|
|
108 |
setDevice(deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
109 |
} |
} |
110 |
|
|
111 |
// Default destructor. |
// Default destructor. |
112 |
qsamplerDevice::~qsamplerDevice (void) |
Device::~Device (void) |
113 |
{ |
{ |
114 |
|
qDeleteAll(m_ports); |
115 |
|
m_ports.clear(); |
116 |
} |
} |
117 |
|
|
118 |
// Copy constructor. |
// Copy constructor. |
119 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
Device::Device ( const Device& device ) |
120 |
: m_params(device.m_params), m_ports(m_ports) |
: m_params(device.m_params), m_ports(device.m_ports) |
121 |
{ |
{ |
122 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
123 |
m_deviceType = device.m_deviceType; |
m_deviceType = device.m_deviceType; |
128 |
|
|
129 |
|
|
130 |
// Initializer. |
// Initializer. |
131 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void Device::setDevice ( DeviceType deviceType, int iDeviceID ) |
132 |
{ |
{ |
133 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
134 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
142 |
|
|
143 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
144 |
m_params.clear(); |
m_params.clear(); |
145 |
|
qDeleteAll(m_ports); |
146 |
m_ports.clear(); |
m_ports.clear(); |
147 |
|
|
148 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
149 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
150 |
switch (deviceType) { |
switch (deviceType) { |
151 |
case qsamplerDevice::Audio: |
case Device::Audio: |
152 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
153 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
154 |
pMainForm->client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
155 |
appendMessagesClient("lscp_get_audio_device_info"); |
appendMessagesClient("lscp_get_audio_device_info"); |
156 |
break; |
break; |
157 |
case qsamplerDevice::Midi: |
case Device::Midi: |
158 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
159 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
160 |
pMainForm->client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
161 |
appendMessagesClient("lscp_get_midi_device_info"); |
appendMessagesClient("lscp_get_midi_device_info"); |
162 |
break; |
break; |
163 |
case qsamplerDevice::None: |
case Device::None: |
164 |
m_sDeviceType = QString::null; |
m_sDeviceType.clear(); |
165 |
break; |
break; |
166 |
} |
} |
167 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
168 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
169 |
m_sDriverName = QString::null; |
m_sDriverName.clear(); |
170 |
m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType); |
m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType); |
171 |
return; |
return; |
172 |
} |
} |
181 |
const QString sParam = pDeviceInfo->params[i].key; |
const QString sParam = pDeviceInfo->params[i].key; |
182 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
183 |
switch (deviceType) { |
switch (deviceType) { |
184 |
case qsamplerDevice::Audio: |
case Device::Audio: |
185 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
186 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
187 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
188 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
189 |
break; |
break; |
190 |
case qsamplerDevice::Midi: |
case Device::Midi: |
191 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
193 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
194 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
195 |
break; |
break; |
196 |
case qsamplerDevice::None: |
case Device::None: |
197 |
break; |
break; |
198 |
} |
} |
199 |
if (pParamInfo) { |
if (pParamInfo) { |
200 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
201 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
202 |
} |
} |
203 |
} |
} |
210 |
|
|
211 |
|
|
212 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
213 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void Device::setDriver ( const QString& sDriverName ) |
214 |
{ |
{ |
215 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
216 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
224 |
|
|
225 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
226 |
m_params.clear(); |
m_params.clear(); |
227 |
|
qDeleteAll(m_ports); |
228 |
m_ports.clear(); |
m_ports.clear(); |
229 |
|
|
230 |
// Retrieve driver info, if any. |
// Retrieve driver info, if any. |
231 |
lscp_driver_info_t *pDriverInfo = NULL; |
lscp_driver_info_t *pDriverInfo = NULL; |
232 |
switch (m_deviceType) { |
switch (m_deviceType) { |
233 |
case qsamplerDevice::Audio: |
case Device::Audio: |
234 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
235 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
236 |
appendMessagesClient("lscp_get_audio_driver_info"); |
appendMessagesClient("lscp_get_audio_driver_info"); |
237 |
break; |
break; |
238 |
case qsamplerDevice::Midi: |
case Device::Midi: |
239 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
240 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
241 |
appendMessagesClient("lscp_get_midi_driver_info"); |
appendMessagesClient("lscp_get_midi_driver_info"); |
242 |
break; |
break; |
243 |
case qsamplerDevice::None: |
case Device::None: |
244 |
break; |
break; |
245 |
} |
} |
246 |
|
|
256 |
const QString sParam = pDriverInfo->parameters[i]; |
const QString sParam = pDriverInfo->parameters[i]; |
257 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
258 |
switch (m_deviceType) { |
switch (m_deviceType) { |
259 |
case qsamplerDevice::Audio: |
case Device::Audio: |
260 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
261 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
262 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
263 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
264 |
break; |
break; |
265 |
case qsamplerDevice::Midi: |
case Device::Midi: |
266 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
267 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
268 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
269 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
270 |
break; |
break; |
271 |
case qsamplerDevice::None: |
case Device::None: |
272 |
break; |
break; |
273 |
} |
} |
274 |
if (pParamInfo) { |
if (pParamInfo) { |
275 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
276 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
277 |
} |
} |
278 |
} |
} |
285 |
|
|
286 |
|
|
287 |
// Device property accessors. |
// Device property accessors. |
288 |
int qsamplerDevice::deviceID (void) const |
int Device::deviceID (void) const |
289 |
{ |
{ |
290 |
return m_iDeviceID; |
return m_iDeviceID; |
291 |
} |
} |
292 |
|
|
293 |
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
Device::DeviceType Device::deviceType (void) const |
294 |
{ |
{ |
295 |
return m_deviceType; |
return m_deviceType; |
296 |
} |
} |
297 |
|
|
298 |
const QString& qsamplerDevice::deviceTypeName (void) const |
const QString& Device::deviceTypeName (void) const |
299 |
{ |
{ |
300 |
return m_sDeviceType; |
return m_sDeviceType; |
301 |
} |
} |
302 |
|
|
303 |
const QString& qsamplerDevice::driverName (void) const |
const QString& Device::driverName (void) const |
304 |
{ |
{ |
305 |
return m_sDriverName; |
return m_sDriverName; |
306 |
} |
} |
307 |
|
|
308 |
// Special device name formatter. |
// Special device name formatter. |
309 |
QString qsamplerDevice::deviceName (void) const |
QString Device::deviceName (void) const |
310 |
{ |
{ |
311 |
QString sPrefix; |
QString sPrefix; |
312 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
313 |
sPrefix += m_sDeviceType + ' '; |
sPrefix += m_sDeviceType + ' '; |
314 |
return sPrefix + m_sDeviceName; |
return sPrefix + m_sDeviceName; |
315 |
} |
} |
316 |
|
|
317 |
|
|
318 |
// Set the proper device parameter value. |
// Set the proper device parameter value. |
319 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool Device::setParam ( const QString& sParam, |
320 |
const QString& sValue ) |
const QString& sValue ) |
321 |
{ |
{ |
322 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
326 |
return false; |
return false; |
327 |
|
|
328 |
// Set proper device parameter. |
// Set proper device parameter. |
329 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
330 |
|
|
331 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
332 |
int iRefresh = 0; |
int iRefresh = 0; |
333 |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
if (m_iDeviceID >= 0 && !sValue.isEmpty()) { |
334 |
|
|
335 |
|
// we need temporary byte arrrays with the final strings, because |
336 |
|
// i.e. QString::toUtf8() only returns a temporary object and the |
337 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
338 |
|
QByteArray finalParamKey = sParam.toUtf8(); |
339 |
|
QByteArray finalParamVal = sValue.toUtf8(); |
340 |
|
|
341 |
// Prepare parameter struct. |
// Prepare parameter struct. |
342 |
lscp_param_t param; |
lscp_param_t param; |
343 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) finalParamKey.constData(); |
344 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) finalParamVal.constData(); |
345 |
// Now it depends on the device type... |
// Now it depends on the device type... |
346 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
347 |
switch (m_deviceType) { |
switch (m_deviceType) { |
348 |
case qsamplerDevice::Audio: |
case Device::Audio: |
349 |
if (sParam == "CHANNELS") iRefresh++; |
if (sParam == "CHANNELS") iRefresh++; |
350 |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
351 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
352 |
appendMessagesClient("lscp_set_audio_device_param"); |
appendMessagesClient("lscp_set_audio_device_param"); |
353 |
break; |
break; |
354 |
case qsamplerDevice::Midi: |
case Device::Midi: |
355 |
if (sParam == "PORTS") iRefresh++; |
if (sParam == "PORTS") iRefresh++; |
356 |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
357 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
358 |
appendMessagesClient("lscp_set_midi_device_param"); |
appendMessagesClient("lscp_set_midi_device_param"); |
359 |
break; |
break; |
360 |
case qsamplerDevice::None: |
case Device::None: |
361 |
break; |
break; |
362 |
} |
} |
363 |
// Show result. |
// Show result. |
380 |
|
|
381 |
|
|
382 |
// Device parameter accessor. |
// Device parameter accessor. |
383 |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
const DeviceParamMap& Device::params (void) const |
384 |
{ |
{ |
385 |
return m_params; |
return m_params; |
386 |
} |
} |
387 |
|
|
388 |
|
|
389 |
// Device port/channel list accessor. |
// Device port/channel list accessor. |
390 |
qsamplerDevicePortList& qsamplerDevice::ports (void) |
DevicePortList& Device::ports (void) |
391 |
{ |
{ |
392 |
return m_ports; |
return m_ports; |
393 |
} |
} |
394 |
|
|
395 |
|
|
396 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
397 |
bool qsamplerDevice::createDevice (void) |
bool Device::createDevice (void) |
398 |
{ |
{ |
399 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
400 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
402 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
403 |
return false; |
return false; |
404 |
|
|
405 |
// Build the parameter list... |
// we need temporary lists with the final strings, because i.e. |
406 |
lscp_param_t *pParams = new lscp_param_t [m_params.count() + 1]; |
// QString::toUtf8() only returns a temporary object and the |
407 |
int iParam = 0; |
// C-style char* pointers for liblscp would immediately be invalidated |
408 |
qsamplerDeviceParamMap::ConstIterator iter; |
QList<QByteArray> finalKeys; |
409 |
|
QList<QByteArray> finalVals; |
410 |
|
|
411 |
|
DeviceParamMap::ConstIterator iter; |
412 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
413 |
if (iter.data().value == QString::null) continue; |
if (iter.value().value.isEmpty()) continue; |
414 |
pParams[iParam].key = (char *) iter.key().latin1(); |
finalKeys.push_back(iter.key().toUtf8()); |
415 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
finalVals.push_back(iter.value().value.toUtf8()); |
416 |
++iParam; |
} |
417 |
|
|
418 |
|
// yeah, we DO HAVE to do the two loops separately ! |
419 |
|
|
420 |
|
// Build the parameter list... |
421 |
|
lscp_param_t *pParams = new lscp_param_t [finalKeys.count() + 1]; |
422 |
|
int iParam; |
423 |
|
for (iParam = 0; iParam < finalKeys.count(); iParam++) { |
424 |
|
pParams[iParam].key = (char *) finalKeys[iParam].constData(); |
425 |
|
pParams[iParam].value = (char *) finalVals[iParam].constData(); |
426 |
} |
} |
427 |
// Null terminated. |
// Null terminated. |
428 |
pParams[iParam].key = NULL; |
pParams[iParam].key = NULL; |
430 |
|
|
431 |
// Now it depends on the device type... |
// Now it depends on the device type... |
432 |
switch (m_deviceType) { |
switch (m_deviceType) { |
433 |
case qsamplerDevice::Audio: |
case Device::Audio: |
434 |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
435 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
436 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
437 |
break; |
break; |
438 |
case qsamplerDevice::Midi: |
case Device::Midi: |
439 |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
440 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
441 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
442 |
break; |
break; |
443 |
case qsamplerDevice::None: |
case Device::None: |
444 |
break; |
break; |
445 |
} |
} |
446 |
|
|
447 |
// Free used parameter array. |
// Free used parameter array. |
448 |
delete pParams; |
delete[] pParams; |
449 |
|
|
450 |
// Show result. |
// Show result. |
451 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0) { |
462 |
|
|
463 |
|
|
464 |
// Destroy existing device. |
// Destroy existing device. |
465 |
bool qsamplerDevice::deleteDevice (void) |
bool Device::deleteDevice (void) |
466 |
{ |
{ |
467 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
468 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
473 |
// Now it depends on the device type... |
// Now it depends on the device type... |
474 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
475 |
switch (m_deviceType) { |
switch (m_deviceType) { |
476 |
case qsamplerDevice::Audio: |
case Device::Audio: |
477 |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
478 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
479 |
appendMessagesClient("lscp_destroy_audio_device"); |
appendMessagesClient("lscp_destroy_audio_device"); |
480 |
break; |
break; |
481 |
case qsamplerDevice::Midi: |
case Device::Midi: |
482 |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
483 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
484 |
appendMessagesClient("lscp_destroy_midi_device"); |
appendMessagesClient("lscp_destroy_midi_device"); |
485 |
break; |
break; |
486 |
case qsamplerDevice::None: |
case Device::None: |
487 |
break; |
break; |
488 |
} |
} |
489 |
|
|
501 |
|
|
502 |
|
|
503 |
// Device parameter dependencies refreshner. |
// Device parameter dependencies refreshner. |
504 |
int qsamplerDevice::refreshParams (void) |
int Device::refreshParams (void) |
505 |
{ |
{ |
506 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
507 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
508 |
return 0; |
return 0; |
509 |
// Refresh all parameters that have dependencies... |
// Refresh all parameters that have dependencies... |
510 |
int iParams = 0; |
int iParams = 0; |
511 |
qsamplerDeviceParamMap::ConstIterator iter; |
DeviceParamMap::ConstIterator iter; |
512 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
513 |
iParams += refreshParam(iter.key()); |
iParams += refreshParam(iter.key()); |
514 |
// Return how many parameters have been refreshed... |
// Return how many parameters have been refreshed... |
517 |
|
|
518 |
|
|
519 |
// Device port/channel list refreshner. |
// Device port/channel list refreshner. |
520 |
int qsamplerDevice::refreshPorts (void) |
int Device::refreshPorts (void) |
521 |
{ |
{ |
522 |
// This should only make sense for actual devices... |
// This should only make sense for actual devices... |
523 |
if (m_iDeviceID < 0) |
if (m_iDeviceID < 0) |
524 |
return 0; |
return 0; |
525 |
// Port/channel count determination... |
// Port/channel count determination... |
526 |
int iPorts = 0; |
int iPorts = 0; |
527 |
switch (m_deviceType) { |
switch (m_deviceType) { |
528 |
case qsamplerDevice::Audio: |
case Device::Audio: |
529 |
iPorts = m_params["CHANNELS"].value.toInt(); |
iPorts = m_params["CHANNELS"].value.toInt(); |
530 |
break; |
break; |
531 |
case qsamplerDevice::Midi: |
case Device::Midi: |
532 |
iPorts = m_params["PORTS"].value.toInt(); |
iPorts = m_params["PORTS"].value.toInt(); |
533 |
break; |
break; |
534 |
case qsamplerDevice::None: |
case Device::None: |
535 |
break; |
break; |
536 |
} |
} |
537 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
538 |
|
qDeleteAll(m_ports); |
539 |
m_ports.clear(); |
m_ports.clear(); |
540 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
541 |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
m_ports.append(new DevicePort(*this, iPort)); |
542 |
// Return how many ports have been refreshed... |
// Return how many ports have been refreshed... |
543 |
return iPorts; |
return iPorts; |
544 |
} |
} |
545 |
|
|
546 |
|
|
547 |
// Refresh/set dependencies given that some parameter has changed. |
// Refresh/set dependencies given that some parameter has changed. |
548 |
int qsamplerDevice::refreshDepends ( const QString& sParam ) |
int Device::refreshDepends ( const QString& sParam ) |
549 |
{ |
{ |
550 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
551 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
552 |
return 0; |
return 0; |
553 |
// Refresh all parameters that depend on this one... |
// Refresh all parameters that depend on this one... |
554 |
int iDepends = 0; |
int iDepends = 0; |
555 |
qsamplerDeviceParamMap::ConstIterator iter; |
DeviceParamMap::ConstIterator iter; |
556 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
557 |
const QStringList& depends = iter.data().depends; |
const QStringList& depends = iter.value().depends; |
558 |
if (depends.find(sParam) != depends.end()) |
if (depends.indexOf(sParam) >= 0) |
559 |
iDepends += refreshParam(iter.key()); |
iDepends += refreshParam(iter.key()); |
560 |
} |
} |
561 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
564 |
|
|
565 |
|
|
566 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
567 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int Device::refreshParam ( const QString& sParam ) |
568 |
{ |
{ |
569 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
570 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
573 |
return 0; |
return 0; |
574 |
|
|
575 |
// Check if we have dependencies... |
// Check if we have dependencies... |
576 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
DeviceParam& param = m_params[sParam.toUpper()]; |
577 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
578 |
return 0; |
return 0; |
579 |
|
|
582 |
// Build dependency list... |
// Build dependency list... |
583 |
lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1]; |
lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1]; |
584 |
int iDepend = 0; |
int iDepend = 0; |
585 |
QStringList::ConstIterator iter; |
|
586 |
for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) { |
// we need temporary lists with the final strings, because i.e. |
587 |
const QString& sDepend = *iter; |
// QString::toUtf8() only returns a temporary object and the |
588 |
pDepends[iDepend].key = (char *) sDepend.latin1(); |
// C-style char* pointers for liblscp would immediately be invalidated |
589 |
pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1(); |
QList<QByteArray> finalKeys; |
590 |
|
QList<QByteArray> finalVals; |
591 |
|
for (int i = 0; i < param.depends.count(); i++) { |
592 |
|
const QString& sDepend = param.depends[i]; |
593 |
|
finalKeys.push_back(sDepend.toUtf8()); |
594 |
|
finalVals.push_back(m_params[sDepend.toUpper()].value.toUtf8()); |
595 |
|
} |
596 |
|
// yeah, we DO HAVE to do those two loops separately ! |
597 |
|
for (int i = 0; i < param.depends.count(); i++) { |
598 |
|
pDepends[iDepend].key = (char *) finalKeys[i].constData(); |
599 |
|
pDepends[iDepend].value = (char *) finalVals[i].constData(); |
600 |
++iDepend; |
++iDepend; |
601 |
} |
} |
602 |
// Null terminated. |
// Null terminated. |
611 |
// Retrieve some modern parameters... |
// Retrieve some modern parameters... |
612 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
613 |
switch (m_deviceType) { |
switch (m_deviceType) { |
614 |
case qsamplerDevice::Audio: |
case Device::Audio: |
615 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
616 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
617 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
618 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
619 |
break; |
break; |
620 |
case qsamplerDevice::Midi: |
case Device::Midi: |
621 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
622 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
623 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
624 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
625 |
break; |
break; |
626 |
case qsamplerDevice::None: |
case Device::None: |
627 |
break; |
break; |
628 |
} |
} |
629 |
if (pParamInfo) { |
if (pParamInfo) { |
630 |
if (param.value != QString::null) |
param = DeviceParam(pParamInfo, |
631 |
param = qsamplerDeviceParam(pParamInfo, param.value); |
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
|
else |
|
|
param = qsamplerDeviceParam(pParamInfo, NULL); |
|
632 |
iRefresh++; |
iRefresh++; |
633 |
} |
} |
634 |
|
|
635 |
// Free used parameter array. |
// Free used parameter array. |
636 |
delete pDepends; |
delete[] pDepends; |
637 |
|
|
638 |
// Return whether the parameters has been changed... |
// Return whether the parameters has been changed... |
639 |
return iRefresh; |
return iRefresh; |
641 |
|
|
642 |
|
|
643 |
// Redirected messages output methods. |
// Redirected messages output methods. |
644 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void Device::appendMessages( const QString& s ) const |
645 |
{ |
{ |
646 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
647 |
if (pMainForm) |
if (pMainForm) |
648 |
pMainForm->appendMessages(deviceName() + ' ' + s); |
pMainForm->appendMessages(deviceName() + ' ' + s); |
649 |
} |
} |
650 |
|
|
651 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void Device::appendMessagesColor( const QString& s, |
652 |
const QString& c ) const |
const QString& c ) const |
653 |
{ |
{ |
654 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
656 |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
657 |
} |
} |
658 |
|
|
659 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void Device::appendMessagesText( const QString& s ) const |
660 |
{ |
{ |
661 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
662 |
if (pMainForm) |
if (pMainForm) |
663 |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
664 |
} |
} |
665 |
|
|
666 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void Device::appendMessagesError( const QString& s ) const |
667 |
{ |
{ |
668 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
669 |
if (pMainForm) |
if (pMainForm) |
670 |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
671 |
} |
} |
672 |
|
|
673 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void Device::appendMessagesClient( const QString& s ) const |
674 |
{ |
{ |
675 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
676 |
if (pMainForm) |
if (pMainForm) |
679 |
|
|
680 |
|
|
681 |
// Device ids enumerator. |
// Device ids enumerator. |
682 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *Device::getDevices ( lscp_client_t *pClient, |
683 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
684 |
{ |
{ |
685 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
686 |
switch (deviceType) { |
switch (deviceType) { |
687 |
case qsamplerDevice::Audio: |
case Device::Audio: |
688 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
689 |
break; |
break; |
690 |
case qsamplerDevice::Midi: |
case Device::Midi: |
691 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
692 |
break; |
break; |
693 |
case qsamplerDevice::None: |
case Device::None: |
694 |
break; |
break; |
695 |
} |
} |
696 |
return piDeviceIDs; |
return piDeviceIDs; |
697 |
} |
} |
698 |
|
|
699 |
|
std::set<int> Device::getDeviceIDs(lscp_client_t *pClient, |
700 |
|
DeviceType deviceType) |
701 |
|
{ |
702 |
|
std::set<int> result; |
703 |
|
int* piDeviceIDs = getDevices(pClient, deviceType); |
704 |
|
if (!piDeviceIDs) return result; |
705 |
|
for (int i = 0; piDeviceIDs[i] != -1; ++i) |
706 |
|
result.insert(piDeviceIDs[i]); |
707 |
|
return result; |
708 |
|
} |
709 |
|
|
710 |
|
|
711 |
// Driver names enumerator. |
// Driver names enumerator. |
712 |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
QStringList Device::getDrivers ( lscp_client_t *pClient, |
713 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
714 |
{ |
{ |
715 |
QStringList drivers; |
QStringList drivers; |
716 |
|
|
717 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
718 |
switch (deviceType) { |
switch (deviceType) { |
719 |
case qsamplerDevice::Audio: |
case Device::Audio: |
720 |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
721 |
break; |
break; |
722 |
case qsamplerDevice::Midi: |
case Device::Midi: |
723 |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
724 |
break; |
break; |
725 |
case qsamplerDevice::None: |
case Device::None: |
726 |
break; |
break; |
727 |
} |
} |
728 |
|
|
734 |
|
|
735 |
|
|
736 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
737 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
738 |
// |
// |
739 |
|
|
740 |
// Constructor. |
// Constructor. |
741 |
qsamplerDevicePort::qsamplerDevicePort ( qsamplerDevice& device, |
DevicePort::DevicePort ( Device& device, |
742 |
int iPortID ) : m_device(device) |
int iPortID ) : m_device(device) |
743 |
{ |
{ |
744 |
setDevicePort(iPortID); |
setDevicePort(iPortID); |
745 |
} |
} |
746 |
|
|
747 |
// Default destructor. |
// Default destructor. |
748 |
qsamplerDevicePort::~qsamplerDevicePort (void) |
DevicePort::~DevicePort (void) |
749 |
{ |
{ |
750 |
} |
} |
751 |
|
|
752 |
|
|
753 |
// Initializer. |
// Initializer. |
754 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void DevicePort::setDevicePort ( int iPortID ) |
755 |
{ |
{ |
756 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
757 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
768 |
// Retrieve device port/channel info, if any. |
// Retrieve device port/channel info, if any. |
769 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
770 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
771 |
case qsamplerDevice::Audio: |
case Device::Audio: |
772 |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
773 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
774 |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
775 |
break; |
break; |
776 |
case qsamplerDevice::Midi: |
case Device::Midi: |
777 |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
778 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
779 |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
780 |
break; |
break; |
781 |
case qsamplerDevice::None: |
case Device::None: |
782 |
break; |
break; |
783 |
} |
} |
784 |
|
|
785 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
786 |
if (pPortInfo == NULL) { |
if (pPortInfo == NULL) { |
787 |
m_sPortName = QString::null; |
m_sPortName.clear(); |
788 |
return; |
return; |
789 |
} |
} |
790 |
|
|
797 |
const QString sParam = pPortInfo->params[i].key; |
const QString sParam = pPortInfo->params[i].key; |
798 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
799 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
800 |
case qsamplerDevice::Audio: |
case Device::Audio: |
801 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
802 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
803 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
804 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
805 |
break; |
break; |
806 |
case qsamplerDevice::Midi: |
case Device::Midi: |
807 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
808 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
809 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
810 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
811 |
break; |
break; |
812 |
case qsamplerDevice::None: |
case Device::None: |
813 |
break; |
break; |
814 |
} |
} |
815 |
if (pParamInfo) { |
if (pParamInfo) { |
816 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
817 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
818 |
} |
} |
819 |
} |
} |
821 |
|
|
822 |
|
|
823 |
// Device port/channel property accessors. |
// Device port/channel property accessors. |
824 |
int qsamplerDevicePort::portID (void) const |
int DevicePort::portID (void) const |
825 |
{ |
{ |
826 |
return m_iPortID; |
return m_iPortID; |
827 |
} |
} |
828 |
|
|
829 |
const QString& qsamplerDevicePort::portName (void) const |
const QString& DevicePort::portName (void) const |
830 |
{ |
{ |
831 |
return m_sPortName; |
return m_sPortName; |
832 |
} |
} |
833 |
|
|
834 |
// Device port/channel parameter accessor. |
// Device port/channel parameter accessor. |
835 |
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
const DeviceParamMap& DevicePort::params (void) const |
836 |
{ |
{ |
837 |
return m_params; |
return m_params; |
838 |
} |
} |
839 |
|
|
840 |
|
|
841 |
// Set the proper device port/channel parameter value. |
// Set the proper device port/channel parameter value. |
842 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool DevicePort::setParam ( const QString& sParam, |
843 |
const QString& sValue ) |
const QString& sValue ) |
844 |
{ |
{ |
845 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
849 |
return false; |
return false; |
850 |
|
|
851 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
852 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
853 |
|
|
854 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
855 |
int iRefresh = 0; |
int iRefresh = 0; |
856 |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
857 |
|
|
858 |
|
// we need temporary byte arrrays with the final strings, because |
859 |
|
// i.e. QString::toUtf8() only returns a temporary object and the |
860 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
861 |
|
QByteArray finalParamKey = sParam.toUtf8(); |
862 |
|
QByteArray finalParamVal = sValue.toUtf8(); |
863 |
|
|
864 |
// Prepare parameter struct. |
// Prepare parameter struct. |
865 |
lscp_param_t param; |
lscp_param_t param; |
866 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) finalParamKey.constData(); |
867 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) finalParamVal.constData(); |
868 |
// Now it depends on the device type... |
// Now it depends on the device type... |
869 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
870 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
871 |
case qsamplerDevice::Audio: |
case Device::Audio: |
872 |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
873 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
874 |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
875 |
break; |
break; |
876 |
case qsamplerDevice::Midi: |
case Device::Midi: |
877 |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
878 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
879 |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
880 |
break; |
break; |
881 |
case qsamplerDevice::None: |
case Device::None: |
882 |
break; |
break; |
883 |
} |
} |
884 |
// Show result. |
// Show result. |
899 |
|
|
900 |
|
|
901 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
902 |
// qsamplerDeviceItem - QTreeWidget device item. |
// QSampler::DeviceItem - QTreeWidget device item. |
903 |
// |
// |
904 |
|
|
905 |
// Constructors. |
// Constructors. |
906 |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
DeviceItem::DeviceItem ( QTreeWidget* pTreeWidget, |
907 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
Device::DeviceType deviceType ) |
908 |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
909 |
m_device(deviceType) |
m_device(deviceType) |
910 |
{ |
{ |
911 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
912 |
case qsamplerDevice::Audio: |
case Device::Audio: |
913 |
setIcon(0, QPixmap(":/icons/audio1.png")); |
setIcon(0, QPixmap(":/images/audio1.png")); |
914 |
setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
915 |
break; |
break; |
916 |
case qsamplerDevice::Midi: |
case Device::Midi: |
917 |
setIcon(0, QPixmap(":/icons/midi1.png")); |
setIcon(0, QPixmap(":/images/midi1.png")); |
918 |
setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
919 |
break; |
break; |
920 |
case qsamplerDevice::None: |
case Device::None: |
921 |
break; |
break; |
922 |
} |
} |
923 |
|
|
924 |
|
// Root items are not selectable... |
925 |
|
setFlags(flags() & ~Qt::ItemIsSelectable); |
926 |
} |
} |
927 |
|
|
928 |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
DeviceItem::DeviceItem ( QTreeWidgetItem* pItem, |
929 |
qsamplerDevice::qsamplerDeviceType deviceType, |
Device::DeviceType deviceType, |
930 |
int iDeviceID ) |
int iDeviceID ) |
931 |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
932 |
m_device(deviceType, iDeviceID) |
m_device(deviceType, iDeviceID) |
933 |
{ |
{ |
934 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
935 |
case qsamplerDevice::Audio: |
case Device::Audio: |
936 |
setIcon(0, QPixmap(":/icons/audio2.png")); |
setIcon(0, QPixmap(":/images/audio2.png")); |
937 |
break; |
break; |
938 |
case qsamplerDevice::Midi: |
case Device::Midi: |
939 |
setIcon(0, QPixmap(":/icons/midi2.png")); |
setIcon(0, QPixmap(":/images/midi2.png")); |
940 |
break; |
break; |
941 |
case qsamplerDevice::None: |
case Device::None: |
942 |
break; |
break; |
943 |
} |
} |
944 |
|
|
946 |
} |
} |
947 |
|
|
948 |
// Default destructor. |
// Default destructor. |
949 |
qsamplerDeviceItem::~qsamplerDeviceItem () |
DeviceItem::~DeviceItem () |
950 |
{ |
{ |
951 |
} |
} |
952 |
|
|
953 |
// Instance accessors. |
// Instance accessors. |
954 |
qsamplerDevice& qsamplerDeviceItem::device () |
Device& DeviceItem::device () |
955 |
{ |
{ |
956 |
return m_device; |
return m_device; |
957 |
} |
} |
958 |
|
|
959 |
|
|
960 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
961 |
// AbstractDeviceParamModel - data model base class for device parameters |
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
962 |
// |
// |
963 |
|
|
964 |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent ) |
965 |
params = NULL; |
: QAbstractTableModel(pParent), m_bEditable(false) |
966 |
|
{ |
967 |
|
m_pParams = NULL; |
968 |
} |
} |
969 |
|
|
970 |
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
|
971 |
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const |
972 |
return (params) ? params->size() : 0; |
{ |
973 |
|
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
974 |
|
return (m_pParams ? m_pParams->size() : 0); |
975 |
} |
} |
976 |
|
|
977 |
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
|
978 |
return 3; |
int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const |
979 |
|
{ |
980 |
|
return 3; |
981 |
} |
} |
982 |
|
|
983 |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
|
984 |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
985 |
|
{ |
986 |
|
return Qt::ItemIsEditable | Qt::ItemIsEnabled; |
987 |
} |
} |
988 |
|
|
|
QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const { |
|
|
if (!index.isValid()) { |
|
|
//std::cout << "inavlid device model index\n" << std::flush; |
|
|
return QVariant(); |
|
|
} |
|
|
if (role != Qt::DisplayRole) { |
|
|
//std::cout << "inavlid display role\n" << std::flush; |
|
|
return QVariant(); |
|
|
} |
|
989 |
|
|
990 |
DeviceParameterRow item; |
QVariant AbstractDeviceParamModel::headerData ( |
991 |
item.name = params->keys()[index.row()]; |
int section, Qt::Orientation orientation, int role) const |
992 |
item.param = (*params)[item.name]; |
{ |
993 |
|
if (role != Qt::DisplayRole) |
994 |
|
return QVariant(); |
995 |
|
|
996 |
//std::cout << "item["<<index.row()<<"]=[" << item.name.toLatin1().data() << "]\n" << std::flush; |
if (orientation == Qt::Horizontal) { |
997 |
|
switch (section) { |
998 |
|
case 0: return tr("Parameter"); |
999 |
|
case 1: return tr("Value"); |
1000 |
|
case 2: return tr("Description"); |
1001 |
|
default: return QVariant(); |
1002 |
|
} |
1003 |
|
} |
1004 |
|
|
1005 |
return QVariant::fromValue(item); |
return QVariant(); |
1006 |
} |
} |
1007 |
|
|
|
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
|
|
if (role != Qt::DisplayRole) return QVariant(); |
|
|
|
|
|
if (orientation == Qt::Horizontal) { |
|
|
switch (section) { |
|
|
case 0: return tr("Parameter"); |
|
|
case 1: return tr("Value"); |
|
|
case 2: return tr("Description"); |
|
|
default: return QVariant(); |
|
|
} |
|
|
} |
|
1008 |
|
|
1009 |
return QVariant(); |
void AbstractDeviceParamModel::refresh ( |
1010 |
|
const DeviceParamMap* pParams, bool bEditable ) |
1011 |
|
{ |
1012 |
|
m_pParams = pParams; |
1013 |
|
m_bEditable = bEditable; |
1014 |
|
// inform the outer world (QTableView) that our data changed |
1015 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
1016 |
|
QAbstractTableModel::reset(); |
1017 |
|
#else |
1018 |
|
QAbstractTableModel::beginResetModel(); |
1019 |
|
QAbstractTableModel::endResetModel(); |
1020 |
|
#endif |
1021 |
} |
} |
1022 |
|
|
|
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
|
|
this->params = params; |
|
|
this->bEditable = bEditable; |
|
|
// inform the outer world (QTableView) that our data changed |
|
|
QAbstractTableModel::reset(); |
|
|
} |
|
1023 |
|
|
1024 |
void AbstractDeviceParamModel::clear() { |
void AbstractDeviceParamModel::clear (void) |
1025 |
params = NULL; |
{ |
1026 |
// inform the outer world (QTableView) that our data changed |
m_pParams = NULL; |
1027 |
QAbstractTableModel::reset(); |
// inform the outer world (QTableView) that our data changed |
1028 |
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
1029 |
|
QAbstractTableModel::reset(); |
1030 |
|
#else |
1031 |
|
QAbstractTableModel::beginResetModel(); |
1032 |
|
QAbstractTableModel::endResetModel(); |
1033 |
|
#endif |
1034 |
} |
} |
1035 |
|
|
1036 |
|
|
1037 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1038 |
// DeviceParamModel - data model for device parameters (used for QTableView) |
// QSampler::DeviceParamModel - data model for device parameters |
1039 |
// |
// (used for QTableView) |
1040 |
|
|
1041 |
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
DeviceParamModel::DeviceParamModel ( QObject *pParent ) |
1042 |
device = NULL; |
: AbstractDeviceParamModel(pParent) |
1043 |
|
{ |
1044 |
|
m_pDevice = NULL; |
1045 |
} |
} |
1046 |
|
|
1047 |
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
QVariant DeviceParamModel::data ( |
1048 |
if (!index.isValid()) { |
const QModelIndex &index, int role) const |
1049 |
return false; |
{ |
1050 |
} |
if (!index.isValid()) |
1051 |
QString key = params->keys()[index.row()]; |
return QVariant(); |
1052 |
//params[key].value = value.toString(); |
|
1053 |
device->setParam(key, value.toString()); |
if (role != Qt::DisplayRole) |
1054 |
emit dataChanged(index, index); |
return QVariant(); |
1055 |
return true; |
|
1056 |
|
DeviceParameterRow item; |
1057 |
|
item.name = m_pParams->keys()[index.row()]; |
1058 |
|
item.param = (*m_pParams)[item.name]; |
1059 |
|
item.alive = (m_pDevice && m_pDevice->deviceID() >= 0); |
1060 |
|
|
1061 |
|
return QVariant::fromValue(item); |
1062 |
} |
} |
1063 |
|
|
1064 |
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
|
1065 |
device = pDevice; |
bool DeviceParamModel::setData ( |
1066 |
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
const QModelIndex& index, const QVariant& value, int /*role*/) |
1067 |
|
{ |
1068 |
|
if (!index.isValid()) |
1069 |
|
return false; |
1070 |
|
|
1071 |
|
QString key = m_pParams->keys()[index.row()]; |
1072 |
|
//m_pParams[key].value = value.toString(); |
1073 |
|
m_pDevice->setParam(key, value.toString()); |
1074 |
|
emit dataChanged(index, index); |
1075 |
|
return true; |
1076 |
} |
} |
1077 |
|
|
1078 |
void DeviceParamModel::clear() { |
|
1079 |
AbstractDeviceParamModel::clear(); |
void DeviceParamModel::refresh ( Device* pDevice, bool bEditable ) |
1080 |
device = NULL; |
{ |
1081 |
|
m_pDevice = pDevice; |
1082 |
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
1083 |
|
} |
1084 |
|
|
1085 |
|
|
1086 |
|
void DeviceParamModel::clear (void) |
1087 |
|
{ |
1088 |
|
AbstractDeviceParamModel::clear(); |
1089 |
|
m_pDevice = NULL; |
1090 |
} |
} |
1091 |
|
|
1092 |
|
|
1093 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1094 |
// PortParamModel - data model for port parameters (used for QTableView) |
// QSampler::PortParamModel - data model for port parameters |
1095 |
// |
// (used for QTableView) |
1096 |
|
|
1097 |
|
PortParamModel::PortParamModel ( QObject *pParent) |
1098 |
|
: AbstractDeviceParamModel(pParent) |
1099 |
|
{ |
1100 |
|
m_pPort = NULL; |
1101 |
|
} |
1102 |
|
|
1103 |
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
QVariant PortParamModel::data ( const QModelIndex &index, int role ) const |
1104 |
port = NULL; |
{ |
1105 |
|
if (!index.isValid()) |
1106 |
|
return QVariant(); |
1107 |
|
|
1108 |
|
if (role != Qt::DisplayRole) |
1109 |
|
return QVariant(); |
1110 |
|
|
1111 |
|
DeviceParameterRow item; |
1112 |
|
item.name = m_pParams->keys()[index.row()]; |
1113 |
|
item.param = (*m_pParams)[item.name]; |
1114 |
|
item.alive = (m_pPort && m_pPort->portID() >= 0); |
1115 |
|
|
1116 |
|
return QVariant::fromValue(item); |
1117 |
} |
} |
1118 |
|
|
1119 |
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
|
1120 |
if (!index.isValid()) { |
bool PortParamModel::setData ( |
1121 |
return false; |
const QModelIndex& index, const QVariant& value, int /*role*/) |
1122 |
} |
{ |
1123 |
QString key = params->keys()[index.row()]; |
if (!index.isValid()) |
1124 |
//params[key].value = value.toString(); |
return false; |
1125 |
port->setParam(key, value.toString()); |
|
1126 |
emit dataChanged(index, index); |
QString key = m_pParams->keys()[index.row()]; |
1127 |
return true; |
//params[key].value = value.toString(); |
1128 |
|
m_pPort->setParam(key, value.toString()); |
1129 |
|
emit dataChanged(index, index); |
1130 |
|
return true; |
1131 |
} |
} |
1132 |
|
|
1133 |
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
|
1134 |
port = pPort; |
void PortParamModel::refresh ( DevicePort* pPort, bool bEditable ) |
1135 |
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
{ |
1136 |
|
m_pPort = pPort; |
1137 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1138 |
} |
} |
1139 |
|
|
1140 |
void PortParamModel::clear() { |
|
1141 |
AbstractDeviceParamModel::clear(); |
void PortParamModel::clear (void) |
1142 |
port = NULL; |
{ |
1143 |
|
AbstractDeviceParamModel::clear(); |
1144 |
|
m_pPort = NULL; |
1145 |
} |
} |
1146 |
|
|
1147 |
|
|
1148 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1149 |
// DeviceParamDelegate - table cell renderer for device/port parameters |
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
1150 |
// |
// |
1151 |
|
|
1152 |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent) |
1153 |
|
: QItemDelegate(pParent) |
1154 |
|
{ |
1155 |
} |
} |
1156 |
|
|
1157 |
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
|
1158 |
const QStyleOptionViewItem &/* option */, |
QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent, |
1159 |
const QModelIndex& index) const |
const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const |
1160 |
{ |
{ |
1161 |
if (!index.isValid()) { |
if (!index.isValid()) |
1162 |
return NULL; |
return NULL; |
1163 |
} |
|
1164 |
|
DeviceParameterRow r = index.model()->data(index, |
1165 |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
Qt::DisplayRole).value<DeviceParameterRow>(); |
1166 |
|
|
1167 |
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
const bool bEnabled = (r.alive) ? !r.param.fix : true; |
1168 |
|
const bool bFix = r.param.fix; |
1169 |
switch (index.column()) { |
|
1170 |
case 0: |
QString val = (r.alive) ? r.param.value : r.param.defaultv; |
1171 |
return new QLabel(r.name, parent); |
|
1172 |
case 1: { |
switch (index.column()) { |
1173 |
if (r.param.type == LSCP_TYPE_BOOL) { |
case 0: |
1174 |
QCheckBox* pCheckBox = new QCheckBox(parent); |
return new QLabel(r.name, pParent); |
1175 |
pCheckBox->setChecked(r.param.value.lower() == "true"); |
case 1: { |
1176 |
pCheckBox->setEnabled(bEnabled); |
if (r.param.type == LSCP_TYPE_BOOL) { |
1177 |
return pCheckBox; |
QCheckBox *pCheckBox = new QCheckBox(pParent); |
1178 |
} else if (r.param.possibilities.count() > 0) { |
if (!val.isEmpty()) |
1179 |
QStringList opts = r.param.possibilities; |
pCheckBox->setChecked(val.toLower() == "true"); |
1180 |
if (r.param.multiplicity) |
pCheckBox->setEnabled(bEnabled); |
1181 |
opts.prepend(tr("(none)")); |
pCheckBox->setCheckable(!bFix); |
1182 |
QComboBox* pComboBox = new QComboBox(parent); |
return pCheckBox; |
1183 |
pComboBox->addItems(opts); |
} else if (r.param.possibilities.count() > 0) { |
1184 |
if (r.param.value.isEmpty()) |
QStringList opts = r.param.possibilities; |
1185 |
pComboBox->setCurrentIndex(0); |
if (r.param.multiplicity) |
1186 |
else |
opts.prepend(tr("(none)")); |
1187 |
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
QComboBox *pComboBox = new QComboBox(pParent); |
1188 |
pComboBox->setEnabled(bEnabled); |
pComboBox->addItems(opts); |
1189 |
return pComboBox; |
if (r.param.value.isEmpty()) |
1190 |
} else if (r.param.type == LSCP_TYPE_INT |
pComboBox->setCurrentIndex(0); |
1191 |
&& !r.param.range_min.isEmpty() |
else |
1192 |
&& !r.param.range_max.isEmpty()) { |
pComboBox->setCurrentIndex(pComboBox->findText(val)); |
1193 |
QSpinBox* pSpinBox = new QSpinBox(parent); |
pComboBox->setEnabled(bEnabled); |
1194 |
pSpinBox->setValue(r.param.value.toInt()); |
pComboBox->setEditable(!bFix); |
1195 |
pSpinBox->setMinimum(r.param.range_min.toInt()); |
return pComboBox; |
1196 |
pSpinBox->setMaximum(r.param.range_max.toInt()); |
} else if (r.param.type == LSCP_TYPE_INT && bEnabled) { |
1197 |
pSpinBox->setEnabled(bEnabled); |
QSpinBox *pSpinBox = new QSpinBox(pParent); |
1198 |
return pSpinBox; |
pSpinBox->setMinimum( |
1199 |
} else { |
(!r.param.range_min.isEmpty()) ? |
1200 |
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
r.param.range_min.toInt() : 0 // or better a negative default min value ? |
1201 |
pLineEdit->setEnabled(bEnabled); |
); |
1202 |
return pLineEdit; |
pSpinBox->setMaximum( |
1203 |
} |
(!r.param.range_max.isEmpty()) ? |
1204 |
} |
r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ? |
1205 |
case 2: |
); |
1206 |
return new QLabel(r.param.description, parent); |
pSpinBox->setValue(val.toInt()); |
1207 |
default: |
pSpinBox->setReadOnly(bFix); |
1208 |
return NULL; |
return pSpinBox; |
1209 |
} |
} else if (bEnabled) { |
1210 |
} |
QLineEdit *pLineEdit = new QLineEdit(val, pParent); |
1211 |
|
pLineEdit->setReadOnly(bFix); |
1212 |
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
return pLineEdit; |
1213 |
// unused, since we set the editor data already in createEditor() |
} else { |
1214 |
} |
QLabel *pLabel = new QLabel(val, pParent); |
1215 |
|
return pLabel; |
1216 |
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
} |
1217 |
if (index.column() == 1) { |
} |
1218 |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
case 2: |
1219 |
if (r.param.type == LSCP_TYPE_BOOL) { |
return new QLabel(r.param.description, pParent); |
1220 |
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
default: |
1221 |
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
return NULL; |
1222 |
} else if (r.param.possibilities.count() > 0) { |
} |
1223 |
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
} |
1224 |
model->setData(index, pComboBox->currentText()); |
|
1225 |
} else if (r.param.type == LSCP_TYPE_INT) { |
|
1226 |
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
void DeviceParamDelegate::setEditorData ( |
1227 |
model->setData(index, pSpinBox->value()); |
QWidget* /*pEditor*/, const QModelIndex& /*index*/) const |
1228 |
} else { |
{ |
1229 |
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
// Unused, since we set the editor data already in createEditor() |
1230 |
model->setData(index, pLineEdit->text()); |
} |
1231 |
} |
|
1232 |
} |
|
1233 |
|
void DeviceParamDelegate::setModelData ( QWidget *pEditor, |
1234 |
|
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1235 |
|
{ |
1236 |
|
if (index.column() == 1) { |
1237 |
|
DeviceParameterRow r = index.model()->data(index, |
1238 |
|
Qt::DisplayRole).value<DeviceParameterRow> (); |
1239 |
|
if (pEditor->metaObject()->className() == QString("QCheckBox")) { |
1240 |
|
QCheckBox *pCheckBox = static_cast<QCheckBox *> (pEditor); |
1241 |
|
pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1242 |
|
} else if (pEditor->metaObject()->className() == QString("QComboBox")) { |
1243 |
|
QComboBox *pComboBox = static_cast<QComboBox *> (pEditor); |
1244 |
|
pModel->setData(index, pComboBox->currentText()); |
1245 |
|
} else if (pEditor->metaObject()->className() == QString("QSpinBox")) { |
1246 |
|
QSpinBox *pSpinBox = static_cast<QSpinBox *> (pEditor); |
1247 |
|
pModel->setData(index, pSpinBox->value()); |
1248 |
|
} else if (pEditor->metaObject()->className() == QString("QLineEdit")) { |
1249 |
|
QLineEdit *pLineEdit = static_cast<QLineEdit *> (pEditor); |
1250 |
|
pModel->setData(index, pLineEdit->text()); |
1251 |
|
} else if (pEditor->metaObject()->className() == QString("QLabel")) { |
1252 |
|
QLabel *pLabel = static_cast<QLabel *> (pEditor); |
1253 |
|
pModel->setData(index, pLabel->text()); |
1254 |
|
} |
1255 |
|
} |
1256 |
} |
} |
1257 |
|
|
1258 |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor, |
1259 |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1260 |
{ |
{ |
1261 |
if (editor) editor->setGeometry(option.rect); |
if (pEditor) |
1262 |
|
pEditor->setGeometry(option.rect); |
1263 |
} |
} |
1264 |
|
|
1265 |
|
} // namespace QSampler |
1266 |
|
|
1267 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |