twothree

Build story

A piano app that listens: Web MIDI in the browser

TwoThree is a web page, and it hears every key you press. There’s no app to install and no driver: one USB cable from the keyboard to the computer, and the browser does the rest. This is how that works, and the few rules that make it trustworthy.

One cable, no driver

Many keyboards send MIDI over USB. MIDI doesn’t carry sound. It carries short messages: this key went down, this hard; this key came up. For a keyboard that follows the USB MIDI standard, as the PSR-E483 does, Windows and macOS need no driver.

Chrome, Edge and Firefox can pass those messages to a web page through Web MIDI. We test in Chrome. The first time, the browser asks if the page may use your MIDI devices. Say yes, and the keyboard shows up by name. A Yamaha PSR-E483 on a Mac calls itself “Digital Keyboard”.

Which cable, and which keyboard settings to check: Learn piano on the Yamaha PSR-E483.

The keyboard makes the sound

TwoThree never plays back the notes you press. Your keyboard’s own speakers do that, with no added delay. Sound made by a browser usually lands 20 to 50 milliseconds after the key, enough to feel late.

When the app does play something, a demo or the click, it sends the notes to your keyboard over the same cable, so they come out of the same speakers or headphones as your playing.

Timing from the key, not the screen

Every MIDI message arrives with a timestamp: the moment the browser received it from the keyboard. TwoThree grades rhythm from that timestamp only, never from when the page got round to handling it, or when the screen drew it.

That matters because pages are busy. A redraw or a slow moment could delay the handling of a note by tens of milliseconds. On our PSR-E483, the gap between a note’s timestamp and our code seeing it had a median of 0.2 ms, but its worst case was 34.7 ms. Timing from the timestamp means that worst case never reaches your score.

Ignoring the flood

A keyboard sends more than notes. The PSR-E483 sends a clock message about 47 times a second, even while it sits idle, and an “I’m still here” message every 200 ms. In six minutes of testing we counted 16,447 clock messages.

  • Those real-time messages all start with a byte of 0xF8 or above. TwoThree drops them before anything else looks at the message, so they never cause a redraw.
  • A key coming up arrives as “key down, with no force” rather than as a separate “key up” message. Both mean the same thing, and both are handled.
  • Extras like Dual and Split are expected to send their notes on other channels; we haven’t tested that yet. TwoThree counts channel 1, and tells you when it sees an extra switched on.

Plugging in and out

The page listens for keyboards coming and going, so a cable pulled out mid-lesson and plugged back in is meant to work again without a reload. We haven’t yet run the full unplug test on the PSR-E483, so if it doesn’t, reload the page. If several MIDI devices are connected, TwoThree prefers the one with your keyboard’s name, and any key you press settles it.

When there’s no Web MIDI

Safari doesn’t offer Web MIDI, and neither does any browser on an iPhone. There, TwoThree still works: with the keys on screen, or with the microphone listening to your keyboard or piano. The microphone listens for single notes, and says plainly what it can’t grade, such as exact timing.

Every lesson checks the right key whichever way the notes arrive. With a cable, it can also check the right time, because the timing comes from the keyboard itself.

Why the note number matters, and why the same key can be C3 or C4: Octave numbers on piano.

Plug in and play a note

The first lesson starts by finding your keyboard, then waits for your first key. No account needed. Your practice saves on this device. A free account keeps it safe and on your other devices.