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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 426 by capela, Mon Mar 7 11:09:32 2005 UTC revision 2387 by capela, Sat Dec 29 00:21:11 2012 UTC
# Line 1  Line 1 
1  // qsamplerDevice.h  // qsamplerDevice.h
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, 2008 Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23  #ifndef __qsamplerDevice_h  #ifndef __qsamplerDevice_h
24  #define __qsamplerDevice_h  #define __qsamplerDevice_h
25    
26  #include <qtable.h>  #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    #include <set>
38    
39  #include <lscp/client.h>  #include <lscp/client.h>
40  #include <lscp/device.h>  #include <lscp/device.h>
41    
42  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
43    
44    namespace QSampler {
45    
46    class DevicePort;
47    
48    // Special QListViewItem::rtti() unique return value.
49    #define QSAMPLER_DEVICE_ITEM    1001
50    
51    
52    //-------------------------------------------------------------------------
53    // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
54    //
55    
56    class DeviceParam
57    {
58    public:
59    
60            // Constructor.
61            DeviceParam(lscp_param_info_t *pParamInfo = NULL,
62                    const char *pszValue = NULL);
63            // Default destructor.
64            ~DeviceParam();
65    
66            // Initializer.
67            void setParam(lscp_param_info_t *pParamInfo,
68                    const char *pszValue = NULL);
69    
70            // Info structure field members.
71            lscp_type_t     type;
72            QString         description;
73            bool            mandatory;
74            bool            fix;
75            bool            multiplicity;
76            QStringList depends;
77            QString         defaultv;
78            QString         range_min;
79            QString         range_max;
80            QStringList possibilities;
81            // The current parameter value.
82            QString         value;
83    };
84    
85    // Typedef'd parameter QMap.
86    typedef QMap<QString, DeviceParam> DeviceParamMap;
87    
88    // Typedef'd device port/channels QList.
89    typedef QList<DevicePort *> DevicePortList;
90    
91    
92    //-------------------------------------------------------------------------
93    // QSampler::Device - MIDI/Audio Device structure.
94    //
95    
96    class Device
97    {
98    public:
99    
100            // We use the same class for MIDI and audio device management
101            enum DeviceType { None, Midi, Audio };
102    
103            // Constructor.
104            Device(DeviceType deviceType, int iDeviceID = -1);
105            // Copy constructor.
106            Device(const Device& device);
107    
108            // Default destructor.
109            ~Device();
110    
111            // Initializer.
112            void setDevice(DeviceType deviceType, int iDeviceID = -1);
113    
114            // Driver name initializer.
115            void setDriver(const QString& sDriverName);
116    
117            // Device property accessors.
118            int            deviceID() const;
119            DeviceType     deviceType() const;
120            const QString& deviceTypeName() const;
121            const QString& driverName() const;
122    
123            // Special device name formatter.
124            QString deviceName() const;
125    
126            // Set the proper device parameter value.
127            bool setParam (const QString& sParam, const QString& sValue);
128    
129            // Device parameters accessor.
130            const DeviceParamMap& params() const;
131    
132            // Device port/channel list accessor.
133            DevicePortList& ports();
134    
135            // Device parameter dependency list refreshner.
136            int refreshParams();
137            // Device port/channel list refreshner.
138            int refreshPorts();
139            // Refresh/set dependencies given that some parameter has changed.
140            int refreshDepends(const QString& sParam);
141    
142            // Create/destroy device methods.
143            bool createDevice();
144            bool deleteDevice();
145    
146            // Message logging methods (brainlessly mapped to main form's).
147            void appendMessages       (const QString& s) const;
148            void appendMessagesColor  (const QString& s, const QString & c) const;
149            void appendMessagesText   (const QString& s) const;
150            void appendMessagesError  (const QString& s) const;
151            void appendMessagesClient (const QString& s) const;
152    
153            // Device ids enumerator.
154            static int *getDevices(lscp_client_t *pClient,
155                    DeviceType deviceType);
156            static std::set<int> getDeviceIDs(lscp_client_t *pClient,
157                    DeviceType deviceType);
158    
159            // Driver names enumerator.
160            static QStringList getDrivers(lscp_client_t *pClient,
161                    DeviceType deviceType);
162    
163    private:
164    
165            // Refresh/set given parameter based on driver supplied dependencies.
166            int refreshParam(const QString& sParam);
167    
168            // Instance variables.
169            int        m_iDeviceID;
170            DeviceType m_deviceType;
171            QString    m_sDeviceType;
172            QString    m_sDriverName;
173            QString    m_sDeviceName;
174    
175            // Device parameter list.
176            DeviceParamMap m_params;
177    
178            // Device port/channel list.
179            DevicePortList m_ports;
180    };
181    
182    
183    //-------------------------------------------------------------------------
184    // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
185    //
186    
187    class DevicePort
188    {
189    public:
190    
191            // Constructor.
192            DevicePort(Device& device, int iPortID);
193            // Default destructor.
194            ~DevicePort();
195    
196            // Initializer.
197            void setDevicePort(int iPortID);
198    
199            // Device port property accessors.
200            int            portID()   const;
201            const QString& portName() const;
202    
203            // Device port parameters accessor.
204            const DeviceParamMap& params() const;
205    
206            // Set the proper device port/channel parameter value.
207            bool setParam (const QString& sParam, const QString& sValue);
208    
209    private:
210    
211            // Device reference.
212            Device& m_device;
213    
214            // Instance variables.
215            int     m_iPortID;
216            QString m_sPortName;
217    
218            // Device port parameter list.
219            DeviceParamMap m_params;
220    };
221    
222    
223    //-------------------------------------------------------------------------
224    // QSampler::DeviceItem - QTreeWidget device item.
225    //
226    
227    class DeviceItem : public QTreeWidgetItem
228    {
229    public:
230    
231            // Constructors.
232            DeviceItem(QTreeWidget *pTreeWidget,
233                    Device::DeviceType deviceType);
234            DeviceItem(QTreeWidgetItem *pItem,
235                    Device::DeviceType deviceType, int iDeviceID);
236    
237            // Default destructor.
238            ~DeviceItem();
239    
240            // Instance accessors.
241            Device& device();
242    
243    private:
244    
245            // Instance variables.
246            Device m_device;
247    };
248    
249    
250    struct DeviceParameterRow {
251            QString     name;
252            DeviceParam param;
253            bool        alive; // whether these params refer to an existing device
254                               // or for a device that is yet to be created
255    };
256    
257    
258  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
259  // qsamplerDeviceParameterTable - Device parameter view table.  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
260  //  //
261    
262  class qsamplerDeviceParameterTable : public QTable  class AbstractDeviceParamModel : public QAbstractTableModel
263    {
264            Q_OBJECT
265    
266    public:
267    
268            AbstractDeviceParamModel(QObject *pParent = NULL);
269    
270            // Overridden methods from subclass(es)
271            int rowCount(const QModelIndex& parent = QModelIndex()) const;
272            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
273            QVariant headerData(int section,
274                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
275            Qt::ItemFlags flags(const QModelIndex& index) const;
276    
277            virtual void clear();
278    
279            void refresh(const DeviceParamMap* params, bool bEditable);
280    
281    protected:
282    
283            const DeviceParamMap *m_pParams;
284            bool m_bEditable;
285    };
286    
287    
288    //-------------------------------------------------------------------------
289    // QSampler::DeviceParamModel - data model for device parameters
290    //                              (used for QTableView)
291    
292    class DeviceParamModel : public AbstractDeviceParamModel
293    {
294            Q_OBJECT
295    
296    public:
297    
298            DeviceParamModel(QObject *pParent = NULL);
299    
300            // Overridden methods from subclass(es)
301            QVariant data(const QModelIndex &index, int role) const;
302            bool setData(const QModelIndex& index,
303                    const QVariant& value, int role = Qt::EditRole);
304    
305            void clear();
306    
307    public slots:
308    
309            void refresh(Device* pDevice, bool bEditable);
310    
311    private:
312    
313            Device *m_pDevice;
314    };
315    
316    
317    //-------------------------------------------------------------------------
318    // QSampler::PortParamModel - data model for port parameters
319    //                            (used for QTableView)
320    
321    class PortParamModel : public AbstractDeviceParamModel
322  {  {
323      Q_OBJECT          Q_OBJECT
324    
325  public:  public:
326    
327      // Constructor.          PortParamModel(QObject *pParent = 0);
328      qsamplerDeviceParameterTable(QWidget *pParent = 0, const char *pszName = 0);  
329      // Default destructor.          // overridden methods from subclass(es)
330      ~qsamplerDeviceParameterTable();          QVariant data(const QModelIndex &index, int role) const;
331            bool setData(const QModelIndex& index,
332                    const QVariant& value, int role = Qt::EditRole);
333    
334            void clear();
335    
336      // LSCP client descriptor accessor.  public slots:
337      void setClient(lscp_client_t *pClient);  
338      lscp_client_t * client();          void refresh(DevicePort* pPort, bool bEditable);
339    
340  private:  private:
341    
342      // LSCP client reference.          DevicePort* m_pPort;
     lscp_client_t *m_pClient;  
343  };  };
344    
345    
346    //-------------------------------------------------------------------------
347    // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
348    //
349    
350    class DeviceParamDelegate : public QItemDelegate
351    {
352            Q_OBJECT
353    
354    public:
355    
356            DeviceParamDelegate(QObject *pParent = NULL);
357    
358            QWidget* createEditor(QWidget *pParent,
359                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
360            void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
361            void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
362                    const QModelIndex& index) const;
363            void updateEditorGeometry(QWidget* pEditor,
364                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
365    };
366    
367    } // namespace QSampler
368    
369    // so we can use it i.e. through QVariant
370    Q_DECLARE_METATYPE(QSampler::DeviceParameterRow)
371    
372  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
373    
374    

Legend:
Removed from v.426  
changed lines
  Added in v.2387

  ViewVC Help
Powered by ViewVC