From 49b59ba5e132448e70783bd191817dd9f6899132 Mon Sep 17 00:00:00 2001 From: Bubobubobubobubo Date: Sun, 5 Nov 2023 01:21:33 +0000 Subject: [PATCH] deploy: 73140b0f8558501fa7c8ae6353433afcef830612 --- assets/{index-f817d48d.js => index-77922318.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-f817d48d.js => index-77922318.js} (99%) diff --git a/assets/index-f817d48d.js b/assets/index-77922318.js similarity index 99% rename from assets/index-f817d48d.js rename to assets/index-77922318.js index cafa41d..1e11dce 100644 --- a/assets/index-f817d48d.js +++ b/assets/index-77922318.js @@ -2920,6 +2920,6 @@ https://github.com/highlightjs/highlight.js/issues/2277`),le=Q,ue=j),K===void 0& `+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 E=_.parts.map(function(I){return Array.isArray(I)?c(I[0])+"-"+c(I[1]):c(I)});return"["+(_.inverted?"^":"")+E.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(E){return"\\x0"+o(E)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(E){return"\\x"+o(E)})}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(E){return"\\x0"+o(E)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(E){return"\\x"+o(E)})}function u(_){return s[_.type](_)}function p(_){var E=_.map(u),I,R;if(E.sort(),E.length>0){for(I=1,R=1;I",R="@",D=":",Y="/",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=jn([["0","9"]],!1,!1),ke=st(".",!1),en=Xs("whitespace"),Zt=jn([" ",` `,"\r"," "],!1,!1),an=st(",",!1),H=st("|",!1),fe=jn([["a","z"]],!1,!1),Ie=jn([["a","z"],"_"],!1,!1),we=jn([["a","z"],"_",["0","9"]],!1,!1),Je=st("<",!1),ye=st(">",!1),Ht=st("@",!1),lt=st(":",!1),yt=jn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),Hn=st("/",!1),dt=st("(",!1),Kt=st(")",!1),Tt=st("[:",!1),Ue=st("]",!1),Fn=st("[",!1),Qr=st("{",!1),ct=st("}",!1),Wn=st("+",!1),Nn=st("*",!1),Ai=st("%",!1),wn=st("^",!1),Wt=st("&",!1),Ar=st(">>",!1),ra=st("<<",!1),li=st("_",!1),ia=st("?",!1),ur=st("!",!1),ci=st("r",!1),Ir=jn([["a","z"],["A","Z"],["0","9"]],!1,!1),jt=st("#",!1),ui=st("b",!1),di=jn([["a","z"],["A","Z"],["0","9"],"-","*","+"],!1,!1),q=jn([["A","G"]],!1,!1),ie=jn(["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),Xn=function(v){return v.filter(w=>w)},ka=function(){return parseFloat($n())},aa=function(){return parseInt($n())},Ls=function(){return parseInt($n())},Zn=function(){},Ms=function(v){return Ut(FG,{sound:v})},La=function(){return $n()},Ma=function(v){return Ut(No,{items:v})},Ps=function(v){return v},Pa=function(v,w){return Ut(YG,{item:v,sound:w})},Bs=function(v,w){return Ut($G,{item:v,soundIndex:w})},Ba=function(v){return v},Yn=function(){return _G[$n()]},Us=function(v,w){return v/w},Fs=function(v){return v.filter(w=>w)},Ua=function(v){return Ut(No,{items:v})},Fa=function(v,w){return w?Ut(vT,{item:v,times:w}):Ut(TT,{items:v})},Ys=function(v){return v},Ya=function(v,w,P){return Ut(zG,{left:v,operation:w,right:P})},$s=function(v,w){return Ut(VG,{items:v,times:w})},$a=function(v){return Ut(_R,{items:v})},Gs=function(v){return v.map(w=>typeof w=="number"?w:void 0)},Qs=function(){return Math.ceil(hR($n()))},dr=function(v){var w=v.filter(P=>P).map(P=>Ut(zn,{pitch:P[0]},P.toString()));return Ut(TT,{items:w})},Ot=function(v){return v},qs=function(v){return v},Ii=function(){},Vs=function(v){return Ut(No,{items:v})},pi=function(v){return Ut(QG,{octave:v})},zs=function(){return $n().split("").reduce((v,w)=>v+(w==="^"?1:-1),0)},Ri=function(){return Ut(zc,{seededRandom:a.seededRandom})},Ga=function(v,w){return Ut(zc,{min:v,max:w,seededRandom:a.seededRandom})},Qa=function(v,w){return Ut(vT,{item:v,times:w})},Hs=function(v){return Ut(qG,{duration:v})},Ni=function(v){return v},qa=function(v){return Ut(ag,{duration:v})},wi=function(v,w,P,X){const oe=v?a.nodeOptions.octave+v:a.nodeOptions.octave;return Ut(zn,{duration:w,pitch:X,pitchOctave:oe,add:P})},Di=function(v){return v.reduce((w,P)=>w+(P==="#"?1:-1),0)},Va=function(v,w,P){return Ut($r,{pitches:[v].concat(w),inversion:P})},sa=function(){return $n()},fi=function(v){return v},_n=function(){return $n()},za=function(v,w,P,X,oe){const ve=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",ft=a.nodeOptions.key?a.nodeOptions.key:"C",hr=e5(X,P,ve,v,w),Js=w||a.nodeOptions.duration,QR=v?a.nodeOptions.octave+v:a.nodeOptions.octave;return Ut($r,{duration:Js,chordOctave:QR,pitches:hr,chordName:X,inversion:oe,scaleName:ve,key:ft})},Kn=function(v,w,P){const X=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",oe=a.nodeOptions.key?a.nodeOptions.key:"C";return Ut(GG,{roman:v,chordName:w,inversion:P,scaleName:X,key:oe})},oa=function(v){const w=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",P=a.nodeOptions.key?a.nodeOptions.key:"C",X=l5(v,P,w);return Ut(zn,{pitch:X.pc,add:X.add,scaleName:w,key:P})},y=0,He=0,Ha=[{line:1,column:1}],pr=0,Ws=[],Oe=0,ge={},la;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,y)}function ml(){return d(He,y)}function st(v,w){return{type:"literal",text:v,ignoreCase:w}}function jn(v,w,P){return{type:"class",parts:v,inverted:w,ignoreCase:P}}function gl(){return{type:"end"}}function Xs(v){return{type:"other",description:v}}function _l(v){var w=Ha[v],P;if(w)return w;for(P=v-1;!Ha[P];)P--;for(w=Ha[P],w={line:w.line,column:w.column};Ppr&&(pr=y,Ws=[]),Ws.push(v))}function g(v,w,P){return new e(e.buildMessage(v,w),v,w,P)}function O(){var v,w,P=y*56+0,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=Xt(),w!==s&&(He=v,w=Xn(w)),v=w,ge[P]={nextPos:y,result:v},v)}function T(){var v,w,P,X,oe,ve,ft,hr=y*56+1,Js=ge[hr];if(Js)return y=Js.nextPos,Js.result;for(v=y,w=y,i.charCodeAt(y)===45?(P=u,y++):(P=s,Oe===0&&f(rn)),P===s&&(P=null),X=[],Be.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(Ze));oe!==s;)X.push(oe),Be.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(Ze));if(i.charCodeAt(y)===46?(oe=p,y++):(oe=s,Oe===0&&f(ke)),oe!==s){if(ve=[],Be.test(i.charAt(y))?(ft=i.charAt(y),y++):(ft=s,Oe===0&&f(Ze)),ft!==s)for(;ft!==s;)ve.push(ft),Be.test(i.charAt(y))?(ft=i.charAt(y),y++):(ft=s,Oe===0&&f(Ze));else ve=s;ve!==s?(P=[P,X,oe,ve],w=P):(y=w,w=s)}else y=w,w=s;if(w===s)if(w=y,i.charCodeAt(y)===46?(P=p,y++):(P=s,Oe===0&&f(ke)),P!==s){if(X=[],Be.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(Ze)),oe!==s)for(;oe!==s;)X.push(oe),Be.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(Ze));else X=s;X!==s?(P=[P,X],w=P):(y=w,w=s)}else y=w,w=s;return w!==s&&(He=v,w=ka()),v=w,ge[hr]={nextPos:y,result:v},v}function C(){var v,w,P=y*56+2,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,i.charCodeAt(y)===45?y++:Oe===0&&f(rn),Be.test(i.charAt(y))?(w=i.charAt(y),y++):(w=s,Oe===0&&f(Ze)),w!==s?(He=v,v=aa()):(y=v,v=s),ge[P]={nextPos:y,result:v},v)}function x(){var v,w,P,X=y*56+3,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,i.charCodeAt(y)===45?y++:Oe===0&&f(rn),w=[],Be.test(i.charAt(y))?(P=i.charAt(y),y++):(P=s,Oe===0&&f(Ze)),P!==s)for(;P!==s;)w.push(P),Be.test(i.charAt(y))?(P=i.charAt(y),y++):(P=s,Oe===0&&f(Ze));else w=s;return w!==s?(He=v,v=Ls()):(y=v,v=s),ge[X]={nextPos:y,result:v},v}function F(){var v,w,P=y*56+4,X=ge[P];return X?(y=X.nextPos,X.result):(Oe++,v=y,tt.test(i.charAt(y))?(w=i.charAt(y),y++):(w=s,Oe===0&&f(Zt)),w!==s&&(He=v,w=Zn()),v=w,Oe--,v===s&&(w=s,Oe===0&&f(en)),ge[P]={nextPos:y,result:v},v)}function U(){var v,w,P=y*56+8,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=W(),w!==s&&(He=v,w=Ms(w)),v=w,ge[P]={nextPos:y,result:v},v)}function W(){var v,w,P,X,oe,ve=y*56+10,ft=ge[ve];if(ft)return y=ft.nextPos,ft.result;if(v=y,rt.test(i.charAt(y))?(w=i.charAt(y),y++):(w=s,Oe===0&&f(fe)),w!==s){if(P=[],ht.test(i.charAt(y))?(X=i.charAt(y),y++):(X=s,Oe===0&&f(Ie)),X!==s)for(;X!==s;)P.push(X),ht.test(i.charAt(y))?(X=i.charAt(y),y++):(X=s,Oe===0&&f(Ie));else P=s;if(P!==s){for(X=[],vt.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(we));oe!==s;)X.push(oe),vt.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(we));He=v,v=La()}else y=v,v=s}else y=v,v=s;return ge[ve]={nextPos:y,result:v},v}function z(){var v,w=y*56+11,P=ge[w];return P?(y=P.nextPos,P.result):(v=pe(),v===s&&(v=he()),ge[w]={nextPos:y,result:v},v)}function pe(){var v,w,P,X,oe=y*56+12,ve=ge[oe];if(ve)return y=ve.nextPos,ve.result;if(v=y,i.charCodeAt(y)===60?(w=E,y++):(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(y)===62?(X=I,y++):(X=s,Oe===0&&f(ye)),X!==s?(He=v,v=Ma(P)):(y=v,v=s)):(y=v,v=s)}else y=v,v=s;return ge[oe]={nextPos:y,result:v},v}function he(){var v,w=y*56+13,P=ge[w];return P?(y=P.nextPos,P.result):(v=W(),v===s&&(v=pe(),v===s&&(v=F())),ge[w]={nextPos:y,result:v},v)}function se(){var v,w,P,X=y*56+14,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,i.charCodeAt(y)===64?(w=R,y++):(w=s,Oe===0&&f(Ht)),w!==s?(P=z(),P!==s?(He=v,v=Ps(P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function ae(){var v,w=y*56+15,P=ge[w];return P?(y=P.nextPos,P.result):(v=sn(),v===s&&(v=it(),v===s&&(v=qt(),v===s&&(v=gu(),v===s&&(v=Qt())))),ge[w]={nextPos:y,result:v},v)}function Ce(){var v,w,P,X=y*56+16,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,w=ae(),w===s&&(w=js()),w!==s?(P=se(),P!==s?(He=v,v=Pa(w,P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function Se(){var v,w,P,X=y*56+17,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,w=Ce(),w===s&&(w=ae(),w===s&&(w=js())),w!==s?(P=Ve(),P!==s?(He=v,v=Bs(w,P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function Ve(){var v,w,P,X=y*56+18,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,i.charCodeAt(y)===58?(w=D,y++):(w=s,Oe===0&&f(lt)),w!==s?(P=wt(),P!==s?(He=v,v=Ba(P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function je(){var v,w,P=y*56+19,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,mt.test(i.charAt(y))?(w=i.charAt(y),y++):(w=s,Oe===0&&f(yt)),w!==s&&(He=v,w=Yn()),v=w,ge[P]={nextPos:y,result:v},v)}function Fe(){var v,w=y*56+20,P=ge[w];return P?(y=P.nextPos,P.result):(v=It(),v===s&&(v=T(),v===s&&(v=je())),ge[w]={nextPos:y,result:v},v)}function It(){var v,w,P,X,oe=y*56+21,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,w=x(),w!==s?(i.charCodeAt(y)===47?(P=Y,y++):(P=s,Oe===0&&f(Hn)),P!==s?(X=x(),X!==s?(He=v,v=Us(w,X)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function Xt(){var v,w,P,X=y*56+22,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,w=[],P=M_(),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=js(),P===s&&(P=gu())))))))),P!==s)for(;P!==s;)w.push(P),P=M_(),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=js(),P===s&&(P=gu()))))))));else w=s;return w!==s&&(He=v,w=Fs(w)),v=w,ge[X]={nextPos:y,result:v},v}function wt(){var v,w=y*56+23,P=ge[w];return P?(y=P.nextPos,P.result):(v=F(),v===s&&(v=x(),v===s&&(v=L_(),v===s&&(v=Su(),v===s&&(v=tn(),v===s&&(v=x_()))))),ge[w]={nextPos:y,result:v},v)}function tn(){var v,w,P,X,oe=y*56+24,ve=ge[oe];if(ve)return y=ve.nextPos,ve.result;if(v=y,i.charCodeAt(y)===60?(w=E,y++):(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(y)===62?(X=I,y++):(X=s,Oe===0&&f(ye)),X!==s?(He=v,v=Ua(P)):(y=v,v=s)):(y=v,v=s)}else y=v,v=s;return ge[oe]={nextPos:y,result:v},v}function it(){var v,w,P,X,oe,ve=y*56+25,ft=ge[ve];return ft?(y=ft.nextPos,ft.result):(v=y,i.charCodeAt(y)===40?(w=Z,y++):(w=s,Oe===0&&f(dt)),w!==s?(i.charCodeAt(y)===58?y++:Oe===0&&f(lt),P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(y)===41?(oe=h,y++):(oe=s,Oe===0&&f(Kt)),oe!==s?(He=v,v=Fa(P,X)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[ve]={nextPos:y,result:v},v)}function pt(){var v,w,P,X=y*56+26,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,i.charCodeAt(y)===58?(w=D,y++):(w=s,Oe===0&&f(lt)),w!==s?(P=x(),P!==s?(He=v,v=Ys(P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function sn(){var v,w,P,X,oe=y*56+27,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,w=it(),w!==s?(P=k_(),P!==s?(X=it(),X!==s?(He=v,v=Ya(w,P,X)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function Qt(){var v,w,P,X,oe,ve=y*56+28,ft=ge[ve];return ft?(y=ft.nextPos,ft.result):(v=y,i.substr(y,2)===b?(w=b,y+=2):(w=s,Oe===0&&f(Tt)),w!==s?(P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(y)===93?(oe=S,y++):(oe=s,Oe===0&&f(Ue)),oe!==s?(He=v,v=$s(P,X)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[ve]={nextPos:y,result:v},v)}function qt(){var v,w,P,X,oe=y*56+29,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,i.charCodeAt(y)===91?(w=N,y++):(w=s,Oe===0&&f(Fn)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(y)===93?(X=S,y++):(X=s,Oe===0&&f(Ue)),X!==s?(He=v,v=$a(P)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function fr(){var v,w=y*56+30,P=ge[w];return P?(y=P.nextPos,P.result):(v=x(),v===s&&(v=C()),ge[w]={nextPos:y,result:v},v)}function Zs(){var v,w,P,X=y*56+31,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,w=[],P=Sl(),P===s&&(P=fr()),P!==s)for(;P!==s;)w.push(P),P=Sl(),P===s&&(P=fr());else w=s;return w!==s&&(He=v,w=Gs(w)),v=w,ge[X]={nextPos:y,result:v},v}function Sl(){var v,w,P,X,oe=y*56+32,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,i.charCodeAt(y)===40?y++:Oe===0&&f(dt),w=fr(),w!==s?(P=k_(),P!==s?(X=Zs(),X!==s?(i.charCodeAt(y)===41?y++:Oe===0&&f(Kt),He=v,v=Qs()):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function Ks(){var v,w,P,X,oe=y*56+33,ve=ge[oe];if(ve)return y=ve.nextPos,ve.result;if(v=y,i.charCodeAt(y)===123?(w=k,y++):(w=s,Oe===0&&f(Qr)),w!==s){if(P=[],X=Zs(),X===s&&(X=F()),X!==s)for(;X!==s;)P.push(X),X=Zs(),X===s&&(X=F());else P=s;P!==s?(i.charCodeAt(y)===125?(X=L,y++):(X=s,Oe===0&&f(ct)),X!==s?(He=v,v=dr(P)):(y=v,v=s)):(y=v,v=s)}else y=v,v=s;return ge[oe]={nextPos:y,result:v},v}function x_(){var v,w,P,X,oe=y*56+34,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,i.charCodeAt(y)===123?(w=k,y++):(w=s,Oe===0&&f(Qr)),w!==s?(P=x(),P===s&&(P=Su()),P!==s?(i.charCodeAt(y)===125?(X=L,y++):(X=s,Oe===0&&f(ct)),X!==s?(He=v,v=Ot(P)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function k_(){var v,w=y*56+35,P=ge[w];return P?(y=P.nextPos,P.result):(i.charCodeAt(y)===43?(v=M,y++):(v=s,Oe===0&&f(Wn)),v===s&&(i.charCodeAt(y)===45?(v=u,y++):(v=s,Oe===0&&f(rn)),v===s&&(i.charCodeAt(y)===42?(v=G,y++):(v=s,Oe===0&&f(Nn)),v===s&&(i.charCodeAt(y)===47?(v=Y,y++):(v=s,Oe===0&&f(Hn)),v===s&&(i.charCodeAt(y)===37?(v=te,y++):(v=s,Oe===0&&f(Ai)),v===s&&(i.charCodeAt(y)===94?(v=re,y++):(v=s,Oe===0&&f(wn)),v===s&&(i.charCodeAt(y)===124?(v=_,y++):(v=s,Oe===0&&f(H)),v===s&&(i.charCodeAt(y)===38?(v=ne,y++):(v=s,Oe===0&&f(Wt)),v===s&&(i.substr(y,2)===ee?(v=ee,y+=2):(v=s,Oe===0&&f(Ar)),v===s&&(i.substr(y,2)===B?(v=B,y+=2):(v=s,Oe===0&&f(ra))))))))))),ge[w]={nextPos:y,result:v},v)}function js(){var v,w,P=y*56+36,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=BR(),w===s&&(w=$R(),w===s&&(w=YR(),w===s&&(w=GR(),w===s&&(w=U(),w===s&&(w=FR(),w===s&&(w=Ol(),w===s&&(w=LR(),w===s&&(w=F(),w===s&&(w=MR(),w===s&&(w=it(),w===s&&(w=Ks(),w===s&&(w=kR())))))))))))),w!==s&&(He=v,w=qs(w)),v=w,ge[P]={nextPos:y,result:v},v)}function kR(){var v,w,P=y*56+37,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,i.charCodeAt(y)===124?(w=_,y++):(w=s,Oe===0&&f(H)),w!==s&&(He=v,w=Ii()),v=w,ge[P]={nextPos:y,result:v},v)}function gu(){var v,w,P,X,oe=y*56+38,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,i.charCodeAt(y)===60?(w=E,y++):(w=s,Oe===0&&f(Je)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(y)===62?(X=I,y++):(X=s,Oe===0&&f(ye)),X!==s?(He=v,v=Vs(P)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function LR(){var v,w,P=y*56+39,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=_u(),w!==s&&(He=v,w=pi(w)),v=w,ge[P]={nextPos:y,result:v},v)}function _u(){var v,w,P,X=y*56+40,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,w=[],i.charCodeAt(y)===94?(P=re,y++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(y)===95?(P=Q,y++):(P=s,Oe===0&&f(li))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(y)===94?(P=re,y++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(y)===95?(P=Q,y++):(P=s,Oe===0&&f(li)));else w=s;return w!==s&&(He=v,w=zs()),v=w,ge[X]={nextPos:y,result:v},v}function L_(){var v,w,P=y*56+41,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,i.charCodeAt(y)===63?(w=j,y++):(w=s,Oe===0&&f(ia)),w!==s&&(He=v,w=Ri()),v=w,ge[P]={nextPos:y,result:v},v)}function Su(){var v,w,P,X,oe,ve,ft=y*56+42,hr=ge[ft];return hr?(y=hr.nextPos,hr.result):(v=y,i.charCodeAt(y)===40?(w=Z,y++):(w=s,Oe===0&&f(dt)),w!==s?(P=x(),P!==s?(i.charCodeAt(y)===44?(X=m,y++):(X=s,Oe===0&&f(an)),X!==s?(oe=x(),oe!==s?(i.charCodeAt(y)===41?(ve=h,y++):(ve=s,Oe===0&&f(Kt)),ve!==s?(He=v,v=Ga(P,oe)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[ft]={nextPos:y,result:v},v)}function M_(){var v,w,P,X,oe=y*56+43,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,w=Se(),w===s&&(w=Ce(),w===s&&(w=ae(),w===s&&(w=js()))),w!==s?(i.charCodeAt(y)===33?(P=K,y++):(P=s,Oe===0&&f(ur)),P!==s?(X=x(),X!==s?(He=v,v=Qa(w,X)):(y=v,v=s)):(y=v,v=s)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function MR(){var v,w,P=y*56+44,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=Fe(),w!==s&&(He=v,w=Hs(w)),v=w,ge[P]={nextPos:y,result:v},v)}function PR(){var v,w,P,X=y*56+45,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,w=Fe(),w!==s?(i.charCodeAt(y)===94?(P=re,y++):(P=s,Oe===0&&f(wn)),P!==s?(He=v,v=Ni(w)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function BR(){var v,w,P,X,oe,ve=y*56+46,ft=ge[ve];return ft?(y=ft.nextPos,ft.result):(v=y,w=PR(),w===s&&(w=null),i.charCodeAt(y)===114?(P=ue,y++):(P=s,Oe===0&&f(ci)),P!==s?(X=y,Oe++,At.test(i.charAt(y))?(oe=i.charAt(y),y++):(oe=s,Oe===0&&f(Ir)),Oe--,oe===s?X=void 0:(y=X,X=s),X!==s?(He=v,v=qa(w)):(y=v,v=s)):(y=v,v=s),ge[ve]={nextPos:y,result:v},v)}function Ol(){var v,w,P,X,oe,ve=y*56+47,ft=ge[ve];return ft?(y=ft.nextPos,ft.result):(v=y,w=_u(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=UR(),X===s&&(X=null),oe=C(),oe===s&&(oe=L_(),oe===s&&(oe=Su(),oe===s&&(oe=x_()))),oe!==s?(He=v,v=wi(w,P,X,oe)):(y=v,v=s),ge[ve]={nextPos:y,result:v},v)}function UR(){var v,w,P,X=y*56+48,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,w=[],i.charCodeAt(y)===35?(P=le,y++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(y)===98?(P=be,y++):(P=s,Oe===0&&f(ui))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(y)===35?(P=le,y++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(y)===98?(P=be,y++):(P=s,Oe===0&&f(ui)));else w=s;return w!==s&&(He=v,w=Di(w)),v=w,ge[X]={nextPos:y,result:v},v}function FR(){var v,w,P,X,oe=y*56+49,ve=ge[oe];if(ve)return y=ve.nextPos,ve.result;if(v=y,w=Ol(),w!==s){if(P=[],X=Ol(),X!==s)for(;X!==s;)P.push(X),X=Ol();else P=s;P!==s?(X=Ou(),X===s&&(X=null),He=v,v=Va(w,P,X)):(y=v,v=s)}else y=v,v=s;return ge[oe]={nextPos:y,result:v},v}function P_(){var v,w,P,X=y*56+50,oe=ge[X];if(oe)return y=oe.nextPos,oe.result;if(v=y,w=[],Nt.test(i.charAt(y))?(P=i.charAt(y),y++):(P=s,Oe===0&&f(di)),P!==s)for(;P!==s;)w.push(P),Nt.test(i.charAt(y))?(P=i.charAt(y),y++):(P=s,Oe===0&&f(di));else w=s;return w!==s&&(He=v,w=sa()),v=w,ge[X]={nextPos:y,result:v},v}function Ou(){var v,w,P,X=y*56+51,oe=ge[X];return oe?(y=oe.nextPos,oe.result):(v=y,i.charCodeAt(y)===37?(w=te,y++):(w=s,Oe===0&&f(Ai)),w!==s?(P=x(),P!==s?(He=v,v=fi(P)):(y=v,v=s)):(y=v,v=s),ge[X]={nextPos:y,result:v},v)}function B_(){var v,w,P=y*56+52,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,Rn.test(i.charAt(y))?(w=i.charAt(y),y++):(w=s,Oe===0&&f(q)),w!==s?(qe.test(i.charAt(y))?(i.charAt(y),y++):Oe===0&&f(ie),He=v,v=_n()):(y=v,v=s),ge[P]={nextPos:y,result:v},v)}function YR(){var v,w,P,X,oe,ve,ft=y*56+53,hr=ge[ft];return hr?(y=hr.nextPos,hr.result):(v=y,w=_u(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=B_(),X!==s?(i.charCodeAt(y)===94?y++:Oe===0&&f(wn),oe=P_(),oe!==s?(ve=Ou(),ve===s&&(ve=null),He=v,v=za(w,P,X,oe,ve)):(y=v,v=s)):(y=v,v=s),ge[ft]={nextPos:y,result:v},v)}function $R(){var v,w,P,X,oe=y*56+54,ve=ge[oe];return ve?(y=ve.nextPos,ve.result):(v=y,i.substr(y,3)===De?(w=De,y+=3):(w=s,Oe===0&&f(de)),w===s&&(i.substr(y,2)===xe?(w=xe,y+=2):(w=s,Oe===0&&f(_e)),w===s&&(i.substr(y,2)===Ee?(w=Ee,y+=2):(w=s,Oe===0&&f(Ae)),w===s&&(i.charCodeAt(y)===105?(w=Ne,y++):(w=s,Oe===0&&f(Qe)),w===s&&(i.substr(y,3)===ce?(w=ce,y+=3):(w=s,Oe===0&&f(Pe)),w===s&&(i.substr(y,2)===Le?(w=Le,y+=2):(w=s,Oe===0&&f(Ct)),w===s&&(i.charCodeAt(y)===118?(w=Xe,y++):(w=s,Oe===0&&f(Dn)))))))),w!==s?(i.charCodeAt(y)===94?y++:Oe===0&&f(wn),P=P_(),P===s&&(P=null),X=Ou(),X===s&&(X=null),He=v,v=Kn(w,P,X)):(y=v,v=s),ge[oe]={nextPos:y,result:v},v)}function GR(){var v,w,P=y*56+55,X=ge[P];return X?(y=X.nextPos,X.result):(v=y,w=B_(),w!==s&&(He=v,w=oa(w)),v=w,ge[P]={nextPos:y,result:v},v)}var U_=a.nodeOptions||{};function Ut(v,w,P=void 0){w.text=P||$n(),w.location=ml();for(var X in U_)(w[X]===void 0||w[X]===null)&&(w[X]=U_[X]);return new v(w)}if(la=c(),la!==s&&y===i.length)return la;throw la!==s&&y1&&(c=c.slice(1));const u=c.map(p=>isNaN(parseInt(p))?p:parseInt(p));return o(...u).toString()}return o.toString()}}return a[0]}const i=new RegExp(t.join("|"),"g");return r.replace(i,a=>n(a))}function f5(r,e,t){let n=r;for(let i=0;ie.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 ri(this)}notStarted(){return this.index<0}peek(){return this.evaluated[this.index-1||0]}hasStarted(){return this.index>=0}reset(){this.index=-1,this.counter=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=CR(n)),n}totalDuration(){return this.evaluated.reduce((t,n)=>t+n.collect("duration"),0)}lead(){let e=this.evaluated.findIndex(t=>t instanceof $r);if(e>=0){for(let t=e+1;t<=this.evaluated.length;t++)if(this.evaluated[t]instanceof $r){const n=this.evaluated[e],i=this.evaluated[t],a=u5(n.notes(),i.notes()),s=ri(i);s.voiceLeadFromNotes(a,this.options.nodeOptions),this.evaluated[t]=s,e=t}}return this}toString(){return this.evaluated.map(e=>e.toString()).join(" ")}rules(e,t=1){const n=f5(this.input,e,t);return new N_(n,this.options.nodeOptions,this.globalOptions)}tonnetzChords(e,t=[3,4,5]){return this.evaluated&&(this.evaluated=this.evaluated.map(n=>n instanceof zn?n.tonnetzChord(e,t):n)),this}tonnetzTransformation(e,t=[3,4,5]){return this.evaluated&&(this.evaluated=this.evaluated.map(n=>n instanceof $r?n.triadTransformation(e,t):n)),this}}const CR=(r,e=void 0)=>r.map(n=>{if(n instanceof _R){const i=n.evaluated.length,a=(e||n.duration)/i;return CR(n.evaluated,a)}else return n.duration=e||n.duration,n}).flat(1/0),h5=r=>{let e={};return UG.forEach(t=>{if(r[t]!==void 0){const n=r[t];e[t]=n,delete r[t]}}),e};class m5{constructor(e,t){A(this,"api");A(this,"settings");A(this,"midiAccess",null);A(this,"midiOutputs",[]);A(this,"currentOutputIndex",0);A(this,"scheduledNotes",{});A(this,"midiInputs",[]);A(this,"currentInputIndex");A(this,"bufferLength",512);A(this,"noteInputBuffer",[]);A(this,"ccInputBuffer",[]);A(this,"activeNotes",[]);A(this,"stickyNotes",[]);A(this,"lastNote");A(this,"lastCC",{});A(this,"lastNoteInChannel",{});A(this,"lastCCInChannel",{});A(this,"midiClockInputIndex");A(this,"midiClockInput");A(this,"lastTimestamp",0);A(this,"midiClockDelta",0);A(this,"lastBPM");A(this,"roundedBPM",0);A(this,"clockBuffer",[]);A(this,"clockBufferLength",24);A(this,"clockTicks",0);A(this,"clockErrorCount",0);A(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 g5{constructor(e,t,n){A(this,"min");A(this,"max");A(this,"wrap");A(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 w_{constructor(e){A(this,"seedValue");A(this,"randomGen",Math.random);A(this,"app");A(this,"values",{});A(this,"evenbar",e=>this.app.clock.time_position.bar%2===0?this.modify(e):this);A(this,"even",e=>this.app.clock.time_position.beat%2===0?this.modify(e):this);A(this,"odd",e=>this.app.clock.time_position.beat%2!==0?this.modify(e):this);A(this,"odds",(e,t)=>this.randomGen()this);A(this,"almostNever",e=>this.odds(.025,e));A(this,"rarely",e=>this.odds(.1,e));A(this,"scarcely",e=>this.odds(.25,e));A(this,"sometimes",e=>this.odds(.5,e));A(this,"often",e=>this.odds(.75,e));A(this,"frequently",e=>this.odds(.9,e));A(this,"almostAlways",e=>this.odds(.985,e));A(this,"always",e=>this.modify(e));A(this,"modify",e=>e(this));A(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));A(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));A(this,"apply",e=>this.modify(e));A(this,"noteLength",(e,...t)=>(t.length>0&&(e=Array.isArray(e)?e.concat(t):[e,...t]),Array.isArray(e)?(this.values.noteLength=e,this.values.dur=e.map(n=>this.app.clock.convertPulseToSecond(n*4*this.app.clock.ppqn))):(this.values.noteLength=e,this.values.dur=this.app.clock.convertPulseToSecond(e*4*this.app.clock.ppqn)),this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class yR extends w_{constructor(t){super(t);A(this,"pitch",(t,...n)=>(n.length>0&&(t=Array.isArray(t)?t.concat(n):[t,...n]),this.values.pitch=t,this.values.key&&this.values.parsedScale&&this.update(),this));A(this,"pc",this.pitch);A(this,"octave",(t,...n)=>(n.length>0&&(t=Array.isArray(t)?t.concat(n):[t,...n]),this.values.octave=t,this.values.key&&(this.values.pitch||this.values.pitch===0)&&this.values.parsedScale&&this.update(),this));A(this,"key",(t,...n)=>(n.length>0&&(t=Array.isArray(t)?t.concat(n):[t,...n]),this.values.key=t,(this.values.pitch||this.values.pitch===0)&&this.values.parsedScale&&this.update(),this));A(this,"scale",(t,...n)=>(n.length>0&&(t=Array.isArray(t)?t.concat(n):[t,...n]),typeof t=="string"||typeof t=="number"?this.values.parsedScale=ta(t):Array.isArray(t)&&(this.values.parsedScale=t.map(i=>ta(i))),this.values.key&&(this.values.pitch||this.values.pitch===0)&&this.update(),this));A(this,"freq",(t,...n)=>{if(n.length>0&&(t=Array.isArray(t)?t.concat(n):[t,...n]),this.values.freq=t,Array.isArray(t)){this.values.note=[],this.values.bend=[];for(const i of t){const a=CT(i);a%1!==0?(this.values.note.push(Math.floor(a)),this.values.bend.push(sg(a)[1])):this.values.note.push(a)}this.values.bend.length===0&&delete this.values.bend}else{const i=CT(t);i%1!==0?(this.values.note=Math.floor(i),this.values.bend=sg(i)[1]):this.values.note=i}return this});A(this,"update",()=>{})}}function Hc(r,e){e.forEach(a=>{Array.isArray(r[a])&&!Array.isArray(r[a][0])&&(r[a]=[r[a]])});const t=Object.keys(r),n=Math.max(...t.map(a=>Array.isArray(r[a])?r[a].length:1)),i=[];for(let a=0;a(Object.keys(e).forEach(i=>{n[i]=e[i]}),Object.keys(n).forEach(i=>{t[i]||(t[i]=[]),t[i].push(n[i])}),t),{})}function AR(r,e){return Object.fromEntries(Object.entries(r).filter(([t])=>e.includes(t)))}class lg extends yR{constructor(t,n){super(n);A(this,"nudge");A(this,"sound");A(this,"methodMap",{volume:["volume","vol"],zrand:["zrand","zr"],curve:["curve"],slide:["slide","sld"],deltaSlide:["deltaSlide","dslide"],pitchJump:["pitchJump","pj"],pitchJumpTime:["pitchJumpTime","pjt"],lfo:["lfo"],znoise:["znoise"],noise:["noise"],zmod:["zmod"],zcrush:["zcrush"],zdelay:["zdelay"],sustainVolume:["sustainVolume"],tremolo:["tremolo"],dur:["dur"],zzfx:["zzfx"],fmi:["fmi"],fmh:["fmh"],fmenv:["fmenv"],fmattack:["fmattack","fmatk"],fmdecay:["fmdecay","fmdec"],fmsustain:["fmsustain","fmsus"],fmrelease:["fmrelease","fmrel"],fmvelocity:["fmvelocity","fmvel"],fmwave:["fmwave","fmw"],fmadsr:(t,n,i,a)=>(this.updateValue("fmattack",t),this.updateValue("fmdecay",n),this.updateValue("fmsustain",i),this.updateValue("fmrelease",a),this),fmad:(t,n)=>(this.updateValue("fmattack",t),this.updateValue("fmdecay",n),this),ftype:["ftype"],fanchor:["fanchor"],attack:["attack","atk"],decay:["decay","dec"],sustain:["sustain","sus"],release:["release","rel"],adsr:(t,n,i,a)=>(this.updateValue("attack",t),this.updateValue("decay",n),this.updateValue("sustain",i),this.updateValue("release",a),this),ad:(t,n)=>(this.updateValue("attack",t),this.updateValue("decay",n),this.updateValue("sustain",0),this.updateValue("release",0),this),lpenv:["lpenv","lpe"],lpattack:["lpattack","lpa"],lpdecay:["lpdecay","lpd"],lpsustain:["lpsustain","lps"],lprelease:["lprelease","lpr"],cutoff:(t,n)=>(this.updateValue("cutoff",t),n&&this.updateValue("resonance",n),this),lpf:(t,n)=>(this.updateValue("cutoff",t),n&&this.updateValue("resonance",n),this),resonance:t=>(t>=0&&t<=1&&this.updateValue("resonance",50*t),this),lpadsr:(t,n,i,a,s)=>(this.updateValue("lpenv",t),this.updateValue("lpattack",n),this.updateValue("lpdecay",i),this.updateValue("lpsustain",a),this.updateValue("lprelease",s),this),lpad:(t,n,i)=>(this.updateValue("lpenv",t),this.updateValue("lpattack",n),this.updateValue("lpdecay",i),this.updateValue("lpsustain",0),this.updateValue("lprelease",0),this),hpenv:["hpenv","hpe"],hpattack:["hpattack","hpa"],hpdecay:["hpdecay","hpd"],hpsustain:["hpsustain","hpsus"],hprelease:["hprelease","hpr"],hcutoff:(t,n)=>(this.updateValue("hcutoff",t),n&&this.updateValue("hresonance",n),this),hpq:t=>(this.updateValue("hresonance",t),this),hpadsr:(t,n,i,a,s)=>(this.updateValue("hpenv",t),this.updateValue("hpattack",n),this.updateValue("hpdecay",i),this.updateValue("hpsustain",a),this.updateValue("hprelease",s),this),hpad:(t,n,i)=>(this.updateValue("hpenv",t),this.updateValue("hpattack",n),this.updateValue("hpdecay",i),this.updateValue("hpsustain",0),this.updateValue("hprelease",0),this),bpenv:["bpenv","bpe"],bpattack:["bpattack","bpa"],bpdecay:["bpdecay","bpd"],bpsustain:["bpsustain","bps"],bprelease:["bprelease","bpr"],bandf:(t,n)=>(this.updateValue("bandf",t),n&&this.updateValue("bandq",n),this),bpf:(t,n)=>(this.updateValue("bandf",t),n&&this.updateValue("bandq",n),this),bandq:["bandq","bpq"],bpadsr:(t,n,i,a,s)=>(this.updateValue("bpenv",t),this.updateValue("bpattack",n),this.updateValue("bpdecay",i),this.updateValue("bpsustain",a),this.updateValue("bprelease",s),this),bpad:(t,n,i)=>(this.updateValue("bpenv",t),this.updateValue("bpattack",n),this.updateValue("bpdecay",i),this.updateValue("bpsustain",0),this.updateValue("bprelease",0),this),vib:["vib"],vibmod:["vibmod"],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},loop:["loop"],loopBegin:["loopBegin","loopb"],loopEnd:["loopEnd","loope"],begin:["begin"],end:["end"],gain:["gain"],dbgain:t=>(this.updateValue("gain",Math.min(Math.pow(10,t/20),10)),this),db:t=>(this.updateValue("gain",Math.min(Math.pow(10,t/20),10)),this),velocity:["velocity","vel"],pan:["pan"],cut:["cut"],clip:["clip"],n:["n"],speed:["speed","spd"],coarse:["coarse"],crush:["crush"],shape:["shape"],vowel:["vowel","vow"],delay:["delay","del"],delayfeedback:["delayfeedback","delayfb"],delaytime:["delaytime","delayt"],orbit:["orbit","o"],room:["room","rm"],roomfade:["roomfade","rfade"],roomlp:["roomlp","rlp"],roomdim:["roomdim","rdim"],sound:["sound","s"],size:t=>(this.updateValue("roomsize",t),this),sz:t=>(this.updateValue("roomsize",t),this),comp:["compressor","cmp"],ratio:t=>(this.updateValue("compressorRatio",t),this),knee:t=>(this.updateValue("compressorKnee",t),this),compAttack:t=>(this.updateValue("compressorAttack",t),this),compRelease:t=>(this.updateValue("compressorRelease",t),this),stretch:t=>(this.updateValue("unit","c"),this.updateValue("speed",1/t),this.updateValue("cut",t),this)});A(this,"processSound",t=>{if(Array.isArray(t)&&typeof t[0]=="string"){const n=[],i=[];return t.forEach(a=>{const s=a.split(":");n.push(s[0]),s[1]&&i.push(parseInt(s[1]))}),{s:n,n:i.length>0?i:void 0,dur:this.app.clock.convertPulseToSecond(this.app.clock.ppqn),analyze:!0}}else{if(typeof t=="object")return{dur:this.app.clock.convertPulseToSecond(this.app.clock.ppqn),analyze:!0,...t};if(t.includes(":")){const n=t.split(":"),i=n[0],a=parseInt(n[1]);return{s:i,n:a,dur:this.app.clock.convertPulseToSecond(this.app.clock.ppqn),analyze:!0}}else return{s:t,dur:.5,analyze:!0}}});A(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});A(this,"update",()=>{const t=AR(this.values,["key","pitch","parsedScale","octave"]),n=Hc(t,["parsedScale"]);n.forEach(a=>{const[s,o]=I_(a.key||"C4",a.pitch||0,a.parsedScale||a.scale||"MAJOR",a.octave||0);a.note=s,a.freq=Ns(s)});const i=Wc(n);this.values.note=i.note,this.values.freq=i.freq});A(this,"chord",t=>{const n=bR(t);return this.updateValue("note",n)});A(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:Ns(a)}));return this.updateValue("chord",i)}else return this});A(this,"note",t=>typeof t=="string"?this.updateValue("note",yr(t)):typeof t==null||t==null?this.updateValue("note",0).updateValue("gain",0):this.updateValue("note",t));A(this,"out",()=>{const t=Hc(this.values,["parsedScale"]);for(const n of t)f2(n,this.nudge+this.app.clock.deviation,n.dur)});this.app=n,this.nudge=n.dough_nudge/100;for(const[i,a]of Object.entries(this.methodMap))if(Symbol.iterator in Object(a))for(const s of a)this[s]=o=>this.updateValue(a[0],o);else this[i]=a;this.values=this.processSound(t)}updateValue(t,n){return n==null?this:(this.values[t]=n,this)}}class cg extends yR{constructor(t,n){super(n);A(this,"midiConnection");A(this,"chord",t=>(this.values.note=bR(t),this));A(this,"note",t=>(this.values.note=t,this));A(this,"sustain",t=>(this.values.sustain=t,this));A(this,"velocity",t=>(this.values.velocity=t,this));A(this,"channel",t=>(this.values.channel=t,this));A(this,"port",t=>(typeof t=="string"?this.values.port=this.midiConnection.getMidiOutputIndex(t):Array.isArray(t)&&(this.values.port=t.map(n=>typeof n=="string"?this.midiConnection.getMidiOutputIndex(n):n)),this));A(this,"add",t=>(this.values.note+=t,this));A(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});A(this,"bend",t=>(this.values.bend=t,this));A(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));A(this,"update",()=>{const t=AR(this.values,["key","pitch","parsedScale","octave"]),n=Hc(t,["parsedScale"]);n.forEach(a=>{const[s,o]=I_(a.key||"C4",a.pitch||0,a.parsedScale||a.scale||"MAJOR",a.octave||0);a.note=s,o&&(a.bend=o)});const i=Wc(n);this.values.note=i.note,i.bend&&(this.values.bend=i.bend)});A(this,"out",()=>{function t(i,a){const s=a.channel?a.channel:0,o=a.velocity?a.velocity:100,l=a.note?a.note:60,c=a.sustain?a.sustain*i.app.clock.pulse_duration*i.app.api.ppqn():i.app.clock.pulse_duration*i.app.api.ppqn(),u=a.bend?a.bend:void 0,p=a.port?i.midiConnection.getMidiOutputIndex(a.port):i.midiConnection.getCurrentMidiPortIndex()||0;i.midiConnection.sendMidiNote(l,s,o,c,p,u)}Hc(this.values,["parsedScale"]).forEach(i=>{t(this,i)})});this.app=n,this.values=t,this.midiConnection=n.api.MidiConnection}}const ho=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,IR=new Set,ug=typeof process=="object"&&process?process:{},RR=(r,e,t,n)=>{typeof ug.emitWarning=="function"?ug.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)};let Xc=globalThis.AbortController,yT=globalThis.AbortSignal;var IT;if(typeof Xc>"u"){yT=class{constructor(){A(this,"onabort");A(this,"_onabort",[]);A(this,"reason");A(this,"aborted",!1)}addEventListener(n,i){this._onabort.push(i)}},Xc=class{constructor(){A(this,"signal",new yT);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=((IT=ug.env)==null?void 0:IT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{r&&(r=!1,RR("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 _5=r=>!IR.has(r),Pi=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),NR=r=>Pi(r)?r<=Math.pow(2,8)?Uint8Array:r<=Math.pow(2,16)?Uint16Array:r<=Math.pow(2,32)?Uint32Array:r<=Number.MAX_SAFE_INTEGER?oc:null:null;class oc extends Array{constructor(e){super(e),this.fill(0)}}var us;const ma=class ma{constructor(e,t){A(this,"heap");A(this,"length");if(!V(ma,us))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=NR(e);if(!t)return[];We(ma,us,!0);const n=new ma(e,t);return We(ma,us,!1),n}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};us=new WeakMap,at(ma,us,!1);let dg=ma;var wr,tr,Dr,xr,ds,on,kr,ln,Lt,nt,Ln,nr,Cn,hn,Lr,mn,_i,Si,Mr,Pr,qi,Mn,tl,fg,Ea,Oi,nl,rr,Kc,wR,va,ps,rl,Wr,Bi,Xr,Ui,il,hg,fs,lc,hs,cc,Dt,Ft,al,mg,Ta,vo;const D_=class D_{constructor(e){at(this,tl);at(this,Kc);at(this,Wr);at(this,Xr);at(this,il);at(this,fs);at(this,hs);at(this,Dt);at(this,al);at(this,Ta);at(this,wr,void 0);at(this,tr,void 0);at(this,Dr,void 0);at(this,xr,void 0);at(this,ds,void 0);A(this,"ttl");A(this,"ttlResolution");A(this,"ttlAutopurge");A(this,"updateAgeOnGet");A(this,"updateAgeOnHas");A(this,"allowStale");A(this,"noDisposeOnSet");A(this,"noUpdateTTL");A(this,"maxEntrySize");A(this,"sizeCalculation");A(this,"noDeleteOnFetchRejection");A(this,"noDeleteOnStaleGet");A(this,"allowStaleOnFetchAbort");A(this,"allowStaleOnFetchRejection");A(this,"ignoreFetchAbort");at(this,on,void 0);at(this,kr,void 0);at(this,ln,void 0);at(this,Lt,void 0);at(this,nt,void 0);at(this,Ln,void 0);at(this,nr,void 0);at(this,Cn,void 0);at(this,hn,void 0);at(this,Lr,void 0);at(this,mn,void 0);at(this,_i,void 0);at(this,Si,void 0);at(this,Mr,void 0);at(this,Pr,void 0);at(this,qi,void 0);at(this,Mn,void 0);at(this,Ea,()=>{});at(this,Oi,()=>{});at(this,nl,()=>{});at(this,rr,()=>!1);at(this,va,e=>{});at(this,ps,(e,t,n)=>{});at(this,rl,(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:E=0,sizeCalculation:I,fetchMethod:R,noDeleteOnFetchRejection:D,noDeleteOnStaleGet:Y,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:h,ignoreFetchAbort:b}=e;if(t!==0&&!Pi(t))throw new TypeError("max option must be a nonnegative integer");const S=t?NR(t):Array;if(!S)throw new Error("invalid max value: "+t);if(We(this,wr,t),We(this,tr,_),this.maxEntrySize=E||V(this,tr),this.sizeCalculation=I,this.sizeCalculation){if(!V(this,tr)&&!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,ds,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,nr,new S(t)),We(this,Cn,0),We(this,hn,0),We(this,Lr,dg.create(t)),We(this,on,0),We(this,kr,0),typeof c=="function"&&We(this,Dr,c),typeof u=="function"?(We(this,xr,u),We(this,mn,[])):(We(this,xr,void 0),We(this,mn,void 0)),We(this,Pr,!!V(this,Dr)),We(this,Mn,!!V(this,xr)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!D,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!h,this.ignoreFetchAbort=!!b,this.maxEntrySize!==0){if(V(this,tr)!==0&&!Pi(V(this,tr)))throw new TypeError("maxSize must be a positive integer if specified");if(!Pi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");ze(this,Kc,wR).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!Y,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Pi(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!Pi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");ze(this,tl,fg).call(this)}if(V(this,wr)===0&&this.ttl===0&&V(this,tr)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!V(this,wr)&&!V(this,tr)){const N="LRU_CACHE_UNBOUNDED";_5(N)&&(IR.add(N),RR("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",N,D_))}}static unsafeExposeInternals(e){return{starts:V(e,Si),ttls:V(e,Mr),sizes:V(e,_i),keyMap:V(e,ln),keyList:V(e,Lt),valList:V(e,nt),next:V(e,Ln),prev:V(e,nr),get head(){return V(e,Cn)},get tail(){return V(e,hn)},free:V(e,Lr),isBackgroundFetch:t=>{var n;return ze(n=e,Dt,Ft).call(n,t)},backgroundFetch:(t,n,i,a)=>{var s;return ze(s=e,hs,cc).call(s,t,n,i,a)},moveToTail:t=>{var n;return ze(n=e,Ta,vo).call(n,t)},indexes:t=>{var n;return ze(n=e,Wr,Bi).call(n,t)},rindexes:t=>{var n;return ze(n=e,Xr,Ui).call(n,t)},isStale:t=>{var n;return V(n=e,rr).call(n,t)}}}get max(){return V(this,wr)}get maxSize(){return V(this,tr)}get calculatedSize(){return V(this,kr)}get size(){return V(this,on)}get fetchMethod(){return V(this,ds)}get dispose(){return V(this,Dr)}get disposeAfter(){return V(this,xr)}getRemainingTTL(e){return V(this,ln).has(e)?1/0:0}*entries(){for(const e of ze(this,Wr,Bi).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,Xr,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]])}*keys(){for(const e of ze(this,Wr,Bi).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,Xr,Ui).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,Wr,Bi).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,Xr,Ui).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,Wr,Bi).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,Wr,Bi).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,Xr,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)}}purgeStale(){let e=!1;for(const t of ze(this,Xr,Ui).call(this,{allowStale:!0}))V(this,rr).call(this,t)&&(this.delete(V(this,Lt)[t]),e=!0);return e}dump(){const e=[];for(const t of ze(this,Wr,Bi).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,Mr)&&V(this,Si)){s.ttl=V(this,Mr)[t];const o=ho.now()-V(this,Si)[t];s.start=Math.floor(Date.now()-o)}V(this,_i)&&(s.size=V(this,_i)[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=ho.now()-i}this.set(t,n.value,n)}}set(e,t,n={}){var m,_,E,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,rl).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,Lr).length!==0?V(this,Lr).pop():V(this,on)===V(this,wr)?ze(this,fs,lc).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,nr)[p]=V(this,hn),We(this,hn,p),bl(this,on)._++,V(this,ps).call(this,p,u,l),l&&(l.set="add"),c=!1;else{ze(this,Ta,vo).call(this,p);const D=V(this,nt)[p];if(t!==D){if(V(this,qi)&&ze(this,Dt,Ft).call(this,D)){D.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:Y}=D;Y!==void 0&&!s&&(V(this,Pr)&&((m=V(this,Dr))==null||m.call(this,Y,e,"set")),V(this,Mn)&&((_=V(this,mn))==null||_.push([Y,e,"set"])))}else s||(V(this,Pr)&&((E=V(this,Dr))==null||E.call(this,D,e,"set")),V(this,Mn)&&((I=V(this,mn))==null||I.push([D,e,"set"])));if(V(this,va).call(this,p),V(this,ps).call(this,p,u,l),V(this,nt)[p]=t,l){l.set="replace";const Y=D&&ze(this,Dt,Ft).call(this,D)?D.__staleWhileFetching:D;Y!==void 0&&(l.oldValue=Y)}}else l&&(l.set="update")}if(i!==0&&!V(this,Mr)&&ze(this,tl,fg).call(this),V(this,Mr)&&(c||V(this,nl).call(this,p,i,a),l&&V(this,Oi).call(this,l,p)),!s&&V(this,Mn)&&V(this,mn)){const D=V(this,mn);let Y;for(;Y=D==null?void 0:D.shift();)(R=V(this,xr))==null||R.call(this,...Y)}return this}pop(){var e;try{for(;V(this,on);){const t=V(this,nt)[V(this,Cn)];if(ze(this,fs,lc).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,xr))==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,rr).call(this,a))i&&(i.has="stale",V(this,Oi).call(this,i,a));else return n&&V(this,Ea).call(this,a),i&&(i.has="hit",V(this,Oi).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,rr).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:E=this.allowStaleOnFetchAbort,context:I,forceRefresh:R=!1,status:D,signal:Y}=t;if(!V(this,qi))return D&&(D.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:D});const Z={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:u,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:E,ignoreFetchAbort:_,status:D,signal:Y};let h=V(this,ln).get(e);if(h===void 0){D&&(D.fetch="miss");const b=ze(this,hs,cc).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 D&&(D.fetch="inflight",M&&(D.returnedStale=!0)),M?b.__staleWhileFetching:b.__returned=b}const S=V(this,rr).call(this,h);if(!R&&!S)return D&&(D.fetch="hit"),ze(this,Ta,vo).call(this,h),i&&V(this,Ea).call(this,h),D&&V(this,Oi).call(this,D,h),b;const N=ze(this,hs,cc).call(this,e,h,Z,I),L=N.__staleWhileFetching!==void 0&&n;return D&&(D.fetch=S?"stale":"refresh",L&&S&&(D.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,Oi).call(this,s,o),V(this,rr).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,Ta,vo).call(this,o),i&&V(this,Ea).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,va).call(this,o);const l=V(this,nt)[o];ze(this,Dt,Ft).call(this,l)?l.__abortController.abort(new Error("deleted")):(V(this,Pr)||V(this,Mn))&&(V(this,Pr)&&((n=V(this,Dr))==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,nr)[o]):o===V(this,Cn)?We(this,Cn,V(this,Ln)[o]):(V(this,Ln)[V(this,nr)[o]]=V(this,Ln)[o],V(this,nr)[V(this,Ln)[o]]=V(this,nr)[o]),bl(this,on)._--,V(this,Lr).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,xr))==null||s.call(this,...l)}return t}clear(){var e,t,n;for(const i of ze(this,Xr,Ui).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,Pr)&&((e=V(this,Dr))==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,Mr)&&V(this,Si)&&(V(this,Mr).fill(0),V(this,Si).fill(0)),V(this,_i)&&V(this,_i).fill(0),We(this,Cn,0),We(this,hn,0),V(this,Lr).length=0,We(this,kr,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,xr))==null||n.call(this,...a)}}};wr=new WeakMap,tr=new WeakMap,Dr=new WeakMap,xr=new WeakMap,ds=new WeakMap,on=new WeakMap,kr=new WeakMap,ln=new WeakMap,Lt=new WeakMap,nt=new WeakMap,Ln=new WeakMap,nr=new WeakMap,Cn=new WeakMap,hn=new WeakMap,Lr=new WeakMap,mn=new WeakMap,_i=new WeakMap,Si=new WeakMap,Mr=new WeakMap,Pr=new WeakMap,qi=new WeakMap,Mn=new WeakMap,tl=new WeakSet,fg=function(){const e=new oc(V(this,wr)),t=new oc(V(this,wr));We(this,Mr,e),We(this,Si,t),We(this,nl,(a,s,o=ho.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{V(this,rr).call(this,a)&&this.delete(V(this,Lt)[a])},s+1);l.unref&&l.unref()}}),We(this,Ea,a=>{t[a]=e[a]!==0?ho.now():0}),We(this,Oi,(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=ho.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,rr,a=>e[a]!==0&&t[a]!==0&&(n||i())-t[a]>e[a])},Ea=new WeakMap,Oi=new WeakMap,nl=new WeakMap,rr=new WeakMap,Kc=new WeakSet,wR=function(){const e=new oc(V(this,wr));We(this,kr,0),We(this,_i,e),We(this,va,t=>{We(this,kr,V(this,kr)-e[t]),e[t]=0}),We(this,rl,(t,n,i,a)=>{if(ze(this,Dt,Ft).call(this,n))return 0;if(!Pi(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!Pi(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,ps,(t,n,i)=>{if(e[t]=n,V(this,tr)){const a=V(this,tr)-e[t];for(;V(this,kr)>a;)ze(this,fs,lc).call(this,!0)}We(this,kr,V(this,kr)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=V(this,kr))})},va=new WeakMap,ps=new WeakMap,rl=new WeakMap,Wr=new WeakSet,Bi=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,hn);!(!ze(this,il,hg).call(this,t)||((e||!V(this,rr).call(this,t))&&(yield t),t===V(this,Cn)));)t=V(this,nr)[t]},Xr=new WeakSet,Ui=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,Cn);!(!ze(this,il,hg).call(this,t)||((e||!V(this,rr).call(this,t))&&(yield t),t===V(this,hn)));)t=V(this,Ln)[t]},il=new WeakSet,hg=function(e){return e!==void 0&&V(this,ln).get(V(this,Lt)[e])===e},fs=new WeakSet,lc=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,Pr)||V(this,Mn))&&(V(this,Pr)&&((a=V(this,Dr))==null||a.call(this,i,n,"evict")),V(this,Mn)&&((s=V(this,mn))==null||s.push([i,n,"evict"]))),V(this,va).call(this,t),e&&(V(this,Lt)[t]=void 0,V(this,nt)[t]=void 0,V(this,Lr).push(t)),V(this,on)===1?(We(this,Cn,We(this,hn,0)),V(this,Lr).length=0):We(this,Cn,V(this,Ln)[t]),V(this,ln).delete(n),bl(this,on)._--,t},hs=new WeakSet,cc=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 Xc,{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:D}=s.signal,Y=n.ignoreFetchAbort&&I!==void 0;if(n.status&&(D&&!R?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,Y&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),D&&!Y&&!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,D=R&&n.allowStaleOnFetchAbort,Y=D||n.allowStaleOnFetchRejection,Z=Y||n.noDeleteOnFetchRejection,h=_;if(V(this,nt)[t]===_&&(!Z||h.__staleWhileFetching===void 0?this.delete(e):D||(V(this,nt)[t]=h.__staleWhileFetching)),Y)return n.status&&h.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw I},m=(I,R)=>{var Y;const D=(Y=V(this,ds))==null?void 0:Y.call(this,e,a,l);D&&D instanceof Promise&&D.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),E=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,E,{...l.options,status:void 0}),t=V(this,ln).get(e)):V(this,nt)[t]=E,E},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 Xc},al=new WeakSet,mg=function(e,t){V(this,nr)[t]=e,V(this,Ln)[e]=t},Ta=new WeakSet,vo=function(e){e!==V(this,hn)&&(e===V(this,Cn)?We(this,Cn,V(this,Ln)[e]):ze(this,al,mg).call(this,V(this,nr)[e],V(this,Ln)[e]),ze(this,al,mg).call(this,V(this,hn),e),We(this,hn,e))};let pg=D_;const wo=class wo{constructor(){A(this,"_fallbackMethod",()=>wo.createSkipProxy());A(this,"out",()=>{})}};A(wo,"createSkipProxy",()=>{const e=new wo;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 el=wo;const Do=class Do extends w_{constructor(t,n){super(n);A(this,"_fallbackMethod",()=>Do.createRestProxy(this.values.noteLength,this.app));A(this,"out",()=>{});this.values.noteLength=t}};A(Do,"createRestProxy",(t,n)=>{const i=new Do(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 Zc=Do;class S5 extends w_{constructor(t,n,i,a=""){super(i);A(this,"input");A(this,"ziffers");A(this,"initCallTime",0);A(this,"startCallTime",0);A(this,"lastCallTime",0);A(this,"waitTime",0);A(this,"played",!1);A(this,"current");A(this,"retro",!1);A(this,"index",-1);A(this,"zid","");A(this,"options",{});A(this,"skipIndex",0);A(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));A(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));A(this,"firstRun",()=>this.notStarted());A(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);A(this,"origin",()=>this.app.clock.pulses_since_origin+1);A(this,"pulse",()=>this.app.clock.time_position.pulse);A(this,"beat",()=>this.app.clock.time_position.beat);A(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);A(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);A(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});A(this,"lead",()=>this.voiceleading());A(this,"invert",t=>(this.atTheBeginning()&&this.ziffers.invert(t),this));A(this,"out",()=>{});this.app=i,this.input=t,this.options=n,this.ziffers=new N_(t,n),this.zid=a}reset(){this.initCallTime=0,this.startCallTime=0,this.lastCallTime=0,this.waitTime=0,this.index=0,this.skipIndex=0,this.played=!1,this.skipIndex=0,this.ziffers.reset()}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 zn){const a=n.getExisting("freq","note","pitch","key","scale","octave","parsedScale");return n.sound&&(t=n.sound),n.soundIndex&&(a.n=n.soundIndex),a.dur=i,new lg(a,this.app).sound(t||"sine")}else if(n instanceof $r){const a=n.pitches.map(l=>l.getExisting("freq","note","pitch","key","scale","octave","parsedScale")),s={dur:i};t&&(s.s=t);let o=Wc(a,s);return new lg(o,this.app)}else if(n instanceof ag)return Zc.createRestProxy(n.duration,this.app)}else return el.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 zn){n.soundIndex&&(i.channel=n.soundIndex);const a=new cg(i,this.app);return t?a.note(t):a}else{if(n instanceof ag)return Zc.createRestProxy(n.duration,this.app);if(n instanceof $r){const a=n.midiChord(),s=Wc(a);return new cg(s,this.app)}}}else return el.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 O5=r=>r[0]==="{"&&r[r.length-1]==="}",mo=(r,e)=>{if(O5(r)){const t=JSON.parse(r);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:r})},b5=r=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new DR({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return mo(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return mo(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return mo(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return mo(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return mo(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 yr(this.valueOf())}}};let Zh;class DR{constructor(e){A(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(),Zh&&clearTimeout(Zh),Zh=setTimeout(()=>{n.speak(i)},200)):n.speak(i)}else t("No text provided")}));this.options=e}}async function xR(){return Promise.all([u2(),Fi("github:tidalcycles/Dirt-Samples/master").then(()=>I2()),x2(),Fi("github:Bubobubobubobubo/Dough-Fox/main"),Fi("github:Bubobubobubobubo/Dough-Samples/main"),Fi("github:Bubobubobubobubo/Dough-Amiga/main"),Fi("github:Bubobubobubobubo/Dough-Amen/main"),Fi("github:Bubobubobubobubo/Dough-Waveforms/main")])}class E5{constructor(e){A(this,"variables",{});A(this,"codeExamples",{});A(this,"counters",{});A(this,"_drunk",new g5(-100,100,!1));A(this,"randomGen",Math.random);A(this,"currentSeed");A(this,"localSeeds",new Map);A(this,"patternCache",new pg({max:1e3,ttl:1e3*60*5}));A(this,"errorTimeoutID",0);A(this,"printTimeoutID",0);A(this,"MidiConnection");A(this,"scale_aid");A(this,"load");A(this,"_loadUniverseFromInterface",e=>{Mc(this.app,e),Pc()});A(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});A(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.stop(),this.play()});A(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.stop()});A(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.stop(),this.play(),this.app.exampleIsPlaying=!0,xM(this.app,e)});A(this,"_all_samples",()=>Jc.get());A(this,"_reportError",e=>{const t=s=>{var l;const o=(l=s.stack)==null?void 0:l.split(` -`);if(o){for(const c of o)if(c.includes("")){const u=c.match(/:(\d+):(\d+)/);if(u)return{line:parseInt(u[1],10),column:parseInt(u[2],10)}}}return{line:null,column:null}},{line:n,column:i}=t(e),a=n&&i?`${e.message} (Line: ${n-2}, Column: ${i})`:e.message;clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=a,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)});A(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)});A(this,"time",()=>this.app.audioContext.currentTime);A(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});A(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.app.clock.pause()});A(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.app.clock.stop()});A(this,"silence",this.stop);A(this,"hush",this.stop);A(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});A(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)});A(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});A(this,"mouseX",()=>this.app._mouseX);A(this,"mouseY",()=>this.app._mouseY);A(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));A(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));A(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(L2(this.app,"local",t),wa(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});A(this,"s",this.script);A(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});A(this,"cs",this.delete_script);A(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});A(this,"cps",this.copy_script);A(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});A(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()});A(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Ko},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});A(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});A(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});A(this,"midi",(e=60,t,n,i)=>{const a={note:e,velocity:t,channel:n,port:i};return new cg(a,this.app)});A(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});A(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});A(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});A(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});A(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});A(this,"midi_panic",()=>{this.MidiConnection.panic()});A(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});A(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});A(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});A(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)});A(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});A(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);A(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());A(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});A(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);A(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});A(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);A(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);A(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());A(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),t5(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});A(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});A(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});A(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});A(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));A(this,"resetAllFromCache",()=>{this.patternCache.forEach(e=>e.reset())});A(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 S5(e,t,this.app,i),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&i!=="z0"&&s.sync("z0"),s});A(this,"z0",(e,t={})=>this.z(e,t,0));A(this,"z1",(e,t={})=>this.z(e,t,1));A(this,"z2",(e,t={})=>this.z(e,t,2));A(this,"z3",(e,t={})=>this.z(e,t,3));A(this,"z4",(e,t={})=>this.z(e,t,4));A(this,"z5",(e,t={})=>this.z(e,t,5));A(this,"z6",(e,t={})=>this.z(e,t,6));A(this,"z7",(e,t={})=>this.z(e,t,7));A(this,"z8",(e,t={})=>this.z(e,t,8));A(this,"z9",(e,t={})=>this.z(e,t,9));A(this,"z10",(e,t={})=>this.z(e,t,10));A(this,"z11",(e,t={})=>this.z(e,t,11));A(this,"z12",(e,t={})=>this.z(e,t,12));A(this,"z13",(e,t={})=>this.z(e,t,13));A(this,"z14",(e,t={})=>this.z(e,t,14));A(this,"z15",(e,t={})=>this.z(e,t,15));A(this,"z16",(e,t={})=>this.z(e,t,16));A(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));A(this,"$",this.counter);A(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);A(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));A(this,"drunk_max",e=>{this._drunk.max=e});A(this,"drunk_min",e=>{this._drunk.min=e});A(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});A(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));A(this,"v",this.variable);A(this,"delete_variable",e=>{delete this.variables[e]});A(this,"dv",this.delete_variable);A(this,"clear_variables",()=>{this.variables={}});A(this,"cv",this.clear_variables);A(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);A(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);A(this,"irand",this.randI);A(this,"rI",this.randI);A(this,"r",this.rand);A(this,"ir",this.randI);A(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=ig(e))});A(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=ig(e);return this.localSeeds.set(e,t),t});A(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});A(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));A(this,"cmp",this.clamp);A(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));A(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));A(this,"tempo",this.bpm);A(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));A(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));A(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});A(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);A(this,"odds",(e,t=1)=>this.randomGen()!1);A(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));A(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));A(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));A(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));A(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));A(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));A(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));A(this,"always",(e=1)=>!0);A(this,"dice",e=>Math.floor(this.randomGen()*e)+1);A(this,"cbar",()=>this.app.clock.time_position.bar+1);A(this,"ctick",()=>this.app.clock.tick+1);A(this,"cpulse",()=>this.app.clock.time_position.pulse+1);A(this,"cbeat",()=>this.app.clock.time_position.beat+1);A(this,"ebeat",()=>this.app.clock.beats_since_origin+1);A(this,"epulse",()=>this.app.clock.pulses_since_origin+1);A(this,"nominator",()=>this.app.clock.time_signature[0]);A(this,"meter",()=>this.app.clock.time_signature[1]);A(this,"denominator",this.meter);A(this,"fill",()=>this.app.fill);A(this,"fullseq",(e,t)=>e.split("").every(n=>n==="x"||n==="o")?[...e].map(n=>n==="x").beat(t):!1);A(this,"seq",(e,t=.5)=>{let n=e.length*t,i=[];for(let a=1;a<=n+1;a+=t)i.push(Math.floor(a*10)/10);return i.pop(),i=i.filter((a,s)=>{const o=s%e.length;return e[o]==="x"}),this.oncount(i,n)});A(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));A(this,"b",this.beat);A(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)});A(this,"B",this.bar);A(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));A(this,"p",this.pulse);A(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));A(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});A(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)});A(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)});A(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)});A(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)});A(this,"delay",(e,t)=>{setTimeout(t,e)});A(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});A(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);A(this,"ec",this.euclid);A(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));A(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});A(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});A(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);A(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,t,n)+1)/2*t);A(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);A(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,t,n)+1)/2*t);A(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,t,n))*2-1)*t);A(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,t,n)+1)/2*t);A(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,t,n,i)+1)/2*t);A(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);A(this,"min",(...e)=>Math.min(...e));A(this,"max",(...e)=>Math.max(...e));A(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);A(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);A(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));A(this,"abs",Math.abs);A(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new DR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});A(this,"stop_hydra",()=>{this.app.hydra.hush()});A(this,"sound",e=>e?new lg(e,this.app):new el);A(this,"snd",this.sound);A(this,"samples",Fi);A(this,"log",e=>{console.log(e),this._logMessage(e)});A(this,"scale",R_);A(this,"rate",e=>{});A(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]});A(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);A(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);A(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));A(this,"reverse",e=>e.reverse());A(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));A(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));A(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));A(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));A(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));A(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});A(this,"raltfont",(e,t)=>{this.app.view.dispatch({effects:this.app.fontSize.reconfigure(Me.theme({"&":{fontFamily:e},".cm-gutters":{fontFamily:e},".cm-content":{fontFamily:e},".cm-comment":{fontFamily:t}}))})});this.app=e,this.MidiConnection=new m5(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 v5=r=>{Array.prototype.mouseX=function(){const e=r.mouseX(),n=window.innerWidth/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.mouseY=function(){const e=r.mouseY(),n=window.innerHeight/this.length,i=Math.floor(e/n);return this[i]},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=OR(ta(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=OR(ta(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.completion_checkbox.checked=r.settings.completions,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.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{mi(),r.updateKnownUniversesView(),Pc()}),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(o_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{rR(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Ko},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(" ")&&(Mc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Km(),r.view.focus(),HA())}),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 E=document.getElementById("modal-settings"),I=document.getElementById("editor");E==null||E.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",()=>{Pc()}),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 MM(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?O_():[])})}),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?[ly()]:[])})}),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?dR:[])})}),r.interface.completion_checkbox.addEventListener("change",()=>{let t=!!r.interface.completion_checkbox.checked;r.settings.completions=t,r.view.dispatch({effects:r.completionsCompartment.reconfigure(t?pR:[])})}),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&&(Mc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Km(),r.view.focus())}),wa(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,rg(r)):(console.log("Loading samples!"),await xR().then(()=>{r.docs=nR(r),r.currentDocumentationPane=t,rg(r)}))})})},AT=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)},C5=(r,e,t=!1)=>{e.addEventListener("resize",()=>AT(r.interface.scope)),e.addEventListener("resize",()=>AT(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)),e.addEventListener("error",n=>{console.log("Je suis bien installé !"),console.log(n.message,` +`);if(o){for(const c of o)if(c.includes("")){const u=c.match(/:(\d+):(\d+)/);if(u)return{line:parseInt(u[1],10),column:parseInt(u[2],10)}}}return{line:null,column:null}},{line:n,column:i}=t(e),a=n&&i?`${e.message} (Line: ${n-2}, Column: ${i})`:e.message;clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=a,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)});A(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)});A(this,"time",()=>this.app.audioContext.currentTime);A(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});A(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.app.clock.pause()});A(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.app.clock.stop()});A(this,"silence",this.stop);A(this,"hush",this.stop);A(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});A(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)});A(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});A(this,"mouseX",()=>this.app._mouseX);A(this,"mouseY",()=>this.app._mouseY);A(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));A(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));A(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(L2(this.app,"local",t),wa(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});A(this,"s",this.script);A(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});A(this,"cs",this.delete_script);A(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});A(this,"cps",this.copy_script);A(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});A(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()});A(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Ko},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});A(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});A(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});A(this,"midi",(e=60,t,n,i)=>{const a={note:e,velocity:t,channel:n,port:i};return new cg(a,this.app)});A(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});A(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});A(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});A(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});A(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});A(this,"midi_panic",()=>{this.MidiConnection.panic()});A(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});A(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});A(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});A(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)});A(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});A(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);A(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());A(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});A(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);A(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});A(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);A(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);A(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());A(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),t5(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});A(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});A(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});A(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});A(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));A(this,"resetAllFromCache",()=>{this.patternCache.forEach(e=>e.reset())});A(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 S5(e,t,this.app,i),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&i!=="z0"&&s.sync("z0"),s});A(this,"z0",(e,t={})=>this.z(e,t,0));A(this,"z1",(e,t={})=>this.z(e,t,1));A(this,"z2",(e,t={})=>this.z(e,t,2));A(this,"z3",(e,t={})=>this.z(e,t,3));A(this,"z4",(e,t={})=>this.z(e,t,4));A(this,"z5",(e,t={})=>this.z(e,t,5));A(this,"z6",(e,t={})=>this.z(e,t,6));A(this,"z7",(e,t={})=>this.z(e,t,7));A(this,"z8",(e,t={})=>this.z(e,t,8));A(this,"z9",(e,t={})=>this.z(e,t,9));A(this,"z10",(e,t={})=>this.z(e,t,10));A(this,"z11",(e,t={})=>this.z(e,t,11));A(this,"z12",(e,t={})=>this.z(e,t,12));A(this,"z13",(e,t={})=>this.z(e,t,13));A(this,"z14",(e,t={})=>this.z(e,t,14));A(this,"z15",(e,t={})=>this.z(e,t,15));A(this,"z16",(e,t={})=>this.z(e,t,16));A(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));A(this,"$",this.counter);A(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);A(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));A(this,"drunk_max",e=>{this._drunk.max=e});A(this,"drunk_min",e=>{this._drunk.min=e});A(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});A(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));A(this,"v",this.variable);A(this,"delete_variable",e=>{delete this.variables[e]});A(this,"dv",this.delete_variable);A(this,"clear_variables",()=>{this.variables={}});A(this,"cv",this.clear_variables);A(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);A(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);A(this,"irand",this.randI);A(this,"rI",this.randI);A(this,"r",this.rand);A(this,"ir",this.randI);A(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=ig(e))});A(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=ig(e);return this.localSeeds.set(e,t),t});A(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});A(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));A(this,"cmp",this.clamp);A(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));A(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));A(this,"tempo",this.bpm);A(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));A(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));A(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});A(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);A(this,"odds",(e,t=1)=>this.randomGen()!1);A(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));A(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));A(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));A(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));A(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));A(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));A(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));A(this,"always",(e=1)=>!0);A(this,"dice",e=>Math.floor(this.randomGen()*e)+1);A(this,"cbar",()=>this.app.clock.time_position.bar+1);A(this,"ctick",()=>this.app.clock.tick+1);A(this,"cpulse",()=>this.app.clock.time_position.pulse+1);A(this,"cbeat",()=>this.app.clock.time_position.beat+1);A(this,"ebeat",()=>this.app.clock.beats_since_origin+1);A(this,"epulse",()=>this.app.clock.pulses_since_origin+1);A(this,"nominator",()=>this.app.clock.time_signature[0]);A(this,"meter",()=>this.app.clock.time_signature[1]);A(this,"denominator",this.meter);A(this,"fill",()=>this.app.fill);A(this,"fullseq",(e,t)=>e.split("").every(n=>n==="x"||n==="o")?[...e].map(n=>n==="x").beat(t):!1);A(this,"seq",(e,t=.5)=>{let n=e.length*t,i=[];for(let a=1;a<=n+1;a+=t)i.push(Math.floor(a*10)/10);return i.pop(),i=i.filter((a,s)=>{const o=s%e.length;return e[o]==="x"}),this.oncount(i,n)});A(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));A(this,"b",this.beat);A(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)});A(this,"B",this.bar);A(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));A(this,"p",this.pulse);A(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));A(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});A(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)});A(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)});A(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)});A(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)});A(this,"delay",(e,t)=>{setTimeout(t,e)});A(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});A(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);A(this,"ec",this.euclid);A(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));A(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});A(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});A(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);A(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,t,n)+1)/2*t);A(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);A(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,t,n)+1)/2*t);A(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,t,n))*2-1)*t);A(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,t,n)+1)/2*t);A(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,t,n,i)+1)/2*t);A(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);A(this,"min",(...e)=>Math.min(...e));A(this,"max",(...e)=>Math.max(...e));A(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);A(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);A(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));A(this,"abs",Math.abs);A(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new DR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});A(this,"stop_hydra",()=>{this.app.hydra.hush()});A(this,"sound",e=>e?new lg(e,this.app):new el);A(this,"snd",this.sound);A(this,"samples",Fi);A(this,"log",e=>{console.log(e),this._logMessage(e)});A(this,"scale",R_);A(this,"rate",e=>{});A(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]});A(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);A(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);A(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));A(this,"reverse",e=>e.reverse());A(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));A(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));A(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));A(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));A(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));A(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});A(this,"raltfont",(e,t)=>{this.app.view.dispatch({effects:this.app.fontSize.reconfigure(Me.theme({"&":{fontFamily:e},".cm-gutters":{fontFamily:e},".cm-content":{fontFamily:e},".cm-comment":{fontFamily:t}}))})});this.app=e,this.MidiConnection=new m5(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 v5=r=>{Array.prototype.mouseX=function(){const e=r.mouseX(),n=window.innerWidth/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.mouseY=function(){const e=r.mouseY(),n=window.innerHeight/this.length,i=Math.floor(e/n);return this[i]},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.dur=function(...e){const t=r.app.clock.pulses_since_origin,n=r.ppqn(),i=this.map((l,c)=>e[c%e.length]),a=i.reduce((l,c)=>l+c*n,0),s=t%a;let o=0;for(let l=0;l0)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=OR(ta(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=OR(ta(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.completion_checkbox.checked=r.settings.completions,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.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{mi(),r.updateKnownUniversesView(),Pc()}),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(o_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{rR(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Ko},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(" ")&&(Mc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Km(),r.view.focus(),HA())}),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 E=document.getElementById("modal-settings"),I=document.getElementById("editor");E==null||E.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",()=>{Pc()}),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 MM(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?O_():[])})}),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?[ly()]:[])})}),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?dR:[])})}),r.interface.completion_checkbox.addEventListener("change",()=>{let t=!!r.interface.completion_checkbox.checked;r.settings.completions=t,r.view.dispatch({effects:r.completionsCompartment.reconfigure(t?pR:[])})}),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&&(Mc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Km(),r.view.focus())}),wa(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,rg(r)):(console.log("Loading samples!"),await xR().then(()=>{r.docs=nR(r),r.currentDocumentationPane=t,rg(r)}))})})},AT=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)},C5=(r,e,t=!1)=>{e.addEventListener("resize",()=>AT(r.interface.scope)),e.addEventListener("resize",()=>AT(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)),e.addEventListener("error",n=>{console.log("Je suis bien installé !"),console.log(n.message,` `,n.filename,":",n.lineno,n.colno?":"+n.colno:"",n.error&&n.error.stack?` `:"",n.error?n.error.stack:void 0)},!1)};class y5{constructor(){A(this,"settings",new kM);A(this,"universes",Ko);A(this,"selected_universe","Welcome");A(this,"fill",!1);A(this,"local_index",1);A(this,"editor_mode","global");A(this,"fontSize");A(this,"withLineNumbers");A(this,"vimModeCompartment");A(this,"hoveringCompartment");A(this,"completionsCompartment");A(this,"chosenLanguage");A(this,"dynamicPlugins");A(this,"currentDocumentationPane","introduction");A(this,"exampleCounter",0);A(this,"exampleIsPlaying",!1);A(this,"editorExtensions",[]);A(this,"userPlugins",[]);A(this,"state");A(this,"view");A(this,"selectedExample","");A(this,"docs",{});A(this,"_mouseX",0);A(this,"_mouseY",0);A(this,"show_error",!1);A(this,"buttonElements",{});A(this,"interface",{});A(this,"blinkTimeouts",{});A(this,"osc",{enabled:!1,color:"#fdba74",thickness:4,refresh:1,fftSize:1024,orientation:"horizontal",is3D:!1,size:1});A(this,"api");A(this,"audioContext");A(this,"clock");A(this,"dough_nudge",20);A(this,"manualPlay",!1);A(this,"isPlaying",!1);A(this,"hydra_backend");A(this,"hydra");A(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,...Ko},LM(this),this.audioContext=new AudioContext({latencyHint:"playback"}),this.clock=new hG(this,this.audioContext),this.api=new E5(this),v5(this.api),b5(this.api),Object.entries(this.api).forEach(([t,n])=>{globalThis[t]=n}),(async()=>{await xR()})(),this.docs=nR(this),P$(this),B$(this),T5(this),DT(this),dG(this),M2(this.interface.scope,this),wa(this,this.universes[this.selected_universe.toString()].init),this.changeModeFromInterface("global"),PM(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"?[ZL()]:[Wg()])}),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(FM))this.interface[e]=document.getElementById(t)}initializeButtonGroups(){for(const[e,t]of Object.entries(YM))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 A5=new y5;C5(A5,window,!1); diff --git a/index.html b/index.html index a64a60d..4cd0698 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - +