Add API to consistently round start/end to duration to pixels

This commit is contained in:
Robin Gareus
2024-11-28 14:51:51 +01:00
parent 911399f8b3
commit d44ceb3ab7
2 changed files with 13 additions and 0 deletions

View File

@@ -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
{

View File

@@ -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;
}