/[svn]/qsampler/trunk/src/qsamplerDevice.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDevice.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 980 by capela, Sun Dec 17 22:29:29 2006 UTC revision 1461 by schoenebeck, Sun Oct 28 23:30:36 2007 UTC
# Line 1  Line 1 
1  // qsamplerDevice.cpp  // qsamplerDevice.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 28  Line 28 
28  #include <qspinbox.h>  #include <qspinbox.h>
29  #include <qlineedit.h>  #include <qlineedit.h>
30    
31    using namespace QSampler;
32    
33  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
34  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.  // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
# Line 130  qsamplerDevice::qsamplerDevice ( const q Line 131  qsamplerDevice::qsamplerDevice ( const q
131  // Initializer.  // Initializer.
132  void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID )  void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID )
133  {  {
134          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
135          if (pMainForm == NULL)          if (pMainForm == NULL)
136                  return;                  return;
137          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 209  void qsamplerDevice::setDevice ( qsample Line 210  void qsamplerDevice::setDevice ( qsample
210  // Driver name initializer/settler.  // Driver name initializer/settler.
211  void qsamplerDevice::setDriver ( const QString& sDriverName )  void qsamplerDevice::setDriver ( const QString& sDriverName )
212  {  {
213          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
214          if (pMainForm == NULL)          if (pMainForm == NULL)
215                  return;                  return;
216          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 313  QString qsamplerDevice::deviceName (void Line 314  QString qsamplerDevice::deviceName (void
314  bool qsamplerDevice::setParam ( const QString& sParam,  bool qsamplerDevice::setParam ( const QString& sParam,
315          const QString& sValue )          const QString& sValue )
316  {  {
317          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
318          if (pMainForm == NULL)          if (pMainForm == NULL)
319                  return false;                  return false;
320          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 383  qsamplerDevicePortList& qsamplerDevice:: Line 384  qsamplerDevicePortList& qsamplerDevice::
384  // Create a new device, as a copy of this current one.  // Create a new device, as a copy of this current one.
385  bool qsamplerDevice::createDevice (void)  bool qsamplerDevice::createDevice (void)
386  {  {
387          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
388          if (pMainForm == NULL)          if (pMainForm == NULL)
389                  return false;                  return false;
390          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 438  bool qsamplerDevice::createDevice (void) Line 439  bool qsamplerDevice::createDevice (void)
439  // Destroy existing device.  // Destroy existing device.
440  bool qsamplerDevice::deleteDevice (void)  bool qsamplerDevice::deleteDevice (void)
441  {  {
442          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
443          if (pMainForm == NULL)          if (pMainForm == NULL)
444                  return false;                  return false;
445          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 539  int qsamplerDevice::refreshDepends ( con Line 540  int qsamplerDevice::refreshDepends ( con
540  // Refresh/set given parameter based on driver supplied dependencies.  // Refresh/set given parameter based on driver supplied dependencies.
541  int qsamplerDevice::refreshParam ( const QString& sParam )  int qsamplerDevice::refreshParam ( const QString& sParam )
542  {  {
543          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
544          if (pMainForm == NULL)          if (pMainForm == NULL)
545                  return 0;                  return 0;
546          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 603  int qsamplerDevice::refreshParam ( const Line 604  int qsamplerDevice::refreshParam ( const
604  // Redirected messages output methods.  // Redirected messages output methods.
605  void qsamplerDevice::appendMessages( const QString& s ) const  void qsamplerDevice::appendMessages( const QString& s ) const
606  {  {
607          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
608          if (pMainForm)          if (pMainForm)
609                  pMainForm->appendMessages(deviceName() + ' ' + s);                  pMainForm->appendMessages(deviceName() + ' ' + s);
610  }  }
# Line 611  void qsamplerDevice::appendMessages( con Line 612  void qsamplerDevice::appendMessages( con
612  void qsamplerDevice::appendMessagesColor( const QString& s,  void qsamplerDevice::appendMessagesColor( const QString& s,
613          const QString& c ) const          const QString& c ) const
614  {  {
615          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
616          if (pMainForm)          if (pMainForm)
617                  pMainForm->appendMessagesColor(deviceName() + ' ' + s, c);                  pMainForm->appendMessagesColor(deviceName() + ' ' + s, c);
618  }  }
619    
620  void qsamplerDevice::appendMessagesText( const QString& s ) const  void qsamplerDevice::appendMessagesText( const QString& s ) const
621  {  {
622          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
623          if (pMainForm)          if (pMainForm)
624                  pMainForm->appendMessagesText(deviceName() + ' ' + s);                  pMainForm->appendMessagesText(deviceName() + ' ' + s);
625  }  }
626    
627  void qsamplerDevice::appendMessagesError( const QString& s ) const  void qsamplerDevice::appendMessagesError( const QString& s ) const
628  {  {
629          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
630          if (pMainForm)          if (pMainForm)
631                  pMainForm->appendMessagesError(deviceName() + "\n\n" + s);                  pMainForm->appendMessagesError(deviceName() + "\n\n" + s);
632  }  }
633    
634  void qsamplerDevice::appendMessagesClient( const QString& s ) const  void qsamplerDevice::appendMessagesClient( const QString& s ) const
635  {  {
636          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
637          if (pMainForm)          if (pMainForm)
638                  pMainForm->appendMessagesClient(deviceName() + ' ' + s);                  pMainForm->appendMessagesClient(deviceName() + ' ' + s);
639  }  }
# Line 702  qsamplerDevicePort::~qsamplerDevicePort Line 703  qsamplerDevicePort::~qsamplerDevicePort
703  // Initializer.  // Initializer.
704  void qsamplerDevicePort::setDevicePort ( int iPortID )  void qsamplerDevicePort::setDevicePort ( int iPortID )
705  {  {
706          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
707          if (pMainForm == NULL)          if (pMainForm == NULL)
708                  return;                  return;
709          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 791  const qsamplerDeviceParamMap& qsamplerDe Line 792  const qsamplerDeviceParamMap& qsamplerDe
792  bool qsamplerDevicePort::setParam ( const QString& sParam,  bool qsamplerDevicePort::setParam ( const QString& sParam,
793          const QString& sValue )          const QString& sValue )
794  {  {
795          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
796          if (pMainForm == NULL)          if (pMainForm == NULL)
797                  return false;                  return false;
798          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 841  bool qsamplerDevicePort::setParam ( cons Line 842  bool qsamplerDevicePort::setParam ( cons
842    
843    
844  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
845  // qsamplerDeviceItem - QListView device item.  // qsamplerDeviceItem - QTreeWidget device item.
846  //  //
847    
848  // Constructors.  // Constructors.
849  qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView,  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget,
850          qsamplerDevice::qsamplerDeviceType deviceType )          qsamplerDevice::qsamplerDeviceType deviceType )
851          : QListViewItem(pListView), m_device(deviceType)          : QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM),
852          m_device(deviceType)
853  {  {
854          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
855          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
856                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png"));                  setIcon(0, QPixmap(":/qsampler/pixmaps/audio1.png"));
857                  QListViewItem::setText(0, QObject::tr("Audio Devices"));                  setText(1, QObject::tr("Audio Devices"));
858                  break;                  break;
859          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
860                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png"));                  setIcon(0, QPixmap(":/qsampler/pixmaps/midi1.png"));
861                  QListViewItem::setText(0, QObject::tr("MIDI Devices"));                  setText(1, QObject::tr("MIDI Devices"));
862                  break;                  break;
863          case qsamplerDevice::None:          case qsamplerDevice::None:
864                  break;                  break;
865          }          }
866  }  }
867    
868  qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem,  qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem,
869          qsamplerDevice::qsamplerDeviceType deviceType,          qsamplerDevice::qsamplerDeviceType deviceType,
870          int iDeviceID )          int iDeviceID )
871          : QListViewItem(pItem), m_device(deviceType, iDeviceID)          : QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM),
872          m_device(deviceType, iDeviceID)
873  {  {
874          switch(m_device.deviceType()) {          switch(m_device.deviceType()) {
875          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
876                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png"));                  setIcon(0, QPixmap(":/qsampler/pixmaps/audio2.png"));
877                  break;                  break;
878          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
879                  QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png"));                  setIcon(0, QPixmap(":/qsampler/pixmaps/midi2.png"));
880                  break;                  break;
881          case qsamplerDevice::None:          case qsamplerDevice::None:
882                  break;                  break;
883          }          }
884    
885          QListViewItem::setText(0, m_device.deviceName());          setText(1, m_device.deviceName());
886  }  }
887    
888  // Default destructor.  // Default destructor.
# Line 893  qsamplerDevice& qsamplerDeviceItem::devi Line 896  qsamplerDevice& qsamplerDeviceItem::devi
896          return m_device;          return m_device;
897  }  }
898    
 // To virtually distinguish between list view items.  
 int qsamplerDeviceItem::rtti() const  
 {  
         return QSAMPLER_DEVICE_ITEM;  
 }  
   
899    
900    
901  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
902  // qsamplerDeviceParamTable - Device parameter view table.  // qsamplerDeviceParamTable - Device parameter view table.
903  //  //
904    #if 0
905  // Constructor.  // Constructor.
906  qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent,  qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent,
907          const char *pszName )          const char *pszName )
# Line 1000  void qsamplerDeviceParamTable::refresh ( Line 997  void qsamplerDeviceParamTable::refresh (
997          QTable::setUpdatesEnabled(true);          QTable::setUpdatesEnabled(true);
998          QTable::updateContents();          QTable::updateContents();
999  }  }
1000    #endif
1001    
1002    DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) {
1003    }
1004    
1005    int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const {
1006        return params.size();
1007    }
1008    
1009    int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const {
1010        return 3;
1011    }
1012    
1013    QVariant DeviceParamModel::data(const QModelIndex &index, int role) const {
1014        if (!index.isValid())
1015            return QVariant();
1016        if (role != Qt::DisplayRole)
1017            return QVariant();
1018    
1019        DeviceParameterRow item;
1020        item.name  = params.keys()[index.row()];
1021        item.param = params[item.name];
1022    
1023        return QVariant::fromValue(item);
1024    }
1025    
1026    QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const {
1027        if (role != Qt::DisplayRole) return QVariant();
1028    
1029        if (orientation == Qt::Horizontal) {
1030            switch (section) {
1031                case 0:  return tr("Parameter");
1032                case 1:  return tr("Value");
1033                case 2:  return tr("Description");
1034                default: return QVariant();
1035            }
1036        }
1037    
1038        return QVariant();
1039    }
1040    
1041    void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable)
1042    {
1043        this->params    = params;
1044        this->bEditable = bEditable;
1045    }
1046    
1047    void DeviceParamModel::clear() {
1048        params.clear();
1049    }
1050    
1051    
1052    DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) {
1053    }
1054    
1055    QWidget* DeviceParamDelegate::createEditor(QWidget *parent,
1056            const QStyleOptionViewItem &/* option */,
1057            const QModelIndex& index) const
1058    {
1059        DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>();
1060    
1061        const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix);
1062    
1063        switch (index.column()) {
1064            case 0:
1065                return new QLabel(r.name, parent);
1066            case 1: {
1067                if (r.param.type == LSCP_TYPE_BOOL) {
1068                    QCheckBox* pCheckBox = new QCheckBox(parent);
1069                    pCheckBox->setChecked(r.param.value.lower() == "true");
1070                    pCheckBox->setEnabled(bEnabled);
1071                    return pCheckBox;
1072                } else if (r.param.possibilities.count() > 0 && bEnabled) {
1073                    QStringList opts = r.param.possibilities;
1074                    if (r.param.multiplicity)
1075                        opts.prepend(tr("(none)"));
1076                    QComboBox* pComboBox = new QComboBox(parent);
1077                    pComboBox->addItems(opts);
1078                    if (r.param.value.isEmpty())
1079                        pComboBox->setCurrentIndex(0);
1080                    else
1081                        pComboBox->setCurrentIndex(pComboBox->findText(r.param.value));
1082                    pComboBox->setEnabled(bEnabled);
1083                    return pComboBox;
1084                } else if (r.param.type == LSCP_TYPE_INT && bEnabled
1085                           && !r.param.range_min.isEmpty()
1086                           && !r.param.range_max.isEmpty()) {
1087                    QSpinBox* pSpinBox = new QSpinBox(parent);
1088                    pSpinBox->setValue(r.param.value.toInt());
1089                    pSpinBox->setMinimum(r.param.range_min.toInt());
1090                    pSpinBox->setMaximum(r.param.range_max.toInt());
1091                    return pSpinBox;
1092                } else {
1093                    QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent);
1094                    return pLineEdit;
1095                }
1096            }
1097            case 2:
1098                return new QLabel(r.param.description, parent);
1099            default:
1100                return NULL;
1101        }
1102    }
1103    
1104    void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1105    /*
1106        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1107        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1108        comboBox->setCurrentIndex(item.selection);
1109    */
1110    }
1111    
1112    void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
1113    /*
1114        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1115        model->setData(index, comboBox->currentIndex());
1116    */
1117    }
1118    
1119    void DeviceParamDelegate::updateEditorGeometry(QWidget* editor,
1120            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1121    {
1122        if (editor) editor->setGeometry(option.rect);
1123    }
1124    
1125  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1126  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.  // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.
1127  //  //
1128    
1129    #if 0
1130  // Constructor.  // Constructor.
1131  qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox (  qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox (
1132          QTable *pTable, EditType editType, const QString& sText )          QTable *pTable, EditType editType, const QString& sText )
# Line 1083  void qsamplerDeviceParamTableEditBox::se Line 1204  void qsamplerDeviceParamTableEditBox::se
1204          else          else
1205                  QTableItem::setContentFromEditor(pWidget);                  QTableItem::setContentFromEditor(pWidget);
1206  }  }
1207    #endif
1208    
1209  // end of qsamplerDevice.cpp  // end of qsamplerDevice.cpp
1210    

Legend:
Removed from v.980  
changed lines
  Added in v.1461

  ViewVC Help
Powered by ViewVC