From 145c8b50dafbcc67d27c3dbbbe9dd79a59996151 Mon Sep 17 00:00:00 2001 From: Bubobubobubobubo Date: Mon, 23 Oct 2023 19:38:52 +0000 Subject: [PATCH] deploy: 818dfd01705800239c2b911a9c09936dd4abc36e --- assets/{index-3d0d974d.js => index-f71b24ed.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-3d0d974d.js => index-f71b24ed.js} (96%) diff --git a/assets/index-3d0d974d.js b/assets/index-f71b24ed.js similarity index 96% rename from assets/index-3d0d974d.js rename to assets/index-f71b24ed.js index ee75855..bad3886 100644 --- a/assets/index-3d0d974d.js +++ b/assets/index-f71b24ed.js @@ -2901,4 +2901,4 @@ https://github.com/highlightjs/highlight.js/issues/2277`),le=Q,ue=j),K===void 0& `+c.line+" | "+_+` `+m+" | "+t("",l.column-1," ")+t("",I,"^")}else a+=` at `+u}return a},e.buildMessage=function(i,a){var s={literal:function(_){return'"'+l(_.text)+'"'},class:function(_){var v=_.parts.map(function(I){return Array.isArray(I)?c(I[0])+"-"+c(I[1]):c(I)});return"["+(_.inverted?"^":"")+v.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(_){return _.description}};function o(_){return _.charCodeAt(0).toString(16).toUpperCase()}function l(_){return _.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(v){return"\\x0"+o(v)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(v){return"\\x"+o(v)})}function c(_){return _.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(v){return"\\x0"+o(v)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(v){return"\\x"+o(v)})}function u(_){return s[_.type](_)}function p(_){var v=_.map(u),I,R;if(v.sort(),v.length>0){for(I=1,R=1;I",R="@",x=":",$="/",Z="(",h=")",b="[:",S="]",N="[",k="{",L="}",M="+",G="*",te="%",re="^",ne="&",ee=">>",B="<<",Q="_",j="?",K="!",ue="r",le="#",be="b",De="iii",xe="ii",Ee="iv",Ne="i",ce="vii",Le="vi",Xe="v",Be=/^[0-9]/,tt=/^[ \n\r\t]/,rt=/^[a-z]/,ht=/^[a-z_]/,vt=/^[a-z_0-9]/,mt=/^[mklpdcwyhnqaefsxtgujzo]/,At=/^[a-zA-Z0-9]/,Nt=/^[a-zA-Z0-9\-*+]/,Rn=/^[A-G]/,qe=/^[bs]/,rn=st("-",!1),Ze=Kn([["0","9"]],!1,!1),ke=st(".",!1),en=Hs("whitespace"),Zt=Kn([" ",` -`,"\r"," "],!1,!1),an=st(",",!1),H=st("|",!1),fe=Kn([["a","z"]],!1,!1),Ie=Kn([["a","z"],"_"],!1,!1),we=Kn([["a","z"],"_",["0","9"]],!1,!1),Je=st("<",!1),ye=st(">",!1),Ht=st("@",!1),lt=st(":",!1),yt=Kn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),zn=st("/",!1),dt=st("(",!1),Kt=st(")",!1),Tt=st("[:",!1),Ue=st("]",!1),Fn=st("[",!1),Fr=st("{",!1),ct=st("}",!1),Hn=st("+",!1),Nn=st("*",!1),Ii=st("%",!1),wn=st("^",!1),Wt=st("&",!1),Cr=st(">>",!1),ta=st("<<",!1),oi=st("_",!1),na=st("?",!1),cr=st("!",!1),li=st("r",!1),yr=Kn([["a","z"],["A","Z"],["0","9"]],!1,!1),jt=st("#",!1),ci=st("b",!1),ui=Kn([["a","z"],["A","Z"],["0","9"],"-","*","+"],!1,!1),q=Kn([["A","G"]],!1,!1),ie=Kn(["b","s"],!1,!1),de=st("iii",!1),_e=st("ii",!1),Ae=st("iv",!1),Qe=st("i",!1),Pe=st("vii",!1),Ct=st("vi",!1),Dn=st("v",!1),Wn=function(T){return T.filter(w=>w)},xa=function(){return parseFloat($n())},ra=function(){return parseInt($n())},xs=function(){return parseInt($n())},Xn=function(){},ks=function(T){return Ut(pG,{sound:T})},ka=function(){return $n()},La=function(T){return Ut(Io,{items:T})},Ls=function(T){return T},Ma=function(T,w){return Ut(fG,{item:T,sound:w})},Ms=function(T,w){return Ut(hG,{item:T,soundIndex:w})},Pa=function(T){return T},Yn=function(){return tG[$n()]},Ps=function(T,w){return T/w},Bs=function(T){return T.filter(w=>w)},Ba=function(T){return Ut(Io,{items:T})},Ua=function(T,w){return w?Ut(mT,{item:T,times:w}):Ut(gT,{items:T})},Us=function(T){return T},Fa=function(T,w,P){return Ut(OG,{left:T,operation:w,right:P})},Fs=function(T,w){return Ut(SG,{items:T,times:w})},Ya=function(T){return Ut(sR,{items:T})},Ys=function(T){return T.map(w=>typeof w=="number"?w:void 0)},$s=function(){return Math.ceil(iR($n()))},ur=function(T){var w=T.filter(P=>P).map(P=>Ut(ni,{pitch:P[0]},P.toString()));return Ut(gT,{items:w})},Ot=function(T){return T},Gs=function(T){return T},Ri=function(){},Qs=function(T){return Ut(Io,{items:T})},di=function(T){return Ut(gG,{octave:T})},qs=function(){return $n().split("").reduce((T,w)=>T+(w==="^"?1:-1),0)},Ni=function(){return Ut(Gc,{seededRandom:a.seededRandom})},$a=function(T,w){return Ut(Gc,{min:T,max:w,seededRandom:a.seededRandom})},Ga=function(T,w){return Ut(mT,{item:T,times:w})},Vs=function(T){return Ut(_G,{duration:T})},wi=function(T){return T},Qa=function(T){return Ut(Jm,{duration:T})},Di=function(T,w,P,X){const oe=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(ni,{duration:w,pitch:X,pitchOctave:oe,add:P})},xi=function(T){return T.reduce((w,P)=>w+(P==="#"?1:-1),0)},qa=function(T,w,P){return Ut(Na,{pitches:[T].concat(w),inversion:P})},ia=function(){return $n()},pi=function(T){return T},_n=function(){return $n()},Va=function(T,w,P,X,oe){const ve=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",ft=a.nodeOptions.key?a.nodeOptions.key:"C",fr=RG(X,P,ve,T,w),Ks=w||a.nodeOptions.duration,DR=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(Na,{duration:Ks,chordOctave:DR,pitches:fr,chordName:X,inversion:oe,scaleName:ve,key:ft})},Zn=function(T,w,P){const X=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",oe=a.nodeOptions.key?a.nodeOptions.key:"C";return Ut(mG,{roman:T,chordName:w,inversion:P,scaleName:X,key:oe})},aa=function(T){const w=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",P=a.nodeOptions.key?a.nodeOptions.key:"C",X=BG(T,P,w);return Ut(ni,{pitch:X.pc,add:X.add,scaleName:w,key:P})},A=0,He=0,za=[{line:1,column:1}],dr=0,zs=[],Oe=0,ge={},sa;if("startRule"in a){if(!(a.startRule in l))throw new Error(`Can't start parsing from rule "`+a.startRule+'".');c=l[a.startRule]}function $n(){return i.substring(He,A)}function dl(){return d(He,A)}function st(T,w){return{type:"literal",text:T,ignoreCase:w}}function Kn(T,w,P){return{type:"class",parts:T,inverted:w,ignoreCase:P}}function pl(){return{type:"end"}}function Hs(T){return{type:"other",description:T}}function fl(T){var w=za[T],P;if(w)return w;for(P=T-1;!za[P];)P--;for(w=za[P],w={line:w.line,column:w.column};Pdr&&(dr=A,zs=[]),zs.push(T))}function g(T,w,P){return new e(e.buildMessage(T,w),T,w,P)}function O(){var T,w,P=A*56+0,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Xt(),w!==s&&(He=T,w=Wn(w)),T=w,ge[P]={nextPos:A,result:T},T)}function C(){var T,w,P,X,oe,ve,ft,fr=A*56+1,Ks=ge[fr];if(Ks)return A=Ks.nextPos,Ks.result;for(T=A,w=A,i.charCodeAt(A)===45?(P=u,A++):(P=s,Oe===0&&f(rn)),P===s&&(P=null),X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));if(i.charCodeAt(A)===46?(oe=p,A++):(oe=s,Oe===0&&f(ke)),oe!==s){if(ve=[],Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze)),ft!==s)for(;ft!==s;)ve.push(ft),Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze));else ve=s;ve!==s?(P=[P,X,oe,ve],w=P):(A=w,w=s)}else A=w,w=s;if(w===s)if(w=A,i.charCodeAt(A)===46?(P=p,A++):(P=s,Oe===0&&f(ke)),P!==s){if(X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze)),oe!==s)for(;oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));else X=s;X!==s?(P=[P,X],w=P):(A=w,w=s)}else A=w,w=s;return w!==s&&(He=T,w=xa()),T=w,ge[fr]={nextPos:A,result:T},T}function y(){var T,w,P=A*56+2,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),Be.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Ze)),w!==s?(He=T,T=ra()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function D(){var T,w,P,X=A*56+3,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),w=[],Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze)),P!==s)for(;P!==s;)w.push(P),Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze));else w=s;return w!==s?(He=T,T=xs()):(A=T,T=s),ge[X]={nextPos:A,result:T},T}function F(){var T,w,P=A*56+4,X=ge[P];return X?(A=X.nextPos,X.result):(Oe++,T=A,tt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Zt)),w!==s&&(He=T,w=Xn()),T=w,Oe--,T===s&&(w=s,Oe===0&&f(en)),ge[P]={nextPos:A,result:T},T)}function U(){var T,w,P=A*56+8,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=W(),w!==s&&(He=T,w=ks(w)),T=w,ge[P]={nextPos:A,result:T},T)}function W(){var T,w,P,X,oe,ve=A*56+10,ft=ge[ve];if(ft)return A=ft.nextPos,ft.result;if(T=A,rt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(fe)),w!==s){if(P=[],ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie)),X!==s)for(;X!==s;)P.push(X),ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie));else P=s;if(P!==s){for(X=[],vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));oe!==s;)X.push(oe),vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));He=T,T=ka()}else A=T,T=s}else A=T,T=s;return ge[ve]={nextPos:A,result:T},T}function z(){var T,w=A*56+11,P=ge[w];return P?(A=P.nextPos,P.result):(T=pe(),T===s&&(T=he()),ge[w]={nextPos:A,result:T},T)}function pe(){var T,w,P,X,oe=A*56+12,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=z(),X!==s)for(;X!==s;)P.push(X),X=z();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=La(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function he(){var T,w=A*56+13,P=ge[w];return P?(A=P.nextPos,P.result):(T=W(),T===s&&(T=pe(),T===s&&(T=F())),ge[w]={nextPos:A,result:T},T)}function se(){var T,w,P,X=A*56+14,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===64?(w=R,A++):(w=s,Oe===0&&f(Ht)),w!==s?(P=z(),P!==s?(He=T,T=Ls(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function ae(){var T,w=A*56+15,P=ge[w];return P?(A=P.nextPos,P.result):(T=sn(),T===s&&(T=it(),T===s&&(T=qt(),T===s&&(T=du(),T===s&&(T=Qt())))),ge[w]={nextPos:A,result:T},T)}function Ce(){var T,w,P,X=A*56+16,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=ae(),w===s&&(w=Zs()),w!==s?(P=se(),P!==s?(He=T,T=Ma(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Se(){var T,w,P,X=A*56+17,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs())),w!==s?(P=Ve(),P!==s?(He=T,T=Ms(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Ve(){var T,w,P,X=A*56+18,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=wt(),P!==s?(He=T,T=Pa(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function je(){var T,w,P=A*56+19,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,mt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(yt)),w!==s&&(He=T,w=Yn()),T=w,ge[P]={nextPos:A,result:T},T)}function Fe(){var T,w=A*56+20,P=ge[w];return P?(A=P.nextPos,P.result):(T=It(),T===s&&(T=C(),T===s&&(T=je())),ge[w]={nextPos:A,result:T},T)}function It(){var T,w,P,X,oe=A*56+21,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=D(),w!==s?(i.charCodeAt(A)===47?(P=$,A++):(P=s,Oe===0&&f(zn)),P!==s?(X=D(),X!==s?(He=T,T=Ps(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xt(){var T,w,P,X=A*56+22,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du())))))))),P!==s)for(;P!==s;)w.push(P),P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du()))))))));else w=s;return w!==s&&(He=T,w=Bs(w)),T=w,ge[X]={nextPos:A,result:T},T}function wt(){var T,w=A*56+23,P=ge[w];return P?(A=P.nextPos,P.result):(T=F(),T===s&&(T=D(),T===s&&(T=R_(),T===s&&(T=fu(),T===s&&(T=tn(),T===s&&(T=A_()))))),ge[w]={nextPos:A,result:T},T)}function tn(){var T,w,P,X,oe=A*56+24,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=wt(),X!==s)for(;X!==s;)P.push(X),X=wt();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Ba(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function it(){var T,w,P,X,oe,ve=A*56+25,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(i.charCodeAt(A)===58?A++:Oe===0&&f(lt),P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===41?(oe=h,A++):(oe=s,Oe===0&&f(Kt)),oe!==s?(He=T,T=Ua(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function pt(){var T,w,P,X=A*56+26,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=D(),P!==s?(He=T,T=Us(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function sn(){var T,w,P,X,oe=A*56+27,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=it(),w!==s?(P=I_(),P!==s?(X=it(),X!==s?(He=T,T=Fa(w,P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Qt(){var T,w,P,X,oe,ve=A*56+28,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.substr(A,2)===b?(w=b,A+=2):(w=s,Oe===0&&f(Tt)),w!==s?(P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===93?(oe=S,A++):(oe=s,Oe===0&&f(Ue)),oe!==s?(He=T,T=Fs(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function qt(){var T,w,P,X,oe=A*56+29,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===91?(w=N,A++):(w=s,Oe===0&&f(Fn)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===93?(X=S,A++):(X=s,Oe===0&&f(Ue)),X!==s?(He=T,T=Ya(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function pr(){var T,w=A*56+30,P=ge[w];return P?(A=P.nextPos,P.result):(T=D(),T===s&&(T=y()),ge[w]={nextPos:A,result:T},T)}function Ws(){var T,w,P,X=A*56+31,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=hl(),P===s&&(P=pr()),P!==s)for(;P!==s;)w.push(P),P=hl(),P===s&&(P=pr());else w=s;return w!==s&&(He=T,w=Ys(w)),T=w,ge[X]={nextPos:A,result:T},T}function hl(){var T,w,P,X,oe=A*56+32,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===40?A++:Oe===0&&f(dt),w=pr(),w!==s?(P=I_(),P!==s?(X=Ws(),X!==s?(i.charCodeAt(A)===41?A++:Oe===0&&f(Kt),He=T,T=$s()):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xs(){var T,w,P,X,oe=A*56+33,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s){if(P=[],X=Ws(),X===s&&(X=F()),X!==s)for(;X!==s;)P.push(X),X=Ws(),X===s&&(X=F());else P=s;P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=ur(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function A_(){var T,w,P,X,oe=A*56+34,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s?(P=D(),P===s&&(P=fu()),P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=Ot(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function I_(){var T,w=A*56+35,P=ge[w];return P?(A=P.nextPos,P.result):(i.charCodeAt(A)===43?(T=M,A++):(T=s,Oe===0&&f(Hn)),T===s&&(i.charCodeAt(A)===45?(T=u,A++):(T=s,Oe===0&&f(rn)),T===s&&(i.charCodeAt(A)===42?(T=G,A++):(T=s,Oe===0&&f(Nn)),T===s&&(i.charCodeAt(A)===47?(T=$,A++):(T=s,Oe===0&&f(zn)),T===s&&(i.charCodeAt(A)===37?(T=te,A++):(T=s,Oe===0&&f(Ii)),T===s&&(i.charCodeAt(A)===94?(T=re,A++):(T=s,Oe===0&&f(wn)),T===s&&(i.charCodeAt(A)===124?(T=_,A++):(T=s,Oe===0&&f(H)),T===s&&(i.charCodeAt(A)===38?(T=ne,A++):(T=s,Oe===0&&f(Wt)),T===s&&(i.substr(A,2)===ee?(T=ee,A+=2):(T=s,Oe===0&&f(Cr)),T===s&&(i.substr(A,2)===B?(T=B,A+=2):(T=s,Oe===0&&f(ta))))))))))),ge[w]={nextPos:A,result:T},T)}function Zs(){var T,w,P=A*56+36,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=yR(),w===s&&(w=NR(),w===s&&(w=RR(),w===s&&(w=wR(),w===s&&(w=U(),w===s&&(w=IR(),w===s&&(w=ml(),w===s&&(w=vR(),w===s&&(w=F(),w===s&&(w=TR(),w===s&&(w=it(),w===s&&(w=Xs(),w===s&&(w=ER())))))))))))),w!==s&&(He=T,w=Gs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function ER(){var T,w,P=A*56+37,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===124?(w=_,A++):(w=s,Oe===0&&f(H)),w!==s&&(He=T,w=Ri()),T=w,ge[P]={nextPos:A,result:T},T)}function du(){var T,w,P,X,oe=A*56+38,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Qs(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function vR(){var T,w,P=A*56+39,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=pu(),w!==s&&(He=T,w=di(w)),T=w,ge[P]={nextPos:A,result:T},T)}function pu(){var T,w,P,X=A*56+40,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi)));else w=s;return w!==s&&(He=T,w=qs()),T=w,ge[X]={nextPos:A,result:T},T}function R_(){var T,w,P=A*56+41,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===63?(w=j,A++):(w=s,Oe===0&&f(na)),w!==s&&(He=T,w=Ni()),T=w,ge[P]={nextPos:A,result:T},T)}function fu(){var T,w,P,X,oe,ve,ft=A*56+42,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(P=D(),P!==s?(i.charCodeAt(A)===44?(X=m,A++):(X=s,Oe===0&&f(an)),X!==s?(oe=D(),oe!==s?(i.charCodeAt(A)===41?(ve=h,A++):(ve=s,Oe===0&&f(Kt)),ve!==s?(He=T,T=$a(P,oe)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function N_(){var T,w,P,X,oe=A*56+43,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=Se(),w===s&&(w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs()))),w!==s?(i.charCodeAt(A)===33?(P=K,A++):(P=s,Oe===0&&f(cr)),P!==s?(X=D(),X!==s?(He=T,T=Ga(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function TR(){var T,w,P=A*56+44,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Fe(),w!==s&&(He=T,w=Vs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function CR(){var T,w,P,X=A*56+45,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Fe(),w!==s?(i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P!==s?(He=T,T=wi(w)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function yR(){var T,w,P,X,oe,ve=A*56+46,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=CR(),w===s&&(w=null),i.charCodeAt(A)===114?(P=ue,A++):(P=s,Oe===0&&f(li)),P!==s?(X=A,Oe++,At.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(yr)),Oe--,oe===s?X=void 0:(A=X,X=s),X!==s?(He=T,T=Qa(w)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function ml(){var T,w,P,X,oe,ve=A*56+47,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=AR(),X===s&&(X=null),oe=y(),oe===s&&(oe=R_(),oe===s&&(oe=fu(),oe===s&&(oe=A_()))),oe!==s?(He=T,T=Di(w,P,X,oe)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function AR(){var T,w,P,X=A*56+48,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci)));else w=s;return w!==s&&(He=T,w=xi(w)),T=w,ge[X]={nextPos:A,result:T},T}function IR(){var T,w,P,X,oe=A*56+49,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,w=ml(),w!==s){if(P=[],X=ml(),X!==s)for(;X!==s;)P.push(X),X=ml();else P=s;P!==s?(X=hu(),X===s&&(X=null),He=T,T=qa(w,P,X)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function w_(){var T,w,P,X=A*56+50,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui)),P!==s)for(;P!==s;)w.push(P),Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui));else w=s;return w!==s&&(He=T,w=ia()),T=w,ge[X]={nextPos:A,result:T},T}function hu(){var T,w,P,X=A*56+51,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===37?(w=te,A++):(w=s,Oe===0&&f(Ii)),w!==s?(P=D(),P!==s?(He=T,T=pi(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function D_(){var T,w,P=A*56+52,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,Rn.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(q)),w!==s?(qe.test(i.charAt(A))?(i.charAt(A),A++):Oe===0&&f(ie),He=T,T=_n()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function RR(){var T,w,P,X,oe,ve,ft=A*56+53,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=D_(),X!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),oe=w_(),oe!==s?(ve=hu(),ve===s&&(ve=null),He=T,T=Va(w,P,X,oe,ve)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function NR(){var T,w,P,X,oe=A*56+54,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.substr(A,3)===De?(w=De,A+=3):(w=s,Oe===0&&f(de)),w===s&&(i.substr(A,2)===xe?(w=xe,A+=2):(w=s,Oe===0&&f(_e)),w===s&&(i.substr(A,2)===Ee?(w=Ee,A+=2):(w=s,Oe===0&&f(Ae)),w===s&&(i.charCodeAt(A)===105?(w=Ne,A++):(w=s,Oe===0&&f(Qe)),w===s&&(i.substr(A,3)===ce?(w=ce,A+=3):(w=s,Oe===0&&f(Pe)),w===s&&(i.substr(A,2)===Le?(w=Le,A+=2):(w=s,Oe===0&&f(Ct)),w===s&&(i.charCodeAt(A)===118?(w=Xe,A++):(w=s,Oe===0&&f(Dn)))))))),w!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),P=w_(),P===s&&(P=null),X=hu(),X===s&&(X=null),He=T,T=Zn(w,P,X)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function wR(){var T,w,P=A*56+55,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=D_(),w!==s&&(He=T,w=aa(w)),T=w,ge[P]={nextPos:A,result:T},T)}var x_=a.nodeOptions||{};function Ut(T,w,P=void 0){w.text=P||$n(),w.location=dl();for(var X in x_)(w[X]===void 0||w[X]===null)&&(w[X]=x_[X]);return new T(w)}if(sa=c(),sa!==s&&A===i.length)return sa;throw sa!==s&&Ae.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}sounds(){return this.evaluated.map(e=>e.collect("sound"))}indices(){return this.evaluated.map(e=>e.collect("soundIndex"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}octaves(){return this.evaluated.map(e=>e.collect("octave"))}retrograde(){return this.evaluated=this.evaluated.reverse(),this}scale(e){return this.applyOptions({scale:e}),this}key(e){return this.applyOptions({key:e}),this}octave(e){return this.applyOptions({octave:e}),this}invert(e){return this.applyOptions({inversion:e}),this}isInOptions(e,t){return this.options.nodeOptions&&this.options.nodeOptions[e]===t}atLast(){return this.index+1>=this.evaluated.length*this.redo}clone(){return ti(this)}notStarted(){return this.index<0}peek(){return this.evaluated[this.index-1||0]}hasStarted(){return this.index>=0}next(){this.index<0&&(this.index=0);const e=this.evaluated[this.index%this.evaluated.length];return this.index++,this.counter++,this.redo>0&&this.index>=this.evaluated.length*this.redo&&(this.index=0,this.evaluated=this.evaluate(this.values)),e}applyOptions(e={}){this.evaluated=this.evaluate(this.evaluated,e),this.applyTransformations()}applyTransformations(){var e;(e=this.globalOptions)!=null&&e.retrograde&&(this.evaluated=this.evaluated.reverse())}update(){return this.evaluated=this.evaluate(this.values),this.applyTransformations(),this}evaluate(e,t={}){let n=e.map(i=>i.evaluate(t)).flat(1/0).filter(i=>i!==void 0);return t.subdivisions&&(n=fR(n)),n}totalDuration(){return this.evaluated.reduce((t,n)=>t+n.collect("duration"),0)}lead(){let e=this.evaluated.findIndex(t=>t instanceof Na);if(e>=0){for(let t=e+1;t<=this.evaluated.length;t++)if(this.evaluated[t]instanceof Na){const n=this.evaluated[e],i=this.evaluated[t],a=FG(n.notes(),i.notes()),s=ti(i);s.voiceLeadFromNotes(a,this.options.nodeOptions),this.evaluated[t]=s,e=t}}return this}}const fR=(r,e=void 0)=>r.map(n=>{if(n instanceof sR){const i=n.evaluated.length,a=(e||n.duration)/i;return fR(n.evaluated,a)}else return n.duration=e||n.duration,n}).flat(1/0),GG=r=>{let e={};return dG.forEach(t=>{if(r[t]!==void 0){const n=r[t];e[t]=n,delete r[t]}}),e};class QG{constructor(e,t){E(this,"api");E(this,"settings");E(this,"midiAccess",null);E(this,"midiOutputs",[]);E(this,"currentOutputIndex",0);E(this,"scheduledNotes",{});E(this,"midiInputs",[]);E(this,"currentInputIndex");E(this,"bufferLength",512);E(this,"noteInputBuffer",[]);E(this,"ccInputBuffer",[]);E(this,"activeNotes",[]);E(this,"stickyNotes",[]);E(this,"lastNote");E(this,"lastCC",{});E(this,"lastNoteInChannel",{});E(this,"lastCCInChannel",{});E(this,"midiClockInputIndex");E(this,"midiClockInput");E(this,"lastTimestamp",0);E(this,"midiClockDelta",0);E(this,"lastBPM");E(this,"roundedBPM",0);E(this,"clockBuffer",[]);E(this,"clockBufferLength",24);E(this,"clockTicks",0);E(this,"clockErrorCount",0);E(this,"skipOnError",0);this.api=e,this.settings=t,this.lastBPM=e.bpm(),this.roundedBPM=this.lastBPM,this.initializeMidiAccess()}async initializeMidiAccess(){try{this.midiAccess=await navigator.requestMIDIAccess(),this.midiOutputs=Array.from(this.midiAccess.outputs.values()),this.midiOutputs.length===0&&(console.warn("No MIDI outputs available."),this.currentOutputIndex=-1),this.midiInputs=Array.from(this.midiAccess.inputs.values()),this.midiInputs.length===0?console.warn("No MIDI inputs available."):this.updateInputSelects()}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex0){const e=document.getElementById("midi-clock-input"),t=document.getElementById("default-midi-input");e.innerHTML="",t.innerHTML="";const n=document.createElement("option");n.value="-1",n.text="Internal",e.appendChild(n);const i=document.createElement("option");if(i.value="-1",i.text="None",t.appendChild(i),this.midiInputs.forEach((a,s)=>{const o=document.createElement("option");o.value=s.toString(),o.text=a.name||s.toString(),e.appendChild(o),t.appendChild(o.cloneNode(!0))}),this.settings.midi_clock_input){const a=this.getMidiInputIndex(this.settings.midi_clock_input);e.value=a.toString(),a>0&&(this.midiClockInput=this.midiInputs[a],this.registerMidiInputListener(a))}else e.value="-1";if(this.settings.default_midi_input){const a=this.getMidiInputIndex(this.settings.default_midi_input);t.value=a.toString(),a>0&&(this.currentInputIndex=a,this.registerMidiInputListener(a))}else t.value="-1";e.addEventListener("change",a=>{const s=a.target.value;if(s==="-1")this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=void 0,this.settings.midi_clock_input=void 0;else{const o=parseInt(s);this.midiClockInputIndex=o,this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=this.midiInputs[o],this.registerMidiInputListener(o),this.settings.midi_clock_input=this.midiClockInput.name||void 0}}),t.addEventListener("change",a=>{const s=a.target.value;s==="-1"?(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=void 0,this.settings.default_midi_input=void 0):(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=parseInt(s),this.registerMidiInputListener(this.currentInputIndex),this.settings.default_midi_input=this.midiInputs[this.currentInputIndex].name||void 0)})}}registerMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&!t.onmidimessage&&(t.onmidimessage=n=>{const i=n;if(t.name===this.settings.midi_clock_input&&(i.data[0]===248?this.skipOnError>0?this.skipOnError-=1:this.onMidiClock(n.timeStamp):i.data[0]===250?(console.log("MIDI start received"),this.api.stop(),this.api.play()):i.data[0]===252?(console.log("MIDI stop received"),this.api.pause()):i.data[0]===251?(console.log("MIDI continue received"),this.api.play()):i.data[0]===254&&console.log("MIDI active sensing received")),t.name===this.settings.default_midi_input){if(i.data[0]>=144&&i.data[0]<=159){const a=i.data[0]-144+1,s=i.data[1],o=i.data[2];this.lastNote={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.lastNoteInChannel[a]={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.settings.midi_channels_scripts&&this.api.script(a),this.pushToMidiInputBuffer({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.activeNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.removeFromStickyNotes(s,a)||this.stickyNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp})}if(i.data[0]>=128&&i.data[0]<=143){const a=i.data[0]-128+1,s=i.data[1];this.removeFromActiveNotes(s,a)}if(i.data[0]>=176&&i.data[0]<=191){const a=i.data[0]-176+1,s=i.data[1],o=i.data[2];this.lastCC[s]=o,this.lastCCInChannel[a]?this.lastCCInChannel[a][s]=o:(this.lastCCInChannel[a]={},this.lastCCInChannel[a][s]=o),this.pushToMidiCCBuffer({control:s,value:o,channel:a,timestamp:n.timeStamp})}}})}}removeFromActiveNotes(e,t){const n=this.activeNotes.findIndex(i=>i.note===e&&i.channel===t);n>=0&&this.activeNotes.splice(n,1)}removeFromStickyNotes(e,t){const n=this.stickyNotes.findIndex(i=>i.note===e&&i.channel===t);return n>=0?(this.stickyNotes.splice(n,1),!0):!1}stickyNotesFromChannel(e){return this.stickyNotes.filter(t=>t.channel===e)}activeNotesFromChannel(e){return this.activeNotes.filter(t=>t.channel===e)}killActiveNotes(){this.activeNotes=[]}killActiveNotesFromChannel(e){this.activeNotes=this.activeNotes.filter(t=>t.channel!==e)}pushToMidiInputBuffer(e){this.noteInputBuffer.push(e),this.noteInputBuffer.length>this.bufferLength&&this.noteInputBuffer.shift()}pushToMidiCCBuffer(e){this.ccInputBuffer.push(e),this.ccInputBuffer.length>this.bufferLength&&this.ccInputBuffer.shift()}findNoteFromBufferInChannel(e){const t=this.noteInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.noteInputBuffer[t];return this.noteInputBuffer.splice(t,1),n}else return}findCCFromBufferInChannel(e){const t=this.ccInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.ccInputBuffer[t];return this.ccInputBuffer.splice(t,1),n}else return}unregisterMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&(t.onmidimessage=null)}}onMidiClock(e){if(this.clockTicks+=1,this.lastTimestamp>0)if(this.lastTimestamp===e)this.clockErrorCount+=1;else if(this.clockErrorCount>0)console.log("Timestamp error count: ",this.clockErrorCount),console.log("Current timestamp: ",e),console.log("Last timestamp: ",this.lastTimestamp),console.log("Last delta: ",this.midiClockDelta),console.log("Current delta: ",e-this.lastTimestamp),console.log("BPMs",this.clockBuffer),this.clockErrorCount=0,this.skipOnError=this.settings.midi_clock_ppqn/4,e=0;else{this.midiClockDelta=e-this.lastTimestamp,this.lastBPM=60*(1e3/this.midiClockDelta/this.settings.midi_clock_ppqn),this.clockBuffer.push(this.lastBPM),this.clockBuffer.length>this.clockBufferLength&&this.clockBuffer.shift();const t=this.estimatedBPM();t!==this.roundedBPM&&(console.log("Estimated BPM: ",t),this.api.bpm(t),this.roundedBPM=t)}this.lastTimestamp=e}estimatedBPM(){const e=this.clockBuffer.reduce((t,n)=>t+n);return Math.round(e/this.clockBuffer.length)}sendMidiClock(){if(!this.midiClockInput){const e=this.midiOutputs[this.currentOutputIndex];e&&e.send([248])}}switchMidiOutput(e){const t=this.getMidiOutputIndex(e);return t!==-1?(this.currentOutputIndex=t,!0):!1}getMidiOutputIndex(e){if(typeof e=="number")return e<0||e>=this.midiOutputs.length?(console.error(`Invalid MIDI output index. Index must be in the range 0-${this.midiOutputs.length-1}.`),this.currentOutputIndex):e;{const t=this.midiOutputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}getMidiInputIndex(e){if(typeof e=="number")return e<0||e>=this.midiInputs.length?(console.error(`Invalid MIDI input index. Index must be in the range 0-${this.midiInputs.length-1}.`),-1):e;{const t=this.midiInputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI input "${e}" not found.`),-1)}}listMidiOutputs(){let e="Available MIDI Outputs: ";return this.midiOutputs.forEach((t,n)=>{e+=`(${n+1}) ${t.name} `}),e}sendMidiNote(e,t,n,i,a=this.currentOutputIndex,s=void 0){typeof a=="string"&&(a=this.getMidiOutputIndex(a));const o=this.midiOutputs[a];if(e=Math.min(Math.max(e,0),127),o){const l=[144+t,e,n],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const u=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=u}else console.error("MIDI output not available.")}sendMidiOn(e,t,n,i=this.currentOutputIndex){typeof i=="string"&&(i=this.getMidiOutputIndex(i));const a=this.midiOutputs[i];if(e=Math.min(Math.max(e,0),127),a){const s=[144+t,e,n];a.send(s)}else console.error("MIDI output not available.")}sendMidiOff(e,t,n=this.currentOutputIndex){typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(e=Math.min(Math.max(e,0),127),i){const a=[128+t,e,0];i.send(a)}else console.error("MIDI output not available.")}sendAllNotesOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,123,0];n.send(i)}else console.error("MIDI output not available.")}sendAllSoundOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,120,0];n.send(i)}else console.error("MIDI output not available.")}sendSysExMessage(e){const t=this.midiOutputs[this.currentOutputIndex];t?t.send(e):console.error("MIDI output not available.")}sendPitchBend(e,t,n=this.currentOutputIndex){(e<0||e>16383)&&console.error("Invalid pitch bend value. Value must be in the range 0-16383."),(t<0||t>15)&&console.error("Invalid MIDI channel. Channel must be in the range 0-15."),typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(i){const a=e&127,s=e>>7&127;i.send([224|t,a,s])}else console.error("MIDI output not available.")}sendProgramChange(e,t){const n=this.midiOutputs[this.currentOutputIndex];n?n.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,n){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+n,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const n=this.scheduledNotes[t];clearTimeout(n),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class qG{constructor(e,t,n){E(this,"min");E(this,"max");E(this,"wrap");E(this,"position");this.min=e,this.max=t,this.wrap=n,this.position=0}step(){const e=Math.floor(Math.random()*3)-1;this.position+=e,this.wrap?this.position>this.max?this.position=this.min:this.positionthis.max&&(this.position=this.max)}getPosition(){return this.position}toggleWrap(e){this.wrap=e}}class C_{constructor(e){E(this,"seedValue");E(this,"randomGen",Math.random);E(this,"app");E(this,"values",{});E(this,"evenbar",e=>this.app.clock.time_position.bar%2===0?this.modify(e):this);E(this,"even",e=>this.app.clock.time_position.beat%2===0?this.modify(e):this);E(this,"odd",e=>this.app.clock.time_position.beat%2!==0?this.modify(e):this);E(this,"odds",(e,t)=>this.randomGen()this);E(this,"almostNever",e=>this.odds(.025,e));E(this,"rarely",e=>this.odds(.1,e));E(this,"scarcely",e=>this.odds(.25,e));E(this,"sometimes",e=>this.odds(.5,e));E(this,"often",e=>this.odds(.75,e));E(this,"frequently",e=>this.odds(.9,e));E(this,"almostAlways",e=>this.odds(.985,e));E(this,"always",e=>this.modify(e));E(this,"modify",e=>e(this));E(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));E(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));E(this,"apply",e=>this.modify(e));E(this,"length",e=>(this.values.length=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class hR extends C_{constructor(t){super(t);E(this,"octave",t=>(this.values.octave=t,this.update(),this));E(this,"key",t=>(this.values.key=t,this.update(),this));E(this,"scale",t=>(b_(t)?(this.values.scaleName=t,this.values.parsedScale=vi(t)):this.values.parsedScale=E_(t),this.update(),this));E(this,"freq",t=>{this.values.freq=t;const n=bG(t);return n%1!==0?(this.values.note=Math.floor(n),this.values.bend=oR(n)[1]):this.values.note=n,this});E(this,"update",()=>{})}}class tg extends hR{constructor(t,n){super(n);E(this,"nudge");E(this,"volume",t=>this.updateValue("volume",t));E(this,"vol",this.volume);E(this,"zrand",t=>this.updateValue("zrand",t));E(this,"curve",t=>this.updateValue("curve",t));E(this,"slide",t=>this.updateValue("slide",t));E(this,"sld",this.slide);E(this,"deltaSlide",t=>this.updateValue("deltaSlide",t));E(this,"dslide",this.deltaSlide);E(this,"pitchJump",t=>this.updateValue("pitchJump",t));E(this,"pj",this.pitchJump);E(this,"pitchJumpTime",t=>this.updateValue("pitchJumpTime",t));E(this,"pjt",this.pitchJumpTime);E(this,"lfo",t=>this.updateValue("lfo",t));E(this,"znoise",t=>this.updateValue("znoise",t));E(this,"noise",t=>this.updateValue("noise",t));E(this,"zmod",t=>this.updateValue("zmod",t));E(this,"zcrush",t=>this.updateValue("zcrush",t));E(this,"zdelay",t=>this.updateValue("zdelay",t));E(this,"sustainVolume",t=>this.updateValue("sustainVolume",t));E(this,"tremolo",t=>this.updateValue("tremolo",t));E(this,"dur",t=>this.updateValue("dur",t));E(this,"zzfx",t=>this.updateValue("zzfx",t));E(this,"fmi",t=>this.updateValue("fmi",t));E(this,"fmh",t=>this.updateValue("fmh",t));E(this,"fmenv",t=>this.updateValue("fmenv",t));E(this,"fmattack",t=>this.updateValue("fmattack",t));E(this,"fmatk",this.fmattack);E(this,"fmdecay",t=>this.updateValue("fmdecay",t));E(this,"fmdec",this.fmdecay);E(this,"fmsustain",t=>this.updateValue("fmsustain",t));E(this,"fmsus",this.fmsustain);E(this,"fmrelease",t=>this.updateValue("fmrelease",t));E(this,"fmrel",this.fmrelease);E(this,"fmvelocity",t=>this.updateValue("fmvelocity",t));E(this,"fmvel",this.fmvelocity);E(this,"fmwave",t=>this.updateValue("fmwave",t));E(this,"fmw",this.fmwave);E(this,"ftype",t=>this.updateValue("ftype",t));E(this,"fanchor",t=>this.updateValue("fanchor",t));E(this,"attack",t=>this.updateValue("attack",t));E(this,"atk",this.attack);E(this,"decay",t=>this.updateValue("decay",t));E(this,"dec",this.decay);E(this,"sustain",t=>this.updateValue("sustain",t));E(this,"sus",this.sustain);E(this,"release",t=>this.updateValue("release",t));E(this,"rel",this.release);E(this,"adsr",(t,n,i,a)=>(this.attack(t),this.decay(n),this.sustain(i),this.release(a),this));E(this,"ad",(t,n)=>(this.attack(t),this.decay(n),this.sustain(0),this.release(0),this));E(this,"lpenv",t=>this.updateValue("lpenv",t));E(this,"lpe",t=>this.updateValue("lpenv",t));E(this,"lpattack",t=>this.updateValue("lpattack",t));E(this,"lpa",this.lpattack);E(this,"lpdecay",t=>this.updateValue("lpdecay",t));E(this,"lpd",this.lpdecay);E(this,"lpsustain",t=>this.updateValue("lpsustain",t));E(this,"lps",this.lpsustain);E(this,"lprelease",t=>this.updateValue("lprelease",t));E(this,"lpr",this.lprelease);E(this,"cutoff",t=>this.updateValue("cutoff",t));E(this,"lpf",this.cutoff);E(this,"resonance",t=>this.updateValue("resonance",Math.min(Math.max(t,0),50)));E(this,"lpq",this.resonance);E(this,"lpadsr",(t,n,i,a,s)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(a),this.lprelease(s),this));E(this,"hpenv",t=>this.updateValue("hpenv",t));E(this,"hpe",t=>this.updateValue("hpe",t));E(this,"hpattack",t=>this.updateValue("hpattack",t));E(this,"hpa",this.hpattack);E(this,"hpdecay",t=>this.updateValue("hpdecay",t));E(this,"hpd",this.hpdecay);E(this,"hpsustain",t=>this.updateValue("hpsustain",t));E(this,"hpsus",this.hpsustain);E(this,"hprelease",t=>this.updateValue("hprelease",t));E(this,"hpr",this.hprelease);E(this,"hcutoff",t=>this.updateValue("hcutoff",t));E(this,"hpf",this.hcutoff);E(this,"hresonance",t=>this.updateValue("hresonance",t));E(this,"hpq",this.hresonance);E(this,"hpadsr",(t,n,i,a,s)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(a),this.hprelease(s),this));E(this,"bpenv",t=>this.updateValue("bpenv",t));E(this,"bpe",t=>this.updateValue("bpe",t));E(this,"bpattack",t=>this.updateValue("bpattack",t));E(this,"bpa",this.bpattack);E(this,"bpdecay",t=>this.updateValue("bpdecay",t));E(this,"bpd",this.bpdecay);E(this,"bpsustain",t=>this.updateValue("bpsustain",t));E(this,"bps",this.bpsustain);E(this,"bprelease",t=>this.updateValue("bprelease",t));E(this,"bpr",this.bprelease);E(this,"bandf",t=>this.updateValue("bandf",t));E(this,"bpf",this.bandf);E(this,"bandq",t=>this.updateValue("bandq",t));E(this,"bpq",this.bandq);E(this,"bpadsr",(t,n,i,a,s)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(a),this.bprelease(s),this));E(this,"freq",t=>this.updateValue("freq",t));E(this,"f",this.freq);E(this,"vib",t=>this.updateValue("vib",t));E(this,"vibmod",t=>this.updateValue("vibmod",t));E(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let n=t.split(":");this.values.fmi=parseFloat(n[0]),n.length>1&&(this.values.fmh=parseFloat(n[1]))}return this});E(this,"loop",t=>this.updateValue("loop",t));E(this,"loopBegin",t=>this.updateValue("loopBegin",t));E(this,"loopEnd",t=>this.updateValue("loopEnd",t));E(this,"begin",t=>this.updateValue("begin",t));E(this,"end",t=>this.updateValue("end",t));E(this,"gain",t=>this.updateValue("gain",t));E(this,"dbgain",t=>this.updateValue("gain",Math.min(Math.pow(10,t/20),10)));E(this,"db",this.dbgain);E(this,"velocity",t=>this.updateValue("velocity",t));E(this,"vel",this.velocity);E(this,"pan",t=>this.updateValue("pan",t));E(this,"sound",t=>this.updateValue("s",t));E(this,"chord",(t,...n)=>(typeof t=="string"?t=xG(t).map(a=>({note:a,freq:Zr(a)})):t instanceof Array&&typeof t[0]=="number"?t=t.map(i=>({note:i,freq:Zr(i)})):typeof t=="number"&&n.length>0&&(t=[t,...n].map(i=>({note:i,freq:Zr(i)}))),this.updateValue("chord",t)));E(this,"invert",(t=0)=>{if(this.values.chord){let n=this.values.chord.map(a=>a.note);n=t<0?[...n].reverse():n;for(let a=0;a({note:a,freq:Zr(a)}));return this.updateValue("chord",i)}else return this});E(this,"snd",this.sound);E(this,"cut",t=>this.updateValue("cut",t));E(this,"clip",t=>this.updateValue("clip",t));E(this,"n",t=>this.updateValue("n",t));E(this,"note",t=>typeof t=="string"?this.updateValue("note",Ur(t)):typeof t==null||t==null?this.updateValue("note",0).updateValue("gain",0):this.updateValue("note",t));E(this,"speed",t=>this.updateValue("speed",t));E(this,"spd",this.speed);E(this,"coarse",t=>this.updateValue("coarse",t));E(this,"crush",t=>this.updateValue("crush",t));E(this,"shape",t=>this.updateValue("shape",t));E(this,"vowel",t=>this.updateValue("vowel",t));E(this,"vow",this.vowel);E(this,"delay",t=>this.updateValue("delay",t));E(this,"del",this.delay);E(this,"delayfeedback",t=>this.updateValue("delayfeedback",t));E(this,"delayfb",this.delayfeedback);E(this,"delaytime",t=>this.updateValue("delaytime",t));E(this,"delayt",this.delaytime);E(this,"orbit",t=>this.updateValue("orbit",t));E(this,"o",this.orbit);E(this,"room",t=>this.updateValue("room",t));E(this,"rm",this.room);E(this,"roomfade",t=>this.updateValue("roomfade",t));E(this,"rfade",this.roomfade);E(this,"roomlp",t=>this.updateValue("roomlp",t));E(this,"rlp",this.roomlp);E(this,"roomdim",t=>this.updateValue("roomdim",t));E(this,"rdim",this.roomdim);E(this,"size",t=>this.updateValue("roomsize",t));E(this,"sz",this.size);E(this,"comp",t=>this.updateValue("compressor",t));E(this,"cmp",this.comp);E(this,"ratio",t=>this.updateValue("compressorRatio",t));E(this,"rt",this.ratio);E(this,"knee",t=>this.updateValue("compressorKnee",t));E(this,"kn",this.knee);E(this,"compAttack",t=>this.updateValue("compressorAttack",t));E(this,"cmpa",this.compAttack);E(this,"compRelease",t=>this.updateValue("compressorRelease",t));E(this,"cmpr",this.compRelease);E(this,"stretch",t=>(this.updateValue("unit","c"),this.updateValue("speed",1/t),this.updateValue("cut",t),this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.freq=Zr(t)});E(this,"out",()=>{this.values.chord?this.values.chord.forEach(t=>{const n={...this.values};n.freq=t.freq,P_(n,this.nudge,this.values.dur)}):P_(this.values,this.nudge,this.values.dur)});this.app=n,this.nudge=n.dough_nudge/100,typeof t=="string"?t.includes(":")?this.values={s:t.split(":")[0],n:t.split(":")[1],dur:n.clock.convertPulseToSecond(n.clock.ppqn),analyze:!0}:this.values={s:t,dur:.5,analyze:!0}:this.values=t}updateValue(t,n){return this.values[t]=n,this}}class ng extends hR{constructor(t,n){super(n);E(this,"midiConnection");E(this,"chord",t=>(this.values.chord=t,this));E(this,"note",t=>(this.values.note=t,this));E(this,"sustain",t=>(this.values.sustain=t,this));E(this,"channel",t=>(this.values.channel=t,this));E(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));E(this,"add",t=>(this.values.note+=t,this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"bend",t=>(this.values.bend=t,this));E(this,"random",(t=0,n=127)=>(t=Math.min(Math.max(t,0),127),n=Math.min(Math.max(n,0),127),this.values.note=Math.floor(this.randomGen()*(n-t+1))+t,this));E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.note=t,this.values.freq=Zr(t),n&&(this.values.bend=n)});E(this,"out",()=>{function t(n,i){const a=i&&i.channel?i.channel:0,s=n.values.channel?n.values.channel:a,o=n.values.velocity?n.values.velocity:100,l=i&&i.note?i.note:60,c=n.values.note?n.values.note:l,u=n.values.sustain?n.values.sustain*n.app.clock.pulse_duration*n.app.api.ppqn():n.app.clock.pulse_duration*n.app.api.ppqn(),p=n.values.bend?n.values.bend:void 0,m=n.values.port?n.midiConnection.getMidiOutputIndex(n.values.port):n.midiConnection.getCurrentMidiPortIndex();n.midiConnection.sendMidiNote(c,s,o,u,m,p)}this.values.chord?this.values.chord.forEach(n=>{t(this,n)}):t(this)});this.app=n,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=n.api.MidiConnection}}const po=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mR=new Set,rg=typeof process=="object"&&process?process:{},gR=(r,e,t,n)=>{typeof rg.emitWarning=="function"?rg.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)};let Qc=globalThis.AbortController,_T=globalThis.AbortSignal;var OT;if(typeof Qc>"u"){_T=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",!1)}addEventListener(n,i){this._onabort.push(i)}},Qc=class{constructor(){E(this,"signal",new _T);e()}abort(n){var i,a;if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(const s of this.signal._onabort)s(n);(a=(i=this.signal).onabort)==null||a.call(i,n)}}};let r=((OT=rg.env)==null?void 0:OT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{r&&(r=!1,gR("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const VG=r=>!mR.has(r),Bi=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),_R=r=>Bi(r)?r<=Math.pow(2,8)?Uint8Array:r<=Math.pow(2,16)?Uint16Array:r<=Math.pow(2,32)?Uint32Array:r<=Number.MAX_SAFE_INTEGER?rc:null:null;class rc extends Array{constructor(e){super(e),this.fill(0)}}var cs;const fa=class fa{constructor(e,t){E(this,"heap");E(this,"length");if(!V(fa,cs))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=_R(e);if(!t)return[];We(fa,cs,!0);const n=new fa(e,t);return We(fa,cs,!1),n}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};cs=new WeakMap,at(fa,cs,!1);let ig=fa;var Rr,er,Nr,wr,us,on,Dr,ln,Lt,nt,Ln,tr,Cn,hn,xr,mn,gi,_i,kr,Lr,qi,Mn,jo,sg,Oa,Si,Jo,nr,zc,SR,ba,ds,el,qr,Ui,Vr,Fi,tl,og,ps,ic,fs,ac,Dt,Ft,nl,lg,Ea,bo;const y_=class y_{constructor(e){at(this,jo);at(this,zc);at(this,qr);at(this,Vr);at(this,tl);at(this,ps);at(this,fs);at(this,Dt);at(this,nl);at(this,Ea);at(this,Rr,void 0);at(this,er,void 0);at(this,Nr,void 0);at(this,wr,void 0);at(this,us,void 0);E(this,"ttl");E(this,"ttlResolution");E(this,"ttlAutopurge");E(this,"updateAgeOnGet");E(this,"updateAgeOnHas");E(this,"allowStale");E(this,"noDisposeOnSet");E(this,"noUpdateTTL");E(this,"maxEntrySize");E(this,"sizeCalculation");E(this,"noDeleteOnFetchRejection");E(this,"noDeleteOnStaleGet");E(this,"allowStaleOnFetchAbort");E(this,"allowStaleOnFetchRejection");E(this,"ignoreFetchAbort");at(this,on,void 0);at(this,Dr,void 0);at(this,ln,void 0);at(this,Lt,void 0);at(this,nt,void 0);at(this,Ln,void 0);at(this,tr,void 0);at(this,Cn,void 0);at(this,hn,void 0);at(this,xr,void 0);at(this,mn,void 0);at(this,gi,void 0);at(this,_i,void 0);at(this,kr,void 0);at(this,Lr,void 0);at(this,qi,void 0);at(this,Mn,void 0);at(this,Oa,()=>{});at(this,Si,()=>{});at(this,Jo,()=>{});at(this,nr,()=>!1);at(this,ba,e=>{});at(this,ds,(e,t,n)=>{});at(this,el,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:m,maxSize:_=0,maxEntrySize:v=0,sizeCalculation:I,fetchMethod:R,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:$,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:h,ignoreFetchAbort:b}=e;if(t!==0&&!Bi(t))throw new TypeError("max option must be a nonnegative integer");const S=t?_R(t):Array;if(!S)throw new Error("invalid max value: "+t);if(We(this,Rr,t),We(this,er,_),this.maxEntrySize=v||V(this,er),this.sizeCalculation=I,this.sizeCalculation){if(!V(this,er)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(R!==void 0&&typeof R!="function")throw new TypeError("fetchMethod must be a function if specified");if(We(this,us,R),We(this,qi,!!R),We(this,ln,new Map),We(this,Lt,new Array(t).fill(void 0)),We(this,nt,new Array(t).fill(void 0)),We(this,Ln,new S(t)),We(this,tr,new S(t)),We(this,Cn,0),We(this,hn,0),We(this,xr,ig.create(t)),We(this,on,0),We(this,Dr,0),typeof c=="function"&&We(this,Nr,c),typeof u=="function"?(We(this,wr,u),We(this,mn,[])):(We(this,wr,void 0),We(this,mn,void 0)),We(this,Lr,!!V(this,Nr)),We(this,Mn,!!V(this,wr)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!h,this.ignoreFetchAbort=!!b,this.maxEntrySize!==0){if(V(this,er)!==0&&!Bi(V(this,er)))throw new TypeError("maxSize must be a positive integer if specified");if(!Bi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");ze(this,zc,SR).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!$,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Bi(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!Bi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");ze(this,jo,sg).call(this)}if(V(this,Rr)===0&&this.ttl===0&&V(this,er)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!V(this,Rr)&&!V(this,er)){const N="LRU_CACHE_UNBOUNDED";VG(N)&&(mR.add(N),gR("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",N,y_))}}static unsafeExposeInternals(e){return{starts:V(e,_i),ttls:V(e,kr),sizes:V(e,gi),keyMap:V(e,ln),keyList:V(e,Lt),valList:V(e,nt),next:V(e,Ln),prev:V(e,tr),get head(){return V(e,Cn)},get tail(){return V(e,hn)},free:V(e,xr),isBackgroundFetch:t=>{var n;return ze(n=e,Dt,Ft).call(n,t)},backgroundFetch:(t,n,i,a)=>{var s;return ze(s=e,fs,ac).call(s,t,n,i,a)},moveToTail:t=>{var n;return ze(n=e,Ea,bo).call(n,t)},indexes:t=>{var n;return ze(n=e,qr,Ui).call(n,t)},rindexes:t=>{var n;return ze(n=e,Vr,Fi).call(n,t)},isStale:t=>{var n;return V(n=e,nr).call(n,t)}}}get max(){return V(this,Rr)}get maxSize(){return V(this,er)}get calculatedSize(){return V(this,Dr)}get size(){return V(this,on)}get fetchMethod(){return V(this,us)}get dispose(){return V(this,Nr)}get disposeAfter(){return V(this,wr)}getRemainingTTL(e){return V(this,ln).has(e)?1/0:0}*entries(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*rentries(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*keys(){for(const e of ze(this,qr,Ui).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*rkeys(){for(const e of ze(this,Vr,Fi).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*values(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}*rvalues(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,V(this,Lt)[n],this))return this.get(V(this,Lt)[n],t)}}forEach(e,t=this){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}rforEach(e,t=this){for(const n of ze(this,Vr,Fi).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}purgeStale(){let e=!1;for(const t of ze(this,Vr,Fi).call(this,{allowStale:!0}))V(this,nr).call(this,t)&&(this.delete(V(this,Lt)[t]),e=!0);return e}dump(){const e=[];for(const t of ze(this,qr,Ui).call(this,{allowStale:!0})){const n=V(this,Lt)[t],i=V(this,nt)[t],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;const s={value:a};if(V(this,kr)&&V(this,_i)){s.ttl=V(this,kr)[t];const o=po.now()-V(this,_i)[t];s.start=Math.floor(Date.now()-o)}V(this,gi)&&(s.size=V(this,gi)[t]),e.unshift([n,s])}return e}load(e){this.clear();for(const[t,n]of e){if(n.start){const i=Date.now()-n.start;n.start=po.now()-i}this.set(t,n.value,n)}}set(e,t,n={}){var m,_,v,I,R;if(t===void 0)return this.delete(e),this;const{ttl:i=this.ttl,start:a,noDisposeOnSet:s=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:l}=n;let{noUpdateTTL:c=this.noUpdateTTL}=n;const u=V(this,el).call(this,e,t,n.size||0,o);if(this.maxEntrySize&&u>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=V(this,on)===0?void 0:V(this,ln).get(e);if(p===void 0)p=V(this,on)===0?V(this,hn):V(this,xr).length!==0?V(this,xr).pop():V(this,on)===V(this,Rr)?ze(this,ps,ic).call(this,!1):V(this,on),V(this,Lt)[p]=e,V(this,nt)[p]=t,V(this,ln).set(e,p),V(this,Ln)[V(this,hn)]=p,V(this,tr)[p]=V(this,hn),We(this,hn,p),gl(this,on)._++,V(this,ds).call(this,p,u,l),l&&(l.set="add"),c=!1;else{ze(this,Ea,bo).call(this,p);const x=V(this,nt)[p];if(t!==x){if(V(this,qi)&&ze(this,Dt,Ft).call(this,x)){x.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:$}=x;$!==void 0&&!s&&(V(this,Lr)&&((m=V(this,Nr))==null||m.call(this,$,e,"set")),V(this,Mn)&&((_=V(this,mn))==null||_.push([$,e,"set"])))}else s||(V(this,Lr)&&((v=V(this,Nr))==null||v.call(this,x,e,"set")),V(this,Mn)&&((I=V(this,mn))==null||I.push([x,e,"set"])));if(V(this,ba).call(this,p),V(this,ds).call(this,p,u,l),V(this,nt)[p]=t,l){l.set="replace";const $=x&&ze(this,Dt,Ft).call(this,x)?x.__staleWhileFetching:x;$!==void 0&&(l.oldValue=$)}}else l&&(l.set="update")}if(i!==0&&!V(this,kr)&&ze(this,jo,sg).call(this),V(this,kr)&&(c||V(this,Jo).call(this,p,i,a),l&&V(this,Si).call(this,l,p)),!s&&V(this,Mn)&&V(this,mn)){const x=V(this,mn);let $;for(;$=x==null?void 0:x.shift();)(R=V(this,wr))==null||R.call(this,...$)}return this}pop(){var e;try{for(;V(this,on);){const t=V(this,nt)[V(this,Cn)];if(ze(this,ps,ic).call(this,!0),ze(this,Dt,Ft).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(V(this,Mn)&&V(this,mn)){const t=V(this,mn);let n;for(;n=t==null?void 0:t.shift();)(e=V(this,wr))==null||e.call(this,...n)}}}has(e,t={}){const{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=V(this,ln).get(e);if(a!==void 0){const s=V(this,nt)[a];if(ze(this,Dt,Ft).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if(V(this,nr).call(this,a))i&&(i.has="stale",V(this,Si).call(this,i,a));else return n&&V(this,Oa).call(this,a),i&&(i.has="hit",V(this,Si).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:n=this.allowStale}=t,i=V(this,ln).get(e);if(i!==void 0&&(n||!V(this,nr).call(this,i))){const a=V(this,nt)[i];return ze(this,Dt,Ft).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:l=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:_=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:I,forceRefresh:R=!1,status:x,signal:$}=t;if(!V(this,qi))return x&&(x.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:x});const Z={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:u,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:v,ignoreFetchAbort:_,status:x,signal:$};let h=V(this,ln).get(e);if(h===void 0){x&&(x.fetch="miss");const b=ze(this,fs,ac).call(this,e,h,Z,I);return b.__returned=b}else{const b=V(this,nt)[h];if(ze(this,Dt,Ft).call(this,b)){const M=n&&b.__staleWhileFetching!==void 0;return x&&(x.fetch="inflight",M&&(x.returnedStale=!0)),M?b.__staleWhileFetching:b.__returned=b}const S=V(this,nr).call(this,h);if(!R&&!S)return x&&(x.fetch="hit"),ze(this,Ea,bo).call(this,h),i&&V(this,Oa).call(this,h),x&&V(this,Si).call(this,x,h),b;const N=ze(this,fs,ac).call(this,e,h,Z,I),L=N.__staleWhileFetching!==void 0&&n;return x&&(x.fetch=S?"stale":"refresh",L&&S&&(x.returnedStale=!0)),L?N.__staleWhileFetching:N.__returned=N}}get(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=V(this,ln).get(e);if(o!==void 0){const l=V(this,nt)[o],c=ze(this,Dt,Ft).call(this,l);return s&&V(this,Si).call(this,s,o),V(this,nr).call(this,o)?(s&&(s.get="stale"),c?(s&&n&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),n?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&n&&(s.returnedStale=!0),n?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:(ze(this,Ea,bo).call(this,o),i&&V(this,Oa).call(this,o),l))}else s&&(s.get="miss")}delete(e){var n,i,a,s;let t=!1;if(V(this,on)!==0){const o=V(this,ln).get(e);if(o!==void 0)if(t=!0,V(this,on)===1)this.clear();else{V(this,ba).call(this,o);const l=V(this,nt)[o];ze(this,Dt,Ft).call(this,l)?l.__abortController.abort(new Error("deleted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((n=V(this,Nr))==null||n.call(this,l,e,"delete")),V(this,Mn)&&((i=V(this,mn))==null||i.push([l,e,"delete"]))),V(this,ln).delete(e),V(this,Lt)[o]=void 0,V(this,nt)[o]=void 0,o===V(this,hn)?We(this,hn,V(this,tr)[o]):o===V(this,Cn)?We(this,Cn,V(this,Ln)[o]):(V(this,Ln)[V(this,tr)[o]]=V(this,Ln)[o],V(this,tr)[V(this,Ln)[o]]=V(this,tr)[o]),gl(this,on)._--,V(this,xr).push(o)}}if(V(this,Mn)&&((a=V(this,mn))!=null&&a.length)){const o=V(this,mn);let l;for(;l=o==null?void 0:o.shift();)(s=V(this,wr))==null||s.call(this,...l)}return t}clear(){var e,t,n;for(const i of ze(this,Vr,Fi).call(this,{allowStale:!0})){const a=V(this,nt)[i];if(ze(this,Dt,Ft).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=V(this,Lt)[i];V(this,Lr)&&((e=V(this,Nr))==null||e.call(this,a,s,"delete")),V(this,Mn)&&((t=V(this,mn))==null||t.push([a,s,"delete"]))}}if(V(this,ln).clear(),V(this,nt).fill(void 0),V(this,Lt).fill(void 0),V(this,kr)&&V(this,_i)&&(V(this,kr).fill(0),V(this,_i).fill(0)),V(this,gi)&&V(this,gi).fill(0),We(this,Cn,0),We(this,hn,0),V(this,xr).length=0,We(this,Dr,0),We(this,on,0),V(this,Mn)&&V(this,mn)){const i=V(this,mn);let a;for(;a=i==null?void 0:i.shift();)(n=V(this,wr))==null||n.call(this,...a)}}};Rr=new WeakMap,er=new WeakMap,Nr=new WeakMap,wr=new WeakMap,us=new WeakMap,on=new WeakMap,Dr=new WeakMap,ln=new WeakMap,Lt=new WeakMap,nt=new WeakMap,Ln=new WeakMap,tr=new WeakMap,Cn=new WeakMap,hn=new WeakMap,xr=new WeakMap,mn=new WeakMap,gi=new WeakMap,_i=new WeakMap,kr=new WeakMap,Lr=new WeakMap,qi=new WeakMap,Mn=new WeakMap,jo=new WeakSet,sg=function(){const e=new rc(V(this,Rr)),t=new rc(V(this,Rr));We(this,kr,e),We(this,_i,t),We(this,Jo,(a,s,o=po.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{V(this,nr).call(this,a)&&this.delete(V(this,Lt)[a])},s+1);l.unref&&l.unref()}}),We(this,Oa,a=>{t[a]=e[a]!==0?po.now():0}),We(this,Si,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=n||i();const c=a.now-l;a.remainingTTL=o-c}});let n=0;const i=()=>{const a=po.now();if(this.ttlResolution>0){n=a;const s=setTimeout(()=>n=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=V(this,ln).get(a);if(s===void 0)return 0;const o=e[s],l=t[s];if(o===0||l===0)return 1/0;const c=(n||i())-l;return o-c},We(this,nr,a=>e[a]!==0&&t[a]!==0&&(n||i())-t[a]>e[a])},Oa=new WeakMap,Si=new WeakMap,Jo=new WeakMap,nr=new WeakMap,zc=new WeakSet,SR=function(){const e=new rc(V(this,Rr));We(this,Dr,0),We(this,gi,e),We(this,ba,t=>{We(this,Dr,V(this,Dr)-e[t]),e[t]=0}),We(this,el,(t,n,i,a)=>{if(ze(this,Dt,Ft).call(this,n))return 0;if(!Bi(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!Bi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),We(this,ds,(t,n,i)=>{if(e[t]=n,V(this,er)){const a=V(this,er)-e[t];for(;V(this,Dr)>a;)ze(this,ps,ic).call(this,!0)}We(this,Dr,V(this,Dr)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=V(this,Dr))})},ba=new WeakMap,ds=new WeakMap,el=new WeakMap,qr=new WeakSet,Ui=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,hn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,Cn)));)t=V(this,tr)[t]},Vr=new WeakSet,Fi=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,Cn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,hn)));)t=V(this,Ln)[t]},tl=new WeakSet,og=function(e){return e!==void 0&&V(this,ln).get(V(this,Lt)[e])===e},ps=new WeakSet,ic=function(e){var a,s;const t=V(this,Cn),n=V(this,Lt)[t],i=V(this,nt)[t];return V(this,qi)&&ze(this,Dt,Ft).call(this,i)?i.__abortController.abort(new Error("evicted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((a=V(this,Nr))==null||a.call(this,i,n,"evict")),V(this,Mn)&&((s=V(this,mn))==null||s.push([i,n,"evict"]))),V(this,ba).call(this,t),e&&(V(this,Lt)[t]=void 0,V(this,nt)[t]=void 0,V(this,xr).push(t)),V(this,on)===1?(We(this,Cn,We(this,hn,0)),V(this,xr).length=0):We(this,Cn,V(this,Ln)[t]),V(this,ln).delete(n),gl(this,on)._--,t},fs=new WeakSet,ac=function(e,t,n,i){const a=t===void 0?void 0:V(this,nt)[t];if(ze(this,Dt,Ft).call(this,a))return a;const s=new Qc,{signal:o}=n;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:n,context:i},c=(I,R=!1)=>{const{aborted:x}=s.signal,$=n.ignoreFetchAbort&&I!==void 0;if(n.status&&(x&&!R?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,$&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),x&&!$&&!R)return p(s.signal.reason);const Z=_;return V(this,nt)[t]===_&&(I===void 0?Z.__staleWhileFetching?V(this,nt)[t]=Z.__staleWhileFetching:this.delete(e):(n.status&&(n.status.fetchUpdated=!0),this.set(e,I,l.options))),I},u=I=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=I),p(I)),p=I=>{const{aborted:R}=s.signal,x=R&&n.allowStaleOnFetchAbort,$=x||n.allowStaleOnFetchRejection,Z=$||n.noDeleteOnFetchRejection,h=_;if(V(this,nt)[t]===_&&(!Z||h.__staleWhileFetching===void 0?this.delete(e):x||(V(this,nt)[t]=h.__staleWhileFetching)),$)return n.status&&h.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw I},m=(I,R)=>{var $;const x=($=V(this,us))==null?void 0:$.call(this,e,a,l);x&&x instanceof Promise&&x.then(Z=>I(Z===void 0?void 0:Z),R),s.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(I(void 0),n.allowStaleOnFetchAbort&&(I=Z=>c(Z,!0)))})};n.status&&(n.status.fetchDispatched=!0);const _=new Promise(m).then(c,u),v=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,v,{...l.options,status:void 0}),t=V(this,ln).get(e)):V(this,nt)[t]=v,v},Dt=new WeakSet,Ft=function(e){if(!V(this,qi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Qc},nl=new WeakSet,lg=function(e,t){V(this,tr)[t]=e,V(this,Ln)[e]=t},Ea=new WeakSet,bo=function(e){e!==V(this,hn)&&(e===V(this,Cn)?We(this,Cn,V(this,Ln)[e]):ze(this,nl,lg).call(this,V(this,tr)[e],V(this,Ln)[e]),ze(this,nl,lg).call(this,V(this,hn),e),We(this,hn,e))};let ag=y_;const Ro=class Ro{constructor(){E(this,"_fallbackMethod",()=>Ro.createSkipProxy());E(this,"out",()=>{})}};E(Ro,"createSkipProxy",()=>{const e=new Ro;return new Proxy(e,{get(t,n,i){return typeof t[n]>"u"?t._fallbackMethod:t[n]},set(t,n,i,a){return!1}})});let qc=Ro;const No=class No extends C_{constructor(t,n){super(n);E(this,"_fallbackMethod",()=>No.createRestProxy(this.values.length,this.app));E(this,"out",()=>{});this.values.length=t}};E(No,"createRestProxy",(t,n)=>{const i=new No(t,n);return new Proxy(i,{get(a,s,o){return typeof a[s]>"u"?a._fallbackMethod:a[s]},set(a,s,o,l){return!1}})});let Vc=No;class zG extends C_{constructor(t,n,i){super(i);E(this,"input");E(this,"ziffers");E(this,"initCallTime",0);E(this,"startCallTime",0);E(this,"lastCallTime",0);E(this,"waitTime",0);E(this,"startBeat",0);E(this,"played",!1);E(this,"current");E(this,"retro",!1);E(this,"index",-1);E(this,"zid","");E(this,"options",{});E(this,"skipIndex",0);E(this,"endTime",0);E(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));E(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));E(this,"firstRun",()=>this.notStarted());E(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);E(this,"origin",()=>this.app.clock.pulses_since_origin+1);E(this,"pulse",()=>this.app.clock.time_position.pulse);E(this,"beat",()=>this.app.clock.time_position.beat);E(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);E(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);E(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.nextBeatInTicks())&&this.origin()>=this.waitTime,n=this.current&&this.pulseToSecond(this.origin())>=this.pulseToSecond(this.lastCallTime)+this.pulseToSecond(this.current.duration*4*this.app.clock.ppqn)&&this.origin()>=this.waitTime,i=t||n;return this.skipIndex=i?0:this.skipIndex+1,this.index=i?this.index+1:this.index,i&&this.notStarted()&&(this.initCallTime=this.app.clock.pulses_since_origin),this.atTheBeginning()&&(this.startCallTime=this.app.clock.pulses_since_origin),i});E(this,"lead",()=>this.voiceleading());E(this,"invert",t=>(this.atTheBeginning()&&this.ziffers.invert(t),this));E(this,"out",()=>{});this.app=i,this.input=t,this.options=n,this.ziffers=new $G(t,n)}get ticks(){return this.ziffers.duration*4*this.app.clock.ppqn}nextEndTime(){return this.startCallTime+this.ticks}updateLastCallTime(){(this.notStarted()||this.played)&&(this.lastCallTime=this.app.clock.pulses_since_origin,this.played=!1)}notStarted(){return this.ziffers.notStarted()}sound(t){if(this.areWeThereYet()){const n=this.next(),i=this.app.clock.convertPulseToSecond(n.duration*4*this.app.clock.ppqn);if(n instanceof ni){const a=n.getExisting("freq","pitch","key","scale","octave","parsedScale");return n.sound&&(t=n.sound),n.soundIndex&&(a.n=n.soundIndex),a.dur=i,new tg(a,this.app).sound(t||"sine")}else if(n instanceof Na){const a=n.pitches.map(o=>o.getExisting("freq","pitch","key","scale","octave","parsedScale")),s={dur:i};return t&&(s.s=t),new tg(s,this.app).chord(a)}else if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app)}else return qc.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const n=this.next(),i=n.getExisting("note","pitch","bend","key","scale","octave","parsedScale");if(n instanceof ni){n.soundIndex&&(i.channel=n.soundIndex);const a=new ng(i,this.app);return t?a.note(t):a}else{if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app);if(n instanceof Na){const a=n.midiChord();return new ng(i,this.app).chord(a)}}}else return qc.createSkipProxy()}scale(t){return this.atTheBeginning()&&this.ziffers.scale(t),this}key(t){return this.atTheBeginning()&&this.ziffers.key(t),this}octave(t){return this.atTheBeginning()&&this.ziffers.octave(t),this}voiceleading(){return this.atTheBeginning()&&this.ziffers.lead(),this}retrograde(){return this.atTheBeginning()&&this.ziffers.retrograde(),this}wait(t){if(this.atTheBeginning()){if(typeof t=="function"){const n=this.app.api.patternCache.get(t.name);return n&&(this.waitTime=n.nextEndTime()),this}this.waitTime=this.origin()+Math.ceil(t*4*this.app.clock.ppqn)}return this}sync(t){if(this.atTheBeginning()&&this.notStarted()){const n=this.app.clock.pulses_since_origin,i=typeof t=="function"?t.name:t;if(n>0){const a=this.app.api.patternCache.get(i);if(a){const s=a.ziffers.duration,o=a.startCallTime,l=s*4*this.app.clock.ppqn;this.waitTime=o+l}}}return this}}const HG=r=>r[0]==="{"&&r[r.length-1]==="}",fo=(r,e)=>{if(HG(r)){const t=JSON.parse(r);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:r})},WG=r=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new OR({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return fo(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return fo(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return fo(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return fo(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return fo(this.valueOf(),{voice:e})},String.prototype.z=function(e={}){return r.z(this.valueOf(),e)},String.prototype.z0=function(e={}){return r.z0(this.valueOf(),e)},String.prototype.z1=function(e={}){return r.z1(this.valueOf(),e)},String.prototype.z2=function(e={}){return r.z2(this.valueOf(),e)},String.prototype.z3=function(e={}){return r.z3(this.valueOf(),e)},String.prototype.z4=function(e={}){return r.z4(this.valueOf(),e)},String.prototype.z5=function(e={}){return r.z5(this.valueOf(),e)},String.prototype.z6=function(e={}){return r.z6(this.valueOf(),e)},String.prototype.z7=function(e={}){return r.z7(this.valueOf(),e)},String.prototype.z8=function(e={}){return r.z8(this.valueOf(),e)},String.prototype.z9=function(e={}){return r.z9(this.valueOf(),e)},String.prototype.z10=function(e={}){return r.z10(this.valueOf(),e)},String.prototype.z11=function(e={}){return r.z11(this.valueOf(),e)},String.prototype.z12=function(e={}){return r.z12(this.valueOf(),e)},String.prototype.z13=function(e={}){return r.z13(this.valueOf(),e)},String.prototype.z14=function(e={}){return r.z14(this.valueOf(),e)},String.prototype.z15=function(e={}){return r.z15(this.valueOf(),e)},String.prototype.z16=function(e={}){return r.z16(this.valueOf(),e)},String.prototype.note=function(){try{return parseInt(this.valueOf())}catch{return Ur(this.valueOf())}}};let qh;class OR{constructor(e){E(this,"speak",()=>new Promise((e,t)=>{if(this.options.text){const n=window.speechSynthesis;n.speaking&&n.cancel();const i=new SpeechSynthesisUtterance(this.options.text);i.rate=this.options.rate||1,i.pitch=this.options.pitch||1,i.volume=this.options.volume||1,this.options.voice&&(i.voice=n.getVoices()[this.options.voice]),this.options.lang&&(this.options.lang.length===2?i.lang=`${this.options.lang}-${this.options.lang.toUpperCase()}`:this.options.lang.length===5?i.lang=this.options.lang:i.lang="en-US"),i.onend=()=>{e()},i.onerror=a=>{t(a)},n.speaking?(n.cancel(),qh&&clearTimeout(qh),qh=setTimeout(()=>{n.speak(i)},200)):n.speak(i)}else t("No text provided")}));this.options=e}}async function bR(){return Promise.all([jR(),Yi("github:tidalcycles/Dirt-Samples/master").then(()=>h2()),O2(),Yi("github:Bubobubobubobubo/Dough-Fox/main"),Yi("github:Bubobubobubobubo/Dough-Samples/main"),Yi("github:Bubobubobubobubo/Dough-Amiga/main"),Yi("github:Bubobubobubobubo/Dough-Amen/main"),Yi("github:Bubobubobubobubo/Dough-Waveforms/main")])}class XG{constructor(e){E(this,"variables",{});E(this,"codeExamples",{});E(this,"counters",{});E(this,"_drunk",new qG(-100,100,!1));E(this,"randomGen",Math.random);E(this,"currentSeed");E(this,"localSeeds",new Map);E(this,"patternCache",new ag({max:1e3,ttl:1e3*60*5}));E(this,"errorTimeoutID",0);E(this,"printTimeoutID",0);E(this,"MidiConnection");E(this,"scale_aid");E(this,"load");E(this,"_loadUniverseFromInterface",e=>{Dc(this.app,e),xc()});E(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"_playDocExample",e=>{let t=this.app.universes[this.app.selected_universe];this.app.exampleIsPlaying=!0,t.example?t.example.candidate=e||this.app.selectedExample:(t.example={candidate:"",committed:"",evaluations:0},t.example.candidate=e||this.app.selectedExample),this.play()});E(this,"_stopDocExample",()=>{let e=this.app.universes[this.app.selected_universe];(e==null?void 0:e.example)!==void 0&&(this.app.exampleIsPlaying=!1,e.example.candidate="",e.example.committed=""),this.pause()});E(this,"_playDocExampleOnce",e=>{let t=this.app.universes[this.app.selected_universe];(t==null?void 0:t.example)!==void 0&&(t.example.candidate="",t.example.committed=""),this.play(),this.app.exampleIsPlaying=!0,OM(this.app,e)});E(this,"_all_samples",()=>dg.get());E(this,"_reportError",e=>{console.log(e),clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="color-red-800",this.app.interface.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),2e3)});E(this,"_logMessage",e=>{console.log(e),clearTimeout(this.printTimeoutID),clearTimeout(this.errorTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="white",this.app.interface.error_line.classList.remove("hidden"),this.printTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),4e3)});E(this,"time",()=>this.app.audioContext.currentTime);E(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});E(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.MidiConnection.sendStopMessage(),this.app.clock.pause()});E(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.MidiConnection.sendStopMessage(),this.app.clock.stop()});E(this,"silence",this.stop);E(this,"hush",this.stop);E(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});E(this,"beat_warp",e=>{this.app.clock.tick=e*this.app.clock.ppqn,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e*this.app.clock.ppqn)});E(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});E(this,"mouseX",()=>this.app._mouseX);E(this,"mouseY",()=>this.app._mouseY);E(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));E(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));E(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(E2(this.app,"local",t),Ra(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});E(this,"s",this.script);E(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});E(this,"cs",this.delete_script);E(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});E(this,"cps",this.copy_script);E(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});E(this,"delete_universe",e=>{this.app.selected_universe===e&&(this.app.selected_universe="Default"),delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Xo},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});E(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});E(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});E(this,"midi",(e=60,t,n)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),n!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=n),new ng(e,this.app)));E(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});E(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});E(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});E(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});E(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});E(this,"midi_panic",()=>{this.MidiConnection.panic()});E(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});E(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});E(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});E(this,"sticky_notes",e=>{let t;if(e?t=this.MidiConnection.stickyNotesFromChannel(e):t=this.MidiConnection.stickyNotes,t.length>0)return t.map(n=>n.note)});E(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});E(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);E(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());E(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});E(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);E(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});E(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);E(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);E(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());E(this,"show_scale",(e,t,n=0,i=this.MidiConnection.currentOutputIndex||0,a=!1)=>{(!this.scale_aid||t!==this.scale_aid)&&(this.hide_scale(e,t,n,i),NG(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});E(this,"hide_scale",(e=0,t=0,n=0,i=this.MidiConnection.currentOutputIndex||0)=>{Array.from(Array(128).keys()).forEach(s=>{this.MidiConnection.sendMidiOff(s,n,i)}),this.scale_aid=void 0});E(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});E(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});E(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));E(this,"z",(e,t={},n="")=>{const i="z"+n.toString(),a=n===""?this.generateCacheKey(e,t):i;let s;return this.app.api.patternCache.has(a)&&(s=this.app.api.patternCache.get(a),s.input!==e&&(s=void 0)),s||(s=new zG(e,t,this.app),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&s.sync("z0"),s});E(this,"z0",(e,t={})=>this.z(e,t,0));E(this,"z1",(e,t={})=>this.z(e,t,1));E(this,"z2",(e,t={})=>this.z(e,t,2));E(this,"z3",(e,t={})=>this.z(e,t,3));E(this,"z4",(e,t={})=>this.z(e,t,4));E(this,"z5",(e,t={})=>this.z(e,t,5));E(this,"z6",(e,t={})=>this.z(e,t,6));E(this,"z7",(e,t={})=>this.z(e,t,7));E(this,"z8",(e,t={})=>this.z(e,t,8));E(this,"z9",(e,t={})=>this.z(e,t,9));E(this,"z10",(e,t={})=>this.z(e,t,10));E(this,"z11",(e,t={})=>this.z(e,t,11));E(this,"z12",(e,t={})=>this.z(e,t,12));E(this,"z13",(e,t={})=>this.z(e,t,13));E(this,"z14",(e,t={})=>this.z(e,t,14));E(this,"z15",(e,t={})=>this.z(e,t,15));E(this,"z16",(e,t={})=>this.z(e,t,16));E(this,"counter",(e,t,n)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==n&&(this.counters[e].step=n??this.counters[e].step),this.counters[e].value+=this.counters[e].step,this.counters[e].limit!==void 0&&this.counters[e].value>this.counters[e].limit&&(this.counters[e].value=0)):this.counters[e]={value:0,step:n??1,limit:t},this.counters[e].value));E(this,"$",this.counter);E(this,"i",e=>e!==void 0?(this.app.universes[this.app.selected_universe].global.evaluations=e,this.app.universes[this.app.selected_universe]):this.app.universes[this.app.selected_universe].global.evaluations);E(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));E(this,"drunk_max",e=>{this._drunk.max=e});E(this,"drunk_min",e=>{this._drunk.min=e});E(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});E(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));E(this,"v",this.variable);E(this,"delete_variable",e=>{delete this.variables[e]});E(this,"dv",this.delete_variable);E(this,"clear_variables",()=>{this.variables={}});E(this,"cv",this.clear_variables);E(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);E(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);E(this,"irand",this.randI);E(this,"rI",this.randI);E(this,"r",this.rand);E(this,"ir",this.randI);E(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=jm(e))});E(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=jm(e);return this.localSeeds.set(e,t),t});E(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});E(this,"quantize",(e,t)=>{if(t.length===0)return e;let n=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),n));E(this,"cmp",this.clamp);E(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));E(this,"bpm",e=>e===void 0?this.app.clock.bpm:((e<1||e>500)&&console.log(`Setting bpm to ${e}`),this.app.clock.bpm=e,e));E(this,"tempo",this.bpm);E(this,"bpb",e=>e===void 0?this.app.clock.time_signature[0]:(e<1&&console.log(`Setting bpb to ${e}`),this.app.clock.time_signature[0]=e,e));E(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));E(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});E(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);E(this,"odds",(e,t=1)=>this.randomGen()!1);E(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));E(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));E(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));E(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));E(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));E(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));E(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));E(this,"always",(e=1)=>!0);E(this,"dice",e=>Math.floor(this.randomGen()*e)+1);E(this,"cbar",()=>this.app.clock.time_position.bar+1);E(this,"ctick",()=>this.app.clock.tick+1);E(this,"cpulse",()=>this.app.clock.time_position.pulse+1);E(this,"cbeat",()=>this.app.clock.time_position.beat+1);E(this,"ebeat",()=>this.app.clock.beats_since_origin+1);E(this,"epulse",()=>this.app.clock.pulses_since_origin+1);E(this,"nominator",()=>this.app.clock.time_signature[0]);E(this,"meter",()=>this.app.clock.time_signature[1]);E(this,"denominator",this.meter);E(this,"fill",()=>this.app.fill);E(this,"beat",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-Math.floor(t*this.ppqn()))%Math.floor(a*this.ppqn())===0).some(a=>a===!0));E(this,"b",this.beat);E(this,"bar",(e=1,t=0)=>{const n=Array.isArray(e)?e:[e],i=this.app.clock.time_signature[1]*this.ppqn(),a=Math.floor(t*i);return n.map(o=>(this.app.clock.pulses_since_origin-a)%Math.floor(o*i)===0).some(o=>o===!0)});E(this,"B",this.bar);E(this,"pulse",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-t)%a===0).some(a=>a===!0));E(this,"p",this.pulse);E(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));E(this,"flip",(e,t=50)=>{let n=e*2;const i=this.app.clock.pulses_since_origin,a=Math.floor(n*this.ppqn()),s=Math.floor(t/100*a);return i%a{let t=e*2;const n=this.app.clock.time_position.bar;return Math.floor(n/t)%2===0});E(this,"onbar",(e,t=this.app.clock.time_signature[0])=>{let n=this.app.clock.time_position.bar%t+1;return typeof e=="number"?e===n:e.some(i=>i==n)});E(this,"onbeat",(...e)=>{let t=[];return e.forEach(n=>{let i=n%this.nominator()||this.nominator(),a=Math.floor(i);a=a==0?this.nominator():a;let s=Math.floor((i-a)*this.ppqn()+1);s<=0&&(s=s+this.ppqn()*this.nominator()),t.push(a===this.cbeat()&&this.cpulse()===s)}),t.some(n=>n==!0)});E(this,"oncount",(e,t)=>{typeof e=="number"&&(e=[e]);const n=this.app.clock.pulses_since_origin;let i=[];return e.forEach(a=>{a=a<1?0:a-1;const s=Math.ceil(a*this.ppqn()),o=n%(this.ppqn()*t);return i.push(o===s)}),i.some(a=>a==!0)});E(this,"oneuclid",(e,t,n=0)=>{const a=this._euclidean_cycle(e,t,n).reduce((s,o,l)=>(o&&s.push(l+1),s),[]);return this.oncount(a,t)});E(this,"delay",(e,t)=>{setTimeout(t,e)});E(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});E(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);E(this,"ec",this.euclid);E(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));E(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});E(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});E(this,"line",(e,t,n=1)=>{const i=[];if(t>e&&n>0||t(Math.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+n)*t);E(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,n)+1)/2*t);E(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);E(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,n)+1)/2*t);E(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,n))*2-1)*t);E(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,n)+1)/2*t);E(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,n,i)+1)/2*t);E(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);E(this,"min",(...e)=>Math.min(...e));E(this,"max",(...e)=>Math.max(...e));E(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);E(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);E(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));E(this,"abs",Math.abs);E(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new OR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});E(this,"stop_hydra",()=>{this.app.hydra.hush()});E(this,"sound",e=>new tg(e,this.app));E(this,"snd",this.sound);E(this,"samples",Yi);E(this,"log",e=>{console.log(e),this._logMessage(e)});E(this,"scale",T_);E(this,"rate",e=>{});E(this,"divseq",(...e)=>{const t=e[0],n=e.slice(1),i=this.app.clock.pulses_since_origin,a=Math.floor(i/Math.floor(t*this.ppqn()));return n[a%n.length]});E(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);E(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);E(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));E(this,"reverse",e=>e.reverse());E(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));E(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));E(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));E(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));E(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));E(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});this.app=e,this.MidiConnection=new QG(this,e.settings)}transmission(){return this.MidiConnection.activeNotes.length>0}_euclidean_cycle(e,t,n=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,u=(l+1)%c;return o[l]>o[u]}if(e>=t)return[!0];const a=Array.from({length:t},(o,l)=>(e*(l-1)%t+t)%t);let s=a.map((o,l)=>i(a,l));return n!=0&&(s=s.slice(n).concat(s.slice(0,n))),s}}const ZG=r=>{Array.prototype.square=function(){return this.map(e=>e*e)},Array.prototype.sometimes=function(e){return r.randomGen()<.5?e(this):this},Array.prototype.apply=function(e){return e(this)},Array.prototype.sqrt=function(){if(this.some(e=>e<0))throw new Error("Cannot take square root of negative number");return this.map(e=>Math.sqrt(e))},Array.prototype.add=function(e){return this.map(t=>t+e)},Array.prototype.sub=function(e){return this.map(t=>t-e)},Array.prototype.mult=function(e){return this.map(t=>t*e)},Array.prototype.div=function(e){if(e===0)throw new Error("Division by zero");return this.map(t=>t/e)},Array.prototype.pick=function(){return this[Math.floor(r.randomGen()*this.length)]},Array.prototype.gen=function(e,t,n){return n<1?[]:Array.from({length:n},()=>Math.floor(r.randomGen()*(t-e+1))+e)},Array.prototype.bar=function(e=1){return e===1?this[r.app.clock.time_position.bar%this.length]:this[Math.floor(r.app.clock.time_position.bar/e)%this.length]},Array.prototype.beat=function(e=1){const t=e,n=r.app.clock.pulses_since_origin,i=Math.floor(n/Math.floor(t*r.ppqn()));return this[i%this.length]},Array.prototype.b=Array.prototype.beat,Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(r.randomGen()*e),e--,[this[e],this[t]]=[this[t],this[e]];return this},Array.prototype.rotate=function(e){const t=this.length;if(e<0)e=t+e%t;else if(e>0)e=e%t;else return this;const n=this.splice(-e,e);return this.unshift(...n),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let n=0;n100)throw new Error("Amount should be between 0 and 100");if(this.length<=1)return this;for(let t=0;t1)this.splice(t,1);else return this;else t++;return this},Array.prototype.repeat=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let n=0;n(i%a+a)%a,n=cR(Ds(r));return this.map(i=>{const a=Math.floor(i/n.length)*12;return n[t(i,n.length)]+e+a})};Array.prototype.scaleArp=function(r="major",e=0){const t=cR(Ds(r));let n=[];e=e>t.length?t.length:e,e=e==0?t.length:e;for(let i=0;i{r.interface.line_numbers_checkbox.checked=r.settings.line_numbers,r.interface.time_position_checkbox.checked=r.settings.time_position,r.interface.tips_checkbox.checked=r.settings.tips,r.interface.midi_clock_checkbox.checked=r.settings.send_clock,r.interface.midi_channels_scripts.checked=r.settings.midi_channels_scripts,r.interface.midi_clock_ppqn.value=r.settings.midi_clock_ppqn.toString(),r.settings.time_position||r.interface.timeviewer.classList.add("hidden"),r.interface.load_demo_songs.checked=r.settings.load_demo_songs;const e=document.querySelectorAll('[id^="tab-"]');for(let t=0;t{e[t].classList.add("bg-orange-300");for(let s=0;s{hi(),r.updateKnownUniversesView(),xc()}),r.buttonElements.play_buttons.forEach(t=>{t.addEventListener("click",()=>{r.isPlaying?(r.setButtonHighlighting("pause",!0),r.isPlaying=!r.isPlaying,r.clock.pause(),r.api.MidiConnection.sendStopMessage()):(r.setButtonHighlighting("play",!0),r.isPlaying=!r.isPlaying,r.clock.start(),r.api.MidiConnection.sendStartMessage())})}),r.buttonElements.clear_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("clear",!0),confirm("Do you want to reset the current universe?")&&(r.universes[r.selected_universe]=structuredClone(t_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{XI(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Xo},r.updateKnownUniversesView())}),r.interface.audio_nudge_range.addEventListener("input",()=>{r.clock.nudge=parseInt(r.interface.audio_nudge_range.value)}),r.interface.dough_nudge_range.addEventListener("input",()=>{r.dough_nudge=parseInt(r.interface.dough_nudge_range.value)}),r.interface.upload_universe_button.addEventListener("click",()=>{const t=document.createElement("input");t.type="file",t.accept=".json",t.addEventListener("change",n=>{var s;const a=(s=n.target.files)==null?void 0:s[0];if(a){const o=new FileReader;o.readAsText(a,"UTF-8"),o.onload=l=>{const c=JSON.parse(l.target.result);for(const[u,p]of Object.entries(c))r.universes[u]=p},o.onerror=l=>{console.error("An error occurred reading the file:",l)}}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}),r.interface.download_universe_button.addEventListener("click",()=>{r.settings.saveApplicationToLocalStorage(r.universes,r.settings);let t=`topos-universes-${Date.now()}.json`;const n=new Blob([JSON.stringify(r.settings.universes)],{type:"application/json"}),i=URL.createObjectURL(n),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}),r.interface.load_universe_button.addEventListener("click",()=>{let t=r.interface.buffer_search.value;t.length>2&&t.length<20&&!t.includes(" ")&&(Dc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Vm(),r.view.focus(),FA())}),r.interface.eval_button.addEventListener("click",()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.flashBackground("#404040",200)}),r.buttonElements.stop_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("stop",!0),r.isPlaying=!1,r.clock.stop()})}),r.interface.local_button.addEventListener("click",()=>r.changeModeFromInterface("local")),r.interface.global_button.addEventListener("click",()=>r.changeModeFromInterface("global")),r.interface.init_button.addEventListener("click",()=>r.changeModeFromInterface("init")),r.interface.note_button.addEventListener("click",()=>r.changeModeFromInterface("notes")),r.interface.font_family_selector.addEventListener("change",()=>{let t=r.interface.font_family_selector.value;console.log("Picking new font : "+t),r.settings.font=t,r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:t,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.font_size_input.addEventListener("input",()=>{let t=r.interface.font_size_input.value;r.settings.font_size=parseInt(t),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.settings_button.addEventListener("click",()=>{const t=document.getElementById("font-family");t&&(t.value=r.settings.font);const n=r.interface.dough_nudge_range;n.value=r.dough_nudge.toString();const i=document.getElementById("doughnumber");i.value=r.dough_nudge.toString(),r.settings.font_size===null&&(r.settings.font_size=12);const a=r.interface.font_size_input;a.value=r.settings.font_size.toString();const s=r.interface.line_numbers_checkbox;s.checked=r.settings.line_numbers;const o=r.interface.time_position_checkbox;o.checked=r.settings.time_position;const l=r.interface.tips_checkbox;l.checked=r.settings.tips;const c=r.interface.midi_clock_checkbox;c.checked=r.settings.send_clock;const u=r.interface.midi_channels_scripts;u.checked=r.settings.midi_channels_scripts;const p=r.interface.midi_clock_ppqn;p.value=r.settings.midi_clock_ppqn.toString();const m=r.interface.load_demo_songs;m.checked=r.settings.load_demo_songs;const _=r.interface.vim_mode_checkbox;_.checked=r.settings.vimMode;let v=document.getElementById("modal-settings"),I=document.getElementById("editor");v==null||v.classList.remove("invisible"),I==null||I.classList.add("invisible")}),r.interface.close_settings_button.addEventListener("click",()=>{let t=document.getElementById("modal-settings"),n=document.getElementById("editor");t==null||t.classList.add("invisible"),n==null||n.classList.remove("invisible");let i=r.interface.font_size_input.value;r.settings.font_size=parseInt(i),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.close_universes_button.addEventListener("click",()=>{xc()}),r.interface.share_button.addEventListener("click",async()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),await vM(r)}),r.interface.vim_mode_checkbox.addEventListener("change",()=>{let t=!!r.interface.vim_mode_checkbox.checked;r.settings.vimMode=t,r.view.dispatch({effects:r.vimModeCompartment.reconfigure(t?f_():[])})}),r.interface.line_numbers_checkbox.addEventListener("change",()=>{let n=!!r.interface.line_numbers_checkbox.checked;r.settings.line_numbers=n,r.view.dispatch({effects:r.withLineNumbers.reconfigure(n?[ey()]:[])})}),r.interface.time_position_checkbox.addEventListener("change",()=>{let t=document.getElementById("timeviewer"),n=!!r.interface.time_position_checkbox.checked;r.settings.time_position=n,n?t.classList.remove("hidden"):t.classList.add("hidden")}),r.interface.tips_checkbox.addEventListener("change",()=>{let t=!!r.interface.tips_checkbox.checked;r.settings.tips=t,r.view.dispatch({effects:r.hoveringCompartment.reconfigure(t?rR:[])})}),r.interface.midi_clock_checkbox.addEventListener("change",()=>{let t=!!r.interface.midi_clock_checkbox.checked;r.settings.send_clock=t}),r.interface.midi_channels_scripts.addEventListener("change",()=>{let t=!!r.interface.midi_channels_scripts.checked;r.settings.midi_channels_scripts=t}),r.interface.midi_clock_ppqn.addEventListener("change",()=>{let t=parseInt(r.interface.midi_clock_ppqn.value);r.settings.midi_clock_ppqn=t}),r.interface.load_demo_songs.addEventListener("change",()=>{let t=!!r.interface.load_demo_songs.checked;r.settings.load_demo_songs=t}),r.interface.universe_creator.addEventListener("submit",t=>{t.preventDefault();let i=new FormData(r.interface.universe_creator).get("universe");i&&i.length>2&&i.length<20&&(Dc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Vm(),r.view.focus())}),Ra(r,r.universes[r.selected_universe.toString()].init),["introduction","interface","interaction","code","time","sound","samples","synths","chaining","patterns","ziffers","midi","functions","lfos","probabilities","variables","shortcuts","about","bonus","oscilloscope"].forEach(t=>{let n="docs_"+t;document.getElementById(n).addEventListener("click",async()=>{n!=="docs_samples"?(r.currentDocumentationPane=t,Km(r)):(console.log("Loading samples!"),await bR().then(()=>{r.docs=WI(r),r.currentDocumentationPane=t,Km(r)}))})})},ST=r=>{if(!r)return;r.width=window.innerWidth,r.height=window.innerHeight;const e=r.getContext("2d"),t=window.devicePixelRatio||1;r.width=window.innerWidth*t,r.height=window.innerHeight*t,e&&e.scale(t,t)},jG=(r,e,t=!1)=>{e.addEventListener("resize",()=>ST(r.interface.scope)),e.addEventListener("resize",()=>ST(r.interface.feedback)),e.addEventListener("beforeunload",()=>(event.preventDefault(),r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),r.clock.stop(),null)),t&&(localStorage.openpages=Date.now(),e.addEventListener("storage",function(n){n.key=="openpages"&&(localStorage.page_available=Date.now()),n.key=="page_available"&&(document.getElementById("all").classList.add("invisible"),alert("Topos is already opened in another tab. Close this tab now to prevent data loss."))},!1))};class JG{constructor(){E(this,"settings",new bM);E(this,"universes",Xo);E(this,"selected_universe","Welcome");E(this,"fill",!1);E(this,"local_index",1);E(this,"editor_mode","global");E(this,"fontSize");E(this,"withLineNumbers");E(this,"vimModeCompartment");E(this,"hoveringCompartment");E(this,"chosenLanguage");E(this,"dynamicPlugins");E(this,"currentDocumentationPane","introduction");E(this,"exampleCounter",0);E(this,"exampleIsPlaying",!1);E(this,"editorExtensions",[]);E(this,"userPlugins",[]);E(this,"state");E(this,"view");E(this,"selectedExample","");E(this,"docs",{});E(this,"_mouseX",0);E(this,"_mouseY",0);E(this,"show_error",!1);E(this,"buttonElements",{});E(this,"interface",{});E(this,"blinkTimeouts",{});E(this,"osc",{enabled:!1,color:"#fdba74",thickness:4,refresh:1,fftSize:256,orientation:"horizontal",is3D:!1,size:1});E(this,"api");E(this,"audioContext");E(this,"clock");E(this,"dough_nudge",20);E(this,"manualPlay",!1);E(this,"isPlaying",!1);E(this,"hydra_backend");E(this,"hydra");E(this,"updateKnownUniversesView",()=>{let e=document.getElementById("ui-known-universe-item-template");if(!e){console.warn("Missing template #ui-known-universe-item-template");return}let t=document.getElementById("existing-universes");if(!t){console.warn("Missing element #existing-universes");return}let n=document.createElement("ul");n.className="lg:h-80 lg:text-normal text-sm h-auto lg:w-80 w-auto lg:pb-2 lg:pt-2 overflow-y-scroll text-white lg:mb-4 border rounded-lg bg-neutral-800",n.append(...Object.keys(this.universes).map(i=>{var o,l;let a=e.content.cloneNode(!0),s=window;return a.querySelector(".universe-name").textContent=i,(o=a.querySelector(".load-universe"))==null||o.addEventListener("click",()=>s._loadUniverseFromInterface(i)),(l=a.querySelector(".delete-universe"))==null||l.addEventListener("click",()=>s._deleteUniverseFromInterface(i)),a})),t.innerHTML="",t.append(n)});this.initializeElements(),this.initializeButtonGroups(),this.initializeHydra(),this.setCanvas(this.interface.feedback),this.setCanvas(this.interface.scope),this.universes={...this.settings.universes,...Xo},EM(this),this.audioContext=new AudioContext({latencyHint:"playback"}),this.clock=new j$(this,this.audioContext),this.api=new XG(this),ZG(this.api),WG(this.api),Object.entries(this.api).forEach(([t,n])=>{globalThis[t]=n}),(async()=>{await bR()})(),this.docs=WI(this),T$(this),C$(this),KG(this),TT(this),X$(this),v2(this.interface.scope,this),Ra(this,this.universes[this.selected_universe.toString()].init),this.changeModeFromInterface("global"),TM(this)}getBuffer(e){const t=this.universes[this.selected_universe.toString()];return e==="locals"?t[e][this.local_index]:t[e]}get note_buffer(){return this.getBuffer("notes")}get example_buffer(){return this.getBuffer("example")}get global_buffer(){return this.getBuffer("global")}get init_buffer(){return this.getBuffer("init")}get local_buffer(){return this.getBuffer("locals")}changeToLocalBuffer(e){const t=document.querySelectorAll('[id^="tab-"]'),n=t[e];n.classList.add("bg-orange-300");for(let a=0;a{t.forEach(a=>{let s=a.children[0];s.classList.contains("text-orange-300")&&(s.classList.remove("text-orange-300"),a.classList.remove("text-orange-300"))}),i.children[0].classList.remove("text-white"),i.children[0].classList.add("text-orange-300"),i.classList.add("text-orange-300"),i.classList.add("fill-orange-300")};switch(e){case"local":this.interface.local_script_tabs.classList.contains("hidden")&&this.interface.local_script_tabs.classList.remove("hidden"),this.editor_mode="local",this.local_index=0,document.getElementById("editor").style.height="calc(100% - 100px)",this.changeToLocalBuffer(this.local_index),n(this.interface.local_button);break;case"global":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="global",document.getElementById("editor").style.height="100%",n(this.interface.global_button);break;case"init":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="init",n(this.interface.init_button);break;case"notes":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="notes",n(this.interface.note_button);break}this.view.dispatch({effects:this.chosenLanguage.reconfigure(this.editor_mode=="notes"?[BL()]:[Gg()])}),this.updateEditorView()}setButtonHighlighting(e,t){document.getElementById("play-label").textContent=e!=="pause"?"Pause":"Play",e!=="pause"?(document.getElementById("pause-icon").classList.remove("hidden"),document.getElementById("play-icon").classList.add("hidden")):(document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),e==="stop"&&(this.isPlaying==!1,document.getElementById("play-label").textContent="Play",document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),this.flashBackground("#404040",200);const n=['[id^="play-button-"]','[id^="clear-button-"]','[id^="stop-button-"]'];let i;switch(e){case"play":i=0;break;case"pause":i=1;break;case"clear":i=2;break;case"stop":i=3;break}document.querySelectorAll(n[i]).forEach(a=>{t&&a.children[0].classList.add("animate-pulse")}),document.querySelectorAll(n.filter((a,s)=>s!=i).join(",")).forEach(a=>{a.children[0].classList.remove("animate-pulse"),a.children[1].classList.remove("animate-pulse")})}unfocusPlayButtons(){document.querySelectorAll('[id^="play-button-"]').forEach(e=>{e.children[0].classList.remove("fill-orange-300"),e.children[0].classList.remove("animate-pulse")})}updateEditorView(){this.view.dispatch({changes:{from:0,to:this.view.state.doc.toString().length,insert:this.currentFile().candidate}})}currentFile(){switch(this.editor_mode){case"global":return this.global_buffer;case"local":return this.local_buffer;case"init":return this.init_buffer;case"notes":return this.note_buffer}}flashBackground(e,t){const n=this.view.dom,i=n.getElementsByClassName("cm-gutter");n.classList.add("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.add("fluid-bg-transition")),n.style.backgroundColor=e,Array.from(i).forEach(a=>a.style.backgroundColor=e),setTimeout(()=>{n.style.backgroundColor="",Array.from(i).forEach(a=>a.style.backgroundColor=""),n.classList.remove("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.remove("fluid-bg-transition"))},t)}initializeElements(){for(const[e,t]of Object.entries(AM))this.interface[e]=document.getElementById(t)}initializeButtonGroups(){for(const[e,t]of Object.entries(IM))this.buttonElements[e]=t.map(n=>document.getElementById(n))}initializeHydra(){this.hydra_backend=new Hydra({canvas:this.interface.hydra_canvas,detectAudio:!1,enableStreamCapture:!1}),this.hydra=this.hydra_backend.synth}setCanvas(e){if(!e)return;const t=e.getContext("2d"),n=window.devicePixelRatio||1;e.width=window.innerWidth*n,e.height=window.innerHeight*n,t&&t.scale(n,n)}}let e5=new JG;jG(e5,window,!1); +`,"\r"," "],!1,!1),an=st(",",!1),H=st("|",!1),fe=Kn([["a","z"]],!1,!1),Ie=Kn([["a","z"],"_"],!1,!1),we=Kn([["a","z"],"_",["0","9"]],!1,!1),Je=st("<",!1),ye=st(">",!1),Ht=st("@",!1),lt=st(":",!1),yt=Kn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),zn=st("/",!1),dt=st("(",!1),Kt=st(")",!1),Tt=st("[:",!1),Ue=st("]",!1),Fn=st("[",!1),Fr=st("{",!1),ct=st("}",!1),Hn=st("+",!1),Nn=st("*",!1),Ii=st("%",!1),wn=st("^",!1),Wt=st("&",!1),Cr=st(">>",!1),ta=st("<<",!1),oi=st("_",!1),na=st("?",!1),cr=st("!",!1),li=st("r",!1),yr=Kn([["a","z"],["A","Z"],["0","9"]],!1,!1),jt=st("#",!1),ci=st("b",!1),ui=Kn([["a","z"],["A","Z"],["0","9"],"-","*","+"],!1,!1),q=Kn([["A","G"]],!1,!1),ie=Kn(["b","s"],!1,!1),de=st("iii",!1),_e=st("ii",!1),Ae=st("iv",!1),Qe=st("i",!1),Pe=st("vii",!1),Ct=st("vi",!1),Dn=st("v",!1),Wn=function(T){return T.filter(w=>w)},xa=function(){return parseFloat($n())},ra=function(){return parseInt($n())},xs=function(){return parseInt($n())},Xn=function(){},ks=function(T){return Ut(pG,{sound:T})},ka=function(){return $n()},La=function(T){return Ut(Io,{items:T})},Ls=function(T){return T},Ma=function(T,w){return Ut(fG,{item:T,sound:w})},Ms=function(T,w){return Ut(hG,{item:T,soundIndex:w})},Pa=function(T){return T},Yn=function(){return tG[$n()]},Ps=function(T,w){return T/w},Bs=function(T){return T.filter(w=>w)},Ba=function(T){return Ut(Io,{items:T})},Ua=function(T,w){return w?Ut(mT,{item:T,times:w}):Ut(gT,{items:T})},Us=function(T){return T},Fa=function(T,w,P){return Ut(OG,{left:T,operation:w,right:P})},Fs=function(T,w){return Ut(SG,{items:T,times:w})},Ya=function(T){return Ut(sR,{items:T})},Ys=function(T){return T.map(w=>typeof w=="number"?w:void 0)},$s=function(){return Math.ceil(iR($n()))},ur=function(T){var w=T.filter(P=>P).map(P=>Ut(ni,{pitch:P[0]},P.toString()));return Ut(gT,{items:w})},Ot=function(T){return T},Gs=function(T){return T},Ri=function(){},Qs=function(T){return Ut(Io,{items:T})},di=function(T){return Ut(gG,{octave:T})},qs=function(){return $n().split("").reduce((T,w)=>T+(w==="^"?1:-1),0)},Ni=function(){return Ut(Gc,{seededRandom:a.seededRandom})},$a=function(T,w){return Ut(Gc,{min:T,max:w,seededRandom:a.seededRandom})},Ga=function(T,w){return Ut(mT,{item:T,times:w})},Vs=function(T){return Ut(_G,{duration:T})},wi=function(T){return T},Qa=function(T){return Ut(Jm,{duration:T})},Di=function(T,w,P,X){const oe=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(ni,{duration:w,pitch:X,pitchOctave:oe,add:P})},xi=function(T){return T.reduce((w,P)=>w+(P==="#"?1:-1),0)},qa=function(T,w,P){return Ut(Na,{pitches:[T].concat(w),inversion:P})},ia=function(){return $n()},pi=function(T){return T},_n=function(){return $n()},Va=function(T,w,P,X,oe){const ve=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",ft=a.nodeOptions.key?a.nodeOptions.key:"C",fr=RG(X,P,ve,T,w),Ks=w||a.nodeOptions.duration,DR=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(Na,{duration:Ks,chordOctave:DR,pitches:fr,chordName:X,inversion:oe,scaleName:ve,key:ft})},Zn=function(T,w,P){const X=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",oe=a.nodeOptions.key?a.nodeOptions.key:"C";return Ut(mG,{roman:T,chordName:w,inversion:P,scaleName:X,key:oe})},aa=function(T){const w=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",P=a.nodeOptions.key?a.nodeOptions.key:"C",X=BG(T,P,w);return Ut(ni,{pitch:X.pc,add:X.add,scaleName:w,key:P})},A=0,He=0,za=[{line:1,column:1}],dr=0,zs=[],Oe=0,ge={},sa;if("startRule"in a){if(!(a.startRule in l))throw new Error(`Can't start parsing from rule "`+a.startRule+'".');c=l[a.startRule]}function $n(){return i.substring(He,A)}function dl(){return d(He,A)}function st(T,w){return{type:"literal",text:T,ignoreCase:w}}function Kn(T,w,P){return{type:"class",parts:T,inverted:w,ignoreCase:P}}function pl(){return{type:"end"}}function Hs(T){return{type:"other",description:T}}function fl(T){var w=za[T],P;if(w)return w;for(P=T-1;!za[P];)P--;for(w=za[P],w={line:w.line,column:w.column};Pdr&&(dr=A,zs=[]),zs.push(T))}function g(T,w,P){return new e(e.buildMessage(T,w),T,w,P)}function O(){var T,w,P=A*56+0,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Xt(),w!==s&&(He=T,w=Wn(w)),T=w,ge[P]={nextPos:A,result:T},T)}function C(){var T,w,P,X,oe,ve,ft,fr=A*56+1,Ks=ge[fr];if(Ks)return A=Ks.nextPos,Ks.result;for(T=A,w=A,i.charCodeAt(A)===45?(P=u,A++):(P=s,Oe===0&&f(rn)),P===s&&(P=null),X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));if(i.charCodeAt(A)===46?(oe=p,A++):(oe=s,Oe===0&&f(ke)),oe!==s){if(ve=[],Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze)),ft!==s)for(;ft!==s;)ve.push(ft),Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze));else ve=s;ve!==s?(P=[P,X,oe,ve],w=P):(A=w,w=s)}else A=w,w=s;if(w===s)if(w=A,i.charCodeAt(A)===46?(P=p,A++):(P=s,Oe===0&&f(ke)),P!==s){if(X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze)),oe!==s)for(;oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));else X=s;X!==s?(P=[P,X],w=P):(A=w,w=s)}else A=w,w=s;return w!==s&&(He=T,w=xa()),T=w,ge[fr]={nextPos:A,result:T},T}function y(){var T,w,P=A*56+2,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),Be.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Ze)),w!==s?(He=T,T=ra()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function D(){var T,w,P,X=A*56+3,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),w=[],Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze)),P!==s)for(;P!==s;)w.push(P),Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze));else w=s;return w!==s?(He=T,T=xs()):(A=T,T=s),ge[X]={nextPos:A,result:T},T}function F(){var T,w,P=A*56+4,X=ge[P];return X?(A=X.nextPos,X.result):(Oe++,T=A,tt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Zt)),w!==s&&(He=T,w=Xn()),T=w,Oe--,T===s&&(w=s,Oe===0&&f(en)),ge[P]={nextPos:A,result:T},T)}function U(){var T,w,P=A*56+8,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=W(),w!==s&&(He=T,w=ks(w)),T=w,ge[P]={nextPos:A,result:T},T)}function W(){var T,w,P,X,oe,ve=A*56+10,ft=ge[ve];if(ft)return A=ft.nextPos,ft.result;if(T=A,rt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(fe)),w!==s){if(P=[],ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie)),X!==s)for(;X!==s;)P.push(X),ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie));else P=s;if(P!==s){for(X=[],vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));oe!==s;)X.push(oe),vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));He=T,T=ka()}else A=T,T=s}else A=T,T=s;return ge[ve]={nextPos:A,result:T},T}function z(){var T,w=A*56+11,P=ge[w];return P?(A=P.nextPos,P.result):(T=pe(),T===s&&(T=he()),ge[w]={nextPos:A,result:T},T)}function pe(){var T,w,P,X,oe=A*56+12,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=z(),X!==s)for(;X!==s;)P.push(X),X=z();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=La(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function he(){var T,w=A*56+13,P=ge[w];return P?(A=P.nextPos,P.result):(T=W(),T===s&&(T=pe(),T===s&&(T=F())),ge[w]={nextPos:A,result:T},T)}function se(){var T,w,P,X=A*56+14,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===64?(w=R,A++):(w=s,Oe===0&&f(Ht)),w!==s?(P=z(),P!==s?(He=T,T=Ls(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function ae(){var T,w=A*56+15,P=ge[w];return P?(A=P.nextPos,P.result):(T=sn(),T===s&&(T=it(),T===s&&(T=qt(),T===s&&(T=du(),T===s&&(T=Qt())))),ge[w]={nextPos:A,result:T},T)}function Ce(){var T,w,P,X=A*56+16,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=ae(),w===s&&(w=Zs()),w!==s?(P=se(),P!==s?(He=T,T=Ma(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Se(){var T,w,P,X=A*56+17,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs())),w!==s?(P=Ve(),P!==s?(He=T,T=Ms(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Ve(){var T,w,P,X=A*56+18,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=wt(),P!==s?(He=T,T=Pa(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function je(){var T,w,P=A*56+19,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,mt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(yt)),w!==s&&(He=T,w=Yn()),T=w,ge[P]={nextPos:A,result:T},T)}function Fe(){var T,w=A*56+20,P=ge[w];return P?(A=P.nextPos,P.result):(T=It(),T===s&&(T=C(),T===s&&(T=je())),ge[w]={nextPos:A,result:T},T)}function It(){var T,w,P,X,oe=A*56+21,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=D(),w!==s?(i.charCodeAt(A)===47?(P=$,A++):(P=s,Oe===0&&f(zn)),P!==s?(X=D(),X!==s?(He=T,T=Ps(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xt(){var T,w,P,X=A*56+22,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du())))))))),P!==s)for(;P!==s;)w.push(P),P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du()))))))));else w=s;return w!==s&&(He=T,w=Bs(w)),T=w,ge[X]={nextPos:A,result:T},T}function wt(){var T,w=A*56+23,P=ge[w];return P?(A=P.nextPos,P.result):(T=F(),T===s&&(T=D(),T===s&&(T=R_(),T===s&&(T=fu(),T===s&&(T=tn(),T===s&&(T=A_()))))),ge[w]={nextPos:A,result:T},T)}function tn(){var T,w,P,X,oe=A*56+24,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=wt(),X!==s)for(;X!==s;)P.push(X),X=wt();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Ba(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function it(){var T,w,P,X,oe,ve=A*56+25,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(i.charCodeAt(A)===58?A++:Oe===0&&f(lt),P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===41?(oe=h,A++):(oe=s,Oe===0&&f(Kt)),oe!==s?(He=T,T=Ua(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function pt(){var T,w,P,X=A*56+26,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=D(),P!==s?(He=T,T=Us(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function sn(){var T,w,P,X,oe=A*56+27,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=it(),w!==s?(P=I_(),P!==s?(X=it(),X!==s?(He=T,T=Fa(w,P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Qt(){var T,w,P,X,oe,ve=A*56+28,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.substr(A,2)===b?(w=b,A+=2):(w=s,Oe===0&&f(Tt)),w!==s?(P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===93?(oe=S,A++):(oe=s,Oe===0&&f(Ue)),oe!==s?(He=T,T=Fs(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function qt(){var T,w,P,X,oe=A*56+29,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===91?(w=N,A++):(w=s,Oe===0&&f(Fn)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===93?(X=S,A++):(X=s,Oe===0&&f(Ue)),X!==s?(He=T,T=Ya(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function pr(){var T,w=A*56+30,P=ge[w];return P?(A=P.nextPos,P.result):(T=D(),T===s&&(T=y()),ge[w]={nextPos:A,result:T},T)}function Ws(){var T,w,P,X=A*56+31,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=hl(),P===s&&(P=pr()),P!==s)for(;P!==s;)w.push(P),P=hl(),P===s&&(P=pr());else w=s;return w!==s&&(He=T,w=Ys(w)),T=w,ge[X]={nextPos:A,result:T},T}function hl(){var T,w,P,X,oe=A*56+32,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===40?A++:Oe===0&&f(dt),w=pr(),w!==s?(P=I_(),P!==s?(X=Ws(),X!==s?(i.charCodeAt(A)===41?A++:Oe===0&&f(Kt),He=T,T=$s()):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xs(){var T,w,P,X,oe=A*56+33,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s){if(P=[],X=Ws(),X===s&&(X=F()),X!==s)for(;X!==s;)P.push(X),X=Ws(),X===s&&(X=F());else P=s;P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=ur(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function A_(){var T,w,P,X,oe=A*56+34,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s?(P=D(),P===s&&(P=fu()),P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=Ot(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function I_(){var T,w=A*56+35,P=ge[w];return P?(A=P.nextPos,P.result):(i.charCodeAt(A)===43?(T=M,A++):(T=s,Oe===0&&f(Hn)),T===s&&(i.charCodeAt(A)===45?(T=u,A++):(T=s,Oe===0&&f(rn)),T===s&&(i.charCodeAt(A)===42?(T=G,A++):(T=s,Oe===0&&f(Nn)),T===s&&(i.charCodeAt(A)===47?(T=$,A++):(T=s,Oe===0&&f(zn)),T===s&&(i.charCodeAt(A)===37?(T=te,A++):(T=s,Oe===0&&f(Ii)),T===s&&(i.charCodeAt(A)===94?(T=re,A++):(T=s,Oe===0&&f(wn)),T===s&&(i.charCodeAt(A)===124?(T=_,A++):(T=s,Oe===0&&f(H)),T===s&&(i.charCodeAt(A)===38?(T=ne,A++):(T=s,Oe===0&&f(Wt)),T===s&&(i.substr(A,2)===ee?(T=ee,A+=2):(T=s,Oe===0&&f(Cr)),T===s&&(i.substr(A,2)===B?(T=B,A+=2):(T=s,Oe===0&&f(ta))))))))))),ge[w]={nextPos:A,result:T},T)}function Zs(){var T,w,P=A*56+36,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=yR(),w===s&&(w=NR(),w===s&&(w=RR(),w===s&&(w=wR(),w===s&&(w=U(),w===s&&(w=IR(),w===s&&(w=ml(),w===s&&(w=vR(),w===s&&(w=F(),w===s&&(w=TR(),w===s&&(w=it(),w===s&&(w=Xs(),w===s&&(w=ER())))))))))))),w!==s&&(He=T,w=Gs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function ER(){var T,w,P=A*56+37,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===124?(w=_,A++):(w=s,Oe===0&&f(H)),w!==s&&(He=T,w=Ri()),T=w,ge[P]={nextPos:A,result:T},T)}function du(){var T,w,P,X,oe=A*56+38,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Qs(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function vR(){var T,w,P=A*56+39,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=pu(),w!==s&&(He=T,w=di(w)),T=w,ge[P]={nextPos:A,result:T},T)}function pu(){var T,w,P,X=A*56+40,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi)));else w=s;return w!==s&&(He=T,w=qs()),T=w,ge[X]={nextPos:A,result:T},T}function R_(){var T,w,P=A*56+41,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===63?(w=j,A++):(w=s,Oe===0&&f(na)),w!==s&&(He=T,w=Ni()),T=w,ge[P]={nextPos:A,result:T},T)}function fu(){var T,w,P,X,oe,ve,ft=A*56+42,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(P=D(),P!==s?(i.charCodeAt(A)===44?(X=m,A++):(X=s,Oe===0&&f(an)),X!==s?(oe=D(),oe!==s?(i.charCodeAt(A)===41?(ve=h,A++):(ve=s,Oe===0&&f(Kt)),ve!==s?(He=T,T=$a(P,oe)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function N_(){var T,w,P,X,oe=A*56+43,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=Se(),w===s&&(w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs()))),w!==s?(i.charCodeAt(A)===33?(P=K,A++):(P=s,Oe===0&&f(cr)),P!==s?(X=D(),X!==s?(He=T,T=Ga(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function TR(){var T,w,P=A*56+44,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Fe(),w!==s&&(He=T,w=Vs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function CR(){var T,w,P,X=A*56+45,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Fe(),w!==s?(i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P!==s?(He=T,T=wi(w)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function yR(){var T,w,P,X,oe,ve=A*56+46,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=CR(),w===s&&(w=null),i.charCodeAt(A)===114?(P=ue,A++):(P=s,Oe===0&&f(li)),P!==s?(X=A,Oe++,At.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(yr)),Oe--,oe===s?X=void 0:(A=X,X=s),X!==s?(He=T,T=Qa(w)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function ml(){var T,w,P,X,oe,ve=A*56+47,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=AR(),X===s&&(X=null),oe=y(),oe===s&&(oe=R_(),oe===s&&(oe=fu(),oe===s&&(oe=A_()))),oe!==s?(He=T,T=Di(w,P,X,oe)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function AR(){var T,w,P,X=A*56+48,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci)));else w=s;return w!==s&&(He=T,w=xi(w)),T=w,ge[X]={nextPos:A,result:T},T}function IR(){var T,w,P,X,oe=A*56+49,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,w=ml(),w!==s){if(P=[],X=ml(),X!==s)for(;X!==s;)P.push(X),X=ml();else P=s;P!==s?(X=hu(),X===s&&(X=null),He=T,T=qa(w,P,X)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function w_(){var T,w,P,X=A*56+50,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui)),P!==s)for(;P!==s;)w.push(P),Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui));else w=s;return w!==s&&(He=T,w=ia()),T=w,ge[X]={nextPos:A,result:T},T}function hu(){var T,w,P,X=A*56+51,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===37?(w=te,A++):(w=s,Oe===0&&f(Ii)),w!==s?(P=D(),P!==s?(He=T,T=pi(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function D_(){var T,w,P=A*56+52,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,Rn.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(q)),w!==s?(qe.test(i.charAt(A))?(i.charAt(A),A++):Oe===0&&f(ie),He=T,T=_n()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function RR(){var T,w,P,X,oe,ve,ft=A*56+53,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=D_(),X!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),oe=w_(),oe!==s?(ve=hu(),ve===s&&(ve=null),He=T,T=Va(w,P,X,oe,ve)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function NR(){var T,w,P,X,oe=A*56+54,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.substr(A,3)===De?(w=De,A+=3):(w=s,Oe===0&&f(de)),w===s&&(i.substr(A,2)===xe?(w=xe,A+=2):(w=s,Oe===0&&f(_e)),w===s&&(i.substr(A,2)===Ee?(w=Ee,A+=2):(w=s,Oe===0&&f(Ae)),w===s&&(i.charCodeAt(A)===105?(w=Ne,A++):(w=s,Oe===0&&f(Qe)),w===s&&(i.substr(A,3)===ce?(w=ce,A+=3):(w=s,Oe===0&&f(Pe)),w===s&&(i.substr(A,2)===Le?(w=Le,A+=2):(w=s,Oe===0&&f(Ct)),w===s&&(i.charCodeAt(A)===118?(w=Xe,A++):(w=s,Oe===0&&f(Dn)))))))),w!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),P=w_(),P===s&&(P=null),X=hu(),X===s&&(X=null),He=T,T=Zn(w,P,X)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function wR(){var T,w,P=A*56+55,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=D_(),w!==s&&(He=T,w=aa(w)),T=w,ge[P]={nextPos:A,result:T},T)}var x_=a.nodeOptions||{};function Ut(T,w,P=void 0){w.text=P||$n(),w.location=dl();for(var X in x_)(w[X]===void 0||w[X]===null)&&(w[X]=x_[X]);return new T(w)}if(sa=c(),sa!==s&&A===i.length)return sa;throw sa!==s&&Ae.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}sounds(){return this.evaluated.map(e=>e.collect("sound"))}indices(){return this.evaluated.map(e=>e.collect("soundIndex"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}octaves(){return this.evaluated.map(e=>e.collect("octave"))}retrograde(){return this.evaluated=this.evaluated.reverse(),this}scale(e){return this.applyOptions({scale:e}),this}key(e){return this.applyOptions({key:e}),this}octave(e){return this.applyOptions({octave:e}),this}invert(e){return this.applyOptions({inversion:e}),this}isInOptions(e,t){return this.options.nodeOptions&&this.options.nodeOptions[e]===t}atLast(){return this.index+1>=this.evaluated.length*this.redo}clone(){return ti(this)}notStarted(){return this.index<0}peek(){return this.evaluated[this.index-1||0]}hasStarted(){return this.index>=0}next(){this.index<0&&(this.index=0);const e=this.evaluated[this.index%this.evaluated.length];return this.index++,this.counter++,this.redo>0&&this.index>=this.evaluated.length*this.redo&&(this.index=0,this.evaluated=this.evaluate(this.values)),e}applyOptions(e={}){this.evaluated=this.evaluate(this.evaluated,e),this.applyTransformations()}applyTransformations(){var e;(e=this.globalOptions)!=null&&e.retrograde&&(this.evaluated=this.evaluated.reverse())}update(){return this.evaluated=this.evaluate(this.values),this.applyTransformations(),this}evaluate(e,t={}){let n=e.map(i=>i.evaluate(t)).flat(1/0).filter(i=>i!==void 0);return t.subdivisions&&(n=fR(n)),n}totalDuration(){return this.evaluated.reduce((t,n)=>t+n.collect("duration"),0)}lead(){let e=this.evaluated.findIndex(t=>t instanceof Na);if(e>=0){for(let t=e+1;t<=this.evaluated.length;t++)if(this.evaluated[t]instanceof Na){const n=this.evaluated[e],i=this.evaluated[t],a=FG(n.notes(),i.notes()),s=ti(i);s.voiceLeadFromNotes(a,this.options.nodeOptions),this.evaluated[t]=s,e=t}}return this}}const fR=(r,e=void 0)=>r.map(n=>{if(n instanceof sR){const i=n.evaluated.length,a=(e||n.duration)/i;return fR(n.evaluated,a)}else return n.duration=e||n.duration,n}).flat(1/0),GG=r=>{let e={};return dG.forEach(t=>{if(r[t]!==void 0){const n=r[t];e[t]=n,delete r[t]}}),e};class QG{constructor(e,t){E(this,"api");E(this,"settings");E(this,"midiAccess",null);E(this,"midiOutputs",[]);E(this,"currentOutputIndex",0);E(this,"scheduledNotes",{});E(this,"midiInputs",[]);E(this,"currentInputIndex");E(this,"bufferLength",512);E(this,"noteInputBuffer",[]);E(this,"ccInputBuffer",[]);E(this,"activeNotes",[]);E(this,"stickyNotes",[]);E(this,"lastNote");E(this,"lastCC",{});E(this,"lastNoteInChannel",{});E(this,"lastCCInChannel",{});E(this,"midiClockInputIndex");E(this,"midiClockInput");E(this,"lastTimestamp",0);E(this,"midiClockDelta",0);E(this,"lastBPM");E(this,"roundedBPM",0);E(this,"clockBuffer",[]);E(this,"clockBufferLength",24);E(this,"clockTicks",0);E(this,"clockErrorCount",0);E(this,"skipOnError",0);this.api=e,this.settings=t,this.lastBPM=e.bpm(),this.roundedBPM=this.lastBPM,this.initializeMidiAccess()}async initializeMidiAccess(){try{this.midiAccess=await navigator.requestMIDIAccess(),this.midiOutputs=Array.from(this.midiAccess.outputs.values()),this.midiOutputs.length===0&&(console.warn("No MIDI outputs available."),this.currentOutputIndex=-1),this.midiInputs=Array.from(this.midiAccess.inputs.values()),this.midiInputs.length===0?console.warn("No MIDI inputs available."):this.updateInputSelects()}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex0){const e=document.getElementById("midi-clock-input"),t=document.getElementById("default-midi-input");e.innerHTML="",t.innerHTML="";const n=document.createElement("option");n.value="-1",n.text="Internal",e.appendChild(n);const i=document.createElement("option");if(i.value="-1",i.text="None",t.appendChild(i),this.midiInputs.forEach((a,s)=>{const o=document.createElement("option");o.value=s.toString(),o.text=a.name||s.toString(),e.appendChild(o),t.appendChild(o.cloneNode(!0))}),this.settings.midi_clock_input){const a=this.getMidiInputIndex(this.settings.midi_clock_input);e.value=a.toString(),a>0&&(this.midiClockInput=this.midiInputs[a],this.registerMidiInputListener(a))}else e.value="-1";if(this.settings.default_midi_input){const a=this.getMidiInputIndex(this.settings.default_midi_input);t.value=a.toString(),a>0&&(this.currentInputIndex=a,this.registerMidiInputListener(a))}else t.value="-1";e.addEventListener("change",a=>{const s=a.target.value;if(s==="-1")this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=void 0,this.settings.midi_clock_input=void 0;else{const o=parseInt(s);this.midiClockInputIndex=o,this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=this.midiInputs[o],this.registerMidiInputListener(o),this.settings.midi_clock_input=this.midiClockInput.name||void 0}}),t.addEventListener("change",a=>{const s=a.target.value;s==="-1"?(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=void 0,this.settings.default_midi_input=void 0):(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=parseInt(s),this.registerMidiInputListener(this.currentInputIndex),this.settings.default_midi_input=this.midiInputs[this.currentInputIndex].name||void 0)})}}registerMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&!t.onmidimessage&&(t.onmidimessage=n=>{const i=n;if(t.name===this.settings.midi_clock_input&&(i.data[0]===248?this.skipOnError>0?this.skipOnError-=1:this.onMidiClock(n.timeStamp):i.data[0]===250?(console.log("MIDI start received"),this.api.stop(),this.api.play()):i.data[0]===252?(console.log("MIDI stop received"),this.api.pause()):i.data[0]===251?(console.log("MIDI continue received"),this.api.play()):i.data[0]===254&&console.log("MIDI active sensing received")),t.name===this.settings.default_midi_input){if(i.data[0]>=144&&i.data[0]<=159){const a=i.data[0]-144+1,s=i.data[1],o=i.data[2];this.lastNote={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.lastNoteInChannel[a]={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.settings.midi_channels_scripts&&this.api.script(a),this.pushToMidiInputBuffer({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.activeNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.removeFromStickyNotes(s,a)||this.stickyNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp})}if(i.data[0]>=128&&i.data[0]<=143){const a=i.data[0]-128+1,s=i.data[1];this.removeFromActiveNotes(s,a)}if(i.data[0]>=176&&i.data[0]<=191){const a=i.data[0]-176+1,s=i.data[1],o=i.data[2];this.lastCC[s]=o,this.lastCCInChannel[a]?this.lastCCInChannel[a][s]=o:(this.lastCCInChannel[a]={},this.lastCCInChannel[a][s]=o),this.pushToMidiCCBuffer({control:s,value:o,channel:a,timestamp:n.timeStamp})}}})}}removeFromActiveNotes(e,t){const n=this.activeNotes.findIndex(i=>i.note===e&&i.channel===t);n>=0&&this.activeNotes.splice(n,1)}removeFromStickyNotes(e,t){const n=this.stickyNotes.findIndex(i=>i.note===e&&i.channel===t);return n>=0?(this.stickyNotes.splice(n,1),!0):!1}stickyNotesFromChannel(e){return this.stickyNotes.filter(t=>t.channel===e)}activeNotesFromChannel(e){return this.activeNotes.filter(t=>t.channel===e)}killActiveNotes(){this.activeNotes=[]}killActiveNotesFromChannel(e){this.activeNotes=this.activeNotes.filter(t=>t.channel!==e)}pushToMidiInputBuffer(e){this.noteInputBuffer.push(e),this.noteInputBuffer.length>this.bufferLength&&this.noteInputBuffer.shift()}pushToMidiCCBuffer(e){this.ccInputBuffer.push(e),this.ccInputBuffer.length>this.bufferLength&&this.ccInputBuffer.shift()}findNoteFromBufferInChannel(e){const t=this.noteInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.noteInputBuffer[t];return this.noteInputBuffer.splice(t,1),n}else return}findCCFromBufferInChannel(e){const t=this.ccInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.ccInputBuffer[t];return this.ccInputBuffer.splice(t,1),n}else return}unregisterMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&(t.onmidimessage=null)}}onMidiClock(e){if(this.clockTicks+=1,this.lastTimestamp>0)if(this.lastTimestamp===e)this.clockErrorCount+=1;else if(this.clockErrorCount>0)console.log("Timestamp error count: ",this.clockErrorCount),console.log("Current timestamp: ",e),console.log("Last timestamp: ",this.lastTimestamp),console.log("Last delta: ",this.midiClockDelta),console.log("Current delta: ",e-this.lastTimestamp),console.log("BPMs",this.clockBuffer),this.clockErrorCount=0,this.skipOnError=this.settings.midi_clock_ppqn/4,e=0;else{this.midiClockDelta=e-this.lastTimestamp,this.lastBPM=60*(1e3/this.midiClockDelta/this.settings.midi_clock_ppqn),this.clockBuffer.push(this.lastBPM),this.clockBuffer.length>this.clockBufferLength&&this.clockBuffer.shift();const t=this.estimatedBPM();t!==this.roundedBPM&&(console.log("Estimated BPM: ",t),this.api.bpm(t),this.roundedBPM=t)}this.lastTimestamp=e}estimatedBPM(){const e=this.clockBuffer.reduce((t,n)=>t+n);return Math.round(e/this.clockBuffer.length)}sendMidiClock(){if(!this.midiClockInput){const e=this.midiOutputs[this.currentOutputIndex];e&&e.send([248])}}switchMidiOutput(e){const t=this.getMidiOutputIndex(e);return t!==-1?(this.currentOutputIndex=t,!0):!1}getMidiOutputIndex(e){if(typeof e=="number")return e<0||e>=this.midiOutputs.length?(console.error(`Invalid MIDI output index. Index must be in the range 0-${this.midiOutputs.length-1}.`),this.currentOutputIndex):e;{const t=this.midiOutputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}getMidiInputIndex(e){if(typeof e=="number")return e<0||e>=this.midiInputs.length?(console.error(`Invalid MIDI input index. Index must be in the range 0-${this.midiInputs.length-1}.`),-1):e;{const t=this.midiInputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI input "${e}" not found.`),-1)}}listMidiOutputs(){let e="Available MIDI Outputs: ";return this.midiOutputs.forEach((t,n)=>{e+=`(${n+1}) ${t.name} `}),e}sendMidiNote(e,t,n,i,a=this.currentOutputIndex,s=void 0){typeof a=="string"&&(a=this.getMidiOutputIndex(a));const o=this.midiOutputs[a];if(e=Math.min(Math.max(e,0),127),o){const l=[144+t,e,n],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const u=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=u}else console.error("MIDI output not available.")}sendMidiOn(e,t,n,i=this.currentOutputIndex){typeof i=="string"&&(i=this.getMidiOutputIndex(i));const a=this.midiOutputs[i];if(e=Math.min(Math.max(e,0),127),a){const s=[144+t,e,n];a.send(s)}else console.error("MIDI output not available.")}sendMidiOff(e,t,n=this.currentOutputIndex){typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(e=Math.min(Math.max(e,0),127),i){const a=[128+t,e,0];i.send(a)}else console.error("MIDI output not available.")}sendAllNotesOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,123,0];n.send(i)}else console.error("MIDI output not available.")}sendAllSoundOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,120,0];n.send(i)}else console.error("MIDI output not available.")}sendSysExMessage(e){const t=this.midiOutputs[this.currentOutputIndex];t?t.send(e):console.error("MIDI output not available.")}sendPitchBend(e,t,n=this.currentOutputIndex){(e<0||e>16383)&&console.error("Invalid pitch bend value. Value must be in the range 0-16383."),(t<0||t>15)&&console.error("Invalid MIDI channel. Channel must be in the range 0-15."),typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(i){const a=e&127,s=e>>7&127;i.send([224|t,a,s])}else console.error("MIDI output not available.")}sendProgramChange(e,t){const n=this.midiOutputs[this.currentOutputIndex];n?n.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,n){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+n,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const n=this.scheduledNotes[t];clearTimeout(n),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class qG{constructor(e,t,n){E(this,"min");E(this,"max");E(this,"wrap");E(this,"position");this.min=e,this.max=t,this.wrap=n,this.position=0}step(){const e=Math.floor(Math.random()*3)-1;this.position+=e,this.wrap?this.position>this.max?this.position=this.min:this.positionthis.max&&(this.position=this.max)}getPosition(){return this.position}toggleWrap(e){this.wrap=e}}class C_{constructor(e){E(this,"seedValue");E(this,"randomGen",Math.random);E(this,"app");E(this,"values",{});E(this,"evenbar",e=>this.app.clock.time_position.bar%2===0?this.modify(e):this);E(this,"even",e=>this.app.clock.time_position.beat%2===0?this.modify(e):this);E(this,"odd",e=>this.app.clock.time_position.beat%2!==0?this.modify(e):this);E(this,"odds",(e,t)=>this.randomGen()this);E(this,"almostNever",e=>this.odds(.025,e));E(this,"rarely",e=>this.odds(.1,e));E(this,"scarcely",e=>this.odds(.25,e));E(this,"sometimes",e=>this.odds(.5,e));E(this,"often",e=>this.odds(.75,e));E(this,"frequently",e=>this.odds(.9,e));E(this,"almostAlways",e=>this.odds(.985,e));E(this,"always",e=>this.modify(e));E(this,"modify",e=>e(this));E(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));E(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));E(this,"apply",e=>this.modify(e));E(this,"length",e=>(this.values.length=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class hR extends C_{constructor(t){super(t);E(this,"octave",t=>(this.values.octave=t,this.update(),this));E(this,"key",t=>(this.values.key=t,this.update(),this));E(this,"scale",t=>(b_(t)?(this.values.scaleName=t,this.values.parsedScale=vi(t)):this.values.parsedScale=E_(t),this.update(),this));E(this,"freq",t=>{this.values.freq=t;const n=bG(t);return n%1!==0?(this.values.note=Math.floor(n),this.values.bend=oR(n)[1]):this.values.note=n,this});E(this,"update",()=>{})}}class tg extends hR{constructor(t,n){super(n);E(this,"nudge");E(this,"volume",t=>this.updateValue("volume",t));E(this,"vol",this.volume);E(this,"zrand",t=>this.updateValue("zrand",t));E(this,"curve",t=>this.updateValue("curve",t));E(this,"slide",t=>this.updateValue("slide",t));E(this,"sld",this.slide);E(this,"deltaSlide",t=>this.updateValue("deltaSlide",t));E(this,"dslide",this.deltaSlide);E(this,"pitchJump",t=>this.updateValue("pitchJump",t));E(this,"pj",this.pitchJump);E(this,"pitchJumpTime",t=>this.updateValue("pitchJumpTime",t));E(this,"pjt",this.pitchJumpTime);E(this,"lfo",t=>this.updateValue("lfo",t));E(this,"znoise",t=>this.updateValue("znoise",t));E(this,"noise",t=>this.updateValue("noise",t));E(this,"zmod",t=>this.updateValue("zmod",t));E(this,"zcrush",t=>this.updateValue("zcrush",t));E(this,"zdelay",t=>this.updateValue("zdelay",t));E(this,"sustainVolume",t=>this.updateValue("sustainVolume",t));E(this,"tremolo",t=>this.updateValue("tremolo",t));E(this,"dur",t=>this.updateValue("dur",t));E(this,"zzfx",t=>this.updateValue("zzfx",t));E(this,"fmi",t=>this.updateValue("fmi",t));E(this,"fmh",t=>this.updateValue("fmh",t));E(this,"fmenv",t=>this.updateValue("fmenv",t));E(this,"fmattack",t=>this.updateValue("fmattack",t));E(this,"fmatk",this.fmattack);E(this,"fmdecay",t=>this.updateValue("fmdecay",t));E(this,"fmdec",this.fmdecay);E(this,"fmsustain",t=>this.updateValue("fmsustain",t));E(this,"fmsus",this.fmsustain);E(this,"fmrelease",t=>this.updateValue("fmrelease",t));E(this,"fmrel",this.fmrelease);E(this,"fmvelocity",t=>this.updateValue("fmvelocity",t));E(this,"fmvel",this.fmvelocity);E(this,"fmwave",t=>this.updateValue("fmwave",t));E(this,"fmw",this.fmwave);E(this,"ftype",t=>this.updateValue("ftype",t));E(this,"fanchor",t=>this.updateValue("fanchor",t));E(this,"attack",t=>this.updateValue("attack",t));E(this,"atk",this.attack);E(this,"decay",t=>this.updateValue("decay",t));E(this,"dec",this.decay);E(this,"sustain",t=>this.updateValue("sustain",t));E(this,"sus",this.sustain);E(this,"release",t=>this.updateValue("release",t));E(this,"rel",this.release);E(this,"adsr",(t,n,i,a)=>(this.attack(t),this.decay(n),this.sustain(i),this.release(a),this));E(this,"ad",(t,n)=>(this.attack(t),this.decay(n),this.sustain(0),this.release(0),this));E(this,"lpenv",t=>this.updateValue("lpenv",t));E(this,"lpe",t=>this.updateValue("lpenv",t));E(this,"lpattack",t=>this.updateValue("lpattack",t));E(this,"lpa",this.lpattack);E(this,"lpdecay",t=>this.updateValue("lpdecay",t));E(this,"lpd",this.lpdecay);E(this,"lpsustain",t=>this.updateValue("lpsustain",t));E(this,"lps",this.lpsustain);E(this,"lprelease",t=>this.updateValue("lprelease",t));E(this,"lpr",this.lprelease);E(this,"cutoff",t=>this.updateValue("cutoff",t));E(this,"lpf",this.cutoff);E(this,"resonance",t=>this.updateValue("resonance",Math.min(Math.max(t,0),50)));E(this,"lpq",this.resonance);E(this,"lpadsr",(t,n,i,a,s)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(a),this.lprelease(s),this));E(this,"lpad",(t,n,i)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this));E(this,"hpenv",t=>this.updateValue("hpenv",t));E(this,"hpe",t=>this.updateValue("hpe",t));E(this,"hpattack",t=>this.updateValue("hpattack",t));E(this,"hpa",this.hpattack);E(this,"hpdecay",t=>this.updateValue("hpdecay",t));E(this,"hpd",this.hpdecay);E(this,"hpsustain",t=>this.updateValue("hpsustain",t));E(this,"hpsus",this.hpsustain);E(this,"hprelease",t=>this.updateValue("hprelease",t));E(this,"hpr",this.hprelease);E(this,"hcutoff",t=>this.updateValue("hcutoff",t));E(this,"hpf",this.hcutoff);E(this,"hresonance",t=>this.updateValue("hresonance",t));E(this,"hpq",this.hresonance);E(this,"hpadsr",(t,n,i,a,s)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(a),this.hprelease(s),this));E(this,"hpad",(t,n,i)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this));E(this,"bpenv",t=>this.updateValue("bpenv",t));E(this,"bpe",t=>this.updateValue("bpe",t));E(this,"bpattack",t=>this.updateValue("bpattack",t));E(this,"bpa",this.bpattack);E(this,"bpdecay",t=>this.updateValue("bpdecay",t));E(this,"bpd",this.bpdecay);E(this,"bpsustain",t=>this.updateValue("bpsustain",t));E(this,"bps",this.bpsustain);E(this,"bprelease",t=>this.updateValue("bprelease",t));E(this,"bpr",this.bprelease);E(this,"bandf",t=>this.updateValue("bandf",t));E(this,"bpf",this.bandf);E(this,"bandq",t=>this.updateValue("bandq",t));E(this,"bpq",this.bandq);E(this,"bpadsr",(t,n,i,a,s)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(a),this.bprelease(s),this));E(this,"bpad",(t,n,i)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this));E(this,"freq",t=>this.updateValue("freq",t));E(this,"f",this.freq);E(this,"vib",t=>this.updateValue("vib",t));E(this,"vibmod",t=>this.updateValue("vibmod",t));E(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let n=t.split(":");this.values.fmi=parseFloat(n[0]),n.length>1&&(this.values.fmh=parseFloat(n[1]))}return this});E(this,"loop",t=>this.updateValue("loop",t));E(this,"loopBegin",t=>this.updateValue("loopBegin",t));E(this,"loopEnd",t=>this.updateValue("loopEnd",t));E(this,"begin",t=>this.updateValue("begin",t));E(this,"end",t=>this.updateValue("end",t));E(this,"gain",t=>this.updateValue("gain",t));E(this,"dbgain",t=>this.updateValue("gain",Math.min(Math.pow(10,t/20),10)));E(this,"db",this.dbgain);E(this,"velocity",t=>this.updateValue("velocity",t));E(this,"vel",this.velocity);E(this,"pan",t=>this.updateValue("pan",t));E(this,"sound",t=>this.updateValue("s",t));E(this,"chord",(t,...n)=>(typeof t=="string"?t=xG(t).map(a=>({note:a,freq:Zr(a)})):t instanceof Array&&typeof t[0]=="number"?t=t.map(i=>({note:i,freq:Zr(i)})):typeof t=="number"&&n.length>0&&(t=[t,...n].map(i=>({note:i,freq:Zr(i)}))),this.updateValue("chord",t)));E(this,"invert",(t=0)=>{if(this.values.chord){let n=this.values.chord.map(a=>a.note);n=t<0?[...n].reverse():n;for(let a=0;a({note:a,freq:Zr(a)}));return this.updateValue("chord",i)}else return this});E(this,"snd",this.sound);E(this,"cut",t=>this.updateValue("cut",t));E(this,"clip",t=>this.updateValue("clip",t));E(this,"n",t=>this.updateValue("n",t));E(this,"note",t=>typeof t=="string"?this.updateValue("note",Ur(t)):typeof t==null||t==null?this.updateValue("note",0).updateValue("gain",0):this.updateValue("note",t));E(this,"speed",t=>this.updateValue("speed",t));E(this,"spd",this.speed);E(this,"coarse",t=>this.updateValue("coarse",t));E(this,"crush",t=>this.updateValue("crush",t));E(this,"shape",t=>this.updateValue("shape",t));E(this,"vowel",t=>this.updateValue("vowel",t));E(this,"vow",this.vowel);E(this,"delay",t=>this.updateValue("delay",t));E(this,"del",this.delay);E(this,"delayfeedback",t=>this.updateValue("delayfeedback",t));E(this,"delayfb",this.delayfeedback);E(this,"delaytime",t=>this.updateValue("delaytime",t));E(this,"delayt",this.delaytime);E(this,"orbit",t=>this.updateValue("orbit",t));E(this,"o",this.orbit);E(this,"room",t=>this.updateValue("room",t));E(this,"rm",this.room);E(this,"roomfade",t=>this.updateValue("roomfade",t));E(this,"rfade",this.roomfade);E(this,"roomlp",t=>this.updateValue("roomlp",t));E(this,"rlp",this.roomlp);E(this,"roomdim",t=>this.updateValue("roomdim",t));E(this,"rdim",this.roomdim);E(this,"size",t=>this.updateValue("roomsize",t));E(this,"sz",this.size);E(this,"comp",t=>this.updateValue("compressor",t));E(this,"cmp",this.comp);E(this,"ratio",t=>this.updateValue("compressorRatio",t));E(this,"rt",this.ratio);E(this,"knee",t=>this.updateValue("compressorKnee",t));E(this,"kn",this.knee);E(this,"compAttack",t=>this.updateValue("compressorAttack",t));E(this,"cmpa",this.compAttack);E(this,"compRelease",t=>this.updateValue("compressorRelease",t));E(this,"cmpr",this.compRelease);E(this,"stretch",t=>(this.updateValue("unit","c"),this.updateValue("speed",1/t),this.updateValue("cut",t),this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.freq=Zr(t)});E(this,"out",()=>{this.values.chord?this.values.chord.forEach(t=>{const n={...this.values};n.freq=t.freq,P_(n,this.nudge,this.values.dur)}):P_(this.values,this.nudge,this.values.dur)});this.app=n,this.nudge=n.dough_nudge/100,typeof t=="string"?t.includes(":")?this.values={s:t.split(":")[0],n:t.split(":")[1],dur:n.clock.convertPulseToSecond(n.clock.ppqn),analyze:!0}:this.values={s:t,dur:.5,analyze:!0}:this.values=t}updateValue(t,n){return this.values[t]=n,this}}class ng extends hR{constructor(t,n){super(n);E(this,"midiConnection");E(this,"chord",t=>(this.values.chord=t,this));E(this,"note",t=>(this.values.note=t,this));E(this,"sustain",t=>(this.values.sustain=t,this));E(this,"channel",t=>(this.values.channel=t,this));E(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));E(this,"add",t=>(this.values.note+=t,this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"bend",t=>(this.values.bend=t,this));E(this,"random",(t=0,n=127)=>(t=Math.min(Math.max(t,0),127),n=Math.min(Math.max(n,0),127),this.values.note=Math.floor(this.randomGen()*(n-t+1))+t,this));E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.note=t,this.values.freq=Zr(t),n&&(this.values.bend=n)});E(this,"out",()=>{function t(n,i){const a=i&&i.channel?i.channel:0,s=n.values.channel?n.values.channel:a,o=n.values.velocity?n.values.velocity:100,l=i&&i.note?i.note:60,c=n.values.note?n.values.note:l,u=n.values.sustain?n.values.sustain*n.app.clock.pulse_duration*n.app.api.ppqn():n.app.clock.pulse_duration*n.app.api.ppqn(),p=n.values.bend?n.values.bend:void 0,m=n.values.port?n.midiConnection.getMidiOutputIndex(n.values.port):n.midiConnection.getCurrentMidiPortIndex();n.midiConnection.sendMidiNote(c,s,o,u,m,p)}this.values.chord?this.values.chord.forEach(n=>{t(this,n)}):t(this)});this.app=n,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=n.api.MidiConnection}}const po=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mR=new Set,rg=typeof process=="object"&&process?process:{},gR=(r,e,t,n)=>{typeof rg.emitWarning=="function"?rg.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)};let Qc=globalThis.AbortController,_T=globalThis.AbortSignal;var OT;if(typeof Qc>"u"){_T=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",!1)}addEventListener(n,i){this._onabort.push(i)}},Qc=class{constructor(){E(this,"signal",new _T);e()}abort(n){var i,a;if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(const s of this.signal._onabort)s(n);(a=(i=this.signal).onabort)==null||a.call(i,n)}}};let r=((OT=rg.env)==null?void 0:OT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{r&&(r=!1,gR("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const VG=r=>!mR.has(r),Bi=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),_R=r=>Bi(r)?r<=Math.pow(2,8)?Uint8Array:r<=Math.pow(2,16)?Uint16Array:r<=Math.pow(2,32)?Uint32Array:r<=Number.MAX_SAFE_INTEGER?rc:null:null;class rc extends Array{constructor(e){super(e),this.fill(0)}}var cs;const fa=class fa{constructor(e,t){E(this,"heap");E(this,"length");if(!V(fa,cs))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=_R(e);if(!t)return[];We(fa,cs,!0);const n=new fa(e,t);return We(fa,cs,!1),n}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};cs=new WeakMap,at(fa,cs,!1);let ig=fa;var Rr,er,Nr,wr,us,on,Dr,ln,Lt,nt,Ln,tr,Cn,hn,xr,mn,gi,_i,kr,Lr,qi,Mn,jo,sg,Oa,Si,Jo,nr,zc,SR,ba,ds,el,qr,Ui,Vr,Fi,tl,og,ps,ic,fs,ac,Dt,Ft,nl,lg,Ea,bo;const y_=class y_{constructor(e){at(this,jo);at(this,zc);at(this,qr);at(this,Vr);at(this,tl);at(this,ps);at(this,fs);at(this,Dt);at(this,nl);at(this,Ea);at(this,Rr,void 0);at(this,er,void 0);at(this,Nr,void 0);at(this,wr,void 0);at(this,us,void 0);E(this,"ttl");E(this,"ttlResolution");E(this,"ttlAutopurge");E(this,"updateAgeOnGet");E(this,"updateAgeOnHas");E(this,"allowStale");E(this,"noDisposeOnSet");E(this,"noUpdateTTL");E(this,"maxEntrySize");E(this,"sizeCalculation");E(this,"noDeleteOnFetchRejection");E(this,"noDeleteOnStaleGet");E(this,"allowStaleOnFetchAbort");E(this,"allowStaleOnFetchRejection");E(this,"ignoreFetchAbort");at(this,on,void 0);at(this,Dr,void 0);at(this,ln,void 0);at(this,Lt,void 0);at(this,nt,void 0);at(this,Ln,void 0);at(this,tr,void 0);at(this,Cn,void 0);at(this,hn,void 0);at(this,xr,void 0);at(this,mn,void 0);at(this,gi,void 0);at(this,_i,void 0);at(this,kr,void 0);at(this,Lr,void 0);at(this,qi,void 0);at(this,Mn,void 0);at(this,Oa,()=>{});at(this,Si,()=>{});at(this,Jo,()=>{});at(this,nr,()=>!1);at(this,ba,e=>{});at(this,ds,(e,t,n)=>{});at(this,el,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:m,maxSize:_=0,maxEntrySize:v=0,sizeCalculation:I,fetchMethod:R,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:$,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:h,ignoreFetchAbort:b}=e;if(t!==0&&!Bi(t))throw new TypeError("max option must be a nonnegative integer");const S=t?_R(t):Array;if(!S)throw new Error("invalid max value: "+t);if(We(this,Rr,t),We(this,er,_),this.maxEntrySize=v||V(this,er),this.sizeCalculation=I,this.sizeCalculation){if(!V(this,er)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(R!==void 0&&typeof R!="function")throw new TypeError("fetchMethod must be a function if specified");if(We(this,us,R),We(this,qi,!!R),We(this,ln,new Map),We(this,Lt,new Array(t).fill(void 0)),We(this,nt,new Array(t).fill(void 0)),We(this,Ln,new S(t)),We(this,tr,new S(t)),We(this,Cn,0),We(this,hn,0),We(this,xr,ig.create(t)),We(this,on,0),We(this,Dr,0),typeof c=="function"&&We(this,Nr,c),typeof u=="function"?(We(this,wr,u),We(this,mn,[])):(We(this,wr,void 0),We(this,mn,void 0)),We(this,Lr,!!V(this,Nr)),We(this,Mn,!!V(this,wr)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!h,this.ignoreFetchAbort=!!b,this.maxEntrySize!==0){if(V(this,er)!==0&&!Bi(V(this,er)))throw new TypeError("maxSize must be a positive integer if specified");if(!Bi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");ze(this,zc,SR).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!$,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Bi(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!Bi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");ze(this,jo,sg).call(this)}if(V(this,Rr)===0&&this.ttl===0&&V(this,er)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!V(this,Rr)&&!V(this,er)){const N="LRU_CACHE_UNBOUNDED";VG(N)&&(mR.add(N),gR("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",N,y_))}}static unsafeExposeInternals(e){return{starts:V(e,_i),ttls:V(e,kr),sizes:V(e,gi),keyMap:V(e,ln),keyList:V(e,Lt),valList:V(e,nt),next:V(e,Ln),prev:V(e,tr),get head(){return V(e,Cn)},get tail(){return V(e,hn)},free:V(e,xr),isBackgroundFetch:t=>{var n;return ze(n=e,Dt,Ft).call(n,t)},backgroundFetch:(t,n,i,a)=>{var s;return ze(s=e,fs,ac).call(s,t,n,i,a)},moveToTail:t=>{var n;return ze(n=e,Ea,bo).call(n,t)},indexes:t=>{var n;return ze(n=e,qr,Ui).call(n,t)},rindexes:t=>{var n;return ze(n=e,Vr,Fi).call(n,t)},isStale:t=>{var n;return V(n=e,nr).call(n,t)}}}get max(){return V(this,Rr)}get maxSize(){return V(this,er)}get calculatedSize(){return V(this,Dr)}get size(){return V(this,on)}get fetchMethod(){return V(this,us)}get dispose(){return V(this,Nr)}get disposeAfter(){return V(this,wr)}getRemainingTTL(e){return V(this,ln).has(e)?1/0:0}*entries(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*rentries(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*keys(){for(const e of ze(this,qr,Ui).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*rkeys(){for(const e of ze(this,Vr,Fi).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*values(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}*rvalues(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,V(this,Lt)[n],this))return this.get(V(this,Lt)[n],t)}}forEach(e,t=this){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}rforEach(e,t=this){for(const n of ze(this,Vr,Fi).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}purgeStale(){let e=!1;for(const t of ze(this,Vr,Fi).call(this,{allowStale:!0}))V(this,nr).call(this,t)&&(this.delete(V(this,Lt)[t]),e=!0);return e}dump(){const e=[];for(const t of ze(this,qr,Ui).call(this,{allowStale:!0})){const n=V(this,Lt)[t],i=V(this,nt)[t],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;const s={value:a};if(V(this,kr)&&V(this,_i)){s.ttl=V(this,kr)[t];const o=po.now()-V(this,_i)[t];s.start=Math.floor(Date.now()-o)}V(this,gi)&&(s.size=V(this,gi)[t]),e.unshift([n,s])}return e}load(e){this.clear();for(const[t,n]of e){if(n.start){const i=Date.now()-n.start;n.start=po.now()-i}this.set(t,n.value,n)}}set(e,t,n={}){var m,_,v,I,R;if(t===void 0)return this.delete(e),this;const{ttl:i=this.ttl,start:a,noDisposeOnSet:s=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:l}=n;let{noUpdateTTL:c=this.noUpdateTTL}=n;const u=V(this,el).call(this,e,t,n.size||0,o);if(this.maxEntrySize&&u>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=V(this,on)===0?void 0:V(this,ln).get(e);if(p===void 0)p=V(this,on)===0?V(this,hn):V(this,xr).length!==0?V(this,xr).pop():V(this,on)===V(this,Rr)?ze(this,ps,ic).call(this,!1):V(this,on),V(this,Lt)[p]=e,V(this,nt)[p]=t,V(this,ln).set(e,p),V(this,Ln)[V(this,hn)]=p,V(this,tr)[p]=V(this,hn),We(this,hn,p),gl(this,on)._++,V(this,ds).call(this,p,u,l),l&&(l.set="add"),c=!1;else{ze(this,Ea,bo).call(this,p);const x=V(this,nt)[p];if(t!==x){if(V(this,qi)&&ze(this,Dt,Ft).call(this,x)){x.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:$}=x;$!==void 0&&!s&&(V(this,Lr)&&((m=V(this,Nr))==null||m.call(this,$,e,"set")),V(this,Mn)&&((_=V(this,mn))==null||_.push([$,e,"set"])))}else s||(V(this,Lr)&&((v=V(this,Nr))==null||v.call(this,x,e,"set")),V(this,Mn)&&((I=V(this,mn))==null||I.push([x,e,"set"])));if(V(this,ba).call(this,p),V(this,ds).call(this,p,u,l),V(this,nt)[p]=t,l){l.set="replace";const $=x&&ze(this,Dt,Ft).call(this,x)?x.__staleWhileFetching:x;$!==void 0&&(l.oldValue=$)}}else l&&(l.set="update")}if(i!==0&&!V(this,kr)&&ze(this,jo,sg).call(this),V(this,kr)&&(c||V(this,Jo).call(this,p,i,a),l&&V(this,Si).call(this,l,p)),!s&&V(this,Mn)&&V(this,mn)){const x=V(this,mn);let $;for(;$=x==null?void 0:x.shift();)(R=V(this,wr))==null||R.call(this,...$)}return this}pop(){var e;try{for(;V(this,on);){const t=V(this,nt)[V(this,Cn)];if(ze(this,ps,ic).call(this,!0),ze(this,Dt,Ft).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(V(this,Mn)&&V(this,mn)){const t=V(this,mn);let n;for(;n=t==null?void 0:t.shift();)(e=V(this,wr))==null||e.call(this,...n)}}}has(e,t={}){const{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=V(this,ln).get(e);if(a!==void 0){const s=V(this,nt)[a];if(ze(this,Dt,Ft).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if(V(this,nr).call(this,a))i&&(i.has="stale",V(this,Si).call(this,i,a));else return n&&V(this,Oa).call(this,a),i&&(i.has="hit",V(this,Si).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:n=this.allowStale}=t,i=V(this,ln).get(e);if(i!==void 0&&(n||!V(this,nr).call(this,i))){const a=V(this,nt)[i];return ze(this,Dt,Ft).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:l=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:_=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:I,forceRefresh:R=!1,status:x,signal:$}=t;if(!V(this,qi))return x&&(x.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:x});const Z={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:u,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:v,ignoreFetchAbort:_,status:x,signal:$};let h=V(this,ln).get(e);if(h===void 0){x&&(x.fetch="miss");const b=ze(this,fs,ac).call(this,e,h,Z,I);return b.__returned=b}else{const b=V(this,nt)[h];if(ze(this,Dt,Ft).call(this,b)){const M=n&&b.__staleWhileFetching!==void 0;return x&&(x.fetch="inflight",M&&(x.returnedStale=!0)),M?b.__staleWhileFetching:b.__returned=b}const S=V(this,nr).call(this,h);if(!R&&!S)return x&&(x.fetch="hit"),ze(this,Ea,bo).call(this,h),i&&V(this,Oa).call(this,h),x&&V(this,Si).call(this,x,h),b;const N=ze(this,fs,ac).call(this,e,h,Z,I),L=N.__staleWhileFetching!==void 0&&n;return x&&(x.fetch=S?"stale":"refresh",L&&S&&(x.returnedStale=!0)),L?N.__staleWhileFetching:N.__returned=N}}get(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=V(this,ln).get(e);if(o!==void 0){const l=V(this,nt)[o],c=ze(this,Dt,Ft).call(this,l);return s&&V(this,Si).call(this,s,o),V(this,nr).call(this,o)?(s&&(s.get="stale"),c?(s&&n&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),n?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&n&&(s.returnedStale=!0),n?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:(ze(this,Ea,bo).call(this,o),i&&V(this,Oa).call(this,o),l))}else s&&(s.get="miss")}delete(e){var n,i,a,s;let t=!1;if(V(this,on)!==0){const o=V(this,ln).get(e);if(o!==void 0)if(t=!0,V(this,on)===1)this.clear();else{V(this,ba).call(this,o);const l=V(this,nt)[o];ze(this,Dt,Ft).call(this,l)?l.__abortController.abort(new Error("deleted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((n=V(this,Nr))==null||n.call(this,l,e,"delete")),V(this,Mn)&&((i=V(this,mn))==null||i.push([l,e,"delete"]))),V(this,ln).delete(e),V(this,Lt)[o]=void 0,V(this,nt)[o]=void 0,o===V(this,hn)?We(this,hn,V(this,tr)[o]):o===V(this,Cn)?We(this,Cn,V(this,Ln)[o]):(V(this,Ln)[V(this,tr)[o]]=V(this,Ln)[o],V(this,tr)[V(this,Ln)[o]]=V(this,tr)[o]),gl(this,on)._--,V(this,xr).push(o)}}if(V(this,Mn)&&((a=V(this,mn))!=null&&a.length)){const o=V(this,mn);let l;for(;l=o==null?void 0:o.shift();)(s=V(this,wr))==null||s.call(this,...l)}return t}clear(){var e,t,n;for(const i of ze(this,Vr,Fi).call(this,{allowStale:!0})){const a=V(this,nt)[i];if(ze(this,Dt,Ft).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=V(this,Lt)[i];V(this,Lr)&&((e=V(this,Nr))==null||e.call(this,a,s,"delete")),V(this,Mn)&&((t=V(this,mn))==null||t.push([a,s,"delete"]))}}if(V(this,ln).clear(),V(this,nt).fill(void 0),V(this,Lt).fill(void 0),V(this,kr)&&V(this,_i)&&(V(this,kr).fill(0),V(this,_i).fill(0)),V(this,gi)&&V(this,gi).fill(0),We(this,Cn,0),We(this,hn,0),V(this,xr).length=0,We(this,Dr,0),We(this,on,0),V(this,Mn)&&V(this,mn)){const i=V(this,mn);let a;for(;a=i==null?void 0:i.shift();)(n=V(this,wr))==null||n.call(this,...a)}}};Rr=new WeakMap,er=new WeakMap,Nr=new WeakMap,wr=new WeakMap,us=new WeakMap,on=new WeakMap,Dr=new WeakMap,ln=new WeakMap,Lt=new WeakMap,nt=new WeakMap,Ln=new WeakMap,tr=new WeakMap,Cn=new WeakMap,hn=new WeakMap,xr=new WeakMap,mn=new WeakMap,gi=new WeakMap,_i=new WeakMap,kr=new WeakMap,Lr=new WeakMap,qi=new WeakMap,Mn=new WeakMap,jo=new WeakSet,sg=function(){const e=new rc(V(this,Rr)),t=new rc(V(this,Rr));We(this,kr,e),We(this,_i,t),We(this,Jo,(a,s,o=po.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{V(this,nr).call(this,a)&&this.delete(V(this,Lt)[a])},s+1);l.unref&&l.unref()}}),We(this,Oa,a=>{t[a]=e[a]!==0?po.now():0}),We(this,Si,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=n||i();const c=a.now-l;a.remainingTTL=o-c}});let n=0;const i=()=>{const a=po.now();if(this.ttlResolution>0){n=a;const s=setTimeout(()=>n=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=V(this,ln).get(a);if(s===void 0)return 0;const o=e[s],l=t[s];if(o===0||l===0)return 1/0;const c=(n||i())-l;return o-c},We(this,nr,a=>e[a]!==0&&t[a]!==0&&(n||i())-t[a]>e[a])},Oa=new WeakMap,Si=new WeakMap,Jo=new WeakMap,nr=new WeakMap,zc=new WeakSet,SR=function(){const e=new rc(V(this,Rr));We(this,Dr,0),We(this,gi,e),We(this,ba,t=>{We(this,Dr,V(this,Dr)-e[t]),e[t]=0}),We(this,el,(t,n,i,a)=>{if(ze(this,Dt,Ft).call(this,n))return 0;if(!Bi(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!Bi(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),We(this,ds,(t,n,i)=>{if(e[t]=n,V(this,er)){const a=V(this,er)-e[t];for(;V(this,Dr)>a;)ze(this,ps,ic).call(this,!0)}We(this,Dr,V(this,Dr)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=V(this,Dr))})},ba=new WeakMap,ds=new WeakMap,el=new WeakMap,qr=new WeakSet,Ui=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,hn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,Cn)));)t=V(this,tr)[t]},Vr=new WeakSet,Fi=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,Cn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,hn)));)t=V(this,Ln)[t]},tl=new WeakSet,og=function(e){return e!==void 0&&V(this,ln).get(V(this,Lt)[e])===e},ps=new WeakSet,ic=function(e){var a,s;const t=V(this,Cn),n=V(this,Lt)[t],i=V(this,nt)[t];return V(this,qi)&&ze(this,Dt,Ft).call(this,i)?i.__abortController.abort(new Error("evicted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((a=V(this,Nr))==null||a.call(this,i,n,"evict")),V(this,Mn)&&((s=V(this,mn))==null||s.push([i,n,"evict"]))),V(this,ba).call(this,t),e&&(V(this,Lt)[t]=void 0,V(this,nt)[t]=void 0,V(this,xr).push(t)),V(this,on)===1?(We(this,Cn,We(this,hn,0)),V(this,xr).length=0):We(this,Cn,V(this,Ln)[t]),V(this,ln).delete(n),gl(this,on)._--,t},fs=new WeakSet,ac=function(e,t,n,i){const a=t===void 0?void 0:V(this,nt)[t];if(ze(this,Dt,Ft).call(this,a))return a;const s=new Qc,{signal:o}=n;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:n,context:i},c=(I,R=!1)=>{const{aborted:x}=s.signal,$=n.ignoreFetchAbort&&I!==void 0;if(n.status&&(x&&!R?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,$&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),x&&!$&&!R)return p(s.signal.reason);const Z=_;return V(this,nt)[t]===_&&(I===void 0?Z.__staleWhileFetching?V(this,nt)[t]=Z.__staleWhileFetching:this.delete(e):(n.status&&(n.status.fetchUpdated=!0),this.set(e,I,l.options))),I},u=I=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=I),p(I)),p=I=>{const{aborted:R}=s.signal,x=R&&n.allowStaleOnFetchAbort,$=x||n.allowStaleOnFetchRejection,Z=$||n.noDeleteOnFetchRejection,h=_;if(V(this,nt)[t]===_&&(!Z||h.__staleWhileFetching===void 0?this.delete(e):x||(V(this,nt)[t]=h.__staleWhileFetching)),$)return n.status&&h.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw I},m=(I,R)=>{var $;const x=($=V(this,us))==null?void 0:$.call(this,e,a,l);x&&x instanceof Promise&&x.then(Z=>I(Z===void 0?void 0:Z),R),s.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(I(void 0),n.allowStaleOnFetchAbort&&(I=Z=>c(Z,!0)))})};n.status&&(n.status.fetchDispatched=!0);const _=new Promise(m).then(c,u),v=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,v,{...l.options,status:void 0}),t=V(this,ln).get(e)):V(this,nt)[t]=v,v},Dt=new WeakSet,Ft=function(e){if(!V(this,qi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Qc},nl=new WeakSet,lg=function(e,t){V(this,tr)[t]=e,V(this,Ln)[e]=t},Ea=new WeakSet,bo=function(e){e!==V(this,hn)&&(e===V(this,Cn)?We(this,Cn,V(this,Ln)[e]):ze(this,nl,lg).call(this,V(this,tr)[e],V(this,Ln)[e]),ze(this,nl,lg).call(this,V(this,hn),e),We(this,hn,e))};let ag=y_;const Ro=class Ro{constructor(){E(this,"_fallbackMethod",()=>Ro.createSkipProxy());E(this,"out",()=>{})}};E(Ro,"createSkipProxy",()=>{const e=new Ro;return new Proxy(e,{get(t,n,i){return typeof t[n]>"u"?t._fallbackMethod:t[n]},set(t,n,i,a){return!1}})});let qc=Ro;const No=class No extends C_{constructor(t,n){super(n);E(this,"_fallbackMethod",()=>No.createRestProxy(this.values.length,this.app));E(this,"out",()=>{});this.values.length=t}};E(No,"createRestProxy",(t,n)=>{const i=new No(t,n);return new Proxy(i,{get(a,s,o){return typeof a[s]>"u"?a._fallbackMethod:a[s]},set(a,s,o,l){return!1}})});let Vc=No;class zG extends C_{constructor(t,n,i){super(i);E(this,"input");E(this,"ziffers");E(this,"initCallTime",0);E(this,"startCallTime",0);E(this,"lastCallTime",0);E(this,"waitTime",0);E(this,"startBeat",0);E(this,"played",!1);E(this,"current");E(this,"retro",!1);E(this,"index",-1);E(this,"zid","");E(this,"options",{});E(this,"skipIndex",0);E(this,"endTime",0);E(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));E(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));E(this,"firstRun",()=>this.notStarted());E(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);E(this,"origin",()=>this.app.clock.pulses_since_origin+1);E(this,"pulse",()=>this.app.clock.time_position.pulse);E(this,"beat",()=>this.app.clock.time_position.beat);E(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);E(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);E(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.nextBeatInTicks())&&this.origin()>=this.waitTime,n=this.current&&this.pulseToSecond(this.origin())>=this.pulseToSecond(this.lastCallTime)+this.pulseToSecond(this.current.duration*4*this.app.clock.ppqn)&&this.origin()>=this.waitTime,i=t||n;return this.skipIndex=i?0:this.skipIndex+1,this.index=i?this.index+1:this.index,i&&this.notStarted()&&(this.initCallTime=this.app.clock.pulses_since_origin),this.atTheBeginning()&&(this.startCallTime=this.app.clock.pulses_since_origin),i});E(this,"lead",()=>this.voiceleading());E(this,"invert",t=>(this.atTheBeginning()&&this.ziffers.invert(t),this));E(this,"out",()=>{});this.app=i,this.input=t,this.options=n,this.ziffers=new $G(t,n)}get ticks(){return this.ziffers.duration*4*this.app.clock.ppqn}nextEndTime(){return this.startCallTime+this.ticks}updateLastCallTime(){(this.notStarted()||this.played)&&(this.lastCallTime=this.app.clock.pulses_since_origin,this.played=!1)}notStarted(){return this.ziffers.notStarted()}sound(t){if(this.areWeThereYet()){const n=this.next(),i=this.app.clock.convertPulseToSecond(n.duration*4*this.app.clock.ppqn);if(n instanceof ni){const a=n.getExisting("freq","pitch","key","scale","octave","parsedScale");return n.sound&&(t=n.sound),n.soundIndex&&(a.n=n.soundIndex),a.dur=i,new tg(a,this.app).sound(t||"sine")}else if(n instanceof Na){const a=n.pitches.map(o=>o.getExisting("freq","pitch","key","scale","octave","parsedScale")),s={dur:i};return t&&(s.s=t),new tg(s,this.app).chord(a)}else if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app)}else return qc.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const n=this.next(),i=n.getExisting("note","pitch","bend","key","scale","octave","parsedScale");if(n instanceof ni){n.soundIndex&&(i.channel=n.soundIndex);const a=new ng(i,this.app);return t?a.note(t):a}else{if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app);if(n instanceof Na){const a=n.midiChord();return new ng(i,this.app).chord(a)}}}else return qc.createSkipProxy()}scale(t){return this.atTheBeginning()&&this.ziffers.scale(t),this}key(t){return this.atTheBeginning()&&this.ziffers.key(t),this}octave(t){return this.atTheBeginning()&&this.ziffers.octave(t),this}voiceleading(){return this.atTheBeginning()&&this.ziffers.lead(),this}retrograde(){return this.atTheBeginning()&&this.ziffers.retrograde(),this}wait(t){if(this.atTheBeginning()){if(typeof t=="function"){const n=this.app.api.patternCache.get(t.name);return n&&(this.waitTime=n.nextEndTime()),this}this.waitTime=this.origin()+Math.ceil(t*4*this.app.clock.ppqn)}return this}sync(t){if(this.atTheBeginning()&&this.notStarted()){const n=this.app.clock.pulses_since_origin,i=typeof t=="function"?t.name:t;if(n>0){const a=this.app.api.patternCache.get(i);if(a){const s=a.ziffers.duration,o=a.startCallTime,l=s*4*this.app.clock.ppqn;this.waitTime=o+l}}}return this}}const HG=r=>r[0]==="{"&&r[r.length-1]==="}",fo=(r,e)=>{if(HG(r)){const t=JSON.parse(r);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:r})},WG=r=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new OR({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return fo(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return fo(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return fo(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return fo(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return fo(this.valueOf(),{voice:e})},String.prototype.z=function(e={}){return r.z(this.valueOf(),e)},String.prototype.z0=function(e={}){return r.z0(this.valueOf(),e)},String.prototype.z1=function(e={}){return r.z1(this.valueOf(),e)},String.prototype.z2=function(e={}){return r.z2(this.valueOf(),e)},String.prototype.z3=function(e={}){return r.z3(this.valueOf(),e)},String.prototype.z4=function(e={}){return r.z4(this.valueOf(),e)},String.prototype.z5=function(e={}){return r.z5(this.valueOf(),e)},String.prototype.z6=function(e={}){return r.z6(this.valueOf(),e)},String.prototype.z7=function(e={}){return r.z7(this.valueOf(),e)},String.prototype.z8=function(e={}){return r.z8(this.valueOf(),e)},String.prototype.z9=function(e={}){return r.z9(this.valueOf(),e)},String.prototype.z10=function(e={}){return r.z10(this.valueOf(),e)},String.prototype.z11=function(e={}){return r.z11(this.valueOf(),e)},String.prototype.z12=function(e={}){return r.z12(this.valueOf(),e)},String.prototype.z13=function(e={}){return r.z13(this.valueOf(),e)},String.prototype.z14=function(e={}){return r.z14(this.valueOf(),e)},String.prototype.z15=function(e={}){return r.z15(this.valueOf(),e)},String.prototype.z16=function(e={}){return r.z16(this.valueOf(),e)},String.prototype.note=function(){try{return parseInt(this.valueOf())}catch{return Ur(this.valueOf())}}};let qh;class OR{constructor(e){E(this,"speak",()=>new Promise((e,t)=>{if(this.options.text){const n=window.speechSynthesis;n.speaking&&n.cancel();const i=new SpeechSynthesisUtterance(this.options.text);i.rate=this.options.rate||1,i.pitch=this.options.pitch||1,i.volume=this.options.volume||1,this.options.voice&&(i.voice=n.getVoices()[this.options.voice]),this.options.lang&&(this.options.lang.length===2?i.lang=`${this.options.lang}-${this.options.lang.toUpperCase()}`:this.options.lang.length===5?i.lang=this.options.lang:i.lang="en-US"),i.onend=()=>{e()},i.onerror=a=>{t(a)},n.speaking?(n.cancel(),qh&&clearTimeout(qh),qh=setTimeout(()=>{n.speak(i)},200)):n.speak(i)}else t("No text provided")}));this.options=e}}async function bR(){return Promise.all([jR(),Yi("github:tidalcycles/Dirt-Samples/master").then(()=>h2()),O2(),Yi("github:Bubobubobubobubo/Dough-Fox/main"),Yi("github:Bubobubobubobubo/Dough-Samples/main"),Yi("github:Bubobubobubobubo/Dough-Amiga/main"),Yi("github:Bubobubobubobubo/Dough-Amen/main"),Yi("github:Bubobubobubobubo/Dough-Waveforms/main")])}class XG{constructor(e){E(this,"variables",{});E(this,"codeExamples",{});E(this,"counters",{});E(this,"_drunk",new qG(-100,100,!1));E(this,"randomGen",Math.random);E(this,"currentSeed");E(this,"localSeeds",new Map);E(this,"patternCache",new ag({max:1e3,ttl:1e3*60*5}));E(this,"errorTimeoutID",0);E(this,"printTimeoutID",0);E(this,"MidiConnection");E(this,"scale_aid");E(this,"load");E(this,"_loadUniverseFromInterface",e=>{Dc(this.app,e),xc()});E(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"_playDocExample",e=>{let t=this.app.universes[this.app.selected_universe];this.app.exampleIsPlaying=!0,t.example?t.example.candidate=e||this.app.selectedExample:(t.example={candidate:"",committed:"",evaluations:0},t.example.candidate=e||this.app.selectedExample),this.play()});E(this,"_stopDocExample",()=>{let e=this.app.universes[this.app.selected_universe];(e==null?void 0:e.example)!==void 0&&(this.app.exampleIsPlaying=!1,e.example.candidate="",e.example.committed=""),this.pause()});E(this,"_playDocExampleOnce",e=>{let t=this.app.universes[this.app.selected_universe];(t==null?void 0:t.example)!==void 0&&(t.example.candidate="",t.example.committed=""),this.play(),this.app.exampleIsPlaying=!0,OM(this.app,e)});E(this,"_all_samples",()=>dg.get());E(this,"_reportError",e=>{console.log(e),clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="color-red-800",this.app.interface.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),2e3)});E(this,"_logMessage",e=>{console.log(e),clearTimeout(this.printTimeoutID),clearTimeout(this.errorTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="white",this.app.interface.error_line.classList.remove("hidden"),this.printTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),4e3)});E(this,"time",()=>this.app.audioContext.currentTime);E(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});E(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.MidiConnection.sendStopMessage(),this.app.clock.pause()});E(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.MidiConnection.sendStopMessage(),this.app.clock.stop()});E(this,"silence",this.stop);E(this,"hush",this.stop);E(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});E(this,"beat_warp",e=>{this.app.clock.tick=e*this.app.clock.ppqn,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e*this.app.clock.ppqn)});E(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});E(this,"mouseX",()=>this.app._mouseX);E(this,"mouseY",()=>this.app._mouseY);E(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));E(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));E(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(E2(this.app,"local",t),Ra(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});E(this,"s",this.script);E(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});E(this,"cs",this.delete_script);E(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});E(this,"cps",this.copy_script);E(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});E(this,"delete_universe",e=>{this.app.selected_universe===e&&(this.app.selected_universe="Default"),delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Xo},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});E(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});E(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});E(this,"midi",(e=60,t,n)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),n!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=n),new ng(e,this.app)));E(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});E(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});E(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});E(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});E(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});E(this,"midi_panic",()=>{this.MidiConnection.panic()});E(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});E(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});E(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});E(this,"sticky_notes",e=>{let t;if(e?t=this.MidiConnection.stickyNotesFromChannel(e):t=this.MidiConnection.stickyNotes,t.length>0)return t.map(n=>n.note)});E(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});E(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);E(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());E(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});E(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);E(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});E(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);E(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);E(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());E(this,"show_scale",(e,t,n=0,i=this.MidiConnection.currentOutputIndex||0,a=!1)=>{(!this.scale_aid||t!==this.scale_aid)&&(this.hide_scale(e,t,n,i),NG(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});E(this,"hide_scale",(e=0,t=0,n=0,i=this.MidiConnection.currentOutputIndex||0)=>{Array.from(Array(128).keys()).forEach(s=>{this.MidiConnection.sendMidiOff(s,n,i)}),this.scale_aid=void 0});E(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});E(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});E(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));E(this,"z",(e,t={},n="")=>{const i="z"+n.toString(),a=n===""?this.generateCacheKey(e,t):i;let s;return this.app.api.patternCache.has(a)&&(s=this.app.api.patternCache.get(a),s.input!==e&&(s=void 0)),s||(s=new zG(e,t,this.app),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&s.sync("z0"),s});E(this,"z0",(e,t={})=>this.z(e,t,0));E(this,"z1",(e,t={})=>this.z(e,t,1));E(this,"z2",(e,t={})=>this.z(e,t,2));E(this,"z3",(e,t={})=>this.z(e,t,3));E(this,"z4",(e,t={})=>this.z(e,t,4));E(this,"z5",(e,t={})=>this.z(e,t,5));E(this,"z6",(e,t={})=>this.z(e,t,6));E(this,"z7",(e,t={})=>this.z(e,t,7));E(this,"z8",(e,t={})=>this.z(e,t,8));E(this,"z9",(e,t={})=>this.z(e,t,9));E(this,"z10",(e,t={})=>this.z(e,t,10));E(this,"z11",(e,t={})=>this.z(e,t,11));E(this,"z12",(e,t={})=>this.z(e,t,12));E(this,"z13",(e,t={})=>this.z(e,t,13));E(this,"z14",(e,t={})=>this.z(e,t,14));E(this,"z15",(e,t={})=>this.z(e,t,15));E(this,"z16",(e,t={})=>this.z(e,t,16));E(this,"counter",(e,t,n)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==n&&(this.counters[e].step=n??this.counters[e].step),this.counters[e].value+=this.counters[e].step,this.counters[e].limit!==void 0&&this.counters[e].value>this.counters[e].limit&&(this.counters[e].value=0)):this.counters[e]={value:0,step:n??1,limit:t},this.counters[e].value));E(this,"$",this.counter);E(this,"i",e=>e!==void 0?(this.app.universes[this.app.selected_universe].global.evaluations=e,this.app.universes[this.app.selected_universe]):this.app.universes[this.app.selected_universe].global.evaluations);E(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));E(this,"drunk_max",e=>{this._drunk.max=e});E(this,"drunk_min",e=>{this._drunk.min=e});E(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});E(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));E(this,"v",this.variable);E(this,"delete_variable",e=>{delete this.variables[e]});E(this,"dv",this.delete_variable);E(this,"clear_variables",()=>{this.variables={}});E(this,"cv",this.clear_variables);E(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);E(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);E(this,"irand",this.randI);E(this,"rI",this.randI);E(this,"r",this.rand);E(this,"ir",this.randI);E(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=jm(e))});E(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=jm(e);return this.localSeeds.set(e,t),t});E(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});E(this,"quantize",(e,t)=>{if(t.length===0)return e;let n=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),n));E(this,"cmp",this.clamp);E(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));E(this,"bpm",e=>e===void 0?this.app.clock.bpm:((e<1||e>500)&&console.log(`Setting bpm to ${e}`),this.app.clock.bpm=e,e));E(this,"tempo",this.bpm);E(this,"bpb",e=>e===void 0?this.app.clock.time_signature[0]:(e<1&&console.log(`Setting bpb to ${e}`),this.app.clock.time_signature[0]=e,e));E(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));E(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});E(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);E(this,"odds",(e,t=1)=>this.randomGen()!1);E(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));E(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));E(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));E(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));E(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));E(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));E(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));E(this,"always",(e=1)=>!0);E(this,"dice",e=>Math.floor(this.randomGen()*e)+1);E(this,"cbar",()=>this.app.clock.time_position.bar+1);E(this,"ctick",()=>this.app.clock.tick+1);E(this,"cpulse",()=>this.app.clock.time_position.pulse+1);E(this,"cbeat",()=>this.app.clock.time_position.beat+1);E(this,"ebeat",()=>this.app.clock.beats_since_origin+1);E(this,"epulse",()=>this.app.clock.pulses_since_origin+1);E(this,"nominator",()=>this.app.clock.time_signature[0]);E(this,"meter",()=>this.app.clock.time_signature[1]);E(this,"denominator",this.meter);E(this,"fill",()=>this.app.fill);E(this,"beat",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-Math.floor(t*this.ppqn()))%Math.floor(a*this.ppqn())===0).some(a=>a===!0));E(this,"b",this.beat);E(this,"bar",(e=1,t=0)=>{const n=Array.isArray(e)?e:[e],i=this.app.clock.time_signature[1]*this.ppqn(),a=Math.floor(t*i);return n.map(o=>(this.app.clock.pulses_since_origin-a)%Math.floor(o*i)===0).some(o=>o===!0)});E(this,"B",this.bar);E(this,"pulse",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-t)%a===0).some(a=>a===!0));E(this,"p",this.pulse);E(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));E(this,"flip",(e,t=50)=>{let n=e*2;const i=this.app.clock.pulses_since_origin,a=Math.floor(n*this.ppqn()),s=Math.floor(t/100*a);return i%a{let t=e*2;const n=this.app.clock.time_position.bar;return Math.floor(n/t)%2===0});E(this,"onbar",(e,t=this.app.clock.time_signature[0])=>{let n=this.app.clock.time_position.bar%t+1;return typeof e=="number"?e===n:e.some(i=>i==n)});E(this,"onbeat",(...e)=>{let t=[];return e.forEach(n=>{let i=n%this.nominator()||this.nominator(),a=Math.floor(i);a=a==0?this.nominator():a;let s=Math.floor((i-a)*this.ppqn()+1);s<=0&&(s=s+this.ppqn()*this.nominator()),t.push(a===this.cbeat()&&this.cpulse()===s)}),t.some(n=>n==!0)});E(this,"oncount",(e,t)=>{typeof e=="number"&&(e=[e]);const n=this.app.clock.pulses_since_origin;let i=[];return e.forEach(a=>{a=a<1?0:a-1;const s=Math.ceil(a*this.ppqn()),o=n%(this.ppqn()*t);return i.push(o===s)}),i.some(a=>a==!0)});E(this,"oneuclid",(e,t,n=0)=>{const a=this._euclidean_cycle(e,t,n).reduce((s,o,l)=>(o&&s.push(l+1),s),[]);return this.oncount(a,t)});E(this,"delay",(e,t)=>{setTimeout(t,e)});E(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});E(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);E(this,"ec",this.euclid);E(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));E(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});E(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});E(this,"line",(e,t,n=1)=>{const i=[];if(t>e&&n>0||t(Math.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+n)*t);E(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,n)+1)/2*t);E(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);E(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,n)+1)/2*t);E(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,n))*2-1)*t);E(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,n)+1)/2*t);E(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,n,i)+1)/2*t);E(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);E(this,"min",(...e)=>Math.min(...e));E(this,"max",(...e)=>Math.max(...e));E(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);E(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);E(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));E(this,"abs",Math.abs);E(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new OR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});E(this,"stop_hydra",()=>{this.app.hydra.hush()});E(this,"sound",e=>new tg(e,this.app));E(this,"snd",this.sound);E(this,"samples",Yi);E(this,"log",e=>{console.log(e),this._logMessage(e)});E(this,"scale",T_);E(this,"rate",e=>{});E(this,"divseq",(...e)=>{const t=e[0],n=e.slice(1),i=this.app.clock.pulses_since_origin,a=Math.floor(i/Math.floor(t*this.ppqn()));return n[a%n.length]});E(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);E(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);E(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));E(this,"reverse",e=>e.reverse());E(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));E(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));E(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));E(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));E(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));E(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});this.app=e,this.MidiConnection=new QG(this,e.settings)}transmission(){return this.MidiConnection.activeNotes.length>0}_euclidean_cycle(e,t,n=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,u=(l+1)%c;return o[l]>o[u]}if(e>=t)return[!0];const a=Array.from({length:t},(o,l)=>(e*(l-1)%t+t)%t);let s=a.map((o,l)=>i(a,l));return n!=0&&(s=s.slice(n).concat(s.slice(0,n))),s}}const ZG=r=>{Array.prototype.square=function(){return this.map(e=>e*e)},Array.prototype.sometimes=function(e){return r.randomGen()<.5?e(this):this},Array.prototype.apply=function(e){return e(this)},Array.prototype.sqrt=function(){if(this.some(e=>e<0))throw new Error("Cannot take square root of negative number");return this.map(e=>Math.sqrt(e))},Array.prototype.add=function(e){return this.map(t=>t+e)},Array.prototype.sub=function(e){return this.map(t=>t-e)},Array.prototype.mult=function(e){return this.map(t=>t*e)},Array.prototype.div=function(e){if(e===0)throw new Error("Division by zero");return this.map(t=>t/e)},Array.prototype.pick=function(){return this[Math.floor(r.randomGen()*this.length)]},Array.prototype.gen=function(e,t,n){return n<1?[]:Array.from({length:n},()=>Math.floor(r.randomGen()*(t-e+1))+e)},Array.prototype.bar=function(e=1){return e===1?this[r.app.clock.time_position.bar%this.length]:this[Math.floor(r.app.clock.time_position.bar/e)%this.length]},Array.prototype.beat=function(e=1){const t=e,n=r.app.clock.pulses_since_origin,i=Math.floor(n/Math.floor(t*r.ppqn()));return this[i%this.length]},Array.prototype.b=Array.prototype.beat,Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(r.randomGen()*e),e--,[this[e],this[t]]=[this[t],this[e]];return this},Array.prototype.rotate=function(e){const t=this.length;if(e<0)e=t+e%t;else if(e>0)e=e%t;else return this;const n=this.splice(-e,e);return this.unshift(...n),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let n=0;n100)throw new Error("Amount should be between 0 and 100");if(this.length<=1)return this;for(let t=0;t1)this.splice(t,1);else return this;else t++;return this},Array.prototype.repeat=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let n=0;n(i%a+a)%a,n=cR(Ds(r));return this.map(i=>{const a=Math.floor(i/n.length)*12;return n[t(i,n.length)]+e+a})};Array.prototype.scaleArp=function(r="major",e=0){const t=cR(Ds(r));let n=[];e=e>t.length?t.length:e,e=e==0?t.length:e;for(let i=0;i{r.interface.line_numbers_checkbox.checked=r.settings.line_numbers,r.interface.time_position_checkbox.checked=r.settings.time_position,r.interface.tips_checkbox.checked=r.settings.tips,r.interface.midi_clock_checkbox.checked=r.settings.send_clock,r.interface.midi_channels_scripts.checked=r.settings.midi_channels_scripts,r.interface.midi_clock_ppqn.value=r.settings.midi_clock_ppqn.toString(),r.settings.time_position||r.interface.timeviewer.classList.add("hidden"),r.interface.load_demo_songs.checked=r.settings.load_demo_songs;const e=document.querySelectorAll('[id^="tab-"]');for(let t=0;t{e[t].classList.add("bg-orange-300");for(let s=0;s{hi(),r.updateKnownUniversesView(),xc()}),r.buttonElements.play_buttons.forEach(t=>{t.addEventListener("click",()=>{r.isPlaying?(r.setButtonHighlighting("pause",!0),r.isPlaying=!r.isPlaying,r.clock.pause(),r.api.MidiConnection.sendStopMessage()):(r.setButtonHighlighting("play",!0),r.isPlaying=!r.isPlaying,r.clock.start(),r.api.MidiConnection.sendStartMessage())})}),r.buttonElements.clear_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("clear",!0),confirm("Do you want to reset the current universe?")&&(r.universes[r.selected_universe]=structuredClone(t_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{XI(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Xo},r.updateKnownUniversesView())}),r.interface.audio_nudge_range.addEventListener("input",()=>{r.clock.nudge=parseInt(r.interface.audio_nudge_range.value)}),r.interface.dough_nudge_range.addEventListener("input",()=>{r.dough_nudge=parseInt(r.interface.dough_nudge_range.value)}),r.interface.upload_universe_button.addEventListener("click",()=>{const t=document.createElement("input");t.type="file",t.accept=".json",t.addEventListener("change",n=>{var s;const a=(s=n.target.files)==null?void 0:s[0];if(a){const o=new FileReader;o.readAsText(a,"UTF-8"),o.onload=l=>{const c=JSON.parse(l.target.result);for(const[u,p]of Object.entries(c))r.universes[u]=p},o.onerror=l=>{console.error("An error occurred reading the file:",l)}}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}),r.interface.download_universe_button.addEventListener("click",()=>{r.settings.saveApplicationToLocalStorage(r.universes,r.settings);let t=`topos-universes-${Date.now()}.json`;const n=new Blob([JSON.stringify(r.settings.universes)],{type:"application/json"}),i=URL.createObjectURL(n),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}),r.interface.load_universe_button.addEventListener("click",()=>{let t=r.interface.buffer_search.value;t.length>2&&t.length<20&&!t.includes(" ")&&(Dc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Vm(),r.view.focus(),FA())}),r.interface.eval_button.addEventListener("click",()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.flashBackground("#404040",200)}),r.buttonElements.stop_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("stop",!0),r.isPlaying=!1,r.clock.stop()})}),r.interface.local_button.addEventListener("click",()=>r.changeModeFromInterface("local")),r.interface.global_button.addEventListener("click",()=>r.changeModeFromInterface("global")),r.interface.init_button.addEventListener("click",()=>r.changeModeFromInterface("init")),r.interface.note_button.addEventListener("click",()=>r.changeModeFromInterface("notes")),r.interface.font_family_selector.addEventListener("change",()=>{let t=r.interface.font_family_selector.value;console.log("Picking new font : "+t),r.settings.font=t,r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:t,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.font_size_input.addEventListener("input",()=>{let t=r.interface.font_size_input.value;r.settings.font_size=parseInt(t),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.settings_button.addEventListener("click",()=>{const t=document.getElementById("font-family");t&&(t.value=r.settings.font);const n=r.interface.dough_nudge_range;n.value=r.dough_nudge.toString();const i=document.getElementById("doughnumber");i.value=r.dough_nudge.toString(),r.settings.font_size===null&&(r.settings.font_size=12);const a=r.interface.font_size_input;a.value=r.settings.font_size.toString();const s=r.interface.line_numbers_checkbox;s.checked=r.settings.line_numbers;const o=r.interface.time_position_checkbox;o.checked=r.settings.time_position;const l=r.interface.tips_checkbox;l.checked=r.settings.tips;const c=r.interface.midi_clock_checkbox;c.checked=r.settings.send_clock;const u=r.interface.midi_channels_scripts;u.checked=r.settings.midi_channels_scripts;const p=r.interface.midi_clock_ppqn;p.value=r.settings.midi_clock_ppqn.toString();const m=r.interface.load_demo_songs;m.checked=r.settings.load_demo_songs;const _=r.interface.vim_mode_checkbox;_.checked=r.settings.vimMode;let v=document.getElementById("modal-settings"),I=document.getElementById("editor");v==null||v.classList.remove("invisible"),I==null||I.classList.add("invisible")}),r.interface.close_settings_button.addEventListener("click",()=>{let t=document.getElementById("modal-settings"),n=document.getElementById("editor");t==null||t.classList.add("invisible"),n==null||n.classList.remove("invisible");let i=r.interface.font_size_input.value;r.settings.font_size=parseInt(i),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.close_universes_button.addEventListener("click",()=>{xc()}),r.interface.share_button.addEventListener("click",async()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),await vM(r)}),r.interface.vim_mode_checkbox.addEventListener("change",()=>{let t=!!r.interface.vim_mode_checkbox.checked;r.settings.vimMode=t,r.view.dispatch({effects:r.vimModeCompartment.reconfigure(t?f_():[])})}),r.interface.line_numbers_checkbox.addEventListener("change",()=>{let n=!!r.interface.line_numbers_checkbox.checked;r.settings.line_numbers=n,r.view.dispatch({effects:r.withLineNumbers.reconfigure(n?[ey()]:[])})}),r.interface.time_position_checkbox.addEventListener("change",()=>{let t=document.getElementById("timeviewer"),n=!!r.interface.time_position_checkbox.checked;r.settings.time_position=n,n?t.classList.remove("hidden"):t.classList.add("hidden")}),r.interface.tips_checkbox.addEventListener("change",()=>{let t=!!r.interface.tips_checkbox.checked;r.settings.tips=t,r.view.dispatch({effects:r.hoveringCompartment.reconfigure(t?rR:[])})}),r.interface.midi_clock_checkbox.addEventListener("change",()=>{let t=!!r.interface.midi_clock_checkbox.checked;r.settings.send_clock=t}),r.interface.midi_channels_scripts.addEventListener("change",()=>{let t=!!r.interface.midi_channels_scripts.checked;r.settings.midi_channels_scripts=t}),r.interface.midi_clock_ppqn.addEventListener("change",()=>{let t=parseInt(r.interface.midi_clock_ppqn.value);r.settings.midi_clock_ppqn=t}),r.interface.load_demo_songs.addEventListener("change",()=>{let t=!!r.interface.load_demo_songs.checked;r.settings.load_demo_songs=t}),r.interface.universe_creator.addEventListener("submit",t=>{t.preventDefault();let i=new FormData(r.interface.universe_creator).get("universe");i&&i.length>2&&i.length<20&&(Dc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Vm(),r.view.focus())}),Ra(r,r.universes[r.selected_universe.toString()].init),["introduction","interface","interaction","code","time","sound","samples","synths","chaining","patterns","ziffers","midi","functions","lfos","probabilities","variables","shortcuts","about","bonus","oscilloscope"].forEach(t=>{let n="docs_"+t;document.getElementById(n).addEventListener("click",async()=>{n!=="docs_samples"?(r.currentDocumentationPane=t,Km(r)):(console.log("Loading samples!"),await bR().then(()=>{r.docs=WI(r),r.currentDocumentationPane=t,Km(r)}))})})},ST=r=>{if(!r)return;r.width=window.innerWidth,r.height=window.innerHeight;const e=r.getContext("2d"),t=window.devicePixelRatio||1;r.width=window.innerWidth*t,r.height=window.innerHeight*t,e&&e.scale(t,t)},jG=(r,e,t=!1)=>{e.addEventListener("resize",()=>ST(r.interface.scope)),e.addEventListener("resize",()=>ST(r.interface.feedback)),e.addEventListener("beforeunload",()=>(event.preventDefault(),r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),r.clock.stop(),null)),t&&(localStorage.openpages=Date.now(),e.addEventListener("storage",function(n){n.key=="openpages"&&(localStorage.page_available=Date.now()),n.key=="page_available"&&(document.getElementById("all").classList.add("invisible"),alert("Topos is already opened in another tab. Close this tab now to prevent data loss."))},!1))};class JG{constructor(){E(this,"settings",new bM);E(this,"universes",Xo);E(this,"selected_universe","Welcome");E(this,"fill",!1);E(this,"local_index",1);E(this,"editor_mode","global");E(this,"fontSize");E(this,"withLineNumbers");E(this,"vimModeCompartment");E(this,"hoveringCompartment");E(this,"chosenLanguage");E(this,"dynamicPlugins");E(this,"currentDocumentationPane","introduction");E(this,"exampleCounter",0);E(this,"exampleIsPlaying",!1);E(this,"editorExtensions",[]);E(this,"userPlugins",[]);E(this,"state");E(this,"view");E(this,"selectedExample","");E(this,"docs",{});E(this,"_mouseX",0);E(this,"_mouseY",0);E(this,"show_error",!1);E(this,"buttonElements",{});E(this,"interface",{});E(this,"blinkTimeouts",{});E(this,"osc",{enabled:!1,color:"#fdba74",thickness:4,refresh:1,fftSize:256,orientation:"horizontal",is3D:!1,size:1});E(this,"api");E(this,"audioContext");E(this,"clock");E(this,"dough_nudge",20);E(this,"manualPlay",!1);E(this,"isPlaying",!1);E(this,"hydra_backend");E(this,"hydra");E(this,"updateKnownUniversesView",()=>{let e=document.getElementById("ui-known-universe-item-template");if(!e){console.warn("Missing template #ui-known-universe-item-template");return}let t=document.getElementById("existing-universes");if(!t){console.warn("Missing element #existing-universes");return}let n=document.createElement("ul");n.className="lg:h-80 lg:text-normal text-sm h-auto lg:w-80 w-auto lg:pb-2 lg:pt-2 overflow-y-scroll text-white lg:mb-4 border rounded-lg bg-neutral-800",n.append(...Object.keys(this.universes).map(i=>{var o,l;let a=e.content.cloneNode(!0),s=window;return a.querySelector(".universe-name").textContent=i,(o=a.querySelector(".load-universe"))==null||o.addEventListener("click",()=>s._loadUniverseFromInterface(i)),(l=a.querySelector(".delete-universe"))==null||l.addEventListener("click",()=>s._deleteUniverseFromInterface(i)),a})),t.innerHTML="",t.append(n)});this.initializeElements(),this.initializeButtonGroups(),this.initializeHydra(),this.setCanvas(this.interface.feedback),this.setCanvas(this.interface.scope),this.universes={...this.settings.universes,...Xo},EM(this),this.audioContext=new AudioContext({latencyHint:"playback"}),this.clock=new j$(this,this.audioContext),this.api=new XG(this),ZG(this.api),WG(this.api),Object.entries(this.api).forEach(([t,n])=>{globalThis[t]=n}),(async()=>{await bR()})(),this.docs=WI(this),T$(this),C$(this),KG(this),TT(this),X$(this),v2(this.interface.scope,this),Ra(this,this.universes[this.selected_universe.toString()].init),this.changeModeFromInterface("global"),TM(this)}getBuffer(e){const t=this.universes[this.selected_universe.toString()];return e==="locals"?t[e][this.local_index]:t[e]}get note_buffer(){return this.getBuffer("notes")}get example_buffer(){return this.getBuffer("example")}get global_buffer(){return this.getBuffer("global")}get init_buffer(){return this.getBuffer("init")}get local_buffer(){return this.getBuffer("locals")}changeToLocalBuffer(e){const t=document.querySelectorAll('[id^="tab-"]'),n=t[e];n.classList.add("bg-orange-300");for(let a=0;a{t.forEach(a=>{let s=a.children[0];s.classList.contains("text-orange-300")&&(s.classList.remove("text-orange-300"),a.classList.remove("text-orange-300"))}),i.children[0].classList.remove("text-white"),i.children[0].classList.add("text-orange-300"),i.classList.add("text-orange-300"),i.classList.add("fill-orange-300")};switch(e){case"local":this.interface.local_script_tabs.classList.contains("hidden")&&this.interface.local_script_tabs.classList.remove("hidden"),this.editor_mode="local",this.local_index=0,document.getElementById("editor").style.height="calc(100% - 100px)",this.changeToLocalBuffer(this.local_index),n(this.interface.local_button);break;case"global":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="global",document.getElementById("editor").style.height="100%",n(this.interface.global_button);break;case"init":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="init",n(this.interface.init_button);break;case"notes":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="notes",n(this.interface.note_button);break}this.view.dispatch({effects:this.chosenLanguage.reconfigure(this.editor_mode=="notes"?[BL()]:[Gg()])}),this.updateEditorView()}setButtonHighlighting(e,t){document.getElementById("play-label").textContent=e!=="pause"?"Pause":"Play",e!=="pause"?(document.getElementById("pause-icon").classList.remove("hidden"),document.getElementById("play-icon").classList.add("hidden")):(document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),e==="stop"&&(this.isPlaying==!1,document.getElementById("play-label").textContent="Play",document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),this.flashBackground("#404040",200);const n=['[id^="play-button-"]','[id^="clear-button-"]','[id^="stop-button-"]'];let i;switch(e){case"play":i=0;break;case"pause":i=1;break;case"clear":i=2;break;case"stop":i=3;break}document.querySelectorAll(n[i]).forEach(a=>{t&&a.children[0].classList.add("animate-pulse")}),document.querySelectorAll(n.filter((a,s)=>s!=i).join(",")).forEach(a=>{a.children[0].classList.remove("animate-pulse"),a.children[1].classList.remove("animate-pulse")})}unfocusPlayButtons(){document.querySelectorAll('[id^="play-button-"]').forEach(e=>{e.children[0].classList.remove("fill-orange-300"),e.children[0].classList.remove("animate-pulse")})}updateEditorView(){this.view.dispatch({changes:{from:0,to:this.view.state.doc.toString().length,insert:this.currentFile().candidate}})}currentFile(){switch(this.editor_mode){case"global":return this.global_buffer;case"local":return this.local_buffer;case"init":return this.init_buffer;case"notes":return this.note_buffer}}flashBackground(e,t){const n=this.view.dom,i=n.getElementsByClassName("cm-gutter");n.classList.add("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.add("fluid-bg-transition")),n.style.backgroundColor=e,Array.from(i).forEach(a=>a.style.backgroundColor=e),setTimeout(()=>{n.style.backgroundColor="",Array.from(i).forEach(a=>a.style.backgroundColor=""),n.classList.remove("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.remove("fluid-bg-transition"))},t)}initializeElements(){for(const[e,t]of Object.entries(AM))this.interface[e]=document.getElementById(t)}initializeButtonGroups(){for(const[e,t]of Object.entries(IM))this.buttonElements[e]=t.map(n=>document.getElementById(n))}initializeHydra(){this.hydra_backend=new Hydra({canvas:this.interface.hydra_canvas,detectAudio:!1,enableStreamCapture:!1}),this.hydra=this.hydra_backend.synth}setCanvas(e){if(!e)return;const t=e.getContext("2d"),n=window.devicePixelRatio||1;e.width=window.innerWidth*n,e.height=window.innerHeight*n,t&&t.scale(n,n)}}let e5=new JG;jG(e5,window,!1); diff --git a/index.html b/index.html index 2b5f5cb..dd4c68d 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - +