Skip to content

Instantly share code, notes, and snippets.

@JiggyPete
Last active January 11, 2017 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiggyPete/0071a5aeee461bc7d9620edb3443efb6 to your computer and use it in GitHub Desktop.
Save JiggyPete/0071a5aeee461bc7d9620edb3443efb6 to your computer and use it in GitHub Desktop.
mario midi controls
// 1: Visit http://mario5.florian-rappl.de/#menu
// 2: Copy and paste the following code into the console
// 3: You may need to update the pad id's for your midi controller. Output will appear in the console when you press pads, take the 2nd value from each pad event and tweak the controller values at the bottom of this script, then paste it into the console again.
// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false // this defaults to 'false' and we won't be covering sysex in this article.
}).then(onMIDISuccess, onMIDIFailure);
} else {
alert("No MIDI support in your browser.");
}
function onMIDIFailure(e) {
// when we get a failed response, run this code
console.log("No access to MIDI devices or your browser doesn't support WebMIDI API. Please use WebMIDIAPIShim " + e);
}
// midi functions
function onMIDISuccess(midiAccess) {
console.log('MIDI Access Object', midiAccess);
var midi = midiAccess;
var inputs = midi.inputs.values();
for( var input = inputs.next(); input && !input.done; input = inputs.next() ) {
console.log('input found')
input.value.onmidimessage = onMIDIMessage;
}
}
function processMidiEvent(data, buttonId, jqueryButton) {
if(data[1] == buttonId ) {
if(data[2] == '127') {
jqueryButton.trigger('mousedown');
}
else {
jqueryButton.trigger('mouseup');
}
}
}
function onMIDIMessage(message) {
data = message.data;
console.log(data)
processMidiEvent(data, '1', $("#lButton"));
processMidiEvent(data, '2', $("#rButton"));
processMidiEvent(data, '49', $("#uButton"));
processMidiEvent(data, '51', $("#dButton"));
processMidiEvent(data, '50', $("#aButton"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment