29 |
#include <QTableWidget> |
#include <QTableWidget> |
30 |
#include <QTableWidgetItem> |
#include <QTableWidgetItem> |
31 |
#include <QAbstractTableModel> |
#include <QAbstractTableModel> |
|
#include <QMetaType> |
|
32 |
#include <QItemDelegate> |
#include <QItemDelegate> |
33 |
#include <QFontMetrics> |
#include <QFontMetrics> |
34 |
#include <QModelIndex> |
#include <QModelIndex> |
35 |
#include <QSize> |
#include <QSize> |
36 |
#include <QList> |
#include <QList> |
|
#include <Q3PtrList> |
|
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 |
|
|
|
// Early forward declarations. |
|
|
class qsamplerMainForm; |
|
|
class qsamplerDevicePort; |
|
|
|
|
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, |
82 |
}; |
}; |
83 |
|
|
84 |
// 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 QptrList. |
// Typedef'd device port/channels QList. |
88 |
typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList; |
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(qsamplerDeviceType deviceType, int iDeviceID = -1); |
Device(DeviceType deviceType, int iDeviceID = -1); |
104 |
// Copy constructor. |
// Copy constructor. |
105 |
qsamplerDevice(const qsamplerDevice& device); |
Device(const Device& device); |
106 |
|
|
107 |
// Default destructor. |
// Default destructor. |
108 |
~qsamplerDevice(); |
~Device(); |
109 |
|
|
110 |
// Initializer. |
// Initializer. |
111 |
void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
void setDevice(DeviceType deviceType, int iDeviceID = -1); |
112 |
|
|
113 |
// Driver name initializer. |
// Driver name initializer. |
114 |
void setDriver(const QString& sDriverName); |
void setDriver(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 |
|
|
122 |
// Special device name formatter. |
// Special device name formatter. |
123 |
QString deviceName() const; |
QString deviceName() const; |
124 |
|
|
126 |
bool setParam (const QString& sParam, const QString& sValue); |
bool setParam (const QString& sParam, const QString& sValue); |
127 |
|
|
128 |
// Device parameters accessor. |
// Device parameters accessor. |
129 |
const qsamplerDeviceParamMap& params() const; |
const DeviceParamMap& params() const; |
130 |
|
|
131 |
// Device port/channel list accessor. |
// Device port/channel list accessor. |
132 |
qsamplerDevicePortList& ports(); |
DevicePortList& ports(); |
133 |
|
|
134 |
// Device parameter dependency list refreshner. |
// Device parameter dependency list refreshner. |
135 |
int refreshParams(); |
int refreshParams(); |
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. |
// Refresh/set given parameter based on driver supplied dependencies. |
163 |
int refreshParam(const QString& sParam); |
int refreshParam(const QString& sParam); |
164 |
|
|
|
// Main application form reference. |
|
|
qsamplerMainForm *m_pMainForm; |
|
|
|
|
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. |
// Device port/channel list. |
176 |
qsamplerDevicePortList m_ports; |
DevicePortList m_ports; |
177 |
}; |
}; |
178 |
|
|
179 |
|
|
180 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
181 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
182 |
// |
// |
183 |
|
|
184 |
class qsamplerDevicePort |
class DevicePort |
185 |
{ |
{ |
186 |
public: |
public: |
187 |
|
|
188 |
// Constructor. |
// Constructor. |
189 |
qsamplerDevicePort(qsamplerDevice& device, int iPortID); |
DevicePort(Device& device, int iPortID); |
190 |
// Default destructor. |
// Default destructor. |
191 |
~qsamplerDevicePort(); |
~DevicePort(); |
192 |
|
|
193 |
// Initializer. |
// Initializer. |
194 |
void setDevicePort(int iPortID); |
void setDevicePort(int iPortID); |
198 |
const QString& portName() const; |
const QString& portName() const; |
199 |
|
|
200 |
// Device port parameters accessor. |
// Device port parameters accessor. |
201 |
const qsamplerDeviceParamMap& params() const; |
const DeviceParamMap& params() const; |
202 |
|
|
203 |
// Set the proper device port/channel parameter value. |
// Set the proper device port/channel parameter value. |
204 |
bool setParam (const QString& sParam, const QString& sValue); |
bool setParam (const QString& sParam, const QString& sValue); |
206 |
private: |
private: |
207 |
|
|
208 |
// Device reference. |
// Device reference. |
209 |
qsamplerDevice& m_device; |
Device& m_device; |
210 |
|
|
211 |
// Instance variables. |
// Instance variables. |
212 |
int m_iPortID; |
int m_iPortID; |
213 |
QString m_sPortName; |
QString m_sPortName; |
214 |
|
|
215 |
// Device port parameter list. |
// Device port parameter list. |
216 |
qsamplerDeviceParamMap m_params; |
DeviceParamMap m_params; |
217 |
}; |
}; |
218 |
|
|
219 |
|
|
220 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
221 |
// qsamplerDeviceItem - QListView device item. |
// QSampler::DeviceItem - QTreeWidget device item. |
222 |
// |
// |
223 |
|
|
224 |
class qsamplerDeviceItem : public QTreeWidgetItem |
class DeviceItem : public QTreeWidgetItem |
225 |
{ |
{ |
226 |
public: |
public: |
227 |
|
|
228 |
// Constructors. |
// Constructors. |
229 |
qsamplerDeviceItem(QTreeWidget* pTreeWidget, |
DeviceItem(QTreeWidget *pTreeWidget, |
230 |
qsamplerDevice::qsamplerDeviceType deviceType); |
Device::DeviceType deviceType); |
231 |
qsamplerDeviceItem(QTreeWidgetItem* pItem, |
DeviceItem(QTreeWidgetItem *pItem, |
232 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
Device::DeviceType deviceType, int iDeviceID); |
233 |
|
|
234 |
// Default destructor. |
// Default destructor. |
235 |
~qsamplerDeviceItem(); |
~DeviceItem(); |
236 |
|
|
237 |
// Instance accessors. |
// Instance accessors. |
238 |
qsamplerDevice& device(); |
Device& device(); |
239 |
|
|
240 |
private: |
private: |
241 |
|
|
242 |
// Instance variables. |
// Instance variables. |
243 |
qsamplerDevice m_device; |
Device m_device; |
244 |
}; |
}; |
245 |
|
|
246 |
|
|
247 |
struct DeviceParameterRow { |
struct DeviceParameterRow { |
248 |
QString name; |
QString name; |
249 |
qsamplerDeviceParam param; |
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 |
|
|
|
// so we can use it i.e. through QVariant |
|
|
Q_DECLARE_METATYPE(DeviceParameterRow) |
|
254 |
|
|
255 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
256 |
// AbstractDeviceParamModel - data model base class for device parameters |
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
257 |
// |
// |
258 |
class AbstractDeviceParamModel : public QAbstractTableModel { |
|
259 |
Q_OBJECT |
class AbstractDeviceParamModel : public QAbstractTableModel |
260 |
public: |
{ |
261 |
AbstractDeviceParamModel(QObject* parent = 0); |
Q_OBJECT |
262 |
|
|
263 |
// overridden methods from subclass(es) |
public: |
264 |
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
|
265 |
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
AbstractDeviceParamModel(QObject *pParent = NULL); |
266 |
QVariant data(const QModelIndex &index, int role) const; |
|
267 |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
// Overridden methods from subclass(es) |
268 |
Qt::ItemFlags flags(const QModelIndex& index) const; |
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
269 |
|
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
270 |
virtual void clear(); |
QVariant headerData(int section, |
271 |
|
Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
272 |
void refresh(const qsamplerDeviceParamMap* params, bool bEditable); |
Qt::ItemFlags flags(const QModelIndex& index) const; |
273 |
|
|
274 |
protected: |
virtual void clear(); |
275 |
const qsamplerDeviceParamMap* params; |
|
276 |
bool bEditable; |
void refresh(const DeviceParamMap* params, bool bEditable); |
277 |
|
|
278 |
|
protected: |
279 |
|
|
280 |
|
const DeviceParamMap *m_pParams; |
281 |
|
bool m_bEditable; |
282 |
}; |
}; |
283 |
|
|
284 |
|
|
285 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
286 |
// DeviceParamModel - data model for device parameters (used for QTableView) |
// QSampler::DeviceParamModel - data model for device parameters |
287 |
// |
// (used for QTableView) |
288 |
class DeviceParamModel : public AbstractDeviceParamModel { |
|
289 |
Q_OBJECT |
class DeviceParamModel : public AbstractDeviceParamModel |
290 |
public: |
{ |
291 |
DeviceParamModel(QObject* parent = 0); |
Q_OBJECT |
292 |
|
|
293 |
// overridden methods from subclass(es) |
public: |
294 |
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
|
295 |
void clear(); |
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 |
public slots: |
void clear(); |
|
void refresh(qsamplerDevice* pDevice, bool bEditable); |
|
303 |
|
|
304 |
private: |
public slots: |
305 |
qsamplerDevice* device; |
|
306 |
|
void refresh(Device* pDevice, bool bEditable); |
307 |
|
|
308 |
|
private: |
309 |
|
|
310 |
|
Device *m_pDevice; |
311 |
}; |
}; |
312 |
|
|
313 |
|
|
314 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
315 |
// PortParamModel - data model for port parameters (used for QTableView) |
// QSampler::PortParamModel - data model for port parameters |
316 |
// |
// (used for QTableView) |
317 |
class PortParamModel : public AbstractDeviceParamModel { |
|
318 |
Q_OBJECT |
class PortParamModel : public AbstractDeviceParamModel |
319 |
public: |
{ |
320 |
PortParamModel(QObject* parent = 0); |
Q_OBJECT |
321 |
|
|
322 |
// overridden methods from subclass(es) |
public: |
323 |
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
|
324 |
void clear(); |
PortParamModel(QObject *pParent = 0); |
325 |
|
|
326 |
|
// 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 |
|
void clear(); |
332 |
|
|
333 |
|
public slots: |
334 |
|
|
335 |
public slots: |
void refresh(DevicePort* pPort, bool bEditable); |
|
void refresh(qsamplerDevicePort* pPort, bool bEditable); |
|
336 |
|
|
337 |
private: |
private: |
338 |
qsamplerDevicePort* port; |
|
339 |
|
DevicePort* m_pPort; |
340 |
}; |
}; |
341 |
|
|
342 |
|
|
343 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
344 |
// DeviceParamDelegate - table cell renderer for device/port parameters |
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
345 |
// |
// |
346 |
class DeviceParamDelegate : public QItemDelegate { |
|
347 |
Q_OBJECT |
class DeviceParamDelegate : public QItemDelegate |
348 |
public: |
{ |
349 |
DeviceParamDelegate(QObject* parent = 0); |
Q_OBJECT |
350 |
QWidget* createEditor(QWidget* parent, |
|
351 |
const QStyleOptionViewItem& option, |
public: |
352 |
const QModelIndex& index) const; |
|
353 |
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
DeviceParamDelegate(QObject *pParent = NULL); |
354 |
void setModelData(QWidget* editor, QAbstractItemModel* model, |
|
355 |
const QModelIndex& index) const; |
QWidget* createEditor(QWidget *pParent, |
356 |
void updateEditorGeometry(QWidget* editor, |
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
357 |
const QStyleOptionViewItem& option, |
void setEditorData(QWidget *pEditor, const QModelIndex& index) const; |
358 |
const QModelIndex& index) const; |
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 |
|
|
371 |
|
|
372 |
// end of qsamplerDevice.h |
// end of qsamplerDevice.h |