diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index af50f1949b..615bce86d6 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -126,8 +126,8 @@ public: timepos_t nt_last() const { return end().decrement(); } timepos_t source_position () const; - timepos_t source_relative_position (Temporal::timepos_t const &) const; - timepos_t region_relative_position (Temporal::timepos_t const &) const; + timecnt_t source_relative_position (Temporal::timepos_t const &) const; + timecnt_t region_relative_position (Temporal::timepos_t const &) const; samplepos_t position_sample () const { return position().samples(); } samplecnt_t start_sample () const { return _start.val().samples(); } @@ -311,9 +311,7 @@ public: /** Convert a timestamp in absolute time to beats measured from source start*/ Temporal::Beats absolute_time_to_source_beats(Temporal::timepos_t const &) const; - Temporal::Beats absolute_time_to_region_beats (Temporal::timepos_t const & b) const { - return position().distance (b+start()).beats (); - } + Temporal::Beats absolute_time_to_region_beats (Temporal::timepos_t const &) const; int apply (Filter &, Progress* progress = 0); diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 7db3cae691..07b84a84fa 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -2071,6 +2071,12 @@ Region::source_beats_to_absolute_beats (Temporal::Beats beats) const return source_position().beats() + beats; } +Temporal::Beats +Region::absolute_time_to_region_beats(timepos_t const & b) const +{ + return (position().distance (b)).beats () + start().beats();; +} + Temporal::timepos_t Region::region_beats_to_absolute_time (Temporal::Beats beats) const { @@ -2087,47 +2093,41 @@ Region::source_beats_to_absolute_time (Temporal::Beats beats) const return source_position() + timepos_t (beats); } +/** Calculate (time - source_position) in Beats + * + * Measure the distance between the absolute time and the position of + * the source start, in beats. The result is positive if time is later + * than source position. + * + * @param p is an absolute time + * @returns time offset from p to the region's source position as the origin in Beat units + */ Temporal::Beats -Region::absolute_time_to_source_beats(timepos_t const & time) const +Region::absolute_time_to_source_beats(timepos_t const& p) const { - /* measure the distance between the absolute time and the position of - the source start, in beats. positive if time is later than source - position. - */ - - return source_position().distance (time).beats(); + return source_position().distance (p).beats(); } -timepos_t +/** Calculate (pos - source-position) + * + * @param p is an absolute time + * @returns time offset from p to the region's source position as the origin. + */ +timecnt_t Region::source_relative_position (timepos_t const & p) const { - /* p is an absolute time, return the time with the source position as - the origin. - - Note that conventionally we would return a timecnt_t, expressing a - distance from the source position. But we return timepos_t for which - the origin is implicit, and in this case, the origin is the region - position, not zero. - - XXX this seems likely to cause problems. - */ - return p.earlier (source_position()); + return source_position().distance (p); } -timepos_t +/** Calculate (p - region-position) + * + * @param p is an absolute time + * @returns the time offset using the region (timeline) position as origin + */ +timecnt_t Region::region_relative_position (timepos_t const & p) const { - /* p is an absolute time, return the time with the region position as - the origin. - - Note that conventionally we would return a timecnt_t, expressing a - distance from the region position. But we return timepos_t for which - the origin is implicit, and in this case, the origin is the region - position, not zero. - - XXX this seems likely to cause problems. - */ - return p.earlier (position()); + return position().distance (p); } Temporal::TimeDomain