LMMS
Loading...
Searching...
No Matches
juce::SmoothedValue< FloatType, SmoothingType > Class Template Reference

#include <juce_SmoothedValue.h>

Inheritance diagram for juce::SmoothedValue< FloatType, SmoothingType >:
juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >

Public Member Functions

 SmoothedValue () noexcept
 SmoothedValue (FloatType initialValue) noexcept
void reset (double sampleRate, double rampLengthInSeconds) noexcept
void reset (int numSteps) noexcept
void setTargetValue (FloatType newValue) noexcept
FloatType getNextValue () noexcept
FloatType skip (int numSamples) noexcept
void setValue (FloatType newValue, bool force=false) noexcept
Public Member Functions inherited from juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >
 SmoothedValueBase ()=default
bool isSmoothing () const noexcept
FloatType getCurrentValue () const noexcept
FloatType getTargetValue () const noexcept
void setCurrentAndTargetValue (FloatType newValue)
void applyGain (FloatType *samples, int numSamples) noexcept

Private Types

template<typename T>
using LinearVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Linear>::value, void>::type
template<typename T>
using MultiplicativeVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Multiplicative>::value, void>::type

Private Member Functions

template<typename T = SmoothingType>
LinearVoid< T > setStepSize () noexcept
template<typename T = SmoothingType>
MultiplicativeVoid< T > setStepSize ()
template<typename T = SmoothingType>
LinearVoid< T > setNextValue () noexcept
template<typename T = SmoothingType>
MultiplicativeVoid< T > setNextValue () noexcept
template<typename T = SmoothingType>
LinearVoid< T > skipCurrentValue (int numSamples) noexcept
template<typename T = SmoothingType>
MultiplicativeVoid< T > skipCurrentValue (int numSamples)

Private Attributes

FloatType step = FloatType()
int stepsToTarget = 0

Additional Inherited Members

Public Types inherited from juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >
using FloatType
Protected Attributes inherited from juce::SmoothedValueBase< SmoothedValue< FloatType, ValueSmoothingTypes::Linear > >
FloatType currentValue
FloatType target
int countdown

Detailed Description

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
class juce::SmoothedValue< FloatType, SmoothingType >

A utility class for values that need smoothing to avoid audio glitches.

A ValueSmoothingTypes::Linear template parameter selects linear smoothing, which increments the SmoothedValue linearly towards its target value.

SmoothedValue() noexcept
Definition juce_SmoothedValue.h:231

A ValueSmoothingTypes::Multiplicative template parameter selects multiplicative smoothing increments towards the target value.

Multiplicative smoothing is useful when you are dealing with exponential/logarithmic values like volume in dB or frequency in Hz. For example a 12 step ramp from 440.0 Hz (A4) to 880.0 Hz (A5) will increase the frequency with an equal temperament tuning across the octave. A 10 step smoothing from 1.0 (0 dB) to 3.16228 (10 dB) will increase the value in increments of 1 dB.

Note that when you are using multiplicative smoothing you cannot ever reach a target value of zero!

@tags{Audio}

Member Typedef Documentation

◆ LinearVoid

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T>
using juce::SmoothedValue< FloatType, SmoothingType >::LinearVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Linear>::value, void>::type
private

◆ MultiplicativeVoid

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T>
using juce::SmoothedValue< FloatType, SmoothingType >::MultiplicativeVoid = typename std::enable_if <std::is_same <T, ValueSmoothingTypes::Multiplicative>::value, void>::type
private

Constructor & Destructor Documentation

◆ SmoothedValue() [1/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue ( )
inlinenoexcept

Constructor.

◆ SmoothedValue() [2/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
juce::SmoothedValue< FloatType, SmoothingType >::SmoothedValue ( FloatType initialValue)
inlinenoexcept

Constructor.

Member Function Documentation

◆ getNextValue()

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
FloatType juce::SmoothedValue< FloatType, SmoothingType >::getNextValue ( )
inlinenoexcept

Compute the next value.

Returns
Smoothed value

◆ reset() [1/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::reset ( double sampleRate,
double rampLengthInSeconds )
inlinenoexcept

Reset to a new sample rate and ramp length.

Parameters
sampleRateThe sample rate
rampLengthInSecondsThe duration of the ramp in seconds

◆ reset() [2/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::reset ( int numSteps)
inlinenoexcept

Set a new ramp length directly in samples.

Parameters
numStepsThe number of samples over which the ramp should be active

◆ setNextValue() [1/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::setNextValue ( )
inlineprivatenoexcept

◆ setNextValue() [2/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::setNextValue ( )
inlineprivatenoexcept

◆ setStepSize() [1/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::setStepSize ( )
inlineprivate

◆ setStepSize() [2/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::setStepSize ( )
inlineprivatenoexcept

◆ setTargetValue()

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::setTargetValue ( FloatType newValue)
inlinenoexcept

Set the next value to ramp towards.

Parameters
newValueThe new target value

◆ setValue()

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
void juce::SmoothedValue< FloatType, SmoothingType >::setValue ( FloatType newValue,
bool force = false )
inlinenoexcept

Using the new methods:

lsv.setValue (x, false); -> lsv.setTargetValue (x); lsv.setValue (x, true); -> lsv.setCurrentAndTargetValue (x);

Parameters
newValueThe new target value
forceIf true, the value will be set immediately, bypassing the ramp

◆ skip()

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
FloatType juce::SmoothedValue< FloatType, SmoothingType >::skip ( int numSamples)
inlinenoexcept

Skip the next numSamples samples. This is identical to calling getNextValue numSamples times. It returns the new current value.

See also
getNextValue

◆ skipCurrentValue() [1/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
MultiplicativeVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue ( int numSamples)
inlineprivate

◆ skipCurrentValue() [2/2]

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
template<typename T = SmoothingType>
LinearVoid< T > juce::SmoothedValue< FloatType, SmoothingType >::skipCurrentValue ( int numSamples)
inlineprivatenoexcept

Member Data Documentation

◆ step

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
FloatType juce::SmoothedValue< FloatType, SmoothingType >::step = FloatType()
private

◆ stepsToTarget

template<typename FloatType, typename SmoothingType = ValueSmoothingTypes::Linear>
int juce::SmoothedValue< FloatType, SmoothingType >::stepsToTarget = 0
private

The documentation for this class was generated from the following file: