/[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 1489 by schoenebeck, Mon Nov 19 03:29:57 2007 UTC revision 1510 by capela, Thu Nov 22 14:17:24 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 36  Line 36 
36    
37  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41    
42  using namespace QSampler;  using namespace QSampler;
43    
44  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 59  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 156  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 208  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 255  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 423  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 802  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 825  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                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
839                          while (pInstrument) {                          while (pInstrument) {
# Line 856  QString qsamplerChannel::getInstrumentNa Line 864  QString qsamplerChannel::getInstrumentNa
864                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();
865  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
866                  if (bInstrumentNames) {                  if (bInstrumentNames) {
867                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                          RIFF::File *pRiff
868                          gig::File  *pGig  = new gig::File(pRiff);                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
869                            gig::File *pGig = new gig::File(pRiff);
870                          int iIndex = 0;                          int iIndex = 0;
871                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
872                          while (pInstrument) {                          while (pInstrument) {
# Line 901  QString qsamplerChannel::loadingInstrume Line 910  QString qsamplerChannel::loadingInstrume
910  // ChannelRoutingModel - data model for audio routing (used for QTableView)  // ChannelRoutingModel - data model for audio routing (used for QTableView)
911  //  //
912    
913  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
914            : QAbstractTableModel(pParent), m_pDevice(NULL)
915    {
916  }  }
917    
918  int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {  
919      return routing.size();  int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const
920    {
921            return m_routing.size();
922  }  }
923    
924  int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {  
925      return 1;  int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const
926    {
927            return 1;
928  }  }
929    
930  Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {  
931      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;  Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const
932    {
933            return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
934  }  }
935    
 bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {  
     if (!index.isValid()) {  
         return false;  
     }  
936    
937      routing[index.row()] = value.toInt();  bool ChannelRoutingModel::setData ( const QModelIndex& index,
938            const QVariant& value, int /*role*/)
939    {
940            if (!index.isValid())
941                    return false;
942    
943      emit dataChanged(index, index);          m_routing[index.row()] = value.toInt();
     return true;  
 }  
944    
945  QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {          emit dataChanged(index, index);
946      if (!index.isValid())          return true;
947          return QVariant();  }
     if (role != Qt::DisplayRole)  
         return QVariant();  
     if (index.column() != 0)  
         return QVariant();  
948    
     ChannelRoutingItem item;  
949    
950      // The common device port item list.  QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const
951      qsamplerDevicePortList& ports = pDevice->ports();  {
952      qsamplerDevicePort* pPort;          if (!index.isValid())
953      for (pPort = ports.first(); pPort; pPort = ports.next()) {                  return QVariant();
954          item.options.append(          if (role != Qt::DisplayRole)
955              pDevice->deviceTypeName()                  return QVariant();
956              + ' ' + pDevice->driverName()          if (index.column() != 0)
957              + ' ' + pPort->portName()                  return QVariant();
958          );  
959      }          ChannelRoutingItem item;
960    
961            // The common device port item list.
962            qsamplerDevicePortList& ports = m_pDevice->ports();
963            QListIterator<qsamplerDevicePort *> iter(ports);
964            while (iter.hasNext()) {
965                    qsamplerDevicePort *pPort = iter.next();
966                    item.options.append(
967                            m_pDevice->deviceTypeName()
968                            + ' ' + m_pDevice->driverName()
969                            + ' ' + pPort->portName()
970                    );
971            }
972    
973      item.selection = routing[index.row()];          item.selection = m_routing[index.row()];
974    
975      return QVariant::fromValue(item);          return QVariant::fromValue(item);
976  }  }
977    
 QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {  
     if (role != Qt::DisplayRole) return QVariant();  
978    
979      switch (orientation) {  QVariant ChannelRoutingModel::headerData ( int section,
980          case Qt::Horizontal:          Qt::Orientation orientation, int role) const
981              return QObject::tr("-> Device Channel");  {
982          case Qt::Vertical:          if (role != Qt::DisplayRole)
983              return QObject::tr("Sampler Channel ") +                  return QVariant();
984                     QString::number(section) + " ->";  
985          default:          switch (orientation) {
986              return QVariant();                  case Qt::Horizontal:
987      }                          return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
988                    case Qt::Vertical:
989                            return QObject::tr("Sampler Channel ") +
990                                    QString::number(section) + " " + UNICODE_RIGHT_ARROW;
991                    default:
992                            return QVariant();
993            }
994  }  }
995    
996    
997  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,  void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
998          const qsamplerChannelRoutingMap& routing )          const qsamplerChannelRoutingMap& routing )
999  {  {
1000      this->pDevice = pDevice;          m_pDevice = pDevice;
1001      this->routing = routing;          m_routing = routing;
1002      // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1003      QAbstractTableModel::reset();          QAbstractTableModel::reset();
1004  }  }
1005    
1006    
# Line 981  void ChannelRoutingModel::refresh ( qsam Line 1008  void ChannelRoutingModel::refresh ( qsam
1008  // ChannelRoutingDelegate - table cell renderer for audio routing  // ChannelRoutingDelegate - table cell renderer for audio routing
1009  //  //
1010    
1011  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {  ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent )
1012            : QItemDelegate(pParent)
1013    {
1014  }  }
1015    
1016  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,  
1017          const QStyleOptionViewItem & option ,  QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent,
1018          const QModelIndex& index) const          const QStyleOptionViewItem & option, const QModelIndex& index ) const
1019  {  {
1020      if (!index.isValid()) {          if (!index.isValid())
1021          return NULL;                  return NULL;
     }  
1022    
1023      if (index.column() != 0) {          if (index.column() != 0)
1024          return NULL;                  return NULL;
     }  
1025    
1026      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1027    
1028      QComboBox* pComboBox = new QComboBox(parent);          QComboBox* pComboBox = new QComboBox(pParent);
1029      pComboBox->addItems(item.options);          pComboBox->addItems(item.options);
1030      pComboBox->setCurrentIndex(item.selection);          pComboBox->setCurrentIndex(item.selection);
1031      pComboBox->setEnabled(true);          pComboBox->setEnabled(true);
1032      pComboBox->setGeometry(option.rect);          pComboBox->setGeometry(option.rect);
1033      return pComboBox;          return pComboBox;
1034  }  }
1035    
1036  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {  
1037      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();  void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor,
1038      QComboBox* comboBox = static_cast<QComboBox*>(editor);          const QModelIndex &index) const
1039      comboBox->setCurrentIndex(item.selection);  {
1040            ChannelRoutingItem item = index.model()->data(index,
1041                    Qt::DisplayRole).value<ChannelRoutingItem> ();
1042            QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1043            pComboBox->setCurrentIndex(item.selection);
1044  }  }
1045    
1046  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {  
1047      QComboBox* comboBox = static_cast<QComboBox*>(editor);  void ChannelRoutingDelegate::setModelData ( QWidget* pEditor,
1048      model->setData(index, comboBox->currentIndex());          QAbstractItemModel *pModel, const QModelIndex& index ) const
1049    {
1050            QComboBox *pComboBox = static_cast<QComboBox*> (pEditor);
1051            pModel->setData(index, pComboBox->currentIndex());
1052  }  }
1053    
1054  void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,  
1055          const QStyleOptionViewItem &option, const QModelIndex &/* index */) const  void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor,
1056            const QStyleOptionViewItem& option, const QModelIndex &/* index */) const
1057  {  {
1058      editor->setGeometry(option.rect);          pEditor->setGeometry(option.rect);
1059  }  }
1060    
1061    
1062  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

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

  ViewVC Help
Powered by ViewVC