From b876baa75763ddcfe0ca98d5128960f5f8815a18 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 29 Nov 2020 18:47:58 -0700 Subject: [PATCH] Temporal: various changes to arithmetic/logic methods to avoid assert() on domain mismatches where none is really needed --- libs/temporal/superclock.cc | 2 +- libs/temporal/temporal/timeline.h | 28 +++++++++++------- libs/temporal/timeline.cc | 48 +++++++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/libs/temporal/superclock.cc b/libs/temporal/superclock.cc index eb46364d92..69da243ead 100644 --- a/libs/temporal/superclock.cc +++ b/libs/temporal/superclock.cc @@ -33,6 +33,6 @@ void Temporal::set_thread_sample_rate (uint32_t sr) { _thread_sample_rate = sr; - std::cout << pthread_name() << " 0x" << std::hex << pthread_self() << std::dec << " TID " << syscall(SYS_gettid) << " set TSR @ " << &_thread_sample_rate << " to " << sr << " = " << _thread_sample_rate << '\n'; + // std::cout << pthread_name() << " 0x" << std::hex << pthread_self() << std::dec << " TID " << syscall(SYS_gettid) << " set TSR @ " << &_thread_sample_rate << " to " << sr << " = " << _thread_sample_rate << '\n'; } diff --git a/libs/temporal/temporal/timeline.h b/libs/temporal/temporal/timeline.h index 7b6fe377b4..a59d4697c2 100644 --- a/libs/temporal/temporal/timeline.h +++ b/libs/temporal/temporal/timeline.h @@ -296,14 +296,14 @@ class LIBTEMPORAL_API timecnt_t { /* construct from timeline types */ explicit timecnt_t (timepos_t const & d) : _distance (d), _position (timepos_t::zero (d.flagged())) {} - explicit timecnt_t (timepos_t const & d, timepos_t const & p) : _distance (d), _position (p) { assert (p.is_beats() == d.is_beats()); } + explicit timecnt_t (timepos_t const & d, timepos_t const & p) : _distance (d), _position (p) { } explicit timecnt_t (timecnt_t const &, timepos_t const & pos); /* construct from int62_t (which will be flagged or not) and timepos_t */ - explicit timecnt_t (int62_t d, timepos_t p) : _distance (d), _position (p) { assert (p.is_beats() == d.flagged()); } + explicit timecnt_t (int62_t d, timepos_t p) : _distance (d), _position (p) {} /* construct from beats */ - explicit timecnt_t (Temporal::Beats const & b, timepos_t const & pos) : _distance (true, b.to_ticks()), _position (pos) { assert ( _distance.flagged() == _position.is_beats()); } + explicit timecnt_t (Temporal::Beats const & b, timepos_t const & pos) : _distance (true, b.to_ticks()), _position (pos) {} static timecnt_t zero (TimeDomain td) { return timecnt_t (timepos_t::zero (td), timepos_t::zero (td)); } @@ -334,12 +334,12 @@ class LIBTEMPORAL_API timecnt_t { timecnt_t abs() const; - Temporal::TimeDomain time_domain () const { return _position.time_domain (); } + Temporal::TimeDomain time_domain () const { return _distance.flagged() ? BeatTime : AudioTime; } - superclock_t superclocks() const { if (_position.is_superclock()) return _distance.val(); return compute_superclocks(); } + superclock_t superclocks() const { if (!_distance.flagged()) return _distance.val(); return compute_superclocks(); } int64_t samples() const { return superclock_to_samples (superclocks(), _thread_sample_rate); } - Temporal::Beats beats () const { if (_position.is_beats()) return Beats::ticks (_distance.val()); return compute_beats(); } - int64_t ticks () const { if (_position.is_beats()) return _distance.val(); return compute_ticks(); } + Temporal::Beats beats () const { if (_distance.flagged()) return Beats::ticks (_distance.val()); return compute_beats(); } + int64_t ticks () const { if (_distance.flagged()) return _distance.val(); return compute_ticks(); } timecnt_t & operator= (superclock_t s) { _distance = int62_t (false, s); return *this; } timecnt_t & operator= (Temporal::Beats const & b) { _distance = int62_t (true, b.to_ticks()); return *this; } @@ -372,10 +372,11 @@ class LIBTEMPORAL_API timecnt_t { //timecnt_t & operator-= (timepos_t); //timecnt_t & operator+= (timepos_t); - bool operator> (timecnt_t const & other) const { return _distance > other.distance (); } - bool operator>= (timecnt_t const & other) const { return _distance >= other.distance(); } - bool operator< (timecnt_t const & other) const { return _distance < other.distance(); } - bool operator<= (timecnt_t const & other) const { return _distance <= other.distance(); } + bool operator> (timecnt_t const & other) const { if (_distance.flagged() == other.distance().flagged()) return _distance > other.distance (); else return expensive_gt (other); } + bool operator>= (timecnt_t const & other) const { if (_distance.flagged() == other.distance().flagged()) return _distance >= other.distance(); else return expensive_gte (other); } + bool operator< (timecnt_t const & other) const { if (_distance.flagged() == other.distance().flagged()) return _distance < other.distance(); else return expensive_lt (other); } + bool operator<= (timecnt_t const & other) const { if (_distance.flagged() == other.distance().flagged()) return _distance <= other.distance(); else return expensive_gte (other); } + timecnt_t & operator=(timecnt_t const & other) { if (this != &other) { if (_distance.flagged() == other.distance().flagged()) { @@ -425,6 +426,11 @@ class LIBTEMPORAL_API timecnt_t { superclock_t compute_superclocks () const; Beats compute_beats () const; int64_t compute_ticks () const; + + bool expensive_lt (timecnt_t const & other) const; + bool expensive_lte (timecnt_t const & other) const; + bool expensive_gt (timecnt_t const & other) const; + bool expensive_gte (timecnt_t const & other) const; }; } /* end namespace Temporal */ diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc index b50aca7c4f..0a1ee2354e 100644 --- a/libs/temporal/timeline.cc +++ b/libs/temporal/timeline.cc @@ -77,8 +77,6 @@ timecnt_t::timecnt_t (timecnt_t const & tc, timepos_t const & pos) } _distance = tc.distance(); - - assert (_position.is_beats() == _distance.flagged()); } void @@ -313,6 +311,46 @@ timecnt_t::operator- () const return timecnt_t (-_distance, _position); } +bool +timecnt_t::expensive_lt (timecnt_t const & other) const +{ + if (!_distance.flagged()) { /* Audio */ + return _distance.val() < other.superclocks(); + } + + return Beats::ticks (_distance.val()) < other.beats (); +} + +bool +timecnt_t::expensive_gt (timecnt_t const & other) const +{ + if (!_distance.flagged()) { /* Audio */ + return _distance.val() > other.superclocks(); + } + + return Beats::ticks (_distance.val()) > other.beats (); +} + +bool +timecnt_t::expensive_lte (timecnt_t const & other) const +{ + if (!_distance.flagged()) { /* Audio */ + return _distance.val() <= other.superclocks(); + } + + return Beats::ticks (_distance.val()) <= other.beats (); +} + +bool +timecnt_t::expensive_gte (timecnt_t const & other) const +{ + if (time_domain() == AudioTime) { + return _distance.val() >= other.superclocks(); + } + + return Beats::ticks (_distance.val()) >= other.beats (); +} + /* timepos */ timepos_t::timepos_t (timecnt_t const & t) @@ -581,7 +619,7 @@ bool timepos_t::expensive_gt (timepos_t const & other) const { if (time_domain() == AudioTime) { - return superclocks() < other.superclocks(); + return superclocks() > other.superclocks(); } return beats() > other.beats (); @@ -591,7 +629,7 @@ bool timepos_t::expensive_lte (timepos_t const & other) const { if (time_domain() == AudioTime) { - return superclocks() < other.superclocks(); + return superclocks() <= other.superclocks(); } return beats() <= other.beats (); @@ -601,7 +639,7 @@ bool timepos_t::expensive_gte (timepos_t const & other) const { if (time_domain() == AudioTime) { - return superclocks() < other.superclocks(); + return superclocks() >= other.superclocks(); } return beats() >= other.beats ();