Finding MIDI Devices
Connecting to Access Object
The very first thing you need to do when using MIDIVal is to connect with MIDI Access Object to get all information about MIDI devices available. This may trigger browser notification asking user for permissions:
PUT PICTURE HERE
import { MIDIVal } from "@midival/core";
MIDIVal.connect()
.then(access => {
console.log("Input Devices", access.inputs);
console.log("Output Devices", access.outputs);
});
You can use inputs
to connect to devices sending MIDI messages IN and to outputs
to send MIDI messages OUT yourself. You can maintain connection to as many devices as you want at any given time.
Connecting to MIDI Input device
If you wish to connect to the Input device (like MIDI keyboard, MIDI sequencer, launchpad, etc.) you can do it the following way:
import { MIDIVal, MIDIValInput } from "@midival/core";
MIDIVal.connect()
.then(access => {
if (!access.inputs) {
console.warn("No inputs yet");
return;
}
const input = new MIDIValInput(access.inputs[0]);
input.onAllNoteOn(message => {
console.log("Note On", message.note, message.velocity);
});
});
The code above will react to any pressed note on the device and display the velocity of it.
Connecting to MIDI Output device
If you wish to send notes to the MIDI device (for example synthesiser, drum machine, VST, DAW) you can connect to it the following way:
MIDIVal.connect()
.then(access => {
if (!access.outputs) {
console.warn("No outputs yet");
return;
}
const output = new MIDIValOutput(access.outputs[0]);
output.sendNoteOn(64, 127);
setTimeout(() => {
output.sendNoteOff(64);
}, 200);
});