/[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 2044 by persson, Sun Jan 10 12:58:51 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 36  Line 35 
35    
36  namespace sf2 {  namespace sf2 {
37      double ToSeconds(int Timecents) {      double ToSeconds(int Timecents) {
38            if (Timecents == NONE) return NONE;
39          if (Timecents == 0) return 1.0;          if (Timecents == 0) return 1.0;
40          if (Timecents == -32768) return 0.0;          if (Timecents == -32768) return 0.0;
41          return pow(_1200TH_ROOT_OF_2, Timecents);          return pow(_1200TH_ROOT_OF_2, Timecents);
42      }      }
43    
44      double ToPermilles(int Centibels) {      double ToPermilles(int Centibels) {
45            if (Centibels == NONE) return NONE;
46          if (Centibels == 0) return 1000.0;          if (Centibels == 0) return 1000.0;
47          if (Centibels < 0) return 0.0;          if (Centibels < 0) return 0.0;
48          return pow(_200TH_ROOT_OF_10, Centibels);          return pow(_200TH_ROOT_OF_10, Centibels);
49      }      }
50    
51        double ToHz(int cents) {
52            if (cents == NONE) return NONE;
53            if (cents == 0) return 8.176;
54            return pow(_1200TH_ROOT_OF_2, cents) * 8.176;
55        }
56    
57      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {      RIFF::Chunk* GetMandatoryChunk(RIFF::List* list, uint32_t chunkId) {
58          RIFF::Chunk* ck = list->GetSubChunk(chunkId);          RIFF::Chunk* ck = list->GetSubChunk(chunkId);
59          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 265  namespace sf2 {
265      Region::Region() {      Region::Region() {
266          pSample = NULL;          pSample = NULL;
267          pInstrument = NULL;          pInstrument = NULL;
268            pParentInstrument = NULL;
269          loKey = hiKey = NONE;          loKey = hiKey = NONE;
270          minVel = maxVel = NONE;          minVel = maxVel = NONE;
271          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;          startAddrsOffset = startAddrsCoarseOffset = endAddrsOffset = endAddrsCoarseOffset = 0;
# Line 268  namespace sf2 { Line 276  namespace sf2 {
276          HasLoop = false;          HasLoop = false;
277          LoopStart = LoopEnd = 0;          LoopStart = LoopEnd = 0;
278    
279          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = ToSeconds(-12000);          EG1PreAttackDelay = EG1Attack = EG1Hold = EG1Decay = EG1Release = -12000;
280          EG1Sustain = 0;          EG1Sustain = 0;
281          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = ToSeconds(-12000);          EG2PreAttackDelay = EG2Attack = EG2Hold = EG2Decay = EG2Release = -12000;
282          EG2Sustain = 0;          EG2Sustain = 0;
283    
284            modEnvToPitch = modLfoToPitch = modEnvToFilterFc = modLfoToFilterFc = modLfoToVolume = 0;
285            freqModLfo = 0;
286            delayModLfo = -12000;
287            vibLfoToPitch = 0;
288            freqVibLfo = 0;
289            delayVibLfo = -12000;
290    
291            exclusiveClass = 0;
292      }      }
293    
294      int Region::GetUnityNote() {      int Region::GetUnityNote() {
# Line 302  namespace sf2 { Line 319  namespace sf2 {
319                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;                  startAddrsCoarseOffset = Gen.GenAmount.wAmount;
320                  break;                  break;
321              case MOD_LFO_TO_PITCH:              case MOD_LFO_TO_PITCH:
322                    modLfoToPitch = Gen.GenAmount.shAmount;
323                  break;                  break;
324              case VIB_LFO_TO_PITCH:              case VIB_LFO_TO_PITCH:
325                    vibLfoToPitch = Gen.GenAmount.shAmount;
326                  break;                  break;
327              case MOD_ENV_TO_PITCH:              case MOD_ENV_TO_PITCH:
328                    modEnvToPitch = Gen.GenAmount.shAmount;
329                  break;                  break;
330              case INITIAL_FILTER_FC:              case INITIAL_FILTER_FC:
331                  break;                  break;
332              case INITIAL_FILTER_Q:              case INITIAL_FILTER_Q:
333                  break;                  break;
334              case MOD_LFO_TO_FILTER_FC:              case MOD_LFO_TO_FILTER_FC:
335                    modLfoToFilterFc = Gen.GenAmount.shAmount;
336                  break;                  break;
337              case MOD_ENV_TO_FILTER_FC:              case MOD_ENV_TO_FILTER_FC:
338                    modEnvToFilterFc = Gen.GenAmount.shAmount;
339                  break;                  break;
340              case END_ADDRS_COARSE_OFFSET:              case END_ADDRS_COARSE_OFFSET:
341                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;                  endAddrsCoarseOffset = Gen.GenAmount.wAmount;
342                  break;                  break;
343              case MOD_LFO_TO_VOLUME:              case MOD_LFO_TO_VOLUME:
344                    modLfoToVolume = Gen.GenAmount.shAmount;
345                  break;                  break;
346              case CHORUS_EFFECTS_SEND:              case CHORUS_EFFECTS_SEND:
347                  break;                  break;
# Line 331  namespace sf2 { Line 354  namespace sf2 {
354                  if (pan >  63) pan =  63;                  if (pan >  63) pan =  63;
355                  break;                  break;
356              case DELAY_MOD_LFO:              case DELAY_MOD_LFO:
357                    delayModLfo = Gen.GenAmount.shAmount;
358                  break;                  break;
359              case FREQ_MOD_LFO:              case FREQ_MOD_LFO:
360                    freqModLfo = Gen.GenAmount.shAmount;
361                  break;                  break;
362              case DELAY_VIB_LFO:              case DELAY_VIB_LFO:
363                    delayVibLfo = Gen.GenAmount.shAmount;
364                  break;                  break;
365              case FREQ_VIB_LFO:              case FREQ_VIB_LFO:
366                    freqVibLfo = Gen.GenAmount.shAmount;
367                  break;                  break;
368              case DELAY_MOD_ENV:              case DELAY_MOD_ENV:
369                  EG2PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG2PreAttackDelay = Gen.GenAmount.shAmount;
370                  break;                  break;
371              case ATTACK_MOD_ENV:              case ATTACK_MOD_ENV:
372                  EG2Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG2Attack = Gen.GenAmount.shAmount;
373                  break;                  break;
374              case HOLD_MOD_ENV:              case HOLD_MOD_ENV:
375                  EG2Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG2Hold = Gen.GenAmount.shAmount;
376                  break;                  break;
377              case DECAY_MOD_ENV:              case DECAY_MOD_ENV:
378                  EG2Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG2Decay = Gen.GenAmount.shAmount;
379                  break;                  break;
380              case SUSTAIN_MOD_ENV:              case SUSTAIN_MOD_ENV:
381                  EG2Sustain = 1000 - Gen.GenAmount.shAmount;                  EG2Sustain = Gen.GenAmount.shAmount;
382                  break;                  break;
383              case RELEASEMODENV:              case RELEASEMODENV:
384                  EG2Release = ToSeconds(Gen.GenAmount.shAmount);                  EG2Release = Gen.GenAmount.shAmount;
385                  break;                  break;
386              case KEYNUM_TO_MOD_ENV_HOLD:              case KEYNUM_TO_MOD_ENV_HOLD:
387                  break;                  break;
388              case KEYNUM_TO_MOD_ENV_DECAY:              case KEYNUM_TO_MOD_ENV_DECAY:
389                  break;                  break;
390              case DELAY_VOL_ENV:              case DELAY_VOL_ENV:
391                  EG1PreAttackDelay = ToSeconds(Gen.GenAmount.shAmount);                  EG1PreAttackDelay = Gen.GenAmount.shAmount;
392                  break;                  break;
393              case ATTACK_VOL_ENV:              case ATTACK_VOL_ENV:
394                  EG1Attack = ToSeconds(Gen.GenAmount.shAmount);                  EG1Attack = Gen.GenAmount.shAmount;
395                  break;                  break;
396              case HOLD_VOL_ENV:              case HOLD_VOL_ENV:
397                  EG1Hold = ToSeconds(Gen.GenAmount.shAmount);                  EG1Hold = Gen.GenAmount.shAmount;
398                  break;                  break;
399              case DECAY_VOL_ENV:              case DECAY_VOL_ENV:
400                  EG1Decay = ToSeconds(Gen.GenAmount.shAmount);                  EG1Decay = Gen.GenAmount.shAmount;
401                  break;                  break;
402              case SUSTAIN_VOL_ENV:              case SUSTAIN_VOL_ENV:
403                  EG1Sustain = ToPermilles(Gen.GenAmount.shAmount);                  EG1Sustain = Gen.GenAmount.shAmount;
404                  break;                  break;
405              case RELEASE_VOL_ENV:              case RELEASE_VOL_ENV:
406                  EG1Release = ToSeconds(Gen.GenAmount.shAmount);                  EG1Release = Gen.GenAmount.shAmount;
407                  break;                  break;
408              case KEYNUM_TO_VOL_ENV_HOLD:              case KEYNUM_TO_VOL_ENV_HOLD:
409                  break;                  break;
# Line 414  namespace sf2 { Line 441  namespace sf2 {
441                  break;                  break;
442              case COARSE_TUNE:              case COARSE_TUNE:
443                  coarseTune = Gen.GenAmount.shAmount;                  coarseTune = Gen.GenAmount.shAmount;
444                    if (coarseTune < -120) coarseTune = -120;
445                    if (coarseTune >  120) coarseTune =  120;
446                  break;                  break;
447              case FINE_TUNE:              case FINE_TUNE:
448                  fineTune = Gen.GenAmount.shAmount;                  fineTune = Gen.GenAmount.shAmount;
# Line 445  namespace sf2 { Line 474  namespace sf2 {
474              case SCALE_TUNING:              case SCALE_TUNING:
475                  break;                  break;
476              case EXCLUSIVE_CLASS:              case EXCLUSIVE_CLASS:
477                    exclusiveClass = Gen.GenAmount.wAmount;
478                  break;                  break;
479              case OVERRIDING_ROOT_KEY:              case OVERRIDING_ROOT_KEY:
480                  overridingRootKey = Gen.GenAmount.shAmount;                  overridingRootKey = Gen.GenAmount.shAmount;
# Line 475  namespace sf2 { Line 505  namespace sf2 {
505          }*/          }*/
506      }      }
507    
508        int Region::GetPan(Region* pPresetRegion) {
509            if (pPresetRegion == NULL) return pan;
510            int p = pPresetRegion->pan + pan;
511            if (p < -64) p = -64;
512            if (p >  63) p =  63;
513            return p;
514        }
515    
516        int Region::GetFineTune(Region* pPresetRegion) {
517            if (pPresetRegion == NULL) return fineTune;
518            int t = pPresetRegion->fineTune + fineTune;
519            if (t < -99) t = -99;
520            if (t >  99) t =  99;
521            return t;
522        }
523    
524        int Region::GetCoarseTune(Region* pPresetRegion) {
525             if (pPresetRegion == NULL) return coarseTune;
526            int t = pPresetRegion->coarseTune + coarseTune;
527            if (t < -120) t = -120;
528            if (t >  120) t =  120;
529            return t;
530        }
531    
532        double Region::GetEG1PreAttackDelay(Region* pPresetRegion) {
533            if (pPresetRegion == NULL || pPresetRegion->EG1PreAttackDelay == NONE) return ToSeconds(EG1PreAttackDelay);
534            return ToSeconds(pPresetRegion->EG1PreAttackDelay + EG1PreAttackDelay);
535        }
536    
537        double Region::GetEG1Attack(Region* pPresetRegion) {
538            if (pPresetRegion == NULL || pPresetRegion->EG1Attack == NONE) return ToSeconds(EG1Attack);
539            return ToSeconds(pPresetRegion->EG1Attack + EG1Attack);
540        }
541    
542        double Region::GetEG1Hold(Region* pPresetRegion) {
543            if (pPresetRegion == NULL || pPresetRegion->EG1Hold == NONE) return ToSeconds(EG1Hold);
544            return ToSeconds(pPresetRegion->EG1Hold + EG1Hold);
545        }
546    
547        double Region::GetEG1Decay(Region* pPresetRegion) {
548            if (pPresetRegion == NULL || pPresetRegion->EG1Decay == NONE) return ToSeconds(EG1Decay);
549            return ToSeconds(pPresetRegion->EG1Decay + EG1Decay);
550        }
551    
552        double Region::GetEG1Sustain(Region* pPresetRegion) {
553            if (pPresetRegion == NULL || pPresetRegion->EG1Sustain == NONE) return ToPermilles(EG1Sustain);
554            return ToPermilles(pPresetRegion->EG1Sustain + EG1Sustain);
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 504  namespace sf2 { Line 664  namespace sf2 {
664          for (int i = 0; i < GetRegionCount(); i++) {          for (int i = 0; i < GetRegionCount(); i++) {
665              Region* r = GetRegion(i);              Region* r = GetRegion(i);
666              if (              if (
667                  key >= r->loKey && key <= r->hiKey &&                  ((r->loKey  == NONE && r->hiKey  == NONE) || (key >= r->loKey && key <= r->hiKey)) &&
668                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))                  ((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))
669              ) {              ) {
670                  v.push_back(r);                  v.push_back(r);
# 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.2044

  ViewVC Help
Powered by ViewVC