From 0acc1a3fecf411eda012e58557be7e3a4256f176 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 4 Oct 2021 17:24:07 -0600 Subject: [PATCH] temporal: use correct implementation of timepos_t::operator+ (timecnt_t) (and +=) If time domains differ, it is necessary to first convert the argument duration into a duration at the position of "this", in the correct time domain. Then we recursively call the operator again, but this time we will use the fast path that just adds two timepos_t values. --- libs/temporal/timeline.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc index 0a64df35c6..0300fbf552 100644 --- a/libs/temporal/timeline.cc +++ b/libs/temporal/timeline.cc @@ -776,20 +776,41 @@ timepos_t::operator+= (Temporal::BBT_Offset const & offset) timepos_t timepos_t::operator+(timecnt_t const & d) const { - if (d.time_domain() == AudioTime) { - return operator+ (timepos_t::from_superclock (d.superclocks())); + if (d.time_domain() == time_domain()) { + if (time_domain() == AudioTime) { + return operator+ (timepos_t::from_superclock (d.superclocks())); + } else { + return operator+ (timepos_t::from_ticks (d.ticks())); + } } - return operator+ (timepos_t::from_ticks (d.ticks())); + TempoMap::SharedPtr tm (TempoMap::use()); + + timecnt_t dur_at_this = tm->convert_duration (d, *this, time_domain()); + + assert (dur_at_this.time_domain() == time_domain()); + + return operator+ (dur_at_this); } timepos_t & timepos_t::operator+=(timecnt_t const & d) { - if (d.time_domain() == AudioTime) { - return operator+= (timepos_t::from_superclock (d.superclocks())); + if (d.time_domain() == time_domain()) { + if (time_domain() == AudioTime) { + return operator+= (timepos_t::from_superclock (d.superclocks())); + } else { + return operator+= (timepos_t::from_ticks (d.ticks())); + } } - return operator+= (timepos_t::from_ticks (d.ticks())); + + TempoMap::SharedPtr tm (TempoMap::use()); + + timecnt_t dur_at_this = tm->convert_duration (d, *this, time_domain()); + + assert (dur_at_this.time_domain() == time_domain()); + + return operator+= (dur_at_this); } /* */