/[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 426 by capela, Mon Mar 7 11:09:32 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) 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 <qtable.h>  #include <QListWidget>
27    #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.
48    #define QSAMPLER_DEVICE_ITEM    1001
49    
50    
51    //-------------------------------------------------------------------------
52    // QSampler::DeviceParam - MIDI/Audio Device parameter structure.
53    //
54    
55    class DeviceParam
56    {
57    public:
58    
59            // Constructor.
60            DeviceParam(lscp_param_info_t *pParamInfo = NULL,
61                    const char *pszValue = NULL);
62            // Default destructor.
63            ~DeviceParam();
64    
65            // Initializer.
66            void setParam(lscp_param_info_t *pParamInfo,
67                    const char *pszValue = NULL);
68    
69            // Info structure field members.
70            lscp_type_t     type;
71            QString         description;
72            bool            mandatory;
73            bool            fix;
74            bool            multiplicity;
75            QStringList depends;
76            QString         defaultv;
77            QString         range_min;
78            QString         range_max;
79            QStringList possibilities;
80            // The current parameter value.
81            QString         value;
82    };
83    
84    // Typedef'd parameter QMap.
85    typedef QMap<QString, DeviceParam> DeviceParamMap;
86    
87    // Typedef'd device port/channels QList.
88    typedef QList<DevicePort *> DevicePortList;
89    
90    
91    //-------------------------------------------------------------------------
92    // QSampler::Device - MIDI/Audio Device structure.
93    //
94    
95    class Device
96    {
97    public:
98    
99            // We use the same class for MIDI and audio device management
100            enum DeviceType { None, Midi, Audio };
101    
102            // Constructor.
103            Device(DeviceType deviceType, int iDeviceID = -1);
104            // Copy constructor.
105            Device(const Device& device);
106    
107            // Default destructor.
108            ~Device();
109    
110            // Initializer.
111            void setDevice(DeviceType deviceType, int iDeviceID = -1);
112    
113            // Driver name initializer.
114            void setDriver(const QString& sDriverName);
115    
116            // Device property accessors.
117            int            deviceID() const;
118            DeviceType     deviceType() const;
119            const QString& deviceTypeName() const;
120            const QString& driverName() const;
121    
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.
129            const DeviceParamMap& params() const;
130    
131            // Device port/channel list accessor.
132            DevicePortList& ports();
133    
134            // Device parameter dependency list refreshner.
135            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                    DeviceType deviceType);
155    
156            // Driver names enumerator.
157            static QStringList getDrivers(lscp_client_t *pClient,
158                    DeviceType deviceType);
159    
160    private:
161    
162            // Refresh/set given parameter based on driver supplied dependencies.
163            int refreshParam(const QString& sParam);
164    
165            // Instance variables.
166            int        m_iDeviceID;
167            DeviceType m_deviceType;
168            QString    m_sDeviceType;
169            QString    m_sDriverName;
170            QString    m_sDeviceName;
171    
172            // Device parameter list.
173            DeviceParamMap m_params;
174    
175            // Device port/channel list.
176            DevicePortList m_ports;
177    };
178    
179    
180    //-------------------------------------------------------------------------
181    // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
182    //
183    
184    class DevicePort
185    {
186    public:
187    
188            // Constructor.
189            DevicePort(Device& device, int iPortID);
190            // Default destructor.
191            ~DevicePort();
192    
193            // Initializer.
194            void setDevicePort(int iPortID);
195    
196            // Device port property accessors.
197            int            portID()   const;
198            const QString& portName() const;
199    
200            // Device port parameters accessor.
201            const DeviceParamMap& params() const;
202    
203            // Set the proper device port/channel parameter value.
204            bool setParam (const QString& sParam, const QString& sValue);
205    
206    private:
207    
208            // Device reference.
209            Device& m_device;
210    
211            // Instance variables.
212            int     m_iPortID;
213            QString m_sPortName;
214    
215            // Device port parameter list.
216            DeviceParamMap m_params;
217    };
218    
219    
220    //-------------------------------------------------------------------------
221    // QSampler::DeviceItem - QTreeWidget device item.
222    //
223    
224    class DeviceItem : public QTreeWidgetItem
225    {
226    public:
227    
228            // Constructors.
229            DeviceItem(QTreeWidget *pTreeWidget,
230                    Device::DeviceType deviceType);
231            DeviceItem(QTreeWidgetItem *pItem,
232                    Device::DeviceType deviceType, int iDeviceID);
233    
234            // Default destructor.
235            ~DeviceItem();
236    
237            // Instance accessors.
238            Device& device();
239    
240    private:
241    
242            // Instance variables.
243            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  // qsamplerDeviceParameterTable - Device parameter view table.  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
257  //  //
258    
259  class qsamplerDeviceParameterTable : public QTable  class AbstractDeviceParamModel : public QAbstractTableModel
260    {
261            Q_OBJECT
262    
263    public:
264    
265            AbstractDeviceParamModel(QObject *pParent = NULL);
266    
267            // Overridden methods from subclass(es)
268            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            const DeviceParamMap *m_pParams;
281            bool m_bEditable;
282    };
283    
284    
285    //-------------------------------------------------------------------------
286    // QSampler::DeviceParamModel - data model for device parameters
287    //                              (used for QTableView)
288    
289    class DeviceParamModel : public AbstractDeviceParamModel
290    {
291            Q_OBJECT
292    
293    public:
294    
295            DeviceParamModel(QObject *pParent = NULL);
296    
297            // Overridden methods from subclass(es)
298            QVariant data(const QModelIndex &index, int role) const;
299            bool setData(const QModelIndex& index,
300                    const QVariant& value, int role = Qt::EditRole);
301    
302            void clear();
303    
304    public slots:
305    
306            void refresh(Device* pDevice, bool bEditable);
307    
308    private:
309    
310            Device *m_pDevice;
311    };
312    
313    
314    //-------------------------------------------------------------------------
315    // QSampler::PortParamModel - data model for port parameters
316    //                            (used for QTableView)
317    
318    class PortParamModel : public AbstractDeviceParamModel
319  {  {
320      Q_OBJECT          Q_OBJECT
321    
322  public:  public:
323    
324      // Constructor.          PortParamModel(QObject *pParent = 0);
325      qsamplerDeviceParameterTable(QWidget *pParent = 0, const char *pszName = 0);  
326      // Default destructor.          // overridden methods from subclass(es)
327      ~qsamplerDeviceParameterTable();          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      // LSCP client descriptor accessor.  public slots:
334      void setClient(lscp_client_t *pClient);  
335      lscp_client_t * client();          void refresh(DevicePort* pPort, bool bEditable);
336    
337  private:  private:
338    
339      // LSCP client reference.          DevicePort* m_pPort;
     lscp_client_t *m_pClient;  
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            QWidget* createEditor(QWidget *pParent,
356                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
357            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    
371    

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

  ViewVC Help
Powered by ViewVC