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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1499 - (hide annotations) (download) (as text)
Tue Nov 20 16:48:04 2007 UTC (16 years, 4 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9752 byte(s)
* Qt4 migration: one first step forward to kiss Qt3Support goodbye.

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 436 enum qsamplerDeviceType { None, Midi, Audio };
101 capela 429
102 capela 431 // Constructor.
103 capela 961 qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
104 capela 484 // Copy constructor.
105     qsamplerDevice(const qsamplerDevice& device);
106 capela 431 // Default destructor.
107     ~qsamplerDevice();
108 capela 429
109     // Initializer.
110 capela 484 void setDevice(qsamplerDeviceType 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 431 int deviceID() const;
117     qsamplerDeviceType deviceType() const;
118 capela 433 const QString& deviceTypeName() const;
119 capela 431 const QString& driverName() const;
120 capela 484 // Special device name formatter.
121     QString deviceName() const;
122 capela 429
123 capela 463 // Set the proper device parameter value.
124 capela 484 bool setParam (const QString& sParam, const QString& sValue);
125 capela 463
126 capela 429 // Device parameters accessor.
127 capela 462 const qsamplerDeviceParamMap& params() const;
128 capela 429
129 capela 463 // Device port/channel list accessor.
130     qsamplerDevicePortList& ports();
131 capela 429
132 capela 467 // Device parameter dependency list refreshner.
133 capela 484 int refreshParams();
134 capela 463 // Device port/channel list refreshner.
135 capela 484 int refreshPorts();
136 capela 467 // Refresh/set dependencies given that some parameter has changed.
137 capela 484 int refreshDepends(const QString& sParam);
138 capela 467
139 capela 484 // Create/destroy device methods.
140     bool createDevice();
141     bool deleteDevice();
142    
143     // Message logging methods (brainlessly mapped to main form's).
144     void appendMessages (const QString& s) const;
145     void appendMessagesColor (const QString& s, const QString & c) const;
146     void appendMessagesText (const QString& s) const;
147     void appendMessagesError (const QString& s) const;
148     void appendMessagesClient (const QString& s) const;
149    
150 capela 430 // Device ids enumerator.
151 capela 431 static int *getDevices(lscp_client_t *pClient,
152 capela 429 qsamplerDeviceType deviceType);
153    
154 capela 430 // Driver names enumerator.
155 capela 431 static QStringList getDrivers(lscp_client_t *pClient,
156 capela 430 qsamplerDeviceType deviceType);
157    
158 capela 429 private:
159    
160 capela 467 // Refresh/set given parameter based on driver supplied dependencies.
161 capela 484 int refreshParam(const QString& sParam);
162 capela 467
163 capela 484 // Main application form reference.
164     qsamplerMainForm *m_pMainForm;
165    
166 capela 429 // Instance variables.
167 capela 431 int m_iDeviceID;
168     qsamplerDeviceType m_deviceType;
169 capela 433 QString m_sDeviceType;
170 capela 431 QString m_sDriverName;
171     QString m_sDeviceName;
172 capela 429
173     // Device parameter list.
174     qsamplerDeviceParamMap m_params;
175 capela 492
176 capela 463 // Device port/channel list.
177     qsamplerDevicePortList m_ports;
178 capela 429 };
179    
180    
181     //-------------------------------------------------------------------------
182 capela 462 // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
183     //
184    
185     class qsamplerDevicePort
186     {
187     public:
188    
189     // Constructor.
190 capela 484 qsamplerDevicePort(qsamplerDevice& device, int iPortID);
191 capela 462 // Default destructor.
192     ~qsamplerDevicePort();
193    
194     // Initializer.
195 capela 484 void setDevicePort(int iPortID);
196 capela 462
197     // Device port property accessors.
198     int portID() const;
199     const QString& portName() const;
200    
201     // Device port parameters accessor.
202     const qsamplerDeviceParamMap& params() const;
203    
204     // Set the proper device port/channel parameter value.
205 capela 484 bool setParam (const QString& sParam, const QString& sValue);
206 capela 462
207     private:
208    
209 capela 484 // Device reference.
210     qsamplerDevice& m_device;
211 capela 492
212 capela 462 // Instance variables.
213     int m_iPortID;
214     QString m_sPortName;
215    
216     // Device port parameter list.
217     qsamplerDeviceParamMap m_params;
218     };
219    
220    
221     //-------------------------------------------------------------------------
222 capela 429 // qsamplerDeviceItem - QListView device item.
223     //
224    
225 schoenebeck 1461 class qsamplerDeviceItem : public QTreeWidgetItem
226 capela 429 {
227     public:
228    
229 capela 431 // Constructors.
230 schoenebeck 1461 qsamplerDeviceItem(QTreeWidget* pTreeWidget,
231 capela 429 qsamplerDevice::qsamplerDeviceType deviceType);
232 schoenebeck 1461 qsamplerDeviceItem(QTreeWidgetItem* pItem,
233 capela 429 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);
234 capela 431 // Default destructor.
235     ~qsamplerDeviceItem();
236 capela 429
237 capela 431 // Instance accessors.
238     qsamplerDevice& device();
239 capela 429
240     private:
241    
242 capela 431 // Instance variables.
243     qsamplerDevice m_device;
244 capela 429 };
245    
246 schoenebeck 1461 struct DeviceParameterRow {
247     QString name;
248     qsamplerDeviceParam param;
249     };
250 capela 426
251 schoenebeck 1461 // so we can use it i.e. through QVariant
252     Q_DECLARE_METATYPE(DeviceParameterRow)
253    
254 schoenebeck 1486 //-------------------------------------------------------------------------
255     // AbstractDeviceParamModel - data model base class for device parameters
256     //
257     class AbstractDeviceParamModel : public QAbstractTableModel {
258 schoenebeck 1461 Q_OBJECT
259     public:
260 schoenebeck 1486 AbstractDeviceParamModel(QObject* parent = 0);
261 schoenebeck 1461
262     // overridden methods from subclass(es)
263 schoenebeck 1486 int rowCount(const QModelIndex& parent = QModelIndex()) const;
264     int columnCount(const QModelIndex& parent = QModelIndex() ) const;
265 schoenebeck 1461 QVariant data(const QModelIndex &index, int role) const;
266     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
267 schoenebeck 1486 Qt::ItemFlags flags(const QModelIndex& index) const;
268 schoenebeck 1461
269 schoenebeck 1486 virtual void clear();
270 schoenebeck 1461
271 schoenebeck 1486 void refresh(const qsamplerDeviceParamMap* params, bool bEditable);
272 schoenebeck 1461
273 schoenebeck 1486 protected:
274     const qsamplerDeviceParamMap* params;
275 schoenebeck 1461 bool bEditable;
276     };
277    
278 schoenebeck 1486 //-------------------------------------------------------------------------
279     // DeviceParamModel - data model for device parameters (used for QTableView)
280     //
281     class DeviceParamModel : public AbstractDeviceParamModel {
282 schoenebeck 1461 Q_OBJECT
283     public:
284 schoenebeck 1486 DeviceParamModel(QObject* parent = 0);
285 schoenebeck 1461
286 schoenebeck 1486 // overridden methods from subclass(es)
287     bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
288     void clear();
289 schoenebeck 1461
290 schoenebeck 1486 public slots:
291     void refresh(qsamplerDevice* pDevice, bool bEditable);
292 schoenebeck 1461
293 schoenebeck 1486 private:
294     qsamplerDevice* device;
295 schoenebeck 1461 };
296    
297 capela 442 //-------------------------------------------------------------------------
298 schoenebeck 1486 // PortParamModel - data model for port parameters (used for QTableView)
299 capela 442 //
300 schoenebeck 1486 class PortParamModel : public AbstractDeviceParamModel {
301     Q_OBJECT
302     public:
303     PortParamModel(QObject* parent = 0);
304 capela 442
305 schoenebeck 1486 // overridden methods from subclass(es)
306     bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
307     void clear();
308 capela 442
309 schoenebeck 1486 public slots:
310     void refresh(qsamplerDevicePort* pPort, bool bEditable);
311 capela 442
312 schoenebeck 1486 private:
313     qsamplerDevicePort* port;
314 capela 442 };
315    
316     //-------------------------------------------------------------------------
317 schoenebeck 1486 // DeviceParamDelegate - table cell renderer for device/port parameters
318 capela 442 //
319 schoenebeck 1486 class DeviceParamDelegate : public QItemDelegate {
320     Q_OBJECT
321     public:
322     DeviceParamDelegate(QObject* parent = 0);
323     QWidget* createEditor(QWidget* parent,
324     const QStyleOptionViewItem& option,
325     const QModelIndex& index) const;
326     void setEditorData(QWidget* editor, const QModelIndex& index) const;
327     void setModelData(QWidget* editor, QAbstractItemModel* model,
328     const QModelIndex& index) const;
329     void updateEditorGeometry(QWidget* editor,
330     const QStyleOptionViewItem& option,
331     const QModelIndex& index) const;
332 capela 442 };
333    
334 capela 426 #endif // __qsamplerDevice_h
335    
336     // end of qsamplerDevice.h

  ViewVC Help
Powered by ViewVC