Skip to content

Commit

Permalink
fixes rounding issue in automatablemodel (#3597)
Browse files Browse the repository at this point in the history
* fixes rounding issue in automatablemodel

* fix CRS knob sticking in instrument plugins
  • Loading branch information
BaraMGB authored Jun 9, 2017
1 parent 1435717 commit 5a2d8f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class FloatModel : public AutomatableModel
{
}
float getRoundedValue() const;
float getDigitCount();
int getDigitCount() const;
defaultTypedMethods(float);

} ;
Expand Down
6 changes: 3 additions & 3 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,19 +716,19 @@ float AutomatableModel::globalAutomationValueAt( const MidiTime& time )

float FloatModel::getRoundedValue() const
{
return static_cast<float>( static_cast<int>( value() / step<float>() + 0.5 ) ) * step<float>();
return qRound( value() / step<float>() ) * step<float>();
}




float FloatModel::getDigitCount()
int FloatModel::getDigitCount() const
{
float steptemp = step<float>();
int digits = 0;
while ( steptemp < 1 )
{
steptemp = steptemp / 0.1f;
steptemp = steptemp * 10.0f;
digits++;
}
return digits;
Expand Down
5 changes: 2 additions & 3 deletions src/gui/widgets/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ void Knob::mouseMoveEvent( QMouseEvent * _me )
emit sliderMoved( model()->value() );
QCursor::setPos( mapToGlobal( m_origMousePos ) );
}

s_textFloat->setText( displayValue() );
}

Expand Down Expand Up @@ -735,7 +734,7 @@ void Knob::setPosition( const QPoint & _p )
float newValue = value * ratio;
if( qAbs( newValue ) >= step )
{
float roundedValue = static_cast<float>( static_cast<int>( ( oldValue - newValue ) / step + 0.5 ) ) * step;
float roundedValue = qRound( ( oldValue - value ) / step ) * step;
model()->setValue( roundedValue );
m_leftOver = 0.0f;
}
Expand All @@ -749,7 +748,7 @@ void Knob::setPosition( const QPoint & _p )
{
if( qAbs( value ) >= step )
{
float roundedValue = static_cast<float>( static_cast<int>( ( oldValue - value ) / step + 0.5 ) ) * step;
float roundedValue = qRound( ( oldValue - value ) / step ) * step;
model()->setValue( roundedValue );
m_leftOver = 0.0f;
}
Expand Down

0 comments on commit 5a2d8f1

Please sign in to comment.