fix(beat): follow a controller that restarted its beat counter

A run of three consecutive indices that all look old means the controller
rebooted and restarted its counter, so resync to it; one or two stray old
frames are still dropped as late copies.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-11-10 01:48:42 +13:00
1 parent 495da4e366
commit 08d7277204
2 files changed
+38 -1

No files matched your search

+21
View File
@@ -84,6 +84,27 @@ def test_stats_count_dups_and_freerun():
assert b.stats["freerun"] == 1 and b.stats["fires"] == 2
def test_controller_restart_is_followed():
b = BeatSync()
assert b.on_frame(frame(29000), 0)
assert not b.on_frame(frame(1), 500) # looks old
assert not b.on_frame(frame(1), 502) # second copy of the same beat
assert not b.on_frame(frame(2), 1000)
assert b.on_frame(frame(3), 1500) # third consecutive: the counter really restarted
assert not b.on_frame(frame(3), 1502)
assert b.on_frame(frame(4), 2000)
def test_stray_old_frames_do_not_reset():
b = BeatSync()
assert b.on_frame(frame(100), 0)
assert not b.on_frame(frame(90), 100)
assert b.on_frame(frame(101), 500)
assert not b.on_frame(frame(99), 600)
assert not b.on_frame(frame(98), 700) # not consecutive upward
assert b.on_frame(frame(102), 1000)
if __name__ == "__main__":
for name, fn in list(globals().items()):
if name.startswith("test_"):