Last active
January 11, 2017 21:17
-
-
Save JiggyPete/0071a5aeee461bc7d9620edb3443efb6 to your computer and use it in GitHub Desktop.
mario midi controls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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