Improve loop drawing.

This commit is contained in:
Jonathan Moore Liles 2008-07-05 22:33:25 -05:00
parent 98613d4d61
commit ea36473caa
1 changed files with 40 additions and 25 deletions

View File

@ -458,33 +458,36 @@ Audio_Region::draw ( void )
/* no coverage */ /* no coverage */
return; return;
const int scroll_x = this->scroll_x(); if ( start() > timeline->xoffset + timeline->x_to_ts( sequence()->w() ) ||
const int start_x = timeline->ts_to_x( _r->start ); start() + length() < timeline->xoffset )
if ( start_x > scroll_x + sequence()->w() ||
start_x + abs_w() < scroll_x )
/* not in viewport */ /* not in viewport */
return; return;
fl_push_clip( X, Y, W, H );
/* account for waveform outlines... */ /* account for waveform outlines... */
X -= 2; X -= 2;
W += 4; W += 4;
/* start with region length... */ /* start with region length... */
int rw = min( abs_w(), sequence()->w() ); // int rw = timeline->ts_to_x( min( length(), timeline->x_to_ts( sequence()->w() ) ) );
int rw = W;
/* calculate waveform offset due to scrolling */ /* calculate waveform offset due to scrolling */
nframes_t offset = 0; nframes_t offset = 0;
if ( start_x < scroll_x ) if ( start() < timeline->xoffset )
{ {
offset = timeline->x_to_ts( scroll_x - start_x ); offset = timeline->xoffset - start();
rw -= scroll_x - start_x; // rw -= timeline->ts_to_x( offset );
} }
/* DMESSAGE( "rw = %d", rw ); */
const int rx = x(); const int rx = x();
fl_push_clip( rx, Y, rw, H ); /* fl_color( FL_RED ); */
/* fl_line( rx + rw, y(), rx + rw, y() + h() ); */
/* draw fade curve outlines--this is only here because of crossfades */ /* draw fade curve outlines--this is only here because of crossfades */
draw_fade( _fade_in, Fade::In, true, X, W ); draw_fade( _fade_in, Fade::In, true, X, W );
@ -494,6 +497,13 @@ Audio_Region::draw ( void )
nframes_t ostart = 0, oend = 0; nframes_t ostart = 0, oend = 0;
const int total_peaks_needed = rw;
/* compensate for scrolling */
if ( X - rx > 0 )
offset += timeline->x_to_ts( X - rx );
do { do {
int channels; int channels;
@ -502,30 +512,29 @@ Audio_Region::draw ( void )
nframes_t start = _r->offset; nframes_t start = _r->offset;
/* int loop_peaks_needed = min( _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() ), rw ); */
int loop_peaks_needed = _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() ); int loop_peaks_needed = _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() );
if ( ! xo ) if ( ! xo ) /* first loop... */
{ {
if ( _loop ) if ( _loop )
start += offset % _loop; start += offset % _loop;
else else
start += offset; start += offset;
/* compensate for ??? */ /* DMESSAGE( "offset = %lu", (unsigned long) offset ); */
/* compensate for scrolling */ /* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
if ( X - rx > 0 )
start += timeline->x_to_ts( X - rx );
loop_peaks_needed -= timeline->ts_to_x( offset ) % loop_peaks_needed; loop_peaks_needed -= timeline->ts_to_x( offset % timeline->x_to_ts( loop_peaks_needed ) );
assert( loop_peaks_needed > 0 ); loop_peaks_needed = min( loop_peaks_needed, total_peaks_needed );
/* DMESSAGE( "loop peaks needed = %d", loop_peaks_needed ); */
assert( loop_peaks_needed >= 0 );
if ( _loop && offset < _loop ) if ( _loop && offset < _loop )
{ {
const int x = loop_peaks_needed; const int x = timeline->ts_to_x( _loop - offset );
/* FIXME: is there no way to draw these symbols direclty? */ /* FIXME: is there no way to draw these symbols direclty? */
fl_font( FL_SYMBOL, 14 ); fl_font( FL_SYMBOL, 14 );
@ -534,17 +543,23 @@ Audio_Region::draw ( void )
fl_color( FL_WHITE ); fl_color( FL_WHITE );
fl_draw( "@2<", X + x - 7, y() + h() - 14, 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 ); fl_draw( "@2<", X + x - 7, y() + h() - 14, 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 );
} }
} }
const int total_peaks_needed = min( timeline->ts_to_x( _clip->length() - start ), rw ); if ( xo + loop_peaks_needed > total_peaks_needed )
{
loop_peaks_needed -= ( xo + loop_peaks_needed ) - total_peaks_needed;
}
if ( 0 == loop_peaks_needed )
break;
const nframes_t end = start + timeline->x_to_ts( loop_peaks_needed ); const nframes_t end = start + timeline->x_to_ts( loop_peaks_needed );
if ( start != ostart || end != oend ) if ( start != ostart || end != oend )
{ {
if ( _clip->read_peaks( timeline->fpp(), if ( _clip->read_peaks( timeline->fpp(),
start, start,
end, end,
&peaks, &pbuf, &channels ) ) &peaks, &pbuf, &channels ) )
{ {
Waveform::scale( pbuf, peaks * channels, _scale ); Waveform::scale( pbuf, peaks * channels, _scale );