/[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 442 by capela, Thu Mar 10 15:48:38 2005 UTC revision 1486 by schoenebeck, Sat Nov 17 02:02:28 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 <QMetaType>
33    #include <QItemDelegate>
34    #include <QFontMetrics>
35    #include <QModelIndex>
36    #include <QSize>
37    #include <QList>
38    #include <Q3PtrList>
39    
40  #include <lscp/client.h>  #include <lscp/client.h>
41  #include <lscp/device.h>  #include <lscp/device.h>
# Line 34  Line 46 
46  // Special QListViewItem::rtti() unique return value.  // Special QListViewItem::rtti() unique return value.
47  #define QSAMPLER_DEVICE_ITEM    1001  #define QSAMPLER_DEVICE_ITEM    1001
48    
49    // Early forward declarations.
50    class qsamplerMainForm;
51    class qsamplerDevicePort;
52    
53    
54  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
55  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
# Line 67  public: Line 83  public:
83          QString         value;          QString         value;
84  };  };
85    
86  // A typedef'd parameter QMap.  // Typedef'd parameter QMap.
87  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;  typedef QMap<QString, qsamplerDeviceParam> qsamplerDeviceParamMap;
88    
89    // Typedef'd device port/channels QptrList.
90    typedef Q3PtrList<qsamplerDevicePort> qsamplerDevicePortList;
91    
92    
93  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
94  // qsamplerDevice - MIDI/Audio Device structure.  // qsamplerDevice - MIDI/Audio Device structure.
# Line 83  public: Line 102  public:
102          enum qsamplerDeviceType { None, Midi, Audio };          enum qsamplerDeviceType { None, Midi, Audio };
103    
104          // Constructor.          // Constructor.
105          qsamplerDevice(lscp_client_t *pClient,          qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
106                  qsamplerDeviceType deviceType, int iDeviceID = -1);          // Copy constructor.
107        qsamplerDevice(const qsamplerDevice& device);
108          // Default destructor.          // Default destructor.
109          ~qsamplerDevice();          ~qsamplerDevice();
110    
111          // Initializer.          // Initializer.
112          void setDevice(lscp_client_t *pClient,          void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1);
                 qsamplerDeviceType deviceType, int iDeviceID = -1);  
113    
114          // Driver name initializer.          // Driver name initializer.
115          void setDriver(lscp_client_t *pClient,          void setDriver(const QString& sDriverName);
                 const QString& sDriverName);  
116    
117          // Device property accessors.          // Device property accessors.
118          int                 deviceID()   const;          int                 deviceID()   const;
119          qsamplerDeviceType  deviceType() const;          qsamplerDeviceType  deviceType() const;
120          const QString&      deviceTypeName() const;          const QString&      deviceTypeName() const;
121          const QString&      driverName() const;          const QString&      driverName() const;
122          const QString&      deviceName() const;          // 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.          // Device parameters accessor.
129          qsamplerDeviceParamMap& params();          const qsamplerDeviceParamMap& params() const;
130    
131            // Device port/channel list accessor.
132            qsamplerDevicePortList& ports();
133    
134          // Update/refresh device/driver data.          // Device parameter dependency list refreshner.
135          void refresh();          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.          // Device ids enumerator.
153          static int *getDevices(lscp_client_t *pClient,          static int *getDevices(lscp_client_t *pClient,
# Line 119  public: Line 159  public:
159    
160  private:  private:
161    
162            // Refresh/set given parameter based on driver supplied dependencies.
163            int refreshParam(const QString& sParam);
164    
165            // Main application form reference.
166            qsamplerMainForm  *m_pMainForm;
167    
168          // Instance variables.          // Instance variables.
169          int                m_iDeviceID;          int                m_iDeviceID;
170          qsamplerDeviceType m_deviceType;          qsamplerDeviceType m_deviceType;
# Line 128  private: Line 174  private:
174    
175          // Device parameter list.          // Device parameter list.
176          qsamplerDeviceParamMap m_params;          qsamplerDeviceParamMap m_params;
177    
178            // Device port/channel list.
179            qsamplerDevicePortList m_ports;
180  };  };
181    
182    
183  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
184  // qsamplerDeviceItem - QListView device item.  // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
185  //  //
186    
187  class qsamplerDeviceItem : public QListViewItem  class qsamplerDevicePort
188  {  {
189  public:  public:
190    
191          // Constructors.          // Constructor.
192          qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient,          qsamplerDevicePort(qsamplerDevice& device, int iPortID);
                 qsamplerDevice::qsamplerDeviceType deviceType);  
         qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient,  
                 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);  
