diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index 4bca72891..931022ab8 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -182,7 +182,6 @@ public: void setRange( const float min, const float max, const float step = 1 ); void setScaleType( ScaleType sc ) { - printf("Settings scale to: %d\n", (int)sc); m_scaleType = sc; } void setScaleLogarithmic( bool set_to_true = true ) @@ -251,6 +250,10 @@ public slots: protected: + //! returns a value which is in range between min() and + //! max() and aligned according to the step size (step size 0.05 -> value + //! 0.12345 becomes 0.10 etc.). You should always call it at the end after + //! doing your own calculations. float fittedValue( float value ) const; @@ -268,6 +271,10 @@ private: void linkModel( AutomatableModel* model ); void unlinkModel( AutomatableModel* model ); + //! @brief Scales @value from linear to logarithmic. + //! Value should be within [0,1] + template T log_to_linear_scale(T value) const; + //! rounds @a value to @a where if it is close to it //! @param value will be modified to rounded value template void round_at(T &value, const T &where) const; diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index ae4db5911..e00b3ce5f 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -246,16 +246,46 @@ void AutomatableModel::setValue( const float value ) //! @brief Scales @value from linear to logarithmic. //! Value should be within [0,1] +//! @todo This should be moved into a maths header template T log_to_linear_scale(T min, T max, T value) -// we get min and max from the class => TODO { - printf("scale: in: %f, out: %f\n",value, exp((log(max)-log(min)) * value + log(min))); return exp((log(max)-log(min)) * value + log(min)); } +template T AutomatableModel::log_to_linear_scale(T value) const +{ + return ::log_to_linear_scale(minValue(), maxValue(), value); +} + + + + +//! @todo: this should be moved into a maths header +template +void round_at(T& value, const T& where, const T& step_size) +{ + if( qAbs( value - where ) + < typeInfo::minEps() * qAbs( step_size ) ) + { + value = where; + } +} + + + + +template +void AutomatableModel::round_at(T& value, const T& where) const +{ + ::round_at(value, where, m_step); +} + + + + void AutomatableModel::setAutomatedValue( const float value ) { ++m_setValueDepth; @@ -265,7 +295,6 @@ void AutomatableModel::setAutomatedValue( const float value ) (m_scaleType == Linear) ? value : log_to_linear_scale( - minValue(), maxValue(), // fit value into [0,1]: (value - minValue()) / maxValue() ); @@ -332,19 +361,6 @@ void AutomatableModel::setStep( const float step ) -template -void AutomatableModel::round_at(T& value, const T& where) const -{ - if( qAbs( value - where ) - < typeInfo::minEps() * qAbs( m_step ) ) - { - value = where; - } -} - - - - float AutomatableModel::fittedValue( float value ) const { value = tLimit( value, m_minValue, m_maxValue ); @@ -354,9 +370,9 @@ float AutomatableModel::fittedValue( float value ) const value = nearbyintf( value / m_step ) * m_step; } - round_at(value, m_maxValue, m_step); - round_at(value, m_minValue, m_step); - round_at(value, 0, m_step); + round_at(value, m_maxValue); + round_at(value, m_minValue); + round_at(value, 0.0f); if( value < m_minValue ) { @@ -462,7 +478,7 @@ float AutomatableModel::controllerValue( int frameOffset ) const v = minValue() + ( range() * controllerConnection()->currentValue( frameOffset ) ); break; case Logarithmic: - v = log_to_linear_scale(minValue(), maxValue(), + v = log_to_linear_scale( controllerConnection()->currentValue( frameOffset )); break; default: