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

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

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

revision 1490 by schoenebeck, Mon Nov 19 04:09:30 2007 UTC revision 1527 by schoenebeck, Mon Nov 26 16:00:21 2007 UTC
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
 #include "qsamplerUtilities.h"  
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    #include "qsamplerUtilities.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
29    
30  #include <qfileinfo.h>  #include <QFileInfo>
31  #include <qcombobox.h>  #include <QComboBox>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
# Line 38  Line 38 
38    
39  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41    
42  using namespace QSampler;  using namespace QSampler;
43    
44  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 61  qsamplerChannel::qsamplerChannel ( int i Line 62  qsamplerChannel::qsamplerChannel ( int i
62          m_iMidiMap          = -1;          m_iMidiMap          = -1;
63          m_sAudioDriver      = "ALSA";          m_sAudioDriver      = "ALSA";
64          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
65          m_fVolume           = 0.0;          m_fVolume           = 0.0f;
66          m_bMute             = false;          m_bMute             = false;
67          m_bSolo             = false;          m_bSolo             = false;
68  }  }
# Line 158  bool qsamplerChannel::loadEngine ( const Line 159  bool qsamplerChannel::loadEngine ( const
159          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
160                  return true;                  return true;
161    
162          if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(),
163                            sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) {
164                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
165                  return false;                  return false;
166          }          }
# Line 210  bool qsamplerChannel::loadInstrument ( c Line 212  bool qsamplerChannel::loadInstrument ( c
212          if (          if (
213                  ::lscp_load_instrument_non_modal(                  ::lscp_load_instrument_non_modal(
214                          pMainForm->client(),                          pMainForm->client(),
215                          qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),                          qsamplerUtilities::lscpEscapePath(
216                                    sInstrumentFile).toUtf8().constData(),
217                          iInstrumentNr, m_iChannelID                          iInstrumentNr, m_iChannelID
218                  ) != LSCP_OK                  ) != LSCP_OK
219          ) {          ) {
# Line 257  bool qsamplerChannel::setMidiDriver ( co Line 260  bool qsamplerChannel::setMidiDriver ( co
260          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
261                  return true;                  return true;
262    
263          if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_midi_type(pMainForm->client(),
264                            m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) {
265                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
266                  return false;                  return false;
267          }          }
# Line 425  bool qsamplerChannel::setAudioDriver ( c Line 429  bool qsamplerChannel::setAudioDriver ( c
429          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
430                  return true;                  return true;
431    
432          if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_audio_type(pMainForm->client(),
433                            m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) {
434                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
435                  return false;                  return false;
436          }          }
# Line 804  bool qsamplerChannel::isInstrumentFile ( Line 809  bool qsamplerChannel::isInstrumentFile (
809          bool bResult = false;          bool bResult = false;
810    
811          QFile file(sInstrumentFile);          QFile file(sInstrumentFile);
812          if (file.open(IO_ReadOnly)) {          if (file.open(QIODevice::ReadOnly)) {
813                  char achHeader[16];                  char achHeader[16];
814                  if (file.readBlock(achHeader, 16)) {                  if (file.read(achHeader, 16) > 0) {
815                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
816                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
817                  }                  }
# Line 827  QStringList qsamplerChannel::getInstrume Line 832  QStringList qsamplerChannel::getInstrume
832          if (isInstrumentFile(sInstrumentFile)) {          if (isInstrumentFile(sInstrumentFile)) {
833  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
834                  if (bInstrumentNames) {                  if (bInstrumentNames) {
835                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                          RIFF::File *pRiff
836                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
837                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
838    #if HAVE_LIBGIG_SETAUTOLOAD
839                            // prevent sleepy response time on large .gig files
840                            pGig->SetAutoLoad(false);
841    #endif
842                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
843                          while (pInstrument) {                          while (pInstrument) {
844                                  instlist.append((pInstrument->pInfo)->Name.c_str());                                  instlist.append((pInstrument->pInfo)->Name.c_str());
# Line 858  QString qsamplerChannel::getInstrumentNa Line 868  QString qsamplerChannel::getInstrumentNa
868                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();
869  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
870                  if (bInstrumentNames) {                  if (bInstrumentNames) {
871                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                          RIFF::File *pRiff
872                          gig::File  *pGig  = new gig::File(pRiff);                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
873                            gig::File *pGig = new gig::File(pRiff);
874    #if HAVE_LIBGIG_SETAUTOLOAD
875                            // prevent sleepy response time on large .gig files
876                            pGig->SetAutoLoad(false);
877    #endif
878                          int iIndex = 0;                          int iIndex = 0;
879                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
880                          while (pInstrument) {                          while (pInstrument) {
# Line 903  QString qsamplerChannel::loadingInstrume Line 918  QString qsamplerChannel::loadingInstrume
918  // ChannelRoutingModel - data model for audio routing (used for QTableView)  // ChannelRoutingModel - data model for audio routing (used for QTableView)
919  //  //
920    
921  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
922            : QAbstractTableModel(pParent), m_pDevice(NULL)
923    {
924  }  }
925    
926  int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {  
927      return routing.size();  int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const
928    {
929            return m_routing.size();
930  }  }
931    
932  int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {  
933      return 1;  int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const
934    {
935            return 1;
936  }  }
937    
938  Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {  
939      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;  Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const
940    {
941            return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
942  }  }
943    
 bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  
     if (!index.isValid()) {  
         return false;  
     }  
944    
945      routing[index.row()] = value.toInt();  bool ChannelRoutingModel::setData ( const QModelIndex& index,
946            const QVariant& value, int /*role*/)
947    {
948            if (!index.isValid())
949                    return false;
950    
951      emit dataChanged(index, index);          m_routing[index.row()] = value.toInt();
     return true;  
 }  
952    
953  QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {          emit dataChanged(index, index);
954      if (!index.isValid())          return true;
955          return QVariant();  }
     if (role != Qt::DisplayRole)  
         return QVariant();  
     if (index.column() != 0)  
         return QVariant();  
956    
     ChannelRoutingItem item;  
957    
958      // The common device port item list.  QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const
959      qsamplerDevicePortList& ports = pDevice->ports();  {
960      qsamplerDevicePort* pPort;          if (!index.isValid())
961      for (pPort = ports.first(); pPort; pPort = ports.next()) {                  return QVariant();
962          item.options.append(          if (role != Qt::DisplayRole)
963              pDevice->deviceTypeName()                  return QVariant();
964              + ' ' + pDevice->driverName()          if (index.column() != 0)
965              + ' ' + pPort->portName()                  return QVariant();
966          );  
967      }          ChannelRoutingItem item;
968    
969            // The common device port item list.
970            qsamplerDevicePortList& ports = m_pDevice->ports();
971            QListIterator<qsamplerDevicePort *> iter(ports);
972            while (iter.hasNext()) {
973                    qsamplerDevicePort *pPort = iter.next();
974                    item.options.append(
975                            m_pDevice->deviceTypeName()
976                            + ' ' + m_pDevice->driverName()
977                            + ' ' + pPort->portName()
978                    );
979            }
980    
981      item.selection = routing[index.row()];          item.selection = m_routing[index.row()];
982    
983      return QVariant::fromValue(item);          return QVariant::fromValue(item);
984  }  }
985    
 QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {  
     if (role != Qt::DisplayRole) return QVariant();  
986    
987      switch (orientation) {  QVariant ChannelRoutingModel::headerData ( int section,
988          case Qt::Horizontal:          Qt::Orientation orientation, int role) const
989              return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");  {
990          case Qt::Vertical:          if (role != Qt::DisplayRole)
991              return QObject::tr("Sampler Channel ") +                  return QVariant();
992                     QString::number(section) + " " + UNICODE_RIGHT_ARROW;  
993          default:          switch (orientation) {
994              return QVariant();                  case Qt::Horizontal:
995      }                          return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
996                    case Qt::Vertical:
997                            return QObject::tr("Sampler Channel ") +
998                                    QString::number(section) + " " + UNICODE_RIGHT_ARROW;
999                    default:
1000                            return QVariant();
1001            }
1002  }  }
1003    
1004    
1005  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
1006          const qsamplerChannelRoutingMap& routing )          const qsamplerChannelRoutingMap& routing )
1007  {  {
1008      this->pDevice = pDevice;          m_pDevice = pDevice;
1009      this->routing = routing;          m_routing = routing;
1010      // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1011      QAbstractTableModel::reset();          QAbstractTableModel::reset();
1012  }  }
1013    
1014    
# Line 983  void ChannelRoutingModel::refresh ( qsam Line 1016  void ChannelRoutingModel::refresh ( qsam
1016  // ChannelRoutingDelegate - table cell renderer for audio routing  // ChannelRoutingDelegate - table cell renderer for audio routing
1017  //  //
1018    
1019  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {  ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent )
1020            : QItemDelegate(pParent)
1021    {
1022  }  }
1023    
1024  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,  
1025          const QStyleOptionViewItem & option ,  QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent,
1026          const QModelIndex& index) const          const QStyleOptionViewItem & option, const QModelIndex& index ) const
1027  {  {
1028      if (!index.isValid()) {          if (!index.isValid())
1029          return NULL;                  return NULL;
     }  
1030    
1031      if (index.column() != 0) {          if (index.column() != 0)
1032          return NULL;                  return NULL;
     }  
1033    
1034      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1035    
1036      QComboBox* pComboBox = new QComboBox(parent);          QComboBox* pComboBox = new QComboBox(pParent);
1037      pComboBox->addItems(item.options);          pComboBox->addItems(item.options);
1038      pComboBox->setCurrentIndex(item.selection);          pComboBox->setCurrentIndex(item.selection);
1039      pComboBox->setEnabled(true);          pComboBox->setEnabled(true);
1040      pComboBox->setGeometry(option.rect);          pComboBox->setGeometry(option.rect);
1041      return pComboBox;          return pComboBox;
1042  }  }
1043    
1044  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {  
1045      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();  void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor,
1046      QComboBox* comboBox = static_cast<QComboBox*>(editor);          const QModelIndex &index) const
1047      comboBox->setCurrentIndex(item.selection);  {
1048            ChannelRoutingItem item = index.model()->data(index,
1049                    Qt::DisplayRole).value<ChannelRoutingItem> ();
1050            QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1051            pComboBox->setCurrentIndex(item.selection);
1052  }  }
1053    
1054  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {  
1055      QComboBox* comboBox = static_cast<QComboBox*>(editor);  void ChannelRoutingDelegate::setModelData ( QWidget* pEditor,
1056      model->setData(index, comboBox->currentIndex());          QAbstractItemModel *pModel, const QModelIndex& index ) const
1057    {
1058            QComboBox *pComboBox = static_cast<QComboBox*> (pEditor);
1059            pModel->setData(index, pComboBox->currentIndex());
1060  }  }
1061    
1062  void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,  
1063          const QStyleOptionViewItem &option, const QModelIndex &/* index */) const  void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor,
1064            const QStyleOptionViewItem& option, const QModelIndex &/* index */) const
1065  {  {
1066      editor->setGeometry(option.rect);          pEditor->setGeometry(option.rect);
1067  }  }
1068    
1069    
1070  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.1490  
changed lines
  Added in v.1527

  ViewVC Help
Powered by ViewVC