From 4586b39e8b09f58fd9be504d88fa43f9f6f6344f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 8 Aug 2025 23:11:59 -0600 Subject: [PATCH] add a method to compute tempo & meter for an audio source (not used yet) --- libs/ardour/ardour/audioregion.h | 2 ++ libs/ardour/audioregion.cc | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index bb078ef2f7..7f0723f5f1 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -291,6 +291,8 @@ class LIBARDOUR_API AudioRegion : public Region, public AudioReadable int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal); void send_change (const PBD::PropertyChange&); void ensure_length_sanity (); + + void set_tempo_stuff_from_source (); }; } /* namespace ARDOUR */ diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 3010687d38..0637e91126 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -433,6 +433,21 @@ AudioRegion::~AudioRegion () } } +void +AudioRegion::set_tempo_stuff_from_source () +{ + samplecnt_t data_size = _session.sample_rate() * 10; + std::unique_ptr data (new Sample[data_size]); + + if (read (data.get(), 0, data_size, 0) == data_size) { + double tempo; + double beatcount; + + estimate_audio_tempo (shared_from_this(), data.get(), data_size, _session.sample_rate(), tempo, _meter, beatcount); + _tempo = Temporal::Tempo (tempo, 4); + } +} + void AudioRegion::post_set (const PropertyChange& /*ignored*/) { @@ -2740,4 +2755,3 @@ AudioRegion::ensure_length_sanity () _length = timecnt_t (timepos_t (_length.val().samples()), _length.val().position()); } } -