From 8bada4b5e1bdbd172cf80e76851627c9b6e087bf Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 25 Mar 2021 10:24:05 -0600 Subject: [PATCH] remove public ::bbt_at (INTEGER) methods, because of superclock_t/samplepos_t confusion libtemporal still needs ::bbt_at (superclock_t) fairly often so retain it as a private method, but public interfaces take either Beats or timepos_t --- libs/ardour/lv2_plugin.cc | 4 ++-- libs/ardour/session_transport.cc | 2 +- libs/ardour/session_vst.cc | 2 +- libs/ardour/vst3_plugin.cc | 2 +- libs/backends/jack/jack_session.cc | 2 +- libs/surfaces/control_protocol/basic_ui.cc | 2 +- libs/surfaces/faderport8/faderport8.cc | 2 +- libs/surfaces/push2/track_mix.cc | 2 +- libs/temporal/tempo.cc | 22 ++++++++++++++-------- libs/temporal/temporal/tempo.h | 7 ++++--- libs/temporal/timeline.cc | 6 +++--- 11 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 9197d7f32b..a9d8e9d79a 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -2736,7 +2736,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs, if (valid && (flags & PORT_INPUT)) { if ((flags & PORT_POSITION)) { - Temporal::BBT_Time bbt (metric.bbt_at (samples_to_superclock (start0, AudioEngine::instance()->sample_rate()))); + Temporal::BBT_Time bbt (metric.bbt_at (timepos_t (start0))); double bpm = metric.tempo().note_types_per_minute(); double time_scale = Port::speed_ratio (); double beatpos = (bbt.bars - 1) * metric.meter().divisions_per_bar() @@ -3118,7 +3118,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs, * so it needs to be realative to that. */ _current_bpm = metric.tempo().note_types_per_minute(); - Temporal::BBT_Time bbt (metric.bbt_at (start0)); + Temporal::BBT_Time bbt (metric.bbt_at (timepos_t (start0))); double beatpos = (bbt.bars - 1) * metric.divisions_per_bar() + (bbt.beats - 1) + (bbt.ticks / Temporal::ticks_per_beat); diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 797b131a54..03a9751fcc 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -533,7 +533,7 @@ Session::start_transport (bool after_loop) const double num = tempometric.divisions_per_bar (); /* XXX possible optimization: get meter and BBT time in one call */ - const Temporal::BBT_Time bbt = tmap->bbt_at (_transport_sample); + const Temporal::BBT_Time bbt = tmap->bbt_at (timepos_t (_transport_sample)); const double bar_fract = (double) bbt.beats / tempometric.divisions_per_bar(); _count_in_samples = tempometric.samples_per_bar (_current_sample_rate); diff --git a/libs/ardour/session_vst.cc b/libs/ardour/session_vst.cc index c8791910d2..da76d32888 100644 --- a/libs/ardour/session_vst.cc +++ b/libs/ardour/session_vst.cc @@ -203,7 +203,7 @@ intptr_t Session::vst_callback ( Temporal::BBT_Time bbt; try { - bbt = tmap->bbt_at (now); + bbt = tmap->bbt_at (timepos_t (now)); bbt.beats = 1; bbt.ticks = 0; /* exact quarter note */ diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index e6c24f2676..60d692c36b 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -636,7 +636,7 @@ VST3Plugin::connect_and_run (BufferSet& bufs, { TempoMap::SharedPtr tmap (TempoMap::use()); const TempoMetric& metric (tmap->metric_at (start)); - const BBT_Time& bbt (metric.bbt_at (start)); + const BBT_Time& bbt (metric.bbt_at (timepos_t (start))); context.tempo = metric.tempo().quarter_notes_per_minute (); context.timeSigNumerator = metric.meter().divisions_per_bar (); diff --git a/libs/backends/jack/jack_session.cc b/libs/backends/jack/jack_session.cc index 2f5dcdc1b9..65656dffb0 100644 --- a/libs/backends/jack/jack_session.cc +++ b/libs/backends/jack/jack_session.cc @@ -129,7 +129,7 @@ JACKSession::timebase_callback (jack_transport_state_t /*state*/, TempoMetric metric (tempo_map->metric_at (tf)); try { - bbt = tempo_map->bbt_at (tf); + bbt = tempo_map->bbt_at (timepos_t (tf)); pos->bar = bbt.bars; pos->beat = bbt.beats; diff --git a/libs/surfaces/control_protocol/basic_ui.cc b/libs/surfaces/control_protocol/basic_ui.cc index 71399afbb6..cfd929b50f 100644 --- a/libs/surfaces/control_protocol/basic_ui.cc +++ b/libs/surfaces/control_protocol/basic_ui.cc @@ -549,7 +549,7 @@ void BasicUI::jump_by_bars (int bars, LocateTransportDisposition ltd) { TempoMap::SharedPtr tmap (TempoMap::use()); - Temporal::BBT_Time bbt (tmap->bbt_at (session->transport_sample())); + Temporal::BBT_Time bbt (tmap->bbt_at (timepos_t (session->transport_sample()))); bars += bbt.bars; if (bars < 0) { diff --git a/libs/surfaces/faderport8/faderport8.cc b/libs/surfaces/faderport8/faderport8.cc index 97b51ea7cc..c3f77f6e29 100644 --- a/libs/surfaces/faderport8/faderport8.cc +++ b/libs/surfaces/faderport8/faderport8.cc @@ -268,7 +268,7 @@ FaderPort8::periodic () _timecode = Timecode::timecode_format_time(TC); char buf[16]; - Temporal::BBT_Time BBT = Temporal::TempoMap::use()->bbt_at (session->transport_sample ()); + Temporal::BBT_Time BBT = Temporal::TempoMap::use()->bbt_at (timepos_t (session->transport_sample ())); snprintf (buf, sizeof (buf), " %02" PRIu32 "|%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, BBT.bars % 100, BBT.beats %100, diff --git a/libs/surfaces/push2/track_mix.cc b/libs/surfaces/push2/track_mix.cc index 09b890c0c5..d96c728c91 100644 --- a/libs/surfaces/push2/track_mix.cc +++ b/libs/surfaces/push2/track_mix.cc @@ -603,7 +603,7 @@ TrackMixLayout::update_clocks () } char buf[16]; - Temporal::BBT_Time BBT = Temporal::TempoMap::use()->bbt_at (pos); + Temporal::BBT_Time BBT = Temporal::TempoMap::use()->bbt_at (timepos_t (pos)); #define BBT_BAR_CHAR "|" diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 32f107843b..7e656a4285 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -573,8 +573,14 @@ MeterPoint::get_state () const } Temporal::BBT_Time -TempoMetric::bbt_at (superclock_t sc) const +TempoMetric::bbt_at (timepos_t const & pos) const { + if (pos.is_beats()) { + return bbt_at (pos.beats()); + } + + superclock_t sc = pos.superclocks(); + const Beats dq = _tempo->quarters_at_superclock (sc) - _meter->beats(); DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("qn @ %1 = %2, meter @ %3 , delta %4\n", sc, _tempo->quarters_at_superclock (sc), _meter->beats(), dq)); @@ -1207,7 +1213,7 @@ TempoMap::move_meter (MeterPoint const & mp, timepos_t const & when, bool push) /* compute the BBT at the given superclock position, given the prior TempoMetric */ - bbt = metric.bbt_at (sc); + bbt = metric.bbt_at (timepos_t::from_superclock (sc)); /* meter changes must fall on a bar change */ @@ -1460,7 +1466,7 @@ TempoMap::set_meter (Meter const & m, timepos_t const & time) /* meter changes must be on bar */ - bbt = metric.bbt_at (sc); + bbt = metric.bbt_at (time); bbt = metric.round_to_bar (bbt); /* compute beat position */ @@ -1509,7 +1515,7 @@ TempoMap::bbt_at (timepos_t const & pos) const Temporal::BBT_Time TempoMap::bbt_at (superclock_t s) const { - return metric_at (s).bbt_at (s); + return metric_at (s).bbt_at (timepos_t::from_superclock (s)); } Temporal::BBT_Time @@ -1691,7 +1697,7 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u /* determine the BBT at start */ - BBT_Time bbt = metric.bbt_at (start); + BBT_Time bbt = metric.bbt_at (timepos_t::from_superclock (start)); DEBUG_TRACE (DEBUG::Grid, string_compose ("start %1 is %2\n", start, bbt)); @@ -1835,7 +1841,7 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u step = metric.superclocks_per_grid_at (start); start += step; - bbt = metric.bbt_at (start); + bbt = metric.bbt_at (timepos_t::from_superclock (start)); DEBUG_TRACE (DEBUG::Grid, string_compose ("step for note type was %1, now @ %2\n", step, start)); } else { @@ -1966,7 +1972,7 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t start, superclock_t end, u } start += step; - bbt = metric.bbt_at (start); + bbt = metric.bbt_at (timepos_t::from_superclock (start)); } while (start < end); @@ -2197,7 +2203,7 @@ TempoMap::bbt_walk (BBT_Time const & bbt, BBT_Offset const & o) const pos += metric.superclocks_per_bar (); } - return metric.bbt_at (pos); + return metric.bbt_at (timepos_t::from_superclock (pos)); } Temporal::Beats diff --git a/libs/temporal/temporal/tempo.h b/libs/temporal/temporal/tempo.h index d94102dd2a..22889dfe08 100644 --- a/libs/temporal/temporal/tempo.h +++ b/libs/temporal/temporal/tempo.h @@ -497,7 +497,7 @@ class LIBTEMPORAL_API TempoMetric { return int_div_round (superclocks_per_note_type_at_superclock (sc) * _tempo->note_type(), (int64_t) _meter->note_value()); } - BBT_Time bbt_at (superclock_t sc) const; + BBT_Time bbt_at (timepos_t const &) const; superclock_t superclock_at (BBT_Time const &) const; samplepos_t samples_per_bar (samplecnt_t sr) const { @@ -757,8 +757,6 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible return metric_at (bbt).meter().round_to_bar (bbt); } - BBT_Time bbt_at (superclock_t sc) const; - BBT_Time bbt_at (Beats const &) const; BBT_Time bbt_at (timepos_t const &) const; Beats quarters_at (BBT_Time const &) const; @@ -850,6 +848,9 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible void copy_points (TempoMap const & other); + BBT_Time bbt_at (Beats const &) const; + BBT_Time bbt_at (superclock_t sc) const; + /* parsing legacy tempo maps */ struct LegacyTempoState diff --git a/libs/temporal/timeline.cc b/libs/temporal/timeline.cc index ec885b5ee9..820c4dcc9c 100644 --- a/libs/temporal/timeline.cc +++ b/libs/temporal/timeline.cc @@ -648,7 +648,7 @@ timepos_t::earlier (Temporal::BBT_Offset const & offset) const TempoMap::SharedPtr tm (TempoMap::use()); if (is_superclock()) { - return timepos_t (tm->superclock_at (tm->bbt_walk (tm->bbt_at (superclocks()), -offset))); + return timepos_t (tm->superclock_at (tm->bbt_walk (tm->bbt_at (*this), -offset))); } return timepos_t (tm->bbtwalk_to_quarters (beats(), -offset)); @@ -747,7 +747,7 @@ 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)))); + v = build (false, (tm->superclock_at (tm->bbt_walk (tm->bbt_at (*this), -offset)))); } else { v = build (true, tm->bbtwalk_to_quarters (beats(), -offset).to_ticks()); } @@ -764,7 +764,7 @@ timepos_t::operator+= (Temporal::BBT_Offset const & offset) if (is_beats()) { v = build (true, tm->bbtwalk_to_quarters (beats(), offset).to_ticks()); } else { - v = build (false, tm->superclock_at (tm->bbt_walk (tm->bbt_at (superclocks()), offset))); + v = build (false, tm->superclock_at (tm->bbt_walk (tm->bbt_at (*this), offset))); } return *this;