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> |
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 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
100 |
enum qsamplerDeviceType { None, Midi, Audio }; |
enum qsamplerDeviceType { None, Midi, Audio }; |
101 |
|
|
102 |
// Constructor. |
// Constructor. |
103 |
qsamplerDevice(qsamplerMainForm *pMainForm, |
qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
|
qsamplerDeviceType deviceType, int iDeviceID = -1); |
|
104 |
// Copy constructor. |
// Copy constructor. |
105 |
qsamplerDevice(const qsamplerDevice& device); |
qsamplerDevice(const qsamplerDevice& device); |
106 |
// Default destructor. |
// Default destructor. |
112 |
// Driver name initializer. |
// Driver name initializer. |
113 |
void setDriver(const QString& sDriverName); |
void setDriver(const QString& sDriverName); |
114 |
|
|
|
// LSCP client descriptor accessor. |
|
|
lscp_client_t *client() const; |
|
|
|
|
115 |
// Device property accessors. |
// Device property accessors. |
116 |
int deviceID() const; |
int deviceID() const; |
117 |
qsamplerDeviceType deviceType() const; |
qsamplerDeviceType deviceType() const; |
172 |
|
|
173 |
// Device parameter list. |
// Device parameter list. |
174 |
qsamplerDeviceParamMap m_params; |
qsamplerDeviceParamMap m_params; |
175 |
|
|
176 |
// Device port/channel list. |
// Device port/channel list. |
177 |
qsamplerDevicePortList m_ports; |
qsamplerDevicePortList m_ports; |
178 |
}; |
}; |
208 |
|
|
209 |
// Device reference. |
// Device reference. |
210 |
qsamplerDevice& m_device; |
qsamplerDevice& m_device; |
211 |
|
|
212 |
// Instance variables. |
// Instance variables. |
213 |
int m_iPortID; |
int m_iPortID; |
214 |
QString m_sPortName; |
QString m_sPortName; |
222 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QListView device item. |
223 |
// |
// |
224 |
|
|
225 |
class qsamplerDeviceItem : public QListViewItem |
class qsamplerDeviceItem : public QTreeWidgetItem |
226 |
{ |
{ |
227 |
public: |
public: |
228 |
|
|
229 |
// Constructors. |
// Constructors. |
230 |
qsamplerDeviceItem(QListView *pListView, qsamplerMainForm *pMainForm, |
qsamplerDeviceItem(QTreeWidget* pTreeWidget, |
231 |
qsamplerDevice::qsamplerDeviceType deviceType); |
qsamplerDevice::qsamplerDeviceType deviceType); |
232 |
qsamplerDeviceItem(QListViewItem *pItem, qsamplerMainForm *pMainForm, |
qsamplerDeviceItem(QTreeWidgetItem* pItem, |
233 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
234 |
// Default destructor. |
// Default destructor. |
235 |
~qsamplerDeviceItem(); |
~qsamplerDeviceItem(); |
237 |
// Instance accessors. |
// Instance accessors. |
238 |
qsamplerDevice& device(); |
qsamplerDevice& device(); |
239 |
|
|
|
// To virtually distinguish between list view items. |
|
|
virtual int rtti() const; |
|
|
|
|
240 |
private: |
private: |
241 |
|
|
242 |
// Instance variables. |
// Instance variables. |
243 |
qsamplerDevice m_device; |
qsamplerDevice m_device; |
244 |
}; |
}; |
245 |
|
|
246 |
|
struct DeviceParameterRow { |
247 |
|
QString name; |
248 |
|
qsamplerDeviceParam param; |
249 |
|
bool alive; // whether these params refer to an existing device or for a device that is yet to be created |
250 |
|
}; |
251 |
|
|
252 |
|
// so we can use it i.e. through QVariant |
253 |
|
Q_DECLARE_METATYPE(DeviceParameterRow) |
254 |
|
|
255 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
256 |
// qsamplerDeviceParamTable - Device parameter view table. |
// AbstractDeviceParamModel - data model base class for device parameters |
257 |
// |
// |
258 |
|
class AbstractDeviceParamModel : public QAbstractTableModel { |
259 |
class qsamplerDeviceParamTable : public QTable |
Q_OBJECT |
260 |
{ |
public: |
261 |
Q_OBJECT |
AbstractDeviceParamModel(QObject* parent = 0); |
262 |
|
|
263 |
public: |
// overridden methods from subclass(es) |
264 |
|
int rowCount(const QModelIndex& parent = QModelIndex()) const; |
265 |
// Constructor. |
int columnCount(const QModelIndex& parent = QModelIndex() ) const; |
266 |
qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0); |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
267 |
// Default destructor. |
Qt::ItemFlags flags(const QModelIndex& index) const; |
268 |
~qsamplerDeviceParamTable(); |
|
269 |
|
virtual void clear(); |
270 |
// Common parameter table renderer. |
|
271 |
void refresh(const qsamplerDeviceParamMap& params, bool bEditable); |
void refresh(const qsamplerDeviceParamMap* params, bool bEditable); |
272 |
|
|
273 |
|
protected: |
274 |
|
const qsamplerDeviceParamMap* params; |
275 |
|
bool bEditable; |
276 |
}; |
}; |
277 |
|
|
|
|
|
278 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
279 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// DeviceParamModel - data model for device parameters (used for QTableView) |
280 |
// |
// |
281 |
|
class DeviceParamModel : public AbstractDeviceParamModel { |
282 |
|
Q_OBJECT |
283 |
|
public: |
284 |
|
DeviceParamModel(QObject* parent = 0); |
285 |
|
|
286 |
|
// overridden methods from subclass(es) |
287 |
|
QVariant data(const QModelIndex &index, int role) const; |
288 |
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
289 |
|
void clear(); |
290 |
|
|
291 |
class qsamplerDeviceParamTableSpinBox : public QTableItem |
public slots: |
292 |
{ |
void refresh(qsamplerDevice* pDevice, bool bEditable); |
|
public: |
|
|
|
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType, |
|
|
const QString& sText); |
|
|
|
|
|
// Public accessors. |
|
|
void setMinValue(int iMinValue); |
|
|
void setMaxValue(int iMaxValue); |
|
|
void setValue(int iValue); |
|
|
|
|
|
protected: |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *createEditor() const; |
|
|
void setContentFromEditor(QWidget *pWidget); |
|
293 |
|
|
294 |
private: |
private: |
295 |
|
qsamplerDevice* device; |
|
// Initial value holders. |
|
|
int m_iValue; |
|
|
int m_iMinValue; |
|
|
int m_iMaxValue; |
|
296 |
}; |
}; |
297 |
|
|
|
|
|
298 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
299 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// PortParamModel - data model for port parameters (used for QTableView) |
300 |
// |
// |
301 |
|
class PortParamModel : public AbstractDeviceParamModel { |
302 |
|
Q_OBJECT |
303 |
|
public: |
304 |
|
PortParamModel(QObject* parent = 0); |
305 |
|
|
306 |
|
// overridden methods from subclass(es) |
307 |
|
QVariant data(const QModelIndex &index, int role) const; |
308 |
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
309 |
|
void clear(); |
310 |
|
|
311 |
class qsamplerDeviceParamTableEditBox : public QTableItem |
public slots: |
312 |
{ |
void refresh(qsamplerDevicePort* pPort, bool bEditable); |
|
public: |
|
|
|
|
|
// Constructor. |
|
|
qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType, |
|
|
const QString& sText); |
|
|
|
|
|
protected: |
|
313 |
|
|
314 |
// Virtual implemetations. |
private: |
315 |
QWidget *createEditor() const; |
qsamplerDevicePort* port; |
|
void setContentFromEditor(QWidget *pWidget); |
|
316 |
}; |
}; |
317 |
|
|
318 |
|
//------------------------------------------------------------------------- |
319 |
|
// DeviceParamDelegate - table cell renderer for device/port parameters |
320 |
|
// |
321 |
|
class DeviceParamDelegate : public QItemDelegate { |
322 |
|
Q_OBJECT |
323 |
|
public: |
324 |
|
DeviceParamDelegate(QObject* parent = 0); |
325 |
|
QWidget* createEditor(QWidget* parent, |
326 |
|
const QStyleOptionViewItem& option, |
327 |
|
const QModelIndex& index) const; |
328 |
|
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
329 |
|
void setModelData(QWidget* editor, QAbstractItemModel* model, |
330 |
|
const QModelIndex& index) const; |
331 |
|
void updateEditorGeometry(QWidget* editor, |
332 |
|
const QStyleOptionViewItem& option, |
333 |
|
const QModelIndex& index) const; |
334 |
|
}; |
335 |
|
|
336 |
#endif // __qsamplerDevice_h |
#endif // __qsamplerDevice_h |
337 |
|
|
|
|
|
338 |
// end of qsamplerDevice.h |
// end of qsamplerDevice.h |