/[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 2059 by capela, Wed Feb 17 19:50:04 2010 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-2010, 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 <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    #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    
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,
68                  const char *pszValue = NULL);                  const char *pszValue = NULL);
69    
70      // Info structure field members.          // Info structure field members.
71      lscp_type_t type;          lscp_type_t     type;
72      QString     description;          QString         description;
73      bool        mandatory;          bool            mandatory;
74      bool        fix;          bool            fix;
75      bool        multiplicity;          bool            multiplicity;
76      QStringList depends;          QStringList depends;
77      QString     defaultv;          QString         defaultv;
78      QString     range_min;          QString         range_min;
79      QString     range_max;          QString         range_max;
80      QStringList possibilities;          QStringList possibilities;
81      // The current parameter value.          // The current parameter value.
82      QString     value;          QString         value;
83  };  };
84    
85  // A 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 QList.
89    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 { Midi, Audio };          enum DeviceType { None, Midi, Audio };
102    
103      // Constructor.          // Constructor.
104      qsamplerDevice(lscp_client_t *pClient,          Device(DeviceType deviceType, int iDeviceID = -1);
105                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
106      // Default destructor.          Device(const Device& device);
107      ~qsamplerDevice();  
108            // Default destructor.
109            ~Device();
110    
111          // Initializer.          // Initializer.
112          void setDevice(lscp_client_t *pClient,          void setDevice(DeviceType deviceType, int iDeviceID = -1);
113                  qsamplerDeviceType deviceType, int iDeviceID = -1);  
114                            // Driver name initializer.
115            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&      driverName() const;          const QString& deviceTypeName() const;
121      const QString&      deviceName() const;          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.          // Device parameters accessor.
130          qsamplerDeviceParamMap& params();          const DeviceParamMap& params() const;
131    
132          // Update/refresh device/driver data.          // Device port/channel list accessor.
133          void refresh();          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.          // 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.
166            int refreshParam(const QString& sParam);
167    
168          // Instance variables.          // Instance variables.
169      int                m_iDeviceID;          int        m_iDeviceID;
170      qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
171      QString            m_sDriverName;          QString    m_sDeviceType;
172      QString            m_sDeviceName;          QString    m_sDriverName;
173            QString    m_sDeviceName;
174    
175          // Device parameter list.          // Device parameter list.
176          qsamplerDeviceParamMap m_params;          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  // qsamplerDeviceItem - QListView device item.  // QSampler::DeviceItem - QTreeWidget device item.
225  //  //
226    
227  class qsamplerDeviceItem : public QListViewItem  class DeviceItem : public QTreeWidgetItem
228  {  {
229  public:  public:
230    
231      // Constructors.          // Constructors.
232      qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          DeviceItem(QTreeWidget *pTreeWidget,
233                  qsamplerDevice::qsamplerDeviceType deviceType);                  Device::DeviceType deviceType);
234      qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,          DeviceItem(QTreeWidgetItem *pItem,
235                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  Device::DeviceType deviceType, int iDeviceID);
     // Default destructor.  
     ~qsamplerDeviceItem();  
236    
237      // Instance accessors.          // Default destructor.
238      const qsamplerDevice& device();          ~DeviceItem();
239    
240      // To virtually distinguish between list view items.          // Instance accessors.
241      virtual int rtti() const;          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 {
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  // qsamplerDeviceParamTable - Device parameter view table.  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
260  //  //
261    
262  class qsamplerDeviceParamTable : public QTable  class AbstractDeviceParamModel : public QAbstractTableModel
263  {  {
264      Q_OBJECT          Q_OBJECT
265    
266  public:  public:
267    
268      // Constructor.          AbstractDeviceParamModel(QObject *pParent = NULL);
     qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);  
     // Default destructor.  
     ~qsamplerDeviceParamTable();  
269    
270      // Client/device descriptor selector.          // Overridden methods from subclass(es)
271          void setDevice(lscp_client_t *pClient,          int rowCount(const QModelIndex& parent = QModelIndex()) const;
272                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID = -1);          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    
     // Client/device descriptor accessors.  
         lscp_client_t *client();  
         int deviceID();  
287    
288          // The main table refresher.  //-------------------------------------------------------------------------
289          void refresh();  // 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:  private:
312    
313      // LSCP client/device references.          Device *m_pDevice;
     lscp_client_t *m_pClient;  
     qsamplerDevice::qsamplerDeviceType m_deviceType;  
     int m_iDeviceID;  
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
324    
325    public:
326    
327            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            void refresh(DevicePort* pPort, bool bEditable);
339    
340    private:
341    
342            DevicePort* m_pPort;
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.430  
changed lines
  Added in v.2059

  ViewVC Help
Powered by ViewVC