1 |
// qsamplerDevice.h |
// qsamplerDevice.h |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 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 <qlistview.h> |
#include <QListWidget> |
27 |
#include <qtable.h> |
#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> |
40 |
|
|
41 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
42 |
|
|
43 |
|
namespace QSampler { |
44 |
|
|
45 |
|
class DevicePort; |
46 |
|
|
47 |
// Special QListViewItem::rtti() unique return value. |
// Special QListViewItem::rtti() unique return value. |
48 |
#define QSAMPLER_DEVICE_ITEM 1001 |
#define QSAMPLER_DEVICE_ITEM 1001 |
49 |
|
|
50 |
|
|
51 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
52 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// QSampler::DeviceParam - MIDI/Audio Device parameter structure. |
53 |
// |
// |
54 |
class qsamplerDeviceParam |
|
55 |
|
class DeviceParam |
56 |
{ |
{ |
57 |
public: |
public: |
58 |
|
|
59 |
// Constructor. |
// Constructor. |
60 |
qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL, |
DeviceParam(lscp_param_info_t *pParamInfo = NULL, |
61 |
const char *pszValue = NULL); |
const char *pszValue = NULL); |
62 |
// Default destructor. |
// Default destructor. |
63 |
~qsamplerDeviceParam(); |
~DeviceParam(); |
64 |
|
|
65 |
// Initializer. |
// Initializer. |
66 |
void setParam(lscp_param_info_t *pParamInfo, |
void setParam(lscp_param_info_t *pParamInfo, |
81 |
QString value; |
QString value; |
82 |
}; |
}; |
83 |
|
|
84 |
// A typedef'd parameter QMap. |
// Typedef'd parameter QMap. |
85 |
typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap; |
typedef QMap<QString, DeviceParam> DeviceParamMap; |
86 |
|
|
87 |
|
// Typedef'd device port/channels QList. |
88 |
|
typedef QList<DevicePort *> DevicePortList; |
89 |
|
|
90 |
|
|
91 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
92 |
// qsamplerDevice - MIDI/Audio Device structure. |
// QSampler::Device - MIDI/Audio Device structure. |
93 |
// |
// |
94 |
|
|
95 |
class qsamplerDevice |
class Device |
96 |
{ |
{ |
97 |
public: |
public: |
98 |
|
|
99 |
// We use the same class for MIDI and audio device management |
// We use the same class for MIDI and audio device management |
100 |
enum qsamplerDeviceType { None, Midi, Audio }; |
enum DeviceType { None, Midi, Audio }; |
101 |
|
|
102 |
// Constructor. |
// Constructor. |
103 |
qsamplerDevice(lscp_client_t *pClient, |
Device(DeviceType deviceType, int iDeviceID = -1); |
104 |
qsamplerDeviceType deviceType, int iDeviceID = -1); |
// Copy constructor. |
105 |
|
Device(const Device& device); |
106 |
|
|
107 |
// Default destructor. |
// Default destructor. |
108 |
~qsamplerDevice(); |
~Device(); |
109 |
|
|
110 |
// Initializer. |
// Initializer. |
111 |
void setDevice(lscp_client_t *pClient, |
void setDevice(DeviceType deviceType, int iDeviceID = -1); |
|
qsamplerDeviceType deviceType, int iDeviceID = -1); |
|
112 |
|
|
113 |
// Driver name initializer. |
// Driver name initializer. |
114 |
void setDriver(lscp_client_t *pClient, |
void setDriver(const QString& sDriverName); |
|
const QString& sDriverName); |
|
115 |
|
|
116 |
// Device property accessors. |
// Device property accessors. |
117 |
int deviceID() const; |
int deviceID() const; |
118 |
qsamplerDeviceType deviceType() const; |
DeviceType deviceType() const; |
119 |
const QString& deviceTypeName() const; |
const QString& deviceTypeName() const; |
120 |
const QString& driverName() const; |
const QString& driverName() const; |
121 |
const QString& deviceName() const; |
|
122 |
|
// Special device name formatter. |
123 |
|
QString deviceName() const; |
124 |
|
|
125 |
|
// Set the proper device parameter value. |
126 |
|
bool setParam (const QString& sParam, const QString& sValue); |
127 |
|
|
128 |
// Device parameters accessor. |
// Device parameters accessor. |
129 |
qsamplerDeviceParamMap& params(); |
const DeviceParamMap& params() const; |
130 |
|
|
131 |
|
// Device port/channel list accessor. |
132 |
|
DevicePortList& ports(); |
133 |
|
|
134 |
// Update/refresh device/driver data. |
// Device parameter dependency list refreshner. |
135 |
void refresh(); |
int refreshParams(); |
136 |
|
// Device port/channel list refreshner. |
137 |
|
int refreshPorts(); |
138 |
|
// Refresh/set dependencies given that some parameter has changed. |
139 |
|
int refreshDepends(const QString& sParam); |
140 |
|
|
141 |
|
// 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 |
// Device ids enumerator. |
// Device ids enumerator. |
153 |
static int *getDevices(lscp_client_t *pClient, |
static int *getDevices(lscp_client_t *pClient, |
154 |
qsamplerDeviceType deviceType); |
DeviceType deviceType); |
155 |
|
|
156 |
// Driver names enumerator. |
// Driver names enumerator. |
157 |
static QStringList getDrivers(lscp_client_t *pClient, |
static QStringList getDrivers(lscp_client_t *pClient, |
158 |
qsamplerDeviceType deviceType); |
DeviceType deviceType); |
159 |
|
|
160 |
private: |
private: |
161 |
|
|
162 |
|
// Refresh/set given parameter based on driver supplied dependencies. |
163 |
|
int refreshParam(const QString& sParam); |
164 |
|
|
165 |
// Instance variables. |
// Instance variables. |
166 |
int m_iDeviceID; |
int m_iDeviceID; |
167 |
qsamplerDeviceType m_deviceType; |
DeviceType m_deviceType; |
168 |
QString m_sDeviceType; |
QString m_sDeviceType; |
169 |
QString m_sDriverName; |
QString m_sDriverName; |
170 |
QString m_sDeviceName; |
QString m_sDeviceName; |
171 |
|
|
172 |
// Device parameter list. |
// Device parameter list. |
173 |
qsamplerDeviceParamMap m_params; |
DeviceParamMap m_params; |
174 |
|
|
175 |
|
// Device port/channel list. |
176 |
|
DevicePortList m_ports; |
177 |
}; |
}; |
178 |
|
|
179 |
|
|
180 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
181 |
// qsamplerDeviceItem - QListView device item. |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
182 |
// |
// |
183 |
|
|
184 |
class qsamplerDeviceItem : public QListViewItem |
class DevicePort |
185 |
{ |
{ |
186 |
public: |
public: |
187 |
|
|
188 |
// Constructors. |
// Constructor. |
189 |
qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient, |
DevicePort(Device& device, int iPortID); |
|
qsamplerDevice::qsamplerDeviceType deviceType); |
|
|
qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient, |
|
|
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
|
190 |
// Default destructor. |
// Default destructor. |
191 |
~qsamplerDeviceItem(); |
~DevicePort(); |
192 |
|
|
193 |
// Instance accessors. |
// Initializer. |
194 |
qsamplerDevice& device(); |
void setDevicePort(int iPortID); |
195 |
|
|
196 |
|
// Device port property accessors. |
197 |
|
int portID() const; |
198 |
|
const QString& portName() const; |
199 |
|
|
200 |
// To virtually distinguish between list view items. |
// Device port parameters accessor. |
201 |
virtual int rtti() const; |
const DeviceParamMap& params() const; |
202 |
|
|
203 |
|
// Set the proper device port/channel parameter value. |
204 |
|
bool setParam (const QString& sParam, const QString& sValue); |
205 |
|
|
206 |
private: |
private: |
207 |
|
|
208 |
|
// Device reference. |
209 |
|
Device& m_device; |
210 |
|
|
211 |
// Instance variables. |
// Instance variables. |
212 |
qsamplerDevice m_device; |
int m_iPortID; |
213 |
|
QString m_sPortName; |
214 |
|
|
215 |
|
// Device port parameter list. |
216 |
|
DeviceParamMap m_params; |
217 |
}; |
}; |
218 |
|
|
219 |
|
|
220 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
221 |
// qsamplerDeviceParamTable - Device parameter view table. |
// QSampler::DeviceItem - QTreeWidget device item. |
222 |
// |
// |
223 |
|
|
224 |
class qsamplerDeviceParamTable : public QTable |
class DeviceItem : public QTreeWidgetItem |
225 |
{ |
{ |
|
Q_OBJECT |
|
|
|
|
226 |
public: |
public: |
227 |
|
|
228 |
// Constructor. |
// Constructors. |
229 |
qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0); |
DeviceItem(QTreeWidget *pTreeWidget, |
230 |
|
Device::DeviceType deviceType); |
231 |
|
DeviceItem(QTreeWidgetItem *pItem, |
232 |
|
Device::DeviceType deviceType, int iDeviceID); |
233 |
|
|
234 |
// Default destructor. |
// Default destructor. |
235 |
~qsamplerDeviceParamTable(); |
~DeviceItem(); |
236 |
|
|
237 |
|
// Instance accessors. |
238 |
|
Device& device(); |
239 |
|
|
240 |
|
private: |
241 |
|
|
242 |
|
// Instance variables. |
243 |
|
Device m_device; |
244 |
|
}; |
245 |
|
|
246 |
|
|
247 |
// Client/device descriptor selector. |
struct DeviceParameterRow { |
248 |
void refresh(qsamplerDevice& device); |
QString name; |
249 |
|
DeviceParam param; |
250 |
|
bool alive; // whether these params refer to an existing device |
251 |
|
// or for a device that is yet to be created |
252 |
}; |
}; |
253 |
|
|
254 |
|
|
255 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
256 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
257 |
// |
// |
258 |
|
|
259 |
class qsamplerDeviceParamTableSpinBox : public QTableItem |
class AbstractDeviceParamModel : public QAbstractTableModel |
260 |
{ |
{ |
261 |
|
Q_OBJECT |
262 |
|
|
263 |
public: |
public: |
264 |
|
|
265 |
// Constructor. |
AbstractDeviceParamModel(QObject *pParent = NULL); |
266 |
qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType); |
|
267 |
|
// Overridden methods from subclass(es) |
268 |
|
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
269 |
|
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
270 |
|
QVariant headerData(int section, |
271 |
|
Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
272 |
|
Qt::ItemFlags flags(const QModelIndex& index) const; |
273 |
|
|
274 |
// Public accessors. |
virtual void clear(); |
275 |
void setMinValue(int iMinValue); |
|
276 |
void setMaxValue(int iMaxValue); |
void refresh(const DeviceParamMap* params, bool bEditable); |
|
void setValue(int iValue); |
|
277 |
|
|
278 |
protected: |
protected: |
279 |
|
|
280 |
// Virtual implemetations. |
const DeviceParamMap *m_pParams; |
281 |
QWidget *createEditor() const; |
bool m_bEditable; |
282 |
void setContentFromEditor(QWidget *pWidget); |
}; |
283 |
|
|
284 |
|
|
285 |
|
//------------------------------------------------------------------------- |
286 |
|
// QSampler::DeviceParamModel - data model for device parameters |
287 |
|
// (used for QTableView) |
288 |
|
|
289 |
|
class DeviceParamModel : public AbstractDeviceParamModel |
290 |
|
{ |
291 |
|
Q_OBJECT |
292 |
|
|
293 |
|
public: |
294 |
|
|
295 |
|
DeviceParamModel(QObject *pParent = NULL); |
296 |
|
|
297 |
|
// Overridden methods from subclass(es) |
298 |
|
QVariant data(const QModelIndex &index, int role) const; |
299 |
|
bool setData(const QModelIndex& index, |
300 |
|
const QVariant& value, int role = Qt::EditRole); |
301 |
|
|
302 |
|
void clear(); |
303 |
|
|
304 |
|
public slots: |
305 |
|
|
306 |
|
void refresh(Device* pDevice, bool bEditable); |
307 |
|
|
308 |
private: |
private: |
309 |
|
|
310 |
// Initial value holders. |
Device *m_pDevice; |
|
int m_iMinValue; |
|
|
int m_iMaxValue; |
|
|
int m_iValue; |
|
311 |
}; |
}; |
312 |
|
|
313 |
|
|
314 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
315 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// QSampler::PortParamModel - data model for port parameters |
316 |
// |
// (used for QTableView) |
317 |
|
|
318 |
class qsamplerDeviceParamTableEditBox : public QTableItem |
class PortParamModel : public AbstractDeviceParamModel |
319 |
{ |
{ |
320 |
|
Q_OBJECT |
321 |
|
|
322 |
public: |
public: |
323 |
|
|
324 |
// Constructor. |
PortParamModel(QObject *pParent = 0); |
|
qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType, |
|
|
const QString& sText); |
|
325 |
|
|
326 |
protected: |
// overridden methods from subclass(es) |
327 |
|
QVariant data(const QModelIndex &index, int role) const; |
328 |
|
bool setData(const QModelIndex& index, |
329 |
|
const QVariant& value, int role = Qt::EditRole); |
330 |
|
|
331 |
// Virtual implemetations. |
void clear(); |
332 |
QWidget *createEditor() const; |
|
333 |
void setContentFromEditor(QWidget *pWidget); |
public slots: |
334 |
|
|
335 |
|
void refresh(DevicePort* pPort, bool bEditable); |
336 |
|
|
337 |
|
private: |
338 |
|
|
339 |
|
DevicePort* m_pPort; |
340 |
|
}; |
341 |
|
|
342 |
|
|
343 |
|
//------------------------------------------------------------------------- |
344 |
|
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
345 |
|
// |
346 |
|
|
347 |
|
class DeviceParamDelegate : public QItemDelegate |
348 |
|
{ |
349 |
|
Q_OBJECT |
350 |
|
|
351 |
|
public: |
352 |
|
|
353 |
|
DeviceParamDelegate(QObject *pParent = NULL); |
354 |
|
|
355 |
|
QWidget* createEditor(QWidget *pParent, |
356 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
357 |
|
void setEditorData(QWidget *pEditor, const QModelIndex& index) const; |
358 |
|
void setModelData(QWidget *pEditor, QAbstractItemModel *pModel, |
359 |
|
const QModelIndex& index) const; |
360 |
|
void updateEditorGeometry(QWidget* pEditor, |
361 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
362 |
}; |
}; |
363 |
|
|
364 |
|
} // namespace QSampler |
365 |
|
|
366 |
|
// so we can use it i.e. through QVariant |
367 |
|
Q_DECLARE_METATYPE(QSampler::DeviceParameterRow) |
368 |
|
|
369 |
#endif // __qsamplerDevice_h |
#endif // __qsamplerDevice_h |
370 |
|
|