From 0e0c63f658fe5e0d0249bcbfba87fdb5e0484208 Mon Sep 17 00:00:00 2001 From: julian laplace Date: Sat, 5 Jul 2025 18:57:07 +0200 Subject: local proxy, json --- client/lib/keys.js | 1 - client/lib/midi.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 client/lib/midi.js (limited to 'client/lib') diff --git a/client/lib/keys.js b/client/lib/keys.js index 84f8103..687517f 100644 --- a/client/lib/keys.js +++ b/client/lib/keys.js @@ -38,7 +38,6 @@ function keydown(e) { if (!(e.keyCode in keys)) return; var index = keys[e.keyCode]; if (e.shiftKey) index += letters.length; - index -= 7; callback(index); } diff --git a/client/lib/midi.js b/client/lib/midi.js new file mode 100644 index 0000000..06cb266 --- /dev/null +++ b/client/lib/midi.js @@ -0,0 +1,33 @@ +/** + * MIDI + * @module midi.js; + */ + +import { WebMidi } from "webmidi"; + +function enable(play) { + WebMidi.enable() + .then(onEnabled) + .catch((error) => console.error(error)); + + // Function triggered when WEBMIDI.js is ready + function onEnabled() { + // Display available MIDI input devices + if (WebMidi.inputs.length < 1) { + console.log("No device detected."); + return; + } else { + WebMidi.inputs.forEach((device, index) => { + document.body.innerHTML += `${index}: ${device.name}
`; + }); + const mySynth = WebMidi.inputs[0]; + // const mySynth = WebMidi.getInputByName("TYPE NAME HERE!") + + mySynth.channels[1].addListener("noteon", (event) => { + console.log(event.note); + }); + } + } +} + +export default { enable }; -- cgit v1.2.3-70-g09d2