/[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 1510 by capela, Thu Nov 22 14:17:24 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>
# Line 75  public: Line 85  public:
85  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
86    
87  // Typedef'd device port/channels QptrList.  // Typedef'd device port/channels QptrList.
88  typedef QPtrList<qsamplerDevicePort> qsamplerDevicePortList;  typedef QList<qsamplerDevicePort *> qsamplerDevicePortList;
89    
90    
91  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 87  class qsamplerDevice Line 97  class qsamplerDevice
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(qsamplerMainForm *pMainForm,          qsamplerDevice(DeviceType deviceType, int iDeviceID = -1);
                 qsamplerDeviceType deviceType, int iDeviceID = -1);  
104          // Copy constructor.          // Copy constructor.
105      qsamplerDevice(const qsamplerDevice& device);          qsamplerDevice(const qsamplerDevice& device);
106          // Default destructor.          // Default destructor.
107          ~qsamplerDevice();          ~qsamplerDevice();
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 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    
155          // Driver names enumerator.          // Driver names enumerator.
156          static QStringList getDrivers(lscp_client_t *pClient,          static QStringList getDrivers(lscp_client_t *pClient,
157                  qsamplerDeviceType deviceType);                  DeviceType deviceType);
158    
159  private:  private:
160    
161          // Refresh/set given parameter based on driver supplied dependencies.          // Refresh/set given parameter based on driver supplied dependencies.
162          int refreshParam(const QString& sParam);          int refreshParam(const QString& sParam);
163    
         // Main application form reference.  
         qsamplerMainForm  *m_pMainForm;  
   
164          // Instance variables.          // Instance variables.
165          int                m_iDeviceID;          int        m_iDeviceID;
166          qsamplerDeviceType m_deviceType;          DeviceType m_deviceType;
167          QString            m_sDeviceType;          QString    m_sDeviceType;
168          QString            m_sDriverName;          QString    m_sDriverName;
169          QString            m_sDeviceName;          QString    m_sDeviceName;
170    
171          // Device parameter list.          // Device parameter list.
172          qsamplerDeviceParamMap m_params;          qsamplerDeviceParamMap m_params;
# Line 216  private: Line 220  private:
220  // qsamplerDeviceItem - QListView device item.  // qsamplerDeviceItem - QListView device item.
221  //  //
222    
223  class qsamplerDeviceItem : public QListViewItem  class qsamplerDeviceItem : public QTreeWidgetItem
224  {  {
225  public:  public:
226    
227          // Constructors.          // Constructors.
228          qsamplerDeviceItem(QListView *pListView, qsamplerMainForm *pMainForm,          qsamplerDeviceItem(QTreeWidget *pTreeWidget,
229                  qsamplerDevice::qsamplerDeviceType deviceType);                  qsamplerDevice::DeviceType deviceType);
230          qsamplerDeviceItem(QListViewItem *pItem, qsamplerMainForm *pMainForm,          qsamplerDeviceItem(QTreeWidgetItem *pItem,
231                  qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);                  qsamplerDevice::DeviceType deviceType, int iDeviceID);
232          // Default destructor.          // Default destructor.
233          ~qsamplerDeviceItem();          ~qsamplerDeviceItem();
234    
235          // Instance accessors.          // Instance accessors.
236          qsamplerDevice& device();          qsamplerDevice& device();
237    
         // To virtually distinguish between list view items.  
         virtual int rtti() const;  
   
238  private:  private:
239    
240          // Instance variables.          // Instance variables.
241          qsamplerDevice m_device;          qsamplerDevice m_device;
242  };  };
243    
244    struct DeviceParameterRow {
245            QString             name;
246            qsamplerDeviceParam param;
247            bool                alive; // whether these params refer to an existing device or for a device that is yet to be created
248    };
249    
250    // so we can use it i.e. through QVariant
251    Q_DECLARE_METATYPE(DeviceParameterRow)
252    
253    
254  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
255  // qsamplerDeviceParamTable - Device parameter view table.  // AbstractDeviceParamModel - data model base class for device parameters
256  //  //
257    class AbstractDeviceParamModel : public QAbstractTableModel
 class qsamplerDeviceParamTable : public QTable  
258  {  {
259          Q_OBJECT          Q_OBJECT
260    
261  public:  public:
262    
263          // Constructor.          AbstractDeviceParamModel(QObject *pParent = NULL);
         qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);  
         // Default destructor.  
         ~qsamplerDeviceParamTable();  
264    
265          // Common parameter table renderer.          // Overridden methods from subclass(es)
266          void refresh(const qsamplerDeviceParamMap& params, bool bEditable);          int rowCount(const QModelIndex& parent = QModelIndex()) const;
267            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
268            QVariant headerData(int section,
269                    Qt::Orientation orientation, int role = Qt::DisplayRole) const;
270            Qt::ItemFlags flags(const QModelIndex& index) const;
271    
272            virtual void clear();
273    
274            void refresh(const qsamplerDeviceParamMap* params, bool bEditable);
275    
276    protected:
277    
278            const qsamplerDeviceParamMap *m_pParams;
279            bool m_bEditable;
280  };  };
281    
282    
283  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
284  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.  // DeviceParamModel - data model for device parameters (used for QTableView)
285  //  //
286    
287  class qsamplerDeviceParamTableSpinBox : public QTableItem  class DeviceParamModel : public AbstractDeviceParamModel
288  {  {
289            Q_OBJECT
290    
291  public:  public:
292    
293          // Constructor.          DeviceParamModel(QObject *pParent = NULL);
         qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
294    
295          // Public accessors.          // Overridden methods from subclass(es)
296          void setMinValue(int iMinValue);          QVariant data(const QModelIndex &index, int role) const;
297          void setMaxValue(int iMaxValue);          bool setData(const QModelIndex& index,
298          void setValue(int iValue);                  const QVariant& value, int role = Qt::EditRole);
299    
300  protected:          void clear();
301    
302    public slots:
303    
304          // Virtual implemetations.          void refresh(qsamplerDevice* pDevice, bool bEditable);
         QWidget *createEditor() const;  
         void setContentFromEditor(QWidget *pWidget);  
305    
306  private:  private:
307    
308          // Initial value holders.          qsamplerDevice *m_pDevice;
         int m_iValue;  
         int m_iMinValue;  
         int m_iMaxValue;  
309  };  };
310    
311    
312  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
313  // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.  // PortParamModel - data model for port parameters (used for QTableView)
314  //  //
315    
316  class qsamplerDeviceParamTableEditBox : public QTableItem  class PortParamModel : public AbstractDeviceParamModel
317  {  {
318            Q_OBJECT
319    
320  public:  public:
321    
322          // Constructor.          PortParamModel(QObject *pParent = 0);
         qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
323    
324  protected:          // overridden methods from subclass(es)
325            QVariant data(const QModelIndex &index, int role) const;
326            bool setData(const QModelIndex& index,
327                    const QVariant& value, int role = Qt::EditRole);
328    
329            void clear();
330    
331          // Virtual implemetations.  public slots:
332          QWidget *createEditor() const;  
333          void setContentFromEditor(QWidget *pWidget);          void refresh(qsamplerDevicePort* pPort, bool bEditable);
334    
335    private:
336    
337            qsamplerDevicePort* m_pPort;
338  };  };
339    
340    
341  #endif  // __qsamplerDevice_h  //-------------------------------------------------------------------------
342    // DeviceParamDelegate - table cell renderer for device/port parameters
343    //
344    class DeviceParamDelegate : public QItemDelegate
345    {
346            Q_OBJECT
347    
348    public:
349    
350            DeviceParamDelegate(QObject *pParent = NULL);
351    
352            QWidget* createEditor(QWidget *pParent,
353                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
354            void setEditorData(QWidget *pEditor, const QModelIndex& index) const;
355            void setModelData(QWidget *pEditor, QAbstractItemModel *pModel,
356                    const QModelIndex& index) const;
357            void updateEditorGeometry(QWidget* pEditor,
358                    const QStyleOptionViewItem& option, const QModelIndex& index) const;
359    };
360    
361    #endif  // __qsamplerDevice_h
362    
363  // end of qsamplerDevice.h  // end of qsamplerDevice.h

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

  ViewVC Help
Powered by ViewVC