Draw beat lines.
This commit is contained in:
parent
e1e1d43f61
commit
609e00eecf
22
Region.C
22
Region.C
|
@ -36,6 +36,8 @@ using namespace std;
|
||||||
|
|
||||||
extern Timeline timeline;
|
extern Timeline timeline;
|
||||||
|
|
||||||
|
Fl_Boxtype Region::_box = FL_PLASTIC_UP_BOX;
|
||||||
|
|
||||||
void
|
void
|
||||||
Region::init ( void )
|
Region::init ( void )
|
||||||
{
|
{
|
||||||
|
@ -296,6 +298,7 @@ Region::resize ( void )
|
||||||
// Fl_Widget::resize( X, y(), W, h() );
|
// Fl_Widget::resize( X, y(), W, h() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int measure = 40;
|
||||||
|
|
||||||
/* X is the timeline offset, W is the width of the track */
|
/* X is the timeline offset, W is the width of the track */
|
||||||
void
|
void
|
||||||
|
@ -304,6 +307,8 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
if ( ! ( W > 0 && H > 0 ) )
|
if ( ! ( W > 0 && H > 0 ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( _offset > timeline.xoffset + timeline.x_to_ts( _track->w() ) ||
|
if ( _offset > timeline.xoffset + timeline.x_to_ts( _track->w() ) ||
|
||||||
( _offset < timeline.xoffset &&
|
( _offset < timeline.xoffset &&
|
||||||
_offset + (_end - _start) < timeline.xoffset ) )
|
_offset + (_end - _start) < timeline.xoffset ) )
|
||||||
|
@ -331,12 +336,15 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
fl_push_clip( rx, Y, rw, H );
|
fl_push_clip( rx, Y, rw, H );
|
||||||
|
|
||||||
/* dirty hack to keep the box from flipping to vertical at small sizes */
|
/* dirty hack to keep the box from flipping to vertical at small sizes */
|
||||||
fl_draw_box( FL_PLASTIC_UP_BOX, rx - 10, Y, rw + 50, H, _box_color );
|
fl_draw_box( box(), rx - 10, Y, rw + 50, H, _box_color );
|
||||||
|
|
||||||
|
|
||||||
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
|
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
|
||||||
|
|
||||||
draw_waveform( rx, Y, rw, H, _clip, _start + offset, min( (_end - _start) - offset, _end), _scale, _color );
|
draw_waveform( rx, Y, rw, H, _clip, _start + offset, min( (_end - _start) - offset, _end), _scale, _color );
|
||||||
|
|
||||||
|
timeline.draw_measure_lines( rx, Y, rw, H, _box_color );
|
||||||
|
|
||||||
fl_color( FL_BLACK );
|
fl_color( FL_BLACK );
|
||||||
fl_line( rx, Y, rx, Y + H );
|
fl_line( rx, Y, rx, Y + H );
|
||||||
fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H );
|
fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H );
|
||||||
|
@ -346,10 +354,10 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
fl_font( FL_HELVETICA, 14 );
|
fl_font( FL_HELVETICA, 14 );
|
||||||
fl_color( FL_BLACK );
|
fl_color( FL_BLACK );
|
||||||
|
|
||||||
int bx = Fl::box_dx( FL_PLASTIC_UP_BOX );
|
int bx = Fl::box_dx( box() );
|
||||||
int by = Fl::box_dy( FL_PLASTIC_UP_BOX );
|
int by = Fl::box_dy( box() );
|
||||||
int bw = Fl::box_dw( FL_PLASTIC_UP_BOX );
|
int bw = Fl::box_dw( box() );
|
||||||
int bh = Fl::box_dh( FL_PLASTIC_UP_BOX );
|
int bh = Fl::box_dh( box() );
|
||||||
|
|
||||||
int dx = min( 32767, timeline.ts_to_x( offset ) );
|
int dx = min( 32767, timeline.ts_to_x( offset ) );
|
||||||
|
|
||||||
|
@ -363,8 +371,8 @@ Region::draw ( int X, int Y, int W, int H )
|
||||||
//(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
|
//(Fl_Align)FL_ALIGN_LEFT | FL_ALIGN_BOTTOM );
|
||||||
|
|
||||||
|
|
||||||
fl_color( FL_RED );
|
/* fl_color( FL_RED ); */
|
||||||
fl_line( x(), y(), x(), y() + h() );
|
/* fl_line( x(), y(), x(), y() + h() ); */
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
Region.H
2
Region.H
|
@ -87,9 +87,11 @@ class Region : public TrackWidget
|
||||||
|
|
||||||
float _scale; /* amplitude adjustment */
|
float _scale; /* amplitude adjustment */
|
||||||
|
|
||||||
|
static Fl_Boxtype _box;
|
||||||
static Fl_Color _selection_color;
|
static Fl_Color _selection_color;
|
||||||
static Fl_Color selection_color ( void ) { return _selection_color; }
|
static Fl_Color selection_color ( void ) { return _selection_color; }
|
||||||
static void selection_color ( Fl_Color v ) { _selection_color = v; }
|
static void selection_color ( Fl_Color v ) { _selection_color = v; }
|
||||||
|
static Fl_Boxtype box ( void ) { return _box; }
|
||||||
|
|
||||||
enum trim_e { NO, LEFT, RIGHT };
|
enum trim_e { NO, LEFT, RIGHT };
|
||||||
void trim ( enum trim_e t, int X );
|
void trim ( enum trim_e t, int X );
|
||||||
|
|
30
Timeline.H
30
Timeline.H
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <FL/fl_draw.H>
|
||||||
|
|
||||||
struct Timeline {
|
struct Timeline {
|
||||||
Fl_Scroll *scroll;
|
Fl_Scroll *scroll;
|
||||||
Fl_Pack *tracks;
|
Fl_Pack *tracks;
|
||||||
|
@ -40,6 +42,9 @@ struct Timeline {
|
||||||
|
|
||||||
nframes_t xoffset;
|
nframes_t xoffset;
|
||||||
|
|
||||||
|
int _beats_per_bar;
|
||||||
|
float _beats_per_minute;
|
||||||
|
|
||||||
int
|
int
|
||||||
ts_to_x( nframes_t ts )
|
ts_to_x( nframes_t ts )
|
||||||
{
|
{
|
||||||
|
@ -52,6 +57,31 @@ struct Timeline {
|
||||||
{
|
{
|
||||||
return x * fpp;
|
return x * fpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float
|
||||||
|
beats_per_minute ( void ) const
|
||||||
|
{
|
||||||
|
// TODO: this should check a tempo map.
|
||||||
|
return _beats_per_minute;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw appropriate measure lines inside the given bounding box */
|
||||||
|
void
|
||||||
|
draw_measure_lines ( int X, int Y, int W, int H, Fl_Color color )
|
||||||
|
{
|
||||||
|
fl_line_style( FL_DASH, 2 );
|
||||||
|
fl_color( fl_color_average( FL_BLACK, color, 0.65f ) );
|
||||||
|
|
||||||
|
int measure = ts_to_x( sample_rate * 60 / beats_per_minute() );
|
||||||
|
|
||||||
|
for ( int x = X; x < X + W; ++x )
|
||||||
|
|
||||||
|
if ( 0 == (ts_to_x( xoffset ) + x) % measure )
|
||||||
|
fl_line( x, Y, x, Y + H );
|
||||||
|
|
||||||
|
fl_line_style( FL_SOLID, 0 );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Timeline timeline;
|
extern Timeline timeline;
|
||||||
|
|
2
Track.C
2
Track.C
|
@ -29,6 +29,8 @@ Track::draw ( void )
|
||||||
{
|
{
|
||||||
Fl_Group::draw();
|
Fl_Group::draw();
|
||||||
|
|
||||||
|
timeline.draw_measure_lines( x(), y(), w(), h(), color() );
|
||||||
|
|
||||||
fl_push_clip( x(), y(), w(), h() );
|
fl_push_clip( x(), y(), w(), h() );
|
||||||
|
|
||||||
for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
|
for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
|
||||||
|
|
2
main.C
2
main.C
|
@ -113,7 +113,7 @@ main ( int argc, char **argv )
|
||||||
timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - (24 * 2) );
|
timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - (24 * 2) );
|
||||||
timeline.scroll->type( Fl_Scroll::VERTICAL );
|
timeline.scroll->type( Fl_Scroll::VERTICAL );
|
||||||
timeline.fpp = 256;
|
timeline.fpp = 256;
|
||||||
|
timeline._beats_per_minute = 120;
|
||||||
|
|
||||||
timeline.sample_rate = 44100;
|
timeline.sample_rate = 44100;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue