Massively rework loggable interface.

This commit is contained in:
Jonathan Moore Liles 2008-04-19 21:15:54 -05:00
parent f3e781762c
commit 300c6c3726
17 changed files with 421 additions and 348 deletions

View File

@ -28,8 +28,68 @@
class Audio_Sequence : public Sequence 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: public:
LOG_CREATE_FUNC( Audio_Sequence );
Audio_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H ) Audio_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H )
{ {
log_create(); log_create();

View File

@ -38,62 +38,31 @@ protected:
const char *class_name ( void ) { return "Control_Point"; } const char *class_name ( void ) { return "Control_Point"; }
char ** get ( void ) void
get ( Log_Entry &e )
{ {
char **sa = (char**)malloc( sizeof( char* ) * 4 ); e.add( ":y", _y );
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;
} }
void 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, ":x" ) )
_r->offset = atol( v );
else
if ( ! strcmp( s, ":y" ) ) if ( ! strcmp( s, ":y" ) )
_y = atof( v ); _y = atof( v );
else
if ( ! strcmp( s, ":track" ) )
{
int i;
sscanf( v, "%X", &i );
Sequence *t = (Sequence*)Loggable::find( i );
assert( t );
t->add( this );
t->sort();
}
free( s );
}
free( sa );
timeline->redraw(); timeline->redraw();
// _make_label(); // _make_label();
} }
}
Control_Point ( ) Control_Point ( )
{ {
@ -101,17 +70,14 @@ protected:
public: public:
/* Sequence_Widget * */
/* clone ( const Sequence_Widget *r ) */
/* { */
/* return new Control_Point( *(Control_Point*)r ); */
/* } */
/* for loggable */ /* for loggable */
static Loggable * LOG_CREATE_FUNC( Control_Point );
create ( char **sa )
{
Control_Point *r = new Control_Point;
r->set( sa );
return (Loggable *)r;
}
Control_Point ( Sequence *t, nframes_t when, float y ) Control_Point ( Sequence *t, nframes_t when, float y )
{ {

View File

@ -25,8 +25,14 @@
class Control_Sequence : public Sequence class Control_Sequence : public Sequence
{ {
Control_Sequence ( ) : Sequence( 0, 0, 1, 1 )
{
}
public: public:
LOG_CREATE_FUNC( Control_Sequence );
Control_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H ) Control_Sequence ( int X, int Y, int W, int H ) : Sequence( X, Y, W, H )
{ {

View File

@ -38,7 +38,9 @@ queue <char *> Loggable::_transaction;
bool bool
Loggable::open ( const char *filename ) 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!" ); printf( "Could not open log file for writing!" );
return false; return false;
@ -46,19 +48,19 @@ Loggable::open ( const char *filename )
/* TODO: replay log here */ /* TODO: replay log here */
/* FIXME: handle transactions!!! */ /* FIXME: handle transactions!!! */
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
while ( fscanf( _fp, "%[^\n]\n", buf ) == 1 ) while ( fscanf( fp, "%[^\n]\n", buf ) == 1 )
{ {
do_this( buf, false ); do_this( buf, false );
} }
} }
Loggable::_fp = fp;
return true; return true;
} }
@ -101,6 +103,19 @@ parse_alist( const char *s )
pair[ l ] = '\0'; pair[ l ] = '\0';
r[ i++ ] = pair; r[ i++ ] = pair;
/* split */
strtok( pair, " " );
/* remove quotes */
char *v = pair + strlen( pair ) + 1;
if ( *v == '"' )
{
v++;
v[ strlen( v ) - 2 ] = '\0';
}
} }
c = s; c = s;
@ -168,20 +183,24 @@ Loggable::do_this ( const char *s, bool reverse )
char **sa = parse_alist( arguments ); char **sa = parse_alist( arguments );
Log_Entry e( sa );
l->log_start(); l->log_start();
l->set( sa ); l->set( e );
l->log_end(); l->log_end();
} }
else if ( ! strcmp( command, create ) ) else if ( ! strcmp( command, create ) )
{ {
char **sa = parse_alist( arguments ); char **sa = parse_alist( arguments );
Log_Entry e( sa );
if ( ! _class_map[ string( classname ) ] ) if ( ! _class_map[ string( classname ) ] )
printf( "error class %s is unregistered!\n", classname ); printf( "error class %s is unregistered!\n", classname );
else else
{ {
/* create */ /* create */
Loggable *l = _class_map[ string( classname ) ]( sa ); Loggable *l = _class_map[ string( classname ) ]( e );
l->update_id( id ); l->update_id( id );
l->log_create(); l->log_create();
} }
@ -436,8 +455,13 @@ void
Loggable::log_start ( void ) Loggable::log_start ( void )
{ {
if ( ! _old_state ) if ( ! _old_state )
_old_state = get(); {
Log_Entry e;
get( e );
_old_state = e.sa();
}
++_nest; ++_nest;
_undo_index = 1; _undo_index = 1;
@ -450,7 +474,15 @@ Loggable::log_end ( void )
if ( --_nest > 0 ) if ( --_nest > 0 )
return; return;
char **_new_state = get(); char **_new_state;
{
Log_Entry e;
get( e );
_new_state = e.sa();
}
if ( log_diff( _old_state, _new_state ) ) if ( log_diff( _old_state, _new_state ) )
{ {
@ -478,7 +510,13 @@ Loggable::log_create ( void )
// indent(); // indent();
log( "%s 0x%X create ", class_name(), _id ); log( "%s 0x%X create ", class_name(), _id );
char **sa = get(); char **sa;
Log_Entry e;
get( e );
sa = e.sa();
if ( sa ) if ( sa )
{ {
@ -498,7 +536,13 @@ Loggable::log_destroy ( void )
// indent(); // indent();
log( "%s 0x%X destroy (nothing) << ", class_name(), _id ); 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( sa, NULL );
log_print( NULL, sa ); log_print( NULL, sa );

View File

@ -32,9 +32,29 @@
#include <queue> #include <queue>
using namespace std; using namespace std;
#include "types.h"
class Log_Entry;
class Loggable; 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 Logger;
class Loggable class Loggable
@ -152,13 +172,8 @@ public:
/* log messages for journal */ /* log messages for journal */
virtual const char *class_name ( void ) = 0; virtual const char *class_name ( void ) = 0;
virtual char ** get ( void ) = 0; virtual void get ( Log_Entry &e ) = 0;
virtual void set ( Log_Entry &e ) = 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, ... );
static bool do_this ( const char *s, bool reverse ); 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 ) */ class Log_Entry
/* #define LOG_END _logger.print( this ) */ {
// 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
};

View File

@ -103,57 +103,25 @@ protected:
const char *class_name ( void ) { return "Region"; } const char *class_name ( void ) { return "Region"; }
char ** get ( void ) void
get ( Log_Entry &e )
{ {
// char *r; e.add( ":source", _clip ? _clip->name() : "" );
char **sa = (char**)malloc( sizeof( char* ) * 8 ); e.add( ":gain %f", _scale );
int i = 0; Sequence_Widget::get( e );
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 );
sa[ i ] = NULL;
return sa;
} }
void 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, ":gain" ) )
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" ) )
_scale = atof( v ); _scale = atof( v );
else if ( ! strcmp( s, ":source" ) ) else if ( ! strcmp( s, ":source" ) )
{ {
@ -162,24 +130,9 @@ protected:
printf( "Grave error: could not open source \"%s\"\n", v ); 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 ); Sequence_Widget::set( e );
}
free( sa );
if ( _track )
_track->redraw();
} }
public: public:
@ -205,16 +158,7 @@ public:
const char *source_name ( void ) const { return _clip->name(); } const char *source_name ( void ) const { return _clip->name(); }
static Loggable * LOG_CREATE_FUNC( Region );
create ( char **sa )
{
Region *r = new Region;
r->set( sa );
return (Loggable *)r;
}
Sequence_Widget *clone ( const Sequence_Widget *r ); Sequence_Widget *clone ( const Sequence_Widget *r );

View File

@ -39,53 +39,29 @@ protected:
const char *class_name ( void ) { return "Ruler_Point"; } const char *class_name ( void ) { return "Ruler_Point"; }
char ** get ( void ) void
get ( Log_Entry &e )
{ {
char **sa = (char**)malloc( sizeof( char* ) * 4 ); Sequence_Point::get( e );
int i = 0; e.add( ":label", _label );
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;
return sa;
} }
void void
set ( char **sa ) set ( Log_Entry &e )
{ {
for ( int i = 0; sa[i]; ++i ) Sequence_Point::set( e );
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, ":label" ) )
if ( ! strcmp( s, ":x" ) )
_r->offset = atol( v );
else if ( ! strcmp( s, ":label" ) )
name( v ); 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(); timeline->redraw();
} }
@ -97,16 +73,7 @@ protected:
public: public:
/* for loggable */ /* for loggable */
static Loggable * LOG_CREATE_FUNC( Ruler_Point );
create ( char **sa )
{
Ruler_Point *r = new Ruler_Point;
r->set( sa );
return (Loggable *)r;
}
Ruler_Point ( nframes_t when, const char *name ) Ruler_Point ( nframes_t when, const char *name )
{ {

View File

@ -27,9 +27,10 @@
queue <Sequence_Widget *> Sequence::_delete_queue; 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; _name = NULL;
_track = track;
box( FL_DOWN_BOX ); box( FL_DOWN_BOX );
color( fl_darker( FL_GRAY ) ); color( fl_darker( FL_GRAY ) );

View File

@ -22,7 +22,6 @@
#include <FL/Fl_Widget.H> #include <FL/Fl_Widget.H>
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
#include <FL/Fl.H> #include <FL/Fl.H>
// #include "Region.H"
#include <stdio.h> #include <stdio.h>
@ -34,10 +33,9 @@
// using namespace std; // using namespace std;
class Region; class Track;
class Sequence_Widget; class Sequence_Widget;
#include "types.h" #include "types.h"
/* This is the base class for all track types. */ /* This is the base class for all track types. */
@ -45,6 +43,8 @@ class Sequence_Widget;
class Sequence : public Fl_Widget, public Loggable class Sequence : public Fl_Widget, public Loggable
{ {
Track *_track; /* track this sequence belongs to */
char *_name; char *_name;
static queue <Sequence_Widget *> _delete_queue; static queue <Sequence_Widget *> _delete_queue;
@ -57,19 +57,10 @@ protected:
virtual const char *class_name ( void ) { return "Sequence"; } 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 " ); */ /* s += sprintf( s, ":items " ); */
/* for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ ) */ /* for ( list <Sequence_Widget *>::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ ) */
@ -81,14 +72,12 @@ protected:
/* s += sprintf( s, "," ); */ /* s += sprintf( s, "," ); */
/* } */ /* } */
return sa;
} }
public: public:
Sequence ( int X, int Y, int W, int H, Track *track=0 );
Sequence ( int X, int Y, int W, int H );
virtual ~Sequence ( ); virtual ~Sequence ( );
const char * name ( void ) const { return _name; } const char * name ( void ) const { return _name; }

View File

@ -28,9 +28,16 @@ protected:
char *_label; 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: public:

View File

@ -76,6 +76,58 @@ protected:
Drag *_drag; 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: public:
Sequence_Widget ( ) Sequence_Widget ( )

View File

@ -22,31 +22,21 @@
#include "Tempo_Sequence.H" #include "Tempo_Sequence.H"
#include "Timeline.H" // for timeline->tempo_track #include "Timeline.H" // for timeline->tempo_track
char ** void
Tempo_Point::get ( void ) Tempo_Point::get ( Log_Entry &e )
{ {
char **sa = (char**)malloc( sizeof( char* ) * 4 ); e.add( ":x", _r->offset );
e.add( ":tempo", _tempo );
int i = 0;
asprintf( &sa[i++], ":x %lu", _r->offset );
asprintf( &sa[i++], ":tempo %.2f", _tempo );
sa[i] = NULL;
return sa;
} }
void 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]; const char *s, *v;
strtok( s, " " ); e.get( i, &s, &v );
char *v = s + strlen( s ) + 1;
if ( ! strcmp( s, ":x" ) ) if ( ! strcmp( s, ":x" ) )
_r->offset = atol( v ); _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!!! */ /* FIXME: we need to add this to the time track on creation!!! */
timeline->tempo_track->add( this ); timeline->tempo_track->add( this );
free( s );
} }
free( sa );
timeline->redraw(); timeline->redraw();
_make_label(); _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_Point::Tempo_Point ( nframes_t when, float bpm )
{ {
_tempo = bpm; _tempo = bpm;

View File

@ -39,8 +39,8 @@ protected:
const char *class_name ( void ) { return "Tempo_Point"; } const char *class_name ( void ) { return "Tempo_Point"; }
char ** get ( void ); void get ( Log_Entry &e );
void set ( char **sa ); void set ( Log_Entry &e );
Tempo_Point ( ) Tempo_Point ( )
{ {
@ -48,7 +48,7 @@ protected:
public: public:
static Loggable * create ( char **sa ); LOG_CREATE_FUNC( Tempo_Point );
Tempo_Point ( nframes_t when, float bpm ); Tempo_Point ( nframes_t when, float bpm );

View File

@ -21,32 +21,22 @@
#include "Time_Sequence.H" #include "Time_Sequence.H"
#include "Timeline.H" // for timeline->time_track #include "Timeline.H" // for timeline->time_track
char ** void
Time_Point::get ( void ) Time_Point::get ( Log_Entry &e )
{ {
char **sa = (char**)malloc( sizeof( char* ) * 5 ); e.add( ":x", _r->offset );
e.add( ":beats_per_bar", _time.beats_per_bar );
int i = 0; e.add( ":beat_type", _time.beat_type );
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;
} }
void 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]; const char *s, *v;
strtok( s, " " ); e.get( i, &s, &v );
char *v = s + strlen( s ) + 1;
if ( ! strcmp( s, ":x" ) ) if ( ! strcmp( s, ":x" ) )
_r->offset = atol( v ); _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!!! */ /* FIXME: we need to add this to the time track on creation!!! */
timeline->time_track->add( this ); timeline->time_track->add( this );
free( s );
} }
free( sa );
timeline->redraw(); timeline->redraw();
_make_label(); _make_label();

View File

@ -65,22 +65,13 @@ protected:
const char *class_name ( void ) { return "Time_Point"; } const char *class_name ( void ) { return "Time_Point"; }
char ** get ( void ); void get ( Log_Entry &e );
void set ( char **sa ); void set ( Log_Entry &e );
public: public:
/* for loggable */ LOG_CREATE_FUNC( Time_Point );
static Loggable *
create ( char **sa )
{
Time_Point *r = new Time_Point;
r->set( sa );
return (Loggable *)r;
}
Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note )
{ {

View File

@ -17,8 +17,8 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/ /*******************************************************************************/
#ifndef Track_H #pragma once
#define Track_H
#include <FL/Fl.H> #include <FL/Fl.H>
#include "Sequence.H" #include "Sequence.H"
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
@ -31,17 +31,17 @@
#include "Loggable.H" #include "Loggable.H"
// #include "Port.H" /* TODO: rename this to Audio_Track or something since it's clearly audio specific. */
/* TODO: rename this to Audio_Sequence_Header or something since it's clearly audio specific. */
#include <vector> #include <vector>
using std::vector; using std::vector;
#include "Port.H"
class Playback_DS; class Playback_DS;
class Record_DS; class Record_DS;
class Port; class Port;
class Region;
class Track : public Fl_Group, public Loggable class Track : public Fl_Group, public Loggable
{ {
@ -72,6 +72,12 @@ private:
bool create_outputs ( int n ); bool create_outputs ( int n );
bool create_inputs ( int n ); bool create_inputs ( int n );
Track ( ) : Fl_Group( 0, 0, 1, 1 )
{
}
public: public:
Fl_Input * name_field; Fl_Input * name_field;
@ -93,21 +99,14 @@ public:
const char *class_name ( void ) { return "Track"; } 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]; const char *s, *v;
strtok( s, " " ); e.get( i, &s, &v );
char *v = s + strlen( s ) + 1;
if ( *v == '"' )
{
v++;
v[ strlen( v ) - 2 ] = '\0';
}
if ( ! strcmp( s, ":h" ) ) if ( ! strcmp( s, ":h" ) )
{ {
@ -115,67 +114,43 @@ public:
Fl_Widget::size( w(), height() ); Fl_Widget::size( w(), height() );
} }
else if ( ! strcmp( s, ":selected" ) ) else if ( ! strcmp( s, ":s" ) )
_selected = atoi( v ); _selected = atoi( v );
// else if ( ! strcmp( s, ":armed" // else if ( ! strcmp( s, ":armed"
else if ( ! strcmp( s, ":name" ) ) else if ( ! strcmp( s, ":n" ) )
{ {
_name = strdup( v ); _name = strdup( v );
name_field->value( _name ); name_field->value( _name );
} }
else if ( ! strcmp( s, ":track" ) ) else if ( ! strcmp( s, ":t" ) )
{ {
int i; int i;
sscanf( v, "%X", &i ); sscanf( v, "%X", &i );
if ( i )
{
Sequence *t = (Sequence*)Loggable::find( i ); Sequence *t = (Sequence*)Loggable::find( i );
assert( t ); assert( t );
track( t ); track( t );
} }
}
}
free( s );
} }
free( sa );
} void
get ( Log_Entry &e )
char ** get ( void )
{ {
char **sa = (char**)malloc( sizeof( char* ) * (1 + 5) ); e.add( ":n", _name );
e.add( ":t", track() );
int i = 0; e.add( ":s", _selected );
e.add( ":h", size() );
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;
} }
/* for loggable */ /* for loggable */
static Loggable * LOG_CREATE_FUNC( Track );
create ( char **sa )
{
Track *r = new Track( 0, 0, 1, 1 );
r->set( sa );
return (Loggable *)r;
}
void void
draw ( void ) draw ( void )
@ -299,4 +274,3 @@ public:
void stop ( nframes_t nframes ); void stop ( nframes_t nframes );
}; };
#endif

View File

@ -78,6 +78,8 @@ main ( int argc, char **argv )
Loggable::register_create( "Time_Point", &Time_Point::create ); Loggable::register_create( "Time_Point", &Time_Point::create );
Loggable::register_create( "Control_Point", &Control_Point::create ); Loggable::register_create( "Control_Point", &Control_Point::create );
Loggable::register_create( "Track", &Track::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 */ /* TODO: change to seesion dir */