/[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 492 by capela, Sat Apr 2 12:23:18 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    
 // Early forward declarations.  
 class qsamplerMainForm;  
 class qsamplerDevicePort;  
   
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 72  public: Line 81  public:
81  };  };
82    
83  // 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 QptrList.  // Typedef'd device port/channels QList.
87  typedef QPtrList<qsamplerDevicePort> qsamplerDevicePortList;  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(qsamplerMainForm *pMainForm,          Device(DeviceType deviceType, int iDeviceID = -1);
                 qsamplerDeviceType deviceType, int iDeviceID = -1);  
103          // Copy constructor.          // Copy constructor.
104      qsamplerDevice(const qsamplerDevice& device);          Device(const Device& device);
105    
106          // Default destructor.          // Default destructor.
107          ~qsamplerDevice();          ~Device();
108    
109          // Initializer.          // Initializer.
110          void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);          void setDevice(DeviceType deviceType, int iDeviceID = -1);
111    
112          // Driver name initializer.          // Driver name initializer.
113          void setDriver(const QString& sDriverName);          void setDriver(const QString& sDriverName);
114    
         // LSCP client descriptor accessor.  
         lscp_client_t *client() const;  
   
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    
121          // Special device name formatter.          // Special device name formatter.
122          QString deviceName() const;          QString deviceName() const;
123    
# Line 118  public: Line 125  public:
125          bool setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
126    
127          // Device parameters accessor.          // Device parameters accessor.
128          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
129    
130          // Device port/channel list accessor.          // Device port/channel list accessor.
131          qsamplerDevicePortList& ports();          DevicePortList& ports();
132    
133          // Device parameter dependency list refreshner.          // Device parameter dependency list refreshner.
134          int refreshParams();          int refreshParams();
# Line 143  public: Line 150  public:
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.          // Refresh/set given parameter based on driver supplied dependencies.
164          int refreshParam(const QString& sParam);          int refreshParam(const QString& sParam);
165    
         // Main application form reference.  
         qsamplerMainForm  *m_pMainForm;  
   
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.          // Device port/channel list.
177          qsamplerDevicePortList m_ports;          DevicePortList m_ports;
178  };  };
179    
180    
181  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
182  // qsamplerDevicePort - MIDI/Audio Device port/channel structure.  // QSampler::DevicePort - MIDI/Audio Device port/channel structure.
183  //  //
184    
185  class qsamplerDevicePort  class DevicePort
186  {  {
187  public:  public:
188    
189          // Constructor.          // Constructor.
190          qsamplerDevicePort(qsamplerDevice& device, int iPortID);          DevicePort(Device& device, int iPortID);
191          // Default destructor.          // Default destructor.
192          ~qsamplerDevicePort();          ~DevicePort();
193    
194          // Initializer.          // Initializer.
195          void setDevicePort(int iPortID);          void setDevicePort(int iPortID);
# Line 193  public: Line 199  public:
199          const QString& portName() const;          const QString& portName() const;
200    
201          // Device port parameters accessor.          // Device port parameters accessor.
202          const qsamplerDeviceParamMap& params() const;          const DeviceParamMap& params() const;
203    
204          // Set the proper device port/channel parameter value.          // Set the proper device port/channel parameter value.
205          bool setParam (const QString& sParam, const QString& sValue);          bool setParam (const QString& sParam, const QString& sValue);
# Line 201  public: Line 207  public:
207  private:  private:
208    
209          // Device reference.          // Device reference.
210          qsamplerDevice& m_device;          Device& m_device;
211    
212          // Instance variables.          // Instance variables.
213          int     m_iPortID;          int     m_iPortID;
214          QString m_sPortName;          QString m_sPortName;
215    
216          // Device port parameter list.          // Device port parameter list.
217          qsamplerDeviceParamMap m_params;          DeviceParamMap m_params;
218  };  };
219    
220    
221  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
222  // qsamplerDeviceItem - QListView device item.  // QSampler::DeviceItem - QTreeWidget device item.
223  //  //
224    
225  class qsamplerDeviceItem : public QListViewItem  class DeviceItem : public QTreeWidgetItem
226  {  {
227  public:  public:
228    
229          // Constructors.          // Constructors.
230          qsamplerDeviceItem(QListView *pListView, qsamplerMainForm *pMainForm,          DeviceItem(QTreeWidget *pTreeWidget,
231                  qsamplerDevice::qsamplerDeviceType deviceType);                  Device::DeviceType deviceType);
232          qsamplerDeviceItem(QListViewItem *pItem, qsamplerMainForm *pMainForm,          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          // Common parameter table renderer.          const DeviceParamMap *m_pParams;
282          void refresh(const qsamplerDeviceParamMap& params, bool bEditable);          bool m_bEditable;
283  };  };
284    
285    
286  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
287  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.  // QSampler::DeviceParamModel - data model for device parameters
288  //  //                              (used for QTableView)
289    
290  class qsamplerDeviceParamTableSpinBox : public QTableItem  class DeviceParamModel : public AbstractDeviceParamModel
291  {  {
292            Q_OBJECT
293    
294  public:  public:
295    
296          // Constructor.          DeviceParamModel(QObject *pParent = NULL);
         qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
297    
298          // Public accessors.          // Overridden methods from subclass(es)
299          void setMinValue(int iMinValue);          QVariant data(const QModelIndex &index, int role) const;
300          void setMaxValue(int iMaxValue);          bool setData(const QModelIndex& index,
301          void setValue(int iValue);                  const QVariant& value, int role = Qt::EditRole);
302    
303  protected:          void clear();
304    
305          // Virtual implemetations.  public slots:
306          QWidget *createEditor() const;  
307          void setContentFromEditor(QWidget *pWidget);          void refresh(Device* pDevice, bool bEditable);
308    
309  private:  private:
310    
311          // Initial value holders.          Device *m_pDevice;
         int m_iValue;  
         int m_iMinValue;  
         int m_iMaxValue;  
312  };  };
313    
314    
315  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
316  // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.  // QSampler::PortParamModel - data model for port parameters
317  //  //                            (used for QTableView)
318    
319  class qsamplerDeviceParamTableEditBox : public QTableItem  class PortParamModel : public AbstractDeviceParamModel
320  {  {
321            Q_OBJECT
322    
323  public:  public:
324    
325          // Constructor.          PortParamModel(QObject *pParent = 0);
         qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
326    
327  protected:          // 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          // Virtual implemetations.          QWidget* createEditor(QWidget *pParent,
357          QWidget *createEditor() const;                  const QStyleOptionViewItem& option, const QModelIndex& index) const;
358          void setContentFromEditor(QWidget *pWidget);          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    

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

  ViewVC Help
Powered by ViewVC