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