193          // Default destructor.          // Default destructor.
194          ~qsamplerDeviceItem();          ~qsamplerDevicePort();
195    
196          // Instance accessors.          // Initializer.
197          qsamplerDevice& device();          void setDevicePort(int iPortID);
198    
199            // Device port property accessors.
200            int            portID()   const;
201            const QString& portName() const;
202    
203          // To virtually distinguish between list view items.          // Device port parameters accessor.
204          virtual int rtti() const;          const qsamplerDeviceParamMap& params() const;
205    
206            // Set the proper device port/channel parameter value.
207            bool setParam (const QString& sParam, const QString& sValue);
208    
209  private:  private:
210    
211            // Device reference.
212            qsamplerDevice& m_device;
213    
214          // Instance variables.          // Instance variables.
215          qsamplerDevice m_device;          int     m_iPortID;
216            QString m_sPortName;
217    
218            // Device port parameter list.
219            qsamplerDeviceParamMap m_params;
220  };  };
221    
222    
223  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
224  // qsamplerDeviceParamTable - Device parameter view table.  // qsamplerDeviceItem - QListView device item.
225  //  //
226    
227  class qsamplerDeviceParamTable : public QTable  class qsamplerDeviceItem : public QTreeWidgetItem
228  {  {
         Q_OBJECT  
   
229  public:  public:
230    
231          // Constructor.          // Constructors.
232          qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0);          qsamplerDeviceItem(QTreeWidget* pTreeWidget,
233                    qsamplerDevice::qsamplerDeviceType deviceType);
234            qsamplerDeviceItem(QTreeWidgetItem* pItem,
235                    qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID);
236          // Default destructor.          // Default destructor.
237          ~qsamplerDeviceParamTable();          ~qsamplerDeviceItem();
238    
239          // Client/device descriptor selector.          // Instance accessors.
240          void refresh(qsamplerDevice& device);          qsamplerDevice& device();
241    
242    private:
243    
244            // Instance variables.
245            qsamplerDevice m_device;
246  };  };
247    
248    struct DeviceParameterRow {
249        QString             name;
250        qsamplerDeviceParam param;
251    };
252    
253    // so we can use it i.e. through QVariant
254    Q_DECLARE_METATYPE(DeviceParameterRow)
255    
256  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
257  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.  // AbstractDeviceParamModel - data model base class for device parameters
258  //  //
259    class AbstractDeviceParamModel : public QAbstractTableModel {
260            Q_OBJECT
261        public:
262            AbstractDeviceParamModel(QObject* parent = 0);
263    
264            // overridden methods from subclass(es)
265            int rowCount(const QModelIndex& parent = QModelIndex()) const;
266            int columnCount(const QModelIndex& parent = QModelIndex() ) const;
267            QVariant data(const QModelIndex &index, int role) const;
268            QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
269            Qt::ItemFlags flags(const QModelIndex& index) const;
270    
271            virtual void clear();
272    
273            void refresh(const qsamplerDeviceParamMap* params, bool bEditable);
274    
275        protected:
276            const qsamplerDeviceParamMap* params;
277            bool bEditable;
278    };
279    
280  class qsamplerDeviceParamTableSpinBox : public QTableItem  //-------------------------------------------------------------------------
281  {  // DeviceParamModel - data model for device parameters (used for QTableView)
282  public:  //
283    class DeviceParamModel : public AbstractDeviceParamModel {
284          // Constructor.          Q_OBJECT
285          qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType);      public:
286            DeviceParamModel(QObject* parent = 0);
287          // Public accessors.  
288          void setMinValue(int iMinValue);          // overridden methods from subclass(es)
289          void setMaxValue(int iMaxValue);          bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
290          void setValue(int iValue);          void clear();
   
 protected:  
   
         // Virtual implemetations.  
         QWidget *createEditor() const;  
         void setContentFromEditor(QWidget *pWidget);  
291    
292  private:      public slots:
293            void refresh(qsamplerDevice* pDevice, bool bEditable);
294    
295          // Initial value holders.      private:
296          int m_iMinValue;          qsamplerDevice* device;
         int m_iMaxValue;  
         int m_iValue;  
297  };  };
298    
   
299  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
300  // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.  // PortParamModel - data model for port parameters (used for QTableView)
301  //  //
302    class PortParamModel : public AbstractDeviceParamModel {
303            Q_OBJECT
304        public:
305            PortParamModel(QObject* parent = 0);
306    
307            // overridden methods from subclass(es)
308            bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
309            void clear();
310    
311  class qsamplerDeviceParamTableEditBox : public QTableItem      public slots:
312  {          void refresh(qsamplerDevicePort* pPort, bool bEditable);
 public:  
   
         // Constructor.  
         qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType,  
                 const QString& sText);  
   
 protected:  
313    
314          // Virtual implemetations.      private:
315          QWidget *createEditor() const;          qsamplerDevicePort* port;
         void setContentFromEditor(QWidget *pWidget);  
316  };  };
317    
318    //-------------------------------------------------------------------------
319    // DeviceParamDelegate - table cell renderer for device/port parameters
320    //
321    class DeviceParamDelegate : public QItemDelegate {
322            Q_OBJECT
323        public:
324            DeviceParamDelegate(QObject* parent = 0);
325            QWidget* createEditor(QWidget* parent,
326                                  const QStyleOptionViewItem& option,
327                                  const QModelIndex& index) const;
328            void setEditorData(QWidget* editor, const QModelIndex& index) const;
329            void setModelData(QWidget* editor, QAbstractItemModel* model,
330                              const QModelIndex& index) const;
331            void updateEditorGeometry(QWidget* editor,
332                                      const QStyleOptionViewItem& option,
333                                      const QModelIndex& index) const;
334    };
335    
336  #endif  // __qsamplerDevice_h  #endif  // __qsamplerDevice_h
337    
   
338  // end of qsamplerDevice.h  // end of qsamplerDevice.h

Legend:
Removed from v.442  
changed lines
  Added in v.1486

  ViewVC Help
Powered by ViewVC