Big fix for loggability which was broken by the previous attempt at making Time and Tempo sequences unlogged.

This commit is contained in:
Jonathan Moore Liles 2008-05-05 00:29:39 -05:00
parent d510b21f7f
commit c3a20870f7
17 changed files with 170 additions and 120 deletions

View File

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

View File

@ -23,6 +23,7 @@
#include "Waveform.H"
#include "Audio_Sequence.H"
#include "Track.H"
#include "dsp.h"

View File

@ -24,6 +24,68 @@
#include <Fl/fl_ask.H>
#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 )

View File

@ -21,76 +21,32 @@
#include "Sequence.H"
#include "Audio_Region.H"
#include "Track.H"
#include <FL/Fl_Input.H>
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 );

View File

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

View File

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

View File

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

View File

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

View File

@ -30,20 +30,30 @@
queue <Sequence_Widget *> 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 ( )

View File

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

View File

@ -56,7 +56,7 @@ protected:
Sequence_Region ( )
{
color( FL_CYAN );
}
virtual ~Sequence_Region ( )

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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