forked from jummbus/jummbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeepbox_editor.min.js
More file actions
1 lines (1 loc) · 184 KB
/
beepbox_editor.min.js
File metadata and controls
1 lines (1 loc) · 184 KB
1
var beepbox,__extends=this&&this.t||function(){var t=function(i,s){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var s in i)i.hasOwnProperty(s)&&(t[s]=i[s])})(i,s)};return function(i,s){function e(){this.constructor=i}t(i,s),i.prototype=null===s?Object.create(s):(e.prototype=s.prototype,new e)}}();!function(t){function i(t){if(!function(t){return!(!t||t&t-1)}(t))throw new Error("FFT array length must be a power of 2.");return Math.round(Math.log(t)/Math.log(2))}t.scaleElementsByFactor=function(t,i){for(var s=0;s<t.length;s++)t[s]*=i},t.inverseRealFourierTransform=function(t){var s=t.length,e=i(s);if(s<4)throw new Error("FFT array length must be at least 4.");for(var n=e-1;n>=2;n--)for(var h=1<<n,r=h>>1,o=h<<1,a=2*Math.PI/o,l=Math.cos(a),u=Math.sin(a),f=2*l,c=0;c<s;c+=o){var d=c,v=d+r,p=d+h,b=p+r,m=p+h,w=t[d],g=t[p];t[d]=w+g,t[v]*=2,t[p]=w-g,t[b]*=2;for(var x=l,y=-u,M=1,k=0,A=1;A<r;A++){var E=d+A,N=p-A,B=p+A,R=m-A,L=t[E],S=t[N],I=t[B],Z=t[R],C=L-S,G=I+Z;t[E]=L+S,t[N]=Z-I,t[B]=C*x-G*y,t[R]=G*x+C*y;var U=f*x-M,j=f*y-k;M=x,k=y,x=U,y=j}}for(A=0;A<s;A+=4){var z=A+1,D=A+2,Y=A+3,T=(L=t[A],S=2*t[z],t[D]),F=2*t[Y];C=L+T,G=L-T,t[A]=C+S,t[z]=C-S,t[D]=G+F,t[Y]=G-F}!function(t){var s=t.length,e=i(s);if(e>16)throw new Error("FFT array length must not be greater than 2^16.");for(var n=16-e,h=0;h<s;h++){var r=void 0;if((r=((r=(61680&(r=(52428&(r=(43690&h)>>1|(21845&h)<<1))>>2|(13107&r)<<2))>>4|(3855&r)<<4)>>8|(255&r)<<8)>>n)>h){var o=t[h];t[h]=t[r],t[r]=o}}}(t)}}(beepbox||(beepbox={})),function(t){var i=function(){function i(){}return i.i=function(t){for(var i=0,s=0;s<t.length;s++)i+=t[s];var e=i/t.length;for(s=0;s<t.length;s++)t[s]-=e;return new Float64Array(t)},i.getDrumWave=function(s){var e=i.s[s];if(null==e)if(e=new Float32Array(32768),i.s[s]=e,0==s)for(var n=1,h=0;h<32768;h++){e[h]=2*(1&n)-1,1==(n+(r=n>>1)&1)&&(r+=16384),n=r}else if(1==s)for(h=0;h<32768;h++)e[h]=2*Math.random()-1;else if(2==s)for(n=1,h=0;h<32768;h++){e[h]=2*(1&n)-1,1==(n+(r=n>>1)&1)&&(r+=32768),n=r}else if(3==s)for(n=1,h=0;h<32768;h++){var r;e[h]=2*(1&n)-1,1==(n+(r=n>>1)&1)&&(r+=40),n=r}else{if(4!=s)throw new Error("Unrecognized drum index: "+s);i.drawNoiseSpectrum(e,10,11,1,1,0),i.drawNoiseSpectrum(e,11,14,-2,-2,0),t.inverseRealFourierTransform(e),t.scaleElementsByFactor(e,1/Math.sqrt(e.length))}return e},i.drawNoiseSpectrum=function(t,i,s,e,n,h){for(var r=0|Math.pow(2,i),o=0|Math.pow(2,s),a=Math.log(2),l=r;l<o;l++){var u=Math.pow(2,e+(n-e)*(Math.log(l)/a-i)/(s-i));u*=Math.pow(l/2048,h);var f=Math.random()*Math.PI*2;t[l]=Math.cos(f)*u,t[32768-l]=Math.sin(f)*u}},i.generateSineWave=function(){for(var t=new Float64Array(i.sineWaveLength+1),s=0;s<i.sineWaveLength+1;s++)t[s]=Math.sin(s*Math.PI*2/i.sineWaveLength);return t},i.scaleNames=["easy :)","easy :(","island :)","island :(","blues :)","blues :(","normal :)","normal :(","dbl harmonic :)","dbl harmonic :(","enigma","expert"],i.scaleFlags=[[!0,!1,!0,!1,!0,!1,!1,!0,!1,!0,!1,!1],[!0,!1,!1,!0,!1,!0,!1,!0,!1,!1,!0,!1],[!0,!1,!1,!1,!0,!0,!1,!0,!1,!1,!1,!0],[!0,!0,!1,!0,!1,!1,!1,!0,!0,!1,!1,!1],[!0,!1,!0,!0,!0,!1,!1,!0,!1,!0,!1,!1],[!0,!1,!1,!0,!1,!0,!0,!0,!1,!1,!0,!1],[!0,!1,!0,!1,!0,!0,!1,!0,!1,!0,!1,!0],[!0,!1,!0,!0,!1,!0,!1,!0,!0,!1,!0,!1],[!0,!0,!1,!1,!0,!0,!1,!0,!0,!1,!1,!0],[!0,!1,!0,!0,!1,!1,!0,!0,!0,!1,!1,!0],[!0,!1,!0,!1,!0,!1,!0,!1,!0,!1,!0,!1],[!0,!0,!0,!0,!0,!0,!0,!0,!0,!0,!0,!0]],i.pianoScaleFlags=[!0,!1,!0,!1,!0,!0,!1,!0,!1,!0,!1,!0],i.blackKeyNameParents=[-1,1,-1,1,-1,1,-1,-1,1,-1,1,-1],i.pitchNames=["C",null,"D",null,"E","F",null,"G",null,"A",null,"B"],i.keyNames=["B","A♯","A","G♯","G","F♯","F","E","D♯","D","C♯","C"],i.keyTransposes=[23,22,21,20,19,18,17,16,15,14,13,12],i.tempoSteps=15,i.reverbRange=4,i.beatsPerBarMin=3,i.beatsPerBarMax=16,i.barCountMin=1,i.barCountMax=128,i.patternsPerChannelMin=1,i.patternsPerChannelMax=64,i.instrumentsPerChannelMin=1,i.instrumentsPerChannelMax=10,i.partNames=["÷3 (triplets)","÷4 (standard)","÷6","÷8"],i.partCounts=[3,4,6,8],i.waveNames=["triangle","square","pulse wide","pulse narrow","sawtooth","double saw","double pulse","spiky","plateau"],i.waveVolumes=[1,.5,.5,.5,.65,.5,.4,.4,.94],i.drumNames=["retro","white","clang","buzz","hollow"],i.drumVolumes=[.25,1,.4,.3,1.5],i.drumBasePitches=[69,69,69,69,96],i.drumPitchFilterMult=[100,8,100,100,1],i.drumWaveIsSoft=[!1,!0,!1,!1,!0],i.s=[null,null,null,null,null],i.filterNames=["none","bright","medium","soft","decay bright","decay medium","decay soft"],i.filterBases=[0,2,3.5,5,1,2.5,4],i.filterDecays=[0,0,0,0,10,7,4],i.filterVolumes=[.2,.4,.7,1,.5,.75,1],i.transitionNames=["seamless","sudden","smooth","slide"],i.effectNames=["none","vibrato light","vibrato delayed","vibrato heavy","tremolo light","tremolo heavy"],i.effectVibratos=[0,.15,.3,.45,0,0],i.effectTremolos=[0,0,0,0,.25,.5],i.effectVibratoDelays=[0,0,3,0,0,0],i.chorusNames=["union","shimmer","hum","honky tonk","dissonant","fifths","octaves","bowed","custom harmony"],i.chorusIntervals=[0,.02,.05,.1,.25,3.5,6,.02,.05],i.chorusOffsets=[0,0,0,0,0,3.5,6,0,0],i.chorusVolumes=[.7,.8,1,1,.9,.9,.8,1,1],i.chorusSigns=[1,1,1,1,1,1,1,-1,1],i.chorusHarmonizes=[!1,!1,!1,!1,!1,!1,!1,!1,!0],i.volumeNames=["loudest","loud","medium","quiet","quietest","mute"],i.volumeValues=[0,.5,1,1.5,2,-1],i.operatorCount=4,i.operatorAlgorithmNames=["1←(2 3 4)","1←(2 3←4)","1←2←(3 4)","1←(2 3)←4","1←2←3←4","1←3 2←4","1 2←(3 4)","1 2←3←4","(1 2)←3←4","(1 2)←(3 4)","1 2 3←4","(1 2 3)←4","1 2 3 4"],i.midiAlgorithmNames=["1<(2 3 4)","1<(2 3<4)","1<2<(3 4)","1<(2 3)<4","1<2<3<4","1<3 2<4","1 2<(3 4)","1 2<3<4","(1 2)<3<4","(1 2)<(3 4)","1 2 3<4","(1 2 3)<4","1 2 3 4"],i.operatorModulatedBy=[[[2,3,4],[],[],[]],[[2,3],[],[4],[]],[[2],[3,4],[],[]],[[2,3],[4],[4],[]],[[2],[3],[4],[]],[[3],[4],[],[]],[[],[3,4],[],[]],[[],[3],[4],[]],[[3],[3],[4],[]],[[3,4],[3,4],[],[]],[[],[],[4],[]],[[4],[4],[4],[]],[[],[],[],[]]],i.operatorAssociatedCarrier=[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,2,1,2],[1,2,2,2],[1,2,2,2],[1,2,2,2],[1,2,2,2],[1,2,3,3],[1,2,3,3],[1,2,3,4]],i.operatorCarrierCounts=[1,1,1,1,1,2,2,2,2,2,3,3,4],i.operatorCarrierChorus=[0,.04,-.073,.091],i.operatorAmplitudeMax=15,i.operatorFrequencyNames=["1×","~1×","2×","~2×","3×","4×","5×","6×","7×","8×","9×","11×","13×","16×","20×"],i.midiFrequencyNames=["1x","~1x","2x","~2x","3x","4x","5x","6x","7x","8x","9x","11x","13x","16x","20x"],i.operatorFrequencies=[1,1,2,2,3,4,5,6,7,8,9,11,13,16,20],i.operatorHzOffsets=[0,1.5,0,-1.3,0,0,0,0,0,0,0,0,0,0,0],i.operatorAmplitudeSigns=[1,-1,1,-1,1,1,1,1,1,1,1,1,1,1,1],i.operatorEnvelopeNames=["custom","steady","punch","flare 1","flare 2","flare 3","pluck 1","pluck 2","pluck 3","swell 1","swell 2","swell 3","tremolo1","tremolo2","tremolo3"],i.operatorEnvelopeType=[0,1,2,3,3,3,4,4,4,4,4,4,5,5,5],i.operatorEnvelopeSpeed=[0,0,0,32,8,2,32,8,2,32,8,2,4,2,1],i.operatorEnvelopeInverted=[!1,!1,!1,!1,!1,!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],i.operatorFeedbackNames=["1⟲","2⟲","3⟲","4⟲","1⟲ 2⟲","3⟲ 4⟲","1⟲ 2⟲ 3⟲","2⟲ 3⟲ 4⟲","1⟲ 2⟲ 3⟲ 4⟲","1→2","1→3","1→4","2→3","2→4","3→4","1→3 2→4","1→4 2→3","1→2→3→4"],i.midiFeedbackNames=["1","2","3","4","1 2","3 4","1 2 3","2 3 4","1 2 3 4","1>2","1>3","1>4","2>3","2>4","3>4","1>3 2>4","1>4 2>3","1>2>3>4"],i.operatorFeedbackIndices=[[[1],[],[],[]],[[],[2],[],[]],[[],[],[3],[]],[[],[],[],[4]],[[1],[2],[],[]],[[],[],[3],[4]],[[1],[2],[3],[]],[[],[2],[3],[4]],[[1],[2],[3],[4]],[[],[1],[],[]],[[],[],[1],[]],[[],[],[],[1]],[[],[],[2],[]],[[],[],[],[2]],[[],[],[],[3]],[[],[],[1],[2]],[[],[],[2],[1]],[[],[1],[2],[3]]],i.pitchChannelTypeNames=["chip","FM (expert)"],i.instrumentTypeNames=["chip","FM","noise"],i.pitchChannelColorsDim=["#0099a1","#a1a100","#c75000","#00a100","#d020d0","#7777b0"],i.pitchChannelColorsBright=["#25f3ff","#ffff25","#ff9752","#50ff50","#ff90ff","#a0a0ff"],i.pitchNoteColorsDim=["#00bdc7","#c7c700","#ff771c","#00c700","#e040e0","#8888d0"],i.pitchNoteColorsBright=["#92f9ff","#ffff92","#ffcdab","#a0ffa0","#ffc0ff","#d0d0ff"],i.drumChannelColorsDim=["#6f6f6f","#996633"],i.drumChannelColorsBright=["#aaaaaa","#ddaa77"],i.drumNoteColorsDim=["#aaaaaa","#cc9966"],i.drumNoteColorsBright=["#eeeeee","#f0d0bb"],i.midiPitchChannelNames=["cyan channel","yellow channel","orange channel","green channel","purple channel","blue channel"],i.midiDrumChannelNames=["gray channel","brown channel"],i.midiSustainInstruments=[71,80,70,68,81,81,81,81,74],i.midiDecayInstruments=[46,46,6,24,25,25,106,106,33],i.drumInterval=6,i.drumCount=12,i.pitchCount=37,i.maxPitch=84,i.pitchChannelCountMin=1,i.pitchChannelCountMax=6,i.drumChannelCountMin=0,i.drumChannelCountMax=2,i.waves=[i.i([1/15,.2,5/15,7/15,.6,11/15,13/15,1,1,13/15,11/15,.6,7/15,5/15,.2,1/15,-1/15,-.2,-5/15,-7/15,-.6,-11/15,-13/15,-1,-1,-13/15,-11/15,-.6,-7/15,-5/15,-.2,-1/15]),i.i([1,-1]),i.i([1,-1,-1,-1]),i.i([1,-1,-1,-1,-1,-1,-1,-1]),i.i([1/31,3/31,5/31,7/31,9/31,11/31,13/31,15/31,17/31,19/31,21/31,23/31,25/31,27/31,29/31,1,-1,-29/31,-27/31,-25/31,-23/31,-21/31,-19/31,-17/31,-15/31,-13/31,-11/31,-9/31,-7/31,-5/31,-3/31,-1/31]),i.i([0,-.2,-.4,-.6,-.8,-1,1,-.8,-.6,-.4,-.2,1,.8,.6,.4,.2]),i.i([1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1]),i.i([1,-1,1,-1,1,0]),i.i([0,.2,.4,.5,.6,.7,.8,.85,.9,.95,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,.95,.9,.85,.8,.7,.6,.5,.4,.2,0,-.2,-.4,-.5,-.6,-.7,-.8,-.85,-.9,-.95,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-.95,-.9,-.85,-.8,-.7,-.6,-.5,-.4,-.2])],i.sineWaveLength=256,i.sineWaveMask=i.sineWaveLength-1,i.sineWave=i.generateSineWave(),i}();t.Config=i;var s=function(){function t(t,i,s,e){this.h=[],this.o=0;for(var n=s;n<e;n++){var h=t[i.charCodeAt(n)];this.h.push(h>>5&1),this.h.push(h>>4&1),this.h.push(h>>3&1),this.h.push(h>>2&1),this.h.push(h>>1&1),this.h.push(1&h)}}return t.prototype.read=function(t){for(var i=0;t>0;)i<<=1,i+=this.h[this.o++],t--;return i},t.prototype.readLongTail=function(t,i){for(var s=t,e=i;this.h[this.o++];)s+=1<<e,e++;for(;e>0;)e--,this.h[this.o++]&&(s+=1<<e);return s},t.prototype.readPartDuration=function(){return this.readLongTail(1,2)},t.prototype.readPinCount=function(){return this.readLongTail(1,0)},t.prototype.readPitchInterval=function(){return this.read(1)?-this.readLongTail(1,3):this.readLongTail(1,3)},t}(),e=function(){function t(){this.h=[]}return t.prototype.write=function(t,i){for(t--;t>=0;)this.h.push(i>>>t&1),t--},t.prototype.writeLongTail=function(t,i,s){if(s<t)throw new Error("value out of bounds");s-=t;for(var e=i;s>=1<<e;)this.h.push(1),s-=1<<e,e++;for(this.h.push(0);e>0;)e--,this.h.push(s>>>e&1)},t.prototype.writePartDuration=function(t){this.writeLongTail(1,2,t)},t.prototype.writePinCount=function(t){this.writeLongTail(1,0,t)},t.prototype.writePitchInterval=function(t){t<0?(this.write(1,1),this.writeLongTail(1,3,-t)):(this.write(1,0),this.writeLongTail(1,3,t))},t.prototype.concat=function(t){this.h=this.h.concat(t.h)},t.prototype.encodeBase64=function(t,i){for(var s=0;s<this.h.length;s+=6){var e=this.h[s]<<5|this.h[s+1]<<4|this.h[s+2]<<3|this.h[s+3]<<2|this.h[s+4]<<1|this.h[s+5];i.push(t[e])}return i},t.prototype.lengthBase64=function(){return Math.ceil(this.h.length/6)},t}();function n(t,i,s){return{interval:t,time:i,volume:s}}function h(t,i,s,e,h){return void 0===h&&(h=!1),{pitches:[t],pins:[n(0,0,e),n(0,s-i,h?0:e)],start:i,end:s}}t.makeNotePin=n,t.makeNote=h;var r=function(){function t(){this.notes=[],this.instrument=0}return t.prototype.cloneNotes=function(){for(var t=[],i=0,s=this.notes;i<s.length;i++){var e=s[i],r=h(-1,e.start,e.end,3);r.pitches=e.pitches.concat(),r.pins=[];for(var o=0,a=e.pins;o<a.length;o++){var l=a[o];r.pins.push(n(l.interval,l.time,l.volume))}t.push(r)}return t},t.prototype.reset=function(){this.notes.length=0,this.instrument=0},t}();t.Pattern=r;var o=function(){function t(t){this.frequency=0,this.amplitude=0,this.envelope=0,this.reset(t)}return t.prototype.reset=function(t){this.frequency=0,this.amplitude=t<=1?i.operatorAmplitudeMax:0,this.envelope=0==t?0:1},t.prototype.copy=function(t){this.frequency=t.frequency,this.amplitude=t.amplitude,this.envelope=t.envelope},t}();t.Operator=o;var a=function(){function t(){this.type=0,this.wave=1,this.filter=1,this.transition=1,this.effect=0,this.chorus=0,this.volume=0,this.algorithm=0,this.feedbackType=0,this.feedbackAmplitude=0,this.feedbackEnvelope=1,this.operators=[];for(var t=0;t<i.operatorCount;t++)this.operators.push(new o(t))}return t.prototype.setTypeAndReset=function(t){switch(this.type=t,t){case 0:this.wave=1,this.filter=1,this.transition=1,this.effect=0,this.chorus=0,this.volume=0;break;case 1:this.wave=1,this.transition=1,this.volume=0;break;case 2:this.transition=1,this.effect=0,this.algorithm=0,this.feedbackType=0,this.feedbackAmplitude=0,this.feedbackEnvelope=1;for(var i=0;i<this.operators.length;i++)this.operators[i].reset(i)}},t.prototype.copy=function(t){this.type=t.type,this.wave=t.wave,this.filter=t.filter,this.transition=t.transition,this.effect=t.effect,this.chorus=t.chorus,this.volume=t.volume,this.algorithm=t.algorithm,this.feedbackType=t.feedbackType,this.feedbackAmplitude=t.feedbackAmplitude,this.feedbackEnvelope=t.feedbackEnvelope;for(var i=0;i<this.operators.length;i++)this.operators[i].copy(t.operators[i])},t}();t.Instrument=a;var l=function(){return function(){this.octave=0,this.instruments=[],this.patterns=[],this.bars=[]}}();t.Channel=l;var u=function(){function t(t){this.channels=[],void 0!=t?this.fromBase64String(t):this.initToDefault(!0)}return t.prototype.getChannelCount=function(){return this.pitchChannelCount+this.drumChannelCount},t.prototype.getChannelIsDrum=function(t){return t>=this.pitchChannelCount},t.prototype.getChannelColorDim=function(t){return t<this.pitchChannelCount?i.pitchChannelColorsDim[t]:i.drumChannelColorsDim[t-this.pitchChannelCount]},t.prototype.getChannelColorBright=function(t){return t<this.pitchChannelCount?i.pitchChannelColorsBright[t]:i.drumChannelColorsBright[t-this.pitchChannelCount]},t.prototype.getNoteColorDim=function(t){return t<this.pitchChannelCount?i.pitchNoteColorsDim[t]:i.drumNoteColorsDim[t-this.pitchChannelCount]},t.prototype.getNoteColorBright=function(t){return t<this.pitchChannelCount?i.pitchNoteColorsBright[t]:i.drumNoteColorsBright[t-this.pitchChannelCount]},t.prototype.initToDefault=function(t){if(void 0===t&&(t=!0),this.scale=0,this.key=i.keyNames.length-1,this.loopStart=0,this.loopLength=4,this.tempo=7,this.reverb=0,this.beatsPerBar=8,this.barCount=16,this.patternsPerChannel=8,this.partsPerBeat=4,this.instrumentsPerChannel=1,t){this.pitchChannelCount=3,this.drumChannelCount=1;for(var s=0;s<this.getChannelCount();s++){this.channels.length<=s&&(this.channels[s]=new l);var e=this.channels[s];e.octave=3-s;for(var n=0;n<this.patternsPerChannel;n++)e.patterns.length<=n?e.patterns[n]=new r:e.patterns[n].reset();e.patterns.length=this.patternsPerChannel;for(var h=0;h<this.instrumentsPerChannel;h++)e.instruments.length<=h&&(e.instruments[h]=new a),e.instruments[h].setTypeAndReset(s<this.pitchChannelCount?0:2);e.instruments.length=this.instrumentsPerChannel;for(var o=0;o<this.barCount;o++)e.bars[o]=1;e.bars.length=this.barCount}this.channels.length=this.getChannelCount()}},t.prototype.toBase64String=function(){var s,n=[],h=t.l;n.push(h[t.u]),n.push(110,h[this.pitchChannelCount],h[this.drumChannelCount]),n.push(115,h[this.scale]),n.push(107,h[this.key]),n.push(108,h[this.loopStart>>6],h[63&this.loopStart]),n.push(101,h[this.loopLength-1>>6],h[this.loopLength-1&63]),n.push(116,h[this.tempo]),n.push(109,h[this.reverb]),n.push(97,h[this.beatsPerBar-1]),n.push(103,h[this.barCount-1>>6],h[this.barCount-1&63]),n.push(106,h[this.patternsPerChannel-1]),n.push(105,h[this.instrumentsPerChannel-1]),n.push(114,h[i.partCounts.indexOf(this.partsPerBeat)]),n.push(111);for(var r=0;r<this.getChannelCount();r++)n.push(h[this.channels[r].octave]);for(r=0;r<this.getChannelCount();r++)for(var o=0;o<this.instrumentsPerChannel;o++){var a=this.channels[r].instruments[o];if(n.push(84,h[a.type]),0==a.type)n.push(119,h[a.wave]),n.push(102,h[a.filter]),n.push(100,h[a.transition]),n.push(99,h[a.effect]),n.push(104,h[a.chorus]),n.push(118,h[a.volume]);else if(1==a.type){n.push(100,h[a.transition]),n.push(99,h[a.effect]),n.push(65,h[a.algorithm]),n.push(70,h[a.feedbackType]),n.push(66,h[a.feedbackAmplitude]),n.push(86,h[a.feedbackEnvelope]),n.push(81);for(var l=0;l<i.operatorCount;l++)n.push(h[a.operators[l].frequency]);n.push(80);for(l=0;l<i.operatorCount;l++)n.push(h[a.operators[l].amplitude]);n.push(69);for(l=0;l<i.operatorCount;l++)n.push(h[a.operators[l].envelope])}else{if(2!=a.type)throw new Error("Unknown instrument type.");n.push(119,h[a.wave]),n.push(100,h[a.transition]),n.push(118,h[a.volume])}}n.push(98),s=new e;for(var u=0;1<<u<this.patternsPerChannel+1;)u++;for(r=0;r<this.getChannelCount();r++)for(o=0;o<this.barCount;o++)s.write(u,this.channels[r].bars[o]);s.encodeBase64(h,n),n.push(112),s=new e;for(var f=0;1<<f<this.instrumentsPerChannel;)f++;for(r=0;r<this.getChannelCount();r++){var c=this.getChannelIsDrum(r),d=c?0:12*this.channels[r].octave,v=(c?4:12)+d,p=c?[4,6,7,2,3,8,0,10]:[12,19,24,31,36,7,0],b=[];for(o=0;o<p.length;o++)p[o]+=d;for(var m=0,w=this.channels[r].patterns;m<w.length;m++){var g=w[m];if(s.write(f,g.instrument),g.notes.length>0){s.write(1,1);for(var x=0,y=0,M=g.notes;y<M.length;y++){var k=M[y];k.start>x&&(s.write(2,0),s.writePartDuration(k.start-x));var A=new e;for(o=1;o<k.pitches.length;o++)A.write(1,1);k.pitches.length<4&&A.write(1,0),A.writePinCount(k.pins.length-1),A.write(2,k.pins[0].volume);var E=0,N=k.pitches[0],B=N,R=[];for(o=1;o<k.pins.length;o++){var L=k.pins[o],S=N+L.interval;B!=S?(A.write(1,1),R.push(S),B=S):A.write(1,0),A.writePartDuration(L.time-E),E=L.time,A.write(2,L.volume)}var I=String.fromCharCode.apply(null,A.encodeBase64(h,[])),Z=b.indexOf(I);-1==Z?(s.write(2,1),s.concat(A)):(s.write(1,1),s.writeLongTail(0,0,Z),b.splice(Z,1)),b.unshift(I),b.length>10&&b.pop();var C=k.pitches.concat(R);for(o=0;o<C.length;o++){var G=C[o],U=p.indexOf(G);if(-1==U){var j=0,z=v;if(z<G)for(;z!=G;)z++,-1==p.indexOf(z)&&j++;else for(;z!=G;)z--,-1==p.indexOf(z)&&j--;s.write(1,0),s.writePitchInterval(j)}else s.write(1,1),s.write(3,U),p.splice(U,1);p.unshift(G),p.length>8&&p.pop(),v=o==k.pitches.length-1?k.pitches[0]:G}x=k.end}x<this.beatsPerBar*this.partsPerBeat&&(s.write(2,0),s.writePartDuration(this.beatsPerBar*this.partsPerBeat-x))}else s.write(1,0)}}for(var D=s.lengthBase64(),Y=[];D>0;)Y.unshift(h[63&D]),D>>=6;if(n.push(h[Y.length]),Array.prototype.push.apply(n,Y),s.encodeBase64(h,n),n.length>=65535)throw new Error("Song hash code too long.");return String.fromCharCode.apply(null,n)},t.prototype.fromBase64String=function(e){if(null!=e&&""!=e){for(var o=0;e.charCodeAt(o)<=32;)o++;if(35==e.charCodeAt(o)&&o++,123!=e.charCodeAt(o)){var u=t.v[e.charCodeAt(o++)];if(!(-1==u||u>t.u||u<t.p)){var f=u<3,c=u<4,d=u<5,v=u<6,p=t.v;if(this.initToDefault(v),f){for(var b=0,m=this.channels;b<m.length;b++){(y=m[b]).instruments[0].transition=0}this.channels[3].instruments[0].wave=0}for(var w=0,g=-1;o<e.length;){var x=e.charCodeAt(o++),y=void 0;if(110==x){this.pitchChannelCount=p[e.charCodeAt(o++)],this.drumChannelCount=p[e.charCodeAt(o++)],this.pitchChannelCount=t.m(i.pitchChannelCountMin,i.pitchChannelCountMax+1,this.pitchChannelCount),this.drumChannelCount=t.m(i.drumChannelCountMin,i.drumChannelCountMax+1,this.drumChannelCount);for(var M=this.channels.length;M<this.getChannelCount();M++)this.channels[M]=new l;this.channels.length=this.getChannelCount()}else if(115==x)this.scale=p[e.charCodeAt(o++)],f&&10==this.scale&&(this.scale=11);else if(107==x)this.key=p[e.charCodeAt(o++)];else if(108==x)this.loopStart=d?p[e.charCodeAt(o++)]:(p[e.charCodeAt(o++)]<<6)+p[e.charCodeAt(o++)];else if(101==x)this.loopLength=d?p[e.charCodeAt(o++)]:(p[e.charCodeAt(o++)]<<6)+p[e.charCodeAt(o++)]+1;else if(116==x)this.tempo=c?[1,4,7,10][p[e.charCodeAt(o++)]]:p[e.charCodeAt(o++)],this.tempo=t.m(0,i.tempoSteps,this.tempo);else if(109==x)this.reverb=p[e.charCodeAt(o++)],this.reverb=t.m(0,i.reverbRange,this.reverb);else if(97==x)this.beatsPerBar=f?[6,7,8,9,10][p[e.charCodeAt(o++)]]:p[e.charCodeAt(o++)]+1,this.beatsPerBar=Math.max(i.beatsPerBarMin,Math.min(i.beatsPerBarMax,this.beatsPerBar));else if(103==x){this.barCount=(p[e.charCodeAt(o++)]<<6)+p[e.charCodeAt(o++)]+1,this.barCount=Math.max(i.barCountMin,Math.min(i.barCountMax,this.barCount));for(var k=0;k<this.getChannelCount();k++){for(var A=this.channels[k].bars.length;A<this.barCount;A++)this.channels[k].bars[A]=1;this.channels[k].bars.length=this.barCount}}else if(106==x){this.patternsPerChannel=p[e.charCodeAt(o++)]+1,this.patternsPerChannel=Math.max(i.patternsPerChannelMin,Math.min(i.patternsPerChannelMax,this.patternsPerChannel));for(var E=0;E<this.getChannelCount();E++){for(var N=this.channels[E].patterns.length;N<this.patternsPerChannel;N++)this.channels[E].patterns[N]=new r;this.channels[E].patterns.length=this.patternsPerChannel}}else if(105==x){this.instrumentsPerChannel=p[e.charCodeAt(o++)]+1,this.instrumentsPerChannel=Math.max(i.instrumentsPerChannelMin,Math.min(i.instrumentsPerChannelMax,this.instrumentsPerChannel));for(var B=0;B<this.getChannelCount();B++){for(var R=this.channels[B].instruments.length;R<this.instrumentsPerChannel;R++)this.channels[B].instruments[R]=new a;if(this.channels[B].instruments.length=this.instrumentsPerChannel,v)for(R=0;R<this.instrumentsPerChannel;R++)this.channels[B].instruments[R].setTypeAndReset(B<this.pitchChannelCount?0:2)}}else if(114==x)this.partsPerBeat=i.partCounts[p[e.charCodeAt(o++)]];else if(111==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].octave=t.m(0,5,p[e.charCodeAt(o++)]);else for(y=0;y<this.getChannelCount();y++)this.channels[y].octave=t.m(0,5,p[e.charCodeAt(o++)]);else if(84==x){++g>=this.instrumentsPerChannel&&(w++,g=0),this.channels[w].instruments[g].setTypeAndReset(t.m(0,3,p[e.charCodeAt(o++)]))}else if(119==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].instruments[0].wave=t.m(0,i.waveNames.length,p[e.charCodeAt(o++)]);else if(v)for(y=0;y<this.getChannelCount();y++)for(var L=y>=this.pitchChannelCount,S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].wave=t.m(0,L?i.drumNames.length:i.waveNames.length,p[e.charCodeAt(o++)]);else{L=w>=this.pitchChannelCount;this.channels[w].instruments[g].wave=t.m(0,L?i.drumNames.length:i.waveNames.length,p[e.charCodeAt(o++)])}else if(102==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].instruments[0].filter=[1,3,4,5][t.m(0,i.filterNames.length,p[e.charCodeAt(o++)])];else if(v)for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].filter=t.m(0,i.filterNames.length,p[e.charCodeAt(o++)]+1);else this.channels[w].instruments[g].filter=t.m(0,i.filterNames.length,p[e.charCodeAt(o++)]);else if(100==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].instruments[0].transition=t.m(0,i.transitionNames.length,p[e.charCodeAt(o++)]);else if(v)for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].transition=t.m(0,i.transitionNames.length,p[e.charCodeAt(o++)]);else this.channels[w].instruments[g].transition=t.m(0,i.transitionNames.length,p[e.charCodeAt(o++)]);else if(99==x)if(f){y=p[e.charCodeAt(o++)];var I=t.m(0,i.effectNames.length,p[e.charCodeAt(o++)]);1==I?I=3:3==I&&(I=5),this.channels[y].instruments[0].effect=I}else if(v)for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].effect=t.m(0,i.effectNames.length,p[e.charCodeAt(o++)]);else this.channels[w].instruments[g].effect=t.m(0,i.effectNames.length,p[e.charCodeAt(o++)]);else if(104==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].instruments[0].chorus=t.m(0,i.chorusNames.length,p[e.charCodeAt(o++)]);else if(v)for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].chorus=t.m(0,i.chorusNames.length,p[e.charCodeAt(o++)]);else this.channels[w].instruments[g].chorus=t.m(0,i.chorusNames.length,p[e.charCodeAt(o++)]);else if(118==x)if(f)y=p[e.charCodeAt(o++)],this.channels[y].instruments[0].volume=t.m(0,i.volumeNames.length,p[e.charCodeAt(o++)]);else if(v)for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.instrumentsPerChannel;S++)this.channels[y].instruments[S].volume=t.m(0,i.volumeNames.length,p[e.charCodeAt(o++)]);else this.channels[w].instruments[g].volume=t.m(0,i.volumeNames.length,p[e.charCodeAt(o++)]);else if(65==x)this.channels[w].instruments[g].algorithm=t.m(0,i.operatorAlgorithmNames.length,p[e.charCodeAt(o++)]);else if(70==x)this.channels[w].instruments[g].feedbackType=t.m(0,i.operatorFeedbackNames.length,p[e.charCodeAt(o++)]);else if(66==x)this.channels[w].instruments[g].feedbackAmplitude=t.m(0,i.operatorAmplitudeMax+1,p[e.charCodeAt(o++)]);else if(86==x)this.channels[w].instruments[g].feedbackEnvelope=t.m(0,i.operatorEnvelopeNames.length,p[e.charCodeAt(o++)]);else if(81==x)for(var Z=0;Z<i.operatorCount;Z++)this.channels[w].instruments[g].operators[Z].frequency=t.m(0,i.operatorFrequencyNames.length,p[e.charCodeAt(o++)]);else if(80==x)for(Z=0;Z<i.operatorCount;Z++)this.channels[w].instruments[g].operators[Z].amplitude=t.m(0,i.operatorAmplitudeMax+1,p[e.charCodeAt(o++)]);else if(69==x)for(Z=0;Z<i.operatorCount;Z++)this.channels[w].instruments[g].operators[Z].envelope=t.m(0,i.operatorEnvelopeNames.length,p[e.charCodeAt(o++)]);else if(98==x){var C=void 0;if(f){y=p[e.charCodeAt(o++)];var G=p[e.charCodeAt(o++)];C=Math.ceil(.5*G);var U=new s(p,e,o,o+C);for(S=0;S<G;S++)this.channels[y].bars[S]=U.read(3)+1}else if(d){for(var j=0;1<<j<this.patternsPerChannel;)j++;C=Math.ceil(this.getChannelCount()*this.barCount*j/6);U=new s(p,e,o,o+C);for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.barCount;S++)this.channels[y].bars[S]=U.read(j)+1}else{for(j=0;1<<j<this.patternsPerChannel+1;)j++;C=Math.ceil(this.getChannelCount()*this.barCount*j/6);U=new s(p,e,o,o+C);for(y=0;y<this.getChannelCount();y++)for(S=0;S<this.barCount;S++)this.channels[y].bars[S]=U.read(j)}o+=C}else if(112==x){var z=0;if(f)y=p[e.charCodeAt(o++)],o++,z=p[e.charCodeAt(o++)],z<<=6,z+=p[e.charCodeAt(o++)];else{y=0;for(var D=p[e.charCodeAt(o++)];D>0;)z<<=6,z+=p[e.charCodeAt(o++)],D--}U=new s(p,e,o,o+z);o+=z;for(var Y=0;1<<Y<this.instrumentsPerChannel;)Y++;for(;;){var T=this.getChannelIsDrum(y),F=T?0:12*this.channels[y].octave,V=null,P=null,O=(T?4:12)+F,W=T?[4,6,7,2,3,8,0,10]:[12,19,24,31,36,7,0],J=[];for(S=0;S<W.length;S++)W[S]+=F;for(S=0;S<this.patternsPerChannel;S++){var Q=this.channels[y].patterns[S];if(Q.reset(),Q.instrument=U.read(Y),f||0!=U.read(1))for(var H=0,X=Q.notes;H<this.beatsPerBar*this.partsPerBeat;){var _=1==U.read(1),K=!1,q=0;if(_?q=U.readLongTail(0,0):K=1==U.read(1),_||K){var $=void 0,tt=void 0,it=void 0;if(_)$=J[q],J.splice(q,1);else{for(($={}).pitchCount=1;$.pitchCount<4&&1==U.read(1);)$.pitchCount++;$.pinCount=U.readPinCount(),$.initialVolume=U.read(2),$.pins=[],$.length=0,$.bendCount=0;for(var st=0;st<$.pinCount;st++)(tt={}).pitchBend=1==U.read(1),tt.pitchBend&&$.bendCount++,$.length+=U.readPartDuration(),tt.time=$.length,tt.volume=U.read(2),$.pins.push(tt)}J.unshift($),J.length>10&&J.pop(),(V=h(0,H,H+$.length,$.initialVolume)).pitches=[],V.pins.length=1;var et=[];for(st=0;st<$.pitchCount+$.bendCount;st++){if(1==U.read(1)){var nt=U.read(3);it=W[nt],W.splice(nt,1)}else{var ht=U.readPitchInterval();it=O;for(var rt=ht;rt>0;){for(it++;-1!=W.indexOf(it);)it++;rt--}for(;rt<0;){for(it--;-1!=W.indexOf(it);)it--;rt++}}W.unshift(it),W.length>8&&W.pop(),st<$.pitchCount?V.pitches.push(it):et.push(it),O=st==$.pitchCount-1?V.pitches[0]:it}et.unshift(V.pitches[0]);for(var ot=0,at=$.pins;ot<at.length;ot++){var lt=at[ot];lt.pitchBend&&et.shift(),P=n(et[0]-V.pitches[0],lt.time,lt.volume),V.pins.push(P)}H=V.end,X.push(V)}else{H+=U.readPartDuration()}}}if(f)break;if(++y>=this.getChannelCount())break}}}}}else this.fromJsonObject(JSON.parse(0==o?e:e.substring(o)))}else this.initToDefault(!0)},t.prototype.toJsonObject=function(s,e,n){void 0===s&&(s=!0),void 0===e&&(e=1),void 0===n&&(n=!0);for(var h=[],r=0;r<this.getChannelCount();r++){for(var o=[],a=this.getChannelIsDrum(r),l=0;l<this.instrumentsPerChannel;l++){var u=this.channels[r].instruments[l];if(2==u.type)o.push({type:i.instrumentTypeNames[u.type],volume:20*(5-u.volume),wave:i.drumNames[u.wave],transition:i.transitionNames[u.transition]});else if(0==u.type)o.push({type:i.instrumentTypeNames[u.type],volume:20*(5-u.volume),wave:i.waveNames[u.wave],transition:i.transitionNames[u.transition],filter:i.filterNames[u.filter],chorus:i.chorusNames[u.chorus],effect:i.effectNames[u.effect]});else{if(1!=u.type)throw new Error("Unrecognized instrument type");for(var f=[],c=0,d=u.operators;c<d.length;c++){var v=d[c];f.push({frequency:i.operatorFrequencyNames[v.frequency],amplitude:v.amplitude,envelope:i.operatorEnvelopeNames[v.envelope]})}o.push({type:i.instrumentTypeNames[u.type],transition:i.transitionNames[u.transition],effect:i.effectNames[u.effect],algorithm:i.operatorAlgorithmNames[u.algorithm],feedbackType:i.operatorFeedbackNames[u.feedbackType],feedbackAmplitude:u.feedbackAmplitude,feedbackEnvelope:i.operatorEnvelopeNames[u.feedbackEnvelope],operators:f})}}for(var p=[],b=0,m=this.channels[r].patterns;b<m.length;b++){for(var w=m[b],g=[],x=0,y=w.notes;x<y.length;x++){for(var M=y[x],k=[],A=0,E=M.pins;A<E.length;A++){var N=E[A];k.push({tick:N.time+M.start,pitchBend:N.interval,volume:Math.round(100*N.volume/3)})}g.push({pitches:M.pitches,points:k})}p.push({instrument:w.instrument+1,notes:g})}var B=[];if(s)for(l=0;l<this.loopStart;l++)B.push(this.channels[r].bars[l]);for(var R=0;R<e;R++)for(l=this.loopStart;l<this.loopStart+this.loopLength;l++)B.push(this.channels[r].bars[l]);if(n)for(l=this.loopStart+this.loopLength;l<this.barCount;l++)B.push(this.channels[r].bars[l]);h.push({type:a?"drum":"pitch",octaveScrollBar:this.channels[r].octave,instruments:o,patterns:p,sequence:B})}return{format:t.g,version:t.u,scale:i.scaleNames[this.scale],key:i.keyNames[this.key],introBars:this.loopStart,loopBars:this.loopLength,beatsPerBar:this.beatsPerBar,ticksPerBeat:this.partsPerBeat,beatsPerMinute:this.getBeatsPerMinute(),reverb:this.reverb,channels:h}},t.prototype.fromJsonObject=function(s){if((this.initToDefault(!0),s)&&!(s.version>t.g)){if(this.scale=11,void 0!=s.scale){var e={"romani :)":8,"romani :(":9},o=void 0!=e[s.scale]?e[s.scale]:i.scaleNames.indexOf(s.scale);-1!=o&&(this.scale=o)}if(void 0!=s.key)if("number"==typeof s.key)this.key=i.keyNames.length-1-(s.key+1200>>>0)%i.keyNames.length;else if("string"==typeof s.key){var u=s.key,f=u.charAt(0).toUpperCase(),c=u.charAt(1).toLowerCase(),d={C:11,D:9,E:7,F:6,G:4,A:2,B:0}[f],v={"#":-1,"♯":-1,b:1,"♭":1}[c];void 0!=d&&(void 0!=v&&(d+=v),d<0&&(d+=12),d%=12,this.key=d)}if(void 0!=s.beatsPerMinute){var p=0|s.beatsPerMinute;this.tempo=Math.round(4+9*Math.log(p/120)/Math.LN2),this.tempo=t.m(0,i.tempoSteps,this.tempo)}void 0!=s.reverb&&(this.reverb=t.m(0,i.reverbRange,0|s.reverb)),void 0!=s.beatsPerBar&&(this.beatsPerBar=Math.max(i.beatsPerBarMin,Math.min(i.beatsPerBarMax,0|s.beatsPerBar))),void 0!=s.ticksPerBeat&&(this.partsPerBeat=0|s.ticksPerBeat,-1==i.partCounts.indexOf(this.partsPerBeat)&&(this.partsPerBeat=i.partCounts[i.partCounts.length-1]));var b=1,m=1,w=1;if(s.channels)for(var g=0,x=s.channels;g<x.length;g++){(A=x[g]).instruments&&(b=Math.max(b,0|A.instruments.length)),A.patterns&&(m=Math.max(m,0|A.patterns.length)),A.sequence&&(w=Math.max(w,0|A.sequence.length))}this.instrumentsPerChannel=b,this.patternsPerChannel=m,this.barCount=w,void 0!=s.introBars&&(this.loopStart=t.m(0,this.barCount,0|s.introBars)),void 0!=s.loopBars&&(this.loopLength=t.m(1,this.barCount-this.loopStart+1,0|s.loopBars));var y=0,M=0;if(s.channels)for(var k=0;k<s.channels.length;k++){var A=s.channels[k];this.channels.length<=k&&(this.channels[k]=new l),void 0!=A.octaveScrollBar&&(this.channels[k].octave=t.m(0,5,0|A.octaveScrollBar));for(var E=this.channels[k].instruments.length;E<this.instrumentsPerChannel;E++)this.channels[k].instruments[E]=new a;this.channels[k].instruments.length=this.instrumentsPerChannel;for(E=this.channels[k].patterns.length;E<this.patternsPerChannel;E++)this.channels[k].patterns[E]=new r;this.channels[k].patterns.length=this.patternsPerChannel;for(E=0;E<this.barCount;E++)this.channels[k].bars[E]=1;this.channels[k].bars.length=this.barCount;var N=!1;(N=A.type?"drum"==A.type:k>=3)?M++:y++;for(E=0;E<this.instrumentsPerChannel;E++){var B=this.channels[k].instruments[E],R=void 0;A.instruments&&(R=A.instruments[E]),void 0==R&&(R={});var L={binary:0},S=R.transition||R.envelope;if(B.transition=void 0!=L[S]?L[S]:i.transitionNames.indexOf(S),-1==B.transition&&(B.transition=1),B.type=i.instrumentTypeNames.indexOf(R.type),-1==B.type&&(B.type=N?2:0),2==B.type)void 0!=R.volume?B.volume=t.m(0,i.volumeNames.length,Math.round(5-(0|R.volume)/20)):B.volume=0,B.wave=i.drumNames.indexOf(R.wave),-1==B.wave&&(B.wave=1);else if(0==B.type){void 0!=R.volume?B.volume=t.m(0,i.volumeNames.length,Math.round(5-(0|R.volume)/20)):B.volume=0,B.wave=i.waveNames.indexOf(R.wave),-1==B.wave&&(B.wave=1);var I={"sustain sharp":1,"sustain medium":2,"sustain soft":3,"decay sharp":4};B.filter=void 0!=I[R.filter]?I[R.filter]:i.filterNames.indexOf(R.filter),-1==B.filter&&(B.filter=0),B.chorus=i.chorusNames.indexOf(R.chorus),-1==B.chorus&&(B.chorus=0),B.effect=i.effectNames.indexOf(R.effect),-1==B.effect&&(B.effect=0)}else{if(1!=B.type)throw new Error("Unrecognized instrument type.");B.effect=i.effectNames.indexOf(R.effect),-1==B.effect&&(B.effect=0),B.algorithm=i.operatorAlgorithmNames.indexOf(R.algorithm),-1==B.algorithm&&(B.algorithm=0),B.feedbackType=i.operatorFeedbackNames.indexOf(R.feedbackType),-1==B.feedbackType&&(B.feedbackType=0),void 0!=R.feedbackAmplitude?B.feedbackAmplitude=t.m(0,i.operatorAmplitudeMax+1,0|R.feedbackAmplitude):B.feedbackAmplitude=0,B.feedbackEnvelope=i.operatorEnvelopeNames.indexOf(R.feedbackEnvelope),-1==B.feedbackEnvelope&&(B.feedbackEnvelope=0);for(var Z=0;Z<i.operatorCount;Z++){var C=B.operators[Z],G=void 0;R.operators&&(G=R.operators[Z]),void 0==G&&(G={}),C.frequency=i.operatorFrequencyNames.indexOf(G.frequency),-1==C.frequency&&(C.frequency=0),void 0!=G.amplitude?C.amplitude=t.m(0,i.operatorAmplitudeMax+1,0|G.amplitude):C.amplitude=0,C.envelope=i.operatorEnvelopeNames.indexOf(G.envelope),-1==C.envelope&&(C.envelope=0)}}}for(E=0;E<this.patternsPerChannel;E++){var U=this.channels[k].patterns[E],j=void 0;if(A.patterns&&(j=A.patterns[E]),void 0!=j&&(U.instrument=t.m(0,this.instrumentsPerChannel,(0|j.instrument)-1),j.notes&&j.notes.length>0)){var z=Math.min(this.beatsPerBar*this.partsPerBeat,j.notes.length>>>0),D=0;for(Z=0;Z<j.notes.length&&!(Z>=z);Z++){var Y=j.notes[Z];if(Y&&Y.pitches&&Y.pitches.length>=1&&Y.points&&Y.points.length>=2){var T=h(0,0,0,0);T.pitches=[],T.pins=[];for(var F=0;F<Y.pitches.length;F++){var V=0|Y.pitches[F];if(-1==T.pitches.indexOf(V)&&(T.pitches.push(V),T.pitches.length>=4))break}if(!(T.pitches.length<1)){var P=D,O=0;for(F=0;F<Y.points.length;F++){var W=Y.points[F];if(void 0!=W&&void 0!=W.tick){var J=void 0==W.pitchBend?0:0|W.pitchBend,Q=0|W.tick,H=void 0==W.volume?3:Math.max(0,Math.min(3,Math.round(3*(0|W.volume)/100)));if(!(Q>this.beatsPerBar*this.partsPerBeat)){if(0==T.pins.length){if(Q<P)continue;T.start=Q,O=J}else if(Q<=P)continue;P=Q,T.pins.push(n(J-O,Q-T.start,H))}}}if(!(T.pins.length<2)){T.end=T.pins[T.pins.length-1].time+T.start;var X=N?i.drumCount-1:i.maxPitch,_=X,K=0;for(F=0;F<T.pitches.length;F++)T.pitches[F]+=O,(T.pitches[F]<0||T.pitches[F]>X)&&(T.pitches.splice(F,1),F--),T.pitches[F]<_&&(_=T.pitches[F]),T.pitches[F]>K&&(K=T.pitches[F]);if(!(T.pitches.length<1)){for(F=0;F<T.pins.length;F++){var q=T.pins[F];q.interval+_<0&&(q.interval=-_),q.interval+K>X&&(q.interval=X-K),F>=2&&q.interval==T.pins[F-1].interval&&q.interval==T.pins[F-2].interval&&q.volume==T.pins[F-1].volume&&q.volume==T.pins[F-2].volume&&(T.pins.splice(F-1,1),F--)}U.notes.push(T),D=T.end}}}}}}}for(E=0;E<this.barCount;E++)this.channels[k].bars[E]=A.sequence?Math.min(this.patternsPerChannel,A.sequence[E]>>>0):0}this.pitchChannelCount=y,this.drumChannelCount=M,this.channels.length=this.getChannelCount()}},t.m=function(t,i,s){return s<=(i-=1)?s>=t?s:t:i},t.prototype.getPattern=function(t,i){var s=this.channels[t].bars[i];return 0==s?null:this.channels[t].patterns[s-1]},t.prototype.getPatternInstrument=function(t,i){var s=this.getPattern(t,i);return null==s?0:s.instrument},t.prototype.getBeatsPerMinute=function(){return Math.round(120*Math.pow(2,(-4+this.tempo)/9))},t.g="BeepBox",t.p=2,t.u=6,t.v=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62,62,0,0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,0,0,0,0,63,0,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,0,0,0,0,0],t.l=[48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,45,95],t}();t.Song=u;var f=function(){function t(){this.active=!1,this.sample=0,this.phases=[],this.phaseDeltas=[],this.volumeStarts=[],this.volumeDeltas=[],this.phaseDeltaScale=0,this.filter=0,this.filterScale=0,this.vibratoScale=0,this.harmonyMult=0,this.harmonyVolumeMult=1,this.feedbackOutputs=[],this.feedbackMult=0,this.feedbackDelta=0,this.reset()}return t.prototype.reset=function(){for(var t=0;t<i.operatorCount;t++)this.phases[t]=0,this.feedbackOutputs[t]=0;this.sample=0},t}(),c=function(){function s(t){void 0===t&&(t=null);var i=this;this.samplesPerSecond=44100,this.effectDuration=.14,this.effectAngle=2*Math.PI/(this.effectDuration*this.samplesPerSecond),this.effectYMult=2*Math.cos(this.effectAngle),this.limitDecay=1/(2*this.samplesPerSecond),this.song=null,this.pianoPressed=!1,this.pianoPitch=[0],this.pianoChannel=0,this.enableIntro=!0,this.enableOutro=!1,this.loopCount=-1,this.volume=1,this.playheadInternal=0,this.bar=0,this.beat=0,this.part=0,this.arpeggio=0,this.arpeggioSampleCountdown=0,this.paused=!0,this.tones=[],this.stillGoing=!1,this.effectPhase=0,this.limit=0,this.samplesForReverb=null,this.reverbDelayLine=new Float32Array(16384),this.reverbDelayPos=0,this.reverbFeedback0=0,this.reverbFeedback1=0,this.reverbFeedback2=0,this.reverbFeedback3=0,this.audioCtx=null,this.scriptNode=null,this.audioProcessCallback=function(t){var s=t.outputBuffer,e=s.getChannelData(0);i.synthesize(e,s.length)},null!=t&&this.setSong(t)}return s.warmUpSynthesizer=function(t){if(null!=t)for(var e=0;e<t.instrumentsPerChannel;e++){for(var n=t.pitchChannelCount;n<t.pitchChannelCount+t.drumChannelCount;n++)i.getDrumWave(t.channels[n].instruments[e].wave);for(n=0;n<t.getChannelCount();n++)s.getGeneratedSynthesizer(t.channels[n].instruments[e])}},s.operatorAmplitudeCurve=function(t){return(Math.pow(16,t/15)-1)/15},Object.defineProperty(s.prototype,"playing",{get:function(){return!this.paused},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"playhead",{get:function(){return this.playheadInternal},set:function(t){if(null!=this.song){this.playheadInternal=Math.max(0,Math.min(this.song.barCount,t));var i=this.playheadInternal;this.bar=Math.floor(i),i=this.song.beatsPerBar*(i-this.bar),this.beat=Math.floor(i),i=this.song.partsPerBeat*(i-this.beat),this.part=Math.floor(i),i=4*(i-this.part),this.arpeggio=Math.floor(i);var s=this.getSamplesPerArpeggio();i=s*(i-this.arpeggio),this.arpeggioSampleCountdown=Math.floor(s-i),this.bar<this.song.loopStart&&(this.enableIntro=!0),this.bar>this.song.loopStart+this.song.loopLength&&(this.enableOutro=!0)}},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"totalSamples",{get:function(){if(null==this.song)return 0;var t=4*this.getSamplesPerArpeggio()*this.song.partsPerBeat*this.song.beatsPerBar,i=this.loopCount;i<0&&(i=1);var s=this.song.loopLength*i;return this.enableIntro&&(s+=this.song.loopStart),this.enableOutro&&(s+=this.song.barCount-(this.song.loopStart+this.song.loopLength)),s*t},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"totalSeconds",{get:function(){return this.totalSamples/this.samplesPerSecond},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"totalBars",{get:function(){return null==this.song?0:this.song.barCount},enumerable:!0,configurable:!0}),s.prototype.setSong=function(t){"string"==typeof t?this.song=new u(t):t instanceof u&&(this.song=t)},s.prototype.play=function(){if(this.paused){this.paused=!1,s.warmUpSynthesizer(this.song);var t=window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.oAudioContext||window.msAudioContext;this.audioCtx=this.audioCtx||new t,this.scriptNode=this.audioCtx.createScriptProcessor?this.audioCtx.createScriptProcessor(2048,0,1):this.audioCtx.createJavaScriptNode(2048,0,1),this.scriptNode.onaudioprocess=this.audioProcessCallback,this.scriptNode.channelCountMode="explicit",this.scriptNode.channelInterpretation="speakers",this.scriptNode.connect(this.audioCtx.destination),this.samplesPerSecond=this.audioCtx.sampleRate,this.effectAngle=2*Math.PI/(this.effectDuration*this.samplesPerSecond),this.effectYMult=2*Math.cos(this.effectAngle),this.limitDecay=1/(2*this.samplesPerSecond)}},s.prototype.pause=function(){this.paused||(this.paused=!0,this.scriptNode.disconnect(this.audioCtx.destination),this.audioCtx.close&&(this.audioCtx.close(),this.audioCtx=null),this.scriptNode=null)},s.prototype.snapToStart=function(){this.bar=0,this.enableIntro=!0,this.snapToBar()},s.prototype.snapToBar=function(t){void 0!==t&&(this.bar=t),this.playheadInternal=this.bar,this.beat=0,this.part=0,this.arpeggio=0,this.arpeggioSampleCountdown=0,this.effectPhase=0;for(var i=0,s=this.tones;i<s.length;i++){s[i].reset()}this.reverbDelayPos=0,this.reverbFeedback0=0,this.reverbFeedback1=0,this.reverbFeedback2=0,this.reverbFeedback3=0;for(var e=0;e<this.reverbDelayLine.length;e++)this.reverbDelayLine[e]=0},s.prototype.nextBar=function(){if(this.song){var t=this.bar;this.bar++,this.enableOutro?this.bar>=this.song.barCount&&(this.bar=this.enableIntro?0:this.song.loopStart):(this.bar>=this.song.loopStart+this.song.loopLength||this.bar>=this.song.barCount)&&(this.bar=this.song.loopStart),this.playheadInternal+=this.bar-t}},s.prototype.prevBar=function(){if(this.song){var t=this.bar;this.bar--,this.bar<0&&(this.bar=this.song.loopStart+this.song.loopLength-1),this.bar>=this.song.barCount&&(this.bar=this.song.barCount-1),this.bar<this.song.loopStart&&(this.enableIntro=!0),!this.enableOutro&&this.bar>=this.song.loopStart+this.song.loopLength&&(this.bar=this.song.loopStart+this.song.loopLength-1),this.playheadInternal+=this.bar-t}},s.prototype.synthesize=function(i,e){if(null!=this.song){var n=this.song.getChannelCount();for(V=this.tones.length;V<n;V++)this.tones[V]=new f;this.tones.length=n;var h=this.getSamplesPerArpeggio(),r=0,o=!1;(0==this.arpeggioSampleCountdown||this.arpeggioSampleCountdown>h)&&(this.arpeggioSampleCountdown=h),this.part>=this.song.partsPerBeat&&(this.beat++,this.part=0,this.arpeggio=0,this.arpeggioSampleCountdown=h),this.beat>=this.song.beatsPerBar&&(this.bar++,this.beat=0,this.part=0,this.arpeggio=0,this.arpeggioSampleCountdown=h,-1==this.loopCount&&(this.bar<this.song.loopStart&&!this.enableIntro&&(this.bar=this.song.loopStart),this.bar>=this.song.loopStart+this.song.loopLength&&!this.enableOutro&&(this.bar=this.song.loopStart))),this.bar>=this.song.barCount&&(this.enableOutro?(this.bar=0,this.enableIntro=!0,o=!0,this.pause()):this.bar=this.song.loopStart),this.bar>=this.song.loopStart&&(this.enableIntro=!1);var a=performance.now();for(V=0;V<e;)i[V++]=0,i[V++]=0,i[V++]=0,i[V++]=0;(null==this.samplesForReverb||this.samplesForReverb.length<e)&&(this.samplesForReverb=new Float32Array(e));var l=this.samplesForReverb;for(V=0;V<e;)l[V++]=0,l[V++]=0,l[V++]=0,l[V++]=0;for(;r<e&&!o;)for(;r<e;){for(var u=e-r,c=this.arpeggioSampleCountdown<=u?this.arpeggioSampleCountdown:u,d=0;d<this.song.getChannelCount();d++){var v=this.song.channels[d].instruments[this.song.getPatternInstrument(d,this.bar)];s.computeTone(this,this.song,d,h,c,v);var p=this.tones[d];if(p.active){var b=this.song.getChannelIsDrum(d)?i:l;s.getGeneratedSynthesizer(v)(this,b,r,c,p,v)}}if(r+=c,this.effectPhase=(this.effectPhase+this.effectAngle*c)%(2*Math.PI),this.arpeggioSampleCountdown-=c,this.arpeggioSampleCountdown<=0&&(this.arpeggio++,this.arpeggioSampleCountdown=h,4==this.arpeggio&&(this.arpeggio=0,this.part++,this.part==this.song.partsPerBeat&&(this.part=0,this.beat++,this.beat==this.song.beatsPerBar)))){this.beat=0,this.bar++,this.effectPhase=0,this.bar<this.song.loopStart?this.enableIntro||(this.bar=this.song.loopStart):this.enableIntro=!1,this.bar>=this.song.loopStart+this.song.loopLength&&(this.loopCount>0&&this.loopCount--,(this.loopCount>0||!this.enableOutro)&&(this.bar=this.song.loopStart)),this.bar>=this.song.barCount&&(this.bar=0,this.enableIntro=!0,o=!0,this.pause());break}}var m=+this.volume,w=this.reverbDelayLine,g=0|this.reverbDelayPos,x=+this.reverbFeedback0,y=+this.reverbFeedback1,M=+this.reverbFeedback2,k=+this.reverbFeedback3,A=.425*Math.pow(this.song.reverb/t.Config.reverbRange,.667),E=+this.limitDecay,N=+this.limit;for(V=0;V<e;V++){var B=l[V],R=g+3041&16383,L=g+6426&16383,S=g+10907&16383,I=w[g]+B,Z=w[R],C=w[L],G=w[S],U=-I+Z,j=-I-Z,z=-C+G,D=-C-G;x+=.5*((U+z)*A-x),y+=.5*((j+D)*A-y),M+=.5*((U-z)*A-M),k+=.5*((j-D)*A-k),w[R]=x,w[L]=y,w[S]=M,w[g]=k,g=g+1&16383;var Y=i[V]+I+Z+C+G,T=Y<0?-Y:Y;N<T&&(N=T),i[V]=Y/(.75*N+.25)*m,N-=E}this.reverbDelayPos=g,this.reverbFeedback0=x,this.reverbFeedback1=y,this.reverbFeedback2=M,this.reverbFeedback3=k,this.limit=N,this.playheadInternal=(((this.arpeggio+1-this.arpeggioSampleCountdown/h)/4+this.part)/this.song.partsPerBeat+this.beat)/this.song.beatsPerBar+this.bar;var F=performance.now()-a;e,F}else for(var V=0;V<e;V++)i[V]=0},s.computeOperatorEnvelope=function(t,s,e,n){switch(i.operatorEnvelopeType[t]){case 0:return n;case 1:return 1;case 4:var h=1/(1+s*i.operatorEnvelopeSpeed[t]);return i.operatorEnvelopeInverted[t]?1-h:h;case 5:return.5-.5*Math.cos(2*e*Math.PI*i.operatorEnvelopeSpeed[t]);case 2:return Math.max(1,2-10*s);case 3:var r=i.operatorEnvelopeSpeed[t],o=.25/Math.sqrt(r);return s<o?s/o:1/(1+(s-o)*r);default:throw new Error("Unrecognized operator envelope type.")}},s.computeTone=function(t,e,n,h,r,o){var a=e.getChannelIsDrum(n),l=t.tones[n],u=e.getPattern(n,t.bar),f=t.pianoPressed&&n==t.pianoChannel,c=a?i.drumBasePitches[o.wave]:i.keyTransposes[e.key],d=a?i.drumInterval:1,v=a?i.drumWaveIsSoft[o.wave]?24:60:48,p=4*h/t.samplesPerSecond,b=1/e.partsPerBeat;l.phaseDeltaScale=0,l.filter=1,l.filterScale=1,l.vibratoScale=0,l.harmonyMult=1,l.harmonyVolumeMult=1,l.active=!1;for(var m=0,w=t.arpeggio,g=t.arpeggioSampleCountdown,x=null,y=!0,M=0,k=0,A=1,E=1,N=0,B=0,R=0,L=0,S=0,I=0,Z=0;Z<i.operatorCount;Z++)l.phaseDeltas[Z]=0,l.volumeStarts[Z]=0,l.volumeDeltas[Z]=0;if(f)x=t.pianoPitch,A=E=1,N=B=1,y=!1;else if(null!=u){var C=t.part+t.beat*e.partsPerBeat,G=null,U=null,j=null;for(Z=0;Z<u.notes.length;Z++)if(u.notes[Z].end<=C)U=u.notes[Z];else if(u.notes[Z].start<=C&&u.notes[Z].end>C)G=u.notes[Z];else if(u.notes[Z].start>C){j=u.notes[Z];break}if(null!=G&&null!=U&&U.end!=G.start&&(U=null),null!=G&&null!=j&&j.start!=G.end&&(j=null),null!=G){x=G.pitches,m=C-G.start;var z=void 0;for(z=1;z<G.pins.length-1&&!(G.pins[z].time+G.start>C);z++);var D=G.pins[z-1],Y=G.pins[z],T=4*G.start,F=4*G.end,V=4*(G.start+D.time),P=4*(G.start+Y.time),O=4*C+w,W=4*C+w+1,J=(O-V)/(P-V),Q=(W-V)/(P-V),H=D.volume+(Y.volume-D.volume)*J,X=D.volume+(Y.volume-D.volume)*Q,_=1,K=1,q=D.interval+(Y.interval-D.interval)*J,$=D.interval+(Y.interval-D.interval)*Q,tt=D.time+(Y.time-D.time)*J,it=D.time+(Y.time-D.time)*Q,st=tt,et=it,nt=1-g/h,ht=1-(g-r)/h;y=O+nt-T==0;var rt=o.transition;O==T&&(0==rt?y=!1:2==rt?_=0:3==rt&&(null==U?_=0:0==U.pins[U.pins.length-1].volume||0==G.pins[0].volume?_=0:(q=.5*(U.pitches[0]+U.pins[U.pins.length-1].interval-G.pitches[0]),st=.5*U.pins[U.pins.length-1].time,y=!1))),W==F&&(0==rt?null==j&&G.start+Y.time!=e.partsPerBeat*e.beatsPerBar&&(K=0):1==rt||2==rt?K=0:3==rt&&(null==j?K=0:0==G.pins[G.pins.length-1].volume||0==j.pins[0].volume?K=0:($=.5*(j.pitches[0]-G.pitches[0]+G.pins[G.pins.length-1].interval),et*=.5))),M=q+($-q)*nt,k=q+($-q)*ht,N=t.volumeConversion(H+(X-H)*nt),B=t.volumeConversion(H+(X-H)*ht),A=_+(K-_)*nt,E=_+(K-_)*ht,R=G.start+tt+(it-tt)*nt,L=G.start+tt+(it-tt)*ht,S=st+(et-st)*nt,I=st+(et-st)*ht}}if(null!=x){var ot=1/t.samplesPerSecond;if(l.active=!0,a||1!=o.type){mt=x[0];if(i.chorusHarmonizes[o.chorus]){var at=0;2==x.length?at=x[1]-x[0]:3==x.length?at=x[1+(w>>1)]-x[0]:4==x.length&&(at=x[(3==w?1:w)+1]-x[0]),l.harmonyMult=Math.pow(2,at/12),l.harmonyVolumeMult=Math.pow(2,-at/v)}else 2==x.length?mt=x[w>>1]:3==x.length?mt=x[3==w?1:w]:4==x.length&&(mt=x[w]);gt=(mt+M)*d,Bt=(mt+k)*d,xt=t.frequencyFromPitch(c+gt),Et=Math.pow(2,-gt/v),Nt=Math.pow(2,-Bt/v);a&&i.drumWaveIsSoft[o.wave]&&(l.filter=Math.min(1,xt*ot*i.drumPitchFilterMult[o.wave]));var lt=void 0;if(a)lt=.19*i.drumVolumes[o.wave];else{var ut=i.filterDecays[o.filter];l.filter=Math.pow(2,-ut*p*S);var ft=Math.pow(2,-ut*p*I);l.filterScale=Math.pow(ft/l.filter,1/r),lt=.135*i.waveVolumes[o.wave]*i.filterVolumes[o.filter]*i.chorusVolumes[o.chorus]}y&&!a&&l.reset(),l.phaseDeltas[0]=xt*ot;var ct=5==o.volume?0:Math.pow(2,-i.volumeValues[o.volume]);l.volumeStarts[0]=A*N*Et*lt*ct;At=E*B*Nt*lt*ct;l.volumeDeltas[0]=(At-l.volumeStarts[0])/r}else{var dt=1,vt=0,pt=i.operatorCarrierCounts[o.algorithm];for(Z=0;Z<i.operatorCount;Z++){var bt=i.operatorAssociatedCarrier[o.algorithm][Z]-1,mt=x[Z<x.length?Z:bt<x.length?bt:0],wt=i.operatorFrequencies[o.operators[Z].frequency],gt=(mt+M)*d+i.operatorCarrierChorus[bt],xt=wt*t.frequencyFromPitch(c+gt)+i.operatorHzOffsets[o.operators[Z].frequency];l.phaseDeltas[Z]=xt*ot*i.sineWaveLength,y&&l.reset();var yt=s.operatorAmplitudeCurve(o.operators[Z].amplitude),Mt=yt*i.operatorAmplitudeSigns[o.operators[Z].frequency],kt=Mt,At=Mt;if(Z<pt){var Et,Nt,Bt=(mt+k)*d;kt*=.03*(Et=Math.pow(2,-gt/v))*A,At*=.03*(Nt=Math.pow(2,-Bt/v))*E,vt+=yt}else kt*=1.5*i.sineWaveLength,At*=1.5*i.sineWaveLength,dt*=1-Math.min(1,o.operators[Z].amplitude/15);var Rt=o.operators[Z].envelope;kt*=s.computeOperatorEnvelope(Rt,p*S,b*R,N),At*=s.computeOperatorEnvelope(Rt,p*I,b*L,B),l.volumeStarts[Z]=kt,l.volumeDeltas[Z]=(At-kt)/r}var Lt=.3*i.sineWaveLength*o.feedbackAmplitude/15,St=Lt*s.computeOperatorEnvelope(o.feedbackEnvelope,p*S,b*R,N),It=Lt*s.computeOperatorEnvelope(o.feedbackEnvelope,p*I,b*L,B);l.feedbackMult=St,l.feedbackDelta=(It-l.feedbackMult)/r,dt*=1-o.feedbackAmplitude/15,dt*=1-Math.min(1,Math.max(0,vt-1)/2);for(Z=0;Z<pt;Z++)l.volumeStarts[Z]*=1+3*dt,l.volumeDeltas[Z]*=1+3*dt}l.phaseDeltaScale=Math.pow(2,(k-M)*d/12/r),l.vibratoScale=m<i.effectVibratoDelays[o.effect]?0:Math.pow(2,i.effectVibratos[o.effect]/12)-1}else{a||l.reset();for(Z=0;Z<i.operatorCount;Z++)l.phaseDeltas[0]=0,l.volumeStarts[0]=0,l.volumeDeltas[0]=0}},s.getGeneratedSynthesizer=function(t){if(1==t.type){var e=t.algorithm+"_"+t.feedbackType;if(void 0==s.fmSynthFunctionCache[e]){for(var n=[],h=0,r=s.fmSourceTemplate;h<r.length;h++){var o=r[h];if(-1!=o.indexOf("// CARRIER OUTPUTS")){if(1==t.type){for(var a=[],l=0;l<i.operatorCarrierCounts[t.algorithm];l++)a.push("operator"+l+"Scaled");n.push(o.replace("/*operator#Scaled*/",a.join(" + ")))}}else if(-1!=o.indexOf("// INSERT OPERATOR COMPUTATION HERE"))for(l=i.operatorCount-1;l>=0;l--)for(var u=0,f=s.operatorSourceTemplate;u<f.length;u++){var c=f[u];if(-1!=c.indexOf("/* + operator@Scaled*/")){for(var d="",v=0,p=i.operatorModulatedBy[t.algorithm][l];v<p.length;v++){d+=" + operator"+((x=p[v])-1)+"Scaled"}var b=i.operatorFeedbackIndices[t.feedbackType][l];if(b.length>0){d+=" + feedbackMult * (";for(var m=[],w=0,g=b;w<g.length;w++){var x=g[w];m.push("operator"+(x-1)+"Output")}d+=m.join(" + ")+")"}n.push(c.replace(/\#/g,l+"").replace("/* + operator@Scaled*/",d))}else n.push(c.replace(/\#/g,l+""))}else if(-1!=o.indexOf("#"))for(l=0;l<i.operatorCount;l++)n.push(o.replace(/\#/g,l+""));else n.push(o)}s.fmSynthFunctionCache[e]=new Function("synth","data","bufferIndex","runLength","tone","instrument",n.join("\n"))}return s.fmSynthFunctionCache[e]}if(0==t.type)return s.chipSynth;if(2==t.type)return s.noiseSynth;throw new Error("Unrecognized instrument type: "+t.type)},s.chipSynth=function(i,s,e,n,h,r){var o=+i.effectYMult,a=+Math.sin(i.effectPhase),l=+Math.sin(i.effectPhase-i.effectAngle),u=t.Config.waves[r.wave],f=+u.length,c=+Math.pow(2,-t.Config.filterBases[r.filter]),d=+t.Config.effectTremolos[r.effect],v=+Math.pow(2,(t.Config.chorusOffsets[r.chorus]+t.Config.chorusIntervals[r.chorus])/12),p=Math.pow(2,(t.Config.chorusOffsets[r.chorus]-t.Config.chorusIntervals[r.chorus])/12)*h.harmonyMult,b=h.harmonyVolumeMult*t.Config.chorusSigns[r.chorus];0==r.chorus&&(h.phases[1]=h.phases[0]);for(var m=p/v,w=h.phaseDeltas[0]*v,g=+h.phaseDeltaScale,x=+h.volumeStarts[0],y=+h.volumeDeltas[0],M=h.filter*c,k=+h.filterScale,A=+h.vibratoScale,E=h.phases[0]%1,N=h.phases[1]%1,B=+h.sample,R=e+n;e<R;){var L=1+A*a,S=1+d*(a-1),I=a;a=o*a-l,l=I,B+=((u[0|E*f]+u[0|N*f]*b)*x*S-B)*M,x+=y,E+=w*L,N+=w*L*m,M*=k,E-=0|E,N-=0|N,w*=g,s[e]+=B,e++}h.phases[0]=E,h.phases[1]=N,h.sample=B},s.noiseSynth=function(i,s,e,n,h,r){for(var o=t.Config.getDrumWave(r.wave),a=+h.phaseDeltas[0]/32768,l=+h.phaseDeltaScale,u=+h.volumeStarts[0],f=+h.volumeDeltas[0],c=+h.filter,d=h.phases[0]%1,v=+h.sample,p=e+n;e<p;)v+=(o[0|32768*d]*u-v)*c,u+=f,d+=a,d-=0|d,a*=l,s[e]+=v,e++;h.phases[0]=d,h.sample=v},s.prototype.frequencyFromPitch=function(t){return 440*Math.pow(2,(t-69)/12)},s.prototype.volumeConversion=function(t){return Math.pow(t/3,1.5)},s.prototype.getSamplesPerArpeggio=function(){if(null==this.song)return 0;var t=4*(this.song.getBeatsPerMinute()/60*this.song.partsPerBeat);return Math.floor(this.samplesPerSecond/t)},s.negativePhaseGuard=1e3,s.fmSynthFunctionCache={},s.fmSourceTemplate=("\n\t\t\t// TODO: Skip this line and oscillator below unless using an effect:\n\t\t\tvar effectYMult = +synth.effectYMult;\n\t\t\tvar effectY = +Math.sin(synth.effectPhase);\n\t\t\tvar prevEffectY = +Math.sin(synth.effectPhase - synth.effectAngle);\n\t\t\t\n\t\t\tvar sineWave = beepbox.Config.sineWave;\n\t\t\t\n\t\t\tvar tremoloScale = +beepbox.Config.effectTremolos[instrument.effect];\n\t\t\t\n\t\t\tvar phaseDeltaScale = +tone.phaseDeltaScale;\n\t\t\tvar vibratoScale = +tone.vibratoScale;\n\t\t\tvar operator#Phase = +((tone.phases[#] % 1) + "+s.negativePhaseGuard+") * "+i.sineWaveLength+";\n\t\t\tvar operator#PhaseDelta = +tone.phaseDeltas[#];\n\t\t\tvar operator#OutputMult = +tone.volumeStarts[#];\n\t\t\tvar operator#OutputDelta = +tone.volumeDeltas[#];\n\t\t\tvar operator#Output = +tone.feedbackOutputs[#];\n\t\t\tvar feedbackMult = +tone.feedbackMult;\n\t\t\tvar feedbackDelta = +tone.feedbackDelta;\n\t\t\tvar sample = +tone.sample;\n\t\t\t\n\t\t\tvar stopIndex = bufferIndex + runLength;\n\t\t\twhile (bufferIndex < stopIndex) {\n\t\t\t\tvar vibrato = 1.0 + vibratoScale * effectY;\n\t\t\t\tvar tremolo = 1.0 + tremoloScale * (effectY - 1.0);\n\t\t\t\tvar temp = effectY;\n\t\t\t\teffectY = effectYMult * effectY - prevEffectY;\n\t\t\t\tprevEffectY = temp;\n\t\t\t\t\n\t\t\t\t// INSERT OPERATOR COMPUTATION HERE\n\t\t\t\tsample = tremolo * (/*operator#Scaled*/); // CARRIER OUTPUTS\n\t\t\t\tfeedbackMult += feedbackDelta;\n\t\t\t\toperator#OutputMult += operator#OutputDelta;\n\t\t\t\toperator#Phase += operator#PhaseDelta * vibrato;\n\t\t\t\toperator#PhaseDelta *= phaseDeltaScale;\n\t\t\t\t\n\t\t\t\tdata[bufferIndex] += sample;\n\t\t\t\tbufferIndex++;\n\t\t\t}\n\t\t\t\n\t\t\ttone.phases[#] = operator#Phase / "+i.sineWaveLength+";\n\t\t\ttone.feedbackOutputs[#] = operator#Output;\n\t\t\ttone.sample = sample;\n\t\t").split("\n"),s.operatorSourceTemplate=("\n\t\t\t\tvar operator#PhaseMix = operator#Phase/* + operator@Scaled*/;\n\t\t\t\tvar operator#PhaseInt = operator#PhaseMix|0;\n\t\t\t\tvar operator#Index = operator#PhaseInt & "+i.sineWaveMask+";\n\t\t\t\tvar operator#Sample = sineWave[operator#Index];\n\t\t\t\toperator#Output = operator#Sample + (sineWave[operator#Index + 1] - operator#Sample) * (operator#PhaseMix - operator#PhaseInt);\n\t\t\t\tvar operator#Scaled = operator#OutputMult * operator#Output;\n\t\t").split("\n"),s}();t.Synth=c}(beepbox||(beepbox={})),function(t){var i=function(){function t(){this.M=[],this.k=!1}return t.prototype.watch=function(t){-1==this.M.indexOf(t)&&this.M.push(t)},t.prototype.unwatch=function(t){var i=this.M.indexOf(t);-1!=i&&this.M.splice(i,1)},t.prototype.changed=function(){this.k=!0},t.prototype.notifyWatchers=function(){if(this.k){this.k=!1;for(var t=0,i=this.M.concat();t<i.length;t++){(0,i[t])()}}},t}();t.ChangeNotifier=i}(beepbox||(beepbox={})),function(t){var i=function(){function i(i){var s=this;this.notifier=new t.ChangeNotifier,this.channel=0,this.bar=0,this.volume=75,this.trackVisibleBars=16,this.barScrollPos=0,this.prompt=null,this.N=null,this.R=0,this.L=0,this.S=0,this.I=!1,this.Z=!1,this.U=function(){var i=window.history.state;i&&i.sequenceNumber==s.R||(null==i?(s.R++,i={canUndo:!0,sequenceNumber:s.R,bar:s.bar,channel:s.channel,prompt:s.prompt},new t.ChangeSong(s,location.hash),window.history.replaceState(i,"","#"+s.song.toBase64String())):(i.sequenceNumber==s.R-1?(s.bar=s.L,s.channel=s.S):i.sequenceNumber!=s.R&&(s.bar=i.bar,s.channel=i.channel),s.R=i.sequenceNumber,s.prompt=i.prompt,new t.ChangeSong(s,location.hash)),s.L=i.bar,s.S=i.channel,s.forgetLastChange(),s.notifier.notifyWatchers())},this.j=function(){s.notifier.notifyWatchers()},this.Y=function(){s.Z=!1;var t,i="#"+s.song.toBase64String();s.I?(s.R++,t={canUndo:!0,sequenceNumber:s.R,bar:s.bar,channel:s.channel,prompt:s.prompt},window.history.pushState(t,"",i)):(t={canUndo:!0,sequenceNumber:s.R,bar:s.bar,channel:s.channel,prompt:s.prompt},window.history.replaceState(t,"",i)),s.L=t.bar,s.S=t.channel,s.I=!1},this.song=new t.Song(i),this.synth=new t.Synth(this.song),this.autoPlay="true"==localStorage.getItem("autoPlay"),this.autoFollow="true"==localStorage.getItem("autoFollow"),this.showFifth="true"==localStorage.getItem("showFifth"),this.showLetters="true"==localStorage.getItem("showLetters"),this.showChannels="true"==localStorage.getItem("showChannels"),this.showScrollBar="true"==localStorage.getItem("showScrollBar"),null!=localStorage.getItem("volume")&&(this.volume=Number(localStorage.getItem("volume"))),this.synth.volume=this.T();var e=window.history.state;null==e&&(e={canUndo:!1,sequenceNumber:0,bar:0,channel:0,prompt:null},window.history.replaceState(e,"","#"+this.song.toBase64String())),window.addEventListener("hashchange",this.U),window.addEventListener("popstate",this.U),this.bar=e.bar,this.channel=e.channel,this.L=e.bar,this.S=e.channel,this.barScrollPos=Math.max(0,this.bar-(this.trackVisibleBars-6)),this.prompt=e.prompt;for(var n=0,h=["input","change","click","keyup","keydown","mousedown","mousemove","mouseup","touchstart","touchmove","touchend","touchcancel"];n<h.length;n++){var r=h[n];window.addEventListener(r,this.j)}}return i.prototype.record=function(t,i){void 0===i&&(i=!1),t.isNoop()?(this.N=null,i&&window.history.back()):(this.N=t,i||(this.I=!0),this.Z||(window.requestAnimationFrame(this.Y),this.Z=!0))},i.prototype.openPrompt=function(t){this.prompt=t;var i="#"+this.song.toBase64String();this.R++;var s={canUndo:!0,sequenceNumber:this.R,bar:this.bar,channel:this.channel,prompt:this.prompt};window.history.pushState(s,"",i)},i.prototype.undo=function(){window.history.state.canUndo&&window.history.back()},i.prototype.redo=function(){window.history.forward()},i.prototype.setProspectiveChange=function(t){this.N=t},i.prototype.forgetLastChange=function(){this.N=null},i.prototype.lastChangeWas=function(t){return null!=t&&t==this.N},i.prototype.savePreferences=function(){localStorage.setItem("autoPlay",this.autoPlay?"true":"false"),localStorage.setItem("autoFollow",this.autoFollow?"true":"false"),localStorage.setItem("showFifth",this.showFifth?"true":"false"),localStorage.setItem("showLetters",this.showLetters?"true":"false"),localStorage.setItem("showChannels",this.showChannels?"true":"false"),localStorage.setItem("showScrollBar",this.showScrollBar?"true":"false"),localStorage.setItem("volume",String(this.volume))},i.prototype.setVolume=function(t){this.volume=t,this.savePreferences(),this.synth.volume=this.T()},i.prototype.T=function(){return Math.min(1,Math.pow(this.volume/50,.5))*Math.pow(2,(this.volume-75)/25)},i.prototype.getCurrentPattern=function(){return this.song.getPattern(this.channel,this.bar)},i.prototype.getCurrentInstrument=function(){var t=this.getCurrentPattern();return null==t?0:t.instrument},i.u=2,i}();t.SongDocument=i}(beepbox||(beepbox={})),function(t){!function(t){function i(t,i,s){var e=document.createElement(t);if(i)for(var n=0,h=Object.keys(i);n<h.length;n++){var r=h[n];"style"==r?e.setAttribute(r,i[r]):e[r]=i[r]}if(s)for(var o=0,a=s;o<a.length;o++){var l=a[o];e.appendChild(l)}return e}function s(t){return document.createTextNode(t)}t.element=i,t.button=function(t,s){return i("button",t,s)},t.div=function(t,s){return i("div",t,s)},t.span=function(t,s){return i("span",t,s)},t.select=function(t,s){return i("select",t,s)},t.option=function(t,i,e,n){void 0===e&&(e=!1),void 0===n&&(n=!1);var h=document.createElement("option");return h.value=t,h.selected=e,h.disabled=n,h.appendChild(s(i)),h},t.canvas=function(t){return i("canvas",t)},t.input=function(t){return i("input",t)},t.br=function(){return i("br")},t.text=s}(t.html||(t.html={}));var i="http://www.w3.org/2000/svg";t.svgElement=function(t,s,e){var n=document.createElementNS(i,t);if(s)for(var h=0,r=Object.keys(s);h<r.length;h++){var o=r[h];n.setAttribute(o,s[o])}if(e)for(var a=0,l=e;a<l.length;a++){var u=l[a];n.appendChild(u)}return n}}(beepbox||(beepbox={})),function(t){var i=document.createElement("style");i.type="text/css",i.appendChild(document.createTextNode('\n\n.beepboxEditor {\n\tdisplay: flex;\n\t-webkit-touch-callout: none;\n\t-webkit-user-select: none;\n\t-khtml-user-select: none;\n\t-moz-user-select: none;\n\t-ms-user-select: none;\n\tuser-select: none;\n\tposition: relative;\n\ttouch-action: manipulation;\n\tcursor: default;\n\tfont-size: small;\n\toverflow: hidden;\n}\n\n.beepboxEditor div {\n\tmargin: 0;\n\tpadding: 0;\n}\n\n.beepboxEditor .promptContainer {\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n\twidth: 100%;\n\theight: 100%;\n\tbackground: rgba(0,0,0,0.5);\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n}\n\n.beepboxEditor .prompt {\n\tmargin: auto;\n\ttext-align: center;\n\tbackground: #000;\n\tborder-radius: 15px;\n\tborder: 4px solid #444;\n\tcolor: #fff;\n\tpadding: 20px;\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .prompt > *:not(:first-child) {\n\tmargin-top: 1.5em;\n}\n\n/* Use psuedo-elements to add cross-browser up & down arrows to select elements: */\n.beepboxEditor .selectContainer {\n\tposition: relative;\n}\n.beepboxEditor .selectContainer:not(.menu)::before {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0.3em;\n\ttop: 0.4em;\n\tborder-bottom: 0.4em solid currentColor;\n\tborder-left: 0.3em solid transparent;\n\tborder-right: 0.3em solid transparent;\n\tpointer-events: none;\n}\n.beepboxEditor .selectContainer:not(.menu)::after {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0.3em;\n\tbottom: 0.4em;\n\tborder-top: 0.4em solid currentColor;\n\tborder-left: 0.3em solid transparent;\n\tborder-right: 0.3em solid transparent;\n\tpointer-events: none;\n}\n.beepboxEditor .selectContainer.menu::after {\n\tcontent: "";\n\tposition: absolute;\n\tright: 0.7em;\n\tmargin: auto;\n\ttop: 0;\n\tbottom: 0;\n\theight: 0;\n\tborder-top: 0.4em solid currentColor;\n\tborder-left: 0.3em solid transparent;\n\tborder-right: 0.3em solid transparent;\n\tpointer-events: none;\n}\n.beepboxEditor select {\n\tmargin: 0;\n\tpadding: 0 0.3em;\n\tdisplay: block;\n\theight: 2em;\n\tborder: none;\n\tborder-radius: 0.4em;\n\tbackground: #444444;\n\tcolor: inherit;\n\tfont-size: inherit;\n\tcursor: pointer;\n\tfont-family: inherit;\n\n\t-webkit-appearance:none;\n\t-moz-appearance: none;\n\tappearance: none;\n}\n.beepboxEditor .menu select {\n\tpadding: 0 2em;\n}\n.beepboxEditor select:focus {\n\tbackground: #777777;\n\toutline: none;\n}\n.beepboxEditor .menu select {\n\ttext-align: center;\n\ttext-align-last: center;\n}\n\n/* This makes it look better in firefox on my computer... What about others?\n@-moz-document url-prefix() {\n\t.beepboxEditor select { padding: 0 2px; }\n}\n*/\n.beepboxEditor button {\n\tmargin: 0;\n\tposition: relative;\n\theight: 2em;\n\tborder: none;\n\tborder-radius: 0.4em;\n\tbackground: #444;\n\tcolor: inherit;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\tcursor: pointer;\n}\n.beepboxEditor button:focus {\n\tbackground: #777;\n\toutline: none;\n}\n.beepboxEditor button.playButton, .beepboxEditor button.pauseButton {\n\tpadding-left: 2em;\n}\n.beepboxEditor button.playButton::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 0.7em;\n\ttop: 50%;\n\tmargin-top: -0.65em;\n\tborder-left: 1em solid currentColor;\n\tborder-top: 0.65em solid transparent;\n\tborder-bottom: 0.65em solid transparent;\n\tpointer-events: none;\n}\n.beepboxEditor button.pauseButton::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 0.7em;\n\ttop: 50%;\n\tmargin-top: -0.65em;\n\twidth: 0.3em;\n\theight: 1.3em;\n\tbackground: currentColor;\n\tpointer-events: none;\n}\n.beepboxEditor button.pauseButton::after {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 1.4em;\n\ttop: 50%;\n\tmargin-top: -0.65em;\n\twidth: 0.3em;\n\theight: 1.3em;\n\tbackground: currentColor;\n\tpointer-events: none;\n}\n\n.beepboxEditor button.prevBarButton::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: -0.5em;\n\tmargin-top: -0.5em;\n\twidth: 0.2em;\n\theight: 1em;\n\tbackground: currentColor;\n\tpointer-events: none;\n}\n.beepboxEditor button.prevBarButton::after {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: -0.3em;\n\tmargin-top: -0.5em;\n\tborder-right: 0.8em solid currentColor;\n\tborder-top: 0.5em solid transparent;\n\tborder-bottom: 0.5em solid transparent;\n\tpointer-events: none;\n}\n\n.beepboxEditor button.nextBarButton::before {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: -0.5em;\n\tmargin-top: -0.5em;\n\tborder-left: 0.8em solid currentColor;\n\tborder-top: 0.5em solid transparent;\n\tborder-bottom: 0.5em solid transparent;\n\tpointer-events: none;\n}\n.beepboxEditor button.nextBarButton::after {\n\tcontent: "";\n\tposition: absolute;\n\tleft: 50%;\n\ttop: 50%;\n\tmargin-left: 0.3em;\n\tmargin-top: -0.5em;\n\twidth: 0.2em;\n\theight: 1em;\n\tbackground: currentColor;\n\tpointer-events: none;\n}\n\n.beepboxEditor canvas {\n\toverflow: hidden;\n\tposition: absolute;\n\tdisplay: block;\n}\n\n.beepboxEditor .trackContainer {\n\toverflow-x: hidden;\n}\n\n.beepboxEditor .selectRow {\n\tmargin: 0;\n\theight: 2.5em;\n\tdisplay: flex;\n\tflex-direction: row;\n\talign-items: center;\n\tjustify-content: space-between;\n}\n\n.beepboxEditor .selectRow > span {\n\tcolor: #999;\n}\n\n.beepboxEditor .operatorRow {\n\tmargin: 0;\n\theight: 2.5em;\n\tdisplay: flex;\n\tflex-direction: row;\n\talign-items: center;\n}\n\n.beepboxEditor .operatorRow > * {\n\tflex-grow: 1;\n\tflex-shrink: 1;\n}\n\n.beepboxEditor .editor-widget-column {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-widgets {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-controls {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-menus {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-settings {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-song-settings {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-instrument-settings {\n\tdisplay: flex;\n\tflex-direction: column;\n}\n\n.beepboxEditor .editor-right-side-top > *, .beepboxEditor .editor-right-side-bottom > * {\n\tflex-shrink: 0;\n}\n\n.beepboxEditor input[type=text], .beepboxEditor input[type=number] {\n\tfont-size: inherit;\n\tbackground: transparent;\n\tborder: 1px solid #777;\n\tcolor: white;\n}\n\n.beepboxEditor input[type=checkbox] {\n transform: scale(1.5);\n}\n\n.beepboxEditor input[type=range] {\n\t-webkit-appearance: none;\n\tcolor: inherit;\n\twidth: 100%;\n\theight: 2em;\n\tfont-size: inherit;\n\tmargin: 0;\n\tcursor: pointer;\n\tbackground-color: black;\n\ttouch-action: pan-y;\n}\n.beepboxEditor input[type=range]:focus {\n\toutline: none;\n}\n.beepboxEditor input[type=range]::-webkit-slider-runnable-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: #444;\n}\n.beepboxEditor input[type=range]::-webkit-slider-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tbackground: currentColor;\n\tcursor: pointer;\n\t-webkit-appearance: none;\n\tmargin-top: -0.75em;\n}\n.beepboxEditor input[type=range]:focus::-webkit-slider-runnable-track {\n\tbackground: #777;\n}\n.beepboxEditor input[type=range]::-moz-range-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: #444;\n}\n.beepboxEditor input[type=range]:focus::-moz-range-track {\n\tbackground: #777;\n}\n.beepboxEditor input[type=range]::-moz-range-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tborder: none;\n\tbackground: currentColor;\n\tcursor: pointer;\n}\n.beepboxEditor input[type=range]::-ms-track {\n\twidth: 100%;\n\theight: 0.5em;\n\tcursor: pointer;\n\tbackground: #444;\n\tborder-color: transparent;\n}\n.beepboxEditor input[type=range]:focus::-ms-track {\n\tbackground: #777;\n}\n.beepboxEditor input[type=range]::-ms-thumb {\n\theight: 2em;\n\twidth: 0.5em;\n\tborder-radius: 0.25em;\n\tbackground: currentColor;\n\tcursor: pointer;\n}\n.beepboxEditor .hintButton {\n\tborder: 1px solid currentColor;\n\tborder-radius: 50%;\n\ttext-decoration: none;\n\twidth: 1em;\n\theight: 1em;\n\ttext-align: center;\n\tmargin-left: auto;\n\tmargin-right: .4em;\n\tcursor: pointer;\n}\n\n/* wide screen */\n@media (min-width: 701px) {\n\t#beepboxEditorContainer {\n\t\tdisplay: table;\n\t}\n\t.beepboxEditor {\n\t\tflex-direction: row;\n\t}\n\t.beepboxEditor:focus-within {\n\t\toutline: 3px solid #555;\n\t}\n\t.beepboxEditor .trackContainer {\n\t\twidth: 512px;\n\t}\n\t.beepboxEditor .trackSelectBox {\n\t\tdisplay: none;\n\t}\n\t.beepboxEditor .playback-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t}\n\t.beepboxEditor .playback-bar-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: .2em 0;\n\t}\n\t.beepboxEditor .playback-volume-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: .2em 0;\n\t\talign-items: center;\n\t}\n\t.beepboxEditor .pauseButton, .beepboxEditor .playButton {\n\t\tflex-grow: 1;\n\t}\n\t.beepboxEditor .nextBarButton, .beepboxEditor .prevBarButton {\n\t\tflex-grow: 1;\n\t\tmargin-left: 10px;\n\t}\n\t.beepboxEditor .editor-widget-column {\n\t\tmargin-left: 6px;\n\t\twidth: 14em;\n\t\tflex-direction: column;\n\t}\n\t.beepboxEditor .editor-widgets {\n\t\tflex-grow: 1;\n\t}\n\t.beepboxEditor .editor-settings input, .beepboxEditor .editor-settings select {\n\t\twidth: 8.6em;\n\t}\n\t.beepboxEditor .editor-menus > * {\n\t\tflex-grow: 1;\n\t\tmargin: .2em 0;\n\t}\n\t.beepboxEditor .editor-menus > button {\n\t\tpadding: 0 2em;\n\t\twhite-space: nowrap;\n\t}\n}\n\n/* narrow screen */\n@media (max-width: 700px) {\n\t.beepboxEditor {\n\t\tflex-direction: column;\n\t}\n\t.beepboxEditor:focus-within {\n\t\toutline: none;\n\t}\n\t.beepboxEditor .editorBox {\n\t\tmax-height: 75vh;\n\t}\n\t.beepboxEditor .editor-menus {\n\t\tflex-direction: row;\n\t}\n\t.beepboxEditor .editor-menus > * {\n\t\tflex-grow: 1;\n\t\tmargin: .2em;\n\t}\n\t.beepboxEditor .editor-menus > button {\n\t\tpadding-left: 2em;\n\t\twhite-space: nowrap;\n\t}\n\t.beepboxEditor .trackContainer {\n\t\toverflow-x: auto;\n\t}\n\t.beepboxEditor .barScrollBar {\n\t\tdisplay: none;\n\t}\n\t.beepboxEditor .playback-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tmargin: .2em 0;\n\t}\n\t.beepboxEditor .playback-bar-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tflex-grow: 1;\n\t}\n\t.beepboxEditor .playback-volume-controls {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\talign-items: center;\n\t\tflex-grow: 1;\n\t\tmargin: 0 .2em;\n\t}\n\t.beepboxEditor .editor-widget-column {\n\t\tflex-direction: column-reverse;\n\t}\n\t.beepboxEditor .editor-settings {\n\t\tflex-direction: row;\n\t}\n\t.beepboxEditor .pauseButton, .beepboxEditor .playButton,\n\t.beepboxEditor .nextBarButton, .beepboxEditor .prevBarButton {\n\t\tflex-grow: 1;\n\t\tmargin: 0 .2em;\n\t}\n\t.beepboxEditor .editor-song-settings, .beepboxEditor .editor-instrument-settings {\n\t\tflex-grow: 1;\n\t\tmargin: 0 .2em;\n\t}\n\t.beepboxEditor .editor-settings input, .beepboxEditor .editor-settings .selectContainer {\n\t\twidth: 60%;\n\t}\n\t.beepboxEditor .editor-settings select {\n\t\twidth: 100%;\n\t}\n\t.fullWidthOnly {\n\t\tdisplay: none;\n\t}\n\tp {\n\t\tmargin: 1em 0.5em;\n\t}\n}\n\n')),document.head.appendChild(i)}(beepbox||(beepbox={})),function(t){var i=function(){function t(){this.V=!0}return t.prototype.P=function(){this.V=!1},t.prototype.isNoop=function(){return this.V},t}();t.Change=i;var s=function(t){function i(i){var s=t.call(this)||this;return s.O=i,s.W=!i,s}return __extends(i,t),i.prototype.undo=function(){this.O?(this.J(),this.W=!0):(this.H(),this.W=!1)},i.prototype.redo=function(){this.O?(this.H(),this.W=!1):(this.J(),this.W=!0)},i.prototype.X=function(){return this.W},i.prototype.J=function(){throw new Error("Change.doForwards(): Override me.")},i.prototype.H=function(){throw new Error("Change.doBackwards(): Override me.")},i}(i);t.UndoableChange=s;var e=function(t){function i(){return t.call(this)||this}return __extends(i,t),i.prototype.append=function(t){t.isNoop()||this.P()},i}(i);t.ChangeGroup=e;var n=function(t){function i(i){var s=t.call(this,!1)||this;return s._=void 0==i?[]:i.concat(),s}return __extends(i,t),i.prototype.append=function(t){t.isNoop()||(this._[this._.length]=t,this.P())},i.prototype.J=function(){for(var t=0;t<this._.length;t++)this._[t].redo()},i.prototype.H=function(){for(var t=this._.length-1;t>=0;t--)this._[t].undo()},i}(s);t.ChangeSequence=n}(beepbox||(beepbox={})),function(t){var i=function(t){function i(i,s){var e=t.call(this,!1)||this;return e.K=i,e.q=s,e.$=e.q.start,e.tt=e.q.end,e.it=e.q.start,e.st=e.q.end,e.et=e.q.pins,e.nt=[],e.ht=e.q.pitches,e.rt=[],e}return __extends(i,t),i.prototype.ot=function(){for(var t=0;t<this.nt.length-1;)this.nt[t].time>=this.nt[t+1].time?this.nt.splice(t,1):t++;for(t=1;t<this.nt.length-1;)this.nt[t-1].interval==this.nt[t].interval&&this.nt[t].interval==this.nt[t+1].interval&&this.nt[t-1].volume==this.nt[t].volume&&this.nt[t].volume==this.nt[t+1].volume?this.nt.splice(t,1):t++;var i=this.nt[0].interval,s=this.nt[0].time;for(t=0;t<this.ht.length;t++)this.rt[t]=this.ht[t]+i;for(t=0;t<this.nt.length;t++)this.nt[t].interval-=i,this.nt[t].time-=s;this.it=this.$+s,this.st=this.it+this.nt[this.nt.length-1].time,this.J(),this.P()},i.prototype.J=function(){this.q.pins=this.nt,this.q.pitches=this.rt,this.q.start=this.it,this.q.end=this.st,this.K.notifier.changed()},i.prototype.H=function(){this.q.pins=this.et,this.q.pitches=this.ht,this.q.start=this.$,this.q.end=this.tt,this.K.notifier.changed()},i}(t.UndoableChange);t.ChangePins=i;var s=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].type!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].type=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeInstrumentType=s;var e=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].transition!=s&&(e.P(),i.song.channels[i.channel].instruments[i.getCurrentInstrument()].transition=s,i.notifier.changed()),e}return __extends(i,t),i}(t.Change);t.ChangeTransition=e;var n=function(t){function i(i,s,e){var n=t.call(this)||this;if(n.oldValue=s,e>i.song.patternsPerChannel)throw new Error("invalid pattern");return i.song.channels[i.channel].bars[i.bar]=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangePattern=n;var h=function(t){function i(i,s){var e=t.call(this)||this;if(i.song.barCount!=s){for(var n=0;n<i.song.getChannelCount();n++){for(var h=i.song.barCount;h<s;h++)i.song.channels[n].bars[h]=1;i.song.channels[n].bars.length=s}var r=i.bar,o=i.barScrollPos,a=i.song.loopStart,l=i.song.loopLength;i.song.barCount>s&&(r=Math.min(r,s-1),o=Math.max(0,Math.min(s-i.trackVisibleBars,o)),l=Math.min(s,l),a=Math.min(s-l,a)),i.bar=r,i.barScrollPos=o,i.song.loopStart=a,i.song.loopLength=l,i.song.barCount=s,i.notifier.changed(),e.P()}return e}return __extends(i,t),i}(t.Change);t.ChangeBarCount=h;var r=function(i){function s(s,e,n){var h=i.call(this)||this;if(s.song.pitchChannelCount!=e||s.song.drumChannelCount!=n){for(var r=[],o=0;o<e;o++){var a=o,l=o;if(o<s.song.pitchChannelCount)r[a]=s.song.channels[l];else{r[a]=new t.Channel,r[a].octave=2;for(var u=0;u<s.song.instrumentsPerChannel;u++){(f=new t.Instrument).setTypeAndReset(0),r[a].instruments[u]=f}for(u=0;u<s.song.patternsPerChannel;u++)r[a].patterns[u]=new t.Pattern;for(u=0;u<s.song.barCount;u++)r[a].bars[u]=1}}for(o=0;o<n;o++){a=o+e,l=o+s.song.pitchChannelCount;if(o<s.song.drumChannelCount)r[a]=s.song.channels[l];else{r[a]=new t.Channel,r[a].octave=0;for(u=0;u<s.song.instrumentsPerChannel;u++){var f;(f=new t.Instrument).setTypeAndReset(2),r[a].instruments[u]=f}for(u=0;u<s.song.patternsPerChannel;u++)r[a].patterns[u]=new t.Pattern;for(u=0;u<s.song.barCount;u++)r[a].bars[u]=1}}s.song.pitchChannelCount=e,s.song.drumChannelCount=n;for(a=0;a<s.song.getChannelCount();a++)s.song.channels[a]=r[a];s.song.channels.length=s.song.getChannelCount(),s.channel=Math.min(s.channel,e+n-1),s.notifier.changed(),h.P()}return h}return __extends(s,i),s}(t.Change);t.ChangeChannelCount=r;var o=function(i){function s(s,e){var n=i.call(this)||this;if(s.song.beatsPerBar!=e){if(s.song.beatsPerBar>e)for(var h=new t.ChangeSequence,r=0;r<s.song.getChannelCount();r++)for(var o=0;o<s.song.channels[r].patterns.length;o++)h.append(new D(s,s.song.channels[r].patterns[o],e*s.song.partsPerBeat,s.song.beatsPerBar*s.song.partsPerBeat));s.song.beatsPerBar=e,s.notifier.changed(),n.P()}return n}return __extends(s,i),s}(t.Change);t.ChangeBeatsPerBar=o;var a=function(t){function i(i,s,e){var n=t.call(this)||this,h=i.channel,r=i.bar;return i.channel=s,i.bar=e,i.barScrollPos=Math.min(i.bar,Math.max(i.bar-(i.trackVisibleBars-1),i.barScrollPos)),i.notifier.changed(),h==s&&r==e||n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeChannelBar=a;var l=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].chorus!=s&&(e.P(),i.song.channels[i.channel].instruments[i.getCurrentInstrument()].chorus=s,i.notifier.changed()),e}return __extends(i,t),i}(t.Change);t.ChangeChorus=l;var u=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].effect!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].effect=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeEffect=u;var f=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].filter!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].filter=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeFilter=f;var c=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].algorithm!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].algorithm=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeAlgorithm=c;var d=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].feedbackType!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].feedbackType=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeFeedbackType=d;var v=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].feedbackEnvelope!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].feedbackEnvelope=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeFeedbackEnvelope=v;var p=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].operators[s].envelope!=e&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].operators[s].envelope=e,i.notifier.changed(),n.P()),n}return __extends(i,t),i}(t.Change);t.ChangeOperatorEnvelope=p;var b=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].operators[s].frequency!=e&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].operators[s].frequency=e,i.notifier.changed(),n.P()),n}return __extends(i,t),i}(t.Change);t.ChangeOperatorFrequency=b;var m=function(t){function i(i,s,e,n){var h=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].operators[s].amplitude=n,i.notifier.changed(),e!=n&&h.P(),h}return __extends(i,t),i}(t.Change);t.ChangeOperatorAmplitude=m;var w=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].feedbackAmplitude=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeFeedbackAmplitude=w;var g=function(i){function s(s,e){var n=i.call(this)||this;if(s.song.instrumentsPerChannel!=e){for(var h=0;h<s.song.getChannelCount();h++){for(var r=s.song.channels[h].instruments[s.song.instrumentsPerChannel-1],o=s.song.instrumentsPerChannel;o<e;o++){var a=new t.Instrument;a.copy(r),s.song.channels[h].instruments[o]=a}s.song.channels[h].instruments.length=e;for(o=0;o<s.song.patternsPerChannel;o++)s.song.channels[h].patterns[o].instrument>=e&&(s.song.channels[h].patterns[o].instrument=0)}s.song.instrumentsPerChannel=e,s.notifier.changed(),n.P()}return n}return __extends(s,i),s}(t.Change);t.ChangeInstrumentsPerChannel=g;var x=function(t){function i(i,s){var e=t.call(this)||this;return i.song.key!=s&&(i.song.key=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeKey=x;var y=function(t){function i(i,s,e,n,h){var r=t.call(this)||this;return r.K=i,r.oldStart=s,r.oldLength=e,r.newStart=n,r.newLength=h,r.K.song.loopStart=r.newStart,r.K.song.loopLength=r.newLength,r.K.notifier.changed(),r.oldStart==r.newStart&&r.oldLength==r.newLength||r.P(),r}return __extends(i,t),i}(t.Change);t.ChangeLoop=y;var M=function(t){function i(i,s,e,n,h){void 0===h&&(h=!1);var r=t.call(this,h)||this;return r.K=i,r.q=s,r.at=e,r.lt=n,r.P(),r.redo(),r}return __extends(i,t),i.prototype.J=function(){this.q.pitches.splice(this.lt,0,this.at),this.K.notifier.changed()},i.prototype.H=function(){this.q.pitches.splice(this.lt,1),this.K.notifier.changed()},i}(t.UndoableChange);t.ChangePitchAdded=M;var k=function(t){function i(i,s,e){var n=t.call(this)||this;return n.oldValue=s,i.song.channels[i.channel].octave=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeOctave=k;var A=function(t){function i(i,s){var e=t.call(this)||this;if(i.song.partsPerBeat!=s){for(var n=0;n<i.song.getChannelCount();n++)for(var h=0;h<i.song.channels[n].patterns.length;h++)e.append(new S(i,i.song.channels[n].patterns[h],i.song.partsPerBeat,s));i.song.partsPerBeat=s,i.notifier.changed(),e.P()}return e}return __extends(i,t),i}(t.ChangeGroup);t.ChangePartsPerBeat=A;var E=function(t){function i(i,s,e,n,h){var r=t.call(this)||this;return s.notes=e,i.song.partsPerBeat!=h&&r.append(new S(i,s,h,i.song.partsPerBeat)),i.song.beatsPerBar!=n&&r.append(new D(i,s,i.song.beatsPerBar*i.song.partsPerBeat,n*i.song.partsPerBeat)),i.notifier.changed(),r.P(),r}return __extends(i,t),i}(t.ChangeGroup);t.ChangePaste=E;var N=function(t){function i(i,s,e){var n=t.call(this)||this;return e.instrument!=s&&(e.instrument=s,i.notifier.changed(),n.P()),n}return __extends(i,t),i}(t.Change);t.ChangePatternInstrument=N;var B=function(i){function s(s,e){var n=i.call(this)||this;if(s.song.patternsPerChannel!=e){for(var h=0;h<s.song.getChannelCount();h++){for(var r=s.song.channels[h].bars,o=s.song.channels[h].patterns,a=0;a<r.length;a++)r[a]>e&&(r[a]=0);for(a=o.length;a<e;a++)o[a]=new t.Pattern;o.length=e}s.song.patternsPerChannel=e,s.notifier.changed(),n.P()}return n}return __extends(s,i),s}(t.Change);t.ChangePatternsPerChannel=B;var R=function(i){function s(s,e,n,h){var r=i.call(this,s,e)||this;h-=r.$;for(var o=r.et[n].time,a=Math.min(o,h),l=Math.max(o,h),u=!1,f=0;f<r.et.length;f++){var c=e.pins[f],d=c.time;d<a?r.nt.push(t.makeNotePin(c.interval,d,c.volume)):d>l&&(u||(r.nt.push(t.makeNotePin(r.et[n].interval,h,r.et[n].volume)),u=!0),r.nt.push(t.makeNotePin(c.interval,d,c.volume)))}return u||r.nt.push(t.makeNotePin(r.et[n].interval,h,r.et[n].volume)),r.ot(),r}return __extends(s,i),s}(i);t.ChangePinTime=R;var L=function(i){function s(s,e,n,h,r,o){var a=i.call(this,s,e)||this;n-=a.$,h-=a.$,r-=e.pitches[o];var l,u,f,c,d=!1,v=!1,p=0,b=3,m=!0;for(h>n?(l=0,u=1,f=e.pins.length,c=function(t){a.nt.push(t)}):(l=e.pins.length-1,u=-1,f=-1,c=function(t){a.nt.unshift(t)});l!=f;l+=u)for(var w=e.pins[l],g=w.time;;)if(d){if(v){if(g*u==h*u)break;w.interval!=p&&(m=!1),c(t.makeNotePin(m?r:w.interval,g,w.volume));break}if(g*u<=h*u&&(p=w.interval,b=w.volume),g*u<h*u)break;c(t.makeNotePin(r,h,b)),v=!0}else{if(g*u<=n*u&&(p=w.interval,b=w.volume),g*u<n*u){c(t.makeNotePin(w.interval,g,w.volume));break}c(t.makeNotePin(p,n,b)),d=!0}return v||c(t.makeNotePin(r,h,b)),a.ot(),a}return __extends(s,i),s}(i);t.ChangePitchBend=L;var S=function(t){function i(i,s,e,n){var h,r=t.call(this)||this;if(e>n)h=function(t){return Math.ceil(t*n/e)};else{if(!(e<n))throw new Error("ChangeRhythm couldn't handle rhythm change from "+e+" to "+n+".");h=function(t){return Math.floor(t*n/e)}}for(var o=0;o<s.notes.length;){var a=s.notes[o];h(a.start)>=h(a.end)?r.append(new j(i,s,a,o,!0)):(r.append(new I(i,a,h)),o++)}return r}return __extends(i,t),i}(t.ChangeSequence);t.ChangeRhythm=S;var I=function(i){function s(s,e,n){for(var h=i.call(this,s,e)||this,r=0,o=h.et;r<o.length;r++){var a=o[r];h.nt.push(t.makeNotePin(a.interval,n(a.time+h.$)-h.$,a.volume))}return h.ot(),h}return __extends(s,i),s}(i);t.ChangeRhythmNote=I;var Z=function(t){function i(i,s){var e=t.call(this)||this;return i.song.scale!=s&&(i.song.scale=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeScale=Z;var C=function(t){function i(i,s){var e=t.call(this)||this;return i.song.fromBase64String(s),i.channel=Math.min(i.channel,i.song.getChannelCount()-1),i.bar=Math.max(0,Math.min(i.song.barCount-1,i.bar)),i.barScrollPos=Math.max(0,Math.min(i.song.barCount-i.trackVisibleBars,i.barScrollPos)),i.barScrollPos=Math.min(i.bar,Math.max(i.bar-(i.trackVisibleBars-1),i.barScrollPos)),i.notifier.changed(),e.P(),e}return __extends(i,t),i}(t.Change);t.ChangeSong=C;var G=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.tempo=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeTempo=G;var U=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.reverb=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeReverb=U;var j=function(t){function i(i,s,e,n,h){void 0===h&&(h=!1);var r=t.call(this,h)||this;return r.K=i,r.ut=s,r.q=e,r.lt=n,r.P(),r.redo(),r}return __extends(i,t),i.prototype.J=function(){this.ut.notes.splice(this.lt,0,this.q),this.K.notifier.changed()},i.prototype.H=function(){this.ut.notes.splice(this.lt,1),this.K.notifier.changed()},i}(t.UndoableChange);t.ChangeNoteAdded=j;var z=function(i){function s(s,e,n,h){var r=i.call(this,s,e)||this;n-=r.$,h-=r.$;var o,a=!1,l=r.et[0].volume,u=r.et[0].interval,f=!0;for(o=0;o<r.et.length;o++){var c=r.et[o];if(c.time<n)l=c.volume,u=c.interval;else{if(!(c.time<=h))break;if(c.time>n&&!a&&r.nt.push(t.makeNotePin(u,n,l)),r.nt.push(t.makeNotePin(c.interval,c.time,c.volume)),a=!0,c.time==h){f=!1;break}}}return f&&r.nt.push(t.makeNotePin(r.et[o].interval,h,r.et[o].volume)),r.ot(),r}return __extends(s,i),s}(i);t.ChangeNoteLength=z;var D=function(t){function i(i,s,e,n,h){for(var r=t.call(this)||this,o=0;o<s.notes.length;){var a=s.notes[o];if(a==h&&void 0!=h)o++;else if(a.end<=e)o++;else{if(a.start>=n)break;a.start<e?(r.append(new z(i,a,a.start,e)),o++):a.end>n?(r.append(new z(i,a,n,a.end)),o++):r.append(new j(i,s,a,o,!0))}}return r}return __extends(i,t),i}(t.ChangeSequence);t.ChangeNoteTruncate=D;var Y=function(i){function s(s,e,n){var h=i.call(this,!1)||this;h.K=s,h.q=e,h.et=e.pins,h.nt=[],h.ht=e.pitches,h.rt=[];for(var r=s.song.getChannelIsDrum(s.channel)?t.Config.drumCount-1:t.Config.maxPitch,o=0;o<h.ht.length;o++){var a=h.ht[o];if(n){for(var l=a+1;l<=r;l++)if(s.song.getChannelIsDrum(s.channel)||t.Config.scaleFlags[s.song.scale][l%12]){a=l;break}}else for(l=a-1;l>=0;l--)if(s.song.getChannelIsDrum(s.channel)||t.Config.scaleFlags[s.song.scale][l%12]){a=l;break}var u=!1;for(l=0;l<h.rt.length;l++)if(h.rt[l]==a){u=!0;break}u||h.rt.push(a)}var f=0,c=r;for(o=1;o<h.rt.length;o++){var d=h.rt[0]-h.rt[o];f<d&&(f=d),c>d+r&&(c=d+r)}for(var v=0,p=h.et;v<p.length;v++){var b=p[v],m=b.interval+h.ht[0];if(m<f&&(m=f),m>c&&(m=c),n){for(o=m+1;o<=c;o++)if(s.song.getChannelIsDrum(s.channel)||t.Config.scaleFlags[s.song.scale][o%12]){m=o;break}}else for(o=m-1;o>=f;o--)if(s.song.getChannelIsDrum(s.channel)||t.Config.scaleFlags[s.song.scale][o%12]){m=o;break}m-=h.rt[0],h.nt.push(t.makeNotePin(m,b.time,b.volume))}if(0!=h.nt[0].interval)throw new Error("wrong pin start interval");for(o=1;o<h.nt.length-1;)h.nt[o-1].interval==h.nt[o].interval&&h.nt[o].interval==h.nt[o+1].interval&&h.nt[o-1].volume==h.nt[o].volume&&h.nt[o].volume==h.nt[o+1].volume?h.nt.splice(o,1):o++;return h.J(),h.P(),h}return __extends(s,i),s.prototype.J=function(){this.q.pins=this.nt,this.q.pitches=this.rt,this.K.notifier.changed()},s.prototype.H=function(){this.q.pins=this.et,this.q.pitches=this.ht,this.K.notifier.changed()},s}(t.UndoableChange);t.ChangeTransposeNote=Y;var T=function(t){function i(i,s,e){for(var n=t.call(this)||this,h=0;h<s.notes.length;h++)n.append(new Y(i,s.notes[h],e));return n}return __extends(i,t),i}(t.ChangeSequence);t.ChangeTranspose=T;var F=function(t){function i(i,s,e){var n=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].volume=e,i.notifier.changed(),s!=e&&n.P(),n}return __extends(i,t),i}(t.Change);t.ChangeVolume=F;var V=function(i){function s(s,e,n,h,r){var o=i.call(this,!1)||this;o.K=s,o.q=e,o.et=e.pins,o.nt=[];for(var a=!1,l=0,u=e.pins;l<u.length;l++){var f=u[l];f.time<n?o.nt.push(f):f.time==n?(o.nt.push(t.makeNotePin(r,n,h)),a=!0):(a||(o.nt.push(t.makeNotePin(r,n,h)),a=!0),o.nt.push(f))}for(var c=1;c<o.nt.length-1;)o.nt[c-1].interval==o.nt[c].interval&&o.nt[c].interval==o.nt[c+1].interval&&o.nt[c-1].volume==o.nt[c].volume&&o.nt[c].volume==o.nt[c+1].volume?o.nt.splice(c,1):c++;return o.J(),o.P(),o}return __extends(s,i),s.prototype.J=function(){this.q.pins=this.nt,this.K.notifier.changed()},s.prototype.H=function(){this.q.pins=this.et,this.K.notifier.changed()},s}(t.UndoableChange);t.ChangeVolumeBend=V;var P=function(t){function i(i,s){var e=t.call(this)||this;return i.song.channels[i.channel].instruments[i.getCurrentInstrument()].wave!=s&&(i.song.channels[i.channel].instruments[i.getCurrentInstrument()].wave=s,i.notifier.changed(),e.P()),e}return __extends(i,t),i}(t.Change);t.ChangeWave=P}(beepbox||(beepbox={})),function(t){function i(t){return t.toFixed(2).replace(/\.?0*$/,"")}var s=function(){return function(){this.valid=!1,this.prevNote=null,this.curNote=null,this.nextNote=null,this.pitch=0,this.pitchIndex=-1,this.curIndex=0,this.start=0,this.end=0,this.part=0,this.notePart=0,this.nearPinIndex=0,this.pins=[]}}(),e=function(){function e(e){var n=this;this.K=e,this.ft=t.svgElement("pattern",{id:"patternEditorNoteBackground",x:"0",y:"0",width:"64",height:"156",patternUnits:"userSpaceOnUse"}),this.ct=t.svgElement("pattern",{id:"patternEditorDrumBackground",x:"0",y:"0",width:"64",height:"40",patternUnits:"userSpaceOnUse"}),this.dt=t.svgElement("rect",{x:"0",y:"0",width:"512",height:"481","pointer-events":"none",fill:"url(#patternEditorNoteBackground)"}),this.vt=t.svgElement("svg"),this.pt=t.svgElement("rect",{id:"",x:"0",y:"0",width:"4",height:"481",fill:"white","pointer-events":"none"}),this.bt=t.svgElement("path",{fill:"none",stroke:"white","stroke-width":"2","pointer-events":"none"}),this.wt=t.svgElement("svg",{style:"background-color: #000000; touch-action: none; position: absolute;",width:"100%",height:"100%",viewBox:"0 0 512 481",preserveAspectRatio:"none"},[t.svgElement("defs",void 0,[this.ft,this.ct]),this.dt,this.vt,this.bt,this.pt]),this.container=t.html.div({style:"height: 100%; overflow:hidden; position: relative; flex-grow: 1;"},[this.wt]),this.gt=13,this.xt=40,this.yt=[],this.Mt=t.svgElement("rect"),this.kt=[[t.makeNotePin(0,0,3),t.makeNotePin(0,2,3)],[t.makeNotePin(0,0,3),t.makeNotePin(0,2,3)],[t.makeNotePin(0,0,3),t.makeNotePin(0,2,3)],[t.makeNotePin(0,0,3),t.makeNotePin(0,2,0)]],this.At=481,this.Et=0,this.Nt=0,this.Bt=!1,this.Rt=!1,this.Lt=!1,this.St=!1,this.It=!1,this.Zt=[],this.Ct=0,this.Gt=0,this.Ut=0,this.jt=0,this.zt=0,this.Dt=0,this.Yt=0,this.Tt=!1,this.Ft=null,this.Vt=new s,this.ut=null,this.Pt=0,this.Ot=0,this.Wt=-1,this.Jt=-1,this.Qt=!1,this.Ht=!1,this.Xt=-1,this._t=-1,this.Kt=-1,this.qt=-1,this.resetCopiedPins=function(){var i=n.$t();n.Zt.length=n.K.song.getChannelCount();for(var s=0;s<n.K.song.pitchChannelCount;s++)n.Zt[s]=[t.makeNotePin(0,0,3),t.makeNotePin(0,i,3)];for(s=n.K.song.pitchChannelCount;s<n.K.song.getChannelCount();s++)n.Zt[s]=[t.makeNotePin(0,0,3),t.makeNotePin(0,i,0)]},this.ti=function(s){var e=Math.floor(n.K.synth.playhead);if(n.K.synth.playing&&null!=n.ut&&n.K.song.getPattern(n.K.channel,Math.floor(n.K.synth.playhead))==n.ut){n.pt.setAttribute("visibility","visible");var h=n.K.synth.playhead-e;Math.abs(h-n.Pt)>.1?n.Pt=h:n.Pt+=.2*(h-n.Pt),n.pt.setAttribute("x",""+i(n.Pt*n.ii-2))}else n.pt.setAttribute("visibility","hidden");n.K.synth.playing&&n.K.autoFollow&&n.qt!=e&&(new t.ChangeChannelBar(n.K,n.K.channel,e),n.K.notifier.notifyWatchers()),n.qt=e,window.requestAnimationFrame(n.ti)},this.si=function(t){n.Rt||(n.Rt=!0,n.It=!1)},this.ei=function(t){n.Rt&&(n.Rt=!1)},this.ni=function(t){if(t.preventDefault(),null!=n.ut){var i=n.wt.getBoundingClientRect();n.Et=((t.clientX||t.pageX)-i.left)*n.ii/(i.right-i.left),n.Nt=((t.clientY||t.pageY)-i.top)*n.At/(i.bottom-i.top),isNaN(n.Et)&&(n.Et=0),isNaN(n.Nt)&&(n.Nt=0),n.It=!1,n.hi()}},this.ri=function(t){if(t.preventDefault(),null!=n.ut){var i=n.wt.getBoundingClientRect();n.Et=(t.touches[0].clientX-i.left)*n.ii/(i.right-i.left),n.Nt=(t.touches[0].clientY-i.top)*n.At/(i.bottom-i.top),isNaN(n.Et)&&(n.Et=0),isNaN(n.Nt)&&(n.Nt=0),n.It=!0,n.hi()}},this.oi=function(t){var i=n.wt.getBoundingClientRect();n.Et=((t.clientX||t.pageX)-i.left)*n.ii/(i.right-i.left),n.Nt=((t.clientY||t.pageY)-i.top)*n.At/(i.bottom-i.top),isNaN(n.Et)&&(n.Et=0),isNaN(n.Nt)&&(n.Nt=0),n.It=!1,n.ai()},this.li=function(t){if(n.Bt){t.preventDefault();var i=n.wt.getBoundingClientRect();n.Et=(t.touches[0].clientX-i.left)*n.ii/(i.right-i.left),n.Nt=(t.touches[0].clientY-i.top)*n.At/(i.bottom-i.top),isNaN(n.Et)&&(n.Et=0),isNaN(n.Nt)&&(n.Nt=0),n.ai()}},this.ui=function(i){if(n.Vt.valid&&null!=n.ut){var s=n.K.lastChangeWas(n.Ft);if(n.Lt&&s)null!=n.Ft&&(n.K.record(n.Ft),n.Ft=null);else if(n.Bt&&s)if(null==n.Vt.curNote){var e=t.makeNote(n.Vt.pitch,n.Vt.start,n.Vt.end,3,n.K.song.getChannelIsDrum(n.K.channel));e.pins=[];for(var h=0,r=n.Vt.pins;h<r.length;h++){var o=r[h];e.pins.push(t.makeNotePin(0,o.time,o.volume))}n.K.record(new t.ChangeNoteAdded(n.K,n.ut,e,n.Vt.curIndex))}else if(-1==n.Vt.pitchIndex){var a=new t.ChangeSequence;4==n.Vt.curNote.pitches.length&&a.append(new t.ChangePitchAdded(n.K,n.Vt.curNote,n.Vt.curNote.pitches[0],0,!0)),a.append(new t.ChangePitchAdded(n.K,n.Vt.curNote,n.Vt.pitch,n.Vt.curNote.pitches.length)),n.K.record(a),n.fi(n.Vt.curNote)}else 1==n.Vt.curNote.pitches.length?n.K.record(new t.ChangeNoteAdded(n.K,n.ut,n.Vt.curNote,n.Vt.curIndex,!0)):n.K.record(new t.ChangePitchAdded(n.K,n.Vt.curNote,n.Vt.pitch,n.Vt.curNote.pitches.indexOf(n.Vt.pitch),!0));n.Bt=!1,n.Lt=!1,n.ci(),n.di()}},this.vi=function(){n.ii=n.K.showLetters?n.K.showScrollBar?460:480:n.K.showScrollBar?492:512,n.ut=n.K.getCurrentPattern(),n.pi=n.ii/(n.K.song.beatsPerBar*n.K.song.partsPerBeat),n.bi=n.K.song.getChannelIsDrum(n.K.channel)?n.xt:n.gt,n.mi=n.K.song.getChannelIsDrum(n.K.channel)?t.Config.drumCount:t.Config.pitchCount,n.Ot=12*n.K.song.channels[n.K.channel].octave,n.Xt==n.K.song.partsPerBeat&&n._t==n.K.song.pitchChannelCount&&n.Kt==n.K.song.drumChannelCount||(n.Xt=n.K.song.partsPerBeat,n._t=n.K.song.pitchChannelCount,n.Kt=n.K.song.drumChannelCount,n.resetCopiedPins()),n.wi=n.Zt[n.K.channel],n.Wt!=n.ii&&(n.Wt=n.ii,n.wt.setAttribute("viewBox","0 0 "+n.ii+" 481"),n.dt.setAttribute("width",""+n.ii));var s,e,h=n.ii/n.K.song.beatsPerBar;if(n.Jt!=h){n.Jt=h,n.ft.setAttribute("width",""+h),n.ct.setAttribute("width",""+h),n.Mt.setAttribute("width",""+(h-2));for(var r=0;r<12;r++)n.yt[r].setAttribute("width",""+(h-2))}n.Bt||n.ci(),n.vt=(s=n.vt,e=s.cloneNode(!1),s.parentNode.replaceChild(e,s),e),n.di(),n.Qt!=n.K.showFifth&&(n.Qt=n.K.showFifth,n.yt[7].setAttribute("fill",n.K.showFifth?"#446688":"#444444"));for(r=0;r<12;r++)n.yt[r].style.visibility=t.Config.scaleFlags[n.K.song.scale][r]?"visible":"hidden";if(n.K.song.getChannelIsDrum(n.K.channel)?n.Ht||(n.Ht=!0,n.dt.setAttribute("fill","url(#patternEditorDrumBackground)"),n.dt.setAttribute("height",""+n.xt*t.Config.drumCount)):n.Ht&&(n.Ht=!1,n.dt.setAttribute("fill","url(#patternEditorNoteBackground)"),n.dt.setAttribute("height",""+n.At)),n.K.showChannels)for(var o=n.K.song.getChannelCount()-1;o>=0;o--)if(o!=n.K.channel&&n.K.song.getChannelIsDrum(o)==n.K.song.getChannelIsDrum(n.K.channel)){var a=n.K.song.getPattern(o,n.K.bar);if(null!=a)for(var l=0,u=a.notes;l<u.length;l++)for(var f=0,c=(b=u[l]).pitches;f<c.length;f++){var d=c[f];(w=t.svgElement("path")).setAttribute("fill",n.K.song.getNoteColorDim(o)),w.setAttribute("pointer-events","none"),n.gi(w,d,b.start,b.pins,.19*n.bi,!1,12*n.K.song.channels[o].octave),n.vt.appendChild(w)}}if(null!=n.ut){for(var v=0,p=n.ut.notes;v<p.length;v++)for(var b=p[v],m=0;m<b.pitches.length;m++){var w;d=b.pitches[m];if((w=t.svgElement("path")).setAttribute("fill",n.K.song.getNoteColorDim(n.K.channel)),w.setAttribute("pointer-events","none"),n.gi(w,d,b.start,b.pins,n.bi/2+1,!1,n.Ot),n.vt.appendChild(w),(w=t.svgElement("path")).setAttribute("fill",n.K.song.getNoteColorBright(n.K.channel)),w.setAttribute("pointer-events","none"),n.gi(w,d,b.start,b.pins,n.bi/2+1,!0,n.Ot),n.vt.appendChild(w),b.pitches.length>1&&!n.K.song.getChannelIsDrum(n.K.channel))if(1==n.K.song.channels[n.K.channel].instruments[n.K.getCurrentInstrument()].type){var g=t.svgElement("text");g.setAttribute("x",""+i(n.pi*b.start+2)),g.setAttribute("y",""+i(n.xi(d-n.Ot))),g.setAttribute("width","30"),g.setAttribute("fill","black"),g.setAttribute("text-anchor","start"),g.setAttribute("dominant-baseline","central"),g.setAttribute("pointer-events","none"),g.textContent=""+(m+1),n.vt.appendChild(g)}}n.dt.style.visibility="visible"}else n.dt.style.visibility="hidden"};for(var h=0;h<12;h++){var r=(12-h)%12,o=t.svgElement("rect");o.setAttribute("x","1"),o.setAttribute("y",""+(r*this.gt+1)),o.setAttribute("height",""+(this.gt-2)),o.setAttribute("fill",0==h?"#886644":"#444444"),this.ft.appendChild(o),this.yt[h]=o}this.Mt.setAttribute("x","1"),this.Mt.setAttribute("y","1"),this.Mt.setAttribute("height",""+(this.xt-2)),this.Mt.setAttribute("fill","#444444"),this.ct.appendChild(this.Mt),this.K.notifier.watch(this.vi),this.vi(),this.ci(),this.di(),window.requestAnimationFrame(this.ti),this.wt.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this.ui),this.wt.addEventListener("mouseover",this.si),this.wt.addEventListener("mouseout",this.ei),this.wt.addEventListener("touchstart",this.ri),this.wt.addEventListener("touchmove",this.li),this.wt.addEventListener("touchend",this.ui),this.wt.addEventListener("touchcancel",this.ui),this.resetCopiedPins()}return e.prototype.$t=function(){return this.K.song.partsPerBeat%3==0?this.K.song.partsPerBeat/3:this.K.song.partsPerBeat%2==0?this.K.song.partsPerBeat/2:this.K.song.partsPerBeat},e.prototype.ci=function(){if(null!=this.ut&&(this.Vt=new s,!(this.Et<0||this.Et>this.ii||this.Nt<0||this.Nt>this.At))){this.Vt.part=Math.floor(Math.max(0,Math.min(this.K.song.beatsPerBar*this.K.song.partsPerBeat-1,this.Et/this.pi)));for(var i=0,e=this.ut.notes;i<e.length;i++){var n=e[i];if(n.end<=this.Vt.part)this.Vt.prevNote=n,this.Vt.curIndex++;else if(n.start<=this.Vt.part&&n.end>this.Vt.part)this.Vt.curNote=n;else if(n.start>this.Vt.part){this.Vt.nextNote=n;break}}var h=this.yi(this.Nt);if(null!=this.Vt.curNote){this.Vt.start=this.Vt.curNote.start,this.Vt.end=this.Vt.curNote.end,this.Vt.pins=this.Vt.curNote.pins;for(var r=0,o=0,a=void 0,l=this.Vt.curNote.pins[0],u=1;u<this.Vt.curNote.pins.length;u++){a=l,l=this.Vt.curNote.pins[u];var f=this.pi*(this.Vt.curNote.start+a.time),c=this.pi*(this.Vt.curNote.start+l.time);if(!(this.Et>c)){if(this.Et<f)throw new Error;var d=(this.Et-f)/(c-f),v=Math.sqrt(1/Math.sqrt(4)-Math.pow(d-.5,2))-.5,p=Math.abs(l.interval-a.interval);r=a.interval*(1-d)+l.interval*d,o=v*p+.95;break}}for(var b=Number.MAX_VALUE,m=-Number.MAX_VALUE,w=Number.MAX_VALUE,g=0,x=this.Vt.curNote.pins;g<x.length;g++){var y=x[g];b>y.interval&&(b=y.interval),m<y.interval&&(m=y.interval);var M=Math.abs(this.Vt.curNote.start+y.time-this.Et/this.pi);w>M&&(w=M,this.Vt.nearPinIndex=this.Vt.curNote.pins.indexOf(y))}if(h-=r,this.Vt.pitch=this.Mi(h,-b,(this.K.song.getChannelIsDrum(this.K.channel)?t.Config.drumCount-1:t.Config.maxPitch)-m),!this.K.song.getChannelIsDrum(this.K.channel))for(var k=o,A=0;A<this.Vt.curNote.pitches.length;A++){var E=Math.abs(this.Vt.curNote.pitches[A]-h+.5);E>k||(k=E,this.Vt.pitch=this.Vt.curNote.pitches[A])}for(A=0;A<this.Vt.curNote.pitches.length;A++)if(this.Vt.curNote.pitches[A]==this.Vt.pitch){this.Vt.pitchIndex=A;break}}else{this.Vt.pitch=this.Mi(h,0,t.Config.maxPitch);var N=this.wi[this.wi.length-1].time,B=Math.floor(this.Vt.part/this.K.song.partsPerBeat),R=this.$t(),L=this.Vt.part%this.K.song.partsPerBeat;if(1==N)this.Vt.start=this.Vt.part;else if(N>this.K.song.partsPerBeat)this.Vt.start=B*this.K.song.partsPerBeat;else if(N==this.K.song.partsPerBeat)this.Vt.start=B*this.K.song.partsPerBeat,R<this.K.song.partsPerBeat&&L>R&&(this.Vt.start+=Math.floor(L/R)*R);else{this.Vt.start=B*this.K.song.partsPerBeat;for(var S=this.K.song.partsPerBeat%N==0?N:Math.min(N,R);S<R&&this.K.song.partsPerBeat%S!=0;)S++;this.Vt.start+=Math.floor(L/S)*S}this.Vt.end=this.Vt.start+N;var I=0,Z=this.K.song.beatsPerBar*this.K.song.partsPerBeat;if(null!=this.Vt.prevNote&&(I=this.Vt.prevNote.end),null!=this.Vt.nextNote&&(Z=this.Vt.nextNote.start),this.Vt.start<I?(this.Vt.start=I,this.Vt.end=this.Vt.start+N,this.Vt.end>Z&&(this.Vt.end=Z)):this.Vt.end>Z&&(this.Vt.end=Z,this.Vt.start=this.Vt.end-N,this.Vt.start<I&&(this.Vt.start=I)),this.Vt.end-this.Vt.start==N)this.Vt.pins=this.wi;else{this.Vt.pins=[];for(var C=0,G=this.wi;C<G.length;C++){var U=G[C];if(!(U.time<=this.Vt.end-this.Vt.start)){this.Vt.pins.push(t.makeNotePin(0,this.Vt.end-this.Vt.start,U.volume));break}if(this.Vt.pins.push(t.makeNotePin(0,U.time,U.volume)),U.time==this.Vt.end-this.Vt.start)break}}}this.Vt.valid=!0}},e.prototype.yi=function(t){return Math.max(0,Math.min(this.mi-1,this.mi-t/this.bi))+this.Ot},e.prototype.Mi=function(i,s,e){i<s&&(i=s),i>e&&(i=e);var n=t.Config.scaleFlags[this.K.song.scale];if(n[Math.floor(i)%12]||this.K.song.getChannelIsDrum(this.K.channel))return Math.floor(i);for(var h=Math.floor(i)+1,r=Math.floor(i)-1;!n[h%12];)h++;for(;!n[r%12];)r--;if(h>e)return r<s?s:r;if(r<s)return h;var o=h,a=r+1;return h%12!=0&&h%12!=7||(o-=.5),r%12!=0&&r%12!=7||(a+=.5),i-a>o-i?h:r},e.prototype.fi=function(i){this.wi=[];for(var s=0,e=i.pins;s<e.length;s++){var n=e[s];this.wi.push(t.makeNotePin(0,n.time,n.volume))}for(var h=1;h<this.wi.length-1;)this.wi[h-1].volume==this.wi[h].volume&&this.wi[h].volume==this.wi[h+1].volume?this.wi.splice(h,1):h++;this.Zt[this.K.channel]=this.wi},e.prototype.hi=function(){this.Bt=!0,this.Ct=this.Et,this.Gt=this.Nt,this.Ut=this.Et,this.jt=this.Nt,this.ci(),this.di(),this.Ft=new t.ChangeSequence,this.K.setProspectiveChange(this.Ft)},e.prototype.ai=function(){var i,s;if(null!=this.ut){var e=this.K.lastChangeWas(this.Ft);if(this.Bt&&this.Vt.valid&&e){if(!this.Lt){var n=this.Et-this.Ct,h=this.Nt-this.Gt;Math.sqrt(n*n+h*h)>5&&(this.Lt=!0,this.St=Math.abs(n)>=Math.abs(h))}if(this.Lt){null!=this.Ft&&this.Ft.undo();var r=Math.floor(this.Et/this.pi),o=new t.ChangeSequence;if(this.Ft=o,this.K.setProspectiveChange(this.Ft),null==this.Vt.curNote){var a=void 0,l=void 0;r<this.Vt.start?(a=!0,l=this.Vt.start-r):(a=!1,l=r-this.Vt.start+1);for(var u=1,f=0;f<=this.K.song.beatsPerBar*this.K.song.partsPerBeat;f++)if(!(f>=5&&f%this.K.song.partsPerBeat!=0&&f!=3*this.K.song.partsPerBeat/2&&f!=4*this.K.song.partsPerBeat/3&&f!=5*this.K.song.partsPerBeat/3)){if(f==l){u=f;break}if(f<l&&(u=f),f>l){u<l-1&&(u=f);break}}a?i=(s=this.Vt.start)-u:s=(i=this.Vt.start)+u,i<0&&(i=0),s>this.K.song.beatsPerBar*this.K.song.partsPerBeat&&(s=this.K.song.beatsPerBar*this.K.song.partsPerBeat),o.append(new t.ChangeNoteTruncate(this.K,this.ut,i,s));var c=void 0;for(c=0;c<this.ut.notes.length&&!(this.ut.notes[c].start>=s);c++);var d=t.makeNote(this.Vt.pitch,i,s,3,this.K.song.getChannelIsDrum(this.K.channel));o.append(new t.ChangeNoteAdded(this.K,this.ut,d,c)),this.fi(d),this.zt=a?i:s,this.Dt=this.Vt.pitch,this.Yt=d.pins[a?0:1].volume,this.Tt=!0}else if(this.St){var v=Math.round((this.Et-this.Ct)/this.pi),p=this.Vt.curNote.pins[this.Vt.nearPinIndex],b=this.Vt.curNote.start+p.time+v;b<0&&(b=0),b>this.K.song.beatsPerBar*this.K.song.partsPerBeat&&(b=this.K.song.beatsPerBar*this.K.song.partsPerBeat),b<=this.Vt.curNote.start&&this.Vt.nearPinIndex==this.Vt.curNote.pins.length-1||b>=this.Vt.curNote.end&&0==this.Vt.nearPinIndex?(o.append(new t.ChangeNoteAdded(this.K,this.ut,this.Vt.curNote,this.Vt.curIndex,!0)),this.Tt=!1):(i=Math.min(this.Vt.curNote.start,b),s=Math.max(this.Vt.curNote.end,b),this.zt=b,this.Dt=this.Vt.curNote.pitches[-1==this.Vt.pitchIndex?0:this.Vt.pitchIndex]+this.Vt.curNote.pins[this.Vt.nearPinIndex].interval,this.Yt=this.Vt.curNote.pins[this.Vt.nearPinIndex].volume,this.Tt=!0,o.append(new t.ChangeNoteTruncate(this.K,this.ut,i,s,this.Vt.curNote)),o.append(new t.ChangePinTime(this.K,this.Vt.curNote,this.Vt.nearPinIndex,b)),this.fi(this.Vt.curNote))}else if(-1==this.Vt.pitchIndex){var m=Math.round(Math.max(this.Vt.curNote.start,Math.min(this.Vt.curNote.end,this.Et/this.pi)))-this.Vt.curNote.start,w=void 0,g=this.Vt.curNote.pins[0],x=0,y=0;for(c=1;c<this.Vt.curNote.pins.length;c++)if(w=g,!(m>(g=this.Vt.curNote.pins[c]).time)){if(m<w.time)throw new Error;var M=(m-w.time)/(g.time-w.time);(x=Math.round(w.volume*(1-M)+g.volume*M+(this.Gt-this.Nt)/25))<0&&(x=0),x>3&&(x=3),y=this.Mi(w.interval*(1-M)+g.interval*M+this.Vt.curNote.pitches[0],0,t.Config.maxPitch)-this.Vt.curNote.pitches[0];break}this.zt=this.Vt.curNote.start+m,this.Dt=this.Vt.curNote.pitches[-1==this.Vt.pitchIndex?0:this.Vt.pitchIndex]+y,this.Yt=x,this.Tt=!0,o.append(new t.ChangeVolumeBend(this.K,this.Vt.curNote,m,x,y)),this.fi(this.Vt.curNote)}else{this.Yt=this.Vt.curNote.pins[this.Vt.nearPinIndex].volume;var k=void 0,A=void 0;this.Et>=this.Ct?(k=this.Vt.part,A=r+1):(k=this.Vt.part+1,A=r),A<0&&(A=0),A>this.K.song.beatsPerBar*this.K.song.partsPerBeat&&(A=this.K.song.beatsPerBar*this.K.song.partsPerBeat),A>this.Vt.curNote.end&&o.append(new t.ChangeNoteTruncate(this.K,this.ut,this.Vt.curNote.start,A,this.Vt.curNote)),A<this.Vt.curNote.start&&o.append(new t.ChangeNoteTruncate(this.K,this.ut,A,this.Vt.curNote.end,this.Vt.curNote));for(var E=Number.MAX_VALUE,N=-Number.MAX_VALUE,B=0,R=this.Vt.curNote.pitches;B<R.length;B++){var L=R[B];E>L&&(E=L),N<L&&(N=L)}E-=this.Vt.curNote.pitches[this.Vt.pitchIndex],N-=this.Vt.curNote.pitches[this.Vt.pitchIndex];var S=this.Mi(this.yi(this.Nt),-E,(this.K.song.getChannelIsDrum(this.K.channel)?t.Config.drumCount-1:t.Config.maxPitch)-N);o.append(new t.ChangePitchBend(this.K,this.Vt.curNote,k,A,S,this.Vt.pitchIndex)),this.fi(this.Vt.curNote),this.zt=A,this.Dt=S,this.Tt=!0}}this.Ut=this.Et,this.jt=this.Nt}else this.ci(),this.di()}},e.prototype.di=function(){if(this.It)if(this.Bt&&this.Vt.valid&&this.Lt&&this.Tt&&null!=this.ut){this.bt.setAttribute("visibility","visible");var t=this.pi*this.zt,s=this.xi(this.Dt-this.Ot),e=this.bi/2,n="";n+="M "+i(t)+" "+i(s-e*(this.Yt/3))+" ",n+="L "+i(t)+" "+i(s-e*(this.Yt/3)-60)+" ",n+="M "+i(t)+" "+i(s+e*(this.Yt/3))+" ",n+="L "+i(t)+" "+i(s+e*(this.Yt/3)+60)+" ",n+="M "+i(t)+" "+i(s-e*(this.Yt/3))+" ",n+="L "+i(t+80)+" "+i(s-e*(this.Yt/3))+" ",n+="M "+i(t)+" "+i(s+e*(this.Yt/3))+" ",n+="L "+i(t+80)+" "+i(s+e*(this.Yt/3))+" ",n+="M "+i(t)+" "+i(s-e*(this.Yt/3))+" ",n+="L "+i(t-80)+" "+i(s-e*(this.Yt/3))+" ",n+="M "+i(t)+" "+i(s+e*(this.Yt/3))+" ",n+="L "+i(t-80)+" "+i(s+e*(this.Yt/3))+" ",this.bt.setAttribute("d",n)}else this.bt.setAttribute("visibility","hidden");else this.Rt&&!this.Bt&&this.Vt.valid&&null!=this.ut?(this.bt.setAttribute("visibility","visible"),this.gi(this.bt,this.Vt.pitch,this.Vt.start,this.Vt.pins,this.bi/2+1,!0,this.Ot)):this.bt.setAttribute("visibility","hidden")},e.prototype.gi=function(t,s,e,n,h,r,o){for(var a=n[0],l="M "+i(this.pi*(e+a.time)+1)+" "+i(this.xi(s-o)+h*(r?a.volume/3:1))+" ",u=1;u<n.length;u++){var f=a;a=n[u];var c=this.pi*(e+f.time)+(1==u?1:0),d=this.pi*(e+a.time)-(u==n.length-1?1:0),v=this.xi(s+f.interval-o),p=this.xi(s+a.interval-o),b=r?f.volume/3:1,m=r?a.volume/3:1;l+="L "+i(c)+" "+i(v-h*b)+" ",f.interval>a.interval&&(l+="L "+i(c+1)+" "+i(v-h*b)+" "),f.interval<a.interval&&(l+="L "+i(d-1)+" "+i(p-h*m)+" "),l+="L "+i(d)+" "+i(p-h*m)+" "}for(u=n.length-2;u>=0;u--){f=a;a=n[u];c=this.pi*(e+f.time)-(u==n.length-2?1:0),d=this.pi*(e+a.time)+(0==u?1:0),v=this.xi(s+f.interval-o),p=this.xi(s+a.interval-o),b=r?f.volume/3:1,m=r?a.volume/3:1;l+="L "+i(c)+" "+i(v+h*b)+" ",f.interval<a.interval&&(l+="L "+i(c-1)+" "+i(v+h*b)+" "),f.interval>a.interval&&(l+="L "+i(d+1)+" "+i(p+h*m)+" "),l+="L "+i(d)+" "+i(p+h*m)+" "}l+="z",t.setAttribute("d",l)},e.prototype.xi=function(t){return this.bi*(this.mi-t-.5)},e}();t.PatternEditor=e}(beepbox||(beepbox={})),function(t){var i=function(){function i(i,s,e,n){this.ki=t.html.text("1"),this.Ai=t.svgElement("text",{x:16,y:23,"font-family":"sans-serif","font-size":20,"text-anchor":"middle","font-weight":"bold",fill:"red"},[this.ki]),this.Ei=t.svgElement("rect",{width:30,height:30,x:1,y:1}),this.container=t.svgElement("svg",void 0,[this.Ei,this.Ai]),this.Ni=1,this.Bi=!0,this.Ri=!1,this.Li="",this.container.setAttribute("x",""+32*s),this.container.setAttribute("y",""+32*e),this.Ei.setAttribute("fill","#444444"),this.Ai.setAttribute("fill",n)}return i.prototype.setSquashed=function(t,i){t?(this.container.setAttribute("y",""+27*i),this.Ei.setAttribute("height","25"),this.Ai.setAttribute("y","21")):(this.container.setAttribute("y",""+32*i),this.Ei.setAttribute("height","30"),this.Ai.setAttribute("y","23"))},i.prototype.setIndex=function(t,i,s,e,n){this.Ni!=t&&(this.Ri||0==t==(0==this.Ni)||this.Ei.setAttribute("fill",0==t?"#000000":"#444444"),this.Ni=t,this.ki.data=""+t),this.Bi==i&&this.Li==n||(this.Bi=i,s?this.Ai.setAttribute("fill","#000000"):this.Ai.setAttribute("fill",n)),this.Ri==s&&this.Li==n||(this.Ri=s,s?(this.Ei.setAttribute("fill",n),this.Ai.setAttribute("fill","#000000")):(this.Ei.setAttribute("fill",0==this.Ni?"#000000":"#444444"),this.Ai.setAttribute("fill",n))),this.Li=n},i}(),s=function(){function s(i,s){var e=this;this.K=i,this.Si=s,this.Ii=32,this.wt=t.svgElement("svg",{style:"background-color: #000000; position: absolute;",height:128}),this.Zi=t.html.select({className:"trackSelectBox",style:"width: 32px; height: 32px; background: none; border: none; appearance: none; color: transparent; position: absolute;"}),this.container=t.html.div({style:"height: 128px; position: relative; overflow:hidden;"},[this.wt,this.Zi]),this.Ci=t.svgElement("g"),this.Gi=t.svgElement("rect",{fill:"white",x:0,y:0,width:4,height:128}),this.Ui=t.svgElement("rect",{fill:"none",stroke:"white","stroke-width":2,"pointer-events":"none",x:1,y:1,width:30,height:30}),this.ji=t.svgElement("path",{fill:"black",stroke:"black","stroke-width":1,"pointer-events":"none"}),this.zi=t.svgElement("path",{fill:"black",stroke:"black","stroke-width":1,"pointer-events":"none"}),this.Di=[],this.Et=0,this.Nt=0,this.ut=null,this.Rt=!1,this.Yi="",this.At=128,this.Ti=32,this.Fi=0,this.Vi=0,this.Pi=0,this.Oi=-1,this.Wi=!1,this.Ji=null,this.Qi=function(){e.Hi(e.Zi.selectedIndex)},this.ti=function(t){var i=e.Ii*e.K.synth.playhead-2;e.Oi!=i&&(e.Oi=i,e.Gi.setAttribute("x",""+i)),window.requestAnimationFrame(e.ti)},this.si=function(t){e.Rt||(e.Rt=!0)},this.ei=function(t){e.Rt&&(e.Rt=!1)},this.ni=function(t){t.preventDefault();var i=e.wt.getBoundingClientRect();e.Et=(t.clientX||t.pageX)-i.left,e.Nt=(t.clientY||t.pageY)-i.top;var s=Math.floor(Math.min(e.K.song.getChannelCount()-1,Math.max(0,e.Nt/e.Ti))),n=Math.floor(Math.min(e.K.song.barCount-1,Math.max(0,e.Et/e.Ii)));if(e.K.channel==s&&e.K.bar==n){var h=e.Nt%e.Ti<e.Ti/2,r=e.K.song.patternsPerChannel;e.Hi((e.K.song.channels[s].bars[n]+(h?1:r))%(r+1))}else e.Xi(s,n)},this.oi=function(t){var i=e.wt.getBoundingClientRect();e.Et=(t.clientX||t.pageX)-i.left,e.Nt=(t.clientY||t.pageY)-i.top,e.di()},this._i=function(t){},this.wt.appendChild(this.Ci),this.wt.appendChild(this.Ui),this.wt.appendChild(this.ji),this.wt.appendChild(this.zi),this.wt.appendChild(this.Gi),window.requestAnimationFrame(this.ti),this.wt.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this._i),this.wt.addEventListener("mouseover",this.si),this.wt.addEventListener("mouseout",this.ei),this.Zi.addEventListener("change",this.Qi)}return s.prototype.Xi=function(i,s){new t.ChangeChannelBar(this.K,i,s),this.Yi="",this.K.forgetLastChange()},s.prototype.Hi=function(i){var s=this.K.song.channels[this.K.channel].bars[this.K.bar],e=this.K.lastChangeWas(this.Ji),n=e?this.Ji.oldValue:s;i!=s&&(this.Ji=new t.ChangePattern(this.K,n,i),this.K.record(this.Ji,e))},s.prototype.onKeyPressed=function(t){switch(t.keyCode){case 38:this.Xi((this.K.channel-1+this.K.song.getChannelCount())%this.K.song.getChannelCount(),this.K.bar),t.preventDefault();break;case 40:this.Xi((this.K.channel+1)%this.K.song.getChannelCount(),this.K.bar),t.preventDefault();break;case 37:this.Xi(this.K.channel,(this.K.bar+this.K.song.barCount-1)%this.K.song.barCount),t.preventDefault();break;case 39:this.Xi(this.K.channel,(this.K.bar+1)%this.K.song.barCount),t.preventDefault();break;case 48:this.Ki("0"),t.preventDefault();break;case 49:this.Ki("1"),t.preventDefault();break;case 50:this.Ki("2"),t.preventDefault();break;case 51:this.Ki("3"),t.preventDefault();break;case 52:this.Ki("4"),t.preventDefault();break;case 53:this.Ki("5"),t.preventDefault();break;case 54:this.Ki("6"),t.preventDefault();break;case 55:this.Ki("7"),t.preventDefault();break;case 56:this.Ki("8"),t.preventDefault();break;case 57:this.Ki("9"),t.preventDefault();break;default:this.Yi=""}},s.prototype.Ki=function(t){this.Yi+=t;var i=parseInt(this.Yi);i<=this.K.song.patternsPerChannel?this.Hi(i):(this.Yi=t,(i=parseInt(this.Yi))<=this.K.song.patternsPerChannel?this.Hi(i):this.Yi="")},s.prototype.di=function(){var i=Math.floor(Math.min(this.K.song.getChannelCount()-1,Math.max(0,this.Nt/this.Ti))),s=Math.floor(Math.min(this.K.song.barCount-1,Math.max(0,this.Et/this.Ii))),e=window.innerWidth>700;e||(s=this.K.bar,i=this.K.channel);var n=s==this.K.bar&&i==this.K.channel;if(this.Rt&&!n?(this.Ui.setAttribute("x",""+(1+this.Ii*s)),this.Ui.setAttribute("y",""+(1+this.Ti*i)),this.Ui.setAttribute("height",""+(this.Ti-2)),this.Ui.style.visibility="visible"):this.Ui.style.visibility="hidden",!this.Rt&&e||!n)this.ji.style.visibility="hidden",this.zi.style.visibility="hidden";else{var h=this.Nt%this.Ti<this.Ti/2,r=this.Ii*(s+.8),o=this.Ti*(i+.5),a=.1*this.Ti,l=.4*this.Ti,u=.175*this.Ti;this.ji.setAttribute("fill",h&&e?"#fff":"#000"),this.zi.setAttribute("fill",!h&&e?"#fff":"#000"),this.ji.setAttribute("d","M "+r+" "+(o-l)+" L "+(r+u)+" "+(o-a)+" L "+(r-u)+" "+(o-a)+" z"),this.zi.setAttribute("d","M "+r+" "+(o+l)+" L "+(r+u)+" "+(o+a)+" L "+(r-u)+" "+(o+a)+" z"),this.ji.style.visibility="visible",this.zi.style.visibility="visible"}this.Zi.style.left=this.Ii*this.K.bar+"px",this.Zi.style.top=this.Ti*this.K.channel+"px",this.Zi.style.height=this.Ti+"px";for(var f=this.K.song.patternsPerChannel,c=this.Pi;c<f;c++)this.Zi.appendChild(t.html.option(c,c,!1,!1));for(c=f;c<this.Pi;c++)this.Zi.removeChild(this.Zi.lastChild);this.Pi=f;var d=this.K.song.channels[this.K.channel].bars[this.K.bar];this.Zi.selectedIndex!=d&&(this.Zi.selectedIndex=d)},s.prototype.render=function(){this.ut=this.K.getCurrentPattern();var t=!(window.innerWidth>700)||this.K.song.getChannelCount()>4||this.K.song.barCount>this.K.trackVisibleBars&&this.K.song.getChannelCount()>3;if(this.Ti=t?27:32,this.Fi!=this.K.song.getChannelCount()){for(var s=this.Fi;s<this.K.song.getChannelCount();s++){this.Di[s]=[];for(var e=0;e<this.Vi;e++){(u=new i(s,e,s,this.K.song.getChannelColorDim(s))).setSquashed(t,s),this.Ci.appendChild(u.container),this.Di[s][e]=u}}for(s=this.K.song.getChannelCount();s<this.Fi;s++)for(e=0;e<this.Vi;e++)this.Ci.removeChild(this.Di[s][e].container);this.Di.length=this.K.song.getChannelCount()}if(this.Vi!=this.K.song.barCount){for(s=0;s<this.K.song.getChannelCount();s++){for(e=this.Vi;e<this.K.song.barCount;e++){(u=new i(s,e,s,this.K.song.getChannelColorDim(s))).setSquashed(t,s),this.Ci.appendChild(u.container),this.Di[s][e]=u}for(e=this.K.song.barCount;e<this.Vi;e++)this.Ci.removeChild(this.Di[s][e].container);this.Di[s].length=this.K.song.barCount}this.Vi=this.K.song.barCount;var n=32*this.K.song.barCount;this.container.style.width=n+"px",this.wt.setAttribute("width",n+"")}if(this.Wi!=t)for(s=0;s<this.K.song.getChannelCount();s++)for(e=0;e<this.Vi;e++)this.Di[s][e].setSquashed(t,s);this.Wi==t&&this.Fi==this.K.song.getChannelCount()||(this.Wi=t,this.Fi=this.K.song.getChannelCount(),this.At=this.K.song.getChannelCount()*this.Ti,this.wt.setAttribute("height",""+this.At),this.Gi.setAttribute("height",""+this.At),this.container.style.height=this.At+"px");for(var h=0;h<this.K.song.getChannelCount();h++)for(var r=0;r<this.Vi;r++){var o=this.K.song.getPattern(h,r),a=r==this.K.bar&&h==this.K.channel,l=null==o||0==o.notes.length,u=this.Di[h][r];r<this.K.song.barCount?(u.setIndex(this.K.song.channels[h].bars[r],l,a,h,l&&!a?this.K.song.getChannelColorDim(h):this.K.song.getChannelColorBright(h)),u.container.style.visibility="visible"):u.container.style.visibility="hidden"}this.di()},s}();t.TrackEditor=s}(beepbox||(beepbox={})),function(t){var i=function(){function i(i){var s=this;this.K=i,this.Ii=32,this.At=20,this.qi=0,this.$i=1,this.ts=2,this.ss=t.svgElement("path",{fill:"none",stroke:"#7744ff","stroke-width":4}),this.es=t.svgElement("path",{fill:"white","pointer-events":"none"}),this.wt=t.svgElement("svg",{style:"background-color: #000000; touch-action: pan-y; position: absolute;",height:this.At},[this.ss,this.es]),this.container=t.html.div({style:"height: 20px; position: relative; margin: 5px 0;"},[this.wt]),this.ns=null,this.Vt={startBar:-1,mode:-1},this.Et=0,this.Nt=0,this.hs=0,this.rs=0,this.os=!1,this.as=!1,this.Bt=!1,this.Rt=!1,this.ls=-1,this.us=-1,this.Vi=0,this.si=function(t){s.Rt||(s.Rt=!0,s.di())},this.ei=function(t){s.Rt&&(s.Rt=!1,s.di())},this.ni=function(t){t.preventDefault(),s.Bt=!0;var i=s.wt.getBoundingClientRect();s.Et=(t.clientX||t.pageX)-i.left,s.Nt=(t.clientY||t.pageY)-i.top,s.ci(),s.di(),s.oi(t)},this.ri=function(t){s.Bt=!0;var i=s.wt.getBoundingClientRect();s.Et=t.touches[0].clientX-i.left,s.Nt=t.touches[0].clientY-i.top,s.ci(),s.di(),s.hs=t.touches[0].clientX,s.rs=t.touches[0].clientY,s.as=!1,s.os=!1},this.oi=function(t){var i=s.wt.getBoundingClientRect();s.Et=(t.clientX||t.pageX)-i.left,s.Nt=(t.clientY||t.pageY)-i.top,s.ai()},this.li=function(t){if(s.Bt){var i=s.wt.getBoundingClientRect();s.Et=t.touches[0].clientX-i.left,s.Nt=t.touches[0].clientY-i.top,s.as||s.os||(Math.abs(t.touches[0].clientY-s.rs)>10?s.os=!0:Math.abs(t.touches[0].clientX-s.hs)>10&&(s.as=!0)),s.as&&(s.ai(),t.preventDefault())}},this.fs=function(t){t.preventDefault(),s.os||(s.ai(),s.Rt=!1,s.ui(t),s.di())},this.ui=function(t){null!=s.ns&&s.K.record(s.ns),s.ns=null,s.Bt=!1,s.ci(),s.cs()},this.vi=function(){s.cs()},this.ci(),this.cs(),this.K.notifier.watch(this.vi),this.container.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this.ui),this.container.addEventListener("mouseover",this.si),this.container.addEventListener("mouseout",this.ei),this.container.addEventListener("touchstart",this.ri),this.container.addEventListener("touchmove",this.li),this.container.addEventListener("touchend",this.fs),this.container.addEventListener("touchcancel",this.fs)}return i.prototype.ci=function(){var t=this.Et/this.Ii;this.Vt.startBar=t,t>this.K.song.loopStart-.25&&t<this.K.song.loopStart+this.K.song.loopLength+.25?t-this.K.song.loopStart<.5*this.K.song.loopLength?this.Vt.mode=this.qi:this.Vt.mode=this.$i:this.Vt.mode=this.ts},i.prototype.ds=function(t){var i=Math.round(t-this.K.song.loopLength/2),s=i+this.K.song.loopLength;return i<0&&(s-=i,i=0),s>this.K.song.barCount&&(i-=s-this.K.song.barCount,s=this.K.song.barCount),{start:i,length:s-i}},i.prototype.ai=function(){if(this.Bt){var i=this.K.song.loopStart,s=this.K.song.loopStart+this.K.song.loopLength;null!=this.ns&&this.K.lastChangeWas(this.ns)&&(s=(i=this.ns.oldStart)+this.ns.oldLength);var e=this.Et/this.Ii,n=void 0,h=void 0,r=void 0;if(this.Vt.mode==this.qi)h=s,(n=i+Math.round(e-this.Vt.startBar))<0&&(n=0),n>=this.K.song.barCount&&(n=this.K.song.barCount),n==h?n=h-1:n>h&&(r=n,n=h,h=r),this.ns=new t.ChangeLoop(this.K,i,s-i,n,h-n);else if(this.Vt.mode==this.$i)n=i,(h=s+Math.round(e-this.Vt.startBar))<0&&(h=0),h>=this.K.song.barCount&&(h=this.K.song.barCount),h==n?h=n+1:h<n&&(r=n,n=h,h=r),this.ns=new t.ChangeLoop(this.K,i,s-i,n,h-n);else if(this.Vt.mode==this.ts){var o=this.ds(e);this.ns=new t.ChangeLoop(this.K,i,s-i,o.start,o.length)}this.K.setProspectiveChange(this.ns)}else this.ci(),this.di()},i.prototype.di=function(){var t=this.Rt&&!this.Bt;if(this.es.style.visibility=t?"visible":"hidden",t){var i=this.At/2,s=this.K.song.loopStart*this.Ii,e=(this.K.song.loopStart+this.K.song.loopLength)*this.Ii;if(this.Vt.mode==this.qi)e=this.K.song.loopStart*this.Ii+2*i;else if(this.Vt.mode==this.$i)s=(this.K.song.loopStart+this.K.song.loopLength)*this.Ii-2*i;else{var n=this.ds(this.Vt.startBar);s=n.start*this.Ii,e=(n.start+n.length)*this.Ii}this.es.setAttribute("d","M "+(s+i)+" 4 L "+(e-i)+" 4 A "+(i-4)+" "+(i-4)+" 0 0 1 "+(e-i)+" "+(this.At-4)+" L "+(s+i)+" "+(this.At-4)+" A "+(i-4)+" "+(i-4)+" 0 0 1 "+(s+i)+" 4 z")}},i.prototype.cs=function(){var t=this.At/2,i=this.K.song.loopStart*this.Ii,s=(this.K.song.loopStart+this.K.song.loopLength)*this.Ii;if(this.Vi!=this.K.song.barCount){this.Vi=this.K.song.barCount;var e=32*this.K.song.barCount;this.container.style.width=e+"px",this.wt.setAttribute("width",e+"")}this.ls==i&&this.us==s||(this.ls=i,this.us=s,this.ss.setAttribute("d","M "+(i+t)+" 2 L "+(s-t)+" 2 A "+(t-2)+" "+(t-2)+" 0 0 1 "+(s-t)+" "+(this.At-2)+" L "+(i+t)+" "+(this.At-2)+" A "+(t-2)+" "+(t-2)+" 0 0 1 "+(i+t)+" 2 z")),this.di()},i}();t.LoopEditor=i}(beepbox||(beepbox={})),function(t){var i=function(){function i(i,s){var e=this;this.K=i,this.vs=s,this.ii=512,this.At=20,this.ps=t.svgElement("svg",{"pointer-events":"none"}),this.bs=t.svgElement("rect",{fill:"#444444",x:0,y:2,width:10,height:this.At-4}),this.ms=t.svgElement("rect",{fill:"none",stroke:"white","stroke-width":2,"pointer-events":"none",x:0,y:1,width:10,height:this.At-2}),this.ws=t.svgElement("path",{fill:"white","pointer-events":"none"}),this.gs=t.svgElement("path",{fill:"white","pointer-events":"none"}),this.wt=t.svgElement("svg",{style:"background-color: #000000; touch-action: pan-y; position: absolute;",width:this.ii,height:this.At},[this.ps,this.bs,this.ms,this.ws,this.gs]),this.container=t.html.div({className:"barScrollBar",style:"width: 512px; height: 20px; overflow: hidden; position: relative;"},[this.wt]),this.Et=0,this.Nt=0,this.Bt=!1,this.Rt=!1,this.xs=!1,this.ys=-1,this.Ms=-1,this.ks=function(t){e.K.barScrollPos=e.vs.scrollLeft/32},this.si=function(t){e.Rt||(e.Rt=!0,e.di())},this.ei=function(t){e.Rt&&(e.Rt=!1,e.di())},this.ni=function(t){t.preventDefault(),e.Bt=!0;var i=e.wt.getBoundingClientRect();e.Et=(t.clientX||t.pageX)-i.left,e.Nt=(t.clientY||t.pageY)-i.top,e.di(),e.Et>=e.K.barScrollPos*e.Ii&&e.Et<=(e.K.barScrollPos+e.K.trackVisibleBars)*e.Ii&&(e.xs=!0,e.As=e.Et)},this.ri=function(t){t.preventDefault(),e.Bt=!0;var i=e.wt.getBoundingClientRect();e.Et=t.touches[0].clientX-i.left,e.Nt=t.touches[0].clientY-i.top,e.di(),e.Et>=e.K.barScrollPos*e.Ii&&e.Et<=(e.K.barScrollPos+e.K.trackVisibleBars)*e.Ii&&(e.xs=!0,e.As=e.Et)},this.oi=function(t){var i=e.wt.getBoundingClientRect();e.Et=(t.clientX||t.pageX)-i.left,e.Nt=(t.clientY||t.pageY)-i.top,e.ai()},this.li=function(t){if(e.Bt){t.preventDefault();var i=e.wt.getBoundingClientRect();e.Et=t.touches[0].clientX-i.left,e.Nt=t.touches[0].clientY-i.top,e.ai()}},this.ui=function(t){!e.xs&&e.Bt&&(e.Et<(e.K.barScrollPos+8)*e.Ii?(e.K.barScrollPos>0&&e.K.barScrollPos--,e.K.notifier.changed()):(e.K.barScrollPos<e.K.song.barCount-e.K.trackVisibleBars&&e.K.barScrollPos++,e.K.notifier.changed())),e.Bt=!1,e.xs=!1,e.di()};var n=.5*this.At;this.ws.setAttribute("d","M 9 "+n+" L 20 "+(n+6)+" L 20 "+(n-6)+" z"),this.gs.setAttribute("d","M "+(this.ii-9)+" "+n+" L "+(this.ii-20)+" "+(n+6)+" L "+(this.ii-20)+" "+(n-6)+" z"),this.container.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this.ui),this.container.addEventListener("mouseover",this.si),this.container.addEventListener("mouseout",this.ei),this.container.addEventListener("touchstart",this.ri),this.container.addEventListener("touchmove",this.li),this.container.addEventListener("touchend",this.ui),this.container.addEventListener("touchcancel",this.ui),this.vs.addEventListener("scroll",this.ks,{capture:!1,passive:!0})}return i.prototype.ai=function(){if(this.xs){for(;this.Et-this.As<.5*-this.Ii&&this.K.barScrollPos>0;)this.K.barScrollPos--,this.As-=this.Ii,this.K.notifier.changed();for(;this.Et-this.As>.5*this.Ii&&this.K.barScrollPos<this.K.song.barCount-this.K.trackVisibleBars;)this.K.barScrollPos++,this.As+=this.Ii,this.K.notifier.changed()}this.Rt&&this.di()},i.prototype.di=function(){var t=!1,i=!1,s=!1;this.Rt&&!this.Bt&&(this.Et<this.K.barScrollPos*this.Ii?t=!0:this.Et>(this.K.barScrollPos+this.K.trackVisibleBars)*this.Ii?i=!0:s=!0),this.ws.style.visibility=t?"visible":"hidden",this.gs.style.visibility=i?"visible":"hidden",this.ms.style.visibility=s?"visible":"hidden"},i.prototype.render=function(){this.Ii=(this.ii-1)/Math.max(this.K.trackVisibleBars,this.K.song.barCount);var i=this.ys!=this.K.song.barCount;if(i){for(this.ys=this.K.song.barCount;this.ps.firstChild;)this.ps.removeChild(this.ps.firstChild);for(var s=0;s<=this.K.song.barCount;s++){var e=s%16==0?0:s%4==0?this.At/8:this.At/3;this.ps.appendChild(t.svgElement("rect",{fill:"#444444",x:s*this.Ii-1,y:e,width:2,height:this.At-2*e}))}}(i||this.Ms!=this.K.barScrollPos)&&(this.Ms=this.K.barScrollPos,this.bs.setAttribute("x",""+this.Ii*this.K.barScrollPos),this.bs.setAttribute("width",""+this.Ii*this.K.trackVisibleBars),this.ms.setAttribute("x",""+this.Ii*this.K.barScrollPos),this.ms.setAttribute("width",""+this.Ii*this.K.trackVisibleBars)),this.di(),this.vs.scrollLeft=32*this.K.barScrollPos},i}();t.BarScrollBar=i}(beepbox||(beepbox={})),function(t){var i=function(){function i(i){var s=this;this.K=i,this.ii=20,this.At=481,this.Es=4,this.Ns=7,this.Bs=(this.At-this.Es)/this.Ns,this.Rs=3*this.Bs+this.Es,this.bs=t.svgElement("rect",{fill:"#444444",x:2,y:0,width:this.ii-4,height:this.Rs}),this.ms=t.svgElement("rect",{fill:"none",stroke:"white","stroke-width":2,"pointer-events":"none",x:1,y:0,width:this.ii-2,height:this.Rs}),this.ji=t.svgElement("path",{fill:"white","pointer-events":"none"}),this.zi=t.svgElement("path",{fill:"white","pointer-events":"none"}),this.wt=t.svgElement("svg",{style:"background-color: #000000; touch-action: pan-x; position: absolute;",width:this.ii,height:"100%",viewBox:"0 0 20 481",preserveAspectRatio:"none"}),this.container=t.html.div({id:"octaveScrollBarContainer",style:"width: 20px; height: 100%; overflow: hidden; position: relative; flex-shrink: 0;"},[this.wt]),this.Et=0,this.Nt=0,this.Bt=!1,this.Rt=!1,this.xs=!1,this.Ls=-1,this.ns=null,this.si=function(t){s.Rt||(s.Rt=!0,s.di())},this.ei=function(t){s.Rt&&(s.Rt=!1,s.di())},this.ni=function(t){t.preventDefault(),s.Bt=!0;var i=s.wt.getBoundingClientRect();s.Et=(t.clientX||t.pageX)-i.left,s.Nt=((t.clientY||t.pageY)-i.top)*s.At/(i.bottom-i.top),isNaN(s.Nt)&&(s.Nt=0),s.K.song.getChannelIsDrum(s.K.channel)||(s.di(),s.Nt>=s.Ss-s.Rs&&s.Nt<=s.Ss&&(s.xs=!0,s.ns=null,s.As=s.Nt))},this.ri=function(t){t.preventDefault(),s.Bt=!0;var i=s.wt.getBoundingClientRect();s.Et=t.touches[0].clientX-i.left,s.Nt=(t.touches[0].clientY-i.top)*s.At/(i.bottom-i.top),isNaN(s.Nt)&&(s.Nt=0),s.K.song.getChannelIsDrum(s.K.channel)||(s.di(),s.Nt>=s.Ss-s.Rs&&s.Nt<=s.Ss&&(s.xs=!0,s.ns=null,s.As=s.Nt))},this.oi=function(t){var i=s.wt.getBoundingClientRect();s.Et=(t.clientX||t.pageX)-i.left,s.Nt=((t.clientY||t.pageY)-i.top)*s.At/(i.bottom-i.top),isNaN(s.Nt)&&(s.Nt=0),s.ai()},this.li=function(t){if(s.Bt){t.preventDefault();var i=s.wt.getBoundingClientRect();s.Et=t.touches[0].clientX-i.left,s.Nt=(t.touches[0].clientY-i.top)*s.At/(i.bottom-i.top),isNaN(s.Nt)&&(s.Nt=0),s.ai()}},this.ui=function(i){if(!s.K.song.getChannelIsDrum(s.K.channel)&&s.Bt)if(s.xs)null!=s.ns&&s.K.record(s.ns);else{var e=s.K.lastChangeWas(s.ns),n=e?s.ns.oldValue:s.K.song.channels[s.K.channel].octave,h=s.K.song.channels[s.K.channel].octave;s.Nt<s.Ss-.5*s.Rs?h<4&&(s.ns=new t.ChangeOctave(s.K,n,h+1),s.K.record(s.ns,e)):h>0&&(s.ns=new t.ChangeOctave(s.K,n,h-1),s.K.record(s.ns,e))}s.Bt=!1,s.xs=!1,s.di()},this.vi=function(){s.Ss=s.At-s.Bs*s.K.song.channels[s.K.channel].octave,s.cs()},this.K.notifier.watch(this.vi),this.vi(),this.wt.appendChild(this.bs);for(var e=0;e<=this.Ns;e++)this.wt.appendChild(t.svgElement("rect",{fill:"#886644",x:0,y:e*this.Bs,width:this.ii,height:this.Es}));this.wt.appendChild(this.ms),this.wt.appendChild(this.ji),this.wt.appendChild(this.zi);var n=.5*this.ii;this.ji.setAttribute("d","M "+n+" 9 L "+(n+6)+" 20 L "+(n-6)+" 20 z"),this.zi.setAttribute("d","M "+n+" "+(this.At-9)+" L "+(n+6)+" "+(this.At-20)+" L "+(n-6)+" "+(this.At-20)+" z"),this.container.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this.ui),this.container.addEventListener("mouseover",this.si),this.container.addEventListener("mouseout",this.ei),this.container.addEventListener("touchstart",this.ri),this.container.addEventListener("touchmove",this.li),this.container.addEventListener("touchend",this.ui),this.container.addEventListener("touchcancel",this.ui)}return i.prototype.ai=function(){if(!this.K.song.getChannelIsDrum(this.K.channel)){if(this.xs){for(var i=this.K.song.channels[this.K.channel].octave,s=this.K.lastChangeWas(this.ns)?this.ns.oldValue:i,e=i;this.Nt-this.As<.5*-this.Bs&&e<4;)e++,this.As-=this.Bs;for(;this.Nt-this.As>.5*this.Bs&&e>0;)e--,this.As+=this.Bs;this.ns=new t.ChangeOctave(this.K,s,e),this.K.setProspectiveChange(this.ns)}this.Rt&&this.di()}},i.prototype.di=function(){var t=!1,i=!1,s=!1;this.Rt&&!this.Bt&&(this.Nt<this.Ss-this.Rs?t=!0:this.Nt>this.Ss?i=!0:s=!0),this.ji.style.visibility=t?"inherit":"hidden",this.zi.style.visibility=i?"inherit":"hidden",this.ms.style.visibility=s?"inherit":"hidden"},i.prototype.cs=function(){this.wt.style.visibility=this.K.song.getChannelIsDrum(this.K.channel)?"hidden":"visible",this.Ls!=this.Ss&&(this.Ls=this.Ss,this.bs.setAttribute("y",""+(this.Ss-this.Rs)),this.ms.setAttribute("y",""+(this.Ss-this.Rs))),this.di()},i}();t.OctaveScrollBar=i}(beepbox||(beepbox={})),function(t){var i=!1;function s(){0,i=!0}var e=document.createElement("img");e.onload=s,e.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAANCAIAAABHKvtLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NEU3RTM2RTg0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NEU3RTM2RTk0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozMzYxN0U3RDQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozMzYxN0U3RTQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PomGIaQAAABgSURBVHjaYpSWlmZhYWFmZgaSTExMQAYTGGAyIICRkRFIMhANWISFhdlggAUHANrBysoKNBfuCGKMvnjx4r59+xhp5wOg6UCSBM+SB0YtGLVgCFgAzDeMeOSGgAUAAQYAGgwJrOg8pdQAAAAASUVORK5CYII=";var n=document.createElement("img");n.onload=s,n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAANCAIAAABHKvtLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NEU3RTM2RUM0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NEU3RTM2RUQ0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0RTdFMzZFQTQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0RTdFMzZFQjQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PhURscAAAAB1SURBVHja7NPBCoAgDAZgnaMX8Oj7P2KKldXPhiR4CwwCv4PInPvxoA0hMLNzDisRYUPCCiMucVallJzzJnaBih5pp2mw936puKEZ2qQ3MeUQmLiKGGNKCZ1IQr2fDnb0C8gMNgNmwA8Cnt/0Tv91vw64BRgALUuP70jrlrwAAAAASUVORK5CYII=";var h=document.createElement("img");h.onload=s,h.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAANCAIAAABHKvtLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzM2MTdFNzc0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzM2MTdFNzg0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozMzYxN0U3NTQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozMzYxN0U3NjQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PgBmMXoAAACTSURBVHja7JQ7CgMhGIT3920M2Hko7+RJPYWViE0myi5sEXAhKQL7FcP8PmawkWKMjx2llNb60MNIKY0xnPPphRDbMsJ7/xw458wAodZa6PRQ5GIF0RjlYCU655xSEqWU3ntrrdb63RcgHcq2H3MX3AV/UEAhBL7DBkTEzmAFuzSY44UC/BDHtU+8z539esFLgAEAkZ4XCDjZXPEAAAAASUVORK5CYII=";var r=document.createElement("img");r.onload=s,r.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAANCAIAAABHKvtLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MzM2MTdFN0I0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MzM2MTdFN0M0NzBEMTFFMTgyMjBBREEyQTVGRDY5MjIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDozMzYxN0U3OTQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDozMzYxN0U3QTQ3MEQxMUUxODIyMEFEQTJBNUZENjkyMiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlZjoH4AAADHSURBVHja7JTNDoMgEIRBGq21iTcfyvd/DeNvJBYBp7uFEE+99NDE70AMMDPLYZRt2z4CeZ4XRcFrRkgphRD7vnvvX8RGdF03DEPf99M0LcuitcamMcZa6wkRuNV1/SSqqroTcC/LEu5KKQ6AEhq21oRzDl5bAME8DUjd3wHjOELPyu9fgNnneV7XNQ6OyNPsTCZ+zBVwBfxBgGyaRgViuWIt+ZIPuAAaZwh00BKxaKeuSfwhUsfI55g+WOMT2DEl3jm94BBgAAtY6T6d3wTNAAAAAElFTkSuQmCC";var o=document.createElement("img");o.onload=s,o.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAArCAIAAACW3x1gAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDowMTgwMTE3NDA3MjA2ODExOUJCOEEzOUJCMkI3MTdFNCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo5NzVEOTA1QzQ5MjMxMUUxOTM3RDhDNEI4QkIxQkFCNSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo5NzVEOTA1QjQ5MjMxMUUxOTM3RDhDNEI4QkIxQkFCNSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjAxODAxMTc0MDcyMDY4MTE5QkI4QTM5QkIyQjcxN0U0IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjAxODAxMTc0MDcyMDY4MTE5QkI4QTM5QkIyQjcxN0U0Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+dtFK5QAACbRJREFUeNrcV0lsG9cZnnmzcJdIcRHFRZtly5IVSVYSOcriNY7jqHHTBE2bJkCRNijQQ9re2kOBAj30kByKAm1PvQVF0RYIkLRpkiZuLMqyLVm7bGvlIpKiuHOGyww52+ubIbXYCYLk2P4ccobz3nzf+9f3D4b9rwv+5cOXL5x48crDT54b8Pr6jOZWQJoxKIi13WJ+Oziz+Z/r6x9N3AvMhb42gcWkf/P1Mz/40fkWz2iuAAsFrljkOK5crVYwTNTrcaMRNDURNhtl1Slrn9x55x+zf/5ooVIVvhLBq1ce+eXPLpt6RnZ22EIBmk1Oi8VuMFoMBgNF6RUMF2tcrVqscPlSKcGV4zaC85qNd25u/PHdm/+8tf5lBBRJ/Oan49/98cVEDmcYg9PZ09LSrjcYSRzHcAAxDGBQQfMgJiuyAiFUFMSUT23mtu9YxYxVgX/6YPa3796QZGUfk9i/Mhvo3//8W99443wwKtB0T1fXqM3m0en0iJUgSIIkKYoiKBL9A4QqAEcCSFJnbnI3uboqIpHP7D7T73WYDbfW4+IexwHB22+OX3zpsfAu5nI96vUM0gY9wqN0JEJG2AAATFs7hlABrhKgk3qJQwwCgrY4/ZiuaSceO+VvslkM11Yi9xG8+dLj33/tdDgLPB1POB09JE0RAOESFEEiVOWQaIZBPxCtX2MBUKVRMAXTWZyk2RaPRp440lIV5PngboPgZE/br16/kBJwR9dTTtdxQkejBzUOoHxO4P2CCAgcV+8iDSHUWWyA0ieDa4N++1J4N8VUVMVfvTCEm/S0vc/Z1g9IoKIjU6PHkCBvyrJ63hMJffZ+tQkyDnDVPThR18beM6zvHmky0i8/OYDAwTGvfXz0WKoCXL5BFVv1p0qgmULRMJTD0HVKWdqj1EZVS2meV+MNU1zHTmZE6tLJ7qOeFvLMQ504TRkt3SarC00j1aOBrhmksUxFu4PuNxytAqHAhZj2Bw2h6Kprgym40d5m9PXqmbXTA53gzIA/V+KaXZ3aTBSCuKrpniDMOo+yv/bGr3qCyv46VE8jDVCmIBT0t7mtK1fkn+rzgpPdrWy5arS2qloCXHMWdp8flYatZGVPm7rd7nc6psUV0BgQgsnhYbnacGcr8DltXE3UGZsxFNA4JAgcUzU/RHDoWsOFh2Pp8ES0OnX9anWAtNnK1wSf00paTIZG0UAhV19+4/uAHNCqc2Hj3n2CDCxDWRvU1FCLJuB43qijahyLiFG2wEZ5wr+gLOKac7USUX/+gVlQ1pahsdZKjEFHcxwPWIZpNus5JgUhPICqY+1B4XvAQItHrUjsDR6aiRRT9gAq2USzUccyLNhNpe0WI5uOYFrEoAPDDqHvoSJMcJ8Q+7f3J6rxIGP1hbKJsN1iQOAgtJNutZu5bKjEpmU1HNXQeABcKzsNIfeKqVbv8H0OLbCgamQIuXySS6y7rOZQIgO2M2WsxrealHRsSdEiW5Kkfez6uV47Dyg0+ANzgUbqIAfXDZBZn3eSoiJUorkyoMzW9bW1Tk+LkFtNJ1YQPApESZFAAxqAQ9jEYZK6aKPItJJaPdRPdmupGlnocDWvra4hcHCi7/jdxXtihe3yWFKx2+lsUJZESVKLxAH2F1A0wNEAsrooC5Ko5ggb38wsBbps+mqZXVxZHeg7Dvq7vYlo+c78vN9t7fSARPxmMrmuCKIgSfUqRnwxeEOQZQRBRnpDWcxur6QWPm3XcT67eX5uLrHD93V5SSOsWk2ttwMLNp9rePwiyZbC0Vs8X/R5T+gNFog41F2SOEjdevRrXhVFUS2sklTjSsmt21xw7ogZ8za3XEcyvdzS3KOXeeInlx9iC3IikqkKCZ2ROjr6kKXJVCjsRqMx9CRBGpHBkWXrW1g9nRG0pNpRRGav8Gw6thy995mhuHW81eSxmK4HpiYnrzNFU9+xXp/XQLz8aIel2RqeTZZrNVHYJYDi7u7s6OqkaaJQSEajYYbJ8xwvSgJaLDI3YuW5EsNkc7lIYmchEbtJC9tHHFS/z6GUuclrE4GJwG6BBpJ1bKy3WGXJ5WDs+WfOOX0t+UgmaqieOM1uXP2Xb/iUv+Nhv7+DYYRstlIoZLYj259rvMg2D+mwuq2ohjL81vTC8tQ0hyk7eRpyTd52W09P6/uBKXLmXuSlK7D3VM+tSAZugv7Lb3349otCOe3OxW3+oWb7gNXqwDAdhqHdX0I1BsNQ+8ZjWBXDOHQh88XY3EpoZml1ZjGdLP/ivX9cffcVtKcPDXdStHJ7bZtcjGS2Ntb7xwbDs2F2K4UX37rzMcOOQoN5RSpuNbnnjPYjlMkP6DaIm1AfpDZdQqlWSVVyMSYeTm5sJtZCHMOHd2q7O2T449+hXdPvd5wc7tpYX12OZslIEd6YWe4a7h+8PHT9D5/GVxhXEiTey2eC1aOnnINnUUuUx2vLtIGUqlKVq/FlgWf5ClstM1yF4Zk0F4zUIiGhkiLNgNxeLaDUfvzxXkAIgfmV7TJGcBJGSJUeFz36wllBlP/+6+suknQSlCGthGfyK7PpWKhcydckUYtRHBN5KZ/m4qHS+jK7OFNYmC6mNyRzlTIRSDlseT537uzApUvDk4HAX29s3C2olsUWk9K/r06jPBj94WmlJu68v4RuNpGEkzLCNJbbza98mL4qiowsj35vOLZVWL8VpnFcDwA6/AQt62FVwQSo7iVjj/WOP/fwzVs3PpicvVuAjcarJKhrawM5i8My+NoFqSxVtlKEApE1DQA4KKqd1nXrdb1Gw/jf/jL2/KPyO5+00bSVotCoorkexS9OkWPnB158eWxpbnYiEPgsrmyyh1rHGCOhztkF07SJOHrlrMnTVo3nFKaCdmgSRxs56kXU3a79lZ3NTz/JLORFXkG4yGwSVNFt7Y6nvzM2dubo7NTUxLVrEzH5Zgo+2PyGswJqarwUq0gV92ivf/wSbbFIGRayZVSP1WqM47pHbKH5TC3MCRW5TmBpt498e/TZN85RRHn6s4mF2flAVJ5Mavb6/K6K2pZvPuZ45ZK364jTfXzE2j5EQn95LsyvbJXWQ+VofDIci4vC00d9lMdlOuZ2DHndI242EgqjPJheiCdLE1vVqYSswC99wznVZ33hvOfKxQ5Ts6HJ3X0oD8xaHlQVoVCrJCq5OLMTSm5sJO4FObY6tVqcCnJrWfkrvaPpaXBxzP3sOd9zT3fYXSa9kab0lFhFVRPlAepAahUWJUEV5UE2XZ5azE6vl+YivCDDr/2WOdzfcmqkdWTINXDC4XXpzTqiWq7F42wwyKxuFO5sMneDxc0Ej/0/y38FGACBHjS0mkQ17AAAAABJRU5ErkJggg==";var a=function(){function s(s){var a=this;this.K=s,this.Is=t.html.canvas({width:"32",height:"481",style:"width: 100%; height: 100%;"}),this.Zs=t.html.canvas({width:"32",height:"40"}),this.container=t.html.div({style:"width: 32px; height: 100%; overflow:hidden; position: relative; flex-shrink: 0; touch-action: none;"},[this.Is,this.Zs]),this.Cs=this.Is.getContext("2d"),this.Gs=this.Zs.getContext("2d"),this.ii=32,this.At=481,this.Et=0,this.Nt=0,this.Bt=!1,this.Rt=!1,this.Us=-1,this.Ht=!1,this.js=-1,this.si=function(t){a.Rt||(a.Rt=!0,a.di())},this.ei=function(t){a.Rt&&(a.Rt=!1,a.di())},this.ni=function(t){t.preventDefault(),a.Bt=!0;var i=a.Is.getBoundingClientRect();a.Et=(t.clientX||t.pageX)-i.left,a.Nt=((t.clientY||t.pageY)-i.top)*a.At/(i.bottom-i.top),isNaN(a.Nt)&&(a.Nt=0),a.K.synth.pianoPressed=!0,a.di()},this.oi=function(t){var i=a.Is.getBoundingClientRect();a.Et=(t.clientX||t.pageX)-i.left,a.Nt=((t.clientY||t.pageY)-i.top)*a.At/(i.bottom-i.top),isNaN(a.Nt)&&(a.Nt=0),a.zs(),a.K.synth.pianoPitch[0]=a.Ds+12*a.K.song.channels[a.K.channel].octave,a.di()},this._i=function(t){a.Bt=!1,a.K.synth.pianoPressed=!1,a.di()},this.ri=function(t){t.preventDefault(),a.Bt=!0;var i=a.Is.getBoundingClientRect();a.Et=t.touches[0].clientX-i.left,a.Nt=(t.touches[0].clientY-i.top)*a.At/(i.bottom-i.top),isNaN(a.Nt)&&(a.Nt=0),a.zs(),a.K.synth.pianoPressed=!0,a.K.synth.pianoPitch[0]=a.Ds+12*a.K.song.channels[a.K.channel].octave},this.li=function(t){t.preventDefault();var i=a.Is.getBoundingClientRect();a.Et=t.touches[0].clientX-i.left,a.Nt=(t.touches[0].clientY-i.top)*a.At/(i.bottom-i.top),isNaN(a.Nt)&&(a.Nt=0),a.zs(),a.K.synth.pianoPitch[0]=a.Ds+12*a.K.song.channels[a.K.channel].octave},this.fs=function(t){t.preventDefault(),a.K.synth.pianoPressed=!1},this.vi=function(){var i=a.K.song.getChannelIsDrum(a.K.channel);a.bi=i?40:13,a.mi=i?t.Config.drumCount:t.Config.pitchCount,a.zs(),a.K.synth.pianoPitch[0]=a.Ds+12*a.K.song.channels[a.K.channel].octave,a.K.synth.pianoChannel=a.K.channel,a.cs()},this.cs=function(){if(i){if(a.K.showLetters){var s=a.K.song.getChannelIsDrum(a.K.channel);if(a.Us!=a.K.song.scale||a.js!=a.K.song.key||a.Ht!=s){var l;a.Us=a.K.song.scale,a.js=a.K.song.key,a.Ht=s,a.Cs.clearRect(0,0,a.ii,a.At);for(var u=0;u<a.mi;u++){var f=(u+t.Config.keyTransposes[a.K.song.key])%12;if(s){l=o;var c=1-u/a.mi*.35,d=.5*(1-c),v=l.width*d,p=l.height*d+a.bi*(a.mi-u-1),b=l.width*c,m=l.height*c;a.Cs.drawImage(l,v,p,b,m);for(var w=1+(u-a.mi/2)/a.mi*.5,g=a.Cs.getImageData(v,p,b,m),x=g.data,y=0;y<x.length;y+=4)x[y+0]*=w,x[y+1]*=w,x[y+2]*=w;a.Cs.putImageData(g,v,p)}else if(t.Config.scaleFlags[a.K.song.scale][u%12]){var M=t.Config.pitchNames[f];if(null==M){var k=t.Config.blackKeyNameParents[u%12];M=t.Config.pitchNames[(f+12+k)%12],1==k?M+="♭":-1==k&&(M+="♯")}var A=t.Config.pianoScaleFlags[f]?"#000000":"#ffffff";l=t.Config.pianoScaleFlags[f]?h:e,a.Cs.drawImage(l,0,a.bi*(a.mi-u-1)),a.Cs.font="bold 11px sans-serif",a.Cs.fillStyle=A,a.Cs.fillText(M,15,a.bi*(a.mi-u)-3)}else l=t.Config.pianoScaleFlags[f]?r:n,a.Cs.drawImage(l,0,a.bi*(a.mi-u-1))}a.di()}}}else window.requestAnimationFrame(a.cs)},this.K.notifier.watch(this.vi),this.vi(),this.container.addEventListener("mousedown",this.ni),document.addEventListener("mousemove",this.oi),document.addEventListener("mouseup",this._i),this.container.addEventListener("mouseover",this.si),this.container.addEventListener("mouseout",this.ei),this.container.addEventListener("touchstart",this.ri),this.container.addEventListener("touchmove",this.li),this.container.addEventListener("touchend",this.fs),this.container.addEventListener("touchcancel",this.fs)}return s.prototype.zs=function(){var i=t.Config.scaleFlags[this.K.song.scale],s=Math.max(0,Math.min(this.mi-1,this.mi-this.Nt/this.bi));if(i[Math.floor(s)%12]||this.K.song.getChannelIsDrum(this.K.channel))this.Ds=Math.floor(s);else{for(var e=Math.floor(s)+1,n=Math.floor(s)-1;!i[e%12];)e++;for(;!i[n%12];)n--;var h=e,r=n+1;e%12!=0&&e%12!=7||(h-=.5),n%12!=0&&n%12!=7||(r+=.5),this.Ds=s-r>h-s?e:n}},s.prototype.di=function(){this.Zs.style.visibility=!this.Rt||this.Bt?"hidden":"visible",this.Rt&&!this.Bt&&(this.Gs.clearRect(0,0,32,40),this.Zs.style.left="0px",this.Zs.style.top=this.bi*(this.mi-this.Ds-1)+"px",this.Gs.lineWidth=2,this.Gs.strokeStyle="#ffffff",this.Gs.strokeRect(1,1,this.ii-2,this.bi-2))},s}();t.Piano=a}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.span,n=t.html.input,h=t.html.br,r=t.html.text,o=function(){function o(a,l){var u=this;this.K=a,this.Si=l,this.Ys=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Ts=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Fs=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Vs=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Ps=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Os=n({style:"width: 3em; margin-left: 1em;",type:"number",step:"1"}),this.Ws=i({style:"width:45%;"},[r("Okay")]),this.Js=i({style:"width:45%;"},[r("Cancel")]),this.container=s({className:"prompt",style:"width: 250px;"},[s({style:"font-size: 2em"},[r("Custom Song Size")]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[s({style:"text-align: right;"},[r("Beats per bar:"),h(),e({style:"font-size: smaller; color: #888888;"},[r("(Multiples of 3 or 4 are recommended)")])]),this.Ys]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[s({style:"display: inline-block; text-align: right;"},[r("Bars per song:"),h(),e({style:"font-size: smaller; color: #888888;"},[r("(Multiples of 2 or 4 are recommended)")])]),this.Ts]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[r("Patterns per channel:"),this.Fs]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[r("Instruments per channel:"),this.Vs]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[r("Number of pitch channels:"),this.Ps]),s({style:"display: flex; flex-direction: row; align-items: center; height: 2em; justify-content: flex-end;"},[r("Number of drum channels:"),this.Os]),s({style:"display: flex; flex-direction: row; justify-content: space-between;"},[this.Ws,this.Js])]),this.Qs=function(){u.K.undo()},this.cleanUp=function(){u.Ws.removeEventListener("click",u.Hs),u.Js.removeEventListener("click",u.Qs),u.Ys.removeEventListener("keypress",o.Xs),u.Ts.removeEventListener("keypress",o.Xs),u.Fs.removeEventListener("keypress",o.Xs),u.Vs.removeEventListener("keypress",o.Xs),u.Ps.removeEventListener("keypress",o.Xs),u.Os.removeEventListener("keypress",o.Xs),u.Ys.removeEventListener("blur",o._s),u.Ts.removeEventListener("blur",o._s),u.Fs.removeEventListener("blur",o._s),u.Vs.removeEventListener("blur",o._s),u.Ps.removeEventListener("blur",o._s),u.Os.removeEventListener("blur",o._s)},this.Hs=function(){var i=new t.ChangeGroup;i.append(new t.ChangeBeatsPerBar(u.K,o.Ks(u.Ys))),i.append(new t.ChangeBarCount(u.K,o.Ks(u.Ts))),i.append(new t.ChangePatternsPerChannel(u.K,o.Ks(u.Fs))),i.append(new t.ChangeInstrumentsPerChannel(u.K,o.Ks(u.Vs))),i.append(new t.ChangeChannelCount(u.K,o.Ks(u.Ps),o.Ks(u.Os))),u.K.prompt=null,u.K.record(i,!0)},this.Ys.value=this.K.song.beatsPerBar+"",this.Ys.min=t.Config.beatsPerBarMin+"",this.Ys.max=t.Config.beatsPerBarMax+"",this.Ts.value=this.K.song.barCount+"",this.Ts.min=t.Config.barCountMin+"",this.Ts.max=t.Config.barCountMax+"",this.Fs.value=this.K.song.patternsPerChannel+"",this.Fs.min=t.Config.patternsPerChannelMin+"",this.Fs.max=t.Config.patternsPerChannelMax+"",this.Vs.value=this.K.song.instrumentsPerChannel+"",this.Vs.min=t.Config.instrumentsPerChannelMin+"",this.Vs.max=t.Config.instrumentsPerChannelMax+"",this.Ps.value=this.K.song.pitchChannelCount+"",this.Ps.min=t.Config.pitchChannelCountMin+"",this.Ps.max=t.Config.pitchChannelCountMax+"",this.Os.value=this.K.song.drumChannelCount+"",this.Os.min=t.Config.drumChannelCountMin+"",this.Os.max=t.Config.drumChannelCountMax+"",this.Ws.addEventListener("click",this.Hs),this.Js.addEventListener("click",this.Qs),this.Ys.addEventListener("keypress",o.Xs),this.Ts.addEventListener("keypress",o.Xs),this.Fs.addEventListener("keypress",o.Xs),this.Vs.addEventListener("keypress",o.Xs),this.Ps.addEventListener("keypress",o.Xs),this.Os.addEventListener("keypress",o.Xs),this.Ys.addEventListener("blur",o._s),this.Ts.addEventListener("blur",o._s),this.Fs.addEventListener("blur",o._s),this.Vs.addEventListener("blur",o._s),this.Ps.addEventListener("blur",o._s),this.Os.addEventListener("blur",o._s)}return o.Xs=function(t){var i=t.which?t.which:t.keyCode;return 46!=i&&i>31&&(i<48||i>57)&&(t.preventDefault(),!0)},o._s=function(t){var i=t.target;i.value=Math.floor(Math.max(Number(i.min),Math.min(Number(i.max),Number(i.value))))+""},o.Ks=function(t){return Math.floor(Number(t.value))},o}();t.SongDurationPrompt=o}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.input,n=t.html.text;function h(t,i,s){return t+s*(i-t)}function r(t,i){if(navigator.msSaveOrOpenBlob)navigator.msSaveOrOpenBlob(t,i);else{var s=document.createElement("a");if(void 0!=s.download){var e=URL.createObjectURL(t);setTimeout(function(){URL.revokeObjectURL(e)},6e4),s.href=e,s.download=i,setTimeout(function(){s.dispatchEvent(new MouseEvent("click"))},0)}else if(navigator.vendor.indexOf("Apple")>-1){var n=new FileReader;n.onloadend=function(){console.log(n.result);var t=n.result.replace(/^data:[^;]*;/,"data:attachment/file;");window.open(t,"_blank")||(window.location.href=t)},n.readAsDataURL(t)}else{var h=URL.createObjectURL(t);setTimeout(function(){URL.revokeObjectURL(h)},6e4),window.open(h,"_blank")||(window.location.href=h)}}}ArrayBuffer.transfer||(ArrayBuffer.transfer=function(t,i){var s=new ArrayBuffer(i);if(!(t instanceof ArrayBuffer&&s instanceof ArrayBuffer))throw new TypeError("Source and destination must be ArrayBuffer instances");for(var e=0,n=Math.min(t.byteLength,s.byteLength),h=0,r=[8,4,2,1];h<r.length;h++){var o=r[h];if(n>=o){var a=l(o,t,s,e,n);e=a.nextOffset,n=a.leftBytes}}return s;function l(t,i,s,e,n){var h=Uint8Array;switch(t){case 8:h=Float64Array;break;case 4:h=Float32Array;break;case 2:h=Uint16Array;break;case 1:default:h=Uint8Array}for(var r=new h(i,e,n/t|0),o=new h(s,e,n/t|0),a=0;a<o.length;a++)o[a]=r[a];return{nextOffset:r.byteOffset+r.byteLength,leftBytes:n-o.length*t}}});var o=function(){function o(a,l){var u=this;this.K=a,this.Si=l,this.qs=e({type:"text",style:"width: 10em;",value:"BeepBox-Song",maxlength:250}),this.$s=e({type:"checkbox"}),this.te=e({style:"width: 2em;",type:"number",min:"1",max:"4",step:"1"}),this.ie=e({type:"checkbox"}),this.se=i({},[n("Export to .wav file")]),this.ee=i({},[n("Export to .midi file")]),this.ne=i({},[n("Export to .json file")]),this.Js=i({},[n("Cancel")]),this.container=s({className:"prompt",style:"width: 200px;"},[s({style:"font-size: 2em"},[n("Export Options")]),s({style:"display: flex; flex-direction: row; align-items: center; justify-content: space-between;"},[n("File name:"),this.qs]),s({style:"display: table; width: 100%;"},[s({style:"display: table-row;"},[s({style:"display: table-cell;"},[n("Intro:")]),s({style:"display: table-cell;"},[n("Loop Count:")]),s({style:"display: table-cell;"},[n("Outro:")])]),s({style:"display: table-row;"},[s({style:"display: table-cell; vertical-align: middle;"},[this.$s]),s({style:"display: table-cell; vertical-align: middle;"},[this.te]),s({style:"display: table-cell; vertical-align: middle;"},[this.ie])])]),this.se,this.ee,this.ne,this.Js]),this.Qs=function(){u.K.undo()},this.cleanUp=function(){u.qs.removeEventListener("input",o.he),u.te.removeEventListener("blur",o._s),u.se.removeEventListener("click",u.re),u.ee.removeEventListener("click",u.oe),u.ne.removeEventListener("click",u.ae),u.Js.removeEventListener("click",u.Qs)},this.re=function(){var i=new t.Synth(u.K.song);if(i.enableIntro=u.$s.checked,i.enableOutro=u.ie.checked,i.loopCount=Number(u.te.value),!i.enableIntro)for(var s=0;s<u.K.song.loopStart;s++)i.nextBar();var e=i.totalSamples,n=new Float32Array(e);i.synthesize(n,e);var h,o,a,l=1*e,f=0,c=new ArrayBuffer(44+2*l),d=new DataView(c);d.setUint32(f,1380533830,!1),f+=4,d.setUint32(f,36+2*l,!0),f+=4,d.setUint32(f,1463899717,!1),f+=4,d.setUint32(f,1718449184,!1),f+=4,d.setUint32(f,16,!0),f+=4,d.setUint16(f,1,!0),f+=2,d.setUint16(f,1,!0),f+=2,d.setUint32(f,44100,!0),f+=4,d.setUint32(f,88200,!0),f+=4,d.setUint16(f,2,!0),f+=2,d.setUint16(f,16,!0),f+=2,d.setUint32(f,1684108385,!1),f+=4,d.setUint32(f,2*l,!0),f+=4,h=1,o=1;for(var v=0;v<e;v++){a=Math.floor(32767*n[v*h]);for(var p=0;p<o;p++)d.setInt16(f,a,!0),f+=2}r(new Blob([c],{type:"audio/wav"}),u.qs.value.trim()+".wav"),u.Qs()},this.oe=function(){var i=0,s=0,e=new ArrayBuffer(1024),n=new DataView(e);function o(t){(s+=t)>e.byteLength&&(e=ArrayBuffer.transfer(e,Math.max(2*e.byteLength,s)),n=new DataView(e))}function a(t){t>>>=0,o(4),n.setUint32(i,t,!1),i=s}function l(t){t>>>=0,o(3),n.setUint8(i,t>>16&255),n.setUint8(i+1,t>>8&255),n.setUint8(i+2,255&t),i=s}function f(t){t>>>=0,o(2),n.setUint16(i,t,!1),i=s}function c(t){t>>>=0,o(1),n.setUint8(i,t),i=s}function d(t,e){e=e>>>0&127|(1&t)<<7,o(1),n.setUint8(i,e),i=s}function v(t){if((t>>>=0)>268435455)throw new Error("writeVariableLength value too big.");for(var i=!1,s=0;s<4;s++){var e=t>>>21-7*s&127;0==e&&3!=s||(i=!0),i&&d(3==s?0:1,e)}}function p(t){v(t.length);for(var i=0;i<t.length;i++){var s=t.charCodeAt(i);if(s>127)throw new Error("Trying to write unicode character as ascii.");c(s)}}var b=u.K.song,m=96/b.partsPerBeat,w=m/4,g=b.getBeatsPerMinute(),x=Math.round(6e7/g),y=60/(96*g),M=96*b.beatsPerBar,k=[];if(u.$s.checked)for(var A=0;A<b.loopStart;A++)k.push(A);for(var E=0;E<Number(u.te.value);E++)for(A=b.loopStart;A<b.loopStart+b.loopLength;A++)k.push(A);if(u.ie.checked)for(A=b.loopStart+b.loopLength;A<b.barCount;A++)k.push(A);for(var N=[{isMeta:!0,channel:-1,midiChannel:-1,isChorus:!1,isDrums:!1}],B=0,R=0;R<u.K.song.getChannelCount();R++)u.K.song.getChannelIsDrum(R)?(N.push({isMeta:!1,channel:R,midiChannel:B++,isChorus:!1,isDrums:!0}),9==B&&B++):(N.push({isMeta:!1,channel:R,midiChannel:B++,isChorus:!1,isDrums:!1}),9==B&&B++,N.push({isMeta:!1,channel:R,midiChannel:B++,isChorus:!0,isDrums:!1}),9==B&&B++);a(1297377380),a(6),f(1),f(N.length),f(96);for(var L=function(e){a(1297379947);var r=e.isMeta,o=e.channel,g=e.midiChannel,A=e.isChorus,E=e.isDrums,N=i;i=s+=4;var B=0,R=0,L=function(t){if(t<B)throw new Error("Midi event time cannot go backwards.");v(t-B),B=t};if(r){L(0),f(65281),p("http://www.beepbox.co/#"+b.toBase64String()),L(0),l(16732419),l(x),L(0),l(16734212),c(b.beatsPerBar),c(2),c(24),c(8);var S=b.scale<10&&1==(1&b.scale),I=11-b.key,Z=I;for(1==(1&I)&&(Z+=6),S&&(Z+=9);Z>6;)Z-=12;L(0),l(16734466),c(Z),c(S?1:0),u.$s.checked&&(R+=M*b.loopStart),L(R),f(65286),p("Loop Start");for(var C=0;C<Number(u.te.value);C++)L(R+=M*b.loopLength),f(65286),p(C<Number(u.te.value)-1?"Loop Repeat":"Loop End");if(u.ie.checked&&(R+=M*(b.barCount-b.loopStart-b.loopLength)),R!=M*k.length)throw new Error("Miscalculated number of bars.")}else{var G=b.getChannelIsDrum(o)?t.Config.midiDrumChannelNames[o-b.pitchChannelCount]:t.Config.midiPitchChannelNames[o];A&&(G+=" chorus"),L(0),f(65283),p(G),L(R),c(176|g),d(0,126),d(0,1),L(R),c(176|g),d(0,68),d(0,127);for(var U=-1,j=-1,z=-1,D=E?33:t.Config.keyTransposes[b.key],Y=E?t.Config.drumInterval:1,T=0,F=k;T<F.length;T++){var V=F[T],P=b.getPattern(o,V);if(null!=P){var O=P.instrument,W=b.channels[o].instruments[O];if(A&&(E||1==W.type||0==W.chorus)){R+=M;continue}if(U!=O){U=O;var J="",Q=81;if(E)J+="type: "+t.Config.instrumentTypeNames[2],J+=", noise: "+t.Config.drumNames[W.wave],J+=", volume: "+t.Config.volumeNames[W.volume],J+=", transition: "+t.Config.transitionNames[W.transition],Q=126;else if(J+="type: "+t.Config.instrumentTypeNames[W.type],0==W.type){J+=", wave: "+t.Config.waveNames[W.wave],J+=", volume: "+t.Config.volumeNames[W.volume],J+=", transition: "+t.Config.transitionNames[W.transition],J+=", filter: "+t.Config.filterNames[W.filter],J+=", chorus: "+t.Config.chorusNames[W.chorus],J+=", effect: "+t.Config.effectNames[W.effect],Q=(0==t.Config.filterDecays[W.filter]?t.Config.midiSustainInstruments:t.Config.midiDecayInstruments)[W.wave]}else{if(1!=W.type)throw new Error("Unrecognized instrument type.");J+=", transition: "+t.Config.transitionNames[W.transition],J+=", effect: "+t.Config.effectNames[W.effect],J+=", algorithm: "+t.Config.midiAlgorithmNames[W.algorithm],J+=", feedbackType: "+t.Config.midiFeedbackNames[W.feedbackType],J+=", feedbackAmplitude: "+W.feedbackAmplitude,J+=", feedbackEnvelope: "+t.Config.operatorEnvelopeNames[W.feedbackEnvelope];for(var H=0;H<t.Config.operatorCount;H++){var X=W.operators[H];J+=", operator"+(H+1)+": {",J+="frequency: "+t.Config.midiFrequencyNames[X.frequency],J+=", amplitude: "+X.amplitude,J+=", envelope: "+t.Config.operatorEnvelopeNames[X.envelope],J+="}"}}L(R),f(65284),p(J),L(R),c(192|g),d(0,Q);var _=(5-W.volume)/5;E||1!=W.type||(_=1),L(R),c(176|g),d(0,7),d(0,Math.round(127*_))}var K=W.effect,q=t.Config.effectVibratos[K],$=t.Config.effectTremolos[K],tt=0,it=!1,st=!0;if(!E)if(0==W.type)tt=t.Config.chorusIntervals[W.chorus],A||(tt*=-1),tt+=t.Config.chorusOffsets[W.chorus],it=t.Config.chorusHarmonizes[W.chorus];else{if(1!=W.type)throw new Error("Unrecognized instrument type.");st=!1}for(var et=0;et<P.notes.length;et++){for(var nt=P.notes[et],ht=R+nt.start*m,rt=ht,ot=nt.pins[0].volume,at=nt.pins[0].interval,lt=D+nt.pitches[0]*Y,ut=1;ut<nt.pins.length;ut++){for(var ft=ht+nt.pins[ut].time*m,ct=nt.pins[ut].volume,dt=nt.pins[ut].interval,vt=ft-rt,pt=0;pt<vt;pt++){var bt=rt+pt,mt=h(ot,ct,pt/vt),wt=h(at,dt,pt/vt),gt=Math.floor(pt/w)%4,xt=nt.pitches[0];st&&(it?A&&(2==nt.pitches.length?xt=nt.pitches[1]:3==nt.pitches.length?xt=nt.pitches[1+(gt>>1)]:4==nt.pitches.length&&(xt=nt.pitches[(3==gt?1:gt)+1])):2==nt.pitches.length?xt=nt.pitches[gt>>1]:3==nt.pitches.length?xt=nt.pitches[3==gt?1:gt]:4==nt.pitches.length&&(xt=nt.pitches[gt]));var yt=wt*Y+tt,Mt=Math.round(yt),kt=yt-Mt,At=Math.sin(2*Math.PI*(bt-R)*y/.14);(2!=K||bt-ht>=3*m)&&(kt+=q*At);var Et=Math.max(0,Math.min(16383,Math.round(8192+4096*kt))),Nt=mt/3,Bt=1+$*(At-1),Rt=Math.round(127*Nt*Bt);Et!=j&&(L(bt),c(224|g),d(0,127&Et),d(0,Et>>7&127)),Rt!=z&&(L(bt),c(176|g),d(0,11),d(0,Rt)),xt=D+xt*Y+Mt,bt==ht?(L(bt),c(144|g),d(0,xt),d(0,64)):xt!=lt&&(L(bt),c(144|g),d(0,xt),d(0,64),L(bt),c(128|g),d(0,lt),d(0,64)),j=Et,z=Rt,lt=xt}rt=ft,ot=ct,at=dt}L(R+nt.end*m),c(128|g),d(0,lt),d(0,64)}}R+=M}}L(R),l(16723712),n.setUint32(N,i-N-4,!1)},S=0,I=N;S<I.length;S++){L(I[S])}e=ArrayBuffer.transfer(e,s),r(new Blob([e],{type:"audio/midi"}),u.qs.value.trim()+".midi"),u.Qs()},this.ae=function(){var t=u.K.song.toJsonObject(u.$s.checked,Number(u.te.value),u.ie.checked),i=JSON.stringify(t,null,"\t");r(new Blob([i],{type:"application/json"}),u.qs.value.trim()+".json"),u.Qs()},this.te.value="1",0==this.K.song.loopStart?(this.$s.checked=!1,this.$s.disabled=!0):(this.$s.checked=!0,this.$s.disabled=!1),this.K.song.loopStart+this.K.song.loopLength==this.K.song.barCount?(this.ie.checked=!1,this.ie.disabled=!0):(this.ie.checked=!0,this.ie.disabled=!1),this.qs.addEventListener("input",o.he),this.te.addEventListener("blur",o._s),this.se.addEventListener("click",this.re),this.ee.addEventListener("click",this.oe),this.ne.addEventListener("click",this.ae),this.Js.addEventListener("click",this.Qs)}return o.he=function(t){var i=t.target,s=/[\+\*\$\?\|\{\}\\\/<>#%!`&'"=:@]/gi;if(s.test(i.value)){var e=i.selectionStart;i.value=i.value.replace(s,""),e--,i.setSelectionRange(e,e)}},o._s=function(t){var i=t.target;i.value=Math.floor(Math.max(Number(i.min),Math.min(Number(i.max),Number(i.value))))+""},o}();t.ExportPrompt=o}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.input,n=t.html.text,h=function(){return function(h,r){var o=this;this.K=h,this.Si=r,this.le=e({type:"file",accept:".json,application/json"}),this.Js=i({},[n("Cancel")]),this.container=s({className:"prompt",style:"width: 200px;"},[s({style:"font-size: 2em"},[n("Import")]),s({style:"text-align: left;"},[n("BeepBox songs can be exported and re-imported as .json files. You could also use other means to make .json files for BeepBox as long as they follow the same structure.")]),this.le,this.Js]),this.Qs=function(){o.K.undo()},this.cleanUp=function(){o.le.removeEventListener("change",o.ue),o.Js.removeEventListener("click",o.Qs)},this.ue=function(){var i=o.le.files[0];if(i){var s=new FileReader;s.addEventListener("load",function(i){o.K.prompt=null,o.K.record(new t.ChangeSong(o.K,s.result),!0)}),s.readAsText(i)}},this.le.addEventListener("change",this.ue),this.Js.addEventListener("click",this.Qs)}}();t.ImportPrompt=h}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.text,n=function(){return function(n,h){var r=this;this.K=n,this.Si=h,this.Js=i({},[e("Close")]),this.container=s({className:"prompt",style:"width: 300px;"},[s({style:"font-size: 2em"},[e("FM Synthesis")]),s({style:"text-align: left; margin: 0.5em 0;"},[e("Popularized by the Sega Genesis and Yamaha keyboards, FM Synthesis is a mysterious but powerful technique for crafting sounds. It may seem confusing, but just play around with the options until you get a feel for it, or check out some examples in "),t.html.element("a",{target:"_blank",href:"#6n10s0kbl00e07t5m0a7g07j7i7r1o2T1d2c0A0F1B0V1Q0200Pff00E0411T1d1c0A0F0B0V1Q2800Pf700E0711T1d2c0A0F1B4VaQ0200Pfb00E0911T1d1c2A0F9B3V1Q1000Pfbc0E0191T1d2c0AcF8B5V1Q0259PffffE0000T1d3c1AcF4B5V4Q2600Pff00E0011T1d1c0AbF0B0V1Q2580PfffaE2226T1d1c0A1F0B0V1Q520dPff4dEd41eb4zhmu0p21h5dfxd7ij7XrjfiAjPudUTtUSRsTzudTudJvdUTztTzrpPudUTtUSSYTzudTudJTdUTztTzrvPudUTtUSQ"},[e("this demo")]),e(". ")]),s({style:"text-align: left; margin: 0.5em 0;"},[e("This FM instrument uses up to four waves, numbered 1, 2, 3, and 4. Each wave may have its own frequency, volume, and volume envelope to control its effect over time. ")]),s({style:"text-align: left; margin: 0.5em 0;"},[e('There are two kinds of waves: "carrier" waves play a tone out loud, but "modulator" waves distort other waves instead. Wave 1 is always a carrier and plays a tone, but other waves may distort it. The "Algorithm" setting determines which waves are modulators, and which other waves those modulators distort. ')]),s({style:"text-align: left; margin: 0.5em 0;"},[e('Modulators distort in one direction (like 1←2), but you can also use "Feedback" to make any wave distort in the opposite direction (1→2), or even itself (1⟲). ')]),s({style:"text-align: left; margin: 0.5em 0;"},[e("You can set the pitch of each wave independently by adding simultaneous notes, one above another. This often sounds harsh or dissonant, but can make cool sound effects! ")]),this.Js]),this.Qs=function(){r.K.undo()},this.cleanUp=function(){r.Js.removeEventListener("click",r.Qs)},this.Js.addEventListener("click",this.Qs)}}();t.InstrumentTypePrompt=n}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.text,n=function(){return function(t,n){var h=this;this.K=t,this.Si=n,this.Js=i({},[e("Close")]),this.container=s({className:"prompt",style:"width: 250px;"},[s({style:"font-size: 2em"},[e("Custom Harmony")]),s({style:"text-align: left;"},[e('BeepBox "chip" instruments play two waves at once, each with their own pitch. The "Chorus" setting usually determines how far apart these pitches are, but in "custom harmony" mode, you can control these pitches individually by making two simultaneous notes, one above the other. This replaces the "arpeggio/trill" effect, and gives you greater control over your harmony. ')]),this.Js]),this.Qs=function(){h.K.undo()},this.cleanUp=function(){h.Js.removeEventListener("click",h.Qs)},this.Js.addEventListener("click",this.Qs)}}();t.ChorusPrompt=n}(beepbox||(beepbox={})),function(t){var i=t.html.button,s=t.html.div,e=t.html.span,n=t.html.select,h=t.html.option,r=t.html.input,o=t.html.text,a=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|android|ipad|playbook|silk/i.test(navigator.userAgent);function l(t,i){for(var s=0,e=i;s<e.length;s++){var n=e[s];t.appendChild(h(n,n,!1,!1))}return t}function u(t,i){t.selectedIndex!=i&&(t.selectedIndex=i)}var f=function(){function t(t,i,s){var e=this;this.input=t,this.K=i,this.fe=s,this.ns=null,this.ce=0,this.de=0,this.ve=function(){e.K.lastChangeWas(e.ns)||(e.de=e.ce),e.ns=e.fe(e.de,parseInt(e.input.value)),e.K.setProspectiveChange(e.ns)},this.pe=function(){e.K.record(e.ns),e.ns=null},t.addEventListener("input",this.ve),t.addEventListener("change",this.pe)}return t.prototype.updateValue=function(t){this.ce=t,this.input.value=String(t)},t}(),c=function(){function c(c){var d=this;this.K=c,this.prompt=null,this.be=new t.PatternEditor(this.K),this.me=new t.TrackEditor(this.K,this),this.we=new t.LoopEditor(this.K),this.vs=s({className:"trackContainer"},[this.me.container,this.we.container]),this.ge=new t.BarScrollBar(this.K,this.vs),this.xe=new t.OctaveScrollBar(this.K),this.ye=new t.Piano(this.K),this.Me=s({},[s({className:"editorBox",style:"height: 481px; display: flex; flex-direction: row; margin-bottom: 6px;"},[this.ye.container,this.be.container,this.xe.container]),this.vs,this.ge.container]),this.ke=i({style:"width: 80px;",type:"button"}),this.Ae=i({className:"prevBarButton",style:"width: 40px;",type:"button",title:"Previous Bar (left bracket)"}),this.Ee=i({className:"nextBarButton",style:"width: 40px;",type:"button",title:"Next Bar (right bracket)"}),this.Ne=r({title:"main volume",style:"width: 5em; flex-grow: 1; margin: 0px;",type:"range",min:"0",max:"100",value:"50",step:"1"}),this.Be=n({style:"width: 100%;"},[h("","Edit",!0,!0),h("undo","Undo (Z)",!1,!1),h("redo","Redo (Y)",!1,!1),h("copy","Copy Pattern (C)",!1,!1),h("paste","Paste Pattern (V)",!1,!1),h("transposeUp","Shift Notes Up (+)",!1,!1),h("transposeDown","Shift Notes Down (-)",!1,!1),h("duration","Custom song size...",!1,!1),h("import","Import JSON...",!1,!1)]),this.Re=n({style:"width: 100%;"},[h("","Preferences",!0,!0),h("autoPlay","Auto Play On Load",!1,!1),h("autoFollow","Auto Follow Track",!1,!1),h("showLetters","Show Piano",!1,!1),h("showFifth","Highlight 'Fifth' Notes",!1,!1),h("showChannels","Show All Channels",!1,!1),h("showScrollBar","Octave Scroll Bar",!1,!1)]),this.Le=i({type:"button"},[o("New"),e({className:"fullWidthOnly"},[o(" Song")]),t.svgElement("svg",{style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"-5 -21 26 26"},[t.svgElement("path",{d:"M 2 0 L 2 -16 L 10 -16 L 14 -12 L 14 0 z M 3 -1 L 13 -1 L 13 -11 L 9 -11 L 9 -15 L 3 -15 z",fill:"currentColor"})])]),this.Se=i({type:"button"},[o("Export"),t.svgElement("svg",{style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"-13 -13 26 26"},[t.svgElement("path",{d:"M -8 3 L -8 8 L 8 8 L 8 3 L 6 3 L 6 6 L -6 6 L -6 3 z M 0 2 L -4 -2 L -1 -2 L -1 -8 L 1 -8 L 1 -2 L 4 -2 z",fill:"currentColor"})])]),this.Ie=l(n({}),t.Config.scaleNames),this.Ze=l(n({}),t.Config.keyNames),this.Ce=new f(r({style:"margin: 0px;",type:"range",min:"0",max:t.Config.tempoSteps-1,value:"7",step:"1"}),this.K,function(i,s){return new t.ChangeTempo(d.K,i,s)}),this.Ge=new f(r({style:"margin: 0px;",type:"range",min:"0",max:t.Config.reverbRange-1,value:"0",step:"1"}),this.K,function(i,s){return new t.ChangeReverb(d.K,i,s)}),this.Ue=l(n({}),t.Config.partNames),this.je=l(n({}),t.Config.pitchChannelTypeNames),this.ze=t.html.element("a",{className:"hintButton"},[o("?")]),this.De=s({className:"selectRow"},[e({},[o("Type: ")]),this.ze,s({className:"selectContainer"},[this.je])]),this.Ye=l(n({}),t.Config.operatorAlgorithmNames),this.Te=s({className:"selectRow"},[e({},[o("Algorithm: ")]),s({className:"selectContainer"},[this.Ye])]),this.Fe=n({}),this.Ve=s({className:"selectRow",style:"display: none;"},[e({},[o("Instrument: ")]),s({className:"selectContainer"},[this.Fe])]),this.Pe=new f(r({style:"margin: 0px;",type:"range",min:"-5",max:"0",value:"0",step:"1"}),this.K,function(i,s){return new t.ChangeVolume(d.K,i,-s)}),this.Oe=s({className:"selectRow"},[e({},[o("Volume: ")]),this.Pe.input]),this.We=l(n({}),t.Config.waveNames),this.Je=l(n({}),t.Config.drumNames),this.Qe=s({className:"selectRow"},[e({},[o("Wave: ")]),s({className:"selectContainer"},[this.We,this.Je])]),this.He=l(n({}),t.Config.transitionNames),this.Xe=l(n({}),t.Config.filterNames),this._e=s({className:"selectRow"},[e({},[o("Filter: ")]),s({className:"selectContainer"},[this.Xe])]),this.Ke=l(n({}),t.Config.chorusNames),this.qe=t.html.element("a",{className:"hintButton"},[o("?")]),this.$e=s({className:"selectRow"},[e({},[o("Chorus: ")]),this.qe,s({className:"selectContainer"},[this.Ke])]),this.tn=l(n({}),t.Config.effectNames),this.in=s({className:"selectRow"},[e({},[o("Effect: ")]),s({className:"selectContainer"},[this.tn])]),this.sn=s({style:"display: flex; flex-direction: column; display: none;"},[]),this.en=l(n({}),t.Config.operatorFeedbackNames),this.nn=s({className:"selectRow"},[e({},[o("Feedback:")]),s({className:"selectContainer"},[this.en])]),this.hn=new f(r({style:"margin: 0px; width: 4em;",type:"range",min:"0",max:t.Config.operatorAmplitudeMax,value:"0",step:"1",title:"Feedback Amplitude"}),this.K,function(i,s){return new t.ChangeFeedbackAmplitude(d.K,i,s)}),this.rn=l(n({style:"width: 100%;",title:"Feedback Envelope"}),t.Config.operatorEnvelopeNames),this.on=s({className:"operatorRow"},[s({style:"margin-right: .1em; visibility: hidden;"},[o("1.")]),s({style:"width: 3em; margin-right: .3em;"}),this.hn.input,s({className:"selectContainer",style:"width: 5em; margin-left: .3em;"},[this.rn])]),this.an=s({},[this.Ve,this.De,this.Oe,this.Qe,s({className:"selectRow"},[e({},[o("Transition: ")]),s({className:"selectContainer"},[this.He])]),this._e,this.$e,this.in,this.Te,this.sn,this.nn,this.on]),this.ln=s({className:"promptContainer",style:"display: none;"}),this.mainLayer=s({className:"beepboxEditor",tabIndex:"0"},[this.Me,s({className:"editor-widget-column"},[s({style:"text-align: center; color: #999;"},[o("BeepBox 2.3")]),s({className:"editor-widgets"},[s({className:"editor-controls"},[s({className:"playback-controls"},[s({className:"playback-bar-controls"},[this.ke,this.Ae,this.Ee]),s({className:"playback-volume-controls"},[t.svgElement("svg",{style:"flex-shrink: 0;",width:"2em",height:"2em",viewBox:"0 0 26 26"},[t.svgElement("path",{d:"M 4 16 L 4 10 L 8 10 L 13 5 L 13 21 L 8 16 z M 15 11 L 16 10 A 7.2 7.2 0 0 1 16 16 L 15 15 A 5.8 5.8 0 0 0 15 12 z M 18 8 L 19 7 A 11.5 11.5 0 0 1 19 19 L 18 18 A 10.1 10.1 0 0 0 18 8 z",fill:"#777"})]),this.Ne])]),s({className:"editor-menus"},[this.Le,s({className:"selectContainer menu"},[this.Be,t.svgElement("svg",{style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"-5 -21 26 26"},[t.svgElement("path",{d:"M 0 0 L 1 -4 L 4 -1 z M 2 -5 L 10 -13 L 13 -10 L 5 -2 zM 11 -14 L 13 -16 L 14 -16 L 16 -14 L 16 -13 L 14 -11 z",fill:"currentColor"})])]),s({className:"selectContainer menu"},[this.Re,t.svgElement("svg",{style:"flex-shrink: 0; position: absolute; left: 0; top: 50%; margin-top: -1em; pointer-events: none;",width:"2em",height:"2em",viewBox:"-13 -13 26 26"},[t.svgElement("path",{d:"M 5.78 -1.6 L 7.93 -0.94 L 7.93 0.94 L 5.78 1.6 L 4.85 3.53 L 5.68 5.61 L 4.21 6.78 L 2.36 5.52 L 0.27 5.99 L -0.85 7.94 L -2.68 7.52 L -2.84 5.28 L -4.52 3.95 L -6.73 4.28 L -7.55 2.59 L -5.9 1.07 L -5.9 -1.07 L -7.55 -2.59 L -6.73 -4.28 L -4.52 -3.95 L -2.84 -5.28 L -2.68 -7.52 L -0.85 -7.94 L 0.27 -5.99 L 2.36 -5.52 L 4.21 -6.78 L 5.68 -5.61 L 4.85 -3.53 M 2.92 0.67 L 2.92 -0.67 L 2.35 -1.87 L 1.3 -2.7 L 0 -3 L -1.3 -2.7 L -2.35 -1.87 L -2.92 -0.67 L -2.92 0.67 L -2.35 1.87 L -1.3 2.7 L -0 3 L 1.3 2.7 L 2.35 1.87 z",fill:"currentColor"})])]),this.Se])]),s({className:"editor-settings"},[s({className:"editor-song-settings"},[s({style:"margin: 3px 0; text-align: center; color: #999;"},[o("Song Settings")]),s({className:"selectRow"},[e({},[o("Scale: ")]),s({className:"selectContainer"},[this.Ie])]),s({className:"selectRow"},[e({},[o("Key: ")]),s({className:"selectContainer"},[this.Ze])]),s({className:"selectRow"},[e({},[o("Tempo: ")]),this.Ce.input]),s({className:"selectRow"},[e({},[o("Reverb: ")]),this.Ge.input]),s({className:"selectRow"},[e({},[o("Rhythm: ")]),s({className:"selectContainer"},[this.Ue])])]),s({className:"editor-instrument-settings"},[s({style:"margin: 3px 0; text-align: center; color: #999;"},[o("Instrument Settings")]),this.an])])])]),this.ln]),this.un=null,this.fn=[],this.cn=[],this.dn=[],this.vn=[],this.pn=function(){d.mainLayer.focus()},this.whenUpdated=function(){var i=d.vs.getBoundingClientRect();d.K.trackVisibleBars=Math.floor((i.right-i.left)/32),d.ge.render(),d.me.render();for(var s=[(d.K.autoPlay?"✓ ":"")+"Auto Play On Load",(d.K.autoFollow?"✓ ":"")+"Auto Follow Track",(d.K.showLetters?"✓ ":"")+"Show Piano",(d.K.showFifth?"✓ ":"")+"Highlight 'Fifth' Notes",(d.K.showChannels?"✓ ":"")+"Show All Channels",(d.K.showScrollBar?"✓ ":"")+"Octave Scroll Bar"],e=0;e<s.length;e++){var n=d.Re.children[e+1];n.innerText!=s[e]&&(n.innerText=s[e])}var h=d.K.song.channels[d.K.channel],r=d.K.getCurrentPattern(),o=d.K.getCurrentInstrument(),a=h.instruments[o],f=d.mainLayer.contains(document.activeElement),c=document.activeElement;if(u(d.Ie,d.K.song.scale),u(d.Ze,d.K.song.key),d.Ce.updateValue(d.K.song.tempo),d.Ce.input.title=d.K.song.getBeatsPerMinute()+" beats per minute",d.Ge.updateValue(d.K.song.reverb),u(d.Ue,t.Config.partCounts.indexOf(d.K.song.partsPerBeat)),2==a.type)d.Oe.style.display="",d.Je.style.display="",d.Qe.style.display="",d.De.style.display="none",d.Te.style.display="none",d.sn.style.display="none",d.nn.style.display="none",d.on.style.display="none",d.We.style.display="none",d._e.style.display="none",d.$e.style.display="none",d.in.style.display="none";else if(0==a.type)d.De.style.display="",d.in.style.display="",d.Je.style.display="none",d.Oe.style.display="",d.We.style.display="",d.Qe.style.display="",d._e.style.display="",d.$e.style.display="",d.Te.style.display="none",d.sn.style.display="none",d.nn.style.display="none",d.on.style.display="none";else{if(1!=a.type)throw new Error("Unrecognized instrument type: "+a.type);d.De.style.display="",d.in.style.display="",d.Je.style.display="none",d.Te.style.display="",d.sn.style.display="",d.nn.style.display="",d.on.style.display="",d.Oe.style.display="none",d.Qe.style.display="none",d._e.style.display="none",d.$e.style.display="none"}if(u(d.je,a.type),u(d.Ye,a.algorithm),d.Ve.style.display=d.K.song.instrumentsPerChannel>1?"":"none",d.Ve.style.visibility=null==r?"hidden":"",d.Fe.children.length!=d.K.song.instrumentsPerChannel){for(;d.Fe.firstChild;)d.Fe.removeChild(d.Fe.firstChild);var v=[];for(e=0;e<d.K.song.instrumentsPerChannel;e++)v.push(e+1);l(d.Fe,v)}d.an.style.color=d.K.song.getNoteColorBright(d.K.channel),u(d.We,a.wave),u(d.Je,a.wave),u(d.Xe,a.filter),u(d.He,a.transition),u(d.tn,a.effect),u(d.Ke,a.chorus),u(d.en,a.feedbackType),d.hn.updateValue(a.feedbackAmplitude),u(d.rn,a.feedbackEnvelope),d.rn.parentElement.style.color=a.feedbackAmplitude>0?"":"#999",d.Pe.updateValue(-a.volume),u(d.Fe,o);for(e=0;e<t.Config.operatorCount;e++){var p=e<t.Config.operatorCarrierCounts[a.algorithm];d.fn[e].style.color=p?"white":"",u(d.vn[e],a.operators[e].frequency),d.cn[e].updateValue(a.operators[e].amplitude),u(d.dn[e],a.operators[e].envelope);var b=(p?"Voice ":"Modulator ")+(e+1);d.vn[e].title=b+" Frequency",d.cn[e].input.title=b+(p?" Volume":" Amplitude"),d.dn[e].title=b+" Envelope",d.dn[e].parentElement.style.color=a.operators[e].amplitude>0?"":"#999"}d.ye.container.style.display=d.K.showLetters?"":"none",d.xe.container.style.display=d.K.showScrollBar?"":"none",d.ge.container.style.display=d.K.song.barCount>d.K.trackVisibleBars?"":"none",d.ze.style.display=1==a.type?"":"none",d.qe.style.display=t.Config.chorusHarmonizes[a.chorus]?"":"none";var m=512;d.K.showLetters&&(m-=32),d.K.showScrollBar&&(m-=20),d.be.container.style.width=String(m)+"px",d.Ne.value=String(d.K.volume),f&&0==c.clientWidth&&d.pn(),d.bn(d.K.prompt),d.K.autoFollow&&!d.K.synth.playing&&d.K.synth.snapToBar(d.K.bar)},this.mn=function(i){if(d.prompt)27==i.keyCode&&window.history.back();else switch(d.me.onKeyPressed(i),i.keyCode){case 32:d.wn(),i.preventDefault();break;case 90:i.shiftKey?d.K.redo():d.K.undo(),i.preventDefault();break;case 89:d.K.redo(),i.preventDefault();break;case 67:d.gn(),i.preventDefault();break;case 86:d.xn(),i.preventDefault();break;case 219:d.K.synth.prevBar(),d.K.autoFollow&&new t.ChangeChannelBar(d.K,d.K.channel,Math.floor(d.K.synth.playhead)),i.preventDefault();break;case 221:d.K.synth.nextBar(),d.K.autoFollow&&new t.ChangeChannelBar(d.K,d.K.channel,Math.floor(d.K.synth.playhead)),i.preventDefault();break;case 189:case 173:d.yn(!1),i.preventDefault();break;case 187:case 61:d.yn(!0),i.preventDefault()}},this.Mn=function(){d.K.synth.prevBar()},this.kn=function(){d.K.synth.nextBar()},this.wn=function(){d.K.synth.playing?d.An():d.En()},this.Nn=function(){d.K.setVolume(Number(d.Ne.value))},this.Bn=function(){d.K.record(new t.ChangeSong(d.K,"")),d.be.resetCopiedPins()},this.Rn=function(){d.Ln("export")},this.Sn=function(){d.Ln("instrumentType")},this.In=function(){d.Ln("chorus")},this.Zn=function(){d.K.record(new t.ChangeScale(d.K,d.Ie.selectedIndex))},this.Cn=function(){d.K.record(new t.ChangeKey(d.K,d.Ze.selectedIndex))},this.Gn=function(){d.K.record(new t.ChangePartsPerBeat(d.K,t.Config.partCounts[d.Ue.selectedIndex]))},this.Un=function(){d.K.record(new t.ChangeInstrumentType(d.K,d.je.selectedIndex))},this.jn=function(){d.K.record(new t.ChangeFeedbackType(d.K,d.en.selectedIndex))},this.zn=function(){d.K.record(new t.ChangeFeedbackEnvelope(d.K,d.rn.selectedIndex))},this.Dn=function(){d.K.record(new t.ChangeAlgorithm(d.K,d.Ye.selectedIndex))},this.Yn=function(){var i=d.K.getCurrentPattern();null!=i&&d.K.record(new t.ChangePatternInstrument(d.K,d.Fe.selectedIndex,i))},this.Tn=function(){d.K.record(new t.ChangeWave(d.K,d.We.selectedIndex))},this.Fn=function(){d.K.record(new t.ChangeWave(d.K,d.Je.selectedIndex))},this.Vn=function(){d.K.record(new t.ChangeFilter(d.K,d.Xe.selectedIndex))},this.Pn=function(){d.K.record(new t.ChangeTransition(d.K,d.He.selectedIndex))},this.On=function(){d.K.record(new t.ChangeEffect(d.K,d.tn.selectedIndex))},this.Wn=function(){d.K.record(new t.ChangeChorus(d.K,d.Ke.selectedIndex))},this.Jn=function(t){switch(d.Be.value){case"undo":d.K.undo();break;case"redo":d.K.redo();break;case"copy":d.gn();break;case"paste":d.xn();break;case"transposeUp":d.yn(!0);break;case"transposeDown":d.yn(!1);break;case"import":d.Ln("import");break;case"duration":d.Ln("duration")}d.Be.selectedIndex=0},this.Qn=function(t){switch(d.Re.value){case"autoPlay":d.K.autoPlay=!d.K.autoPlay;break;case"autoFollow":d.K.autoFollow=!d.K.autoFollow;break;case"showLetters":d.K.showLetters=!d.K.showLetters;break;case"showFifth":d.K.showFifth=!d.K.showFifth;break;case"showChannels":d.K.showChannels=!d.K.showChannels;break;case"showScrollBar":d.K.showScrollBar=!d.K.showScrollBar}d.Re.selectedIndex=0,d.K.notifier.changed(),d.K.savePreferences()},this.K.notifier.watch(this.whenUpdated),this.sn.appendChild(s({className:"operatorRow",style:"color: #999; height: 1em; margin-top: 0.5em;"},[s({style:"margin-right: .1em; visibility: hidden;"},[o("1.")]),s({style:"width: 3em; margin-right: .3em;"},[o("Freq:")]),s({style:"width: 4em; margin: 0;"},[o("Volume:")]),s({style:"width: 5em; margin-left: .3em;"},[o("Envelope:")])]));for(var v=function(i){var e=i,h=s({style:"margin-right: .1em; color: #999;"},[o(i+1+".")]),a=l(n({style:"width: 100%;",title:"Frequency"}),t.Config.operatorFrequencyNames),u=new f(r({style:"margin: 0; width: 4em;",type:"range",min:"0",max:t.Config.operatorAmplitudeMax,value:"0",step:"1",title:"Volume"}),p.K,function(i,s){return new t.ChangeOperatorAmplitude(d.K,e,i,s)}),c=l(n({style:"width: 100%;",title:"Envelope"}),t.Config.operatorEnvelopeNames),v=s({className:"operatorRow"},[h,s({className:"selectContainer",style:"width: 3em; margin-right: .3em;"},[a]),u.input,s({className:"selectContainer",style:"width: 5em; margin-left: .3em;"},[c])]);p.sn.appendChild(v),p.fn[i]=v,p.cn[i]=u,p.dn[i]=c,p.vn[i]=a,c.addEventListener("change",function(){d.K.record(new t.ChangeOperatorEnvelope(d.K,e,c.selectedIndex))}),a.addEventListener("change",function(){d.K.record(new t.ChangeOperatorFrequency(d.K,e,a.selectedIndex))})},p=this,b=0;b<t.Config.operatorCount;b++)v(b);this.Be.addEventListener("change",this.Jn),this.Re.addEventListener("change",this.Qn),this.Ie.addEventListener("change",this.Zn),this.Ze.addEventListener("change",this.Cn),this.Ue.addEventListener("change",this.Gn),this.je.addEventListener("change",this.Un),this.Ye.addEventListener("change",this.Dn),this.Fe.addEventListener("change",this.Yn),this.en.addEventListener("change",this.jn),this.rn.addEventListener("change",this.zn),this.We.addEventListener("change",this.Tn),this.Je.addEventListener("change",this.Fn),this.He.addEventListener("change",this.Pn),this.Xe.addEventListener("change",this.Vn),this.Ke.addEventListener("change",this.Wn),this.tn.addEventListener("change",this.On),this.ke.addEventListener("click",this.wn),this.Ae.addEventListener("click",this.Mn),this.Ee.addEventListener("click",this.kn),this.Le.addEventListener("click",this.Bn),this.Se.addEventListener("click",this.Rn),this.Ne.addEventListener("input",this.Nn),this.ze.addEventListener("click",this.Sn),this.qe.addEventListener("click",this.In),this.Me.addEventListener("mousedown",this.pn),this.mainLayer.addEventListener("keydown",this.mn),a&&(this.Re.children[1].disabled=!0)}return c.prototype.Ln=function(t){this.K.openPrompt(t),this.bn(t)},c.prototype.bn=function(i){if(this.prompt&&(this.Hn&&this.En(),this.Hn=!1,this.ln.style.display="none",this.ln.removeChild(this.prompt.container),this.prompt.cleanUp(),this.prompt=null,this.mainLayer.focus()),i){switch(i){case"export":this.prompt=new t.ExportPrompt(this.K,this);break;case"import":this.prompt=new t.ImportPrompt(this.K,this);break;case"duration":this.prompt=new t.SongDurationPrompt(this.K,this);break;case"instrumentType":this.prompt=new t.InstrumentTypePrompt(this.K,this);break;case"chorus":this.prompt=new t.ChorusPrompt(this.K,this);break;default:throw new Error("Unrecognized prompt type.")}this.prompt&&(this.Hn=this.K.synth.playing,this.An(),this.ln.style.display=null,this.ln.appendChild(this.prompt.container))}},c.prototype.updatePlayButton=function(){this.K.synth.playing?(this.ke.classList.remove("playButton"),this.ke.classList.add("pauseButton"),this.ke.title="Pause (Space)",this.ke.innerText="Pause"):(this.ke.classList.remove("pauseButton"),this.ke.classList.add("playButton"),this.ke.title="Play (Space)",this.ke.innerText="Play")},c.prototype.En=function(){this.K.synth.play(),this.updatePlayButton()},c.prototype.An=function(){this.K.synth.pause(),this.K.autoFollow?this.K.synth.snapToBar(this.K.bar):this.K.synth.snapToBar(),this.updatePlayButton()},c.prototype.gn=function(){var t=this.K.getCurrentPattern();if(null!=t){var i={notes:t.notes,beatsPerBar:this.K.song.beatsPerBar,partsPerBeat:this.K.song.partsPerBeat,drums:this.K.song.getChannelIsDrum(this.K.channel)};window.localStorage.setItem("patternCopy",JSON.stringify(i))}},c.prototype.xn=function(){var i=this.K.getCurrentPattern();if(null!=i){var s=JSON.parse(String(window.localStorage.getItem("patternCopy")));null!=s&&s.drums==this.K.song.getChannelIsDrum(this.K.channel)&&this.K.record(new t.ChangePaste(this.K,i,s.notes,s.beatsPerBar,s.partsPerBeat))}},c.prototype.yn=function(i){var s=this.K.getCurrentPattern();if(null!=s){var e=this.K.lastChangeWas(this.un);this.un=new t.ChangeTranspose(this.K,s,i),this.K.record(this.un,e)}},c}();t.SongEditor=c;var d=new t.SongDocument(location.hash),v=new c(d);if(document.getElementById("beepboxEditorContainer").appendChild(v.mainLayer),v.whenUpdated(),v.mainLayer.focus(),!a&&d.autoPlay){function p(){document.hidden||(d.synth.play(),v.updatePlayButton(),window.removeEventListener("visibilitychange",p))}document.hidden?window.addEventListener("visibilitychange",p):p()}"scrollRestoration"in history&&(history.scrollRestoration="manual"),v.updatePlayButton()}(beepbox||(beepbox={}));