/[svn]/qsampler/trunk/src/qsamplerDevice.h
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerDevice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1510 - (show annotations) (download) (as text)
Thu Nov 22 14:17:24 2007 UTC (16 years, 5 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9384 byte(s)
- Qt4 migration: code cleanup, personal standards beautification :)

1 // qsamplerDevice.h
2 //
3 /****************************************************************************
4 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
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 *****************************************************************************/
22
23 #ifndef __qsamplerDevice_h
24 #define __qsamplerDevice_h
25
26 #include <QListWidget>
27 #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>
39 #include <lscp/device.h>
40
41 #include "qsamplerOptions.h"
42
43
44 // Special QListViewItem::rtti() unique return value.
45 #define QSAMPLER_DEVICE_ITEM 1001
46
47 // Early forward declarations.
48 class qsamplerMainForm;
49 class qsamplerDevicePort;
50
51
52 //-------------------------------------------------------------------------
53 // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
54 //
55 class qsamplerDeviceParam
56 {
57 public:
58
59 // Constructor.
60 qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,
61 const char *pszValue = NULL);
62 // Default destructor.
63 ~qsamplerDeviceParam();
64
65 // Initializer.
66 void setParam(lscp_param_info_t *pParamInfo,
67 const char *pszValue = NULL);
68
69 // Info structure field members.
70 lscp_type_t type;
71 QString description;
72 bool mandatory;
73 bool fix;
74 bool multiplicity;
75 QStringList depends;
76 QString defaultv;
77 QString range_min;
78 QString range_max;
79 QStringList possibilities;
80 // The current parameter value.
81 QString value;
82 };
83
84 // Typedef'd parameter QMap.
85 typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
86
87 // Typedef'd device port/channels QptrList.
88 typedef QList<qsamplerDevicePort *> qsamplerDevicePortList;
89
90
91 //-------------------------------------------------------------------------
92 // qsamplerDevice - MIDI/Audio Device structure.
93 //
94
95 class qsamplerDevice
96 {
97 public:
98
99 // We use the same class for MIDI and audio device management
100 enum DeviceType { None, Midi, Audio };
101
102 // Constructor.
103 qsamplerDevice(DeviceType deviceType, int iDeviceID = -1);
104 // Copy constructor.
105 qsamplerDevice(const qsamplerDevice& device);
106 // Default destructor.
107 ~qsamplerDevice();
108
109 // Initializer.
110 void setDevice(DeviceType deviceType, int iDeviceID = -1);
111
112 // Driver name initializer.
113 void setDriver(const QString& sDriverName);
114
115 // Device property accessors.
116 int deviceID() const;
117 DeviceType deviceType() const;
118 const QString& deviceTypeName() const;
119 const QString& driverName() const;
120
121 // 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.
128 const qsamplerDeviceParamMap& params() const;
129
130 // Device port/channel list accessor.
131 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.
152 static int *getDevices(lscp_client_t *pClient,
153 DeviceType deviceType);
154
155 // Driver names enumerator.
156 static QStringList getDrivers(lscp_client_t *pClient,
157 DeviceType deviceType);
158
159 private:
160
161 // Refresh/set given parameter based on driver supplied dependencies.
162 int refreshParam(const QString& sParam);
163
164 // Instance variables.
165 int m_iDeviceID;
166 DeviceType m_deviceType;
167 QString m_sDeviceType;
168 QString m_sDriverName;
169 QString m_sDeviceName;
170
171 // Device parameter list.
172 qsamplerDeviceParamMap m_params;
173
174 // Device port/channel list.
175 qsamplerDevicePortList m_ports;
176 };
177
178
179 //-------------------------------------------------------------------------
180 // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
181 //
182
183 class qsamplerDevicePort
184 {
185 public:
186
187 // Constructor.
188 qsamplerDevicePort(qsamplerDevice& device, int iPortID);
189 // Default destructor.
190 ~qsamplerDevicePort();
191
192 // Initializer.
193 void setDevicePort(int iPortID);
194
195 // Device port property accessors.
196 int portID() const;
197 const QString& portName() const;
198
199 // Device port parameters accessor.
200 const qsamplerDeviceParamMap& params() const;
201
202 // Set the proper device port/channel parameter value.
203 bool setParam (const QString& sParam, const QString& sValue);
204
205 private:
206
207 // Device reference.
208 qsamplerDevice& m_device;
209
210 // Instance variables.
211 int m_iPortID;
212 QString m_sPortName;
213
214 // Device port parameter list.
215 qsamplerDeviceParamMap m_params;
216 };
217
218
219 //-------------------------------------------------------------------------
220 // qsamplerDeviceItem - QListView device item.
221 //
222
223 class qsamplerDeviceItem : public QTreeWidgetItem
224 {
225 public:
226
227 // Constructors.
228 qsamplerDeviceItem(QTreeWidget *pTreeWidget,
229 qsamplerDevice::DeviceType deviceType);
230 qsamplerDeviceItem(QTreeWidgetItem *pItem,
231 qsamplerDevice::DeviceType deviceType, int iDeviceID);
232 // Default destructor.
233 ~qsamplerDeviceItem();
234
235 // Instance accessors.
236 qsamplerDevice& device();
237
238 private:
239
240 // Instance variables.
241 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 // AbstractDeviceParamModel - data model base class for device parameters
256 //
257 class AbstractDeviceParamModel : public QAbstractTableModel
258 {
259 Q_OBJECT
260
261 public:
262
263 AbstractDeviceParamModel(QObject *pParent = NULL);
264
265 // Overridden methods from subclass(es)
266 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 const qsamplerDeviceParamMap *m_pParams;
279 bool m_bEditable;
280 };
281
282
283 //-------------------------------------------------------------------------
284 // DeviceParamModel - data model for device parameters (used for QTableView)
285 //
286
287 class DeviceParamModel : public AbstractDeviceParamModel
288 {
289 Q_OBJECT
290
291 public:
292
293 DeviceParamModel(QObject *pParent = NULL);
294
295 // Overridden methods from subclass(es)
296 QVariant data(const QModelIndex &index, int role) const;
297 bool setData(const QModelIndex& index,
298 const QVariant& value, int role = Qt::EditRole);
299
300 void clear();
301
302 public slots:
303
304 void refresh(qsamplerDevice* pDevice, bool bEditable);
305
306 private:
307
308 qsamplerDevice *m_pDevice;
309 };
310
311
312 //-------------------------------------------------------------------------
313 // PortParamModel - data model for port parameters (used for QTableView)
314 //
315
316 class PortParamModel : public AbstractDeviceParamModel
317 {
318 Q_OBJECT
319
320 public:
321
322 PortParamModel(QObject *pParent = 0);
323
324 // 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 public slots:
332
333 void refresh(qsamplerDevicePort* pPort, bool bEditable);
334
335 private:
336
337 qsamplerDevicePort* m_pPort;
338 };
339
340
341 //-------------------------------------------------------------------------
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

  ViewVC Help
Powered by ViewVC