Oops. Write journal entries in proper order when generating snapshot.

This commit is contained in:
Jonathan Moore Liles 2008-08-03 22:54:22 -05:00
parent 174ca34382
commit 74ffa575d9
14 changed files with 109 additions and 42 deletions

View File

@ -75,10 +75,10 @@ Audio_Sequence::capture_region ( void ) const
void void
Audio_Sequence::get ( Log_Entry &e ) const Audio_Sequence::get ( Log_Entry &e ) const
{ {
e.add( ":track", _track ); e.add( ":track", _track );
e.add( ":name", name() ); e.add( ":name", name() );
} }
void void
Audio_Sequence::set ( Log_Entry &e ) Audio_Sequence::set ( Log_Entry &e )

View File

@ -56,6 +56,9 @@ std::queue <char *> Loggable::_transaction;
progress_func *Loggable::_progress_callback = NULL; progress_func *Loggable::_progress_callback = NULL;
void *Loggable::_progress_callback_arg = NULL; void *Loggable::_progress_callback_arg = NULL;
snapshot_func *Loggable::_snapshot_callback = NULL;
void *Loggable::_snapshot_callback_arg = NULL;
/** ensure that _loggables array is big enough for /n/ elements */ /** ensure that _loggables array is big enough for /n/ elements */
@ -419,6 +422,12 @@ Loggable::snapshot ( FILE *fp )
{ {
FILE *ofp = _fp; FILE *ofp = _fp;
if ( ! Loggable::_snapshot_callback )
{
DWARNING( "No snapshot callback defined" );
return false;
}
if ( ! ( _fp = fp ) ) if ( ! ( _fp = fp ) )
{ {
_fp = ofp; _fp = ofp;
@ -427,13 +436,7 @@ Loggable::snapshot ( FILE *fp )
block_start(); block_start();
for ( int i = 0; i < _log_id; ++i ) Loggable::_snapshot_callback( _snapshot_callback_arg );
{
const Loggable * l = _loggables[ i ];
if ( l && _class_map[ std::string( l->class_name() ) ] )
l->log_create();
}
block_end(); block_end();

View File

@ -34,6 +34,7 @@
#include "types.h" #include "types.h"
typedef void (progress_func)( int, void * ); typedef void (progress_func)( int, void * );
typedef void (snapshot_func)( void * );
class Log_Entry; class Log_Entry;
class Loggable; class Loggable;
@ -79,6 +80,9 @@ class Loggable
static progress_func *_progress_callback; static progress_func *_progress_callback;
static void *_progress_callback_arg; static void *_progress_callback_arg;
static snapshot_func *_snapshot_callback;
static void *_snapshot_callback_arg;
private: private:
int _id; int _id;
@ -124,6 +128,7 @@ private:
public: public:
static void snapshot_callback ( snapshot_func *p, void *arg ) { _snapshot_callback = p; _snapshot_callback_arg = arg; }
static void progress_callback ( progress_func *p, void *arg ) { _progress_callback = p; _progress_callback_arg = arg;} static void progress_callback ( progress_func *p, void *arg ) { _progress_callback = p; _progress_callback_arg = arg;}
static const char *escape ( const char *s ); static const char *escape ( const char *s );
@ -165,16 +170,17 @@ public:
virtual const char *class_name ( void ) const = 0; virtual const char *class_name ( void ) const = 0;
virtual void log_children ( void ) const { return; }
static bool do_this ( const char *s, bool reverse ); static bool do_this ( const char *s, bool reverse );
void log_create ( void ) const;
protected: protected:
void log_start ( void ); void log_start ( void );
void log_end ( void ); void log_end ( void );
void log_create ( void ) const;
void log_destroy ( void ) const; void log_destroy ( void ) const;
/* leaf subclasses *must* call log_create() at the end of their copy contructors */ /* leaf subclasses *must* call log_create() at the end of their copy contructors */

View File

@ -85,23 +85,25 @@ Sequence::~Sequence ( )
void
Sequence::log_children ( void ) const
{
if ( id() > 0 )
log_create();
for ( std::list <Sequence_Widget*>::const_iterator i = _widgets.begin();
i != _widgets.end(); ++i )
(*i)->log_create();
}
/** remove all widgets from this sequence */ /** remove all widgets from this sequence */
void void
Sequence::clear ( void ) Sequence::clear ( void )
{ {
Loggable::block_start(); Loggable::block_start();
for ( std::list <Sequence_Widget*>::iterator i = _widgets.begin(); while ( _widgets.size() )
i != _widgets.end(); ++i ) delete _widgets.front();
{
Sequence_Widget *w = *i;
*i = NULL;
delete w;
}
_widgets.clear();
Loggable::block_end(); Loggable::block_end();
} }
@ -137,6 +139,11 @@ Sequence::overlaps ( Sequence_Widget *r )
void void
Sequence::handle_widget_change ( nframes_t start, nframes_t length ) Sequence::handle_widget_change ( nframes_t start, nframes_t length )
{ {
timeline->wrlock();
sort();
timeline->unlock();
// timeline->update_length( start + length ); // timeline->update_length( start + length );
} }
@ -177,8 +184,6 @@ Sequence::add ( Sequence_Widget *r )
r->sequence( this ); r->sequence( this );
_widgets.push_back( r ); _widgets.push_back( r );
sort();
timeline->unlock(); timeline->unlock();
handle_widget_change( r->start(), r->length() ); handle_widget_change( r->start(), r->length() );

View File

@ -62,9 +62,10 @@ protected:
Sequence_Widget *widget_at ( nframes_t ts, int Y ); Sequence_Widget *widget_at ( nframes_t ts, int Y );
Sequence_Widget *event_widget ( void ); Sequence_Widget *event_widget ( void );
public: public:
virtual void log_children ( void ) const;
/* child classes should implement this if they need to take /* child classes should implement this if they need to take
special action when a widget is changed/moved/resized. /start/ special action when a widget is changed/moved/resized. /start/
and /length/ define the affected region */ and /length/ define the affected region */

View File

@ -135,7 +135,7 @@ Sequence_Widget::set ( Log_Entry &e )
sscanf( v, "%X", &i ); sscanf( v, "%X", &i );
Sequence *t = (Sequence*)Loggable::find( i ); Sequence *t = (Sequence*)Loggable::find( i );
assert( t ); ASSERT( t, "No such object ID (%s)", v );
t->add( this ); t->add( this );
} }
@ -144,8 +144,10 @@ Sequence_Widget::set ( Log_Entry &e )
} }
if ( _sequence ) if ( _sequence )
{
_sequence->handle_widget_change( _r->start, _r->length );
_sequence->redraw(); _sequence->redraw();
}
} }
void void

