/[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 430 by capela, Tue Mar 8 17:23:29 2005 UTC revision 1509 by capela, Thu Nov 22 11:10:44 2007 UTC
# Line 1  Line 1 
1  // qsamplerDevice.h  // qsamplerDevice.h
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, 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 <qlistview.h>  #include <QListWidget>
27  #include <qtable.h>  #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    
38  #include <lscp/client.h>  #include <lscp/client.h>
39  #include <lscp/device.h>  #include <lscp/device.h>
# Line 34  Line 44 
44  // Special QListViewItem::rtti() unique return value.  // Special QListViewItem::rtti() unique return value.
45  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
46    
47    // Early forward declarations.
48    class qsamplerMainForm;
49    class qsamplerDevicePort;
50    
51    
52  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
53  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
# Line 42  class qsamplerDeviceParam Line 56  class qsamplerDeviceParam
56  {  {
57  public:  public:
58    
59      // Constructor.          // Constructor.
60      qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,          qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,
61                  const char *pszValue = NULL);                  const char *pszValue = NULL);
62      // Default destructor.          // Default destructor.
63      ~qsamplerDeviceParam();          ~qsamplerDeviceParam();
64    
65          // Initializer.          // Initializer.
66          void setParam(lscp_param_info_t *pParamInfo,          void setParam(lscp_param_info_t *pParamInfo,
67                  const char *pszValue = NULL);                  const char *pszValue = NULL);
68    
69      // Info structure field members.          // Info structure field members.
70      lscp_type_t type;          lscp_type_t     type;
71      QString     description;          QString         description;
72      bool        mandatory;          bool            mandatory;
73      bool        fix;          bool            fix;
74      bool        multiplicity;          bool            multiplicity;
75      QStringList depends;          QStringList depends;
76      QString     defaultv;          QString         defaultv;
77      QString     range_min;          QString         range_min;
78      QString     range_max;          QString         range_max;
79      QStringList possibilities;          QStringList possibilities;
80      // The current parameter value.          // The current parameter value.
81      QString     value;          QString         value;
82  };  };
83    
84  // A typedef'd parameter QMap.  // Typedef'd parameter QMap.
85  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
86    
87    // Typedef'd device port/channels QptrList.
88    typedef QList<qsamplerDevicePort *> qsamplerDevicePortList;
89    
90    
91  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
92  // qsamplerDevice - MIDI/Audio Device structure.  // qsamplerDevice - MIDI/Audio Device structure.
# Line 79  class qsamplerDevice Line 96  class qsamplerDevice
96  {  {
97  public:  public:
98    
99      // We use the same class for MIDI and audio device management          // We use the same class for MIDI and audio device management
100      enum qsamplerDeviceType { Midi, Audio };          enum DeviceType { None, Midi, Audio };
101    
102      // Constructor.          // Constructor.
103      qsamplerDevice(lscp_client_t *pClient,          qsamplerDevice(DeviceType deviceType, int iDeviceID = -1);
104                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
105      // Default destructor.          qsamplerDevice(const qsamplerDevice& device);
106      ~qsamplerDevice();          // Default destructor.
107            ~qsamplerDevice();
108    
109          // Initializer.          // Initializer.
110          void setDevice(lscp_client_t *pClient,          void setDevice(DeviceType deviceType, int iDeviceID = -1);
111                  qsamplerDeviceType deviceType, int iDeviceID = -1);  
112                            // Driver name initializer.
113            void setDriver(const QString& sDriverName);
114    
115          // Device property accessors.          // Device property accessors.
116      int                 deviceID()   const;          int            deviceID() const;
117      qsamplerDeviceType  deviceType() const;          DeviceType     deviceType() const;
118      const QString&      driverName() const;          const QString& deviceTypeName() const;
119      const QString&      deviceName() const;          const QString& driverName() const;
120    
121            // Special device name formatter.
122            QString deviceName() const;
123    
124            // Set the proper device parameter value.
125            bool setParam (const QString& sParam, const QString& sValue);
126    
127          // Device parameters accessor.          // Device parameters accessor.
128          qsamplerDeviceParamMap& params();          const qsamplerDeviceParamMap& params() const;
129    
130            // Device port/channel list accessor.
131            qsamplerDevicePortList& ports();
132    
133          // Update/refresh device/driver data.          // Device parameter dependency list refreshner.
134          void refresh();          int refreshParams();
135            // Device port/channel list refreshner.
136            int refreshPorts();
137            // Refresh/set dependencies given that some parameter has changed.
138            int refreshDepends(const QString& sParam);
139    
140            // 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            void appendMessagesColor  (const QString& s, const QString & c) const;
147            void appendMessagesText   (const QString& s) const;
148            void appendMessagesError  (const QString& s) const;
149            void appendMessagesClient (const QString& s) const;
150    
151          // Device ids enumerator.          // Device ids enumerator.
152      static int *getDevices(lscp_client_t *pClient,          static int *getDevices(lscp_client_t *pClient,
153                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
154    
155          // Driver names enumerator.          // Driver names enumerator.
156      static QStringList getDrivers(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
157                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
158    
159  private:  private:
160    
161            // Refresh/set given parameter based on driver supplied dependencies.
162            int refreshParam(const QString& sParam);
163    
164          // Instance variables.          // Instance variables.
165      int                m_iDeviceID;          int        m_iDeviceID;
166      qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
167      QString            m_sDriverName;          QString    m_sDeviceType;
168      QString            m_sDeviceName;          QString    m_sDriverName;
169            QString    m_sDeviceName;
170    
171          // Device parameter list.          // Device parameter list.
172          qsamplerDeviceParamMap m_params;          qsamplerDeviceParamMap m_params;
173    
174            // Device port/channel list.
175            qsamplerDevicePortList m_ports;
176    };
177    
178    
179    //-------------------------------------------------------------------------
180    // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
181    //
182    
183    class qsamplerDevicePort
184    {
185    public:
186    
187            // Constructor.
188            qsamplerDevicePort(qsamplerDevice& device, int iPortID);
189            // Default destructor.
190            ~qsamplerDevicePort();
191    
192            // Initializer.
193            void setDevicePort(int iPortID);
194    
195            // Device port property accessors.
196            int            portID()   const;
197            const QString& portName() const;
198    
199            // Device port parameters accessor.
200            const qsamplerDeviceParamMap& params() const;
201    
202            // Set the proper device port/channel parameter value.
203            bool setParam (const QString& sParam, const QString& sValue);
204    
205    private:
206    
207            // Device reference.
208            qsamplerDevice& m_device;
209    
210            // Instance variables.
211            int     m_iPortID;
212            QString m_sPortName;
213    
214            // Device port parameter list.
215            qsamplerDeviceParamMap m_params;
216  };  };
217    
218    
# Line 129  private: Line 220  private:
220  // qsamplerDeviceItem - QListView device item.  // qsamplerDeviceItem - QListView device item.
221  //  //
222    
223  class qsamplerDeviceItem : public QListViewItem  class qsamplerDeviceItem : public QTreeWidgetItem
224    {
225    public:
226    
227            // Constructors.
228            qsamplerDeviceItem(QTreeWidget *pTreeWidget,
229                    qsamplerDevice::DeviceType deviceType);
230            qsamplerDeviceItem(QTreeWidgetItem *pItem,
231                    qsamplerDevice::DeviceType deviceType, int iDeviceID);
232            // Default destructor.
233            ~qsamplerDeviceItem();
234    
235            // Instance accessors.
236            qsamplerDevice& device();
237    
238    private:
239    
240            // Instance variables.
241            qsamplerDevice m_device;
242    };
243    
244    struct DeviceParameterRow {
245            QString             name;
246            qsamplerDeviceParam param;
247            bool                alive; // whether these params refer to an existing device or for a device that is yet to be created
248    };
249    
250    // so we can use it i.e. through QVariant
251    Q_DECLARE_METATYPE(DeviceParameterRow)
252    
253    
254    //-------------------------------------------------------------------------
255    // AbstractDeviceParamModel - data model base class for device parameters
256    //
257    class AbstractDeviceParamModel : public QAbstractTableModel
258    {
259            Q_OBJECT
260    
261    public:
262    
263            AbstractDeviceParamModel(QObject *pParent = NULL);
264    
265            // Overridden methods from subclass(es)
266            int rowCount(const QModelIndex& parent = QModelIndex()) const;
267            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
268            QVariant headerData(int section,
269                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
270            Qt::ItemFlags flags(const QModelIndex& index) const;
271    
272            virtual void clear();
273    
274            void refresh(const qsamplerDeviceParamMap* params, bool bEditable);
275    
276    protected:
277    
278            const qsamplerDeviceParamMap *m_params;
279            bool m_bEditable;
280    };
281    
282    
283    //-------------------------------------------------------------------------
284    // DeviceParamModel - data model for device parameters (used for QTableView)
285    //
286    
287    class DeviceParamModel : public AbstractDeviceParamModel
288  {  {
289            Q_OBJECT
290    
291  public:  public:
292    
293      // Constructors.          DeviceParamModel(QObject *pParent = NULL);
     qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,  
                 qsamplerDevice::qsamplerDeviceType deviceType);  
     qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,  
                 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);  
     // Default destructor.  
     ~qsamplerDeviceItem();  
294    
295      // Instance accessors.          // Overridden methods from subclass(es)
296      const qsamplerDevice& device();          QVariant data(const QModelIndex &index, int role) const;
297            bool setData(const QModelIndex& index,
298                    const QVariant& value, int role = Qt::EditRole);
299    
300      // To virtually distinguish between list view items.          void clear();
301      virtual int rtti() const;  
302    public slots:
303    
304            void refresh(qsamplerDevice* pDevice, bool bEditable);
305    
306  private:  private:
307    
308      // Instance variables.          qsamplerDevice *m_device;
     qsamplerDevice m_device;  
309  };  };
310    
311    
312  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
313  // qsamplerDeviceParamTable - Device parameter view table.  // PortParamModel - data model for port parameters (used for QTableView)
314  //  //
315    
316  class qsamplerDeviceParamTable : public QTable  class PortParamModel : public AbstractDeviceParamModel
317  {  {
318      Q_OBJECT          Q_OBJECT
319    
320  public:  public:
321    
322      // Constructor.          PortParamModel(QObject *pParent = 0);
323      qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);  
324      // Default destructor.          // overridden methods from subclass(es)
325      ~qsamplerDeviceParamTable();          QVariant data(const QModelIndex &index, int role) const;
326            bool setData(const QModelIndex& index,
327                    const QVariant& value, int role = Qt::EditRole);
328    
329      // Client/device descriptor selector.          void clear();
         void setDevice(lscp_client_t *pClient,  
                 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID = -1);  
330    
331      // Client/device descriptor accessors.  public slots:
332          lscp_client_t *client();  
333          int deviceID();          void refresh(qsamplerDevicePort* pPort, bool bEditable);
334    
         // The main table refresher.  
         void refresh();  
           
335  private:  private:
336    
337      // LSCP client/device references.          qsamplerDevicePort* m_port;
     lscp_client_t *m_pClient;  
     qsamplerDevice::qsamplerDeviceType m_deviceType;  
     int m_iDeviceID;  
338  };  };
339    
340    
341  #endif  // __qsamplerDevice_h  //-------------------------------------------------------------------------
342    // DeviceParamDelegate - table cell renderer for device/port parameters
343    //
344    class DeviceParamDelegate : public QItemDelegate
345    {
346            Q_OBJECT
347    
348    public:
349    
350            DeviceParamDelegate(QObject *pParent = NULL);
351    
352            QWidget* createEditor(QWidget *pParent,
353                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
354            void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
355            void setModelData(QWidget *pEditor, QAbstractItemModel* model,
356                    const QModelIndex& index) const;
357            void updateEditorGeometry(QWidget* pEditor,
358                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
359    };
360    
361    #endif  // __qsamplerDevice_h
362    
363  // end of qsamplerDevice.h  // end of qsamplerDevice.h

Legend:
Removed from v.430  
changed lines
  Added in v.1509

  ViewVC Help
Powered by ViewVC