diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index b9646ae..06fb377 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -36,7 +36,7 @@ decl {extern char *user_config_dir;} {global class TLE {open } { - decl {Fl_Color system_colors[3];} {selected public + decl {Fl_Color system_colors[3];} {public } decl {static void menubar_cb ( void *v )} {} decl {void menubar_cb ( void )} {} @@ -252,14 +252,17 @@ exit( 0 );} } { MenuItem {} { label Bars + callback {Timeline::snap_to = Timeline::Bars;} selected xywh {0 0 40 25} type Radio value 1 } MenuItem {} { label Beats + callback {Timeline::snap_to = Timeline::Beats;} xywh {10 10 40 25} type Radio } MenuItem {} { label Off + callback {Timeline::snap_to = Timeline::None;} xywh {20 20 40 25} type Radio } } diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 6908858..b0aeb53 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -32,6 +32,7 @@ #include "Track.H" bool Timeline::draw_with_measure_lines = true; +Timeline::snap_e Timeline::snap_to = Bars; const float UPDATE_FREQ = 0.02f; @@ -240,14 +241,31 @@ Timeline::bbt ( nframes_t when ) int Timeline::nearest_line ( int ix ) { + if ( snap_to == None ) + return -1; + for ( int x = ix - 10; x < ix + 10; ++x ) { const int measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset )); -// const int abs_x = ts_to_x( xoffset ) + x; +// const int abs_x = ts_to_x( xoffset ) + x - Track::width(); + + const int abs_x = ts_to_x( xoffset ) + x; + + int bpb = beats_per_bar( x_to_ts( x -Track::width() ) + xoffset ); if ( 0 == x % measure ) - return x; + { + if ( snap_to == Bars ) + { + if ( 0 == (abs_x / measure) % bpb ) + return x; + } + else if ( snap_to == Beats ) + { + return x; + } + } } return -1; diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 0304f24..05b2a6e 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -86,12 +86,6 @@ class Timeline : public Fl_Overlay_Window, public RWLock Rectangle _selection; - enum snap_flags_e { - SNAP_TO_REGION, - SNAP_TO_BAR, - SNAP_TO_BEAT - } snap_to; - Fl_Scroll *scroll; Fl_Pack *tracks; Fl_Pack *rulers; @@ -112,7 +106,14 @@ class Timeline : public Fl_Overlay_Window, public RWLock public: + enum snap_e { + Bars, + Beats, + None + }; + static bool draw_with_measure_lines; + static snap_e snap_to; Tempo_Sequence *tempo_track; Time_Sequence *time_track;