diff options
Diffstat (limited to 'client/lib')
| -rw-r--r-- | client/lib/keys.js | 1 | ||||
| -rw-r--r-- | client/lib/midi.js | 33 |
2 files changed, 33 insertions, 1 deletions
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} <br>`; + }); + 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 }; |
