From b3d2cf94a16951a38b7e2ae63ccff0d24eb1891e Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 14 May 2008 16:50:31 -0500 Subject: [PATCH] Un-unify tempo and time sequences... Add an update_tempomap() method to Timeline instead, which must be called every time the time or tempo tracks are edited. This is perhaps as ugly as the unified map was, but is at least a bit more compatible with the possibility of moving all the meat of tempomapping into a library. --- Timeline/Tempo_Point.C | 8 +++- ...{Tempo_Map_Sequence.C => Tempo_Sequence.C} | 6 +-- Timeline/Tempo_Sequence.H | 2 - Timeline/Time_Point.C | 41 +++++++++++++++++++ Timeline/Time_Point.H | 13 ++---- Timeline/Timeline.C | 31 ++++++++++---- Timeline/Timeline.H | 4 ++ Timeline/makefile.inc | 2 +- 8 files changed, 81 insertions(+), 26 deletions(-) rename Timeline/{Tempo_Map_Sequence.C => Tempo_Sequence.C} (96%) diff --git a/Timeline/Tempo_Point.C b/Timeline/Tempo_Point.C index bd260fc..4937034 100644 --- a/Timeline/Tempo_Point.C +++ b/Timeline/Tempo_Point.C @@ -20,7 +20,7 @@ #include "Tempo_Point.H" -#include "Tempo_Map_Sequence.H" +#include "Tempo_Sequence.H" #include "Timeline.H" // for timeline->tempo_track void @@ -52,6 +52,7 @@ Tempo_Point::set ( Log_Entry &e ) } + timeline->update_tempomap(); timeline->redraw(); _make_label(); @@ -61,6 +62,7 @@ Tempo_Point::set ( Log_Entry &e ) Tempo_Point::Tempo_Point ( ) { timeline->tempo_track->add( this ); + timeline->update_tempomap(); } Tempo_Point::Tempo_Point ( nframes_t when, float bpm ) @@ -71,6 +73,7 @@ Tempo_Point::Tempo_Point ( nframes_t when, float bpm ) _make_label(); timeline->tempo_track->add( this ); + timeline->update_tempomap(); log_create(); } @@ -79,6 +82,8 @@ Tempo_Point::Tempo_Point ( nframes_t when, float bpm ) Tempo_Point::~Tempo_Point ( ) { + timeline->tempo_track->remove( this ); + timeline->update_tempomap(); log_destroy(); } @@ -100,6 +105,7 @@ Tempo_Point::handle ( int m ) if ( m == FL_RELEASE ) { sequence()->sort(); + timeline->update_tempomap(); timeline->redraw(); } return r; diff --git a/Timeline/Tempo_Map_Sequence.C b/Timeline/Tempo_Sequence.C similarity index 96% rename from Timeline/Tempo_Map_Sequence.C rename to Timeline/Tempo_Sequence.C index 4e29f56..57a2fa8 100644 --- a/Timeline/Tempo_Map_Sequence.C +++ b/Timeline/Tempo_Sequence.C @@ -17,11 +17,11 @@ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*******************************************************************************/ -#include "Tempo_Map_Sequence.H" +#include "Tempo_Sequence.H" void -Tempo_Map_Sequence::draw ( void ) +Tempo_Sequence::draw ( void ) { if ( ! fl_not_clipped( x(), y(), w(), h() ) ) return; @@ -59,7 +59,7 @@ Tempo_Map_Sequence::draw ( void ) } int -Tempo_Map_Sequence::handle ( int m ) +Tempo_Sequence::handle ( int m ) { int r = Sequence::handle( m ); diff --git a/Timeline/Tempo_Sequence.H b/Timeline/Tempo_Sequence.H index d936453..e10d4ed 100644 --- a/Timeline/Tempo_Sequence.H +++ b/Timeline/Tempo_Sequence.H @@ -22,8 +22,6 @@ #include "Sequence.H" #include "Tempo_Point.H" -#include - class Tempo_Sequence : public Sequence { diff --git a/Timeline/Time_Point.C b/Timeline/Time_Point.C index 7686b15..a0a9df9 100644 --- a/Timeline/Time_Point.C +++ b/Timeline/Time_Point.C @@ -53,6 +53,7 @@ Time_Point::set ( Log_Entry &e ) } + timeline->update_tempomap(); timeline->redraw(); _make_label(); @@ -62,6 +63,7 @@ Time_Point::set ( Log_Entry &e ) Time_Point::Time_Point ( ) : _time( 4, 4 ) { timeline->time_track->add( this ); + timeline->update_tempomap(); } Time_Point::Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) @@ -70,6 +72,7 @@ Time_Point::Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note _make_label(); timeline->time_track->add( this ); + timeline->update_tempomap(); log_create(); } @@ -78,5 +81,43 @@ Time_Point::Time_Point ( const Time_Point &rhs ) : Sequence_Point( rhs ) { _time = rhs._time; + timeline->update_tempomap(); log_create(); + +} + +Time_Point::~Time_Point ( ) +{ + timeline->time_track->remove( this ); + timeline->update_tempomap(); + + log_destroy(); +} + + +int +Time_Point::handle ( int m ) +{ + + if ( m == FL_PUSH && Fl::event_button3() && ! ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) ) ) + { + +/* float t = _tempo; */ +/* edit( &t ); */ +/* tempo( t ); */ + + return 0; + + } + + int r = Sequence_Widget::handle( m ); + + if ( m == FL_RELEASE ) + { + sequence()->sort(); + timeline->update_tempomap(); + timeline->redraw(); + } + return r; + } diff --git a/Timeline/Time_Point.H b/Timeline/Time_Point.H index c3198d5..700d3e8 100644 --- a/Timeline/Time_Point.H +++ b/Timeline/Time_Point.H @@ -36,9 +36,6 @@ struct time_sig } }; - -#define __CLASS__ "Time_Point" - class Time_Point : public Sequence_Point { time_sig _time; @@ -70,15 +67,11 @@ public: Time_Point ( nframes_t when, int bpb, int note ); Time_Point ( const Time_Point &rhs ); - ~Time_Point ( ) - { - log_destroy(); - } - + ~Time_Point ( ); void time ( int bpb, int note ) { _time.beats_per_bar = bpb; _time.beat_type = note; } time_sig time ( void ) const { return _time; } -}; + int handle ( int m ); -#undef __CLASS__ +}; diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index 707fd54..d2d8c3b 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -363,6 +363,24 @@ draw_measure_cb ( nframes_t frame, const BBT &bbt, void *arg ) /* FIXME: wrong place for this */ const float ticks_per_beat = 1920.0; +void +Timeline::update_tempomap ( void ) +{ + _tempomap.clear(); + + for ( list ::const_iterator i = time_track->_widgets.begin(); + i != time_track->_widgets.end(); ++i ) + _tempomap.push_back( *i ); + + for ( list ::const_iterator i = tempo_track->_widgets.begin(); + i != tempo_track->_widgets.end(); ++i ) + _tempomap.push_back( *i ); + + /* FIXME: shouldn't we ensure that time points always precede + tempo points at the same position? */ + _tempomap.sort(); +} + position_info Timeline::solve_tempomap ( nframes_t frame ) const { @@ -374,7 +392,6 @@ position_info Timeline::render_tempomap( nframes_t start, nframes_t length, measure_line_callback * cb, void *arg ) const { - const nframes_t end = start + length; position_info pos; @@ -384,10 +401,6 @@ Timeline::render_tempomap( nframes_t start, nframes_t length, measure_line_callb const nframes_t samples_per_minute = sample_rate() * 60; - list & tempo_map = tempo_track->_widgets; - -/* tempo_map.sort( Sequence_Widget::sort_func ); */ - float bpm = 120.0f; time_sig sig; @@ -402,8 +415,8 @@ Timeline::render_tempomap( nframes_t start, nframes_t length, measure_line_callb /* FIXME: don't we need to sort so that Time_Points always preceed Tempo_Points? */ - for ( list ::iterator i = tempo_map.begin(); - i != tempo_map.end(); ++i ) + for ( list ::const_iterator i = _tempomap.begin(); + i != _tempomap.end(); ++i ) { if ( ! strcmp( (*i)->class_name(), "Tempo_Point" ) ) @@ -421,9 +434,9 @@ Timeline::render_tempomap( nframes_t start, nframes_t length, measure_line_callb } { - list ::iterator n = i; + list ::const_iterator n = i; ++n; - if ( n == tempo_map.end() ) + if ( n == _tempomap.end() ) next = end; else // next = min( (*n)->start(), end ); diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index fad391d..ae4df53 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -112,6 +112,8 @@ class Timeline : public Fl_Overlay_Window, public RWLock Timeline ( const Timeline &rhs ); Timeline & operator = ( const Timeline &rhs ); + std::list _tempomap; + public: enum snap_e { @@ -137,6 +139,8 @@ public: Timeline ( int X, int Y, int W, int H, const char *L=0 ); + void update_tempomap ( void ); + nframes_t fpp ( void ) const { return 1 << _fpp; } nframes_t length ( void ) const { return _length; } nframes_t sample_rate ( void ) const { return engine->sample_rate(); } diff --git a/Timeline/makefile.inc b/Timeline/makefile.inc index b88c5d1..017e6c2 100644 --- a/Timeline/makefile.inc +++ b/Timeline/makefile.inc @@ -24,8 +24,8 @@ Timeline/Sequence_Point.C \ Timeline/Sequence_Region.C \ Timeline/Sequence_Widget.C \ Timeline/TLE.C \ -Timeline/Tempo_Map_Sequence.C \ Timeline/Tempo_Point.C \ +Timeline/Tempo_Sequence.C \ Timeline/Time_Point.C \ Timeline/Timeline.C \ Timeline/Track.C \