/[svn]/linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.cpp

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

revision 2252 by iliev, Sat Aug 20 14:01:36 2011 UTC revision 2300 by iliev, Mon Dec 12 09:20:00 2011 UTC
# Line 129  namespace LinuxSampler { namespace sfz { Line 129  namespace LinuxSampler { namespace sfz {
129            
130            
131      EGv2Unit::EGv2Unit(SfzSignalUnitRack* rack)      EGv2Unit::EGv2Unit(SfzSignalUnitRack* rack)
132          : EGUnit< ::LinuxSampler::sfz::EG>(rack), suAmpOnCC(rack), suVolOnCC(rack),          : EGUnit< ::LinuxSampler::sfz::EG>(rack), EqUnitSupport(rack), suAmpOnCC(rack), suVolOnCC(rack),
133            suPitchOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack), suPanOnCC(rack)            suPitchOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack), suPanOnCC(rack)
134      { }      { }
135            
# Line 311  namespace LinuxSampler { namespace sfz { Line 311  namespace LinuxSampler { namespace sfz {
311            
312            
313      LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack)      LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack)
314          : LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f),          : LFOUnit(rack), EqUnitSupport(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f),
315            lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f),            lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f),
316            suVolOnCC(rack), suPitchOnCC(rack), suPanOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack)            suVolOnCC(rack), suPitchOnCC(rack), suPanOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack)
317      {      {
# Line 399  namespace LinuxSampler { namespace sfz { Line 399  namespace LinuxSampler { namespace sfz {
399          RTList<CC>::Iterator end  = pCtrls->end();          RTList<CC>::Iterator end  = pCtrls->end();
400          for(; ctrl != end; ++ctrl) {          for(; ctrl != end; ++ctrl) {
401              (*ctrl).Value = pVoice->GetControllerValue((*ctrl).Controller);              (*ctrl).Value = pVoice->GetControllerValue((*ctrl).Controller);
402              if ((*ctrl).pSmoother != NULL) (*ctrl).pSmoother->setValue((*ctrl).Value);              if ((*ctrl).pSmoother != NULL) {
403                    if ((*ctrl).Step > 0) {
404                        float val = Normalize((*ctrl).Value, (*ctrl).Curve) * (*ctrl).Influence;
405                        (*ctrl).pSmoother->setValue( ((int) (val / (*ctrl).Step)) * (*ctrl).Step );
406                    } else {
407                        (*ctrl).pSmoother->setValue((*ctrl).Value);
408                    }
409                }
410          }          }
411          CCSignalUnit::Trigger();          CCSignalUnit::Trigger();
412      }      }
# Line 411  namespace LinuxSampler { namespace sfz { Line 418  namespace LinuxSampler { namespace sfz {
418          }          }
419      }      }
420            
421        void CCUnit::SetCCs(::sfz::Array<float>& cc) {
422            RemoveAllCCs();
423            for (int i = 0; i < 128; i++) {
424                if (cc[i] != 0) AddCC(i, cc[i]);
425            }
426        }
427        
428      void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) {      void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) {
429          RemoveAllCCs();          RemoveAllCCs();
430          for (int i = 0; i < cc.size(); i++) {          for (int i = 0; i < cc.size(); i++) {
431              if (cc[i].Influence != 0) {              if (cc[i].Influence != 0) {
432                  short int curve = cc[i].Curve;                  short int curve = cc[i].Curve;
433                  if (curve >= GetCurveCount()) curve = -1;                  if (curve >= GetCurveCount()) curve = -1;
434                  AddSmoothCC(cc[i].Controller, cc[i].Influence, curve, cc[i].Smooth);                  AddSmoothCC(cc[i].Controller, cc[i].Influence, curve, cc[i].Smooth, cc[i].Step);
435              }              }
436          }          }
437      }      }
438            
439      void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) {      void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth, float Step) {
440          AddCC(Controller, Influence, Curve);          AddCC(Controller, Influence, Curve, NULL, Step);
441      }      }
442            
443      int CCUnit::GetCurveCount() {      int CCUnit::GetCurveCount() {
# Line 443  namespace LinuxSampler { namespace sfz { Line 457  namespace LinuxSampler { namespace sfz {
457          if (pSmoothers != NULL) delete pSmoothers;          if (pSmoothers != NULL) delete pSmoothers;
458      }      }
459            
460      void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) {      void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth, float Step) {
461          if (Smooth > 0) {          if (Smooth > 0) {
462              if (pSmoothers->poolIsEmpty()) {              if (pSmoothers->poolIsEmpty()) {
463                  std::cerr << "Maximum number of smoothers reached" << std::endl;                  std::cerr << "Maximum number of smoothers reached" << std::endl;
# Line 451  namespace LinuxSampler { namespace sfz { Line 465  namespace LinuxSampler { namespace sfz {
465              }              }
466              Smoother* smoother = &(*(pSmoothers->allocAppend()));              Smoother* smoother = &(*(pSmoothers->allocAppend()));
467              smoother->trigger(Smooth / 1000.0f, GetSampleRate());              smoother->trigger(Smooth / 1000.0f, GetSampleRate());
468              AddCC(Controller, Influence, Curve, smoother);              AddCC(Controller, Influence, Curve, smoother, Step);
469          } else {          } else {
470              AddCC(Controller, Influence, Curve);              AddCC(Controller, Influence, Curve, NULL, Step);
471          }          }
472      }      }
473            
# Line 474  namespace LinuxSampler { namespace sfz { Line 488  namespace LinuxSampler { namespace sfz {
488                    
489      }      }
490            
491        float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional<float> >& cc) {
492            float f = 0;
493            for (int i = 0; i < 128; i++) {
494                if (cc[i]) {
495                    f += (pVoice->GetControllerValue(i) / 127.0f) * (*cc[i]);
496                }
497            }
498            return f;
499        }
500        
501        float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional<int> >& cc) {
502            float f = 0;
503            for (int i = 0; i < 128; i++) {
504                if (cc[i]) {
505                    f += (pVoice->GetControllerValue(i) / 127.0f) * (*cc[i]);
506                }
507            }
508            return f;
509        }
510        
511      SfzSignalUnitRack* const EndpointUnit::GetRack() {      SfzSignalUnitRack* const EndpointUnit::GetRack() {
512          return static_cast<SfzSignalUnitRack* const>(pRack);          return static_cast<SfzSignalUnitRack* const>(pRack);
513      }      }
514            
515      void EndpointUnit::Trigger() {      void EndpointUnit::Trigger() {
516            uiDelayTrigger = (uint)GetInfluence(pVoice->pRegion->delay_samples_oncc);
517            if (pVoice->pRegion->delay_samples) uiDelayTrigger += *pVoice->pRegion->delay_samples;
518            
519            if (pVoice->pRegion->delay) {
520                /* here we use the device sample rate */
521                uiDelayTrigger += (uint)( (*pVoice->pRegion->delay) * pVoice->GetSampleRate() );
522            }
523            
524            if (pVoice->pRegion->delay_random) {
525                float r = pVoice->GetEngine()->Random();
526                uiDelayTrigger += (uint)( r * (*pVoice->pRegion->delay_random) * pVoice->GetSampleRate() );
527            }
528            
529            uiDelayTrigger += (uint)(GetInfluence(pVoice->pRegion->delay_oncc) * pVoice->GetSampleRate());
530            
531          float xfInVelCoeff = 1;          float xfInVelCoeff = 1;
532                    
533          if (pVoice->MIDIVelocity <= pVoice->pRegion->xfin_lovel) {          if (pVoice->MIDIVelocity <= pVoice->pRegion->xfin_lovel) {
# Line 550  namespace LinuxSampler { namespace sfz { Line 599  namespace LinuxSampler { namespace sfz {
599      }      }
600            
601      bool EndpointUnit::Active() {      bool EndpointUnit::Active() {
602            if (pRack->isReleaseStageEntered() && uiDelayTrigger) {
603                return false; // The key was released before the delay end, so the voice won't play at all.
604            }
605            
606          if (GetRack()->suVolEG.Active()) return true;          if (GetRack()->suVolEG.Active()) return true;
607                    
608          bool b = false;          bool b = false;
# Line 641  namespace LinuxSampler { namespace sfz { Line 694  namespace LinuxSampler { namespace sfz {
694      }      }
695            
696      float EndpointUnit::GetPitch() {      float EndpointUnit::GetPitch() {
697          double p;          double p = GetRack()->suPitchOnCC.Active() ? RTMath::CentsToFreqRatioUnlimited(GetRack()->suPitchOnCC.GetLevel()) : 1;
698            
699          EGv1Unit* u = &(GetRack()->suPitchEG);          EGv1Unit* u = &(GetRack()->suPitchEG);
700          p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1;          p *= u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1;
701                    
702          for (int i = 0; i < GetRack()->pitchEGs.size(); i++) {          for (int i = 0; i < GetRack()->pitchEGs.size(); i++) {
703              EGv2Unit* eg = GetRack()->pitchEGs[i];              EGv2Unit* eg = GetRack()->pitchEGs[i];
# Line 725  namespace LinuxSampler { namespace sfz { Line 779  namespace LinuxSampler { namespace sfz {
779            
780            
781      SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice)      SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice)
782          : SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this),          : SignalUnitRack(MaxUnitCount), EqUnitSupport(this, voice), pVoice(voice),
783          EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), panEGs(maxEgCount),          suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this),
784          suVolOnCC(this), suCutoffOnCC(this), suResOnCC(this),          EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount),
785            resEGs(maxEgCount), panEGs(maxEgCount), eqEGs(maxEgCount),
786            suVolOnCC(this), suPitchOnCC(this), suCutoffOnCC(this), suResOnCC(this),
787          suAmpLFO(this), suPitchLFO(this), suFilLFO(this),          suAmpLFO(this), suPitchLFO(this), suFilLFO(this),
788          LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount),          LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount),
789          filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount)          filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount), eqLFOs(maxLfoCount)
790      {      {
791          suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice;          suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice;
792          suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice;          suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice;
793          suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = suVolOnCC.pVoice = suCutoffOnCC.pVoice = suResOnCC.pVoice = voice;          suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice;
794            
795            suVolOnCC.pVoice = suPitchOnCC.pVoice = suCutoffOnCC.pVoice = suResOnCC.pVoice = voice;
796          suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice;          suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice;
797          suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice;          suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice;
798          suAmpLFO.suFadeEG.pVoice = suAmpLFO.suDepthOnCC.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice;          suAmpLFO.suFadeEG.pVoice = suAmpLFO.suDepthOnCC.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice;
# Line 748  namespace LinuxSampler { namespace sfz { Line 806  namespace LinuxSampler { namespace sfz {
806              EGs[i]->suCutoffOnCC.pVoice = voice;              EGs[i]->suCutoffOnCC.pVoice = voice;
807              EGs[i]->suResOnCC.pVoice = voice;              EGs[i]->suResOnCC.pVoice = voice;
808              EGs[i]->suPanOnCC.pVoice = voice;              EGs[i]->suPanOnCC.pVoice = voice;
809                EGs[i]->SetVoice(voice); // class EqUnitSupport
810          }          }
811                    
812          for (int i = 0; i < LFOs.capacity(); i++) {          for (int i = 0; i < LFOs.capacity(); i++) {
# Line 762  namespace LinuxSampler { namespace sfz { Line 821  namespace LinuxSampler { namespace sfz {
821              LFOs[i]->suPanOnCC.pVoice = voice;              LFOs[i]->suPanOnCC.pVoice = voice;
822              LFOs[i]->suCutoffOnCC.pVoice = voice;              LFOs[i]->suCutoffOnCC.pVoice = voice;
823              LFOs[i]->suResOnCC.pVoice = voice;              LFOs[i]->suResOnCC.pVoice = voice;
824                LFOs[i]->SetVoice(voice); // class EqUnitSupport
825          }          }
826      }      }
827            
# Line 779  namespace LinuxSampler { namespace sfz { Line 839  namespace LinuxSampler { namespace sfz {
839          Pool<CCSignalUnit::CC>* pCCPool = pVoice->pEngine->pCCPool;          Pool<CCSignalUnit::CC>* pCCPool = pVoice->pEngine->pCCPool;
840          Pool<Smoother>* pSmootherPool = pVoice->pEngine->pSmootherPool;          Pool<Smoother>* pSmootherPool = pVoice->pEngine->pSmootherPool;
841                    
842            EqUnitSupport::InitCCLists(pCCPool, pSmootherPool);
843            
844          suVolOnCC.InitCCList(pCCPool, pSmootherPool);          suVolOnCC.InitCCList(pCCPool, pSmootherPool);
845            suPitchOnCC.InitCCList(pCCPool, pSmootherPool);
846          suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);          suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);
847          suResOnCC.InitCCList(pCCPool, pSmootherPool);          suResOnCC.InitCCList(pCCPool, pSmootherPool);
848          suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool);          suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool);
# Line 799  namespace LinuxSampler { namespace sfz { Line 862  namespace LinuxSampler { namespace sfz {
862              EGs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);              EGs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);
863              EGs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool);              EGs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool);
864              EGs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool);              EGs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool);
865                EGs[i]->InitCCLists(pCCPool, pSmootherPool); // class EqUnitSupport
866          }          }
867                    
868          for (int i = 0; i < LFOs.capacity(); i++) {          for (int i = 0; i < LFOs.capacity(); i++) {
# Line 810  namespace LinuxSampler { namespace sfz { Line 874  namespace LinuxSampler { namespace sfz {
874              LFOs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool);              LFOs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool);
875              LFOs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);              LFOs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);
876              LFOs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool);              LFOs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool);
877                LFOs[i]->InitCCLists(pCCPool, pSmootherPool); // class EqUnitSupport
878          }          }
879      }      }
880            
# Line 820  namespace LinuxSampler { namespace sfz { Line 885  namespace LinuxSampler { namespace sfz {
885          filEGs.clear();          filEGs.clear();
886          resEGs.clear();          resEGs.clear();
887          panEGs.clear();          panEGs.clear();
888            eqEGs.clear();
889                    
890          LFOs.clear();          LFOs.clear();
891          volLFOs.clear();          volLFOs.clear();
# Line 827  namespace LinuxSampler { namespace sfz { Line 893  namespace LinuxSampler { namespace sfz {
893          filLFOs.clear();          filLFOs.clear();
894          resLFOs.clear();          resLFOs.clear();
895          panLFOs.clear();          panLFOs.clear();
896            eqLFOs.clear();
897                    
898          ::sfz::Region* const pRegion = pVoice->pRegion;          ::sfz::Region* const pRegion = pVoice->pRegion;
899                    
900          suVolOnCC.SetCCs(pRegion->volume_oncc);          suVolOnCC.SetCCs(pRegion->volume_oncc);
901            suPitchOnCC.SetCCs(pRegion->pitch_oncc);
902          suCutoffOnCC.SetCCs(pRegion->cutoff_oncc);          suCutoffOnCC.SetCCs(pRegion->cutoff_oncc);
903          suResOnCC.SetCCs(pRegion->resonance_oncc);          suResOnCC.SetCCs(pRegion->resonance_oncc);
904                    
# Line 847  namespace LinuxSampler { namespace sfz { Line 915  namespace LinuxSampler { namespace sfz {
915                  EGs[EGs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->eg[i].cutoff_oncc);                  EGs[EGs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->eg[i].cutoff_oncc);
916                  EGs[EGs.size() - 1]->suResOnCC.SetCCs(pRegion->eg[i].resonance_oncc);                  EGs[EGs.size() - 1]->suResOnCC.SetCCs(pRegion->eg[i].resonance_oncc);
917                  EGs[EGs.size() - 1]->suPanOnCC.SetCCs(pRegion->eg[i].pan_oncc);                  EGs[EGs.size() - 1]->suPanOnCC.SetCCs(pRegion->eg[i].pan_oncc);
918                    if (pVoice->bEqSupport) {
919                        EGs[EGs.size() - 1]->suEq1FreqOnCC.SetCCs(pRegion->eg[i].eq1freq_oncc);
920                        EGs[EGs.size() - 1]->suEq2FreqOnCC.SetCCs(pRegion->eg[i].eq2freq_oncc);
921                        EGs[EGs.size() - 1]->suEq3FreqOnCC.SetCCs(pRegion->eg[i].eq3freq_oncc);
922                        EGs[EGs.size() - 1]->suEq1GainOnCC.SetCCs(pRegion->eg[i].eq1gain_oncc);
923                        EGs[EGs.size() - 1]->suEq2GainOnCC.SetCCs(pRegion->eg[i].eq2gain_oncc);
924                        EGs[EGs.size() - 1]->suEq3GainOnCC.SetCCs(pRegion->eg[i].eq3gain_oncc);
925                        EGs[EGs.size() - 1]->suEq1BwOnCC.SetCCs(pRegion->eg[i].eq1bw_oncc);
926                        EGs[EGs.size() - 1]->suEq2BwOnCC.SetCCs(pRegion->eg[i].eq2bw_oncc);
927                        EGs[EGs.size() - 1]->suEq3BwOnCC.SetCCs(pRegion->eg[i].eq3bw_oncc);
928                    }
929              } else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; }              } else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; }
930                            
931              if ( pRegion->eg[i].amplitude > 0 || !pRegion->eg[i].amplitude_oncc.empty() ||              if ( pRegion->eg[i].amplitude > 0 || !pRegion->eg[i].amplitude_oncc.empty() ||
# Line 875  namespace LinuxSampler { namespace sfz { Line 954  namespace LinuxSampler { namespace sfz {
954                  if(panEGs.size() < panEGs.capacity()) panEGs.add(EGs[EGs.size() - 1]);                  if(panEGs.size() < panEGs.capacity()) panEGs.add(EGs[EGs.size() - 1]);
955                  else std::cerr << "Maximum number of EGs reached!" << std::endl;                  else std::cerr << "Maximum number of EGs reached!" << std::endl;
956              }              }
957                
958                if (pRegion->eg[i].HasEq()) {
959                    if(eqEGs.size() < eqEGs.capacity()) eqEGs.add(EGs[EGs.size() - 1]);
960                    else std::cerr << "Maximum number of EGs reached!" << std::endl;
961                }
962          }          }
963                    
964          if (pRegion->ampeg_sustain == -1) {          if (pRegion->ampeg_sustain == -1) {
# Line 899  namespace LinuxSampler { namespace sfz { Line 983  namespace LinuxSampler { namespace sfz {
983                  LFOs[LFOs.size() - 1]->suPanOnCC.SetCCs(pRegion->lfos[i].pan_oncc);                  LFOs[LFOs.size() - 1]->suPanOnCC.SetCCs(pRegion->lfos[i].pan_oncc);
984                  LFOs[LFOs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->lfos[i].cutoff_oncc);                  LFOs[LFOs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->lfos[i].cutoff_oncc);
985                  LFOs[LFOs.size() - 1]->suResOnCC.SetCCs(pRegion->lfos[i].resonance_oncc);                  LFOs[LFOs.size() - 1]->suResOnCC.SetCCs(pRegion->lfos[i].resonance_oncc);
986                    if (pVoice->bEqSupport) {
987                        LFOs[LFOs.size() - 1]->suEq1FreqOnCC.SetCCs(pRegion->lfos[i].eq1freq_oncc);
988                        LFOs[LFOs.size() - 1]->suEq2FreqOnCC.SetCCs(pRegion->lfos[i].eq2freq_oncc);
989                        LFOs[LFOs.size() - 1]->suEq3FreqOnCC.SetCCs(pRegion->lfos[i].eq3freq_oncc);
990                        LFOs[LFOs.size() - 1]->suEq1GainOnCC.SetCCs(pRegion->lfos[i].eq1gain_oncc);
991                        LFOs[LFOs.size() - 1]->suEq2GainOnCC.SetCCs(pRegion->lfos[i].eq2gain_oncc);
992                        LFOs[LFOs.size() - 1]->suEq3GainOnCC.SetCCs(pRegion->lfos[i].eq3gain_oncc);
993                        LFOs[LFOs.size() - 1]->suEq1BwOnCC.SetCCs(pRegion->lfos[i].eq1bw_oncc);
994                        LFOs[LFOs.size() - 1]->suEq2BwOnCC.SetCCs(pRegion->lfos[i].eq2bw_oncc);
995                        LFOs[LFOs.size() - 1]->suEq3BwOnCC.SetCCs(pRegion->lfos[i].eq3bw_oncc);
996                    }
997              } else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; }              } else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; }
998                            
999              if (pRegion->lfos[i].volume != 0 || !pRegion->lfos[i].volume_oncc.empty()) {              if (pRegion->lfos[i].volume != 0 || !pRegion->lfos[i].volume_oncc.empty()) {
# Line 925  namespace LinuxSampler { namespace sfz { Line 1020  namespace LinuxSampler { namespace sfz {
1020                  if(panLFOs.size() < panLFOs.capacity()) panLFOs.add(LFOs[LFOs.size() - 1]);                  if(panLFOs.size() < panLFOs.capacity()) panLFOs.add(LFOs[LFOs.size() - 1]);
1021                  else std::cerr << "Maximum number of LFOs reached!" << std::endl;                  else std::cerr << "Maximum number of LFOs reached!" << std::endl;
1022              }              }
1023                
1024                if (pRegion->lfos[i].HasEq()) {
1025                    if(eqLFOs.size() < eqLFOs.capacity()) eqLFOs.add(LFOs[LFOs.size() - 1]);
1026                    else std::cerr << "Maximum number of LFOs reached!" << std::endl;
1027                }
1028            }
1029            
1030            if (!pVoice->bEqSupport) {
1031                bHasEq = false;
1032            } else {
1033                suEq1GainOnCC.SetCCs(pRegion->eq1_gain_oncc);
1034                suEq2GainOnCC.SetCCs(pRegion->eq2_gain_oncc);
1035                suEq3GainOnCC.SetCCs(pRegion->eq3_gain_oncc);
1036                suEq1FreqOnCC.SetCCs(pRegion->eq1_freq_oncc);
1037                suEq2FreqOnCC.SetCCs(pRegion->eq2_freq_oncc);
1038                suEq3FreqOnCC.SetCCs(pRegion->eq3_freq_oncc);
1039                suEq1BwOnCC.SetCCs(pRegion->eq1_bw_oncc);
1040                suEq2BwOnCC.SetCCs(pRegion->eq2_bw_oncc);
1041                suEq3BwOnCC.SetCCs(pRegion->eq3_bw_oncc);
1042            
1043                bHasEq = pRegion->eq1_gain || pRegion->eq2_gain || pRegion->eq3_gain ||
1044                         pRegion->eq1_vel2gain || pRegion->eq2_vel2gain || pRegion->eq3_vel2gain ||
1045                         suEq1GainOnCC.HasCCs() || suEq2GainOnCC.HasCCs() || suEq3GainOnCC.HasCCs() ||
1046                         eqEGs.size() > 0 || eqLFOs.size() > 0;
1047          }          }
1048                    
1049          suPitchLFO.suDepthOnCC.SetCCs(pRegion->pitchlfo_depthcc);          suPitchLFO.suDepthOnCC.SetCCs(pRegion->pitchlfo_depthcc);
# Line 938  namespace LinuxSampler { namespace sfz { Line 1057  namespace LinuxSampler { namespace sfz {
1057                    
1058          Units.clear();          Units.clear();
1059                    
1060            EqUnitSupport::ImportUnits(this);
1061            
1062          Units.add(&suVolOnCC);          Units.add(&suVolOnCC);
1063            Units.add(&suPitchOnCC);
1064          Units.add(&suCutoffOnCC);          Units.add(&suCutoffOnCC);
1065          Units.add(&suResOnCC);          Units.add(&suResOnCC);
1066                    
# Line 969  namespace LinuxSampler { namespace sfz { Line 1091  namespace LinuxSampler { namespace sfz {
1091              Units.add(&(EGs[i]->suCutoffOnCC));              Units.add(&(EGs[i]->suCutoffOnCC));
1092              Units.add(&(EGs[i]->suResOnCC));              Units.add(&(EGs[i]->suResOnCC));
1093              Units.add(&(EGs[i]->suPanOnCC));              Units.add(&(EGs[i]->suPanOnCC));
1094                EGs[i]->ImportUnits(this); // class EqUnitSupport
1095          }          }
1096                    
1097          for (int i = 0; i < LFOs.size(); i++) {          for (int i = 0; i < LFOs.size(); i++) {
# Line 980  namespace LinuxSampler { namespace sfz { Line 1103  namespace LinuxSampler { namespace sfz {
1103              Units.add(&(LFOs[i]->suPanOnCC));              Units.add(&(LFOs[i]->suPanOnCC));
1104              Units.add(&(LFOs[i]->suCutoffOnCC));              Units.add(&(LFOs[i]->suCutoffOnCC));
1105              Units.add(&(LFOs[i]->suResOnCC));              Units.add(&(LFOs[i]->suResOnCC));
1106                LFOs[i]->ImportUnits(this); // class EqUnitSupport
1107          }          }
1108                    
1109          Units.add(&suEndpoint);          Units.add(&suEndpoint);
# Line 1003  namespace LinuxSampler { namespace sfz { Line 1127  namespace LinuxSampler { namespace sfz {
1127      }      }
1128            
1129      void SfzSignalUnitRack::Reset() {      void SfzSignalUnitRack::Reset() {
1130            EqUnitSupport::ResetUnits();
1131            
1132          suVolOnCC.RemoveAllCCs();          suVolOnCC.RemoveAllCCs();
1133            suPitchOnCC.RemoveAllCCs();
1134          suCutoffOnCC.RemoveAllCCs();          suCutoffOnCC.RemoveAllCCs();
1135          suResOnCC.RemoveAllCCs();          suResOnCC.RemoveAllCCs();
1136          suEndpoint.suXFInCC.RemoveAllCCs();          suEndpoint.suXFInCC.RemoveAllCCs();
# Line 1023  namespace LinuxSampler { namespace sfz { Line 1150  namespace LinuxSampler { namespace sfz {
1150              EGs[i]->suCutoffOnCC.RemoveAllCCs();              EGs[i]->suCutoffOnCC.RemoveAllCCs();
1151              EGs[i]->suResOnCC.RemoveAllCCs();              EGs[i]->suResOnCC.RemoveAllCCs();
1152              EGs[i]->suPanOnCC.RemoveAllCCs();              EGs[i]->suPanOnCC.RemoveAllCCs();
1153                EGs[i]->ResetUnits(); // class EqUnitSupport
1154          }          }
1155                    
1156          for (int i = 0; i < LFOs.capacity(); i++) {          for (int i = 0; i < LFOs.capacity(); i++) {
# Line 1034  namespace LinuxSampler { namespace sfz { Line 1162  namespace LinuxSampler { namespace sfz {
1162              LFOs[i]->suPanOnCC.RemoveAllCCs();              LFOs[i]->suPanOnCC.RemoveAllCCs();
1163              LFOs[i]->suCutoffOnCC.RemoveAllCCs();              LFOs[i]->suCutoffOnCC.RemoveAllCCs();
1164              LFOs[i]->suResOnCC.RemoveAllCCs();              LFOs[i]->suResOnCC.RemoveAllCCs();
1165                LFOs[i]->ResetUnits(); // class EqUnitSupport
1166            }
1167        }
1168        
1169        void SfzSignalUnitRack::UpdateEqSettings(EqSupport* pEqSupport) {
1170            if (!pEqSupport->HasSupport()) return;
1171            if (pEqSupport->GetBandCount() < 3) {
1172                std::cerr << "SfzSignalUnitRack::UpdateEqSettings: EQ should have at least 3 bands\n";
1173                return;
1174          }          }
1175            
1176            ::sfz::Region* const pRegion = pVoice->pRegion;
1177            
1178            float dB1 = (suEq1GainOnCC.Active() ? suEq1GainOnCC.GetLevel() : 0) + pRegion->eq1_gain;
1179            float dB2 = (suEq2GainOnCC.Active() ? suEq2GainOnCC.GetLevel() : 0) + pRegion->eq2_gain;
1180            float dB3 = (suEq3GainOnCC.Active() ? suEq3GainOnCC.GetLevel() : 0) + pRegion->eq3_gain;
1181            
1182            float freq1 = (suEq1FreqOnCC.Active() ? suEq1FreqOnCC.GetLevel() : 0) + pRegion->eq1_freq;
1183            float freq2 = (suEq2FreqOnCC.Active() ? suEq2FreqOnCC.GetLevel() : 0) + pRegion->eq2_freq;
1184            float freq3 = (suEq3FreqOnCC.Active() ? suEq3FreqOnCC.GetLevel() : 0) + pRegion->eq3_freq;
1185            
1186            float bw1 = (suEq1BwOnCC.Active() ? suEq1BwOnCC.GetLevel() : 0) + pRegion->eq1_bw;
1187            float bw2 = (suEq2BwOnCC.Active() ? suEq2BwOnCC.GetLevel() : 0) + pRegion->eq2_bw;
1188            float bw3 = (suEq3BwOnCC.Active() ? suEq3BwOnCC.GetLevel() : 0) + pRegion->eq3_bw;
1189            
1190            const float vel = pVoice->MIDIVelocity / 127.0f;
1191            
1192            dB1 += pRegion->eq1_vel2gain * vel;
1193            dB2 += pRegion->eq2_vel2gain * vel;
1194            dB3 += pRegion->eq3_vel2gain * vel;
1195            
1196            freq1 += pRegion->eq1_vel2freq * vel;
1197            freq2 += pRegion->eq2_vel2freq * vel;
1198            freq3 += pRegion->eq3_vel2freq * vel;
1199            
1200            for (int i = 0; i < eqEGs.size(); i++) {
1201                EGv2Unit* eg = eqEGs[i];
1202                if (!eg->Active()) continue;
1203                
1204                float l = eg->GetLevel();
1205                dB1 += ((eg->suEq1GainOnCC.Active() ? eg->suEq1GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq1gain) * l;
1206                dB2 += ((eg->suEq2GainOnCC.Active() ? eg->suEq2GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq2gain) * l;
1207                dB3 += ((eg->suEq3GainOnCC.Active() ? eg->suEq3GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq3gain) * l;
1208                
1209                freq1 += ((eg->suEq1FreqOnCC.Active() ? eg->suEq1FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq1freq) * l;
1210                freq2 += ((eg->suEq2FreqOnCC.Active() ? eg->suEq2FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq2freq) * l;
1211                freq3 += ((eg->suEq3FreqOnCC.Active() ? eg->suEq3FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq3freq) * l;
1212                
1213                bw1 += ((eg->suEq1BwOnCC.Active() ? eg->suEq1BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq1bw) * l;
1214                bw2 += ((eg->suEq2BwOnCC.Active() ? eg->suEq2BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq2bw) * l;
1215                bw3 += ((eg->suEq3BwOnCC.Active() ? eg->suEq3BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq3bw) * l;
1216            }
1217            
1218            for (int i = 0; i < eqLFOs.size(); i++) {
1219                LFOv2Unit* lfo = eqLFOs[i];
1220                if (!lfo->Active()) continue;
1221                
1222                float l = lfo->GetLevel();
1223                dB1 += ((lfo->suEq1GainOnCC.Active() ? lfo->suEq1GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1gain) * l;
1224                dB2 += ((lfo->suEq2GainOnCC.Active() ? lfo->suEq2GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2gain) * l;
1225                dB3 += ((lfo->suEq3GainOnCC.Active() ? lfo->suEq3GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3gain) * l;
1226                
1227                freq1 += ((lfo->suEq1FreqOnCC.Active() ? lfo->suEq1FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1freq) * l;
1228                freq2 += ((lfo->suEq2FreqOnCC.Active() ? lfo->suEq2FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2freq) * l;
1229                freq3 += ((lfo->suEq3FreqOnCC.Active() ? lfo->suEq3FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3freq) * l;
1230                
1231                bw1 += ((lfo->suEq1BwOnCC.Active() ? lfo->suEq1BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1bw) * l;
1232                bw2 += ((lfo->suEq2BwOnCC.Active() ? lfo->suEq2BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2bw) * l;
1233                bw3 += ((lfo->suEq3BwOnCC.Active() ? lfo->suEq3BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3bw) * l;
1234            }
1235            
1236            pEqSupport->SetGain(0, dB1);
1237            pEqSupport->SetGain(1, dB2);
1238            pEqSupport->SetGain(2, dB3);
1239            
1240            pEqSupport->SetFreq(0, freq1);
1241            pEqSupport->SetFreq(1, freq2);
1242            pEqSupport->SetFreq(2, freq3);
1243            
1244            pEqSupport->SetBandwidth(0, bw1);
1245            pEqSupport->SetBandwidth(1, bw2);
1246            pEqSupport->SetBandwidth(2, bw3);
1247        }
1248        
1249        EqUnitSupport::EqUnitSupport(SfzSignalUnitRack* pRack, Voice* pVoice)
1250            : suEq1GainOnCC(pRack), suEq2GainOnCC(pRack), suEq3GainOnCC(pRack),
1251              suEq1FreqOnCC(pRack), suEq2FreqOnCC(pRack), suEq3FreqOnCC(pRack),
1252              suEq1BwOnCC(pRack), suEq2BwOnCC(pRack), suEq3BwOnCC(pRack)
1253        {
1254            SetVoice(pVoice);
1255        }
1256        
1257        void EqUnitSupport::SetVoice(Voice* pVoice) {
1258            suEq1GainOnCC.pVoice = suEq2GainOnCC.pVoice = suEq3GainOnCC.pVoice = pVoice;
1259            suEq1FreqOnCC.pVoice = suEq2FreqOnCC.pVoice = suEq3FreqOnCC.pVoice = pVoice;
1260            suEq1BwOnCC.pVoice = suEq2BwOnCC.pVoice = suEq3BwOnCC.pVoice = pVoice;
1261        }
1262        
1263        void EqUnitSupport::ImportUnits(SfzSignalUnitRack* pRack) {
1264            if (suEq1GainOnCC.HasCCs()) pRack->Units.add(&suEq1GainOnCC);
1265            if (suEq2GainOnCC.HasCCs()) pRack->Units.add(&suEq2GainOnCC);
1266            if (suEq3GainOnCC.HasCCs()) pRack->Units.add(&suEq3GainOnCC);
1267            if (suEq1FreqOnCC.HasCCs()) pRack->Units.add(&suEq1FreqOnCC);
1268            if (suEq2FreqOnCC.HasCCs()) pRack->Units.add(&suEq2FreqOnCC);
1269            if (suEq3FreqOnCC.HasCCs()) pRack->Units.add(&suEq3FreqOnCC);
1270            if (suEq1BwOnCC.HasCCs()) pRack->Units.add(&suEq1BwOnCC);
1271            if (suEq2BwOnCC.HasCCs()) pRack->Units.add(&suEq2BwOnCC);
1272            if (suEq3BwOnCC.HasCCs()) pRack->Units.add(&suEq3BwOnCC);
1273        }
1274        
1275        void EqUnitSupport::ResetUnits() {
1276            suEq1GainOnCC.RemoveAllCCs();
1277            suEq2GainOnCC.RemoveAllCCs();
1278            suEq3GainOnCC.RemoveAllCCs();
1279            suEq1FreqOnCC.RemoveAllCCs();
1280            suEq2FreqOnCC.RemoveAllCCs();
1281            suEq3FreqOnCC.RemoveAllCCs();
1282            suEq1BwOnCC.RemoveAllCCs();
1283            suEq2BwOnCC.RemoveAllCCs();
1284            suEq3BwOnCC.RemoveAllCCs();
1285        }
1286        
1287        void EqUnitSupport::InitCCLists(Pool<CCSignalUnit::CC>* pCCPool, Pool<Smoother>* pSmootherPool) {
1288            suEq1GainOnCC.InitCCList(pCCPool, pSmootherPool);
1289            suEq2GainOnCC.InitCCList(pCCPool, pSmootherPool);
1290            suEq3GainOnCC.InitCCList(pCCPool, pSmootherPool);
1291            suEq1FreqOnCC.InitCCList(pCCPool, pSmootherPool);
1292            suEq2FreqOnCC.InitCCList(pCCPool, pSmootherPool);
1293            suEq3FreqOnCC.InitCCList(pCCPool, pSmootherPool);
1294            suEq1BwOnCC.InitCCList(pCCPool, pSmootherPool);
1295            suEq2BwOnCC.InitCCList(pCCPool, pSmootherPool);
1296            suEq3BwOnCC.InitCCList(pCCPool, pSmootherPool);
1297      }      }
1298            
1299  }} // namespace LinuxSampler::sfz  }} // namespace LinuxSampler::sfz

Legend:
Removed from v.2252  
changed lines
  Added in v.2300

  ViewVC Help
Powered by ViewVC