suggest a fix for precision on knob dragging (#3075)

* fixes precision on knob dragging

* fixes precision on fader dragging

* diaplay a rounded float on knobs

* enter rounded value on fader

* add getRoundedValue() and getDigitCount() to floatmodel

* whitespace
This commit is contained in:
Steffen Baranowsky
2017-01-12 15:02:54 +01:00
committed by GitHub
parent 7e8513235c
commit 7cf6150e75
4 changed files with 40 additions and 18 deletions

View File

@@ -406,7 +406,8 @@ public:
AutomatableModel( Float, val, min, max, step, parent, displayName, defaultConstructed )
{
}
float getRoundedValue() const;
float getDigitCount();
defaultTypedMethods(float);
} ;

View File

@@ -275,9 +275,10 @@ float AutomatableModel::inverseScaledValue( float value ) const
QString AutomatableModel::displayValue( const float val ) const
{
const FloatModel *floatmodel = dynamic_cast<const FloatModel*>( this );
switch( m_dataType )
{
case Float: return QString::number( castValue<float>( scaledValue( val ) ) );
case Float: return QString::number( castValue<float>( scaledValue( floatmodel->getRoundedValue() ) ) );
case Integer: return QString::number( castValue<int>( scaledValue( val ) ) );
case Bool: return QString::number( castValue<bool>( scaledValue( val ) ) );
}
@@ -713,6 +714,23 @@ float AutomatableModel::globalAutomationValueAt( const MidiTime& time )
}
}
float FloatModel::getRoundedValue() const
{
return static_cast<float>( static_cast<int>( value() / step<float>() + 0.5 ) ) * step<float>();
}
float FloatModel::getDigitCount()
{
float steptemp = step<float>();
int digits = 0;
while ( steptemp < 1 )
{
steptemp = steptemp / 0.1f;
digits++;
}
return digits;
}

View File

@@ -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>();
float newValue = static_cast<float>( static_cast<int>( ( 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 )

View File

@@ -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<float>( static_cast<int>( ( 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<float>( static_cast<int>( ( 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;
}