diff --git a/Timeline/Sequence_Widget.H b/Timeline/Sequence_Widget.H index 17219dd..15a841f 100644 --- a/Timeline/Sequence_Widget.H +++ b/Timeline/Sequence_Widget.H @@ -382,13 +382,13 @@ public: } bool - operator< ( const Sequence_Widget & rhs ) + operator< ( const Sequence_Widget & rhs ) const { return _r->start < rhs._r->start; } bool - operator<=( const Sequence_Widget & rhs ) + operator<=( const Sequence_Widget & rhs ) const { return _r->start <= rhs._r->start; } @@ -397,7 +397,7 @@ public: virtual int handle ( int m ); static bool - sort_func ( Sequence_Widget *lhs, Sequence_Widget *rhs ) + sort_func ( const Sequence_Widget *lhs, const Sequence_Widget *rhs ) { return *lhs < *rhs; } diff --git a/Timeline/Tempo_Point.C b/Timeline/Tempo_Point.C index 4937034..b8df1b8 100644 --- a/Timeline/Tempo_Point.C +++ b/Timeline/Tempo_Point.C @@ -139,7 +139,7 @@ public: Fl_Float_Input *fi = _fi = new Fl_Float_Input( 12, 0 + 24, 50, 24, "Tempo:" ); fi->align( FL_ALIGN_TOP ); - fi->when( FL_WHEN_ENTER_KEY ); + fi->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY ); fi->callback( &Tempo_Point_Editor::enter_cb, (void*)this ); char pat[10]; diff --git a/Timeline/Tempo_Sequence.C b/Timeline/Tempo_Sequence.C index 57a2fa8..e920505 100644 --- a/Timeline/Tempo_Sequence.C +++ b/Timeline/Tempo_Sequence.C @@ -19,45 +19,6 @@ #include "Tempo_Sequence.H" - -void -Tempo_Sequence::draw ( void ) -{ - if ( ! fl_not_clipped( x(), y(), w(), h() ) ) - return; - - fl_push_clip( x(), y(), w(), h() ); - - /* draw the box with the ends cut off. */ - draw_box( box(), - x() - Fl::box_dx( box() ) - 1, y(), - w() + Fl::box_dw( box() ) + 2, h() >> 1, color() ); - draw_box( box(), - x() - Fl::box_dx( box() ) - 1, y() + (h() >> 1) , - w() + Fl::box_dw( box() ) + 2, h() >> 1, color() ); - - int X, Y, W, H; - - fl_clip_box( x(), y(), w(), h(), X, Y, W, H ); - - if ( Sequence_Widget::pushed() && Sequence_Widget::pushed()->sequence() == this ) - { - /* make sure the Sequence_Widget::pushed widget is above all others */ - remove( Sequence_Widget::pushed() ); - add( Sequence_Widget::pushed() ); - } - - timeline->draw_measure_lines( X, Y, W, H, color() ); - - for ( list ::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r ) - (*r)->draw_box(); - - for ( list ::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r ) - (*r)->draw(); - - fl_pop_clip(); -} - int Tempo_Sequence::handle ( int m ) { diff --git a/Timeline/Tempo_Sequence.H b/Timeline/Tempo_Sequence.H index e10d4ed..38a12a0 100644 --- a/Timeline/Tempo_Sequence.H +++ b/Timeline/Tempo_Sequence.H @@ -40,7 +40,6 @@ public: // box( FL_DOWN_BOX ); } - void draw ( void ); int handle ( int m ); }; diff --git a/Timeline/Time_Point.C b/Timeline/Time_Point.C index a0a9df9..ceddea3 100644 --- a/Timeline/Time_Point.C +++ b/Timeline/Time_Point.C @@ -68,7 +68,8 @@ Time_Point::Time_Point ( ) : _time( 4, 4 ) Time_Point::Time_Point ( nframes_t when, int bpb, int note ) : _time( bpb, note ) { - _r->offset = when; + start( when ); + _make_label(); timeline->time_track->add( this ); @@ -102,9 +103,11 @@ 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 ); */ + time_sig t = _time; + + edit( &t ); + + time( t.beats_per_bar, t.beat_type ); return 0; @@ -121,3 +124,95 @@ Time_Point::handle ( int m ) return r; } + + + +#include +#include + + +class Time_Point_Editor : public Fl_Menu_Window +{ + + /* not permitted */ + Time_Point_Editor ( const Time_Point_Editor &rhs ); + Time_Point_Editor & operator = ( const Time_Point_Editor &rhs ); + + time_sig *_sig; + Fl_Int_Input *_beats; + Fl_Int_Input *_beat_type; + + bool _sucess; + +public: + + Time_Point_Editor ( time_sig *sig ) + : Fl_Menu_Window( 150, 110, "Edit Time" ) + { + _sig = sig; + + set_modal(); + + { + Fl_Int_Input *o = _beats = new Fl_Int_Input( 50, 0 + 24, 50, 24, "Beats Per Bar:" ); + o->align( FL_ALIGN_TOP ); + o->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY ); + o->callback( &Time_Point_Editor::enter_cb, (void*)this ); + } + + { + Fl_Int_Input *o = _beat_type = new Fl_Int_Input( 50, 0 + 75, 50, 24, "Beat Type:" ); + o->align( FL_ALIGN_TOP ); + o->when( FL_WHEN_NOT_CHANGED | FL_WHEN_ENTER_KEY ); + o->callback( &Time_Point_Editor::enter_cb, (void*)this ); + } + + char pat[10]; + snprintf( pat, sizeof( pat ), "%d", _sig->beats_per_bar ); + + _beats->value( pat ); + + snprintf( pat, sizeof( pat ), "%d", _sig->beat_type ); + + _beat_type->value( pat ); + + end(); + + show(); + + while ( shown() ) + Fl::wait(); + } + + static void + enter_cb ( Fl_Widget *w, void *v ) + { + ((Time_Point_Editor*)v)->enter_cb(); + } + + void + enter_cb ( void ) + { + _sig->beats_per_bar = atoi( _beats->value() ); + _sig->beat_type = atoi( _beat_type->value() ); + + _sucess = true; + + hide(); + } + + bool + sucess ( void ) + { + return _sucess; + } +}; + + +bool +Time_Point::edit ( time_sig *sig ) +{ + Time_Point_Editor ti( sig ); + + return ti.sucess(); +} diff --git a/Timeline/Time_Point.H b/Timeline/Time_Point.H index 700d3e8..b907d50 100644 --- a/Timeline/Time_Point.H +++ b/Timeline/Time_Point.H @@ -64,12 +64,20 @@ public: LOG_CREATE_FUNC( Time_Point ); SEQUENCE_WIDGET_CLONE_FUNC( Time_Point ); + static bool edit ( time_sig *sig ); + Time_Point ( nframes_t when, int bpb, int note ); Time_Point ( const Time_Point &rhs ); ~Time_Point ( ); - void time ( int bpb, int note ) { _time.beats_per_bar = bpb; _time.beat_type = note; } + void + time ( int bpb, int note ) + { + _time.beats_per_bar = bpb; _time.beat_type = note; + _make_label(); + redraw(); + } time_sig time ( void ) const { return _time; } int handle ( int m ); diff --git a/Timeline/Time_Sequence.C b/Timeline/Time_Sequence.C new file mode 100644 index 0000000..75088a1 --- /dev/null +++ b/Timeline/Time_Sequence.C @@ -0,0 +1,50 @@ + +/*******************************************************************************/ +/* 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. */ +/*******************************************************************************/ + +#include "Time_Sequence.H" + +int +Time_Sequence::handle ( int m ) +{ + int r = Sequence::handle( m ); + + if ( r ) + return r; + + switch ( m ) + { + case FL_PUSH: + if ( Fl::event_button1() ) + { + static time_sig t = time_sig( 4, 4 ); + + if ( Time_Point::edit( &t ) ) + { + add( new Time_Point( timeline->x_to_offset( Fl::event_x() ), t.beats_per_bar, t.beat_type ) ); + + timeline->redraw(); + } + return 0; + } + default: + return 0; + + } + +} diff --git a/Timeline/Time_Sequence.H b/Timeline/Time_Sequence.H index 09c6768..3b0a5e0 100644 --- a/Timeline/Time_Sequence.H +++ b/Timeline/Time_Sequence.H @@ -62,4 +62,5 @@ public: add( new Time_Point( when, bpb, note ) ); } + int handle ( int m ); }; diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index d2d8c3b..fd14bed 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -378,7 +378,7 @@ Timeline::update_tempomap ( void ) /* FIXME: shouldn't we ensure that time points always precede tempo points at the same position? */ - _tempomap.sort(); + _tempomap.sort( Sequence_Widget::sort_func ); } position_info diff --git a/Timeline/makefile.inc b/Timeline/makefile.inc index 017e6c2..68de35b 100644 --- a/Timeline/makefile.inc +++ b/Timeline/makefile.inc @@ -27,6 +27,7 @@ Timeline/TLE.C \ Timeline/Tempo_Point.C \ Timeline/Tempo_Sequence.C \ Timeline/Time_Point.C \ +Timeline/Time_Sequence.C \ Timeline/Timeline.C \ Timeline/Track.C \ Timeline/Transport.C \