mudcube / MIDI.js

:musical_keyboard: Making life easy to create a MIDI-app on the web. Includes a library to program synesthesia into your app for memory recognition or for creating trippy effects. Convert soundfonts for Guitar, Bass, Drums, ect. into code that can be read by the browser. Supports multiple simultaneous instruments and perfect timing.
http://mudcu.be/midi-js/
MIT License
3.8k stars 641 forks source link

Basic.html does not play WebMIDI #177

Open turnerhayes opened 8 years ago

turnerhayes commented 8 years ago

The WebMIDI plugin doesn't seem to be playing (this is on Chrome v50.0.2661.86). It is falling back on WebAudio. This appears to be because the WebMIDI detection code doesn't account for the current Web MIDI API; it looks for .outputs to be either a function or an array, but it is currently a MIDIOutputMap object, and subscripts don't work for accessing values of that type. I think this code will get the first output, if applicable:

output = pluginOutputs.values().next();

if (output) {
    output = output.value;
}

This still doesn't fix it, though, because the various output.send() calls pass delay * 1000, and Basic.html passes undefined for several of those delays, and Chrome complains that "The provided double value is non-finite." (presumably because undefined * 1000 is NaN). That's easily remedied by simply passing (delay || 0) * 1000 in place of delay * 1000.

It's still not playing for me, presumably because the WebMIDI branch of the loader code calls the WebMIDI's connect function directly, rather than going through requestQueue() like webaudio and audiotag, which means that the sound font isn't getting loaded. that doesn't seem to fix it, maybe this is some issue with my particular computer/MIDI setup. That being said, it might be handy to provide some way to allow people to select from MIDI outputs, rather than just using the first one.

john02813 commented 7 years ago

I want to play more than just one note in BASIC.html. I tried using for next loop but all the notes played at the same time as a chord instead of one at a time like a song.