Log scales finalized

This commit is contained in:
Vesa
2014-06-20 22:46:10 +03:00
parent 737839164a
commit 14909bdf1b
9 changed files with 121 additions and 65 deletions

View File

@@ -162,7 +162,11 @@ public:
{
return castValue<T>( m_step );
}
//! @brief Returns value scaled with the scale type and min/max values of this model
float scaledValue( float value ) const;
//! @brief Returns value applied with the inverse of this model's scale type
float inverseScaledValue( float value ) const;
void setInitValue( const float value );
@@ -187,6 +191,10 @@ public:
{
setScaleType( setToTrue ? Logarithmic : Linear );
}
bool isScaleLogarithmic() const
{
return m_scaleType == Logarithmic;
}
void setStep( const float step );
@@ -224,16 +232,7 @@ public:
return "automatablemodel";
}
QString displayValue( const float val ) const
{
switch( m_dataType )
{
case Float: return QString::number( castValue<float>( val ) );
case Integer: return QString::number( castValue<int>( val ) );
case Bool: return QString::number( castValue<bool>( val ) );
}
return "0";
}
QString displayValue( const float val ) const;
bool hasLinkedModels() const
{

View File

@@ -22,10 +22,11 @@
*
*/
#ifndef _LMMS_CONSTANTS_H
#define _LMMS_CONSTANTS_H
#ifndef LMMS_CONSTANTS_H
#define LMMS_CONSTANTS_H
const float F_PI = 3.1415926535f;
const float F_E = 2.718281828459045f;
const float F_2PI = 2*F_PI;
const float F_PI_2 = F_PI*0.5;

View File

@@ -128,5 +128,42 @@ static inline double sinc( double _x )
}
//! @brief Returns logarithm of value, while accounting for zeros or negative values
static inline float saneLog( float value )
{
if( value == 0.0f )
{
return 0.0f;
}
return value < 0.0f
? logf( -value ) * -1.0f
: logf( value );
}
//! @brief Scales @value from linear to logarithmic.
//! Value should be within [0,1]
static inline float logToLinearScale( float min, float max, float value )
{
if( min < 0 )
{
return powf( value * ( 1.0f - min / max ) + min / max, F_E ) * ( max - min ) + min;
}
return powf( value, F_E ) * ( max - min ) + min;
}
//! @brief Scales value from logarithmic to linear. Value should be in min-max range.
static inline float linearToLogScale( float min, float max, float value )
{
static const float EXP = 1.0f / F_E;
const float val = ( value - min ) / ( max - min );
if( min < 0 )
{
return powf( val * ( 1.0f - min / max ) + min / max, EXP ) * ( max - min ) + min;
}
return powf( val, EXP ) * ( max - min ) + min;
}
#endif