21 |
|
|
22 |
#include "qsamplerDevice.h" |
#include "qsamplerDevice.h" |
23 |
|
|
24 |
|
#include <qspinbox.h> |
25 |
|
#include <qlineedit.h> |
26 |
|
|
27 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
28 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
29 |
|
|
121 |
qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDeviceType deviceType, int iDeviceID ) |
122 |
{ |
{ |
123 |
// Device id and type should be always set. |
// Device id and type should be always set. |
124 |
m_iDeviceID = iDeviceID; |
m_iDeviceID = iDeviceID; |
125 |
m_deviceType = deviceType; |
m_deviceType = deviceType; |
126 |
|
|
127 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
128 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
143 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
144 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
145 |
m_sDriverName = QString::null; |
m_sDriverName = QString::null; |
146 |
m_sDeviceName = QObject::tr("New device"); |
m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType); |
147 |
return; |
return; |
148 |
} |
} |
149 |
|
|
177 |
} |
} |
178 |
|
|
179 |
|
|
180 |
// Driver name initializer. |
// Driver name initializer/settler. |
181 |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
182 |
const QString& sDriverName ) |
const QString& sDriverName ) |
183 |
{ |
{ |
257 |
} |
} |
258 |
|
|
259 |
// Device parameter accessor. |
// Device parameter accessor. |
260 |
qsamplerDeviceParamMap& qsamplerDevice::params (void) |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
261 |
{ |
{ |
262 |
return m_params; |
return m_params; |
263 |
} |
} |
264 |
|
|
265 |
|
|
266 |
// Update/refresh device/driver data. |
// Set the proper device parameter value. |
267 |
void qsamplerDevice::refresh (void) |
void qsamplerDevice::setParam ( const QString& sParam, |
268 |
|
const QString& sValue ) |
269 |
{ |
{ |
270 |
|
m_params[sParam].value = sValue; |
271 |
} |
} |
272 |
|
|
273 |
|
|
274 |
// Device ids enumerator. |
// Device ids enumerator. |
275 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
276 |
qsamplerDeviceType deviceType ) |
qsamplerDeviceType deviceType ) |
316 |
|
|
317 |
|
|
318 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
319 |
|
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
320 |
|
// |
321 |
|
|
322 |
|
// Constructor. |
323 |
|
qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient, |
324 |
|
const qsamplerDevice& device, int iPortID ) |
325 |
|
{ |
326 |
|
setDevicePort(pClient, device, iPortID); |
327 |
|
} |
328 |
|
|
329 |
|
// Default destructor. |
330 |
|
qsamplerDevicePort::~qsamplerDevicePort (void) |
331 |
|
{ |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
// Initializer. |
336 |
|
void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient, |
337 |
|
const qsamplerDevice& device, int iPortID ) |
338 |
|
{ |
339 |
|
// Device port id should be always set. |
340 |
|
m_iPortID = iPortID; |
341 |
|
|
342 |
|
// Retrieve device port/channel info, if any. |
343 |
|
lscp_device_port_info_t *pPortInfo = NULL; |
344 |
|
switch (device.deviceType()) { |
345 |
|
case qsamplerDevice::Audio: |
346 |
|
pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID); |
347 |
|
break; |
348 |
|
case qsamplerDevice::Midi: |
349 |
|
pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID); |
350 |
|
break; |
351 |
|
case qsamplerDevice::None: |
352 |
|
break; |
353 |
|
} |
354 |
|
|
355 |
|
// If we're bogus, bail out... |
356 |
|
if (pPortInfo == NULL) { |
357 |
|
m_sPortName = QString::null; |
358 |
|
return; |
359 |
|
} |
360 |
|
|
361 |
|
// Set device port/channel properties... |
362 |
|
m_sPortName = pPortInfo->name; |
363 |
|
|
364 |
|
// Grab device port/channel parameters... |
365 |
|
m_params.clear(); |
366 |
|
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
367 |
|
const char *pszParam = pPortInfo->params[i].key; |
368 |
|
lscp_param_info_t *pParamInfo = NULL; |
369 |
|
switch (device.deviceType()) { |
370 |
|
case qsamplerDevice::Audio: |
371 |
|
pParamInfo = ::lscp_get_audio_channel_param_info(pClient, |
372 |
|
device.deviceID(), iPortID, pszParam); |
373 |
|
break; |
374 |
|
case qsamplerDevice::Midi: |
375 |
|
pParamInfo = ::lscp_get_midi_port_param_info(pClient, |
376 |
|
device.deviceID(), iPortID, pszParam); |
377 |
|
break; |
378 |
|
case qsamplerDevice::None: |
379 |
|
break; |
380 |
|
} |
381 |
|
if (pParamInfo) { |
382 |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, |
383 |
|
pPortInfo->params[i].value); |
384 |
|
} |
385 |
|
} |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
|
// Device port/channel property accessors. |
390 |
|
int qsamplerDevicePort::portID (void) const |
391 |
|
{ |
392 |
|
return m_iPortID; |
393 |
|
} |
394 |
|
|
395 |
|
const QString& qsamplerDevicePort::portName (void) const |
396 |
|
{ |
397 |
|
return m_sPortName; |
398 |
|
} |
399 |
|
|
400 |
|
// Device port/channel parameter accessor. |
401 |
|
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
402 |
|
{ |
403 |
|
return m_params; |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
|
// Set the proper device port/channel parameter value. |
408 |
|
void qsamplerDevicePort::setParam ( const QString& sParam, |
409 |
|
const QString& sValue ) |
410 |
|
{ |
411 |
|
m_params[sParam].value = sValue; |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
//------------------------------------------------------------------------- |
416 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QListView device item. |
417 |
// |
// |
418 |
|
|
509 |
} |
} |
510 |
|
|
511 |
|
|
512 |
// The main table refresher. |
// Common parameter table renderer. |
513 |
void qsamplerDeviceParamTable::refresh ( qsamplerDevice& device ) |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
514 |
|
bool bEditable ) |
515 |
{ |
{ |
516 |
// Always (re)start it empty. |
// Always (re)start it empty. |
517 |
QTable::setUpdatesEnabled(false); |
QTable::setUpdatesEnabled(false); |
518 |
QTable::setNumRows(0); |
QTable::setNumRows(0); |
519 |
|
|
520 |
// Now fill the parameter table... |
// Fill the parameter table... |
|
qsamplerDeviceParamMap& params = device.params(); |
|
521 |
QTable::insertRows(0, params.count()); |
QTable::insertRows(0, params.count()); |
522 |
int iRow = 0; |
int iRow = 0; |
523 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
524 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
for (iter = params.begin(); iter != params.end(); ++iter) { |
525 |
const qsamplerDeviceParam& param = iter.data(); |
const qsamplerDeviceParam& param = iter.data(); |
526 |
bool fEnabled = (device.deviceID() < 0 || !param.fix); |
bool bEnabled = (bEditable || !param.fix); |
527 |
QTable::setText(iRow, 0, iter.key()); |
QTable::setText(iRow, 0, iter.key()); |
528 |
QTable::setText(iRow, 1, param.description); |
QTable::setText(iRow, 1, param.description); |
529 |
if (param.type == LSCP_TYPE_BOOL) { |
if (param.type == LSCP_TYPE_BOOL) { |
530 |
QStringList opts; |
QStringList opts; |
531 |
opts.append(tr("false")); |
opts.append(tr("False")); |
532 |
opts.append(tr("true")); |
opts.append(tr("True")); |
533 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
534 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
535 |
pComboItem->setEnabled(fEnabled); |
pComboItem->setEnabled(bEnabled); |
536 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
537 |
} else if (param.possibilities.count() > 0 && !param.multiplicity) { |
} else if (param.possibilities.count() > 0 && bEnabled) { |
538 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
QComboTableItem *pComboItem = new QComboTableItem(this, |
539 |
param.possibilities); |
param.possibilities); |
540 |
pComboItem->setCurrentItem(param.value); |
pComboItem->setCurrentItem(param.value); |
541 |
pComboItem->setEnabled(fEnabled); |
pComboItem->setEnabled(bEnabled); |
542 |
|
pComboItem->setEditable(bEnabled && param.multiplicity); |
543 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
544 |
|
} else if (param.type == LSCP_TYPE_INT && bEnabled |
545 |
|
&& !param.range_min.isEmpty() |
546 |
|
&& !param.range_max.isEmpty()) { |
547 |
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
548 |
|
new qsamplerDeviceParamTableSpinBox(this, |
549 |
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
550 |
|
param.value); |
551 |
|
pSpinItem->setMinValue(param.range_min.toInt()); |
552 |
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
553 |
|
QTable::setItem(iRow, 2, pSpinItem); |
554 |
} else { |
} else { |
555 |
QTableItem* pTableItem = new QTableItem(this, |
qsamplerDeviceParamTableEditBox *pEditItem = |
556 |
fEnabled ? QTableItem::OnTyping : QTableItem::Never, |
new qsamplerDeviceParamTableEditBox(this, |
557 |
param.value); |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
558 |
QTable::setItem(iRow, 2, pTableItem); |
param.value); |
559 |
|
QTable::setItem(iRow, 2, pEditItem); |
560 |
} |
} |
561 |
++iRow; |
++iRow; |
562 |
} |
} |
570 |
} |
} |
571 |
|
|
572 |
|
|
573 |
|
//------------------------------------------------------------------------- |
574 |
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
575 |
|
// |
576 |
|
|
577 |
|
// Constructor. |
578 |
|
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
579 |
|
QTable *pTable, EditType editType, const QString& sText ) |
580 |
|
: QTableItem(pTable, editType, sText) |
581 |
|
{ |
582 |
|
m_iValue = sText.toInt(); |
583 |
|
m_iMinValue = m_iMaxValue = 0; |
584 |
|
} |
585 |
|
|
586 |
|
// Public accessors. |
587 |
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
588 |
|
{ |
589 |
|
m_iValue = iValue; |
590 |
|
QTableItem::setText(QString::number(m_iValue)); |
591 |
|
} |
592 |
|
|
593 |
|
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
594 |
|
{ |
595 |
|
m_iMinValue = iMinValue; |
596 |
|
} |
597 |
|
|
598 |
|
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
599 |
|
{ |
600 |
|
m_iMaxValue = iMaxValue; |
601 |
|
} |
602 |
|
|
603 |
|
// Virtual implemetations. |
604 |
|
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
605 |
|
{ |
606 |
|
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
607 |
|
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
608 |
|
QTableItem::table(), SLOT(doValueChanged())); |
609 |
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
610 |
|
pSpinBox->setMinValue(m_iMinValue); |
611 |
|
pSpinBox->setMaxValue(m_iMaxValue); |
612 |
|
} |
613 |
|
pSpinBox->setValue(m_iValue); |
614 |
|
return pSpinBox; |
615 |
|
} |
616 |
|
|
617 |
|
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
618 |
|
{ |
619 |
|
if (pWidget->inherits("QSpinBox")) |
620 |
|
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
621 |
|
else |
622 |
|
QTableItem::setContentFromEditor(pWidget); |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
|
//------------------------------------------------------------------------- |
627 |
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
628 |
|
// |
629 |
|
|
630 |
|
// Constructor. |
631 |
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
632 |
|
QTable *pTable, EditType editType, const QString& sText ) |
633 |
|
: QTableItem(pTable, editType, sText) |
634 |
|
{ |
635 |
|
} |
636 |
|
|
637 |
|
// Virtual implemetations. |
638 |
|
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
639 |
|
{ |
640 |
|
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
641 |
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
642 |
|
QTableItem::table(), SLOT(doValueChanged())); |
643 |
|
pEditBox->setText(QTableItem::text()); |
644 |
|
return pEditBox; |
645 |
|
} |
646 |
|
|
647 |
|
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
648 |
|
{ |
649 |
|
if (pWidget->inherits("QLineEdit")) |
650 |
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
651 |
|
else |
652 |
|
QTableItem::setContentFromEditor(pWidget); |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |