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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1510 - (hide 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 capela 426 // qsamplerDevice.h
2     //
3     /****************************************************************************
4 schoenebeck 1461 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5 capela 1464 Copyright (C) 2007, Christian Schoenebeck
6 capela 426
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 capela 920 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 capela 426
21     *****************************************************************************/
22    
23     #ifndef __qsamplerDevice_h
24     #define __qsamplerDevice_h
25    
26 schoenebeck 1461 #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 capela 426
38     #include <lscp/client.h>
39     #include <lscp/device.h>
40    
41     #include "qsamplerOptions.h"
42    
43    
44 capela 430 // Special QListViewItem::rtti() unique return value.
45 capela 429 #define QSAMPLER_DEVICE_ITEM 1001
46    
47 capela 484 // Early forward declarations.
48     class qsamplerMainForm;
49 capela 463 class qsamplerDevicePort;
50 capela 429
51 capela 463
52 capela 426 //-------------------------------------------------------------------------
53 capela 429 // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
54 capela 426 //
55 capela 429 class qsamplerDeviceParam
56     {
57     public:
58 capela 426
59 capela 431 // Constructor.
60     qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,
61 capela 429 const char *pszValue = NULL);
62 capela 431 // Default destructor.
63     ~qsamplerDeviceParam();
64 capela 429
65     // Initializer.
66     void setParam(lscp_param_info_t *pParamInfo,
67     const char *pszValue = NULL);
68    
69 capela 431 // 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 capela 429 };
83    
84 capela 463 // Typedef'd parameter QMap.
85 capela 429 typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
86    
87 capela 463 // Typedef'd device port/channels QptrList.
88 capela 1499 typedef QList<qsamplerDevicePort *> qsamplerDevicePortList;
89 capela 429
90 capela 463
91 capela 429 //-------------------------------------------------------------------------
92     // qsamplerDevice - MIDI/Audio Device structure.
93     //
94    
95     class qsamplerDevice
96 capela 426 {
97 capela 429 public:
98    
99 capela 431 // We use the same class for MIDI and audio device management
100 capela 1509 enum DeviceType { None, Midi, Audio };
101 capela 429
102 capela 431 // Constructor.
103 capela 1509 qsamplerDevice(DeviceType deviceType, int iDeviceID = -1);
104 capela 484 // Copy constructor.
105 capela 1509 qsamplerDevice(const qsamplerDevice& device);
106 capela 431 // Default destructor.
107     ~qsamplerDevice();
108 capela 429
109     // Initializer.
110 capela 1509 void setDevice(DeviceType deviceType, int iDeviceID = -1);
111 capela 431
112     // Driver name initializer.
113 capela 484 void setDriver(const QString& sDriverName);
114 capela 431
115 capela 429 // Device property accessors.
116 capela 1509 int deviceID() const;
117     DeviceType deviceType() const;
118     const QString& deviceTypeName() const;
119     const QString& driverName() const;
120    
121 capela 484 // Special device name formatter.
122     QString deviceName() const;
123 capela 429
124 capela 463 // Set the proper device parameter value.
125 capela 484 bool setParam (const QString& sParam, const QString& sValue);
126 capela 463
127 capela 429 // Device parameters accessor.
128 capela 462 const qsamplerDeviceParamMap& params() const;
129 capela 429
130 capela 463 // Device port/channel list accessor.
131     qsamplerDevicePortList& ports();
132 capela 429
133 capela 467 // Device parameter dependency list refreshner.
134 capela 484 int refreshParams();
135 capela 463 // Device port/channel list refreshner.
136 capela 484 int refreshPorts();
137 capela 467 // Refresh/set dependencies given that some parameter has changed.
138 capela 484 int refreshDepends(const QString& sParam);
139 capela 467
140 capela 484 // 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 capela 430 // Device ids enumerator.
152 capela 431 static int *getDevices(lscp_client_t *pClient,
153 capela 1509 DeviceType deviceType);
154 capela 429
155 capela 430 // Driver names enumerator.
156 capela 431 static QStringList getDrivers(lscp_client_t *pClient,
157 capela 1509 DeviceType deviceType);
158 capela 430
159 capela 429 private:
160    
161 capela 467 // Refresh/set given parameter based on driver supplied dependencies.
162 capela 484 int refreshParam(const QString& sParam);
163 capela 467
164 capela 429 // Instance variables.
165 capela 1509 int m_iDeviceID;
166     DeviceType m_deviceType;
167     QString m_sDeviceType;
168     QString m_sDriverName;
169     QString m_sDeviceName;
170 capela 429
171     // Device parameter list.
172     qsamplerDeviceParamMap m_params;
173 capela 492
174 capela 463 // Device port/channel list.
175     qsamplerDevicePortList m_ports;
176 capela 429 };
177    
178    
179     //-------------------------------------------------------------------------
180 capela 462 // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
181     //
182    
183     class qsamplerDevicePort
184     {
185     public:
186    
187     // Constructor.
188 capela 484 qsamplerDevicePort(qsamplerDevice& device, int iPortID);
189 capela 462 // Default destructor.
190     ~qsamplerDevicePort();
191    
192     // Initializer.
193 capela 484 void setDevicePort(int iPortID);
194 capela 462
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 capela 484 bool setParam (const QString& sParam, const QString& sValue);
204 capela 462
205     private:
206    
207 capela 484 // Device reference.
208     qsamplerDevice& m_device;
209 capela 492
210 capela 462 // 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 capela 429 // qsamplerDeviceItem - QListView device item.
221     //
222    
223 schoenebeck 1461 class qsamplerDeviceItem : public QTreeWidgetItem
224 capela 429 {
225     public:
226    
227 capela 431 // Constructors.
228 capela 1509 qsamplerDeviceItem(QTreeWidget *pTreeWidget,
229     qsamplerDevice::DeviceType deviceType);
230     qsamplerDeviceItem(QTreeWidgetItem *pItem,
231     qsamplerDevice::DeviceType deviceType, int iDeviceID);
232 capela 431 // Default destructor.
233     ~qsamplerDeviceItem();
234 capela 429
235 capela 431 // Instance accessors.
236     qsamplerDevice& device();
237 capela 429
238     private:
239    
240 capela 431 // Instance variables.
241     qsamplerDevice m_device;
242 capela 429 };
243    
244 schoenebeck 1461 struct DeviceParameterRow {
245 capela 1509 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 schoenebeck 1461 };
249 capela 426
250 schoenebeck 1461 // so we can use it i.e. through QVariant
251     Q_DECLARE_METATYPE(DeviceParameterRow)
252    
253 capela 1509
254 schoenebeck 1486 //-------------------------------------------------------------------------
255     // AbstractDeviceParamModel - data model base class for device parameters
256     //
257 capela 1509 class AbstractDeviceParamModel : public QAbstractTableModel
258     {
259     Q_OBJECT
260 schoenebeck 1461
261 capela 1509 public:
262 schoenebeck 1461
263 capela 1509 AbstractDeviceParamModel(QObject *pParent = NULL);
264 schoenebeck 1461
265 capela 1509 // 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 schoenebeck 1461
272 capela 1509 virtual void clear();
273    
274     void refresh(const qsamplerDeviceParamMap* params, bool bEditable);
275    
276     protected:
277    
278 capela 1510 const qsamplerDeviceParamMap *m_pParams;
279 capela 1509 bool m_bEditable;
280 schoenebeck 1461 };
281    
282 capela 1509
283 schoenebeck 1486 //-------------------------------------------------------------------------
284     // DeviceParamModel - data model for device parameters (used for QTableView)
285     //
286 schoenebeck 1461
287 capela 1509 class DeviceParamModel : public AbstractDeviceParamModel
288     {
289     Q_OBJECT
290 schoenebeck 1461
291 capela 1509 public:
292 schoenebeck 1461
293 capela 1509 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 capela 1510 qsamplerDevice *m_pDevice;
309 schoenebeck 1461 };
310    
311 capela 1509
312 capela 442 //-------------------------------------------------------------------------
313 schoenebeck 1486 // PortParamModel - data model for port parameters (used for QTableView)
314 capela 442 //
315    
316 capela 1509 class PortParamModel : public AbstractDeviceParamModel
317     {
318     Q_OBJECT
319 capela 442
320 capela 1509 public:
321 capela 442
322 capela 1509 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 capela 1510 qsamplerDevicePort* m_pPort;
338 capela 442 };
339    
340 capela 1509
341 capela 442 //-------------------------------------------------------------------------
342 schoenebeck 1486 // DeviceParamDelegate - table cell renderer for device/port parameters
343 capela 442 //
344 capela 1509 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 capela 1510 void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
356 capela 1509 const QModelIndex& index) const;
357     void updateEditorGeometry(QWidget* pEditor,
358     const QStyleOptionViewItem& option, const QModelIndex& index) const;
359 capela 442 };
360    
361 capela 426 #endif // __qsamplerDevice_h
362    
363     // end of qsamplerDevice.h

  ViewVC Help
Powered by ViewVC