/[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 2387 by capela, Sat Dec 29 00:21:11 2012 UTC revision 2563 by capela, Tue May 20 10:59:37 2014 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 2008 Christian Schoenebeck     Copyright (C) 2007, 2008 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
# Line 32  Line 32 
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
35    #include "SF.h"
36  #endif  #endif
37    
38  namespace QSampler {  namespace QSampler {
39    
40  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 128
41    
42  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
43    
# Line 822  bool Channel::isDlsInstrumentFile ( cons Line 823  bool Channel::isDlsInstrumentFile ( cons
823  }  }
824    
825    
826    // FIXME: Check whether a given file is an instrument file (SF2 only).
827    bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile )
828    {
829            bool bResult = false;
830    
831            QFile file(sInstrumentFile);
832            if (file.open(QIODevice::ReadOnly)) {
833                    char achHeader[8];
834                    if (file.read(achHeader, 8) > 0) {
835                            bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0
836                                            && ::memcmp(&achHeader[4], "sfbk", 4) == 0);
837                    }
838                    file.close();
839            }
840    
841            return bResult;
842    }
843    
844    
845  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
846  QStringList Channel::getInstrumentList( const QString& sInstrumentFile,  QStringList Channel::getInstrumentList(
847          bool bInstrumentNames )          const QString& sInstrumentFile, bool bInstrumentNames )
848  {  {
849          QStringList instlist;          QStringList instlist;
850    
851          if (isDlsInstrumentFile(sInstrumentFile)) {          const QFileInfo fi(sInstrumentFile);
852          #ifdef CONFIG_LIBGIG          if (!fi.exists()) {
853                  if (bInstrumentNames) {                  instlist.append(noInstrumentName());
854                    return instlist;
855            }
856    
857    #ifdef CONFIG_LIBGIG
858            if (bInstrumentNames) {
859                    if (isDlsInstrumentFile(sInstrumentFile)) {
860                          RIFF::File *pRiff                          RIFF::File *pRiff
861                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
862                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
# Line 846  QStringList Channel::getInstrumentList( Line 872  QStringList Channel::getInstrumentList(
872                          delete pGig;                          delete pGig;
873                          delete pRiff;                          delete pRiff;
874                  }                  }
875          #endif                  else
876                    if (isSf2InstrumentFile(sInstrumentFile)) {
877                            RIFF::File *pRiff
878                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
879                            sf2::File *pSf2 = new sf2::File(pRiff);
880                            const int iPresetCount = pSf2->GetPresetCount();
881                            for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) {
882                                    sf2::Preset *pPreset = pSf2->GetPreset(iIndex);
883                                    if (pPreset) {
884                                            instlist.append(pPreset->Name.c_str());
885                                    } else {
886                                            instlist.append(fi.fileName()
887                                                    + " [" + QString::number(iIndex) + "]");
888                                    }
889                            }
890                            delete pSf2;
891                            delete pRiff;
892                    }
893          }          }
894    #endif
895    
896          if (instlist.isEmpty()) {          if (instlist.isEmpty()) {
897                  QFileInfo fi(sInstrumentFile);                  for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) {
898                  if (fi.exists()) {                          instlist.append(fi.fileName()
899                          QString sInstrumentName = fi.fileName();                                  + " [" + QString::number(iIndex) + "]");
                         int iInstrumentNr = 0;  
                         while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) {  
                                 instlist.append(sInstrumentName  
                                         + " [" + QString::number(++iInstrumentNr) + "]");  
                         }  
900                  }                  }
                 else instlist.append(noInstrumentName());  
901          }          }
902    
903          return instlist;          return instlist;
# Line 867  QStringList Channel::getInstrumentList( Line 905  QStringList Channel::getInstrumentList(
905    
906    
907  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
908  QString Channel::getInstrumentName( const QString& sInstrumentFile,  QString Channel::getInstrumentName (
909          int iInstrumentNr, bool bInstrumentNames )          const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames )
910  {  {
911            const QFileInfo fi(sInstrumentFile);
912            if (!fi.exists())
913                    return noInstrumentName();
914    
915          QString sInstrumentName;          QString sInstrumentName;
916    
917          if (isDlsInstrumentFile(sInstrumentFile)) {  #ifdef CONFIG_LIBGIG
918          #ifdef CONFIG_LIBGIG          if (bInstrumentNames) {
919                  if (bInstrumentNames) {                  if (isDlsInstrumentFile(sInstrumentFile)) {
920                          RIFF::File *pRiff                          RIFF::File *pRiff
921                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
922                          gig::File *pGig = new gig::File(pRiff);                          gig::File *pGig = new gig::File(pRiff);
# Line 895  QString Channel::getInstrumentName( cons Line 937  QString Channel::getInstrumentName( cons
937                          delete pGig;                          delete pGig;
938                          delete pRiff;                          delete pRiff;
939                  }                  }
940          #endif                  else
941                    if (isSf2InstrumentFile(sInstrumentFile)) {
942                            RIFF::File *pRiff
943                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
944                            sf2::File *pSf2 = new sf2::File(pRiff);
945                            sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr);
946                            if (pPreset)
947                                    sInstrumentName = pPreset->Name.c_str();
948                            delete pSf2;
949                            delete pRiff;
950                    }
951          }          }
952    #endif
953    
954          if (sInstrumentName.isEmpty()) {          if (sInstrumentName.isEmpty()) {
955                  QFileInfo fi(sInstrumentFile);                  sInstrumentName  = fi.fileName();
956                  if (fi.exists()) {                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
                         sInstrumentName  = fi.fileName();  
                         sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";  
                 }  
                 else sInstrumentName = noInstrumentName();  
957          }          }
958    
959          return sInstrumentName;          return sInstrumentName;

Legend:
Removed from v.2387  
changed lines
  Added in v.2563

  ViewVC Help
Powered by ViewVC