2008-02-21 11:39:13 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* 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 "Timeline.H"
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Tempo_Sequence.H"
|
|
|
|
#include "Time_Sequence.H"
|
|
|
|
#include "Audio_Sequence.H"
|
|
|
|
#include "Control_Sequence.H"
|
2008-02-26 05:58:15 +01:00
|
|
|
#include <FL/Fl_Scrollbar.H>
|
|
|
|
|
2008-05-05 00:32:08 +02:00
|
|
|
#include "Annotation_Sequence.H"
|
2008-04-18 22:18:07 +02:00
|
|
|
|
2008-04-09 02:05:15 +02:00
|
|
|
// #include <FL/Fl_Image.H>
|
|
|
|
// #include <FL/Fl_RGB_Image.H> // needed for alpha blending
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Track.H"
|
2008-02-29 03:02:40 +01:00
|
|
|
|
2008-04-25 04:48:44 +02:00
|
|
|
bool Timeline::draw_with_measure_lines = true;
|
2008-04-26 18:07:43 +02:00
|
|
|
Timeline::snap_e Timeline::snap_to = Bars;
|
2008-04-27 20:56:20 +02:00
|
|
|
bool Timeline::snap_magnetic = true;
|
2008-04-30 03:08:49 +02:00
|
|
|
bool Timeline::follow_playhead = true;
|
2008-05-01 08:47:49 +02:00
|
|
|
bool Timeline::center_playhead = true;
|
2008-04-25 04:48:44 +02:00
|
|
|
|
2008-04-12 21:50:36 +02:00
|
|
|
const float UPDATE_FREQ = 0.02f;
|
|
|
|
|
2008-04-12 21:13:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
#include "Playback_DS.H"
|
2008-04-23 07:35:49 +02:00
|
|
|
#include "Record_DS.H"
|
2008-04-12 21:13:30 +02:00
|
|
|
|
2008-04-12 21:50:36 +02:00
|
|
|
#include "Transport.H"
|
|
|
|
|
2008-04-28 07:11:47 +02:00
|
|
|
/** return the combined height of all visible children of (veritcal)
|
|
|
|
pack, /p/. This is necessary because pack sizes are adjusted only
|
|
|
|
when the relevant areas are exposes. */
|
|
|
|
static int
|
|
|
|
pack_visible_height ( const Fl_Pack *p )
|
|
|
|
{
|
|
|
|
int th = 0;
|
|
|
|
|
2008-04-28 18:48:35 +02:00
|
|
|
const Fl_Widget* const *w = p->array();
|
|
|
|
for ( int i = p->children(); i--; ++w )
|
2008-04-28 07:11:47 +02:00
|
|
|
if ( (*w)->visible() )
|
|
|
|
th += (*w)->h() + p->spacing();
|
|
|
|
|
|
|
|
return th;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** recalculate the size of vertical scrolling area and inform scrollbar */
|
|
|
|
void
|
|
|
|
Timeline::adjust_vscroll ( void )
|
|
|
|
{
|
|
|
|
vscroll->value( _yposition, h() - rulers->h() - hscroll->h(), 0, pack_visible_height( tracks ) );
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:58:15 +01:00
|
|
|
void
|
2008-03-06 23:45:23 +01:00
|
|
|
Timeline::cb_scroll ( Fl_Widget *w, void *v )
|
2008-02-26 05:58:15 +01:00
|
|
|
{
|
2008-03-06 23:45:23 +01:00
|
|
|
((Timeline*)v)->cb_scroll( w );
|
|
|
|
}
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-03-06 23:45:23 +01:00
|
|
|
void
|
|
|
|
Timeline::cb_scroll ( Fl_Widget *w )
|
|
|
|
{
|
|
|
|
if ( w == vscroll )
|
2008-02-26 05:58:15 +01:00
|
|
|
{
|
2008-03-06 23:45:23 +01:00
|
|
|
tracks->position( tracks->x(), (rulers->y() + rulers->h()) - vscroll->value() );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-03-07 00:29:28 +01:00
|
|
|
yposition( vscroll->value() );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-04-28 07:11:47 +02:00
|
|
|
adjust_vscroll();
|
2008-02-26 05:58:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-06 23:45:23 +01:00
|
|
|
if ( hscroll->zoom_changed() )
|
|
|
|
{
|
2008-05-03 04:17:34 +02:00
|
|
|
|
|
|
|
nframes_t under_mouse = x_to_offset( Fl::event_x() );
|
|
|
|
|
2008-04-27 17:45:49 +02:00
|
|
|
_fpp = hscroll->zoom();
|
2008-02-27 21:04:17 +01:00
|
|
|
|
2008-05-03 04:17:34 +02:00
|
|
|
const int tw = tracks->w() - Track::width();
|
|
|
|
// hscroll->value( ts_to_x( xoffset ), tw, 0, ts_to_x( _length ) );
|
|
|
|
hscroll->value( max( 0, ts_to_x( under_mouse ) - ( Fl::event_x() - tracks->x() - Track::width() ) ),
|
|
|
|
tw, 0, ts_to_x( _length ) );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-03-06 23:45:23 +01:00
|
|
|
redraw();
|
|
|
|
}
|
2008-04-27 15:37:50 +02:00
|
|
|
|
|
|
|
xposition( hscroll->value() );
|
2008-03-06 23:45:23 +01:00
|
|
|
}
|
2008-02-26 05:58:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-01 05:57:53 +01:00
|
|
|
Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Window( X, Y, W, H, L )
|
2008-02-21 17:20:36 +01:00
|
|
|
{
|
2008-02-23 07:59:10 +01:00
|
|
|
|
2008-02-29 03:47:29 +01:00
|
|
|
box( FL_FLAT_BOX );
|
2008-02-23 07:59:10 +01:00
|
|
|
xoffset = 0;
|
2008-04-28 18:48:35 +02:00
|
|
|
_yposition = 0;
|
|
|
|
_old_yposition = 0;
|
|
|
|
_old_xposition = 0;
|
2008-02-23 07:59:10 +01:00
|
|
|
|
2008-03-01 05:57:53 +01:00
|
|
|
X = Y = 0;
|
2008-04-23 04:22:46 +02:00
|
|
|
|
2008-04-26 10:42:44 +02:00
|
|
|
p1 = p2 = 0;
|
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
{
|
2008-02-28 21:10:41 +01:00
|
|
|
Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-03-05 03:12:54 +01:00
|
|
|
o->range( 0, 48000 * 300 );
|
2008-04-27 15:37:50 +02:00
|
|
|
// o->zoom_range( 1, 16384 );
|
2008-04-27 17:45:49 +02:00
|
|
|
// o->zoom_range( 1, 65536 << 4 );
|
|
|
|
o->zoom_range( 1, 20 );
|
|
|
|
|
|
|
|
o->zoom( 8 );
|
|
|
|
|
2008-02-26 05:58:15 +01:00
|
|
|
o->type( FL_HORIZONTAL );
|
2008-03-06 23:45:23 +01:00
|
|
|
o->callback( cb_scroll, this );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
|
|
|
hscroll = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-02-28 21:10:41 +01:00
|
|
|
Fl_Scrollbar *o = new Fl_Scrollbar( X + W - 18, Y, 18, H - 18 );
|
2008-02-26 05:58:15 +01:00
|
|
|
|
|
|
|
o->type( FL_VERTICAL );
|
2008-03-06 23:45:23 +01:00
|
|
|
o->callback( cb_scroll, this );
|
2008-02-26 05:58:15 +01:00
|
|
|
vscroll = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Fl_Pack *o = new Fl_Pack( X + Track::width(), Y, (W - Track::width()) - vscroll->w(), H - hscroll->h(), "rulers" );
|
2008-02-21 17:20:36 +01:00
|
|
|
o->type( Fl_Pack::VERTICAL );
|
|
|
|
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Tempo_Sequence *o = new Tempo_Sequence( 0, 0, 800, 24 );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
2008-04-27 12:33:26 +02:00
|
|
|
o->color( fl_gray_ramp( 18 ) );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
2008-02-29 03:47:29 +01:00
|
|
|
o->label( "Tempo" );
|
|
|
|
o->align( FL_ALIGN_LEFT );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
|
|
|
tempo_track = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Time_Sequence *o = new Time_Sequence( 0, 24, 800, 24 );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
2008-04-27 12:33:26 +02:00
|
|
|
o->color( fl_gray_ramp( 16 ) );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
2008-02-29 03:47:29 +01:00
|
|
|
o->label( "Time" );
|
|
|
|
o->align( FL_ALIGN_LEFT );
|
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
time_track = o;
|
|
|
|
}
|
|
|
|
|
2008-04-18 22:18:07 +02:00
|
|
|
|
2008-05-05 01:06:36 +02:00
|
|
|
/* { */
|
|
|
|
/* Annotation_Sequence *o = new Annotation_Sequence( 0, 24, 800, 24 ); */
|
2008-04-18 22:18:07 +02:00
|
|
|
|
2008-05-05 01:06:36 +02:00
|
|
|
/* o->color( fl_gray_ramp( 'F' ) ); */
|
2008-04-18 22:18:07 +02:00
|
|
|
|
2008-05-05 01:06:36 +02:00
|
|
|
/* o->label( "Ruler" ); */
|
|
|
|
/* o->align( FL_ALIGN_LEFT ); */
|
|
|
|
|
|
|
|
/* ruler_track = o; */
|
|
|
|
/* } */
|
2008-04-18 22:18:07 +02:00
|
|
|
|
2008-02-26 05:58:15 +01:00
|
|
|
o->size( o->w(), o->child( 0 )->h() * o->children() );
|
2008-02-21 17:20:36 +01:00
|
|
|
rulers = o;
|
|
|
|
o->end();
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:58:15 +01:00
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
{
|
2008-04-27 14:04:37 +02:00
|
|
|
// sample_rate() = engine->sample_rate();
|
2008-04-27 17:45:49 +02:00
|
|
|
_fpp = 8;
|
2008-04-27 14:04:37 +02:00
|
|
|
// _length = sample_rate() * 60 * 2;
|
|
|
|
/* FIXME: hack */
|
|
|
|
_length = -1;
|
2008-02-21 17:20:36 +01:00
|
|
|
|
|
|
|
{
|
2008-04-28 06:42:05 +02:00
|
|
|
Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 1 );
|
2008-02-21 17:20:36 +01:00
|
|
|
o->type( Fl_Pack::VERTICAL );
|
2008-04-28 06:42:05 +02:00
|
|
|
o->spacing( 1 );
|
2008-02-21 17:20:36 +01:00
|
|
|
|
|
|
|
tracks = o;
|
|
|
|
o->end();
|
2008-04-23 04:22:46 +02:00
|
|
|
resizable( o );
|
2008-02-21 17:20:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-26 14:37:25 +02:00
|
|
|
/* rulers go above tracks... */
|
|
|
|
add( rulers );
|
2008-04-12 21:50:36 +02:00
|
|
|
|
2008-02-29 04:34:03 +01:00
|
|
|
/* make sure scrollbars are on top */
|
|
|
|
add( vscroll );
|
|
|
|
add( hscroll );
|
|
|
|
|
2008-02-26 05:58:15 +01:00
|
|
|
vscroll->range( 0, tracks->h() );
|
|
|
|
|
2008-02-23 07:59:10 +01:00
|
|
|
redraw();
|
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
end();
|
2008-04-12 21:50:36 +02:00
|
|
|
|
|
|
|
Fl::add_timeout( UPDATE_FREQ, update_cb, this );
|
|
|
|
|
2008-02-21 17:20:36 +01:00
|
|
|
}
|
2008-02-21 11:39:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
float
|
|
|
|
Timeline::beats_per_minute ( nframes_t when ) const
|
|
|
|
{
|
|
|
|
return tempo_track->beats_per_minute( when );
|
|
|
|
}
|
|
|
|
|
2008-02-28 17:37:02 +01:00
|
|
|
int
|
|
|
|
Timeline::beats_per_bar ( nframes_t when ) const
|
|
|
|
{
|
|
|
|
time_sig t = time_track->time( when );
|
|
|
|
|
|
|
|
return t.beats_per_bar;
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:39:13 +01:00
|
|
|
void
|
|
|
|
Timeline::beats_per_minute ( nframes_t when, float bpm )
|
|
|
|
{
|
|
|
|
tempo_track->add( new Tempo_Point( when, bpm ) );
|
|
|
|
}
|
|
|
|
|
2008-05-08 00:55:01 +02:00
|
|
|
void
|
|
|
|
Timeline::time ( nframes_t when, int bpb, int note_type )
|
|
|
|
{
|
|
|
|
time_track->add( new Time_Point( when, bpb, note_type ) );
|
|
|
|
}
|
|
|
|
|
2008-04-18 22:18:07 +02:00
|
|
|
#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 )
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Tempo_Sequence *tempo = (Tempo_Sequence*)rulers->child( 0 );
|
2008-04-18 22:18:07 +02:00
|
|
|
|
|
|
|
BBT bbt;
|
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
for ( list <Sequence_Widget *>::const_iterator i = tempo.widgets.begin();
|
2008-04-18 22:18:07 +02:00
|
|
|
i != tempo.widgets.end(); ++i )
|
|
|
|
{
|
|
|
|
Tempo_Point *p = *i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
nearest_line_cb ( nframes_t frame, int X, int Y, int H, void *arg )
|
|
|
|
{
|
|
|
|
*((nframes_t*)arg) = frame;
|
|
|
|
}
|
|
|
|
|
2008-02-28 21:36:46 +01:00
|
|
|
/** return the absolute pixel of the nearest measure line to /x/ */
|
2008-05-03 03:48:16 +02:00
|
|
|
bool
|
|
|
|
Timeline::nearest_line ( nframes_t when, nframes_t *frame ) const
|
2008-02-28 21:36:46 +01:00
|
|
|
{
|
2008-04-26 18:07:43 +02:00
|
|
|
if ( snap_to == None )
|
2008-05-03 03:48:16 +02:00
|
|
|
return false;
|
2008-04-26 18:07:43 +02:00
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
*frame = -1;
|
2008-04-27 18:01:55 +02:00
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
/* FIXME: handle snap to bar */
|
|
|
|
draw_measure( when - x_to_ts( 10 ), 0, 20, 0, (Fl_Color)0, nearest_line_cb, frame, false );
|
2008-02-28 21:36:46 +01:00
|
|
|
|
2008-05-04 01:44:28 +02:00
|
|
|
return *frame != (nframes_t)-1;
|
2008-05-03 03:48:16 +02:00
|
|
|
}
|
2008-04-27 15:37:50 +02:00
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
nframes_t
|
|
|
|
Timeline::x_to_offset ( int x ) const
|
|
|
|
{
|
|
|
|
return x_to_ts( max( 0, x - Track::width() ) ) + xoffset;
|
|
|
|
}
|
2008-04-26 18:07:43 +02:00
|
|
|
|
|
|
|
|
2008-02-28 21:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
void
|
|
|
|
static
|
|
|
|
draw_measure_cb ( nframes_t frame, int X, int Y, int H, void *arg )
|
2008-04-30 23:03:58 +02:00
|
|
|
{
|
2008-05-03 03:48:16 +02:00
|
|
|
|
|
|
|
fl_color( FL_BLACK );
|
|
|
|
|
|
|
|
fl_line( X, Y, X, Y + H );
|
2008-04-30 23:03:58 +02:00
|
|
|
}
|
|
|
|
|
2008-03-01 06:42:03 +01:00
|
|
|
/** draw appropriate measure lines inside the given bounding box */
|
2008-02-21 11:39:13 +01:00
|
|
|
void
|
2008-05-03 03:48:16 +02:00
|
|
|
Timeline::draw_measure ( nframes_t when, int Y, int W, int H, Fl_Color color, measure_line_callback * cb, void *arg, bool BBT ) const
|
2008-02-21 11:39:13 +01:00
|
|
|
{
|
2008-04-25 04:48:44 +02:00
|
|
|
if ( ! draw_with_measure_lines )
|
2008-03-01 06:42:03 +01:00
|
|
|
return;
|
|
|
|
|
2008-05-04 01:25:59 +02:00
|
|
|
if ( ! tempo_track->_widgets.size() || ! time_track->_widgets.size() )
|
|
|
|
{
|
|
|
|
DWARNING( "No tempo/time points" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-01 16:48:15 +01:00
|
|
|
fl_line_style( FL_DASH, 0 );
|
2008-02-28 17:37:02 +01:00
|
|
|
|
2008-04-27 18:01:55 +02:00
|
|
|
const Fl_Color beat = fl_color_average( FL_BLACK, color, 0.65f );
|
2008-04-30 23:03:58 +02:00
|
|
|
const Fl_Color bar = fl_color_average( FL_RED, beat, 0.65f );
|
2008-02-21 11:39:13 +01:00
|
|
|
|
2008-04-27 18:01:55 +02:00
|
|
|
const nframes_t samples_per_minute = sample_rate() * 60;
|
2008-02-21 11:39:13 +01:00
|
|
|
|
2008-04-27 20:44:20 +02:00
|
|
|
/* we need to back up a bit in order to catch all the numbers */
|
2008-04-30 23:03:58 +02:00
|
|
|
|
|
|
|
/* if ( BBT ) */
|
|
|
|
/* { */
|
|
|
|
/* X -= 40; */
|
|
|
|
/* W += 40; */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
list <Sequence_Widget*>::const_iterator tpi;
|
|
|
|
list <Sequence_Widget*>::const_iterator mpi;
|
|
|
|
|
|
|
|
/* find the first points before our range */
|
|
|
|
|
|
|
|
for ( list <Sequence_Widget *>::const_reverse_iterator i = tempo_track->_widgets.rbegin();
|
|
|
|
i != tempo_track->_widgets.rend(); i++ )
|
|
|
|
if ( (*i)->offset() <= when )
|
|
|
|
{
|
|
|
|
tpi = i.base();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( list <Sequence_Widget *>::const_reverse_iterator i = time_track->_widgets.rbegin();
|
|
|
|
i != time_track->_widgets.rend(); i++ )
|
|
|
|
if ( (*i)->offset() <= when )
|
|
|
|
{
|
|
|
|
mpi = i.base();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-04 01:25:59 +02:00
|
|
|
|
2008-04-30 23:03:58 +02:00
|
|
|
--tpi;
|
|
|
|
|
|
|
|
/* start on the next beat */
|
|
|
|
const Tempo_Point *tp = (Tempo_Point*)(*tpi);
|
|
|
|
nframes_t beat_inc = samples_per_minute / tp->tempo();
|
|
|
|
|
|
|
|
nframes_t f = when - ( ( when - tp->offset() ) % beat_inc );
|
|
|
|
|
|
|
|
for ( ; tpi != tempo_track->_widgets.end(); ++tpi )
|
2008-04-27 20:44:20 +02:00
|
|
|
{
|
2008-04-30 23:03:58 +02:00
|
|
|
list <Sequence_Widget*>::const_iterator ntpi = tpi;
|
|
|
|
++ntpi;
|
|
|
|
|
|
|
|
tp = (Tempo_Point*)(*tpi);
|
2008-05-02 03:21:35 +02:00
|
|
|
const Tempo_Point *ntp = ntpi == tempo_track->_widgets.end() ? NULL : (Tempo_Point*)(*ntpi);
|
2008-04-30 23:03:58 +02:00
|
|
|
|
|
|
|
const nframes_t ntpo = ntp ? ntp->offset() : when + x_to_ts( W + 1 );
|
|
|
|
|
|
|
|
beat_inc = samples_per_minute / tp->tempo();
|
|
|
|
|
|
|
|
const int incx = ts_to_x( beat_inc );
|
|
|
|
|
|
|
|
if ( incx < 8 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for ( ; f < ntpo; f += beat_inc )
|
|
|
|
{
|
|
|
|
const int x = ts_to_x( f - xoffset ) + Track::width();
|
|
|
|
|
2008-05-03 03:48:16 +02:00
|
|
|
cb( f, x, Y, H, arg );
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
2008-02-21 11:39:13 +01:00
|
|
|
}
|
2008-04-27 15:37:50 +02:00
|
|
|
|
2008-02-21 11:39:13 +01:00
|
|
|
fl_line_style( FL_SOLID, 0 );
|
|
|
|
}
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-04-18 22:18:07 +02:00
|
|
|
void
|
|
|
|
Timeline::draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
|
|
|
|
{
|
2008-05-03 03:48:16 +02:00
|
|
|
draw_measure( x_to_offset( X ), Y, W, H, color, draw_measure_cb, 0, false );
|
2008-04-18 22:18:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 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 )
|
|
|
|
{
|
2008-05-03 03:48:16 +02:00
|
|
|
// draw_measure( X, Y, W, H, color, true );
|
2008-04-18 22:18:07 +02:00
|
|
|
}
|
2008-02-28 19:34:10 +01:00
|
|
|
|
|
|
|
void
|
2008-03-07 00:29:28 +01:00
|
|
|
Timeline::xposition ( int X )
|
2008-02-28 19:34:10 +01:00
|
|
|
{
|
2008-03-07 00:29:28 +01:00
|
|
|
// _old_xposition = xoffset;
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-04-27 15:37:50 +02:00
|
|
|
/* FIXME: shouldn't have to do this... */
|
|
|
|
X = min( X, ts_to_x( _length ) - tracks->w() - Track::width() );
|
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
xoffset = x_to_ts( X );
|
|
|
|
|
|
|
|
damage( FL_DAMAGE_SCROLL );
|
|
|
|
}
|
|
|
|
|
2008-03-07 00:29:28 +01:00
|
|
|
void
|
|
|
|
Timeline::yposition ( int Y )
|
|
|
|
{
|
|
|
|
// _old_yposition = _yposition;
|
|
|
|
|
|
|
|
_yposition = Y;
|
|
|
|
|
|
|
|
damage( FL_DAMAGE_SCROLL );
|
|
|
|
}
|
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
void
|
|
|
|
Timeline::draw_clip ( void * v, int X, int Y, int W, int H )
|
|
|
|
{
|
|
|
|
Timeline *tl = (Timeline *)v;
|
|
|
|
|
|
|
|
fl_push_clip( X, Y, W, H );
|
|
|
|
|
2008-04-28 06:42:05 +02:00
|
|
|
/* fl_color( rand() ); */
|
|
|
|
/* fl_rectf( X, Y, X + W, Y + H ); */
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-04-28 06:42:05 +02:00
|
|
|
tl->draw_box();
|
2008-02-29 03:47:29 +01:00
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
tl->draw_child( *tl->rulers );
|
|
|
|
|
2008-04-28 07:11:47 +02:00
|
|
|
fl_push_clip( tl->tracks->x(), tl->rulers->y() + tl->rulers->h(), tl->tracks->w(), tl->h() - tl->rulers->h() - tl->hscroll->h() );
|
2008-02-29 03:47:29 +01:00
|
|
|
tl->draw_child( *tl->tracks );
|
2008-04-28 07:11:47 +02:00
|
|
|
fl_pop_clip();
|
2008-02-29 03:47:29 +01:00
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
fl_pop_clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-23 04:22:46 +02:00
|
|
|
// static unsigned char *rect_image;
|
2008-03-09 18:38:50 +01:00
|
|
|
|
2008-04-23 04:22:46 +02:00
|
|
|
void
|
|
|
|
Timeline::resize ( int X, int Y, int W, int H )
|
|
|
|
{
|
|
|
|
Fl_Overlay_Window::resize( X, Y, W, H );
|
2008-03-09 18:38:50 +01:00
|
|
|
|
2008-04-23 04:22:46 +02:00
|
|
|
/* why is this necessary? */
|
2008-04-23 08:33:21 +02:00
|
|
|
rulers->resize( Track::width(), 0, W - Track::width() - vscroll->w(), rulers->h() );
|
2008-04-26 12:17:47 +02:00
|
|
|
|
|
|
|
/* why is THIS necessary? */
|
|
|
|
hscroll->resize( 0, H - 18, hscroll->w(), 18 );
|
|
|
|
vscroll->size( vscroll->w(), H - 18 );
|
2008-04-23 04:22:46 +02:00
|
|
|
}
|
2008-03-09 18:38:50 +01:00
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
void
|
|
|
|
Timeline::draw ( void )
|
|
|
|
{
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
2008-04-19 03:05:57 +02:00
|
|
|
int bdx = 0;
|
|
|
|
int bdw = 0;
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-04-19 03:05:57 +02:00
|
|
|
X = tracks->x() + bdx + 1;
|
|
|
|
Y = tracks->y();
|
|
|
|
W = tracks->w() - bdw - 1;
|
|
|
|
H = tracks->h();
|
2008-03-09 18:38:50 +01:00
|
|
|
|
2008-04-28 07:11:47 +02:00
|
|
|
adjust_vscroll();
|
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* if ( damage() & FL_DAMAGE_USER1 ) */
|
|
|
|
/* { */
|
|
|
|
|
|
|
|
/* /\* save the rectangle so we can draw it (darkened) in the overlay *\/ */
|
|
|
|
/* Rectangle &r = _selection; */
|
|
|
|
/* make_current(); */
|
|
|
|
/* rect_image = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
|
|
|
|
|
|
|
|
/* return; */
|
|
|
|
/* } */
|
|
|
|
|
2008-05-06 01:49:18 +02:00
|
|
|
|
2008-04-30 02:38:28 +02:00
|
|
|
if ( ( damage() & FL_DAMAGE_ALL ) || ( damage() & FL_DAMAGE_EXPOSE ) )
|
2008-02-28 19:34:10 +01:00
|
|
|
{
|
2008-05-04 01:44:28 +02:00
|
|
|
DMESSAGE( "complete redraw" );
|
2008-04-27 20:44:20 +02:00
|
|
|
|
2008-04-27 14:34:33 +02:00
|
|
|
draw_box( box(), 0, 0, w(), h(), color() );
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-03-01 07:01:00 +01:00
|
|
|
fl_push_clip( 0, rulers->y(), w(), rulers->h() );
|
2008-02-28 19:34:10 +01:00
|
|
|
draw_child( *rulers );
|
|
|
|
fl_pop_clip();
|
|
|
|
|
2008-03-01 16:48:15 +01:00
|
|
|
fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), hscroll->y() - (rulers->y() + rulers->h()) );
|
2008-02-28 19:34:10 +01:00
|
|
|
draw_child( *tracks );
|
|
|
|
fl_pop_clip();
|
|
|
|
|
|
|
|
draw_child( *hscroll );
|
|
|
|
draw_child( *vscroll );
|
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
redraw_overlay();
|
2008-03-09 06:06:37 +01:00
|
|
|
|
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* Rectangle &r = _selection; */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
|
|
|
/* unsigned char *data = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
|
|
|
|
|
|
|
|
/* Fl_RGB_Image bi( data, r.w, r.h, 3 ); */
|
|
|
|
|
|
|
|
/* bi.color_average( FL_BLACK, 0.50f ); */
|
|
|
|
|
|
|
|
/* bi.draw( r.x, r.y ); */
|
|
|
|
|
|
|
|
/* delete[] data; */
|
|
|
|
|
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* if ( r.w && r.h ) */
|
|
|
|
/* { */
|
|
|
|
/* const unsigned char data[] = { 0, 127, 0, 96, */
|
|
|
|
/* 0, 96, 0, 127 }; */
|
|
|
|
/* Fl_RGB_Image bi( data, 2, 2, 2 ); */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* Fl_Image *bi2 = bi.copy( r.w, r.h ); */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* bi2->draw( r.x, r.y ); */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* delete bi2; */
|
|
|
|
/* } */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-05-06 01:49:18 +02:00
|
|
|
goto done;
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( damage() & FL_DAMAGE_SCROLL )
|
|
|
|
{
|
|
|
|
int dx = ts_to_x( _old_xposition ) - ts_to_x( xoffset );
|
2008-03-07 00:29:28 +01:00
|
|
|
int dy = _old_yposition - _yposition;
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-05-01 06:24:20 +02:00
|
|
|
/* draw_child( *rulers ); */
|
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
if ( ! dy )
|
2008-04-23 08:33:21 +02:00
|
|
|
fl_scroll( rulers->x(), rulers->y(), rulers->w(), rulers->h(), dx, 0, draw_clip, this );
|
2008-02-28 19:34:10 +01:00
|
|
|
|
|
|
|
Y = rulers->y() + rulers->h();
|
|
|
|
H = h() - rulers->h() - hscroll->h();
|
|
|
|
|
2008-02-29 03:02:40 +01:00
|
|
|
if ( dy == 0 )
|
2008-04-19 06:16:21 +02:00
|
|
|
fl_scroll( X + Track::width(), Y, W - Track::width(), H, dx, dy, draw_clip, this );
|
2008-02-29 03:02:40 +01:00
|
|
|
else
|
|
|
|
fl_scroll( X, Y, W, H, dx, dy, draw_clip, this );
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
2008-03-09 06:06:37 +01:00
|
|
|
|
2008-04-27 09:18:03 +02:00
|
|
|
if ( damage() & FL_DAMAGE_CHILD )
|
|
|
|
{
|
|
|
|
fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
|
|
|
|
update_child( *rulers );
|
|
|
|
fl_pop_clip();
|
|
|
|
|
2008-04-28 07:11:47 +02:00
|
|
|
fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - rulers->h() - hscroll->h() );
|
2008-04-27 09:18:03 +02:00
|
|
|
update_child( *tracks );
|
|
|
|
fl_pop_clip();
|
|
|
|
|
|
|
|
update_child( *hscroll );
|
|
|
|
update_child( *vscroll );
|
|
|
|
}
|
|
|
|
|
2008-05-06 01:49:18 +02:00
|
|
|
done:
|
|
|
|
|
|
|
|
_old_xposition = xoffset;
|
|
|
|
_old_yposition = _yposition;
|
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 21:50:36 +02:00
|
|
|
void
|
2008-04-24 04:23:29 +02:00
|
|
|
Timeline::draw_cursor ( nframes_t frame, Fl_Color color )
|
2008-04-12 21:50:36 +02:00
|
|
|
{
|
2008-05-06 01:49:18 +02:00
|
|
|
// int x = ( ts_to_x( frame ) - ts_to_x( xoffset ) ) + tracks->x() + Track::width();
|
|
|
|
|
|
|
|
if ( frame < xoffset )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int x = ts_to_x( frame - xoffset ) + tracks->x() + Track::width();
|
2008-04-12 21:50:36 +02:00
|
|
|
|
2008-05-06 01:49:18 +02:00
|
|
|
if ( x > tracks->x() + tracks->w() )
|
2008-04-12 21:50:36 +02:00
|
|
|
return;
|
|
|
|
|
2008-04-24 04:23:29 +02:00
|
|
|
fl_color( color );
|
2008-04-12 21:50:36 +02:00
|
|
|
|
2008-05-06 01:49:18 +02:00
|
|
|
const int y = rulers->y() + rulers->h();
|
|
|
|
const int h = this->h() - hscroll->h();
|
2008-04-12 23:47:33 +02:00
|
|
|
|
2008-04-23 08:01:32 +02:00
|
|
|
fl_push_clip( Track::width(), y, tracks->w(), h );
|
|
|
|
|
2008-04-12 23:47:33 +02:00
|
|
|
fl_line( x, y, x, h );
|
2008-04-19 07:30:41 +02:00
|
|
|
|
2008-04-24 04:23:29 +02:00
|
|
|
fl_color( fl_darker( color ) );
|
2008-04-19 07:30:41 +02:00
|
|
|
|
|
|
|
fl_line( x - 1, y, x - 1, h );
|
|
|
|
|
|
|
|
fl_color( FL_BLACK );
|
|
|
|
|
|
|
|
fl_line( x + 1, y, x + 1, h );
|
|
|
|
|
2008-04-23 08:01:32 +02:00
|
|
|
/* draw cap */
|
2008-04-24 04:23:29 +02:00
|
|
|
fl_color( color );
|
2008-04-23 08:01:32 +02:00
|
|
|
fl_begin_polygon();
|
|
|
|
|
|
|
|
fl_vertex( x - 8, y );
|
|
|
|
fl_vertex( x, y + 8 );
|
|
|
|
fl_vertex( x + 8, y );
|
|
|
|
|
|
|
|
fl_end_polygon();
|
|
|
|
|
|
|
|
|
|
|
|
/* draw cap outline */
|
|
|
|
fl_color( FL_BLACK );
|
|
|
|
fl_begin_line();
|
|
|
|
|
|
|
|
fl_vertex( x - 8, y );
|
|
|
|
fl_vertex( x, y + 8 );
|
|
|
|
fl_vertex( x + 8, y );
|
|
|
|
|
|
|
|
fl_end_line();
|
|
|
|
|
|
|
|
fl_pop_clip();
|
2008-04-24 04:23:29 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Timeline::draw_playhead ( void )
|
|
|
|
{
|
2008-04-26 10:42:44 +02:00
|
|
|
if ( p1 != p2 )
|
|
|
|
{
|
|
|
|
draw_cursor( p1, FL_BLUE );
|
|
|
|
draw_cursor( p2, FL_GREEN );
|
|
|
|
}
|
2008-04-24 04:23:29 +02:00
|
|
|
|
|
|
|
draw_cursor( transport->frame, FL_RED );
|
2008-04-12 21:50:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Timeline::redraw_playhead ( void )
|
|
|
|
{
|
2008-04-13 02:02:58 +02:00
|
|
|
static nframes_t last_playhead = -1;
|
|
|
|
|
2008-04-22 04:47:29 +02:00
|
|
|
if ( last_playhead != transport->frame )
|
2008-04-13 02:02:58 +02:00
|
|
|
{
|
|
|
|
redraw_overlay();
|
2008-04-22 04:47:29 +02:00
|
|
|
last_playhead = transport->frame;
|
2008-04-30 03:08:49 +02:00
|
|
|
|
|
|
|
if ( follow_playhead )
|
2008-05-01 08:47:49 +02:00
|
|
|
{
|
|
|
|
if ( center_playhead && active() )
|
|
|
|
xposition( max( 0, ts_to_x( transport->frame ) - ( ( tracks->w() - Track::width() ) >> 1 ) ) );
|
|
|
|
else if ( ts_to_x( transport->frame ) > ts_to_x( xoffset ) + ( tracks->w() - Track::width() ) )
|
|
|
|
xposition( ts_to_x( transport->frame ) );
|
|
|
|
}
|
2008-04-13 02:02:58 +02:00
|
|
|
}
|
2008-04-12 21:50:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** called so many times a second to redraw the playhead etc. */
|
|
|
|
void
|
|
|
|
Timeline::update_cb ( void *arg )
|
|
|
|
{
|
|
|
|
Fl::repeat_timeout( UPDATE_FREQ, update_cb, arg );
|
|
|
|
|
|
|
|
Timeline *tl = (Timeline *)arg;
|
|
|
|
|
|
|
|
tl->redraw_playhead();
|
|
|
|
}
|
|
|
|
|
2008-03-01 05:57:53 +01:00
|
|
|
void
|
|
|
|
Timeline::draw_overlay ( void )
|
|
|
|
{
|
2008-04-12 21:50:36 +02:00
|
|
|
|
|
|
|
draw_playhead();
|
|
|
|
|
2008-03-09 06:06:37 +01:00
|
|
|
if ( ! ( _selection.w && _selection.h ) )
|
|
|
|
return;
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
fl_push_clip( tracks->x() + Track::width(), rulers->y() + rulers->h(), tracks->w() - Track::width(), h() - rulers->h() - hscroll->h() );
|
2008-03-06 00:15:44 +01:00
|
|
|
|
|
|
|
const Rectangle &r = _selection;
|
|
|
|
|
|
|
|
fl_color( FL_BLACK );
|
2008-03-07 00:21:57 +01:00
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
fl_line_style( FL_SOLID, 2 );
|
2008-03-07 00:21:57 +01:00
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
fl_rect( r.x + 2, r.y + 2, r.w, r.h );
|
|
|
|
fl_color( FL_MAGENTA );
|
|
|
|
fl_line_style( FL_DASH, 2 );
|
|
|
|
fl_rect( r.x, r.y, r.w, r.h );
|
|
|
|
|
2008-03-07 00:21:57 +01:00
|
|
|
fl_line( r.x, r.y, r.x + r.w, r.y + r.h );
|
|
|
|
|
|
|
|
fl_line( r.x + r.w, r.y, r.x, r.y + r.h );
|
|
|
|
|
|
|
|
/* fl_overlay_rect( r.x, r.y, r.w, r.h ); */
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
fl_line_style( FL_SOLID, 0 );
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
|
2008-03-09 06:06:37 +01:00
|
|
|
/* const unsigned char data[] = { 127, 127, 127, 96, */
|
|
|
|
/* 127, 96, 127, 40 }; */
|
|
|
|
/* Fl_RGB_Image bi( data, 2, 2, 2 ); */
|
|
|
|
|
|
|
|
/* Fl_Image *bi2 = bi.copy( r.w, r.h ); */
|
|
|
|
|
|
|
|
/* bi2->draw( r.x, r.y ); */
|
|
|
|
|
|
|
|
/* delete bi2; */
|
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
|
2008-03-09 06:06:37 +01:00
|
|
|
/* unsigned char *data = fl_read_image( NULL, r.x, r.y, r.w, r.h, 0 ); */
|
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Fl_RGB_Image bi( rect_image, r.w, r.h, 3 ); */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
|
|
|
/* bi.color_average( FL_BLACK, 0.50f ); */
|
|
|
|
|
|
|
|
/* bi.draw( r.x, r.y ); */
|
|
|
|
|
2008-03-09 18:38:50 +01:00
|
|
|
/* delete[] rect_image; */
|
|
|
|
/* rect_image = NULL; */
|
2008-03-09 06:06:37 +01:00
|
|
|
|
|
|
|
fl_pop_clip();
|
2008-03-06 00:15:44 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
}
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-04-19 06:16:21 +02:00
|
|
|
// #include "Sequence_Widget.H"
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
/** select all widgets in inside rectangle /r/ */
|
|
|
|
void
|
2008-04-29 23:16:09 +02:00
|
|
|
Timeline::select ( const Rectangle &r )
|
2008-03-05 20:06:41 +01:00
|
|
|
{
|
2008-03-06 00:15:44 +01:00
|
|
|
const int Y = r.y;
|
2008-03-05 20:32:39 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Track *t = (Track*)tracks->child( i );
|
2008-03-01 05:57:53 +01:00
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
if ( ! ( t->y() > Y + r.h || t->y() + t->h() < Y ) )
|
2008-04-29 22:47:03 +02:00
|
|
|
t->select( r.x, r.y, r.w, r.h, true, true );
|
2008-03-05 20:06:41 +01:00
|
|
|
}
|
2008-03-01 05:57:53 +01:00
|
|
|
}
|
2008-02-28 19:34:10 +01:00
|
|
|
|
2008-04-29 23:16:09 +02:00
|
|
|
void
|
|
|
|
Timeline::delete_selected ( void )
|
|
|
|
{
|
|
|
|
Sequence_Widget::delete_selected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Timeline::select_none ( void )
|
|
|
|
{
|
|
|
|
Sequence_Widget::select_none();
|
|
|
|
}
|
|
|
|
|
2008-05-01 11:47:37 +02:00
|
|
|
|
|
|
|
/** An unfortunate necessity for implementing our own DND aside from
|
|
|
|
* the (bogus) native FLTK system */
|
|
|
|
Track *
|
|
|
|
Timeline::track_under ( int Y )
|
|
|
|
{
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( ! ( t->y() > Y || t->y() + t->h() < Y ) )
|
|
|
|
return t;
|
|
|
|
}
|
2008-05-04 01:44:28 +02:00
|
|
|
|
|
|
|
return NULL;
|
2008-05-01 11:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
int
|
|
|
|
Timeline::handle ( int m )
|
|
|
|
{
|
2008-03-05 20:06:41 +01:00
|
|
|
static Drag *drag = NULL;
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
switch ( m )
|
|
|
|
{
|
2008-04-27 05:50:58 +02:00
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
2008-04-27 20:44:20 +02:00
|
|
|
// redraw();
|
2008-04-27 05:50:58 +02:00
|
|
|
return 1;
|
2008-03-03 19:59:05 +01:00
|
|
|
case FL_KEYBOARD:
|
2008-04-27 05:50:58 +02:00
|
|
|
case FL_SHORTCUT:
|
2008-03-03 19:59:05 +01:00
|
|
|
{
|
2008-05-07 01:38:55 +02:00
|
|
|
if ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) )
|
2008-04-27 05:50:58 +02:00
|
|
|
/* we don't want any keys with modifiers... */
|
|
|
|
return 0;
|
|
|
|
|
2008-03-03 19:59:05 +01:00
|
|
|
switch ( Fl::event_key() )
|
|
|
|
{
|
|
|
|
case FL_Delete:
|
2008-04-27 05:50:58 +02:00
|
|
|
case FL_Home:
|
|
|
|
case FL_End:
|
|
|
|
/* keep scrollbar from eating these. */
|
|
|
|
return 0;
|
2008-04-22 02:52:59 +02:00
|
|
|
case 'p':
|
|
|
|
{
|
|
|
|
int X = Fl::event_x() - Track::width();
|
|
|
|
|
|
|
|
if ( X > 0 )
|
|
|
|
{
|
2008-04-22 04:47:29 +02:00
|
|
|
transport->locate( xoffset + x_to_ts( X ) );
|
2008-04-22 02:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2008-04-24 04:23:29 +02:00
|
|
|
case '[':
|
|
|
|
{
|
|
|
|
int X = Fl::event_x() - Track::width();
|
|
|
|
|
|
|
|
if ( X > 0 )
|
|
|
|
{
|
|
|
|
p1 = xoffset + x_to_ts( X );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case ']':
|
|
|
|
{
|
|
|
|
int X = Fl::event_x() - Track::width();
|
|
|
|
|
|
|
|
if ( X > 0 )
|
|
|
|
{
|
|
|
|
p2 = xoffset + x_to_ts( X );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2008-04-15 09:13:22 +02:00
|
|
|
default:
|
|
|
|
return Fl_Overlay_Window::handle( m );
|
2008-03-03 19:59:05 +01:00
|
|
|
}
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2008-04-27 05:50:58 +02:00
|
|
|
|
|
|
|
if ( m == FL_PUSH )
|
|
|
|
Fl::focus( this );
|
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
int r = Fl_Overlay_Window::handle( m );
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-06 00:15:44 +01:00
|
|
|
if ( m != FL_RELEASE && r )
|
2008-03-05 20:06:41 +01:00
|
|
|
return r;
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
const int X = Fl::event_x();
|
|
|
|
const int Y = Fl::event_y();
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
switch ( m )
|
|
|
|
{
|
|
|
|
case FL_PUSH:
|
|
|
|
{
|
2008-04-27 05:50:58 +02:00
|
|
|
// take_focus();
|
2008-04-15 09:13:22 +02:00
|
|
|
|
2008-05-02 08:01:35 +02:00
|
|
|
if ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) )
|
|
|
|
return 0;
|
|
|
|
|
2008-04-19 04:26:27 +02:00
|
|
|
if ( Fl::event_button1() )
|
|
|
|
{
|
|
|
|
assert( ! drag );
|
|
|
|
|
|
|
|
drag = new Drag( X - x(), Y - y() );
|
|
|
|
_selection.x = drag->x;
|
|
|
|
_selection.y = drag->y;
|
|
|
|
}
|
2008-05-06 05:00:30 +02:00
|
|
|
else if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() )
|
2008-04-19 04:26:27 +02:00
|
|
|
{
|
|
|
|
Fl_Menu_Item menu[] =
|
|
|
|
{
|
|
|
|
{ "Add Track", 0, 0, 0, FL_SUBMENU },
|
|
|
|
{ "Audio", 0, 0, 0 },
|
|
|
|
{ 0 },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
const Fl_Menu_Item *r = menu->popup( X, Y, "Timeline" );
|
|
|
|
|
|
|
|
if ( r == &menu[1] )
|
|
|
|
{
|
|
|
|
/* FIXME: prompt for I/O config? */
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
Loggable::block_start();
|
|
|
|
|
2008-04-19 04:26:27 +02:00
|
|
|
/* add audio track */
|
2008-04-19 07:09:42 +02:00
|
|
|
char *name = get_unique_track_name( "Audio" );
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
Track *t = new Track( name );
|
2008-03-06 00:15:44 +01:00
|
|
|
|
2008-05-05 07:29:39 +02:00
|
|
|
Audio_Sequence *o = new Audio_Sequence( t );
|
2008-04-30 03:12:35 +02:00
|
|
|
|
|
|
|
// new Control_Sequence( t );
|
2008-04-19 04:26:27 +02:00
|
|
|
|
2008-04-24 00:29:14 +02:00
|
|
|
add_track( t );
|
|
|
|
|
2008-05-07 18:18:57 +02:00
|
|
|
t->sequence( o );
|
2008-04-20 23:46:47 +02:00
|
|
|
|
|
|
|
Loggable::block_end();
|
2008-04-19 04:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2008-03-06 00:15:44 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FL_DRAG:
|
|
|
|
{
|
2008-03-06 00:15:44 +01:00
|
|
|
int ox = X - drag->x;
|
|
|
|
int oy = Y - drag->y;
|
|
|
|
|
|
|
|
if ( ox < 0 )
|
|
|
|
_selection.x = X;
|
|
|
|
if ( oy < 0 )
|
|
|
|
_selection.y = Y;
|
|
|
|
|
|
|
|
_selection.w = abs( ox );
|
|
|
|
_selection.h = abs( oy );
|
2008-03-05 20:06:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FL_RELEASE:
|
|
|
|
{
|
|
|
|
delete drag;
|
|
|
|
drag = NULL;
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
select( _selection );
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
_selection.w = _selection.h = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-03-05 20:06:41 +01:00
|
|
|
redraw_overlay();
|
|
|
|
return 1;
|
|
|
|
}
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
2008-03-01 15:23:59 +01:00
|
|
|
|
2008-02-28 19:34:10 +01:00
|
|
|
}
|
2008-04-08 22:06:38 +02:00
|
|
|
|
|
|
|
|
2008-04-23 22:43:17 +02:00
|
|
|
void
|
|
|
|
Timeline::zoom_in ( void )
|
|
|
|
{
|
|
|
|
hscroll->zoom_in();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Timeline::zoom_out ( void )
|
|
|
|
{
|
|
|
|
hscroll->zoom_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** zoom the display to show /secs/ seconds per screen */
|
|
|
|
void
|
|
|
|
Timeline::zoom ( float secs )
|
|
|
|
{
|
2008-05-03 00:34:43 +02:00
|
|
|
const int sw = tracks->w() - Track::width();
|
2008-04-23 22:43:17 +02:00
|
|
|
|
2008-05-03 00:34:43 +02:00
|
|
|
int fpp = (int)((secs * sample_rate()) / sw);
|
|
|
|
|
|
|
|
int p = 0;
|
|
|
|
while ( 1 << p < fpp ) p++;
|
|
|
|
|
|
|
|
hscroll->zoom( p );
|
2008-04-23 22:43:17 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|
2008-04-19 07:09:42 +02:00
|
|
|
|
2008-05-03 01:03:44 +02:00
|
|
|
void
|
|
|
|
Timeline::zoom_fit ( void )
|
|
|
|
{
|
|
|
|
zoom( _length / (float)sample_rate() );
|
|
|
|
}
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
Track *
|
|
|
|
Timeline::track_by_name ( const char *name )
|
2008-04-19 07:09:42 +02:00
|
|
|
{
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( ! strcmp( name, t->name() ) )
|
2008-04-20 23:46:47 +02:00
|
|
|
return t;
|
2008-04-19 07:09:42 +02:00
|
|
|
}
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
return NULL;
|
2008-04-19 07:09:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
Timeline::get_unique_track_name ( const char *name )
|
|
|
|
{
|
|
|
|
char pat[256];
|
|
|
|
|
|
|
|
strcpy( pat, name );
|
|
|
|
|
2008-04-20 23:46:47 +02:00
|
|
|
for ( int i = 1; track_by_name( pat ); ++i )
|
2008-04-19 07:09:42 +02:00
|
|
|
snprintf( pat, sizeof( pat ), "%s.%d", name, i );
|
|
|
|
|
|
|
|
return strdup( pat );
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:26:27 +02:00
|
|
|
void
|
2008-04-19 06:16:21 +02:00
|
|
|
Timeline::add_track ( Track *track )
|
2008-04-19 04:26:27 +02:00
|
|
|
{
|
2008-05-04 01:44:28 +02:00
|
|
|
DMESSAGE( "added new track to the timeline" );
|
|
|
|
|
2008-04-19 04:26:27 +02:00
|
|
|
/* FIXME: do locking */
|
|
|
|
tracks->add( track );
|
|
|
|
|
|
|
|
/* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
|
|
|
|
redraw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-04-19 06:16:21 +02:00
|
|
|
Timeline::remove_track ( Track *track )
|
2008-04-19 04:26:27 +02:00
|
|
|
{
|
2008-05-04 01:44:28 +02:00
|
|
|
DMESSAGE( "removed track from the timeline" );
|
2008-04-19 04:26:27 +02:00
|
|
|
|
|
|
|
/* FIXME: do locking */
|
|
|
|
|
|
|
|
/* FIXME: what to do about track contents? */
|
|
|
|
tracks->remove( track );
|
|
|
|
|
|
|
|
/* FIXME: why is this necessary? doesn't the above add do DAMAGE_CHILD? */
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2008-04-25 08:34:08 +02:00
|
|
|
/** Initiate recording for all armed tracks */
|
|
|
|
bool
|
|
|
|
Timeline::record ( void )
|
|
|
|
{
|
2008-04-25 09:35:55 +02:00
|
|
|
Loggable::block_start();
|
|
|
|
|
2008-04-25 08:34:08 +02:00
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->armed() && t->record_ds )
|
|
|
|
t->record_ds->start( transport->frame );
|
|
|
|
}
|
|
|
|
|
|
|
|
deactivate();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** stop recording for all armed tracks */
|
|
|
|
void
|
|
|
|
Timeline::stop ( void )
|
|
|
|
{
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->armed() && t->record_ds )
|
|
|
|
t->record_ds->stop( transport->frame );
|
|
|
|
}
|
|
|
|
|
2008-04-25 09:35:55 +02:00
|
|
|
Loggable::block_end();
|
|
|
|
|
2008-04-25 08:34:08 +02:00
|
|
|
activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-08 22:06:38 +02:00
|
|
|
/**********/
|
|
|
|
/* Engine */
|
|
|
|
/**********/
|
|
|
|
|
|
|
|
/** call process() on each track header */
|
|
|
|
nframes_t
|
|
|
|
Timeline::process ( nframes_t nframes )
|
|
|
|
{
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Track *t = (Track*)tracks->child( i );
|
2008-04-08 22:06:38 +02:00
|
|
|
|
|
|
|
t->process( nframes );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: BOGUS */
|
|
|
|
return nframes;
|
|
|
|
}
|
2008-04-12 21:13:30 +02:00
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
void
|
|
|
|
Timeline::seek ( nframes_t frame )
|
|
|
|
{
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Track *t = (Track*)tracks->child( i );
|
2008-04-12 21:13:30 +02:00
|
|
|
|
|
|
|
t->seek( frame );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* THREAD: RT */
|
|
|
|
int
|
|
|
|
Timeline::seek_pending ( void )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
2008-04-19 06:16:21 +02:00
|
|
|
Track *t = (Track*)tracks->child( i );
|
2008-04-12 21:13:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
if ( t->playback_ds )
|
|
|
|
r += t->playback_ds->buffer_percent() < 50;
|
2008-04-12 21:13:30 +02:00
|
|
|
}
|
2008-04-26 12:24:09 +02:00
|
|
|
|
|
|
|
return r;
|
2008-04-12 21:13:30 +02:00
|
|
|
}
|
2008-04-23 07:35:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* FIXME: shouldn't these belong to the engine? */
|
|
|
|
int
|
|
|
|
Timeline::total_input_buffer_percent ( void )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->record_ds )
|
|
|
|
{
|
|
|
|
++cnt;
|
|
|
|
r += t->record_ds->buffer_percent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 00:29:14 +02:00
|
|
|
if ( ! cnt )
|
|
|
|
return 0;
|
|
|
|
|
2008-04-23 07:35:49 +02:00
|
|
|
return r / cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Timeline::total_output_buffer_percent ( void )
|
|
|
|
{
|
2008-04-24 00:29:14 +02:00
|
|
|
|
2008-04-23 07:35:49 +02:00
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->playback_ds )
|
|
|
|
{
|
|
|
|
++cnt;
|
|
|
|
r += t->playback_ds->buffer_percent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 00:29:14 +02:00
|
|
|
if ( ! cnt )
|
|
|
|
return 0;
|
|
|
|
|
2008-04-23 07:35:49 +02:00
|
|
|
return r / cnt;
|
|
|
|
}
|
2008-05-01 13:35:42 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
Timeline::total_playback_xruns ( void )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->playback_ds )
|
|
|
|
r += t->playback_ds->xruns();
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Timeline::total_capture_xruns ( void )
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
for ( int i = tracks->children(); i-- ; )
|
|
|
|
{
|
|
|
|
Track *t = (Track*)tracks->child( i );
|
|
|
|
|
|
|
|
if ( t->record_ds )
|
|
|
|
r += t->record_ds->xruns();
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|