Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get a midi file's notes and time offsets
// Using: https://raw.githubusercontent.com/nfroidure/MIDIFile/master/dist/MIDIFile.js
$('#input-area').prepend('<input type="file" id="someFile" />'); $('#someFile').change(function() { var f = document.getElementById('someFile').files[0]; var fr = new FileReader(); fr.onload = function(d) { window.fileNotes = $.map(new MIDIFile(window.SomeBuff = d.target.result).getMidiEvents().filter(function(e) { return e.subtype === 9 || e.subtype === 8 }), function(e) { return { ms: e.playTime, note: (e.param1 - 27)/(67-27), on: e.subtype === 9 }; }) }; fr.readAsArrayBuffer(f); })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment