!function(){var e="undefined"!=typeof exports?exports:this,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function n(e){this.message=e}n.prototype=new Error,n.prototype.name="InvalidCharacterError",e.btoa||(e.btoa=function(e){for(var r,i,a=0,s=t,o="";e.charAt(0|a)||(s="=",a%1);o+=s.charAt(63&r>>8-a%1*8)){if((i=e.charCodeAt(a+=3/4))>255)throw new n("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|i}return o}),e.atob||(e.atob=function(e){if((e=e.replace(/=+$/,"")).length%4==1)throw new n("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,i,a=0,s=0,o="";i=e.charAt(s++);~i&&(r=a%4?64*r+i:i,a++%4)?o+=String.fromCharCode(255&r>>(-2*a&6)):0)i=t.indexOf(i);return o})}();
/**
 * @license -------------------------------------------------------------------
 *   module: Base64Binary
 *      src: http://blog.danguer.com/2011/10/24/base64-binary-decoding-in-javascript/
 *  license: Simplified BSD License
 * -------------------------------------------------------------------
 * Copyright 2011, Daniel Guerrero. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     - Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     - Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL DANIEL GUERRERO BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var Base64Binary={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",decodeArrayBuffer:function(e){var t=Math.ceil(3*e.length/4),n=new ArrayBuffer(t);return this.decode(e,n),n},decode:function(e,t){var n,r,i,a,s,o,c,u=this._keyStr.indexOf(e.charAt(e.length-1)),d=this._keyStr.indexOf(e.charAt(e.length-1)),h=Math.ceil(3*e.length/4);64==u&&h--,64==d&&h--;var f=0,p=0;for(n=t?new Uint8Array(t):new Uint8Array(h),e=e.replace(/[^A-Za-z0-9\+\/\=]/g,""),f=0;f<h;f+=3)r=this._keyStr.indexOf(e.charAt(p++))<<2|(s=this._keyStr.indexOf(e.charAt(p++)))>>4,i=(15&s)<<4|(o=this._keyStr.indexOf(e.charAt(p++)))>>2,a=(3&o)<<6|(c=this._keyStr.indexOf(e.charAt(p++))),n[f]=r,64!=o&&(n[f+1]=i),64!=c&&(n[f+2]=a);return n}};
/**
 * @license -------------------------------------------------------------------
 *   module: WebAudioShim - Fix naming issues for WebAudioAPI supports
 *      src: https://github.com/Dinahmoe/webaudioshim
 *   author: Dinahmoe AB
 * -------------------------------------------------------------------
 * Copyright (c) 2012 DinahMoe AB
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */window.AudioContext=window.AudioContext||window.webkitAudioContext||null,window.OfflineAudioContext=window.OfflineAudioContext||window.webkitOfflineAudioContext||null,function(e){var t,n,r,i=function(e){return"[object Function]"===Object.prototype.toString.call(e)||"[object AudioContextConstructor]"===Object.prototype.toString.call(e)};i(e)&&(n=new e).destination&&n.sampleRate&&(t=e.prototype,r=Object.getPrototypeOf(n.createBufferSource()),i(r.start)||i(r.noteOn)&&(r.start=function(e,t,n){switch(arguments.length){case 0:throw new Error("Not enough arguments.");case 1:this.noteOn(e);break;case 2:if(!this.buffer)throw new Error("Missing AudioBuffer");this.noteGrainOn(e,t,this.buffer.duration-t);break;case 3:this.noteGrainOn(e,t,n)}}),i(r.noteOn)||(r.noteOn=r.start),i(r.noteGrainOn)||(r.noteGrainOn=r.start),i(r.stop)||(r.stop=r.noteOff),i(r.noteOff)||(r.noteOff=r.stop),[["createGainNode","createGain"],["createDelayNode","createDelay"],["createJavaScriptNode","createScriptProcessor"]].forEach((function(e){for(var t,n;e.length;)t=e.pop(),i(this[t])?this[e.pop()]=this[t]:(n=e.pop(),this[t]=this[n])}),t))}(window.AudioContext),function(e){"use strict";var t,n,r,i,a,s;function o(){}function c(){this.inputInUse=!1,this.outputInUse=!1;var e=document.createElement("object");e.id="_Jazz"+Math.random()+"ie",e.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90",this.activeX=e;var t=document.createElement("object");t.id="_Jazz"+Math.random(),t.type="audio/x-jazz",e.appendChild(t),this.objRef=t;var n=document.createElement("p");n.appendChild(document.createTextNode("This page requires the "));var r,i=document.createElement("a");(i.appendChild(document.createTextNode("Jazz plugin")),i.href="http://jazz-soft.net/",n.appendChild(i),n.appendChild(document.createTextNode(".")),t.appendChild(n),r=document.getElementById("MIDIPlugin"))||((r=document.createElement("div")).id="MIDIPlugin",r.style.position="absolute",r.style.visibility="hidden",r.style.left="-9999px",r.style.top="-9999px",document.body.appendChild(r));r.appendChild(e),this.objRef.isJazz?this._Jazz=this.objRef:this.activeX.isJazz?this._Jazz=this.activeX:this._Jazz=null,this._Jazz&&(this._Jazz._jazzTimeZero=this._Jazz.Time(),this._Jazz._perfTimeZero=window.performance.now())}function u(){this._promise&&this._promise.fail({code:1})}function d(){this.jazz.MidiOutLong(this.data)}o.prototype.then=function(e,t){this.accept=e,this.reject=t},o.prototype.succeed=function(e){this.accept&&this.accept(e)},o.prototype.fail=function(e){this.reject&&this.reject(e)},t=function(){return(new n)._promise},n=function(){this._jazzInstances=new Array,this._jazzInstances.push(new c),this._promise=new o,this._jazzInstances[0]._Jazz?(this._Jazz=this._jazzInstances[0]._Jazz,window.setTimeout(r.bind(this),3)):window.setTimeout(u.bind(this),3)},r=function(){this._promise&&this._promise.succeed(this)},n.prototype.inputs=function(){if(!this._Jazz)return null;for(var e=this._Jazz.MidiInList(),t=new Array(e.length),n=0;n<e.length;n++)t[n]=new i(this,e[n],n);return t},n.prototype.outputs=function(){if(!this._Jazz)return null;for(var e=this._Jazz.MidiOutList(),t=new Array(e.length),n=0;n<e.length;n++)t[n]=new a(this,e[n],n);return t},(i=function(e,t,n){this._listeners=[],this._midiAccess=e,this._index=n,this._inLongSysexMessage=!1,this._sysexBuffer=new Uint8Array,this.id=n+"."+t,this.manufacturer="",this.name=t,this.type="input",this.version="",this.onmidimessage=null;for(var r=null,i=0;i<e._jazzInstances.length&&!r;i++)e._jazzInstances[i].inputInUse||(r=e._jazzInstances[i]);r||(r=new c,e._jazzInstances.push(r)),r.inputInUse=!0,this._jazzInstance=r._Jazz,this._input=this._jazzInstance.MidiInOpen(this._index,s.bind(this))}).prototype.addEventListener=function(e,t,n){if("midimessage"===e){for(var r=0;r<this._listeners.length;r++)if(this._listeners[r]==t)return;this._listeners.push(t)}},i.prototype.removeEventListener=function(e,t,n){if("midimessage"===e)for(var r=0;r<this._listeners.length;r++)if(this._listeners[r]==t)return void this._listeners.splice(r,1)},i.prototype.preventDefault=function(){this._pvtDef=!0},i.prototype.dispatchEvent=function(e){this._pvtDef=!1;for(var t=0;t<this._listeners.length;t++)this._listeners[t].handleEvent?this._listeners[t].handleEvent.bind(this)(e):this._listeners[t].bind(this)(e);return this.onmidimessage&&this.onmidimessage(e),this._pvtDef},i.prototype.appendToSysexBuffer=function(e){var t=this._sysexBuffer.length,n=new Uint8Array(t+e.length);n.set(this._sysexBuffer),n.set(e,t),this._sysexBuffer=n},i.prototype.bufferLongSysex=function(e,t){for(var n=t;n<e.length;){if(247==e[n])return n++,this.appendToSysexBuffer(e.slice(t,n)),n;n++}return this.appendToSysexBuffer(e.slice(t,n)),this._inLongSysexMessage=!0,n},s=function(e,t){var n,r=0,i=!1;for(n=0;n<t.length;n+=r){if(this._inLongSysexMessage){if(247!=t[(n=this.bufferLongSysex(t,n))-1])return;i=!0}else switch(i=!1,240&t[n]){case 128:case 144:case 160:case 176:case 224:r=3;break;case 192:case 208:r=2;break;case 240:switch(t[n]){case 240:if(247!=t[(n=this.bufferLongSysex(t,n))-1])return;i=!0;break;case 241:case 243:r=2;break;case 242:r=3;break;default:r=1;break}break}var a=document.createEvent("Event");a.initEvent("midimessage",!1,!1),a.receivedTime=parseFloat(e.toString())+this._jazzInstance._perfTimeZero,i||this._inLongSysexMessage?(a.data=new Uint8Array(this._sysexBuffer),this._sysexBuffer=new Uint8Array(0),this._inLongSysexMessage=!1):a.data=new Uint8Array(t.slice(n,r+n)),this.dispatchEvent(a)}},(a=function(e,t,n){this._listeners=[],this._midiAccess=e,this._index=n,this.id=n+"."+t,this.manufacturer="",this.name=t,this.type="output",this.version="";for(var r=null,i=0;i<e._jazzInstances.length&&!r;i++)e._jazzInstances[i].outputInUse||(r=e._jazzInstances[i]);r||(r=new c,e._jazzInstances.push(r)),r.outputInUse=!0,this._jazzInstance=r._Jazz,this._jazzInstance.MidiOutOpen(this.name)}).prototype.send=function(e,t){var n=0;if(0===e.length)return!1;if(t&&(n=Math.floor(t-window.performance.now())),t&&n>1){var r=new Object;r.jazz=this._jazzInstance,r.data=e,window.setTimeout(d.bind(r),n)}else this._jazzInstance.MidiOutLong(e);return!0},window.navigator.requestMIDIAccess||(window.navigator.requestMIDIAccess=t)}(window),function(e){var t,n={};"performance"in e&&"now"in e.performance||("performance"in e||Object.defineProperty(e,"performance",{get:function(){return n}}),t=function(){for(var t,n=["moz","webkit","o","ms"],r=n.length,i={value:(t=Date.now(),function(){return Date.now()-t})};r>=0;r--)if(n[r]+"Now"in e.performance)return i.value=function(t){return function(){e.performance[t]()}}(n[r]+"Now"),i;return"timing"in e.performance&&"connectStart"in e.performance.timing&&(i.value=(e.performance.timing.connectStart,function(){Date.now()})),i}(),Object.defineProperty(e.performance,"now",t))}(window);var clone=function(e){if("object"!=typeof e)return e;if(null==e)return e;var t="number"==typeof e.length?[]:{};for(var n in e)t[n]=clone(e[n]);return t};function Replayer(e,t,n,r){for(var i=[],a=r||120,s=!!r,o=e.header.ticksPerBeat,c=0;c<e.tracks.length;c++)i[c]={nextEventIndex:0,ticksToNextEvent:e.tracks[c].length?e.tracks[c][0].deltaTime:null};var u;function d(){for(var t=null,n=null,r=null,a=0;a<i.length;a++)null!=i[a].ticksToNextEvent&&(null==t||i[a].ticksToNextEvent<t)&&(t=i[a].ticksToNextEvent,n=a,r=i[a].nextEventIndex);if(null!=n){var s=e.tracks[n][r];e.tracks[n][r+1]?i[n].ticksToNextEvent+=e.tracks[n][r+1].deltaTime:i[n].ticksToNextEvent=null,i[n].nextEventIndex+=1;for(a=0;a<i.length;a++)null!=i[a].ticksToNextEvent&&(i[a].ticksToNextEvent-=t);return{ticksToEvent:t,event:s,track:n}}return null}var h=[];return function(){function e(){s||"meta"!=u.event.type||"setTempo"!=u.event.subtype||(a=6e7/u.event.microsecondsPerBeat);var e=0;u.ticksToEvent>0&&(e=u.ticksToEvent/o/(a/60));var n=1e3*e*t||0;h.push([u,n]),u=d()}if(u=d())for(;u;)e()}(),{getData:function(){return clone(h)}}}function MidiFile(e){function t(e){var t=e.read(4),n=e.readInt32();return{id:t,length:n,data:e.read(n)}}var n;function r(e){var t={};t.deltaTime=e.readVarInt();var r,i=e.readInt8();if(240==(240&i)){if(255==i){t.type="meta";var a=e.readInt8(),s=e.readVarInt();switch(a){case 0:if(t.subtype="sequenceNumber",2!=s)throw"Expected length for sequenceNumber event is 2, got "+s;return t.number=e.readInt16(),t;case 1:return t.subtype="text",t.text=e.read(s),t;case 2:return t.subtype="copyrightNotice",t.text=e.read(s),t;case 3:return t.subtype="trackName",t.text=e.read(s),t;case 4:return t.subtype="instrumentName",t.text=e.read(s),t;case 5:return t.subtype="lyrics",t.text=e.read(s),t;case 6:return t.subtype="marker",t.text=e.read(s),t;case 7:return t.subtype="cuePoint",t.text=e.read(s),t;case 32:if(t.subtype="midiChannelPrefix",1!=s)throw"Expected length for midiChannelPrefix event is 1, got "+s;return t.channel=e.readInt8(),t;case 47:if(t.subtype="endOfTrack",0!=s)throw"Expected length for endOfTrack event is 0, got "+s;return t;case 81:if(t.subtype="setTempo",3!=s)throw"Expected length for setTempo event is 3, got "+s;return t.microsecondsPerBeat=(e.readInt8()<<16)+(e.readInt8()<<8)+e.readInt8(),t;case 84:if(t.subtype="smpteOffset",5!=s)throw"Expected length for smpteOffset event is 5, got "+s;var o=e.readInt8();return t.frameRate={0:24,32:25,64:29,96:30}[96&o],t.hour=31&o,t.min=e.readInt8(),t.sec=e.readInt8(),t.frame=e.readInt8(),t.subframe=e.readInt8(),t;case 88:if(t.subtype="timeSignature",4!=s)throw"Expected length for timeSignature event is 4, got "+s;return t.numerator=e.readInt8(),t.denominator=Math.pow(2,e.readInt8()),t.metronome=e.readInt8(),t.thirtyseconds=e.readInt8(),t;case 89:if(t.subtype="keySignature",2!=s)throw"Expected length for keySignature event is 2, got "+s;return t.key=e.readInt8(!0),t.scale=e.readInt8(),t;case 127:return t.subtype="sequencerSpecific",t.data=e.read(s),t;default:return t.subtype="unknown",t.data=e.read(s),t}return t.data=e.read(s),t}if(240==i){t.type="sysEx";s=e.readVarInt();return t.data=e.read(s),t}if(247==i){t.type="dividedSysEx";s=e.readVarInt();return t.data=e.read(s),t}throw"Unrecognised MIDI event type byte: "+i}0==(128&i)?(r=i,i=n):(r=e.readInt8(),n=i);var c=i>>4;switch(t.channel=15&i,t.type="channel",c){case 8:return t.subtype="noteOff",t.noteNumber=r,t.velocity=e.readInt8(),t;case 9:return t.noteNumber=r,t.velocity=e.readInt8(),0==t.velocity?t.subtype="noteOff":t.subtype="noteOn",t;case 10:return t.subtype="noteAftertouch",t.noteNumber=r,t.amount=e.readInt8(),t;case 11:return t.subtype="controller",t.controllerType=r,t.value=e.readInt8(),t;case 12:return t.subtype="programChange",t.programNumber=r,t;case 13:return t.subtype="channelAftertouch",t.amount=r,t;case 14:return t.subtype="pitchBend",t.value=r+(e.readInt8()<<7),t;default:throw"Unrecognised MIDI event type: "+c}}stream=Stream(e);var i=t(stream);if("MThd"!=i.id||6!=i.length)throw"Bad .mid file - header not found";var a=Stream(i.data),s=a.readInt16(),o=a.readInt16(),c=a.readInt16();if(32768&c)throw"Expressing time division in SMTPE frames is not supported yet";ticksPerBeat=c;for(var u={formatType:s,trackCount:o,ticksPerBeat:ticksPerBeat},d=[],h=0;h<u.trackCount;h++){d[h]=[];var f=t(stream);if("MTrk"!=f.id)throw"Unexpected chunk - expected MTrk, got "+f.id;for(var p=Stream(f.data);!p.eof();){var l=r(p);d[h].push(l)}}return{header:u,tracks:d}}function Stream(e){var t=0;function n(n){var r=e.charCodeAt(t);return n&&r>127&&(r-=256),t+=1,r}return{eof:function(){return t>=e.length},read:function(n){var r=e.substr(t,n);return t+=n,r},readInt32:function(){var n=(e.charCodeAt(t)<<24)+(e.charCodeAt(t+1)<<16)+(e.charCodeAt(t+2)<<8)+e.charCodeAt(t+3);return t+=4,n},readInt16:function(){var n=(e.charCodeAt(t)<<8)+e.charCodeAt(t+1);return t+=2,n},readInt8:n,readVarInt:function(){for(var e=0;;){var t=n();if(!(128&t))return e+t;e+=127&t,e<<=7}}}}