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