Browse Source

Make snap type configurable.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
8e1bc189e6
3 changed files with 31 additions and 9 deletions
  1. +4
    -1
      Timeline/TLE.fl
  2. +20
    -2
      Timeline/Timeline.C
  3. +7
    -6
      Timeline/Timeline.H

+ 4
- 1
Timeline/TLE.fl View File

@@ -36,7 +36,7 @@ decl {extern char *user_config_dir;} {global


class TLE {open 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 {static void menubar_cb ( void *v )} {}
decl {void menubar_cb ( void )} {} decl {void menubar_cb ( void )} {}
@@ -252,14 +252,17 @@ exit( 0 );}
} { } {
MenuItem {} { MenuItem {} {
label Bars label Bars
callback {Timeline::snap_to = Timeline::Bars;} selected
xywh {0 0 40 25} type Radio value 1 xywh {0 0 40 25} type Radio value 1
} }
MenuItem {} { MenuItem {} {
label Beats label Beats
callback {Timeline::snap_to = Timeline::Beats;}
xywh {10 10 40 25} type Radio xywh {10 10 40 25} type Radio
} }
MenuItem {} { MenuItem {} {
label Off label Off
callback {Timeline::snap_to = Timeline::None;}
xywh {20 20 40 25} type Radio xywh {20 20 40 25} type Radio
} }
} }


+ 20
- 2
Timeline/Timeline.C View File

@@ -32,6 +32,7 @@
#include "Track.H" #include "Track.H"


bool Timeline::draw_with_measure_lines = true; bool Timeline::draw_with_measure_lines = true;
Timeline::snap_e Timeline::snap_to = Bars;


const float UPDATE_FREQ = 0.02f; const float UPDATE_FREQ = 0.02f;


@@ -240,14 +241,31 @@ Timeline::bbt ( nframes_t when )
int int
Timeline::nearest_line ( int ix ) Timeline::nearest_line ( int ix )
{ {
if ( snap_to == None )
return -1;

for ( int x = ix - 10; x < ix + 10; ++x ) 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 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 ) 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; return -1;


+ 7
- 6
Timeline/Timeline.H View File

@@ -86,12 +86,6 @@ class Timeline : public Fl_Overlay_Window, public RWLock


Rectangle _selection; Rectangle _selection;


enum snap_flags_e {
SNAP_TO_REGION,
SNAP_TO_BAR,
SNAP_TO_BEAT
} snap_to;

Fl_Scroll *scroll; Fl_Scroll *scroll;
Fl_Pack *tracks; Fl_Pack *tracks;
Fl_Pack *rulers; Fl_Pack *rulers;
@@ -112,7 +106,14 @@ class Timeline : public Fl_Overlay_Window, public RWLock


public: public:


enum snap_e {
Bars,
Beats,
None
};

static bool draw_with_measure_lines; static bool draw_with_measure_lines;
static snap_e snap_to;


Tempo_Sequence *tempo_track; Tempo_Sequence *tempo_track;
Time_Sequence *time_track; Time_Sequence *time_track;


Loading…
Cancel
Save