feat: browser simulator served by the controller, desktop build, browser bridge
- led-simulator: the rig runs the C++ led-driver as WebAssembly (sim-driver/), one single-threaded worker per bar, no cross-origin isolation needed. Rooms (one JSON per room) with an on-page editor, and a pattern gallery. The Python server, Pyodide boot and ring buffer are removed. - sim-controller sim_rig.c: serves /sim/ from an embedded pack, the page's WebSocket and the rooms/flash API. The desktop build embeds it too. - bridge.c: a "browser" bridge kind that carries ESP-NOW frames to the page; devices announced through it are marked sim. - UI: Simulator in the Menu, split view with resize and pop-out, swipe between controller and rig on phones; SIM/REAL badges in Devices. - Fades: preset pushes and Wi-Fi driver bodies always carry fade and beat_time, so "off" no longer inherits an earlier fade. - Also the sequences-v2 work in progress: desktop port, bridge firmware, serial bridge, Wi-Fi drivers, sequence timeline, audio and API changes. - led-driver: ESP-NOW link, beat sync, control messages, sim hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
698c1463c0
commit
581b751904
506 files changed
+42336
-3599
No files matched your search
+82
-20
@@ -81,9 +81,9 @@ def test_sync_phase_needs_playback(c):
|
||||
assert c.post("/sequences/sync-phase", json={"mode": "step"}).status_code == 409
|
||||
|
||||
|
||||
def test_plays_on_beats_and_finishes(c, zone, clock):
|
||||
def test_plays_on_beats(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"), "loop": False,
|
||||
sid = new_id(c.post("/sequences", json={"name": unique("pytest-seq"),
|
||||
"lanes": [[{"preset_id": a, "beats": 2}, {"preset_id": b, "beats": 1}]]}))
|
||||
resp = c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
assert resp.status_code == 200
|
||||
@@ -94,16 +94,14 @@ def test_plays_on_beats_and_finishes(c, zone, clock):
|
||||
assert st["lane0_current_step"] == 1 and st["lane0_beats_per_step"] == 2
|
||||
assert st["sequence_beats_per_pass"] == 3
|
||||
seen = set()
|
||||
deadline = time.monotonic() + 10 * BEAT_S
|
||||
deadline = time.monotonic() + 4 * BEAT_S
|
||||
while time.monotonic() < deadline:
|
||||
st = c.get("/sequences/status").json()
|
||||
if not st["active"]:
|
||||
break
|
||||
seen.add(st["lane0_current_step"])
|
||||
time.sleep(BEAT_S / 3)
|
||||
assert st["active"] is False, "sequence should end after its 3 beats"
|
||||
assert st["active"] is True, "a looping sequence keeps playing"
|
||||
assert {1, 2} <= seen
|
||||
assert c.get("/api/audio/status").json()["status"]["beat_readout"] == "3/3"
|
||||
# (A loop-off sequence is a one-shot: see test_play_routes_oneshot_over_preset)
|
||||
|
||||
|
||||
def test_loops_and_stops(c, zone, clock):
|
||||
@@ -231,12 +229,14 @@ def test_chase_moves_and_bounces(c, zone, clock):
|
||||
assert seen[:5] == [0, 1, 2, 1, 0][: len(seen[:5])] and len(seen) >= 4
|
||||
|
||||
|
||||
# ------------------------------------------------------------------- animations
|
||||
# ------------------------------------------------------------------- one-shots
|
||||
# A sequence with loop off is a one-shot: it plays once over whatever runs in the zone, then the zone goes
|
||||
# back to its last looping preset or sequence. /fire plays one; /play routes one-shots the same way.
|
||||
|
||||
|
||||
def test_animation_plays_once_alone(c, zone, clock):
|
||||
def test_oneshot_plays_once_alone(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", loop=False, targets=TARGETS[:1], lanes=[[{"preset_id": a, "beats": 2}]],
|
||||
aid = make(c, loop=False, targets=TARGETS[:1], lanes=[[{"preset_id": a, "beats": 2}]],
|
||||
lane_opts=[{"targets": [0]}])
|
||||
resp = c.post(f"/sequences/{aid}/fire", json={"zone_id": zone})
|
||||
assert resp.status_code == 200 and resp.json()["wait"] == "now"
|
||||
@@ -246,35 +246,84 @@ def test_animation_plays_once_alone(c, zone, clock):
|
||||
assert st["overlay"]["active"] is False
|
||||
|
||||
|
||||
def test_animation_over_sequence_keeps_time(c, zone, clock):
|
||||
def test_oneshot_is_timed_in_seconds(c, zone, clock):
|
||||
# Whatever its advance_mode says, a one-shot counts seconds: 1.5 s, not 99 beats (~30 s at 200 BPM)
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, loop=False, advance_mode="beats", targets=TARGETS[:1],
|
||||
lanes=[[{"preset_id": a, "seconds": 1.5, "beats": 99}]], lane_opts=[{"targets": [0]}])
|
||||
assert c.post(f"/sequences/{aid}/fire", json={"zone_id": zone}).status_code == 200
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["lanes"][0]["mode"] == "time", "a one-shot's lanes are timed"
|
||||
t0 = time.monotonic()
|
||||
while time.monotonic() - t0 < 10 and c.get("/sequences/status").json()["overlay"]["active"]:
|
||||
time.sleep(0.1)
|
||||
elapsed = time.monotonic() - t0
|
||||
assert c.get("/sequences/status").json()["overlay"]["active"] is False
|
||||
assert elapsed < 6, "the one-shot ends after its seconds"
|
||||
|
||||
|
||||
def test_play_routes_oneshot_over_preset(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
# A 6-beat pass, so the beat count can't wrap round while the animation plays
|
||||
assert c.post(f"/zones/{zone}/play", json={"preset_id": a}).status_code == 200 # the looping preset
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
assert c.post(f"/sequences/{aid}/play", json={"zone_id": zone}).status_code == 200
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False, "a one-shot never becomes the zone's looping sequence"
|
||||
assert st["overlay"]["active"] is True and st["overlay"]["sequence_id"] == aid
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is False and st["active"] is False
|
||||
|
||||
|
||||
def test_oneshot_over_sequence_keeps_time(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
# A 6-beat pass, so the beat count can't wrap round while the one-shot plays
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 3}, {"preset_id": b, "beats": 3}]],
|
||||
lanes_group_ids=[["pytest-g1"]])
|
||||
aid = make(c, kind="animation", loop=False, lanes=[[{"preset_id": b, "beats": 3}]],
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 3}]],
|
||||
targets=[{"group_ids": ["pytest-g1"]}], lane_opts=[{"targets": [0]}])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
c.post(f"/sequences/{aid}/fire", json={}) # the playing sequence's zone
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["sequence_beat_at"] >= 2, beats=4)
|
||||
assert st["overlay"]["active"] is True and st["active"] is True and st["sequence_id"] == sid
|
||||
assert st["sequence_beat_at"] >= 2, "the sequence keeps counting under the animation"
|
||||
assert st["sequence_beat_at"] >= 2, "the sequence keeps counting under the one-shot"
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is False and st["active"] is True and st["sequence_id"] == sid
|
||||
|
||||
|
||||
def test_animation_step_fires_overlay(c, zone, clock):
|
||||
def test_oneshot_clip_lasts_its_length(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
aid = make(c, kind="animation", loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": aid, "beats": 1, "length": "animation"}]])
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": b, "beats": 2}]])
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": aid, "beats": 3}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is True and st["overlay"]["sequence_id"] == aid
|
||||
assert st["lanes"][0]["beats_in_step"] == 2, "the step lasts as long as the animation"
|
||||
assert st["lanes"][0]["beats_in_step"] == 3, "the clip lasts as long as it is drawn"
|
||||
|
||||
|
||||
def test_looping_sequence_as_clip_plays_once(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
lid = make(c, lanes=[[{"preset_id": b, "beats": 1}]]) # loops on its own
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 1}, {"animation_id": lid, "beats": 6}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
st = wait_for(c, lambda s: s["overlay"]["active"])
|
||||
assert st["overlay"]["active"] is True
|
||||
st = wait_for(c, lambda s: not s["overlay"]["active"], beats=4)
|
||||
assert st["overlay"]["active"] is False, "over the zone it plays once, not for ever"
|
||||
|
||||
|
||||
def test_legacy_animation_kind_plays_once(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", lanes=[[{"preset_id": a, "beats": 1}]])
|
||||
rec = c.get(f"/sequences/{aid}").json()
|
||||
assert rec["loop"] is False and "kind" not in rec, "an older client's animation is a one-shot"
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False and st["overlay"]["active"] is True
|
||||
|
||||
|
||||
def test_overlay_stop_and_fire_errors(c, zone, clock):
|
||||
a, = presets(c, 1)
|
||||
aid = make(c, kind="animation", loop=True, lanes=[[{"preset_id": a, "beats": 1}]])
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": a, "beats": 8}]])
|
||||
assert c.post("/sequences/999999/fire", json={"zone_id": zone}).status_code == 404
|
||||
c.post("/sequences/stop")
|
||||
assert c.post(f"/sequences/{aid}/fire", json={}).status_code == 400 # no zone, nothing playing
|
||||
@@ -283,3 +332,16 @@ def test_overlay_stop_and_fire_errors(c, zone, clock):
|
||||
assert st["overlay"]["active"] is True
|
||||
assert c.post("/sequences/overlay/stop").json() == {"ok": True}
|
||||
assert c.get("/sequences/status").json()["overlay"]["active"] is False
|
||||
|
||||
def test_preset_takes_over_from_sequence(c, zone, clock):
|
||||
a, b = presets(c, 2)
|
||||
sid = make(c, lanes=[[{"preset_id": a, "beats": 2}]])
|
||||
c.post(f"/sequences/{sid}/play", json={"zone_id": zone})
|
||||
assert c.get("/sequences/status").json()["active"] is True
|
||||
aid = make(c, loop=False, lanes=[[{"preset_id": a, "beats": 4}]])
|
||||
c.post(f"/sequences/{aid}/play", json={"zone_id": zone})
|
||||
# The UI has sent the preset to the drivers itself
|
||||
assert c.post(f"/zones/{zone}/play", json={"preset_id": b, "drivers": False}).status_code == 200
|
||||
st = c.get("/sequences/status").json()
|
||||
assert st["active"] is False, "a looping preset replaces the zone's looping sequence"
|
||||
assert st["overlay"]["active"] is True, "the one-shot carries on, then comes back to the preset"
|
||||
Reference in new issue
Block a user