diff --git a/Timeline/Audio_File.C b/Timeline/Audio_File.C index 5f7005d..ba2a5d2 100644 --- a/Timeline/Audio_File.C +++ b/Timeline/Audio_File.C @@ -20,11 +20,11 @@ #include "Audio_File.H" #include "Audio_File_SF.H" -map Audio_File::_open_files; +std::map Audio_File::_open_files; Audio_File::~Audio_File ( ) { - _open_files[ string( _filename ) ] = NULL; + _open_files[ std::string( _filename ) ] = NULL; } /** attmpet to open any supported filetype */ @@ -34,7 +34,7 @@ Audio_File::from_file ( const char * filename ) Audio_File *a; - if ( ( a = _open_files[ string( filename ) ] ) ) + if ( ( a = _open_files[ std::string( filename ) ] ) ) return a; if ( ( a = Audio_File_SF::from_file( filename ) ) ) @@ -51,7 +51,7 @@ done: /* a->_peaks->clip( a ); */ /* a->_peaks->open(); */ - _open_files[ string( filename ) ] = a; + _open_files[ std::string( filename ) ] = a; return a; } diff --git a/Timeline/Audio_File.H b/Timeline/Audio_File.H index e7a4a86..4a66b6e 100644 --- a/Timeline/Audio_File.H +++ b/Timeline/Audio_File.H @@ -23,19 +23,17 @@ #include #include "types.h" -typedef float sample_t; #include "Peaks.H" #include #include -using namespace std; class Peak_Writer; class Audio_File { - static map _open_files; + static std::map _open_files; protected: diff --git a/Timeline/Ruler_Point.H b/Timeline/Ruler_Point.H new file mode 100644 index 0000000..357b756 --- /dev/null +++ b/Timeline/Ruler_Point.H @@ -0,0 +1,152 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include "Loggable.H" +#include "Track_Point.H" + +class Ruler_Point : public Track_Point +{ + +public: + + const char *name ( void ) const { return _label; } + void name ( const char *s ) + { + if ( _label ) + free( _label ); + _label = strdup( s ); + } + +protected: + + const char *class_name ( void ) { return "Ruler_Point"; } + + char ** get ( void ) + { + 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; + + return sa; + } + + void + set ( char **sa ) + { + for ( int i = 0; sa[i]; ++i ) + { + char *s = sa[i]; + + strtok( s, " " ); + + char *v = s + strlen( s ) + 1; + + if ( ! strcmp( s, ":x" ) ) + _r->offset = atol( v ); + else if ( ! strcmp( s, ":label" ) ) + name( v ); + else if ( ! strcmp( s, ":track" ) ) + { + int i; + sscanf( v, "%X", &i ); + Track *t = (Track*)Loggable::find( i ); + + assert( t ); + + t->add( this ); + } + + + free( s ); + } + + free( sa ); + + timeline->redraw(); + } + + Ruler_Point ( ) + { + + } + +public: + + /* for loggable */ + static Loggable * + create ( char **sa ) + { + Ruler_Point *r = new Ruler_Point; + + r->set( sa ); + + return (Loggable *)r; + } + + + Ruler_Point ( nframes_t when, const char *name ) + { + _r->offset = when; + + _label = strdup( name ); + + log_create(); + } + + Ruler_Point ( const Ruler_Point &rhs ) + { + _r->offset = rhs._r->offset; + _label = strdup( rhs._label ); + } + + Track_Widget *clone ( const Track_Widget *r ) + { + return new Ruler_Point( *(Ruler_Point*)r ); + } + + ~Ruler_Point ( ) + { + if ( _label ) free( _label ); + log_destroy(); + } + + + int + handle ( int m ) + { + int r = Track_Widget::handle( m ); + + if ( m == FL_RELEASE ) + { + _track->sort(); + timeline->redraw(); + } + + return r; + } + +}; diff --git a/Timeline/Ruler_Track.H b/Timeline/Ruler_Track.H new file mode 100644 index 0000000..6ff6518 --- /dev/null +++ b/Timeline/Ruler_Track.H @@ -0,0 +1,43 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#pragma once + +#include "Track.H" +#include "Ruler_Point.H" +#include "Timeline.H" + +class Ruler_Track : public Track +{ + +public: + + Ruler_Track ( int X, int Y, int W, int H ) : Track ( X, Y, W, H ) + { + box( FL_UP_BOX ); + } + + void + draw ( void ) + { + Track::draw(); + timeline->draw_measure_BBT( x(), y(), w(), h(), FL_WHITE ); + + } +}; diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 2415e4b..3863f48 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -24,6 +24,8 @@ #include "Control_Track.H" #include +#include "Ruler_Track.H" + // #include // #include // needed for alpha blending @@ -140,6 +142,22 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi } + { + Ruler_Track *o = new Ruler_Track( 0, 24, 800, 24 ); + + o->color( FL_GREEN ); + +/* o->add( new Time_Point( 0, 4, 4 ) ); */ +/* o->add( new Time_Point( 345344, 6, 8 ) ); */ + + o->label( "Ruler" ); + o->align( FL_ALIGN_LEFT ); + + ruler_track = o; + // o->end(); + + } + o->size( o->w(), o->child( 0 )->h() * o->children() ); rulers = o; o->end(); @@ -218,6 +236,36 @@ Timeline::beats_per_minute ( nframes_t when, float bpm ) tempo_track->add( new Tempo_Point( when, bpm ) ); } +#if 0 +struct BBT +{ + int bar, beat, tick; + + BBT ( int bar, int beat, int tick ) : bar( bar ), beat( beat ), tick( tick ) + { + } +}; + +/** returns the BBT value for timestamp /when/ by examining the tempo/time maps */ +BBT +Timeline::bbt ( nframes_t when ) +{ + Tempo_Track *tempo = (Tempo_Track*)rulers->child( 0 ); + + BBT bbt; + + for ( list ::const_iterator i = tempo.widgets.begin(); + i != tempo.widgets.end(); ++i ) + { + Tempo_Point *p = *i; + + } + + + +}; +#endif + /** return the absolute pixel of the nearest measure line to /x/ */ int Timeline::nearest_line ( int ix ) @@ -240,7 +288,7 @@ Timeline::nearest_line ( int ix ) searched both the time and tempo lists once for every horiontal pixel and performs a number of calculations--this is slow. */ void -Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) +Timeline::draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT ) { if ( ! _enable_measure_lines ) return; @@ -248,14 +296,15 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) // fl_line_style( FL_DASH, 2 ); fl_line_style( FL_DASH, 0 ); - Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f ); - Fl_Color bar = fl_color_average( FL_RED, color, 0.65f ); + Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f ); + Fl_Color bar = fl_color_average( FL_RED, color, 0.65f ); int measure; for ( int x = X; x < X + W; ++x ) { - measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track_Header::width() ) + xoffset )); + + measure = ts_to_x( (double)(_sample_rate * 60) / beats_per_minute( x_to_ts( x - Track_Header::width() ) + xoffset ) ); const int abs_x = ts_to_x( xoffset ) + x - Track_Header::width(); @@ -268,6 +317,41 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) if ( measure * bpb < 8 ) break; + if ( BBT ) + { + fl_font( FL_HELVETICA, 14 ); + + fl_color( fl_lighter( color ) ); + + char pat[40]; + + const nframes_t ts = x_to_ts( abs_x ); + +// if ( draw_hms ) + { + + const double seconds = (double)ts / _sample_rate; + + int S = (int)seconds; + int M = S / 60; S -= M * 60; + int H = M / 60; M -= H * 60; + + snprintf( pat, sizeof( pat ), "%d:%d:%d", H, M, S ); + } +// else if ( draw_bbt ) + { + +/* const int bar = */ +/* const int beat; */ +/* const int tick = 0; */ + +/* snprintf( pat, sizeof( pat ), "%d:%d:%d", bar, beat, tick ); */ + } + + + fl_draw( pat, x, Y + 14 ); + } + fl_color( bar ); } else @@ -287,6 +371,18 @@ Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) } +void +Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ) +{ + draw_measure( X, Y, W, H, color, false ); +} + +/** just like draw mesure lines except that it also draws the BBT values. */ +void +Timeline::draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color ) +{ + draw_measure( X, Y, W, H, color, true ); +} void Timeline::xposition ( int X ) diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 086405b..4853031 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -44,6 +44,7 @@ extern Timeline *timeline; class Tempo_Track; class Time_Track; +class Ruler_Track; #include using std::list; @@ -98,14 +99,15 @@ class Timeline : public Fl_Overlay_Window, public RWLock SNAP_TO_BEAT } snap_to; - Fl_Scroll *scroll; - Fl_Pack *tracks; - Fl_Pack *rulers; - Scalebar *hscroll; + Fl_Scroll *scroll; + Fl_Pack *tracks; + Fl_Pack *rulers; + Scalebar *hscroll; Fl_Scrollbar *vscroll; Tempo_Track *tempo_track; - Time_Track *time_track; + Time_Track *time_track; + Ruler_Track *ruler_track; static void cb_scroll ( Fl_Widget *w, void *v ); @@ -136,6 +138,9 @@ public: int nearest_line ( int ix ); void draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color ); + void draw_measure_BBT ( int X, int Y, int W, int H, Fl_Color color ); + void draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT ); + void xposition ( int X ); void yposition ( int Y ); void draw_playhead ( void ); diff --git a/Timeline/Track.H b/Timeline/Track.H index 53d4455..5755e5e 100644 --- a/Timeline/Track.H +++ b/Timeline/Track.H @@ -31,8 +31,8 @@ #include #include -#include -using namespace std; + +// using namespace std; class Region; class Track_Widget; @@ -51,7 +51,7 @@ class Track : public Fl_Widget, public Loggable protected: - list _widgets; + std::list _widgets; Track_Widget *event_widget ( void ); virtual const char *class_name ( void ) { return "Track"; } @@ -103,7 +103,7 @@ public: void remove_selected ( void ); - const list widgets ( void ) const { return _widgets; } + const std::list widgets ( void ) const { return _widgets; } void queue_delete ( Track_Widget *r ) {