From 80ec2b6e35bc73acdcabf23a5fb4d45415ea5c35 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 19 Feb 2008 00:22:42 -0600 Subject: [PATCH] Work in snapping some more. --- Region.C | 8 ++++++++ Timeline.H | 7 ++++++- Track.H | 10 +++++----- Waveform.H | 1 + main.C | 10 ++++------ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Region.C b/Region.C index d2a5467..b592e2c 100644 --- a/Region.C +++ b/Region.C @@ -277,8 +277,16 @@ void Region::resize ( void ) { int X = timeline.ts_to_x( _offset ); + + assert( _end >= _start ); + int W = timeline.ts_to_x( _end - _start ); + printf( "%dx%d\n", X, W ); + + if ( W > 5000 ) + W = 5000; + if ( W ) Fl_Widget::resize( X, y(), W, h() ); } diff --git a/Timeline.H b/Timeline.H index ba5054a..e719ae3 100644 --- a/Timeline.H +++ b/Timeline.H @@ -23,19 +23,24 @@ #include #include "Clip.H" +#include + +#include struct Timeline { Fl_Scroll *scroll; Fl_Pack *tracks; float fpp; /* frames per pixel */ +// nframes_t fpp; nframes_t sample_rate; int ts_to_x( nframes_t ts ) { - return ts / fpp; +// assert( ts / fpp > 0 ); + return ts / fpp; } nframes_t diff --git a/Track.H b/Track.H index 4c194bc..4459391 100644 --- a/Track.H +++ b/Track.H @@ -101,24 +101,24 @@ public: if ( abs( rx1 - wx2 ) < snap_pixels ) { - r->offset( w->offset() + ( w->end() - w->start() ) + 1 ); + r->offset( w->offset() + w->length() + 1 ); - printf( "snap: %lu | %lu\n", w->offset() + (w->end() - w->start()), r->offset() ); + printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() ); goto done; } if ( abs( rx2 - wx1 ) < snap_pixels ) { - r->offset( (w->offset() - ( r->end() - r->start() )) - 1 ); + r->offset( ( w->offset() - r->length() ) - 1 ); - printf( "snap: %lu | %lu\n", r->offset() + (r->end() - r->start()), w->offset() ); + printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() ); goto done; } } - r->offset( timeline.x_to_ts( r->x() )); + r->offset( timeline.x_to_ts( r->x() ) ); done: diff --git a/Waveform.H b/Waveform.H index 2824ec1..2074a90 100644 --- a/Waveform.H +++ b/Waveform.H @@ -71,6 +71,7 @@ public: nframes_t start ( void ) const { return _start; } void end ( nframes_t e ) { _end = e; } nframes_t end ( void ) const { return _end; } + nframes_t length ( void ) const { return _end - _start; } void scale ( float s ) { _scale = s; } float scale ( void ) const { return _scale; } diff --git a/main.C b/main.C index 3a34653..fd06866 100644 --- a/main.C +++ b/main.C @@ -88,15 +88,16 @@ main ( int argc, char **argv ) timeline.sample_rate = 44100; - timeline.tracks = new Fl_Pack( 0, 0, 5000, 5000 ); + timeline.tracks = new Fl_Pack( 0, 0, 32767, 5000 ); timeline.tracks->type( Fl_Pack::VERTICAL ); + timeline.tracks->spacing( 20 ); Fl::get_system_colors(); Fl::scheme( "plastic" ); // Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 ); - Track *track1 = new Track( 40, 0, 5000, 100 ); + Track *track1 = new Track( 40, 0, 32768, 100 ); // pack->type( Fl_Pack::VERTICAL ); // pack->box( FL_DOWN_BOX ); @@ -107,10 +108,7 @@ main ( int argc, char **argv ) // wave->resize( 0, 0, 500, 100 ); - // wave->peaks( peaks ); - wave->start( 0 ); -// wave->end( (len / sizeof( float )) / 2 ); - wave->end( 50 ); + wave->offset( 1024 ); wave->color( FL_CYAN ); wave->selection_color( fl_darker( FL_GRAY ) );