--- qsampler/trunk/src/qsamplerDevice.h 2005/03/15 23:54:14 467 +++ qsampler/trunk/src/qsamplerDevice.h 2007/11/20 16:48:04 1499 @@ -1,7 +1,8 @@ // qsamplerDevice.h // /**************************************************************************** - Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -13,17 +14,26 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *****************************************************************************/ #ifndef __qsamplerDevice_h #define __qsamplerDevice_h -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -34,7 +44,8 @@ // Special QListViewItem::rtti() unique return value. #define QSAMPLER_DEVICE_ITEM 1001 -// Early forward declaration. +// Early forward declarations. +class qsamplerMainForm; class qsamplerDevicePort; @@ -74,7 +85,7 @@ typedef QMap qsamplerDeviceParamMap; // Typedef'd device port/channels QptrList. -typedef QPtrList qsamplerDevicePortList; +typedef QList qsamplerDevicePortList; //------------------------------------------------------------------------- @@ -89,28 +100,28 @@ enum qsamplerDeviceType { None, Midi, Audio }; // Constructor. - qsamplerDevice(lscp_client_t *pClient, - qsamplerDeviceType deviceType, int iDeviceID = -1); + qsamplerDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); + // Copy constructor. + qsamplerDevice(const qsamplerDevice& device); // Default destructor. ~qsamplerDevice(); // Initializer. - void setDevice(lscp_client_t *pClient, - qsamplerDeviceType deviceType, int iDeviceID = -1); + void setDevice(qsamplerDeviceType deviceType, int iDeviceID = -1); // Driver name initializer. - void setDriver(lscp_client_t *pClient, - const QString& sDriverName); + void setDriver(const QString& sDriverName); // Device property accessors. int deviceID() const; qsamplerDeviceType deviceType() const; const QString& deviceTypeName() const; const QString& driverName() const; - const QString& deviceName() const; + // Special device name formatter. + QString deviceName() const; // Set the proper device parameter value. - void setParam (const QString& sParam, const QString& sValue); + bool setParam (const QString& sParam, const QString& sValue); // Device parameters accessor. const qsamplerDeviceParamMap& params() const; @@ -119,11 +130,22 @@ qsamplerDevicePortList& ports(); // Device parameter dependency list refreshner. - int refreshParams(lscp_client_t *pClient); + int refreshParams(); // Device port/channel list refreshner. - int refreshPorts(lscp_client_t *pClient); + int refreshPorts(); // Refresh/set dependencies given that some parameter has changed. - int refreshDepends(lscp_client_t *pClient, const QString& sParam); + int refreshDepends(const QString& sParam); + + // Create/destroy device methods. + bool createDevice(); + bool deleteDevice(); + + // Message logging methods (brainlessly mapped to main form's). + void appendMessages (const QString& s) const; + void appendMessagesColor (const QString& s, const QString & c) const; + void appendMessagesText (const QString& s) const; + void appendMessagesError (const QString& s) const; + void appendMessagesClient (const QString& s) const; // Device ids enumerator. static int *getDevices(lscp_client_t *pClient, @@ -136,7 +158,10 @@ private: // Refresh/set given parameter based on driver supplied dependencies. - int refreshParam(lscp_client_t *pClient, const QString& sParam); + int refreshParam(const QString& sParam); + + // Main application form reference. + qsamplerMainForm *m_pMainForm; // Instance variables. int m_iDeviceID; @@ -147,7 +172,7 @@ // Device parameter list. qsamplerDeviceParamMap m_params; - + // Device port/channel list. qsamplerDevicePortList m_ports; }; @@ -162,14 +187,12 @@ public: // Constructor. - qsamplerDevicePort(lscp_client_t *pClient, - const qsamplerDevice& device, int iPortID); + qsamplerDevicePort(qsamplerDevice& device, int iPortID); // Default destructor. ~qsamplerDevicePort(); // Initializer. - void setDevicePort(lscp_client_t *pClient, - const qsamplerDevice& device, int iPortID); + void setDevicePort(int iPortID); // Device port property accessors. int portID() const; @@ -179,10 +202,13 @@ const qsamplerDeviceParamMap& params() const; // Set the proper device port/channel parameter value. - void setParam (const QString& sParam, const QString& sValue); + bool setParam (const QString& sParam, const QString& sValue); private: + // Device reference. + qsamplerDevice& m_device; + // Instance variables. int m_iPortID; QString m_sPortName; @@ -196,14 +222,14 @@ // qsamplerDeviceItem - QListView device item. // -class qsamplerDeviceItem : public QListViewItem +class qsamplerDeviceItem : public QTreeWidgetItem { public: // Constructors. - qsamplerDeviceItem(QListView *pListView, lscp_client_t *pClient, + qsamplerDeviceItem(QTreeWidget* pTreeWidget, qsamplerDevice::qsamplerDeviceType deviceType); - qsamplerDeviceItem(QListViewItem *pItem, lscp_client_t *pClient, + qsamplerDeviceItem(QTreeWidgetItem* pItem, qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID); // Default destructor. ~qsamplerDeviceItem(); @@ -211,89 +237,100 @@ // Instance accessors. qsamplerDevice& device(); - // To virtually distinguish between list view items. - virtual int rtti() const; - private: // Instance variables. qsamplerDevice m_device; }; +struct DeviceParameterRow { + QString name; + qsamplerDeviceParam param; +}; + +// so we can use it i.e. through QVariant +Q_DECLARE_METATYPE(DeviceParameterRow) //------------------------------------------------------------------------- -// qsamplerDeviceParamTable - Device parameter view table. +// AbstractDeviceParamModel - data model base class for device parameters // - -class qsamplerDeviceParamTable : public QTable -{ - Q_OBJECT - -public: - - // Constructor. - qsamplerDeviceParamTable(QWidget *pParent = 0, const char *pszName = 0); - // Default destructor. - ~qsamplerDeviceParamTable(); - - // Common parameter table renderer. - void refresh(const qsamplerDeviceParamMap& params, bool bEditable); +class AbstractDeviceParamModel : public QAbstractTableModel { + Q_OBJECT + public: + AbstractDeviceParamModel(QObject* parent = 0); + + // overridden methods from subclass(es) + int rowCount(const QModelIndex& parent = QModelIndex()) const; + int columnCount(const QModelIndex& parent = QModelIndex() ) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + Qt::ItemFlags flags(const QModelIndex& index) const; + + virtual void clear(); + + void refresh(const qsamplerDeviceParamMap* params, bool bEditable); + + protected: + const qsamplerDeviceParamMap* params; + bool bEditable; }; - //------------------------------------------------------------------------- -// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. +// DeviceParamModel - data model for device parameters (used for QTableView) // +class DeviceParamModel : public AbstractDeviceParamModel { + Q_OBJECT + public: + DeviceParamModel(QObject* parent = 0); + + // overridden methods from subclass(es) + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + void clear(); -class qsamplerDeviceParamTableSpinBox : public QTableItem -{ -public: - - // Constructor. - qsamplerDeviceParamTableSpinBox (QTable *pTable, EditType editType, - const QString& sText); - - // Public accessors. - void setMinValue(int iMinValue); - void setMaxValue(int iMaxValue); - void setValue(int iValue); - -protected: - - // Virtual implemetations. - QWidget *createEditor() const; - void setContentFromEditor(QWidget *pWidget); + public slots: + void refresh(qsamplerDevice* pDevice, bool bEditable); -private: - - // Initial value holders. - int m_iValue; - int m_iMinValue; - int m_iMaxValue; + private: + qsamplerDevice* device; }; - //------------------------------------------------------------------------- -// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. +// PortParamModel - data model for port parameters (used for QTableView) // +class PortParamModel : public AbstractDeviceParamModel { + Q_OBJECT + public: + PortParamModel(QObject* parent = 0); + + // overridden methods from subclass(es) + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + void clear(); -class qsamplerDeviceParamTableEditBox : public QTableItem -{ -public: - - // Constructor. - qsamplerDeviceParamTableEditBox (QTable *pTable, EditType editType, - const QString& sText); - -protected: + public slots: + void refresh(qsamplerDevicePort* pPort, bool bEditable); - // Virtual implemetations. - QWidget *createEditor() const; - void setContentFromEditor(QWidget *pWidget); + private: + qsamplerDevicePort* port; }; +//------------------------------------------------------------------------- +// DeviceParamDelegate - table cell renderer for device/port parameters +// +class DeviceParamDelegate : public QItemDelegate { + Q_OBJECT + public: + DeviceParamDelegate(QObject* parent = 0); + QWidget* createEditor(QWidget* parent, + const QStyleOptionViewItem& option, + const QModelIndex& index) const; + void setEditorData(QWidget* editor, const QModelIndex& index) const; + void setModelData(QWidget* editor, QAbstractItemModel* model, + const QModelIndex& index) const; + void updateEditorGeometry(QWidget* editor, + const QStyleOptionViewItem& option, + const QModelIndex& index) const; +}; #endif // __qsamplerDevice_h - // end of qsamplerDevice.h