Tone.js
Tone.js copied to clipboard
No buffer for note error when using Tone.Sampler onload to track readiness to play
Describe the bug
I'm using Tone.Sampler within a React app to play notes on the keyboard. I'm using the onload constructor param to track when the sampler is ready to play, and enable my keyboard based on this. However, I noticed that when I play a note right after the keyboard gets enabled (by spamming the taps, for example), I get a buffer error: Error: No available buffers for note: 60
.
I've tried it in Safari and Firefox, both seem to have this issue, Firefox less frequently.
When I put a small timeout on setting the loading state of a sampler, I can eliminate this behaviour, but ideally I would like to not rely on hardcoded timeouts.
To Reproduce
Here's a codesandbox example.
Expected behavior I would expect the onload to allow to reliably set loading state to false.
What I've tried
When I put a small timeout on setting the loading state of a sampler, I can eliminate this behaviour, but ideally I would like to not rely on hardcoded timeouts.