From ec37470778445367202cb695fe32d411d7ec7dac Mon Sep 17 00:00:00 2001 From: severak Date: Thu, 8 Aug 2024 19:26:26 +0200 Subject: [PATCH] Doing some experiments with WebMidiLink --- gm.html | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gm.html b/gm.html index 35a0a7b..1529265 100644 --- a/gm.html +++ b/gm.html @@ -354,6 +354,40 @@ }); + // TODO - put this into heartbeat.js, wrap it and link to https://www.g200kg.com/en/docs/webmidilink/spec.html + function webMidiLinkRecv(event) { + var msg = event.data.split(","); + switch (msg[0]) { + case "midi": + switch (parseInt(msg[1], 16) & 0xf0) { + case 0x80: + console.log('note off', parseInt(msg[2], 16)); + synth.noteOff(parseInt(msg[2], 16)); + break; + case 0x90: + var velo = parseInt(msg[3], 16); + if (velo > 0) { + console.log('note on', parseInt(msg[2], 16), velo); + synth.noteOn(parseInt(msg[2], 16), velo); + } else { + console.log('note on', parseInt(msg[2], 16), velo); + synth.noteOff(parseInt(msg[2], 16)); + } + break; + case 0xb0: + if (parseInt(msg[2], 16) == 0x78) { + console.log('panik!'); + synth.panic(); + } + break; + } + break; + } + } + + window.addEventListener("message", webMidiLinkRecv, false); + + });