/[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 2251 by iliev, Sat Aug 20 10:38:31 2011 UTC revision 2296 by iliev, Thu Dec 8 20:03:47 2011 UTC
# 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 603  namespace LinuxSampler { namespace sfz { Line 617  namespace LinuxSampler { namespace sfz {
617      }      }
618            
619      float EndpointUnit::GetFilterCutoff() {      float EndpointUnit::GetFilterCutoff() {
620          float val;          float val = GetRack()->suCutoffOnCC.Active() ? RTMath::CentsToFreqRatioUnlimited(GetRack()->suCutoffOnCC.GetLevel()) : 1;
621                    
622          FilLFOUnit* u = &(GetRack()->suFilLFO);          FilLFOUnit* u = &(GetRack()->suFilLFO);
623          CCSignalUnit* u1 = &(GetRack()->suFilLFO.suDepthOnCC);          CCSignalUnit* u1 = &(GetRack()->suFilLFO.suDepthOnCC);
624          float f = u1->Active() ? u1->GetLevel() : 0;          float f = u1->Active() ? u1->GetLevel() : 0;
625          val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * (u->pLfoInfo->cutoff + f)) : 1;          val *= u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * (u->pLfoInfo->cutoff + f)) : 1;
626                    
627          FilEGUnit* u2 = &(GetRack()->suFilEG);          FilEGUnit* u2 = &(GetRack()->suFilEG);
628          val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1;          val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1;
# Line 635  namespace LinuxSampler { namespace sfz { Line 649  namespace LinuxSampler { namespace sfz {
649      }      }
650            
651      float EndpointUnit::CalculateFilterCutoff(float cutoff) {      float EndpointUnit::CalculateFilterCutoff(float cutoff) {
652           cutoff *= GetFilterCutoff();          cutoff *= GetFilterCutoff();
653           float maxCutoff = 0.49 * pVoice->GetSampleRate();          float maxCutoff = 0.49 * pVoice->GetSampleRate();
654           return cutoff > maxCutoff ? maxCutoff : cutoff;          return cutoff > maxCutoff ? maxCutoff : cutoff;
655      }      }
656            
657      float EndpointUnit::GetPitch() {      float EndpointUnit::GetPitch() {
658          double p;          double p = GetRack()->suPitchOnCC.Active() ? RTMath::CentsToFreqRatioUnlimited(GetRack()->suPitchOnCC.GetLevel()) : 1;
659            
660          EGv1Unit* u = &(GetRack()->suPitchEG);          EGv1Unit* u = &(GetRack()->suPitchEG);
661          p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1;          p *= u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1;
662                    
663          for (int i = 0; i < GetRack()->pitchEGs.size(); i++) {          for (int i = 0; i < GetRack()->pitchEGs.size(); i++) {
664              EGv2Unit* eg = GetRack()->pitchEGs[i];              EGv2Unit* eg = GetRack()->pitchEGs[i];
# Line 670  namespace LinuxSampler { namespace sfz { Line 685  namespace LinuxSampler { namespace sfz {
685      }      }
686            
687      float EndpointUnit::GetResonance() {      float EndpointUnit::GetResonance() {
688           float val = 0;           float val = GetRack()->suResOnCC.Active() ? GetRack()->suResOnCC.GetLevel() : 0;
689                    
690          for (int i = 0; i < GetRack()->resEGs.size(); i++) {          for (int i = 0; i < GetRack()->resEGs.size(); i++) {
691              EGv2Unit* eg = GetRack()->resEGs[i];              EGv2Unit* eg = GetRack()->resEGs[i];
# Line 726  namespace LinuxSampler { namespace sfz { Line 741  namespace LinuxSampler { namespace sfz {
741            
742      SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice)      SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice)
743          : SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this),          : SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this),
744          EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), panEGs(maxEgCount), suVolOnCC(this),          EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), panEGs(maxEgCount),
745            suEq1GainOnCC(this), suEq2GainOnCC(this), suEq3GainOnCC(this),
746            suEq1FreqOnCC(this), suEq2FreqOnCC(this), suEq3FreqOnCC(this),
747            suEq1BwOnCC(this), suEq2BwOnCC(this), suEq3BwOnCC(this),
748            suVolOnCC(this), suPitchOnCC(this), suCutoffOnCC(this), suResOnCC(this),
749          suAmpLFO(this), suPitchLFO(this), suFilLFO(this),          suAmpLFO(this), suPitchLFO(this), suFilLFO(this),
750          LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount),          LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount),
751          filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount)          filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount)
752      {      {
753          suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice;          suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice;
754          suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice;          suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice;
755          suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = suVolOnCC.pVoice = voice;          suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice;
756            
757            suEq1GainOnCC.pVoice = suEq2GainOnCC.pVoice = suEq3GainOnCC.pVoice = voice;
758            suEq1FreqOnCC.pVoice = suEq2FreqOnCC.pVoice = suEq3FreqOnCC.pVoice = voice;
759            suEq1BwOnCC.pVoice = suEq2BwOnCC.pVoice = suEq3BwOnCC.pVoice = voice;
760            
761            suVolOnCC.pVoice = suPitchOnCC.pVoice = suCutoffOnCC.pVoice = suResOnCC.pVoice = voice;
762          suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice;          suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice;
763          suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice;          suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice;
764          suAmpLFO.suFadeEG.pVoice = suAmpLFO.suDepthOnCC.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice;          suAmpLFO.suFadeEG.pVoice = suAmpLFO.suDepthOnCC.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice;
# Line 778  namespace LinuxSampler { namespace sfz { Line 803  namespace LinuxSampler { namespace sfz {
803          Pool<CCSignalUnit::CC>* pCCPool = pVoice->pEngine->pCCPool;          Pool<CCSignalUnit::CC>* pCCPool = pVoice->pEngine->pCCPool;
804          Pool<Smoother>* pSmootherPool = pVoice->pEngine->pSmootherPool;          Pool<Smoother>* pSmootherPool = pVoice->pEngine->pSmootherPool;
805                    
806            suEq1GainOnCC.InitCCList(pCCPool, pSmootherPool);
807            suEq2GainOnCC.InitCCList(pCCPool, pSmootherPool);
808            suEq3GainOnCC.InitCCList(pCCPool, pSmootherPool);
809            suEq1FreqOnCC.InitCCList(pCCPool, pSmootherPool);
810            suEq2FreqOnCC.InitCCList(pCCPool, pSmootherPool);
811            suEq3FreqOnCC.InitCCList(pCCPool, pSmootherPool);
812            suEq1BwOnCC.InitCCList(pCCPool, pSmootherPool);
813            suEq2BwOnCC.InitCCList(pCCPool, pSmootherPool);
814            suEq3BwOnCC.InitCCList(pCCPool, pSmootherPool);
815            
816          suVolOnCC.InitCCList(pCCPool, pSmootherPool);          suVolOnCC.InitCCList(pCCPool, pSmootherPool);
817            suPitchOnCC.InitCCList(pCCPool, pSmootherPool);
818            suCutoffOnCC.InitCCList(pCCPool, pSmootherPool);
819            suResOnCC.InitCCList(pCCPool, pSmootherPool);
820          suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool);          suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool);
821          suEndpoint.suXFOutCC.InitCCList(pCCPool, pSmootherPool);          suEndpoint.suXFOutCC.InitCCList(pCCPool, pSmootherPool);
822          suEndpoint.suPanOnCC.InitCCList(pCCPool, pSmootherPool);          suEndpoint.suPanOnCC.InitCCList(pCCPool, pSmootherPool);
# Line 827  namespace LinuxSampler { namespace sfz { Line 865  namespace LinuxSampler { namespace sfz {
865                    
866          ::sfz::Region* const pRegion = pVoice->pRegion;          ::sfz::Region* const pRegion = pVoice->pRegion;
867                    
868            suEq1GainOnCC.SetCCs(pRegion->eq1_gain_oncc);
869            suEq2GainOnCC.SetCCs(pRegion->eq2_gain_oncc);
870            suEq3GainOnCC.SetCCs(pRegion->eq3_gain_oncc);
871            suEq1FreqOnCC.SetCCs(pRegion->eq1_freq_oncc);
872            suEq2FreqOnCC.SetCCs(pRegion->eq2_freq_oncc);
873            suEq3FreqOnCC.SetCCs(pRegion->eq3_freq_oncc);
874            suEq1BwOnCC.SetCCs(pRegion->eq1_bw_oncc);
875            suEq2BwOnCC.SetCCs(pRegion->eq2_bw_oncc);
876            suEq3BwOnCC.SetCCs(pRegion->eq3_bw_oncc);
877            
878            bHasEq = pRegion->eq1_gain || pRegion->eq2_gain || pRegion->eq3_gain ||
879                     suEq1GainOnCC.HasCCs() || suEq2GainOnCC.HasCCs() || suEq3GainOnCC.HasCCs();
880            
881          suVolOnCC.SetCCs(pRegion->volume_oncc);          suVolOnCC.SetCCs(pRegion->volume_oncc);
882            suPitchOnCC.SetCCs(pRegion->pitch_oncc);
883            suCutoffOnCC.SetCCs(pRegion->cutoff_oncc);
884            suResOnCC.SetCCs(pRegion->resonance_oncc);
885                    
886          for (int i = 0; i < pRegion->eg.size(); i++) {          for (int i = 0; i < pRegion->eg.size(); i++) {
887              if (pRegion->eg[i].node.size() == 0) continue;              if (pRegion->eg[i].node.size() == 0) continue;
# Line 933  namespace LinuxSampler { namespace sfz { Line 987  namespace LinuxSampler { namespace sfz {
987                    
988          Units.clear();          Units.clear();
989                    
990            Units.add(&suEq1GainOnCC);
991            Units.add(&suEq2GainOnCC);
992            Units.add(&suEq3GainOnCC);
993            Units.add(&suEq1FreqOnCC);
994            Units.add(&suEq2FreqOnCC);
995            Units.add(&suEq3FreqOnCC);
996            Units.add(&suEq1BwOnCC);
997            Units.add(&suEq2BwOnCC);
998            Units.add(&suEq3BwOnCC);
999            
1000          Units.add(&suVolOnCC);          Units.add(&suVolOnCC);
1001            Units.add(&suPitchOnCC);
1002            Units.add(&suCutoffOnCC);
1003            Units.add(&suResOnCC);
1004                    
1005          Units.add(&suVolEG);          Units.add(&suVolEG);
1006          Units.add(&suFilEG);          Units.add(&suFilEG);
# Line 996  namespace LinuxSampler { namespace sfz { Line 1063  namespace LinuxSampler { namespace sfz {
1063      }      }
1064            
1065      void SfzSignalUnitRack::Reset() {      void SfzSignalUnitRack::Reset() {
1066            suEq1GainOnCC.RemoveAllCCs();
1067            suEq2GainOnCC.RemoveAllCCs();
1068            suEq3GainOnCC.RemoveAllCCs();
1069            suEq1FreqOnCC.RemoveAllCCs();
1070            suEq2FreqOnCC.RemoveAllCCs();
1071            suEq3FreqOnCC.RemoveAllCCs();
1072            suEq1BwOnCC.RemoveAllCCs();
1073            suEq2BwOnCC.RemoveAllCCs();
1074            suEq3BwOnCC.RemoveAllCCs();
1075            
1076          suVolOnCC.RemoveAllCCs();          suVolOnCC.RemoveAllCCs();
1077            suPitchOnCC.RemoveAllCCs();
1078            suCutoffOnCC.RemoveAllCCs();
1079            suResOnCC.RemoveAllCCs();
1080          suEndpoint.suXFInCC.RemoveAllCCs();          suEndpoint.suXFInCC.RemoveAllCCs();
1081          suEndpoint.suXFOutCC.RemoveAllCCs();          suEndpoint.suXFOutCC.RemoveAllCCs();
1082          suEndpoint.suPanOnCC.RemoveAllCCs();          suEndpoint.suPanOnCC.RemoveAllCCs();
# Line 1028  namespace LinuxSampler { namespace sfz { Line 1108  namespace LinuxSampler { namespace sfz {
1108          }          }
1109      }      }
1110            
1111        void SfzSignalUnitRack::UpdateEqSettings(EqSupport* pEqSupport) {
1112            if (!pEqSupport->HasSupport()) return;
1113            if (pEqSupport->GetBandCount() < 3) {
1114                std::cerr << "SfzSignalUnitRack::UpdateEqSettings: EQ should have at least 3 bands\n";
1115                return;
1116            }
1117            
1118            ::sfz::Region* const pRegion = pVoice->pRegion;
1119            
1120            float dB = (suEq1GainOnCC.Active() ? suEq1GainOnCC.GetLevel() : 0) + pRegion->eq1_gain;
1121            pEqSupport->SetGain(0, dB);
1122            
1123            dB = (suEq2GainOnCC.Active() ? suEq2GainOnCC.GetLevel() : 0) + pRegion->eq2_gain;
1124            pEqSupport->SetGain(1, dB);
1125            
1126            dB = (suEq3GainOnCC.Active() ? suEq3GainOnCC.GetLevel() : 0) + pRegion->eq3_gain;
1127            pEqSupport->SetGain(2, dB);
1128            
1129            float freq = (suEq1FreqOnCC.Active() ? suEq1FreqOnCC.GetLevel() : 0) + pRegion->eq1_freq;
1130            pEqSupport->SetFreq(0, freq);
1131            
1132            freq = (suEq2FreqOnCC.Active() ? suEq2FreqOnCC.GetLevel() : 0) + pRegion->eq2_freq;
1133            pEqSupport->SetFreq(1, freq);
1134            
1135            freq = (suEq3FreqOnCC.Active() ? suEq3FreqOnCC.GetLevel() : 0) + pRegion->eq3_freq;
1136            pEqSupport->SetFreq(2, freq);
1137            
1138            float bw = (suEq1BwOnCC.Active() ? suEq1BwOnCC.GetLevel() : 0) + pRegion->eq1_bw;
1139            pEqSupport->SetBandwidth(0, bw);
1140            
1141            bw = (suEq2BwOnCC.Active() ? suEq2BwOnCC.GetLevel() : 0) + pRegion->eq2_bw;
1142            pEqSupport->SetBandwidth(1, bw);
1143            
1144            bw = (suEq3BwOnCC.Active() ? suEq3BwOnCC.GetLevel() : 0) + pRegion->eq3_bw;
1145            pEqSupport->SetBandwidth(2, bw);
1146        }
1147        
1148  }} // namespace LinuxSampler::sfz  }} // namespace LinuxSampler::sfz

Legend:
Removed from v.2251  
changed lines
  Added in v.2296

  ViewVC Help
Powered by ViewVC