/[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 436 by capela, Wed Mar 9 20:55:04 2005 UTC revision 3518 by capela, Sun Jun 30 16:58:30 2019 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-2019, 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);
         // Default destructor.  
         ~qsamplerDeviceParam();  
63    
64          // Initializer.          // Initializer.
65          void setParam(lscp_param_info_t *pParamInfo,          void setParam(lscp_param_info_t *pParamInfo,
# Line 67  public: Line 80  public:
80          QString         value;          QString         value;
81  };  };
82    
83  // A typedef'd parameter QMap.  // Typedef'd parameter QMap.
84  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, DeviceParam> DeviceParamMap;
85    
86    // Typedef'd device port/channels QList.
87    typedef QList<DevicePort *> DevicePortList;
88    
89    
90  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
91  // qsamplerDevice - MIDI/Audio Device structure.  // QSampler::Device - MIDI/Audio Device structure.
92  //  //
93    
94  class qsamplerDevice  class Device
95  {  {
96  public:  public:
97    
98          // We use the same class for MIDI and audio device management          // We use the same class for MIDI and audio device management
99          enum qsamplerDeviceType { None, Midi, Audio };          enum DeviceType { None, Midi, Audio };
100    
101          // Constructor.          // Constructor.
102          qsamplerDevice(lscp_client_t *pClient,          Device(DeviceType deviceType, int iDeviceID = -1);
103                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
104            Device(const Device& device);
105    
106          // Default destructor.          // Default destructor.
107          ~qsamplerDevice();          ~Device();
108    
109          // Initializer.          // Initializer.
110          void setDevice(lscp_client_t *pClient,          void setDevice(DeviceType deviceType, int iDeviceID = -1);
                 qsamplerDeviceType deviceType, int iDeviceID = -1);  
111    
112          // Driver name initializer.          // Driver name initializer.
113          void setDriver(lscp_client_t *pClient,          void setDriver(const QString& sDriverName);
                 const QString& sDriverName);  
114    
115          // Device property accessors.          // Device property accessors.
116          int                 deviceID()   const;          int            deviceID() const;
117          qsamplerDeviceType  deviceType() const;          DeviceType     deviceType() const;
118          const QString&      deviceTypeName() const;          const QString& deviceTypeName() const;
119          const QString&      driverName() const;          const QString& driverName() const;
120          const QString&      deviceName() 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 DeviceParamMap& params() const;
129    
130            // Device port/channel list accessor.
131            DevicePortList& 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.          // Device ids enumerator.
152          static int *getDevices(lscp_client_t *pClient,          static int *getDevices(lscp_client_t *pClient,
153                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
154            static std::set<int> getDeviceIDs(lscp_client_t *pClient,
155                    DeviceType deviceType);
156    
157          // Driver names enumerator.          // Driver names enumerator.
158          static QStringList getDrivers(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
159                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
160    
161  private:  private:
162    
163            // Refresh/set given parameter based on driver supplied dependencies.
164            int refreshParam(const QString& sParam);
165    
166          // Instance variables.          // Instance variables.
167          int                m_iDeviceID;          int        m_iDeviceID;
168          qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
169          QString            m_sDeviceType;          QString    m_sDeviceType;
170          QString            m_sDriverName;          QString    m_sDriverName;
171          QString            m_sDeviceName;          QString    m_sDeviceName;
172    
173          // Device parameter list.          // Device parameter list.
174          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
175    
176            // Device port/channel list.
177            DevicePortList m_ports;
178  };  };
179    
180    
181  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
182  // qsamplerDeviceItem - QListView device item.  // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
183  //  //
184    
185  class qsamplerDeviceItem : public QListViewItem  class DevicePort
186    {
187    public:
188    
189            // Constructor.
190            DevicePort(Device& device, int iPortID);
191            // Default destructor.
192            ~DevicePort();
193    
194            // Initializer.
195            void setDevicePort(int iPortID);
196    
197            // Device port property accessors.
198            int            portID()   const;
199            const QString& portName() const;
200    
201            // Device port parameters accessor.
202            const DeviceParamMap& params() const;
203    
204            // Set the proper device port/channel parameter value.
205            bool setParam (const QString& sParam, const QString& sValue);
206    
207    private:
208    
209            // Device reference.
210            Device& m_device;
211    
212            // Instance variables.
213            int     m_iPortID;
214            QString m_sPortName;
215    
216            // Device port parameter list.
217            DeviceParamMap m_params;
218    };
219    
220    
221    //-------------------------------------------------------------------------
222    // QSampler::DeviceItem - QTreeWidget device item.
223    //
224    
225    class DeviceItem : public QTreeWidgetItem
226  {  {
227  public:  public:
228    
229          // Constructors.          // Constructors.
230          qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          DeviceItem(QTreeWidget *pTreeWidget,
231                  qsamplerDevice::qsamplerDeviceType deviceType);                  Device::DeviceType deviceType);
232          qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,          DeviceItem(QTreeWidgetItem *pItem,
233                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  Device::DeviceType deviceType, int iDeviceID);
234    
235          // Default destructor.          // Default destructor.
236          ~qsamplerDeviceItem();          ~DeviceItem();
237    
238          // Instance accessors.          // Instance accessors.
239          qsamplerDevice& device();          Device& device();
   
         // To virtually distinguish between list view items.  
         virtual int rtti() const;  
240    
241  private:  private:
242    
243          // Instance variables.          // Instance variables.
244          qsamplerDevice m_device;          Device m_device;
245    };
246    
247    
248    struct DeviceParameterRow {
249            QString     name;
250            DeviceParam param;
251            bool        alive; // whether these params refer to an existing device
252                               // or for a device that is yet to be created
253  };  };
254    
255    
256  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
257  // qsamplerDeviceParamTable - Device parameter view table.  // QSampler::AbstractDeviceParamModel - data model base class for device parameters
258  //  //
259    
260  class qsamplerDeviceParamTable : public QTable  class AbstractDeviceParamModel : public QAbstractTableModel
261  {  {
262          Q_OBJECT          Q_OBJECT
263    
264  public:  public:
265    
266          // Constructor.          AbstractDeviceParamModel(QObject *pParent = NULL);
267          qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);  
268          // Default destructor.          // Overridden methods from subclass(es)
269          ~qsamplerDeviceParamTable();          int rowCount(const QModelIndex& parent = QModelIndex()) const;
270            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
271            QVariant headerData(int section,
272                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
273            Qt::ItemFlags flags(const QModelIndex& index) const;
274    
275            virtual void clear();
276    
277            void refresh(const DeviceParamMap* params, bool bEditable);
278    
279    protected:
280    
281            const DeviceParamMap *m_pParams;
282            bool m_bEditable;
283    };
284    
285          // Client/device descriptor selector.  
286          void refresh(qsamplerDevice& device);  //-------------------------------------------------------------------------
287    // QSampler::DeviceParamModel - data model for device parameters
288    //                              (used for QTableView)
289    
290    class DeviceParamModel : public AbstractDeviceParamModel
291    {
292            Q_OBJECT
293    
294    public:
295    
296            DeviceParamModel(QObject *pParent = NULL);
297    
298            // Overridden methods from subclass(es)
299            QVariant data(const QModelIndex &index, int role) const;
300            bool setData(const QModelIndex& index,
301                    const QVariant& value, int role = Qt::EditRole);
302    
303            void clear();
304    
305    public slots:
306    
307            void refresh(Device* pDevice, bool bEditable);
308    
309    private:
310    
311            Device *m_pDevice;
312  };  };
313    
314    
315    //-------------------------------------------------------------------------
316    // QSampler::PortParamModel - data model for port parameters
317    //                            (used for QTableView)
318    
319    class PortParamModel : public AbstractDeviceParamModel
320    {
321            Q_OBJECT
322    
323    public:
324    
325            PortParamModel(QObject *pParent = 0);
326    
327            // overridden methods from subclass(es)
328            QVariant data(const QModelIndex &index, int role) const;
329            bool setData(const QModelIndex& index,
330                    const QVariant& value, int role = Qt::EditRole);
331    
332            void clear();
333    
334    public slots:
335    
336            void refresh(DevicePort* pPort, bool bEditable);
337    
338    private:
339    
340            DevicePort* m_pPort;
341    };
342    
343    
344    //-------------------------------------------------------------------------
345    // QSampler::DeviceParamDelegate - table cell renderer for device/port parameters
346    //
347    
348    class DeviceParamDelegate : public QItemDelegate
349    {
350            Q_OBJECT
351    
352    public:
353    
354            DeviceParamDelegate(QObject *pParent = NULL);
355    
356            QWidget* createEditor(QWidget *pParent,
357                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
358            void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
359            void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
360                    const QModelIndex& index) const;
361            void updateEditorGeometry(QWidget* pEditor,
362                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
363    };
364    
365    } // namespace QSampler
366    
367    // so we can use it i.e. through QVariant
368    Q_DECLARE_METATYPE(QSampler::DeviceParameterRow)
369    
370  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
371    
372    

Legend:
Removed from v.436  
changed lines
  Added in v.3518

  ViewVC Help
Powered by ViewVC