Make time points editable etc.

Fix sorting of tempomap.
This commit is contained in:
Jonathan Moore Liles 2008-05-14 17:36:23 -05:00
parent b3d2cf94a1
commit 705482f72f
10 changed files with 165 additions and 50 deletions

View File

@ -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;
}

View File

@ -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];

View File

@ -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 <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r )
(*r)->draw_box();
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r )
(*r)->draw();
fl_pop_clip();
}
int
Tempo_Sequence::handle ( int m )
{

View File

@ -40,7 +40,6 @@ public:
// box( FL_DOWN_BOX );
}
void draw ( void );
int handle ( int m );
};

View File

@ -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 <FL/Fl_Int_Input.H>
#include <FL/Fl_Menu_Window.H>
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();
}

View File

@ -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 );

50
Timeline/Time_Sequence.C Normal file
View File

@ -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;
}
}

View File

@ -62,4 +62,5 @@ public:
add( new Time_Point( when, bpb, note ) );
}
int handle ( int m );
};

View File

@ -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

View File

@ -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 \