Skip to content

Instantly share code, notes, and snippets.

@JimmyHoffa
Created January 21, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimmyHoffa/bf988f5d498db2851c33 to your computer and use it in GitHub Desktop.
Save JimmyHoffa/bf988f5d498db2851c33 to your computer and use it in GitHub Desktop.
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