Stop all future note-on events?

edited July 2020 in Questions & Support

Hi everybody (which is probably just djipco),

first, I just recently stumbled upon WebMidi.js and it's helping me doing my small "project" (more like a sketch) already. But i've got a question:

I can schedule midi notes to be played in the future, by e.g.

someMidiOutput.playNote("C3", <channel>, {time: 10000, duration: 1000})

which should play the C3 in 10 seconds, lasting one second. Now I can't seem to be able to cancel this scheduled note, i.e. by using


I can only cancel a currently playing note. If I call the stopNote directly after the playNote above, I will still hear the note in 10 seconds.

Is there a way to instantly remove all future events (I'd guess there is some internal queue that can be emptied, or somewhat?)





  • edited July 2020

    The proper way to do that would be to call the Output.clear() method. This method has been implemented in the next version (v3) of WebMidi.js. But... the method relies on the MIDIOutput.clear() method being available in Chrome. Unfortunately, this is not the case yet. Such a method is indeed defined in the Web MIDI API specification. A ticket has been opened in 2015 regarding this issue but has not been addressed yet. I urge you to leave a comment in this ticket's thread to demonstrate that this is a very much needed feature.

    So, for now, one way for you to do it would be to keep your own queue and only send the messages that are ready to be played a short time before they are scheduled to play (say, within 100 ms). This way, you could cancel your queue at your own leisure. I know this is not ideal but, unfortunately, that's the state of the Web MIDI API for now.

    This queuing system could be implemented in WebMidi.js. I am actually thinking about it for v3. I would have preferred to rely on the builtin mechanism but, if it's not coming, I guess someone will have to figure it out because this is an important feature.

    Hope this helps. Cheers!

Sign In or Register to comment.