View File

@ -83,7 +83,11 @@ Tempo_Point::set ( Log_Entry &e )
_make_label(); _make_label();
} }
void
Tempo_Point::log_children ( void ) const
{
log_create();
}
int int
Tempo_Point::handle ( int m ) Tempo_Point::handle ( int m )

View File

@ -44,6 +44,7 @@ protected:
virtual void get ( Log_Entry &e ) const; virtual void get ( Log_Entry &e ) const;
void set ( Log_Entry &e ); void set ( Log_Entry &e );
void log_children ( void ) const;
Tempo_Point ( ); Tempo_Point ( );

View File

@ -93,6 +93,12 @@ Time_Point::set ( Log_Entry &e )
_make_label(); _make_label();
} }
void
Time_Point::log_children ( void ) const
{
log_create();
}
int int
Time_Point::handle ( int m ) Time_Point::handle ( int m )
{ {

View File

@ -57,6 +57,7 @@ protected:
virtual void get ( Log_Entry &e ) const; virtual void get ( Log_Entry &e ) const;
void set ( Log_Entry &e ); void set ( Log_Entry &e );
void log_children ( void ) const;
Time_Point ( ); Time_Point ( );

View File

@ -105,6 +105,20 @@ draw_full_arrow_symbol ( Fl_Color color )
/** callback used by Loggable class to create a snapshot of system
* state. */
void
Timeline::snapshot ( void )
{
tempo_track->log_children();
time_track->log_children();
for ( int i = 0; i < tracks->children(); ++i )
{
((Track*)tracks->child( i ))->log_children();
}
}
/** recalculate the size of vertical scrolling area and inform scrollbar */ /** recalculate the size of vertical scrolling area and inform scrollbar */
void void
Timeline::adjust_vscroll ( void ) Timeline::adjust_vscroll ( void )
@ -347,6 +361,8 @@ Timeline::ntracks ( void ) const
Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Window( X, Y, W, H, L ) Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Window( X, Y, W, H, L )
{ {
Loggable::snapshot_callback( &Timeline::snapshot, this );
_sample_rate = 0; _sample_rate = 0;
box( FL_FLAT_BOX ); box( FL_FLAT_BOX );

View File

@ -213,6 +213,9 @@ public:
private: private:
static void snapshot ( void *v ) { ((Timeline*)v)->snapshot(); }
void snapshot ( void );
friend class Engine; // FIXME: only Engine::process() needs to be friended.x friend class Engine; // FIXME: only Engine::process() needs to be friended.x
Track * track_by_name ( const char *name ); Track * track_by_name ( const char *name );

View File

@ -72,16 +72,6 @@ Track::Track ( ) : Fl_Group( 0, 0, 1, 1 )
timeline->add_track( this ); timeline->add_track( this );
} }
void
Track::solo ( bool b )
{
if ( b && ! solo_button->value() )
++_soloing;
else if ( ! b && solo_button->value() )
--_soloing;
solo_button->value( b );
}
Track::~Track ( ) Track::~Track ( )
{ {
@ -306,6 +296,33 @@ Track::get ( Log_Entry &e ) const
e.add( ":show-all-takes", _show_all_takes ); e.add( ":show-all-takes", _show_all_takes );
} }
void
Track::log_children ( void ) const
{
log_create();
for ( int i = control->children(); i--; )
((Sequence*)control->child( i ))->log_children();
for ( int i = annotation->children(); i--; )
((Sequence*)annotation->child( i ))->log_children();
for ( int i = takes->children(); i--; )
((Sequence*)takes->child( i ))->log_children();
sequence()->log_children();
}
void
Track::solo ( bool b )
{
if ( b && ! solo_button->value() )
++_soloing;
else if ( ! b && solo_button->value() )
--_soloing;
solo_button->value( b );
}
void void
Track::cb_input_field ( Fl_Widget *, void *v ) Track::cb_input_field ( Fl_Widget *, void *v )

View File

@ -108,6 +108,8 @@ protected:
public: public:
virtual void log_children ( void ) const;
Fl_Input *name_field; Fl_Input *name_field;
Fl_Button *record_button; Fl_Button *record_button;
Fl_Button *mute_button; Fl_Button *mute_button;