From faac64850275d2c5764b2676cdf57fba9964d268 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 3 May 2023 21:53:36 -0600 Subject: [PATCH] temporal: add TempoMap::{next,previous_}meter() --- libs/temporal/tempo.cc | 27 +++++++++++++++++++++++++++ libs/temporal/temporal/tempo.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 799bb1e7d4..257fa4da72 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -3119,6 +3119,33 @@ TempoMap::previous_tempo (TempoPoint const & point) const return &(*i); } +MeterPoint const * +TempoMap::next_meter (MeterPoint const & t) const +{ + Meters::const_iterator i = _meters.iterator_to (t); + ++i; + + if (i != _meters.end()) { + return &(*i); + } + + return 0; +} + +MeterPoint const * +TempoMap::previous_meter (MeterPoint const & point) const +{ + Meters::const_iterator i = _meters.iterator_to (point); + + if (i == _meters.begin()) { + return 0; + } + + --i; + + return &(*i); +} + double TempoMap::quarters_per_minute_at (timepos_t const & pos) const { diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index b032290ab5..0a6bc50424 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -796,6 +796,9 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API TempoPoint const* previous_tempo (TempoPoint const &) const; LIBTEMPORAL_API TempoPoint const* next_tempo (TempoPoint const &) const; + LIBTEMPORAL_API MeterPoint const* previous_meter (MeterPoint const &) const; + LIBTEMPORAL_API MeterPoint const* next_meter (MeterPoint const &) const; + LIBTEMPORAL_API bool tempo_exists_before (TempoPoint const & t) const { return (bool) previous_tempo (t); } LIBTEMPORAL_API bool tempo_exists_after (TempoPoint const & t) const { return (bool) next_tempo (t); }