Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ float AutomatableModel::globalAutomationValueAt( const MidiTime& time )

float FloatModel::getRoundedValue() const
{
return floorf( value() * powf( 10.0f, getDigitCount() ) + 0.5f ) / powf( 10.0f, getDigitCount() );
return qRound( value() / step<float>() ) * step<float>();
}


Expand All @@ -728,7 +728,7 @@ int FloatModel::getDigitCount() const
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this code:

		if( qAbs( value ) >= step )
		{
			float roundedValue = qRound( ( oldValue - value ) / step ) * step;
			model()->setValue( roundedValue );
			m_leftOver = 0.0f;
		}
		else
		{
			m_leftOver = value;
		}

is duplicated, maybe something like:

	float consideredValue = value; // linear code

	if( model()->isScaleLogarithmic() ) // logarithmic code
	{
		const float pos = model()->minValue() < 0
			? oldValue / qMax( qAbs( model()->maxValue() ), qAbs( model()->minValue() ) )
			: ( oldValue - model()->minValue() ) / model()->range();
		const float ratio = 0.1f + qAbs( pos ) * 15.f;
		consideredValue = value * ratio;
	}

	if( qAbs( consideredValue ) >= step )
	{
		float roundedValue = qRound( ( oldValue - value ) / step ) * step;
		model()->setValue( roundedValue );
		m_leftOver = 0.0f;
	}
	else
	{
		m_leftOver = value;
	}

model()->setValue( roundedValue );
m_leftOver = 0.0f;
}
Expand Down