Browse Source

Implement snap to bar.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
8f0fb79543
3 changed files with 27 additions and 0 deletions
  1. +17
    -0
      Timeline.C
  2. +2
    -0
      Timeline.H
  3. +8
    -0
      Track.C

+ 17
- 0
Timeline.C View File

@@ -190,6 +190,23 @@ Timeline::beats_per_minute ( nframes_t when, float bpm )
tempo_track->add( new Tempo_Point( when, bpm ) );
}

/** return the absolute pixel of the nearest measure line to /x/ */
int
Timeline::nearest_line ( int ix )
{
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 ) + xoffset ));

// const int abs_x = ts_to_x( xoffset ) + x;

if ( 0 == x % measure )
return x;
}

return -1;
}

/* draw appropriate measure lines inside the given bounding box */
void
Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )


+ 2
- 0
Timeline.H View File

@@ -106,6 +106,8 @@ struct Timeline : public Fl_Group
float beats_per_minute ( nframes_t when ) const;
int beats_per_bar ( nframes_t when ) const;
void beats_per_minute ( nframes_t when, float bpm );
int nearest_line ( int ix );

void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color );
void position ( int X );
void draw ( void );


+ 8
- 0
Track.C View File

@@ -119,6 +119,14 @@ Track::snap ( Track_Widget *r )
int rx1 = r->x();
int rx2 = r->x() + r->w();

int nx = timeline->nearest_line( r->abs_x() );

if ( nx >= 0 )
{
r->offset( timeline->x_to_ts( nx ) );
return;
}

for ( list <Track_Widget*>::iterator i = _widgets.begin(); i != _widgets.end(); i++ )
{
const Track_Widget *w = (*i);


Loading…
Cancel
Save