--- linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.cpp 2011/08/20 10:38:31 2251 +++ linuxsampler/trunk/src/engines/sfz/SfzSignalUnitRack.cpp 2016/10/31 00:05:00 3034 @@ -2,7 +2,7 @@ * * * LinuxSampler - modular, streaming capable sampler * * * - * Copyright (C) 2011 Grigor Iliev * + * Copyright (C) 2011 - 2012 Grigor Iliev * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -129,7 +129,7 @@ EGv2Unit::EGv2Unit(SfzSignalUnitRack* rack) - : EGUnit< ::LinuxSampler::sfz::EG>(rack), suAmpOnCC(rack), suVolOnCC(rack), + : EGUnit< ::LinuxSampler::sfz::EG>(rack), EqUnitSupport(rack), suAmpOnCC(rack), suVolOnCC(rack), suPitchOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack), suPanOnCC(rack) { } @@ -142,7 +142,7 @@ f = GetInfluence(egInfo.node[i].time_oncc); egInfo.node[i].time = std::min(egInfo.node[i].time + f, 100.0f); } - EG.trigger(egInfo, GetSampleRate(), pVoice->MIDIVelocity); + EG.trigger(egInfo, GetSampleRate(), pVoice->MIDIVelocity()); } @@ -151,7 +151,7 @@ depth = pRegion->pitcheg_depth + GetInfluence(pRegion->pitcheg_depth_oncc); // the length of the decay and release curves are dependent on the velocity - const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); + const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); // set the delay trigger float delay = pRegion->pitcheg_delay + pRegion->pitcheg_vel2delay * velrelease; @@ -177,7 +177,7 @@ EG.trigger ( uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, - uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() + uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), true ); } @@ -187,7 +187,7 @@ depth = pRegion->fileg_depth + GetInfluence(pRegion->fileg_depth_oncc); // the length of the decay and release curves are dependent on the velocity - const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); + const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); // set the delay trigger float delay = pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease; @@ -213,7 +213,7 @@ EG.trigger ( uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, - uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() + uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), true ); } @@ -222,7 +222,7 @@ ::sfz::Region* const pRegion = pVoice->pRegion; // the length of the decay and release curves are dependent on the velocity - const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); + const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); // set the delay trigger float delay = pRegion->ampeg_delay + pRegion->ampeg_vel2delay * velrelease; @@ -248,20 +248,20 @@ EG.trigger ( uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, - uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() + uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), false ); } LFOUnit::LFOUnit(SfzSignalUnitRack* rack) : SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL), - suFadeEG(rack), suFreqOnCC(rack, this), suDepthOnCC(rack) + suFadeEG(rack), suDepthOnCC(rack), suFreqOnCC(rack, this) { } LFOUnit::LFOUnit(const LFOUnit& Unit) : SfzSignalUnit(Unit), suFadeEG(static_cast(Unit.pRack)), - suFreqOnCC(static_cast(Unit.pRack), this), - suDepthOnCC(static_cast(Unit.pRack)) + suDepthOnCC(static_cast(Unit.pRack)), + suFreqOnCC(static_cast(Unit.pRack), this) { Copy(Unit); } @@ -287,7 +287,7 @@ if (f != 0) { suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); - suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); + suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate(), false); } } } @@ -311,7 +311,7 @@ LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) - : 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), lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), suVolOnCC(rack), suPitchOnCC(rack), suPanOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack) { @@ -399,7 +399,14 @@ RTList::Iterator end = pCtrls->end(); for(; ctrl != end; ++ctrl) { (*ctrl).Value = pVoice->GetControllerValue((*ctrl).Controller); - if ((*ctrl).pSmoother != NULL) (*ctrl).pSmoother->setValue((*ctrl).Value); + if ((*ctrl).pSmoother != NULL) { + if ((*ctrl).Step > 0) { + float val = Normalize((*ctrl).Value, (*ctrl).Curve) * (*ctrl).Influence; + (*ctrl).pSmoother->setValue( ((int) (val / (*ctrl).Step)) * (*ctrl).Step ); + } else { + (*ctrl).pSmoother->setValue((*ctrl).Value); + } + } } CCSignalUnit::Trigger(); } @@ -411,19 +418,26 @@ } } + void CCUnit::SetCCs(::sfz::Array& cc) { + RemoveAllCCs(); + for (int i = 0; i < 128; i++) { + if (cc[i] != 0) AddCC(i, cc[i]); + } + } + void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { RemoveAllCCs(); for (int i = 0; i < cc.size(); i++) { if (cc[i].Influence != 0) { short int curve = cc[i].Curve; if (curve >= GetCurveCount()) curve = -1; - 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); } } } - void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { - AddCC(Controller, Influence, Curve); + void CCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth, float Step) { + AddCC(Controller, Influence, Curve, NULL, Step); } int CCUnit::GetCurveCount() { @@ -443,7 +457,7 @@ if (pSmoothers != NULL) delete pSmoothers; } - 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) { if (Smooth > 0) { if (pSmoothers->poolIsEmpty()) { std::cerr << "Maximum number of smoothers reached" << std::endl; @@ -451,9 +465,9 @@ } Smoother* smoother = &(*(pSmoothers->allocAppend())); smoother->trigger(Smooth / 1000.0f, GetSampleRate()); - AddCC(Controller, Influence, Curve, smoother); + AddCC(Controller, Influence, Curve, smoother, Step); } else { - AddCC(Controller, Influence, Curve); + AddCC(Controller, Influence, Curve, NULL, Step); } } @@ -469,25 +483,60 @@ EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) - : EndpointSignalUnit(rack), suXFInCC(rack), suXFOutCC(rack), suPanOnCC(rack), pitchVeltrackRatio(0) + : EndpointSignalUnit(rack), pitchVeltrackRatio(0), suXFInCC(rack), suXFOutCC(rack), suPanOnCC(rack) { } + float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional >& cc) { + float f = 0; + for (int i = 0; i < 128; i++) { + if (cc[i]) { + f += (pVoice->GetControllerValue(i) / 127.0f) * (*cc[i]); + } + } + return f; + } + + float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional >& cc) { + float f = 0; + for (int i = 0; i < 128; i++) { + if (cc[i]) { + f += (pVoice->GetControllerValue(i) / 127.0f) * (*cc[i]); + } + } + return f; + } + SfzSignalUnitRack* const EndpointUnit::GetRack() { return static_cast(pRack); } void EndpointUnit::Trigger() { + uiDelayTrigger = (uint)GetInfluence(pVoice->pRegion->delay_samples_oncc); + if (pVoice->pRegion->delay_samples) uiDelayTrigger += *pVoice->pRegion->delay_samples; + + if (pVoice->pRegion->delay) { + /* here we use the device sample rate */ + uiDelayTrigger += (uint)( (*pVoice->pRegion->delay) * pVoice->GetSampleRate() ); + } + + if (pVoice->pRegion->delay_random) { + float r = pVoice->GetEngine()->Random(); + uiDelayTrigger += (uint)( r * (*pVoice->pRegion->delay_random) * pVoice->GetSampleRate() ); + } + + uiDelayTrigger += (uint)(GetInfluence(pVoice->pRegion->delay_oncc) * pVoice->GetSampleRate()); + float xfInVelCoeff = 1; - if (pVoice->MIDIVelocity <= pVoice->pRegion->xfin_lovel) { + if (pVoice->MIDIVelocity() <= pVoice->pRegion->xfin_lovel) { xfInVelCoeff = 0; - } else if (pVoice->MIDIVelocity >= pVoice->pRegion->xfin_hivel) { + } else if (pVoice->MIDIVelocity() >= pVoice->pRegion->xfin_hivel) { xfInVelCoeff = 1; } else { float xfVelSize = pVoice->pRegion->xfin_hivel - pVoice->pRegion->xfin_lovel; - float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfin_lovel; + float velPos = pVoice->MIDIVelocity() - pVoice->pRegion->xfin_lovel; xfInVelCoeff = velPos / xfVelSize; if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { xfInVelCoeff = sin(xfInVelCoeff * M_PI / 2.0); @@ -496,13 +545,13 @@ float xfOutVelCoeff = 1; - if (pVoice->MIDIVelocity >= pVoice->pRegion->xfout_hivel) { + if (pVoice->MIDIVelocity() >= pVoice->pRegion->xfout_hivel) { if (pVoice->pRegion->xfout_lovel < 127 /* is set */) xfOutVelCoeff = 0; - } else if (pVoice->MIDIVelocity <= pVoice->pRegion->xfout_lovel) { + } else if (pVoice->MIDIVelocity() <= pVoice->pRegion->xfout_lovel) { xfOutVelCoeff = 1; } else { float xfVelSize = pVoice->pRegion->xfout_hivel - pVoice->pRegion->xfout_lovel; - float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfout_lovel; + float velPos = pVoice->MIDIVelocity() - pVoice->pRegion->xfout_lovel; xfOutVelCoeff = 1.0f - velPos / xfVelSize; if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { xfOutVelCoeff = sin(xfOutVelCoeff * M_PI / 2.0); @@ -511,13 +560,13 @@ float xfInKeyCoeff = 1; - if (pVoice->MIDIKey <= pVoice->pRegion->xfin_lokey) { + if (pVoice->MIDIKey() <= pVoice->pRegion->xfin_lokey) { if (pVoice->pRegion->xfin_hikey > 0 /* is set */) xfInKeyCoeff = 0; - } else if (pVoice->MIDIKey >= pVoice->pRegion->xfin_hikey) { + } else if (pVoice->MIDIKey() >= pVoice->pRegion->xfin_hikey) { xfInKeyCoeff = 1; } else { float xfKeySize = pVoice->pRegion->xfin_hikey - pVoice->pRegion->xfin_lokey; - float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfin_lokey; + float keyPos = pVoice->MIDIKey() - pVoice->pRegion->xfin_lokey; xfInKeyCoeff = keyPos / xfKeySize; if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { xfInKeyCoeff = sin(xfInKeyCoeff * M_PI / 2.0); @@ -526,13 +575,13 @@ float xfOutKeyCoeff = 1; - if (pVoice->MIDIKey >= pVoice->pRegion->xfout_hikey) { + if (pVoice->MIDIKey() >= pVoice->pRegion->xfout_hikey) { if (pVoice->pRegion->xfout_lokey < 127 /* is set */) xfOutKeyCoeff = 0; - } else if (pVoice->MIDIKey <= pVoice->pRegion->xfout_lokey) { + } else if (pVoice->MIDIKey() <= pVoice->pRegion->xfout_lokey) { xfOutKeyCoeff = 1; } else { float xfKeySize = pVoice->pRegion->xfout_hikey - pVoice->pRegion->xfout_lokey; - float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfout_lokey; + float keyPos = pVoice->MIDIKey() - pVoice->pRegion->xfout_lokey; xfOutKeyCoeff = 1.0f - keyPos / xfKeySize; if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { xfOutKeyCoeff = sin(xfOutKeyCoeff * M_PI / 2.0); @@ -546,10 +595,14 @@ suPanOnCC.SetCCs(pVoice->pRegion->pan_oncc); - pitchVeltrackRatio = RTMath::CentsToFreqRatioUnlimited((pVoice->MIDIVelocity / 127.0f) * pVoice->pRegion->pitch_veltrack); + pitchVeltrackRatio = RTMath::CentsToFreqRatioUnlimited((pVoice->MIDIVelocity() / 127.0f) * pVoice->pRegion->pitch_veltrack); } bool EndpointUnit::Active() { + if (pRack->isReleaseStageEntered() && uiDelayTrigger) { + return false; // The key was released before the delay end, so the voice won't play at all. + } + if (GetRack()->suVolEG.Active()) return true; bool b = false; @@ -603,12 +656,12 @@ } float EndpointUnit::GetFilterCutoff() { - float val; + float val = GetRack()->suCutoffOnCC.Active() ? RTMath::CentsToFreqRatioUnlimited(GetRack()->suCutoffOnCC.GetLevel()) : 1; FilLFOUnit* u = &(GetRack()->suFilLFO); CCSignalUnit* u1 = &(GetRack()->suFilLFO.suDepthOnCC); float f = u1->Active() ? u1->GetLevel() : 0; - val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * (u->pLfoInfo->cutoff + f)) : 1; + val *= u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * (u->pLfoInfo->cutoff + f)) : 1; FilEGUnit* u2 = &(GetRack()->suFilEG); val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; @@ -635,15 +688,16 @@ } float EndpointUnit::CalculateFilterCutoff(float cutoff) { - cutoff *= GetFilterCutoff(); - float maxCutoff = 0.49 * pVoice->GetSampleRate(); - return cutoff > maxCutoff ? maxCutoff : cutoff; + cutoff *= GetFilterCutoff(); + float maxCutoff = 0.49 * pVoice->GetSampleRate(); + return cutoff > maxCutoff ? maxCutoff : cutoff; } float EndpointUnit::GetPitch() { - double p; + double p = GetRack()->suPitchOnCC.Active() ? RTMath::CentsToFreqRatioUnlimited(GetRack()->suPitchOnCC.GetLevel()) : 1; + EGv1Unit* u = &(GetRack()->suPitchEG); - p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; + p *= u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; for (int i = 0; i < GetRack()->pitchEGs.size(); i++) { EGv2Unit* eg = GetRack()->pitchEGs[i]; @@ -670,7 +724,7 @@ } float EndpointUnit::GetResonance() { - float val = 0; + float val = GetRack()->suResOnCC.Active() ? GetRack()->suResOnCC.GetLevel() : 0; for (int i = 0; i < GetRack()->resEGs.size(); i++) { EGv2Unit* eg = GetRack()->resEGs[i]; @@ -717,23 +771,26 @@ pan += lfo->GetLevel() * (lfo->pLfoInfo->pan + f); } - if(pan < -100) return -100; - if(pan > 100) return 100; - return pan; } SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) - : SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), - EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), panEGs(maxEgCount), suVolOnCC(this), + : SignalUnitRack(MaxUnitCount), EqUnitSupport(this, voice), + suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), suAmpLFO(this), suPitchLFO(this), suFilLFO(this), + suVolOnCC(this), suPitchOnCC(this), suCutoffOnCC(this), suResOnCC(this), + EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), + resEGs(maxEgCount), panEGs(maxEgCount), eqEGs(maxEgCount), LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount), - filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) + filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount), eqLFOs(maxLfoCount), + pVoice(voice) { suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice; suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; - suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = suVolOnCC.pVoice = voice; + suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; + + suVolOnCC.pVoice = suPitchOnCC.pVoice = suCutoffOnCC.pVoice = suResOnCC.pVoice = voice; suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice; suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice; suAmpLFO.suFadeEG.pVoice = suAmpLFO.suDepthOnCC.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice; @@ -747,6 +804,7 @@ EGs[i]->suCutoffOnCC.pVoice = voice; EGs[i]->suResOnCC.pVoice = voice; EGs[i]->suPanOnCC.pVoice = voice; + EGs[i]->SetVoice(voice); // class EqUnitSupport } for (int i = 0; i < LFOs.capacity(); i++) { @@ -761,6 +819,7 @@ LFOs[i]->suPanOnCC.pVoice = voice; LFOs[i]->suCutoffOnCC.pVoice = voice; LFOs[i]->suResOnCC.pVoice = voice; + LFOs[i]->SetVoice(voice); // class EqUnitSupport } } @@ -778,7 +837,12 @@ Pool* pCCPool = pVoice->pEngine->pCCPool; Pool* pSmootherPool = pVoice->pEngine->pSmootherPool; + EqUnitSupport::InitCCLists(pCCPool, pSmootherPool); + suVolOnCC.InitCCList(pCCPool, pSmootherPool); + suPitchOnCC.InitCCList(pCCPool, pSmootherPool); + suCutoffOnCC.InitCCList(pCCPool, pSmootherPool); + suResOnCC.InitCCList(pCCPool, pSmootherPool); suEndpoint.suXFInCC.InitCCList(pCCPool, pSmootherPool); suEndpoint.suXFOutCC.InitCCList(pCCPool, pSmootherPool); suEndpoint.suPanOnCC.InitCCList(pCCPool, pSmootherPool); @@ -796,6 +860,7 @@ EGs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool); EGs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool); EGs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool); + EGs[i]->InitCCLists(pCCPool, pSmootherPool); // class EqUnitSupport } for (int i = 0; i < LFOs.capacity(); i++) { @@ -807,6 +872,7 @@ LFOs[i]->suPanOnCC.InitCCList(pCCPool, pSmootherPool); LFOs[i]->suCutoffOnCC.InitCCList(pCCPool, pSmootherPool); LFOs[i]->suResOnCC.InitCCList(pCCPool, pSmootherPool); + LFOs[i]->InitCCLists(pCCPool, pSmootherPool); // class EqUnitSupport } } @@ -817,6 +883,7 @@ filEGs.clear(); resEGs.clear(); panEGs.clear(); + eqEGs.clear(); LFOs.clear(); volLFOs.clear(); @@ -824,10 +891,14 @@ filLFOs.clear(); resLFOs.clear(); panLFOs.clear(); + eqLFOs.clear(); ::sfz::Region* const pRegion = pVoice->pRegion; suVolOnCC.SetCCs(pRegion->volume_oncc); + suPitchOnCC.SetCCs(pRegion->pitch_oncc); + suCutoffOnCC.SetCCs(pRegion->cutoff_oncc); + suResOnCC.SetCCs(pRegion->resonance_oncc); for (int i = 0; i < pRegion->eg.size(); i++) { if (pRegion->eg[i].node.size() == 0) continue; @@ -842,6 +913,17 @@ EGs[EGs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->eg[i].cutoff_oncc); EGs[EGs.size() - 1]->suResOnCC.SetCCs(pRegion->eg[i].resonance_oncc); EGs[EGs.size() - 1]->suPanOnCC.SetCCs(pRegion->eg[i].pan_oncc); + if (pVoice->bEqSupport) { + EGs[EGs.size() - 1]->suEq1FreqOnCC.SetCCs(pRegion->eg[i].eq1freq_oncc); + EGs[EGs.size() - 1]->suEq2FreqOnCC.SetCCs(pRegion->eg[i].eq2freq_oncc); + EGs[EGs.size() - 1]->suEq3FreqOnCC.SetCCs(pRegion->eg[i].eq3freq_oncc); + EGs[EGs.size() - 1]->suEq1GainOnCC.SetCCs(pRegion->eg[i].eq1gain_oncc); + EGs[EGs.size() - 1]->suEq2GainOnCC.SetCCs(pRegion->eg[i].eq2gain_oncc); + EGs[EGs.size() - 1]->suEq3GainOnCC.SetCCs(pRegion->eg[i].eq3gain_oncc); + EGs[EGs.size() - 1]->suEq1BwOnCC.SetCCs(pRegion->eg[i].eq1bw_oncc); + EGs[EGs.size() - 1]->suEq2BwOnCC.SetCCs(pRegion->eg[i].eq2bw_oncc); + EGs[EGs.size() - 1]->suEq3BwOnCC.SetCCs(pRegion->eg[i].eq3bw_oncc); + } } else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; } if ( pRegion->eg[i].amplitude > 0 || !pRegion->eg[i].amplitude_oncc.empty() || @@ -870,6 +952,11 @@ if(panEGs.size() < panEGs.capacity()) panEGs.add(EGs[EGs.size() - 1]); else std::cerr << "Maximum number of EGs reached!" << std::endl; } + + if (pRegion->eg[i].HasEq()) { + if(eqEGs.size() < eqEGs.capacity()) eqEGs.add(EGs[EGs.size() - 1]); + else std::cerr << "Maximum number of EGs reached!" << std::endl; + } } if (pRegion->ampeg_sustain == -1) { @@ -894,6 +981,17 @@ LFOs[LFOs.size() - 1]->suPanOnCC.SetCCs(pRegion->lfos[i].pan_oncc); LFOs[LFOs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->lfos[i].cutoff_oncc); LFOs[LFOs.size() - 1]->suResOnCC.SetCCs(pRegion->lfos[i].resonance_oncc); + if (pVoice->bEqSupport) { + LFOs[LFOs.size() - 1]->suEq1FreqOnCC.SetCCs(pRegion->lfos[i].eq1freq_oncc); + LFOs[LFOs.size() - 1]->suEq2FreqOnCC.SetCCs(pRegion->lfos[i].eq2freq_oncc); + LFOs[LFOs.size() - 1]->suEq3FreqOnCC.SetCCs(pRegion->lfos[i].eq3freq_oncc); + LFOs[LFOs.size() - 1]->suEq1GainOnCC.SetCCs(pRegion->lfos[i].eq1gain_oncc); + LFOs[LFOs.size() - 1]->suEq2GainOnCC.SetCCs(pRegion->lfos[i].eq2gain_oncc); + LFOs[LFOs.size() - 1]->suEq3GainOnCC.SetCCs(pRegion->lfos[i].eq3gain_oncc); + LFOs[LFOs.size() - 1]->suEq1BwOnCC.SetCCs(pRegion->lfos[i].eq1bw_oncc); + LFOs[LFOs.size() - 1]->suEq2BwOnCC.SetCCs(pRegion->lfos[i].eq2bw_oncc); + LFOs[LFOs.size() - 1]->suEq3BwOnCC.SetCCs(pRegion->lfos[i].eq3bw_oncc); + } } else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } if (pRegion->lfos[i].volume != 0 || !pRegion->lfos[i].volume_oncc.empty()) { @@ -920,6 +1018,30 @@ if(panLFOs.size() < panLFOs.capacity()) panLFOs.add(LFOs[LFOs.size() - 1]); else std::cerr << "Maximum number of LFOs reached!" << std::endl; } + + if (pRegion->lfos[i].HasEq()) { + if(eqLFOs.size() < eqLFOs.capacity()) eqLFOs.add(LFOs[LFOs.size() - 1]); + else std::cerr << "Maximum number of LFOs reached!" << std::endl; + } + } + + if (!pVoice->bEqSupport) { + bHasEq = false; + } else { + suEq1GainOnCC.SetCCs(pRegion->eq1_gain_oncc); + suEq2GainOnCC.SetCCs(pRegion->eq2_gain_oncc); + suEq3GainOnCC.SetCCs(pRegion->eq3_gain_oncc); + suEq1FreqOnCC.SetCCs(pRegion->eq1_freq_oncc); + suEq2FreqOnCC.SetCCs(pRegion->eq2_freq_oncc); + suEq3FreqOnCC.SetCCs(pRegion->eq3_freq_oncc); + suEq1BwOnCC.SetCCs(pRegion->eq1_bw_oncc); + suEq2BwOnCC.SetCCs(pRegion->eq2_bw_oncc); + suEq3BwOnCC.SetCCs(pRegion->eq3_bw_oncc); + + bHasEq = pRegion->eq1_gain || pRegion->eq2_gain || pRegion->eq3_gain || + pRegion->eq1_vel2gain || pRegion->eq2_vel2gain || pRegion->eq3_vel2gain || + suEq1GainOnCC.HasCCs() || suEq2GainOnCC.HasCCs() || suEq3GainOnCC.HasCCs() || + eqEGs.size() > 0 || eqLFOs.size() > 0; } suPitchLFO.suDepthOnCC.SetCCs(pRegion->pitchlfo_depthcc); @@ -933,7 +1055,12 @@ Units.clear(); + EqUnitSupport::ImportUnits(this); + Units.add(&suVolOnCC); + Units.add(&suPitchOnCC); + Units.add(&suCutoffOnCC); + Units.add(&suResOnCC); Units.add(&suVolEG); Units.add(&suFilEG); @@ -962,6 +1089,7 @@ Units.add(&(EGs[i]->suCutoffOnCC)); Units.add(&(EGs[i]->suResOnCC)); Units.add(&(EGs[i]->suPanOnCC)); + EGs[i]->ImportUnits(this); // class EqUnitSupport } for (int i = 0; i < LFOs.size(); i++) { @@ -973,6 +1101,7 @@ Units.add(&(LFOs[i]->suPanOnCC)); Units.add(&(LFOs[i]->suCutoffOnCC)); Units.add(&(LFOs[i]->suResOnCC)); + LFOs[i]->ImportUnits(this); // class EqUnitSupport } Units.add(&suEndpoint); @@ -994,9 +1123,21 @@ volEGs[i]->EG.enterFadeOutStage(); } } - + + void SfzSignalUnitRack::EnterFadeOutStage(int maxFadeOutSteps) { + suVolEG.EG.enterFadeOutStage(maxFadeOutSteps); + for (int i = 0; i < volEGs.size(); i++) { + volEGs[i]->EG.enterFadeOutStage(maxFadeOutSteps); + } + } + void SfzSignalUnitRack::Reset() { + EqUnitSupport::ResetUnits(); + suVolOnCC.RemoveAllCCs(); + suPitchOnCC.RemoveAllCCs(); + suCutoffOnCC.RemoveAllCCs(); + suResOnCC.RemoveAllCCs(); suEndpoint.suXFInCC.RemoveAllCCs(); suEndpoint.suXFOutCC.RemoveAllCCs(); suEndpoint.suPanOnCC.RemoveAllCCs(); @@ -1014,6 +1155,7 @@ EGs[i]->suCutoffOnCC.RemoveAllCCs(); EGs[i]->suResOnCC.RemoveAllCCs(); EGs[i]->suPanOnCC.RemoveAllCCs(); + EGs[i]->ResetUnits(); // class EqUnitSupport } for (int i = 0; i < LFOs.capacity(); i++) { @@ -1025,7 +1167,145 @@ LFOs[i]->suPanOnCC.RemoveAllCCs(); LFOs[i]->suCutoffOnCC.RemoveAllCCs(); LFOs[i]->suResOnCC.RemoveAllCCs(); + LFOs[i]->ResetUnits(); // class EqUnitSupport + } + } + + void SfzSignalUnitRack::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { + suVolEG.EG.CalculateFadeOutCoeff(FadeOutTime, SampleRate); + for (int i = 0; i < EGs.capacity(); i++) { + EGs[i]->EG.CalculateFadeOutCoeff(FadeOutTime, SampleRate); + } + } + + void SfzSignalUnitRack::UpdateEqSettings(EqSupport* pEqSupport) { + if (!pEqSupport->HasSupport()) return; + if (pEqSupport->GetBandCount() < 3) { + std::cerr << "SfzSignalUnitRack::UpdateEqSettings: EQ should have at least 3 bands\n"; + return; + } + + ::sfz::Region* const pRegion = pVoice->pRegion; + + float dB1 = (suEq1GainOnCC.Active() ? suEq1GainOnCC.GetLevel() : 0) + pRegion->eq1_gain; + float dB2 = (suEq2GainOnCC.Active() ? suEq2GainOnCC.GetLevel() : 0) + pRegion->eq2_gain; + float dB3 = (suEq3GainOnCC.Active() ? suEq3GainOnCC.GetLevel() : 0) + pRegion->eq3_gain; + + float freq1 = (suEq1FreqOnCC.Active() ? suEq1FreqOnCC.GetLevel() : 0) + pRegion->eq1_freq; + float freq2 = (suEq2FreqOnCC.Active() ? suEq2FreqOnCC.GetLevel() : 0) + pRegion->eq2_freq; + float freq3 = (suEq3FreqOnCC.Active() ? suEq3FreqOnCC.GetLevel() : 0) + pRegion->eq3_freq; + + float bw1 = (suEq1BwOnCC.Active() ? suEq1BwOnCC.GetLevel() : 0) + pRegion->eq1_bw; + float bw2 = (suEq2BwOnCC.Active() ? suEq2BwOnCC.GetLevel() : 0) + pRegion->eq2_bw; + float bw3 = (suEq3BwOnCC.Active() ? suEq3BwOnCC.GetLevel() : 0) + pRegion->eq3_bw; + + const float vel = pVoice->MIDIVelocity() / 127.0f; + + dB1 += pRegion->eq1_vel2gain * vel; + dB2 += pRegion->eq2_vel2gain * vel; + dB3 += pRegion->eq3_vel2gain * vel; + + freq1 += pRegion->eq1_vel2freq * vel; + freq2 += pRegion->eq2_vel2freq * vel; + freq3 += pRegion->eq3_vel2freq * vel; + + for (int i = 0; i < eqEGs.size(); i++) { + EGv2Unit* eg = eqEGs[i]; + if (!eg->Active()) continue; + + float l = eg->GetLevel(); + dB1 += ((eg->suEq1GainOnCC.Active() ? eg->suEq1GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq1gain) * l; + dB2 += ((eg->suEq2GainOnCC.Active() ? eg->suEq2GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq2gain) * l; + dB3 += ((eg->suEq3GainOnCC.Active() ? eg->suEq3GainOnCC.GetLevel() : 0) + eg->pEGInfo->eq3gain) * l; + + freq1 += ((eg->suEq1FreqOnCC.Active() ? eg->suEq1FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq1freq) * l; + freq2 += ((eg->suEq2FreqOnCC.Active() ? eg->suEq2FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq2freq) * l; + freq3 += ((eg->suEq3FreqOnCC.Active() ? eg->suEq3FreqOnCC.GetLevel() : 0) + eg->pEGInfo->eq3freq) * l; + + bw1 += ((eg->suEq1BwOnCC.Active() ? eg->suEq1BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq1bw) * l; + bw2 += ((eg->suEq2BwOnCC.Active() ? eg->suEq2BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq2bw) * l; + bw3 += ((eg->suEq3BwOnCC.Active() ? eg->suEq3BwOnCC.GetLevel() : 0) + eg->pEGInfo->eq3bw) * l; + } + + for (int i = 0; i < eqLFOs.size(); i++) { + LFOv2Unit* lfo = eqLFOs[i]; + if (!lfo->Active()) continue; + + float l = lfo->GetLevel(); + dB1 += ((lfo->suEq1GainOnCC.Active() ? lfo->suEq1GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1gain) * l; + dB2 += ((lfo->suEq2GainOnCC.Active() ? lfo->suEq2GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2gain) * l; + dB3 += ((lfo->suEq3GainOnCC.Active() ? lfo->suEq3GainOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3gain) * l; + + freq1 += ((lfo->suEq1FreqOnCC.Active() ? lfo->suEq1FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1freq) * l; + freq2 += ((lfo->suEq2FreqOnCC.Active() ? lfo->suEq2FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2freq) * l; + freq3 += ((lfo->suEq3FreqOnCC.Active() ? lfo->suEq3FreqOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3freq) * l; + + bw1 += ((lfo->suEq1BwOnCC.Active() ? lfo->suEq1BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq1bw) * l; + bw2 += ((lfo->suEq2BwOnCC.Active() ? lfo->suEq2BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq2bw) * l; + bw3 += ((lfo->suEq3BwOnCC.Active() ? lfo->suEq3BwOnCC.GetLevel() : 0) + lfo->pLfoInfo->eq3bw) * l; } + + pEqSupport->SetGain(0, dB1); + pEqSupport->SetGain(1, dB2); + pEqSupport->SetGain(2, dB3); + + pEqSupport->SetFreq(0, freq1); + pEqSupport->SetFreq(1, freq2); + pEqSupport->SetFreq(2, freq3); + + pEqSupport->SetBandwidth(0, bw1); + pEqSupport->SetBandwidth(1, bw2); + pEqSupport->SetBandwidth(2, bw3); + } + + EqUnitSupport::EqUnitSupport(SfzSignalUnitRack* pRack, Voice* pVoice) + : suEq1GainOnCC(pRack), suEq2GainOnCC(pRack), suEq3GainOnCC(pRack), + suEq1FreqOnCC(pRack), suEq2FreqOnCC(pRack), suEq3FreqOnCC(pRack), + suEq1BwOnCC(pRack), suEq2BwOnCC(pRack), suEq3BwOnCC(pRack) + { + SetVoice(pVoice); + } + + void EqUnitSupport::SetVoice(Voice* pVoice) { + suEq1GainOnCC.pVoice = suEq2GainOnCC.pVoice = suEq3GainOnCC.pVoice = pVoice; + suEq1FreqOnCC.pVoice = suEq2FreqOnCC.pVoice = suEq3FreqOnCC.pVoice = pVoice; + suEq1BwOnCC.pVoice = suEq2BwOnCC.pVoice = suEq3BwOnCC.pVoice = pVoice; + } + + void EqUnitSupport::ImportUnits(SfzSignalUnitRack* pRack) { + if (suEq1GainOnCC.HasCCs()) pRack->Units.add(&suEq1GainOnCC); + if (suEq2GainOnCC.HasCCs()) pRack->Units.add(&suEq2GainOnCC); + if (suEq3GainOnCC.HasCCs()) pRack->Units.add(&suEq3GainOnCC); + if (suEq1FreqOnCC.HasCCs()) pRack->Units.add(&suEq1FreqOnCC); + if (suEq2FreqOnCC.HasCCs()) pRack->Units.add(&suEq2FreqOnCC); + if (suEq3FreqOnCC.HasCCs()) pRack->Units.add(&suEq3FreqOnCC); + if (suEq1BwOnCC.HasCCs()) pRack->Units.add(&suEq1BwOnCC); + if (suEq2BwOnCC.HasCCs()) pRack->Units.add(&suEq2BwOnCC); + if (suEq3BwOnCC.HasCCs()) pRack->Units.add(&suEq3BwOnCC); + } + + void EqUnitSupport::ResetUnits() { + suEq1GainOnCC.RemoveAllCCs(); + suEq2GainOnCC.RemoveAllCCs(); + suEq3GainOnCC.RemoveAllCCs(); + suEq1FreqOnCC.RemoveAllCCs(); + suEq2FreqOnCC.RemoveAllCCs(); + suEq3FreqOnCC.RemoveAllCCs(); + suEq1BwOnCC.RemoveAllCCs(); + suEq2BwOnCC.RemoveAllCCs(); + suEq3BwOnCC.RemoveAllCCs(); + } + + void EqUnitSupport::InitCCLists(Pool* pCCPool, Pool* pSmootherPool) { + suEq1GainOnCC.InitCCList(pCCPool, pSmootherPool); + suEq2GainOnCC.InitCCList(pCCPool, pSmootherPool); + suEq3GainOnCC.InitCCList(pCCPool, pSmootherPool); + suEq1FreqOnCC.InitCCList(pCCPool, pSmootherPool); + suEq2FreqOnCC.InitCCList(pCCPool, pSmootherPool); + suEq3FreqOnCC.InitCCList(pCCPool, pSmootherPool); + suEq1BwOnCC.InitCCList(pCCPool, pSmootherPool); + suEq2BwOnCC.InitCCList(pCCPool, pSmootherPool); + suEq3BwOnCC.InitCCList(pCCPool, pSmootherPool); } }} // namespace LinuxSampler::sfz