More accurate BPM: average over 96 ticks (4 quarter notes)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 19:34:12 -04:00
parent 91d16595b7
commit 20fc5e40b8
+8 -4
View File
@@ -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