2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
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 |
|
|
34 |
using namespace QSampler; |
using namespace QSampler; |
35 |
|
|
109 |
// Constructor. |
// Constructor. |
110 |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
111 |
{ |
{ |
112 |
m_ports.setAutoDelete(true); |
// m_ports.setAutoDelete(true); |
113 |
|
|
114 |
setDevice(deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
115 |
} |
} |
117 |
// Default destructor. |
// Default destructor. |
118 |
qsamplerDevice::~qsamplerDevice (void) |
qsamplerDevice::~qsamplerDevice (void) |
119 |
{ |
{ |
120 |
|
qDeleteAll(m_ports); |
121 |
|
m_ports.clear(); |
122 |
} |
} |
123 |
|
|
124 |
// Copy constructor. |
// Copy constructor. |
125 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
126 |
: m_params(device.m_params), m_ports(m_ports) |
: m_params(device.m_params), m_ports(device.m_ports) |
127 |
{ |
{ |
128 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
129 |
m_deviceType = device.m_deviceType; |
m_deviceType = device.m_deviceType; |
148 |
|
|
149 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
150 |
m_params.clear(); |
m_params.clear(); |
151 |
|
qDeleteAll(m_ports); |
152 |
m_ports.clear(); |
m_ports.clear(); |
153 |
|
|
154 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
188 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
189 |
switch (deviceType) { |
switch (deviceType) { |
190 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
191 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_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_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
195 |
break; |
break; |
196 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
197 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
198 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
199 |
|
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 qsamplerDevice::None: |
203 |
break; |
break; |
204 |
} |
} |
205 |
if (pParamInfo) { |
if (pParamInfo) { |
206 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
207 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
208 |
} |
} |
209 |
} |
} |
230 |
|
|
231 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
232 |
m_params.clear(); |
m_params.clear(); |
233 |
|
qDeleteAll(m_ports); |
234 |
m_ports.clear(); |
m_ports.clear(); |
235 |
|
|
236 |
// Retrieve driver info, if any. |
// Retrieve driver info, if any. |
238 |
switch (m_deviceType) { |
switch (m_deviceType) { |
239 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
240 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
241 |
sDriverName.latin1())) == 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 qsamplerDevice::Midi: |
245 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
246 |
sDriverName.latin1())) == 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 qsamplerDevice::None: |
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 qsamplerDevice::Audio: |
266 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_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_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
270 |
break; |
break; |
271 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
272 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
273 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
274 |
|
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 qsamplerDevice::None: |
278 |
break; |
break; |
279 |
} |
} |
280 |
if (pParamInfo) { |
if (pParamInfo) { |
281 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
282 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
283 |
} |
} |
284 |
} |
} |
332 |
return false; |
return false; |
333 |
|
|
334 |
// Set proper device parameter. |
// Set proper device parameter. |
335 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
336 |
|
|
337 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
338 |
int iRefresh = 0; |
int iRefresh = 0; |
339 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
340 |
// Prepare parameter struct. |
// Prepare parameter struct. |
341 |
lscp_param_t param; |
lscp_param_t param; |
342 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) sParam.toUtf8().constData(); |
343 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) sValue.toUtf8().constData(); |
344 |
// Now it depends on the device type... |
// Now it depends on the device type... |
345 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
346 |
switch (m_deviceType) { |
switch (m_deviceType) { |
406 |
int iParam = 0; |
int iParam = 0; |
407 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
408 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
409 |
pParams[iParam].key = (char *) iter.key().latin1(); |
if (iter.value().value == QString::null) continue; |
410 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
pParams[iParam].key = (char *) iter.key().toUtf8().constData(); |
411 |
|
pParams[iParam].value = (char *) iter.value().value.toUtf8().constData(); |
412 |
++iParam; |
++iParam; |
413 |
} |
} |
414 |
// Null terminated. |
// Null terminated. |
419 |
switch (m_deviceType) { |
switch (m_deviceType) { |
420 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
421 |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
422 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
423 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
424 |
break; |
break; |
425 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
426 |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
427 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
428 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
429 |
break; |
break; |
430 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
522 |
break; |
break; |
523 |
} |
} |
524 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
525 |
|
qDeleteAll(m_ports); |
526 |
m_ports.clear(); |
m_ports.clear(); |
527 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
528 |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
541 |
int iDepends = 0; |
int iDepends = 0; |
542 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
543 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
544 |
const QStringList& depends = iter.data().depends; |
const QStringList& depends = iter.value().depends; |
545 |
if (depends.find(sParam) != depends.end()) |
if (depends.indexOf(sParam) >= 0) |
546 |
iDepends += refreshParam(iter.key()); |
iDepends += refreshParam(iter.key()); |
547 |
} |
} |
548 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
560 |
return 0; |
return 0; |
561 |
|
|
562 |
// Check if we have dependencies... |
// Check if we have dependencies... |
563 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.toUpper()]; |
564 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
565 |
return 0; |
return 0; |
566 |
|
|
572 |
QStringList::ConstIterator iter; |
QStringList::ConstIterator iter; |
573 |
for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) { |
for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) { |
574 |
const QString& sDepend = *iter; |
const QString& sDepend = *iter; |
575 |
pDepends[iDepend].key = (char *) sDepend.latin1(); |
pDepends[iDepend].key = (char *) sDepend.toUtf8().constData(); |
576 |
pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1(); |
pDepends[iDepend].value = (char *) m_params[sDepend.toUpper()].value |
577 |
|
.toUtf8().constData(); |
578 |
++iDepend; |
++iDepend; |
579 |
} |
} |
580 |
// Null terminated. |
// Null terminated. |
590 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
591 |
switch (m_deviceType) { |
switch (m_deviceType) { |
592 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
593 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
594 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
595 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
596 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
597 |
break; |
break; |
598 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
599 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
600 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
601 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
602 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
603 |
break; |
break; |
604 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
605 |
break; |
break; |
606 |
} |
} |
607 |
if (pParamInfo) { |
if (pParamInfo) { |
608 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
param = qsamplerDeviceParam(pParamInfo, |
609 |
|
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
610 |
iRefresh++; |
iRefresh++; |
611 |
} |
} |
612 |
|
|
767 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
768 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
769 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
770 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
771 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
772 |
break; |
break; |
773 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
774 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
775 |
pMainForm->client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
776 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
777 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
778 |
break; |
break; |
779 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
780 |
break; |
break; |
781 |
} |
} |
782 |
if (pParamInfo) { |
if (pParamInfo) { |
783 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
784 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
785 |
} |
} |
786 |
} |
} |
816 |
return false; |
return false; |
817 |
|
|
818 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
819 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
820 |
|
|
821 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
822 |
int iRefresh = 0; |
int iRefresh = 0; |
823 |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
824 |
// Prepare parameter struct. |
// Prepare parameter struct. |
825 |
lscp_param_t param; |
lscp_param_t param; |
826 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) sParam.toUtf8().constData(); |
827 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) sValue.toUtf8().constData(); |
828 |
// Now it depends on the device type... |
// Now it depends on the device type... |
829 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
830 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
870 |
{ |
{ |
871 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
872 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
873 |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
874 |
setText(1, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
875 |
break; |
break; |
876 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
877 |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
878 |
setText(1, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
879 |
break; |
break; |
880 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
881 |
break; |
break; |
890 |
{ |
{ |
891 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
892 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
893 |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
894 |
break; |
break; |
895 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
896 |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
897 |
break; |
break; |
898 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
899 |
break; |
break; |
900 |
} |
} |
901 |
|
|
902 |
setText(1, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
903 |
} |
} |
904 |
|
|
905 |
// Default destructor. |
// Default destructor. |
906 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
qsamplerDeviceItem::~qsamplerDeviceItem () |
907 |
{ |
{ |
908 |
} |
} |
909 |
|
|
910 |
// Instance accessors. |
// Instance accessors. |
911 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device () |
912 |
{ |
{ |
913 |
return m_device; |
return m_device; |
914 |
} |
} |
915 |
|
|
916 |
|
|
|
|
|
917 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
918 |
// qsamplerDeviceParamTable - Device parameter view table. |
// AbstractDeviceParamModel - data model base class for device parameters |
919 |
// |
// |
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
|
|
const char *pszName ) |
|
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(3); |
|
|
QTable::setShowGrid(false); |
|
|
QTable::setSorting(false); |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
|
|
// No vertical header. |
|
|
QTable::verticalHeader()->hide(); |
|
|
QTable::setLeftMargin(0); |
|
|
// Initialize the fixed table column headings. |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
|
|
pHeader->setLabel(0, tr("Parameter")); |
|
|
pHeader->setLabel(1, tr("Description")); |
|
|
pHeader->setLabel(2, tr("Value")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
QTable::setColumnReadOnly(1, true); |
|
|
// QTable::setColumnReadOnly(2, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
|
} |
|
920 |
|
|
921 |
// Default destructor. |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
922 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
params = NULL; |
|
{ |
|
923 |
} |
} |
924 |
|
|
925 |
|
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
926 |
// Common parameter table renderer. |
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
927 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
return (params) ? params->size() : 0; |
|
bool bEditable ) |
|
|
{ |
|
|
// Always (re)start it empty. |
|
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
|
|
|
|
// Fill the parameter table... |
|
|
QTable::insertRows(0, params.count()); |
|
|
int iRow = 0; |
|
|
qsamplerDeviceParamMap::ConstIterator iter; |
|
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
|
|
const qsamplerDeviceParam& param = iter.data(); |
|
|
bool bEnabled = (bEditable || !param.fix); |
|
|
QTable::setText(iRow, 0, iter.key()); |
|
|
QTable::setText(iRow, 1, param.description); |
|
|
if (param.type == LSCP_TYPE_BOOL) { |
|
|
QStringList opts; |
|
|
opts.append(tr("false")); |
|
|
opts.append(tr("true")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.possibilities.count() > 0 && bEnabled) { |
|
|
QStringList opts = param.possibilities; |
|
|
if (param.multiplicity) |
|
|
opts.prepend(tr("(none)")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
if (param.value.isEmpty()) |
|
|
pComboItem->setCurrentItem(0); |
|
|
else |
|
|
pComboItem->setCurrentItem(param.value); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.type == LSCP_TYPE_INT && bEnabled |
|
|
&& !param.range_min.isEmpty() |
|
|
&& !param.range_max.isEmpty()) { |
|
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
|
|
new qsamplerDeviceParamTableSpinBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
pSpinItem->setMinValue(param.range_min.toInt()); |
|
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
|
|
QTable::setItem(iRow, 2, pSpinItem); |
|
|
} else { |
|
|
qsamplerDeviceParamTableEditBox *pEditItem = |
|
|
new qsamplerDeviceParamTableEditBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
QTable::setItem(iRow, 2, pEditItem); |
|
|
} |
|
|
++iRow; |
|
|
} |
|
|
|
|
|
// Adjust optimal column widths. |
|
|
QTable::adjustColumn(0); |
|
|
QTable::adjustColumn(2); |
|
|
|
|
|
QTable::setUpdatesEnabled(true); |
|
|
QTable::updateContents(); |
|
|
} |
|
|
#endif |
|
|
|
|
|
DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
|
928 |
} |
} |
929 |
|
|
930 |
int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
931 |
return params.size(); |
return 3; |
932 |
} |
} |
933 |
|
|
934 |
int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
935 |
return 3; |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
936 |
} |
} |
937 |
|
|
938 |
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const { |
939 |
if (!index.isValid()) |
if (!index.isValid()) { |
940 |
|
//std::cout << "inavlid device model index\n" << std::flush; |
941 |
return QVariant(); |
return QVariant(); |
942 |
if (role != Qt::DisplayRole) |
} |
943 |
|
if (role != Qt::DisplayRole) { |
944 |
|
//std::cout << "inavlid display role\n" << std::flush; |
945 |
return QVariant(); |
return QVariant(); |
946 |
|
} |
947 |
|
|
948 |
DeviceParameterRow item; |
DeviceParameterRow item; |
949 |
item.name = params.keys()[index.row()]; |
item.name = params->keys()[index.row()]; |
950 |
item.param = params[item.name]; |
item.param = (*params)[item.name]; |
951 |
|
|
952 |
|
//std::cout << "item["<<index.row()<<"]=[" << item.name.toUtf8().constData() << "]\n" << std::flush; |
953 |
|
|
954 |
return QVariant::fromValue(item); |
return QVariant::fromValue(item); |
955 |
} |
} |
956 |
|
|
957 |
QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
958 |
if (role != Qt::DisplayRole) return QVariant(); |
if (role != Qt::DisplayRole) return QVariant(); |
959 |
|
|
960 |
if (orientation == Qt::Horizontal) { |
if (orientation == Qt::Horizontal) { |
969 |
return QVariant(); |
return QVariant(); |
970 |
} |
} |
971 |
|
|
972 |
void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable) |
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
|
{ |
|
973 |
this->params = params; |
this->params = params; |
974 |
this->bEditable = bEditable; |
this->bEditable = bEditable; |
975 |
|
// inform the outer world (QTableView) that our data changed |
976 |
|
QAbstractTableModel::reset(); |
977 |
|
} |
978 |
|
|
979 |
|
void AbstractDeviceParamModel::clear() { |
980 |
|
params = NULL; |
981 |
|
// inform the outer world (QTableView) that our data changed |
982 |
|
QAbstractTableModel::reset(); |
983 |
|
} |
984 |
|
|
985 |
|
|
986 |
|
//------------------------------------------------------------------------- |
987 |
|
// DeviceParamModel - data model for device parameters (used for QTableView) |
988 |
|
// |
989 |
|
|
990 |
|
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
991 |
|
device = NULL; |
992 |
|
} |
993 |
|
|
994 |
|
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
995 |
|
if (!index.isValid()) { |
996 |
|
return false; |
997 |
|
} |
998 |
|
QString key = params->keys()[index.row()]; |
999 |
|
//params[key].value = value.toString(); |
1000 |
|
device->setParam(key, value.toString()); |
1001 |
|
emit dataChanged(index, index); |
1002 |
|
return true; |
1003 |
|
} |
1004 |
|
|
1005 |
|
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
1006 |
|
device = pDevice; |
1007 |
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
1008 |
} |
} |
1009 |
|
|
1010 |
void DeviceParamModel::clear() { |
void DeviceParamModel::clear() { |
1011 |
params.clear(); |
AbstractDeviceParamModel::clear(); |
1012 |
|
device = NULL; |
1013 |
|
} |
1014 |
|
|
1015 |
|
|
1016 |
|
//------------------------------------------------------------------------- |
1017 |
|
// PortParamModel - data model for port parameters (used for QTableView) |
1018 |
|
// |
1019 |
|
|
1020 |
|
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
1021 |
|
port = NULL; |
1022 |
|
} |
1023 |
|
|
1024 |
|
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
1025 |
|
if (!index.isValid()) { |
1026 |
|
return false; |
1027 |
|
} |
1028 |
|
QString key = params->keys()[index.row()]; |
1029 |
|
//params[key].value = value.toString(); |
1030 |
|
port->setParam(key, value.toString()); |
1031 |
|
emit dataChanged(index, index); |
1032 |
|
return true; |
1033 |
|
} |
1034 |
|
|
1035 |
|
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
1036 |
|
port = pPort; |
1037 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1038 |
|
} |
1039 |
|
|
1040 |
|
void PortParamModel::clear() { |
1041 |
|
AbstractDeviceParamModel::clear(); |
1042 |
|
port = NULL; |
1043 |
} |
} |
1044 |
|
|
1045 |
|
|
1046 |
|
//------------------------------------------------------------------------- |
1047 |
|
// DeviceParamDelegate - table cell renderer for device/port parameters |
1048 |
|
// |
1049 |
|
|
1050 |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
1051 |
} |
} |
1052 |
|
|
1054 |
const QStyleOptionViewItem &/* option */, |
const QStyleOptionViewItem &/* option */, |
1055 |
const QModelIndex& index) const |
const QModelIndex& index) const |
1056 |
{ |
{ |
1057 |
|
if (!index.isValid()) { |
1058 |
|
return NULL; |
1059 |
|
} |
1060 |
|
|
1061 |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1062 |
|
|
1063 |
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1068 |
case 1: { |
case 1: { |
1069 |
if (r.param.type == LSCP_TYPE_BOOL) { |
if (r.param.type == LSCP_TYPE_BOOL) { |
1070 |
QCheckBox* pCheckBox = new QCheckBox(parent); |
QCheckBox* pCheckBox = new QCheckBox(parent); |
1071 |
pCheckBox->setChecked(r.param.value.lower() == "true"); |
pCheckBox->setChecked(r.param.value.toLower() == "true"); |
1072 |
pCheckBox->setEnabled(bEnabled); |
pCheckBox->setEnabled(bEnabled); |
1073 |
return pCheckBox; |
return pCheckBox; |
1074 |
} else if (r.param.possibilities.count() > 0 && bEnabled) { |
} else if (r.param.possibilities.count() > 0) { |
1075 |
QStringList opts = r.param.possibilities; |
QStringList opts = r.param.possibilities; |
1076 |
if (r.param.multiplicity) |
if (r.param.multiplicity) |
1077 |
opts.prepend(tr("(none)")); |
opts.prepend(tr("(none)")); |
1083 |
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1084 |
pComboBox->setEnabled(bEnabled); |
pComboBox->setEnabled(bEnabled); |
1085 |
return pComboBox; |
return pComboBox; |
1086 |
} else if (r.param.type == LSCP_TYPE_INT && bEnabled |
} else if (r.param.type == LSCP_TYPE_INT |
1087 |
&& !r.param.range_min.isEmpty() |
&& !r.param.range_min.isEmpty() |
1088 |
&& !r.param.range_max.isEmpty()) { |
&& !r.param.range_max.isEmpty()) { |
1089 |
QSpinBox* pSpinBox = new QSpinBox(parent); |
QSpinBox* pSpinBox = new QSpinBox(parent); |
1090 |
pSpinBox->setValue(r.param.value.toInt()); |
pSpinBox->setValue(r.param.value.toInt()); |
1091 |
pSpinBox->setMinimum(r.param.range_min.toInt()); |
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1092 |
pSpinBox->setMaximum(r.param.range_max.toInt()); |
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1093 |
|
pSpinBox->setEnabled(bEnabled); |
1094 |
return pSpinBox; |
return pSpinBox; |
1095 |
} else { |
} else { |
1096 |
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1097 |
|
pLineEdit->setEnabled(bEnabled); |
1098 |
return pLineEdit; |
return pLineEdit; |
1099 |
} |
} |
1100 |
} |
} |
1105 |
} |
} |
1106 |
} |
} |
1107 |
|
|
1108 |
void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
1109 |
/* |
// unused, since we set the editor data already in createEditor() |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
|
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
|
|
comboBox->setCurrentIndex(item.selection); |
|
|
*/ |
|
1110 |
} |
} |
1111 |
|
|
1112 |
void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1113 |
/* |
if (index.column() == 1) { |
1114 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1115 |
model->setData(index, comboBox->currentIndex()); |
if (r.param.type == LSCP_TYPE_BOOL) { |
1116 |
*/ |
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
1117 |
|
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1118 |
|
} else if (r.param.possibilities.count() > 0) { |
1119 |
|
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
1120 |
|
model->setData(index, pComboBox->currentText()); |
1121 |
|
} else if (r.param.type == LSCP_TYPE_INT) { |
1122 |
|
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
1123 |
|
model->setData(index, pSpinBox->value()); |
1124 |
|
} else { |
1125 |
|
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
1126 |
|
model->setData(index, pLineEdit->text()); |
1127 |
|
} |
1128 |
|
} |
1129 |
} |
} |
1130 |
|
|
1131 |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1134 |
if (editor) editor->setGeometry(option.rect); |
if (editor) editor->setGeometry(option.rect); |
1135 |
} |
} |
1136 |
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
m_iValue = sText.toInt(); |
|
|
m_iMinValue = m_iMaxValue = 0; |
|
|
} |
|
|
|
|
|
// Public accessors. |
|
|
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
|
|
{ |
|
|
m_iValue = iValue; |
|
|
QTableItem::setText(QString::number(m_iValue)); |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
|
|
{ |
|
|
m_iMinValue = iMinValue; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
|
|
{ |
|
|
m_iMaxValue = iMaxValue; |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
|
|
{ |
|
|
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
|
|
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
|
|
pSpinBox->setMinValue(m_iMinValue); |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
|
|
} |
|
|
pSpinBox->setValue(m_iValue); |
|
|
return pSpinBox; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QSpinBox")) |
|
|
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
|
|
// |
|
|
|
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
|
|
{ |
|
|
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
|
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
pEditBox->setText(QTableItem::text()); |
|
|
return pEditBox; |
|
|
} |
|
|
|
|
|
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QLineEdit")) |
|
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
#endif |
|
|
|
|
1137 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |
|
|
|