Created
November 12, 2018 05:29
-
-
Save urish/6c225d46aa7f17b1dedc1803bd1881b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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