spessasynth_lib
Version:
MIDI and SoundFont2/DLS library for the browsers with no compromises
43 lines (36 loc) • 1.14 kB
JavaScript
import { Synthetizer } from "../synthetizer/synthetizer.js";
import { consoleColors } from "../utils/other.js";
import { SpessaSynthCoreUtils } from "spessasynth_core";
/**
* web_midi_link.js
* purpose: handles the web midi link connection to the synthesizer
* https://www.g200kg.com/en/docs/webmidilink/
*/
export class WebMIDILinkHandler
{
/**
* @param synth {Synthetizer} the synth to play to
*/
constructor(synth)
{
window.addEventListener("message", msg =>
{
if (typeof msg.data !== "string")
{
return;
}
/**
* @type {string[]}
*/
const data = msg.data.split(",");
if (data[0] !== "midi")
{
return;
}
data.shift(); // remove MIDI
const midiData = data.map(byte => parseInt(byte, 16));
synth.sendMessage(midiData);
});
SpessaSynthCoreUtils.SpessaSynthInfo("%cWeb MIDI Link handler created!", consoleColors.recognized);
}
}