Skip to content

Web MIDI API

spessasus edited this page Aug 26, 2024 · 1 revision

Web MIDI API

SpessaSynth provides an easy way to connect physical MIDI Devices to it and back using MIDIDeviceHandler.

Tip

If you encounter any errors in this documentation, please open an issue!

Importing

// normal install
import { MIDIDeviceHandler } from "./spessasynth_lib/external_midi/midi_handler.js";
// npm package
import { MIDIDeviceHandler } from "spessasynth_lib";

Tip

Using the npm package? Make sure you've read this

Initialization

const MIDIHandler = new MIDIDeviceHandler();

Properties

inputs

The MIDI inputs as MIDIInputMap.

outputs

The MIDI outputs as MIDIOutputMap.

Methods

createMIDIDevicHandler

Initializes the connection to physical MIDI Devices.

MIDIHandler.createMIDIDeviceHandler();

The returned value is boolean, true if succeeded, false if failed.

Important

This function is asynchronous.

connectMIDIOutputToSeq

Connects a Sequencer instance to a MIDI Output, playing back the sequence to it.

MIDIHandler.connectMIDIOutputToSeq(output, seq);
  • output - a MIDIOutput to connect to.
  • seq - a Sequencer instance to connect.

disconnectSeqFromMIDI

Disconnects all MIDI devices from the sequencer.

MIDIHandler.connectMIDIOutputToSeq(seq);
  • seq - a Sequencer instance to disconnect.

connectDeviceToSynth

Connects a MIDI Input to a Synthetizer instance, responding to all received messages.

MIDIHandler.connectDeviceToSynth(input, synth);
  • input - a MIDIInput to connect.
  • synth - a Synthetizer instance to connect to.

disconnectAllDevicesFromSynth

Disconnects all MIDI Inputs from the Synthetizer instance.

MIDIHandler.disconnectAllDevicesFromSynth();

No arguments as this simply removes the onmidimessage property from the inputs.