/[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 2020 by iliev, Fri Oct 30 16:25:27 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 36  Line 33 
33    
34  namespace sf2 {  namespace sf2 {
35      double ToSeconds(int Timecents) {      double ToSeconds(int Timecents) {
36            if (Timecents == NONE) return NONE;
37          if (Timecents == 0) return 1.0;          if (Timecents == 0) return 1.0;
38          if (Timecents == -32768) return 0.0;          if (Timecents == -32768) return 0.0;
39          return pow(_1200TH_ROOT_OF_2, Timecents);          return pow(_1200TH_ROOT_OF_2, Timecents);
40      }      }
41    
42      double ToPermilles(int Centibels) {      double ToPermilles(int Centibels) {
43            if (Centibels == NONE) return NONE;
44          if (Centibels == 0) return 1000.0;          if (Centibels == 0) return 1000.0;
45          if (Centibels < 0) return 0.0;          if (Centibels < 0) return 0.0;
46          return pow(_200TH_ROOT_OF_10, Centibels);          return pow(_200TH_ROOT_OF_10, Centibels);
47      }      }
48    
49        double ToHz(int cents) {
50            if (cents == NONE) return NONE;
51            if (cents == 0) return 8.176;
52            return pow(_1200TH_ROOT_OF_2, cents) * 8.176;
53        }
54    
55      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {
56          RIFF::Chunk* ck = list->GetSubChunk(chunkId);          RIFF::Chunk* ck = list->GetSubChunk(chunkId);
57          if(ck == NULL) throw Exception("Mandatory chunk in RIFF list chunk not found: " + ToString(chunkId));          if(ck == NULL) throw Exception("Mandatory chunk in RIFF list chunk not found: " + ToString(chunkId));
# Line 258  namespace sf2 { Line 263  namespace sf2 {
263      Region::Region() {      Region::Region() {
264          pSample = NULL;          pSample = NULL;
265          pInstrument = NULL;          pInstrument = NULL;
266            pParentInstrument = NULL;
267          loKey = hiKey = NONE;          loKey = hiKey = NONE;
268          minVel = maxVel = NONE;          minVel = maxVel = NONE;
269          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;
# Line 268  namespace sf2 { Line 274  namespace sf2 {
274          HasLoop = false;          HasLoop = false;
275          LoopStart = LoopEnd = 0;          LoopStart = LoopEnd = 0;
276    
277          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = ToSeconds(-12000);          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = -12000;
278          EG1Sustain = 0;          EG1Sustain = 0;
279          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = ToSeconds(-12000);          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = -12000;
280          EG2Sustain = 0;          EG2Sustain = 0;
281    
282            modEnvToPitch = modLfoToPitch = modEnvToFilterFc = modLfoToFilterFc = modLfoToVolume = 0;
283            freqModLfo = 0;
284            delayModLfo = -12000;
285            vibLfoToPitch = 0;
286            freqVibLfo = 0;
287            delayVibLfo = -12000;
288    
289            exclusiveClass = 0;
290      }      }
291    
292      int Region::GetUnityNote() {      int Region::GetUnityNote() {
# Line 302  namespace sf2 { Line 317  namespace sf2 {
317                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;
318                  break;                  break;
319              case MOD_LFO_TO_PITCH:              case MOD_LFO_TO_PITCH:
320                    modLfoToPitch = Gen.GenAmount.shAmount;
321                  break;                  break;
322              case VIB_LFO_TO_PITCH:              case VIB_LFO_TO_PITCH:
323                    vibLfoToPitch = Gen.GenAmount.shAmount;
324                  break;                  break;
325              case MOD_ENV_TO_PITCH:              case MOD_ENV_TO_PITCH:
326                    modEnvToPitch = Gen.GenAmount.shAmount;
327                  break;                  break;
328              case INITIAL_FILTER_FC:              case INITIAL_FILTER_FC:
329                  break;                  break;
330              case INITIAL_FILTER_Q:              case INITIAL_FILTER_Q:
331                  break;                  break;
332              case MOD_LFO_TO_FILTER_FC:              case MOD_LFO_TO_FILTER_FC:
333                    modLfoToFilterFc = Gen.GenAmount.shAmount;
334                  break;                  break;
335              case MOD_ENV_TO_FILTER_FC:              case MOD_ENV_TO_FILTER_FC:
336                    modEnvToFilterFc = Gen.GenAmount.shAmount;
337                  break;                  break;
338              case END_ADDRS_COARSE_OFFSET:              case END_ADDRS_COARSE_OFFSET:
339                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;
340                  break;                  break;
341              case MOD_LFO_TO_VOLUME:              case MOD_LFO_TO_VOLUME:
342                    modLfoToVolume = Gen.GenAmount.shAmount;
343                  break;                  break;
344              case CHORUS_EFFECTS_SEND:              case CHORUS_EFFECTS_SEND:
345                  break;                  break;
# Line 331  namespace sf2 { Line 352  namespace sf2 {
352                  if (pan >  63) pan =  63;                  if (pan >  63) pan =  63;
353                  break;                  break;
354              case DELAY_MOD_LFO:              case DELAY_MOD_LFO:
355                    delayModLfo = Gen.GenAmount.shAmount;
356                  break;                  break;
357              case FREQ_MOD_LFO:              case FREQ_MOD_LFO:
358                    freqModLfo = Gen.GenAmount.shAmount;
359                  break;                  break;
360              case DELAY_VIB_LFO:              case DELAY_VIB_LFO:
361                    delayVibLfo = Gen.GenAmount.shAmount;
362                  break;                  break;
363              case FREQ_VIB_LFO:              case FREQ_VIB_LFO:
364                    freqVibLfo = Gen.GenAmount.shAmount;
365                  break;                  break;
366              case DELAY_MOD_ENV:              case DELAY_MOD_ENV:
367                  EG2PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG2PreAttackDelay = Gen.GenAmount.shAmount;
368                  break;                  break;
369              case ATTACK_MOD_ENV:              case ATTACK_MOD_ENV:
370                  EG2Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG2Attack = Gen.GenAmount.shAmount;
371                  break;                  break;
372              case HOLD_MOD_ENV:              case HOLD_MOD_ENV:
373                  EG2Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG2Hold = Gen.GenAmount.shAmount;
374                  break;                  break;
375              case DECAY_MOD_ENV:              case DECAY_MOD_ENV:
376                  EG2Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG2Decay = Gen.GenAmount.shAmount;
377                  break;                  break;
378              case SUSTAIN_MOD_ENV:              case SUSTAIN_MOD_ENV:
379                  EG2Sustain = 1000 - Gen.GenAmount.shAmount;                  EG2Sustain = Gen.GenAmount.shAmount;
380                  break;                  break;
381              case RELEASEMODENV:              case RELEASEMODENV:
382                  EG2Release = ToSeconds(Gen.GenAmount.shAmount);                  EG2Release = Gen.GenAmount.shAmount;
383                  break;                  break;
384              case KEYNUM_TO_MOD_ENV_HOLD:              case KEYNUM_TO_MOD_ENV_HOLD:
385                  break;                  break;
386              case KEYNUM_TO_MOD_ENV_DECAY:              case KEYNUM_TO_MOD_ENV_DECAY:
387                  break;                  break;
388              case DELAY_VOL_ENV:              case DELAY_VOL_ENV:
389                  EG1PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG1PreAttackDelay = Gen.GenAmount.shAmount;
390                  break;                  break;
391              case ATTACK_VOL_ENV:              case ATTACK_VOL_ENV:
392                  EG1Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG1Attack = Gen.GenAmount.shAmount;
393                  break;                  break;
394              case HOLD_VOL_ENV:              case HOLD_VOL_ENV:
395                  EG1Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG1Hold = Gen.GenAmount.shAmount;
396                  break;                  break;
397              case DECAY_VOL_ENV:              case DECAY_VOL_ENV:
398                  EG1Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG1Decay = Gen.GenAmount.shAmount;
399                  break;                  break;
400              case SUSTAIN_VOL_ENV:              case SUSTAIN_VOL_ENV:
401                  EG1Sustain = ToPermilles(Gen.GenAmount.shAmount);                  EG1Sustain = Gen.GenAmount.shAmount;
402                  break;                  break;
403              case RELEASE_VOL_ENV:              case RELEASE_VOL_ENV:
404                  EG1Release = ToSeconds(Gen.GenAmount.shAmount);                  EG1Release = Gen.GenAmount.shAmount;
405                  break;                  break;
406              case KEYNUM_TO_VOL_ENV_HOLD:              case KEYNUM_TO_VOL_ENV_HOLD:
407                  break;                  break;
# Line 414  namespace sf2 { Line 439  namespace sf2 {
439                  break;                  break;
440              case COARSE_TUNE:              case COARSE_TUNE:
441                  coarseTune = Gen.GenAmount.shAmount;                  coarseTune = Gen.GenAmount.shAmount;
442                    if (coarseTune < -120) coarseTune = -120;
443                    if (coarseTune >  120) coarseTune =  120;
444                  break;                  break;
445              case FINE_TUNE:              case FINE_TUNE:
446                  fineTune = Gen.GenAmount.shAmount;                  fineTune = Gen.GenAmount.shAmount;
# Line 445  namespace sf2 { Line 472  namespace sf2 {
472              case SCALE_TUNING:              case SCALE_TUNING:
473                  break;                  break;
474              case EXCLUSIVE_CLASS:              case EXCLUSIVE_CLASS:
475                    exclusiveClass = Gen.GenAmount.wAmount;
476                  break;                  break;
477              case OVERRIDING_ROOT_KEY:              case OVERRIDING_ROOT_KEY:
478                  overridingRootKey = Gen.GenAmount.shAmount;                  overridingRootKey = Gen.GenAmount.shAmount;
# Line 475  namespace sf2 { Line 503  namespace sf2 {
503          }*/          }*/
504      }      }
505    
506        int Region::GetPan(Region* pPresetRegion) {
507            if (pPresetRegion == NULL) return pan;
508            int p = pPresetRegion->pan + pan;
509            if (p < -64) p = -64;
510            if (p >  63) p =  63;
511            return p;
512        }
513    
514        int Region::GetFineTune(Region* pPresetRegion) {
515            if (pPresetRegion == NULL) return fineTune;
516            int t = pPresetRegion->fineTune + fineTune;
517            if (t < -99) t = -99;
518            if (t >  99) t =  99;
519            return t;
520        }
521    
522        int Region::GetCoarseTune(Region* pPresetRegion) {
523             if (pPresetRegion == NULL) return coarseTune;
524            int t = pPresetRegion->coarseTune + coarseTune;
525            if (t < -120) t = -120;
526            if (t >  120) t =  120;
527            return t;
528        }
529    
530        double Region::GetEG1PreAttackDelay(Region* pPresetRegion) {
531            if (pPresetRegion == NULL || pPresetRegion->EG1PreAttackDelay == NONE) return ToSeconds(EG1PreAttackDelay);
532            return ToSeconds(pPresetRegion->EG1PreAttackDelay + EG1PreAttackDelay);
533        }
534    
535        double Region::GetEG1Attack(Region* pPresetRegion) {
536            if (pPresetRegion == NULL || pPresetRegion->EG1Attack == NONE) return ToSeconds(EG1Attack);
537            return ToSeconds(pPresetRegion->EG1Attack + EG1Attack);
538        }
539    
540        double Region::GetEG1Hold(Region* pPresetRegion) {
541            if (pPresetRegion == NULL || pPresetRegion->EG1Hold == NONE) return ToSeconds(EG1Hold);
542            return ToSeconds(pPresetRegion->EG1Hold + EG1Hold);
543        }
544    
545        double Region::GetEG1Decay(Region* pPresetRegion) {
546            if (pPresetRegion == NULL || pPresetRegion->EG1Decay == NONE) return ToSeconds(EG1Decay);
547            return ToSeconds(pPresetRegion->EG1Decay + EG1Decay);
548        }
549    
550        double Region::GetEG1Sustain(Region* pPresetRegion) {
551            if (pPresetRegion == NULL || pPresetRegion->EG1Sustain == NONE) return ToPermilles(EG1Sustain);
552            return ToPermilles(pPresetRegion->EG1Sustain + EG1Sustain);
553        }
554    
555        double Region::GetEG1Release(Region* pPresetRegion) {
556            if (pPresetRegion == NULL || pPresetRegion->EG1Release == NONE) return ToSeconds(EG1Release);
557            return ToSeconds(pPresetRegion->EG1Release + EG1Release);
558        }
559    
560        double Region::GetEG2PreAttackDelay(Region* pPresetRegion) {
561            if (pPresetRegion == NULL || pPresetRegion->EG2PreAttackDelay == NONE) return ToSeconds(EG2PreAttackDelay);
562            return ToSeconds(pPresetRegion->EG2PreAttackDelay + EG2PreAttackDelay);
563        }
564    
565        double Region::GetEG2Attack(Region* pPresetRegion) {
566            if (pPresetRegion == NULL || pPresetRegion->EG2Attack == NONE) return ToSeconds(EG2Attack);
567            return ToSeconds(pPresetRegion->EG2Attack + EG2Attack);
568        }
569    
570        double Region::GetEG2Hold(Region* pPresetRegion) {
571            if (pPresetRegion == NULL || pPresetRegion->EG2Hold == NONE) return ToSeconds(EG2Hold);
572            return ToSeconds(pPresetRegion->EG2Hold + EG2Hold);
573        }
574    
575        double Region::GetEG2Decay(Region* pPresetRegion) {
576            if (pPresetRegion == NULL || pPresetRegion->EG2Decay == NONE) return ToSeconds(EG2Decay);
577            return ToSeconds(pPresetRegion->EG2Decay + EG2Decay);
578        }
579    
580        double Region::GetEG2Sustain(Region* pPresetRegion) {
581            if (pPresetRegion == NULL || pPresetRegion->EG2Sustain == NONE) {
582                return EG2Sustain == NONE ? NONE : 1000 - EG2Sustain;
583            }
584            return 1000 - (pPresetRegion->EG2Sustain + EG2Sustain);
585        }
586    
587        double Region::GetEG2Release(Region* pPresetRegion) {
588            if (pPresetRegion == NULL || pPresetRegion->EG2Release == NONE) return ToSeconds(EG2Release);
589            return ToSeconds(pPresetRegion->EG2Release + EG2Release);
590        }
591    
592        int Region::GetModEnvToPitch(Region* pPresetRegion) {
593            return modEnvToPitch + (pPresetRegion ? pPresetRegion->modEnvToPitch : 0);
594        }
595    
596        int Region::GetModLfoToPitch(Region* pPresetRegion) {
597            return modLfoToPitch + (pPresetRegion ? pPresetRegion->modLfoToPitch : 0);
598        }
599    
600        int Region::GetModEnvToFilterFc(Region* pPresetRegion) {
601            return modEnvToFilterFc + (pPresetRegion ? pPresetRegion->modEnvToFilterFc : 0);
602        }
603    
604        int Region::GetModLfoToFilterFc(Region* pPresetRegion) {
605            return modLfoToFilterFc + (pPresetRegion ? pPresetRegion->modLfoToFilterFc : 0);
606        }
607    
608        double Region::GetModLfoToVolume(Region* pPresetRegion) {
609            return ToPermilles(modLfoToVolume + (pPresetRegion ? pPresetRegion->modLfoToVolume : 0));
610        }
611    
612        double Region::GetFreqModLfo(Region* pPresetRegion) {
613            if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo);
614            return ToHz(pPresetRegion->freqModLfo + freqModLfo);
615        }
616    
617        double Region::GetDelayModLfo(Region* pPresetRegion) {
618            if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo);
619            return ToSeconds(pPresetRegion->delayModLfo + delayModLfo);
620        }
621    
622        int Region::GetVibLfoToPitch(Region* pPresetRegion) {
623            return vibLfoToPitch + (pPresetRegion ? pPresetRegion->vibLfoToPitch : 0);
624        }
625    
626        double Region::GetFreqVibLfo(Region* pPresetRegion) {
627            if (pPresetRegion == NULL || pPresetRegion->freqVibLfo == NONE) return ToHz(freqVibLfo);
628            return ToHz(pPresetRegion->freqVibLfo + freqVibLfo);
629        }
630    
631        double Region::GetDelayVibLfo(Region* pPresetRegion) {
632            if (pPresetRegion == NULL || pPresetRegion->delayVibLfo == NONE) return ToSeconds(delayVibLfo);
633            return ToSeconds(pPresetRegion->delayVibLfo + delayVibLfo);
634        }
635    
636      InstrumentBase::InstrumentBase(sf2::File* pFile) {      InstrumentBase::InstrumentBase(sf2::File* pFile) {
637          this->pFile = pFile;          this->pFile = pFile;
638          pGlobalRegion = NULL;          pGlobalRegion = NULL;
# Line 499  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                  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 521  namespace sf2 { Line 679  namespace sf2 {
679      }      }
680    
681      Instrument::~Instrument() {      Instrument::~Instrument() {
           
682      }      }
683    
684      Region* Instrument::CreateRegion() {      Region* Instrument::CreateRegion() {
685          Region* r = new Region;          Region* r = new Region;
686            r->pParentInstrument = this;
687    
688          if (pGlobalRegion != NULL) {          if (pGlobalRegion != NULL) {
689              r->loKey       = pGlobalRegion->loKey;              r->loKey       = pGlobalRegion->loKey;
690              r->hiKey       = pGlobalRegion->hiKey;              r->hiKey       = pGlobalRegion->hiKey;
# Line 558  namespace sf2 { Line 717  namespace sf2 {
717              r->EG2Sustain         = pGlobalRegion->EG2Sustain;              r->EG2Sustain         = pGlobalRegion->EG2Sustain;
718              r->EG2Release         = pGlobalRegion->EG2Release;              r->EG2Release         = pGlobalRegion->EG2Release;
719    
720                r->modEnvToPitch     = pGlobalRegion->modEnvToPitch;
721                r->modLfoToPitch     = pGlobalRegion->modLfoToPitch;
722                r->modEnvToFilterFc  = pGlobalRegion->modEnvToFilterFc;
723                r->modLfoToFilterFc  = pGlobalRegion->modLfoToFilterFc;
724                r->modLfoToVolume    = pGlobalRegion->modLfoToVolume;
725                r->freqModLfo        = pGlobalRegion->freqModLfo;
726                r->delayModLfo       = pGlobalRegion->delayModLfo;
727                r->vibLfoToPitch     = pGlobalRegion->vibLfoToPitch;
728                r->freqVibLfo        = pGlobalRegion->freqVibLfo;
729                r->delayVibLfo       = pGlobalRegion->delayVibLfo;
730    
731              r->HasLoop    = pGlobalRegion->HasLoop;              r->HasLoop    = pGlobalRegion->HasLoop;
732              r->LoopStart  = pGlobalRegion->LoopStart;              r->LoopStart  = pGlobalRegion->LoopStart;
733              r->LoopEnd    = pGlobalRegion->LoopEnd;              r->LoopEnd    = pGlobalRegion->LoopEnd;
734    
735                r->exclusiveClass = pGlobalRegion->exclusiveClass;
736          }          }
737    
738          return r;          return r;
# Line 595  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 630  namespace sf2 { Line 802  namespace sf2 {
802      }      }
803    
804      Preset::~Preset() {      Preset::~Preset() {
805                }
806    
807        Region* Preset::CreateRegion() {
808            Region* r = new Region;
809    
810            r->EG1PreAttackDelay = r->EG1Attack = r->EG1Hold = r->EG1Decay = r->EG1Sustain = r->EG1Release = NONE;
811            r->EG2PreAttackDelay = r->EG2Attack = r->EG2Hold = r->EG2Decay = r->EG2Sustain = r->EG2Release = NONE;
812            r->freqModLfo = r->delayModLfo = r->freqVibLfo = r->delayVibLfo = NONE;
813    
814            if (pGlobalRegion != NULL) {
815                r->pan         = pGlobalRegion->pan;
816                r->fineTune    = pGlobalRegion->fineTune;
817                r->coarseTune  = pGlobalRegion->coarseTune;
818    
819                r->EG1PreAttackDelay  = pGlobalRegion->EG1PreAttackDelay;
820                r->EG1Attack          = pGlobalRegion->EG1Attack;
821                r->EG1Hold            = pGlobalRegion->EG1Hold;
822                r->EG1Decay           = pGlobalRegion->EG1Decay;
823                r->EG1Sustain         = pGlobalRegion->EG1Sustain;
824                r->EG1Release         = pGlobalRegion->EG1Release;
825    
826                r->EG2PreAttackDelay  = pGlobalRegion->EG2PreAttackDelay;
827                r->EG2Attack          = pGlobalRegion->EG2Attack;
828                r->EG2Hold            = pGlobalRegion->EG2Hold;
829                r->EG2Decay           = pGlobalRegion->EG2Decay;
830                r->EG2Sustain         = pGlobalRegion->EG2Sustain;
831                r->EG2Release         = pGlobalRegion->EG2Release;
832    
833                r->modEnvToPitch     = pGlobalRegion->modEnvToPitch;
834                r->modLfoToPitch     = pGlobalRegion->modLfoToPitch;
835                r->modEnvToFilterFc  = pGlobalRegion->modEnvToFilterFc;
836                r->modLfoToFilterFc  = pGlobalRegion->modLfoToFilterFc;
837                r->modLfoToVolume    = pGlobalRegion->modLfoToVolume;
838                r->freqModLfo        = pGlobalRegion->freqModLfo;
839                r->delayModLfo       = pGlobalRegion->delayModLfo;
840                r->vibLfoToPitch     = pGlobalRegion->vibLfoToPitch;
841                r->freqVibLfo        = pGlobalRegion->freqVibLfo;
842                r->delayVibLfo       = pGlobalRegion->delayVibLfo;
843            }
844    
845            return r;
846      }      }
847    
848      void Preset::LoadRegions(int idx1, int idx2) {      void Preset::LoadRegions(int idx1, int idx2) {
# Line 642  namespace sf2 { Line 854  namespace sf2 {
854                  throw Exception("Broken SF2 file (invalid PresetGenNdx)");                  throw Exception("Broken SF2 file (invalid PresetGenNdx)");
855              }              }
856    
857              Region* reg = new Region;              Region* reg = CreateRegion();
858    
859              for (int j = gIdx1; j < gIdx2; j++) {              for (int j = gIdx1; j < gIdx2; j++) {
860                  reg->SetGenerator(pFile, pFile->PresetGenLists[j]);                  reg->SetGenerator(pFile, pFile->PresetGenLists[j]);
# Line 857  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 968  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 1013  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 1120  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.2020  
changed lines
  Added in v.2100

  ViewVC Help
Powered by ViewVC