From 50232a23a7b8581fa989b02395b6e23c213f4a55 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 12 Jun 2023 12:36:16 -0600 Subject: [PATCH] temporal: hide superclock_t variant of TempoMap::metric_at() This fixes several callsites that were passing samplepos_t to get a TempoMetric, some of them somewhat significant (e.g. VST plugins that want tempo information). Bad API design on my part, apologies. This commit combines libs/ and gtk2_ardour because the new private status of the ::metric_at() call would be a blocking point for git bisect --- gtk2_ardour/automation_controller.cc | 2 +- gtk2_ardour/editor_tempodisplay.cc | 4 ++-- gtk2_ardour/verbose_cursor.cc | 2 +- libs/ardour/lv2_plugin.cc | 2 +- libs/ardour/midi_clock_slave.cc | 2 +- libs/ardour/session.cc | 4 ++-- libs/ardour/session_transport.cc | 2 +- libs/ardour/session_vst.cc | 2 +- libs/ardour/ticker.cc | 2 +- libs/surfaces/websockets/transport.cc | 4 ++-- libs/temporal/temporal/tempo.h | 8 +++++++- 11 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gtk2_ardour/automation_controller.cc b/gtk2_ardour/automation_controller.cc index 81df0429be..9fb3b1da37 100644 --- a/gtk2_ardour/automation_controller.cc +++ b/gtk2_ardour/automation_controller.cc @@ -284,7 +284,7 @@ AutomationController::set_freq_beats(double beats) const ARDOUR::ParameterDescriptor& desc = _controllable->desc(); const ARDOUR::Session& session = _controllable->session(); const samplepos_t pos = session.transport_sample(); - const Temporal::Tempo& tempo = Temporal::TempoMap::use()->metric_at (pos).tempo(); + const Temporal::Tempo& tempo = Temporal::TempoMap::use()->metric_at (timepos_t (pos)).tempo(); const double bpm = tempo.note_types_per_minute(); const double bps = bpm / 60.0; const double freq = bps / beats; diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index a341f8423d..7a299651b0 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -623,7 +623,7 @@ Editor::edit_meter_section (Temporal::MeterPoint& section) return; } - Temporal::TempoMetric tm (TempoMap::use()->metric_at (section.sclock())); + Temporal::TempoMetric tm (TempoMap::use()->metric_at (timepos_t (section.sample(TEMPORAL_SAMPLE_RATE)))); Temporal::MeterPoint const * mpp (TempoMap::use()->previous_meter (tm.meter())); double bpb = meter_dialog.get_bpb (); @@ -702,7 +702,7 @@ Editor::edit_tempo_section (TempoPoint& section) return; } - Temporal::TempoMetric tm (TempoMap::use()->metric_at (section.sclock())); + Temporal::TempoMetric tm (TempoMap::use()->metric_at (timepos_t (section.sample (TEMPORAL_SAMPLE_RATE)))); Temporal::TempoPoint const * tpp (TempoMap::use()->previous_tempo (tm.tempo())); double bpm = tempo_dialog.get_bpm (); diff --git a/gtk2_ardour/verbose_cursor.cc b/gtk2_ardour/verbose_cursor.cc index c8e1dcd97b..8a2e88ee1c 100644 --- a/gtk2_ardour/verbose_cursor.cc +++ b/gtk2_ardour/verbose_cursor.cc @@ -145,7 +145,7 @@ VerboseCursor::set_duration (samplepos_t start, samplepos_t end) Timecode::Time timecode; Temporal::BBT_Time sbbt; Temporal::BBT_Time ebbt; - Meter const & meter_at_start (TempoMap::use()->metric_at (start).meter()); + Meter const & meter_at_start (TempoMap::use()->metric_at (timepos_t (start)).meter()); if (_editor->_session == 0) { return; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index b9afa431a0..c3c6933bae 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -2767,7 +2767,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs, samplepos_t start0 = std::max (samplepos_t (0), start); TempoMap::SharedPtr tmap (TempoMap::use()); - TempoMetric metric (tmap->metric_at (samples_to_superclock (start0, TEMPORAL_SAMPLE_RATE))); + TempoMetric metric (tmap->metric_at (timepos_t (start0))); TempoMapPoints tempo_map_points; tmap->get_grid (tempo_map_points, diff --git a/libs/ardour/midi_clock_slave.cc b/libs/ardour/midi_clock_slave.cc index 23b84ee592..f42bbf1051 100644 --- a/libs/ardour/midi_clock_slave.cc +++ b/libs/ardour/midi_clock_slave.cc @@ -155,7 +155,7 @@ MIDIClock_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now void MIDIClock_TransportMaster::calculate_one_ppqn_in_samples_at(samplepos_t time) { - const Temporal::TempoMetric& metric = Temporal::TempoMap::use()->metric_at (time); + const Temporal::TempoMetric& metric = Temporal::TempoMap::use()->metric_at (timepos_t (time)); const double samples_per_quarter_note = metric.tempo().samples_per_quarter_note (ENGINE->sample_rate()); one_ppqn_in_samples = samples_per_quarter_note / double (ppqn); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index ad83420fcd..b90213306e 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2128,7 +2128,7 @@ Session::preroll_samples (samplepos_t pos) const { const float pr = Config->get_preroll_seconds(); if (pos >= 0 && pr < 0) { - Temporal::TempoMetric const & metric (TempoMap::use()->metric_at (pos)); + Temporal::TempoMetric const & metric (TempoMap::use()->metric_at (timepos_t (pos))); return metric.samples_per_bar (sample_rate()) * -pr; } if (pr < 0) { @@ -7615,7 +7615,7 @@ Session::maybe_update_tempo_from_midiclock_tempo (float bpm) TempoMap::WritableSharedPtr tmap (TempoMap::write_copy()); if (tmap->n_tempos() == 1) { - Temporal::TempoMetric const & metric (tmap->metric_at (0)); + Temporal::TempoMetric const & metric (tmap->metric_at (timepos_t (0))); if (fabs (metric.tempo().note_types_per_minute() - bpm) >= Config->get_midi_clock_resolution()) { /* fix note type as quarters, because that's how MIDI clock works */ tmap->change_tempo (metric.get_editable_tempo(), Tempo (bpm, bpm, 4.0)); diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index f49d6b4c53..374dfa1a0f 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -560,7 +560,7 @@ Session::start_transport (bool after_loop) * - use [fixed] tempo/meter at _transport_sample * - calc duration of 1 bar + time-to-beat before or at transport_sample */ - TempoMetric const & tempometric = tmap->metric_at (_transport_sample); + TempoMetric const & tempometric = tmap->metric_at (timepos_t (_transport_sample)); const double num = tempometric.divisions_per_bar (); /* XXX possible optimization: get meter and BBT time in one call */ diff --git a/libs/ardour/session_vst.cc b/libs/ardour/session_vst.cc index 44df4e1d02..d82ebf9003 100644 --- a/libs/ardour/session_vst.cc +++ b/libs/ardour/session_vst.cc @@ -317,7 +317,7 @@ intptr_t Session::vst_callback ( // returns tempo (in bpm * 10000) at sample sample location passed in if (session) { TempoMap::SharedPtr tmap (TempoMap::fetch()); - const Tempo& t (tmap->metric_at (value).tempo()); + const Tempo& t (tmap->metric_at (timepos_t (value)).tempo()); return t.quarter_notes_per_minute() * 1000; } else { return 0; diff --git a/libs/ardour/ticker.cc b/libs/ardour/ticker.cc index 118c10ff9d..73191da257 100644 --- a/libs/ardour/ticker.cc +++ b/libs/ardour/ticker.cc @@ -218,7 +218,7 @@ out: double MidiClockTicker::one_ppqn_in_samples (samplepos_t transport_position) const { - Tempo const & tempo (TempoMap::use()->metric_at (transport_position).tempo()); + Tempo const & tempo (TempoMap::use()->metric_at (timepos_t (transport_position)).tempo()); const double samples_per_quarter_note = tempo.samples_per_quarter_note (_session.nominal_sample_rate()); return samples_per_quarter_note / 24.0; } diff --git a/libs/surfaces/websockets/transport.cc b/libs/surfaces/websockets/transport.cc index 58b98e2ddd..1173116f53 100644 --- a/libs/surfaces/websockets/transport.cc +++ b/libs/surfaces/websockets/transport.cc @@ -29,7 +29,7 @@ using namespace Temporal; double ArdourTransport::tempo () const { - const Tempo& tempo (TempoMap::fetch()->metric_at (0).tempo()); + const Tempo& tempo (TempoMap::fetch()->metric_at (timepos_t (0)).tempo()); return tempo.note_types_per_minute (); } @@ -40,7 +40,7 @@ ArdourTransport::set_tempo (double bpm) TempoMap::WritableSharedPtr tmap (TempoMap::write_copy()); - Tempo tempo (bpm, tmap->metric_at (0).tempo().note_type ()); + Tempo tempo (bpm, tmap->metric_at (timepos_t (0)).tempo().note_type ()); tmap->set_tempo (tempo, timepos_t()); TempoMap::update (tmap); diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index ee3f0e47cb..83fa1df75c 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -814,7 +814,6 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible Meter at the given time. If can_match is false, the TempoMetric will only refer to the Tempo or Metric preceding the given time. */ - LIBTEMPORAL_API TempoMetric metric_at (superclock_t, bool can_match = true) const; LIBTEMPORAL_API TempoMetric metric_at (Beats const &, bool can_match = true) const; LIBTEMPORAL_API TempoMetric metric_at (BBT_Argument const &, bool can_match = true) const; @@ -1091,6 +1090,13 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible return _get_tempo_and_meter > (t, m, &Point::beats, b, _points.begin(), _points.end(), &_tempos.front(), &_meters.front(), can_match, ret_iterator_after_not_at); } + /* This is private, and should not be callable from outside the map + because of potential confusion between samplepos_t and + superclock_t. The timepos_t variant of ::metric_at() handles any + samplepos_t-passing call. + */ + TempoMetric metric_at (superclock_t, bool can_match = true) const; + /* parsing legacy tempo maps */ struct LegacyTempoState