UNPKG

@strudel/web

Version:

Easy to setup, opiniated bundle of Strudel for the browser.

8 lines 459 kB
var strudel=function(o){"use strict";var df=typeof document<"u"?document.currentScript:null;/** * @license Fraction.js v4.3.7 31/08/2023 * https://www.xarg.org/2014/03/rational-numbers-in-javascript/ * * Copyright (c) 2023, Robert Eisele (robert@raw.org) * Dual licensed under the MIT or GPL Version 2 licenses. **/var OC=2e3,ne={s:1,n:0,d:1};function Zt(e,t){if(isNaN(e=parseInt(e,10)))throw ti();return e*t}function Re(e,t){if(t===0)throw br();var n=Object.create(we.prototype);n.s=e<0?-1:1,e=e<0?-e:e;var u=jn(e,t);return n.n=e/u,n.d=t/u,n}function pf(e){for(var t={},n=e,u=2,i=4;i<=n;){for(;n%u===0;)n/=u,t[u]=(t[u]||0)+1;i+=1+2*u++}return n!==e?n>1&&(t[n]=(t[n]||0)+1):t[e]=(t[e]||0)+1,t}var ct=function(e,t){var n=0,u=1,i=1,r=0,s=0,a=0,f=1,d=1,h=0,g=1,p=1,E=1,b=1e7,y;if(e!=null)if(t!==void 0){if(n=e,u=t,i=n*u,n%1!==0||u%1!==0)throw qC()}else switch(typeof e){case"object":{if("d"in e&&"n"in e)n=e.n,u=e.d,"s"in e&&(n*=e.s);else if(0 in e)n=e[0],1 in e&&(u=e[1]);else throw ti();i=n*u;break}case"number":{if(e<0&&(i=e,e=-e),e%1===0)n=e;else if(e>0){for(e>=1&&(d=Math.pow(10,Math.floor(1+Math.log(e)/Math.LN10)),e/=d);g<=b&&E<=b;)if(y=(h+p)/(g+E),e===y){g+E<=b?(n=h+p,u=g+E):E>g?(n=p,u=E):(n=h,u=g);break}else e>y?(h+=p,g+=E):(p+=h,E+=g),g>b?(n=p,u=E):(n=h,u=g);n*=d}else(isNaN(e)||isNaN(t))&&(u=n=NaN);break}case"string":{if(g=e.match(/\d+|./g),g===null)throw ti();if(g[h]==="-"?(i=-1,h++):g[h]==="+"&&h++,g.length===h+1?s=Zt(g[h++],i):g[h+1]==="."||g[h]==="."?(g[h]!=="."&&(r=Zt(g[h++],i)),h++,(h+1===g.length||g[h+1]==="("&&g[h+3]===")"||g[h+1]==="'"&&g[h+3]==="'")&&(s=Zt(g[h],i),f=Math.pow(10,g[h].length),h++),(g[h]==="("&&g[h+2]===")"||g[h]==="'"&&g[h+2]==="'")&&(a=Zt(g[h+1],i),d=Math.pow(10,g[h+1].length)-1,h+=3)):g[h+1]==="/"||g[h+1]===":"?(s=Zt(g[h],i),f=Zt(g[h+2],1),h+=3):g[h+3]==="/"&&g[h+1]===" "&&(r=Zt(g[h],i),s=Zt(g[h+2],i),f=Zt(g[h+4],1),h+=5),g.length<=h){u=f*d,i=n=a+u*r+d*s;break}}default:throw ti()}if(u===0)throw br();ne.s=i<0?-1:1,ne.n=Math.abs(n),ne.d=Math.abs(u)};function WC(e,t,n){for(var u=1;t>0;e=e*e%n,t>>=1)t&1&&(u=u*e%n);return u}function $C(e,t){for(;t%2===0;t/=2);for(;t%5===0;t/=5);if(t===1)return 0;for(var n=10%t,u=1;n!==1;u++)if(n=n*10%t,u>OC)return 0;return u}function zC(e,t,n){for(var u=1,i=WC(10,n,t),r=0;r<300;r++){if(u===i)return r;u=u*10%t,i=i*10%t}return 0}function jn(e,t){if(!e)return t;if(!t)return e;for(;;){if(e%=t,!e)return t;if(t%=e,!t)return e}}function we(e,t){if(ct(e,t),this instanceof we)e=jn(ne.d,ne.n),this.s=ne.s,this.n=ne.n/e,this.d=ne.d/e;else return Re(ne.s*ne.n,ne.d)}var br=function(){return new Error("Division by Zero")},ti=function(){return new Error("Invalid argument")},qC=function(){return new Error("Parameters must be integer")};we.prototype={s:1,n:0,d:1,abs:function(){return Re(this.n,this.d)},neg:function(){return Re(-this.s*this.n,this.d)},add:function(e,t){return ct(e,t),Re(this.s*this.n*ne.d+ne.s*this.d*ne.n,this.d*ne.d)},sub:function(e,t){return ct(e,t),Re(this.s*this.n*ne.d-ne.s*this.d*ne.n,this.d*ne.d)},mul:function(e,t){return ct(e,t),Re(this.s*ne.s*this.n*ne.n,this.d*ne.d)},div:function(e,t){return ct(e,t),Re(this.s*ne.s*this.n*ne.d,this.d*ne.n)},clone:function(){return Re(this.s*this.n,this.d)},mod:function(e,t){if(isNaN(this.n)||isNaN(this.d))return new we(NaN);if(e===void 0)return Re(this.s*this.n%this.d,1);if(ct(e,t),ne.n===0&&this.d===0)throw br();return Re(this.s*(ne.d*this.n)%(ne.n*this.d),ne.d*this.d)},gcd:function(e,t){return ct(e,t),Re(jn(ne.n,this.n)*jn(ne.d,this.d),ne.d*this.d)},lcm:function(e,t){return ct(e,t),ne.n===0&&this.n===0?Re(0,1):Re(ne.n*this.n,jn(ne.n,this.n)*jn(ne.d,this.d))},ceil:function(e){return e=Math.pow(10,e||0),isNaN(this.n)||isNaN(this.d)?new we(NaN):Re(Math.ceil(e*this.s*this.n/this.d),e)},floor:function(e){return e=Math.pow(10,e||0),isNaN(this.n)||isNaN(this.d)?new we(NaN):Re(Math.floor(e*this.s*this.n/this.d),e)},round:function(e){return e=Math.pow(10,e||0),isNaN(this.n)||isNaN(this.d)?new we(NaN):Re(Math.round(e*this.s*this.n/this.d),e)},roundTo:function(e,t){return ct(e,t),Re(this.s*Math.round(this.n*ne.d/(this.d*ne.n))*ne.n,ne.d)},inverse:function(){return Re(this.s*this.d,this.n)},pow:function(e,t){if(ct(e,t),ne.d===1)return ne.s<0?Re(Math.pow(this.s*this.d,ne.n),Math.pow(this.n,ne.n)):Re(Math.pow(this.s*this.n,ne.n),Math.pow(this.d,ne.n));if(this.s<0)return null;var n=pf(this.n),u=pf(this.d),i=1,r=1;for(var s in n)if(s!=="1"){if(s==="0"){i=0;break}if(n[s]*=ne.n,n[s]%ne.d===0)n[s]/=ne.d;else return null;i*=Math.pow(s,n[s])}for(var s in u)if(s!=="1"){if(u[s]*=ne.n,u[s]%ne.d===0)u[s]/=ne.d;else return null;r*=Math.pow(s,u[s])}return ne.s<0?Re(r,i):Re(i,r)},equals:function(e,t){return ct(e,t),this.s*this.n*ne.d===ne.s*ne.n*this.d},compare:function(e,t){ct(e,t);var n=this.s*this.n*ne.d-ne.s*ne.n*this.d;return(0<n)-(n<0)},simplify:function(e){if(isNaN(this.n)||isNaN(this.d))return this;e=e||.001;for(var t=this.abs(),n=t.toContinued(),u=1;u<n.length;u++){for(var i=Re(n[u-1],1),r=u-2;r>=0;r--)i=i.inverse().add(n[r]);if(Math.abs(i.sub(t).valueOf())<e)return i.mul(this.s)}return this},divisible:function(e,t){return ct(e,t),!(!(ne.n*this.d)||this.n*ne.d%(ne.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(e){var t,n="",u=this.n,i=this.d;return this.s<0&&(n+="-"),i===1?n+=u:(e&&(t=Math.floor(u/i))>0&&(n+=t,n+=" ",u%=i),n+=u,n+="/",n+=i),n},toLatex:function(e){var t,n="",u=this.n,i=this.d;return this.s<0&&(n+="-"),i===1?n+=u:(e&&(t=Math.floor(u/i))>0&&(n+=t,u%=i),n+="\\frac{",n+=u,n+="}{",n+=i,n+="}"),n},toContinued:function(){var e,t=this.n,n=this.d,u=[];if(isNaN(t)||isNaN(n))return u;do u.push(Math.floor(t/n)),e=t%n,t=n,n=e;while(t!==1);return u},toString:function(e){var t=this.n,n=this.d;if(isNaN(t)||isNaN(n))return"NaN";e=e||15;var u=$C(t,n),i=zC(t,n,u),r=this.s<0?"-":"";if(r+=t/n|0,t%=n,t*=10,t&&(r+="."),u){for(var s=i;s--;)r+=t/n|0,t%=n,t*=10;r+="(";for(var s=u;s--;)r+=t/n|0,t%=n,t*=10;r+=")"}else for(var s=e;t&&s--;)r+=t/n|0,t%=n,t*=10;return r}};const ni="strudel.log";let jC=1e3,mf,gf;function Xe(e,t,n={}){let u=performance.now();mf===e&&u-gf<jC||(mf=e,gf=u,console.log(`%c${e}`,"background-color: black;color:white;border-radius:15px"),typeof document<"u"&&typeof CustomEvent<"u"&&document.dispatchEvent(new CustomEvent(ni,{detail:{message:e,type:t,data:n}})))}Xe.key=ni;const Af=e=>/^[a-gA-G][#bs]*[0-9]$/.test(e),pn=e=>/^[a-gA-G][#bsf]*[0-9]?$/.test(e),Mr=e=>{if(typeof e!="string")return[];const[t,n="",u]=e.match(/^([a-gA-G])([#bsf]*)([0-9]*)$/)?.slice(1)||[];return t?[t,n,u?Number(u):void 0]:[]},XC={c:0,d:2,e:4,f:5,g:7,a:9,b:11},ZC={"#":1,b:-1,s:1,f:-1},Ht=(e,t=3)=>{const[n,u,i=t]=Mr(e);if(!n)throw new Error('not a note: "'+e+'"');const r=XC[n.toLowerCase()],s=u?.split("").reduce((a,f)=>a+ZC[f],0)||0;return(Number(i)+1)*12+r+s},mn=e=>Math.pow(2,(e-69)/12)*440,ui=e=>12*Math.log(e/440)/Math.LN2+69,Cf=(e,t)=>{if(typeof e!="object")throw new Error("valueToMidi: expected object value");let{freq:n,note:u}=e;if(typeof n=="number")return ui(n);if(typeof u=="string")return Ht(u);if(typeof u=="number")return u;if(!t)throw new Error("valueToMidi: expected freq or note to be set");return t},Df=(e,t)=>(e-t)*1e3,Br=e=>mn(typeof e=="number"?e:Ht(e)),HC=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],Ef=e=>{const t=Math.floor(e/12)-1;return HC[e%12]+t},lt=(e,t)=>(e%t+t)%t;function Pr(e,t=0){return isNaN(Number(e))?(Xe(`"${e}" is not a number, falling back to ${t}`,"warning"),t):e}const yf=(e,t)=>lt(Math.round(Pr(e??0,0)),t),vf=e=>{let{value:t,context:n}=e,u=t;if(typeof u=="object"&&!Array.isArray(u)&&(u=u.note||u.n||u.value,u===void 0))throw new Error(`cannot find a playable note for ${JSON.stringify(t)}`);if(typeof u=="number"&&n.type!=="frequency")u=mn(e.value);else if(typeof u=="number"&&n.type==="frequency")u=e.value;else if(typeof u!="string"||!pn(u))throw new Error("not a note: "+JSON.stringify(u));return u},wr=e=>{let{value:t,context:n}=e;if(typeof t=="object")return t.freq?t.freq:Br(t.note||t.n||t.value);if(typeof t=="number"&&n.type!=="frequency")t=mn(e.value);else if(typeof t=="string"&&pn(t))t=mn(Ht(e.value));else if(typeof t!="number")throw new Error("not a note or frequency: "+t);return t},Ir=(e,t)=>e.slice(t).concat(e.slice(0,t)),Sr=(...e)=>e.reduce((t,n)=>(...u)=>t(n(...u)),t=>t),Ff=(...e)=>Sr(...e.reverse()),_n=e=>e.filter(t=>t!=null),Ot=e=>[].concat(...e),kn=e=>e,bf=(e,t)=>e,ii=(e,t)=>Array.from({length:t-e+1},(n,u)=>u+e);function ye(e,t,n=e.length){const u=function i(...r){if(r.length>=n)return e.apply(this,r);{const s=function(...a){return i.apply(this,r.concat(a))};return t&&t(s,r),s}};return t&&t(u,[]),u}function ri(e){const t=Number(e);if(!isNaN(t))return t;if(pn(e))return Ht(e);throw new Error(`cannot parse as numeral: "${e}"`)}function si(e,t){return(...n)=>e(...n.map(t))}function ft(e){return si(e,ri)}function _r(e){const t=Number(e);if(!isNaN(t))return t;const n={pi:Math.PI,w:1,h:.5,q:.25,e:.125,s:.0625,t:1/3,f:.2,x:1/6}[e];if(typeof n<"u")return n;throw new Error(`cannot parse as fractional: "${e}"`)}const Mf=e=>si(e,_r),ai=function(e,t){return[t.slice(0,e),t.slice(e)]},oi=(e,t,n)=>t.map((u,i)=>e(u,n[i])),kr=function(e){const t=[];for(let n=0;n<e.length-1;++n)t.push([e[n],e[n+1]]);return t},ci=(e,t,n)=>Math.min(Math.max(e,t),n),KC=["Do","Reb","Re","Mib","Mi","Fa","Solb","Sol","Lab","La","Sib","Si"],YC=["Sa","Re","Ga","Ma","Pa","Dha","Ni"],JC=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Hb","H"],UC=["Ni","Pab","Pa","Voub","Vou","Ga","Dib","Di","Keb","Ke","Zob","Zo"],QC=["I","Ro","Ha","Ni","Ho","He","To"],e2=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"],Bf=(e,t="letters")=>{const u=(t==="solfeggio"?KC:t==="indian"?YC:t==="german"?JC:t==="byzantine"?UC:t==="japanese"?QC:e2)[e%12],i=Math.floor(e/12)-1;return u+i};function Pf(e){var t={};return e.filter(function(n){return t.hasOwn(n)?!1:t[n]=!0})}function wf(e){return e.sort().filter(function(t,n,u){return!n||t!=u[n-1]})}function xr(e){return e.sort((t,n)=>t.compare(n)).filter(function(t,n,u){return!n||t.ne(u[n-1])})}function Nr(e){const t=new TextEncoder().encode(e);return btoa(String.fromCharCode(...t))}function Tr(e){const t=new Uint8Array(atob(e).split("").map(u=>u.charCodeAt(0)));return new TextDecoder().decode(t)}function If(e){return encodeURIComponent(Nr(e))}function Sf(e){return Tr(decodeURIComponent(e))}function Vr(e,t){return Array.isArray(e)?e.map(t):Object.fromEntries(Object.entries(e).map(([n,u],i)=>[n,t(u,n,i)]))}we.prototype.sam=function(){return this.floor()},we.prototype.nextSam=function(){return this.sam().add(1)},we.prototype.wholeCycle=function(){return new $e(this.sam(),this.nextSam())},we.prototype.cyclePos=function(){return this.sub(this.sam())},we.prototype.lt=function(e){return this.compare(e)<0},we.prototype.gt=function(e){return this.compare(e)>0},we.prototype.lte=function(e){return this.compare(e)<=0},we.prototype.gte=function(e){return this.compare(e)>=0},we.prototype.eq=function(e){return this.compare(e)==0},we.prototype.ne=function(e){return this.compare(e)!=0},we.prototype.max=function(e){return this.gt(e)?this:e},we.prototype.maximum=function(...e){return e=e.map(t=>new we(t)),e.reduce((t,n)=>n.max(t),this)},we.prototype.min=function(e){return this.lt(e)?this:e},we.prototype.mulmaybe=function(e){return e!==void 0?this.mul(e):void 0},we.prototype.divmaybe=function(e){return e!==void 0?this.div(e):void 0},we.prototype.addmaybe=function(e){return e!==void 0?this.add(e):void 0},we.prototype.submaybe=function(e){return e!==void 0?this.sub(e):void 0},we.prototype.show=function(){return this.s*this.n+"/"+this.d},we.prototype.or=function(e){return this.eq(0)?e:this};const Z=e=>we(e),t2=(...e)=>{if(e=_n(e),e.length!==0)return e.reduce((t,n)=>t.gcd(n),Z(1))},Kt=(...e)=>{if(e=_n(e),e.length!==0)return e.reduce((t,n)=>t===void 0||n===void 0?void 0:t.lcm(n),Z(1))};Z._original=we;class $e{constructor(t,n){this.begin=Z(t),this.end=Z(n)}get spanCycles(){const t=[];var n=this.begin;const u=this.end,i=u.sam();if(n.equals(u))return[new $e(n,u)];for(;u.gt(n);){if(n.sam().equals(i)){t.push(new $e(n,this.end));break}const r=n.nextSam();t.push(new $e(n,r)),n=r}return t}get duration(){return this.end.sub(this.begin)}cycleArc(){const t=this.begin.cyclePos(),n=t.add(this.duration);return new $e(t,n)}withTime(t){return new $e(t(this.begin),t(this.end))}withEnd(t){return new $e(this.begin,t(this.end))}withCycle(t){const n=this.begin.sam(),u=n.add(t(this.begin.sub(n))),i=n.add(t(this.end.sub(n)));return new $e(u,i)}intersection(t){const n=this.begin.max(t.begin),u=this.end.min(t.end);if(!n.gt(u)&&!(n.equals(u)&&(n.equals(this.end)&&this.begin.lt(this.end)||n.equals(t.end)&&t.begin.lt(t.end))))return new $e(n,u)}intersection_e(t){const n=this.intersection(t);if(n==null)throw"TimeSpans do not intersect";return n}midpoint(){return this.begin.add(this.duration.div(Z(2)))}equals(t){return this.begin.equals(t.begin)&&this.end.equals(t.end)}show(){return this.begin.show()+" → "+this.end.show()}}class Oe{constructor(t,n,u,i={},r=!1){this.whole=t,this.part=n,this.value=u,this.context=i,this.stateful=r,r&&console.assert(typeof this.value=="function","Stateful values must be functions")}get duration(){let t;return typeof this.value?.duration=="number"?t=Z(this.value.duration):t=this.whole.end.sub(this.whole.begin),typeof this.value?.clip=="number"?t.mul(this.value.clip):t}get endClipped(){return this.whole.begin.add(this.duration)}isActive(t){return this.whole.begin<=t&&this.endClipped>=t}isInPast(t){return t>this.endClipped}isInNearPast(t,n){return n-t<=this.endClipped}isInFuture(t){return t<this.whole.begin}isInNearFuture(t,n){return n<this.whole.begin&&n>this.whole.begin-t}isWithinTime(t,n){return this.whole.begin<=n&&this.endClipped>=t}wholeOrPart(){return this.whole?this.whole:this.part}withSpan(t){const n=this.whole?t(this.whole):void 0;return new Oe(n,t(this.part),this.value,this.context)}withValue(t){return new Oe(this.whole,this.part,t(this.value),this.context)}hasOnset(){return this.whole!=null&&this.whole.begin.equals(this.part.begin)}hasTag(t){return this.context.tags?.includes(t)}resolveState(t){if(this.stateful&&this.hasOnset()){console.log("stateful");const n=this.value,[u,i]=n(t);return[u,new Oe(this.whole,this.part,i,this.context,!1)]}return[t,this]}spanEquals(t){return this.whole==null&&t.whole==null||this.whole.equals(t.whole)}equals(t){return this.spanEquals(t)&&this.part.equals(t.part)&&this.value===t.value}show(t=!1){const n=typeof this.value=="object"?t?JSON.stringify(this.value).slice(1,-1).replaceAll('"',"").replaceAll(","," "):JSON.stringify(this.value):this.value;var u="";if(this.whole==null)u="~"+this.part.show;else{var i=this.whole.begin.equals(this.part.begin)&&this.whole.end.equals(this.part.end);this.whole.begin.equals(this.part.begin)||(u=this.whole.begin.show()+" ⇜ "),i||(u+="("),u+=this.part.show(),i||(u+=")"),this.whole.end.equals(this.part.end)||(u+=" ⇝ "+this.whole.end.show())}return"[ "+u+" | "+n+" ]"}showWhole(t=!1){return`${this.whole==null?"~":this.whole.show()}: ${typeof this.value=="object"?t?JSON.stringify(this.value).slice(1,-1).replaceAll('"',"").replaceAll(","," "):JSON.stringify(this.value):this.value}`}combineContext(t){const n=this;return{...n.context,...t.context,locations:(n.context.locations||[]).concat(t.context.locations||[])}}setContext(t){return new Oe(this.whole,this.part,this.value,t)}ensureObjectValue(){if(typeof this.value!="object")throw new Error(`expected hap.value to be an object, but got "${this.value}". Hint: append .note() or .s() to the end`,"error")}}class xn{constructor(t,n={}){this.span=t,this.controls=n}setSpan(t){return new xn(t,this.controls)}withSpan(t){return this.setSpan(t(this.span))}setControls(t){return new xn(this.span,t)}}function n2(e,t,n){if(t?.value!==void 0&&Object.keys(t).length===1)return Xe("[warn]: Can't do arithmetic on control pattern."),e;const u=Object.keys(e).filter(i=>Object.keys(t).includes(i));return Object.assign({},e,t,Object.fromEntries(u.map(i=>[i,n(e[i],t[i])])))}ye((e,t)=>e*t),ye((e,t)=>t.map(e));function Rr(e,t=60){let n=0,u=Z(0),i=[""],r="";for(;i[0].length<t;){const s=e.queryArc(n,n+1),a=s.filter(h=>h.hasOnset()).map(h=>h.duration),f=t2(...a),d=f.inverse();i=i.map(h=>h+"|"),r+="|";for(let h=0;h<d;h++){const[g,p]=[u,u.add(f)],E=s.filter(y=>y.whole.begin.lte(g)&&y.whole.end.gte(p)),b=E.length-i.length;b>0&&(i=i.concat(Array(b).fill(r))),i=i.map((y,P)=>{const k=E[P];if(k){const W=k.whole.begin.eq(g)?""+k.value:"-";return y+W}return y+"."}),r+=".",u=u.add(f)}n++}return i.join(` `)}let Lr,kt=!0;const _f=function(e){kt=!!e},Gr=e=>Lr=e;let ue=class Qe{constructor(t,n=void 0){this.query=t,this._Pattern=!0,this.tactus=n}get tactus(){return this.__tactus}set tactus(t){this.__tactus=t===void 0?void 0:Z(t)}setTactus(t){return this.tactus=t,this}withTactus(t){return kt?new Qe(this.query,this.tactus===void 0?void 0:t(this.tactus)):this}get hasTactus(){return this.tactus!==void 0}withValue(t){const n=new Qe(u=>this.query(u).map(i=>i.withValue(t)));return n.tactus=this.tactus,n}fmap(t){return this.withValue(t)}appWhole(t,n){const u=this,i=function(r){const s=u.query(r),a=n.query(r),f=function(d,h){const g=d.part.intersection(h.part);if(g!=null)return new Oe(t(d.whole,h.whole),g,d.value(h.value),h.combineContext(d))};return Ot(s.map(d=>_n(a.map(h=>f(d,h)))))};return new Qe(i)}appBoth(t){const n=this,u=function(r,s){if(!(r==null||s==null))return r.intersection_e(s)},i=n.appWhole(u,t);return kt&&(i.tactus=Kt(t.tactus,n.tactus)),i}appLeft(t){const n=this,u=function(r){const s=[];for(const a of n.query(r)){const f=t.query(r.setSpan(a.wholeOrPart()));for(const d of f){const h=a.whole,g=a.part.intersection(d.part);if(g){const p=a.value(d.value),E=d.combineContext(a),b=new Oe(h,g,p,E);s.push(b)}}}return s},i=new Qe(u);return i.tactus=this.tactus,i}appRight(t){const n=this,u=function(r){const s=[];for(const a of t.query(r)){const f=n.query(r.setSpan(a.wholeOrPart()));for(const d of f){const h=a.whole,g=d.part.intersection(a.part);if(g){const p=d.value(a.value),E=a.combineContext(d),b=new Oe(h,g,p,E);s.push(b)}}}return s},i=new Qe(u);return i.tactus=t.tactus,i}bindWhole(t,n){const u=this,i=function(r){const s=function(f,d){return new Oe(t(f.whole,d.whole),d.part,d.value,Object.assign({},f.context,d.context,{locations:(f.context.locations||[]).concat(d.context.locations||[])}))},a=function(f){return n(f.value).query(r.setSpan(f.part)).map(d=>s(f,d))};return Ot(u.query(r).map(f=>a(f)))};return new Qe(i)}bind(t){const n=function(u,i){if(!(u==null||i==null))return u.intersection_e(i)};return this.bindWhole(n,t)}join(){return this.bind(kn)}outerBind(t){return this.bindWhole(n=>n,t).setTactus(this.tactus)}outerJoin(){return this.outerBind(kn)}innerBind(t){return this.bindWhole((n,u)=>u,t)}innerJoin(){return this.innerBind(kn)}resetJoin(t=!1){const n=this;return new Qe(u=>n.discreteOnly().query(u).map(i=>i.value.late(t?i.whole.begin:i.whole.begin.cyclePos()).query(u).map(r=>new Oe(r.whole?r.whole.intersection(i.whole):void 0,r.part.intersection(i.part),r.value).setContext(i.combineContext(r))).filter(r=>r.part)).flat())}restartJoin(){return this.resetJoin(!0)}squeezeJoin(){const t=this;function n(u){const i=t.discreteOnly().query(u);function r(a){const d=a.value._focusSpan(a.wholeOrPart()).query(u.setSpan(a.part));function h(g,p){let E;if(p.whole&&g.whole&&(E=p.whole.intersection(g.whole),!E))return;const b=p.part.intersection(g.part);if(!b)return;const y=p.combineContext(g);return new Oe(E,b,p.value,y)}return d.map(g=>h(a,g))}return Ot(i.map(r)).filter(a=>a)}return new Qe(n)}squeezeBind(t){return this.fmap(t).squeezeJoin()}queryArc(t,n,u={}){try{return this.query(new xn(new $e(t,n),u))}catch(i){return Xe(`[query]: ${i.message}`,"error"),[]}}splitQueries(){const t=this,n=u=>Ot(u.span.spanCycles.map(i=>t.query(u.setSpan(i))));return new Qe(n)}withQuerySpan(t){return new Qe(n=>this.query(n.withSpan(t)))}withQuerySpanMaybe(t){const n=this;return new Qe(u=>{const i=u.withSpan(t);return i.span?n.query(i):[]})}withQueryTime(t){return new Qe(n=>this.query(n.withSpan(u=>u.withTime(t))))}withHapSpan(t){return new Qe(n=>this.query(n).map(u=>u.withSpan(t)))}withHapTime(t){return this.withHapSpan(n=>n.withTime(t))}withHaps(t){const n=new Qe(u=>t(this.query(u),u));return n.tactus=this.tactus,n}withHap(t){return this.withHaps(n=>n.map(t))}setContext(t){return this.withHap(n=>n.setContext(t))}withContext(t){const n=this.withHap(u=>u.setContext(t(u.context)));return this.__pure!==void 0&&(n.__pure=this.__pure,n.__pure_loc=this.__pure_loc),n}stripContext(){return this.withHap(t=>t.setContext({}))}withLoc(t,n){const u={start:t,end:n},i=this.withContext(r=>{const s=(r.locations||[]).concat([u]);return{...r,locations:s}});return this.__pure&&(i.__pure=this.__pure,i.__pure_loc=u),i}filterHaps(t){return new Qe(n=>this.query(n).filter(t))}filterValues(t){return new Qe(n=>this.query(n).filter(u=>t(u.value))).setTactus(this.tactus)}removeUndefineds(){return this.filterValues(t=>t!=null)}onsetsOnly(){return this.filterHaps(t=>t.hasOnset())}discreteOnly(){return this.filterHaps(t=>t.whole)}defragmentHaps(){return this.discreteOnly().withHaps(n=>{const u=[];for(var i=0;i<n.length;++i){for(var r=!0,s=n[i];r;){const d=JSON.stringify(n[i].value);for(var a=!1,f=i+1;f<n.length;f++){const h=n[f];if(s.whole.equals(h.whole)){if(s.part.begin.eq(h.part.end)){if(d===JSON.stringify(h.value)){s=new Oe(s.whole,new $e(h.part.begin,s.part.end),s.value),n.splice(f,1),a=!0;break}}else if(h.part.begin.eq(s.part.end)&&d==JSON.stringify(h.value)){s=new Oe(s.whole,new $e(s.part.begin,h.part.end),s.value),n.splice(f,1),a=!0;break}}}r=a}u.push(s)}return u})}firstCycle(t=!1){var n=this;return t||(n=n.stripContext()),n.query(new xn(new $e(Z(0),Z(1))))}get firstCycleValues(){return this.firstCycle().map(t=>t.value)}get showFirstCycle(){return this.firstCycle().map(t=>`${t.value}: ${t.whole.begin.toFraction()} - ${t.whole.end.toFraction()}`)}sortHapsByPart(){return this.withHaps(t=>t.sort((n,u)=>n.part.begin.sub(u.part.begin).or(n.part.end.sub(u.part.end)).or(n.whole.begin.sub(u.whole.begin).or(n.whole.end.sub(u.whole.end)))))}asNumber(){return this.fmap(ri)}_opIn(t,n){return this.fmap(n).appLeft(J(t))}_opOut(t,n){return this.fmap(n).appRight(J(t))}_opMix(t,n){return this.fmap(n).appBoth(J(t))}_opSqueeze(t,n){const u=J(t);return this.fmap(i=>u.fmap(r=>n(i)(r))).squeezeJoin()}_opSqueezeOut(t,n){const u=this;return J(t).fmap(r=>u.fmap(s=>n(s)(r))).squeezeJoin()}_opReset(t,n){return J(t).fmap(i=>this.fmap(r=>n(r)(i))).resetJoin()}_opRestart(t,n){return J(t).fmap(i=>this.fmap(r=>n(r)(i))).restartJoin()}layer(...t){return Ne(...t.map(n=>n(this)))}superimpose(...t){return this.stack(...t.map(n=>n(this)))}stack(...t){return Ne(this,...t)}sequence(...t){return pt(this,...t)}seq(...t){return pt(this,...t)}cat(...t){return qr(this,...t)}fastcat(...t){return dt(this,...t)}slowcat(...t){return gn(this,...t)}onTrigger(t,n=!0){return this.withHap(u=>u.setContext({...u.context,onTrigger:(...i)=>{u.context.onTrigger?.(...i),t(...i)},dominantTrigger:u.context.dominantTrigger||n}))}log(t=(u,i)=>`[hap] ${i.showWhole(!0)}`,n=(u,i)=>({hap:i})){return this.onTrigger((...u)=>{Xe(t(...u),void 0,n(...u))},!1)}logValues(t=kn){return this.log((n,u)=>t(u.value))}drawLine(){return console.log(Rr(this)),this}};function u2(e,t){let n=[];return t.forEach(u=>{const i=n.findIndex(([r])=>e(u,r));i===-1?n.push([u]):n[i].push(u)}),n}const i2=(e,t)=>e.spanEquals(t);ue.prototype.collect=function(){return this.withHaps(e=>u2(i2,e).map(t=>new Oe(t[0].whole,t[0].part,t,{})))},ue.prototype.arpWith=function(e){return this.collect().fmap(t=>J(e(t))).innerJoin().withHap(t=>new Oe(t.whole,t.part,t.value.value,t.combineContext(t.value)))},ue.prototype.arp=function(e){return this.arpWith(t=>e.fmap(n=>t[n%t.length]))};function li(e){return!Array.isArray(e)&&typeof e=="object"}function r2(e,t,n){return li(e)||li(t)?(li(e)||(e={value:e}),li(t)||(t={value:t}),n2(e,t,n)):n(e,t)}(function(){const e={set:[(n,u)=>u],keep:[n=>n],keepif:[(n,u)=>u?n:void 0],add:[ft((n,u)=>n+u)],sub:[ft((n,u)=>n-u)],mul:[ft((n,u)=>n*u)],div:[ft((n,u)=>n/u)],mod:[ft(lt)],pow:[ft(Math.pow)],band:[ft((n,u)=>n&u)],bor:[ft((n,u)=>n|u)],bxor:[ft((n,u)=>n^u)],blshift:[ft((n,u)=>n<<u)],brshift:[ft((n,u)=>n>>u)],lt:[(n,u)=>n<u],gt:[(n,u)=>n>u],lte:[(n,u)=>n<=u],gte:[(n,u)=>n>=u],eq:[(n,u)=>n==u],eqt:[(n,u)=>n===u],ne:[(n,u)=>n!=u],net:[(n,u)=>n!==u],and:[(n,u)=>n&&u],or:[(n,u)=>n||u],func:[(n,u)=>u(n)]},t=["In","Out","Mix","Squeeze","SqueezeOut","Reset","Restart"];for(const[n,[u,i]]of Object.entries(e)){ue.prototype["_"+n]=function(r){return this.fmap(s=>u(s,r))},Object.defineProperty(ue.prototype,n,{get:function(){const r=this,s=(...a)=>r[n].in(...a);for(const a of t)s[a.toLowerCase()]=function(...f){var d=r;f=pt(f),i&&(d=i(d),f=i(f));var h;return n==="keepif"?(h=d["_op"+a](f,g=>p=>u(g,p)),h=h.removeUndefineds()):h=d["_op"+a](f,g=>p=>r2(g,p,u)),h};return s.squeezein=s.squeeze,s}});for(const r of t)ue.prototype[r.toLowerCase()]=function(...s){return this.set[r.toLowerCase()](s)}}ue.prototype.struct=function(...n){return this.keepif.out(...n)},ue.prototype.structAll=function(...n){return this.keep.out(...n)},ue.prototype.mask=function(...n){return this.keepif.in(...n)},ue.prototype.maskAll=function(...n){return this.keep.in(...n)},ue.prototype.reset=function(...n){return this.keepif.reset(...n)},ue.prototype.resetAll=function(...n){return this.keep.reset(...n)},ue.prototype.restart=function(...n){return this.keepif.restart(...n)},ue.prototype.restartAll=function(...n){return this.keep.restart(...n)}})();const kf=Ne,xf=Ne,Nf=Ai,Nn=e=>new ue(()=>[],e),Pe=Nn(1),ht=Nn(0);function et(e){function t(u){return u.span.spanCycles.map(i=>new Oe(Z(i.begin).wholeCycle(),i,e))}const n=new ue(t,1);return n.__pure=e,n}function fi(e){return e instanceof ue||e?._Pattern}function J(e){return fi(e)?e:Lr&&typeof e=="string"?Lr(e):et(e)}function Ne(...e){e=e.map(u=>Array.isArray(u)?pt(...u):J(u));const t=u=>Ot(e.map(i=>i.query(u))),n=new ue(t);return kt&&(n.tactus=Kt(...e.map(u=>u.tactus))),n}function Or(e,t){if(t=t.map(r=>Array.isArray(r)?pt(...r):J(r)),t.length===0)return Pe;if(t.length===1)return t[0];const[n,...u]=t.map(r=>r.tactus),i=kt?n.maximum(...u):void 0;return Ne(...e(i,t))}function Wr(...e){return Or((t,n)=>n.map(u=>u.tactus.eq(t)?u:mt(u,Nn(t.sub(u.tactus)))),e)}function $r(...e){return Or((t,n)=>n.map(u=>u.tactus.eq(t)?u:mt(Nn(t.sub(u.tactus)),u)),e)}function zr(...e){return Or((t,n)=>n.map(u=>{if(u.tactus.eq(t))return u;const i=Nn(t.sub(u.tactus).div(2));return mt(i,u,i)}),e)}function Tf(e,...t){const[n,...u]=t.map(s=>s.tactus),i=n.maximum(...u),r={centre:zr,left:Wr,right:$r,expand:Ne,repeat:(...s)=>Qr(i,...s)};return e.inhabit(r).fmap(s=>s(...t)).innerJoin().setTactus(i)}function gn(...e){if(e=e.map(u=>Array.isArray(u)?dt(...u):J(u)),e.length==1)return e[0];const t=function(u){const i=u.span,r=lt(i.begin.sam(),e.length),s=e[r];if(!s)return[];const a=i.begin.floor().sub(i.begin.div(e.length).floor());return s.withHapTime(f=>f.add(a)).query(u.setSpan(i.withTime(f=>f.sub(a))))},n=kt?Kt(...e.map(u=>u.tactus)):void 0;return new ue(t).splitQueries().setTactus(n)}function hi(...e){e=e.map(J);const t=function(n){const u=Math.floor(n.span.begin)%e.length;return e[u]?.query(n)||[]};return new ue(t).splitQueries()}function qr(...e){return gn(...e)}function Vf(...e){const t=e.reduce((n,[u])=>n+u,0);return e=e.map(([n,u])=>[n,u.fast(n)]),mt(...e).slow(t)}function dt(...e){let t=gn(...e);return e.length>1&&(t=t._fast(e.length),t.tactus=e.length),t}function pt(...e){return dt(...e)}function jr(...e){return dt(...e)}function Xr(e){return Array.isArray(e)?e.length==0?[Pe,0]:e.length==1?Xr(e[0]):[dt(...e.map(t=>Xr(t)[0])),e.length]:[J(e),1]}const Rf=ye((e,t)=>J(t).mask(e)),Lf=ye((e,t)=>J(t).struct(e)),Gf=ye((e,t)=>J(t).superimpose(...e)),Of=ye((e,t)=>J(t).set(e)),Wf=ye((e,t)=>J(t).keep(e)),$f=ye((e,t)=>J(t).keepif(e)),zf=ye((e,t)=>J(t).add(e)),qf=ye((e,t)=>J(t).sub(e)),jf=ye((e,t)=>J(t).mul(e)),Xf=ye((e,t)=>J(t).div(e)),Zf=ye((e,t)=>J(t).mod(e)),Hf=ye((e,t)=>J(t).pow(e)),Kf=ye((e,t)=>J(t).band(e)),Yf=ye((e,t)=>J(t).bor(e)),Jf=ye((e,t)=>J(t).bxor(e)),Uf=ye((e,t)=>J(t).blshift(e)),Qf=ye((e,t)=>J(t).brshift(e)),eh=ye((e,t)=>J(t).lt(e)),th=ye((e,t)=>J(t).gt(e)),nh=ye((e,t)=>J(t).lte(e)),uh=ye((e,t)=>J(t).gte(e)),ih=ye((e,t)=>J(t).eq(e)),rh=ye((e,t)=>J(t).eqt(e)),sh=ye((e,t)=>J(t).ne(e)),ah=ye((e,t)=>J(t).net(e)),oh=ye((e,t)=>J(t).and(e)),ch=ye((e,t)=>J(t).or(e)),lh=ye((e,t)=>J(t).func(e));function O(e,t,n=!0,u=!1,i=r=>r.innerJoin()){if(Array.isArray(e)){const a={};for(const f of e)a[f]=O(f,t,n);return a}const r=t.length;var s;return n?s=function(...a){a=a.map(J);const f=a[a.length-1];let d;if(r===1)d=t(f);else{const h=a.slice(0,-1);if(h.every(g=>g.__pure!=null)){const g=h.map(E=>E.__pure),p=h.filter(E=>E.__pure_loc).map(E=>E.__pure_loc);d=t(...g,f),d=d.withContext(E=>{const b=(E.locations||[]).concat(p);return{...E,locations:b}})}else{const[g,...p]=h;let E=(...b)=>t(...b,f);E=ye(E,null,r-1),d=i(p.reduce((b,y)=>b.appLeft(y),g.fmap(E)))}}return u&&(d.tactus=f.tactus),d}:s=function(...a){a=a.map(J);const f=t(...a);return u&&(f.tactus=a[a.length-1].tactus),f},ue.prototype[e]=function(...a){if(r===2&&a.length!==1)a=[pt(...a)];else if(r!==a.length+1)throw new Error(`.${e}() expects ${r-1} inputs but got ${a.length}.`);return a=a.map(J),s(...a,this)},r>1&&(ue.prototype["_"+e]=function(...a){return t(...a,this)}),ye(s,null,r)}function di(e,t,n=!0,u=!1,i=r=>r.stepJoin()){return O(e,t,n,u,i)}const fh=O("round",function(e){return e.asNumber().fmap(t=>Math.round(t))}),hh=O("floor",function(e){return e.asNumber().fmap(t=>Math.floor(t))}),dh=O("ceil",function(e){return e.asNumber().fmap(t=>Math.ceil(t))}),ph=O("toBipolar",function(e){return e.fmap(t=>t*2-1)}),mh=O("fromBipolar",function(e){return e.fmap(t=>(t+1)/2)}),gh=O("range",function(e,t,n){return n.mul(t-e).add(e)}),Ah=O("rangex",function(e,t,n){return n._range(Math.log(e),Math.log(t)).fmap(Math.exp)}),Ch=O("range2",function(e,t,n){return n.fromBipolar()._range(e,t)}),Dh=O("ratio",e=>e.fmap(t=>Array.isArray(t)?t.slice(1).reduce((n,u)=>n/u,t[0]):t)),Eh=O("compress",function(e,t,n){return e=Z(e),t=Z(t),e.gt(t)||e.gt(1)||t.gt(1)||e.lt(0)||t.lt(0)?Pe:n._fastGap(Z(1).div(t.sub(e)))._late(e)}),{compressSpan:yh,compressspan:vh}=O(["compressSpan","compressspan"],function(e,t){return t._compress(e.begin,e.end)}),{fastGap:Fh,fastgap:bh}=O(["fastGap","fastgap"],function(e,t){const n=function(i){const r=i.begin.sam(),s=i.begin.sub(r).mul(e).min(1),a=i.end.sub(r).mul(e).min(1);if(!(s>=1))return new $e(r.add(s),r.add(a))},u=function(i){const r=i.part.begin,s=i.part.end,a=r.sam(),f=r.sub(a).div(e).min(1),d=s.sub(a).div(e).min(1),h=new $e(a.add(f),a.add(d)),g=i.whole?new $e(h.begin.sub(r.sub(i.whole.begin).div(e)),h.end.add(i.whole.end.sub(s).div(e))):void 0;return new Oe(g,h,i.value,i.context)};return t.withQuerySpanMaybe(n).withHap(u).splitQueries()}),Mh=O("focus",function(e,t,n){return e=Z(e),t=Z(t),n._fast(Z(1).div(t.sub(e))).late(e.cyclePos())}),{focusSpan:Bh,focusspan:Ph}=O(["focusSpan","focusspan"],function(e,t){return t._focus(e.begin,e.end)}),wh=O("ply",function(e,t){const n=t.fmap(u=>et(u)._fast(e)).squeezeJoin();return kt&&(n.tactus=Z(e).mulmaybe(t.tactus)),n}),{fast:Ih,density:l5}=O(["fast","density"],function(e,t){return e===0?Pe:(e=Z(e),t.withQueryTime(u=>u.mul(e)).withHapTime(u=>u.div(e)).setTactus(t.tactus))},!0,!0),Sh=O("hurry",function(e,t){return t._fast(e).mul(et({speed:e}))}),{slow:_h,sparsity:kh}=O(["slow","sparsity"],function(e,t){return e===0?Pe:t._fast(Z(1).div(e))}),xh=O("inside",function(e,t,n){return t(n._slow(e))._fast(e)}),Nh=O("outside",function(e,t,n){return t(n._fast(e))._slow(e)}),Th=O("lastOf",function(e,t,n){const u=Array(e-1).fill(n);return u.push(t(n)),hi(...u)}),{firstOf:Vh,every:Rh}=O(["firstOf","every"],function(e,t,n){const u=Array(e-1).fill(n);return u.unshift(t(n)),hi(...u)}),Lh=O("apply",function(e,t){return e(t)}),Gh=O("cpm",function(e,t){return t._fast(e/60/1)}),Oh=O("early",function(e,t){return e=Z(e),t.withQueryTime(n=>n.add(e)).withHapTime(n=>n.sub(e))},!0,!0),Zr=O("late",function(e,t){return e=Z(e),t._early(Z(0).sub(e))},!0,!0),Wh=O("zoom",function(e,t,n){if(t=Z(t),e=Z(e),e.gte(t))return ht;const u=t.sub(e),i=kt?n.tactus.mulmaybe(u):void 0;return n.withQuerySpan(r=>r.withCycle(s=>s.mul(u).add(e))).withHapSpan(r=>r.withCycle(s=>s.sub(e).div(u))).splitQueries().setTactus(i)}),{zoomArc:$h,zoomarc:zh}=O(["zoomArc","zoomarc"],function(e,t){return t.zoom(e.begin,e.end)}),qh=O("linger",function(e,t){return e==0?Pe:e<0?t._zoom(e.add(1),1)._slow(e):t._zoom(0,e)._slow(e)},!0,!0),jh=O("segment",function(e,t){return t.struct(et(!0)._fast(e)).setTactus(e)}),Xh=O("swingBy",(e,t,n)=>n.inside(t,Zr(jr(0,e/2)))),Zh=O("swing",(e,t)=>t.swingBy(1/3,e)),{invert:Hh,inv:Kh}=O(["invert","inv"],function(e){return e.fmap(t=>!t)},!0,!0),Yh=O("when",function(e,t,n){return e?t(n):n}),Jh=O("off",function(e,t,n){return Ne(n,t(n.late(e)))}),Uh=O("brak",function(e){return e.when(gn(!1,!0),t=>dt(t,Pe)._late(.25))}),Hr=O("rev",function(e){const t=function(n){const u=n.span,i=u.begin.sam(),r=u.begin.nextSam(),s=function(f){const d=f.withTime(g=>i.add(r.sub(g))),h=d.begin;return d.begin=d.end,d.end=h,d};return e.query(n.setSpan(s(u))).map(f=>f.withSpan(s))};return new ue(t).splitQueries()},!1,!0),Qh=O("pressBy",function(e,t){return t.fmap(n=>et(n).compress(e,1)).squeezeJoin()}),ed=O("press",function(e){return e._pressBy(.5)});ue.prototype.hush=function(){return Pe};const td=O("palindrome",function(e){return e.lastOf(2,Hr)},!0,!0),{juxBy:nd,juxby:ud}=O(["juxBy","juxby"],function(e,t,n){e/=2;const u=function(s,a,f){return a in s?s[a]:f},i=n.withValue(s=>Object.assign({},s,{pan:u(s,"pan",.5)-e})),r=t(n.withValue(s=>Object.assign({},s,{pan:u(s,"pan",.5)+e})));return Ne(i,r).setTactus(kt?Kt(i.tactus,r.tactus):void 0)}),id=O("jux",function(e,t){return t._juxBy(1,e,t)}),{echoWith:rd,echowith:sd,stutWith:ad,stutwith:od}=O(["echoWith","echowith","stutWith","stutwith"],function(e,t,n,u){return Ne(...ii(0,e-1).map(i=>n(u.late(Z(t).mul(i)),i)))}),cd=O("echo",function(e,t,n,u){return u._echoWith(e,t,(i,r)=>i.gain(Math.pow(n,r)))}),ld=O("stut",function(e,t,n,u){return u._echoWith(e,n,(i,r)=>i.gain(Math.pow(t,r)))}),Kr=function(e,t,n=!1){return e=Z(e),gn(...ii(0,e.sub(1)).map(u=>n?t.late(Z(u).div(e)):t.early(Z(u).div(e))))},fd=O("iter",function(e,t){return Kr(e,t,!1)},!0,!0),{iterBack:hd,iterback:dd}=O(["iterBack","iterback"],function(e,t){return Kr(e,t,!0)},!0,!0),{repeatCycles:pd}=O("repeatCycles",function(e,t){return new ue(function(n){const u=n.span.begin.sam(),i=u.div(e).sam(),r=u.sub(i);return n=n.withSpan(s=>s.withTime(a=>a.sub(r))),t.query(n).map(s=>s.withSpan(a=>a.withTime(f=>f.add(r))))}).splitQueries()},!0,!0),Yr=function(e,t,n,u=!1,i=!1){const r=Array(e-1).fill(!1);r.unshift(!0);const s=Kr(e,pt(...r),!u);return i||(n=n.repeatCycles(e)),n.when(s,t)},{chunk:md,slowchunk:gd,slowChunk:Ad}=O(["chunk","slowchunk","slowChunk"],function(e,t,n){return Yr(e,t,n,!1,!1)}),{chunkBack:Cd,chunkback:Dd}=O(["chunkBack","chunkback"],function(e,t,n){return Yr(e,t,n,!0)}),{fastchunk:Ed,fastChunk:yd}=O(["fastchunk","fastChunk"],function(e,t,n){return Yr(e,t,n,!1,!0)}),vd=O("bypass",function(e,t){return e=!!parseInt(e),e?Pe:t},!0,!0),Fd=O("ribbon",(e,t,n)=>n.early(e).restart(et(1).slow(t))),bd=O("hsla",(e,t,n,u,i)=>i.color(`hsla(${e}turn,${t*100}%,${n*100}%,${u})`)),Md=O("hsl",(e,t,n,u)=>u.color(`hsl(${e}turn,${t*100}%,${n*100}%)`));ue.prototype.tag=function(e){return this.withContext(t=>({...t,tags:(t.tags||[]).concat([e])}))},ue.prototype.stepJoin=function(){const e=this,t=mt(...pi(mi(e.queryArc(0,1)))).tactus,n=function(u){const r=e.early(u.span.begin.sam()).query(u.setSpan(new $e(Z(0),Z(1))));return mt(...pi(mi(r))).query(u)};return new ue(n,t)};function pi(e){const t=e.filter((r,s)=>s.hasTactus).reduce((r,s)=>r.add(s),Z(0)),n=_n(e.map((r,s)=>s.tactus)).reduce((r,s)=>r.add(s),Z(0)),u=t.eq(0)?void 0:n.div(t);function i(r,s){return s.tactus===void 0?[r.mulmaybe(u),s]:[s.tactus,s]}return e.map(r=>i(...r))}function mi(e){const t=Ot(e.map(i=>[i.part.begin,i.part.end])),n=xr([Z(0),Z(1),...t]);return kr(n).map(i=>[i[1].sub(i[0]),Ne(...Jr(new $e(...i),e).map(r=>r.value.withHap(s=>s.setContext(s.combineContext(r)))))])}function Jr(e,t){return _n(t.map(n=>Ur(e,n)))}function Ur(e,t){const n=e.intersection(t.part);if(n!=null)return new Oe(t.whole,n,t.value,t.context)}const Bd=O("steps",function(e,t){return t.tactus===void 0?t:t.tactus.eq(Z(0))?ht:t.fast(Z(e).div(t.tactus))});function gi(e,...t){const n=t.map(i=>Xr(i));if(n.length==0)return Pe;e==0&&(e=n[0][1]);const u=[];for(const i of n)i[1]!=0&&(e==i[1]?u.push(i[0]):u.push(i[0]._fast(Z(e).div(Z(i[1])))));return Ne(...u)}function Qr(e,...t){return t.length==0?Pe:Array.isArray(t[0])?gi(e,...t):Ai(...t).steps(e)}function Ai(...e){if(Array.isArray(e[0]))return gi(0,...e);if(e=e.filter(r=>r.hasTactus),e.length==0)return Pe;const t=e[0].tactus;if(t.eq(Z(0)))return ht;const[n,...u]=e,i=Ne(n,...u.map(r=>r._slow(r.tactus.div(t))));return i.tactus=t,i}function mt(...e){if(e.length===0)return ht;const t=s=>Array.isArray(s)?s:[s.tactus,s];if(e=e.map(t),e.find(s=>s[0]===void 0)){const s=e.map(f=>f[0]).filter(f=>f!==void 0);if(s.length===0)return dt(...e.map(f=>f[1]));if(s.length===e.length)return ht;const a=s.reduce((f,d)=>f.add(d),Z(0)).div(s.length);for(let f of e)f[0]===void 0&&(f[0]=a)}if(e.length==1){const s=J(e[0][1]);return s.tactus=e[0][0],s}const n=e.map(s=>s[0]).reduce((s,a)=>s.add(a),Z(0));let u=Z(0);const i=[];for(const[s,a]of e){if(Z(s).eq(0))continue;const f=u.add(s);i.push(J(a)._compress(u.div(n),f.div(n))),u=f}const r=Ne(...i);return r.tactus=n,r}const Pd=mt,Ci=mt;function wd(...e){e=e.map(i=>Array.isArray(i)?i.map(J):[J(i)]);const t=Kt(...e.map(i=>Z(i.length)));let n=[];for(let i=0;i<t;++i)n.push(...e.map(r=>r.length==0?Pe:r[i%r.length]));n=n.filter(i=>i.hasTactus&&i.tactus>0);const u=n.reduce((i,r)=>i.add(r.tactus),Z(0));return n=mt(...n),n.tactus=u,n}const Id=di("s_add",function(e,t){if(!t.hasTactus||t.tactus.lte(0)||(e=Z(e),e.eq(0)))return ht;const n=e<0;n&&(e=e.abs());const u=e.div(t.tactus);return u.lte(0)?ht:u.gte(1)?t:n?t.zoom(Z(1).sub(u),1):t.zoom(0,u)}),Sd=di("s_sub",function(e,t){return t.hasTactus?(e=Z(e),e.lt(0)?t.s_add(Z(0).sub(t.tactus.add(e))):t.s_add(t.tactus.sub(e))):ht}),_d=di("s_expand",function(e,t){return t.withTactus(n=>n.mul(Z(e)))}),kd=di("s_contract",function(e,t){return t.withTactus(n=>n.div(Z(e)))});ue.prototype.s_taperlist=function(e,t){const n=this;if(!n.hasTactus)return[n];if(t=t-1,t===0)return[n];const u=[],i=e>0;e=Z(Math.abs(e));const r=n.tactus.sub(e.mul(Z(t))).max(Z(0));for(let s=0;s<t;++s)u.push(n.zoom(0,r.add(e.mul(Z(s))).div(n.tactus)));return u.push(n),i&&u.reverse(),u};const xd=(e,t,n)=>n.s_taperlist(e,t),Nd=O("s_taper",function(e,t,n){if(!n.hasTactus)return ht;const u=n.s_taperlist(e,t),i=mt(...u);return i.tactus=u.reduce((r,s)=>r.add(s.tactus),Z(0)),i},!0,!1,e=>e.stepJoin());ue.prototype.s_tour=function(...e){return mt(...[].concat(...e.map((t,n)=>[...e.slice(0,e.length-n),this,...e.slice(e.length-n)]),this,...e))};const Td=function(e,...t){return e.s_tour(...t)},Vd=O("chop",function(e,t){const u=Array.from({length:e},(r,s)=>s).map(r=>({begin:r/e,end:(r+1)/e})),i=function(r){return pt(u.map(s=>Object.assign({},r,s)))};return t.squeezeBind(i).setTactus(kt?Z(e).mulmaybe(t.tactus):void 0)}),Rd=O("striate",function(e,t){const u=Array.from({length:e},(r,s)=>s).map(r=>({begin:r/e,end:(r+1)/e})),i=gn(...u);return t.set(i)._fast(e).setTactus(kt?Z(e).mulmaybe(t.tactus):void 0)}),Ld=function(e,t,n=.5){return t.speed(1/e*n).unit("c").slow(e)},es=O("slice",function(e,t,n){return e.innerBind(u=>t.outerBind(i=>n.outerBind(r=>{r=r instanceof Object?r:{s:r};const s=Array.isArray(u)?u[i]:i/u,a=Array.isArray(u)?u[i+1]:(i+1)/u;return et({begin:s,end:a,_slices:u,...r})}))).setTactus(t.tactus)},!1),Gd=O("splice",function(e,t,n){const u=es(e,t,n);return new ue(i=>{const r=i.controls._cps||1;return u.query(i).map(a=>a.withValue(f=>({speed:r/f._slices/a.whole.duration*(f.speed||1),unit:"c",...f})))}).setTactus(t.tactus)},!1),{loopAt:Od,loopat:Wd}=O(["loopAt","loopat"],function(e,t){return new ue(n=>Ld(e,t,n.controls._cps).query(n))}),$d=O("fit",e=>e.withHaps((t,n)=>t.map(u=>u.withValue(i=>({...i,speed:(n.controls._cps||1)/u.whole.duration,unit:"c"}))))),{loopAtCps:zd,loopatcps:qd}=O(["loopAtCps","loopatcps"],function(e,t,n){return Ld(e,n,t)}),jd=e=>et(1).withValue(()=>J(e())).innerJoin();let Xd=e=>e<.5?1:1-(e-.5)/.5,ts=(e,t,n)=>{t=J(t),e=J(e),n=J(n);let u=t.fmap(r=>({gain:Xd(r)})),i=t.fmap(r=>({gain:Xd(1-r)}));return Ne(e.mul(u),n.mul(i))};ue.prototype.xfade=function(e,t){return ts(this,e,t)};function Eu(e){let t=Array.isArray(e);e=t?e:[e];const n=e[0],u=s=>{let a;if(typeof s=="object"&&s.value!==void 0&&(a={...s},s=s.value,delete a.value),t&&Array.isArray(s)){const f=a||{};return s.forEach((d,h)=>{h<e.length&&(f[e[h]]=d)}),f}else return a?(a[n]=s,a):{[n]:s}},i=(...s)=>pt(...s).withValue(u),r=function(...s){return s.length?this.set(i(...s)):this.fmap(u)};return ue.prototype[n]=r,i}function I(e,...t){const n=Array.isArray(e)?e[0]:e;let u={};return u[n]=Eu(e),t.forEach(i=>{u[i]=u[n],ue.prototype[i]=ue.prototype[n]}),u}const{s:ns,sound:us}=I(["s","n","gain"],"sound"),{source:is,src:rs}=I("source","src"),{n:ss}=I("n"),{note:as}=I(["note","n"]),{accelerate:os}=I("accelerate"),{velocity:cs}=I("velocity"),{gain:ls}=I("gain"),{postgain:fs}=I("postgain"),{amp:hs}=I("amp"),{attack:ds,att:ps}=I("attack","att"),{fmh:ms}=I(["fmh","fmi"],"fmh"),{fmi:gs,fm:As}=I(["fmi","fmh"],"fm"),{fmenv:Cs}=I("fmenv"),{fmattack:Ds}=I("fmattack"),{fmdecay:Es}=I("fmdecay"),{fmsustain:ys}=I("fmsustain"),{fmrelease:vs}=I("fmrelease"),{fmvelocity:Fs}=I("fmvelocity"),{bank:bs}=I("bank"),{analyze:Ms}=I("analyze"),{fft:Bs}=I("fft"),{decay:Ps,dec:ws}=I("decay","dec"),{sustain:Is,sus:Ss}=I("sustain","sus"),{release:_s,rel:ks}=I("release","rel"),{hold:xs}=I("hold"),{bandf:Ns,bpf:Ts,bp:Vs}=I(["bandf","bandq","bpenv"],"bpf","bp"),{bandq:Rs,bpq:Ls}=I("bandq","bpq"),{begin:Gs}=I("begin"),{end:Os}=I("end"),{loop:Ws}=I("loop"),{loopBegin:$s,loopb:zs}=I("loopBegin","loopb"),{loopEnd:qs,loope:js}=I("loopEnd","loope"),{crush:Xs}=I("crush"),{coarse:Zs}=I("coarse"),{drive:Hs}=I("drive"),{channels:Ks,ch:Ys}=I("channels","ch"),{phaserrate:Js,phasr:Us}=I("phaserrate","phasr"),{phaser:Qs,ph:ea}=I(["phaser","phaserdepth","phasercenter","phasersweep"],"ph"),{phasersweep:ta,phs:na}=I("phasersweep","phs"),{phasercenter:ua,phc:ia}=I("phasercenter","phc"),{phaserdepth:ra,phd:sa,phasdp:aa}=I("phaserdepth","phd","phasdp"),{channel:oa}=I("channel"),{cut:ca}=I("cut"),{cutoff:la,ctf:fa,lpf:ha,lp:da}=I(["cutoff","resonance","lpenv"],"ctf","lpf","lp"),{lpenv:pa,lpe:ma}=I("lpenv","lpe"),{hpenv:ga,hpe:Aa}=I("hpenv","hpe"),{bpenv:Ca,bpe:Da}=I("bpenv","bpe"),{lpattack:Ea,lpa:ya}=I("lpattack","lpa"),{hpattack:va,hpa:Fa}=I("hpattack","hpa"),{bpattack:ba,bpa:Ma}=I("bpattack","bpa"),{lpdecay:Ba,lpd:Pa}=I("lpdecay","lpd"),{hpdecay:wa,hpd:Ia}=I("hpdecay","hpd"),{bpdecay:Sa,bpd:_a}=I("bpdecay","bpd"),{lpsustain:ka,lps:xa}=I("lpsustain","lps"),{hpsustain:Na,hps:Ta}=I("hpsustain","hps"),{bpsustain:Va,bps:Ra}=I("bpsustain","bps"),{lprelease:La,lpr:Ga}=I("lprelease","lpr"),{hprelease:Oa,hpr:Wa}=I("hprelease","hpr"),{bprelease:$a,bpr:za}=I("bprelease","bpr"),{ftype:qa}=I("ftype"),{fanchor:ja}=I("fanchor"),{vib:Xa,vibrato:Za,v:Ha}=I(["vib","vibmod"],"vibrato","v"),{noise:Ka}=I("noise"),{vibmod:Ya,vmod:Ja}=I(["vibmod","vib"],"vmod"),{hcutoff:Ua,hpf:Qa,hp:eo}=I(["hcutoff","hresonance","hpenv"],"hpf","hp"),{hresonance:to,hpq:no}=I("hresonance","hpq"),{resonance:uo,lpq:io}=I("resonance","lpq"),{djf:ro}=I("djf"),{delay:so}=I(["delay","delaytime","delayfeedback"]),{delayfeedback:ao,delayfb:oo,dfb:co}=I("delayfeedback","delayfb","dfb"),{delaytime:lo,delayt:fo,dt:ho}=I("delaytime","delayt","dt"),{lock:po}=I("lock"),{detune:mo,det:go}=I("detune","det"),{unison:Ao}=I("unison"),{spread:Co}=I("spread"),{dry:Do}=I("dry"),{fadeTime:Eo,fadeOutTime:yo}=I("fadeTime","fadeOutTime"),{fadeInTime:vo}=I("fadeInTime"),{freq:Fo}=I("freq"),{pattack:bo,patt:Mo}=I("pattack","patt"),{pdecay:Bo,pdec:Po}=I("pdecay","pdec"),{psustain:wo,psus:Io}=I("psustain","psus"),{prelease:So,prel:_o}=I("prelease","prel"),{penv:ko}=I("penv"),{pcurve:xo}=I("pcurve"),{panchor:No}=I("panchor"),{gate:To,gat:Vo}=I("gate","gat"),{leslie:Ro}=I("leslie"),{lrate:Lo}=I("lrate"),{lsize:Go}=I("lsize"),{activeLabel:Oo}=I("activeLabel"),{label:Wo}=I(["label","activeLabel"]),{degree:$o}=I("degree"),{mtranspose:zo}=I("mtranspose"),{ctranspose:qo}=I("ctranspose"),{harmonic:jo}=I("harmonic"),{stepsPerOctave:Xo}=I("stepsPerOctave"),{octaveR:Zo}=I("octaveR"),{nudge:Ho}=I("nudge"),{octave:Ko}=I("octave"),{orbit:Yo}=I("orbit"),{overgain:Jo}=I("overgain"),{overshape:Uo}=I("overshape"),{pan:Qo}=I("pan"),{panspan:ec}=I("panspan"),{pansplay:tc}=I("pansplay"),{panwidth:nc}=I("panwidth"),{panorient:uc}=I("panorient"),{rate:ic}=I("rate"),{slide:rc}=I("slide"),{semitone:sc}=I("semitone"),{voice:ac}=I("voice"),{chord:oc}=I("chord"),{dictionary:cc,dict:lc}=I("dictionary","dict"),{anchor:fc}=I("anchor"),{offset:hc}=I("offset"),{octaves:dc}=I("octaves"),{mode:pc}=I(["mode","anchor"]),{room:mc}=I(["room","size"]),{roomlp:gc,rlp:Ac}=I("roomlp","rlp"),{roomdim:Cc,rdim:Dc}=I("roomdim","rdim"),{roomfade:Ec,rfade:yc}=I("roomfade","rfade"),{ir:vc,iresponse:Fc}=I(["ir","i"],"iresponse"),{roomsize:bc,size:Mc,sz:Bc,rsize:Pc}=I("roomsize","size","sz","rsize"),{shape:wc}=I(["shape","shapevol"]),{distort:Ic,dist:Sc}=I(["distort","distortvol"],"dist"),{compressor:_c}=I(["compressor","compressorRatio","compressorKnee","compressorAttack","compressorRelease"]),{compressorKnee:kc}=I("compressorKnee"),{compressorRatio:xc}=I("compressorRatio"),{compressorAttack:Nc}=I("compressorAttack"),{compressorRelease:Tc}=I("compressorRelease"),{speed:Vc}=I("speed"),{unit:Rc}=I("unit"),{squiz:Lc}=I("squiz"),{vowel:Gc}=I("vowel"),{waveloss:Oc}=I("waveloss"),{density:s2}=I("density"),{expression:Wc}=I("expression"),{sustainpedal:$c}=I("sustainpedal"),{tremolodepth:zc,tremdp:qc}=I("tremolodepth","tremdp"),{tremolorate:jc,tremr:Xc}=I("tremolorate","tremr"),{fshift:Zc}=I("fshift"),{fshiftnote:Hc}=I("fshiftnote"),{fshiftphase:Kc}=I("fshiftphase"),{triode:Yc}=I("triode"),{krush:Jc}=I("krush"),{kcutoff:Uc}=I("kcutoff"),{octer:Qc}=I("octer"),{octersub:e0}=I("octersub"),{octersubsub:t0}=I("octersubsub"),{ring:n0}=I("ring"),{ringf:u0}=I("ringf"),{ringdf:i0}=I("ringdf"),{freeze:r0}=I("freeze"),{xsdelay:s0}=I("xsdelay"),{tsdelay:a0}=I("tsdelay"),{real:o0}=I("real"),{imag:c0}=I("imag"),{enhance:l0}=I("enhance"),{partials:f0}=I("partials"),{comb:h0}=I("comb"),{smear:d0}=I("smear"),{scram:p0}=I("scram"),{binshift:m0}=I("binshift"),{hbrick:g0}=I("hbrick"),{lbrick:A0}=I("lbrick"),{midichan:C0}=I("midichan"),{control:D0}=I("control"),{ccn:E0}=I("ccn"),{ccv:y0}=I("ccv"),{polyTouch:v0}=I("polyTouch"),{midibend:F0}=I("midibend"),{miditouch:b0}=I("miditouch"),{ctlNum:M0}=I("ctlNum"),{frameRate:B0}=I("frameRate"),{frames:P0}=I("frames"),{hours:w0}=I("hours"),{midicmd:I0}=I("midicmd"),{minutes:S0}=I("minutes"),{progNum:_0}=I("progNum"),{seconds:k0}=I("seconds"),{songPtr:x0}=I("songPtr"),{uid:N0}=I("uid"),{val:T0}=I("val"),{cps:V0}=I("cps"),{clip:R0,legato:L0}=I("clip","legato"),{duration:G0,dur:O0}=I("duration","dur"),{zrand:W0}=I("zrand"),{curve:$0}=I("curve"),{deltaSlide:z0}=I("deltaSlide"),{pitchJump:q0}=I("pitchJump"),{pitchJumpTime:j0}=I("pitchJumpTime"),{lfo:X0,repeatTime:Z0}=I("lfo","repeatTime"),{znoise:H0}=I("znoise"),{zmod:K0}=I("zmod"),{zcrush:Y0}=I("zcrush"),{zdelay:J0}=I("zdelay"),{tremolo:U0}=I("tremolo"),{zzfx:Q0}=I("zzfx"),{color:el,colour:tl}=I(["color","colour"]);let Di=(...e)=>e.reduce((t,n)=>Object.assign(t,{[n]:Eu(n)}),{});const nl=O("adsr",(e,t)=>{e=Array.isArray(e)?e:[e];const[n,u,i,r]=e;return t.set({attack:n,decay:u,sustain:i,release:r})}),ul=O("ad",(e,t)=>{e=Array.isArray(e)?e:[e];const[n,u=n]=e;return t.attack(n).decay(u)}),il=O("ds",(e,t)=>{e=Array.isArray(e)?e:[e];const[n,u=0]=e;return t.set({decay:n,sustain:u})}),rl=O("ar",(e,t)=>{e=Array.isArray(e)?e:[e];const[n,u=n]=e;return t.set({attack:n,release:u})}),Zd=Object.freeze(Object.defineProperty({__proto__:null,accelerate:os,activeLabel:Oo,ad:ul,adsr:nl,amp:hs,analyze:Ms,anchor:fc,ar:rl,att:ps,attack:ds,bandf:Ns,bandq:Rs,bank:bs,begin:Gs,binshift:m0,bp:Vs,bpa:Ma,bpattack:ba,bpd:_a,bpdecay:Sa,bpe:Da,bpenv:Ca,bpf:Ts,bpq:Ls,bpr:za,bprelease:$a,bps:Ra,bpsustain:Va,ccn:E0,ccv:y0,ch:Ys,channel:oa,channels:Ks,chord:oc,clip:R0,coarse:Zs,color:el,colour:tl,comb:h0,compressor:_c,compressorAttack:Nc,compressorKnee:kc,compressorRatio:xc,compressorRelease:Tc,control:D0,cps:V0,createParam:Eu,createParams:Di,crush:Xs,ctf:fa,ctlNum:M0,ctranspose:qo,curve:$0,cut:ca,cutoff:la,dec:ws,decay:Ps,degree:$o,delay:so,delayfb:oo,delayfeedback:ao,delayt:fo,delaytime:lo,deltaSlide:z0,density:s2,det:go,detune:mo,dfb:co,dict:lc,dictionary:cc,dist:Sc,distort:Ic,djf:ro,drive:Hs,dry:Do,ds:il,dt:ho,dur:O0,duration:G0,end:Os,enhance:l0,expression:Wc,fadeInTime:vo,fadeOutTime:yo,fadeTime:Eo,fanchor:ja,fft:Bs,fm:As,fmattack:Ds,fmdecay:Es,fmenv:Cs,fmh:ms,fmi:gs,fmrelease:vs,fmsustain:ys,fmvelocity:Fs,frameRate:B0,frames:P0,freeze:r0,freq:Fo,fshift:Zc,fshiftnote:Hc,fshiftphase:Kc,ftype:qa,gain:ls,gat:Vo,gate:To,harmonic:jo,hbrick:g0,hcutoff:Ua,hold:xs,hours:w0,hp:eo,hpa:Fa,hpattack:va,hpd:Ia,hpdecay:wa,hpe:Aa,hpenv:ga,hpf:Qa,hpq:no,hpr:Wa,hprelease:Oa,hps:Ta,hpsustain:Na,hresonance:to,imag:c0,ir:vc,iresponse:Fc,kcutoff:Uc,krush:Jc,label:Wo,lbrick:A0,legato:L0,leslie:Ro,lfo:X0,lock:po,loop:Ws,loopBegin:$s,loopEnd:qs,loopb:zs,loope:js,lp:da,lpa:ya,lpattack:Ea,lpd:Pa,lpdecay:Ba,lpe:ma,lpenv:pa,lpf:ha,lpq:io,lpr:Ga,lprelease:La,lps:xa,lpsustain:ka,lrate:Lo,lsize:Go,midibend:F0,midichan:C0,midicmd:I0,miditouch:b0,minutes:S0,mode:pc,mtranspose:zo,n:ss,noise:Ka,note:as,nudge:Ho,octave:Ko,octaveR:Zo,octaves:dc,octer:Qc,octersub:e0,octersubsub:t0,offset:hc,orbit:Yo,overgain:Jo,overshape:Uo,pan:Qo,panchor:No,panorient:uc,panspan:ec,pansplay:tc,panw