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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3788 - (hide annotations) (download) (as text)
Thu Jun 11 16:59:09 2020 UTC (3 years, 10 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9272 byte(s)
- Messages widget micro-refactoring.
1 capela 426 // qsamplerDevice.h
2     //
3     /****************************************************************************
4 capela 3788 Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1698 Copyright (C) 2007, 2008 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 schoenebeck 1698 #include <set>
38 capela 426
39     #include <lscp/client.h>
40     #include <lscp/device.h>
41    
42     #include "qsamplerOptions.h"
43    
44 capela 1558 namespace QSampler {
45 capela 426
46 capela 1558 class DevicePort;
47    
48 capela 430 // Special QListViewItem::rtti() unique return value.
49 capela 429 #define QSAMPLER_DEVICE_ITEM 1001
50    
51    
52 capela 426 //-------------------------------------------------------------------------
53 capela 1558 // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
54 capela 426 //
55 capela 1558
56     class DeviceParam
57 capela 429 {
58     public:
59 capela 426
60 capela 431 // Constructor.
61 capela 3555 DeviceParam(lscp_param_info_t *pParamInfo = nullptr,
62     const char *pszValue = nullptr);
63 capela 429
64     // Initializer.
65     void setParam(lscp_param_info_t *pParamInfo,
66 capela 3555 const char *pszValue = nullptr);
67 capela 429
68 capela 431 // Info structure field members.
69     lscp_type_t type;
70     QString description;
71     bool mandatory;
72     bool fix;
73     bool multiplicity;
74     QStringList depends;
75     QString defaultv;
76     QString range_min;
77     QString range_max;
78     QStringList possibilities;
79     // The current parameter value.
80     QString value;
81 capela 429 };
82    
83 capela 463 // Typedef'd parameter QMap.
84 capela 1558 typedef QMap<QString, DeviceParam> DeviceParamMap;
85 capela 429
86 capela 1558 // Typedef'd device port/channels QList.
87     typedef QList<DevicePort *> DevicePortList;
88 capela 429
89 capela 463
90 capela 429 //-------------------------------------------------------------------------
91 capela 1558 // QSampler::Device - MIDI/Audio Device structure.
92 capela 429 //
93    
94 capela 1558 class Device
95 capela 426 {
96 capela 429 public:
97    
98 capela 431 // We use the same class for MIDI and audio device management
99 capela 1509 enum DeviceType { None, Midi, Audio };
100 capela 429
101 capela 431 // Constructor.
102 capela 1558 Device(DeviceType deviceType, int iDeviceID = -1);
103 capela 484 // Copy constructor.
104 capela 1558 Device(const Device& device);
105    
106 capela 431 // Default destructor.
107 capela 1558 ~Device();
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 1558 const DeviceParamMap& params() const;
129 capela 429
130 capela 463 // Device port/channel list accessor.
131 capela 1558 DevicePortList& 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 capela 3788 void appendMessagesColor (const QString& s, const QColor& rgb) const;
147 capela 484 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 schoenebeck 1698 static std::set<int> getDeviceIDs(lscp_client_t *pClient,
155     DeviceType deviceType);
156 capela 429
157 capela 430 // Driver names enumerator.
158 capela 431 static QStringList getDrivers(lscp_client_t *pClient,
159 capela 1509 DeviceType deviceType);
160 capela 430
161 capela 429 private:
162    
163 capela 467 // Refresh/set given parameter based on driver supplied dependencies.
164 capela 484 int refreshParam(const QString& sParam);
165 capela 467
166 capela 429 // Instance variables.
167 capela 1509 int m_iDeviceID;
168     DeviceType m_deviceType;
169     QString m_sDeviceType;
170     QString m_sDriverName;
171     QString m_sDeviceName;
172 capela 429
173     // Device parameter list.
174 capela 1558 DeviceParamMap m_params;
175 capela 492
176 capela 463 // Device port/channel list.
177 capela 1558 DevicePortList m_ports;
178 capela 429 };
179    
180    
181     //-------------------------------------------------------------------------
182 capela 1558 // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
183 capela 462 //
184    
185 capela 1558 class DevicePort
186 capela 462 {
187     public:
188    
189     // Constructor.
190 capela 1558 DevicePort(Device& device, int iPortID);
191 capela 462 // Default destructor.
192 capela 1558 ~DevicePort();
193 capela 462
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 capela 1558 const DeviceParamMap& params() const;
203 capela 462
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 capela 1558 Device& 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 capela 1558 DeviceParamMap m_params;
218 capela 462 };
219    
220    
221     //-------------------------------------------------------------------------
222 capela 1558 // QSampler::DeviceItem - QTreeWidget device item.
223 capela 429 //
224    
225 capela 1558 class DeviceItem : public QTreeWidgetItem
226 capela 429 {
227     public:
228    
229 capela 431 // Constructors.
230 capela 1558 DeviceItem(QTreeWidget *pTreeWidget,
231     Device::DeviceType deviceType);
232     DeviceItem(QTreeWidgetItem *pItem,
233     Device::DeviceType deviceType, int iDeviceID);
234    
235 capela 431 // Default destructor.
236 capela 1558 ~DeviceItem();
237 capela 429
238 capela 431 // Instance accessors.
239 capela 1558 Device& device();
240 capela 429
241     private:
242    
243 capela 431 // Instance variables.
244 capela 1558 Device m_device;
245 capela 429 };
246    
247 capela 1558
248 schoenebeck 1461 struct DeviceParameterRow {
249 capela 1558 QString name;
250     DeviceParam param;
251     bool alive; // whether these params refer to an existing device
252     // or for a device that is yet to be created
253 schoenebeck 1461 };
254 capela 426
255 schoenebeck 1461
256 schoenebeck 1486 //-------------------------------------------------------------------------
257 capela 1558 // QSampler::AbstractDeviceParamModel - data model base class for device parameters
258 schoenebeck 1486 //
259 capela 1558
260 capela 1509 class AbstractDeviceParamModel : public QAbstractTableModel
261     {
262     Q_OBJECT
263 schoenebeck 1461
264 capela 1509 public:
265 schoenebeck 1461
266 capela 3555 AbstractDeviceParamModel(QObject *pParent = nullptr);
267 schoenebeck 1461
268 capela 1509 // Overridden methods from subclass(es)
269     int rowCount(const QModelIndex& parent = QModelIndex()) const;
270     int columnCount(const QModelIndex& parent = QModelIndex() ) const;
271     QVariant headerData(int section,
272     Qt::Orientation orientation, int role = Qt::DisplayRole) const;
273     Qt::ItemFlags flags(const QModelIndex& index) const;
274 schoenebeck 1461
275 capela 1509 virtual void clear();
276    
277 capela 1558 void refresh(const DeviceParamMap* params, bool bEditable);
278 capela 1509
279     protected:
280    
281 capela 1558 const DeviceParamMap *m_pParams;
282 capela 1509 bool m_bEditable;
283 schoenebeck 1461 };
284    
285 capela 1509
286 schoenebeck 1486 //-------------------------------------------------------------------------
287 capela 1558 // QSampler::DeviceParamModel - data model for device parameters
288     // (used for QTableView)
289 schoenebeck 1461
290 capela 1509 class DeviceParamModel : public AbstractDeviceParamModel
291     {
292     Q_OBJECT
293 schoenebeck 1461
294 capela 1509 public:
295 schoenebeck 1461
296 capela 3555 DeviceParamModel(QObject *pParent = nullptr);
297 capela 1509
298     // Overridden methods from subclass(es)
299     QVariant data(const QModelIndex &index, int role) const;
300     bool setData(const QModelIndex& index,
301     const QVariant& value, int role = Qt::EditRole);
302    
303     void clear();
304    
305     public slots:
306    
307 capela 1558 void refresh(Device* pDevice, bool bEditable);
308 capela 1509
309     private:
310    
311 capela 1558 Device *m_pDevice;
312 schoenebeck 1461 };
313    
314 capela 1509
315 capela 442 //-------------------------------------------------------------------------
316 capela 1558 // QSampler::PortParamModel - data model for port parameters
317     // (used for QTableView)
318 capela 442
319 capela 1509 class PortParamModel : public AbstractDeviceParamModel
320     {
321     Q_OBJECT
322 capela 442
323 capela 1509 public:
324 capela 442
325 capela 1509 PortParamModel(QObject *pParent = 0);
326    
327     // overridden methods from subclass(es)
328     QVariant data(const QModelIndex &index, int role) const;
329     bool setData(const QModelIndex& index,
330     const QVariant& value, int role = Qt::EditRole);
331    
332     void clear();
333    
334     public slots:
335    
336 capela 1558 void refresh(DevicePort* pPort, bool bEditable);
337 capela 1509
338     private:
339    
340 capela 1558 DevicePort* m_pPort;
341 capela 442 };
342    
343 capela 1509
344 capela 442 //-------------------------------------------------------------------------
345 capela 1558 // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
346 capela 442 //
347 capela 1558
348 capela 1509 class DeviceParamDelegate : public QItemDelegate
349     {
350     Q_OBJECT
351    
352     public:
353    
354 capela 3555 DeviceParamDelegate(QObject *pParent = nullptr);
355 capela 1509
356     QWidget* createEditor(QWidget *pParent,
357     const QStyleOptionViewItem& option, const QModelIndex& index) const;
358     void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
359 capela 1510 void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
360 capela 1509 const QModelIndex& index) const;
361     void updateEditorGeometry(QWidget* pEditor,
362     const QStyleOptionViewItem& option, const QModelIndex& index) const;
363 capela 442 };
364    
365 capela 1558 } // namespace QSampler
366    
367     // so we can use it i.e. through QVariant
368     Q_DECLARE_METATYPE(QSampler::DeviceParameterRow)
369    
370 capela 426 #endif // __qsamplerDevice_h
371    
372 capela 1558
373 capela 426 // end of qsamplerDevice.h

  ViewVC Help
Powered by ViewVC