31 |
#include <QLineEdit> |
#include <QLineEdit> |
32 |
|
|
33 |
|
|
34 |
using namespace QSampler; |
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); |
46 |
|
|
47 |
|
|
48 |
// Default destructor. |
// Default destructor. |
49 |
qsamplerDeviceParam::~qsamplerDeviceParam (void) |
DeviceParam::~DeviceParam (void) |
50 |
{ |
{ |
51 |
} |
} |
52 |
|
|
53 |
|
|
54 |
// Initializer. |
// Initializer. |
55 |
void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
void DeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
56 |
const char *pszValue ) |
const char *pszValue ) |
57 |
{ |
{ |
58 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
103 |
|
|
104 |
|
|
105 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
106 |
// qsamplerDevice - MIDI/Audio Device structure. |
// QSampler::Device - MIDI/Audio Device structure. |
107 |
// |
// |
108 |
|
|
109 |
// Constructor. |
// Constructor. |
110 |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
Device::Device ( DeviceType deviceType, int iDeviceID ) |
111 |
{ |
{ |
112 |
// m_ports.setAutoDelete(true); |
// m_ports.setAutoDelete(true); |
113 |
|
|
115 |
} |
} |
116 |
|
|
117 |
// Default destructor. |
// Default destructor. |
118 |
qsamplerDevice::~qsamplerDevice (void) |
Device::~Device (void) |
119 |
{ |
{ |
120 |
qDeleteAll(m_ports); |
qDeleteAll(m_ports); |
121 |
m_ports.clear(); |
m_ports.clear(); |
122 |
} |
} |
123 |
|
|
124 |
// Copy constructor. |
// Copy constructor. |
125 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
Device::Device ( const Device& device ) |
126 |
: m_params(device.m_params), m_ports(device.m_ports) |
: m_params(device.m_params), m_ports(device.m_ports) |
127 |
{ |
{ |
128 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
134 |
|
|
135 |
|
|
136 |
// Initializer. |
// Initializer. |
137 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void Device::setDevice ( DeviceType deviceType, int iDeviceID ) |
138 |
{ |
{ |
139 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
140 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
154 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
155 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
156 |
switch (deviceType) { |
switch (deviceType) { |
157 |
case qsamplerDevice::Audio: |
case Device::Audio: |
158 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
159 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
160 |
pMainForm->client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
161 |
appendMessagesClient("lscp_get_audio_device_info"); |
appendMessagesClient("lscp_get_audio_device_info"); |
162 |
break; |
break; |
163 |
case qsamplerDevice::Midi: |
case Device::Midi: |
164 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
165 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
166 |
pMainForm->client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
167 |
appendMessagesClient("lscp_get_midi_device_info"); |
appendMessagesClient("lscp_get_midi_device_info"); |
168 |
break; |
break; |
169 |
case qsamplerDevice::None: |
case Device::None: |
170 |
m_sDeviceType = QString::null; |
m_sDeviceType = QString::null; |
171 |
break; |
break; |
172 |
} |
} |
187 |
const QString sParam = pDeviceInfo->params[i].key; |
const QString sParam = pDeviceInfo->params[i].key; |
188 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
189 |
switch (deviceType) { |
switch (deviceType) { |
190 |
case qsamplerDevice::Audio: |
case Device::Audio: |
191 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
192 |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
193 |
sParam.toUtf8().constData(), NULL)) == NULL) |
sParam.toUtf8().constData(), NULL)) == NULL) |
194 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
195 |
break; |
break; |
196 |
case qsamplerDevice::Midi: |
case Device::Midi: |
197 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
198 |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
199 |
sParam.toUtf8().constData(), NULL)) == NULL) |
sParam.toUtf8().constData(), NULL)) == NULL) |
200 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
201 |
break; |
break; |
202 |
case qsamplerDevice::None: |
case Device::None: |
203 |
break; |
break; |
204 |
} |
} |
205 |
if (pParamInfo) { |
if (pParamInfo) { |
206 |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
207 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
208 |
} |
} |
209 |
} |
} |
216 |
|
|
217 |
|
|
218 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
219 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void Device::setDriver ( const QString& sDriverName ) |
220 |
{ |
{ |
221 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
222 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
236 |
// Retrieve driver info, if any. |
// Retrieve driver info, if any. |
237 |
lscp_driver_info_t *pDriverInfo = NULL; |
lscp_driver_info_t *pDriverInfo = NULL; |
238 |
switch (m_deviceType) { |
switch (m_deviceType) { |
239 |
case qsamplerDevice::Audio: |
case Device::Audio: |
240 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
241 |
sDriverName.toUtf8().constData())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
242 |
appendMessagesClient("lscp_get_audio_driver_info"); |
appendMessagesClient("lscp_get_audio_driver_info"); |
243 |
break; |
break; |
244 |
case qsamplerDevice::Midi: |
case Device::Midi: |
245 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
246 |
sDriverName.toUtf8().constData())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
247 |
appendMessagesClient("lscp_get_midi_driver_info"); |
appendMessagesClient("lscp_get_midi_driver_info"); |
248 |
break; |
break; |
249 |
case qsamplerDevice::None: |
case Device::None: |
250 |
break; |
break; |
251 |
} |
} |
252 |
|
|
262 |
const QString sParam = pDriverInfo->parameters[i]; |
const QString sParam = pDriverInfo->parameters[i]; |
263 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
264 |
switch (m_deviceType) { |
switch (m_deviceType) { |
265 |
case qsamplerDevice::Audio: |
case Device::Audio: |
266 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
267 |
pMainForm->client(), sDriverName.toUtf8().constData(), |
pMainForm->client(), sDriverName.toUtf8().constData(), |
268 |
sParam.toUtf8().constData(), NULL)) == NULL) |
sParam.toUtf8().constData(), NULL)) == NULL) |
269 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
270 |
break; |
break; |
271 |
case qsamplerDevice::Midi: |
case Device::Midi: |
272 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
273 |
pMainForm->client(), sDriverName.toUtf8().constData(), |
pMainForm->client(), sDriverName.toUtf8().constData(), |
274 |
sParam.toUtf8().constData(), NULL)) == NULL) |
sParam.toUtf8().constData(), NULL)) == NULL) |
275 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
276 |
break; |
break; |
277 |
case qsamplerDevice::None: |
case Device::None: |
278 |
break; |
break; |
279 |
} |
} |
280 |
if (pParamInfo) { |
if (pParamInfo) { |
281 |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
282 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
283 |
} |
} |
284 |
} |
} |
291 |
|
|
292 |
|
|
293 |
// Device property accessors. |
// Device property accessors. |
294 |
int qsamplerDevice::deviceID (void) const |
int Device::deviceID (void) const |
295 |
{ |
{ |
296 |
return m_iDeviceID; |
return m_iDeviceID; |
297 |
} |
} |
298 |
|
|
299 |
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
Device::DeviceType Device::deviceType (void) const |
300 |
{ |
{ |
301 |
return m_deviceType; |
return m_deviceType; |
302 |
} |
} |
303 |
|
|
304 |
const QString& qsamplerDevice::deviceTypeName (void) const |
const QString& Device::deviceTypeName (void) const |
305 |
{ |
{ |
306 |
return m_sDeviceType; |
return m_sDeviceType; |
307 |
} |
} |
308 |
|
|
309 |
const QString& qsamplerDevice::driverName (void) const |
const QString& Device::driverName (void) const |
310 |
{ |
{ |
311 |
return m_sDriverName; |
return m_sDriverName; |
312 |
} |
} |
313 |
|
|
314 |
// Special device name formatter. |
// Special device name formatter. |
315 |
QString qsamplerDevice::deviceName (void) const |
QString Device::deviceName (void) const |
316 |
{ |
{ |
317 |
QString sPrefix; |
QString sPrefix; |
318 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
319 |
sPrefix += m_sDeviceType + ' '; |
sPrefix += m_sDeviceType + ' '; |
320 |
return sPrefix + m_sDeviceName; |
return sPrefix + m_sDeviceName; |
321 |
} |
} |
322 |
|
|
323 |
|
|
324 |
// Set the proper device parameter value. |
// Set the proper device parameter value. |
325 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool Device::setParam ( const QString& sParam, |
326 |
const QString& sValue ) |
const QString& sValue ) |
327 |
{ |
{ |
328 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
351 |
// Now it depends on the device type... |
// Now it depends on the device type... |
352 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
353 |
switch (m_deviceType) { |
switch (m_deviceType) { |
354 |
case qsamplerDevice::Audio: |
case Device::Audio: |
355 |
if (sParam == "CHANNELS") iRefresh++; |
if (sParam == "CHANNELS") iRefresh++; |
356 |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
357 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
358 |
appendMessagesClient("lscp_set_audio_device_param"); |
appendMessagesClient("lscp_set_audio_device_param"); |
359 |
break; |
break; |
360 |
case qsamplerDevice::Midi: |
case Device::Midi: |
361 |
if (sParam == "PORTS") iRefresh++; |
if (sParam == "PORTS") iRefresh++; |
362 |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
363 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
364 |
appendMessagesClient("lscp_set_midi_device_param"); |
appendMessagesClient("lscp_set_midi_device_param"); |
365 |
break; |
break; |
366 |
case qsamplerDevice::None: |
case Device::None: |
367 |
break; |
break; |
368 |
} |
} |
369 |
// Show result. |
// Show result. |
386 |
|
|
387 |
|
|
388 |
// Device parameter accessor. |
// Device parameter accessor. |
389 |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
const DeviceParamMap& Device::params (void) const |
390 |
{ |
{ |
391 |
return m_params; |
return m_params; |
392 |
} |
} |
393 |
|
|
394 |
|
|
395 |
// Device port/channel list accessor. |
// Device port/channel list accessor. |
396 |
qsamplerDevicePortList& qsamplerDevice::ports (void) |
DevicePortList& Device::ports (void) |
397 |
{ |
{ |
398 |
return m_ports; |
return m_ports; |
399 |
} |
} |
400 |
|
|
401 |
|
|
402 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
403 |
bool qsamplerDevice::createDevice (void) |
bool Device::createDevice (void) |
404 |
{ |
{ |
405 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
406 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
414 |
QList<QByteArray> finalKeys; |
QList<QByteArray> finalKeys; |
415 |
QList<QByteArray> finalVals; |
QList<QByteArray> finalVals; |
416 |
|
|
417 |
qsamplerDeviceParamMap::ConstIterator iter; |
DeviceParamMap::ConstIterator iter; |
418 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
419 |
if (iter.value().value == QString::null) continue; |
if (iter.value().value == QString::null) continue; |
420 |
finalKeys.push_back(iter.key().toUtf8()); |
finalKeys.push_back(iter.key().toUtf8()); |
436 |
|
|
437 |
// Now it depends on the device type... |
// Now it depends on the device type... |
438 |
switch (m_deviceType) { |
switch (m_deviceType) { |
439 |
case qsamplerDevice::Audio: |
case Device::Audio: |
440 |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
441 |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
442 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
443 |
break; |
break; |
444 |
case qsamplerDevice::Midi: |
case Device::Midi: |
445 |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
446 |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
447 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
448 |
break; |
break; |
449 |
case qsamplerDevice::None: |
case Device::None: |
450 |
break; |
break; |
451 |
} |
} |
452 |
|
|
468 |
|
|
469 |
|
|
470 |
// Destroy existing device. |
// Destroy existing device. |
471 |
bool qsamplerDevice::deleteDevice (void) |
bool Device::deleteDevice (void) |
472 |
{ |
{ |
473 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
474 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
479 |
// Now it depends on the device type... |
// Now it depends on the device type... |
480 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
481 |
switch (m_deviceType) { |
switch (m_deviceType) { |
482 |
case qsamplerDevice::Audio: |
case Device::Audio: |
483 |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
484 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
485 |
appendMessagesClient("lscp_destroy_audio_device"); |
appendMessagesClient("lscp_destroy_audio_device"); |
486 |
break; |
break; |
487 |
case qsamplerDevice::Midi: |
case Device::Midi: |
488 |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
489 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
490 |
appendMessagesClient("lscp_destroy_midi_device"); |
appendMessagesClient("lscp_destroy_midi_device"); |
491 |
break; |
break; |
492 |
case qsamplerDevice::None: |
case Device::None: |
493 |
break; |
break; |
494 |
} |
} |
495 |
|
|
507 |
|
|
508 |
|
|
509 |
// Device parameter dependencies refreshner. |
// Device parameter dependencies refreshner. |
510 |
int qsamplerDevice::refreshParams (void) |
int Device::refreshParams (void) |
511 |
{ |
{ |
512 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
513 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
514 |
return 0; |
return 0; |
515 |
// Refresh all parameters that have dependencies... |
// Refresh all parameters that have dependencies... |
516 |
int iParams = 0; |
int iParams = 0; |
517 |
qsamplerDeviceParamMap::ConstIterator iter; |
DeviceParamMap::ConstIterator iter; |
518 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
519 |
iParams += refreshParam(iter.key()); |
iParams += refreshParam(iter.key()); |
520 |
// Return how many parameters have been refreshed... |
// Return how many parameters have been refreshed... |
523 |
|
|
524 |
|
|
525 |
// Device port/channel list refreshner. |
// Device port/channel list refreshner. |
526 |
int qsamplerDevice::refreshPorts (void) |
int Device::refreshPorts (void) |
527 |
{ |
{ |
528 |
// This should only make sense for actual devices... |
// This should only make sense for actual devices... |
529 |
if (m_iDeviceID < 0) |
if (m_iDeviceID < 0) |
530 |
return 0; |
return 0; |
531 |
// Port/channel count determination... |
// Port/channel count determination... |
532 |
int iPorts = 0; |
int iPorts = 0; |
533 |
switch (m_deviceType) { |
switch (m_deviceType) { |
534 |
case qsamplerDevice::Audio: |
case Device::Audio: |
535 |
iPorts = m_params["CHANNELS"].value.toInt(); |
iPorts = m_params["CHANNELS"].value.toInt(); |
536 |
break; |
break; |
537 |
case qsamplerDevice::Midi: |
case Device::Midi: |
538 |
iPorts = m_params["PORTS"].value.toInt(); |
iPorts = m_params["PORTS"].value.toInt(); |
539 |
break; |
break; |
540 |
case qsamplerDevice::None: |
case Device::None: |
541 |
break; |
break; |
542 |
} |
} |
543 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
544 |
qDeleteAll(m_ports); |
qDeleteAll(m_ports); |
545 |
m_ports.clear(); |
m_ports.clear(); |
546 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
547 |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
m_ports.append(new DevicePort(*this, iPort)); |
548 |
// Return how many ports have been refreshed... |
// Return how many ports have been refreshed... |
549 |
return iPorts; |
return iPorts; |
550 |
} |
} |
551 |
|
|
552 |
|
|
553 |
// Refresh/set dependencies given that some parameter has changed. |
// Refresh/set dependencies given that some parameter has changed. |
554 |
int qsamplerDevice::refreshDepends ( const QString& sParam ) |
int Device::refreshDepends ( const QString& sParam ) |
555 |
{ |
{ |
556 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
557 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
558 |
return 0; |
return 0; |
559 |
// Refresh all parameters that depend on this one... |
// Refresh all parameters that depend on this one... |
560 |
int iDepends = 0; |
int iDepends = 0; |
561 |
qsamplerDeviceParamMap::ConstIterator iter; |
DeviceParamMap::ConstIterator iter; |
562 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
563 |
const QStringList& depends = iter.value().depends; |
const QStringList& depends = iter.value().depends; |
564 |
if (depends.indexOf(sParam) >= 0) |
if (depends.indexOf(sParam) >= 0) |
570 |
|
|
571 |
|
|
572 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
573 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int Device::refreshParam ( const QString& sParam ) |
574 |
{ |
{ |
575 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
576 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
579 |
return 0; |
return 0; |
580 |
|
|
581 |
// Check if we have dependencies... |
// Check if we have dependencies... |
582 |
qsamplerDeviceParam& param = m_params[sParam.toUpper()]; |
DeviceParam& param = m_params[sParam.toUpper()]; |
583 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
584 |
return 0; |
return 0; |
585 |
|
|
617 |
// Retrieve some modern parameters... |
// Retrieve some modern parameters... |
618 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
619 |
switch (m_deviceType) { |
switch (m_deviceType) { |
620 |
case qsamplerDevice::Audio: |
case Device::Audio: |
621 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
622 |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
623 |
sParam.toUtf8().constData(), pDepends)) == NULL) |
sParam.toUtf8().constData(), pDepends)) == NULL) |
624 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
625 |
break; |
break; |
626 |
case qsamplerDevice::Midi: |
case Device::Midi: |
627 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
628 |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
629 |
sParam.toUtf8().constData(), pDepends)) == NULL) |
sParam.toUtf8().constData(), pDepends)) == NULL) |
630 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
631 |
break; |
break; |
632 |
case qsamplerDevice::None: |
case Device::None: |
633 |
break; |
break; |
634 |
} |
} |
635 |
if (pParamInfo) { |
if (pParamInfo) { |
636 |
param = qsamplerDeviceParam(pParamInfo, |
param = DeviceParam(pParamInfo, |
637 |
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
638 |
iRefresh++; |
iRefresh++; |
639 |
} |
} |
647 |
|
|
648 |
|
|
649 |
// Redirected messages output methods. |
// Redirected messages output methods. |
650 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void Device::appendMessages( const QString& s ) const |
651 |
{ |
{ |
652 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
653 |
if (pMainForm) |
if (pMainForm) |
654 |
pMainForm->appendMessages(deviceName() + ' ' + s); |
pMainForm->appendMessages(deviceName() + ' ' + s); |
655 |
} |
} |
656 |
|
|
657 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void Device::appendMessagesColor( const QString& s, |
658 |
const QString& c ) const |
const QString& c ) const |
659 |
{ |
{ |
660 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
662 |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
663 |
} |
} |
664 |
|
|
665 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void Device::appendMessagesText( const QString& s ) const |
666 |
{ |
{ |
667 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
668 |
if (pMainForm) |
if (pMainForm) |
669 |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
670 |
} |
} |
671 |
|
|
672 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void Device::appendMessagesError( const QString& s ) const |
673 |
{ |
{ |
674 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
675 |
if (pMainForm) |
if (pMainForm) |
676 |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
677 |
} |
} |
678 |
|
|
679 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void Device::appendMessagesClient( const QString& s ) const |
680 |
{ |
{ |
681 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
682 |
if (pMainForm) |
if (pMainForm) |
685 |
|
|
686 |
|
|
687 |
// Device ids enumerator. |
// Device ids enumerator. |
688 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *Device::getDevices ( lscp_client_t *pClient, |
689 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
690 |
{ |
{ |
691 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
692 |
switch (deviceType) { |
switch (deviceType) { |
693 |
case qsamplerDevice::Audio: |
case Device::Audio: |
694 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
695 |
break; |
break; |
696 |
case qsamplerDevice::Midi: |
case Device::Midi: |
697 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
698 |
break; |
break; |
699 |
case qsamplerDevice::None: |
case Device::None: |
700 |
break; |
break; |
701 |
} |
} |
702 |
return piDeviceIDs; |
return piDeviceIDs; |
704 |
|
|
705 |
|
|
706 |
// Driver names enumerator. |
// Driver names enumerator. |
707 |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
QStringList Device::getDrivers ( lscp_client_t *pClient, |
708 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
709 |
{ |
{ |
710 |
QStringList drivers; |
QStringList drivers; |
711 |
|
|
712 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
713 |
switch (deviceType) { |
switch (deviceType) { |
714 |
case qsamplerDevice::Audio: |
case Device::Audio: |
715 |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
716 |
break; |
break; |
717 |
case qsamplerDevice::Midi: |
case Device::Midi: |
718 |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
719 |
break; |
break; |
720 |
case qsamplerDevice::None: |
case Device::None: |
721 |
break; |
break; |
722 |
} |
} |
723 |
|
|
729 |
|
|
730 |
|
|
731 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
732 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
733 |
// |
// |
734 |
|
|
735 |
// Constructor. |
// Constructor. |
736 |
qsamplerDevicePort::qsamplerDevicePort ( qsamplerDevice& device, |
DevicePort::DevicePort ( Device& device, |
737 |
int iPortID ) : m_device(device) |
int iPortID ) : m_device(device) |
738 |
{ |
{ |
739 |
setDevicePort(iPortID); |
setDevicePort(iPortID); |
740 |
} |
} |
741 |
|
|
742 |
// Default destructor. |
// Default destructor. |
743 |
qsamplerDevicePort::~qsamplerDevicePort (void) |
DevicePort::~DevicePort (void) |
744 |
{ |
{ |
745 |
} |
} |
746 |
|
|
747 |
|
|
748 |
// Initializer. |
// Initializer. |
749 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void DevicePort::setDevicePort ( int iPortID ) |
750 |
{ |
{ |
751 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
752 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
763 |
// Retrieve device port/channel info, if any. |
// Retrieve device port/channel info, if any. |
764 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
765 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
766 |
case qsamplerDevice::Audio: |
case Device::Audio: |
767 |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
768 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
769 |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
770 |
break; |
break; |
771 |
case qsamplerDevice::Midi: |
case Device::Midi: |
772 |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
773 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
774 |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
775 |
break; |
break; |
776 |
case qsamplerDevice::None: |
case Device::None: |
777 |
break; |
break; |
778 |
} |
} |
779 |
|
|
792 |
const QString sParam = pPortInfo->params[i].key; |
const QString sParam = pPortInfo->params[i].key; |
793 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
794 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
795 |
case qsamplerDevice::Audio: |
case Device::Audio: |
796 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
797 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
798 |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
799 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
800 |
break; |
break; |
801 |
case qsamplerDevice::Midi: |
case Device::Midi: |
802 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
803 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
804 |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
805 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
806 |
break; |
break; |
807 |
case qsamplerDevice::None: |
case Device::None: |
808 |
break; |
break; |
809 |
} |
} |
810 |
if (pParamInfo) { |
if (pParamInfo) { |
811 |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
812 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
813 |
} |
} |
814 |
} |
} |
816 |
|
|
817 |
|
|
818 |
// Device port/channel property accessors. |
// Device port/channel property accessors. |
819 |
int qsamplerDevicePort::portID (void) const |
int DevicePort::portID (void) const |
820 |
{ |
{ |
821 |
return m_iPortID; |
return m_iPortID; |
822 |
} |
} |
823 |
|
|
824 |
const QString& qsamplerDevicePort::portName (void) const |
const QString& DevicePort::portName (void) const |
825 |
{ |
{ |
826 |
return m_sPortName; |
return m_sPortName; |
827 |
} |
} |
828 |
|
|
829 |
// Device port/channel parameter accessor. |
// Device port/channel parameter accessor. |
830 |
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
const DeviceParamMap& DevicePort::params (void) const |
831 |
{ |
{ |
832 |
return m_params; |
return m_params; |
833 |
} |
} |
834 |
|
|
835 |
|
|
836 |
// Set the proper device port/channel parameter value. |
// Set the proper device port/channel parameter value. |
837 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool DevicePort::setParam ( const QString& sParam, |
838 |
const QString& sValue ) |
const QString& sValue ) |
839 |
{ |
{ |
840 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
863 |
// Now it depends on the device type... |
// Now it depends on the device type... |
864 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
865 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
866 |
case qsamplerDevice::Audio: |
case Device::Audio: |
867 |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
868 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
869 |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
870 |
break; |
break; |
871 |
case qsamplerDevice::Midi: |
case Device::Midi: |
872 |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
if ((ret = ::lscp_set_midi_port_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_midi_port_param"); |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
875 |
break; |
break; |
876 |
case qsamplerDevice::None: |
case Device::None: |
877 |
break; |
break; |
878 |
} |
} |
879 |
// Show result. |
// Show result. |
894 |
|
|
895 |
|
|
896 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
897 |
// qsamplerDeviceItem - QTreeWidget device item. |
// QSampler::DeviceItem - QTreeWidget device item. |
898 |
// |
// |
899 |
|
|
900 |
// Constructors. |
// Constructors. |
901 |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
DeviceItem::DeviceItem ( QTreeWidget* pTreeWidget, |
902 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
Device::DeviceType deviceType ) |
903 |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
904 |
m_device(deviceType) |
m_device(deviceType) |
905 |
{ |
{ |
906 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
907 |
case qsamplerDevice::Audio: |
case Device::Audio: |
908 |
setIcon(0, QPixmap(":/icons/audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
909 |
setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
910 |
break; |
break; |
911 |
case qsamplerDevice::Midi: |
case Device::Midi: |
912 |
setIcon(0, QPixmap(":/icons/midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
913 |
setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
914 |
break; |
break; |
915 |
case qsamplerDevice::None: |
case Device::None: |
916 |
break; |
break; |
917 |
} |
} |
918 |
|
|
919 |
|
// Root items are not selectable... |
920 |
|
setFlags(flags() & ~Qt::ItemIsSelectable); |
921 |
} |
} |
922 |
|
|
923 |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
DeviceItem::DeviceItem ( QTreeWidgetItem* pItem, |
924 |
qsamplerDevice::qsamplerDeviceType deviceType, |
Device::DeviceType deviceType, |
925 |
int iDeviceID ) |
int iDeviceID ) |
926 |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
927 |
m_device(deviceType, iDeviceID) |
m_device(deviceType, iDeviceID) |
928 |
{ |
{ |
929 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
930 |
case qsamplerDevice::Audio: |
case Device::Audio: |
931 |
setIcon(0, QPixmap(":/icons/audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
932 |
break; |
break; |
933 |
case qsamplerDevice::Midi: |
case Device::Midi: |
934 |
setIcon(0, QPixmap(":/icons/midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
935 |
break; |
break; |
936 |
case qsamplerDevice::None: |
case Device::None: |
937 |
break; |
break; |
938 |
} |
} |
939 |
|
|
941 |
} |
} |
942 |
|
|
943 |
// Default destructor. |
// Default destructor. |
944 |
qsamplerDeviceItem::~qsamplerDeviceItem () |
DeviceItem::~DeviceItem () |
945 |
{ |
{ |
946 |
} |
} |
947 |
|
|
948 |
// Instance accessors. |
// Instance accessors. |
949 |
qsamplerDevice& qsamplerDeviceItem::device () |
Device& DeviceItem::device () |
950 |
{ |
{ |
951 |
return m_device; |
return m_device; |
952 |
} |
} |
953 |
|
|
954 |
|
|
955 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
956 |
// AbstractDeviceParamModel - data model base class for device parameters |
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
957 |
// |
// |
958 |
|
|
959 |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent ) |
960 |
params = NULL; |
: QAbstractTableModel(pParent), m_bEditable(false) |
961 |
|
{ |
962 |
|
m_pParams = NULL; |
963 |
} |
} |
964 |
|
|
965 |
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
|
966 |
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const |
967 |
return (params) ? params->size() : 0; |
{ |
968 |
|
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
969 |
|
return (m_pParams ? m_pParams->size() : 0); |
970 |
} |
} |
971 |
|
|
972 |
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
|
973 |
return 3; |
int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const |
974 |
|
{ |
975 |
|
return 3; |
976 |
} |
} |
977 |
|
|
978 |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
|
979 |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
980 |
|
{ |
981 |
|
return Qt::ItemIsEditable | Qt::ItemIsEnabled; |
982 |
} |
} |
983 |
|
|
|
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
|
|
if (role != Qt::DisplayRole) return QVariant(); |
|
984 |
|
|
985 |
if (orientation == Qt::Horizontal) { |
QVariant AbstractDeviceParamModel::headerData ( |
986 |
switch (section) { |
int section, Qt::Orientation orientation, int role) const |
987 |
case 0: return tr("Parameter"); |
{ |
988 |
case 1: return tr("Value"); |
if (role != Qt::DisplayRole) |
989 |
case 2: return tr("Description"); |
return QVariant(); |
990 |
default: return QVariant(); |
|
991 |
} |
if (orientation == Qt::Horizontal) { |
992 |
} |
switch (section) { |
993 |
|
case 0: return tr("Parameter"); |
994 |
|
case 1: return tr("Value"); |
995 |
|
case 2: return tr("Description"); |
996 |
|
default: return QVariant(); |
997 |
|
} |
998 |
|
} |
999 |
|
|
1000 |
return QVariant(); |
return QVariant(); |
1001 |
} |
} |
1002 |
|
|
1003 |
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
|
1004 |
this->params = params; |
void AbstractDeviceParamModel::refresh ( |
1005 |
this->bEditable = bEditable; |
const DeviceParamMap* pParams, bool bEditable ) |
1006 |
// inform the outer world (QTableView) that our data changed |
{ |
1007 |
QAbstractTableModel::reset(); |
m_pParams = pParams; |
1008 |
|
m_bEditable = bEditable; |
1009 |
|
// inform the outer world (QTableView) that our data changed |
1010 |
|
QAbstractTableModel::reset(); |
1011 |
} |
} |
1012 |
|
|
1013 |
void AbstractDeviceParamModel::clear() { |
|
1014 |
params = NULL; |
void AbstractDeviceParamModel::clear (void) |
1015 |
// inform the outer world (QTableView) that our data changed |
{ |
1016 |
QAbstractTableModel::reset(); |
m_pParams = NULL; |
1017 |
|
// inform the outer world (QTableView) that our data changed |
1018 |
|
QAbstractTableModel::reset(); |
1019 |
} |
} |
1020 |
|
|
1021 |
|
|
1022 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1023 |
// DeviceParamModel - data model for device parameters (used for QTableView) |
// QSampler::DeviceParamModel - data model for device parameters |
1024 |
// |
// (used for QTableView) |
1025 |
|
|
1026 |
|
DeviceParamModel::DeviceParamModel ( QObject *pParent ) |
1027 |
|
: AbstractDeviceParamModel(pParent) |
1028 |
|
{ |
1029 |
|
m_pDevice = NULL; |
1030 |
|
} |
1031 |
|
|
1032 |
|
QVariant DeviceParamModel::data ( |
1033 |
|
const QModelIndex &index, int role) const |
1034 |
|
{ |
1035 |
|
if (!index.isValid()) |
1036 |
|
return QVariant(); |
1037 |
|
|
1038 |
|
if (role != Qt::DisplayRole) |
1039 |
|
return QVariant(); |
1040 |
|
|
1041 |
|
DeviceParameterRow item; |
1042 |
|
item.name = m_pParams->keys()[index.row()]; |
1043 |
|
item.param = (*m_pParams)[item.name]; |
1044 |
|
item.alive = (m_pDevice && m_pDevice->deviceID() >= 0); |
1045 |
|
|
1046 |
|
return QVariant::fromValue(item); |
1047 |
|
} |
1048 |
|
|
1049 |
|
|
1050 |
|
bool DeviceParamModel::setData ( |
1051 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1052 |
|
{ |
1053 |
|
if (!index.isValid()) |
1054 |
|
return false; |
1055 |
|
|
1056 |
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
QString key = m_pParams->keys()[index.row()]; |
1057 |
device = NULL; |
//m_pParams[key].value = value.toString(); |
1058 |
|
m_pDevice->setParam(key, value.toString()); |
1059 |
|
emit dataChanged(index, index); |
1060 |
|
return true; |
1061 |
} |
} |
1062 |
|
|
1063 |
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
|
1064 |
if (!index.isValid()) { |
void DeviceParamModel::refresh ( Device* pDevice, bool bEditable ) |
1065 |
//std::cout << "inavlid device model index\n" << std::flush; |
{ |
1066 |
return QVariant(); |
m_pDevice = pDevice; |
1067 |
} |
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
1068 |
if (role != Qt::DisplayRole) { |
} |
1069 |
//std::cout << "inavlid display role\n" << std::flush; |
|
1070 |
return QVariant(); |
|
1071 |
} |
void DeviceParamModel::clear (void) |
1072 |
|
{ |
1073 |
DeviceParameterRow item; |
AbstractDeviceParamModel::clear(); |
1074 |
item.name = params->keys()[index.row()]; |
m_pDevice = NULL; |
|
item.param = (*params)[item.name]; |
|
|
item.alive = device != NULL && device->deviceID() >= 0; |
|
|
|
|
|
return QVariant::fromValue(item); |
|
|
} |
|
|
|
|
|
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
|
|
if (!index.isValid()) { |
|
|
return false; |
|
|
} |
|
|
QString key = params->keys()[index.row()]; |
|
|
//params[key].value = value.toString(); |
|
|
device->setParam(key, value.toString()); |
|
|
emit dataChanged(index, index); |
|
|
return true; |
|
|
} |
|
|
|
|
|
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
|
|
device = pDevice; |
|
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
|
|
} |
|
|
|
|
|
void DeviceParamModel::clear() { |
|
|
AbstractDeviceParamModel::clear(); |
|
|
device = NULL; |
|
1075 |
} |
} |
1076 |
|
|
1077 |
|
|
1078 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1079 |
// PortParamModel - data model for port parameters (used for QTableView) |
// QSampler::PortParamModel - data model for port parameters |
1080 |
// |
// (used for QTableView) |
1081 |
|
|
1082 |
|
PortParamModel::PortParamModel ( QObject *pParent) |
1083 |
|
: AbstractDeviceParamModel(pParent) |
1084 |
|
{ |
1085 |
|
m_pPort = NULL; |
1086 |
|
} |
1087 |
|
|
1088 |
|
QVariant PortParamModel::data ( const QModelIndex &index, int role ) const |
1089 |
|
{ |
1090 |
|
if (!index.isValid()) |
1091 |
|
return QVariant(); |
1092 |
|
|
1093 |
|
if (role != Qt::DisplayRole) |
1094 |
|
return QVariant(); |
1095 |
|
|
1096 |
|
DeviceParameterRow item; |
1097 |
|
item.name = m_pParams->keys()[index.row()]; |
1098 |
|
item.param = (*m_pParams)[item.name]; |
1099 |
|
item.alive = (m_pPort && m_pPort->portID() >= 0); |
1100 |
|
|
1101 |
|
return QVariant::fromValue(item); |
1102 |
|
} |
1103 |
|
|
1104 |
|
|
1105 |
|
bool PortParamModel::setData ( |
1106 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1107 |
|
{ |
1108 |
|
if (!index.isValid()) |
1109 |
|
return false; |
1110 |
|
|
1111 |
|
QString key = m_pParams->keys()[index.row()]; |
1112 |
|
//params[key].value = value.toString(); |
1113 |
|
m_pPort->setParam(key, value.toString()); |
1114 |
|
emit dataChanged(index, index); |
1115 |
|
return true; |
1116 |
|
} |
1117 |
|
|
1118 |
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
|
1119 |
port = NULL; |
void PortParamModel::refresh ( DevicePort* pPort, bool bEditable ) |
1120 |
|
{ |
1121 |
|
m_pPort = pPort; |
1122 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1123 |
} |
} |
1124 |
|
|
1125 |
QVariant PortParamModel::data(const QModelIndex &index, int role) const { |
|
1126 |
if (!index.isValid()) { |
void PortParamModel::clear (void) |
1127 |
//std::cout << "inavlid device model index\n" << std::flush; |
{ |
1128 |
return QVariant(); |
AbstractDeviceParamModel::clear(); |
1129 |
} |
m_pPort = NULL; |
|
if (role != Qt::DisplayRole) { |
|
|
//std::cout << "inavlid display role\n" << std::flush; |
|
|
return QVariant(); |
|
|
} |
|
|
|
|
|
DeviceParameterRow item; |
|
|
item.name = params->keys()[index.row()]; |
|
|
item.param = (*params)[item.name]; |
|
|
item.alive = port != NULL && port->portID() >= 0; |
|
|
|
|
|
return QVariant::fromValue(item); |
|
|
} |
|
|
|
|
|
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
|
|
if (!index.isValid()) { |
|
|
return false; |
|
|
} |
|
|
QString key = params->keys()[index.row()]; |
|
|
//params[key].value = value.toString(); |
|
|
port->setParam(key, value.toString()); |
|
|
emit dataChanged(index, index); |
|
|
return true; |
|
|
} |
|
|
|
|
|
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
|
|
port = pPort; |
|
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
|
|
} |
|
|
|
|
|
void PortParamModel::clear() { |
|
|
AbstractDeviceParamModel::clear(); |
|
|
port = NULL; |
|
1130 |
} |
} |
1131 |
|
|
1132 |
|
|
1133 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1134 |
// DeviceParamDelegate - table cell renderer for device/port parameters |
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
1135 |
// |
// |
1136 |
|
|
1137 |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent) |
1138 |
|
: QItemDelegate(pParent) |
1139 |
|
{ |
1140 |
|
} |
1141 |
|
|
1142 |
|
|
1143 |
|
QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent, |
1144 |
|
const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const |
1145 |
|
{ |
1146 |
|
if (!index.isValid()) |
1147 |
|
return NULL; |
1148 |
|
|
1149 |
|
DeviceParameterRow r = index.model()->data(index, |
1150 |
|
Qt::DisplayRole).value<DeviceParameterRow>(); |
1151 |
|
|
1152 |
|
const bool bEnabled = (r.alive) ? !r.param.fix : true; |
1153 |
|
|
1154 |
|
QString val = (r.alive) ? r.param.value : r.param.defaultv; |
1155 |
|
|
1156 |
|
switch (index.column()) { |
1157 |
|
case 0: |
1158 |
|
return new QLabel(r.name, pParent); |
1159 |
|
case 1: { |
1160 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1161 |
|
QCheckBox *pCheckBox = new QCheckBox(pParent); |
1162 |
|
if (val != QString::null) |
1163 |
|
pCheckBox->setChecked(val.toLower() == "true"); |
1164 |
|
pCheckBox->setEnabled(bEnabled); |
1165 |
|
return pCheckBox; |
1166 |
|
} else if (r.param.possibilities.count() > 0) { |
1167 |
|
QStringList opts = r.param.possibilities; |
1168 |
|
if (r.param.multiplicity) |
1169 |
|
opts.prepend(tr("(none)")); |
1170 |
|
QComboBox *pComboBox = new QComboBox(pParent); |
1171 |
|
pComboBox->addItems(opts); |
1172 |
|
if (r.param.value.isEmpty()) |
1173 |
|
pComboBox->setCurrentIndex(0); |
1174 |
|
else |
1175 |
|
pComboBox->setCurrentIndex(pComboBox->findText(val)); |
1176 |
|
pComboBox->setEnabled(bEnabled); |
1177 |
|
return pComboBox; |
1178 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled) { |
1179 |
|
QSpinBox *pSpinBox = new QSpinBox(pParent); |
1180 |
|
pSpinBox->setMinimum( |
1181 |
|
(!r.param.range_min.isEmpty()) ? |
1182 |
|
r.param.range_min.toInt() : 0 // or better a negative default min value ? |
1183 |
|
); |
1184 |
|
pSpinBox->setMaximum( |
1185 |
|
(!r.param.range_max.isEmpty()) ? |
1186 |
|
r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ? |
1187 |
|
); |
1188 |
|
pSpinBox->setValue(val.toInt()); |
1189 |
|
return pSpinBox; |
1190 |
|
} else if (bEnabled) { |
1191 |
|
QLineEdit *pLineEdit = new QLineEdit(val, pParent); |
1192 |
|
return pLineEdit; |
1193 |
|
} else { |
1194 |
|
QLabel *pLabel = new QLabel(val, pParent); |
1195 |
|
return pLabel; |
1196 |
|
} |
1197 |
|
} |
1198 |
|
case 2: |
1199 |
|
return new QLabel(r.param.description, pParent); |
1200 |
|
default: |
1201 |
|
return NULL; |
1202 |
|
} |
1203 |
|
} |
1204 |
|
|
1205 |
|
|
1206 |
|
void DeviceParamDelegate::setEditorData ( |
1207 |
|
QWidget* /*pEditor*/, const QModelIndex& /*index*/) const |
1208 |
|
{ |
1209 |
|
// Unused, since we set the editor data already in createEditor() |
1210 |
} |
} |
1211 |
|
|
1212 |
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
|
1213 |
const QStyleOptionViewItem &/* option */, |
void DeviceParamDelegate::setModelData ( QWidget *pEditor, |
1214 |
const QModelIndex& index) const |
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1215 |
{ |
{ |
1216 |
if (!index.isValid()) { |
if (index.column() == 1) { |
1217 |
return NULL; |
DeviceParameterRow r = index.model()->data(index, |
1218 |
} |
Qt::DisplayRole).value<DeviceParameterRow> (); |
1219 |
|
if (pEditor->metaObject()->className() == QString("QCheckBox")) { |
1220 |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
QCheckBox *pCheckBox = static_cast<QCheckBox *> (pEditor); |
1221 |
|
pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1222 |
const bool bEnabled = (r.alive) ? !r.param.fix : true; |
} else if (pEditor->metaObject()->className() == QString("QComboBox")) { |
1223 |
|
QComboBox *pComboBox = static_cast<QComboBox *> (pEditor); |
1224 |
QString val = (r.alive) ? r.param.value : r.param.defaultv; |
pModel->setData(index, pComboBox->currentText()); |
1225 |
|
} else if (pEditor->metaObject()->className() == QString("QSpinBox")) { |
1226 |
switch (index.column()) { |
QSpinBox *pSpinBox = static_cast<QSpinBox *> (pEditor); |
1227 |
case 0: |
pModel->setData(index, pSpinBox->value()); |
1228 |
return new QLabel(r.name, parent); |
} else if (pEditor->metaObject()->className() == QString("QLineEdit")) { |
1229 |
case 1: { |
QLineEdit *pLineEdit = static_cast<QLineEdit *> (pEditor); |
1230 |
if (r.param.type == LSCP_TYPE_BOOL) { |
pModel->setData(index, pLineEdit->text()); |
1231 |
QCheckBox* pCheckBox = new QCheckBox(parent); |
} else if (pEditor->metaObject()->className() == QString("QLabel")) { |
1232 |
if (val != QString::null) |
QLabel *pLabel = static_cast<QLabel *> (pEditor); |
1233 |
pCheckBox->setChecked(val.toLower() == "true"); |
pModel->setData(index, pLabel->text()); |
1234 |
pCheckBox->setEnabled(bEnabled); |
} |
1235 |
return pCheckBox; |
} |
|
} else if (r.param.possibilities.count() > 0) { |
|
|
QStringList opts = r.param.possibilities; |
|
|
if (r.param.multiplicity) |
|
|
opts.prepend(tr("(none)")); |
|
|
QComboBox* pComboBox = new QComboBox(parent); |
|
|
pComboBox->addItems(opts); |
|
|
if (r.param.value.isEmpty()) |
|
|
pComboBox->setCurrentIndex(0); |
|
|
else |
|
|
pComboBox->setCurrentIndex(pComboBox->findText(val)); |
|
|
pComboBox->setEnabled(bEnabled); |
|
|
return pComboBox; |
|
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled) { |
|
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
|
|
pSpinBox->setMinimum( |
|
|
(!r.param.range_min.isEmpty()) ? |
|
|
r.param.range_min.toInt() : 0 // or better a negative default min value ? |
|
|
); |
|
|
pSpinBox->setMaximum( |
|
|
(!r.param.range_max.isEmpty()) ? |
|
|
r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ? |
|
|
); |
|
|
pSpinBox->setValue(val.toInt()); |
|
|
return pSpinBox; |
|
|
} else if (bEnabled) { |
|
|
QLineEdit* pLineEdit = new QLineEdit(val, parent); |
|
|
return pLineEdit; |
|
|
} else { |
|
|
QLabel* pLabel = new QLabel(val, parent); |
|
|
return pLabel; |
|
|
} |
|
|
} |
|
|
case 2: |
|
|
return new QLabel(r.param.description, parent); |
|
|
default: |
|
|
return NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
|
|
// unused, since we set the editor data already in createEditor() |
|
|
} |
|
|
|
|
|
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
|
|
if (index.column() == 1) { |
|
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
|
|
if (editor->metaObject()->className() == "QCheckBox") { |
|
|
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
|
|
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
|
|
} else if (editor->metaObject()->className() == "QComboBox") { |
|
|
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
|
|
model->setData(index, pComboBox->currentText()); |
|
|
} else if (editor->metaObject()->className() == "QSpinBox") { |
|
|
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
|
|
model->setData(index, pSpinBox->value()); |
|
|
} else if (editor->metaObject()->className() == "QLineEdit") { |
|
|
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
|
|
model->setData(index, pLineEdit->text()); |
|
|
} else if (editor->metaObject()->className() == "QLabel") { |
|
|
QLabel* pLabel = static_cast<QLabel*>(editor); |
|
|
model->setData(index, pLabel->text()); |
|
|
} |
|
|
} |
|
1236 |
} |
} |
1237 |
|
|
1238 |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor, |
1239 |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1240 |
{ |
{ |
1241 |
if (editor) editor->setGeometry(option.rect); |
if (pEditor) |
1242 |
|
pEditor->setGeometry(option.rect); |
1243 |
} |
} |
1244 |
|
|
1245 |
|
} // namespace QSampler |
1246 |
|
|
1247 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |