From 83fceb23dccd218f0cd2c9e2146a505aa6984faf Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 22 Sep 2013 21:34:04 -0700 Subject: [PATCH] Timeline: Improve behavior of audio region gain adjustment mode. --- timeline/src/Audio_Region.C | 40 +++++++++++++++++++++++----------- timeline/src/Audio_Region.H | 2 +- timeline/src/Sequence_Region.C | 6 ++--- timeline/src/Sequence_Widget.C | 2 +- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/timeline/src/Audio_Region.C b/timeline/src/Audio_Region.C index 05e8e75..f734b8d 100644 --- a/timeline/src/Audio_Region.C +++ b/timeline/src/Audio_Region.C @@ -153,7 +153,7 @@ Audio_Region::Audio_Region ( const Audio_Region & rhs ) : Sequence_Region( rhs ) _box_color = rhs._box_color; _color = rhs._color; - _adjusting_gain = false; + _adjusting_gain = 0.0f; log_create(); } @@ -661,7 +661,7 @@ Audio_Region::draw ( void ) - if ( _adjusting_gain ) + if ( _adjusting_gain > 0.0f ) { fl_color( fl_color_add_alpha( FL_DARK1, 127 ) ); @@ -744,7 +744,7 @@ Audio_Region::handle ( int m ) int X = Fl::event_x(); int Y = Fl::event_y(); - + Logger _log( this ); switch ( m ) @@ -753,29 +753,40 @@ Audio_Region::handle ( int m ) case FL_UNFOCUS: return 1; case FL_KEYUP: - if ( Fl::event_key() == 'g' ) + if ( _adjusting_gain > 0 ) { - _adjusting_gain = false; + _adjusting_gain = 0; redraw(); return 1; } break; case FL_KEYBOARD: - if ( Fl::event_key() == 'g' ) + if ( Fl::event_key() == 'g' ) { - _adjusting_gain = true; - redraw(); + if ( _adjusting_gain <= 0 ) + { + _adjusting_gain = _scale; + redraw(); + } return 1; } return menu().test_shortcut() != 0; case FL_ENTER: return Sequence_Region::handle( m ); case FL_LEAVE: + if ( _adjusting_gain > 0 ) + { + _adjusting_gain = 0; + redraw(); + } return Sequence_Region::handle( m ); case FL_PUSH: { - if ( Fl::event_key() == 'g' ) + if ( _adjusting_gain > 0.0f ) + { + _adjusting_gain = _scale; return 1; + } /* splitting */ if ( test_press( FL_BUTTON2 | FL_SHIFT ) ) @@ -832,15 +843,18 @@ Audio_Region::handle ( int m ) if ( ! _drag ) { - begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) ); + begin_drag( Drag( X, Y, x_to_offset( X ) ) ); _log.hold(); } - if ( Fl::event_key() == 'g' ) + if ( _adjusting_gain ) { - float d = (float)h() / ( y() - Fl::event_y() ); + int d = _drag->y - Y; + + _scale = _adjusting_gain + ( 0.01f * d ); - _scale = -0.5f * d; + if ( _scale < 0.01f ) + _scale = 0.01f; redraw(); return 1; diff --git a/timeline/src/Audio_Region.H b/timeline/src/Audio_Region.H index 033757c..fb142d8 100644 --- a/timeline/src/Audio_Region.H +++ b/timeline/src/Audio_Region.H @@ -99,7 +99,7 @@ private: Audio_File *_clip; /* clip this region represents */ - bool _adjusting_gain; + float _adjusting_gain; float _scale; /* amplitude adjustment */ Fade _fade_in; diff --git a/timeline/src/Sequence_Region.C b/timeline/src/Sequence_Region.C index 3657ead..cc26c4a 100644 --- a/timeline/src/Sequence_Region.C +++ b/timeline/src/Sequence_Region.C @@ -154,12 +154,12 @@ Sequence_Region::handle ( int m ) { case 1: trim( trimming = LEFT, X ); - begin_drag( Drag( x() - X, y() - Y ) ); + begin_drag( Drag( X, Y ) ); _log.hold(); break; case 3: trim( trimming = RIGHT, X ); - begin_drag( Drag( x() - X, y() - Y ) ); + begin_drag( Drag( X, Y) ); _log.hold(); break; default: @@ -207,7 +207,7 @@ Sequence_Region::handle ( int m ) { if ( ! _drag ) { - begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) ); + begin_drag( Drag( X, Y, x_to_offset( X ) ) ); _log.hold(); } diff --git a/timeline/src/Sequence_Widget.C b/timeline/src/Sequence_Widget.C index fadae37..70ba673 100644 --- a/timeline/src/Sequence_Widget.C +++ b/timeline/src/Sequence_Widget.C @@ -442,7 +442,7 @@ Sequence_Widget::handle ( int m ) if ( ! _drag ) { - begin_drag ( Drag( x() - X, y() - Y, start() - x_to_offset( X ) ) ); + begin_drag ( Drag( Y, x_to_offset( X ) ) ); _log.hold(); }