|
|
import { Synthetizer } from "../synthetizer/synthetizer.js"; |
|
|
import { consoleColors } from "../utils/other.js"; |
|
|
import { SpessaSynthInfo } from "../utils/loggin.js"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class WebMIDILinkHandler |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
constructor(synth) |
|
|
{ |
|
|
|
|
|
window.addEventListener("message", msg => |
|
|
{ |
|
|
if (typeof msg.data !== "string") |
|
|
{ |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const data = msg.data.split(","); |
|
|
if (data[0] !== "midi") |
|
|
{ |
|
|
return; |
|
|
} |
|
|
|
|
|
data.shift(); |
|
|
|
|
|
const midiData = data.map(byte => parseInt(byte, 16)); |
|
|
|
|
|
synth.sendMessage(midiData); |
|
|
}); |
|
|
|
|
|
SpessaSynthInfo("%cWeb MIDI Link handler created!", consoleColors.recognized); |
|
|
} |
|
|
} |