Skip to content

Commit

Permalink
Doing some experiments with WebMidiLink
Browse files Browse the repository at this point in the history
  • Loading branch information
severak2 committed Aug 8, 2024
1 parent 35a8601 commit ec37470
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gm.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);


});
</script>

Expand Down

0 comments on commit ec37470

Please sign in to comment.