!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.musicaljs=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0&&a.velocity>0){for(b=q.createGain(),b.gain.setValueAtTime(0,h),b.gain.linearRampToValueAtTime(p,j);j+1/32>l&&i>l+1/256;)l+=1/256,b.gain.linearRampToValueAtTime(p*(g.sustain+(1-g.sustain)*Math.exp((j-l)/k)),l);b.gain.setTargetAtTime(p*g.sustain,l,k),b.gain.setValueAtTime(p*(g.sustain+(1-g.sustain)*Math.exp((j-i)/k)),i),b.gain.linearRampToValueAtTime(0,n),b.connect(this._out),!g.cutoff&&!g.cutfollow||g.cutoff==1/0?c=b:(c=q.createBiquadFilter(),c.frequency.value=g.cutoff+a.frequency*g.cutfollow,c.Q.value=g.resonance,c.connect(b)),e=m(this._atop,g.wave,a.frequency),e.connect(c),e.start(h),e.stop(n),o&&(f=m(this._atop,g.wave,a.frequency*g.detune),f.connect(c),f.start(h),f.stop(n)),a.gainNode=b,a.oscillators=[e],o&&a.oscillators.push(f),a.cleanuptime=n}else a.duration=0;this._startSet.push(a)},d.prototype._truncateSound=function(a,b){if(b=g?n.gain.setValueAtTime(0,g):h>=g?n.gain.linearRampToValueAtTime(m*(g-f)/(h-f)):n.gain.setValueAtTime(m*(e.sustain+(1-e.sustain)*Math.exp((h-g)/i)),g),n.gain.linearRampToValueAtTime(0,j),a.oscillators)for(c=0;cd.bufferSecs);++a);if(a>0){for(b=this._queue.splice(0,a),a=0;a0?this._queue[0].time:1/0}}for(a=0;a=c&&(k.push({order:[c,0],f:this._trigger,t:this,a:["noteoff",f]}),f.cleanuptime!=1/0&&this._cleanupSet.push(f),delete this._finishSet[e]);for(a=0;a=c&&(k.push({order:[c,1],f:i.callback,t:null,a:[]}),this._callbackSet.splice(a,1),a-=1);for(a=0;a0&&f.velocity>0&&g!==f&&(this._finishSet[e]=f,k.push({order:[f.time,2],f:this._trigger,t:this,a:["noteon",f]})));for(this._startPollTimer(),k.sort(function(a,b){return a.order[0]!=b.order[0]?a.order[0]-b.order[0]:a.order[1]-b.order[1]}),a=0;a0&&(g=Math.min(g,this._cleanupSet[0].cleanuptime+1)),g=Math.min(g,this._minQueueTime-d.dequeueTime),c=Math.max(.001,g-this._atop.ac.currentTime),isNaN(c)||c==1/0||(this._pollTimer=setTimeout(f,Math.round(1e3*c)))}},d.prototype.tone=function(a,b,c,e,f,g){if(this._atop){"object"==typeof a&&(null==c&&(c=a.velocity),null==b&&(b=a.duration),null==e&&(e=a.delay),null==f&&(f=a.timbre),null==g&&(g=a.origin),a=a.pitch);var h,l;if(a||(a="C"),isNaN(a)?(h=j(a),l=k(h)):(l=Number(a),0>l?(h=-l,l=k(h)):h=frequencyToMidi(l)),f||(f=this._timbre),f!==this._timbre){var m,n=f;f={};for(m in i)m in n?f[m]=n[m]:f[m]=defaulTimbre[m]}var o=(this._atop.ac,this.now()),p=o+(e||0),q={time:p,on:!1,frequency:l,midi:h,velocity:null==c?1:c,duration:null==b?d.toneLength:b,timbre:f,instrument:this,gainNode:null,oscillators:null,cleanuptime:1/0,origin:g};p=1/8&&(r-=1/32),s=(p.velocity||1)*i*v.volume,this.tone(p.pitch,r,s,h,e,p));h+=n.time*q}w=Math.max(h,w)}}this._maxScheduledTime=Math.max(this._maxScheduledTime,this.now()+w),u&&this.schedule(w,u)},d.pitchToMidi=function(a){return"string"==typeof a?j(a):a},d.midiToPitch=function(a){return"number"==typeof a?n(a):a},b.exports=d},{"./parser-abc":3,"./utils":4}],3:[function(a,b,c){var d=a("./utils"),e=d.pitchToFrequency,f=/^([A-Za-z]):\s*(.*)$/,g=/(?:\[[A-Za-z]:[^\]]*\])|\s+|%[^\n]*|![^\s!:|\[\]]*!|\+[^+|!]*\+|[_<>@^]?"[^"]*"|\[|\]|>+|<+|(?:(?:\^+|_+|=|)[A-Ga-g](?:,+|'+|))|\(\d+(?::\d+){0,2}|\d*\/\d+|\d+\/?|\/+|[xzXZ]|\[?\|\]?|:?\|:?|::|./g;b.exports=function(a){function b(a,b){switch(a){case"V":D!==C&&c(b.split(" ")[0]);break;case"M":i(b,D);break;case"L":j(b,D);break;case"Q":k(b,D)}D.hasOwnProperty(a)?D[a]+="\n"+b:D[a]=b,"K"==a&&(E=n(b),D===C&&c(d()))}function c(a){a=a||"",(a||D===C)&&(C.voice||(C.voice={}),C.voice.hasOwnProperty(a)?(D=C.voice[a],F=D.accent):(D={id:a,accent:{slurred:0}},C.voice[a]=D,F=D.accent))}function d(){return C.V?C.V.split(/\s+/)[0]:""}function h(a){var e,f=a.match(g),h=null,i=0,j=0,k=null;if(!f)return null;for(;i/.test(f[i]))j=f[i++].length;else if(/^\(\d+(?::\d+)*/.test(f[i]))k=r(f[i++]);else if(/^[!+].*[!+]$/.test(f[i]))s(f[i++],F);else if(/^.?".*"$/.test(f[i]))i++;else if(/^[()]$/.test(f[i]))"("==f[i++]?F.slurred+=1:(F.slurred-=1,F.slurred<=0&&(F.slurred=0,D.stems&&D.stems.length>=1&&p(D.stems[D.stems.length-1],!1)));else if(/\|/.test(f[i])){for(e in F)1==e.length&&delete F[e];i++}else h=t(f,i,E,F),null!==h?(k&&(q(h.stem,k.time),k.count-=1,k.count||(k=null)),j&&D.stems&&D.stems.length&&(e=j>0?(1-Math.pow(.5,j))*h.stem.time:(Math.pow(.5,-j)-1)*D.stems[D.stems.length-1].time,o(D.stems[D.stems.length-1],e),o(h.stem,-e)),j=0,F.slurred&&p(h.stem,!0),D===C&&c(d()),"stems"in D||(D.stems=[]),D.stems.push(h.stem),i=h.index):i++}function i(a,b){var c=/^C/.test(a)?1:w(a);c&&(b.unitnote||(.75>c?b.unitnote=1/16:b.unitnote=1/8))}function j(a,b){var c=w(a);c&&(b.unitnote=c)}function k(a,b){var c,d=a.split(/\s+|=/),e=null,f=null;for(c=0;c=0||/^[1-4]$/.test(d[c])?e=e||w(d[c]):f=f||Number(d[c]);e&&(b.unitbeat=e),f&&(b.tempo=f)}function l(a){var b,c,d,e,f,g={};for(c=0;c0)for(b=0;a>b&&7>b;++b)d[c.charAt(b)]="^";else for(b=0;b>a&&b>-7;--b)d[c.charAt(6+b)]="_";return d}function n(a){if(!a)return{};var b,c={"c#":7,"f#":6,b:5,e:4,a:3,d:2,g:1,c:0,f:-1,bb:-2,eb:-3,ab:-4,db:-5,gb:-6,cb:-7,"a#m":7,"d#m":6,"g#m":5,"c#m":4,"f#m":3,bm:2,em:1,am:0,dm:-1,gm:-2,cm:-3,fm:-4,bbm:-5,ebm:-6,abm:-7,"g#mix":7,"c#mix":6,"f#mix":5,bmix:4,emix:3,amix:2,dmix:1,gmix:0,cmix:-1,fmix:-2,bbmix:-3,ebmix:-4,abmix:-5,dbmix:-6,gbmix:-7,"d#dor":7,"g#dor":6,"c#dor":5,"f#dor":4,bdor:3,edor:2,ador:1,ddor:0,gdor:-1,cdor:-2,fdor:-3,bbdor:-4,ebdor:-5,abdor:-6,dbdor:-7,"e#phr":7,"a#phr":6,"d#phr":5,"g#phr":4,"c#phr":3,"f#phr":2,bphr:1,ephr:0,aphr:-1,dphr:-2,gphr:-3,cphr:-4,fphr:-5,bbphr:-6,ebphr:-7,"f#lyd":7,blyd:6,elyd:5,alyd:4,dlyd:3,glyd:2,clyd:1,flyd:0,bblyd:-1,eblyd:-2,ablyd:-3,dblyd:-4,gblyd:-5,cblyd:-6,fblyd:-7,"b#loc":7,"e#loc":6,"a#loc":5,"d#loc":4,"g#loc":3,"c#loc":2,"f#loc":1,bloc:0,eloc:-1,aloc:-2,dloc:-3,gloc:-4,cloc:-5,floc:-6,bbloc:-7},d=a.replace(/\s+/g,"").toLowerCase().substr(0,5),e=d.match(/maj|min|mix|dor|phr|lyd|loc|m/);b=e?"maj"==e?d.substr(0,e.index):"min"==e?d.substr(0,e.index+1):d.substr(0,e.index+e[0].length):/^[a-g][#b]?/.exec(d)||"";var f=m(c[b]),g=a.substr(b.length).match(/(_+|=|\^+)[a-g]/gi);if(g)for(var h=0;hg&&(k=f,n=g),b0&&"="==a.charAt(0)?a.substr(1):a}function v(a,b,c){var d,e=/^(\^+|_+|=|)([A-Ga-g])(.*)$/.exec(a);return e?(d=e[2].toUpperCase(),e[1].length>0?(c[d]=e[1],u(a)):u(c.hasOwnProperty(d)?c[d]+e[2]+e[3]:b.hasOwnProperty(d)?b[d]+e[2]+e[3]:a)):a}function w(a){var b,c,d,e=/^(\d*)(?:\/(\d*))?$|^(\/+)$/.exec(a),f=0;if(e){if(e[3])return Math.pow(.5,e[3].length);if(c=e[2]?parseFloat(e[2]):/\//.test(a)?2:1,d=0,b=e[1]?parseFloat(e[1]):1,e[2])for(;d+1c;)d+=1,f=parseFloat(e[1].substring(0,d)),b=parseFloat(e[1].substring(d));return f+b/c}}var x,y,z,A,B=a.split("\n"),C={},D=C,E={},F={slurred:0};for(x=0;xe;e++)d[e]=2*Math.random()-1;return c}var f=a("./wavetable-builder");b.exports.isAudioPresent=isAudioPresent=function(){return!(!c.AudioContext&&!c.webkitAudioContext)},b.exports.getAudioTop=getAudioTop=function(){if(getAudioTop.audioTop)return getAudioTop.audioTop;if(!isAudioPresent())return null;var a=new(c.AudioContext||c.webkitAudioContext);return getAudioTop.audioTop={ac:a,wavetable:f(a),out:null,currentStart:null},d(),getAudioTop.audioTop},b.exports.audioCurrentStartTime=audioCurrentStartTime=function(){var a=getAudioTop();return null!=a.currentStart?a.currentStart:(a.currentStart=Math.max(.25,a.ac.currentTime),setTimeout(function(){a.currentStart=null},0),a.currentStart)},b.exports.midiToFrequency=midiToFrequency=function(a){return 440*Math.pow(2,(a-69)/12)};var g={C:0,D:2,E:4,F:5,G:7,A:9,B:11,c:12,d:14,e:16,f:17,g:19,a:21,b:23},h={"^":1,"":0,"=":0,_:-1},i=["C","^C","D","_E","E","F","^F","G","_A","A","_B","B","c","^c","d","_e","e","f","^f","g","_a","a","_b","b"];b.exports.pitchToMidi=pitchToMidi=function(a){var b=/^(\^+|_+|=|)([A-Ga-g])([,']*)$/.exec(a);if(!b)return null;var c=b[3].replace(/,/g,"").length-b[3].replace(/'/g,"").length,d=g[b[2]]+h[b[1].charAt(0)]*b[1].length+12*c;return d+60},b.exports.midiToPitch=function(a){var b=(a-72)%12;(a>60||0!=b)&&(b+=12);for(var c=Math.round((a-b-60)/12),d=i[b];0!=c;)d+=c>0?"'":",",c+=c>0?-1:1;return d},b.exports.pitchToFrequency=pitchToFrequency=function(a){return midiToFrequency(pitchToMidi(a))},b.exports.defaultTimbre=defaultTimbre={wave:"square",gain:.1,attack:.002,decay:.4,decayfollow:0,sustain:0,release:.1,cutoff:0,cutfollow:0,resonance:0,detune:0},b.exports.makeTimbre=function(a,b){a||(a={}),"string"==typeof a&&(a={wave:a});var c,d={},e=b&&b.wavetable&&b.wavetable[a.wave];for(c in defaultTimbre)a.hasOwnProperty(c)?d[c]=a[c]:e&&e.defs&&e.defs.hasOwnProperty(c)?d[c]=e.defs[c]:d[c]=defaultTimbre[c];return d};b.exports.makeOscillator=makeOscillator=function(a,b,c){if("noise"==b){var d=a.ac.createBufferSource();return d.buffer=e(),d.loop=!0,d}var f,g,h,i,j=a.wavetable,k=a.ac.createOscillator();try{if(j.hasOwnProperty(b)){if(g=j[b].wave,j[b].freq){h=0;for(f in j[b].freq)i=Number(f),c>i&&i>h&&(h=i,g=j[b].freq[h])}!k.setPeriodicWave&&k.setWaveTable?k.setWaveTable(g):k.setPeriodicWave(g)}else k.type=b}catch(l){window.console&&window.console.log(l),k.type="square"}return k.frequency.value=c,k}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./wavetable-builder":5}],5:[function(a,b,c){b.exports=function(a){return function(b){function c(b){var c,d=b.real.length,e=new Float32Array(d),f=new Float32Array(d);for(c=0;d>c;++c)e[c]=b.real[c],f[c]=b.imag[c];try{return a.createPeriodicWave(e,f)}catch(g){}try{return a.createWaveTable(e,f)}catch(g){}return null}function d(a,b,c){var d,e,f={real:[],imag:[]},g=a.real.length;for(d=0;g>d;++d)e=Math.log(b[Math.min(d,b.length-1)]),f.real.push(a.real[d]*Math.exp(c*e)),f.imag.push(a.imag[d]*Math.exp(c*e));return f}var e,f,g,h,i,j,k={};for(e in b)if(f=b[e],j=c(f)){if(i={wave:j},f.mult)for(h=b[e].freq,i.freq={},g=0;g