/[svn]/libgig/trunk/src/SF.cpp
ViewVC logotype

Diff of /libgig/trunk/src/SF.cpp

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

revision 2026 by iliev, Tue Nov 3 19:08:44 2009 UTC revision 2100 by persson, Sun May 30 11:39:36 2010 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libsf2 - C++ cross-platform SF2 format file access library            *   *   libsf2 - C++ cross-platform SF2 format file access library            *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2009 Grigor Iliev  <grigor@grigoriliev.com>             *   *   Copyright (C) 2009-2010 Grigor Iliev  <grigor@grigoriliev.com>,       *
6   *   Copyright (C) 2009 Christian Schoenebeck                              *   *    Christian Schoenebeck and Andreas Persson                            *
  *   Copyright (C) 2009 Andreas Persson                                    *  
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 22  Line 21 
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
23    
 #include <vector>  
   
24  #include "RIFF.h"  #include "RIFF.h"
25    
26  #include "SF.h"  #include "SF.h"
# Line 616  namespace sf2 { Line 613  namespace sf2 {
613          if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo);          if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo);
614          return ToHz(pPresetRegion->freqModLfo + freqModLfo);          return ToHz(pPresetRegion->freqModLfo + freqModLfo);
615      }      }
616        
617      double Region::GetDelayModLfo(Region* pPresetRegion) {      double Region::GetDelayModLfo(Region* pPresetRegion) {
618          if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo);          if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo);
619          return ToSeconds(pPresetRegion->delayModLfo + delayModLfo);          return ToSeconds(pPresetRegion->delayModLfo + delayModLfo);
# Line 660  namespace sf2 { Line 657  namespace sf2 {
657          return regions[idx];          return regions[idx];
658      }      }
659    
660      std::vector<Region*> InstrumentBase::GetRegionsOnKey(int key, uint8_t vel) {      Query::Query(InstrumentBase& instrument) : instrument(instrument) {
661          std::vector<Region*> v;          i = 0;
662          for (int i = 0; i < GetRegionCount(); i++) {      }
663              Region* r = GetRegion(i);  
664              if (      Region* Query::next() {
665                  ((r->loKey  == NONE && r->hiKey  == NONE) || (key >= r->loKey && key <= r->hiKey)) &&          while (i < instrument.GetRegionCount()) {
666                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))              Region* r = instrument.GetRegion(i++);
667              ) {              if (((r->loKey  == NONE && r->hiKey  == NONE) || (key >= r->loKey && key <= r->hiKey)) &&
668                  v.push_back(r);                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))) {
669                    return r;
670              }              }
671          }          }
672            return 0;
         return v;  
673      }      }
674    
675      Instrument::Instrument(sf2::File* pFile, RIFF::Chunk* ck) : InstrumentBase(pFile) {      Instrument::Instrument(sf2::File* pFile, RIFF::Chunk* ck) : InstrumentBase(pFile) {
# Line 682  namespace sf2 { Line 679  namespace sf2 {
679      }      }
680    
681      Instrument::~Instrument() {      Instrument::~Instrument() {
           
682      }      }
683    
684      Region* Instrument::CreateRegion() {      Region* Instrument::CreateRegion() {
# Line 771  namespace sf2 { Line 767  namespace sf2 {
767              }              }
768    
769              Region* reg = CreateRegion();              Region* reg = CreateRegion();
770                
771              for (int j = gIdx1; j < gIdx2; j++) {              for (int j = gIdx1; j < gIdx2; j++) {
772                  reg->SetGenerator(pFile, pFile->InstGenLists[j]);                  reg->SetGenerator(pFile, pFile->InstGenLists[j]);
773                  // TODO: ignore generators following a sampleID generator                  // TODO: ignore generators following a sampleID generator
# Line 806  namespace sf2 { Line 802  namespace sf2 {
802      }      }
803    
804      Preset::~Preset() {      Preset::~Preset() {
           
805      }      }
806    
807      Region* Preset::CreateRegion() {      Region* Preset::CreateRegion() {
# Line 1074  namespace sf2 { Line 1069  namespace sf2 {
1069              if (Samples[i]) delete (Samples[i]);              if (Samples[i]) delete (Samples[i]);
1070          }          }
1071      }      }
1072        
1073      int File::GetPresetCount() {      int File::GetPresetCount() {
1074          return Presets.size() - 1; // exclude terminal preset (EOP)          return Presets.size() - 1; // exclude terminal preset (EOP)
1075      }      }
# Line 1185  namespace sf2 { Line 1180  namespace sf2 {
1180       * that the size is given in bytes! You get the number of actually cached       * that the size is given in bytes! You get the number of actually cached
1181       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
1182       * @code       * @code
1183       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);
1184       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
1185       * @endcode       * @endcode
1186       *       *
1187       * @param SampleCount - number of sample points to load into RAM       * @param SampleCount - number of sample points to load into RAM
# Line 1230  namespace sf2 { Line 1225  namespace sf2 {
1225       * that the size is given in bytes! You get the number of actually cached       * that the size is given in bytes! You get the number of actually cached
1226       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
1227       * @code       * @code
1228       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);
1229       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
1230       * @endcode       * @endcode
1231       * The method will add \a NullSamplesCount silence samples past the       * The method will add \a NullSamplesCount silence samples past the
1232       * official buffer end (this won't affect the 'Size' member of the       * official buffer end (this won't affect the 'Size' member of the
# Line 1337  namespace sf2 { Line 1332  namespace sf2 {
1332          if (SampleCount == 0) return 0;          if (SampleCount == 0) return 0;
1333          long pos = GetPos();          long pos = GetPos();
1334          if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos;          if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos;
1335            
1336          if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) {          if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) {
1337              uint8_t* pBuf = (uint8_t*)pBuffer;              uint8_t* pBuf = (uint8_t*)pBuffer;
1338              if (SampleType == MONO_SAMPLE || SampleType == ROM_MONO_SAMPLE) {              if (SampleType == MONO_SAMPLE || SampleType == ROM_MONO_SAMPLE) {

Legend:
Removed from v.2026  
changed lines
  Added in v.2100

  ViewVC Help
Powered by ViewVC