6

Using the Web MIDI API, I can send some messages:

// Note on
output.send([0x90, 0x20, 0x50]);

I can also schedule some messages to be well-timed and sent in the future:

// Note off, 1 second later
output.send([0x80, 0x20, 0x40], performance.now() + 1000);

Now, suppose I've scheduled many messages to be sent in the future over several seconds, and now I want to cancel the sending of those messages. According to the spec, I should be able to call clear on the output:

output.clear();

However, this is undefined on Chrome (at least as of v79).

Uncaught TypeError: output.clear is not a function

I assume this part just isn't implemented yet. Is that the case? And if so, is there some alternative I can use today?

Brad
  • 159,648
  • 54
  • 349
  • 530
  • How did you initialize the `output` variable? Would be helpful if you can post the relevant code too. You should also specify what version of Chrome you are testing against. – Asesh Feb 02 '20 at 03:06
  • @Asesh `output` is just a `MIDIOutput`. It's obtained by doing something like `const midi = await navigator.requestMIDIAccess()`, and then `midi.outputs.values().next().value`. I'm not doing anything special, nor using any library. It's the Web MIDI API, straight up. Chrome v79. – Brad Feb 02 '20 at 04:27
  • 1
    https://bugs.chromium.org/p/chromium/issues/detail?id=471798&q=Midioutput%20clear&can=2 – Kaiido Feb 02 '20 at 04:33
  • @Kaiido That's the one! Thanks for finding it. :-) Could you please post that as an answer? I'll kick the bounty over to you in a few days... I'll leave the question open for now, in case anyone knows of a viable workaround. – Brad Feb 02 '20 at 04:38
  • 2
    Posted a CW, please don't give the bounty to this answer, it only answers the small half of the question. – Kaiido Feb 02 '20 at 05:04

1 Answers1

6

It is indeed not yet available. You can follow this issue to get updated of any advancements.

Note that Firefox has a flag to allow the Web Midi API, might worth a try to see if they do handle it.

Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • Thanks!! Did not know about the Web MIDI flag in Firefox. – Brad Feb 02 '20 at 05:14
  • 3
    Update: Web MIDI in Firefox doesn't work at all. :-( The flag may enable it some day, but it's seemingly just mocked out for now. Worse yet, it might get pulled. There is a lot of incorrect information on the issue tracker about it and security concerns. – Brad Feb 05 '20 at 01:25