Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.53k
stars
115
forks
source link
TypeError: Cannot read properties of undefined (reading 'channels') #288
Description Describe the problem and how to reproduce it. If appropriate, include code samples, screenshots, error messages, etc.
Environment: Specify the environment where you are witnessing the problem:
Details Add any other information, context or details that could help track down the problem.
Trying to add web midi to a project but have issues:
TypeError: Cannot read properties of undefined (reading 'channels') at onEnabled (main.js:303:1)
import {WebMidi} from "webmidi"; WebMidi .enable() .then(onEnabled) .catch(err => console.log(err));
function onEnabled() { if (WebMidi.inputs.length < 1) { document.body.innerHTML+= "No device detected."; } 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[0].addListener("noteon", e => { document.body.innerHTML+=
${e.note.name} <br>
; });}
window.WebMidi = WebMidi;
when I call window.WebMidi() in console output is:{ "eventMap": {}, "eventsSuspended": false, "defaults": { "note": { "attack": 0.5039370078740157, "release": 0.5039370078740157, "duration": null } }, "interface": {}, "validation": true, "_inputs": [], "_disconnectedInputs": [], "_outputs": [], "_disconnectedOutputs": [], "_stateChangeQueue": [], "_octaveOffset": 0, "constructor": null }
calling window.inputs logs []
Same error appears when I try to play a note instead.
App is developed with react.js, ionic and capacitor.js Node.js v17.8.0 Language: Javascript On MacOs BigSur