/[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 2202 by persson, Sat Jul 9 16:43:35 2011 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;          return pow(_200TH_ROOT_OF_10, Centibels) * 1000.0;
46          return pow(_200TH_ROOT_OF_10, Centibels);      }
47    
48        double ToHz(int cents) {
49            if (cents == NONE) return NONE;
50            if (cents == 0) return 8.176;
51            return pow(_1200TH_ROOT_OF_2, cents) * 8.176;
52      }      }
53    
54      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {
# Line 258  namespace sf2 { Line 262  namespace sf2 {
262      Region::Region() {      Region::Region() {
263          pSample = NULL;          pSample = NULL;
264          pInstrument = NULL;          pInstrument = NULL;
265            pParentInstrument = NULL;
266          loKey = hiKey = NONE;          loKey = hiKey = NONE;
267          minVel = maxVel = NONE;          minVel = maxVel = NONE;
268          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;
# Line 268  namespace sf2 { Line 273  namespace sf2 {
273          HasLoop = false;          HasLoop = false;
274          LoopStart = LoopEnd = 0;          LoopStart = LoopEnd = 0;
275    
276          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = ToSeconds(-12000);          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = -12000;
277          EG1Sustain = 0;          EG1Sustain = 0;
278          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = ToSeconds(-12000);          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = -12000;
279          EG2Sustain = 0;          EG2Sustain = 0;
280    
281            modEnvToPitch = modLfoToPitch = modEnvToFilterFc = modLfoToFilterFc = modLfoToVolume = 0;
282            freqModLfo = 0;
283            delayModLfo = -12000;
284            vibLfoToPitch = 0;
285            freqVibLfo = 0;
286            delayVibLfo = -12000;
287    
288            exclusiveClass = 0;
289      }      }
290    
291      int Region::GetUnityNote() {      int Region::GetUnityNote() {
# Line 302  namespace sf2 { Line 316  namespace sf2 {
316                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;
317                  break;                  break;
318              case MOD_LFO_TO_PITCH:              case MOD_LFO_TO_PITCH:
319                    modLfoToPitch = Gen.GenAmount.shAmount;
320                  break;                  break;
321              case VIB_LFO_TO_PITCH:              case VIB_LFO_TO_PITCH:
322                    vibLfoToPitch = Gen.GenAmount.shAmount;
323                  break;                  break;
324              case MOD_ENV_TO_PITCH:              case MOD_ENV_TO_PITCH:
325                    modEnvToPitch = Gen.GenAmount.shAmount;
326                  break;                  break;
327              case INITIAL_FILTER_FC:              case INITIAL_FILTER_FC:
328                  break;                  break;
329              case INITIAL_FILTER_Q:              case INITIAL_FILTER_Q:
330                  break;                  break;
331              case MOD_LFO_TO_FILTER_FC:              case MOD_LFO_TO_FILTER_FC:
332                    modLfoToFilterFc = Gen.GenAmount.shAmount;
333                  break;                  break;
334              case MOD_ENV_TO_FILTER_FC:              case MOD_ENV_TO_FILTER_FC:
335                    modEnvToFilterFc = Gen.GenAmount.shAmount;
336                  break;                  break;
337              case END_ADDRS_COARSE_OFFSET:              case END_ADDRS_COARSE_OFFSET:
338                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;
339                  break;                  break;
340              case MOD_LFO_TO_VOLUME:              case MOD_LFO_TO_VOLUME:
341                    modLfoToVolume = Gen.GenAmount.shAmount;
342                  break;                  break;
343              case CHORUS_EFFECTS_SEND:              case CHORUS_EFFECTS_SEND:
344                  break;                  break;
# Line 331  namespace sf2 { Line 351  namespace sf2 {
351                  if (pan >  63) pan =  63;                  if (pan >  63) pan =  63;
352                  break;                  break;
353              case DELAY_MOD_LFO:              case DELAY_MOD_LFO:
354                    delayModLfo = Gen.GenAmount.shAmount;
355                  break;                  break;
356              case FREQ_MOD_LFO:              case FREQ_MOD_LFO:
357                    freqModLfo = Gen.GenAmount.shAmount;
358                  break;                  break;
359              case DELAY_VIB_LFO:              case DELAY_VIB_LFO:
360                    delayVibLfo = Gen.GenAmount.shAmount;
361                  break;                  break;
362              case FREQ_VIB_LFO:              case FREQ_VIB_LFO:
363                    freqVibLfo = Gen.GenAmount.shAmount;
364                  break;                  break;
365              case DELAY_MOD_ENV:              case DELAY_MOD_ENV:
366                  EG2PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG2PreAttackDelay = Gen.GenAmount.shAmount;
367                  break;                  break;
368              case ATTACK_MOD_ENV:              case ATTACK_MOD_ENV:
369                  EG2Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG2Attack = Gen.GenAmount.shAmount;
370                  break;                  break;
371              case HOLD_MOD_ENV:              case HOLD_MOD_ENV:
372                  EG2Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG2Hold = Gen.GenAmount.shAmount;
373                  break;                  break;
374              case DECAY_MOD_ENV:              case DECAY_MOD_ENV:
375                  EG2Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG2Decay = Gen.GenAmount.shAmount;
376                  break;                  break;
377              case SUSTAIN_MOD_ENV:              case SUSTAIN_MOD_ENV:
378                  EG2Sustain = 1000 - Gen.GenAmount.shAmount;                  EG2Sustain = Gen.GenAmount.shAmount;
379                  break;                  break;
380              case RELEASEMODENV:              case RELEASEMODENV:
381                  EG2Release = ToSeconds(Gen.GenAmount.shAmount);                  EG2Release = Gen.GenAmount.shAmount;
382                  break;                  break;
383              case KEYNUM_TO_MOD_ENV_HOLD:              case KEYNUM_TO_MOD_ENV_HOLD:
384                  break;                  break;
385              case KEYNUM_TO_MOD_ENV_DECAY:              case KEYNUM_TO_MOD_ENV_DECAY:
386                  break;                  break;
387              case DELAY_VOL_ENV:              case DELAY_VOL_ENV:
388                  EG1PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG1PreAttackDelay = Gen.GenAmount.shAmount;
389                  break;                  break;
390              case ATTACK_VOL_ENV:              case ATTACK_VOL_ENV:
391                  EG1Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG1Attack = Gen.GenAmount.shAmount;
392                  break;                  break;
393              case HOLD_VOL_ENV:              case HOLD_VOL_ENV:
394                  EG1Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG1Hold = Gen.GenAmount.shAmount;
395                  break;                  break;
396              case DECAY_VOL_ENV:              case DECAY_VOL_ENV:
397                  EG1Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG1Decay = Gen.GenAmount.shAmount;
398                  break;                  break;
399              case SUSTAIN_VOL_ENV:              case SUSTAIN_VOL_ENV:
400                  EG1Sustain = ToPermilles(Gen.GenAmount.shAmount);                  EG1Sustain = Gen.GenAmount.shAmount;
401                  break;                  break;
402              case RELEASE_VOL_ENV:              case RELEASE_VOL_ENV:
403                  EG1Release = ToSeconds(Gen.GenAmount.shAmount);                  EG1Release = Gen.GenAmount.shAmount;
404                  break;                  break;
405              case KEYNUM_TO_VOL_ENV_HOLD:              case KEYNUM_TO_VOL_ENV_HOLD:
406                  break;                  break;
# Line 414  namespace sf2 { Line 438  namespace sf2 {
438                  break;                  break;
439              case COARSE_TUNE:              case COARSE_TUNE:
440                  coarseTune = Gen.GenAmount.shAmount;                  coarseTune = Gen.GenAmount.shAmount;
441                    if (coarseTune < -120) coarseTune = -120;
442                    if (coarseTune >  120) coarseTune =  120;
443                  break;                  break;
444              case FINE_TUNE:              case FINE_TUNE:
445                  fineTune = Gen.GenAmount.shAmount;                  fineTune = Gen.GenAmount.shAmount;
# Line 445  namespace sf2 { Line 471  namespace sf2 {
471              case SCALE_TUNING:              case SCALE_TUNING:
472                  break;                  break;
473              case EXCLUSIVE_CLASS:              case EXCLUSIVE_CLASS:
474                    exclusiveClass = Gen.GenAmount.wAmount;
475                  break;                  break;
476              case OVERRIDING_ROOT_KEY:              case OVERRIDING_ROOT_KEY:
477                  overridingRootKey = Gen.GenAmount.shAmount;                  overridingRootKey = Gen.GenAmount.shAmount;
# Line 475  namespace sf2 { Line 502  namespace sf2 {
502          }*/          }*/
503      }      }
504    
505        int Region::GetPan(Region* pPresetRegion) {
506            if (pPresetRegion == NULL) return pan;
507            int p = pPresetRegion->pan + pan;
508            if (p < -64) p = -64;
509            if (p >  63) p =  63;
510            return p;
511        }
512    
513        int Region::GetFineTune(Region* pPresetRegion) {
514            if (pPresetRegion == NULL) return fineTune;
515            int t = pPresetRegion->fineTune + fineTune;
516            if (t < -99) t = -99;
517            if (t >  99) t =  99;
518            return t;
519        }
520    
521        int Region::GetCoarseTune(Region* pPresetRegion) {
522             if (pPresetRegion == NULL) return coarseTune;
523            int t = pPresetRegion->coarseTune + coarseTune;
524            if (t < -120) t = -120;
525            if (t >  120) t =  120;
526            return t;
527        }
528    
529        double Region::GetEG1PreAttackDelay(Region* pPresetRegion) {
530            if (pPresetRegion == NULL || pPresetRegion->EG1PreAttackDelay == NONE) return ToSeconds(EG1PreAttackDelay);
531            return ToSeconds(pPresetRegion->EG1PreAttackDelay + EG1PreAttackDelay);
532        }
533    
534        double Region::GetEG1Attack(Region* pPresetRegion) {
535            if (pPresetRegion == NULL || pPresetRegion->EG1Attack == NONE) return ToSeconds(EG1Attack);
536            return ToSeconds(pPresetRegion->EG1Attack + EG1Attack);
537        }
538    
539        double Region::GetEG1Hold(Region* pPresetRegion) {
540            if (pPresetRegion == NULL || pPresetRegion->EG1Hold == NONE) return ToSeconds(EG1Hold);
541            return ToSeconds(pPresetRegion->EG1Hold + EG1Hold);
542        }
543    
544        double Region::GetEG1Decay(Region* pPresetRegion) {
545            if (pPresetRegion == NULL || pPresetRegion->EG1Decay == NONE) return ToSeconds(EG1Decay);
546            return ToSeconds(pPresetRegion->EG1Decay + EG1Decay);
547        }
548    
549        double Region::GetEG1Sustain(Region* pPresetRegion) {
550            int sustain = EG1Sustain;
551            if (pPresetRegion != NULL && pPresetRegion->EG1Sustain != NONE) sustain += EG1Sustain;
552            if (sustain == NONE) return NONE;
553            sustain = std::min(0, std::max(sustain, 1000));
554            return ToPermilles(-sustain);
555        }
556    
557        double Region::GetEG1Release(Region* pPresetRegion) {
558            if (pPresetRegion == NULL || pPresetRegion->EG1Release == NONE) return ToSeconds(EG1Release);
559            return ToSeconds(pPresetRegion->EG1Release + EG1Release);
560        }
561    
562        double Region::GetEG2PreAttackDelay(Region* pPresetRegion) {
563            if (pPresetRegion == NULL || pPresetRegion->EG2PreAttackDelay == NONE) return ToSeconds(EG2PreAttackDelay);
564            return ToSeconds(pPresetRegion->EG2PreAttackDelay + EG2PreAttackDelay);
565        }
566    
567        double Region::GetEG2Attack(Region* pPresetRegion) {
568            if (pPresetRegion == NULL || pPresetRegion->EG2Attack == NONE) return ToSeconds(EG2Attack);
569            return ToSeconds(pPresetRegion->EG2Attack + EG2Attack);
570        }
571    
572        double Region::GetEG2Hold(Region* pPresetRegion) {
573            if (pPresetRegion == NULL || pPresetRegion->EG2Hold == NONE) return ToSeconds(EG2Hold);
574            return ToSeconds(pPresetRegion->EG2Hold + EG2Hold);
575        }
576    
577        double Region::GetEG2Decay(Region* pPresetRegion) {
578            if (pPresetRegion == NULL || pPresetRegion->EG2Decay == NONE) return ToSeconds(EG2Decay);
579            return ToSeconds(pPresetRegion->EG2Decay + EG2Decay);
580        }
581    
582        double Region::GetEG2Sustain(Region* pPresetRegion) {
583            if (pPresetRegion == NULL || pPresetRegion->EG2Sustain == NONE) {
584                return EG2Sustain == NONE ? NONE : 1000 - EG2Sustain;
585            }
586            return 1000 - (pPresetRegion->EG2Sustain + EG2Sustain);
587        }
588    
589        double Region::GetEG2Release(Region* pPresetRegion) {
590            if (pPresetRegion == NULL || pPresetRegion->EG2Release == NONE) return ToSeconds(EG2Release);
591            return ToSeconds(pPresetRegion->EG2Release + EG2Release);
592        }
593    
594        int Region::GetModEnvToPitch(Region* pPresetRegion) {
595            return modEnvToPitch + (pPresetRegion ? pPresetRegion->modEnvToPitch : 0);
596        }
597    
598        int Region::GetModLfoToPitch(Region* pPresetRegion) {
599            return modLfoToPitch + (pPresetRegion ? pPresetRegion->modLfoToPitch : 0);
600        }
601    
602        int Region::GetModEnvToFilterFc(Region* pPresetRegion) {
603            return modEnvToFilterFc + (pPresetRegion ? pPresetRegion->modEnvToFilterFc : 0);
604        }
605    
606        int Region::GetModLfoToFilterFc(Region* pPresetRegion) {
607            return modLfoToFilterFc + (pPresetRegion ? pPresetRegion->modLfoToFilterFc : 0);
608        }
609    
610        double Region::GetModLfoToVolume(Region* pPresetRegion) {
611            return ToPermilles(modLfoToVolume + (pPresetRegion ? pPresetRegion->modLfoToVolume : 0));
612        }
613    
614        double Region::GetFreqModLfo(Region* pPresetRegion) {
615            if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo);
616            return ToHz(pPresetRegion->freqModLfo + freqModLfo);
617        }
618    
619        double Region::GetDelayModLfo(Region* pPresetRegion) {
620            if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo);
621            return ToSeconds(pPresetRegion->delayModLfo + delayModLfo);
622        }
623    
624        int Region::GetVibLfoToPitch(Region* pPresetRegion) {
625            return vibLfoToPitch + (pPresetRegion ? pPresetRegion->vibLfoToPitch : 0);
626        }
627    
628        double Region::GetFreqVibLfo(Region* pPresetRegion) {
629            if (pPresetRegion == NULL || pPresetRegion->freqVibLfo == NONE) return ToHz(freqVibLfo);
630            return ToHz(pPresetRegion->freqVibLfo + freqVibLfo);
631        }
632    
633        double Region::GetDelayVibLfo(Region* pPresetRegion) {
634            if (pPresetRegion == NULL || pPresetRegion->delayVibLfo == NONE) return ToSeconds(delayVibLfo);
635            return ToSeconds(pPresetRegion->delayVibLfo + delayVibLfo);
636        }
637    
638      InstrumentBase::InstrumentBase(sf2::File* pFile) {      InstrumentBase::InstrumentBase(sf2::File* pFile) {
639          this->pFile = pFile;          this->pFile = pFile;
640          pGlobalRegion = NULL;          pGlobalRegion = NULL;
# Line 499  namespace sf2 { Line 659  namespace sf2 {
659          return regions[idx];          return regions[idx];
660      }      }
661    
662      std::vector<Region*> InstrumentBase::GetRegionsOnKey(int key, uint8_t vel) {      Query::Query(InstrumentBase& instrument) : instrument(instrument) {
663          std::vector<Region*> v;          i = 0;
664          for (int i = 0; i < GetRegionCount(); i++) {      }
665              Region* r = GetRegion(i);  
666              if (      Region* Query::next() {
667                  key >= r->loKey && key <= r->hiKey &&          while (i < instrument.GetRegionCount()) {
668                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))              Region* r = instrument.GetRegion(i++);
669              ) {              if (((r->loKey  == NONE && r->hiKey  == NONE) || (key >= r->loKey && key <= r->hiKey)) &&
670                  v.push_back(r);                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))) {
671                    return r;
672              }              }
673          }          }
674            return 0;
         return v;  
