From 2d6a93b448e5fd92cadc4e2c94f6445e84b29439 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 18 Feb 2008 18:35:37 -0600 Subject: [PATCH] Try to make snapping more accurate. --- Region.C | 4 +++- Region.H | 4 ++-- Track.H | 27 +++++++++++++++++++++------ Waveform.H | 4 +++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Region.C b/Region.C index a4a9f45..d2a5467 100644 --- a/Region.C +++ b/Region.C @@ -221,6 +221,8 @@ Region::handle ( int m ) // nx = _track->snap( this, nx ); +// _offset = timeline.x_to_ts( nx ); + position( nx, y() ); _track->snap( this ); @@ -260,7 +262,7 @@ Region::handle ( int m ) timeline.scroll->position( pos, timeline.scroll->yposition() ); } - _offset = timeline.x_to_ts( x() ); +// _offset = timeline.x_to_ts( x() ); return 1; default: diff --git a/Region.H b/Region.H index eccada8..183d9cb 100644 --- a/Region.H +++ b/Region.H @@ -48,9 +48,9 @@ public: void resize ( void ); - Track * track ( void ) { return _track; } + Track * track ( void ) const { return _track; } void track ( Track *t ) { _track = t; } - nframes_t offset ( void ) { return _offset; } + nframes_t offset ( void ) const { return _offset; } void offset ( nframes_t o ) { _offset = o; } }; diff --git a/Track.H b/Track.H index b85fba0..4c194bc 100644 --- a/Track.H +++ b/Track.H @@ -25,6 +25,9 @@ #include + +#include + #include using std::list; @@ -88,7 +91,7 @@ public: for ( int i = children(); i-- ; ) { - const Fl_Widget *w = child( i ); + const Region *w = (Region*)child( i ); if ( w == r ) continue; @@ -98,17 +101,29 @@ public: if ( abs( rx1 - wx2 ) < snap_pixels ) { - rx1 = wx2 - 1; - break; + r->offset( w->offset() + ( w->end() - w->start() ) + 1 ); + + printf( "snap: %lu | %lu\n", w->offset() + (w->end() - w->start()), r->offset() ); + + goto done; } if ( abs( rx2 - wx1 ) < snap_pixels ) { - rx1 = (wx1 - r->w()) + 1; - break; + r->offset( (w->offset() - ( r->end() - r->start() )) - 1 ); + + printf( "snap: %lu | %lu\n", r->offset() + (r->end() - r->start()), w->offset() ); + + goto done; } } - r->position( rx1, y() ); + + r->offset( timeline.x_to_ts( r->x() )); + + done: + + r->resize(); +// r->position( rx1, y() ); } int handle ( int m ) diff --git a/Waveform.H b/Waveform.H index 563c879..2824ec1 100644 --- a/Waveform.H +++ b/Waveform.H @@ -68,9 +68,11 @@ public: void draw ( int X, int Y, int W, int H ); void start ( nframes_t s ) { _start = s; } + nframes_t start ( void ) const { return _start; } void end ( nframes_t e ) { _end = e; } + nframes_t end ( void ) const { return _end; } void scale ( float s ) { _scale = s; } - float scale ( void ) { return _scale; } + float scale ( void ) const { return _scale; } // void peaks ( float *p ) { _peaks = p; } void normalize ( void );