5 ms·
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 omneity 3mo 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/send https://developer.mozilla.org/en-US/docs/Web/API/MIDIOutput/...
1: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now https://developer.mozilla.org/en-US/docs/Web/API/Performance...
- halfradaition 3mo agoBrilliant suggestion. I'll test scheduling directly on the Web MIDI API thread to keep JS main thread timers out of the equation.
- omneity 3mo agoGlad it helped! A little credit on the post would go a long way :)