1 #ifndef __SmoothValue_h__
2 #define __SmoothValue_h__
14 template<
typename T,
typename Value = SimpleValue<T>>
30 update(Value::get() + other);
34 update(Value::get() - other);
38 update(Value::get() * other);
42 update(Value::get() / other);
60 template<
typename T,
typename Value = SimpleValue<T>>
63 T delta = Value::DEFAULT_DELTA;
66 StiffValue(T delta, T init) : Value(init), delta(delta) {}
69 if(
abs(Value::get() - newValue) > delta)
70 Value::update(newValue);
77 update(Value::get() + other);
81 update(Value::get() - other);
85 update(Value::get() * other);
89 update(Value::get() / other);
112 template<
typename T,
typename Value = SimpleValue<T>>
126 scale = maximum - minimum;
130 void setRange(T from_lo, T from_hi, T to_lo, T to_hi){
133 scale = (to_hi - to_lo) / (from_hi - from_lo);
152 update(Value::get() + other);
156 update(Value::get() - other);
160 update(Value::get() * other);
164 update(Value::get() / other);
186 template<
typename T,
typename Value = SimpleValue<T>>
189 T c = Value::DEFAULT_EXP_C;
190 T k = Value::DEFAULT_EXP_K;
197 setRange(minimum, maximum);
200 ASSERT(minimum > 0 && maximum > 0,
"Exponential min/max must be greater than 0");
202 k = logf(maximum/minimum);
208 return logf(Value::get()/c)/k;
211 Value::update(c * expf(k * x));
221 update(Value::get() + other);
225 update(Value::get() - other);
229 update(Value::get() * other);
233 update(Value::get() / other);
252 template<
typename T,
typename Value = SimpleValue<T>>
255 T c = Value::DEFAULT_LOG_C;
256 T k = Value::DEFAULT_LOG_K;
270 Value::update(logf(k * x + c));
273 return (expf(Value::get()) - c) / k;
285 update(Value::get() + other);
289 update(Value::get() - other);
293 update(Value::get() * other);
297 update(Value::get() / other);
SmoothValue< float > SmoothFloat
LinearValue< float > LinearFloat
SmoothValue< float, LinearFloat > SmoothLinearFloat
SmoothValue< int, StiffInt > SmoothStiffInt
ExponentialValue< float > ExponentialFloat
LogarithmicValue< float > LogarithmicFloat
LinearValue< int > LinearInt
SmoothValue< int, ExponentialInt > SmoothExponentialInt
ExponentialValue< int > ExponentialInt
SmoothValue< int > SmoothInt
StiffValue< int > StiffInt
LogarithmicValue< int > LogarithmicInt
SmoothValue< float, StiffFloat > SmoothStiffFloat
SmoothValue< float, ExponentialFloat > SmoothExponentialFloat
SmoothValue< int, LinearInt > SmoothLinearInt
StiffValue< float > StiffFloat
Exponentially scaled value.
ExponentialValue< T, Value > & operator-=(const T &other)
void setRange(T minimum, T maximum)
ExponentialValue< T, Value > & operator/=(const T &other)
ExponentialValue(T value)
T getControl()
Get the input value.
ExponentialValue< T, Value > & operator+=(const T &other)
ExponentialValue()
Default range scales [0, 1] to [0.5, 2].
ExponentialValue< T, Value > & operator*=(const T &other)
ExponentialValue(T minimum, T maximum, T init)
ExponentialValue(const ExponentialValue< T > &other)
ExponentialValue< T, Value > & operator=(const T &x)
T getControl()
Get the input value.
void setRange(T minimum, T maximum)
LinearValue(T minimum, T maximum, T init)
LinearValue< T, Value > & operator-=(const T &other)
LinearValue< T, Value > & operator/=(const T &other)
LinearValue< T, Value > & operator+=(const T &other)
void setRange(T from_lo, T from_hi, T to_lo, T to_hi)
LinearValue(const LinearValue< T, Value > &other)
LinearValue< T, Value > & operator*=(const T &other)
LinearValue< T, Value > & operator=(const T &x)
Logarithmically scaled value.
LogarithmicValue< T, Value > & operator*=(const T &other)
LogarithmicValue< T, Value > & operator=(const T &x)
LogarithmicValue< T, Value > & operator/=(const T &other)
LogarithmicValue(T a, T b, T init)
LogarithmicValue< T, Value > & operator+=(const T &other)
LogarithmicValue(T value)
LogarithmicValue< T, Value > & operator-=(const T &other)
LogarithmicValue()
Default range scales [0, 1] to [0.5, 2].
LogarithmicValue(const LogarithmicValue< T > &other)
Applies exponential smoothing to a scalar value.
SmoothValue< T, Value > & operator/=(const T &other)
SmoothValue< T, Value > & operator-=(const T &other)
SmoothValue(const SmoothValue< T, Value > &other)
static T normal(float lambda, int blocksize)
SmoothValue< T, Value > & operator=(const T &x)
SmoothValue< T, Value > & operator+=(const T &other)
SmoothValue< T, Value > & operator*=(const T &other)
SmoothValue(T lambda, T init)
Applies simple hysteresis to a scalar.
StiffValue< T, Value > & operator*=(const T &other)
StiffValue< T, Value > & operator+=(const T &other)
StiffValue< T, Value > & operator/=(const T &other)
StiffValue< T, Value > & operator-=(const T &other)
StiffValue(const StiffValue< T, Value > &other)
StiffValue< T, Value > & operator=(const T &other)
StiffValue(T delta, T init)
static T normal(float delta)
#define ASSERT(cond, msg)