From ed813d0c03b87f9d97288e3070ccf9a87ce8138b Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 19 Apr 2008 00:09:42 -0500 Subject: [PATCH] Name newly created tracks. --- Timeline/Region.H | 2 -- Timeline/Timeline.C | 32 +++++++++++++++++++++++++++++++- Timeline/Timeline.H | 3 +++ Timeline/Track.C | 9 +++++++-- Timeline/Track.H | 16 +++++++++++++++- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Timeline/Region.H b/Timeline/Region.H index b8fa52e..5b38260 100644 --- a/Timeline/Region.H +++ b/Timeline/Region.H @@ -200,8 +200,6 @@ public: bool current ( void ) const { return this == belowmouse(); } - friend class Track; /* for _clip in Track::write() */ - public: diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index b6e4017..a27fc71 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -740,7 +740,9 @@ Timeline::handle ( int m ) /* FIXME: prompt for I/O config? */ /* add audio track */ - Track *t = new Track( 0, 0, tracks->w(), 30 ); + char *name = get_unique_track_name( "Audio" ); + + Track *t = new Track( 0, 0, tracks->w(), 30, name ); add_track( t ); @@ -797,6 +799,34 @@ Timeline::handle ( int m ) } + +bool +Timeline::track_name_exists ( const char *name ) +{ + for ( int i = tracks->children(); i-- ; ) + { + Track *t = (Track*)tracks->child( i ); + + if ( ! strcmp( name, t->name() ) ) + return true; + } + + return false; +} + +char * +Timeline::get_unique_track_name ( const char *name ) +{ + char pat[256]; + + strcpy( pat, name ); + + for ( int i = 1; track_name_exists( pat ); ++i ) + snprintf( pat, sizeof( pat ), "%s.%d", name, i ); + + return strdup( pat ); +} + void Timeline::add_track ( Track *track ) { diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 1984239..887c1b0 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -157,6 +157,9 @@ private: friend class Engine; // FIXME: only Engine::process() needs to be friended.x + bool track_name_exists ( const char *name ); + char * get_unique_track_name ( const char *name ); + /* Engine */ nframes_t process ( nframes_t nframes ); void seek ( nframes_t frame ); diff --git a/Timeline/Track.C b/Timeline/Track.C index 423c608..599a0fe 100644 --- a/Timeline/Track.C +++ b/Timeline/Track.C @@ -106,6 +106,8 @@ Track::Track ( int X, int Y, int W, int H, const char *L ) : _show_all_takes = false; _size = 1; + labeltype( FL_NO_LABEL ); + { char pname[40]; static int no = 0, ni = 0; @@ -142,6 +144,8 @@ Track::Track ( int X, int Y, int W, int H, const char *L ) : o->textcolor( 32 ); o->callback( cb_input_field, (void*)this ); + + o->hide(); } { @@ -220,6 +224,9 @@ Track::Track ( int X, int Y, int W, int H, const char *L ) : } end(); + if ( L ) + name( L ); + log_create(); } @@ -283,8 +290,6 @@ Track::size ( int v ) resize(); } - - void Track::track( Sequence * t ) { diff --git a/Timeline/Track.H b/Timeline/Track.H index afeaef8..550b66c 100644 --- a/Timeline/Track.H +++ b/Timeline/Track.H @@ -27,6 +27,7 @@ #include #include #include +#include #include "Loggable.H" @@ -188,6 +189,13 @@ public: } else Fl_Group::draw(); + + if ( ! name_field->visible() ) + { + fl_color( FL_WHITE ); + fl_font( FL_HELVETICA, 14 ); + fl_draw( name_field->value(), name_field->x(), name_field->y(), name_field->w(), name_field->h(), FL_ALIGN_CENTER ); + } } void add_control( Sequence *t ); @@ -210,6 +218,13 @@ public: resize(); } + void name ( const char *name ) + { + if ( _name ) free( _name ); + _name = strdup( name ); + name_field->value( _name ); + } + const char * name ( void ) const { return _name; } bool mute ( void ) const { return mute_button->value(); } bool solo ( void ) const { return solo_button->value(); } @@ -273,7 +288,6 @@ public: } } - /* Engine */ nframes_t process ( nframes_t nframes ); void seek ( nframes_t frame );