/[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 429 by capela, Tue Mar 8 14:56:05 2005 UTC revision 1461 by schoenebeck, Sun Oct 28 23:30:36 2007 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-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     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 13 
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15    
16     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
17     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19    
20  *****************************************************************************/  *****************************************************************************/
21    
22  #ifndef __qsamplerDevice_h  #ifndef __qsamplerDevice_h
23  #define __qsamplerDevice_h  #define __qsamplerDevice_h
24    
25  #include <qlistview.h>  #include <QListWidget>
26  #include <qtable.h>  #include <QListWidgetItem>
27    #include <QTreeWidgetItem>
28    #include <QTableWidget>
29    #include <QTableWidgetItem>
30    #include <QAbstractTableModel>
31    #include <QMetaType>
32    #include <QItemDelegate>
33    #include <QFontMetrics>
34    #include <QModelIndex>
35    #include <QSize>
36    #include <QList>
37    #include <Q3PtrList>
38    
39  #include <lscp/client.h>  #include <lscp/client.h>
40  #include <lscp/device.h>  #include <lscp/device.h>
# Line 31  Line 42 
42  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
43    
44    
45  // Special QListViewItem::rtti() return values.  // Special QListViewItem::rtti() unique return value.
46  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
47    
48    // Early forward declarations.
49    class qsamplerMainForm;
50    class qsamplerDevicePort;
51    
52    
53  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
54  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
# Line 42  class qsamplerDeviceParam Line 57  class qsamplerDeviceParam
57  {  {
58  public:  public:
59    
60      // Constructor.          // Constructor.
61      qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,          qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,
62                  const char *pszValue = NULL);                  const char *pszValue = NULL);
63      // Default destructor.          // Default destructor.
64      ~qsamplerDeviceParam();          ~qsamplerDeviceParam();
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, qsamplerDeviceParam> qsamplerDeviceParamMap;
87    
88    // Typedef'd device port/channels QptrList.
89    typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList;
90    
91    
92  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
93  // qsamplerDevice - MIDI/Audio Device structure.  // qsamplerDevice - MIDI/Audio Device structure.
# Line 79  class qsamplerDevice Line 97  class qsamplerDevice
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 qsamplerDeviceType { None, Midi, Audio };
102    
103      // Constructor.          // Constructor.
104      qsamplerDevice(lscp_client_t *pClient,          qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
105                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
106      // Default destructor.      qsamplerDevice(const qsamplerDevice& device);
107      ~qsamplerDevice();          // Default destructor.
108            ~qsamplerDevice();
109    
110          // Initializer.          // Initializer.
111          void setDevice(lscp_client_t *pClient,          void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
112                  qsamplerDeviceType deviceType, int iDeviceID = -1);  
113                            // Driver name initializer.
114            void setDriver(const QString& sDriverName);
115    
116          // Device property accessors.          // Device property accessors.
117      int                 deviceID()   const;          int                 deviceID()   const;
118      qsamplerDeviceType  deviceType() const;          qsamplerDeviceType  deviceType() const;
119      const QString&      driverName() const;          const QString&      deviceTypeName() const;
120      const QString&      deviceName() const;          const QString&      driverName() const;
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.
152            static int *getDevices(lscp_client_t *pClient,
153                    qsamplerDeviceType deviceType);
154    
155          // Device enumerator.          // Driver names enumerator.
156      static int *getDevices(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
157                  qsamplerDeviceType deviceType);                  qsamplerDeviceType deviceType);
158    
159  private:  private:
160    
161            // Refresh/set given parameter based on driver supplied dependencies.
162            int refreshParam(const QString& sParam);
163    
164            // Main application form reference.
165            qsamplerMainForm  *m_pMainForm;
166    
167          // Instance variables.          // Instance variables.
168      int                m_iDeviceID;          int                m_iDeviceID;
169      qsamplerDeviceType m_deviceType;          qsamplerDeviceType m_deviceType;
170      QString            m_sDriverName;          QString            m_sDeviceType;
171      QString            m_sDeviceName;          QString            m_sDriverName;
172            QString            m_sDeviceName;
173    
174          // Device parameter list.          // Device parameter list.
175          qsamplerDeviceParamMap m_params;          qsamplerDeviceParamMap m_params;
176    
177            // Device port/channel list.
178            qsamplerDevicePortList m_ports;
179    };
180    
181    
182    //-------------------------------------------------------------------------
183    // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
184    //
185    
186    class qsamplerDevicePort
187    {
188    public:
189    
190            // Constructor.
191            qsamplerDevicePort(qsamplerDevice& device, int iPortID);
192            // Default destructor.
193            ~qsamplerDevicePort();
194    
195            // Initializer.
196            void setDevicePort(int iPortID);
197    
198            // Device port property accessors.
199            int            portID()   const;
200            const QString& portName() const;
201    
202            // Device port parameters accessor.
203            const qsamplerDeviceParamMap& params() const;
204    
205            // Set the proper device port/channel parameter value.
206            bool setParam (const QString& sParam, const QString& sValue);
207    
208    private:
209    
210            // Device reference.
211            qsamplerDevice& m_device;
212    
213            // Instance variables.
214            int     m_iPortID;
215            QString m_sPortName;
216    
217            // Device port parameter list.
218            qsamplerDeviceParamMap m_params;
219  };  };
220    
221    
# Line 125  private: Line 223  private:
223  // qsamplerDeviceItem - QListView device item.  // qsamplerDeviceItem - QListView device item.
224  //  //
225    
226  class qsamplerDeviceItem : public QListViewItem  class qsamplerDeviceItem : public QTreeWidgetItem
227  {  {
228  public:  public:
229    
230      // Constructors.          // Constructors.
231      qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          qsamplerDeviceItem(QTreeWidget* pTreeWidget,
232                  qsamplerDevice::qsamplerDeviceType deviceType);                  qsamplerDevice::qsamplerDeviceType deviceType);
233      qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,          qsamplerDeviceItem(QTreeWidgetItem* pItem,
234                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);
235      // Default destructor.          // Default destructor.
236      ~qsamplerDeviceItem();          ~qsamplerDeviceItem();
   
     // Instance accessors.  
     const qsamplerDevice& device();  
237    
238      // To virtually distinguish between list view items.          // Instance accessors.
239      virtual int rtti() const;          qsamplerDevice& device();
240    
241  private:  private:
242    
243      // Instance variables.          // Instance variables.
244      qsamplerDevice m_device;          qsamplerDevice m_device;
245  };  };
246    
247    
# Line 154  private: Line 249  private:
249  // qsamplerDeviceParamTable - Device parameter view table.  // qsamplerDeviceParamTable - Device parameter view table.
250  //  //
251    
252    #if 0
253  class qsamplerDeviceParamTable : public QTable  class qsamplerDeviceParamTable : public QTable
254  {  {
255      Q_OBJECT          Q_OBJECT
256    
257  public:  public:
258    
259      // Constructor.          // Constructor.
260      qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);          qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);
261      // Default destructor.          // Default destructor.
262      ~qsamplerDeviceParamTable();          ~qsamplerDeviceParamTable();
263    
264            // Common parameter table renderer.
265            void refresh(const qsamplerDeviceParamMap& params, bool bEditable);
266    };
267    #endif
268    
269      // Client/device descriptor selector.  struct DeviceParameterRow {
270          void setDevice(lscp_client_t *pClient,      QString             name;
271                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID = -1);      qsamplerDeviceParam param;
272    };
273    
274      // Client/device descriptor accessors.  // so we can use it i.e. through QVariant
275          lscp_client_t *client();  Q_DECLARE_METATYPE(DeviceParameterRow)
276          int deviceID();  
277    class DeviceParamModel : public QAbstractTableModel {
278            Q_OBJECT
279        public:
280            DeviceParamModel(QObject* parent = 0);
281    
282            // overridden methods from subclass(es)
283            int rowCount(const QModelIndex &parent) const;
284            int columnCount(const QModelIndex &parent) const;
285            QVariant data(const QModelIndex &index, int role) const;
286            QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
287    
288            void clear();
289    
290        public slots:
291            void refresh(const qsamplerDeviceParamMap& params, bool bEditable);
292    
293        private:
294            qsamplerDeviceParamMap params;
295            bool bEditable;
296    };
297    
298    class DeviceParamDelegate : public QItemDelegate {
299            Q_OBJECT
300        public:
301            DeviceParamDelegate(QObject* parent = 0);
302    
303            QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
304                                  const QModelIndex& index) const;
305    
306            void setEditorData(QWidget* editor, const QModelIndex& index) const;
307            void setModelData(QWidget* editor, QAbstractItemModel* model,
308                              const QModelIndex& index) const;
309    
310            void updateEditorGeometry(QWidget* editor,
311                const QStyleOptionViewItem& option, const QModelIndex& index) const;
312    };
313    
314    
315    //-------------------------------------------------------------------------
316    // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.
317    //
318    
319    #if 0
320    class qsamplerDeviceParamTableSpinBox : public QTableWidgetItem
321    {
322    public:
323    
324            // Constructor.
325            qsamplerDeviceParamTableSpinBox (QTableWidget *pTable, Qt::ItemFlags flags,
326                    const QString& sText);
327    
328            // Public accessors.
329            void setMinValue(int iMinValue);
330            void setMaxValue(int iMaxValue);
331            void setValue(int iValue);
332    
333    protected:
334    
335            // Virtual implemetations.
336            QWidget *createEditor() const;
337            void setContentFromEditor(QWidget *pWidget);
338    
         // The main table refresher.  
         void refresh();  
           
339  private:  private:
340    
341      // LSCP client/device references.          // Initial value holders.
342      lscp_client_t *m_pClient;          int m_iValue;
343      qsamplerDevice::qsamplerDeviceType m_deviceType;          int m_iMinValue;
344      int m_iDeviceID;          int m_iMaxValue;
345  };  };
346    
347    
348    //-------------------------------------------------------------------------
349    // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.
350    //
351    
352    class qsamplerDeviceParamTableEditBox : public QTableWidgetItem
353    {
354    public:
355    
356            // Constructor.
357            qsamplerDeviceParamTableEditBox (QTableWidget *pTable, Qt::ItemFlags flags,
358                    const QString& sText);
359    
360    protected:
361    
362            // Virtual implemetations.
363            QWidget *createEditor() const;
364            void setContentFromEditor(QWidget *pWidget);
365    };
366    #endif
367    
368  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
369    
370    

Legend:
Removed from v.429  
changed lines
  Added in v.1461

  ViewVC Help
Powered by ViewVC