From 9215800114f7c81d2214a3b97e7b473afdb9d0ee Mon Sep 17 00:00:00 2001 From: NoiseByNorthwest Date: Sat, 21 Jan 2012 20:34:24 +0100 Subject: [PATCH] Add magnetic effect (for init value) on knobs --- include/AutomatableModel.h | 5 +++++ src/gui/widgets/knob.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index b9b436f2b..453949b73 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -268,6 +268,11 @@ signals: return AutomatableModel::value( _frameOffset ); \ } \ \ + inline type initValue() const \ + { \ + return AutomatableModel::initValue(); \ + } \ + \ inline type minValue() const \ { \ return AutomatableModel::minValue(); \ diff --git a/src/gui/widgets/knob.cpp b/src/gui/widgets/knob.cpp index 40dff8dcf..0df4a8b6d 100644 --- a/src/gui/widgets/knob.cpp +++ b/src/gui/widgets/knob.cpp @@ -558,7 +558,33 @@ void knob::wheelEvent( QWheelEvent * _we ) void knob::setPosition( const QPoint & _p ) { - model()->setValue( model()->value() - getValue( _p ) ); + const float current = model()->value(); + const float next = current - getValue( _p ); + + if( model()->initValue() == current ) + { + // not critical but should be a property + static int magnet_dec = 0; + if( ++magnet_dec > 20 ) + { + magnet_dec = 0; + model()->setValue( next ); + } + + return; + } + + const bool current_sign = model()->initValue() - current < 0; + const bool next_sign = model()->initValue() - next < 0; + + if( current_sign != next_sign ) + { + model()->setValue( model()->initValue() ); + } + else + { + model()->setValue( next ); + } }