/[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 467 by capela, Tue Mar 15 23:54:14 2005 UTC revision 1558 by capela, Thu Dec 6 09:35:33 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>
40    
41  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
42    
43    namespace QSampler {
44    
45    class DevicePort;
46    
47  // Special QListViewItem::rtti() unique return value.  // Special QListViewItem::rtti() unique return value.
48  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
49    
 // Early forward declaration.  
 class qsamplerDevicePort;  
   
50    
51  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
52  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
53  //  //
54  class qsamplerDeviceParam  
55    class DeviceParam
56  {  {
57  public:  public:
58    
59          // Constructor.          // Constructor.
60          qsamplerDeviceParam(lscp_param_info_t *pParamInfo = NULL,          DeviceParam(lscp_param_info_t *pParamInfo = NULL,
61                  const char *pszValue = NULL);                  const char *pszValue = NULL);
62          // Default destructor.          // Default destructor.
63          ~qsamplerDeviceParam();          ~DeviceParam();
64    
65          // Initializer.          // Initializer.
66          void setParam(lscp_param_info_t *pParamInfo,          void setParam(lscp_param_info_t *pParamInfo,
# Line 71  public: Line 82  public:
82  };  };
83    
84  // Typedef'd parameter QMap.  // Typedef'd parameter QMap.
85  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, DeviceParam> DeviceParamMap;
86    
87  // Typedef'd device port/channels QptrList.  // Typedef'd device port/channels QList.
88  typedef QPtrList<qsamplerDevicePort> qsamplerDevicePortList;  typedef QList<DevicePort *> DevicePortList;
89    
90    
91  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
92  // qsamplerDevice - MIDI/Audio Device structure.  // QSampler::Device - MIDI/Audio Device structure.
93  //  //
94    
95  class qsamplerDevice  class Device
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 { None, Midi, Audio };          enum DeviceType { None, Midi, Audio };
101    
102          // Constructor.          // Constructor.
103          qsamplerDevice(lscp_client_t *pClient,          Device(DeviceType deviceType, int iDeviceID = -1);
104                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
105            Device(const Device& device);
106    
107          // Default destructor.          // Default destructor.
108          ~qsamplerDevice();          ~Device();
109    
110          // Initializer.          // Initializer.
111          void setDevice(lscp_client_t *pClient,          void setDevice(DeviceType deviceType, int iDeviceID = -1);
                 qsamplerDeviceType deviceType, int iDeviceID = -1);  
112    
113          // Driver name initializer.          // Driver name initializer.
114          void setDriver(lscp_client_t *pClient,          void setDriver(const QString& sDriverName);
                 const QString& sDriverName);  
115    
116          // Device property accessors.          // Device property accessors.
117          int                 deviceID()   const;          int            deviceID() const;
118          qsamplerDeviceType  deviceType() const;          DeviceType     deviceType() const;
119          const QString&      deviceTypeName() const;          const QString& deviceTypeName() const;
120          const QString&      driverName() const;          const QString& driverName() const;
121          const QString&      deviceName() const;  
122            // Special device name formatter.
123            QString deviceName() const;
124    
125          // Set the proper device parameter value.          // Set the proper device parameter value.
126          void setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
127    
128          // Device parameters accessor.          // Device parameters accessor.
129          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
130    
131          // Device port/channel list accessor.          // Device port/channel list accessor.
132          qsamplerDevicePortList& ports();          DevicePortList& ports();
133    
134          // Device parameter dependency list refreshner.          // Device parameter dependency list refreshner.
135          int refreshParams(lscp_client_t *pClient);          int refreshParams();
136          // Device port/channel list refreshner.          // Device port/channel list refreshner.
137          int refreshPorts(lscp_client_t *pClient);          int refreshPorts();
138          // Refresh/set dependencies given that some parameter has changed.          // Refresh/set dependencies given that some parameter has changed.
139          int refreshDepends(lscp_client_t *pClient, const QString& sParam);          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.          // Device ids enumerator.
153          static int *getDevices(lscp_client_t *pClient,          static int *getDevices(lscp_client_t *pClient,
154                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
155    
156          // Driver names enumerator.          // Driver names enumerator.
157          static QStringList getDrivers(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
158                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
159    
160  private:  private:
161    
162          // Refresh/set given parameter based on driver supplied dependencies.          // Refresh/set given parameter based on driver supplied dependencies.
163          int refreshParam(lscp_client_t *pClient, const QString& sParam);          int refreshParam(const QString& sParam);
164    
165          // Instance variables.          // Instance variables.
166          int                m_iDeviceID;          int        m_iDeviceID;
167          qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
168          QString            m_sDeviceType;          QString    m_sDeviceType;
169          QString            m_sDriverName;          QString    m_sDriverName;
170          QString            m_sDeviceName;          QString    m_sDeviceName;
171    
172          // Device parameter list.          // Device parameter list.
173          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
174            
175          // Device port/channel list.          // Device port/channel list.
176          qsamplerDevicePortList m_ports;          DevicePortList m_ports;
177  };  };
178    
179    
180  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
181  // qsamplerDevicePort - MIDI/Audio Device port/channel structure.  // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
182  //  //
183    
184  class qsamplerDevicePort  class DevicePort
185  {  {
186  public:  public:
187    
188          // Constructor.          // Constructor.
189          qsamplerDevicePort(lscp_client_t *pClient,          DevicePort(Device& device, int iPortID);
                 const qsamplerDevice& device, int iPortID);  
190          // Default destructor.          // Default destructor.
191          ~qsamplerDevicePort();          ~DevicePort();
192    
193          // Initializer.          // Initializer.
194          void setDevicePort(lscp_client_t *pClient,          void setDevicePort(int iPortID);
                 const qsamplerDevice& device, int iPortID);  
195    
196          // Device port property accessors.          // Device port property accessors.
197          int            portID()   const;          int            portID()   const;
198          const QString& portName() const;          const QString& portName() const;
199    
200          // Device port parameters accessor.          // Device port parameters accessor.
201          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
202    
203          // Set the proper device port/channel parameter value.          // Set the proper device port/channel parameter value.
204          void setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
205    
206  private:  private:
207    
208            // Device reference.
209            Device& m_device;
210    
211          // Instance variables.          // Instance variables.
212          int     m_iPortID;          int     m_iPortID;
213          QString m_sPortName;          QString m_sPortName;
214    
215          // Device port parameter list.          // Device port parameter list.
216          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
217  };  };
218    
219    
220  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
221  // qsamplerDeviceItem - QListView device item.  // QSampler::DeviceItem - QTreeWidget device item.
222  //  //
223    
224  class qsamplerDeviceItem : public QListViewItem  class DeviceItem : public QTreeWidgetItem
225  {  {
226  public:  public:
227    
228          // Constructors.          // Constructors.
229          qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          DeviceItem(QTreeWidget *pTreeWidget,
230                  qsamplerDevice::qsamplerDeviceType deviceType);                  Device::DeviceType deviceType);
231          qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,          DeviceItem(QTreeWidgetItem *pItem,
232                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  Device::DeviceType deviceType, int iDeviceID);
233    
234          // Default destructor.          // Default destructor.
235          ~qsamplerDeviceItem();          ~DeviceItem();
236    
237          // Instance accessors.          // Instance accessors.
238          qsamplerDevice& device();          Device& device();
   
         // To virtually distinguish between list view items.  
         virtual int rtti() const;  
239    
240  private:  private:
241    
242          // Instance variables.          // Instance variables.
243          qsamplerDevice m_device;          Device m_device;
244    };
245    
246    
247    struct DeviceParameterRow {
248            QString     name;
249            DeviceParam param;
250            bool        alive; // whether these params refer to an existing device
251                               // or for a device that is yet to be created
252  };  };
253    
254    
255  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
256  // qsamplerDeviceParamTable - Device parameter view table.  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
257  //  //
258    
259  class qsamplerDeviceParamTable : public QTable  class AbstractDeviceParamModel : public QAbstractTableModel
260  {  {
261          Q_OBJECT          Q_OBJECT
262    
263  public:  public:
264    
265          // Constructor.          AbstractDeviceParamModel(QObject *pParent = NULL);
266          qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);  
267          // Default destructor.          // Overridden methods from subclass(es)
268          ~qsamplerDeviceParamTable();          int rowCount(const QModelIndex& parent = QModelIndex()) const;
269            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
270            QVariant headerData(int section,
271                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
272            Qt::ItemFlags flags(const QModelIndex& index) const;
273    
274            virtual void clear();
275    
276            void refresh(const DeviceParamMap* params, bool bEditable);
277    
278    protected:
279    
280          // Common parameter table renderer.          const DeviceParamMap *m_pParams;
281          void refresh(const qsamplerDeviceParamMap& params, bool bEditable);          bool m_bEditable;
282  };  };
283    
284    
285  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
286  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.  // QSampler::DeviceParamModel - data model for device parameters
287  //  //                              (used for QTableView)
288    
289  class qsamplerDeviceParamTableSpinBox : public QTableItem  class DeviceParamModel : public AbstractDeviceParamModel
290  {  {
291            Q_OBJECT
292    
293  public:  public:
294    
295          // Constructor.          DeviceParamModel(QObject *pParent = NULL);
         qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
296    
297          // Public accessors.          // Overridden methods from subclass(es)
298          void setMinValue(int iMinValue);          QVariant data(const QModelIndex &index, int role) const;
299          void setMaxValue(int iMaxValue);          bool setData(const QModelIndex& index,
300          void setValue(int iValue);                  const QVariant& value, int role = Qt::EditRole);
301    
302  protected:          void clear();
303    
304          // Virtual implemetations.  public slots:
305          QWidget *createEditor() const;  
306          void setContentFromEditor(QWidget *pWidget);          void refresh(Device* pDevice, bool bEditable);
307    
308  private:  private:
309    
310          // Initial value holders.          Device *m_pDevice;
         int m_iValue;  
         int m_iMinValue;  
         int m_iMaxValue;  
311  };  };
312    
313    
314  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
315  // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.  // QSampler::PortParamModel - data model for port parameters
316  //  //                            (used for QTableView)
317    
318  class qsamplerDeviceParamTableEditBox : public QTableItem  class PortParamModel : public AbstractDeviceParamModel
319  {  {
320            Q_OBJECT
321    
322  public:  public:
323    
324          // Constructor.          PortParamModel(QObject *pParent = 0);
         qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
325    
326  protected:          // overridden methods from subclass(es)
327            QVariant data(const QModelIndex &index, int role) const;
328            bool setData(const QModelIndex& index,
329                    const QVariant& value, int role = Qt::EditRole);
330    
331            void clear();
332    
333    public slots:
334    
335            void refresh(DevicePort* pPort, bool bEditable);
336    
337    private:
338    
339            DevicePort* m_pPort;
340    };
341    
342    
343    //-------------------------------------------------------------------------
344    // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
345    //
346    
347    class DeviceParamDelegate : public QItemDelegate
348    {
349            Q_OBJECT
350    
351    public:
352    
353            DeviceParamDelegate(QObject *pParent = NULL);
354    
355          // Virtual implemetations.          QWidget* createEditor(QWidget *pParent,
356          QWidget *createEditor() const;                  const QStyleOptionViewItem& option, const QModelIndex& index) const;
357          void setContentFromEditor(QWidget *pWidget);          void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
358            void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
359                    const QModelIndex& index) const;
360            void updateEditorGeometry(QWidget* pEditor,
361                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
362  };  };
363    
364    } // namespace QSampler
365    
366    // so we can use it i.e. through QVariant
367    Q_DECLARE_METATYPE(QSampler::DeviceParameterRow)
368    
369  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
370    

Legend:
Removed from v.467  
changed lines
  Added in v.1558

  ViewVC Help
Powered by ViewVC