675      }      }
676    
677      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 681  namespace sf2 {
681      }      }
682    
683      Instrument::~Instrument() {      Instrument::~Instrument() {
           
684      }      }
685    
686      Region* Instrument::CreateRegion() {      Region* Instrument::CreateRegion() {
687          Region* r = new Region;          Region* r = new Region;
688            r->pParentInstrument = this;
689    
690          if (pGlobalRegion != NULL) {          if (pGlobalRegion != NULL) {
691              r->loKey       = pGlobalRegion->loKey;              r->loKey       = pGlobalRegion->loKey;
692              r->hiKey       = pGlobalRegion->hiKey;              r->hiKey       = pGlobalRegion->hiKey;
# Line 558  namespace sf2 { Line 719  namespace sf2 {
719              r->EG2Sustain         = pGlobalRegion->EG2Sustain;              r->EG2Sustain         = pGlobalRegion->EG2Sustain;
720              r->EG2Release         = pGlobalRegion->EG2Release;              r->EG2Release         = pGlobalRegion->EG2Release;
721    
722                r->modEnvToPitch     = pGlobalRegion->modEnvToPitch;
723                r->modLfoToPitch     = pGlobalRegion->modLfoToPitch;
724                r->modEnvToFilterFc  = pGlobalRegion->modEnvToFilterFc;
725                r->modLfoToFilterFc  = pGlobalRegion->modLfoToFilterFc;
726                r->modLfoToVolume    = pGlobalRegion->modLfoToVolume;
727                r->freqModLfo        = pGlobalRegion->freqModLfo;
728                r->delayModLfo       = pGlobalRegion->delayModLfo;
729                r->vibLfoToPitch     = pGlobalRegion->vibLfoToPitch;
730                r->freqVibLfo        = pGlobalRegion->freqVibLfo;
731                r->delayVibLfo       = pGlobalRegion->delayVibLfo;
732    
733              r->HasLoop    = pGlobalRegion->HasLoop;              r->HasLoop    = pGlobalRegion->HasLoop;
734              r->LoopStart  = pGlobalRegion->LoopStart;              r->LoopStart  = pGlobalRegion->LoopStart;
735              r->LoopEnd    = pGlobalRegion->LoopEnd;              r->LoopEnd    = pGlobalRegion->LoopEnd;
736    
737                r->exclusiveClass = pGlobalRegion->exclusiveClass;
738          }          }
739    
740          return r;          return r;
# Line 595  namespace sf2 { Line 769  namespace sf2 {
769              }              }
770    
771              Region* reg = CreateRegion();              Region* reg = CreateRegion();
772                
773              for (int j = gIdx1; j < gIdx2; j++) {              for (int j = gIdx1; j < gIdx2; j++) {
774                  reg->SetGenerator(pFile, pFile->InstGenLists[j]);                  reg->SetGenerator(pFile, pFile->InstGenLists[j]);
775                  // TODO: ignore generators following a sampleID generator                  // TODO: ignore generators following a sampleID generator
# Line 630  namespace sf2 { Line 804  namespace sf2 {
804      }      }
805    
806      Preset::~Preset() {      Preset::~Preset() {
807                }
808    
809        Region* Preset::CreateRegion() {
810            Region* r = new Region;
811    
812            r->EG1PreAttackDelay = r->EG1Attack = r->EG1Hold = r->EG1Decay = r->EG1Sustain = r->EG1Release = NONE;
813            r->EG2PreAttackDelay = r->EG2Attack = r->EG2Hold = r->EG2Decay = r->EG2Sustain = r->EG2Release = NONE;
814            r->freqModLfo = r->delayModLfo = r->freqVibLfo = r->delayVibLfo = NONE;
815    
816            if (pGlobalRegion != NULL) {
817                r->pan         = pGlobalRegion->pan;
818                r->fineTune    = pGlobalRegion->fineTune;
819                r->coarseTune  = pGlobalRegion->coarseTune;
820    
821                r->EG1PreAttackDelay  = pGlobalRegion->EG1PreAttackDelay;
822                r->EG1Attack          = pGlobalRegion->EG1Attack;
823                r->EG1Hold            = pGlobalRegion->EG1Hold;
824                r->EG1Decay           = pGlobalRegion->EG1Decay;
825                r->EG1Sustain         = pGlobalRegion->EG1Sustain;
826                r->EG1Release         = pGlobalRegion->EG1Release;
827    
828                r->EG2PreAttackDelay  = pGlobalRegion->EG2PreAttackDelay;
829                r->EG2Attack          = pGlobalRegion->EG2Attack;
830                r->EG2Hold            = pGlobalRegion->EG2Hold;
831                r->EG2Decay           = pGlobalRegion->EG2Decay;
832                r->EG2Sustain         = pGlobalRegion->EG2Sustain;
833                r->EG2Release         = pGlobalRegion->EG2Release;
834    
835                r->modEnvToPitch     = pGlobalRegion->modEnvToPitch;
836                r->modLfoToPitch     = pGlobalRegion->modLfoToPitch;
837                r->modEnvToFilterFc  = pGlobalRegion->modEnvToFilterFc;
838                r->modLfoToFilterFc  = pGlobalRegion->modLfoToFilterFc;
839                r->modLfoToVolume    = pGlobalRegion->modLfoToVolume;
840                r->freqModLfo        = pGlobalRegion->freqModLfo;
841                r->delayModLfo       = pGlobalRegion->delayModLfo;
842                r->vibLfoToPitch     = pGlobalRegion->vibLfoToPitch;
843                r->freqVibLfo        = pGlobalRegion->freqVibLfo;
844                r->delayVibLfo       = pGlobalRegion->delayVibLfo;
845            }
846    
847            return r;
848      }      }
849    
850      void Preset::LoadRegions(int idx1, int idx2) {      void Preset::LoadRegions(int idx1, int idx2) {
# Line 642  namespace sf2 { Line 856  namespace sf2 {
856                  throw Exception("Broken SF2 file (invalid PresetGenNdx)");                  throw Exception("Broken SF2 file (invalid PresetGenNdx)");
857              }              }
858    
859              Region* reg = new Region;              Region* reg = CreateRegion();
860    
861              for (int j = gIdx1; j < gIdx2; j++) {              for (int j = gIdx1; j < gIdx2; j++) {
862                  reg->SetGenerator(pFile, pFile->PresetGenLists[j]);                  reg->SetGenerator(pFile, pFile->PresetGenLists[j]);
# Line 857  namespace sf2 { Line 1071  namespace sf2 {
1071              if (Samples[i]) delete (Samples[i]);              if (Samples[i]) delete (Samples[i]);
1072          }          }
1073      }      }
1074        
1075      int File::GetPresetCount() {      int File::GetPresetCount() {
1076          return Presets.size() - 1; // exclude terminal preset (EOP)          return Presets.size() - 1; // exclude terminal preset (EOP)
1077      }      }
# Line 968  namespace sf2 { Line 1182  namespace sf2 {
1182       * 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
1183       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
1184       * @code       * @code
1185       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);
1186       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
1187       * @endcode       * @endcode
1188       *       *
1189       * @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 1227  namespace sf2 {
1227       * 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
1228       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
1229       * @code       * @code
1230       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);
1231       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
1232       * @endcode       * @endcode
1233       * The method will add \a NullSamplesCount silence samples past the       * The method will add \a NullSamplesCount silence samples past the
1234       * 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 1334  namespace sf2 {
1334          if (SampleCount == 0) return 0;          if (SampleCount == 0) return 0;
1335          long pos = GetPos();          long pos = GetPos();
1336          if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos;          if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos;
1337            
1338          if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) {          if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) {
1339              uint8_t* pBuf = (uint8_t*)pBuffer;              uint8_t* pBuf = (uint8_t*)pBuffer;
1340              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.2202

  ViewVC Help
Powered by ViewVC