| @@ -28,8 +28,68 @@ | |||
| class Audio_Sequence : public Sequence | |||
| { | |||
| protected: | |||
| /* void set ( char **sa ) */ | |||
| /* { */ | |||
| /* for ( int i = 0; sa[i]; ++i ) */ | |||
| /* { */ | |||
| /* char *s = sa[i]; */ | |||
| /* char *v = s + strlen( s ) + 1; */ | |||
| /* else if ( ! strcmp( s, ":name" ) ) */ | |||
| /* { */ | |||
| /* if ( _name ) */ | |||
| /* free( _name ); */ | |||
| /* _name = strdup( v ); */ | |||
| /* } */ | |||
| /* else if ( ! strcmp( s, ":track" ) ) */ | |||
| /* { */ | |||
| /* int i; */ | |||
| /* sscanf( v, "%X", &i ); */ | |||
| /* if ( i ) */ | |||
| /* { */ | |||
| /* Sequence *t = (Sequence*)Loggable::find( i ); */ | |||
| /* assert( t ); */ | |||
| /* track( t ); */ | |||
| /* } */ | |||
| /* } */ | |||
| /* free( s ); */ | |||
| /* } */ | |||
| /* free( sa ); */ | |||
| /* } */ | |||
| /* char ** get ( void ) */ | |||
| /* { */ | |||
| /* char **sa = (char**)malloc( sizeof( char* ) * (1 + 1) ); */ | |||
| /* int i = 0; */ | |||
| /* asprintf( &sa[ i++ ], ":name \"%s\"", _name ? _name : "" ); */ | |||
| /* // asprintf( &sa[ i++ ], ":track 0x%X", track() ? track()->id() : 0 ); */ | |||
| /* sa[ i ] = NULL; */ | |||
| /* return sa; */ | |||
| /* } */ | |||
| Audio_Sequence ( ) : Sequence( 0, 0, 0, 0 ) | |||
| { | |||
| } | |||
| public: | |||
| LOG_CREATE_FUNC( Audio_Sequence ); | |||
| Audio_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H ) | |||
| { | |||
| log_create(); | |||
| @@ -38,60 +38,29 @@ protected: | |||
| const char *class_name ( void ) { return "Control_Point"; } | |||
| char ** get ( void ) | |||
| void | |||
| get ( Log_Entry &e ) | |||
| { | |||
| char **sa = (char**)malloc( sizeof( char* ) * 4 ); | |||
| int i = 0; | |||
| asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
| asprintf( &sa[i++], ":y %.2f", _y ); | |||
| asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 ); | |||
| sa[i] = NULL; | |||
| return sa; | |||
| e.add( ":y", _y ); | |||
| } | |||
| void | |||
| set ( char **sa ) | |||
| set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| const char *s, *v; | |||
| strtok( s, " " ); | |||
| e.get( i, &s, &v ); | |||
| char *v = s + strlen( s ) + 1; | |||
| if ( ! strcmp( s, ":y" ) ) | |||
| _y = atof( v ); | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| else | |||
| if ( ! strcmp( s, ":y" ) ) | |||
| _y = atof( v ); | |||
| else | |||
| if ( ! strcmp( s, ":track" ) ) | |||
| { | |||
| int i; | |||
| sscanf( v, "%X", &i ); | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| timeline->redraw(); | |||
| assert( t ); | |||
| t->add( this ); | |||
| t->sort(); | |||
| } | |||
| free( s ); | |||
| // _make_label(); | |||
| } | |||
| free( sa ); | |||
| timeline->redraw(); | |||
| // _make_label(); | |||
| } | |||
| Control_Point ( ) | |||
| @@ -101,17 +70,14 @@ protected: | |||
| public: | |||
| /* for loggable */ | |||
| static Loggable * | |||
| create ( char **sa ) | |||
| { | |||
| Control_Point *r = new Control_Point; | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| /* Sequence_Widget * */ | |||
| /* clone ( const Sequence_Widget *r ) */ | |||
| /* { */ | |||
| /* return new Control_Point( *(Control_Point*)r ); */ | |||
| /* } */ | |||
| /* for loggable */ | |||
| LOG_CREATE_FUNC( Control_Point ); | |||
| Control_Point ( Sequence *t, nframes_t when, float y ) | |||
| { | |||
| @@ -183,7 +149,7 @@ public: | |||
| /* { */ | |||
| /* } */ | |||
| void | |||
| void | |||
| draw ( int X, int Y, int W, int H ) | |||
| { | |||
| @@ -25,8 +25,14 @@ | |||
| class Control_Sequence : public Sequence | |||
| { | |||
| Control_Sequence ( ) : Sequence( 0, 0, 1, 1 ) | |||
| { | |||
| } | |||
| public: | |||
| LOG_CREATE_FUNC( Control_Sequence ); | |||
| Control_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H ) | |||
| { | |||
| @@ -38,7 +38,9 @@ queue <char *> Loggable::_transaction; | |||
| bool | |||
| Loggable::open ( const char *filename ) | |||
| { | |||
| if ( ! ( Loggable::_fp = fopen( filename, "a+" ) ) ) | |||
| FILE *fp; | |||
| if ( ! ( fp = fopen( filename, "a+" ) ) ) | |||
| { | |||
| printf( "Could not open log file for writing!" ); | |||
| return false; | |||
| @@ -46,19 +48,19 @@ Loggable::open ( const char *filename ) | |||
| /* TODO: replay log here */ | |||
| /* FIXME: handle transactions!!! */ | |||
| { | |||
| char buf[BUFSIZ]; | |||
| while ( fscanf( _fp, "%[^\n]\n", buf ) == 1 ) | |||
| while ( fscanf( fp, "%[^\n]\n", buf ) == 1 ) | |||
| { | |||
| do_this( buf, false ); | |||
| } | |||
| } | |||
| Loggable::_fp = fp; | |||
| return true; | |||
| } | |||
| @@ -101,6 +103,19 @@ parse_alist( const char *s ) | |||
| pair[ l ] = '\0'; | |||
| r[ i++ ] = pair; | |||
| /* split */ | |||
| strtok( pair, " " ); | |||
| /* remove quotes */ | |||
| char *v = pair + strlen( pair ) + 1; | |||
| if ( *v == '"' ) | |||
| { | |||
| v++; | |||
| v[ strlen( v ) - 2 ] = '\0'; | |||
| } | |||
| } | |||
| c = s; | |||
| @@ -168,20 +183,24 @@ Loggable::do_this ( const char *s, bool reverse ) | |||
| char **sa = parse_alist( arguments ); | |||
| Log_Entry e( sa ); | |||
| l->log_start(); | |||
| l->set( sa ); | |||
| l->set( e ); | |||
| l->log_end(); | |||
| } | |||
| else if ( ! strcmp( command, create ) ) | |||
| { | |||
| char **sa = parse_alist( arguments ); | |||
| Log_Entry e( sa ); | |||
| if ( ! _class_map[ string( classname ) ] ) | |||
| printf( "error class %s is unregistered!\n", classname ); | |||
| else | |||
| { | |||
| /* create */ | |||
| Loggable *l = _class_map[ string( classname ) ]( sa ); | |||
| Loggable *l = _class_map[ string( classname ) ]( e ); | |||
| l->update_id( id ); | |||
| l->log_create(); | |||
| } | |||
| @@ -436,8 +455,13 @@ void | |||
| Loggable::log_start ( void ) | |||
| { | |||
| if ( ! _old_state ) | |||
| _old_state = get(); | |||
| { | |||
| Log_Entry e; | |||
| get( e ); | |||
| _old_state = e.sa(); | |||
| } | |||
| ++_nest; | |||
| _undo_index = 1; | |||
| @@ -450,7 +474,15 @@ Loggable::log_end ( void ) | |||
| if ( --_nest > 0 ) | |||
| return; | |||
| char **_new_state = get(); | |||
| char **_new_state; | |||
| { | |||
| Log_Entry e; | |||
| get( e ); | |||
| _new_state = e.sa(); | |||
| } | |||
| if ( log_diff( _old_state, _new_state ) ) | |||
| { | |||
| @@ -478,7 +510,13 @@ Loggable::log_create ( void ) | |||
| // indent(); | |||
| log( "%s 0x%X create ", class_name(), _id ); | |||
| char **sa = get(); | |||
| char **sa; | |||
| Log_Entry e; | |||
| get( e ); | |||
| sa = e.sa(); | |||
| if ( sa ) | |||
| { | |||
| @@ -498,7 +536,13 @@ Loggable::log_destroy ( void ) | |||
| // indent(); | |||
| log( "%s 0x%X destroy (nothing) << ", class_name(), _id ); | |||
| char **sa = get(); | |||
| char **sa; | |||
| Log_Entry e; | |||
| get( e ); | |||
| sa = e.sa(); | |||
| // log_print( sa, NULL ); | |||
| log_print( NULL, sa ); | |||
| @@ -32,9 +32,29 @@ | |||
| #include <queue> | |||
| using namespace std; | |||
| #include "types.h" | |||
| class Log_Entry; | |||
| class Loggable; | |||
| typedef Loggable *(create_func)(char **); | |||
| typedef Loggable *(create_func)(Log_Entry &); | |||
| /* struct Pair */ | |||
| /* { */ | |||
| /* const char *name; */ | |||
| /* const char *value; */ | |||
| /* }; */ | |||
| #define LOG_CREATE_FUNC( class ) \ | |||
| static Loggable * \ | |||
| create ( Log_Entry &e ) \ | |||
| { \ | |||
| class *r = new class; \ | |||
| r->set( e ); \ | |||
| return (Loggable *)r; \ | |||
| } \ | |||
| class Logger; | |||
| class Loggable | |||
| @@ -152,13 +172,8 @@ public: | |||
| /* log messages for journal */ | |||
| virtual const char *class_name ( void ) = 0; | |||
| virtual char ** get ( void ) = 0; | |||
| /* this method must parse an array of name/value pair strings and make the appropriate changes too | |||
| the object state */ | |||
| virtual void set ( char **sa ) = 0; | |||
| // void log ( const char *module, const char *action, const char *fmt, ... ); | |||
| virtual void get ( Log_Entry &e ) = 0; | |||
| virtual void set ( Log_Entry &e ) = 0; | |||
| static bool do_this ( const char *s, bool reverse ); | |||
| @@ -212,9 +227,104 @@ public: | |||
| }; | |||
| /* #ifndef _LOGGABLE_C */ | |||
| /* #define log( act, fmt, args... ) log( __CLASS__, act, fmt, ## args ) */ | |||
| /* #endif */ | |||
| /* #define LOG_START Logger _logger( this ) */ | |||
| /* #define LOG_END _logger.print( this ) */ | |||
| class Log_Entry | |||
| { | |||
| // vector <Pair> _sa; | |||
| char **_sa; | |||
| int _i; | |||
| public: | |||
| Log_Entry ( ) | |||
| { | |||
| _sa = (char**)malloc( sizeof( char * ) ); | |||
| *_sa = NULL; | |||
| _i = 0; | |||
| } | |||
| Log_Entry ( char **sa ) | |||
| { | |||
| _sa = _sa; | |||
| for ( _i = 0; _sa[ _i ]; ++_i ); | |||
| } | |||
| ~Log_Entry ( ) | |||
| { | |||
| if ( ! _sa ) | |||
| return; | |||
| for ( _i = 0; _sa[ _i ]; ++_i ) | |||
| { | |||
| free( _sa[ _i ] ); | |||
| } | |||
| free( _sa ); | |||
| } | |||
| /****************/ | |||
| /* Construction */ | |||
| /****************/ | |||
| void grow ( ) | |||
| { | |||
| _sa = (char**)realloc( _sa, sizeof( char * ) * (_i + 2) ); | |||
| _sa[ _i ] = NULL; | |||
| } | |||
| #define ADD( type, format, exp ) \ | |||
| void add ( const char *name, type v ) \ | |||
| { \ | |||
| grow(); \ | |||
| asprintf( &_sa[ _i++ ], "%s " format, name, (exp) ); \ | |||
| } \ | |||
| /***************/ | |||
| /* Examination */ | |||
| /***************/ | |||
| int size ( void ) const | |||
| { | |||
| return _i; | |||
| } | |||
| void get ( int n, const char **name, const char **value ) | |||
| { | |||
| *name = _sa[ n ]; | |||
| *value = *name + strlen( *name ) + 1; | |||
| } | |||
| char **sa ( void ) | |||
| { | |||
| char **sa = _sa; | |||
| _sa = NULL; | |||
| return sa; | |||
| } | |||
| /* #define ADD ( type, format, exp ) \ */ | |||
| /* void add ( const char *name, type v ) \ */ | |||
| /* { \ */ | |||
| /* char pat[ 256 ]; \ */ | |||
| /* Pair p; \ */ | |||
| /* p.name = strdup( name ); \ */ | |||
| /* snprintf( pat, sizeof( pat ), format, exp ); \ */ | |||
| /* p.value = strdup( pat ); \ */ | |||
| /* _sa.push( p ); \ */ | |||
| /* } \ */ | |||
| ADD( int, "%d", v ); | |||
| ADD( nframes_t, "%lu", v ); | |||
| ADD( const char *, "\"%s\"", v ? v : "" ); | |||
| ADD( Loggable *, "0x%X", v ? v->id() : 0 ); | |||
| ADD( float, "%f", v ); | |||
| ADD( double, "%f", v ); | |||
| #undef ADD | |||
| }; | |||
| @@ -103,57 +103,25 @@ protected: | |||
| const char *class_name ( void ) { return "Region"; } | |||
| char ** get ( void ) | |||
| void | |||
| get ( Log_Entry &e ) | |||
| { | |||
| // char *r; | |||
| char **sa = (char**)malloc( sizeof( char* ) * 8 ); | |||
| int i = 0; | |||
| asprintf( &sa[ i++ ], ":source \"%s\"", _clip ? _clip->name() : "" ); | |||
| asprintf( &sa[ i++ ], ":track 0x%X", _track ? _track->id() : 0 ); | |||
| asprintf( &sa[ i++ ], ":x %lu", _r->offset ); | |||
| asprintf( &sa[ i++ ], ":l %lu", _r->start ); | |||
| asprintf( &sa[ i++ ], ":r %lu", _r->end ); | |||
| asprintf( &sa[ i++ ], ":selected %d", selected() ); | |||
| asprintf( &sa[ i++ ], ":gain %f", _scale ); | |||
| e.add( ":source", _clip ? _clip->name() : "" ); | |||
| e.add( ":gain %f", _scale ); | |||
| sa[ i ] = NULL; | |||
| return sa; | |||
| Sequence_Widget::get( e ); | |||
| } | |||
| void | |||
| set ( char **sa ) | |||
| set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| strtok( s, " " ); | |||
| const char *s, *v; | |||
| char *v = s + strlen( s ) + 1; | |||
| e.get( i, &s, &v ); | |||
| if ( *v == '"' ) | |||
| { | |||
| v++; | |||
| v[ strlen( v ) - 2 ] = '\0'; | |||
| } | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| else if ( ! strcmp( s, ":l" ) ) | |||
| _r->start = atol( v ); | |||
| else if ( ! strcmp( s, ":r" ) ) | |||
| _r->end = atol( v ); | |||
| else if ( ! strcmp( s, ":selected" ) ) | |||
| { | |||
| if ( atoi( v ) ) | |||
| select(); | |||
| else | |||
| deselect(); | |||
| } | |||
| else if ( ! strcmp( s, ":gain" ) ) | |||
| if ( ! strcmp( s, ":gain" ) ) | |||
| _scale = atof( v ); | |||
| else if ( ! strcmp( s, ":source" ) ) | |||
| { | |||
| @@ -162,24 +130,9 @@ protected: | |||
| printf( "Grave error: could not open source \"%s\"\n", v ); | |||
| } | |||
| } | |||
| else if ( ! strcmp( s, ":track" ) ) | |||
| { | |||
| int i; | |||
| sscanf( v, "%X", &i ); | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| assert( t ); | |||
| t->add( this ); | |||
| } | |||
| free( s ); | |||
| } | |||
| free( sa ); | |||
| if ( _track ) | |||
| _track->redraw(); | |||
| Sequence_Widget::set( e ); | |||
| } | |||
| public: | |||
| @@ -205,16 +158,7 @@ public: | |||
| const char *source_name ( void ) const { return _clip->name(); } | |||
| static Loggable * | |||
| create ( char **sa ) | |||
| { | |||
| Region *r = new Region; | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| LOG_CREATE_FUNC( Region ); | |||
| Sequence_Widget *clone ( const Sequence_Widget *r ); | |||
| @@ -39,53 +39,29 @@ protected: | |||
| const char *class_name ( void ) { return "Ruler_Point"; } | |||
| char ** get ( void ) | |||
| void | |||
| get ( Log_Entry &e ) | |||
| { | |||
| char **sa = (char**)malloc( sizeof( char* ) * 4 ); | |||
| int i = 0; | |||
| asprintf( &sa[i++], ":track 0x%X", _track ? _track->id() : 0 ); | |||
| asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
| asprintf( &sa[i++], ":label \"%s\"", _label ); | |||
| sa[i] = NULL; | |||
| Sequence_Point::get( e ); | |||
| return sa; | |||
| e.add( ":label", _label ); | |||
| } | |||
| void | |||
| set ( char **sa ) | |||
| set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| Sequence_Point::set( e ); | |||
| strtok( s, " " ); | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| const char *s, *v; | |||
| char *v = s + strlen( s ) + 1; | |||
| e.get( i, &s, &v ); | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| else if ( ! strcmp( s, ":label" ) ) | |||
| if ( ! strcmp( s, ":label" ) ) | |||
| name( v ); | |||
| else if ( ! strcmp( s, ":track" ) ) | |||
| { | |||
| int i; | |||
| sscanf( v, "%X", &i ); | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| assert( t ); | |||
| t->add( this ); | |||
| } | |||
| free( s ); | |||
| } | |||
| free( sa ); | |||
| timeline->redraw(); | |||
| } | |||
| @@ -97,16 +73,7 @@ protected: | |||
| public: | |||
| /* for loggable */ | |||
| static Loggable * | |||
| create ( char **sa ) | |||
| { | |||
| Ruler_Point *r = new Ruler_Point; | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| LOG_CREATE_FUNC( Ruler_Point ); | |||
| Ruler_Point ( nframes_t when, const char *name ) | |||
| { | |||
| @@ -27,9 +27,10 @@ | |||
| queue <Sequence_Widget *> Sequence::_delete_queue; | |||
| Sequence::Sequence ( int X, int Y, int W, int H ) : Fl_Widget( X, Y, W, H ) | |||
| Sequence::Sequence ( int X, int Y, int W, int H, Track *track ) : Fl_Widget( X, Y, W, H ) | |||
| { | |||
| _name = NULL; | |||
| _track = track; | |||
| box( FL_DOWN_BOX ); | |||
| color( fl_darker( FL_GRAY ) ); | |||
| @@ -22,7 +22,6 @@ | |||
| #include <FL/Fl_Widget.H> | |||
| #include <FL/Fl_Group.H> | |||
| #include <FL/Fl.H> | |||
| // #include "Region.H" | |||
| #include <stdio.h> | |||
| @@ -34,10 +33,9 @@ | |||
| // using namespace std; | |||
| class Region; | |||
| class Track; | |||
| class Sequence_Widget; | |||
| #include "types.h" | |||
| /* This is the base class for all track types. */ | |||
| @@ -45,6 +43,8 @@ class Sequence_Widget; | |||
| class Sequence : public Fl_Widget, public Loggable | |||
| { | |||
| Track *_track; /* track this sequence belongs to */ | |||
| char *_name; | |||
| static queue <Sequence_Widget *> _delete_queue; | |||
| @@ -57,19 +57,10 @@ protected: | |||
| virtual const char *class_name ( void ) { return "Sequence"; } | |||
| void set ( char ** ) { return; } | |||
| virtual void set ( Log_Entry &e ) { return; } | |||
| char ** get ( void ) | |||
| virtual void get ( Log_Entry &e ) | |||
| { | |||
| // char *r; | |||
| char **sa = (char**)malloc( sizeof( char* ) * 2); | |||
| sa[0] = (char*)malloc( (_widgets.size() * ((sizeof( int ) * 2) + 3)) + 1 ); | |||
| sa[1] = NULL; | |||
| sa[0][0] = '\0'; | |||
| /* char *s = sa[0]; */ | |||
| /* s += sprintf( s, ":items " ); */ | |||
| /* for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ ) */ | |||
| @@ -81,14 +72,12 @@ protected: | |||
| /* s += sprintf( s, "," ); */ | |||
| /* } */ | |||
| return sa; | |||
| } | |||
| public: | |||
| Sequence ( int X, int Y, int W, int H, Track *track=0 ); | |||
| Sequence ( int X, int Y, int W, int H ); | |||
| virtual ~Sequence ( ); | |||
| const char * name ( void ) const { return _name; } | |||
| @@ -28,9 +28,16 @@ protected: | |||
| char *_label; | |||
| /* void set ( char **a ) */ | |||
| /* { */ | |||
| /* } */ | |||
| virtual void get ( Log_Entry &e ) | |||
| { | |||
| e.add( ":x", _r->offset ); | |||
| e.add( ":t", _track ); | |||
| } | |||
| virtual void set ( Log_Entry &e ) | |||
| { | |||
| Sequence_Widget::set( e ); | |||
| } | |||
| public: | |||
| @@ -76,6 +76,58 @@ protected: | |||
| Drag *_drag; | |||
| virtual void | |||
| get ( Log_Entry &e ) | |||
| { | |||
| e.add( ":x", _r->offset ); | |||
| e.add( ":l", _r->start ); | |||
| e.add( ":r", _r->end ); | |||
| e.add( ":t", _track ); | |||
| e.add( ":s", selected() ); | |||
| } | |||
| virtual void | |||
| set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| const char *s, *v; | |||
| e.get( i, &s, &v ); | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| else if ( ! strcmp( s, ":l" ) ) | |||
| _r->start = atol( v ); | |||
| else if ( ! strcmp( s, ":r" ) ) | |||
| _r->end = atol( v ); | |||
| else if ( ! strcmp( s, ":s" ) ) | |||
| { | |||
| if ( atoi( v ) ) | |||
| select(); | |||
| else | |||
| deselect(); | |||
| } | |||
| else if ( ! strcmp( s, ":track" ) ) | |||
| { | |||
| int i; | |||
| sscanf( v, "%X", &i ); | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| assert( t ); | |||
| t->add( this ); | |||
| } | |||
| // else | |||
| // e.erase( i ); | |||
| } | |||
| if ( _track ) | |||
| _track->redraw(); | |||
| } | |||
| public: | |||
| Sequence_Widget ( ) | |||
| @@ -22,31 +22,21 @@ | |||
| #include "Tempo_Sequence.H" | |||
| #include "Timeline.H" // for timeline->tempo_track | |||
| char ** | |||
| Tempo_Point::get ( void ) | |||
| void | |||
| Tempo_Point::get ( Log_Entry &e ) | |||
| { | |||
| char **sa = (char**)malloc( sizeof( char* ) * 4 ); | |||
| int i = 0; | |||
| asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
| asprintf( &sa[i++], ":tempo %.2f", _tempo ); | |||
| sa[i] = NULL; | |||
| return sa; | |||
| e.add( ":x", _r->offset ); | |||
| e.add( ":tempo", _tempo ); | |||
| } | |||
| void | |||
| Tempo_Point::set ( char **sa ) | |||
| Tempo_Point::set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| strtok( s, " " ); | |||
| const char *s, *v; | |||
| char *v = s + strlen( s ) + 1; | |||
| e.get( i, &s, &v ); | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| @@ -55,30 +45,14 @@ Tempo_Point::set ( char **sa ) | |||
| /* FIXME: we need to add this to the time track on creation!!! */ | |||
| timeline->tempo_track->add( this ); | |||
| free( s ); | |||
| } | |||
| free( sa ); | |||
| timeline->redraw(); | |||
| _make_label(); | |||
| } | |||
| /* for loggable */ | |||
| Loggable * | |||
| Tempo_Point::create ( char **sa ) | |||
| { | |||
| Tempo_Point *r = new Tempo_Point; | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| Tempo_Point::Tempo_Point ( nframes_t when, float bpm ) | |||
| { | |||
| _tempo = bpm; | |||
| @@ -39,8 +39,8 @@ protected: | |||
| const char *class_name ( void ) { return "Tempo_Point"; } | |||
| char ** get ( void ); | |||
| void set ( char **sa ); | |||
| void get ( Log_Entry &e ); | |||
| void set ( Log_Entry &e ); | |||
| Tempo_Point ( ) | |||
| { | |||
| @@ -48,7 +48,7 @@ protected: | |||
| public: | |||
| static Loggable * create ( char **sa ); | |||
| LOG_CREATE_FUNC( Tempo_Point ); | |||
| Tempo_Point ( nframes_t when, float bpm ); | |||
| @@ -21,32 +21,22 @@ | |||
| #include "Time_Sequence.H" | |||
| #include "Timeline.H" // for timeline->time_track | |||
| char ** | |||
| Time_Point::get ( void ) | |||
| void | |||
| Time_Point::get ( Log_Entry &e ) | |||
| { | |||
| char **sa = (char**)malloc( sizeof( char* ) * 5 ); | |||
| int i = 0; | |||
| asprintf( &sa[i++], ":x %lu", _r->offset ); | |||
| asprintf( &sa[i++], ":beats_per_bar %d", _time.beats_per_bar ); | |||
| asprintf( &sa[i++], ":beat_type %d", _time.beat_type ); | |||
| sa[i] = NULL; | |||
| return sa; | |||
| e.add( ":x", _r->offset ); | |||
| e.add( ":beats_per_bar", _time.beats_per_bar ); | |||
| e.add( ":beat_type", _time.beat_type ); | |||
| } | |||
| void | |||
| Time_Point::set ( char **sa ) | |||
| Time_Point::set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| for ( int i = 0; i < e.size(); ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| strtok( s, " " ); | |||
| const char *s, *v; | |||
| char *v = s + strlen( s ) + 1; | |||
| e.get( i, &s, &v ); | |||
| if ( ! strcmp( s, ":x" ) ) | |||
| _r->offset = atol( v ); | |||
| @@ -57,12 +47,8 @@ Time_Point::set ( char **sa ) | |||
| /* FIXME: we need to add this to the time track on creation!!! */ | |||
| timeline->time_track->add( this ); | |||
| free( s ); | |||
| } | |||
| free( sa ); | |||
| timeline->redraw(); | |||
| _make_label(); | |||
| @@ -65,22 +65,13 @@ protected: | |||
| const char *class_name ( void ) { return "Time_Point"; } | |||
| char ** get ( void ); | |||
| void set ( char **sa ); | |||
| void get ( Log_Entry &e ); | |||
| void set ( Log_Entry &e ); | |||
| public: | |||
| /* for loggable */ | |||
| static Loggable * | |||
| create ( char **sa ) | |||
| { | |||
| Time_Point *r = new Time_Point; | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| LOG_CREATE_FUNC( Time_Point ); | |||
| Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) | |||
| { | |||
| @@ -17,8 +17,8 @@ | |||
| /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |||
| /*******************************************************************************/ | |||
| #ifndef Track_H | |||
| #define Track_H | |||
| #pragma once | |||
| #include <FL/Fl.H> | |||
| #include "Sequence.H" | |||
| #include <FL/Fl_Group.H> | |||
| @@ -31,17 +31,17 @@ | |||
| #include "Loggable.H" | |||
| // #include "Port.H" | |||
| /* TODO: rename this to Audio_Sequence_Header or something since it's clearly audio specific. */ | |||
| /* TODO: rename this to Audio_Track or something since it's clearly audio specific. */ | |||
| #include <vector> | |||
| using std::vector; | |||
| #include "Port.H" | |||
| class Playback_DS; | |||
| class Record_DS; | |||
| class Port; | |||
| class Region; | |||
| class Track : public Fl_Group, public Loggable | |||
| { | |||
| @@ -72,6 +72,12 @@ private: | |||
| bool create_outputs ( int n ); | |||
| bool create_inputs ( int n ); | |||
| Track ( ) : Fl_Group( 0, 0, 1, 1 ) | |||
| { | |||
| } | |||
| public: | |||
| Fl_Input * name_field; | |||
| @@ -93,21 +99,14 @@ public: | |||
| const char *class_name ( void ) { return "Track"; } | |||
| void set ( char **sa ) | |||
| void | |||
| set ( Log_Entry &e ) | |||
| { | |||
| for ( int i = 0; sa[i]; ++i ) | |||
| for ( int i = 0; e.size(); ++i ) | |||
| { | |||
| char *s = sa[i]; | |||
| strtok( s, " " ); | |||
| const char *s, *v; | |||
| char *v = s + strlen( s ) + 1; | |||
| if ( *v == '"' ) | |||
| { | |||
| v++; | |||
| v[ strlen( v ) - 2 ] = '\0'; | |||
| } | |||
| e.get( i, &s, &v ); | |||
| if ( ! strcmp( s, ":h" ) ) | |||
| { | |||
| @@ -115,67 +114,43 @@ public: | |||
| Fl_Widget::size( w(), height() ); | |||
| } | |||
| else if ( ! strcmp( s, ":selected" ) ) | |||
| else if ( ! strcmp( s, ":s" ) ) | |||
| _selected = atoi( v ); | |||
| // else if ( ! strcmp( s, ":armed" | |||
| else if ( ! strcmp( s, ":name" ) ) | |||
| else if ( ! strcmp( s, ":n" ) ) | |||
| { | |||
| _name = strdup( v ); | |||
| name_field->value( _name ); | |||
| } | |||
| else if ( ! strcmp( s, ":track" ) ) | |||
| else if ( ! strcmp( s, ":t" ) ) | |||
| { | |||
| int i; | |||
| sscanf( v, "%X", &i ); | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| assert( t ); | |||
| track( t ); | |||
| } | |||
| if ( i ) | |||
| { | |||
| Sequence *t = (Sequence*)Loggable::find( i ); | |||
| assert( t ); | |||
| free( s ); | |||
| track( t ); | |||
| } | |||
| } | |||
| } | |||
| free( sa ); | |||
| } | |||
| char ** get ( void ) | |||
| { | |||
| char **sa = (char**)malloc( sizeof( char* ) * (1 + 5) ); | |||
| int i = 0; | |||
| asprintf( &sa[ i++ ], ":name \"%s\"", _name ? _name : "" ); | |||
| asprintf( &sa[ i++ ], ":track 0x%X", track() ? track()->id() : 0 ); | |||
| asprintf( &sa[ i++ ], ":selected %d", _selected ); | |||
| // asprintf( &sa[ i++ ], ":record %d", record_button->value() ); | |||
| /* asprintf( &sa[ i++ ], ":solo %d", solo_button->value() ); */ | |||
| /* asprintf( &sa[ i++ ], ":mute %d", mute_button->value() ); */ | |||
| asprintf( &sa[ i++ ], ":h %d", size() ); | |||
| // asprintf( &sa[ i++ ], ":gain %f", _scale ); | |||
| sa[ i ] = NULL; | |||
| return sa; | |||
| void | |||
| get ( Log_Entry &e ) | |||
| { | |||
| e.add( ":n", _name ); | |||
| e.add( ":t", track() ); | |||
| e.add( ":s", _selected ); | |||
| e.add( ":h", size() ); | |||
| } | |||
| /* for loggable */ | |||
| static Loggable * | |||
| create ( char **sa ) | |||
| { | |||
| Track *r = new Track( 0, 0, 1, 1 ); | |||
| r->set( sa ); | |||
| return (Loggable *)r; | |||
| } | |||
| LOG_CREATE_FUNC( Track ); | |||
| void | |||
| draw ( void ) | |||
| @@ -299,4 +274,3 @@ public: | |||
| void stop ( nframes_t nframes ); | |||
| }; | |||
| #endif | |||
| @@ -73,11 +73,13 @@ main ( int argc, char **argv ) | |||
| // Fl::scheme( "gtk+" ); | |||
| /* welcome to C++ */ | |||
| Loggable::register_create( "Region", &Region::create ); | |||
| Loggable::register_create( "Tempo_Point", &Tempo_Point::create ); | |||
| Loggable::register_create( "Time_Point", &Time_Point::create ); | |||
| Loggable::register_create( "Control_Point", &Control_Point::create ); | |||
| Loggable::register_create( "Track", &Track::create ); | |||
| Loggable::register_create( "Region", &Region::create ); | |||
| Loggable::register_create( "Tempo_Point", &Tempo_Point::create ); | |||
| Loggable::register_create( "Time_Point", &Time_Point::create ); | |||
| Loggable::register_create( "Control_Point", &Control_Point::create ); | |||
| Loggable::register_create( "Track", &Track::create ); | |||
| Loggable::register_create( "Audio_Sequence", &Audio_Sequence::create ); | |||
| Loggable::register_create( "Control_Sequence", &Control_Sequence::create ); | |||
| /* TODO: change to seesion dir */ | |||