Skip to content

web: time the MIDI out checks with a delay - #338

Merged
mishan merged 1 commit into
masterfrom
midiclock
Oct 4, 2026
Merged

mishan merged 1 commit into
masterfrom
midiclock

Conversation

@mishan

@mishan mishan commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Fixes the flaky MIDI clock goes out check in pagetest.mjs, which failed master's CI after #337 merged ("28 ticks 46.1 ms apart") and blocked that deploy. It had failed the same way on several PRs.

Cause

  • The worklet stamps each MIDI message with the audio time of the frame it sounds at, and posts it to the page as it composes.
  • At a delay of 0 (the page's default, and what the test used), a message that reaches the page a few milliseconds late is past due. handOff then sends it stamped now, i.e. Math.max(due, now).
  • On real hardware the output latency covers this. Headless CI audio has almost none, so on a loaded runner the test measured the page's arrival times, not the piece's.
  • The note checks in the same block were affected too, just less visibly (a half-beat note measured 479–492 ms).

Change

  • The MIDI out block of the test runs with a 100 ms delay, which is what the setting is for.
  • The delayed-note check keeps its own 200 ms, and the delay returns to 0 at the end.
  • No change to the page itself.

Testing

  • pagetest.mjs, 3 runs: the half-beat note now measures 500.0 ms exactly (it was 490–492 locally before), beat spacing is 1002.6–1002.8 ms, and the clock is 41.7 ms apart every time.
  • I couldn't reproduce the CI failure under local CPU load, so the evidence is the code path above plus the exact note timing now.

The worklet stamps a MIDI message with the time its frame sounds and
posts it as it composes. At the page's default delay of 0, one that
reaches the page a few milliseconds late is past due and goes out
stamped now; headless audio has almost no output latency to absorb
that, so on a loaded CI runner the clock check measured ticks 46 ms
apart where 41.7 was due (master's #337 merge and several PRs), and a
half-beat note once came out at 479 ms. The MIDI out block now runs at
a 100 ms delay, which is what the setting is for; the delayed-note
check keeps its 200, and the delay goes back to 0 at the end. The
half-beat note now measures 500.0 ms exactly.
@mishan
mishan merged commit c3b190e into master Oct 4, 2026
33 of 34 checks passed
@mishan
mishan deleted the midiclock branch October 4, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant