From 0266d98a3b08ba90523b4b657d59da6acf036c77 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 31 Aug 2023 18:23:40 -0600 Subject: [PATCH] temporal: add TempoMap::{max,min}_notes_per_minute() API --- libs/temporal/tempo.cc | 32 ++++++++++++++++++++++++++++++++ libs/temporal/temporal/tempo.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 604dda006d..7269b26c13 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -4756,6 +4756,38 @@ TempoMap::map_assert (bool expr, char const * exprstr, char const * file, int li } } +double +TempoMap::max_notes_per_minute() const +{ + double npm = 0; + for (auto const & t : _tempos) { + if (t.note_types_per_minute() > npm) { + npm = t.note_types_per_minute(); + } + if (t.end_note_types_per_minute() > npm) { + npm = t.end_note_types_per_minute(); + } + } + + return npm; +} + +double +TempoMap::min_notes_per_minute() const +{ + double npm = std::numeric_limits::max(); + + for (auto const & t : _tempos) { + if (t.note_types_per_minute() < npm) { + npm = t.note_types_per_minute(); + } + if (t.end_note_types_per_minute() < npm) { + npm = t.end_note_types_per_minute(); + } + } + + return npm; +} #if 0 void diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index 94ce2490af..31244b8151 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -948,6 +948,9 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const { return _tempo_at (b, Point::beat_comparator()); } LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Argument const & bbt) const { return _tempo_at (bbt, Point::bbt_comparator()); } + LIBTEMPORAL_API double max_notes_per_minute() const; + LIBTEMPORAL_API double min_notes_per_minute() const; + /* convenience function that hides some complexities behind fetching * the bpm at position */