In this lesson, you’ll learn how to use the Web MIDI API
alongside Tone.js
to connect to MIDI devices, receive MIDI messages, and prepare for MIDI output.
MIDI devices (like keyboards, controllers) send messages to your browser. With Tone.js
, you can convert these MIDI messages into beautiful synthesized sounds or trigger effects. This opens up endless possibilities for web-based music creation!
- First, you ask the browser for MIDI access.
- Then, you listen to MIDI input devices for note or control change messages.
- You can also send MIDI messages to output devices.
- Here, we’ll focus on connecting and logging MIDI input messages.
// Request MIDI access from browser
async function requestMIDI() {
const access = await navigator.requestMIDIAccess();
const inputs = [...access.inputs.values()];
inputs.forEach(input => {
input.onmidimessage = (msg) => {
console.log(msg.data);
};
});
}
Click the button above, then play notes on your connected MIDI keyboard or controller. MIDI message data will appear below in real time.