From d44ceb3ab7cf6df58be943ef0b6f2b94ea328fd8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 28 Nov 2024 14:51:51 +0100 Subject: [PATCH] Add API to consistently round start/end to duration to pixels --- gtk2_ardour/editing_context.cc | 6 ++++++ gtk2_ardour/editing_context.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/gtk2_ardour/editing_context.cc b/gtk2_ardour/editing_context.cc index 71915501ef..5642880207 100644 --- a/gtk2_ardour/editing_context.cc +++ b/gtk2_ardour/editing_context.cc @@ -1327,6 +1327,12 @@ EditingContext::time_to_pixel_unrounded (timepos_t const & pos) const return sample_to_pixel_unrounded (pos.samples()); } +double +EditingContext::time_delta_to_pixel (timepos_t const& start, timepos_t const& end) const +{ + return sample_to_pixel (end.samples()) - sample_to_pixel (start.samples ()); +} + double EditingContext::duration_to_pixels (timecnt_t const & dur) const { diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index e84c3f2213..eb04b62baf 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -224,8 +224,15 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider double time_to_pixel (Temporal::timepos_t const & pos) const; double time_to_pixel_unrounded (Temporal::timepos_t const & pos) const; + double time_delta_to_pixel (Temporal::timepos_t const& start, Temporal::timepos_t const& end) const; + + /* deprecated, prefer time_delta_to_pixel + * first taking the duation and then rounding leads to different results: + * duration_to_pixels (start.distance(end)) != time_to_pixel (end) - time_to_pixel (start) + */ double duration_to_pixels (Temporal::timecnt_t const & pos) const; double duration_to_pixels_unrounded (Temporal::timecnt_t const & pos) const; + samplecnt_t pixel_duration_to_samples (double pixels) const { return pixels * samples_per_pixel; }