From 143035f0e8615d4eb98b9d4d08ffa0d11271e12d Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 28 Feb 2008 06:51:51 -0600 Subject: [PATCH] Make region deletion undoable. --- Audio_Track.C | 6 +----- Region.C | 16 ++++++++++++++++ Region.H | 36 +++++++++++++++++++++--------------- Track.C | 4 ++-- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Audio_Track.C b/Audio_Track.C index 9d80bf4..5b51c59 100644 --- a/Audio_Track.C +++ b/Audio_Track.C @@ -87,11 +87,7 @@ Audio_Track::handle ( int m ) return 0; } - Region *r = new Region( c ); - - r->offset( timeline->x_to_ts( Fl::event_x() ) ); - - this->add( r ); + Region *r = new Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() ) ); redraw(); return 1; diff --git a/Region.C b/Region.C index 1292b9b..e115dee 100644 --- a/Region.C +++ b/Region.C @@ -91,6 +91,7 @@ Region::init ( void ) _color = FL_BLUE; } +/* copy constructor */ Region::Region ( const Region & rhs ) { _offset = rhs._offset; @@ -103,6 +104,7 @@ Region::Region ( const Region & rhs ) log_create(); } +/* */ Region::Region ( Audio_File *c ) { init(); @@ -113,6 +115,20 @@ Region::Region ( Audio_File *c ) } +/* used when DND importing */ +Region::Region ( Audio_File *c, Track *t, nframes_t o ) +{ + init(); + _clip = c; + _end = _clip->length(); + _track = t; + _offset = o; + + _track->add( this ); + + log_create(); +} + void Region::trim ( enum trim_e t, int X ) { diff --git a/Region.H b/Region.H index 0ef846d..1f7016e 100644 --- a/Region.H +++ b/Region.H @@ -63,11 +63,12 @@ protected: char ** log_dump ( void ) { // char *r; - char **sa = (char**)malloc( sizeof( char* ) * 7 ); + char **sa = (char**)malloc( sizeof( char* ) * 8 ); int i = 0; - asprintf( &sa[ i++ ], ":source \"%s\"", _clip->name() ); + asprintf( &sa[ i++ ], ":source \"%s\"", _clip ? _clip->name() : "" ); + asprintf( &sa[ i++ ], ":track 0x%X", _track ? _track->id() : 0 ); asprintf( &sa[ i++ ], ":x %lu", _offset ); asprintf( &sa[ i++ ], ":l %lu", _start ); asprintf( &sa[ i++ ], ":r %lu", _end ); @@ -75,9 +76,6 @@ protected: asprintf( &sa[ i++ ], ":gain %f", _scale ); sa[ i ] = NULL; -// asprintf( &sa[4], ":track 0x%X", _track->id() ); - -// asprintf( &r, ":x %lu\n:l %lu\n:r %lu\n:selected %d\n:gain %f", _offset, _start, _end, _selected, _scale ); return sa; } @@ -115,18 +113,23 @@ protected: _scale = atof( v ); else if ( ! strcmp( s, ":source" ) ) - _clip = Audio_File::from_file( v ); -/* else */ -/* if ( ! strcmp( s, ":track" ) ) */ -/* { */ -/* int i; */ -/* sscanf( v, "%X", &i ); */ -/* Track *t = (Track*)Loggable::find( i ); */ + { + if ( ! ( _clip = Audio_File::from_file( v ) ) ) + { + printf( "Grave error: could not open source \"%s\"\n", v ); + } + } + else + if ( ! strcmp( s, ":track" ) ) + { + int i; + sscanf( v, "%X", &i ); + Track *t = (Track*)Loggable::find( i ); -/* assert( t ); */ + assert( t ); -/* t->add( this ); */ -/* } */ + t->add( this ); + } free( s ); @@ -153,6 +156,8 @@ public: r->set( sa ); + r->log_create(); + return (Loggable *)r; } @@ -167,6 +172,7 @@ public: Region ( const Region & rhs ); Region ( Audio_File *c ); + Region ( Audio_File *c, Track *t, nframes_t o ); int handle ( int m ); void draw_box( int X, int Y, int W, int H ); diff --git a/Track.C b/Track.C index 4850256..ad2dfc5 100644 --- a/Track.C +++ b/Track.C @@ -76,7 +76,7 @@ Track::draw ( void ) void Track::remove ( Track_Widget *r ) { - Logger _log( this ); +// Logger _log( this ); _widgets.remove( r ); } @@ -96,7 +96,7 @@ Track::event_widget ( void ) void Track::add ( Track_Widget *r ) { - Logger _log( this ); +// Logger _log( this ); if ( r->track() ) {