/[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 1499 by capela, Tue Nov 20 16:48:04 2007 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) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     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 34  Line 34 
34  #include <QModelIndex>  #include <QModelIndex>
35  #include <QSize>  #include <QSize>
36  #include <QList>  #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.  // Special QListViewItem::rtti() unique return value.
49  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
50    
 // Early forward declarations.  
 class qsamplerMainForm;  
 class qsamplerDevicePort;  
   
51    
52  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
53  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
54  //  //
55  class qsamplerDeviceParam  
56    class DeviceParam
57  {  {
58  public:  public:
59    
60          // Constructor.          // Constructor.
61          qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,          DeviceParam(lscp_param_info_t *pParamInfo = NULL,
62                  const char *pszValue = NULL);                  const char *pszValue = NULL);
63          // Default destructor.          // Default destructor.
64          ~qsamplerDeviceParam();          ~DeviceParam();
65    
66          // Initializer.          // Initializer.
67          void setParam(lscp_param_info_t *pParamInfo,          void setParam(lscp_param_info_t *pParamInfo,
# Line 82  public: Line 83  public:
83  };  };
84    
85  // Typedef'd parameter QMap.  // Typedef'd parameter QMap.
86  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, DeviceParam> DeviceParamMap;
87    
88  // Typedef'd device port/channels QptrList.  // Typedef'd device port/channels QList.
89  typedef QList<qsamplerDevicePort *> qsamplerDevicePortList;  typedef QList<DevicePort *> DevicePortList;
90    
91    
92  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
93  // qsamplerDevice - MIDI/Audio Device structure.  // QSampler::Device - MIDI/Audio Device structure.
94  //  //
95    
96  class qsamplerDevice  class Device
97  {  {
98  public:  public:
99    
100          // We use the same class for MIDI and audio device management          // We use the same class for MIDI and audio device management
101          enum qsamplerDeviceType { None, Midi, Audio };          enum DeviceType { None, Midi, Audio };
102    
103          // Constructor.          // Constructor.
104          qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);          Device(DeviceType deviceType, int iDeviceID = -1);
105          // Copy constructor.          // Copy constructor.
106      qsamplerDevice(const qsamplerDevice& device);          Device(const Device& device);
107    
108          // Default destructor.          // Default destructor.
109          ~qsamplerDevice();          ~Device();
110    
111          // Initializer.          // Initializer.
112          void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);          void setDevice(DeviceType deviceType, int iDeviceID = -1);
113    
114          // Driver name initializer.          // Driver name initializer.
115          void setDriver(const QString& sDriverName);          void setDriver(const QString& sDriverName);
116    
117          // Device property accessors.          // Device property accessors.
118          int                 deviceID()   const;          int            deviceID() const;
119          qsamplerDeviceType  deviceType() const;          DeviceType     deviceType() const;
120          const QString&      deviceTypeName() const;          const QString& deviceTypeName() const;
121          const QString&      driverName() const;          const QString& driverName() const;
122    
123          // Special device name formatter.          // Special device name formatter.
124          QString deviceName() const;          QString deviceName() const;
125    
# Line 124  public: Line 127  public:
127          bool setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
128    
129          // Device parameters accessor.          // Device parameters accessor.
130          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
131    
132          // Device port/channel list accessor.          // Device port/channel list accessor.
133          qsamplerDevicePortList& ports();          DevicePortList& ports();
134    
135          // Device parameter dependency list refreshner.          // Device parameter dependency list refreshner.
136          int refreshParams();          int refreshParams();
# Line 149  public: Line 152  public:
152    
153          // Device ids enumerator.          // Device ids enumerator.
154          static int *getDevices(lscp_client_t *pClient,          static int *getDevices(lscp_client_t *pClient,
155                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
156            static std::set<int> getDeviceIDs(lscp_client_t *pClient,
157                    DeviceType deviceType);
158    
159          // Driver names enumerator.          // Driver names enumerator.
160          static QStringList getDrivers(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
161                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
162    
163  private:  private:
164    
165          // Refresh/set given parameter based on driver supplied dependencies.          // Refresh/set given parameter based on driver supplied dependencies.
166          int refreshParam(const QString& sParam);          int refreshParam(const QString& sParam);
167    
         // Main application form reference.  
         qsamplerMainForm  *m_pMainForm;  
   
168          // Instance variables.          // Instance variables.
169          int                m_iDeviceID;          int        m_iDeviceID;
170          qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
171          QString            m_sDeviceType;          QString    m_sDeviceType;
172          QString            m_sDriverName;          QString    m_sDriverName;
173          QString            m_sDeviceName;          QString    m_sDeviceName;
174    
175          // Device parameter list.          // Device parameter list.
176          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
177    
178          // Device port/channel list.          // Device port/channel list.
179          qsamplerDevicePortList m_ports;          DevicePortList m_ports;
180  };  };
181    
182    
183  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
184  // qsamplerDevicePort - MIDI/Audio Device port/channel structure.  // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
185  //  //
186    
187  class qsamplerDevicePort  class DevicePort
188  {  {
189  public:  public:
190    
191          // Constructor.          // Constructor.
192          qsamplerDevicePort(qsamplerDevice& device, int iPortID);          DevicePort(Device& device, int iPortID);
193          // Default destructor.          // Default destructor.
194          ~qsamplerDevicePort();          ~DevicePort();
195    
196          // Initializer.          // Initializer.
197          void setDevicePort(int iPortID);          void setDevicePort(int iPortID);
# Line 199  public: Line 201  public:
201          const QString& portName() const;          const QString& portName() const;
202    
203          // Device port parameters accessor.          // Device port parameters accessor.
204          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
205    
206          // Set the proper device port/channel parameter value.          // Set the proper device port/channel parameter value.
207          bool setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
# Line 207  public: Line 209  public:
209  private:  private:
210    
211          // Device reference.          // Device reference.
212          qsamplerDevice& m_device;          Device& m_device;
213    
214          // Instance variables.          // Instance variables.
215          int     m_iPortID;          int     m_iPortID;
216          QString m_sPortName;          QString m_sPortName;
217    
218          // Device port parameter list.          // Device port parameter list.
219          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
220  };  };
221    
222    
223  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
224  // qsamplerDeviceItem - QListView device item.  // QSampler::DeviceItem - QTreeWidget device item.
225  //  //
226    
227  class qsamplerDeviceItem : public QTreeWidgetItem  class DeviceItem : public QTreeWidgetItem
228  {  {
229  public:  public:
230    
231          // Constructors.          // Constructors.
232          qsamplerDeviceItem(QTreeWidget* pTreeWidget,          DeviceItem(QTreeWidget *pTreeWidget,
233                  qsamplerDevice::qsamplerDeviceType deviceType);                  Device::DeviceType deviceType);
234          qsamplerDeviceItem(QTreeWidgetItem* pItem,          DeviceItem(QTreeWidgetItem *pItem,
235                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  Device::DeviceType deviceType, int iDeviceID);
236    
237          // Default destructor.          // Default destructor.
238          ~qsamplerDeviceItem();          ~DeviceItem();
239    
240          // Instance accessors.          // Instance accessors.
241          qsamplerDevice& device();          Device& device();
242    
243  private:  private:
244    
245          // Instance variables.          // Instance variables.
246          qsamplerDevice m_device;          Device m_device;
247  };  };
248    
249    
250  struct DeviceParameterRow {  struct DeviceParameterRow {
251      QString             name;          QString     name;
252      qsamplerDeviceParam param;          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    
 // so we can use it i.e. through QVariant  
 Q_DECLARE_METATYPE(DeviceParameterRow)  
257    
258  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
259  // AbstractDeviceParamModel - data model base class for device parameters  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
260  //  //
261  class AbstractDeviceParamModel : public QAbstractTableModel {  
262          Q_OBJECT  class AbstractDeviceParamModel : public QAbstractTableModel
263      public:  {
264          AbstractDeviceParamModel(QObject* parent = 0);          Q_OBJECT
265    
266          // overridden methods from subclass(es)  public:
267          int rowCount(const QModelIndex& parent = QModelIndex()) const;  
268          int columnCount(const QModelIndex& parent = QModelIndex() ) const;          AbstractDeviceParamModel(QObject *pParent = NULL);
269          QVariant data(const QModelIndex &index, int role) const;  
270          QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;          // Overridden methods from subclass(es)
271          Qt::ItemFlags flags(const QModelIndex& index) const;          int rowCount(const QModelIndex& parent = QModelIndex()) const;
272            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
273          virtual void clear();          QVariant headerData(int section,
274                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
275          void refresh(const qsamplerDeviceParamMap* params, bool bEditable);          Qt::ItemFlags flags(const QModelIndex& index) const;
276    
277      protected:          virtual void clear();
278          const qsamplerDeviceParamMap* params;  
279          bool bEditable;          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  // DeviceParamModel - data model for device parameters (used for QTableView)  // QSampler::DeviceParamModel - data model for device parameters
290  //  //                              (used for QTableView)
291  class DeviceParamModel : public AbstractDeviceParamModel {  
292          Q_OBJECT  class DeviceParamModel : public AbstractDeviceParamModel
293      public:  {
294          DeviceParamModel(QObject* parent = 0);          Q_OBJECT
295    
296          // overridden methods from subclass(es)  public:
297          bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);  
298          void clear();          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      public slots:          void clear();
         void refresh(qsamplerDevice* pDevice, bool bEditable);  
306    
307      private:  public slots:
308          qsamplerDevice* device;  
309            void refresh(Device* pDevice, bool bEditable);
310    
311    private:
312    
313            Device *m_pDevice;
314  };  };
315    
316    
317  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
318  // PortParamModel - data model for port parameters (used for QTableView)  // QSampler::PortParamModel - data model for port parameters
319  //  //                            (used for QTableView)
320  class PortParamModel : public AbstractDeviceParamModel {  
321          Q_OBJECT  class PortParamModel : public AbstractDeviceParamModel
322      public:  {
323          PortParamModel(QObject* parent = 0);          Q_OBJECT
324    
325          // overridden methods from subclass(es)  public:
326          bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);  
327          void clear();          PortParamModel(QObject *pParent = 0);
328    
329            // overridden methods from subclass(es)
330            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    public slots:
337    
338      public slots:          void refresh(DevicePort* pPort, bool bEditable);
         void refresh(qsamplerDevicePort* pPort, bool bEditable);  
339    
340      private:  private:
341          qsamplerDevicePort* port;  
342            DevicePort* m_pPort;
343  };  };
344    
345    
346  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
347  // DeviceParamDelegate - table cell renderer for device/port parameters  // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
348  //  //
349  class DeviceParamDelegate : public QItemDelegate {  
350          Q_OBJECT  class DeviceParamDelegate : public QItemDelegate
351      public:  {
352          DeviceParamDelegate(QObject* parent = 0);          Q_OBJECT
353          QWidget* createEditor(QWidget* parent,  
354                                const QStyleOptionViewItem& option,  public:
355                                const QModelIndex& index) const;  
356          void setEditorData(QWidget* editor, const QModelIndex& index) const;          DeviceParamDelegate(QObject *pParent = NULL);
357          void setModelData(QWidget* editor, QAbstractItemModel* model,  
358                            const QModelIndex& index) const;          QWidget* createEditor(QWidget *pParent,
359          void updateEditorGeometry(QWidget* editor,                  const QStyleOptionViewItem& option, const QModelIndex& index) const;
360                                    const QStyleOptionViewItem& option,          void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
361                                    const QModelIndex& index) const;          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    
375  // end of qsamplerDevice.h  // end of qsamplerDevice.h

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

  ViewVC Help
Powered by ViewVC