From 20fc5e40b82d7d9c77a67ae287ef0f272c805bea Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 29 Mar 2026 19:34:12 -0400 Subject: [PATCH] More accurate BPM: average over 96 ticks (4 quarter notes) Co-Authored-By: Claude Opus 4.6 (1M context) --- pytheory/live.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pytheory/live.py b/pytheory/live.py index 64778b3..d78ce7d 100644 --- a/pytheory/live.py +++ b/pytheory/live.py @@ -352,10 +352,14 @@ class LiveEngine: now = _time.perf_counter() self._clock_times.append(now) - if len(self._clock_times) > 48: - self._clock_times = self._clock_times[-48:] - if len(self._clock_times) >= 24: - # Time span of 24 clock ticks = 1 quarter note + if len(self._clock_times) > 96: + self._clock_times = self._clock_times[-96:] + if len(self._clock_times) >= 96: + # Average over 4 quarter notes (96 ticks) for stability + total_time = self._clock_times[-1] - self._clock_times[-96] + if total_time > 0: + self._bpm = 60.0 * 4.0 / total_time + elif len(self._clock_times) >= 24: quarter_note_time = self._clock_times[-1] - self._clock_times[-24] if quarter_note_time > 0: self._bpm = 60.0 / quarter_note_time