Hacker News new | ask | show | jobs
by omneity 34 days ago
The Web MIDI API[0] used by the author has a built-in precise scheduler, that has higher precision and works better than the unreliable setTimeout approach used by OP when coupled with the Performance API[1].

Pass a timestamp as the second argument to midiOutput.send(data, timestamp), calculated with performance.now. Something like midiOutput.send(data, performance.now() + offset)

0: https://developer.mozilla.org/en-US/docs/Web/API/MIDIOutput/...

1: https://developer.mozilla.org/en-US/docs/Web/API/Performance...

1 comments

Brilliant suggestion. I'll test scheduling directly on the Web MIDI API thread to keep JS main thread timers out of the equation.
Glad it helped! A little credit on the post would go a long way :)