BPM tap button averages the whole session, not the last 8 taps

TapTempo kept a rolling window of 8 taps, so a long tapping session
chased the most recent taps instead of converging on the overall tempo
(trav noticed the estimate never settled). Every tap since the session
started now counts; a >2.5s gap still begins a fresh session.
This commit is contained in:
2026-07-03 11:30:37 -04:00
parent 4fa21a76ac
commit 4fc630f00b
2 changed files with 23 additions and 14 deletions
+3 -3
View File
@@ -3,18 +3,18 @@
class TapTempo:
RESET_GAP_SECONDS = 2.5
MAX_TAPS = 8
def __init__(self):
self._taps: list[float] = []
def tap(self, now: float) -> int | None:
"""Record a tap at monotonic time `now`; returns the current bpm
estimate (None until there are two taps in the series)."""
estimate (None until there are two taps in the series). Every tap
since the series started counts — the estimate converges on the
overall tempo instead of chasing the most recent few taps."""
if self._taps and now - self._taps[-1] > self.RESET_GAP_SECONDS:
self._taps = []
self._taps.append(now)
self._taps = self._taps[-self.MAX_TAPS:]
return self.bpm()
def bpm(self) -> int | None: