From 7dc9a475e9f45271def619309da71f3819bb90d1 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 1 Jul 2008 22:19:31 -0500 Subject: [PATCH] Bypass magnetic snap for loop points. --- Timeline/Audio_Region.C | 2 +- Timeline/Timeline.C | 22 +++++++++++++++++----- Timeline/Timeline.H | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Timeline/Audio_Region.C b/Timeline/Audio_Region.C index f3e1402..5278db6 100644 --- a/Timeline/Audio_Region.C +++ b/Timeline/Audio_Region.C @@ -253,7 +253,7 @@ Audio_Region::menu_cb ( const Fl_Menu_ *m ) { nframes_t f = offset + _r->start; - if ( timeline->nearest_line( &f ) ) + if ( timeline->nearest_line( &f, false ) ) _loop = f - _r->start; else _loop = offset; diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 8d4049e..a385618 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -503,7 +503,7 @@ abs_diff ( nframes_t n1, nframes_t n2 ) } static void -nearest_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) +nearest_line_snap_cb ( nframes_t frame, const BBT &bbt, void *arg ) { nearest_line_arg *n = (nearest_line_arg *)arg; @@ -518,6 +518,18 @@ nearest_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) n->closest = frame; } +static void +nearest_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) +{ + nearest_line_arg *n = (nearest_line_arg *)arg; + + if ( n->bar && bbt.beat ) + return; + + if ( abs_diff( frame, n->original ) < abs_diff( n->original, n->closest ) ) + n->closest = frame; +} + static void prev_next_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) { @@ -534,17 +546,17 @@ prev_next_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) the nearest measure line to /when/. Returns true if the new value of *frame is valid, false otherwise. */ bool -Timeline::nearest_line ( nframes_t *frame ) const +Timeline::nearest_line ( nframes_t *frame, bool snap ) const { - if ( None == Timeline::snap_to ) + if ( snap && None == Timeline::snap_to ) return false; nframes_t when = *frame; - nearest_line_arg n = { when, -1, Timeline::Bars == Timeline::snap_to }; + nearest_line_arg n = { when, -1, snap && Timeline::Bars == Timeline::snap_to }; render_tempomap( when > x_to_ts( w() >> 1 ) ? when - x_to_ts( w() >> 1 ) : 0, - when + x_to_ts( w() >> 1 ), nearest_line_cb, &n ); + when + x_to_ts( w() >> 1 ), snap ? nearest_line_snap_cb : nearest_line_cb, &n ); if ( n.closest == (nframes_t)-1 ) return false; diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 2948bd9..8c67a41 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -156,7 +156,7 @@ public: int beats_per_bar ( nframes_t when ) const; void beats_per_minute ( nframes_t when, float bpm ); void time ( nframes_t when, int bpb, int beat_type ); - bool nearest_line ( nframes_t *f ) const; + bool nearest_line ( nframes_t *f, bool snap=true ) const; bool next_line ( nframes_t *f, bool bar=false ) const; bool prev_line ( nframes_t *f, bool bar=false ) const;