From 61f3d5661125d434de400f3763ce3e0b6975c766 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Fri, 2 May 2008 15:02:24 -0500 Subject: [PATCH] Allow the user to add/edit tempo points. --- Timeline/TLE.fl | 6 +-- Timeline/Tempo_Point.C | 79 +++++++++++++++++++++++++++++++++++++++ Timeline/Tempo_Point.H | 4 +- Timeline/Tempo_Sequence.H | 29 ++++++++++++++ 4 files changed, 114 insertions(+), 4 deletions(-) diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index da0f062..7100e5b 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -34,7 +34,7 @@ decl {\#include } {} decl {extern char *user_config_dir;} {global } -class TLE {open +class TLE {open selected } { decl {Fl_Color system_colors[3];} {public } @@ -114,7 +114,7 @@ free( path );} {} label {Non-DAW - Timeline} open xywh {577 94 1024 768} type Double resizable xclass {Non-DAW} visible } { - Fl_Menu_Bar menubar {open + Fl_Menu_Bar menubar { xywh {0 0 1024 25} } { Submenu {} { @@ -158,7 +158,7 @@ Loggable::compact();} printf( "dropped %d buffers\\n", engine->dropped() ); -exit( 0 );} selected +exit( 0 );} xywh {40 40 40 25} shortcut 0x40071 } } diff --git a/Timeline/Tempo_Point.C b/Timeline/Tempo_Point.C index dab9bb7..23cf239 100644 --- a/Timeline/Tempo_Point.C +++ b/Timeline/Tempo_Point.C @@ -72,9 +72,18 @@ Tempo_Point::~Tempo_Point ( ) } + int Tempo_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 ) @@ -84,3 +93,73 @@ Tempo_Point::handle ( int m ) } return r; } + + +#include +#include + + +class Tempo_Point_Editor : public Fl_Menu_Window +{ + + float *_tempo; + Fl_Float_Input *_fi; + + bool _sucess; + +public: + + Tempo_Point_Editor ( int X, int Y, float *tempo ) : Fl_Menu_Window( X, Y, 75, 58, "Edit Tempo" ) + { + _sucess = false; + _tempo = tempo; + + set_modal(); + + 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->callback( &Tempo_Point_Editor::enter_cb, (void*)this ); + + char pat[10]; + snprintf( pat, sizeof( pat ), "%.1f", *tempo ); + + fi->value( pat ); + + end(); + + show(); + + while ( shown() ) + Fl::wait(); + } + + static void + enter_cb ( Fl_Widget *w, void *v ) + { + ((Tempo_Point_Editor*)v)->enter_cb(); + } + + void + enter_cb ( void ) + { + sscanf( _fi->value(), "%f", _tempo ); + _sucess = true; + hide(); + } + + bool + sucess ( void ) + { + return _sucess; + } +}; + + +bool +Tempo_Point::edit ( float *tempo ) +{ + Tempo_Point_Editor ti( Fl::event_x(), Fl::event_y(), tempo ); + + return ti.sucess(); +} diff --git a/Timeline/Tempo_Point.H b/Timeline/Tempo_Point.H index 7b8968f..4b4246b 100644 --- a/Timeline/Tempo_Point.H +++ b/Timeline/Tempo_Point.H @@ -48,6 +48,8 @@ protected: public: + static bool edit ( float *tempo ); + LOG_CREATE_FUNC( Tempo_Point ); Tempo_Point ( nframes_t when, float bpm ); @@ -69,7 +71,7 @@ public: float tempo ( void ) const { return _tempo; } void tempo ( float v ) - { _tempo = v; } + { if ( v != _tempo ) { _tempo = v; _make_label(); timeline->redraw(); } } int handle ( int m ); }; diff --git a/Timeline/Tempo_Sequence.H b/Timeline/Tempo_Sequence.H index 894a7cc..0548f7f 100644 --- a/Timeline/Tempo_Sequence.H +++ b/Timeline/Tempo_Sequence.H @@ -69,4 +69,33 @@ public: sort(); } + int + handle ( int m ) + { + int r = Sequence::handle( m ); + + if ( r ) + return r; + + switch ( m ) + { + case FL_PUSH: + if ( Fl::event_button1() ) + { + static float t = 120.0f; + + if ( Tempo_Point::edit( &t ) ) + { + add( new Tempo_Point( timeline->x_to_offset( Fl::event_x() ), t ) ); + + timeline->redraw(); + } + return 0; + } + default: + return 0; + + } + + } };