Skip to content

Instantly share code, notes, and snippets.

@urish
Created November 12, 2018 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urish/6c225d46aa7f17b1dedc1803bd1881b4 to your computer and use it in GitHub Desktop.
Save urish/6c225d46aa7f17b1dedc1803bd1881b4 to your computer and use it in GitHub Desktop.
const NOTE_ON = 0x90;
const NOTE_OFF = 0x80;
const delay = (ms) =>
new Promise(resolve => setTimeout(resolve, ms));
async function playDoReMi(midi) {
const midiOutput = Array.from(midi.outputs.values())[0];
const notes = [60, 62, 64]; // Do-Re-Mi
for (let note of notes) {
midiOutput.send([NOTE_ON, note, 127]);
await delay(500);
midiOutput.send([NOTE_OFF, note, 0]);
}
}
navigator.requestMIDIAccess().then(playDoReMi);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment