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