diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index acefc95c34f..984672f68a1 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -406,7 +406,8 @@ class FloatModel : public AutomatableModel AutomatableModel( Float, val, min, max, step, parent, displayName, defaultConstructed ) { } - + float getRoundedValue() const; + float getDigitCount(); defaultTypedMethods(float); } ; diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 509ee4aa0f9..29337f9d240 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -275,9 +275,10 @@ float AutomatableModel::inverseScaledValue( float value ) const QString AutomatableModel::displayValue( const float val ) const { + const FloatModel *floatmodel = dynamic_cast( this ); switch( m_dataType ) { - case Float: return QString::number( castValue( scaledValue( val ) ) ); + case Float: return QString::number( castValue( scaledValue( floatmodel->getRoundedValue() ) ) ); case Integer: return QString::number( castValue( scaledValue( val ) ) ); case Bool: return QString::number( castValue( scaledValue( val ) ) ); } @@ -713,6 +714,23 @@ float AutomatableModel::globalAutomationValueAt( const MidiTime& time ) } } +float FloatModel::getRoundedValue() const +{ + return static_cast( static_cast( value() / step() + 0.5 ) ) * step(); +} + + +float FloatModel::getDigitCount() +{ + float steptemp = step(); + int digits = 0; + while ( steptemp < 1 ) + { + steptemp = steptemp / 0.1f; + digits++; + } + return digits; +} diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index ff058189511..392df734ba1 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -174,7 +174,9 @@ void Fader::mouseMoveEvent( QMouseEvent *mouseEvent ) float delta = dy * ( model()->maxValue() - model()->minValue() ) / (float) ( height() - ( *m_knob ).height() ); - model()->setValue( m_startValue + delta ); + const float step = model()->step(); + float newValue = static_cast( static_cast( ( m_startValue + delta ) / step + 0.5 ) ) * step; + model()->setValue( newValue ); updateTextFloat(); } @@ -215,7 +217,6 @@ void Fader::mouseDoubleClickEvent( QMouseEvent* mouseEvent ) { bool ok; float newValue; - // TODO: dbV handling if( m_displayConversion ) { @@ -223,9 +224,9 @@ void Fader::mouseDoubleClickEvent( QMouseEvent* mouseEvent ) tr( "Please enter a new value between %1 and %2:" ). arg( model()->minValue() * 100 ). arg( model()->maxValue() * 100 ), - model()->value() * 100, + model()->getRoundedValue() * 100, model()->minValue() * 100, - model()->maxValue() * 100, 4, &ok ) * 0.01f; + model()->maxValue() * 100, model()->getDigitCount(), &ok ) * 0.01f; } else { @@ -233,9 +234,9 @@ void Fader::mouseDoubleClickEvent( QMouseEvent* mouseEvent ) tr( "Please enter a new value between %1 and %2:" ). arg( model()->minValue() ). arg( model()->maxValue() ), - model()->value(), + model()->getRoundedValue(), model()->minValue(), - model()->maxValue(), 4, &ok ); + model()->maxValue(), model()->getDigitCount(), &ok ); } if( ok ) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 65af949ed45..962ddca1180 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -51,7 +51,6 @@ #include "templates.h" #include "TextFloat.h" - TextFloat * Knob::s_textFloat = NULL; @@ -729,6 +728,7 @@ void Knob::setPosition( const QPoint & _p ) const float oldValue = model()->value(); + if( model()->isScaleLogarithmic() ) // logarithmic code { const float pos = model()->minValue() < 0 @@ -738,7 +738,8 @@ void Knob::setPosition( const QPoint & _p ) float newValue = value * ratio; if( qAbs( newValue ) >= step ) { - model()->setValue( oldValue - newValue ); + float roundedValue = static_cast( static_cast( ( oldValue - newValue ) / step + 0.5 ) ) * step; + model()->setValue( roundedValue ); m_leftOver = 0.0f; } else @@ -747,12 +748,12 @@ void Knob::setPosition( const QPoint & _p ) } } - else // linear code { if( qAbs( value ) >= step ) { - model()->setValue( oldValue - value ); + float roundedValue = static_cast( static_cast( ( oldValue - value ) / step + 0.5 ) ) * step; + model()->setValue( roundedValue ); m_leftOver = 0.0f; } else @@ -769,6 +770,7 @@ void Knob::enterValue() { bool ok; float new_val; + if( isVolumeKnob() && ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() ) { @@ -776,8 +778,8 @@ void Knob::enterValue() this, windowTitle(), tr( "Please enter a new value between " "-96.0 dBFS and 6.0 dBFS:" ), - 20.0 * log10( model()->value() / 100.0 ), - -96.0, 6.0, 4, &ok ); + 20.0 * log10( model()->getRoundedValue() / 100.0 ), + -96.0, 6.0, model()->getDigitCount(), &ok ); if( new_val <= -96.0 ) { new_val = 0.0f; @@ -795,9 +797,9 @@ void Knob::enterValue() "%1 and %2:" ). arg( model()->minValue() ). arg( model()->maxValue() ), - model()->value(), + model()->getRoundedValue(), model()->minValue(), - model()->maxValue(), 4, &ok ); + model()->maxValue(), model()->getDigitCount(), &ok ); } if( ok ) @@ -828,11 +830,11 @@ QString Knob::displayValue() const ConfigManager::inst()->value( "app", "displaydbfs" ).toInt() ) { return m_description.trimmed() + QString( " %1 dBFS" ). - arg( 20.0 * log10( model()->value() / volumeRatio() ), + arg( 20.0 * log10( model()->getRoundedValue() / volumeRatio() ), 3, 'f', 2 ); } return m_description.trimmed() + QString( " %1" ). - arg( model()->value() ) + m_unit; + arg( model()->getRoundedValue() ) + m_unit; }