13
0

Waveview: fix visual jitter when trimming or splitting regions

The left edge of a region on the the editor is rounded to be
on a pixel. When zoomed out, the position corresponding to that
pixel is not usually identical to the region's position().

We need to correct for this as best as possible, while keeping
peaks aligned to pixels.
This commit is contained in:
Robin Gareus 2024-09-26 02:20:35 +02:00
parent 68eb63e0c8
commit 9d0415ba04
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -1091,12 +1091,19 @@ WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) cons
assert (image_to_draw);
/* Calculate the sample that corresponds to the region-rectangle's left edge
* in the editor at current zoom (see TimeAxisViewItem::set_position).
*/
double const samples_per_pixel = _props->samples_per_pixel;
samplepos_t const region_position = _region->position().samples();
samplepos_t const region_view_x = round (round (region_position / samples_per_pixel) * samples_per_pixel);
ARDOUR::sampleoffset_t region_view_dx = region_position - region_view_x;
/* compute the first pixel of the image that should be used when we
* render the specified range.
*/
double image_origin_in_self_coordinates =
(image_to_draw->props.get_sample_start () - _props->region_start) / _props->samples_per_pixel;
double image_origin_in_self_coordinates = (image_to_draw->props.get_sample_start () - _props->region_start + region_view_dx) / samples_per_pixel;
/* the image may only be a best-effort ... it may not span the entire
* range requested, though it is guaranteed to cover the start. So