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 |
|
|
125 |
m_deviceType = deviceType; |
m_deviceType = deviceType; |
126 |
|
|
127 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
|
QString sDeviceType; |
|
128 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
129 |
switch (deviceType) { |
switch (deviceType) { |
130 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
131 |
sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
132 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
133 |
break; |
break; |
134 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
135 |
sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
136 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
137 |
break; |
break; |
138 |
|
case qsamplerDevice::None: |
139 |
|
m_sDeviceType = QString::null; |
140 |
|
break; |
141 |
} |
} |
142 |
|
|
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 %1 device").arg(sDeviceType); |
m_sDeviceName = QObject::tr("New device"); |
147 |
return; |
return; |
148 |
} |
} |
149 |
|
|
166 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
167 |
m_sDriverName.latin1(), pszParam, NULL); |
m_sDriverName.latin1(), pszParam, NULL); |
168 |
break; |
break; |
169 |
|
case qsamplerDevice::None: |
170 |
|
break; |
171 |
|
} |
172 |
|
if (pParamInfo) { |
173 |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, |
174 |
|
pDeviceInfo->params[i].value); |
175 |
} |
} |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pDeviceInfo->params[i].value); |
|
176 |
} |
} |
177 |
} |
} |
178 |
|
|
196 |
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
197 |
sDriverName.latin1()); |
sDriverName.latin1()); |
198 |
break; |
break; |
199 |
|
case qsamplerDevice::None: |
200 |
|
break; |
201 |
} |
} |
202 |
|
|
203 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
221 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
222 |
sDriverName.latin1(), pszParam, NULL); |
sDriverName.latin1(), pszParam, NULL); |
223 |
break; |
break; |
224 |
|
case qsamplerDevice::None: |
225 |
|
break; |
226 |
} |
} |
227 |
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pParamInfo->defaultv); |
if (pParamInfo) |
228 |
|
m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pParamInfo->defaultv); |
229 |
} |
} |
230 |
} |
} |
231 |
|
|
241 |
return m_deviceType; |
return m_deviceType; |
242 |
} |
} |
243 |
|
|
244 |
|
const QString& qsamplerDevice::deviceTypeName (void) const |
245 |
|
{ |
246 |
|
return m_sDeviceType; |
247 |
|
} |
248 |
|
|
249 |
const QString& qsamplerDevice::driverName (void) const |
const QString& qsamplerDevice::driverName (void) const |
250 |
{ |
{ |
251 |
return m_sDriverName; |
return m_sDriverName; |
280 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
281 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
282 |
break; |
break; |
283 |
|
case qsamplerDevice::None: |
284 |
|
break; |
285 |
} |
} |
286 |
return piDeviceIDs; |
return piDeviceIDs; |
287 |
} |
} |
301 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
302 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
303 |
break; |
break; |
304 |
|
case qsamplerDevice::None: |
305 |
|
break; |
306 |
} |
} |
307 |
|
|
308 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
317 |
// |
// |
318 |
|
|
319 |
// Constructors. |
// Constructors. |
320 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
321 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
322 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
: QListViewItem(pListView), m_device(pClient, deviceType) |
323 |
{ |
{ |
324 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
330 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
331 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
332 |
break; |
break; |
333 |
|
case qsamplerDevice::None: |
334 |
|
break; |
335 |
} |
} |
336 |
} |
} |
337 |
|
|
338 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, lscp_client_t *pClient, |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
339 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID ) |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
340 |
|
int iDeviceID ) |
341 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
342 |
{ |
{ |
343 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
347 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
348 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
349 |
break; |
break; |
350 |
|
case qsamplerDevice::None: |
351 |
|
break; |
352 |
} |
} |
353 |
|
|
354 |
QListViewItem::setText(0, m_device.deviceName()); |
QListViewItem::setText(0, m_device.deviceName()); |
378 |
// |
// |
379 |
|
|
380 |
// Constructor. |
// Constructor. |
381 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, const char *pszName ) |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
382 |
|
const char *pszName ) |
383 |
: QTable(pParent, pszName) |
: QTable(pParent, pszName) |
384 |
{ |
{ |
385 |
// Set fixed number of columns. |
// Set fixed number of columns. |
393 |
QTable::setLeftMargin(0); |
QTable::setLeftMargin(0); |
394 |
// Initialize the fixed table column headings. |
// Initialize the fixed table column headings. |
395 |
QHeader *pHeader = QTable::horizontalHeader(); |
QHeader *pHeader = QTable::horizontalHeader(); |
396 |
pHeader->setLabel(0, tr("Description")); |
pHeader->setLabel(0, tr("Parameter")); |
397 |
pHeader->setLabel(1, tr("Value")); |
pHeader->setLabel(1, tr("Description")); |
398 |
pHeader->setLabel(2, tr("Parameter")); |
pHeader->setLabel(2, tr("Value")); |
399 |
// Set read-onlyness of each column |
// Set read-onlyness of each column |
400 |
QTable::setColumnReadOnly(0, true); |
QTable::setColumnReadOnly(0, true); |
401 |
// QTable::setColumnReadOnly(1, true); -- of course not. |
QTable::setColumnReadOnly(1, true); |
402 |
QTable::setColumnReadOnly(2, true); |
// QTable::setColumnReadOnly(2, true); -- of course not. |
403 |
QTable::setColumnStretchable(0, true); |
QTable::setColumnStretchable(1, true); |
404 |
} |
} |
405 |
|
|
406 |
// Default destructor. |
// Default destructor. |
413 |
void qsamplerDeviceParamTable::refresh ( qsamplerDevice& device ) |
void qsamplerDeviceParamTable::refresh ( qsamplerDevice& device ) |
414 |
{ |
{ |
415 |
// Always (re)start it empty. |
// Always (re)start it empty. |
416 |
|
QTable::setUpdatesEnabled(false); |
417 |
QTable::setNumRows(0); |
QTable::setNumRows(0); |
418 |
|
|
419 |
// Now fill the parameter table... |
// Now fill the parameter table... |
423 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
424 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
for (iter = params.begin(); iter != params.end(); ++iter) { |
425 |
const qsamplerDeviceParam& param = iter.data(); |
const qsamplerDeviceParam& param = iter.data(); |
426 |
QTable::setText(iRow, 0, param.description); |
bool bEnabled = (device.deviceID() < 0 || !param.fix); |
427 |
|
QTable::setText(iRow, 0, iter.key()); |
428 |
|
QTable::setText(iRow, 1, param.description); |
429 |
if (param.type == LSCP_TYPE_BOOL) { |
if (param.type == LSCP_TYPE_BOOL) { |
430 |
QStringList opts; |
QStringList opts; |
431 |
opts.append(tr("false")); |
opts.append(tr("false")); |
432 |
opts.append(tr("true")); |
opts.append(tr("true")); |
433 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
434 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
435 |
pComboItem->setEnabled(param.fix); |
pComboItem->setEnabled(bEnabled); |
436 |
QTable::setItem(iRow, 1, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
437 |
} else if (param.possibilities.count() > 0) { |
} else if (param.possibilities.count() > 0) { |
438 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
QComboTableItem *pComboItem = new QComboTableItem(this, |
439 |
param.possibilities); |
param.possibilities); |
440 |
pComboItem->setCurrentItem(param.value); |
pComboItem->setCurrentItem(param.value); |
441 |
pComboItem->setEnabled(param.fix); |
pComboItem->setEnabled(bEnabled); |
442 |
QTable::setItem(iRow, 1, pComboItem); |
pComboItem->setEditable(bEnabled && param.multiplicity); |
443 |
|
QTable::setItem(iRow, 2, pComboItem); |
444 |
|
} else if (param.type == LSCP_TYPE_INT |
445 |
|
&& !param.range_min.isEmpty() |
446 |
|
&& !param.range_max.isEmpty()) { |
447 |
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
448 |
|
new qsamplerDeviceParamTableSpinBox(this, |
449 |
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
450 |
|
param.value); |
451 |
|
pSpinItem->setMinValue(param.range_min.toInt()); |
452 |
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
453 |
|
QTable::setItem(iRow, 2, pSpinItem); |
454 |
} else { |
} else { |
455 |
QTableItem* pTableItem = new QTableItem(this, |
qsamplerDeviceParamTableEditBox *pEditItem = |
456 |
param.fix ? QTableItem::Never : QTableItem::OnTyping, |
new qsamplerDeviceParamTableEditBox(this, |
457 |
param.value); |
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
458 |
QTable::setItem(iRow, 1, pTableItem); |
param.value); |
459 |
|
QTable::setItem(iRow, 2, pEditItem); |
460 |
} |
} |
|
QTable::setText(iRow, 2, iter.key()); |
|
461 |
++iRow; |
++iRow; |
462 |
} |
} |
463 |
|
|
464 |
// Adjust optimal column width. |
// Adjust optimal column widths. |
465 |
for (int iCol = 0; iCol < QTable::numCols(); iCol++) |
QTable::adjustColumn(0); |
466 |
QTable::adjustColumn(iCol); |
QTable::adjustColumn(2); |
467 |
|
|
468 |
|
QTable::setUpdatesEnabled(true); |
469 |
|
QTable::updateContents(); |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
//------------------------------------------------------------------------- |
474 |
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
475 |
|
// |
476 |
|
|
477 |
|
// Constructor. |
478 |
|
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
479 |
|
QTable *pTable, EditType editType, const QString& sText ) |
480 |
|
: QTableItem(pTable, editType, sText) |
481 |
|
{ |
482 |
|
m_iValue = sText.toInt(); |
483 |
|
m_iMinValue = m_iMaxValue = 0; |
484 |
|
} |
485 |
|
|
486 |
|
// Public accessors. |
487 |
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
488 |
|
{ |
489 |
|
m_iValue = iValue; |
490 |
|
QTableItem::setText(QString::number(m_iValue)); |
491 |
|
} |
492 |
|
|
493 |
|
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
494 |
|
{ |
495 |
|
m_iMinValue = iMinValue; |
496 |
|
} |
497 |
|
|
498 |
|
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
499 |
|
{ |
500 |
|
m_iMaxValue = iMaxValue; |
501 |
|
} |
502 |
|
|
503 |
|
// Virtual implemetations. |
504 |
|
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
505 |
|
{ |
506 |
|
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
507 |
|
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
508 |
|
QTableItem::table(), SLOT(doValueChanged())); |
509 |
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
510 |
|
pSpinBox->setMinValue(m_iMinValue); |
511 |
|
pSpinBox->setMaxValue(m_iMaxValue); |
512 |
|
} |
513 |
|
pSpinBox->setValue(m_iValue); |
514 |
|
return pSpinBox; |
515 |
|
} |
516 |
|
|
517 |
|
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
518 |
|
{ |
519 |
|
if (pWidget->inherits("QSpinBox")) |
520 |
|
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
521 |
|
else |
522 |
|
QTableItem::setContentFromEditor(pWidget); |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
//------------------------------------------------------------------------- |
527 |
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
528 |
|
// |
529 |
|
|
530 |
|
// Constructor. |
531 |
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
532 |
|
QTable *pTable, EditType editType, const QString& sText ) |
533 |
|
: QTableItem(pTable, editType, sText) |
534 |
|
{ |
535 |
|
} |
536 |
|
|
537 |
|
// Virtual implemetations. |
538 |
|
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
539 |
|
{ |
540 |
|
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
541 |
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
542 |
|
QTableItem::table(), SLOT(doValueChanged())); |
543 |
|
pEditBox->setText(QTableItem::text()); |
544 |
|
return pEditBox; |
545 |
|
} |
546 |
|
|
547 |
|
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
548 |
|
{ |
549 |
|
if (pWidget->inherits("QLineEdit")) |
550 |
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
551 |
|
else |
552 |
|
QTableItem::setContentFromEditor(pWidget); |
553 |
} |
} |
554 |
|
|
555 |
|
|