1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2006, 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 |
29 |
#include <qspinbox.h> |
#include <qspinbox.h> |
30 |
#include <qlineedit.h> |
#include <qlineedit.h> |
31 |
|
|
32 |
|
using namespace QSampler; |
33 |
|
|
34 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
35 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
132 |
// Initializer. |
// Initializer. |
133 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
134 |
{ |
{ |
135 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
136 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
137 |
return; |
return; |
138 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
211 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
212 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
213 |
{ |
{ |
214 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
215 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
216 |
return; |
return; |
217 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
315 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool qsamplerDevice::setParam ( const QString& sParam, |
316 |
const QString& sValue ) |
const QString& sValue ) |
317 |
{ |
{ |
318 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
319 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
320 |
return false; |
return false; |
321 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
385 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
386 |
bool qsamplerDevice::createDevice (void) |
bool qsamplerDevice::createDevice (void) |
387 |
{ |
{ |
388 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
389 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
390 |
return false; |
return false; |
391 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
440 |
// Destroy existing device. |
// Destroy existing device. |
441 |
bool qsamplerDevice::deleteDevice (void) |
bool qsamplerDevice::deleteDevice (void) |
442 |
{ |
{ |
443 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
444 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
445 |
return false; |
return false; |
446 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
541 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
542 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
543 |
{ |
{ |
544 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
545 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
546 |
return 0; |
return 0; |
547 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
605 |
// Redirected messages output methods. |
// Redirected messages output methods. |
606 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void qsamplerDevice::appendMessages( const QString& s ) const |
607 |
{ |
{ |
608 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
609 |
if (pMainForm) |
if (pMainForm) |
610 |
pMainForm->appendMessages(deviceName() + ' ' + s); |
pMainForm->appendMessages(deviceName() + ' ' + s); |
611 |
} |
} |
613 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void qsamplerDevice::appendMessagesColor( const QString& s, |
614 |
const QString& c ) const |
const QString& c ) const |
615 |
{ |
{ |
616 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
617 |
if (pMainForm) |
if (pMainForm) |
618 |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
619 |
} |
} |
620 |
|
|
621 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
622 |
{ |
{ |
623 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
624 |
if (pMainForm) |
if (pMainForm) |
625 |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
626 |
} |
} |
627 |
|
|
628 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
629 |
{ |
{ |
630 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
631 |
if (pMainForm) |
if (pMainForm) |
632 |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
633 |
} |
} |
634 |
|
|
635 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
636 |
{ |
{ |
637 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
638 |
if (pMainForm) |
if (pMainForm) |
639 |
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
640 |
} |
} |
677 |
break; |
break; |
678 |
} |
} |
679 |
|
|
680 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
681 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
682 |
|
|
683 |
return drivers; |
return drivers; |
704 |
// Initializer. |
// Initializer. |
705 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
706 |
{ |
{ |
707 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
708 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
709 |
return; |
return; |
710 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
793 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
794 |
const QString& sValue ) |
const QString& sValue ) |
795 |
{ |
{ |
796 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
797 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
798 |
return false; |
return false; |
799 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
843 |
|
|
844 |
|
|
845 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
846 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
847 |
// |
// |
848 |
|
|
849 |
// Constructors. |
// Constructors. |
850 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
851 |
qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::qsamplerDeviceType deviceType ) |
852 |
: QListViewItem(pListView), m_device(deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
853 |
|
m_device(deviceType) |
854 |
{ |
{ |
855 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
856 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
857 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio1.png")); |
858 |
QListViewItem::setText(0, QObject::tr("Audio Devices")); |
setText(1, QObject::tr("Audio Devices")); |
859 |
break; |
break; |
860 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
861 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi1.png")); |
862 |
QListViewItem::setText(0, QObject::tr("MIDI Devices")); |
setText(1, QObject::tr("MIDI Devices")); |
863 |
break; |
break; |
864 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
865 |
break; |
break; |
866 |
} |
} |
867 |
} |
} |
868 |
|
|
869 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
870 |
qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::qsamplerDeviceType deviceType, |
871 |
int iDeviceID ) |
int iDeviceID ) |
872 |
: QListViewItem(pItem), m_device(deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
873 |
|
m_device(deviceType, iDeviceID) |
874 |
{ |
{ |
875 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
876 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
877 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/audio2.png")); |
878 |
break; |
break; |
879 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
880 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/qsampler/pixmaps/midi2.png")); |
881 |
break; |
break; |
882 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
883 |
break; |
break; |
884 |
} |
} |
885 |
|
|
886 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(1, m_device.deviceName()); |
887 |
} |
} |
888 |
|
|
889 |
// Default destructor. |
// Default destructor. |
897 |
return m_device; |
return m_device; |
898 |
} |
} |
899 |
|
|
|
// To virtually distinguish between list view items. |
|
|
int qsamplerDeviceItem::rtti() const |
|
|
{ |
|
|
return QSAMPLER_DEVICE_ITEM; |
|
|
} |
|
|
|
|
900 |
|
|
901 |
|
|
902 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
903 |
// qsamplerDeviceParamTable - Device parameter view table. |
// qsamplerDeviceParamTable - Device parameter view table. |
904 |
// |
// |
905 |
|
#if 0 |
906 |
// Constructor. |
// Constructor. |
907 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
908 |
const char *pszName ) |
const char *pszName ) |
998 |
QTable::setUpdatesEnabled(true); |
QTable::setUpdatesEnabled(true); |
999 |
QTable::updateContents(); |
QTable::updateContents(); |
1000 |
} |
} |
1001 |
|
#endif |
1002 |
|
|
1003 |
|
DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
1004 |
|
} |
1005 |
|
|
1006 |
|
int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
1007 |
|
return params.size(); |
1008 |
|
} |
1009 |
|
|
1010 |
|
int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
1011 |
|
return 3; |
1012 |
|
} |
1013 |
|
|
1014 |
|
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
1015 |
|
if (!index.isValid()) |
1016 |
|
return QVariant(); |
1017 |
|
if (role != Qt::DisplayRole) |
1018 |
|
return QVariant(); |
1019 |
|
|
1020 |
|
DeviceParameterRow item; |
1021 |
|
item.name = params.keys()[index.row()]; |
1022 |
|
item.param = params[item.name]; |
1023 |
|
|
1024 |
|
return QVariant::fromValue(item); |
1025 |
|
} |
1026 |
|
|
1027 |
|
QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
1028 |
|
if (role != Qt::DisplayRole) return QVariant(); |
1029 |
|
|
1030 |
|
if (orientation == Qt::Horizontal) { |
1031 |
|
switch (section) { |
1032 |
|
case 0: return tr("Parameter"); |
1033 |
|
case 1: return tr("Value"); |
1034 |
|
case 2: return tr("Description"); |
1035 |
|
default: return QVariant(); |
1036 |
|
} |
1037 |
|
} |
1038 |
|
|
1039 |
|
return QVariant(); |
1040 |
|
} |
1041 |
|
|
1042 |
|
void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable) |
1043 |
|
{ |
1044 |
|
this->params = params; |
1045 |
|
this->bEditable = bEditable; |
1046 |
|
} |
1047 |
|
|
1048 |
|
void DeviceParamModel::clear() { |
1049 |
|
params.clear(); |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
|
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
1054 |
|
} |
1055 |
|
|
1056 |
|
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
1057 |
|
const QStyleOptionViewItem &/* option */, |
1058 |
|
const QModelIndex& index) const |
1059 |
|
{ |
1060 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1061 |
|
|
1062 |
|
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1063 |
|
|
1064 |
|
switch (index.column()) { |
1065 |
|
case 0: |
1066 |
|
return new QLabel(r.name, parent); |
1067 |
|
case 1: { |
1068 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1069 |
|
QCheckBox* pCheckBox = new QCheckBox(parent); |
1070 |
|
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1071 |
|
pCheckBox->setEnabled(bEnabled); |
1072 |
|
return pCheckBox; |
1073 |
|
} else if (r.param.possibilities.count() > 0 && bEnabled) { |
1074 |
|
QStringList opts = r.param.possibilities; |
1075 |
|
if (r.param.multiplicity) |
1076 |
|
opts.prepend(tr("(none)")); |
1077 |
|
QComboBox* pComboBox = new QComboBox(parent); |
1078 |
|
pComboBox->addItems(opts); |
1079 |
|
if (r.param.value.isEmpty()) |
1080 |
|
pComboBox->setCurrentIndex(0); |
1081 |
|
else |
1082 |
|
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1083 |
|
pComboBox->setEnabled(bEnabled); |
1084 |
|
return pComboBox; |
1085 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled |
1086 |
|
&& !r.param.range_min.isEmpty() |
1087 |
|
&& !r.param.range_max.isEmpty()) { |
1088 |
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
1089 |
|
pSpinBox->setValue(r.param.value.toInt()); |
1090 |
|
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1091 |
|
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1092 |
|
return pSpinBox; |
1093 |
|
} else { |
1094 |
|
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1095 |
|
return pLineEdit; |
1096 |
|
} |
1097 |
|
} |
1098 |
|
case 2: |
1099 |
|
return new QLabel(r.param.description, parent); |
1100 |
|
default: |
1101 |
|
return NULL; |
1102 |
|
} |
1103 |
|
} |
1104 |
|
|
1105 |
|
void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1106 |
|
/* |
1107 |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1108 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1109 |
|
comboBox->setCurrentIndex(item.selection); |
1110 |
|
*/ |
1111 |
|
} |
1112 |
|
|
1113 |
|
void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
1114 |
|
/* |
1115 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1116 |
|
model->setData(index, comboBox->currentIndex()); |
1117 |
|
*/ |
1118 |
|
} |
1119 |
|
|
1120 |
|
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1121 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1122 |
|
{ |
1123 |
|
if (editor) editor->setGeometry(option.rect); |
1124 |
|
} |
1125 |
|
|
1126 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1127 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
1128 |
// |
// |
1129 |
|
|
1130 |
|
#if 0 |
1131 |
// Constructor. |
// Constructor. |
1132 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
1133 |
QTable *pTable, EditType editType, const QString& sText ) |
QTable *pTable, EditType editType, const QString& sText ) |
1205 |
else |
else |
1206 |
QTableItem::setContentFromEditor(pWidget); |
QTableItem::setContentFromEditor(pWidget); |
1207 |
} |
} |
1208 |
|
#endif |
1209 |
|
|
1210 |
|
|
1211 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |
|
|
|