metronome/wokwi
Me Here da7c94e67f Implement per-track playback flow (rep / end / relative goto)
Adds the per-track end-action model designed in docs/track-format.md §3, end to
end across both engines, both firmwares, and the editors.

Grammar (parsed + serialized by engine.js and both app.py):
  rep=<n>     cycles before the end-action fires (default 1)
  end=stop    stop after rep cycles
  end=next    advance one track (sugar for end=+1)
  end=<±N>    relative goto after rep cycles (e.g. end=-2 = D.S.)
  (absent)    loop forever — the metronome default

Firmware runtime (pico-cp + pico-explorer): _on_new_bar now consults a per-track
_end_plan() and fires stop / gapless-advance / relative-goto at the right bar.
A cycle = b<bars>, else one master bar; fire bar = rep * cycle. Explicit end=
governs; with no end, the global Continue toggle stays a default (=end=next, still
needs b<bars>) so existing set-lists and the CONT UI are unchanged. _prepare_next
takes a target index; the seam machinery, _do_advance and live-sync all carry rep/end.

Editors (editor.html + editor-beta.html): state.rep/state.end thread through
applySetup / currentSetup / currentPatch so load -> edit -> save preserves the
flow; authoring is via the program-string field (no graphical control yet).

Tests: the 3 playback-flow vectors now pass on both engines (39 pass / 3 known).
Runtime decision logic (_end_plan / _goto_target) unit-tested for stop, rep,
relative goto clamp/wrap, and legacy-Continue precedence. Codec round-trip
verified idempotent. Both firmwares compile + mpy-cross clean.

Also: untrack stale __pycache__/*.pyc build artifacts and gitignore them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 00:37:06 -05:00
..
diagram.json Add Wokwi (Pi Pico) simulation of the Micro metronome 2026-05-28 08:04:53 -05:00
main.py Add Wokwi (Pi Pico) simulation of the Micro metronome 2026-05-28 08:04:53 -05:00
README.md Add Wokwi (Pi Pico) simulation of the Micro metronome 2026-05-28 08:04:53 -05:00
ssd1306.py Add Wokwi (Pi Pico) simulation of the Micro metronome 2026-05-28 08:04:53 -05:00

Wokwi simulation — PMµ Micro (Raspberry Pi Pico)

A runnable Wokwi simulation of the PMµ Micro metronome on a Raspberry Pi Pico (RP2040), in MicroPython. It's a functional standin — Wokwi has no 14segment display or analog audio path, so we approximate:

Real device Simulated with
Clickable thumbroller KY040 rotary encoder (rotate / press / hold+rotate)
Amber 14segment display SSD1306 OLED (shows BPM and track names)
Analog click + speaker Piezo buzzer (accent beat = higher, longer beep)

Controls

  • Rotate the encoder → tempo (BPM)
  • Press (the encoder's button) → start / stop
  • Hold the button + rotate → switch track (release to load it)

Run it (you do this part — I can't operate your Wokwi account)

I can't log into wokwi.com or create the project on the site for you. Use these files:

  1. Open https://wokwi.com/pi-pico — it starts a new Pi Pico MicroPython project.
  2. Click the diagram.json tab and replace its contents with this folder's diagram.json.
  3. Replace main.py with this folder's main.py.
  4. Add a new file named ssd1306.py (the next to the file tabs) and paste this folder's ssd1306.py.
  5. Press ▶ (play). Rotate / click the encoder; you'll hear the click and see the OLED update.

If you use the Wokwi VS Code extension instead, keep these three files together and add a diagram.json reference as usual.

Pin map (Pico GPIO)

Function Pin
OLED SDA / SCL (I²C0) GP0 / GP1
Encoder CLK / DT / SW GP2 / GP3 / GP4
Buzzer GP5
OLED + encoder power 3V3 / GND

The real firmware ("PORTS TO FIRMWARE" in the web app) drives a 14segment display over I²C and injects the click into the analog signal path; this sim keeps the same control model and beat scheduling so the feel matches.