From 9d0415ba04008b5f82516121d1009b7587a00c7e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 26 Sep 2024 02:20:35 +0200 Subject: [PATCH] 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. --- libs/waveview/wave_view.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/waveview/wave_view.cc b/libs/waveview/wave_view.cc index 7d406306ae..79365b1432 100644 --- a/libs/waveview/wave_view.cc +++ b/libs/waveview/wave_view.cc @@ -1091,12 +1091,19 @@ WaveView::render (Rect const & area, Cairo::RefPtr 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