From 8fb70885ec8a1ffbf8729341576e37783593a013 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 29 Sep 2020 17:53:06 -0600 Subject: [PATCH] changes needed to get audio_clock.cc to work --- libs/temporal/temporal/timeline.h | 3 +++ libs/temporal/temporal/types.h | 2 ++ libs/temporal/timeline.cc | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/libs/temporal/temporal/timeline.h b/libs/temporal/temporal/timeline.h index d11a0a1db5..5cc2764e24 100644 --- a/libs/temporal/temporal/timeline.h +++ b/libs/temporal/temporal/timeline.h @@ -162,6 +162,7 @@ class LIBTEMPORAL_API timepos_t : public int62_t { timepos_t earlier (BBT_Offset const & d) const; /* like ::earlier() but changes this. loosely equivalent to operator-= */ + timepos_t & shift_earlier (timepos_t const & d); timepos_t & shift_earlier (timecnt_t const & d); timepos_t & shift_earlier (Temporal::Beats const &); timepos_t & shift_earlier (Temporal::BBT_Offset const &); @@ -351,6 +352,8 @@ class LIBTEMPORAL_API timecnt_t { timecnt_t operator*(ratio_t const &) const; timecnt_t operator/(ratio_t const &) const; + ratio_t operator/ (timecnt_t const &) const; + timecnt_t operator-() const; timecnt_t operator- (timecnt_t const & t) const; timecnt_t operator+ (timecnt_t const & t) const; diff --git a/libs/temporal/temporal/types.h b/libs/temporal/temporal/types.h index 56eed44f56..b8684da01f 100644 --- a/libs/temporal/temporal/types.h +++ b/libs/temporal/temporal/types.h @@ -72,6 +72,8 @@ class _ratio_t { bool is_unity() const { return _numerator == _denominator; } bool is_zero() const { return _numerator == 0; } + operator double() const { return (double) _numerator / _denominator; }; + /* provide an easy way to multiply double by ratio_t. Note that this must be written as ratio_t * double, not the other way around. We are not trying to duplicate boost::rational here (which also doesn't diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc index 8cba5a6d2c..7057e5ec3c 100644 --- a/libs/temporal/timeline.cc +++ b/libs/temporal/timeline.cc @@ -116,6 +116,20 @@ timecnt_t::operator*(ratio_t const & r) const return timecnt_t (v, _position); } +ratio_t +timecnt_t::operator/ (timecnt_t const & other) const +{ + if (time_domain() == other.time_domain()) { + return ratio_t (distance().val(), other.distance().val()); + } + + if (time_domain() == AudioTime) { + return ratio_t (distance().val(), other.samples()); + } + + return ratio_t (beats().to_ticks(), other.beats().to_ticks()); +} + timecnt_t timecnt_t::operator/(ratio_t const & r) const { @@ -393,6 +407,16 @@ timepos_t::earlier (timecnt_t const & distance) const /* */ +timepos_t & +timepos_t::shift_earlier (timepos_t const & d) +{ + if (d.time_domain() == AudioTime) { + return shift_earlier (d.superclocks()); + } + + return shift_earlier (d.beats()); +} + timepos_t & timepos_t::shift_earlier (timecnt_t const & d) {