From def35cf043cd9449e163d2773a22e377000d7164 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 1 Dec 2020 22:30:04 -0700 Subject: [PATCH] mark BBT_Offset (double) constructor explicit to avoid implicit conversion in timeline expressions. Also clean up the mess this had caused. --- libs/ardour/smf_source.cc | 4 +- libs/evoral/ControlList.cc | 4 +- libs/temporal/temporal/bbt_time.h | 2 +- libs/temporal/timeline.cc | 63 +++++++++++++++++-------------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 784885870a..d8a778a2ad 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -255,7 +255,7 @@ SMFSource::read_unlocked (const Lock& lock, _smf_last_read_end = start + duration; return timecnt_t(); } - time += ev_delta_t; // accumulate delta time + time += timepos_t::from_ticks (ev_delta_t); // accumulate delta time } } else { DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("SMF read_unlocked: set time to %1\n", _smf_last_read_time)); @@ -272,7 +272,7 @@ SMFSource::read_unlocked (const Lock& lock, break; } - time += ev_delta_t; // accumulate delta time + time += timepos_t::from_ticks (ev_delta_t); // accumulate delta time _smf_last_read_time = time; if (ret == 0) { // meta-event (skipped, just accumulate time) diff --git a/libs/evoral/ControlList.cc b/libs/evoral/ControlList.cc index 70eb504146..e7dac1cd19 100644 --- a/libs/evoral/ControlList.cc +++ b/libs/evoral/ControlList.cc @@ -2053,10 +2053,10 @@ ControlList::move_ranges (const list< RangeMove> & movements) switch (_time_domain) { case AudioTime: - ev->when += dx.samples(); + ev->when += dx; break; case BeatTime: - ev->when += dx.beats().to_ticks(); + ev->when += dx; break; default: /*NOTREACHED*/ diff --git a/libs/temporal/temporal/bbt_time.h b/libs/temporal/temporal/bbt_time.h index aa1a5992e3..4203653d41 100644 --- a/libs/temporal/temporal/bbt_time.h +++ b/libs/temporal/temporal/bbt_time.h @@ -146,7 +146,7 @@ struct LIBTEMPORAL_API BBT_Offset BBT_Offset () : bars (0), beats (0), ticks (0) {} BBT_Offset (int32_t ba, uint32_t be, uint32_t t) : bars (ba), beats (be), ticks (t) {} BBT_Offset (BBT_Time const & bbt) : bars (bbt.bars), beats (bbt.beats), ticks (bbt.ticks) {} - BBT_Offset (double beats); + explicit BBT_Offset (double beats); /* unlike BBT_Time, we can define +,-,* and / operators for BBT_Offset * because there is no requirement that the result is "well-formed" or diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc index 1da2894a4a..f9723c87d0 100644 --- a/libs/temporal/timeline.cc +++ b/libs/temporal/timeline.cc @@ -362,6 +362,7 @@ std::operator<< (std::ostream & o, timecnt_t const & tc) timepos_t::timepos_t (timecnt_t const & t) { if (t.distance() < 0) { + std::cerr << "timecnt_t has negative distance distance " << " val " << t.distance().val() << " flagged " << t.distance().flagged() << std::endl; throw std::domain_error("negative value for timepos_t constructor"); } @@ -577,48 +578,34 @@ timepos_t::earlier (Temporal::BBT_Offset const & offset) const } -timepos_t & -timepos_t::shift_earlier (Temporal::BBT_Offset const & offset) -{ - TempoMap::SharedPtr tm (TempoMap::use()); - - if (is_superclock()) { - v = build (false, (tm->superclock_at (tm->bbt_walk (tm->bbt_at (superclocks()), -offset)))); - } else { - v = build (true, tm->bbtwalk_to_quarters (beats(), -offset).to_ticks()); - } - - return *this; -} - - timepos_t timepos_t::earlier (timepos_t const & other) const { - if (other.is_superclock()) { - return earlier (other.superclocks()); + if (is_superclock()) { + return timepos_t::from_superclock (val() - other.superclocks()); } - return earlier (other.beats()); + return timepos_t::from_ticks (val() - other.ticks()); } timepos_t timepos_t::earlier (timecnt_t const & distance) const { - if (distance.time_domain() == AudioTime) { - return earlier (distance.superclocks()); + if (is_superclock()) { + return timepos_t::from_superclock (val() - distance.superclocks()); } - return earlier (distance.beats()); + + return timepos_t::from_ticks (val() - distance.ticks()); } bool timepos_t::expensive_lt (timepos_t const & other) const { if (time_domain() == AudioTime) { - return superclocks() < other.superclocks(); + return val() < other.superclocks(); } - return beats() < other.beats (); + return ticks() < other.ticks (); } bool @@ -656,21 +643,25 @@ timepos_t::expensive_gte (timepos_t const & other) const timepos_t & timepos_t::shift_earlier (timepos_t const & d) { - if (d.time_domain() == AudioTime) { - return shift_earlier (d.superclocks()); + if (is_superclock()) { + v = build (false, val() - d.superclocks()); + } else { + v = build (true, val() - d.ticks()); } - return shift_earlier (d.beats()); + return *this; } timepos_t & timepos_t::shift_earlier (timecnt_t const & d) { - if (d.time_domain() == AudioTime) { - return shift_earlier (d.superclocks()); + if (is_superclock()) { + v = build (false, val() - d.superclocks()); + } else { + v = build (true, val() - d.ticks()); } - return shift_earlier (d.beats()); + return *this; } timepos_t & @@ -690,6 +681,20 @@ timepos_t::shift_earlier (Temporal::Beats const & b) return *this; } +timepos_t & +timepos_t::shift_earlier (Temporal::BBT_Offset const & offset) +{ + TempoMap::SharedPtr tm (TempoMap::use()); + + if (is_superclock()) { + v = build (false, (tm->superclock_at (tm->bbt_walk (tm->bbt_at (superclocks()), -offset)))); + } else { + v = build (true, tm->bbtwalk_to_quarters (beats(), -offset).to_ticks()); + } + + return *this; +} + /* */ timepos_t &