diff --git a/assets/index-281307f5.js b/assets/index-6a579f1c.js
similarity index 97%
rename from assets/index-281307f5.js
rename to assets/index-6a579f1c.js
index bbafc75..2e16346 100644
--- a/assets/index-281307f5.js
+++ b/assets/index-6a579f1c.js
@@ -397,7 +397,15 @@ if (onbar(4, 1, 3)) {
mod(.5)::snd('sd').out();
}
`,!0)}
-
+
+
+- divbar(bar: number): return true or false alternatively every _n_ bars.
+${t("Alternating over four bars",`
+divbar(2)
+ ? mod(.5) && snd(['kick', 'hh'].div(1)).out()
+ : mod(.5) && snd(['east', 'snare'].div(1)).out()
+`,!0)};
+
## What are pulses?
To make a beat, you need a certain number of time grains or **pulses**. The **pulse** is also known as the [PPQN](https://en.wikipedia.org/wiki/Pulses_per_quarter_note). By default, Topos is using a _pulses per quarter note_ of 48. You can change it by using the ppqn(number) function. It means that the lowest possible rhythmic value is 1/48 of a quarter note. That's plenty of time already.
@@ -1192,7 +1200,7 @@ Topos is made to be controlled entirely with a keyboard. It is recommanded to st
`+c.line+" | "+g+`
`+m+" | "+t("",l.column-1," ")+t("",v,"^")}else a+=`
at `+d}return a},e.buildMessage=function(i,a){var s={literal:function(g){return'"'+l(g.text)+'"'},class:function(g){var b=g.parts.map(function(v){return Array.isArray(v)?c(v[0])+"-"+c(v[1]):c(v)});return"["+(g.inverted?"^":"")+b.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(g){return g.description}};function o(g){return g.charCodeAt(0).toString(16).toUpperCase()}function l(g){return 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(b){return"\\x0"+o(b)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(b){return"\\x"+o(b)})}function c(g){return g.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(b){return"\\x0"+o(b)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(b){return"\\x"+o(b)})}function d(g){return s[g.type](g)}function p(g){var b=g.map(d),v,y;if(b.sort(),b.length>0){for(v=1,y=1;v>",A="<<",D="<",M=">",w="_",B="?",re=":",ie="r",j=/^[0-9]/,J=/^[ \n\r\t]/,L=/^[mklpdcwyhnqaefsxtgujzo]/,G=vt("-",!1),Z=Qn([["0","9"]],!1,!1),z=vt(".",!1),ce=qn("whitespace"),ue=Qn([" ",`
-`,"\r"," "],!1,!1),Te=vt(",",!1),Pe=vt("|",!1),Ve=Qn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),Re=vt("(",!1),Ie=vt(")",!1),le=vt("+",!1),Me=vt("*",!1),je=vt("/",!1),He=vt("%",!1),rt=vt("^",!1),ft=vt("&",!1),Ct=vt(">>",!1),Vt=vt("<<",!1),ht=vt("<",!1),Nt=vt(">",!1),kt=vt("_",!1),Gr=vt("?",!1),Fe=vt(":",!1),kr=vt("r",!1),st=function(F){return F.filter(K=>K)},Qe=function(){return parseFloat(br())},Mr=function(){return parseInt(br())},nr=function(){},hr=function(){return Ik[br()]},V=function(F){return F.filter(K=>K)},he=function(F){return Cr(Xk,{items:F})},ve=function(F,K,ae){return Cr(Zk,{left:F,operation:K,right:ae})},Ce=function(F){return F},Ke=function(F){return Cr(Lm,{items:F})},Ee=function(F){return Cr(Hk,{octave:F})},Gt=function(){return br().split("").reduce((F,K)=>F+(K==="^"?1:-1),0)},ot=function(){return Cr(GS,{seededRandom:a.seededRandom})},Tt=function(F,K){return Cr(GS,{min:F,max:K,seededRandom:a.seededRandom})},Jr=function(F,K){return Cr(Wk,{item:F,times:K})},lt=function(F){return Cr(zk,{duration:F})},Wt=function(F){return Cr(Nh,{duration:F})},Ot=function(F,K,ae){const _e=F?a.nodeOptions.octave+F:a.nodeOptions.octave;return Cr(Ki,{duration:K,pitch:ae,octave:_e})},we=function(F,K){return Cr(Vk,{pitches:[F].concat(K)})},H=0,Et=0,nt=[{line:1,column:1}],$t=0,cr=[],ze=0,Ge={},Dt;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 br(){return i.substring(Et,H)}function yi(){return Qt(Et,H)}function vt(F,K){return{type:"literal",text:F,ignoreCase:K}}function Qn(F,K,ae){return{type:"class",parts:F,inverted:K,ignoreCase:ae}}function en(){return{type:"end"}}function qn(F){return{type:"other",description:F}}function tn(F){var K=nt[F],ae;if(K)return K;for(ae=F-1;!nt[ae];)ae--;for(K=nt[ae],K={line:K.line,column:K.column};ae$t&&($t=H,cr=[]),cr.push(F))}function ni(F,K,ae){return new e(e.buildMessage(F,K),F,K,ae)}function Y(){var F,K,ae=H*24+0,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,K=ye(),K!==s&&(Et=F,K=st(K)),F=K,Ge[ae]={nextPos:H,result:F},F)}function ee(){var F,K,ae,_e,Le,Je,vr,An=H*24+1,Ri=Ge[An];if(Ri)return H=Ri.nextPos,Ri.result;for(F=H,K=H,i.charCodeAt(H)===45?(ae=d,H++):(ae=s,ze===0&&We(G)),ae===s&&(ae=null),_e=[],j.test(i.charAt(H))?(Le=i.charAt(H),H++):(Le=s,ze===0&&We(Z));Le!==s;)_e.push(Le),j.test(i.charAt(H))?(Le=i.charAt(H),H++):(Le=s,ze===0&&We(Z));if(i.charCodeAt(H)===46?(Le=p,H++):(Le=s,ze===0&&We(z)),Le!==s){if(Je=[],j.test(i.charAt(H))?(vr=i.charAt(H),H++):(vr=s,ze===0&&We(Z)),vr!==s)for(;vr!==s;)Je.push(vr),j.test(i.charAt(H))?(vr=i.charAt(H),H++):(vr=s,ze===0&&We(Z));else Je=s;Je!==s?(ae=[ae,_e,Le,Je],K=ae):(H=K,K=s)}else H=K,K=s;if(K===s)if(K=H,i.charCodeAt(H)===46?(ae=p,H++):(ae=s,ze===0&&We(z)),ae!==s){if(_e=[],j.test(i.charAt(H))?(Le=i.charAt(H),H++):(Le=s,ze===0&&We(Z)),Le!==s)for(;Le!==s;)_e.push(Le),j.test(i.charAt(H))?(Le=i.charAt(H),H++):(Le=s,ze===0&&We(Z));else _e=s;_e!==s?(ae=[ae,_e],K=ae):(H=K,K=s)}else H=K,K=s;return K!==s&&(Et=F,K=Qe()),F=K,Ge[An]={nextPos:H,result:F},F}function se(){var F,K,ae=H*24+2,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,i.charCodeAt(H)===45?H++:ze===0&&We(G),j.test(i.charAt(H))?(K=i.charAt(H),H++):(K=s,ze===0&&We(Z)),K!==s?(Et=F,F=Mr()):(H=F,F=s),Ge[ae]={nextPos:H,result:F},F)}function fe(){var F,K,ae=H*24+3,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(ze++,F=H,J.test(i.charAt(H))?(K=i.charAt(H),H++):(K=s,ze===0&&We(ue)),K!==s&&(Et=F,K=nr()),F=K,ze--,F===s&&(K=s,ze===0&&We(ce)),Ge[ae]={nextPos:H,result:F},F)}function Se(){var F,K,ae=H*24+7,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,L.test(i.charAt(H))?(K=i.charAt(H),H++):(K=s,ze===0&&We(Ve)),K!==s&&(Et=F,K=hr()),F=K,Ge[ae]={nextPos:H,result:F},F)}function xe(){var F,K=H*24+8,ae=Ge[K];return ae?(H=ae.nextPos,ae.result):(F=Se(),F===s&&(F=ee()),Ge[K]={nextPos:H,result:F},F)}function ye(){var F,K,ae,_e=H*24+9,Le=Ge[_e];if(Le)return H=Le.nextPos,Le.result;if(F=H,K=[],ae=Ai(),ae===s&&(ae=mr(),ae===s&&(ae=dt(),ae===s&&(ae=ii(),ae===s&&(ae=ai())))),ae!==s)for(;ae!==s;)K.push(ae),ae=Ai(),ae===s&&(ae=mr(),ae===s&&(ae=dt(),ae===s&&(ae=ii(),ae===s&&(ae=ai()))));else K=s;return K!==s&&(Et=F,K=V(K)),F=K,Ge[_e]={nextPos:H,result:F},F}function dt(){var F,K,ae,_e,Le=H*24+10,Je=Ge[Le];return Je?(H=Je.nextPos,Je.result):(F=H,i.charCodeAt(H)===40?(K=b,H++):(K=s,ze===0&&We(Re)),K!==s?(ae=ye(),ae!==s?(i.charCodeAt(H)===41?(_e=v,H++):(_e=s,ze===0&&We(Ie)),_e!==s?(Et=F,F=he(ae)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s),Ge[Le]={nextPos:H,result:F},F)}function mr(){var F,K,ae,_e,Le=H*24+11,Je=Ge[Le];return Je?(H=Je.nextPos,Je.result):(F=H,K=dt(),K!==s?(ae=$r(),ae!==s?(_e=dt(),_e!==s?(Et=F,F=ve(K,ae,_e)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s),Ge[Le]={nextPos:H,result:F},F)}function $r(){var F,K=H*24+12,ae=Ge[K];return ae?(H=ae.nextPos,ae.result):(i.charCodeAt(H)===43?(F=y,H++):(F=s,ze===0&&We(le)),F===s&&(i.charCodeAt(H)===45?(F=d,H++):(F=s,ze===0&&We(G)),F===s&&(i.charCodeAt(H)===42?(F=N,H++):(F=s,ze===0&&We(Me)),F===s&&(i.charCodeAt(H)===47?(F=U,H++):(F=s,ze===0&&We(je)),F===s&&(i.charCodeAt(H)===37?(F=W,H++):(F=s,ze===0&&We(He)),F===s&&(i.charCodeAt(H)===94?(F=f,H++):(F=s,ze===0&&We(rt)),F===s&&(i.charCodeAt(H)===124?(F=g,H++):(F=s,ze===0&&We(Pe)),F===s&&(i.charCodeAt(H)===38?(F=E,H++):(F=s,ze===0&&We(ft)),F===s&&(i.substr(H,2)===O?(F=O,H+=2):(F=s,ze===0&&We(Ct)),F===s&&(i.substr(H,2)===A?(F=A,H+=2):(F=s,ze===0&&We(Vt))))))))))),Ge[K]={nextPos:H,result:F},F)}function ii(){var F,K,ae=H*24+13,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,K=ra(),K===s&&(K=na(),K===s&&(K=si(),K===s&&(K=Va(),K===s&&(K=fe(),K===s&&(K=za(),K===s&&(K=Ha(),K===s&&(K=ta(),K===s&&(K=dt())))))))),K!==s&&(Et=F,K=Ce(K)),F=K,Ge[ae]={nextPos:H,result:F},F)}function ai(){var F,K,ae,_e,Le=H*24+14,Je=Ge[Le];return Je?(H=Je.nextPos,Je.result):(F=H,i.charCodeAt(H)===60?(K=D,H++):(K=s,ze===0&&We(ht)),K!==s?(ae=ye(),ae!==s?(i.charCodeAt(H)===62?(_e=M,H++):(_e=s,ze===0&&We(Nt)),_e!==s?(Et=F,F=Ke(ae)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s),Ge[Le]={nextPos:H,result:F},F)}function Va(){var F,K,ae=H*24+15,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,K=Pr(),K!==s&&(Et=F,K=Ee(K)),F=K,Ge[ae]={nextPos:H,result:F},F)}function Pr(){var F,K,ae,_e=H*24+16,Le=Ge[_e];if(Le)return H=Le.nextPos,Le.result;if(F=H,K=[],i.charCodeAt(H)===94?(ae=f,H++):(ae=s,ze===0&&We(rt)),ae===s&&(i.charCodeAt(H)===95?(ae=w,H++):(ae=s,ze===0&&We(kt))),ae!==s)for(;ae!==s;)K.push(ae),i.charCodeAt(H)===94?(ae=f,H++):(ae=s,ze===0&&We(rt)),ae===s&&(i.charCodeAt(H)===95?(ae=w,H++):(ae=s,ze===0&&We(kt)));else K=s;return K!==s&&(Et=F,K=Gt()),F=K,Ge[_e]={nextPos:H,result:F},F}function Ha(){var F,K,ae=H*24+17,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,i.charCodeAt(H)===63?(K=B,H++):(K=s,ze===0&&We(Gr)),K!==s&&(Et=F,K=ot()),F=K,Ge[ae]={nextPos:H,result:F},F)}function ta(){var F,K,ae,_e,Le,Je,vr=H*24+18,An=Ge[vr];return An?(H=An.nextPos,An.result):(F=H,i.charCodeAt(H)===40?(K=b,H++):(K=s,ze===0&&We(Re)),K!==s?(ae=se(),ae!==s?(i.charCodeAt(H)===44?(_e=m,H++):(_e=s,ze===0&&We(Te)),_e!==s?(Le=se(),Le!==s?(i.charCodeAt(H)===41?(Je=v,H++):(Je=s,ze===0&&We(Ie)),Je!==s?(Et=F,F=Tt(ae,Le)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s),Ge[vr]={nextPos:H,result:F},F)}function Ai(){var F,K,ae,_e,Le=H*24+19,Je=Ge[Le];return Je?(H=Je.nextPos,Je.result):(F=H,K=ii(),K!==s?(i.charCodeAt(H)===58?(ae=re,H++):(ae=s,ze===0&&We(Fe)),ae!==s?(_e=se(),_e!==s?(Et=F,F=Jr(K,_e)):(H=F,F=s)):(H=F,F=s)):(H=F,F=s),Ge[Le]={nextPos:H,result:F},F)}function za(){var F,K,ae=H*24+20,_e=Ge[ae];return _e?(H=_e.nextPos,_e.result):(F=H,K=xe(),K!==s&&(Et=F,K=lt(K)),F=K,Ge[ae]={nextPos:H,result:F},F)}function ra(){var F,K,ae,_e=H*24+21,Le=Ge[_e];return Le?(H=Le.nextPos,Le.result):(F=H,K=xe(),K===s&&(K=null),i.charCodeAt(H)===114?(ae=ie,H++):(ae=s,ze===0&&We(kr)),ae!==s?(Et=F,F=Wt(K)):(H=F,F=s),Ge[_e]={nextPos:H,result:F},F)}function si(){var F,K,ae,_e,Le=H*24+22,Je=Ge[Le];return Je?(H=Je.nextPos,Je.result):(F=H,K=Pr(),K===s&&(K=null),ae=xe(),ae===s&&(ae=null),_e=se(),_e!==s?(Et=F,F=Ot(K,ae,_e)):(H=F,F=s),Ge[Le]={nextPos:H,result:F},F)}function na(){var F,K,ae,_e,Le=H*24+23,Je=Ge[Le];if(Je)return H=Je.nextPos,Je.result;if(F=H,K=si(),K!==s){if(ae=[],_e=si(),_e!==s)for(;_e!==s;)ae.push(_e),_e=si();else ae=s;ae!==s?(Et=F,F=we(K,ae)):(H=F,F=s)}else H=F,F=s;return Ge[Le]={nextPos:H,result:F},F}var Tr=a.nodeOptions||{};function Cr(F,K){K.text=br(),K.location=yi();for(var ae in Tr)(K[ae]===void 0||K[ae]===null)&&(K[ae]=Tr[ae]);return new F(K)}if(Dt=c(),Dt!==s&&H===i.length)return Dt;throw Dt!==s&&He.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}retrograde(){return this.evaluated=this.evaluated.reverse(),this}scale(e){return this.isInOptions("scaleName",e)?this:(this.update({scale:e}),this)}key(e){return this.isInOptions("key",e)?this:(this.update({key:e}),this)}octave(e){return this.isInOptions("octave",e)?this:(this.update({octave:e}),this)}isInOptions(e,t){return this.options.nodeOptions&&this.options.nodeOptions[e]===t}next(){return this.index++,this.counter++,this.redo>0&&this.index>=this.evaluated.length*this.redo&&(this.update(),this.index=0),this.evaluated[this.index%this.evaluated.length]}applyTransformations(){var e;(e=this.globalOptions)!=null&&e.retrograde&&(this.evaluated=this.evaluated.reverse())}clone(){return Fs(this)}notStarted(){return this.index<0}peek(){return this.evaluated[this.index-1||0]}hasStarted(){return this.index>=0}evaluate(e={}){return this.values.map(r=>r.evaluate(e)).flat(1/0).filter(r=>r!==void 0)}totalDuration(){return this.evaluated.reduce((t,r)=>t+r.collect("duration"),0)}}const Jk=n=>{let e={};return qk.forEach(t=>{if(n[t]!==void 0){const r=n[t];e[t]=r,delete n[t]}}),e};class eM{constructor(){R(this,"midiAccess",null);R(this,"midiOutputs",[]);R(this,"currentOutputIndex",0);R(this,"scheduledNotes",{});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)}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex=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(r=>r.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}listMidiOutputs(){console.log("Available MIDI Outputs:"),this.midiOutputs.forEach((e,t)=>{console.log(`${t+1}. ${e.name}`)})}sendMidiNote(e,t,r,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,r],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const d=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=d}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,r=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 r=="string"&&(r=this.getMidiOutputIndex(r));const i=this.midiOutputs[r];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 r=this.midiOutputs[this.currentOutputIndex];r?r.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,r){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+r,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const r=this.scheduledNotes[t];clearTimeout(r),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class tM{constructor(e,t,r){R(this,"min");R(this,"max");R(this,"wrap");R(this,"position");this.min=e,this.max=t,this.wrap=r,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}}const rM={major:[0,2,4,5,7,9,11],naturalMinor:[0,2,3,5,7,8,10],harmonicMinor:[0,2,3,5,7,8,11],melodicMinor:[0,2,3,5,7,9,11],dorian:[0,2,3,5,7,9,10],phrygian:[0,1,3,5,7,8,10],lydian:[0,2,4,6,7,9,11],mixolydian:[0,2,4,5,7,9,10],aeolian:[0,2,3,5,7,8,10],locrian:[0,1,3,5,6,8,10],wholeTone:[0,2,4,6,8,10],majorPentatonic:[0,2,4,7,9],minorPentatonic:[0,3,5,7,10],chromatic:[0,1,2,3,4,5,6,7,8,9,10,11],blues:[0,3,5,6,7,10],diminished:[0,2,3,5,6,8,9,11],neapolitanMinor:[0,1,3,5,7,8,11],neapolitanMajor:[0,1,3,5,7,9,11],enigmatic:[0,1,4,6,8,10,11],doubleHarmonic:[0,1,4,5,7,8,11],octatonic:[0,2,3,5,6,8,9,11],bebopDominant:[0,2,4,5,7,9,10,11],bebopMajor:[0,2,4,5,7,8,9,11],bebopMinor:[0,2,3,5,7,8,9,11],bebopDorian:[0,2,3,4,5,7,9,10],harmonicMajor:[0,2,4,5,7,8,11],hungarianMinor:[0,2,3,6,7,8,11],hungarianMajor:[0,3,4,6,7,9,10],oriental:[0,1,4,5,6,9,10],romanianMinor:[0,2,3,6,7,9,10],spanishGypsy:[0,1,4,5,7,8,10],jewish:[0,1,4,5,7,8,10],hindu:[0,2,4,5,7,8,10],japanese:[0,1,5,7,8],hirajoshi:[0,2,3,7,8],kumoi:[0,2,3,7,9],inSen:[0,1,5,7,10],iwato:[0,1,5,6,10],yo:[0,2,5,7,9],minorBlues:[0,3,5,6,7,10],algerian:[0,2,3,5,6,7,8,11],augmented:[0,3,4,7,8,11],balinese:[0,1,3,7,8],byzantine:[0,1,4,5,7,8,11],chinese:[0,4,6,7,11],egyptian:[0,2,5,7,10],eightToneSpanish:[0,1,3,4,5,6,8,10],hawaiian:[0,2,3,5,7,9,10],hindustan:[0,2,4,5,7,8,10],persian:[0,1,4,5,6,8,11],eastIndianPurvi:[0,1,4,6,7,8,11],orientalA:[0,1,4,5,6,9,10]};function nM(n,e="major",t=4){const r=rM[e];if(!r)throw new Error(`Unknown scale ${e}`);let i=n%r.length;i<0&&(i+=r.length);let a=Math.floor(n/r.length);return 60+(t+a)*12+r[i]}class km{constructor(e){R(this,"seedValue");R(this,"randomGen",Math.random);R(this,"app");R(this,"values",{});R(this,"odds",(e,t)=>this.randomGen()this.odds(.025,e));R(this,"rarely",e=>this.odds(.1,e));R(this,"scarcely",e=>this.odds(.25,e));R(this,"sometimes",e=>this.odds(.5,e));R(this,"often",e=>this.odds(.75,e));R(this,"frequently",e=>this.odds(.9,e));R(this,"almostAlways",e=>this.odds(.985,e));R(this,"modify",e=>e(this));R(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));R(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));R(this,"apply",e=>this.modify(e));R(this,"duration",e=>(this.values.duration=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class Qy extends km{constructor(t){super(t);R(this,"octave",t=>(this.values.octave=t,this.update(),this));R(this,"key",t=>(this.values.key=t,this.update(),this));R(this,"scale",t=>(Dm(t)?(this.values.scaleName=t,this.values.parsedScale=Zi(t)):this.values.parsedScale=wm(t),this.update(),this));R(this,"freq",t=>{this.values.freq=t;const r=Mk(t);return r%1!==0?(this.values.note=Math.floor(r),this.values.bend=Yy(r)[1]):this.values.note=r,this});R(this,"update",()=>{})}}let Ir=[],iM=(n,e)=>{let t,r=[],i={lc:0,l:e||0,value:n,set(a){i.value=a,i.notify()},get(){return i.lc||i.listen(()=>{})(),i.value},notify(a){t=r;let s=!Ir.length;for(let o=0;o{r===t&&(r=r.slice());let o=r.indexOf(a);~o&&(r.splice(o,2),i.lc--,i.lc||i.off())}},subscribe(a,s){let o=i.listen(a,s);return a(i.value),o},off(){}};return i},aM=(n={})=>{let e=iM(n);return e.setKey=function(t,r){typeof r>"u"?t in e.value&&(e.value={...e.value},delete e.value[t],e.notify(t)):e.value[t]!==r&&(e.value={...e.value,[t]:r},e.notify(t))},e};if(typeof DelayNode<"u"){class n extends DelayNode{constructor(t,r,i,a){super(t),r=Math.abs(r),this.delayTime.value=i;const s=t.createGain();s.gain.value=Math.min(Math.abs(a),.995),this.feedback=s.gain;const o=t.createGain();return o.gain.value=r,this.delayGain=o,this.connect(s),this.connect(o),s.connect(this),this.connect=l=>o.connect(l),this}start(t){this.delayGain.gain.setValueAtTime(this.delayGain.gain.value,t+this.delayTime.value)}}AudioContext.prototype.createFeedbackDelay=function(e,t,r){return new n(this,e,t,r)}}typeof AudioContext<"u"&&(AudioContext.prototype.impulseResponse=function(n,e=1){const t=this.sampleRate*n,r=this.createBuffer(e,t,this.sampleRate),i=r.getChannelData(0);for(let a=0;a(e.buffer=this.impulseResponse(t),e.duration=n,e),e.setDuration(n),e});var $S={a:{freqs:[660,1120,2750,3e3,3350],gains:[1,.5012,.0708,.0631,.0126],qs:[80,90,120,130,140]},e:{freqs:[440,1800,2700,3e3,3300],gains:[1,.1995,.1259,.1,.1],qs:[70,80,100,120,120]},i:{freqs:[270,1850,2900,3350,3590],gains:[1,.0631,.0631,.0158,.0158],qs:[40,90,100,120,120]},o:{freqs:[430,820,2700,3e3,3300],gains:[1,.3162,.0501,.0794,.01995],qs:[40,80,100,120,120]},u:{freqs:[370,630,2750,3e3,3400],gains:[1,.1,.0708,.0316,.01995],qs:[40,60,100,120,120]}};if(typeof GainNode<"u"){class n extends GainNode{constructor(t,r){if(super(t),!$S[r])throw new Error("vowel: unknown vowel "+r);const{gains:i,qs:a,freqs:s}=$S[r],o=t.createGain();for(let l=0;l<5;l++){const c=t.createGain();c.gain.value=i[l];const d=t.createBiquadFilter();d.type="bandpass",d.Q.value=a[l],d.frequency.value=s[l],this.connect(d),d.connect(c),c.connect(o)}return o.gain.value=8,this.connect=l=>o.connect(l),this}}AudioContext.prototype.createVowelFilter=function(e){return new n(this,e)}}const sM=n=>{var i;if(typeof n!="string")return[];const[e,t="",r]=((i=n.match(/^([a-gA-G])([#bsf]*)([0-9]*)$/))==null?void 0:i.slice(1))||[];return e?[e,t,r?Number(r):void 0]:[]},oM={c:0,d:2,e:4,f:5,g:7,a:9,b:11},lM={"#":1,b:-1,s:1,f:-1},Mm=(n,e=3)=>{const[t,r,i=e]=sM(n);if(!t)throw new Error('not a note: "'+n+'"');const a=oM[t.toLowerCase()],s=(r==null?void 0:r.split("").reduce((o,l)=>o+lM[l],0))||0;return(Number(i)+1)*12+a+s},cM=n=>Math.pow(2,(n-69)/12)*440,uM=(n,e,t)=>Math.min(Math.max(n,e),t),dM=n=>12*Math.log(n/440)/Math.LN2+69,pM=(n,e)=>{if(typeof n!="object")throw new Error("valueToMidi: expected object value");let{freq:t,note:r}=n;if(typeof t=="number")return dM(t);if(typeof r=="string")return Mm(r);if(typeof r=="number")return r;if(!e)throw new Error("valueToMidi: expected freq or note to be set");return e},fM="data:application/javascript;base64,Ly8gTElDRU5TRSBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSB2My4wIHNlZSBodHRwczovL2dpdGh1Yi5jb20vZGt0cjAvV2ViRGlydC9ibG9iL21haW4vTElDRU5TRQovLyBhbGwgdGhlIGNyZWRpdCBnb2VzIHRvIGRrdHIwJ3Mgd2ViZGlydDogaHR0cHM6Ly9naXRodWIuY29tL2RrdHIwL1dlYkRpcnQvYmxvYi81Y2UzZDY5ODM2MmM1NGQ2ZTFiNjhhY2M0N2ViMjk1NWFjNjJjNzkzL2Rpc3QvQXVkaW9Xb3JrbGV0cy5qcwovLyA8MwoKY2xhc3MgQ29hcnNlUHJvY2Vzc29yIGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBzdGF0aWMgZ2V0IHBhcmFtZXRlckRlc2NyaXB0b3JzKCkgewogICAgcmV0dXJuIFt7IG5hbWU6ICdjb2Fyc2UnLCBkZWZhdWx0VmFsdWU6IDEgfV07CiAgfQoKICBjb25zdHJ1Y3RvcigpIHsKICAgIHN1cGVyKCk7CiAgICB0aGlzLm5vdFN0YXJ0ZWQgPSB0cnVlOwogIH0KCiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgY29uc3Qgb3V0cHV0ID0gb3V0cHV0c1swXTsKICAgIGNvbnN0IGNvYXJzZSA9IHBhcmFtZXRlcnMuY29hcnNlOwogICAgY29uc3QgYmxvY2tTaXplID0gMTI4OwogICAgY29uc3QgaGFzSW5wdXQgPSAhKGlucHV0WzBdID09PSB1bmRlZmluZWQpOwogICAgaWYgKGhhc0lucHV0KSB7CiAgICAgIHRoaXMubm90U3RhcnRlZCA9IGZhbHNlOwogICAgICBvdXRwdXRbMF1bMF0gPSBpbnB1dFswXVswXTsKICAgICAgZm9yIChsZXQgbiA9IDE7IG4gPCBibG9ja1NpemU7IG4rKykgewogICAgICAgIGZvciAobGV0IG8gPSAwOyBvIDwgb3V0cHV0Lmxlbmd0aDsgbysrKSB7CiAgICAgICAgICBvdXRwdXRbb11bbl0gPSBuICUgY29hcnNlID09IDAgPyBpbnB1dFswXVtuXSA6IG91dHB1dFtvXVtuIC0gMV07CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoJ2NvYXJzZS1wcm9jZXNzb3InLCBDb2Fyc2VQcm9jZXNzb3IpOwoKY2xhc3MgQ3J1c2hQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogIHN0YXRpYyBnZXQgcGFyYW1ldGVyRGVzY3JpcHRvcnMoKSB7CiAgICByZXR1cm4gW3sgbmFtZTogJ2NydXNoJywgZGVmYXVsdFZhbHVlOiAwIH1dOwogIH0KCiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5ub3RTdGFydGVkID0gdHJ1ZTsKICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBpbnB1dCA9IGlucHV0c1swXTsKICAgIGNvbnN0IG91dHB1dCA9IG91dHB1dHNbMF07CiAgICBjb25zdCBjcnVzaCA9IHBhcmFtZXRlcnMuY3J1c2g7CiAgICBjb25zdCBibG9ja1NpemUgPSAxMjg7CiAgICBjb25zdCBoYXNJbnB1dCA9ICEoaW5wdXRbMF0gPT09IHVuZGVmaW5lZCk7CiAgICBpZiAoaGFzSW5wdXQpIHsKICAgICAgdGhpcy5ub3RTdGFydGVkID0gZmFsc2U7CiAgICAgIGlmIChjcnVzaC5sZW5ndGggPT09IDEpIHsKICAgICAgICBjb25zdCB4ID0gTWF0aC5wb3coMiwgY3J1c2hbMF0gLSAxKTsKICAgICAgICBmb3IgKGxldCBuID0gMDsgbiA8IGJsb2NrU2l6ZTsgbisrKSB7CiAgICAgICAgICBjb25zdCB2YWx1ZSA9IE1hdGgucm91bmQoaW5wdXRbMF1bbl0gKiB4KSAvIHg7CiAgICAgICAgICBmb3IgKGxldCBvID0gMDsgbyA8IG91dHB1dC5sZW5ndGg7IG8rKykgewogICAgICAgICAgICBvdXRwdXRbb11bbl0gPSB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yIChsZXQgbiA9IDA7IG4gPCBibG9ja1NpemU7IG4rKykgewogICAgICAgICAgbGV0IHggPSBNYXRoLnBvdygyLCBjcnVzaFtuXSAtIDEpOwogICAgICAgICAgY29uc3QgdmFsdWUgPSBNYXRoLnJvdW5kKGlucHV0WzBdW25dICogeCkgLyB4OwogICAgICAgICAgZm9yIChsZXQgbyA9IDA7IG8gPCBvdXRwdXQubGVuZ3RoOyBvKyspIHsKICAgICAgICAgICAgb3V0cHV0W29dW25dID0gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQpyZWdpc3RlclByb2Nlc3NvcignY3J1c2gtcHJvY2Vzc29yJywgQ3J1c2hQcm9jZXNzb3IpOwoKY2xhc3MgU2hhcGVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogIHN0YXRpYyBnZXQgcGFyYW1ldGVyRGVzY3JpcHRvcnMoKSB7CiAgICByZXR1cm4gW3sgbmFtZTogJ3NoYXBlJywgZGVmYXVsdFZhbHVlOiAwIH1dOwogIH0KCiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5ub3RTdGFydGVkID0gdHJ1ZTsKICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBpbnB1dCA9IGlucHV0c1swXTsKICAgIGNvbnN0IG91dHB1dCA9IG91dHB1dHNbMF07CiAgICBjb25zdCBzaGFwZTAgPSBwYXJhbWV0ZXJzLnNoYXBlWzBdOwogICAgY29uc3Qgc2hhcGUxID0gc2hhcGUwIDwgMSA/IHNoYXBlMCA6IDEuMCAtIDRlLTEwOwogICAgY29uc3Qgc2hhcGUgPSAoMi4wICogc2hhcGUxKSAvICgxLjAgLSBzaGFwZTEpOwogICAgY29uc3QgYmxvY2tTaXplID0gMTI4OwogICAgY29uc3QgaGFzSW5wdXQgPSAhKGlucHV0WzBdID09PSB1bmRlZmluZWQpOwogICAgaWYgKGhhc0lucHV0KSB7CiAgICAgIHRoaXMubm90U3RhcnRlZCA9IGZhbHNlOwogICAgICBmb3IgKGxldCBuID0gMDsgbiA8IGJsb2NrU2l6ZTsgbisrKSB7CiAgICAgICAgY29uc3QgdmFsdWUgPSAoKDEgKyBzaGFwZSkgKiBpbnB1dFswXVtuXSkgLyAoMSArIHNoYXBlICogTWF0aC5hYnMoaW5wdXRbMF1bbl0pKTsKICAgICAgICBmb3IgKGxldCBvID0gMDsgbyA8IG91dHB1dC5sZW5ndGg7IG8rKykgewogICAgICAgICAgb3V0cHV0W29dW25dID0gdmFsdWU7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoJ3NoYXBlLXByb2Nlc3NvcicsIFNoYXBlUHJvY2Vzc29yKTsK";function Nl(n){const e=Yr().createGain();return e.gain.value=n,e}const hM=({s:n,freq:e,t})=>{const r=Yr().createOscillator();return r.type=n||"triangle",r.frequency.value=Number(e),r.start(t),{node:r,stop:i=>r.stop(i)}},qy=(n,e,t,r,i,a)=>{const s=Yr().createGain();return s.gain.setValueAtTime(0,a),s.gain.linearRampToValueAtTime(i,a+n),s.gain.linearRampToValueAtTime(t*i,a+n+e),{node:s,stop:o=>{s.gain.setValueAtTime(t*i,o),s.gain.linearRampToValueAtTime(0,o+r)}}},Fc=(n,e,t)=>{const r=Yr().createBiquadFilter();return r.type=n,r.frequency.value=e,r.Q.value=t,r};let mM=n=>console.log(n);const Ya=(...n)=>mM(...n),Pm=aM();function Vy(n,e,t={}){Pm.setKey(n,{onTrigger:e,data:t})}function QS(n){return Pm.get()[n]}let Yc;const Yr=()=>(Yc||(Yc=new AudioContext),Yc);let xo;const Bm=()=>{const n=Yr();return xo||(xo=n.createGain(),xo.connect(n.destination)),xo};let Gc;function _M(){return Gc||(Gc=Yr().audioWorklet.addModule(fM),Gc)}function $c(n,e,t){const r=new AudioWorkletNode(n,e);return Object.entries(t).forEach(([i,a])=>{r.parameters.get(i).value=a}),r}async function gM(n={}){const{disableWorklets:e=!1}=n;typeof window<"u"&&(await Yr().resume(),e?console.log("disableWorklets: AudioWorklet effects coarse, crush and shape are skipped!"):await _M().catch(t=>{console.warn("could not load AudioWorklet effects coarse, crush and shape",t)}))}async function SM(n){return new Promise(e=>{document.addEventListener("click",async function t(){await gM(n),e(),document.removeEventListener("click",t)})})}let xi={};function OM(n,e,t,r){var i;if(t=uM(t,0,.98),!xi[n]){const a=Yr().createFeedbackDelay(1,e,t);(i=a.start)==null||i.call(a,r),a.connect(Bm()),xi[n]=a}return xi[n].delayTime.value!==e&&xi[n].delayTime.setValueAtTime(e,r),xi[n].feedback.value!==t&&xi[n].feedback.setValueAtTime(t,r),xi[n]}let Li={};function EM(n,e=2){if(!Li[n]){const t=Yr().createReverb(e);t.connect(Bm()),Li[n]=t}return Li[n].duration!==e&&(Li[n]=Li[n].setDuration(e),Li[n].duration=e),Li[n]}function qS(n,e,t){const r=Nl(t);return n.connect(r),r.connect(e),r}const bM=async(n,e,t)=>{const r=Yr();if(typeof n!="object")throw new Error(`expected hap.value to be an object, but got "${n}". Hint: append .note() or .s() to the end`,"error");let i=r.currentTime+e,{s:a="triangle",bank:s,source:o,gain:l=.8,cutoff:c,resonance:d=1,hcutoff:p,hresonance:m=1,bandf:g,bandq:b=1,coarse:v,crush:y,shape:N,pan:U,vowel:W,delay:f=0,delayfeedback:E=.5,delaytime:O=.25,orbit:A=1,room:D,size:M=2,velocity:w=1}=n;l*=w;let B=[];const re=()=>{B.forEach(Z=>Z==null?void 0:Z.disconnect())};s&&a&&(a=`${s}_${a}`);let ie;if(o)ie=o(i,n,t);else if(QS(a)){const{onTrigger:Z}=QS(a),z=await Z(i,n,re);z&&(ie=z.node,z.stop(i+t))}else throw new Error(`sound ${a} not found! Is it loaded?`);if(!ie)return;if(r.currentTime>i){Ya("[webaudio] skip hap: still loading",r.currentTime-i);return}const j=[];if(j.push(ie),j.push(Nl(l)),c!==void 0&&j.push(Fc("lowpass",c,d)),p!==void 0&&j.push(Fc("highpass",p,m)),g!==void 0&&j.push(Fc("bandpass",g,b)),W!==void 0&&j.push(r.createVowelFilter(W)),v!==void 0&&j.push($c(r,"coarse-processor",{coarse:v})),y!==void 0&&j.push($c(r,"crush-processor",{crush:y})),N!==void 0&&j.push($c(r,"shape-processor",{shape:N})),U!==void 0){const Z=r.createStereoPanner();Z.pan.value=2*U-1,j.push(Z)}const J=Nl(1);j.push(J),J.connect(Bm());let L;if(f>0&&O>0&&E>0){const Z=OM(A,O,E,i);L=qS(J,Z,f)}let G;if(D>0&&M>0){const Z=EM(A,M);G=qS(J,Z,D)}j.slice(1).reduce((Z,z)=>Z.connect(z),j[0]),B=j.concat([L,G])},Qc={};function TM(n,e){var t=e?1e3:1024;if(n=t);return n.toFixed(1)+" "+r[i]}const CM=async(n,e,t,r,i,a,s)=>{let o=0;i!==void 0&&t!==void 0&&Ya("[sampler] hap has note and freq. ignoring note","warning");let l=pM({freq:i,note:t},36);o=l-36;const c=Yr();let d;if(Array.isArray(a))d=a[e%a.length];else{const b=y=>Mm(y)-l,v=Object.keys(a).filter(y=>!y.startsWith("_")).reduce((y,N,U)=>!y||Math.abs(b(N)){const i=t?`sound "${t}:${r}"`:"sample";if(!Qc[n]){Ya(`[sampler] load ${i}..`,"load-sample",{url:n});const a=Date.now();Qc[n]=fetch(n).then(s=>s.arrayBuffer()).then(async s=>{const o=Date.now()-a,l=TM(s.byteLength);return Ya(`[sampler] load ${i}... done! loaded ${l} in ${o}ms`,"loaded-sample",{url:n}),await e.decodeAudioData(s)})}return Qc[n]};function yM(n){const e=Yr(),t=e.createBuffer(n.numberOfChannels,n.length,e.sampleRate);for(let r=0;rObject.entries(n).forEach(([r,i])=>{if(typeof i=="string"&&(i=[i]),typeof i!="object")throw new Error("wrong sample map format for "+r);t=i._base||t;const a=s=>(t+s).replace("github:","https://raw.githubusercontent.com/");Array.isArray(i)?i=i.map(a):i=Object.fromEntries(Object.entries(i).map(([s,o])=>[s,(typeof o=="string"?[o]:o).map(a)])),e(r,i)});let RM={};function IM(n){const e=Object.entries(RM).find(([t])=>n.startsWith(t));if(e)return e[1]}const Dl=async(n,e=n._base||"",t={})=>{if(typeof n=="string"){const a=IM(n);if(a)return a(n);if(n.startsWith("github:")){let[o,l]=n.split("github:");l=l.endsWith("/")?l.slice(0,-1):l,n=`https://raw.githubusercontent.com/${l}/strudel.json`}if(typeof fetch!="function")return;const s=n.split("/").slice(0,-1).join("/");return typeof fetch>"u"?void 0:fetch(n).then(o=>o.json()).then(o=>Dl(o,e||o._base||s,t)).catch(o=>{throw console.error(o),new Error(`error loading "${n}"`)})}const{prebake:r,tag:i}=t;AM(n,(a,s)=>Vy(a,(o,l,c)=>NM(o,l,c,s),{type:"sample",samples:s,baseUrl:e,prebake:r,tag:i}),e)},VS=[];async function NM(n,e,t,r,i){const{s:a,freq:s,unit:o,nudge:l=0,cut:c,loop:d,clip:p=void 0,n:m=0,note:g,speed:b=1,begin:v=0,end:y=1}=e;if(b===0)return;const N=Yr(),{attack:U=.001,decay:W=.001,sustain:f=1,release:E=.001}=e,O=n+l,A=await CM(a,m,g,b,s,r,i);if(N.currentTime>n){Ya(`[sampler] still loading sound "${a}:${m}"`,"highlight");return}if(!A){Ya(`[sampler] could not load "${a}:${m}"`,"error");return}A.playbackRate.value=Math.abs(b)*A.playbackRate.value,o==="c"&&(A.playbackRate.value=A.playbackRate.value*A.buffer.duration*1);const D=v*A.buffer.duration;A.start(O,D);const M=A.buffer.duration/A.playbackRate.value,{node:w,stop:B}=qy(U,W,f,E,1,n);A.connect(w);const re=N.createGain();w.connect(re),A.onended=function(){A.disconnect(),w.disconnect(),re.disconnect(),t()};const ie={node:re,bufferSource:A,stop:(j,J=p===void 0)=>{let L=j;J&&(L=n+(y-v)*M),A.stop(L+E),B(L)}};if(c!==void 0){const j=VS[c];j&&(j.node.gain.setValueAtTime(1,O),j.node.gain.linearRampToValueAtTime(0,O+.01)),VS[c]=ie}return ie}const DM=(n,e=1,t="sine")=>{const r=Yr(),i=r.createOscillator();i.type=t,i.frequency.value=n,i.start();const a=new GainNode(r,{gain:e});return i.connect(a),{node:a,stop:s=>i.stop(s)}},wM=(n,e,t,r="sine")=>{const i=n.frequency.value*e,a=i*t;return DM(i,a,r)};function xM(){["sine","square","triangle","sawtooth"].forEach(n=>{Vy(n,(e,t,r)=>{const{attack:i=.001,decay:a=.05,sustain:s=.6,release:o=.01,fmh:l=1,fmi:c}=t;let{n:d,note:p,freq:m}=t;d=p||d||36,typeof d=="string"&&(d=Mm(d)),!m&&typeof d=="number"&&(m=cM(d));const{node:g,stop:b}=hM({t:e,s:n,freq:m});let v;if(c){const{node:W,stop:f}=wM(g,l,c);W.connect(g.frequency),v=f}const y=Nl(.3),{node:N,stop:U}=qy(i,a,s,o,1,e);return g.onended=()=>{g.disconnect(),y.disconnect(),r()},{node:g.connect(y).connect(N),stop:W=>{U(W);let f=W+o;b(f),v==null||v(f)}}},{type:"synth",prebake:!0})})}class Hy extends Qy{constructor(t,r){super(r);R(this,"attack",t=>(this.values.attack=t,this));R(this,"atk",this.attack);R(this,"decay",t=>(this.values.decay=t,this));R(this,"dec",this.decay);R(this,"release",t=>(this.values.release=t,this));R(this,"rel",this.release);R(this,"unit",t=>(this.values.unit=t,this));R(this,"freq",t=>(this.values.freq=t,this));R(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let r=t.split(":");this.values.fmi=parseFloat(r[0]),r.length>1&&(this.values.fmh=parseFloat(r[1]))}return this});R(this,"sound",t=>(this.values.s=t,this));R(this,"fmi",t=>(this.values.fmi=t,this));R(this,"fmh",t=>(this.values.fmh=t,this));R(this,"nudge",t=>(this.values.nudge=t,this));R(this,"cut",t=>(this.values.cut=t,this));R(this,"loop",t=>(this.values.loop=t,this));R(this,"clip",t=>(this.values.clip=t,this));R(this,"n",t=>(this.values.n=t,this));R(this,"note",t=>(this.values.note=t,this));R(this,"speed",t=>(this.values.speed=t,this));R(this,"begin",t=>(this.values.begin=t,this));R(this,"end",t=>(this.values.end=t,this));R(this,"gain",t=>(this.values.gain=t,this));R(this,"cutoff",t=>(this.values.cutoff=t,this));R(this,"lpf",this.cutoff);R(this,"resonance",t=>(this.values.resonance=t,this));R(this,"lpq",this.resonance);R(this,"hcutoff",t=>(this.values.hcutoff=t,this));R(this,"hpf",this.hcutoff);R(this,"hresonance",t=>(this.values.hresonance=t,this));R(this,"hpq",this.hresonance);R(this,"bandf",t=>(this.values.bandf=t,this));R(this,"bpf",this.bandf);R(this,"bandq",t=>(this.values.bandq=t,this));R(this,"bpq",this.bandq);R(this,"coarse",t=>(this.values.coarse=t,this));R(this,"crush",t=>(this.values.crush=t,this));R(this,"shape",t=>(this.values.shape=t,this));R(this,"pan",t=>(this.values.pan=t,this));R(this,"vowel",t=>(this.values.vowel=t,this));R(this,"delay",t=>(this.values.delay=t,this));R(this,"del",this.delay);R(this,"delayfeedback",t=>(this.values.delayfeedback=t,this));R(this,"delayfb",this.delayfeedback);R(this,"delaytime",t=>(this.values.delaytime=t,this));R(this,"delayt",this.delaytime);R(this,"orbit",t=>(this.values.orbit=t,this));R(this,"o",this.orbit);R(this,"room",t=>(this.values.room=t,this));R(this,"size",t=>(this.values.size=t,this));R(this,"sz",this.size);R(this,"velocity",t=>(this.values.velocity=t,this));R(this,"vel",this.velocity);R(this,"modify",t=>{const r=t(this);return r instanceof Object?r:(t(this.values),this)});R(this,"sustain",t=>(this.values.dur=t,this));R(this,"sus",this.sustain);R(this,"update",()=>{if(this.values.key&&this.values.pitch&&this.values.parsedScale&&this.values.octave){const[t,r]=xm(this.values.key,this.values.pitch,this.values.parsedScale,this.values.octave);this.values.freq=Ys(t)}});R(this,"out",()=>bM(this.values,this.app.clock.pulse_duration,this.values.dur||.5));this.app=r,typeof t=="string"?this.values={s:t,dur:.5}:this.values=t}}class zy extends Qy{constructor(t,r){super(r);R(this,"midiConnection");R(this,"note",t=>(this.values.note=t,this));R(this,"sustain",t=>(this.values.sustain=t,this));R(this,"channel",t=>(this.values.channel=t,this));R(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));R(this,"add",t=>(this.values.note+=t,this));R(this,"modify",t=>{const r=t(this);return r instanceof Object?r:(t(this.values),this)});R(this,"bend",t=>(this.values.bend=t,this));R(this,"random",(t=0,r=127)=>(t=Math.min(Math.max(t,0),127),r=Math.min(Math.max(r,0),127),this.values.note=Math.floor(this.randomGen()*(r-t+1))+t,this));R(this,"update",()=>{if(this.values.key&&this.values.pitch&&this.values.parsedScale&&this.values.octave){const[t,r]=xm(this.values.key,this.values.pitch,this.values.parsedScale,this.values.octave);this.values.note=t,this.values.freq=Ys(t),r&&(this.values.bend=r)}});R(this,"out",()=>{const t=this.values.note?this.values.note:60,r=this.values.channel?this.values.channel:0,i=this.values.velocity?this.values.velocity:100,a=this.values.sustain?this.values.sustain*this.app.clock.pulse_duration*this.app.api.ppqn():this.app.clock.pulse_duration*this.app.api.ppqn(),s=this.values.bend?this.values.bend:void 0,o=this.values.port?this.midiConnection.getMidiOutputIndex(this.values.port):this.midiConnection.getCurrentMidiPortIndex();this.midiConnection.sendMidiNote(t,r,i,a,o,s)});this.app=r,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=r.api.MidiConnection}}const ss=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,Wy=new Set,Dh=typeof process=="object"&&process?process:{},Xy=(n,e,t,r)=>{typeof Dh.emitWarning=="function"?Dh.emitWarning(n,e,t,r):console.error(`[${t}] ${e}: ${n}`)};let wl=globalThis.AbortController,HS=globalThis.AbortSignal;var LT;if(typeof wl>"u"){HS=class{constructor(){R(this,"onabort");R(this,"_onabort",[]);R(this,"reason");R(this,"aborted",!1)}addEventListener(r,i){this._onabort.push(i)}},wl=class{constructor(){R(this,"signal",new HS);e()}abort(r){var i,a;if(!this.signal.aborted){this.signal.reason=r,this.signal.aborted=!0;for(const s of this.signal._onabort)s(r);(a=(i=this.signal).onabort)==null||a.call(i,r)}}};let n=((LT=Dh.env)==null?void 0:LT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{n&&(n=!1,Xy("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 LM=n=>!Wy.has(n),ci=n=>n&&n===Math.floor(n)&&n>0&&isFinite(n),Zy=n=>ci(n)?n<=Math.pow(2,8)?Uint8Array:n<=Math.pow(2,16)?Uint16Array:n<=Math.pow(2,32)?Uint32Array:n<=Number.MAX_SAFE_INTEGER?Xo:null:null;class Xo extends Array{constructor(e){super(e),this.fill(0)}}var va;const Pi=class Pi{constructor(e,t){R(this,"heap");R(this,"length");if(!$(Pi,va))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=Zy(e);if(!t)return[];$e(Pi,va,!0);const r=new Pi(e,t);return $e(Pi,va,!1),r}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};va=new WeakMap,tt(Pi,va,!1);let wh=Pi;var _n,Vr,gn,Sn,ya,Kt,On,jt,xt,et,Nr,Hr,gr,sr,En,or,Hn,zn,bn,Tn,mi,Dr,Qs,Lh,Gi,Wn,qs,zr,Pl,Ky,$i,Aa,Vs,xn,ui,Ln,di,Hs,kh,Ra,Zo,Ia,Ko,At,Mt,zs,Mh,Qi,fs;const $m=class $m{constructor(e){tt(this,Qs);tt(this,Pl);tt(this,xn);tt(this,Ln);tt(this,Hs);tt(this,Ra);tt(this,Ia);tt(this,At);tt(this,zs);tt(this,Qi);tt(this,_n,void 0);tt(this,Vr,void 0);tt(this,gn,void 0);tt(this,Sn,void 0);tt(this,ya,void 0);R(this,"ttl");R(this,"ttlResolution");R(this,"ttlAutopurge");R(this,"updateAgeOnGet");R(this,"updateAgeOnHas");R(this,"allowStale");R(this,"noDisposeOnSet");R(this,"noUpdateTTL");R(this,"maxEntrySize");R(this,"sizeCalculation");R(this,"noDeleteOnFetchRejection");R(this,"noDeleteOnStaleGet");R(this,"allowStaleOnFetchAbort");R(this,"allowStaleOnFetchRejection");R(this,"ignoreFetchAbort");tt(this,Kt,void 0);tt(this,On,void 0);tt(this,jt,void 0);tt(this,xt,void 0);tt(this,et,void 0);tt(this,Nr,void 0);tt(this,Hr,void 0);tt(this,gr,void 0);tt(this,sr,void 0);tt(this,En,void 0);tt(this,or,void 0);tt(this,Hn,void 0);tt(this,zn,void 0);tt(this,bn,void 0);tt(this,Tn,void 0);tt(this,mi,void 0);tt(this,Dr,void 0);tt(this,Gi,()=>{});tt(this,Wn,()=>{});tt(this,qs,()=>{});tt(this,zr,()=>!1);tt(this,$i,e=>{});tt(this,Aa,(e,t,r)=>{});tt(this,Vs,(e,t,r,i)=>{if(r||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:d,noDisposeOnSet:p,noUpdateTTL:m,maxSize:g=0,maxEntrySize:b=0,sizeCalculation:v,fetchMethod:y,noDeleteOnFetchRejection:N,noDeleteOnStaleGet:U,allowStaleOnFetchRejection:W,allowStaleOnFetchAbort:f,ignoreFetchAbort:E}=e;if(t!==0&&!ci(t))throw new TypeError("max option must be a nonnegative integer");const O=t?Zy(t):Array;if(!O)throw new Error("invalid max value: "+t);if($e(this,_n,t),$e(this,Vr,g),this.maxEntrySize=b||$(this,Vr),this.sizeCalculation=v,this.sizeCalculation){if(!$(this,Vr)&&!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(y!==void 0&&typeof y!="function")throw new TypeError("fetchMethod must be a function if specified");if($e(this,ya,y),$e(this,mi,!!y),$e(this,jt,new Map),$e(this,xt,new Array(t).fill(void 0)),$e(this,et,new Array(t).fill(void 0)),$e(this,Nr,new O(t)),$e(this,Hr,new O(t)),$e(this,gr,0),$e(this,sr,0),$e(this,En,wh.create(t)),$e(this,Kt,0),$e(this,On,0),typeof c=="function"&&$e(this,gn,c),typeof d=="function"?($e(this,Sn,d),$e(this,or,[])):($e(this,Sn,void 0),$e(this,or,void 0)),$e(this,Tn,!!$(this,gn)),$e(this,Dr,!!$(this,Sn)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!N,this.allowStaleOnFetchRejection=!!W,this.allowStaleOnFetchAbort=!!f,this.ignoreFetchAbort=!!E,this.maxEntrySize!==0){if($(this,Vr)!==0&&!ci($(this,Vr)))throw new TypeError("maxSize must be a positive integer if specified");if(!ci(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");Ue(this,Pl,Ky).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!U,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=ci(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!ci(this.ttl))throw new TypeError("ttl must be a positive integer if specified");Ue(this,Qs,Lh).call(this)}if($(this,_n)===0&&this.ttl===0&&$(this,Vr)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!$(this,_n)&&!$(this,Vr)){const A="LRU_CACHE_UNBOUNDED";LM(A)&&(Wy.add(A),Xy("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",A,$m))}}static unsafeExposeInternals(e){return{starts:$(e,zn),ttls:$(e,bn),sizes:$(e,Hn),keyMap:$(e,jt),keyList:$(e,xt),valList:$(e,et),next:$(e,Nr),prev:$(e,Hr),get head(){return $(e,gr)},get tail(){return $(e,sr)},free:$(e,En),isBackgroundFetch:t=>{var r;return Ue(r=e,At,Mt).call(r,t)},backgroundFetch:(t,r,i,a)=>{var s;return Ue(s=e,Ia,Ko).call(s,t,r,i,a)},moveToTail:t=>{var r;return Ue(r=e,Qi,fs).call(r,t)},indexes:t=>{var r;return Ue(r=e,xn,ui).call(r,t)},rindexes:t=>{var r;return Ue(r=e,Ln,di).call(r,t)},isStale:t=>{var r;return $(r=e,zr).call(r,t)}}}get max(){return $(this,_n)}get maxSize(){return $(this,Vr)}get calculatedSize(){return $(this,On)}get size(){return $(this,Kt)}get fetchMethod(){return $(this,ya)}get dispose(){return $(this,gn)}get disposeAfter(){return $(this,Sn)}getRemainingTTL(e){return $(this,jt).has(e)?1/0:0}*entries(){for(const e of Ue(this,xn,ui).call(this))$(this,et)[e]!==void 0&&$(this,xt)[e]!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield[$(this,xt)[e],$(this,et)[e]])}*rentries(){for(const e of Ue(this,Ln,di).call(this))$(this,et)[e]!==void 0&&$(this,xt)[e]!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield[$(this,xt)[e],$(this,et)[e]])}*keys(){for(const e of Ue(this,xn,ui).call(this)){const t=$(this,xt)[e];t!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield t)}}*rkeys(){for(const e of Ue(this,Ln,di).call(this)){const t=$(this,xt)[e];t!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield t)}}*values(){for(const e of Ue(this,xn,ui).call(this))$(this,et)[e]!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield $(this,et)[e])}*rvalues(){for(const e of Ue(this,Ln,di).call(this))$(this,et)[e]!==void 0&&!Ue(this,At,Mt).call(this,$(this,et)[e])&&(yield $(this,et)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const r of Ue(this,xn,ui).call(this)){const i=$(this,et)[r],a=Ue(this,At,Mt).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,$(this,xt)[r],this))return this.get($(this,xt)[r],t)}}forEach(e,t=this){for(const r of Ue(this,xn,ui).call(this)){const i=$(this,et)[r],a=Ue(this,At,Mt).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,$(this,xt)[r],this)}}rforEach(e,t=this){for(const r of Ue(this,Ln,di).call(this)){const i=$(this,et)[r],a=Ue(this,At,Mt).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,$(this,xt)[r],this)}}purgeStale(){let e=!1;for(const t of Ue(this,Ln,di).call(this,{allowStale:!0}))$(this,zr).call(this,t)&&(this.delete($(this,xt)[t]),e=!0);return e}dump(){const e=[];for(const t of Ue(this,xn,ui).call(this,{allowStale:!0})){const r=$(this,xt)[t],i=$(this,et)[t],a=Ue(this,At,Mt).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||r===void 0)continue;const s={value:a};if($(this,bn)&&$(this,zn)){s.ttl=$(this,bn)[t];const o=ss.now()-$(this,zn)[t];s.start=Math.floor(Date.now()-o)}$(this,Hn)&&(s.size=$(this,Hn)[t]),e.unshift([r,s])}return e}load(e){this.clear();for(const[t,r]of e){if(r.start){const i=Date.now()-r.start;r.start=ss.now()-i}this.set(t,r.value,r)}}set(e,t,r={}){var m,g,b,v,y;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}=r;let{noUpdateTTL:c=this.noUpdateTTL}=r;const d=$(this,Vs).call(this,e,t,r.size||0,o);if(this.maxEntrySize&&d>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=$(this,Kt)===0?void 0:$(this,jt).get(e);if(p===void 0)p=$(this,Kt)===0?$(this,sr):$(this,En).length!==0?$(this,En).pop():$(this,Kt)===$(this,_n)?Ue(this,Ra,Zo).call(this,!1):$(this,Kt),$(this,xt)[p]=e,$(this,et)[p]=t,$(this,jt).set(e,p),$(this,Nr)[$(this,sr)]=p,$(this,Hr)[p]=$(this,sr),$e(this,sr,p),lo(this,Kt)._++,$(this,Aa).call(this,p,d,l),l&&(l.set="add"),c=!1;else{Ue(this,Qi,fs).call(this,p);const N=$(this,et)[p];if(t!==N){if($(this,mi)&&Ue(this,At,Mt).call(this,N)){N.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:U}=N;U!==void 0&&!s&&($(this,Tn)&&((m=$(this,gn))==null||m.call(this,U,e,"set")),$(this,Dr)&&((g=$(this,or))==null||g.push([U,e,"set"])))}else s||($(this,Tn)&&((b=$(this,gn))==null||b.call(this,N,e,"set")),$(this,Dr)&&((v=$(this,or))==null||v.push([N,e,"set"])));if($(this,$i).call(this,p),$(this,Aa).call(this,p,d,l),$(this,et)[p]=t,l){l.set="replace";const U=N&&Ue(this,At,Mt).call(this,N)?N.__staleWhileFetching:N;U!==void 0&&(l.oldValue=U)}}else l&&(l.set="update")}if(i!==0&&!$(this,bn)&&Ue(this,Qs,Lh).call(this),$(this,bn)&&(c||$(this,qs).call(this,p,i,a),l&&$(this,Wn).call(this,l,p)),!s&&$(this,Dr)&&$(this,or)){const N=$(this,or);let U;for(;U=N==null?void 0:N.shift();)(y=$(this,Sn))==null||y.call(this,...U)}return this}pop(){var e;try{for(;$(this,Kt);){const t=$(this,et)[$(this,gr)];if(Ue(this,Ra,Zo).call(this,!0),Ue(this,At,Mt).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if($(this,Dr)&&$(this,or)){const t=$(this,or);let r;for(;r=t==null?void 0:t.shift();)(e=$(this,Sn))==null||e.call(this,...r)}}}has(e,t={}){const{updateAgeOnHas:r=this.updateAgeOnHas,status:i}=t,a=$(this,jt).get(e);if(a!==void 0){const s=$(this,et)[a];if(Ue(this,At,Mt).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if($(this,zr).call(this,a))i&&(i.has="stale",$(this,Wn).call(this,i,a));else return r&&$(this,Gi).call(this,a),i&&(i.has="hit",$(this,Wn).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:r=this.allowStale}=t,i=$(this,jt).get(e);if(i!==void 0&&(r||!$(this,zr).call(this,i))){const a=$(this,et)[i];return Ue(this,At,Mt).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:r=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:d=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:b=this.allowStaleOnFetchAbort,context:v,forceRefresh:y=!1,status:N,signal:U}=t;if(!$(this,mi))return N&&(N.fetch="get"),this.get(e,{allowStale:r,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:N});const W={allowStale:r,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:d,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:b,ignoreFetchAbort:g,status:N,signal:U};let f=$(this,jt).get(e);if(f===void 0){N&&(N.fetch="miss");const E=Ue(this,Ia,Ko).call(this,e,f,W,v);return E.__returned=E}else{const E=$(this,et)[f];if(Ue(this,At,Mt).call(this,E)){const w=r&&E.__staleWhileFetching!==void 0;return N&&(N.fetch="inflight",w&&(N.returnedStale=!0)),w?E.__staleWhileFetching:E.__returned=E}const O=$(this,zr).call(this,f);if(!y&&!O)return N&&(N.fetch="hit"),Ue(this,Qi,fs).call(this,f),i&&$(this,Gi).call(this,f),N&&$(this,Wn).call(this,N,f),E;const A=Ue(this,Ia,Ko).call(this,e,f,W,v),M=A.__staleWhileFetching!==void 0&&r;return N&&(N.fetch=O?"stale":"refresh",M&&O&&(N.returnedStale=!0)),M?A.__staleWhileFetching:A.__returned=A}}get(e,t={}){const{allowStale:r=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=$(this,jt).get(e);if(o!==void 0){const l=$(this,et)[o],c=Ue(this,At,Mt).call(this,l);return s&&$(this,Wn).call(this,s,o),$(this,zr).call(this,o)?(s&&(s.get="stale"),c?(s&&r&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),r?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&r&&(s.returnedStale=!0),r?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:(Ue(this,Qi,fs).call(this,o),i&&$(this,Gi).call(this,o),l))}else s&&(s.get="miss")}delete(e){var r,i,a,s;let t=!1;if($(this,Kt)!==0){const o=$(this,jt).get(e);if(o!==void 0)if(t=!0,$(this,Kt)===1)this.clear();else{$(this,$i).call(this,o);const l=$(this,et)[o];Ue(this,At,Mt).call(this,l)?l.__abortController.abort(new Error("deleted")):($(this,Tn)||$(this,Dr))&&($(this,Tn)&&((r=$(this,gn))==null||r.call(this,l,e,"delete")),$(this,Dr)&&((i=$(this,or))==null||i.push([l,e,"delete"]))),$(this,jt).delete(e),$(this,xt)[o]=void 0,$(this,et)[o]=void 0,o===$(this,sr)?$e(this,sr,$(this,Hr)[o]):o===$(this,gr)?$e(this,gr,$(this,Nr)[o]):($(this,Nr)[$(this,Hr)[o]]=$(this,Nr)[o],$(this,Hr)[$(this,Nr)[o]]=$(this,Hr)[o]),lo(this,Kt)._--,$(this,En).push(o)}}if($(this,Dr)&&((a=$(this,or))!=null&&a.length)){const o=$(this,or);let l;for(;l=o==null?void 0:o.shift();)(s=$(this,Sn))==null||s.call(this,...l)}return t}clear(){var e,t,r;for(const i of Ue(this,Ln,di).call(this,{allowStale:!0})){const a=$(this,et)[i];if(Ue(this,At,Mt).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=$(this,xt)[i];$(this,Tn)&&((e=$(this,gn))==null||e.call(this,a,s,"delete")),$(this,Dr)&&((t=$(this,or))==null||t.push([a,s,"delete"]))}}if($(this,jt).clear(),$(this,et).fill(void 0),$(this,xt).fill(void 0),$(this,bn)&&$(this,zn)&&($(this,bn).fill(0),$(this,zn).fill(0)),$(this,Hn)&&$(this,Hn).fill(0),$e(this,gr,0),$e(this,sr,0),$(this,En).length=0,$e(this,On,0),$e(this,Kt,0),$(this,Dr)&&$(this,or)){const i=$(this,or);let a;for(;a=i==null?void 0:i.shift();)(r=$(this,Sn))==null||r.call(this,...a)}}};_n=new WeakMap,Vr=new WeakMap,gn=new WeakMap,Sn=new WeakMap,ya=new WeakMap,Kt=new WeakMap,On=new WeakMap,jt=new WeakMap,xt=new WeakMap,et=new WeakMap,Nr=new WeakMap,Hr=new WeakMap,gr=new WeakMap,sr=new WeakMap,En=new WeakMap,or=new WeakMap,Hn=new WeakMap,zn=new WeakMap,bn=new WeakMap,Tn=new WeakMap,mi=new WeakMap,Dr=new WeakMap,Qs=new WeakSet,Lh=function(){const e=new Xo($(this,_n)),t=new Xo($(this,_n));$e(this,bn,e),$e(this,zn,t),$e(this,qs,(a,s,o=ss.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{$(this,zr).call(this,a)&&this.delete($(this,xt)[a])},s+1);l.unref&&l.unref()}}),$e(this,Gi,a=>{t[a]=e[a]!==0?ss.now():0}),$e(this,Wn,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=r||i();const c=a.now-l;a.remainingTTL=o-c}});let r=0;const i=()=>{const a=ss.now();if(this.ttlResolution>0){r=a;const s=setTimeout(()=>r=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=$(this,jt).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=(r||i())-l;return o-c},$e(this,zr,a=>e[a]!==0&&t[a]!==0&&(r||i())-t[a]>e[a])},Gi=new WeakMap,Wn=new WeakMap,qs=new WeakMap,zr=new WeakMap,Pl=new WeakSet,Ky=function(){const e=new Xo($(this,_n));$e(this,On,0),$e(this,Hn,e),$e(this,$i,t=>{$e(this,On,$(this,On)-e[t]),e[t]=0}),$e(this,Vs,(t,r,i,a)=>{if(Ue(this,At,Mt).call(this,r))return 0;if(!ci(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(r,t),!ci(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}),$e(this,Aa,(t,r,i)=>{if(e[t]=r,$(this,Vr)){const a=$(this,Vr)-e[t];for(;$(this,On)>a;)Ue(this,Ra,Zo).call(this,!0)}$e(this,On,$(this,On)+e[t]),i&&(i.entrySize=r,i.totalCalculatedSize=$(this,On))})},$i=new WeakMap,Aa=new WeakMap,Vs=new WeakMap,xn=new WeakSet,ui=function*({allowStale:e=this.allowStale}={}){if($(this,Kt))for(let t=$(this,sr);!(!Ue(this,Hs,kh).call(this,t)||((e||!$(this,zr).call(this,t))&&(yield t),t===$(this,gr)));)t=$(this,Hr)[t]},Ln=new WeakSet,di=function*({allowStale:e=this.allowStale}={}){if($(this,Kt))for(let t=$(this,gr);!(!Ue(this,Hs,kh).call(this,t)||((e||!$(this,zr).call(this,t))&&(yield t),t===$(this,sr)));)t=$(this,Nr)[t]},Hs=new WeakSet,kh=function(e){return e!==void 0&&$(this,jt).get($(this,xt)[e])===e},Ra=new WeakSet,Zo=function(e){var a,s;const t=$(this,gr),r=$(this,xt)[t],i=$(this,et)[t];return $(this,mi)&&Ue(this,At,Mt).call(this,i)?i.__abortController.abort(new Error("evicted")):($(this,Tn)||$(this,Dr))&&($(this,Tn)&&((a=$(this,gn))==null||a.call(this,i,r,"evict")),$(this,Dr)&&((s=$(this,or))==null||s.push([i,r,"evict"]))),$(this,$i).call(this,t),e&&($(this,xt)[t]=void 0,$(this,et)[t]=void 0,$(this,En).push(t)),$(this,Kt)===1?($e(this,gr,$e(this,sr,0)),$(this,En).length=0):$e(this,gr,$(this,Nr)[t]),$(this,jt).delete(r),lo(this,Kt)._--,t},Ia=new WeakSet,Ko=function(e,t,r,i){const a=t===void 0?void 0:$(this,et)[t];if(Ue(this,At,Mt).call(this,a))return a;const s=new wl,{signal:o}=r;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:r,context:i},c=(v,y=!1)=>{const{aborted:N}=s.signal,U=r.ignoreFetchAbort&&v!==void 0;if(r.status&&(N&&!y?(r.status.fetchAborted=!0,r.status.fetchError=s.signal.reason,U&&(r.status.fetchAbortIgnored=!0)):r.status.fetchResolved=!0),N&&!U&&!y)return p(s.signal.reason);const W=g;return $(this,et)[t]===g&&(v===void 0?W.__staleWhileFetching?$(this,et)[t]=W.__staleWhileFetching:this.delete(e):(r.status&&(r.status.fetchUpdated=!0),this.set(e,v,l.options))),v},d=v=>(r.status&&(r.status.fetchRejected=!0,r.status.fetchError=v),p(v)),p=v=>{const{aborted:y}=s.signal,N=y&&r.allowStaleOnFetchAbort,U=N||r.allowStaleOnFetchRejection,W=U||r.noDeleteOnFetchRejection,f=g;if($(this,et)[t]===g&&(!W||f.__staleWhileFetching===void 0?this.delete(e):N||($(this,et)[t]=f.__staleWhileFetching)),U)return r.status&&f.__staleWhileFetching!==void 0&&(r.status.returnedStale=!0),f.__staleWhileFetching;if(f.__returned===f)throw v},m=(v,y)=>{var U;const N=(U=$(this,ya))==null?void 0:U.call(this,e,a,l);N&&N instanceof Promise&&N.then(W=>v(W===void 0?void 0:W),y),s.signal.addEventListener("abort",()=>{(!r.ignoreFetchAbort||r.allowStaleOnFetchAbort)&&(v(void 0),r.allowStaleOnFetchAbort&&(v=W=>c(W,!0)))})};r.status&&(r.status.fetchDispatched=!0);const g=new Promise(m).then(c,d),b=Object.assign(g,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,b,{...l.options,status:void 0}),t=$(this,jt).get(e)):$(this,et)[t]=b,b},At=new WeakSet,Mt=function(e){if(!$(this,mi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof wl},zs=new WeakSet,Mh=function(e,t){$(this,Hr)[t]=e,$(this,Nr)[e]=t},Qi=new WeakSet,fs=function(e){e!==$(this,sr)&&(e===$(this,gr)?$e(this,gr,$(this,Nr)[e]):Ue(this,zs,Mh).call(this,$(this,Hr)[e],$(this,Nr)[e]),Ue(this,zs,Mh).call(this,$(this,sr),e),$e(this,sr,e))};let xh=$m;const Os=class Os{constructor(){R(this,"_fallbackMethod",()=>Os.createSkipProxy());R(this,"out",()=>{})}};R(Os,"createSkipProxy",()=>{const e=new Os;return new Proxy(e,{get(t,r,i){return typeof t[r]>"u"?t._fallbackMethod:t[r]},set(t,r,i,a){return!1}})});let xl=Os;const Es=class Es extends km{constructor(t,r){super(r);R(this,"_fallbackMethod",()=>Es.createRestProxy(this.values.duration,this.app));R(this,"out",()=>{});this.values.duration=t}};R(Es,"createRestProxy",(t,r)=>{const i=new Es(t,r);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 Ll=Es;class kM extends km{constructor(t,r,i){super(i);R(this,"input");R(this,"ziffers");R(this,"firstCallTime",0);R(this,"lastCallTime",0);R(this,"waitTime",0);R(this,"startBeat",0);R(this,"played",!1);R(this,"current");R(this,"retro",!1);R(this,"index",-1);R(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));R(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));R(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.app.clock.next_beat_in_ticks)&&this.app.clock.pulses_since_origin+1>=this.firstCallTime+this.waitTime||this.current&&this.pulseToSecond(this.app.clock.pulses_since_origin+1)>=this.pulseToSecond(this.lastCallTime)+this.current.duration*4*this.pulseToSecond(this.app.api.ppqn());return this.index=t?this.index+1:this.index,t&&this.notStarted()&&(this.firstCallTime=this.app.clock.pulses_since_origin+1),t});R(this,"out",()=>{});this.app=i,this.input=t,this.ziffers=new jk(t,r)}get ticks(){return this.ziffers.duration*4*this.app.clock.ppqn}nextEndTime(){return this.firstCallTime+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 r=this.next();if(r instanceof Ki){const i=r.getExisting("freq","pitch","key","scale","octave");return new Hy(i,this.app).sound(t)}else if(r instanceof Nh)return Ll.createRestProxy(r.duration,this.app)}else return xl.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const r=this.next();if(r instanceof Ki){const i=r.getExisting("note","pitch","bend","key","scale","octave"),a=new zy(i,this.app);return t?a.note(t):a}else if(r instanceof Nh)return Ll.createRestProxy(r.duration,this.app)}else return xl.createSkipProxy()}scale(t){return this.ziffers.scale(t),this}key(t){return this.ziffers.key(t),this}octave(t){return this.ziffers.octave(t),this}retrograde(){return this.index===-1&&this.ziffers.index===-1&&this.ziffers.retrograde(),this}wait(t){return this.index===-1&&this.ziffers.index===-1&&(this.waitTime=Math.ceil(t*4*this.app.clock.ppqn)),this}}async function zS(){return Promise.all([SM(),Dl("github:tidalcycles/Dirt-Samples/master").then(()=>xM()),Dl("github:Bubobubobubobubo/Topos-Samples/main")])}class MM{constructor(e){R(this,"variables",{});R(this,"codeExamples",{});R(this,"counters",{});R(this,"_drunk",new tM(-100,100,!1));R(this,"randomGen",Math.random);R(this,"currentSeed");R(this,"localSeeds",new Map);R(this,"patternCache",new xh({max:1e3,ttl:1e3*60*5}));R(this,"errorTimeoutID",0);R(this,"MidiConnection",new eM);R(this,"load");R(this,"_loadUniverseFromInterface",e=>{this.app.loadUniverse(e),this.app.openBuffersModal()});R(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});R(this,"_playDocExample",e=>{this.play(),console.log("Executing documentation example: "+this.app.selectedExample),this.app.universes[this.app.selected_universe].global.candidate=e||this.app.selectedExample,Us(this.app,this.app.universes[this.app.selected_universe].global)});R(this,"_playDocExampleOnce",e=>{this.play(),console.log("Executing documentation example: "+this.app.selectedExample),Tk(this.app,e)});R(this,"_all_samples",()=>Pm.get());R(this,"_reportError",e=>{console.log(e),clearTimeout(this.errorTimeoutID),this.app.error_line.innerHTML=e,this.app.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.error_line.classList.add("hidden"),2e3)});R(this,"time",()=>this.app.audioContext.currentTime);R(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.app.clock.start()});R(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.app.clock.pause()});R(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.app.clock.stop()});R(this,"silence",this.stop);R(this,"hush",this.stop);R(this,"onmousemove",e=>{this.app._mouseX=e.clientX,this.app._mouseY=e.clientY});R(this,"mouseX",()=>this.app._mouseX);R(this,"mouseY",()=>this.app._mouseY);R(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));R(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));R(this,"script",(...e)=>{e.forEach(t=>{Us(this.app,this.app.universes[this.app.selected_universe].locals[t])})});R(this,"s",this.script);R(this,"clear_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});R(this,"cs",this.clear_script);R(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]=this.app.universes[this.app.selected_universe].locals[e]});R(this,"cps",this.copy_script);R(this,"midi_outputs",()=>(console.log(this.MidiConnection.listMidiOutputs()),this.MidiConnection.midiOutputs));R(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});R(this,"midi",(e=60,t,r)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),r!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=r),new zy(e,this.app)));R(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});R(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});R(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});R(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});R(this,"control_change",({control:e=20,value:t=0,channel:r=0})=>{this.MidiConnection.sendMidiControlChange(e,t,r)});R(this,"midi_panic",()=>{this.MidiConnection.panic()});R(this,"z",(e,t={})=>{const i=((...s)=>s.map(o=>JSON.stringify(o)).join(","))(e,t);let a;return this.app.api.patternCache.has(i)?a=this.app.api.patternCache.get(i):(a=new kM(e,t,this.app),this.app.api.patternCache.set(i,a)),a&&a.updateLastCallTime(),a});R(this,"counter",(e,t,r)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==r&&(this.counters[e].step=r??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:r??1,limit:t},this.counters[e].value));R(this,"$",this.counter);R(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);R(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));R(this,"drunk_max",e=>{this._drunk.max=e});R(this,"drunk_min",e=>{this._drunk.min=e});R(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});R(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));R(this,"v",this.variable);R(this,"delete_variable",e=>{delete this.variables[e]});R(this,"dv",this.delete_variable);R(this,"clear_variables",()=>{this.variables={}});R(this,"cv",this.clear_variables);R(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);R(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);R(this,"irand",this.randI);R(this,"rI",this.randI);R(this,"r",this.rand);R(this,"ir",this.randI);R(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=Ih(e))});R(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=Ih(e);return this.localSeeds.set(e,t),t});R(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});R(this,"quantize",(e,t)=>{if(t.length===0)return e;let r=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),r));R(this,"cmp",this.clamp);R(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));R(this,"tempo",this.bpm);R(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));R(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));R(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});R(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);R(this,"odds",(e,t=15)=>this.randomGen()this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));R(this,"rarely",(e=15)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));R(this,"scarcely",(e=15)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));R(this,"sometimes",(e=15)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));R(this,"often",(e=15)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));R(this,"frequently",(e=15)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));R(this,"almostAlways",(e=15)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));R(this,"dice",e=>Math.floor(this.randomGen()*e)+1);R(this,"bar",()=>this.app.clock.time_position.bar);R(this,"tick",()=>this.app.clock.tick);R(this,"pulse",()=>this.app.clock.time_position.pulse);R(this,"beat",()=>this.app.clock.time_position.beat);R(this,"ebeat",()=>this.app.clock.beats_since_origin);R(this,"epulse",()=>this.app.clock.pulses_since_origin);R(this,"mod",(...e)=>e.map(r=>this.epulse()%Math.floor(r*this.ppqn())===0).some(r=>r===!0));R(this,"modpulse",(...e)=>e.map(r=>this.epulse()%r===0).some(r=>r===!0));R(this,"pmod",this.modpulse);R(this,"modbar",(...e)=>e.map(r=>this.bar()%Math.floor(r*this.ppqn())===0).some(r=>r===!0));R(this,"bmod",this.modbar);R(this,"div",e=>{const t=this.epulse();return Math.floor(t/Math.floor(e*this.ppqn()))%2===0});R(this,"divbar",e=>{const t=this.bar()-1;return Math.floor(t/e)%2===0});R(this,"onbar",(e,...t)=>{const r=[...Array(e).keys()].map(i=>i+1);return console.log(t.some(i=>r.includes(i%e))),t.some(i=>r.includes(i%e))});R(this,"onbeat",(...e)=>{let t=[];return e.forEach(r=>{const i=r%this.app.clock.time_signature[0];r=i===0?r:i;let a=Math.floor(r),s=r-a;t.push(a===this.app.clock.time_position.beat&&this.app.clock.time_position.pulse===s*this.app.clock.ppqn)}),t.some(r=>r==!0)});R(this,"delay",(e,t)=>{setTimeout(t,e)});R(this,"delayr",(e,t,r)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(r,a)})});R(this,"euclid",(e,t,r,i=0)=>this._euclidean_cycle(t,r,i)[e%r]);R(this,"ec",this.euclid);R(this,"rhythm",(e,t,r,i=0)=>this.mod(e)&&this._euclidean_cycle(t,r,i).div(e));R(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});R(this,"line",(e,t,r=1)=>{const i=[];if(t>e&&r>0||tMath.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+t);R(this,"usine",(e=1,t=0)=>(this.sine(e,t)+1)/2);R(this,"saw",(e=1,t=0)=>this.app.clock.ctx.currentTime*e%1*2-1+t);R(this,"usaw",(e=1,t=0)=>(this.saw(e,t)+1)/2);R(this,"triangle",(e=1,t=0)=>Math.abs(this.saw(e,t))*2-1);R(this,"utriangle",(e=1,t=0)=>(this.triangle(e,t)+1)/2);R(this,"square",(e=1,t=0,r=.5)=>{const i=1/e;return(Date.now()/1e3+t)%i/i(this.square(e,t,r)+1)/2);R(this,"noise",()=>this.randomGen()*2-1);R(this,"min",(...e)=>Math.min(...e));R(this,"max",(...e)=>Math.max(...e));R(this,"mean",(...e)=>e.reduce((r,i)=>r+i,0)/e.length);R(this,"limit",(e,t,r)=>Math.min(Math.max(e,t),r));R(this,"abs",Math.abs);R(this,"sound",e=>new Hy(e,this.app));R(this,"snd",this.sound);R(this,"samples",Dl);R(this,"log",console.log);R(this,"scale",nM);R(this,"rate",e=>{});R(this,"divseq",(...e)=>{const t=e[0],r=e.slice(1),i=this.epulse(),a=Math.floor(i/Math.floor(t*this.ppqn()));return r[a%r.length]});R(this,"seqbeat",(...e)=>e[this.ebeat()%e.length]);R(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);this.app=e}_euclidean_cycle(e,t,r=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,d=(l+1)%c;return o[l]>o[d]}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 r!=0&&(s=s.slice(r).concat(s.slice(0,r))),s}}const PM=n=>{Array.prototype.in=function(e){return this.includes(e)},Array.prototype.square=function(){return this.map(e=>e*e)},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.division=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(n.randomGen()*this.length)]},Array.prototype.beat=function(e=1){return this[n.ebeat()/e%this.length]},Array.prototype.bar=function(){return this[(n.app.clock.time_position.bar+1)%this.length]},Array.prototype.pulse=function(){return this[n.app.clock.time_position.pulse%this.length]},Array.prototype.div=function(e){const t=e,r=n.epulse(),i=Math.floor(r/Math.floor(t*n.ppqn()));return this[i%this.length]},Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(Math.random()*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 r=this.splice(-e,e);return this.unshift(...r),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let r=0;r100)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.repeatAll=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let r=0;r (GFM Style)",type:"boolean"},requireSpaceBeforeHeadingText:{defaultValue:!1,describe:"Makes adding a space between `#` and the header text mandatory (GFM Style)",type:"boolean"},ghMentions:{defaultValue:!1,describe:"Enables github @mentions",type:"boolean"},ghMentionsLink:{defaultValue:"https://github.com/{u}",describe:"Changes the link generated by @mentions. Only applies if ghMentions option is enabled.",type:"string"},encodeEmails:{defaultValue:!0,describe:"Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities",type:"boolean"},openLinksInNewWindow:{defaultValue:!1,describe:"Open all links in new windows",type:"boolean"},backslashEscapesHTMLTags:{defaultValue:!1,describe:"Support for HTML Tag escaping. ex: