Make snap type configurable.
This commit is contained in:
parent
07b193c9c5
commit
8e1bc189e6
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue