Current logscales fix.

This commit is contained in:
Johannes Lorenz
2014-04-05 09:05:22 +02:00
parent 1f5ef70d2c
commit 554323dcb6
2 changed files with 44 additions and 21 deletions

View File

@@ -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<class T> 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<class T> void round_at(T &value, const T &where) const;

View File

@@ -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<class T> 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<class T> T AutomatableModel::log_to_linear_scale(T value) const
{
return ::log_to_linear_scale(minValue<float>(), maxValue<float>(), value);
}
//! @todo: this should be moved into a maths header
template<class T>
void round_at(T& value, const T& where, const T& step_size)
{
if( qAbs<float>( value - where )
< typeInfo<float>::minEps() * qAbs<float>( step_size ) )
{
value = where;
}
}
template<class T>
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<float>(), maxValue<float>(),
// fit value into [0,1]:
(value - minValue<float>()) / maxValue<float>()
);
@@ -332,19 +361,6 @@ void AutomatableModel::setStep( const float step )
template<class T>
void AutomatableModel::round_at(T& value, const T& where) const
{
if( qAbs<float>( value - where )
< typeInfo<float>::minEps() * qAbs<float>( m_step ) )
{
value = where;
}
}
float AutomatableModel::fittedValue( float value ) const
{
value = tLimit<float>( 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<float>() + ( range() * controllerConnection()->currentValue( frameOffset ) );
break;
case Logarithmic:
v = log_to_linear_scale(minValue<float>(), maxValue<float>(),
v = log_to_linear_scale(
controllerConnection()->currentValue( frameOffset ));
break;
default: