Improve journaling.

pull/3/head
Jonathan Moore Liles 2008-02-24 07:28:55 -06:00
parent 0f9d79b3d8
commit cc39d05c7a
9 changed files with 113 additions and 36 deletions

View File

@ -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

View File

@ -29,6 +29,7 @@
#include <vector>
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 */

View File

@ -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;
}

View File

@ -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:

View File

@ -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:

View File

@ -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 );

View File

@ -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 */

View File

@ -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; }

View File

@ -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();