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