From cc39d05c7af956c3acc47fab16efd4f8bc25c319 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 24 Feb 2008 07:28:55 -0600 Subject: [PATCH] Improve journaling. --- Loggable.C | 27 +++++++++++++++++++++------ Loggable.H | 39 +++++++++++++++++++++++++++++++++++++++ Region.C | 19 ++++++++++++++++--- Tempo_Point.H | 14 +++++++++++--- Time_Point.H | 15 ++++++++++++--- Timeline.H | 2 +- Track.C | 4 +--- Track_Point.H | 8 -------- Track_Widget.H | 21 ++++++++++++--------- 9 files changed, 113 insertions(+), 36 deletions(-) diff --git a/Loggable.C b/Loggable.C index 22e2323..59ead6c 100644 --- a/Loggable.C +++ b/Loggable.C @@ -129,17 +129,22 @@ log_diff ( char **sa1, char **sa2 ) void Loggable::log_start ( void ) { -// if ( _old_state ) - // log_end(); - if ( _old_state ) - return; + if ( ! _old_state ) + _old_state = log_dump(); + + ++_nest; - _old_state = log_dump(); } void Loggable::log_end ( void ) { + + if ( --_nest > 0 ) + return; + +// assert( _old_state ); + char **_new_state = log_dump(); // if ( _old_state ) @@ -152,11 +157,21 @@ Loggable::log_end ( void ) log_print( _old_state, _new_state ); } - free_sa( _old_state ); if ( _new_state ) free_sa( _new_state ); + if ( _old_state ) + free_sa( _old_state ); + _old_state = NULL; + +/* if ( _old_state ) */ +/* { */ +/* free_sa( _old_state ); */ +/* _old_state = NULL; */ +/* } */ + +// _old_state = NULL; } void diff --git a/Loggable.H b/Loggable.H index 51e6537..68d302e 100644 --- a/Loggable.H +++ b/Loggable.H @@ -29,6 +29,7 @@ #include using std::vector; +class Logger; class Loggable { @@ -44,6 +45,7 @@ private: char **_old_state; char **_new_state; + int _nest; static void indent ( void ) @@ -89,6 +91,7 @@ public: { _id = ++_log_id; _old_state = NULL; + _nest = 0; _loggables.push_back( this ); } @@ -115,8 +118,44 @@ public: int id ( void ) { return _id; } + friend class Logger; }; + +class Logger +{ + + Loggable *_this; + Logger ( ) {} + +public: + + Logger ( Loggable *l ) : _this( l ) + { + _this->log_start(); + + } + + ~Logger ( ) + { + _this->log_end(); + } + + void hold ( void ) + { + printf( "hold\n" ); + _this->_nest++; + } + + void release ( void ) + { + printf( "release\n" ); + _this->_nest--; + assert( _this->_nest ); + } +}; + + /* #ifndef _LOGGABLE_C */ /* #define log( act, fmt, args... ) log( __CLASS__, act, fmt, ## args ) */ /* #endif */ diff --git a/Region.C b/Region.C index 580bcba..7963c52 100644 --- a/Region.C +++ b/Region.C @@ -144,6 +144,7 @@ Region::trim ( enum trim_e t, int X ) int Region::handle ( int m ) { + static bool dragging = false; static int ox, oy; static enum trim_e trimming; @@ -156,7 +157,8 @@ Region::handle ( int m ) int ret; - log_start(); + Logger _log( this ); +//log_start(); switch ( m ) { @@ -170,9 +172,11 @@ Region::handle ( int m ) { case 1: trim( trimming = LEFT, X ); +// _log.hold(); break; case 3: trim( trimming = RIGHT, X ); +// _log.hold(); break; case 2: { @@ -240,10 +244,19 @@ Region::handle ( int m ) { trimming = NO; } - printf( "releasing\n"); + if ( dragging ) + _log.release(); + + dragging = false; goto changed; case FL_DRAG: + if ( ! dragging ) + { + _log.hold(); + dragging = true; + } + if ( Fl::event_state() & FL_SHIFT && Fl::event_state() & FL_CTRL ) { @@ -307,7 +320,7 @@ Region::handle ( int m ) changed: - log_end(); +// log_end(); return 1; } diff --git a/Tempo_Point.H b/Tempo_Point.H index 01f7690..855312a 100644 --- a/Tempo_Point.H +++ b/Tempo_Point.H @@ -40,9 +40,17 @@ protected: const char *class_name ( void ) { return "Tempo_Point"; } -/* void log_create ( void ) { log( "create", "%lu %f", _offset, _tempo ); } */ -/* void log_destroy ( void ) { log( "destroy", NULL ); } */ -/* void log_move ( void ) { log( "move", "%lu", _offset ); } */ + char ** log_dump ( void ) + { + char **sa = (char**)malloc( sizeof( char* ) * 3 ); + + sa[2] = NULL; + + asprintf( &sa[0], ":x %lu", _offset ); + asprintf( &sa[1], ":tempo %f", _tempo ); + + return sa; + } public: diff --git a/Time_Point.H b/Time_Point.H index aa63289..794fab0 100644 --- a/Time_Point.H +++ b/Time_Point.H @@ -54,9 +54,18 @@ protected: const char *class_name ( void ) { return "Time_Point"; } -/* void log_create ( void ) { log( "create", "%lu %d %d", _offset, _time.beats_per_bar, _time.note_type ); } */ -/* void log_destroy ( void ) { log( "destroy", NULL ); } */ -/* void log_move ( void ) { log( "move", "%lu", _offset ); } */ + char ** log_dump ( void ) + { + char **sa = (char**)malloc( sizeof( char* ) * 4 ); + + sa[3] = NULL; + + asprintf( &sa[0], ":x %lu", _offset ); + asprintf( &sa[1], ":beats_per_bar %d", _time.beats_per_bar ); + asprintf( &sa[2], ":beat_type %d", _time.note_type ); + + return sa; + } public: diff --git a/Timeline.H b/Timeline.H index d72d023..3171f3d 100644 --- a/Timeline.H +++ b/Timeline.H @@ -179,7 +179,7 @@ struct Timeline : public Fl_Group if ( damage() & FL_DAMAGE_SCROLL ) { - printf( "doing scroll\n" ); +// printf( "doing scroll\n" ); int dx = ts_to_x( _old_position ) - ts_to_x( xoffset ); fl_scroll( X, tracks->y(), W, tracks->h(), dx, 0, draw_clip, this ); diff --git a/Track.C b/Track.C index 40a1e01..e4ecace 100644 --- a/Track.C +++ b/Track.C @@ -88,7 +88,7 @@ Track::event_widget ( void ) void Track::add ( Track_Widget *r ) { - log_start(); + Logger _log( this ); if ( r->track() ) { @@ -99,8 +99,6 @@ Track::add ( Track_Widget *r ) _widgets.push_back( r ); r->track( this ); - - log_end(); } /* snap /r/ to nearest edge */ diff --git a/Track_Point.H b/Track_Point.H index ef43bd9..6a6110f 100644 --- a/Track_Point.H +++ b/Track_Point.H @@ -32,14 +32,6 @@ protected: { } - char ** log_dump ( void ) - { - return NULL; - } - void log_change ( void ) - { - } - public: Fl_Align align ( void ) const { return FL_ALIGN_RIGHT; } diff --git a/Track_Widget.H b/Track_Widget.H index 632e77d..8d728d7 100644 --- a/Track_Widget.H +++ b/Track_Widget.H @@ -199,11 +199,13 @@ public: handle ( int m ) { static int ox, oy; - static bool moved = false; + static bool dragging = false; int X = Fl::event_x(); int Y = Fl::event_y(); + Logger _log( this ); + switch ( m ) { case FL_ENTER: @@ -230,16 +232,19 @@ public: return 1; } case FL_RELEASE: - if ( moved ) - { -// log_move(); - moved = false; - } -// dump(); + if ( dragging ) + _log.release(); + dragging = false; fl_cursor( FL_CURSOR_DEFAULT ); return 1; case FL_DRAG: { + if ( ! dragging ) + { + dragging = true; + _log.hold(); + } + redraw(); if ( ox + X >= _track->x() ) @@ -249,8 +254,6 @@ public: _offset = timeline->x_to_ts( nx ) + timeline->xoffset; _track->snap( this ); - - moved = true; } // _track->redraw();