1 line
23 KiB
JavaScript
1 line
23 KiB
JavaScript
if(typeof MIDI=="undefined")var MIDI={};(function(){"use strict";var e={},t=function(t){var n=new Audio,r=t.split(";")[0];n.id="audio",n.setAttribute("preload","auto"),n.setAttribute("audiobuffer",!0),n.addEventListener("canplaythrough",function(){e[r]=!0},!1),n.src="data:"+t,document.body.appendChild(n)};MIDI.audioDetect=function(n){if(typeof Audio=="undefined")return n({});var r=new Audio;if(typeof r.canPlayType=="undefined")return n(e);var i=r.canPlayType('audio/ogg; codecs="vorbis"');i=i==="probably"||i==="maybe";var s=r.canPlayType("audio/mpeg");s=s==="probably"||s==="maybe";if(!i&&!s){n(e);return}i&&t("audio/ogg;base64,T2dnUwACAAAAAAAAAADqnjMlAAAAAOyyzPIBHgF2b3JiaXMAAAAAAUAfAABAHwAAQB8AAEAfAACZAU9nZ1MAAAAAAAAAAAAA6p4zJQEAAAANJGeqCj3//////////5ADdm9yYmlzLQAAAFhpcGguT3JnIGxpYlZvcmJpcyBJIDIwMTAxMTAxIChTY2hhdWZlbnVnZ2V0KQAAAAABBXZvcmJpcw9CQ1YBAAABAAxSFCElGVNKYwiVUlIpBR1jUFtHHWPUOUYhZBBTiEkZpXtPKpVYSsgRUlgpRR1TTFNJlVKWKUUdYxRTSCFT1jFloXMUS4ZJCSVsTa50FkvomWOWMUYdY85aSp1j1jFFHWNSUkmhcxg6ZiVkFDpGxehifDA6laJCKL7H3lLpLYWKW4q91xpT6y2EGEtpwQhhc+211dxKasUYY4wxxsXiUyiC0JBVAAABAABABAFCQ1YBAAoAAMJQDEVRgNCQVQBABgCAABRFcRTHcRxHkiTLAkJDVgEAQAAAAgAAKI7hKJIjSZJkWZZlWZameZaouaov+64u667t6roOhIasBACAAAAYRqF1TCqDEEPKQ4QUY9AzoxBDDEzGHGNONKQMMogzxZAyiFssLqgQBKEhKwKAKAAAwBjEGGIMOeekZFIi55iUTkoDnaPUUcoolRRLjBmlEluJMYLOUeooZZRCjKXFjFKJscRUAABAgAMAQICFUGjIigAgCgCAMAYphZRCjCnmFHOIMeUcgwwxxiBkzinoGJNOSuWck85JiRhjzjEHlXNOSuekctBJyaQTAAAQ4AAAEGAhFBqyIgCIEwAwSJKmWZomipamiaJniqrqiaKqWp5nmp5pqqpnmqpqqqrrmqrqypbnmaZnmqrqmaaqiqbquqaquq6nqrZsuqoum65q267s+rZru77uqapsm6or66bqyrrqyrbuurbtS56nqqKquq5nqq6ruq5uq65r25pqyq6purJtuq4tu7Js664s67pmqq5suqotm64s667s2rYqy7ovuq5uq7Ks+6os+75s67ru2rrwi65r66os674qy74x27bwy7ouHJMnqqqnqq7rmarrqq5r26rr2rqmmq5suq4tm6or26os67Yry7aumaosm64r26bryrIqy77vyrJui67r66Ys67oqy8Lu6roxzLat+6Lr6roqy7qvyrKuu7ru+7JuC7umqrpuyrKvm7Ks+7auC8us27oxuq7vq7It/KosC7+u+8Iy6z5jdF1fV21ZGFbZ9n3d95Vj1nVhWW1b+V1bZ7y+bgy7bvzKrQvLstq2scy6rSyvrxvDLux8W/iVmqratum6um7Ksq/Lui60dd1XRtf1fdW2fV+VZd+3hV9pG8OwjK6r+6os68Jry8ov67qw7MIvLKttK7+r68ow27qw3L6wLL/uC8uq277v6rrStXVluX2fsSu38QsAABhwAAAIMKEMFBqyIgCIEwBAEHIOKQahYgpCCKGkEEIqFWNSMuakZM5JKaWUFEpJrWJMSuaclMwxKaGUlkopqYRSWiqlxBRKaS2l1mJKqcVQSmulpNZKSa2llGJMrcUYMSYlc05K5pyUklJrJZXWMucoZQ5K6iCklEoqraTUYuacpA46Kx2E1EoqMZWUYgupxFZKaq2kFGMrMdXUWo4hpRhLSrGVlFptMdXWWqs1YkxK5pyUzDkqJaXWSiqtZc5J6iC01DkoqaTUYiopxco5SR2ElDLIqJSUWiupxBJSia20FGMpqcXUYq4pxRZDSS2WlFosqcTWYoy1tVRTJ6XFklKMJZUYW6y5ttZqDKXEVkqLsaSUW2sx1xZjjqGkFksrsZWUWmy15dhayzW1VGNKrdYWY40x5ZRrrT2n1mJNMdXaWqy51ZZbzLXnTkprpZQWS0oxttZijTHmHEppraQUWykpxtZara3FXEMpsZXSWiypxNhirLXFVmNqrcYWW62ltVprrb3GVlsurdXcYqw9tZRrrLXmWFNtBQAADDgAAASYUAYKDVkJAEQBAADGMMYYhEYpx5yT0ijlnHNSKucghJBS5hyEEFLKnINQSkuZcxBKSSmUklJqrYVSUmqttQIAAAocAAACbNCUWByg0JCVAEAqAIDBcTRNFFXVdX1fsSxRVFXXlW3jVyxNFFVVdm1b+DVRVFXXtW3bFn5NFFVVdmXZtoWiqrqybduybgvDqKqua9uybeuorqvbuq3bui9UXVmWbVu3dR3XtnXd9nVd+Bmzbeu2buu+8CMMR9/4IeTj+3RCCAAAT3AAACqwYXWEk6KxwEJDVgIAGQAAgDFKGYUYM0gxphhjTDHGmAAAgAEHAIAAE8pAoSErAoAoAADAOeecc84555xzzjnnnHPOOeecc44xxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY0wAwE6EA8BOhIVQaMhKACAcAABACCEpKaWUUkoRU85BSSmllFKqFIOMSkoppZRSpBR1lFJKKaWUIqWgpJJSSimllElJKaWUUkoppYw6SimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaVUSimllFJKKaWUUkoppRQAYPLgAACVYOMMK0lnhaPBhYasBAByAwAAhRiDEEJpraRUUkolVc5BKCWUlEpKKZWUUqqYgxBKKqmlklJKKbXSQSihlFBKKSWUUkooJYQQSgmhlFRCK6mEUkoHoYQSQimhhFRKKSWUzkEoIYUOQkmllNRCSB10VFIpIZVSSiklpZQ6CKGUklJLLZVSWkqpdBJSKamV1FJqqbWSUgmhpFZKSSWl0lpJJbUSSkklpZRSSymFVFJJJYSSUioltZZaSqm11lJIqZWUUkqppdRSSiWlkEpKqZSSUmollZRSaiGVlEpJKaTUSimlpFRCSamlUlpKLbWUSkmptFRSSaWUlEpJKaVSSksppRJKSqmllFpJKYWSUkoplZJSSyW1VEoKJaWUUkmptJRSSymVklIBAEAHDgAAAUZUWoidZlx5BI4oZJiAAgAAQABAgAkgMEBQMApBgDACAQAAAADAAAAfAABHARAR0ZzBAUKCwgJDg8MDAAAAAAAAAAAAAACAT2dnUwAEAAAAAAAAAADqnjMlAgAAADzQPmcBAQA="),s&&t("audio/mpeg;base64,/+MYxAAAAANIAUAAAASEEB/jwOFM/0MM/90b/+RhST//w4NFwOjf///PZu////9lns5GFDv//l9GlUIEEIAAAgIg8Ir/JGq3/+MYxDsLIj5QMYcoAP0dv9HIjUcH//yYSg+CIbkGP//8w0bLVjUP///3Z0x5QCAv/yLjwtGKTEFNRTMuOTeqqqqqqqqqqqqq/+MYxEkNmdJkUYc4AKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");var o=(new Date).getTime(),u=window.setInterval(function(){for(var t in e);var r=(new Date).getTime(),i=r-o>5e3;if(t||i)window.clearInterval(u),n(e)},1)}})();if(typeof MIDI=="undefined")var MIDI={};typeof MIDI.Soundfont=="undefined"&&(MIDI.Soundfont={}),function(){"use strict";var e=!1;MIDI.loadPlugin=function(e){typeof e=="function"&&(e={callback:e});var r=e.instruments||e.instrument||"acoustic_grand_piano";typeof r!="object"&&(r=[r]),r.map(function(e){return typeof e=="number"&&(e=MIDI.GeneralMIDI.byId[e]),e}),MIDI.soundfontUrl=e.soundfontUrl||MIDI.soundfontUrl||"./soundfont/",MIDI.audioDetect(function(i){var s="";typeof s=="undefined"&&(n[window.location.hash]?s=window.location.hash.substr(1):s=""),s===""&&(navigator.requestMIDIAccess?s="webmidi":window.webkitAudioContext?s="webaudio":window.Audio?s="audiotag":s="flash");if(!t[s])return;var o=i["audio/ogg"]?"ogg":"mp3";t[s](o,r,e.callback)})};var t={};t.webmidi=function(e,t,n){MIDI.loader&&MIDI.loader.message("Web MIDI API..."),MIDI.WebMIDI.connect(n)},t.flash=function(e,t,n){MIDI.loader&&MIDI.loader.message("Flash API..."),DOMLoader.script.add({src:"./inc/SoundManager2/script/soundmanager2.js",verify:"SoundManager",callback:function(){MIDI.Flash.connect(n)}})},t.audiotag=function(t,n,s){MIDI.loader&&MIDI.loader.message("HTML5 Audio API...");var o=i({items:n,getNext:function(n){e?DOMLoader.sendRequest({url:MIDI.soundfontUrl+n+"-"+t+".js",onprogress:r,onload:function(e){MIDI.Soundfont[n]=JSON.parse(e.responseText),MIDI.loader&&MIDI.loader.update(null,"Downloading",100),o.getNext()}}):DOMLoader.script.add({src:MIDI.soundfontUrl+n+"-"+t+".js",verify:"MIDI.Soundfont."+n,callback:function(){MIDI.loader&&MIDI.loader.update(null,"Downloading...",100),o.getNext()}})},onComplete:function(){MIDI.AudioTag.connect(s)}})},t.webaudio=function(t,n,s){MIDI.loader&&MIDI.loader.message("Web Audio API...");var o=i({items:n,getNext:function(n){e?DOMLoader.sendRequest({url:MIDI.soundfontUrl+n+"-"+t+".js",onprogress:r,onload:function(e){MIDI.Soundfont[n]=JSON.parse(e.responseText),MIDI.loader&&MIDI.loader.update(null,"Downloading...",100),o.getNext()}}):DOMLoader.script.add({src:MIDI.soundfontUrl+n+"-"+t+".js",verify:"MIDI.Soundfont."+n,callback:function(){MIDI.loader&&MIDI.loader.update(null,"Downloading...",100),o.getNext()}})},onComplete:function(){MIDI.WebAudioAPI.connect(s)}})};var n={"#webmidi":!0,"#webaudio":!0,"#audiotag":!0,"#flash":!0},r=function(e){this.totalSize||(this.getResponseHeader("Content-Length-Raw")?this.totalSize=parseInt(this.getResponseHeader("Content-Length-Raw")):this.totalSize=e.total);var t=this.totalSize?Math.round(e.loaded/this.totalSize*100):"";MIDI.loader&&MIDI.loader.update(null,"Downloading...",t)},i=function(e){var t={};t.queue=[];for(var n in e.items)t.queue.push(e.items[n]);return t.getNext=function(){if(!t.queue.length)return e.onComplete();e.getNext(t.queue.shift())},setTimeout(t.getNext,1),t}}();if(typeof MIDI=="undefined")var MIDI={};(function(){"use strict";(function(){var e=null,t=null,n=[],r=MIDI.WebMIDI={};r.setVolume=function(e,n){t.send([176+e,7,n])},r.programChange=function(e,n){t.send([192+e,n])},r.noteOn=function(e,n,r,i){t.send([144+e,n,r],i*1e3)},r.noteOff=function(e,n,r){t.send([128+e,n],r*1e3)},r.chordOn=function(e,n,r,i){for(var s=0;s<n.length;s++){var o=n[s];t.send([144+e,o,r],i*1e3)}},r.chordOff=function(e,n,r){for(var i=0;i<n.length;i++){var s=n[i];t.send([128,e,s,velocity],r*1e3)}},r.stopAllNotes=function(){for(var e=0;e<16;e++)t.send([176+e,123,0])},r.getInput=function(){return e.getInputs()},r.getOutputs=function(){return e.getOutputs()},r.connect=function(n){MIDI.technology="Web MIDI API",MIDI.setVolume=r.setVolume,MIDI.programChange=r.programChange,MIDI.noteOn=r.noteOn,MIDI.noteOff=r.noteOff,MIDI.chordOn=r.chordOn,MIDI.chordOff=r.chordOff,MIDI.stopAllNotes=r.stopAllNotes,MIDI.getInput=r.getInput,MIDI.getOutputs=r.getOutputs,navigator.requestMIDIAccess(function(r){e=r,t=e.getOutput(0),n&&n()},function(e){console.log("uh-oh! Something went wrong! Error code: "+e.code)})}})(),typeof MIDI.WebAudioAPI=="undefined"&&(MIDI.WebAudioAPI={}),(window.AudioContext||window.webkitAudioContext)&&function(){var e=window.AudioContext||window.webkitAudioContext,t=MIDI.WebAudioAPI,n,r={},i=1,s={},o=function(e,t,r,i,o){var u=MIDI.GeneralMIDI.byName[e],a=u.number,f=t[r],l=MIDI.Soundfont[e][f].split(",")[1],c=Base64Binary.decodeArrayBuffer(l);n.decodeAudioData(c,function(n){var l=f;while(l.length<3)l+=" ";typeof MIDI.loader!="undefined"&&MIDI.loader.update(null,u.instrument+"<br>Processing: "+(r/87*100>>0)+"%<br>"+l),n.id=f,i[r]=n;if(i.length===t.length){while(i.length){n=i.pop();if(!n)continue;var c=MIDI.keyToNote[n.id];s[a+""+c]=n}o(e)}})};t.setVolume=function(e){i=e},t.programChange=function(e,t){MIDI.channels[e].instrument=t},t.noteOn=function(e,t,o,u){if(!MIDI.channels[e])return;var a=MIDI.channels[e].instrument;if(!s[a+""+t])return;u<n.currentTime&&(u+=n.currentTime);var f=n.createBufferSource();r[e+""+t]=f,f.buffer=s[a+""+t],f.connect(n.destination);var l=n.createGainNode(),c=o/100*i*2-1;return l.connect(n.destination),l.gain.value=Math.max(-1,c),f.connect(l),f.noteOn(u||0),f},t.noteOff=function(e,t,i){i=i||0,i<n.currentTime&&(i+=n.currentTime);var s=r[e+""+t];if(!s)return;return s.gain.linearRampToValueAtTime(1,i),s.gain.linearRampToValueAtTime(0,i+.2),s.noteOff(i+.3),s},t.chordOn=function(e,n,r,i){var s={},o;for(var u=0,a=n.length;u<a;u++)s[o=n[u]]=t.noteOn(e,o,r,i);return s},t.chordOff=function(e,n,r){var i={},s;for(var o=0,u=n.length;o<u;o++)i[s=n[o]]=t.noteOff(e,s,r);return i},t.connect=function(r){MIDI.technology="Web Audio API",MIDI.setVolume=t.setVolume,MIDI.programChange=t.programChange,MIDI.noteOn=t.noteOn,MIDI.noteOff=t.noteOff,MIDI.chordOn=t.chordOn,MIDI.chordOff=t.chordOff,MIDI.Player.ctx=n=new e;var i=[],s=MIDI.keyToNote;for(var u in s)i.push(u);var a=[],f={},l=function(e){delete f[e];for(var t in f)break;t||r()};for(var c in MIDI.Soundfont){f[c]=!0;for(var h=0;h<i.length;h++)o(c,i,h,a,l)}}}(),window.Audio&&function(){var e=MIDI.AudioTag={},t={},n=1,r=-1,i=[],s={};for(var o=0;o<12;o++)i[o]=new Audio;var u=function(e,t){if(!MIDI.channels[e])return;var o=MIDI.channels[e].instrument,u=MIDI.GeneralMIDI.byId[o].id,t=s[t];if(!t)return;var a=(r+1)%i.length,f=(new Date).getTime(),l=i[a];l.src=MIDI.Soundfont[u][t.id],l.volume=n,l.play(),r=a};e.programChange=function(e,t){MIDI.channels[e].instrument=t},e.setVolume=function(e){n=e},e.noteOn=function(e,n,r,i){var o=t[n];if(!s[o])return;if(i)return window.setTimeout(function(){u(e,o)},i*1e3);u(e,o)},e.noteOff=function(e,t,n){},e.chordOn=function(e,n,r,i){for(var o in n){var a=n[o],f=t[a];if(!s[f])continue;u(e,f)}},e.chordOff=function(e,t,n){},e.stopAllNotes=function(){for(var e=0,t=i.length;e<t;e++)i[e].pause()},e.connect=function(n){var r={};for(var i in MIDI.keyToNote)t[MIDI.keyToNote[i]]=i,s[i]={id:i};MIDI.technology="HTML Audio Tag",MIDI.setVolume=e.setVolume,MIDI.programChange=e.programChange,MIDI.noteOn=e.noteOn,MIDI.noteOff=e.noteOff,MIDI.chordOn=e.chordOn,MIDI.chordOff=e.chordOff,n&&n()}}(),function(){var e=MIDI.Flash={},t={},n={};e.programChange=function(e,t){MIDI.channels[e].instrument=t},e.setVolume=function(e,t){},e.noteOn=function(e,r,i,s){if(!MIDI.channels[e])return;var o=MIDI.channels[e].instrument,u=MIDI.GeneralMIDI.byId[o].number;r=u+""+t[r];if(!n[r])return;if(s)return window.setTimeout(function(){n[r].play({volume:i*2})},s*1e3);n[r].play({volume:i*2})},e.noteOff=function(e,t,n){},e.chordOn=function(e,r,i,s){if(!MIDI.channels[e])return;var o=MIDI.channels[e].instrument,u=MIDI.GeneralMIDI.byId[o].number;for(var a in r){var f=r[a],l=u+""+t[f];n[l]&&n[l].play({volume:i*2})}},e.chordOff=function(e,t,n){},e.stopAllNotes=function(){},e.connect=function(r){soundManager.flashVersion=9,soundManager.useHTML5Audio=!0,soundManager.url="../inc/SoundManager2/swf/",soundManager.useHighPerformance=!0,soundManager.wmode="transparent",soundManager.flashPollingInterval=1,soundManager.debugMode=!1,soundManager.onload=function(){var i=function(e,t,r){var i=MIDI.GeneralMIDI.byName[e],s=i.number;n[s+""+t]=soundManager.createSound({id:t,url:MIDI.soundfontUrl+e+"-mp3/"+t+".mp3",multiShot:!0,autoLoad:!0,onload:r})};for(var s in MIDI.Soundfont){var o=[],u=function(){o.push(this.sID);if(typeof MIDI.loader=="undefined")return;MIDI.loader.update(null,"Processing: "+this.sID)};for(var a=0;a<88;a++){var f=t[a+21];i(s,f,u)}}MIDI.technology="Flash",MIDI.setVolume=e.setVolume,MIDI.programChange=e.programChange,MIDI.noteOn=e.noteOn,MIDI.noteOff=e.noteOff,MIDI.chordOn=e.chordOn,MIDI.chordOff=e.chordOff;var l=window.setInterval(function(){if(o.length!==88)return;window.clearInterval(l),r&&r()},25)},soundManager.onerror=function(){};for(var i in MIDI.keyToNote)t[MIDI.keyToNote[i]]=i}}(),MIDI.GeneralMIDI=function(e){var t=function(e){return e.replace(/[^a-z0-9 ]/gi,"").replace(/[ ]/g,"_").toLowerCase()},n={byName:{},byId:{},byCategory:{}};for(var r in e){var i=e[r];for(var s=0,o=i.length;s<o;s++){var u=i[s];if(!u)continue;var a=parseInt(u.substr(0,u.indexOf(" ")),10);u=u.replace(a+" ",""),n.byId[--a]=n.byName[t(u)]=n.byCategory[t(r)]={id:t(u),instrument:u,number:a,category:r}}}return n}({Piano:["1 Acoustic Grand Piano","2 Bright Acoustic Piano","3 Electric Grand Piano","4 Honky-tonk Piano","5 Electric Piano 1","6 Electric Piano 2","7 Harpsichord","8 Clavinet"],"Chromatic Percussion":["9 Celesta","10 Glockenspiel","11 Music Box","12 Vibraphone","13 Marimba","14 Xylophone","15 Tubular Bells","16 Dulcimer"],Organ:["17 Drawbar Organ","18 Percussive Organ","19 Rock Organ","20 Church Organ","21 Reed Organ","22 Accordion","23 Harmonica","24 Tango Accordion"],Guitar:["25 Acoustic Guitar (nylon)","26 Acoustic Guitar (steel)","27 Electric Guitar (jazz)","28 Electric Guitar (clean)","29 Electric Guitar (muted)","30 Overdriven Guitar","31 Distortion Guitar","32 Guitar Harmonics"],Bass:["33 Acoustic Bass","34 Electric Bass (finger)","35 Electric Bass (pick)","36 Fretless Bass","37 Slap Bass 1","38 Slap Bass 2","39 Synth Bass 1","40 Synth Bass 2"],Strings:["41 Violin","42 Viola","43 Cello","44 Contrabass","45 Tremolo Strings","46 Pizzicato Strings","47 Orchestral Harp","48 Timpani"],Ensemble:["49 String Ensemble 1","50 String Ensemble 2","51 Synth Strings 1","52 Synth Strings 2","53 Choir Aahs","54 Voice Oohs","55 Synth Choir","56 Orchestra Hit"],Brass:["57 Trumpet","58 Trombone","59 Tuba","60 Muted Trumpet","61 French Horn","62 Brass Section","63 Synth Brass 1","64 Synth Brass 2"],Reed:["65 Soprano Sax","66 Alto Sax","67 Tenor Sax","68 Baritone Sax","69 Oboe","70 English Horn","71 Bassoon","72 Clarinet"],Pipe:["73 Piccolo","74 Flute","75 Recorder","76 Pan Flute","77 Blown Bottle","78 Shakuhachi","79 Whistle","80 Ocarina"],"Synth Lead":["81 Lead 1 (square)","82 Lead 2 (sawtooth)","83 Lead 3 (calliope)","84 Lead 4 (chiff)","85 Lead 5 (charang)","86 Lead 6 (voice)","87 Lead 7 (fifths)","88 Lead 8 (bass + lead)"],"Synth Pad":["89 Pad 1 (new age)","90 Pad 2 (warm)","91 Pad 3 (polysynth)","92 Pad 4 (choir)","93 Pad 5 (bowed)","94 Pad 6 (metallic)","95 Pad 7 (halo)","96 Pad 8 (sweep)"],"Synth Effects":["97 FX 1 (rain)","98 FX 2 (soundtrack)","99 FX 3 (crystal)","100 FX 4 (atmosphere)","101 FX 5 (brightness)","102 FX 6 (goblins)","103 FX 7 (echoes)","104 FX 8 (sci-fi)"],Ethnic:["105 Sitar","106 Banjo","107 Shamisen","108 Koto","109 Kalimba","110 Bagpipe","111 Fiddle","112 Shanai"],Percussive:["113 Tinkle Bell","114 Agogo","115 Steel Drums","116 Woodblock","117 Taiko Drum","118 Melodic Tom","119 Synth Drum"],"Sound effects":["120 Reverse Cymbal","121 Guitar Fret Noise","122 Breath Noise","123 Seashore","124 Bird Tweet","125 Telephone Ring","126 Helicopter","127 Applause","128 Gunshot"]}),MIDI.channels=function(){var e={};for(var t=0;t<16;t++)e[t]={instrument:0,mute:!1,mono:!1,omni:!1,solo:!1};return e}(),MIDI.pianoKeyOffset=21,MIDI.keyToNote={},MIDI.noteToKey={},function(){var e=21,t=108,n=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"];for(var r=e;r<=t;r++){var i=(r-12)/12>>0,s=n[r%12]+i;MIDI.keyToNote[s]=r,MIDI.noteToKey[r]=s}}()})();if(typeof MIDI=="undefined")var MIDI={};typeof MIDI.Player=="undefined"&&(MIDI.Player={}),function(){"use strict";var e=MIDI.Player;e.callback=undefined,e.currentTime=0,e.endTime=0,e.restart=0,e.playing=!1,e.timeWarp=1,e.start=e.resume=function(){e.currentTime<-1&&(e.currentTime=-1),f(e.currentTime)},e.pause=function(){var t=e.restart;l(),e.restart=t},e.stop=function(){l(),e.restart=0,e.currentTime=0},e.addListener=function(e){s=e},e.removeListener=function(){s=undefined},e.clearAnimation=function(){e.interval&&window.clearInterval(e.interval)},e.setAnimation=function(t){var n=typeof t=="function"?t:t.callback,r=t.interval||30,s=0,o=0,u=0;e.clearAnimation(),e.interval=window.setInterval(function(){if(e.endTime===0)return;e.playing?(s=u===e.currentTime?o-(new Date).getTime():0,e.currentTime===0?s=0:s=e.currentTime-s,u!==e.currentTime&&(o=(new Date).getTime(),u=e.currentTime)):s=e.currentTime;var t=e.endTime,r=s/t,a=s/1e3,f=a/60,l=a-f*60,c=f*60+l,h=t/1e3;if(h-c<-1)return;n({now:c,end:h,events:i})},r)},e.loadMidiFile=function(){e.replayer=new Replayer(MidiFile(e.currentData),e.timeWarp),e.data=e.replayer.getData(),e.endTime=a()},e.loadFile=function(t,n){e.stop();if(t.indexOf("base64,")!==-1){var r=window.atob(t.split(",")[1]);e.currentData=r,e.loadMidiFile(),n&&n(r);return}var i=t.split(" - ")[1]||t;document.getElementById("playback-title").innerHTML=i.replace(".mid","");var s=new XMLHttpRequest;s.open("GET",t),s.overrideMimeType("text/plain; charset=x-user-defined"),s.onreadystatechange=function(){if(this.readyState===4&&this.status===200){var t=this.responseText||"",r=[],i=t.length,s=String.fromCharCode;for(var o=0;o<i;o++)r[o]=s(t.charCodeAt(o)&255);var u=r.join("");e.currentData=u,e.loadMidiFile(),n&&n(u)}},s.send()};var t=[],n,r=0,i={},s=undefined,o=function(t,r,o,u,a,l){var c=window.setTimeout(function(){var u={channel:t,note:r,now:o,end:e.endTime,message:a,velocity:l};a===128?delete i[r]:i[r]=u,s&&s(u),e.currentTime=o,e.currentTime===n&&n<e.endTime&&f(n,!0)},o-u);return c},u=function(){return MIDI.lang==="WebAudioAPI"?MIDI.Player.ctx:(e.ctx||(e.ctx={currentTime:0}),e.ctx)},a=function(){var t=e.data,n=t.length,r=.5;for(var i=0;i<n;i++)r+=t[i][1];return r},f=function(i,s){if(!e.replayer)return;s||(typeof i=="undefined"&&(i=e.restart),e.playing&&l(),e.playing=!0,e.data=e.replayer.getData(),e.endTime=a());var f,c=0,h=0,p=e.data,d=u(),v=p.length;n=.5,r=d.currentTime;for(var m=0;m<v&&h<100;m++){n+=p[m][1];if(n<i){c=n;continue}i=n-c;var g=p[m][0].event;if(g.type!=="channel")continue;var y=g.channel;switch(g.subtype){case"noteOn":if(MIDI.channels[y].mute)break;f=g.noteNumber-(e.MIDIOffset||0),t.push({event:g,source:MIDI.noteOn(y,g.noteNumber,g.velocity,i/1e3+d.currentTime),interval:o(y,f,n,c,144,g.velocity)}),h++;break;case"noteOff":if(MIDI.channels[y].mute)break;f=g.noteNumber-(e.MIDIOffset||0),t.push({event:g,source:MIDI.noteOff(y,g.noteNumber,i/1e3+d.currentTime),interval:o(y,f,n,c,128)});break;default:}}},l=function(){var n=u();e.playing=!1,e.restart+=(n.currentTime-r)*1e3;while(t.length){var o=t.pop();window.clearInterval(o.interval);if(!o.source)continue;if(typeof o.source=="number")window.clearTimeout(o.source);else{var a=o.source;a.disconnect(0),a.noteOff(0)}}for(var f in i){var o=i[f];i[f].message===144&&s&&s({channel:o.channel,note:o.note,now:o.now,end:o.end,message:128,velocity:o.velocity})}i={}}}();if(typeof DOMLoader=="undefined")var DOMLoader={};if(typeof XMLHttpRequest=="undefined"){var XMLHttpRequest;(function(){var e=[function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}];for(var t=0;t<e.length;t++){try{e[t]()}catch(n){continue}break}XMLHttpRequest=e[t]})()}if(typeof (new XMLHttpRequest).responseText=="undefined"){var IEBinaryToArray_ByteStr_Script="<!-- IEBinaryToArray_ByteStr -->\r\n<script type='text/vbscript'>\r\nFunction IEBinaryToArray_ByteStr(Binary)\r\n IEBinaryToArray_ByteStr = CStr(Binary)\r\nEnd Function\r\nFunction IEBinaryToArray_ByteStr_Last(Binary)\r\n Dim lastIndex\r\n lastIndex = LenB(Binary)\r\n if lastIndex mod 2 Then\r\n IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n Else\r\n IEBinaryToArray_ByteStr_Last = \"\"\r\n End If\r\nEnd Function\r\n</script>\r\n";document.write(IEBinaryToArray_ByteStr_Script),DOMLoader.sendRequest=function(e){function t(e){var t={};for(var n=0;n<256;n++)for(var r=0;r<256;r++)t[String.fromCharCode(n+r*256)]=String.fromCharCode(n)+String.fromCharCode(r);var i=IEBinaryToArray_ByteStr(e),s=IEBinaryToArray_ByteStr_Last(e);return i.replace(/[\s\S]/g,function(e){return t[e]})+s}var n=XMLHttpRequest();return n.open("GET",e.url,!0),e.responseType&&(n.responseType=e.responseType),e.onerror&&(n.onerror=e.onerror),e.onprogress&&(n.onprogress=e.onprogress),n.onreadystatechange=function(r){n.readyState===4&&(n.status===200?n.responseText=t(n.responseBody):n=!1,e.onload&&e.onload(n))},n.setRequestHeader("Accept-Charset","x-user-defined"),n.send(null),n}}else DOMLoader.sendRequest=function(e){var t=new XMLHttpRequest;return t.open(e.data?"POST":"GET",e.url,!0),t.overrideMimeType&&t.overrideMimeType("text/plain; charset=x-user-defined"),e.data&&t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.responseType&&(t.responseType=e.responseType),e.onerror&&(t.onerror=e.onerror),e.onprogress&&(t.onprogress=e.onprogress),t.onreadystatechange=function(n){if(t.readyState===4){if(t.status!==200&&t.status!=304){e.onerror&&e.onerror(n,!1);return}e.onload&&e.onload(t)}},t.send(e.data),t};if(typeof DOMLoader=="undefined")var DOMLoader={};(function(){"use strict";DOMLoader.script=function(){return this.loaded={},this.loading={},this},DOMLoader.script.prototype.add=function(e){var t=this;typeof e=="string"&&(e={src:e});var n=e.srcs;typeof n=="undefined"&&(n=[{src:e.src,verify:e.verify}]);var r=document.getElementsByTagName("head")[0],i=function(e,n){if(t.loaded[e.src])return;if(n&&typeof window[n]=="undefined")return;t.loaded[e.src]=!0,t.loading[e.src]&&t.loading[e.src](),delete t.loading[e.src],e.callback&&e.callback(),typeof f!="undefined"&&f()},s=[],o=function(n){typeof n=="string"&&(n={src:n,verify:e.verify});if(/([\w\d.])$/.test(n.verify)){n.test=n.verify;if(typeof n.test=="object")for(var o in n.test)s.push(n.test[o]);else s.push(n.test)}if(t.loaded[n.src])return;var u=document.createElement("script");u.onreadystatechange=function(){if(this.readyState!=="loaded"&&this.readyState!=="complete")return;i(n)},u.onload=function(){i(n)},u.onerror=function(){},u.setAttribute("type","text/javascript"),u.setAttribute("src",n.src),r.appendChild(u),t.loading[n.src]=function(){}},u=function(t){if(t)i(t,t.test);else for(var r=0;r<n.length;r++)i(n[r],n[r].test);var o=!0;for(var r=0;r<s.length;r++){var a=s[r];if(a&&a.indexOf(".")!==-1){a=a.split(".");var f=window[a[0]];if(typeof f=="undefined")continue;a.length===2?typeof f[a[1]]=="undefined"&&(o=!1):a.length===3&&typeof f[a[1]][a[2]]=="undefined"&&(o=!1)}else typeof window[a]=="undefined"&&(o=!1)}!e.strictOrder&&o?e.callback&&e.callback():setTimeout(function(){u(t)},10)};if(e.strictOrder){var a=-1,f=function(){a++;if(!n[a])e.callback&&e.callback();else{var r=n[a],i=r.src;t.loading[i]?t.loading[i]=function(){r.callback&&r.callback(),f()}:t.loaded[i]?f():(o(r),u(r))}};f()}else{for(var a=0;a<n.length;a++)o(n[a]);u()}},DOMLoader.script=new DOMLoader.script})(); |