Bypass magnetic snap for loop points.

This commit is contained in:
Jonathan Moore Liles 2008-07-01 22:19:31 -05:00
parent b0098355cc
commit 7dc9a475e9
3 changed files with 19 additions and 7 deletions

View File

@ -253,7 +253,7 @@ Audio_Region::menu_cb ( const Fl_Menu_ *m )
{ {
nframes_t f = offset + _r->start; nframes_t f = offset + _r->start;
if ( timeline->nearest_line( &f ) ) if ( timeline->nearest_line( &f, false ) )
_loop = f - _r->start; _loop = f - _r->start;
else else
_loop = offset; _loop = offset;

View File

@ -503,7 +503,7 @@ abs_diff ( nframes_t n1, nframes_t n2 )
} }
static void 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; 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; 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 static void
prev_next_line_cb ( nframes_t frame, const BBT &bbt, void *arg ) 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 the nearest measure line to /when/. Returns true if the new value of
*frame is valid, false otherwise. */ *frame is valid, false otherwise. */
bool 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; return false;
nframes_t when = *frame; 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, 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 ) if ( n.closest == (nframes_t)-1 )
return false; return false;

View File

@ -156,7 +156,7 @@ public:
int beats_per_bar ( nframes_t when ) const; int beats_per_bar ( nframes_t when ) const;
void beats_per_minute ( nframes_t when, float bpm ); void beats_per_minute ( nframes_t when, float bpm );
void time ( nframes_t when, int bpb, int beat_type ); 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 next_line ( nframes_t *f, bool bar=false ) const;
bool prev_line ( nframes_t *f, bool bar=false ) const; bool prev_line ( nframes_t *f, bool bar=false ) const;