Consider loop points when drawing waveforms.
This commit is contained in:
parent
7dc9a475e9
commit
dfaf04645c
|
@ -458,112 +458,120 @@ Audio_Region::draw ( void )
|
||||||
/* no coverage */
|
/* no coverage */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const int scroll_x = this->scroll_x();
|
||||||
|
const int start_x = timeline->ts_to_x( _r->start );
|
||||||
|
|
||||||
|
if ( start_x > scroll_x + sequence()->w() ||
|
||||||
|
start_x + abs_w() < scroll_x )
|
||||||
|
/* not in viewport */
|
||||||
|
return;
|
||||||
|
|
||||||
/* account for waveform outlines... */
|
/* account for waveform outlines... */
|
||||||
X -= 2;
|
X -= 2;
|
||||||
W += 4;
|
W += 4;
|
||||||
|
|
||||||
int OX = scroll_x();
|
/* start with region length... */
|
||||||
int ox = timeline->ts_to_x( _r->start );
|
int rw = min( abs_w(), sequence()->w() );
|
||||||
|
|
||||||
if ( ox > OX + sequence()->w() ||
|
|
||||||
( ox < OX && ox + abs_w() < OX ) )
|
|
||||||
/* not in viewport */
|
|
||||||
return;
|
|
||||||
|
|
||||||
int rw = timeline->ts_to_x( _r->length );
|
|
||||||
|
|
||||||
/* calculate waveform offset due to scrolling */
|
/* calculate waveform offset due to scrolling */
|
||||||
nframes_t offset = 0;
|
nframes_t offset = 0;
|
||||||
if ( ox < OX )
|
if ( start_x < scroll_x )
|
||||||
{
|
{
|
||||||
offset = timeline->x_to_ts( OX - ox );
|
offset = timeline->x_to_ts( scroll_x - start_x );
|
||||||
|
|
||||||
rw -= OX - ox;
|
rw -= scroll_x - start_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
rw = min( rw, sequence()->w() );
|
const int rx = x();
|
||||||
|
|
||||||
int rx = x();
|
|
||||||
|
|
||||||
fl_push_clip( rx, Y, rw, H );
|
fl_push_clip( rx, Y, rw, H );
|
||||||
|
|
||||||
/* get actual peak data */
|
/* draw fade curve outlines--this is only here because of crossfades */
|
||||||
int channels;
|
draw_fade( _fade_in, Fade::In, true, X, W );
|
||||||
int peaks;
|
draw_fade( _fade_out, Fade::Out, true, X, W );
|
||||||
Peak *pbuf;
|
|
||||||
|
|
||||||
|
int xo = 0;
|
||||||
|
|
||||||
// const nframes_t start = _r->start + offset + timeline->x_to_ts( X - rx );
|
do {
|
||||||
// nframes_t start = _r->start + offset;
|
|
||||||
nframes_t start = _r->offset + offset;
|
|
||||||
|
|
||||||
/* compensate for ??? */
|
int channels;
|
||||||
if ( X - rx > 0 )
|
int peaks;
|
||||||
start += timeline->x_to_ts( X - rx );
|
Peak *pbuf;
|
||||||
|
|
||||||
const int peaks_needed = min( timeline->ts_to_x( _clip->length() - start ), W );
|
nframes_t start = _r->offset;
|
||||||
|
|
||||||
const nframes_t end = start + timeline->x_to_ts( peaks_needed );
|
/* int loop_peaks_needed = min( _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() ), rw ); */
|
||||||
|
|
||||||
if ( _clip->read_peaks( timeline->fpp(),
|
int loop_peaks_needed = _loop ? timeline->ts_to_x( _loop ) : timeline->ts_to_x( _clip->length() );
|
||||||
start,
|
|
||||||
end,
|
|
||||||
&peaks, &pbuf, &channels ) &&
|
|
||||||
peaks )
|
|
||||||
{
|
|
||||||
|
|
||||||
assert( pbuf );
|
if ( ! xo )
|
||||||
|
|
||||||
/* draw fade curve outlines--this is only here because of crossfades */
|
|
||||||
draw_fade( _fade_in, Fade::In, true, X, W );
|
|
||||||
draw_fade( _fade_out, Fade::Out, true, X, W );
|
|
||||||
|
|
||||||
int ch = (h() - Fl::box_dh( box() )) / channels;
|
|
||||||
|
|
||||||
Waveform::scale( pbuf, peaks * channels, _scale );
|
|
||||||
|
|
||||||
|
|
||||||
for ( int i = 0; i < channels; ++i )
|
|
||||||
{
|
{
|
||||||
// Peak *pb = pbuf + (peaks * i);
|
|
||||||
|
|
||||||
/* int fw = timeline->ts_to_x( fade.length ); */
|
if ( _loop )
|
||||||
|
start += offset % _loop;
|
||||||
|
else
|
||||||
|
start += offset;
|
||||||
|
|
||||||
/* /\* if ( draw_fade_waveform ) *\/ */
|
/* compensate for ??? */
|
||||||
/* for ( int j = min( fw, peaks ); j--; ) */
|
/* compensate for scrolling */
|
||||||
/* { */
|
if ( X - rx > 0 )
|
||||||
/* const float g = fade.gain( j * timeline->fpp() ); */
|
start += timeline->x_to_ts( X - rx );
|
||||||
/* pb[ j ].min *= g; */
|
|
||||||
/* pb[ j ].max *= g; */
|
loop_peaks_needed -= timeline->ts_to_x( offset ) % loop_peaks_needed;
|
||||||
/* } */
|
|
||||||
|
assert( loop_peaks_needed > 0 );
|
||||||
|
|
||||||
|
if ( _loop && offset < _loop )
|
||||||
|
{
|
||||||
|
const int x = loop_peaks_needed;
|
||||||
|
|
||||||
|
/* FIXME: is there no way to draw these symbols direclty? */
|
||||||
|
fl_font( FL_SYMBOL, 14 );
|
||||||
|
fl_color( FL_WHITE );
|
||||||
|
fl_draw( "@2>", X + x - 7, y(), 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 );
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
Waveform::draw( X,
|
|
||||||
(y() + Fl::box_dy( box() )) + (i * ch),
|
|
||||||
W,
|
|
||||||
ch,
|
|
||||||
pbuf + i, peaks, channels,
|
|
||||||
selected() ? fl_invert_color( _color ) : _color );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( peaks < peaks_needed )
|
const int total_peaks_needed = min( timeline->ts_to_x( _clip->length() - start ), rw );
|
||||||
{
|
const nframes_t end = start + timeline->x_to_ts( loop_peaks_needed );
|
||||||
/* couldn't read peaks--perhaps they're being generated. Try again later. */
|
|
||||||
Fl::add_timeout( 0.1f, &Audio_Region::peaks_pending_cb,
|
|
||||||
new Peaks_Redraw_Request( this, start + timeline->x_to_ts( peaks ), end ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( _loop )
|
if ( _clip->read_peaks( timeline->fpp(),
|
||||||
{
|
start,
|
||||||
const int x = timeline->ts_to_x( _loop - offset );
|
end,
|
||||||
|
&peaks, &pbuf, &channels ) &&
|
||||||
|
peaks )
|
||||||
|
{
|
||||||
|
assert( pbuf );
|
||||||
|
|
||||||
|
int ch = (h() - Fl::box_dh( box() )) / channels;
|
||||||
|
|
||||||
|
Waveform::scale( pbuf, peaks * channels, _scale );
|
||||||
|
|
||||||
|
for ( int i = 0; i < channels; ++i )
|
||||||
|
{
|
||||||
|
Waveform::draw( X + xo,
|
||||||
|
(y() + Fl::box_dy( box() )) + (i * ch),
|
||||||
|
loop_peaks_needed,
|
||||||
|
ch,
|
||||||
|
pbuf + i, peaks, channels,
|
||||||
|
selected() ? fl_invert_color( _color ) : _color );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( peaks < loop_peaks_needed )
|
||||||
|
{
|
||||||
|
/* couldn't read peaks--perhaps they're being generated. Try again later. */
|
||||||
|
Fl::add_timeout( 0.1f, &Audio_Region::peaks_pending_cb,
|
||||||
|
new Peaks_Redraw_Request( this, start + timeline->x_to_ts( peaks ), end ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
xo += loop_peaks_needed;
|
||||||
|
|
||||||
/* FIXME: is there no way to draw these symbols direclty? */
|
|
||||||
fl_font( FL_SYMBOL, 14 );
|
|
||||||
fl_color( FL_WHITE );
|
|
||||||
fl_draw( "@2>", X + x - 7, y(), 14, 14, (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_BOTTOM), 0, 1 );
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
while ( _loop && xo < W );
|
||||||
|
|
||||||
timeline->draw_measure_lines( X, Y, W, H, _box_color );
|
timeline->draw_measure_lines( X, Y, W, H, _box_color );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue