1 |
capela |
426 |
// qsamplerDevice.h |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
schoenebeck |
1461 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
capela |
426 |
|
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 |
capela |
920 |
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 |
capela |
426 |
|
20 |
|
|
*****************************************************************************/ |
21 |
|
|
|
22 |
|
|
#ifndef __qsamplerDevice_h |
23 |
|
|
#define __qsamplerDevice_h |
24 |
|
|
|
25 |
schoenebeck |
1461 |
#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 |
capela |
426 |
|
39 |
|
|
#include <lscp/client.h> |
40 |
|
|
#include <lscp/device.h> |
41 |
|
|
|
42 |
|
|
#include "qsamplerOptions.h" |
43 |
|
|
|
44 |
|
|
|
45 |
capela |
430 |
// Special QListViewItem::rtti() unique return value. |
46 |
capela |
429 |
#define QSAMPLER_DEVICE_ITEM 1001 |
47 |
|
|
|
48 |
capela |
484 |
// Early forward declarations. |
49 |
|
|
class qsamplerMainForm; |
50 |
capela |
463 |
class qsamplerDevicePort; |
51 |
capela |
429 |
|
52 |
capela |
463 |
|
53 |
capela |
426 |
//------------------------------------------------------------------------- |
54 |
capela |
429 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
55 |
capela |
426 |
// |
56 |
capela |
429 |
class qsamplerDeviceParam |
57 |
|
|
{ |
58 |
|
|
public: |
59 |
capela |
426 |
|
60 |
capela |
431 |
// Constructor. |
61 |
|
|
qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL, |
62 |
capela |
429 |
const char *pszValue = NULL); |
63 |
capela |
431 |
// Default destructor. |
64 |
|
|
~qsamplerDeviceParam(); |
65 |
capela |
429 |
|
66 |
|
|
// Initializer. |
67 |
|
|
void setParam(lscp_param_info_t *pParamInfo, |
68 |
|
|
const char *pszValue = NULL); |
69 |
|
|
|
70 |
capela |
431 |
// 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 |
capela |
429 |
}; |
84 |
|
|
|
85 |
capela |
463 |
// Typedef'd parameter QMap. |
86 |
capela |
429 |
typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap; |
87 |
|
|
|
88 |
capela |
463 |
// Typedef'd device port/channels QptrList. |
89 |
schoenebeck |
1461 |
typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList; |
90 |
capela |
429 |
|
91 |
capela |
463 |
|
92 |
capela |
429 |
//------------------------------------------------------------------------- |
93 |
|
|
// qsamplerDevice - MIDI/Audio Device structure. |
94 |
|
|
// |
95 |
|
|
|
96 |
|
|
class qsamplerDevice |
97 |
capela |
426 |
{ |
98 |
capela |
429 |
public: |
99 |
|
|
|
100 |
capela |
431 |
// We use the same class for MIDI and audio device management |
101 |
capela |
436 |
enum qsamplerDeviceType { None, Midi, Audio }; |
102 |
capela |
429 |
|
103 |
capela |
431 |
// Constructor. |
104 |
capela |
961 |
qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
105 |
capela |
484 |
// Copy constructor. |
106 |
|
|
qsamplerDevice(const qsamplerDevice& device); |
107 |
capela |
431 |
// Default destructor. |
108 |
|
|
~qsamplerDevice(); |
109 |
capela |
429 |
|
110 |
|
|
// Initializer. |
111 |
capela |
484 |
void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
112 |
capela |
431 |
|
113 |
|
|
// Driver name initializer. |
114 |
capela |
484 |
void setDriver(const QString& sDriverName); |
115 |
capela |
431 |
|
116 |
capela |
429 |
// Device property accessors. |
117 |
capela |
431 |
int deviceID() const; |
118 |
|
|
qsamplerDeviceType deviceType() const; |
119 |
capela |
433 |
const QString& deviceTypeName() const; |
120 |
capela |
431 |
const QString& driverName() const; |
121 |
capela |
484 |
// Special device name formatter. |
122 |
|
|
QString deviceName() const; |
123 |
capela |
429 |
|
124 |
capela |
463 |
// Set the proper device parameter value. |
125 |
capela |
484 |
bool setParam (const QString& sParam, const QString& sValue); |
126 |
capela |
463 |
|
127 |
capela |
429 |
// Device parameters accessor. |
128 |
capela |
462 |
const qsamplerDeviceParamMap& params() const; |
129 |
capela |
429 |
|
130 |
capela |
463 |
// Device port/channel list accessor. |
131 |
|
|
qsamplerDevicePortList& ports(); |
132 |
capela |
429 |
|
133 |
capela |
467 |
// Device parameter dependency list refreshner. |
134 |
capela |
484 |
int refreshParams(); |
135 |
capela |
463 |
// Device port/channel list refreshner. |
136 |
capela |
484 |
int refreshPorts(); |
137 |
capela |
467 |
// Refresh/set dependencies given that some parameter has changed. |
138 |
capela |
484 |
int refreshDepends(const QString& sParam); |
139 |
capela |
467 |
|
140 |
capela |
484 |
// 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 |
capela |
430 |
// Device ids enumerator. |
152 |
capela |
431 |
static int *getDevices(lscp_client_t *pClient, |
153 |
capela |
429 |
qsamplerDeviceType deviceType); |
154 |
|
|
|
155 |
capela |
430 |
// Driver names enumerator. |
156 |
capela |
431 |
static QStringList getDrivers(lscp_client_t *pClient, |
157 |
capela |
430 |
qsamplerDeviceType deviceType); |
158 |
|
|
|
159 |
capela |
429 |
private: |
160 |
|
|
|
161 |
capela |
467 |
// Refresh/set given parameter based on driver supplied dependencies. |
162 |
capela |
484 |
int refreshParam(const QString& sParam); |
163 |
capela |
467 |
|
164 |
capela |
484 |
// Main application form reference. |
165 |
|
|
qsamplerMainForm *m_pMainForm; |
166 |
|
|
|
167 |
capela |
429 |
// Instance variables. |
168 |
capela |
431 |
int m_iDeviceID; |
169 |
|
|
qsamplerDeviceType m_deviceType; |
170 |
capela |
433 |
QString m_sDeviceType; |
171 |
capela |
431 |
QString m_sDriverName; |
172 |
|
|
QString m_sDeviceName; |
173 |
capela |
429 |
|
174 |
|
|
// Device parameter list. |
175 |
|
|
qsamplerDeviceParamMap m_params; |
176 |
capela |
492 |
|
177 |
capela |
463 |
// Device port/channel list. |
178 |
|
|
qsamplerDevicePortList m_ports; |
179 |
capela |
429 |
}; |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
//------------------------------------------------------------------------- |
183 |
capela |
462 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
184 |
|
|
// |
185 |
|
|
|
186 |
|
|
class qsamplerDevicePort |
187 |
|
|
{ |
188 |
|
|
public: |
189 |
|
|
|
190 |
|
|
// Constructor. |
191 |
capela |
484 |
qsamplerDevicePort(qsamplerDevice& device, int iPortID); |
192 |
capela |
462 |
// Default destructor. |
193 |
|
|
~qsamplerDevicePort(); |
194 |
|
|
|
195 |
|
|
// Initializer. |
196 |
capela |
484 |
void setDevicePort(int iPortID); |
197 |
capela |
462 |
|
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 |
capela |
484 |
bool setParam (const QString& sParam, const QString& sValue); |
207 |
capela |
462 |
|
208 |
|
|
private: |
209 |
|
|
|
210 |
capela |
484 |
// Device reference. |
211 |
|
|
qsamplerDevice& m_device; |
212 |
capela |
492 |
|
213 |
capela |
462 |
// 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 |
capela |
429 |
// qsamplerDeviceItem - QListView device item. |
224 |
|
|
// |
225 |
|
|
|
226 |
schoenebeck |
1461 |
class qsamplerDeviceItem : public QTreeWidgetItem |
227 |
capela |
429 |
{ |
228 |
|
|
public: |
229 |
|
|
|
230 |
capela |
431 |
// Constructors. |
231 |
schoenebeck |
1461 |
qsamplerDeviceItem(QTreeWidget* pTreeWidget, |
232 |
capela |
429 |
qsamplerDevice::qsamplerDeviceType deviceType); |
233 |
schoenebeck |
1461 |
qsamplerDeviceItem(QTreeWidgetItem* pItem, |
234 |
capela |
429 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
235 |
capela |
431 |
// Default destructor. |
236 |
|
|
~qsamplerDeviceItem(); |
237 |
capela |
429 |
|
238 |
capela |
431 |
// Instance accessors. |
239 |
|
|
qsamplerDevice& device(); |
240 |
capela |
429 |
|
241 |
|
|
private: |
242 |
|
|
|
243 |
capela |
431 |
// Instance variables. |
244 |
|
|
qsamplerDevice m_device; |
245 |
capela |
429 |
}; |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
//------------------------------------------------------------------------- |
249 |
|
|
// qsamplerDeviceParamTable - Device parameter view table. |
250 |
|
|
// |
251 |
|
|
|
252 |
schoenebeck |
1461 |
#if 0 |
253 |
capela |
429 |
class qsamplerDeviceParamTable : public QTable |
254 |
|
|
{ |
255 |
capela |
431 |
Q_OBJECT |
256 |
capela |
426 |
|
257 |
|
|
public: |
258 |
|
|
|
259 |
capela |
431 |
// Constructor. |
260 |
|
|
qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0); |
261 |
|
|
// Default destructor. |
262 |
|
|
~qsamplerDeviceParamTable(); |
263 |
capela |
426 |
|
264 |
capela |
462 |
// Common parameter table renderer. |
265 |
|
|
void refresh(const qsamplerDeviceParamMap& params, bool bEditable); |
266 |
capela |
426 |
}; |
267 |
schoenebeck |
1461 |
#endif |
268 |
capela |
426 |
|
269 |
schoenebeck |
1461 |
struct DeviceParameterRow { |
270 |
|
|
QString name; |
271 |
|
|
qsamplerDeviceParam param; |
272 |
|
|
}; |
273 |
capela |
426 |
|
274 |
schoenebeck |
1461 |
// 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 |
capela |
442 |
//------------------------------------------------------------------------- |
316 |
|
|
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
317 |
|
|
// |
318 |
|
|
|
319 |
schoenebeck |
1461 |
#if 0 |
320 |
|
|
class qsamplerDeviceParamTableSpinBox : public QTableWidgetItem |
321 |
capela |
442 |
{ |
322 |
|
|
public: |
323 |
|
|
|
324 |
|
|
// Constructor. |
325 |
schoenebeck |
1461 |
qsamplerDeviceParamTableSpinBox (QTableWidget *pTable, Qt::ItemFlags flags, |
326 |
capela |
447 |
const QString& sText); |
327 |
capela |
442 |
|
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 |
capela |
447 |
int m_iValue; |
343 |
capela |
442 |
int m_iMinValue; |
344 |
|
|
int m_iMaxValue; |
345 |
|
|
}; |
346 |
|
|
|
347 |
|
|
|
348 |
|
|
//------------------------------------------------------------------------- |
349 |
|
|
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
350 |
|
|
// |
351 |
|
|
|
352 |
schoenebeck |
1461 |
class qsamplerDeviceParamTableEditBox : public QTableWidgetItem |
353 |
capela |
442 |
{ |
354 |
|
|
public: |
355 |
|
|
|
356 |
|
|
// Constructor. |
357 |
schoenebeck |
1461 |
qsamplerDeviceParamTableEditBox (QTableWidget *pTable, Qt::ItemFlags flags, |
358 |
capela |
442 |
const QString& sText); |
359 |
|
|
|
360 |
|
|
protected: |
361 |
|
|
|
362 |
|
|
// Virtual implemetations. |
363 |
|
|
QWidget *createEditor() const; |
364 |
|
|
void setContentFromEditor(QWidget *pWidget); |
365 |
|
|
}; |
366 |
schoenebeck |
1461 |
#endif |
367 |
capela |
442 |
|
368 |
capela |
426 |
#endif // __qsamplerDevice_h |
369 |
|
|
|
370 |
|
|
|
371 |
|
|
// end of qsamplerDevice.h |