diff --git a/modules/juce_audio_basics/utilities/juce_LinearSmoothedValue.h b/modules/juce_audio_basics/utilities/juce_LinearSmoothedValue.h index e6f8806cfd..5eaa2e5203 100644 --- a/modules/juce_audio_basics/utilities/juce_LinearSmoothedValue.h +++ b/modules/juce_audio_basics/utilities/juce_LinearSmoothedValue.h @@ -60,7 +60,7 @@ public: void reset (int numSteps) noexcept { stepsToTarget = numSteps; - setCurrentValueToTargetValue(); + setCurrentAndTargetValue (target); } /** Set the next value to ramp towards. @@ -75,7 +75,7 @@ public: if (stepsToTarget <= 0) { - setCurrentValueToTargetValue(); + setCurrentAndTargetValue (target); return; } @@ -83,10 +83,12 @@ public: step = (target - currentValue) / static_cast (countdown); } - /** Sets the current value to the target value. */ - void setCurrentValueToTargetValue() noexcept + /** Sets the current value and the target value. + @param newValue the new value to take + */ + void setCurrentAndTargetValue (FloatType newValue) { - currentValue = target; + target = currentValue = newValue; countdown = 0; } @@ -198,7 +200,7 @@ public: { if (numSamples >= countdown) { - setCurrentValueToTargetValue(); + setCurrentAndTargetValue (target); return target; } @@ -210,20 +212,24 @@ public: //============================================================================== /** THIS FUNCTION IS DEPRECATED. - Use `setTargetValue (float)` and `setCurrentValueToTargetValue()` instead: + Use `setTargetValue (float)` and `setCurrentAndTargetValue()` instead: lsv.setValue (x, false); -> lsv.setTargetValue (x); - lsv.setValue (x, true); -> lsv.setTargetValue (x); lsv.setCurrentValueToTargetValue(); + lsv.setValue (x, true); -> lsv.setCurrentAndTargetValue (x); @param newValue The new target value @param force If true, the value will be set immediately, bypassing the ramp */ JUCE_DEPRECATED_WITH_BODY (void setValue (FloatType newValue, bool force = false) noexcept, { - setTargetValue (newValue); - if (force) - setCurrentValueToTargetValue(); + { + target = newValue; + setCurrentAndTargetValue (target); + return; + } + + setTargetValue (newValue); }) private: diff --git a/modules/juce_dsp/processors/juce_LadderFilter.cpp b/modules/juce_dsp/processors/juce_LadderFilter.cpp index 05c43e8e5c..9829ba8ea3 100644 --- a/modules/juce_dsp/processors/juce_LadderFilter.cpp +++ b/modules/juce_dsp/processors/juce_LadderFilter.cpp @@ -78,8 +78,8 @@ void LadderFilter::reset() noexcept for (auto& s : state) s.fill (Type (0)); - cutoffTransformSmoother.setCurrentValueToTargetValue(); - scaledResonanceSmoother.setCurrentValueToTargetValue(); + cutoffTransformSmoother.setCurrentAndTargetValue (cutoffTransformSmoother.getTargetValue()); + scaledResonanceSmoother.setCurrentAndTargetValue (scaledResonanceSmoother.getTargetValue()); } //============================================================================== diff --git a/modules/juce_dsp/processors/juce_Oscillator.h b/modules/juce_dsp/processors/juce_Oscillator.h index 4048836f5e..0c41ee8997 100644 --- a/modules/juce_dsp/processors/juce_Oscillator.h +++ b/modules/juce_dsp/processors/juce_Oscillator.h @@ -84,10 +84,13 @@ public: /** Sets the frequency of the oscillator. */ void setFrequency (NumericType newFrequency, bool force = false) noexcept { - frequency.setTargetValue (newFrequency); - if (force) - frequency.setCurrentValueToTargetValue(); + { + frequency.setCurrentAndTargetValue (newFrequency); + return; + } + + frequency.setTargetValue (newFrequency); } /** Returns the current frequency of the oscillator. */