1 |
// qsamplerDevice.h |
// qsamplerDevice.h |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2005, 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 |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
#ifndef __qsamplerDevice_h |
#ifndef __qsamplerDevice_h |
24 |
#define __qsamplerDevice_h |
#define __qsamplerDevice_h |
25 |
|
|
26 |
#include <qtable.h> |
#include <QListWidget> |
27 |
|
#include <QListWidgetItem> |
28 |
|
#include <QTreeWidgetItem> |
29 |
|
#include <QTableWidget> |
30 |
|
#include <QTableWidgetItem> |
31 |
|
#include <QAbstractTableModel> |
32 |
|
#include <QItemDelegate> |
33 |
|
#include <QFontMetrics> |
34 |
|
#include <QModelIndex> |
35 |
|
#include <QSize> |
36 |
|
#include <QList> |
37 |
|
|
38 |
#include <lscp/client.h> |
#include <lscp/client.h> |
39 |
#include <lscp/device.h> |
#include <lscp/device.h> |
41 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
42 |
|
|
43 |
|
|
44 |
|
// Special QListViewItem::rtti() unique return value. |
45 |
|
#define QSAMPLER_DEVICE_ITEM 1001 |
46 |
|
|
47 |
|
// Early forward declarations. |
48 |
|
class qsamplerMainForm; |
49 |
|
class qsamplerDevicePort; |
50 |
|
|
51 |
|
|
52 |
|
//------------------------------------------------------------------------- |
53 |
|
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
54 |
|
// |
55 |
|
class qsamplerDeviceParam |
56 |
|
{ |
57 |
|
public: |
58 |
|
|
59 |
|
// Constructor. |
60 |
|
qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL, |
61 |
|
const char *pszValue = NULL); |
62 |
|
// Default destructor. |
63 |
|
~qsamplerDeviceParam(); |
64 |
|
|
65 |
|
// Initializer. |
66 |
|
void setParam(lscp_param_info_t *pParamInfo, |
67 |
|
const char *pszValue = NULL); |
68 |
|
|
69 |
|
// Info structure field members. |
70 |
|
lscp_type_t type; |
71 |
|
QString description; |
72 |
|
bool mandatory; |
73 |
|
bool fix; |
74 |
|
bool multiplicity; |
75 |
|
QStringList depends; |
76 |
|
QString defaultv; |
77 |
|
QString range_min; |
78 |
|
QString range_max; |
79 |
|
QStringList possibilities; |
80 |
|
// The current parameter value. |
81 |
|
QString value; |
82 |
|
}; |
83 |
|
|
84 |
|
// Typedef'd parameter QMap. |
85 |
|
typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap; |
86 |
|
|
87 |
|
// Typedef'd device port/channels QptrList. |
88 |
|
typedef QList<qsamplerDevicePort *> qsamplerDevicePortList; |
89 |
|
|
90 |
|
|
91 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
92 |
// qsamplerDeviceParameterTable - Device parameter view table. |
// qsamplerDevice - MIDI/Audio Device structure. |
93 |
// |
// |
94 |
|
|
95 |
class qsamplerDeviceParameterTable : public QTable |
class qsamplerDevice |
96 |
{ |
{ |
97 |
Q_OBJECT |
public: |
98 |
|
|
99 |
|
// We use the same class for MIDI and audio device management |
100 |
|
enum qsamplerDeviceType { None, Midi, Audio }; |
101 |
|
|
102 |
|
// Constructor. |
103 |
|
qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
104 |
|
// Copy constructor. |
105 |
|
qsamplerDevice(const qsamplerDevice& device); |
106 |
|
// Default destructor. |
107 |
|
~qsamplerDevice(); |
108 |
|
|
109 |
|
// Initializer. |
110 |
|
void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
111 |
|
|
112 |
|
// Driver name initializer. |
113 |
|
void setDriver(const QString& sDriverName); |
114 |
|
|
115 |
|
// Device property accessors. |
116 |
|
int deviceID() const; |
117 |
|
qsamplerDeviceType deviceType() const; |
118 |
|
const QString& deviceTypeName() const; |
119 |
|
const QString& driverName() const; |
120 |
|
// Special device name formatter. |
121 |
|
QString deviceName() const; |
122 |
|
|
123 |
|
// Set the proper device parameter value. |
124 |
|
bool setParam (const QString& sParam, const QString& sValue); |
125 |
|
|
126 |
|
// Device parameters accessor. |
127 |
|
const qsamplerDeviceParamMap& params() const; |
128 |
|
|
129 |
|
// Device port/channel list accessor. |
130 |
|
qsamplerDevicePortList& ports(); |
131 |
|
|
132 |
|
// Device parameter dependency list refreshner. |
133 |
|
int refreshParams(); |
134 |
|
// Device port/channel list refreshner. |
135 |
|
int refreshPorts(); |
136 |
|
// Refresh/set dependencies given that some parameter has changed. |
137 |
|
int refreshDepends(const QString& sParam); |
138 |
|
|
139 |
|
// Create/destroy device methods. |
140 |
|
bool createDevice(); |
141 |
|
bool deleteDevice(); |
142 |
|
|
143 |
|
// Message logging methods (brainlessly mapped to main form's). |
144 |
|
void appendMessages (const QString& s) const; |
145 |
|
void appendMessagesColor (const QString& s, const QString & c) const; |
146 |
|
void appendMessagesText (const QString& s) const; |
147 |
|
void appendMessagesError (const QString& s) const; |
148 |
|
void appendMessagesClient (const QString& s) const; |
149 |
|
|
150 |
|
// Device ids enumerator. |
151 |
|
static int *getDevices(lscp_client_t *pClient, |
152 |
|
qsamplerDeviceType deviceType); |
153 |
|
|
154 |
|
// Driver names enumerator. |
155 |
|
static QStringList getDrivers(lscp_client_t *pClient, |
156 |
|
qsamplerDeviceType deviceType); |
157 |
|
|
158 |
|
private: |
159 |
|
|
160 |
|
// Refresh/set given parameter based on driver supplied dependencies. |
161 |
|
int refreshParam(const QString& sParam); |
162 |
|
|
163 |
|
// Main application form reference. |
164 |
|
qsamplerMainForm *m_pMainForm; |
165 |
|
|
166 |
|
// Instance variables. |
167 |
|
int m_iDeviceID; |
168 |
|
qsamplerDeviceType m_deviceType; |
169 |
|
QString m_sDeviceType; |
170 |
|
QString m_sDriverName; |
171 |
|
QString m_sDeviceName; |
172 |
|
|
173 |
|
// Device parameter list. |
174 |
|
qsamplerDeviceParamMap m_params; |
175 |
|
|
176 |
|
// Device port/channel list. |
177 |
|
qsamplerDevicePortList m_ports; |
178 |
|
}; |
179 |
|
|
180 |
|
|
181 |
|
//------------------------------------------------------------------------- |
182 |
|
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
183 |
|
// |
184 |
|
|
185 |
|
class qsamplerDevicePort |
186 |
|
{ |
187 |
public: |
public: |
188 |
|
|
189 |
// Constructor. |
// Constructor. |
190 |
qsamplerDeviceParameterTable(QWidget *pParent = 0, const char *pszName = 0); |
qsamplerDevicePort(qsamplerDevice& device, int iPortID); |
191 |
// Default destructor. |
// Default destructor. |
192 |
~qsamplerDeviceParameterTable(); |
~qsamplerDevicePort(); |
193 |
|
|
194 |
// LSCP client descriptor accessor. |
// Initializer. |
195 |
void setClient(lscp_client_t *pClient); |
void setDevicePort(int iPortID); |
196 |
lscp_client_t * client(); |
|
197 |
|
// Device port property accessors. |
198 |
|
int portID() const; |
199 |
|
const QString& portName() const; |
200 |
|
|
201 |
|
// Device port parameters accessor. |
202 |
|
const qsamplerDeviceParamMap& params() const; |
203 |
|
|
204 |
|
// Set the proper device port/channel parameter value. |
205 |
|
bool setParam (const QString& sParam, const QString& sValue); |
206 |
|
|
207 |
private: |
private: |
208 |
|
|
209 |
// LSCP client reference. |
// Device reference. |
210 |
lscp_client_t *m_pClient; |
qsamplerDevice& m_device; |
211 |
|
|
212 |
|
// Instance variables. |
213 |
|
int m_iPortID; |
214 |
|
QString m_sPortName; |
215 |
|
|
216 |
|
// Device port parameter list. |
217 |
|
qsamplerDeviceParamMap m_params; |
218 |
}; |
}; |
219 |
|
|
220 |
|
|
221 |
#endif // __qsamplerDevice_h |
//------------------------------------------------------------------------- |
222 |
|
// qsamplerDeviceItem - QListView device item. |
223 |
|
// |
224 |
|
|
225 |
|
class qsamplerDeviceItem : public QTreeWidgetItem |
226 |
|
{ |
227 |
|
public: |
228 |
|
|
229 |
|
// Constructors. |
230 |
|
qsamplerDeviceItem(QTreeWidget* pTreeWidget, |
231 |
|
qsamplerDevice::qsamplerDeviceType deviceType); |
232 |
|
qsamplerDeviceItem(QTreeWidgetItem* pItem, |
233 |
|
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
234 |
|
// Default destructor. |
235 |
|
~qsamplerDeviceItem(); |
236 |
|
|
237 |
|
// Instance accessors. |
238 |
|
qsamplerDevice& device(); |
239 |
|
|
240 |
|
private: |
241 |
|
|
242 |
|
// Instance variables. |
243 |
|
qsamplerDevice m_device; |
244 |
|
}; |
245 |
|
|
246 |
|
struct DeviceParameterRow { |
247 |
|
QString name; |
248 |
|
qsamplerDeviceParam param; |
249 |
|
bool alive; // whether these params refer to an existing device or for a device that is yet to be created |
250 |
|
}; |
251 |
|
|
252 |
|
// so we can use it i.e. through QVariant |
253 |
|
Q_DECLARE_METATYPE(DeviceParameterRow) |
254 |
|
|
255 |
|
//------------------------------------------------------------------------- |
256 |
|
// AbstractDeviceParamModel - data model base class for device parameters |
257 |
|
// |
258 |
|
class AbstractDeviceParamModel : public QAbstractTableModel { |
259 |
|
Q_OBJECT |
260 |
|
public: |
261 |
|
AbstractDeviceParamModel(QObject* parent = 0); |
262 |
|
|
263 |
|
// overridden methods from subclass(es) |
264 |
|
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
265 |
|
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
266 |
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
267 |
|
Qt::ItemFlags flags(const QModelIndex& index) const; |
268 |
|
|
269 |
|
virtual void clear(); |
270 |
|
|
271 |
|
void refresh(const qsamplerDeviceParamMap* params, bool bEditable); |
272 |
|
|
273 |
|
protected: |
274 |
|
const qsamplerDeviceParamMap* params; |
275 |
|
bool bEditable; |
276 |
|
}; |
277 |
|
|
278 |
|
//------------------------------------------------------------------------- |
279 |
|
// DeviceParamModel - data model for device parameters (used for QTableView) |
280 |
|
// |
281 |
|
class DeviceParamModel : public AbstractDeviceParamModel { |
282 |
|
Q_OBJECT |
283 |
|
public: |
284 |
|
DeviceParamModel(QObject* parent = 0); |
285 |
|
|
286 |
|
// overridden methods from subclass(es) |
287 |
|
QVariant data(const QModelIndex &index, int role) const; |
288 |
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
289 |
|
void clear(); |
290 |
|
|
291 |
|
public slots: |
292 |
|
void refresh(qsamplerDevice* pDevice, bool bEditable); |
293 |
|
|
294 |
|
private: |
295 |
|
qsamplerDevice* device; |
296 |
|
}; |
297 |
|
|
298 |
|
//------------------------------------------------------------------------- |
299 |
|
// PortParamModel - data model for port parameters (used for QTableView) |
300 |
|
// |
301 |
|
class PortParamModel : public AbstractDeviceParamModel { |
302 |
|
Q_OBJECT |
303 |
|
public: |
304 |
|
PortParamModel(QObject* parent = 0); |
305 |
|
|
306 |
|
// overridden methods from subclass(es) |
307 |
|
QVariant data(const QModelIndex &index, int role) const; |
308 |
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
309 |
|
void clear(); |
310 |
|
|
311 |
|
public slots: |
312 |
|
void refresh(qsamplerDevicePort* pPort, bool bEditable); |
313 |
|
|
314 |
|
private: |
315 |
|
qsamplerDevicePort* port; |
316 |
|
}; |
317 |
|
|
318 |
|
//------------------------------------------------------------------------- |
319 |
|
// DeviceParamDelegate - table cell renderer for device/port parameters |
320 |
|
// |
321 |
|
class DeviceParamDelegate : public QItemDelegate { |
322 |
|
Q_OBJECT |
323 |
|
public: |
324 |
|
DeviceParamDelegate(QObject* parent = 0); |
325 |
|
QWidget* createEditor(QWidget* parent, |
326 |
|
const QStyleOptionViewItem& option, |
327 |
|
const QModelIndex& index) const; |
328 |
|
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
329 |
|
void setModelData(QWidget* editor, QAbstractItemModel* model, |
330 |
|
const QModelIndex& index) const; |
331 |
|
void updateEditorGeometry(QWidget* editor, |
332 |
|
const QStyleOptionViewItem& option, |
333 |
|
const QModelIndex& index) const; |
334 |
|
}; |
335 |
|
|
336 |
|
#endif // __qsamplerDevice_h |
337 |
|
|
338 |
// end of qsamplerDevice.h |
// end of qsamplerDevice.h |