Merge pull request #875 from diizy/logs

Logscale models: fix all issues and finalize the implementation
This commit is contained in:
Tobias Doerffel
2014-06-21 23:43:05 +02:00
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,40 @@ static inline double sinc( double _x )
}
//! @brief Exponential function that deals with negative bases
static inline float signedPowf( float v, float e )
{
return v < 0
? powf( -v, e ) * -1.0f
: powf( v, e );
}
//! @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 )
{
const float mmax = qMax( qAbs( min ), qAbs( max ) );
const float val = value * ( max - min ) + min;
return signedPowf( val / mmax, F_E ) * mmax;
}
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 )
{
const float mmax = qMax( qAbs( min ), qAbs( max ) );
return signedPowf( value / mmax, EXP ) * mmax;
}
return powf( val, EXP ) * ( max - min ) + min;
}
#endif