filter input name more flexibly (tested against desktop and Quest2)

webchuck
Fabien Benetou 2 years ago
parent 3a51d1ca83
commit 730cfb5659
  1. 11
      index.html

@ -2423,13 +2423,11 @@ function startWebMIDI(){
let notesPlaying = {} let notesPlaying = {}
let synth let synth
function webMidiStarted(){ function webMidiStarted(){
let midiStarted = Date.now() console.log("WebMidi enabled!", WebMidi.inputs)
console.log("WebMidi enabled!") let myInput = WebMidi.inputs.filter(i => i.name.match("MPK mini Play mk3"))?.[0]
synth = new Tone.Synth().toDestination() if (!myInput){ console.log("missing mk3 keyboard"); return;}
//let myInput = WebMidi.getInputByName("MPK mini Play mk3"); // on Quest 2
let myInput = WebMidi.getInputByName("MPK mini Play mk3:MPK mini Play mk3"); // on desktop
WebMidi.inputs.forEach(input => console.log(input.manufacturer, input.name));
const keyboard = myInput.channels[1] const keyboard = myInput.channels[1]
synth = new Tone.Synth().toDestination()
keyboard.addListener("noteon", e => { keyboard.addListener("noteon", e => {
let identifierNoOctave = e.note.identifier.slice(0,-1) let identifierNoOctave = e.note.identifier.slice(0,-1)
let pos = ""+ (Object.getOwnPropertyNames(notes).indexOf(identifierNoOctave)/40+e.note.octave/3.3-1.1)+ " 1.5 -.1" let pos = ""+ (Object.getOwnPropertyNames(notes).indexOf(identifierNoOctave)/40+e.note.octave/3.3-1.1)+ " 1.5 -.1"
@ -2444,7 +2442,6 @@ function webMidiStarted(){
setInterval( _=> pushBackClass("musicalnote", .001), 10) setInterval( _=> pushBackClass("musicalnote", .001), 10)
const pads = myInput.channels[10] const pads = myInput.channels[10]
pads.addListener("noteon", e => { pads.addListener("noteon", e => {
let identifierNoOctave = e.note.identifier.slice(0,-1) let identifierNoOctave = e.note.identifier.slice(0,-1)
let audio = new Audio(drumkitBaseURL+drumKit[identifierNoOctave]) let audio = new Audio(drumkitBaseURL+drumKit[identifierNoOctave])

Loading…
Cancel
Save