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 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
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 |
17 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
|
20 |
*****************************************************************************/ |
*****************************************************************************/ |
21 |
|
|
22 |
#ifndef __qsamplerDevice_h |
#ifndef __qsamplerDevice_h |
23 |
#define __qsamplerDevice_h |
#define __qsamplerDevice_h |
24 |
|
|
25 |
#include <qlistview.h> |
#include <QListWidget> |
26 |
#include <qtable.h> |
#include <QListWidgetItem> |
27 |
|
#include <QTreeWidgetItem> |
28 |
|
#include <QTableWidget> |
29 |
|
#include <QTableWidgetItem> |
30 |
|
#include <QAbstractTableModel> |
31 |
|
#include <QMetaType> |
32 |
|
#include <QItemDelegate> |
33 |
|
#include <QFontMetrics> |
34 |
|
#include <QModelIndex> |
35 |
|
#include <QSize> |
36 |
|
#include <QList> |
37 |
|
#include <Q3PtrList> |
38 |
|
|
39 |
#include <lscp/client.h> |
#include <lscp/client.h> |
40 |
#include <lscp/device.h> |
#include <lscp/device.h> |
45 |
// Special QListViewItem::rtti() unique return value. |
// Special QListViewItem::rtti() unique return value. |
46 |
#define QSAMPLER_DEVICE_ITEM 1001 |
#define QSAMPLER_DEVICE_ITEM 1001 |
47 |
|
|
48 |
|
// Early forward declarations. |
49 |
|
class qsamplerMainForm; |
50 |
|
class qsamplerDevicePort; |
51 |
|
|
52 |
|
|
53 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
54 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
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, qsamplerDeviceParam> qsamplerDeviceParamMap; |
87 |
|
|
88 |
|
// Typedef'd device port/channels QptrList. |
89 |
|
typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList; |
90 |
|
|
91 |
|
|
92 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
93 |
// qsamplerDevice - MIDI/Audio Device structure. |
// qsamplerDevice - MIDI/Audio Device structure. |
101 |
enum qsamplerDeviceType { None, Midi, Audio }; |
enum qsamplerDeviceType { None, Midi, Audio }; |
102 |
|
|
103 |
// Constructor. |
// Constructor. |
104 |
qsamplerDevice(lscp_client_t *pClient, |
qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); |
105 |
qsamplerDeviceType deviceType, int iDeviceID = -1); |
// Copy constructor. |
106 |
|
qsamplerDevice(const qsamplerDevice& device); |
107 |
// Default destructor. |
// Default destructor. |
108 |
~qsamplerDevice(); |
~qsamplerDevice(); |
109 |
|
|
110 |
// Initializer. |
// Initializer. |
111 |
void setDevice(lscp_client_t *pClient, |
void setDevice(qsamplerDeviceType 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; |
qsamplerDeviceType 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; |
// Special device name formatter. |
122 |
|
QString deviceName() const; |
123 |
|
|
124 |
|
// Set the proper device parameter value. |
125 |
|
bool setParam (const QString& sParam, const QString& sValue); |
126 |
|
|
127 |
// Device parameters accessor. |
// Device parameters accessor. |
128 |
qsamplerDeviceParamMap& params(); |
const qsamplerDeviceParamMap& params() const; |
129 |
|
|
130 |
// Update/refresh device/driver data. |
// Device port/channel list accessor. |
131 |
void refresh(); |
qsamplerDevicePortList& ports(); |
132 |
|
|
133 |
|
// Device parameter dependency list refreshner. |
134 |
|
int refreshParams(); |
135 |
|
// Device port/channel list refreshner. |
136 |
|
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, |
158 |
|
|
159 |
private: |
private: |
160 |
|
|
161 |
|
// Refresh/set given parameter based on driver supplied dependencies. |
162 |
|
int refreshParam(const QString& sParam); |
163 |
|
|
164 |
|
// Main application form reference. |
165 |
|
qsamplerMainForm *m_pMainForm; |
166 |
|
|
167 |
// Instance variables. |
// Instance variables. |
168 |
int m_iDeviceID; |
int m_iDeviceID; |
169 |
qsamplerDeviceType m_deviceType; |
qsamplerDeviceType m_deviceType; |
173 |
|
|
174 |
// Device parameter list. |
// Device parameter list. |
175 |
qsamplerDeviceParamMap m_params; |
qsamplerDeviceParamMap m_params; |
176 |
|
|
177 |
|
// Device port/channel list. |
178 |
|
qsamplerDevicePortList m_ports; |
179 |
|
}; |
180 |
|
|
181 |
|
|
182 |
|
//------------------------------------------------------------------------- |
183 |
|
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
184 |
|
// |
185 |
|
|
186 |
|
class qsamplerDevicePort |
187 |
|
{ |
188 |
|
public: |
189 |
|
|
190 |
|
// Constructor. |
191 |
|
qsamplerDevicePort(qsamplerDevice& device, int iPortID); |
192 |
|
// Default destructor. |
193 |
|
~qsamplerDevicePort(); |
194 |
|
|
195 |
|
// Initializer. |
196 |
|
void setDevicePort(int iPortID); |
197 |
|
|
198 |
|
// Device port property accessors. |
199 |
|
int portID() const; |
200 |
|
const QString& portName() const; |
201 |
|
|
202 |
|
// Device port parameters accessor. |
203 |
|
const qsamplerDeviceParamMap& params() const; |
204 |
|
|
205 |
|
// Set the proper device port/channel parameter value. |
206 |
|
bool setParam (const QString& sParam, const QString& sValue); |
207 |
|
|
208 |
|
private: |
209 |
|
|
210 |
|
// Device reference. |
211 |
|
qsamplerDevice& m_device; |
212 |
|
|
213 |
|
// Instance variables. |
214 |
|
int m_iPortID; |
215 |
|
QString m_sPortName; |
216 |
|
|
217 |
|
// Device port parameter list. |
218 |
|
qsamplerDeviceParamMap m_params; |
219 |
}; |
}; |
220 |
|
|
221 |
|
|
223 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QListView device item. |
224 |
// |
// |
225 |
|
|
226 |
class qsamplerDeviceItem : public QListViewItem |
class qsamplerDeviceItem : public QTreeWidgetItem |
227 |
{ |
{ |
228 |
public: |
public: |
229 |
|
|
230 |
// Constructors. |
// Constructors. |
231 |
qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient, |
qsamplerDeviceItem(QTreeWidget* pTreeWidget, |
232 |
qsamplerDevice::qsamplerDeviceType deviceType); |
qsamplerDevice::qsamplerDeviceType deviceType); |
233 |
qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient, |
qsamplerDeviceItem(QTreeWidgetItem* pItem, |
234 |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); |
235 |
// Default destructor. |
// Default destructor. |
236 |
~qsamplerDeviceItem(); |
~qsamplerDeviceItem(); |
238 |
// Instance accessors. |
// Instance accessors. |
239 |
qsamplerDevice& device(); |
qsamplerDevice& device(); |
240 |
|
|
|
// To virtually distinguish between list view items. |
|
|
virtual int rtti() const; |
|
|
|
|
241 |
private: |
private: |
242 |
|
|
243 |
// Instance variables. |
// Instance variables. |
249 |
// qsamplerDeviceParamTable - Device parameter view table. |
// qsamplerDeviceParamTable - Device parameter view table. |
250 |
// |
// |
251 |
|
|
252 |
|
#if 0 |
253 |
class qsamplerDeviceParamTable : public QTable |
class qsamplerDeviceParamTable : public QTable |
254 |
{ |
{ |
255 |
Q_OBJECT |
Q_OBJECT |
261 |
// Default destructor. |
// Default destructor. |
262 |
~qsamplerDeviceParamTable(); |
~qsamplerDeviceParamTable(); |
263 |
|
|
264 |
// Client/device descriptor selector. |
// Common parameter table renderer. |
265 |
void refresh(qsamplerDevice& device); |
void refresh(const qsamplerDeviceParamMap& params, bool bEditable); |
266 |
|
}; |
267 |
|
#endif |
268 |
|
|
269 |
|
struct DeviceParameterRow { |
270 |
|
QString name; |
271 |
|
qsamplerDeviceParam param; |
272 |
|
}; |
273 |
|
|
274 |
|
// so we can use it i.e. through QVariant |
275 |
|
Q_DECLARE_METATYPE(DeviceParameterRow) |
276 |
|
|
277 |
|
class DeviceParamModel : public QAbstractTableModel { |
278 |
|
Q_OBJECT |
279 |
|
public: |
280 |
|
DeviceParamModel(QObject* parent = 0); |
281 |
|
|
282 |
|
// overridden methods from subclass(es) |
283 |
|
int rowCount(const QModelIndex &parent) const; |
284 |
|
int columnCount(const QModelIndex &parent) const; |
285 |
|
QVariant data(const QModelIndex &index, int role) const; |
286 |
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
287 |
|
|
288 |
|
void clear(); |
289 |
|
|
290 |
|
public slots: |
291 |
|
void refresh(const qsamplerDeviceParamMap& params, bool bEditable); |
292 |
|
|
293 |
|
private: |
294 |
|
qsamplerDeviceParamMap params; |
295 |
|
bool bEditable; |
296 |
|
}; |
297 |
|
|
298 |
|
class DeviceParamDelegate : public QItemDelegate { |
299 |
|
Q_OBJECT |
300 |
|
public: |
301 |
|
DeviceParamDelegate(QObject* parent = 0); |
302 |
|
|
303 |
|
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, |
304 |
|
const QModelIndex& index) const; |
305 |
|
|
306 |
|
void setEditorData(QWidget* editor, const QModelIndex& index) const; |
307 |
|
void setModelData(QWidget* editor, QAbstractItemModel* model, |
308 |
|
const QModelIndex& index) const; |
309 |
|
|
310 |
|
void updateEditorGeometry(QWidget* editor, |
311 |
|
const QStyleOptionViewItem& option, const QModelIndex& index) const; |
312 |
}; |
}; |
313 |
|
|
314 |
|
|
316 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
317 |
// |
// |
318 |
|
|
319 |
class qsamplerDeviceParamTableSpinBox : public QTableItem |
#if 0 |
320 |
|
class qsamplerDeviceParamTableSpinBox : public QTableWidgetItem |
321 |
{ |
{ |
322 |
public: |
public: |
323 |
|
|
324 |
// Constructor. |
// Constructor. |
325 |
qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType); |
qsamplerDeviceParamTableSpinBox (QTableWidget *pTable, Qt::ItemFlags flags, |
326 |
|
const QString& sText); |
327 |
|
|
328 |
// Public accessors. |
// Public accessors. |
329 |
void setMinValue(int iMinValue); |
void setMinValue(int iMinValue); |
339 |
private: |
private: |
340 |
|
|
341 |
// Initial value holders. |
// Initial value holders. |
342 |
|
int m_iValue; |
343 |
int m_iMinValue; |
int m_iMinValue; |
344 |
int m_iMaxValue; |
int m_iMaxValue; |
|
int m_iValue; |
|
345 |
}; |
}; |
346 |
|
|
347 |
|
|
349 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
350 |
// |
// |
351 |
|
|
352 |
class qsamplerDeviceParamTableEditBox : public QTableItem |
class qsamplerDeviceParamTableEditBox : public QTableWidgetItem |
353 |
{ |
{ |
354 |
public: |
public: |
355 |
|
|
356 |
// Constructor. |
// Constructor. |
357 |
qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType, |
qsamplerDeviceParamTableEditBox (QTableWidget *pTable, Qt::ItemFlags flags, |
358 |
const QString& sText); |
const QString& sText); |
359 |
|
|
360 |
protected: |
protected: |
363 |
QWidget *createEditor() const; |
QWidget *createEditor() const; |
364 |
void setContentFromEditor(QWidget *pWidget); |
void setContentFromEditor(QWidget *pWidget); |
365 |
}; |
}; |
366 |
|
#endif |
367 |
|
|
368 |
#endif // __qsamplerDevice_h |
#endif // __qsamplerDevice_h |
369 |
|
|