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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (hide annotations) (download) (as text)
Thu Dec 6 09:35:33 2007 UTC (16 years, 4 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9190 byte(s)
* Qt4 migration: complete QSampler namespace overhaul.

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 capela 1558 namespace QSampler {
44 capela 426
45 capela 1558 class DevicePort;
46    
47 capela 430 // Special QListViewItem::rtti() unique return value.
48 capela 429 #define QSAMPLER_DEVICE_ITEM 1001
49    
50    
51 capela 426 //-------------------------------------------------------------------------
52 capela 1558 // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
53 capela 426 //
54 capela 1558
55     class DeviceParam
56 capela 429 {
57     public:
58 capela 426
59 capela 431 // Constructor.
60 capela 1558 DeviceParam(lscp_param_info_t *pParamInfo = NULL,
61 capela 429 const char *pszValue = NULL);
62 capela 431 // Default destructor.
63 capela 1558 ~DeviceParam();
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 1558 typedef QMap<QString, DeviceParam> DeviceParamMap;
86 capela 429
87 capela 1558 // Typedef'd device port/channels QList.
88     typedef QList<DevicePort *> DevicePortList;
89 capela 429
90 capela 463
91 capela 429 //-------------------------------------------------------------------------
92 capela 1558 // QSampler::Device - MIDI/Audio Device structure.
93 capela 429 //
94    
95 capela 1558 class Device
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 1558 Device(DeviceType deviceType, int iDeviceID = -1);
104 capela 484 // Copy constructor.
105 capela 1558 Device(const Device& device);
106    
107 capela 431 // Default destructor.
108 capela 1558 ~Device();
109 capela 429
110     // Initializer.
111 capela 1509 void setDevice(DeviceType deviceType, int iDeviceID = -1);
112 capela 431
113     // Driver name initializer.
114 capela 484 void setDriver(const QString& sDriverName);
115 capela 431
116 capela 429 // Device property accessors.
117 capela 1509 int deviceID() const;
118     DeviceType deviceType() const;
119     const QString& deviceTypeName() const;
120     const QString& driverName() const;
121    
122 capela 484 // Special device name formatter.
123     QString deviceName() const;
124 capela 429
125 capela 463 // Set the proper device parameter value.
126 capela 484 bool setParam (const QString& sParam, const QString& sValue);
127 capela 463
128 capela 429 // Device parameters accessor.
129 capela 1558 const DeviceParamMap& params() const;
130 capela 429
131 capela 463 // Device port/channel list accessor.
132 capela 1558 DevicePortList& ports();
133 capela 429
134 capela 467 // Device parameter dependency list refreshner.
135 capela 484 int refreshParams();
136 capela 463 // Device port/channel list refreshner.
137 capela 484 int refreshPorts();
138 capela 467 // Refresh/set dependencies given that some parameter has changed.
139 capela 484 int refreshDepends(const QString& sParam);
140 capela 467
141 capela 484 // Create/destroy device methods.
142     bool createDevice();
143     bool deleteDevice();
144    
145     // Message logging methods (brainlessly mapped to main form's).
146     void appendMessages (const QString& s) const;
147     void appendMessagesColor (const QString& s, const QString & c) const;
148     void appendMessagesText (const QString& s) const;
149     void appendMessagesError (const QString& s) const;
150     void appendMessagesClient (const QString& s) const;
151    
152 capela 430 // Device ids enumerator.
153 capela 431 static int *getDevices(lscp_client_t *pClient,
154 capela 1509 DeviceType deviceType);
155 capela 429
156 capela 430 // Driver names enumerator.
157 capela 431 static QStringList getDrivers(lscp_client_t *pClient,
158 capela 1509 DeviceType deviceType);
159 capela 430
160 capela 429 private:
161    
162 capela 467 // Refresh/set given parameter based on driver supplied dependencies.
163 capela 484 int refreshParam(const QString& sParam);
164 capela 467
165 capela 429 // Instance variables.
166 capela 1509 int m_iDeviceID;
167     DeviceType m_deviceType;
168     QString m_sDeviceType;
169     QString m_sDriverName;
170     QString m_sDeviceName;
171 capela 429
172     // Device parameter list.
173 capela 1558 DeviceParamMap m_params;
174 capela 492
175 capela 463 // Device port/channel list.
176 capela 1558 DevicePortList m_ports;
177 capela 429 };
178    
179    
180     //-------------------------------------------------------------------------
181 capela 1558 // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
182 capela 462 //
183    
184 capela 1558 class DevicePort
185 capela 462 {
186     public:
187    
188     // Constructor.
189 capela 1558 DevicePort(Device& device, int iPortID);
190 capela 462 // Default destructor.
191 capela 1558 ~DevicePort();
192 capela 462
193     // Initializer.
194 capela 484 void setDevicePort(int iPortID);
195 capela 462
196     // Device port property accessors.
197     int portID() const;
198     const QString& portName() const;
199    
200     // Device port parameters accessor.
201 capela 1558 const DeviceParamMap& params() const;
202 capela 462
203     // Set the proper device port/channel parameter value.
204 capela 484 bool setParam (const QString& sParam, const QString& sValue);
205 capela 462
206     private:
207    
208 capela 484 // Device reference.
209 capela 1558 Device& m_device;
210 capela 492
211 capela 462 // Instance variables.
212     int m_iPortID;
213     QString m_sPortName;
214    
215     // Device port parameter list.
216 capela 1558 DeviceParamMap m_params;
217 capela 462 };
218    
219    
220     //-------------------------------------------------------------------------
221 capela 1558 // QSampler::DeviceItem - QTreeWidget device item.
222 capela 429 //
223    
224 capela 1558 class DeviceItem : public QTreeWidgetItem
225 capela 429 {
226     public:
227    
228 capela 431 // Constructors.
229 capela 1558 DeviceItem(QTreeWidget *pTreeWidget,
230     Device::DeviceType deviceType);
231     DeviceItem(QTreeWidgetItem *pItem,
232     Device::DeviceType deviceType, int iDeviceID);
233    
234 capela 431 // Default destructor.
235 capela 1558 ~DeviceItem();
236 capela 429
237 capela 431 // Instance accessors.
238 capela 1558 Device& device();
239 capela 429
240     private:
241    
242 capela 431 // Instance variables.
243 capela 1558 Device m_device;
244 capela 429 };
245    
246 capela 1558
247 schoenebeck 1461 struct DeviceParameterRow {
248 capela 1558 QString name;
249     DeviceParam param;
250     bool alive; // whether these params refer to an existing device
251     // or for a device that is yet to be created
252 schoenebeck 1461 };
253 capela 426
254 schoenebeck 1461
255 schoenebeck 1486 //-------------------------------------------------------------------------
256 capela 1558 // QSampler::AbstractDeviceParamModel - data model base class for device parameters
257 schoenebeck 1486 //
258 capela 1558
259 capela 1509 class AbstractDeviceParamModel : public QAbstractTableModel
260     {
261     Q_OBJECT
262 schoenebeck 1461
263 capela 1509 public:
264 schoenebeck 1461
265 capela 1509 AbstractDeviceParamModel(QObject *pParent = NULL);
266 schoenebeck 1461
267 capela 1509 // Overridden methods from subclass(es)
268     int rowCount(const QModelIndex& parent = QModelIndex()) const;
269     int columnCount(const QModelIndex& parent = QModelIndex() ) const;
270     QVariant headerData(int section,
271     Qt::Orientation orientation, int role = Qt::DisplayRole) const;
272     Qt::ItemFlags flags(const QModelIndex& index) const;
273 schoenebeck 1461
274 capela 1509 virtual void clear();
275    
276 capela 1558 void refresh(const DeviceParamMap* params, bool bEditable);
277 capela 1509
278     protected:
279    
280 capela 1558 const DeviceParamMap *m_pParams;
281 capela 1509 bool m_bEditable;
282 schoenebeck 1461 };
283    
284 capela 1509
285 schoenebeck 1486 //-------------------------------------------------------------------------
286 capela 1558 // QSampler::DeviceParamModel - data model for device parameters
287     // (used for QTableView)
288 schoenebeck 1461
289 capela 1509 class DeviceParamModel : public AbstractDeviceParamModel
290     {
291     Q_OBJECT
292 schoenebeck 1461
293 capela 1509 public:
294 schoenebeck 1461
295 capela 1509 DeviceParamModel(QObject *pParent = NULL);
296    
297     // Overridden methods from subclass(es)
298     QVariant data(const QModelIndex &index, int role) const;
299     bool setData(const QModelIndex& index,
300     const QVariant& value, int role = Qt::EditRole);
301    
302     void clear();
303    
304     public slots:
305    
306 capela 1558 void refresh(Device* pDevice, bool bEditable);
307 capela 1509
308     private:
309    
310 capela 1558 Device *m_pDevice;
311 schoenebeck 1461 };
312    
313 capela 1509
314 capela 442 //-------------------------------------------------------------------------
315 capela 1558 // QSampler::PortParamModel - data model for port parameters
316     // (used for QTableView)
317 capela 442
318 capela 1509 class PortParamModel : public AbstractDeviceParamModel
319     {
320     Q_OBJECT
321 capela 442
322 capela 1509 public:
323 capela 442
324 capela 1509 PortParamModel(QObject *pParent = 0);
325    
326     // overridden methods from subclass(es)
327     QVariant data(const QModelIndex &index, int role) const;
328     bool setData(const QModelIndex& index,
329     const QVariant& value, int role = Qt::EditRole);
330    
331     void clear();
332    
333     public slots:
334    
335 capela 1558 void refresh(DevicePort* pPort, bool bEditable);
336 capela 1509
337     private:
338    
339 capela 1558 DevicePort* m_pPort;
340 capela 442 };
341    
342 capela 1509
343 capela 442 //-------------------------------------------------------------------------
344 capela 1558 // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
345 capela 442 //
346 capela 1558
347 capela 1509 class DeviceParamDelegate : public QItemDelegate
348     {
349     Q_OBJECT
350    
351     public:
352    
353     DeviceParamDelegate(QObject *pParent = NULL);
354    
355     QWidget* createEditor(QWidget *pParent,
356     const QStyleOptionViewItem& option, const QModelIndex& index) const;
357     void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
358 capela 1510 void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
359 capela 1509 const QModelIndex& index) const;
360     void updateEditorGeometry(QWidget* pEditor,
361     const QStyleOptionViewItem& option, const QModelIndex& index) const;
362 capela 442 };
363    
364 capela 1558 } // namespace QSampler
365    
366     // so we can use it i.e. through QVariant
367     Q_DECLARE_METATYPE(QSampler::DeviceParameterRow)
368    
369 capela 426 #endif // __qsamplerDevice_h
370    
371 capela 1558
372 capela 426 // end of qsamplerDevice.h

  ViewVC Help
Powered by ViewVC