/[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 1464 by capela, Thu Nov 1 17:14:21 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       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 <QMetaType>
33    #include <QItemDelegate>
34    #include <QFontMetrics>
35    #include <QModelIndex>
36    #include <QSize>
37    #include <QList>
38    #include <Q3PtrList>
39    
40  #include <lscp/client.h>  #include <lscp/client.h>
41  #include <lscp/device.h>  #include <lscp/device.h>
# Line 31  Line 43 
43  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
44    
45    
46  // Special QListViewItem::rtti() return values.  // Special QListViewItem::rtti() unique return value.
47  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
48    
49    // Early forward declarations.
50    class qsamplerMainForm;
51    class qsamplerDevicePort;
52    
53    
54  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
55  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
# Line 42  class qsamplerDeviceParam Line 58  class qsamplerDeviceParam
58  {  {
59  public:  public:
60    
61      // Constructor.          // Constructor.
62      qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,          qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,
63                  const char *pszValue = NULL);                  const char *pszValue = NULL);
64      // Default destructor.          // Default destructor.
65      ~qsamplerDeviceParam();          ~qsamplerDeviceParam();
66    
67          // Initializer.          // Initializer.
68          void setParam(lscp_param_info_t *pParamInfo,          void setParam(lscp_param_info_t *pParamInfo,
69                  const char *pszValue = NULL);                  const char *pszValue = NULL);
70    
71      // Info structure field members.          // Info structure field members.
72      lscp_type_t type;          lscp_type_t     type;
73      QString     description;          QString         description;
74      bool        mandatory;          bool            mandatory;
75      bool        fix;          bool            fix;
76      bool        multiplicity;          bool            multiplicity;
77      QStringList depends;          QStringList depends;
78      QString     defaultv;          QString         defaultv;
79      QString     range_min;          QString         range_min;
80      QString     range_max;          QString         range_max;
81      QStringList possibilities;          QStringList possibilities;
82      // The current parameter value.          // The current parameter value.
83      QString     value;          QString         value;
84  };  };
85    
86  // A typedef'd parameter QMap.  // Typedef'd parameter QMap.
87  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
88    
89    // Typedef'd device port/channels QptrList.
90    typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList;
91    
92    
93  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
94  // qsamplerDevice - MIDI/Audio Device structure.  // qsamplerDevice - MIDI/Audio Device structure.
# Line 79  class qsamplerDevice Line 98  class qsamplerDevice
98  {  {
99  public:  public:
100    
101      // We use the same class for MIDI and audio device management          // We use the same class for MIDI and audio device management
102      enum qsamplerDeviceType { Midi, Audio };          enum qsamplerDeviceType { None, Midi, Audio };
103    
104      // Constructor.          // Constructor.
105      qsamplerDevice(lscp_client_t *pClient,          qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
106                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
107      // Default destructor.      qsamplerDevice(const qsamplerDevice& device);
108      ~qsamplerDevice();          // Default destructor.
109            ~qsamplerDevice();
110    
111          // Initializer.          // Initializer.
112          void setDevice(lscp_client_t *pClient,          void setDevice(qsamplerDeviceType 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;          qsamplerDeviceType  deviceType() const;
120      const QString&      driverName() const;          const QString&      deviceTypeName() const;
121      const QString&      deviceName() const;          const QString&      driverName() const;
122            // Special device name formatter.
123            QString deviceName() const;
124    
125            // Set the proper device parameter value.
126            bool setParam (const QString& sParam, const QString& sValue);
127    
128          // Device parameters accessor.          // Device parameters accessor.
129          qsamplerDeviceParamMap& params();          const qsamplerDeviceParamMap& params() const;
130    
131            // Device port/channel list accessor.
132            qsamplerDevicePortList& ports();
133    
134          // Update/refresh device/driver data.          // Device parameter dependency list refreshner.
135          void refresh();          int refreshParams();
136            // Device port/channel list refreshner.
137            int refreshPorts();
138            // Refresh/set dependencies given that some parameter has changed.
139            int refreshDepends(const QString& sParam);
140    
141            // Create/destroy device methods.
142            bool createDevice();
143            bool deleteDevice();
144    
145            // Message logging methods (brainlessly mapped to main form's).
146            void appendMessages       (const QString& s) const;
147            void appendMessagesColor  (const QString& s, const QString & c) const;
148            void appendMessagesText   (const QString& s) const;
149            void appendMessagesError  (const QString& s) const;
150            void appendMessagesClient (const QString& s) const;
151    
152            // Device ids enumerator.
153            static int *getDevices(lscp_client_t *pClient,
154                    qsamplerDeviceType deviceType);
155    
156          // Device enumerator.          // Driver names enumerator.
157      static int *getDevices(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
158                  qsamplerDeviceType deviceType);                  qsamplerDeviceType deviceType);
159    
160  private:  private:
161    
162            // Refresh/set given parameter based on driver supplied dependencies.
163            int refreshParam(const QString& sParam);
164    
165            // Main application form reference.
166            qsamplerMainForm  *m_pMainForm;
167    
168          // Instance variables.          // Instance variables.
169      int                m_iDeviceID;          int                m_iDeviceID;
170      qsamplerDeviceType m_deviceType;          qsamplerDeviceType 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;          qsamplerDeviceParamMap m_params;
177    
178            // Device port/channel list.
179            qsamplerDevicePortList m_ports;
180    };
181    
182    
183    //-------------------------------------------------------------------------
184    // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
185    //
186    
187    class qsamplerDevicePort
188    {
189    public:
190    
191            // Constructor.
192            qsamplerDevicePort(qsamplerDevice& device, int iPortID);
193            // Default destructor.
194            ~qsamplerDevicePort();
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 qsamplerDeviceParamMap& 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            qsamplerDevice& m_device;
213    
214            // Instance variables.
215            int     m_iPortID;
216            QString m_sPortName;
217    
218            // Device port parameter list.
219            qsamplerDeviceParamMap m_params;
220  };  };
221    
222    
# Line 125  private: Line 224  private:
224  // qsamplerDeviceItem - QListView device item.  // qsamplerDeviceItem - QListView device item.
225  //  //
226    
227  class qsamplerDeviceItem : public QListViewItem  class qsamplerDeviceItem : public QTreeWidgetItem
228  {  {
229  public:  public:
230    
231      // Constructors.          // Constructors.
232      qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          qsamplerDeviceItem(QTreeWidget* pTreeWidget,
233                  qsamplerDevice::qsamplerDeviceType deviceType);                  qsamplerDevice::qsamplerDeviceType deviceType);
234      qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,          qsamplerDeviceItem(QTreeWidgetItem* pItem,
235                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);
236      // Default destructor.          // Default destructor.
237      ~qsamplerDeviceItem();          ~qsamplerDeviceItem();
   
     // Instance accessors.  
     const qsamplerDevice& device();  
238    
239      // To virtually distinguish between list view items.          // Instance accessors.
240      virtual int rtti() const;          qsamplerDevice& device();
241    
242  private:  private:
243    
244      // Instance variables.          // Instance variables.
245      qsamplerDevice m_device;          qsamplerDevice m_device;
246  };  };
247    
248    
# Line 154  private: Line 250  private:
250  // qsamplerDeviceParamTable - Device parameter view table.  // qsamplerDeviceParamTable - Device parameter view table.
251  //  //
252    
253    #if 0
254  class qsamplerDeviceParamTable : public QTable  class qsamplerDeviceParamTable : public QTable
255  {  {
256      Q_OBJECT          Q_OBJECT
257    
258  public:  public:
259    
260      // Constructor.          // Constructor.
261      qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);          qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);
262      // Default destructor.          // Default destructor.
263      ~qsamplerDeviceParamTable();          ~qsamplerDeviceParamTable();
264    
265            // Common parameter table renderer.
266            void refresh(const qsamplerDeviceParamMap& params, bool bEditable);
267    };
268    #endif
269    
270      // Client/device descriptor selector.  struct DeviceParameterRow {
271          void setDevice(lscp_client_t *pClient,      QString             name;
272                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID = -1);      qsamplerDeviceParam param;
273    };
274    
275      // Client/device descriptor accessors.  // so we can use it i.e. through QVariant
276          lscp_client_t *client();  Q_DECLARE_METATYPE(DeviceParameterRow)
277          int deviceID();  
278    class DeviceParamModel : public QAbstractTableModel {
279            Q_OBJECT
280        public:
281            DeviceParamModel(QObject* parent = 0);
282    
283            // overridden methods from subclass(es)
284            int rowCount(const QModelIndex &parent) const;
285            int columnCount(const QModelIndex &parent) const;
286            QVariant data(const QModelIndex &index, int role) const;
287            QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
288    
289            void clear();
290    
291        public slots:
292            void refresh(const qsamplerDeviceParamMap& params, bool bEditable);
293    
294        private:
295            qsamplerDeviceParamMap params;
296            bool bEditable;
297    };
298    
299    class DeviceParamDelegate : public QItemDelegate {
300            Q_OBJECT
301        public:
302            DeviceParamDelegate(QObject* parent = 0);
303    
304            QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
305                                  const QModelIndex& index) const;
306    
307            void setEditorData(QWidget* editor, const QModelIndex& index) const;
308            void setModelData(QWidget* editor, QAbstractItemModel* model,
309                              const QModelIndex& index) const;
310    
311            void updateEditorGeometry(QWidget* editor,
312                const QStyleOptionViewItem& option, const QModelIndex& index) const;
313    };
314    
315    
316    //-------------------------------------------------------------------------
317    // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.
318    //
319    
320    #if 0
321    class qsamplerDeviceParamTableSpinBox : public QTableWidgetItem
322    {
323    public:
324    
325            // Constructor.
326            qsamplerDeviceParamTableSpinBox (QTableWidget *pTable, Qt::ItemFlags flags,
327                    const QString& sText);
328    
329            // Public accessors.
330            void setMinValue(int iMinValue);
331            void setMaxValue(int iMaxValue);
332            void setValue(int iValue);
333    
334    protected:
335    
336            // Virtual implemetations.
337            QWidget *createEditor() const;
338            void setContentFromEditor(QWidget *pWidget);
339    
         // The main table refresher.  
         void refresh();  
           
340  private:  private:
341    
342      // LSCP client/device references.          // Initial value holders.
343      lscp_client_t *m_pClient;          int m_iValue;
344      qsamplerDevice::qsamplerDeviceType m_deviceType;          int m_iMinValue;
345      int m_iDeviceID;          int m_iMaxValue;
346  };  };
347    
348    
349    //-------------------------------------------------------------------------
350    // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.
351    //
352    
353    class qsamplerDeviceParamTableEditBox : public QTableWidgetItem
354    {
355    public:
356    
357            // Constructor.
358            qsamplerDeviceParamTableEditBox (QTableWidget *pTable, Qt::ItemFlags flags,
359                    const QString& sText);
360    
361    protected:
362    
363            // Virtual implemetations.
364            QWidget *createEditor() const;
365            void setContentFromEditor(QWidget *pWidget);
366    };
367    #endif
368    
369  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
370    
371    

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

  ViewVC Help
Powered by ViewVC