forked from trav/lintunes
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user