diff --git a/Timeline/Annotation_Sequence.H b/Timeline/Annotation_Sequence.H index 7f9bc62..01fe23c 100644 --- a/Timeline/Annotation_Sequence.H +++ b/Timeline/Annotation_Sequence.H @@ -24,7 +24,9 @@ #include "Annotation_Region.H" #include "Timeline.H" -class Annotation_Sequence : public Sequence, public Loggable +#include "Track.H" + +class Annotation_Sequence : public Sequence { protected: @@ -51,13 +53,14 @@ protected: assert( t ); - t->track( this ); + t->add( this ); } } } - Annotation_Sequence ( ) : Sequence ( 0, 0, 0, 0 ) + Annotation_Sequence ( ) : Sequence ( 0 ) { + color( fl_darker( FL_GREEN ) ); } public: @@ -67,20 +70,15 @@ public: Fl_Cursor cursor ( void ) const { return FL_CURSOR_INSERT; } - Annotation_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 ) + Annotation_Sequence ( Track *track ) : Sequence( track ) { - _track = track; - color( fl_darker( FL_GREEN ) ); log_create(); - -// labeltype( FL_NO_LABEL ); } - Annotation_Sequence ( int X, int Y, int W, int H ) : Sequence ( X, Y, W, H ) + Annotation_Sequence ( int X, int Y, int W, int H ) : Sequence ( 0 ) { -// box( FL_UP_BOX ); } ~Annotation_Sequence ( ) @@ -88,13 +86,6 @@ public: log_destroy(); } -/* void */ -/* draw ( void ) */ -/* { */ -/* // timeline->draw_measure_BBT( x(), y(), w(), h(), FL_WHITE ); */ -/* Sequence::draw(); */ -/* } */ - int handle ( int m ) { diff --git a/Timeline/Audio_Region.C b/Timeline/Audio_Region.C index 45b0b36..ed188cf 100644 --- a/Timeline/Audio_Region.C +++ b/Timeline/Audio_Region.C @@ -23,6 +23,7 @@ #include "Waveform.H" #include "Audio_Sequence.H" +#include "Track.H" #include "dsp.h" diff --git a/Timeline/Audio_Sequence.C b/Timeline/Audio_Sequence.C index 08c2920..a45917b 100644 --- a/Timeline/Audio_Sequence.C +++ b/Timeline/Audio_Sequence.C @@ -24,6 +24,68 @@ #include +#include "Track.H" + +Audio_Sequence::Audio_Sequence ( Track *track ) : Sequence( track ) +{ + + _track = track; + + if ( track ) + track->add( this ); + + log_create(); + + /* FIXME: temporary */ + labeltype( FL_NO_LABEL ); + +} + + +Audio_Sequence::~Audio_Sequence ( ) +{ + log_destroy(); +} + + +const Audio_Region * +Audio_Sequence::capture ( void ) const +{ + return track()->capture(); +} + +void +Audio_Sequence::get ( Log_Entry &e ) const + { + e.add( ":t", _track ); + e.add( ":n", name() ); + } + +void +Audio_Sequence::set ( Log_Entry &e ) +{ + for ( int i = 0; i < e.size(); ++i ) + { + const char *s, *v; + + e.get( i, &s, &v ); + + if ( ! strcmp( ":t", s ) ) + { + int i; + sscanf( v, "%X", &i ); + Track *t = (Track*)Loggable::find( i ); + + assert( t ); + + t->track( this ); + } + else if ( ! strcmp( ":n", s ) ) + name( strdup( v ) ); + } +} + + static void deurlify ( char *url ) diff --git a/Timeline/Audio_Sequence.H b/Timeline/Audio_Sequence.H index 2ec7901..6b115a4 100644 --- a/Timeline/Audio_Sequence.H +++ b/Timeline/Audio_Sequence.H @@ -21,76 +21,32 @@ #include "Sequence.H" #include "Audio_Region.H" -#include "Track.H" #include -class Audio_Sequence : public Sequence, public Loggable +class Audio_Sequence : public Sequence { protected: - virtual void get ( Log_Entry &e ) const - { - e.add( ":t", _track ); - e.add( ":n", name() ); - } + void get ( Log_Entry &e ) const; - void - set ( Log_Entry &e ) - { - for ( int i = 0; i < e.size(); ++i ) - { - const char *s, *v; + void set ( Log_Entry &e ); - e.get( i, &s, &v ); - - if ( ! strcmp( ":t", s ) ) - { - int i; - sscanf( v, "%X", &i ); - Track *t = (Track*)Loggable::find( i ); - - assert( t ); - - t->track( this ); - } - else if ( ! strcmp( ":n", s ) ) - name( strdup( v ) ); - } - } - - Audio_Sequence ( ) : Sequence( 0, 0, 0, 0 ) + Audio_Sequence ( ) : Sequence( 0 ) { } - public: LOG_CREATE_FUNC( Audio_Sequence ); Fl_Cursor cursor ( void ) const { return FL_CURSOR_DEFAULT; } - Audio_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0, track ) - { - _track = track; - - if ( track ) - track->add( this ); - - log_create(); - - /* FIXME: temporary */ - labeltype( FL_NO_LABEL ); - - } - - ~Audio_Sequence ( ) - { - log_destroy(); - } + Audio_Sequence ( Track *track ); + ~Audio_Sequence ( ); Sequence * clone_empty ( void ) @@ -107,7 +63,7 @@ public: void dump ( void ); void remove_selected ( void ); - const Audio_Region *capture ( void ) const { return track()->capture(); } + const Audio_Region *capture ( void ) const; nframes_t play ( sample_t *buf, nframes_t frame, nframes_t nframes, int channels ); diff --git a/Timeline/Control_Sequence.C b/Timeline/Control_Sequence.C index 62ba038..f7069fa 100644 --- a/Timeline/Control_Sequence.C +++ b/Timeline/Control_Sequence.C @@ -29,7 +29,7 @@ bool Control_Sequence::draw_with_gradient = true; bool Control_Sequence::draw_with_polygon = true; bool Control_Sequence::draw_with_grid = true; -Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 ) +Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0 ) { init(); diff --git a/Timeline/Control_Sequence.H b/Timeline/Control_Sequence.H index 1a58cfb..222d87c 100644 --- a/Timeline/Control_Sequence.H +++ b/Timeline/Control_Sequence.H @@ -23,7 +23,7 @@ #include "Control_Point.H" #include "Port.H" -class Control_Sequence : public Sequence, public Loggable +class Control_Sequence : public Sequence { public: @@ -46,7 +46,7 @@ protected: virtual void get ( Log_Entry &e ) const; void set ( Log_Entry &e ); - Control_Sequence ( ) : Sequence( 0, 0, 0, 1 ) + Control_Sequence ( ) : Sequence( 0 ) { init(); } diff --git a/Timeline/Loggable.C b/Timeline/Loggable.C index e005d15..e6a64d8 100644 --- a/Timeline/Loggable.C +++ b/Timeline/Loggable.C @@ -249,14 +249,7 @@ Loggable::do_this ( const char *s, bool reverse ) Log_Entry e( sa ); - - - - assert( _class_map[ string( classname ) ] ); - -/* if ( ! _class_map[ string( classname ) ] ) */ -/* printf( "error class %s is unregistered!\n", classname ); */ -/* else */ + ASSERT( _class_map[ string( classname ) ], "Journal contains an object of class \"%s\", but I don't know how to create such objects.", classname ); { /* create */ diff --git a/Timeline/Loggable.H b/Timeline/Loggable.H index fe6df6d..0a5cc19 100644 --- a/Timeline/Loggable.H +++ b/Timeline/Loggable.H @@ -37,23 +37,22 @@ using namespace std; #include "debug.h" /* welcome to C++ */ -class Loggable_ID -{ +/* This class is just a dummy to allow base classes with null ids but + * whose children are really loggable. */ -protected: +/* class Loggable_ID */ +/* { */ - int _id; +/* public: */ -public: +/* Loggable_ID ( ) { } */ +/* virtual ~Loggable_ID ( ) { } */ - Loggable_ID ( ) : _id( 0 ) { } - virtual ~Loggable_ID ( ) { } +/* virtual int id ( void ) const = 0; */ - int id ( void ) { return _id; } +/* virtual const char *class_name ( void ) const = 0; */ - virtual const char *class_name ( void ) const = 0; - -}; +/* }; */ class Log_Entry; class Loggable; @@ -77,8 +76,11 @@ typedef Loggable *(create_func)(Log_Entry &); LOG_NAME_FUNC( class ); \ +#define LOG_NOT_LOGGABLE_FUNC( class ) \ + virtual const char *class_name ( void ) const { return #class ; } \ + class Logger; -class Loggable : public Loggable_ID +class Loggable { static FILE *_fp; @@ -94,6 +96,7 @@ class Loggable : public Loggable_ID private: + int _id; char **_old_state; char **_new_state; @@ -117,6 +120,8 @@ private: public: + int id ( void ) const { return _id; } + static bool open ( const char *filename ); static bool close ( void ); static void undo ( void ); @@ -150,13 +155,19 @@ public: return _loggables[ id - 1 ]; } - Loggable ( ) + Loggable ( bool loggable=true ) { - _id = ++_log_id; - _old_state = NULL; - _nest = 0; + if ( loggable ) + { + _id = ++_log_id; + _old_state = NULL; + _nest = 0; + + _loggables.push_back( this ); + } + else + _id = 0; - _loggables.push_back( this ); } /** must be called after construction in create() methods */ @@ -201,6 +212,9 @@ public: virtual void get ( Log_Entry &e ) const = 0; virtual void set ( Log_Entry &e ) = 0; + virtual const char *class_name ( void ) const = 0; + + static bool do_this ( const char *s, bool reverse ); protected: @@ -356,7 +370,7 @@ public: ADD( nframes_t, "%lu", (unsigned long)v ); ADD( unsigned long, "%lu", v ); ADD( const char *, "\"%s\"", v ? v : "" ); - ADD( Loggable_ID *, "0x%X", v ? v->id() : 0 ); + ADD( Loggable * , "0x%X", v ? v->id() : 0 ); ADD( float, "%f", v ); ADD( double, "%f", v ); diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index 76897e5..41f40a6 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -30,20 +30,30 @@ queue Sequence::_delete_queue; -Sequence::Sequence ( int X, int Y, int W, int H, Track *track ) : Fl_Widget( X, Y, W, H ) +Sequence::Sequence ( Track *track ) : Fl_Widget( 0, 0, 0, 0 ), Loggable( true ) { - _name = NULL; + init(); + _track = track; -/* if ( track ) */ -/* track->add( this ); */ +// log_create(); +} + +Sequence::Sequence ( int X, int Y, int W, int H ) : Fl_Widget( X, Y, W, H ), Loggable( false ) +{ + init(); +} + +void +Sequence::init ( void ) +{ + _track = NULL; + + _name = NULL; box( FL_DOWN_BOX ); -// color( fl_darker( FL_GRAY ) ); color( FL_BACKGROUND_COLOR ); align( FL_ALIGN_LEFT ); - -// log_create(); } Sequence::~Sequence ( ) diff --git a/Timeline/Sequence.H b/Timeline/Sequence.H index f0d4da0..c57dd72 100644 --- a/Timeline/Sequence.H +++ b/Timeline/Sequence.H @@ -38,11 +38,13 @@ class Sequence_Widget; /* This is the base class for all track types. */ -class Sequence : public Fl_Widget, public Loggable_ID +class Sequence : public Fl_Widget, public Loggable { static queue _delete_queue; + void init ( void ); + protected: Track *_track; /* track this sequence belongs to */ @@ -58,7 +60,8 @@ public: /* welcome to C++ */ LOG_NAME_FUNC( Sequence ); - Sequence ( int X, int Y, int W, int H, Track *track=0 ); + Sequence ( Track *track=0 ); + Sequence ( int X, int Y, int W, int H ); virtual ~Sequence ( ); diff --git a/Timeline/Sequence_Region.H b/Timeline/Sequence_Region.H index 0f61fba..063925e 100644 --- a/Timeline/Sequence_Region.H +++ b/Timeline/Sequence_Region.H @@ -56,7 +56,7 @@ protected: Sequence_Region ( ) { - + color( FL_CYAN ); } virtual ~Sequence_Region ( ) diff --git a/Timeline/Tempo_Sequence.H b/Timeline/Tempo_Sequence.H index 0548f7f..a2840ee 100644 --- a/Timeline/Tempo_Sequence.H +++ b/Timeline/Tempo_Sequence.H @@ -27,6 +27,12 @@ class Tempo_Sequence : public Sequence { +protected: + + /* not used */ + void get ( Log_Entry &e ) const { } + void set ( Log_Entry &e ) { } + public: Fl_Cursor cursor ( void ) const { return FL_CURSOR_DEFAULT; } diff --git a/Timeline/Time_Sequence.H b/Timeline/Time_Sequence.H index 52f96b4..09c6768 100644 --- a/Timeline/Time_Sequence.H +++ b/Timeline/Time_Sequence.H @@ -28,6 +28,12 @@ using std::list; class Time_Sequence : public Sequence { +protected: + + /* not used */ + void get ( Log_Entry &e ) const { } + void set ( Log_Entry &e ) { } + public: Fl_Cursor cursor ( void ) const { return FL_CURSOR_DEFAULT; } diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index a2fd69d..aed647f 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -918,7 +918,7 @@ Timeline::handle ( int m ) Track *t = new Track( name ); - Sequence *o = new Audio_Sequence( t ); + Audio_Sequence *o = new Audio_Sequence( t ); // new Control_Sequence( t ); diff --git a/Timeline/Track.C b/Timeline/Track.C index 545c609..d32f6f7 100644 --- a/Timeline/Track.C +++ b/Timeline/Track.C @@ -93,7 +93,7 @@ Track::cb_button ( Fl_Widget *w ) show_all_takes( take_menu->menu()[ v ].value() ); return; case 1: /* new */ - track( track()->clone_empty() ); + track( (Audio_Sequence*)track()->clone_empty() ); return; } @@ -101,7 +101,7 @@ Track::cb_button ( Fl_Widget *w ) for ( int i = takes->children(); i--; ) { - Sequence *t = (Sequence*)takes->child( i ); + Audio_Sequence *t = (Audio_Sequence*)takes->child( i ); if ( ! strcmp( s, t->name() ) ) { track( t ); @@ -319,7 +319,7 @@ Track::size ( int v ) void -Track::add ( Sequence * t ) +Track::add ( Audio_Sequence * t ) { takes->insert( *t, 0 ); if ( ! t->name() ) @@ -335,7 +335,7 @@ Track::add ( Sequence * t ) } void -Track::remove ( Sequence *t ) +Track::remove ( Audio_Sequence *t ) { takes->remove( t ); @@ -353,7 +353,7 @@ Track::remove ( Control_Sequence *t ) } void -Track::track ( Sequence * t ) +Track::track ( Audio_Sequence * t ) { t->track( this ); @@ -441,12 +441,13 @@ Track::draw ( void ) int Track::handle ( int m ) { - Logger log( this ); switch ( m ) { case FL_MOUSEWHEEL: { + Logger log( this ); + if ( ! Fl::event_shift() ) return 0; @@ -463,6 +464,7 @@ Track::handle ( int m ) } case FL_PUSH: { + Logger log( this ); int X = Fl::event_x(); int Y = Fl::event_y(); diff --git a/Timeline/Track.H b/Timeline/Track.H index 5e0d95f..86ed8fc 100644 --- a/Timeline/Track.H +++ b/Timeline/Track.H @@ -48,6 +48,11 @@ class Port; class Audio_Region; class Audio_File; + +//class Audio_Sequence; + +#include "Audio_Sequence.H" + class Track : public Fl_Group, public Loggable { @@ -74,7 +79,7 @@ private: enum { AUDIO } _type; - Sequence *_track; + Audio_Sequence *_track; Audio_Region *_capture; /* capture region */ Audio_File *_capture_af; /* capture write source */ @@ -157,7 +162,7 @@ public: if ( i ) { - Sequence *t = (Sequence*)Loggable::find( i ); + Audio_Sequence *t = (Audio_Sequence*)Loggable::find( i ); /* FIXME: our track might not have been * defined yet... what should we do about this @@ -192,8 +197,8 @@ public: void remove ( Annotation_Sequence *t ); void add ( Control_Sequence *t ); - void add ( Sequence *t ); - void remove ( Sequence *t ); + void add ( Audio_Sequence *t ); + void remove ( Audio_Sequence *t ); void remove ( Control_Sequence *t ); void select ( int X, int Y, int W, int H, bool include_control, bool merge_control ); @@ -243,8 +248,8 @@ public: static int width ( void ) { return 150; } - void track( Sequence * t ); - Sequence * track ( void ) const { return _track; } + void track ( Audio_Sequence * t ); + Audio_Sequence * track ( void ) const { return _track; } void draw ( void ); int handle ( int m ); diff --git a/Timeline/main.C b/Timeline/main.C index eb2d4b6..e70fb41 100644 --- a/Timeline/main.C +++ b/Timeline/main.C @@ -90,6 +90,7 @@ main ( int argc, char **argv ) LOG_REGISTER_CREATE( Time_Point ); LOG_REGISTER_CREATE( Tempo_Point ); LOG_REGISTER_CREATE( Annotation_Point ); + LOG_REGISTER_CREATE( Annotation_Region ); LOG_REGISTER_CREATE( Control_Point ); LOG_REGISTER_CREATE( Track ); LOG_REGISTER_CREATE( Audio_Sequence );