1 |
capela |
426 |
// qsamplerDevice.h |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
schoenebeck |
1461 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
schoenebeck |
1698 |
Copyright (C) 2007, 2008 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 <QItemDelegate> |
33 |
|
|
#include <QFontMetrics> |
34 |
|
|
#include <QModelIndex> |
35 |
|
|
#include <QSize> |
36 |
|
|
#include <QList> |
37 |
schoenebeck |
1698 |
#include <set> |
38 |
capela |
426 |
|
39 |
|
|
#include <lscp/client.h> |
40 |
|
|
#include <lscp/device.h> |
41 |
|
|
|
42 |
|
|
#include "qsamplerOptions.h" |
43 |
|
|
|
44 |
capela |
1558 |
namespace QSampler { |
45 |
capela |
426 |
|
46 |
capela |
1558 |
class DevicePort; |
47 |
|
|
|
48 |
capela |
430 |
// Special QListViewItem::rtti() unique return value. |
49 |
capela |
429 |
#define QSAMPLER_DEVICE_ITEM 1001 |
50 |
|
|
|
51 |
|
|
|
52 |
capela |
426 |
//------------------------------------------------------------------------- |
53 |
capela |
1558 |
// QSampler::DeviceParam - MIDI/Audio Device parameter structure. |
54 |
capela |
426 |
// |
55 |
capela |
1558 |
|
56 |
|
|
class DeviceParam |
57 |
capela |
429 |
{ |
58 |
|
|
public: |
59 |
capela |
426 |
|
60 |
capela |
431 |
// Constructor. |
61 |
capela |
1558 |
DeviceParam(lscp_param_info_t *pParamInfo = NULL, |
62 |
capela |
429 |
const char *pszValue = NULL); |
63 |
capela |
431 |
// Default destructor. |
64 |
capela |
1558 |
~DeviceParam(); |
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 |
1558 |
typedef QMap<QString, DeviceParam> DeviceParamMap; |
87 |
capela |
429 |
|
88 |
capela |
1558 |
// Typedef'd device port/channels QList. |
89 |
|
|
typedef QList<DevicePort *> DevicePortList; |
90 |
capela |
429 |
|
91 |
capela |
463 |
|
92 |
capela |
429 |
//------------------------------------------------------------------------- |
93 |
capela |
1558 |
// QSampler::Device - MIDI/Audio Device structure. |
94 |
capela |
429 |
// |
95 |
|
|
|
96 |
capela |
1558 |
class Device |
97 |
capela |
426 |
{ |
98 |
capela |
429 |
public: |
99 |
|
|
|
100 |
capela |
431 |
// We use the same class for MIDI and audio device management |
101 |
capela |
1509 |
enum DeviceType { None, Midi, Audio }; |
102 |
capela |
429 |
|
103 |
capela |
431 |
// Constructor. |
104 |
capela |
1558 |
Device(DeviceType deviceType, int iDeviceID = -1); |
105 |
capela |
484 |
// Copy constructor. |
106 |
capela |
1558 |
Device(const Device& device); |
107 |
|
|
|
108 |
capela |
431 |
// Default destructor. |
109 |
capela |
1558 |
~Device(); |
110 |
capela |
429 |
|
111 |
|
|
// Initializer. |
112 |
capela |
1509 |
void setDevice(DeviceType 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 |
1509 |
int deviceID() const; |
119 |
|
|
DeviceType deviceType() const; |
120 |
|
|
const QString& deviceTypeName() const; |
121 |
|
|
const QString& driverName() const; |
122 |
|
|
|
123 |
capela |
484 |
// Special device name formatter. |
124 |
|
|
QString deviceName() const; |
125 |
capela |
429 |
|
126 |
capela |
463 |
// Set the proper device parameter value. |
127 |
capela |
484 |
bool setParam (const QString& sParam, const QString& sValue); |
128 |
capela |
463 |
|
129 |
capela |
429 |
// Device parameters accessor. |
130 |
capela |
1558 |
const DeviceParamMap& params() const; |
131 |
capela |
429 |
|
132 |
capela |
463 |
// Device port/channel list accessor. |
133 |
capela |
1558 |
DevicePortList& ports(); |
134 |
capela |
429 |
|
135 |
capela |
467 |
// Device parameter dependency list refreshner. |
136 |
capela |
484 |
int refreshParams(); |
137 |
capela |
463 |
// Device port/channel list refreshner. |
138 |
capela |
484 |
int refreshPorts(); |
139 |
capela |
467 |
// Refresh/set dependencies given that some parameter has changed. |
140 |
capela |
484 |
int refreshDepends(const QString& sParam); |
141 |
capela |
467 |
|
142 |
capela |
484 |
// Create/destroy device methods. |
143 |
|
|
bool createDevice(); |
144 |
|
|
bool deleteDevice(); |
145 |
|
|
|
146 |
|
|
// Message logging methods (brainlessly mapped to main form's). |
147 |
|
|
void appendMessages (const QString& s) const; |
148 |
|
|
void appendMessagesColor (const QString& s, const QString & c) const; |
149 |
|
|
void appendMessagesText (const QString& s) const; |
150 |
|
|
void appendMessagesError (const QString& s) const; |
151 |
|
|
void appendMessagesClient (const QString& s) const; |
152 |
|
|
|
153 |
capela |
430 |
// Device ids enumerator. |
154 |
capela |
431 |
static int *getDevices(lscp_client_t *pClient, |
155 |
capela |
1509 |
DeviceType deviceType); |
156 |
schoenebeck |
1698 |
static std::set<int> getDeviceIDs(lscp_client_t *pClient, |
157 |
|
|
DeviceType deviceType); |
158 |
capela |
429 |
|
159 |
capela |
430 |
// Driver names enumerator. |
160 |
capela |
431 |
static QStringList getDrivers(lscp_client_t *pClient, |
161 |
capela |
1509 |
DeviceType deviceType); |
162 |
capela |
430 |
|
163 |
capela |
429 |
private: |
164 |
|
|
|
165 |
capela |
467 |
// Refresh/set given parameter based on driver supplied dependencies. |
166 |
capela |
484 |
int refreshParam(const QString& sParam); |
167 |
capela |
467 |
|
168 |
capela |
429 |
// Instance variables. |
169 |
capela |
1509 |
int m_iDeviceID; |
170 |
|
|
DeviceType m_deviceType; |
171 |
|
|
QString m_sDeviceType; |
172 |
|
|
QString m_sDriverName; |
173 |
|
|
QString m_sDeviceName; |
174 |
capela |
429 |
|
175 |
|
|
// Device parameter list. |
176 |
capela |
1558 |
DeviceParamMap m_params; |
177 |
capela |
492 |
|
178 |
capela |
463 |
// Device port/channel list. |
179 |
capela |
1558 |
DevicePortList m_ports; |
180 |
capela |
429 |
}; |
181 |
|
|
|
182 |
|
|
|
183 |
|
|
//------------------------------------------------------------------------- |
184 |
capela |
1558 |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
185 |
capela |
462 |
// |
186 |
|
|
|
187 |
capela |
1558 |
class DevicePort |
188 |
capela |
462 |
{ |
189 |
|
|
public: |
190 |
|
|
|
191 |
|
|
// Constructor. |
192 |
capela |
1558 |
DevicePort(Device& device, int iPortID); |
193 |
capela |
462 |
// Default destructor. |
194 |
capela |
1558 |
~DevicePort(); |
195 |
capela |
462 |
|
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 |
capela |
1558 |
const DeviceParamMap& params() const; |
205 |
capela |
462 |
|
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 |
capela |
1558 |
Device& 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 |
capela |
1558 |
DeviceParamMap m_params; |
220 |
capela |
462 |
}; |
221 |
|
|
|
222 |
|
|
|
223 |
|
|
//------------------------------------------------------------------------- |
224 |
capela |
1558 |
// QSampler::DeviceItem - QTreeWidget device item. |
225 |
capela |
429 |
// |
226 |
|
|
|
227 |
capela |
1558 |
class DeviceItem : public QTreeWidgetItem |
228 |
capela |
429 |
{ |
229 |
|
|
public: |
230 |
|
|
|
231 |
capela |
431 |
// Constructors. |
232 |
capela |
1558 |
DeviceItem(QTreeWidget *pTreeWidget, |
233 |
|
|
Device::DeviceType deviceType); |
234 |
|
|
DeviceItem(QTreeWidgetItem *pItem, |
235 |
|
|
Device::DeviceType deviceType, int iDeviceID); |
236 |
|
|
|
237 |
capela |
431 |
// Default destructor. |
238 |
capela |
1558 |
~DeviceItem(); |
239 |
capela |
429 |
|
240 |
capela |
431 |
// Instance accessors. |
241 |
capela |
1558 |
Device& device(); |
242 |
capela |
429 |
|
243 |
|
|
private: |
244 |
|
|
|
245 |
capela |
431 |
// Instance variables. |
246 |
capela |
1558 |
Device m_device; |
247 |
capela |
429 |
}; |
248 |
|
|
|
249 |
capela |
1558 |
|
250 |
schoenebeck |
1461 |
struct DeviceParameterRow { |
251 |
capela |
1558 |
QString name; |
252 |
|
|
DeviceParam param; |
253 |
|
|
bool alive; // whether these params refer to an existing device |
254 |
|
|
// or for a device that is yet to be created |
255 |
schoenebeck |
1461 |
}; |
256 |
capela |
426 |
|
257 |
schoenebeck |
1461 |
|
258 |
schoenebeck |
1486 |
//------------------------------------------------------------------------- |
259 |
capela |
1558 |
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
260 |
schoenebeck |
1486 |
// |
261 |
capela |
1558 |
|
262 |
capela |
1509 |
class AbstractDeviceParamModel : public QAbstractTableModel |
263 |
|
|
{ |
264 |
|
|
Q_OBJECT |
265 |
schoenebeck |
1461 |
|
266 |
capela |
1509 |
public: |
267 |
schoenebeck |
1461 |
|
268 |
capela |
1509 |
AbstractDeviceParamModel(QObject *pParent = NULL); |
269 |
schoenebeck |
1461 |
|
270 |
capela |
1509 |
// Overridden methods from subclass(es) |
271 |
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
272 |
|
|
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
273 |
|
|
QVariant headerData(int section, |
274 |
|
|
Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
275 |
|
|
Qt::ItemFlags flags(const QModelIndex& index) const; |
276 |
schoenebeck |
1461 |
|
277 |
capela |
1509 |
virtual void clear(); |
278 |
|
|
|
279 |
capela |
1558 |
void refresh(const DeviceParamMap* params, bool bEditable); |
280 |
capela |
1509 |
|
281 |
|
|
protected: |
282 |
|
|
|
283 |
capela |
1558 |
const DeviceParamMap *m_pParams; |
284 |
capela |
1509 |
bool m_bEditable; |
285 |
schoenebeck |
1461 |
}; |
286 |
|
|
|
287 |
capela |
1509 |
|
288 |
schoenebeck |
1486 |
//------------------------------------------------------------------------- |
289 |
capela |
1558 |
// QSampler::DeviceParamModel - data model for device parameters |
290 |
|
|
// (used for QTableView) |
291 |
schoenebeck |
1461 |
|
292 |
capela |
1509 |
class DeviceParamModel : public AbstractDeviceParamModel |
293 |
|
|
{ |
294 |
|
|
Q_OBJECT |
295 |
schoenebeck |
1461 |
|
296 |
capela |
1509 |
public: |
297 |
schoenebeck |
1461 |
|
298 |
capela |
1509 |
DeviceParamModel(QObject *pParent = NULL); |
299 |
|
|
|
300 |
|
|
// Overridden methods from subclass(es) |
301 |
|
|
QVariant data(const QModelIndex &index, int role) const; |
302 |
|
|
bool setData(const QModelIndex& index, |
303 |
|
|
const QVariant& value, int role = Qt::EditRole); |
304 |
|
|
|
305 |
|
|
void clear(); |
306 |
|
|
|
307 |
|
|
public slots: |
308 |
|
|
|
309 |
capela |
1558 |
void refresh(Device* pDevice, bool bEditable); |
310 |
capela |
1509 |
|
311 |
|
|
private: |
312 |
|
|
|
313 |
capela |
1558 |
Device *m_pDevice; |
314 |
schoenebeck |
1461 |
}; |
315 |
|
|
|
316 |
capela |
1509 |
|
317 |
capela |
442 |
//------------------------------------------------------------------------- |
318 |
capela |
1558 |
// QSampler::PortParamModel - data model for port parameters |
319 |
|
|
// (used for QTableView) |
320 |
capela |
442 |
|
321 |
capela |
1509 |
class PortParamModel : public AbstractDeviceParamModel |
322 |
|
|
{ |
323 |
|
|
Q_OBJECT |
324 |
capela |
442 |
|
325 |
capela |
1509 |
public: |
326 |
capela |
442 |
|
327 |
capela |
1509 |
PortParamModel(QObject *pParent = 0); |
328 |
|
|
|
329 |
|
|
// overridden methods from subclass(es) |
330 |
|
|
QVariant data(const QModelIndex &index, int role) const; |
331 |
|
|
bool setData(const QModelIndex& index, |
332 |
|
|
const QVariant& value, int role = Qt::EditRole); |
333 |
|
|
|
334 |
|
|
void clear(); |
335 |
|
|
|
336 |
|
|
public slots: |
337 |
|
|
|
338 |
capela |
1558 |
void refresh(DevicePort* pPort, bool bEditable); |
339 |
capela |
1509 |
|
340 |
|
|
private: |
341 |
|
|
|
342 |
capela |
1558 |
DevicePort* m_pPort; |
343 |
capela |
442 |
}; |
344 |
|
|
|
345 |
capela |
1509 |
|
346 |
capela |
442 |
//------------------------------------------------------------------------- |
347 |
capela |
1558 |
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
348 |
capela |
442 |
// |
349 |
capela |
1558 |
|
350 |
capela |
1509 |
class DeviceParamDelegate : public QItemDelegate |
351 |
|
|
{ |
352 |
|
|
Q_OBJECT |
353 |
|
|
|
354 |
|
|
public: |
355 |
|
|
|
356 |
|
|
DeviceParamDelegate(QObject *pParent = NULL); |
357 |
|
|
|
358 |
|
|
QWidget* createEditor(QWidget *pParent, |
359 |
|
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
360 |
|
|
void setEditorData(QWidget *pEditor, const QModelIndex& index) const; |
361 |
capela |
1510 |
void setModelData(QWidget *pEditor, QAbstractItemModel *pModel, |
362 |
capela |
1509 |
const QModelIndex& index) const; |
363 |
|
|
void updateEditorGeometry(QWidget* pEditor, |
364 |
|
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
365 |
capela |
442 |
}; |
366 |
|
|
|
367 |
capela |
1558 |
} // namespace QSampler |
368 |
|
|
|
369 |
|
|
// so we can use it i.e. through QVariant |
370 |
|
|
Q_DECLARE_METATYPE(QSampler::DeviceParameterRow) |
371 |
|
|
|
372 |
capela |
426 |
#endif // __qsamplerDevice_h |
373 |
|
|
|
374 |
capela |
1558 |
|
375 |
capela |
426 |
// end of qsamplerDevice.h |