sonarium 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +271 -0
- package/dist/index.d.ts +1000 -0
- package/dist/index.js +2716 -0
- package/dist/index.js.map +1 -0
- package/dist/sonarium.iife.js +236 -0
- package/dist/sonarium.iife.js.map +1 -0
- package/package.json +63 -0
- package/src/core/engine.ts +468 -0
- package/src/core/listener.ts +61 -0
- package/src/core/matter-voice.ts +240 -0
- package/src/core/profile.ts +313 -0
- package/src/core/room.ts +135 -0
- package/src/core/scanner.ts +176 -0
- package/src/core/voices.ts +222 -0
- package/src/index.ts +74 -0
- package/src/interact/activate.ts +56 -0
- package/src/interact/drag.ts +52 -0
- package/src/interact/keyboard.ts +48 -0
- package/src/interact/midi.ts +40 -0
- package/src/interact/motion.ts +61 -0
- package/src/interact/pointer.ts +65 -0
- package/src/interact/scroll.ts +43 -0
- package/src/math/chroma.ts +111 -0
- package/src/math/mapping.ts +100 -0
- package/src/math/matter.ts +201 -0
- package/src/math/modular.ts +99 -0
- package/src/math/pulse.ts +64 -0
- package/src/math/scales.ts +90 -0
- package/src/math/util.ts +16 -0
- package/src/spatial/backend.ts +166 -0
- package/src/spatial/bus.ts +114 -0
- package/src/spatial/decoder.ts +63 -0
- package/src/spatial/encoder.ts +54 -0
- package/src/spatial/field.ts +75 -0
- package/src/spatial/perceptual.ts +43 -0
- package/src/spatial/room-foa.ts +81 -0
- package/src/spatial/rotation.ts +73 -0
- package/src/spatial/sh.ts +38 -0
- package/src/spatial/sphere.ts +36 -0
- package/src/themes/index.ts +60 -0
- package/src/types.ts +157 -0
- package/src/ui/gate.ts +65 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";var Sonarium=(()=>{var am=Object.create;var pn=Object.defineProperty;var cm=Object.getOwnPropertyDescriptor;var um=Object.getOwnPropertyNames;var lm=Object.getPrototypeOf,hm=Object.prototype.hasOwnProperty;var me=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),go=(o,t)=>{for(var e in t)pn(o,e,{get:t[e],enumerable:!0})},Ba=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of um(t))!hm.call(o,n)&&n!==e&&pn(o,n,{get:()=>t[n],enumerable:!(r=cm(t,n))||r.enumerable});return o};var ja=(o,t,e)=>(e=o!=null?am(lm(o)):{},Ba(t||!o||!o.__esModule?pn(e,"default",{value:o,enumerable:!0}):e,o)),pm=o=>Ba(pn({},"__esModule",{value:!0}),o);var za=me((fg,Ar)=>{"use strict";function mm(o){if(Array.isArray(o))return o}Ar.exports=mm,Ar.exports.__esModule=!0,Ar.exports.default=Ar.exports});var Ua=me((gg,Cr)=>{"use strict";function dm(o,t){var e=o==null?null:typeof Symbol<"u"&&o[Symbol.iterator]||o["@@iterator"];if(e!=null){var r,n,s,a,i=[],c=!0,u=!1;try{if(s=(e=e.call(o)).next,t===0){if(Object(e)!==e)return;c=!1}else for(;!(c=(r=s.call(e)).done)&&(i.push(r.value),i.length!==t);c=!0);}catch(l){u=!0,n=l}finally{try{if(!c&&e.return!=null&&(a=e.return(),Object(a)!==a))return}finally{if(u)throw n}}return i}}Cr.exports=dm,Cr.exports.__esModule=!0,Cr.exports.default=Cr.exports});var Ha=me((_g,Nr)=>{"use strict";function fm(o,t){(t==null||t>o.length)&&(t=o.length);for(var e=0,r=Array(t);e<t;e++)r[e]=o[e];return r}Nr.exports=fm,Nr.exports.__esModule=!0,Nr.exports.default=Nr.exports});var Ya=me((xg,kr)=>{"use strict";var $a=Ha();function gm(o,t){if(o){if(typeof o=="string")return $a(o,t);var e={}.toString.call(o).slice(8,-1);return e==="Object"&&o.constructor&&(e=o.constructor.name),e==="Map"||e==="Set"?Array.from(o):e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?$a(o,t):void 0}}kr.exports=gm,kr.exports.__esModule=!0,kr.exports.default=kr.exports});var Xa=me((yg,Or)=>{"use strict";function _m(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}Or.exports=_m,Or.exports.__esModule=!0,Or.exports.default=Or.exports});var Za=me((vg,Er)=>{"use strict";var xm=za(),ym=Ua(),vm=Ya(),bm=Xa();function wm(o,t){return xm(o)||ym(o,t)||vm(o,t)||bm()}Er.exports=wm,Er.exports.__esModule=!0,Er.exports.default=Er.exports});var Qa=me((bg,Mr)=>{"use strict";function Tm(o,t){if(!(o instanceof t))throw new TypeError("Cannot call a class as a function")}Mr.exports=Tm,Mr.exports.__esModule=!0,Mr.exports.default=Mr.exports});var Ns=me((wg,Be)=>{"use strict";function Cs(o){"@babel/helpers - typeof";return Be.exports=Cs=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Be.exports.__esModule=!0,Be.exports.default=Be.exports,Cs(o)}Be.exports=Cs,Be.exports.__esModule=!0,Be.exports.default=Be.exports});var Ja=me((Tg,Fr)=>{"use strict";var Ka=Ns().default;function Sm(o,t){if(Ka(o)!="object"||!o)return o;var e=o[Symbol.toPrimitive];if(e!==void 0){var r=e.call(o,t||"default");if(Ka(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(o)}Fr.exports=Sm,Fr.exports.__esModule=!0,Fr.exports.default=Fr.exports});var tc=me((Sg,Dr)=>{"use strict";var Am=Ns().default,Cm=Ja();function Nm(o){var t=Cm(o,"string");return Am(t)=="symbol"?t:t+""}Dr.exports=Nm,Dr.exports.__esModule=!0,Dr.exports.default=Dr.exports});var oc=me((Ag,Rr)=>{"use strict";var km=tc();function ec(o,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(o,km(r.key),r)}}function Om(o,t,e){return t&&ec(o.prototype,t),e&&ec(o,e),Object.defineProperty(o,"prototype",{writable:!1}),o}Rr.exports=Om,Rr.exports.__esModule=!0,Rr.exports.default=Rr.exports});var ks=me((mn,rc)=>{"use strict";(function(o,t){typeof mn=="object"&&typeof rc<"u"?t(mn,Za(),Qa(),oc()):typeof define=="function"&&define.amd?define(["exports","@babel/runtime/helpers/slicedToArray","@babel/runtime/helpers/classCallCheck","@babel/runtime/helpers/createClass"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.automationEvents={},o._slicedToArray,o._classCallCheck,o._createClass))})(mn,(function(o,t,e,r){"use strict";var n=function(w,C,k){return{endTime:C,insertTime:k,type:"exponentialRampToValue",value:w}},s=function(w,C,k){return{endTime:C,insertTime:k,type:"linearRampToValue",value:w}},a=function(w,C){return{startTime:C,type:"setValue",value:w}},i=function(w,C,k){return{duration:k,startTime:C,type:"setValueCurve",values:w}},c=function(w,C,k){var R=k.startTime,V=k.target,M=k.timeConstant;return V+(C-V)*Math.exp((R-w)/M)},u=function(w){return w.type==="exponentialRampToValue"},l=function(w){return w.type==="linearRampToValue"},h=function(w){return u(w)||l(w)},p=function(w){return w.type==="setValue"},m=function(w){return w.type==="setValueCurve"},d=function(w,C,k,R){var V=w[C];return V===void 0?R:h(V)||p(V)?V.value:m(V)?V.values[V.values.length-1]:c(k,d(w,C-1,V.startTime,R),V)},f=function(w,C,k,R,V){return k===void 0?[R.insertTime,V]:h(k)?[k.endTime,k.value]:p(k)?[k.startTime,k.value]:m(k)?[k.startTime+k.duration,k.values[k.values.length-1]]:[k.startTime,d(w,C-1,k.startTime,V)]},g=function(w){return w.type==="cancelAndHold"},y=function(w){return w.type==="cancelScheduledValues"},S=function(w){return g(w)||y(w)?w.cancelTime:u(w)||l(w)?w.endTime:w.startTime},O=function(w,C,k,R){var V=R.endTime,M=R.value;return k===M?M:0<k&&0<M||k<0&&M<0?k*Math.pow(M/k,(w-C)/(V-C)):w<V?k:M},D=function(w,C,k,R){var V=R.endTime,M=R.value;return k+(w-C)/(V-C)*(M-k)},_=function(w,C){var k=Math.floor(C);if(k===C)return w[k];var R=Math.ceil(C);return(1-(C-k))*w[k]+(1-(R-C))*w[R]},b=function(w,C){var k=C.duration,R=C.startTime,V=C.values,M=(w-R)/k*(V.length-1);return _(V,M)},T=function(w,C,k){for(var R=w.length,V=Math.max(1,Math.floor(k/C*R))+1,M=w instanceof Float32Array?new Float32Array(V):w.slice(0,V),J=0;J<V;J+=1){var tt=J/(V-1)*k,yt=tt/C*(R-1);M[J]=_(w,yt)}return M},v=function(w){return w.type==="setTarget"},q=(function(){function L(w){e(this,L),this._automationEvents=[],this._currenTime=0,this._defaultValue=w}return r(L,[{key:Symbol.iterator,value:function(){return this._automationEvents[Symbol.iterator]()}},{key:"add",value:function(C){var k=S(C);if(g(C)||y(C)){var R=this._automationEvents.findIndex(function(Lt){return y(C)&&m(Lt)?Lt.startTime+Lt.duration>=k:S(Lt)>=k}),V=this._automationEvents[R];if(R!==-1&&(this._automationEvents=this._automationEvents.slice(0,R)),g(C)){var M=this._automationEvents[this._automationEvents.length-1];if(V!==void 0&&h(V)){if(M!==void 0&&v(M))throw new Error("The internal list is malformed.");var J=M===void 0?V.insertTime:m(M)?M.startTime+M.duration:S(M),tt=M===void 0?this._defaultValue:m(M)?M.values[M.values.length-1]:M.value,yt=u(V)?O(k,J,tt,V):D(k,J,tt,V),Y=u(V)?n(yt,k,this._currenTime):s(yt,k,this._currenTime);this._automationEvents.push(Y)}if(M!==void 0&&v(M)&&this._automationEvents.push(a(this.getValue(k),k)),M!==void 0&&m(M)&&M.startTime+M.duration>k){var nt=k-M.startTime;this._automationEvents[this._automationEvents.length-1]=i(T(M.values,M.duration,nt),M.startTime,nt)}}}else{var lt=this._automationEvents.findIndex(function(Lt){return S(Lt)>k}),U=lt===-1?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[lt-1];if(U!==void 0&&m(U)&&S(U)+U.duration>k)return!1;var oe=u(C)?n(C.value,C.endTime,this._currenTime):l(C)?s(C.value,k,this._currenTime):C;if(lt===-1)this._automationEvents.push(oe);else{if(m(C)&&k+C.duration>S(this._automationEvents[lt]))return!1;this._automationEvents.splice(lt,0,oe)}}return!0}},{key:"flush",value:function(C){var k=this._automationEvents.findIndex(function(M){return S(M)>C});if(k>1){var R=this._automationEvents.slice(k-1),V=R[0];v(V)&&R.unshift(a(d(this._automationEvents,k-2,V.startTime,this._defaultValue),V.startTime)),this._automationEvents=R}}},{key:"getValue",value:function(C){if(this._automationEvents.length===0)return this._defaultValue;var k=this._automationEvents.findIndex(function(Lt){return S(Lt)>C}),R=this._automationEvents[k],V=(k===-1?this._automationEvents.length:k)-1,M=this._automationEvents[V];if(M!==void 0&&v(M)&&(R===void 0||!h(R)||R.insertTime>C))return c(C,d(this._automationEvents,V-1,M.startTime,this._defaultValue),M);if(M!==void 0&&p(M)&&(R===void 0||!h(R)))return M.value;if(M!==void 0&&m(M)&&(R===void 0||!h(R)||M.startTime+M.duration>C))return C<M.startTime+M.duration?b(C,M):M.values[M.values.length-1];if(M!==void 0&&h(M)&&(R===void 0||!h(R)))return M.value;if(R!==void 0&&u(R)){var J=f(this._automationEvents,V,M,R,this._defaultValue),tt=t(J,2),yt=tt[0],Y=tt[1];return O(C,yt,Y,R)}if(R!==void 0&&l(R)){var nt=f(this._automationEvents,V,M,R,this._defaultValue),lt=t(nt,2),U=lt[0],oe=lt[1];return D(C,U,oe,R)}return this._defaultValue}}])})(),P=function(w){return{cancelTime:w,type:"cancelAndHold"}},I=function(w){return{cancelTime:w,type:"cancelScheduledValues"}},F=function(w,C){return{endTime:C,type:"exponentialRampToValue",value:w}},B=function(w,C){return{endTime:C,type:"linearRampToValue",value:w}},W=function(w,C,k){return{startTime:C,target:w,timeConstant:k,type:"setTarget"}};o.AutomationEventList=q,o.createCancelAndHoldAutomationEvent=P,o.createCancelScheduledValuesAutomationEvent=I,o.createExponentialRampToValueAutomationEvent=F,o.createLinearRampToValueAutomationEvent=B,o.createSetTargetAutomationEvent=W,o.createSetValueAutomationEvent=a,o.createSetValueCurveAutomationEvent=i}))});var pg={};go(pg,{CUBE_LAYOUT:()=>sn,DEFAULT_FACTORS:()=>ia,DEG:()=>_t,SCALES:()=>Fo,THEMES:()=>Qi,applyMat3:()=>Dp,chroma:()=>Pi,create:()=>om,decodeGains:()=>Mp,decodeMatrix:()=>us,degreeToMidi:()=>is,foaGains:()=>mo,lookMatrix:()=>hs,mapping:()=>Oa,matter:()=>Wa,midiToFreq:()=>xr,midiToNoteName:()=>rn,modular:()=>Ci,parseKey:()=>on,pulse:()=>Xi,rotationMatrix:()=>ls,siteKey:()=>ss,sphereMapping:()=>sa,stepInScale:()=>as,unitVector:()=>Ji,version:()=>lg});var Sr="15.1.22";var re=ja(ks());var nc=()=>new DOMException("","AbortError");var sc=o=>(t,e,[r,n,s],a)=>{o(t[n],[e,r,s],i=>i[0]===e&&i[1]===r,a)};var ic=o=>(t,e,r)=>{let n=[];for(let s=0;s<r.numberOfInputs;s+=1)n.push(new Set);o.set(t,{activeInputs:n,outputs:new Set,passiveInputs:new WeakMap,renderer:e})};var ac=o=>(t,e)=>{o.set(t,{activeInputs:new Set,passiveInputs:new WeakMap,renderer:e})};var Fe=new WeakSet,dn=new WeakMap,Po=new WeakMap,fn=new WeakMap,Ir=new WeakMap,qo=new WeakMap,gn=new WeakMap,Pr=new WeakMap,qr=new WeakMap,Vr=new WeakMap;var cc={construct(){return cc}},uc=o=>{try{let t=new Proxy(o,cc);new t}catch{return!1}return!0};var lc=/^import(?:(?:[\s]+[\w]+|(?:[\s]+[\w]+[\s]*,)?[\s]*\{[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?(?:[\s]*,[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?)*[\s]*}|(?:[\s]+[\w]+[\s]*,)?[\s]*\*[\s]+as[\s]+[\w]+)[\s]+from)?(?:[\s]*)("([^"\\]|\\.)+"|'([^'\\]|\\.)+')(?:[\s]*);?/,Os=(o,t)=>{let e=[],r=o.replace(/^[\s]+/,""),n=r.match(lc);for(;n!==null;){let s=n[1].slice(1,-1),a=n[0].replace(/([\s]+)?;?$/,"").replace(s,new URL(s,t).toString());e.push(a),r=r.slice(n[0].length).replace(/^[\s]+/,""),n=r.match(lc)}return[e.join(";"),r]};var hc=o=>{if(o!==void 0&&!Array.isArray(o))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},pc=o=>{if(!uc(o))throw new TypeError("The given value for processorCtor should be a constructor.");if(o.prototype===null||typeof o.prototype!="object")throw new TypeError("The given value for processorCtor should have a prototype.")},mc=(o,t,e,r,n,s,a,i,c,u,l,h,p)=>{let m=0;return(d,f,g={credentials:"omit"})=>{let y=l.get(d);if(y!==void 0&&y.has(f))return Promise.resolve();let S=u.get(d);if(S!==void 0){let _=S.get(f);if(_!==void 0)return _}let O=s(d),D=O.audioWorklet===void 0?n(f).then(([_,b])=>{let[T,v]=Os(_,b),q=`${T};((a,b)=>{(a[b]=a[b]||[]).push((AudioWorkletProcessor,global,registerProcessor,sampleRate,self,window)=>{${v}
|
|
3
|
+
})})(window,'_AWGS')`;return e(q)}).then(()=>{let _=p._AWGS.pop();if(_===void 0)throw new SyntaxError;r(O.currentTime,O.sampleRate,()=>_(class{},void 0,(b,T)=>{if(b.trim()==="")throw t();let v=qr.get(O);if(v!==void 0){if(v.has(b))throw t();pc(T),hc(T.parameterDescriptors),v.set(b,T)}else pc(T),hc(T.parameterDescriptors),qr.set(O,new Map([[b,T]]))},O.sampleRate,void 0,void 0))}):Promise.all([n(f),Promise.resolve(o(h,h))]).then(([[_,b],T])=>{let v=m+1;m=v;let[q,P]=Os(_,b),W=`${q};((AudioWorkletProcessor,registerProcessor)=>{${P}
|
|
4
|
+
})(${T?"AudioWorkletProcessor":"class extends AudioWorkletProcessor {__b=new WeakSet();constructor(){super();(p=>p.postMessage=(q=>(m,t)=>q.call(p,m,t?t.filter(u=>!this.__b.has(u)):t))(p.postMessage))(this.port)}}"},(n,p)=>registerProcessor(n,class extends p{${T?"":"__c = (a) => a.forEach(e=>this.__b.add(e.buffer));"}process(i,o,p){${T?"":"i.forEach(this.__c);o.forEach(this.__c);this.__c(Object.values(p));"}return super.process(i.map(j=>j.some(k=>k.length===0)?[]:j),o,p)}}));registerProcessor('__sac${v}',class extends AudioWorkletProcessor{process(){return !1}})`,L=new Blob([W],{type:"application/javascript; charset=utf-8"}),w=URL.createObjectURL(L);return O.audioWorklet.addModule(w,g).then(()=>{if(i(O))return O;let C=a(O);return C.audioWorklet.addModule(w,g).then(()=>C)}).then(C=>{if(c===null)throw new SyntaxError;try{new c(C,`__sac${v}`)}catch{throw new SyntaxError}}).finally(()=>URL.revokeObjectURL(w))});return S===void 0?u.set(d,new Map([[f,D]])):S.set(f,D),D.then(()=>{let _=l.get(d);_===void 0?l.set(d,new Set([f])):_.add(f)}).finally(()=>{let _=u.get(d);_!==void 0&&_.delete(f)}),D}};var Mt=(o,t)=>{let e=o.get(t);if(e===void 0)throw new Error("A value with the given key could not be found.");return e};var Ke=(o,t)=>{let e=Array.from(o).filter(t);if(e.length>1)throw Error("More than one element was found.");if(e.length===0)throw Error("No element was found.");let[r]=e;return o.delete(r),r};var _n=(o,t,e,r)=>{let n=Mt(o,t),s=Ke(n,a=>a[0]===e&&a[1]===r);return n.size===0&&o.delete(t),s};var De=o=>Mt(gn,o);var ve=o=>{if(Fe.has(o))throw new Error("The AudioNode is already stored.");Fe.add(o),De(o).forEach(t=>t(!0))};var xn=o=>"port"in o;var Re=o=>{if(!Fe.has(o))throw new Error("The AudioNode is not stored.");Fe.delete(o),De(o).forEach(t=>t(!1))};var Lr=(o,t)=>{!xn(o)&&t.every(e=>e.size===0)&&Re(o)};var dc=(o,t,e,r,n,s,a,i,c,u,l,h,p)=>{let m=new WeakMap;return(d,f,g,y,S)=>{let{activeInputs:O,passiveInputs:D}=s(f),{outputs:_}=s(d),b=i(d),T=v=>{let q=c(f),P=c(d);if(v){let I=_n(D,d,g,y);o(O,d,I,!1),!S&&!h(d)&&e(P,q,g,y),p(f)&&ve(f)}else{let I=r(O,d,g,y);t(D,y,I,!1),!S&&!h(d)&&n(P,q,g,y);let F=a(f);if(F===0)l(f)&&Lr(f,O);else{let B=m.get(f);B!==void 0&&clearTimeout(B),m.set(f,setTimeout(()=>{l(f)&&Lr(f,O)},F*1e3))}}};return u(_,[f,g,y],v=>v[0]===f&&v[1]===g&&v[2]===y,!0)?(b.add(T),l(d)?o(O,d,[g,y,T],!0):t(D,y,[d,g,T],!0),!0):!1}};var fc=o=>(t,e,[r,n,s],a)=>{let i=t.get(r);i===void 0?t.set(r,new Set([[n,e,s]])):o(i,[n,e,s],c=>c[0]===n&&c[1]===e,a)};var gc=o=>(t,e)=>{let r=o(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});e.connect(r).connect(t.destination);let n=()=>{e.removeEventListener("ended",n),e.disconnect(r),r.disconnect()};e.addEventListener("ended",n)};var _c=o=>(t,e)=>{o(t).add(e)};var Em={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},xc=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=n(i),l={...Em,...c},h=r(u,l),p=s(u)?t():null;super(i,!1,h,p),this._nativeAnalyserNode=h}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(i){this._nativeAnalyserNode.fftSize=i}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(i){let c=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=i,!(i>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=c,e()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(i){let c=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=i,!(this._nativeAnalyserNode.maxDecibels>i))throw this._nativeAnalyserNode.minDecibels=c,e()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(i){this._nativeAnalyserNode.smoothingTimeConstant=i}getByteFrequencyData(i){this._nativeAnalyserNode.getByteFrequencyData(i)}getByteTimeDomainData(i){this._nativeAnalyserNode.getByteTimeDomainData(i)}getFloatFrequencyData(i){this._nativeAnalyserNode.getFloatFrequencyData(i)}getFloatTimeDomainData(i){this._nativeAnalyserNode.getFloatTimeDomainData(i)}};var st=(o,t)=>o.context===t;var yc=(o,t,e)=>()=>{let r=new WeakMap,n=async(s,a)=>{let i=t(s);if(!st(i,a)){let u={channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,fftSize:i.fftSize,maxDecibels:i.maxDecibels,minDecibels:i.minDecibels,smoothingTimeConstant:i.smoothingTimeConstant};i=o(a,u)}return r.set(a,i),await e(s,a,i),i};return{render(s,a){let i=r.get(a);return i!==void 0?Promise.resolve(i):n(s,a)}}};var Vo=o=>{try{o.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0};var de=()=>new DOMException("","IndexSizeError");var Lo=o=>{o.getChannelData=(t=>e=>{try{return t.call(o,e)}catch(r){throw r.code===12?de():r}})(o.getChannelData)};var Mm={numberOfChannels:1},vc=(o,t,e,r,n,s,a,i)=>{let c=null;return class bc{constructor(l){if(n===null)throw new Error("Missing the native OfflineAudioContext constructor.");let{length:h,numberOfChannels:p,sampleRate:m}={...Mm,...l};c===null&&(c=new n(1,1,44100));let d=r!==null&&t(s,s)?new r({length:h,numberOfChannels:p,sampleRate:m}):c.createBuffer(p,h,m);if(d.numberOfChannels===0)throw e();return typeof d.copyFromChannel!="function"?(a(d),Lo(d)):t(Vo,()=>Vo(d))||i(d),o.add(d),d}static[Symbol.hasInstance](l){return l!==null&&typeof l=="object"&&Object.getPrototypeOf(l)===bc.prototype||o.has(l)}}};var Nt=-34028234663852886e22,Tt=-Nt;var Zt=o=>Fe.has(o);var Fm={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},wc=(o,t,e,r,n,s,a,i)=>class extends o{constructor(u,l){let h=s(u),p={...Fm,...l},m=n(h,p),d=a(h),f=d?t():null;super(u,!1,m,f),this._audioBufferSourceNodeRenderer=f,this._isBufferNullified=!1,this._isBufferSet=p.buffer!==null,this._nativeAudioBufferSourceNode=m,this._onended=null,this._playbackRate=e(this,d,m.playbackRate,Tt,Nt)}get buffer(){return this._isBufferNullified?null:this._nativeAudioBufferSourceNode.buffer}set buffer(u){if(this._nativeAudioBufferSourceNode.buffer=u,u!==null){if(this._isBufferSet)throw r();this._isBufferSet=!0}}get loop(){return this._nativeAudioBufferSourceNode.loop}set loop(u){this._nativeAudioBufferSourceNode.loop=u}get loopEnd(){return this._nativeAudioBufferSourceNode.loopEnd}set loopEnd(u){this._nativeAudioBufferSourceNode.loopEnd=u}get loopStart(){return this._nativeAudioBufferSourceNode.loopStart}set loopStart(u){this._nativeAudioBufferSourceNode.loopStart=u}get onended(){return this._onended}set onended(u){let l=typeof u=="function"?i(this,u):null;this._nativeAudioBufferSourceNode.onended=l;let h=this._nativeAudioBufferSourceNode.onended;this._onended=h!==null&&h===l?u:h}get playbackRate(){return this._playbackRate}start(u=0,l=0,h){if(this._nativeAudioBufferSourceNode.start(u,l,h),this._audioBufferSourceNodeRenderer!==null&&(this._audioBufferSourceNodeRenderer.start=h===void 0?[u,l]:[u,l,h]),this.context.state!=="closed"){ve(this);let p=()=>{this._nativeAudioBufferSourceNode.removeEventListener("ended",p),Zt(this)&&Re(this)};this._nativeAudioBufferSourceNode.addEventListener("ended",p)}}stop(u=0){this._nativeAudioBufferSourceNode.stop(u),this._audioBufferSourceNodeRenderer!==null&&(this._audioBufferSourceNodeRenderer.stop=u)}};var Tc=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=null,i=null,c=async(u,l)=>{let h=e(u),p=st(h,l);if(!p){let m={buffer:h.buffer,channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,loop:h.loop,loopEnd:h.loopEnd,loopStart:h.loopStart,playbackRate:h.playbackRate.value};h=t(l,m),a!==null&&h.start(...a),i!==null&&h.stop(i)}return s.set(l,h),p?await o(l,u.playbackRate,h.playbackRate):await r(l,u.playbackRate,h.playbackRate),await n(u,l,h),h};return{set start(u){a=u},set stop(u){i=u},render(u,l){let h=s.get(l);return h!==void 0?Promise.resolve(h):c(u,l)}}};var Sc=o=>"playbackRate"in o;var Ac=o=>"frequency"in o&&"gain"in o;var Cc=o=>"offset"in o;var Nc=o=>!("frequency"in o)&&"gain"in o;var kc=o=>"detune"in o&&"frequency"in o&&!("gain"in o);var Oc=o=>"pan"in o;var Rt=o=>Mt(dn,o);var Je=o=>Mt(fn,o);var yn=(o,t)=>{let{activeInputs:e}=Rt(o);e.forEach(n=>n.forEach(([s])=>{t.includes(o)||yn(s,[...t,o])}));let r=Sc(o)?[o.playbackRate]:xn(o)?Array.from(o.parameters.values()):Ac(o)?[o.Q,o.detune,o.frequency,o.gain]:Cc(o)?[o.offset]:Nc(o)?[o.gain]:kc(o)?[o.detune,o.frequency]:Oc(o)?[o.pan]:[];for(let n of r){let s=Je(n);s!==void 0&&s.activeInputs.forEach(([a])=>yn(a,t))}Zt(o)&&Re(o)};var to=o=>{yn(o.destination,[])};var vn=o=>o===void 0||typeof o=="number"||typeof o=="string"&&(o==="balanced"||o==="interactive"||o==="playback");var Ec=(o,t,e,r,n,s,a,i,c)=>class extends o{constructor(l={}){if(c===null)throw new Error("Missing the native AudioContext constructor.");let h;try{h=new c(l)}catch(d){throw d.code===12&&d.message==="sampleRate is not in range"?e():d}if(h===null)throw r();if(!vn(l.latencyHint))throw new TypeError(`The provided value '${l.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(l.sampleRate!==void 0&&h.sampleRate!==l.sampleRate)throw e();super(h,2);let{latencyHint:p}=l,{sampleRate:m}=h;if(this._baseLatency=typeof h.baseLatency=="number"?h.baseLatency:p==="balanced"?512/m:p==="interactive"||p===void 0?256/m:p==="playback"?1024/m:Math.max(2,Math.min(128,Math.round(p*m/128)))*128/m,this._nativeAudioContext=h,c.name==="webkitAudioContext"?(this._nativeGainNode=h.createGain(),this._nativeOscillatorNode=h.createOscillator(),this._nativeGainNode.gain.value=1e-37,this._nativeOscillatorNode.connect(this._nativeGainNode).connect(h.destination),this._nativeOscillatorNode.start()):(this._nativeGainNode=null,this._nativeOscillatorNode=null),this._state=null,h.state==="running"){this._state="suspended";let d=()=>{this._state==="suspended"&&(this._state=null),h.removeEventListener("statechange",d)};h.addEventListener("statechange",d)}}get baseLatency(){return this._baseLatency}get state(){return this._state!==null?this._state:this._nativeAudioContext.state}close(){return this.state==="closed"?this._nativeAudioContext.close().then(()=>{throw t()}):(this._state==="suspended"&&(this._state=null),this._nativeAudioContext.close().then(()=>{this._nativeGainNode!==null&&this._nativeOscillatorNode!==null&&(this._nativeOscillatorNode.stop(),this._nativeGainNode.disconnect(),this._nativeOscillatorNode.disconnect()),to(this)}))}createMediaElementSource(l){return new n(this,{mediaElement:l})}createMediaStreamDestination(){return new s(this)}createMediaStreamSource(l){return new a(this,{mediaStream:l})}createMediaStreamTrackSource(l){return new i(this,{mediaStreamTrack:l})}resume(){return this._state==="suspended"?new Promise((l,h)=>{let p=()=>{this._nativeAudioContext.removeEventListener("statechange",p),this._nativeAudioContext.state==="running"?l():this.resume().then(l,h)};this._nativeAudioContext.addEventListener("statechange",p)}):this._nativeAudioContext.resume().catch(l=>{throw l===void 0||l.code===15?t():l})}suspend(){return this._nativeAudioContext.suspend().catch(l=>{throw l===void 0?t():l})}};var Mc=(o,t,e,r,n,s,a,i)=>class extends o{constructor(u,l){let h=s(u),p=a(h),m=n(h,l,p),d=p?t(i):null;super(u,!1,m,d),this._isNodeOfNativeOfflineAudioContext=p,this._nativeAudioDestinationNode=m}get channelCount(){return this._nativeAudioDestinationNode.channelCount}set channelCount(u){if(this._isNodeOfNativeOfflineAudioContext)throw r();if(u>this._nativeAudioDestinationNode.maxChannelCount)throw e();this._nativeAudioDestinationNode.channelCount=u}get channelCountMode(){return this._nativeAudioDestinationNode.channelCountMode}set channelCountMode(u){if(this._isNodeOfNativeOfflineAudioContext)throw r();this._nativeAudioDestinationNode.channelCountMode=u}get maxChannelCount(){return this._nativeAudioDestinationNode.maxChannelCount}};var Fc=o=>{let t=new WeakMap,e=async(r,n)=>{let s=n.destination;return t.set(n,s),await o(r,n,s),s};return{render(r,n){let s=t.get(n);return s!==void 0?Promise.resolve(s):e(r,n)}}};var Dc=(o,t,e,r,n,s,a,i)=>(c,u)=>{let l=u.listener,h=()=>{let _=new Float32Array(1),b=t(u,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:9}),T=a(u),v=!1,q=[0,0,-1,0,1,0],P=[0,0,0],I=()=>{if(v)return;v=!0;let L=r(u,256,9,0);L.onaudioprocess=({inputBuffer:w})=>{let C=[s(w,_,0),s(w,_,1),s(w,_,2),s(w,_,3),s(w,_,4),s(w,_,5)];C.some((R,V)=>R!==q[V])&&(l.setOrientation(...C),q=C);let k=[s(w,_,6),s(w,_,7),s(w,_,8)];k.some((R,V)=>R!==P[V])&&(l.setPosition(...k),P=k)},b.connect(L)},F=L=>w=>{w!==q[L]&&(q[L]=w,l.setOrientation(...q))},B=L=>w=>{w!==P[L]&&(P[L]=w,l.setPosition(...P))},W=(L,w,C)=>{let k=e(u,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:w});k.connect(b,0,L),k.start(),Object.defineProperty(k.offset,"defaultValue",{get(){return w}});let R=o({context:c},T,k.offset,Tt,Nt);return i(R,"value",V=>()=>V.call(R),V=>M=>{try{V.call(R,M)}catch(J){if(J.code!==9)throw J}I(),T&&C(M)}),R.cancelAndHoldAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.cancelAndHoldAtTime),R.cancelScheduledValues=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.cancelScheduledValues),R.exponentialRampToValueAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.exponentialRampToValueAtTime),R.linearRampToValueAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.linearRampToValueAtTime),R.setTargetAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.setTargetAtTime),R.setValueAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.setValueAtTime),R.setValueCurveAtTime=(V=>T?()=>{throw n()}:(...M)=>{let J=V.apply(R,M);return I(),J})(R.setValueCurveAtTime),R};return{forwardX:W(0,0,F(0)),forwardY:W(1,0,F(1)),forwardZ:W(2,-1,F(2)),positionX:W(6,0,B(0)),positionY:W(7,0,B(1)),positionZ:W(8,0,B(2)),upX:W(3,0,F(3)),upY:W(4,1,F(4)),upZ:W(5,0,F(5))}},{forwardX:p,forwardY:m,forwardZ:d,positionX:f,positionY:g,positionZ:y,upX:S,upY:O,upZ:D}=l.forwardX===void 0?h():l;return{get forwardX(){return p},get forwardY(){return m},get forwardZ(){return d},get positionX(){return f},get positionY(){return g},get positionZ(){return y},get upX(){return S},get upY(){return O},get upZ(){return D}}};var _o=o=>"context"in o;var eo=o=>_o(o[0]);var be=(o,t,e,r)=>{for(let n of o)if(e(n)){if(r)return!1;throw Error("The set contains at least one similar element.")}return o.add(t),!0};var Es=(o,t,[e,r],n)=>{be(o,[t,e,r],s=>s[0]===t&&s[1]===e,n)};var Ms=(o,[t,e,r],n)=>{let s=o.get(t);s===void 0?o.set(t,new Set([[e,r]])):be(s,[e,r],a=>a[0]===e,n)};var fe=o=>"inputs"in o;var Go=(o,t,e,r)=>{if(fe(t)){let n=t.inputs[r];return o.connect(n,e,0),[n,e,0]}return o.connect(t,e,r),[t,e,r]};var Fs=(o,t,e)=>{for(let r of o)if(r[0]===t&&r[1]===e)return o.delete(r),r;return null};var Rc=(o,t,e)=>Ke(o,r=>r[0]===t&&r[1]===e);var Ds=(o,t)=>{if(!De(o).delete(t))throw new Error("Missing the expected event listener.")};var Rs=(o,t,e)=>{let r=Mt(o,t),n=Ke(r,s=>s[0]===e);return r.size===0&&o.delete(t),n};var Wo=(o,t,e,r)=>{fe(t)?o.disconnect(t.inputs[r],e,0):o.disconnect(t,e,r)};var ht=o=>Mt(Po,o);var xo=o=>Mt(Ir,o);var je=o=>Pr.has(o);var Bo=o=>!Fe.has(o);var Is=(o,t)=>new Promise(e=>{if(t!==null)e(!0);else{let r=o.createScriptProcessor(256,1,1),n=o.createGain(),s=o.createBuffer(1,2,44100),a=s.getChannelData(0);a[0]=1,a[1]=1;let i=o.createBufferSource();i.buffer=s,i.loop=!0,i.connect(r).connect(o.destination),i.connect(n),i.disconnect(n),r.onaudioprocess=c=>{let u=c.inputBuffer.getChannelData(0);Array.prototype.some.call(u,l=>l===1)?e(!0):e(!1),i.stop(),r.onaudioprocess=null,i.disconnect(r),r.disconnect(o.destination)},i.start()}});var bn=(o,t)=>{let e=new Map;for(let r of o)for(let n of r){let s=e.get(n);e.set(n,s===void 0?1:s+1)}e.forEach((r,n)=>t(n,r))};var yo=o=>"context"in o;var Ic=o=>{let t=new Map;o.connect=(e=>(r,n=0,s=0)=>{let a=yo(r)?e(r,n,s):e(r,n),i=t.get(r);return i===void 0?t.set(r,[{input:s,output:n}]):i.every(c=>c.input!==s||c.output!==n)&&i.push({input:s,output:n}),a})(o.connect.bind(o)),o.disconnect=(e=>(r,n,s)=>{if(e.apply(o),r===void 0)t.clear();else if(typeof r=="number")for(let[a,i]of t){let c=i.filter(u=>u.output!==r);c.length===0?t.delete(a):t.set(a,c)}else if(t.has(r))if(n===void 0)t.delete(r);else{let a=t.get(r);if(a!==void 0){let i=a.filter(c=>c.output!==n&&(c.input!==s||s===void 0));i.length===0?t.delete(r):t.set(r,i)}}for(let[a,i]of t)i.forEach(c=>{yo(a)?o.connect(a,c.output,c.input):o.connect(a,c.output)})})(o.disconnect)};var Dm=(o,t,e,r)=>{let{activeInputs:n,passiveInputs:s}=Je(t),{outputs:a}=Rt(o),i=De(o),c=u=>{let l=ht(o),h=xo(t);if(u){let p=Rs(s,o,e);Es(n,o,p,!1),!r&&!je(o)&&l.connect(h,e)}else{let p=Rc(n,o,e);Ms(s,p,!1),!r&&!je(o)&&l.disconnect(h,e)}};return be(a,[t,e],u=>u[0]===t&&u[1]===e,!0)?(i.add(c),Zt(o)?Es(n,o,[e,c],!0):Ms(s,[o,e,c],!0),!0):!1},Rm=(o,t,e,r)=>{let{activeInputs:n,passiveInputs:s}=Rt(t),a=Fs(n[r],o,e);return a===null?[_n(s,o,e,r)[2],!1]:[a[2],!0]},Im=(o,t,e)=>{let{activeInputs:r,passiveInputs:n}=Je(t),s=Fs(r,o,e);return s===null?[Rs(n,o,e)[1],!1]:[s[2],!0]},Ps=(o,t,e,r,n)=>{let[s,a]=Rm(o,e,r,n);if(s!==null&&(Ds(o,s),a&&!t&&!je(o)&&Wo(ht(o),ht(e),r,n)),Zt(e)){let{activeInputs:i}=Rt(e);Lr(e,i)}},qs=(o,t,e,r)=>{let[n,s]=Im(o,e,r);n!==null&&(Ds(o,n),s&&!t&&!je(o)&&ht(o).disconnect(xo(e),r))},Pm=(o,t)=>{let e=Rt(o),r=[];for(let n of e.outputs)eo(n)?Ps(o,t,...n):qs(o,t,...n),r.push(n[0]);return e.outputs.clear(),r},qm=(o,t,e)=>{let r=Rt(o),n=[];for(let s of r.outputs)s[1]===e&&(eo(s)?Ps(o,t,...s):qs(o,t,...s),n.push(s[0]),r.outputs.delete(s));return n},Vm=(o,t,e,r,n)=>{let s=Rt(o);return Array.from(s.outputs).filter(a=>a[0]===e&&(r===void 0||a[1]===r)&&(n===void 0||a[2]===n)).map(a=>(eo(a)?Ps(o,t,...a):qs(o,t,...a),s.outputs.delete(a),a[0]))},Pc=(o,t,e,r,n,s,a,i,c,u,l,h,p,m,d,f)=>class extends u{constructor(y,S,O,D){super(O),this._context=y,this._nativeAudioNode=O;let _=l(y);h(_)&&e(Is,()=>Is(_,f))!==!0&&Ic(O),Po.set(this,O),gn.set(this,new Set),y.state!=="closed"&&S&&ve(this),o(this,D,O)}get channelCount(){return this._nativeAudioNode.channelCount}set channelCount(y){this._nativeAudioNode.channelCount=y}get channelCountMode(){return this._nativeAudioNode.channelCountMode}set channelCountMode(y){this._nativeAudioNode.channelCountMode=y}get channelInterpretation(){return this._nativeAudioNode.channelInterpretation}set channelInterpretation(y){this._nativeAudioNode.channelInterpretation=y}get context(){return this._context}get numberOfInputs(){return this._nativeAudioNode.numberOfInputs}get numberOfOutputs(){return this._nativeAudioNode.numberOfOutputs}connect(y,S=0,O=0){if(S<0||S>=this._nativeAudioNode.numberOfOutputs)throw n();let D=l(this._context),_=d(D);if(p(y)||m(y))throw s();if(_o(y)){let v=ht(y);try{let P=Go(this._nativeAudioNode,v,S,O),I=Bo(this);(_||I)&&this._nativeAudioNode.disconnect(...P),this.context.state!=="closed"&&!I&&Bo(y)&&ve(y)}catch(P){throw P.code===12?s():P}if(t(this,y,S,O,_)){let P=c([this],y);bn(P,r(_))}return y}let b=xo(y);if(b.name==="playbackRate"&&b.maxValue===1024)throw a();try{this._nativeAudioNode.connect(b,S),(_||Bo(this))&&this._nativeAudioNode.disconnect(b,S)}catch(v){throw v.code===12?s():v}if(Dm(this,y,S,_)){let v=c([this],y);bn(v,r(_))}}disconnect(y,S,O){let D,_=l(this._context),b=d(_);if(y===void 0)D=Pm(this,b);else if(typeof y=="number"){if(y<0||y>=this.numberOfOutputs)throw n();D=qm(this,b,y)}else{if(S!==void 0&&(S<0||S>=this.numberOfOutputs)||_o(y)&&O!==void 0&&(O<0||O>=y.numberOfInputs))throw n();if(D=Vm(this,b,y,S,O),D.length===0)throw s()}for(let T of D){let v=c([this],T);bn(v,i)}}};var qc=ja(ks()),Vc=(o,t,e,r,n,s,a,i,c,u,l,h,p)=>(m,d,f,g=null,y=null)=>{let S=f.value,O=new qc.AutomationEventList(S),D=d?r(O):null,_={get defaultValue(){return S},get maxValue(){return g===null?f.maxValue:g},get minValue(){return y===null?f.minValue:y},get value(){return f.value},set value(b){f.value=b,_.setValueAtTime(b,m.context.currentTime)},cancelAndHoldAtTime(b){if(typeof f.cancelAndHoldAtTime=="function")D===null&&O.flush(m.context.currentTime),O.add(n(b)),f.cancelAndHoldAtTime(b);else{let T=Array.from(O).pop();D===null&&O.flush(m.context.currentTime),O.add(n(b));let v=Array.from(O).pop();f.cancelScheduledValues(b),T!==v&&v!==void 0&&(v.type==="exponentialRampToValue"?f.exponentialRampToValueAtTime(v.value,v.endTime):v.type==="linearRampToValue"?f.linearRampToValueAtTime(v.value,v.endTime):v.type==="setValue"?f.setValueAtTime(v.value,v.startTime):v.type==="setValueCurve"&&f.setValueCurveAtTime(v.values,v.startTime,v.duration))}return _},cancelScheduledValues(b){return D===null&&O.flush(m.context.currentTime),O.add(s(b)),f.cancelScheduledValues(b),_},exponentialRampToValueAtTime(b,T){if(b===0)throw new RangeError;if(!Number.isFinite(T)||T<0)throw new RangeError;let v=m.context.currentTime;return D===null&&O.flush(v),Array.from(O).length===0&&(O.add(u(S,v)),f.setValueAtTime(S,v)),O.add(a(b,T)),f.exponentialRampToValueAtTime(b,T),_},linearRampToValueAtTime(b,T){let v=m.context.currentTime;return D===null&&O.flush(v),Array.from(O).length===0&&(O.add(u(S,v)),f.setValueAtTime(S,v)),O.add(i(b,T)),f.linearRampToValueAtTime(b,T),_},setTargetAtTime(b,T,v){return D===null&&O.flush(m.context.currentTime),O.add(c(b,T,v)),f.setTargetAtTime(b,T,v),_},setValueAtTime(b,T){return D===null&&O.flush(m.context.currentTime),O.add(u(b,T)),f.setValueAtTime(b,T),_},setValueCurveAtTime(b,T,v){let q=b instanceof Float32Array?b:new Float32Array(b);if(h!==null&&h.name==="webkitAudioContext"){let P=T+v,I=m.context.sampleRate,F=Math.ceil(T*I),B=Math.floor(P*I),W=B-F,L=new Float32Array(W);for(let C=0;C<W;C+=1){let k=(q.length-1)/v*((F+C)/I-T),R=Math.floor(k),V=Math.ceil(k);L[C]=R===V?q[R]:(1-(k-R))*q[R]+(1-(V-k))*q[V]}D===null&&O.flush(m.context.currentTime),O.add(l(L,T,v)),f.setValueCurveAtTime(L,T,v);let w=B/I;w<P&&p(_,L[L.length-1],w),p(_,q[q.length-1],P)}else D===null&&O.flush(m.context.currentTime),O.add(l(q,T,v)),f.setValueCurveAtTime(q,T,v);return _}};return e.set(_,f),t.set(_,m),o(_,D),_};var Lc=o=>({replay(t){for(let e of o)if(e.type==="exponentialRampToValue"){let{endTime:r,value:n}=e;t.exponentialRampToValueAtTime(n,r)}else if(e.type==="linearRampToValue"){let{endTime:r,value:n}=e;t.linearRampToValueAtTime(n,r)}else if(e.type==="setTarget"){let{startTime:r,target:n,timeConstant:s}=e;t.setTargetAtTime(n,r,s)}else if(e.type==="setValue"){let{startTime:r,value:n}=e;t.setValueAtTime(n,r)}else if(e.type==="setValueCurve"){let{duration:r,startTime:n,values:s}=e;t.setValueCurveAtTime(s,n,r)}else throw new Error("Can't apply an unknown automation.")}});var jo=class{constructor(t){this._map=new Map(t)}get size(){return this._map.size}entries(){return this._map.entries()}forEach(t,e=null){return this._map.forEach((r,n)=>t.call(e,r,n,this))}get(t){return this._map.get(t)}has(t){return this._map.has(t)}keys(){return this._map.keys()}values(){return this._map.values()}};var Lm={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:1,numberOfOutputs:1,parameterData:{},processorOptions:{}},Gc=(o,t,e,r,n,s,a,i,c,u,l,h,p,m)=>class extends t{constructor(f,g,y){var S;let O=i(f),D=c(O),_=l({...Lm,...y});p(_);let b=qr.get(O),T=b?.get(g),v=D||O.state!=="closed"?O:(S=a(O))!==null&&S!==void 0?S:O,q=n(v,D?null:f.baseLatency,u,g,T,_),P=D?r(g,_,T):null;super(f,!0,q,P);let I=[];q.parameters.forEach((B,W)=>{let L=e(this,D,B);I.push([W,L])}),this._nativeAudioWorkletNode=q,this._onprocessorerror=null,this._parameters=new jo(I),D&&o(O,this);let{activeInputs:F}=s(this);h(q,F)}get onprocessorerror(){return this._onprocessorerror}set onprocessorerror(f){let g=typeof f=="function"?m(this,f):null;this._nativeAudioWorkletNode.onprocessorerror=g;let y=this._nativeAudioWorkletNode.onprocessorerror;this._onprocessorerror=y!==null&&y===g?f:y}get parameters(){return this._parameters===null?this._nativeAudioWorkletNode.parameters:this._parameters}get port(){return this._nativeAudioWorkletNode.port}};function zo(o,t,e,r,n){if(typeof o.copyFromChannel=="function")t[e].byteLength===0&&(t[e]=new Float32Array(128)),o.copyFromChannel(t[e],r,n);else{let s=o.getChannelData(r);if(t[e].byteLength===0)t[e]=s.slice(n,n+128);else{let a=new Float32Array(s.buffer,n*Float32Array.BYTES_PER_ELEMENT,128);t[e].set(a)}}}var wn=(o,t,e,r,n)=>{typeof o.copyToChannel=="function"?t[e].byteLength!==0&&o.copyToChannel(t[e],r,n):t[e].byteLength!==0&&o.getChannelData(r).set(t[e],n)};var Uo=(o,t)=>{let e=[];for(let r=0;r<o;r+=1){let n=[],s=typeof t=="number"?t:t[r];for(let a=0;a<s;a+=1)n.push(new Float32Array(128));e.push(n)}return e};var Wc=(o,t)=>{let e=Mt(Vr,o),r=ht(t);return Mt(e,r)};var Gm=async(o,t,e,r,n,s,a)=>{let i=t===null?Math.ceil(o.context.length/128)*128:t.length,c=r.channelCount*r.numberOfInputs,u=n.reduce((g,y)=>g+y,0),l=u===0?null:e.createBuffer(u,i,e.sampleRate);if(s===void 0)throw new Error("Missing the processor constructor.");let h=Rt(o),p=await Wc(e,o),m=Uo(r.numberOfInputs,r.channelCount),d=Uo(r.numberOfOutputs,n),f=Array.from(o.parameters.keys()).reduce((g,y)=>({...g,[y]:new Float32Array(128)}),{});for(let g=0;g<i;g+=128){if(r.numberOfInputs>0&&t!==null)for(let y=0;y<r.numberOfInputs;y+=1)for(let S=0;S<r.channelCount;S+=1)zo(t,m[y],S,S,g);s.parameterDescriptors!==void 0&&t!==null&&s.parameterDescriptors.forEach(({name:y},S)=>{zo(t,f,y,c+S,g)});for(let y=0;y<r.numberOfInputs;y+=1)for(let S=0;S<n[y];S+=1)d[y][S].byteLength===0&&(d[y][S]=new Float32Array(128));try{let y=m.map((O,D)=>h.activeInputs[D].size===0?[]:O),S=a(g/e.sampleRate,e.sampleRate,()=>p.process(y,d,f));if(l!==null)for(let O=0,D=0;O<r.numberOfOutputs;O+=1){for(let _=0;_<n[O];_+=1)wn(l,d[O],_,D+_,g);D+=n[O]}if(!S)break}catch(y){o.dispatchEvent(new ErrorEvent("processorerror",{colno:y.colno,filename:y.filename,lineno:y.lineno,message:y.message}));break}}return l},Bc=(o,t,e,r,n,s,a,i,c,u,l,h,p,m,d,f)=>(g,y,S)=>{let O=new WeakMap,D=null,_=async(b,T)=>{let v=l(b),q=null,P=st(v,T),I=Array.isArray(y.outputChannelCount)?y.outputChannelCount:Array.from(y.outputChannelCount);if(h===null){let F=I.reduce((w,C)=>w+C,0),B=n(T,{channelCount:Math.max(1,F),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,F)}),W=[];for(let w=0;w<b.numberOfOutputs;w+=1)W.push(r(T,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:I[w]}));let L=a(T,{channelCount:y.channelCount,channelCountMode:y.channelCountMode,channelInterpretation:y.channelInterpretation,gain:1});L.connect=t.bind(null,W),L.disconnect=c.bind(null,W),q=[B,W,L]}else P||(v=new h(T,g));if(O.set(T,q===null?v:q[2]),q!==null){if(D===null){if(S===void 0)throw new Error("Missing the processor constructor.");if(p===null)throw new Error("Missing the native OfflineAudioContext constructor.");let C=b.channelCount*b.numberOfInputs,k=S.parameterDescriptors===void 0?0:S.parameterDescriptors.length,R=C+k;D=Gm(b,R===0?null:await(async()=>{let M=new p(R,Math.ceil(b.context.length/128)*128,T.sampleRate),J=[],tt=[];for(let nt=0;nt<y.numberOfInputs;nt+=1)J.push(a(M,{channelCount:y.channelCount,channelCountMode:y.channelCountMode,channelInterpretation:y.channelInterpretation,gain:1})),tt.push(n(M,{channelCount:y.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:y.channelCount}));let yt=await Promise.all(Array.from(b.parameters.values()).map(async nt=>{let lt=s(M,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:nt.value});return await m(M,nt,lt.offset),lt})),Y=r(M,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,C+k)});for(let nt=0;nt<y.numberOfInputs;nt+=1){J[nt].connect(tt[nt]);for(let lt=0;lt<y.channelCount;lt+=1)tt[nt].connect(Y,lt,nt*y.channelCount+lt)}for(let[nt,lt]of yt.entries())lt.connect(Y,0,C+nt),lt.start(0);return Y.connect(M.destination),await Promise.all(J.map(nt=>d(b,M,nt))),f(M)})(),T,y,I,S,u)}let F=await D,B=e(T,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),[W,L,w]=q;F!==null&&(B.buffer=F,B.start(0)),B.connect(W);for(let C=0,k=0;C<b.numberOfOutputs;C+=1){let R=L[C];for(let V=0;V<I[C];V+=1)W.connect(R,k+V,V);k+=I[C]}return w}if(P)for(let[F,B]of b.parameters.entries())await o(T,B,v.parameters.get(F));else for(let[F,B]of b.parameters.entries())await m(T,B,v.parameters.get(F));return await d(b,T,v),v};return{render(b,T){i(T,b);let v=O.get(T);return v!==void 0?Promise.resolve(v):_(b,T)}}};var jc=(o,t,e,r,n,s,a,i,c,u,l,h,p,m,d,f,g,y,S,O)=>class extends d{constructor(_,b){super(_,b),this._nativeContext=_,this._audioWorklet=o===void 0?void 0:{addModule:(T,v)=>o(this,T,v)}}get audioWorklet(){return this._audioWorklet}createAnalyser(){return new t(this)}createBiquadFilter(){return new n(this)}createBuffer(_,b,T){return new e({length:b,numberOfChannels:_,sampleRate:T})}createBufferSource(){return new r(this)}createChannelMerger(_=6){return new s(this,{numberOfInputs:_})}createChannelSplitter(_=6){return new a(this,{numberOfOutputs:_})}createConstantSource(){return new i(this)}createConvolver(){return new c(this)}createDelay(_=1){return new l(this,{maxDelayTime:_})}createDynamicsCompressor(){return new h(this)}createGain(){return new p(this)}createIIRFilter(_,b){return new m(this,{feedback:b,feedforward:_})}createOscillator(){return new f(this)}createPanner(){return new g(this)}createPeriodicWave(_,b,T={disableNormalization:!1}){return new y(this,{...T,imag:b,real:_})}createStereoPanner(){return new S(this)}createWaveShaper(){return new O(this)}decodeAudioData(_,b,T){return u(this._nativeContext,_).then(v=>(typeof b=="function"&&b(v),v),v=>{throw typeof T=="function"&&T(v),v})}};var Wm={Q:1,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:350,gain:0,type:"lowpass"},zc=(o,t,e,r,n,s,a,i)=>class extends o{constructor(u,l){let h=s(u),p={...Wm,...l},m=n(h,p),d=a(h),f=d?e():null;super(u,!1,m,f),this._Q=t(this,d,m.Q,Tt,Nt),this._detune=t(this,d,m.detune,1200*Math.log2(Tt),-1200*Math.log2(Tt)),this._frequency=t(this,d,m.frequency,u.sampleRate/2,0),this._gain=t(this,d,m.gain,40*Math.log10(Tt),Nt),this._nativeBiquadFilterNode=m,i(this,1)}get detune(){return this._detune}get frequency(){return this._frequency}get gain(){return this._gain}get Q(){return this._Q}get type(){return this._nativeBiquadFilterNode.type}set type(u){this._nativeBiquadFilterNode.type=u}getFrequencyResponse(u,l,h){try{this._nativeBiquadFilterNode.getFrequencyResponse(u,l,h)}catch(p){throw p.code===11?r():p}if(u.length!==l.length||l.length!==h.length)throw r()}};var Uc=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=async(i,c)=>{let u=e(i),l=st(u,c);if(!l){let h={Q:u.Q.value,channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,detune:u.detune.value,frequency:u.frequency.value,gain:u.gain.value,type:u.type};u=t(c,h)}return s.set(c,u),l?(await o(c,i.Q,u.Q),await o(c,i.detune,u.detune),await o(c,i.frequency,u.frequency),await o(c,i.gain,u.gain)):(await r(c,i.Q,u.Q),await r(c,i.detune,u.detune),await r(c,i.frequency,u.frequency),await r(c,i.gain,u.gain)),await n(i,c,u),u};return{render(i,c){let u=s.get(c);return u!==void 0?Promise.resolve(u):a(i,c)}}};var Hc=(o,t)=>(e,r)=>{let n=t.get(e);if(n!==void 0)return n;let s=o.get(e);if(s!==void 0)return s;try{let a=r();return a instanceof Promise?(o.set(e,a),a.catch(()=>!1).then(i=>(o.delete(e),t.set(e,i),i))):(t.set(e,a),a)}catch{return t.set(e,!1),!1}};var Bm={channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6},$c=(o,t,e,r,n)=>class extends o{constructor(a,i){let c=r(a),u={...Bm,...i},l=e(c,u),h=n(c)?t():null;super(a,!1,l,h)}};var Yc=(o,t,e)=>()=>{let r=new WeakMap,n=async(s,a)=>{let i=t(s);if(!st(i,a)){let u={channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,numberOfInputs:i.numberOfInputs};i=o(a,u)}return r.set(a,i),await e(s,a,i),i};return{render(s,a){let i=r.get(a);return i!==void 0?Promise.resolve(i):n(s,a)}}};var jm={channelCount:6,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:6},Xc=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=r(i),l=s({...jm,...c}),h=e(u,l),p=n(u)?t():null;super(i,!1,h,p)}};var Zc=(o,t,e)=>()=>{let r=new WeakMap,n=async(s,a)=>{let i=t(s);if(!st(i,a)){let u={channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,numberOfOutputs:i.numberOfOutputs};i=o(a,u)}return r.set(a,i),await e(s,a,i),i};return{render(s,a){let i=r.get(a);return i!==void 0?Promise.resolve(i):n(s,a)}}};var Qc=o=>(t,e,r)=>o(e,t,r);var Kc=o=>(t,e,r=0,n=0)=>{let s=t[r];if(s===void 0)throw o();return yo(e)?s.connect(e,0,n):s.connect(e,0)};var Jc=o=>(t,e)=>{let r=o(t,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),n=t.createBuffer(1,2,44100);return r.buffer=n,r.loop=!0,r.connect(e),r.start(),()=>{r.stop(),r.disconnect(e)}};var zm={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",offset:1},tu=(o,t,e,r,n,s,a)=>class extends o{constructor(c,u){let l=n(c),h={...zm,...u},p=r(l,h),m=s(l),d=m?e():null;super(c,!1,p,d),this._constantSourceNodeRenderer=d,this._nativeConstantSourceNode=p,this._offset=t(this,m,p.offset,Tt,Nt),this._onended=null}get offset(){return this._offset}get onended(){return this._onended}set onended(c){let u=typeof c=="function"?a(this,c):null;this._nativeConstantSourceNode.onended=u;let l=this._nativeConstantSourceNode.onended;this._onended=l!==null&&l===u?c:l}start(c=0){if(this._nativeConstantSourceNode.start(c),this._constantSourceNodeRenderer!==null&&(this._constantSourceNodeRenderer.start=c),this.context.state!=="closed"){ve(this);let u=()=>{this._nativeConstantSourceNode.removeEventListener("ended",u),Zt(this)&&Re(this)};this._nativeConstantSourceNode.addEventListener("ended",u)}}stop(c=0){this._nativeConstantSourceNode.stop(c),this._constantSourceNodeRenderer!==null&&(this._constantSourceNodeRenderer.stop=c)}};var eu=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=null,i=null,c=async(u,l)=>{let h=e(u),p=st(h,l);if(!p){let m={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,offset:h.offset.value};h=t(l,m),a!==null&&h.start(a),i!==null&&h.stop(i)}return s.set(l,h),p?await o(l,u.offset,h.offset):await r(l,u.offset,h.offset),await n(u,l,h),h};return{set start(u){a=u},set stop(u){i=u},render(u,l){let h=s.get(l);return h!==void 0?Promise.resolve(h):c(u,l)}}};var ou=o=>t=>(o[0]=t,o[0]);var Um={buffer:null,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",disableNormalization:!1},ru=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=r(i),l={...Um,...c},h=e(u,l),m=n(u)?t():null;super(i,!1,h,m),this._isBufferNullified=!1,this._nativeConvolverNode=h,l.buffer!==null&&s(this,l.buffer.duration)}get buffer(){return this._isBufferNullified?null:this._nativeConvolverNode.buffer}set buffer(i){if(this._nativeConvolverNode.buffer=i,i===null&&this._nativeConvolverNode.buffer!==null){let c=this._nativeConvolverNode.context;this._nativeConvolverNode.buffer=c.createBuffer(1,1,c.sampleRate),this._isBufferNullified=!0,s(this,0)}else this._isBufferNullified=!1,s(this,this._nativeConvolverNode.buffer===null?0:this._nativeConvolverNode.buffer.duration)}get normalize(){return this._nativeConvolverNode.normalize}set normalize(i){this._nativeConvolverNode.normalize=i}};var nu=(o,t,e)=>()=>{let r=new WeakMap,n=async(s,a)=>{let i=t(s);if(!st(i,a)){let u={buffer:i.buffer,channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,disableNormalization:!i.normalize};i=o(a,u)}return r.set(a,i),fe(i)?await e(s,a,i.inputs[0]):await e(s,a,i),i};return{render(s,a){let i=r.get(a);return i!==void 0?Promise.resolve(i):n(s,a)}}};var su=(o,t)=>(e,r,n)=>{if(t===null)throw new Error("Missing the native OfflineAudioContext constructor.");try{return new t(e,r,n)}catch(s){throw s.name==="SyntaxError"?o():s}};var iu=()=>new DOMException("","DataCloneError");var Vs=o=>{let{port1:t,port2:e}=new MessageChannel;return new Promise(r=>{let n=()=>{e.onmessage=null,t.close(),e.close(),r()};e.onmessage=()=>n();try{t.postMessage(o,[o])}catch{}finally{n()}})};var au=(o,t,e,r,n,s,a,i,c,u,l)=>(h,p)=>{let m=a(h)?h:s(h);if(n.has(p)){let d=e();return Promise.reject(d)}try{n.add(p)}catch{}return t(c,()=>c(m))?m.decodeAudioData(p).then(d=>(Vs(p).catch(()=>{}),t(i,()=>i(d))||l(d),o.add(d),d)):new Promise((d,f)=>{let g=async()=>{try{await Vs(p)}catch{}},y=S=>{f(S),g()};try{m.decodeAudioData(p,S=>{typeof S.copyFromChannel!="function"&&(u(S),Lo(S)),o.add(S),g().then(()=>d(S))},S=>{y(S===null?r():S)})}catch(S){y(S)}})};var cu=(o,t,e,r,n,s,a,i)=>(c,u)=>{let l=t.get(c);if(l===void 0)throw new Error("Missing the expected cycle count.");let h=s(c.context),p=i(h);if(l===u){if(t.delete(c),!p&&a(c)){let m=r(c),{outputs:d}=e(c);for(let f of d)if(eo(f)){let g=r(f[0]);o(m,g,f[1],f[2])}else{let g=n(f[0]);m.connect(g,f[1])}}}else t.set(c,l-u)};var Hm={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",delayTime:0,maxDelayTime:1},uu=(o,t,e,r,n,s,a)=>class extends o{constructor(c,u){let l=n(c),h={...Hm,...u},p=r(l,h),m=s(l),d=m?e(h.maxDelayTime):null;super(c,!1,p,d),this._delayTime=t(this,m,p.delayTime),a(this,h.maxDelayTime)}get delayTime(){return this._delayTime}};var lu=(o,t,e,r,n)=>s=>{let a=new WeakMap,i=async(c,u)=>{let l=e(c),h=st(l,u);if(!h){let p={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,delayTime:l.delayTime.value,maxDelayTime:s};l=t(u,p)}return a.set(u,l),h?await o(u,c.delayTime,l.delayTime):await r(u,c.delayTime,l.delayTime),await n(c,u,l),l};return{render(c,u){let l=a.get(u);return l!==void 0?Promise.resolve(l):i(c,u)}}};var hu=o=>(t,e,r,n)=>o(t[n],s=>s[0]===e&&s[1]===r);var pu=o=>(t,e)=>{o(t).delete(e)};var mu=o=>"delayTime"in o;var du=(o,t,e)=>function r(n,s){let a=_o(s)?s:e(o,s);if(mu(a))return[];if(n[0]===a)return[n];if(n.includes(a))return[];let{outputs:i}=t(a);return Array.from(i).map(c=>r([...n,a],c[0])).reduce((c,u)=>c.concat(u),[])};var Tn=(o,t,e)=>{let r=t[e];if(r===void 0)throw o();return r},fu=o=>(t,e=void 0,r=void 0,n=0)=>e===void 0?t.forEach(s=>s.disconnect()):typeof e=="number"?Tn(o,t,e).disconnect():yo(e)?r===void 0?t.forEach(s=>s.disconnect(e)):n===void 0?Tn(o,t,r).disconnect(e,0):Tn(o,t,r).disconnect(e,0,n):r===void 0?t.forEach(s=>s.disconnect(e)):Tn(o,t,r).disconnect(e,0);var $m={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},gu=(o,t,e,r,n,s,a,i)=>class extends o{constructor(u,l){let h=s(u),p={...$m,...l},m=r(h,p),d=a(h),f=d?e():null;super(u,!1,m,f),this._attack=t(this,d,m.attack),this._knee=t(this,d,m.knee),this._nativeDynamicsCompressorNode=m,this._ratio=t(this,d,m.ratio),this._release=t(this,d,m.release),this._threshold=t(this,d,m.threshold),i(this,.006)}get attack(){return this._attack}get channelCount(){return this._nativeDynamicsCompressorNode.channelCount}set channelCount(u){let l=this._nativeDynamicsCompressorNode.channelCount;if(this._nativeDynamicsCompressorNode.channelCount=u,u>2)throw this._nativeDynamicsCompressorNode.channelCount=l,n()}get channelCountMode(){return this._nativeDynamicsCompressorNode.channelCountMode}set channelCountMode(u){let l=this._nativeDynamicsCompressorNode.channelCountMode;if(this._nativeDynamicsCompressorNode.channelCountMode=u,u==="max")throw this._nativeDynamicsCompressorNode.channelCountMode=l,n()}get knee(){return this._knee}get ratio(){return this._ratio}get reduction(){return typeof this._nativeDynamicsCompressorNode.reduction.value=="number"?this._nativeDynamicsCompressorNode.reduction.value:this._nativeDynamicsCompressorNode.reduction}get release(){return this._release}get threshold(){return this._threshold}};var _u=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=async(i,c)=>{let u=e(i),l=st(u,c);if(!l){let h={attack:u.attack.value,channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,knee:u.knee.value,ratio:u.ratio.value,release:u.release.value,threshold:u.threshold.value};u=t(c,h)}return s.set(c,u),l?(await o(c,i.attack,u.attack),await o(c,i.knee,u.knee),await o(c,i.ratio,u.ratio),await o(c,i.release,u.release),await o(c,i.threshold,u.threshold)):(await r(c,i.attack,u.attack),await r(c,i.knee,u.knee),await r(c,i.ratio,u.ratio),await r(c,i.release,u.release),await r(c,i.threshold,u.threshold)),await n(i,c,u),u};return{render(i,c){let u=s.get(c);return u!==void 0?Promise.resolve(u):a(i,c)}}};var xu=()=>new DOMException("","EncodingError");var yu=o=>t=>new Promise((e,r)=>{if(o===null){r(new SyntaxError);return}let n=o.document.head;if(n===null)r(new SyntaxError);else{let s=o.document.createElement("script"),a=new Blob([t],{type:"application/javascript"}),i=URL.createObjectURL(a),c=o.onerror,u=()=>{o.onerror=c,URL.revokeObjectURL(i)};o.onerror=(l,h,p,m,d)=>{if(h===i||h===o.location.href&&p===1&&m===1)return u(),r(d),!1;if(c!==null)return c(l,h,p,m,d)},s.onerror=()=>{u(),r(new SyntaxError)},s.onload=()=>{u(),e()},s.src=i,s.type="module",n.appendChild(s)}});var vu=o=>class{constructor(e){this._nativeEventTarget=e,this._listeners=new WeakMap}addEventListener(e,r,n){if(r!==null){let s=this._listeners.get(r);s===void 0&&(s=o(this,r),typeof r=="function"&&this._listeners.set(r,s)),this._nativeEventTarget.addEventListener(e,s,n)}}dispatchEvent(e){return this._nativeEventTarget.dispatchEvent(e)}removeEventListener(e,r,n){let s=r===null?void 0:this._listeners.get(r);this._nativeEventTarget.removeEventListener(e,s===void 0?null:s,n)}};var bu=o=>(t,e,r)=>{Object.defineProperties(o,{currentFrame:{configurable:!0,get(){return Math.round(t*e)}},currentTime:{configurable:!0,get(){return t}}});try{return r()}finally{o!==null&&(delete o.currentFrame,delete o.currentTime)}};var wu=o=>async t=>{try{let e=await fetch(t);if(e.ok)return[await e.text(),e.url]}catch{}throw o()};var Ym={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},Tu=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=n(i),l={...Ym,...c},h=r(u,l),p=s(u),m=p?e():null;super(i,!1,h,m),this._gain=t(this,p,h.gain,Tt,Nt)}get gain(){return this._gain}};var Su=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=async(i,c)=>{let u=e(i),l=st(u,c);if(!l){let h={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,gain:u.gain.value};u=t(c,h)}return s.set(c,u),l?await o(c,i.gain,u.gain):await r(c,i.gain,u.gain),await n(i,c,u),u};return{render(i,c){let u=s.get(c);return u!==void 0?Promise.resolve(u):a(i,c)}}};var Au=(o,t)=>e=>t(o,e);var Cu=o=>t=>{let e=o(t);if(e.renderer===null)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return e.renderer};var Nu=o=>t=>{var e;return(e=o.get(t))!==null&&e!==void 0?e:0};var ku=o=>t=>{let e=o(t);if(e.renderer===null)throw new Error("Missing the renderer of the given AudioParam in the audio graph.");return e.renderer};var Ou=o=>t=>o.get(t);var ft=()=>new DOMException("","InvalidStateError");var Eu=o=>t=>{let e=o.get(t);if(e===void 0)throw ft();return e};var Mu=(o,t)=>e=>{let r=o.get(e);if(r!==void 0)return r;if(t===null)throw new Error("Missing the native OfflineAudioContext constructor.");return r=new t(1,1,44100),o.set(e,r),r};var Fu=o=>t=>{let e=o.get(t);if(e===void 0)throw new Error("The context has no set of AudioWorkletNodes.");return e};var Ho=()=>new DOMException("","InvalidAccessError");var Du=o=>{o.getFrequencyResponse=(t=>(e,r,n)=>{if(e.length!==r.length||r.length!==n.length)throw Ho();return t.call(o,e,r,n)})(o.getFrequencyResponse)};var Xm={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},Ru=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=r(i),l=n(u),h={...Xm,...c},p=t(u,l?null:i.baseLatency,h),m=l?e(h.feedback,h.feedforward):null;super(i,!1,p,m),Du(p),this._nativeIIRFilterNode=p,s(this,1)}getFrequencyResponse(i,c,u){return this._nativeIIRFilterNode.getFrequencyResponse(i,c,u)}};var Sn=(o,t,e,r,n,s,a,i,c,u,l)=>{let h=u.length,p=i;for(let m=0;m<h;m+=1){let d=e[0]*u[m];for(let f=1;f<n;f+=1){let g=p-f&c-1;d+=e[f]*s[g],d-=o[f]*a[g]}for(let f=n;f<r;f+=1)d+=e[f]*s[p-f&c-1];for(let f=n;f<t;f+=1)d-=o[f]*a[p-f&c-1];s[p]=u[m],a[p]=d,p=p+1&c-1,l[m]=d}return p};var Zm=(o,t,e,r)=>{let n=e instanceof Float64Array?e:new Float64Array(e),s=r instanceof Float64Array?r:new Float64Array(r),a=n.length,i=s.length,c=Math.min(a,i);if(n[0]!==1){for(let d=0;d<a;d+=1)s[d]/=n[0];for(let d=1;d<i;d+=1)n[d]/=n[0]}let u=32,l=new Float32Array(u),h=new Float32Array(u),p=t.createBuffer(o.numberOfChannels,o.length,o.sampleRate),m=o.numberOfChannels;for(let d=0;d<m;d+=1){let f=o.getChannelData(d),g=p.getChannelData(d);l.fill(0),h.fill(0),Sn(n,a,s,i,c,l,h,0,u,f,g)}return p},Iu=(o,t,e,r,n)=>(s,a)=>{let i=new WeakMap,c=null,u=async(l,h)=>{let p=null,m=t(l),d=st(m,h);if(h.createIIRFilter===void 0?p=o(h,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}):d||(m=h.createIIRFilter(a,s)),i.set(h,p===null?m:p),p!==null){if(c===null){if(e===null)throw new Error("Missing the native OfflineAudioContext constructor.");let g=new e(l.context.destination.channelCount,l.context.length,h.sampleRate);c=(async()=>{await r(l,g,g.destination);let y=await n(g);return Zm(y,h,s,a)})()}let f=await c;return p.buffer=f,p.start(0),p}return await r(l,h,m),m};return{render(l,h){let p=i.get(h);return p!==void 0?Promise.resolve(p):u(l,h)}}};var Pu=(o,t,e,r,n,s)=>a=>(i,c)=>{let u=o.get(i);if(u===void 0){if(!a&&s(i)){let l=r(i),{outputs:h}=e(i);for(let p of h)if(eo(p)){let m=r(p[0]);t(l,m,p[1],p[2])}else{let m=n(p[0]);l.disconnect(m,p[1])}}o.set(i,c)}else o.set(i,u+c)};var qu=(o,t)=>e=>{let r=o.get(e);return t(r)||t(e)};var Vu=(o,t)=>e=>o.has(e)||t(e);var Lu=(o,t)=>e=>o.has(e)||t(e);var Gu=(o,t)=>e=>{let r=o.get(e);return t(r)||t(e)};var Wu=o=>t=>o!==null&&t instanceof o;var Bu=o=>t=>o!==null&&typeof o.AudioNode=="function"&&t instanceof o.AudioNode;var ju=o=>t=>o!==null&&typeof o.AudioParam=="function"&&t instanceof o.AudioParam;var zu=(o,t)=>e=>o(e)||t(e);var Uu=o=>t=>o!==null&&t instanceof o;var Hu=o=>o!==null&&o.isSecureContext;var $u=(o,t,e,r)=>class extends o{constructor(s,a){let i=e(s),c=t(i,a);if(r(i))throw TypeError();super(s,!0,c,null),this._nativeMediaElementAudioSourceNode=c}get mediaElement(){return this._nativeMediaElementAudioSourceNode.mediaElement}};var Qm={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers"},Yu=(o,t,e,r)=>class extends o{constructor(s,a){let i=e(s);if(r(i))throw new TypeError;let c={...Qm,...a},u=t(i,c);super(s,!1,u,null),this._nativeMediaStreamAudioDestinationNode=u}get stream(){return this._nativeMediaStreamAudioDestinationNode.stream}};var Xu=(o,t,e,r)=>class extends o{constructor(s,a){let i=e(s),c=t(i,a);if(r(i))throw new TypeError;super(s,!0,c,null),this._nativeMediaStreamAudioSourceNode=c}get mediaStream(){return this._nativeMediaStreamAudioSourceNode.mediaStream}};var Zu=(o,t,e)=>class extends o{constructor(n,s){let a=e(n),i=t(a,s);super(n,!0,i,null)}};var Qu=(o,t,e,r,n)=>class extends r{constructor(a={}){if(n===null)throw new Error("Missing the native AudioContext constructor.");let i;try{i=new n(a)}catch(l){throw l.code===12&&l.message==="sampleRate is not in range"?t():l}if(i===null)throw e();if(!vn(a.latencyHint))throw new TypeError(`The provided value '${a.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(a.sampleRate!==void 0&&i.sampleRate!==a.sampleRate)throw t();super(i,2);let{latencyHint:c}=a,{sampleRate:u}=i;if(this._baseLatency=typeof i.baseLatency=="number"?i.baseLatency:c==="balanced"?512/u:c==="interactive"||c===void 0?256/u:c==="playback"?1024/u:Math.max(2,Math.min(128,Math.round(c*u/128)))*128/u,this._nativeAudioContext=i,n.name==="webkitAudioContext"?(this._nativeGainNode=i.createGain(),this._nativeOscillatorNode=i.createOscillator(),this._nativeGainNode.gain.value=1e-37,this._nativeOscillatorNode.connect(this._nativeGainNode).connect(i.destination),this._nativeOscillatorNode.start()):(this._nativeGainNode=null,this._nativeOscillatorNode=null),this._state=null,i.state==="running"){this._state="suspended";let l=()=>{this._state==="suspended"&&(this._state=null),i.removeEventListener("statechange",l)};i.addEventListener("statechange",l)}}get baseLatency(){return this._baseLatency}get state(){return this._state!==null?this._state:this._nativeAudioContext.state}close(){return this.state==="closed"?this._nativeAudioContext.close().then(()=>{throw o()}):(this._state==="suspended"&&(this._state=null),this._nativeAudioContext.close().then(()=>{this._nativeGainNode!==null&&this._nativeOscillatorNode!==null&&(this._nativeOscillatorNode.stop(),this._nativeGainNode.disconnect(),this._nativeOscillatorNode.disconnect()),to(this)}))}resume(){return this._state==="suspended"?new Promise((a,i)=>{let c=()=>{this._nativeAudioContext.removeEventListener("statechange",c),this._nativeAudioContext.state==="running"?a():this.resume().then(a,i)};this._nativeAudioContext.addEventListener("statechange",c)}):this._nativeAudioContext.resume().catch(a=>{throw a===void 0||a.code===15?o():a})}suspend(){return this._nativeAudioContext.suspend().catch(a=>{throw a===void 0?o():a})}};var Ku=(o,t,e,r,n,s)=>class extends e{constructor(i,c){super(i),this._nativeContext=i,qo.set(this,i),r(i)&&n.set(i,new Set),this._destination=new o(this,c),this._listener=t(this,i),this._onstatechange=null}get currentTime(){return this._nativeContext.currentTime}get destination(){return this._destination}get listener(){return this._listener}get onstatechange(){return this._onstatechange}set onstatechange(i){let c=typeof i=="function"?s(this,i):null;this._nativeContext.onstatechange=c;let u=this._nativeContext.onstatechange;this._onstatechange=u!==null&&u===c?i:u}get sampleRate(){return this._nativeContext.sampleRate}get state(){return this._nativeContext.state}};var we=o=>{let t=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{let e=o.decodeAudioData(t.buffer,()=>{});return e===void 0?!1:(e.catch(()=>{}),!0)}catch{}return!1};var Km={numberOfChannels:1},Ju=(o,t,e,r,n)=>class extends r{constructor(a){let{length:i,numberOfChannels:c,sampleRate:u}={...Km,...a},l=e(c,i,u);o(we,()=>we(l))||l.addEventListener("statechange",(()=>{let h=0,p=m=>{this._state==="running"&&(h>0?(l.removeEventListener("statechange",p),m.stopImmediatePropagation(),this._waitForThePromiseToSettle(m)):h+=1)};return p})()),super(l,c),this._length=i,this._nativeOfflineAudioContext=l,this._state=null}get length(){return this._nativeOfflineAudioContext.length===void 0?this._length:this._nativeOfflineAudioContext.length}get state(){return this._state===null?this._nativeOfflineAudioContext.state:this._state}startRendering(){return this._state==="running"?Promise.reject(t()):(this._state="running",n(this.destination,this._nativeOfflineAudioContext).finally(()=>{this._state=null,to(this)}))}_waitForThePromiseToSettle(a){this._state===null?this._nativeOfflineAudioContext.dispatchEvent(a):setTimeout(()=>this._waitForThePromiseToSettle(a))}};var tl=(o,t)=>(e,r,n)=>{let s=new Set;return e.connect=(a=>(i,c=0,u=0)=>{let l=s.size===0;if(t(i))return a.call(e,i,c,u),o(s,[i,c,u],h=>h[0]===i&&h[1]===c&&h[2]===u,!0),l&&r(),i;a.call(e,i,c),o(s,[i,c],h=>h[0]===i&&h[1]===c,!0),l&&r()})(e.connect),e.disconnect=(a=>(i,c,u)=>{let l=s.size>0;if(i===void 0)a.apply(e),s.clear();else if(typeof i=="number"){a.call(e,i);for(let p of s)p[1]===i&&s.delete(p)}else{t(i)?a.call(e,i,c,u):a.call(e,i,c);for(let p of s)p[0]===i&&(c===void 0||p[1]===c)&&(u===void 0||p[2]===u)&&s.delete(p)}let h=s.size===0;l&&h&&n()})(e.disconnect),e};var it=(o,t,e)=>{let r=t[e];r!==void 0&&r!==o[e]&&(o[e]=r)};var et=(o,t)=>{it(o,t,"channelCount"),it(o,t,"channelCountMode"),it(o,t,"channelInterpretation")};var Ls=o=>typeof o.getFloatTimeDomainData=="function";var el=o=>{o.getFloatTimeDomainData=t=>{let e=new Uint8Array(t.length);o.getByteTimeDomainData(e);let r=Math.max(e.length,o.fftSize);for(let n=0;n<r;n+=1)t[n]=(e[n]-128)*.0078125;return t}};var ol=(o,t)=>(e,r)=>{let n=e.createAnalyser();if(et(n,r),!(r.maxDecibels>r.minDecibels))throw t();return it(n,r,"fftSize"),it(n,r,"maxDecibels"),it(n,r,"minDecibels"),it(n,r,"smoothingTimeConstant"),o(Ls,()=>Ls(n))||el(n),n};var rl=o=>o===null?null:o.hasOwnProperty("AudioBuffer")?o.AudioBuffer:null;var ct=(o,t,e)=>{let r=t[e];r!==void 0&&r!==o[e].value&&(o[e].value=r)};var nl=o=>{o.start=(t=>{let e=!1;return(r=0,n=0,s)=>{if(e)throw ft();t.call(o,r,n,s),e=!0}})(o.start)};var $o=o=>{o.start=(t=>(e=0,r=0,n)=>{if(typeof n=="number"&&n<0||r<0||e<0)throw new RangeError("The parameters can't be negative.");t.call(o,e,r,n)})(o.start)};var Yo=o=>{o.stop=(t=>(e=0)=>{if(e<0)throw new RangeError("The parameter can't be negative.");t.call(o,e)})(o.stop)};var sl=(o,t,e,r,n,s,a,i,c,u,l)=>(h,p)=>{let m=h.createBufferSource();return et(m,p),ct(m,p,"playbackRate"),it(m,p,"buffer"),it(m,p,"loop"),it(m,p,"loopEnd"),it(m,p,"loopStart"),t(e,()=>e(h))||nl(m),t(r,()=>r(h))||c(m),t(n,()=>n(h))||u(m,h),t(s,()=>s(h))||$o(m),t(a,()=>a(h))||l(m,h),t(i,()=>i(h))||Yo(m),o(h,m),m};var il=o=>o===null?null:o.hasOwnProperty("AudioContext")?o.AudioContext:o.hasOwnProperty("webkitAudioContext")?o.webkitAudioContext:null;var al=(o,t)=>(e,r,n)=>{let s=e.destination;if(s.channelCount!==r)try{s.channelCount=r}catch{}n&&s.channelCountMode!=="explicit"&&(s.channelCountMode="explicit"),s.maxChannelCount===0&&Object.defineProperty(s,"maxChannelCount",{value:r});let a=o(e,{channelCount:r,channelCountMode:s.channelCountMode,channelInterpretation:s.channelInterpretation,gain:1});return t(a,"channelCount",i=>()=>i.call(a),i=>c=>{i.call(a,c);try{s.channelCount=c}catch(u){if(c>s.maxChannelCount)throw u}}),t(a,"channelCountMode",i=>()=>i.call(a),i=>c=>{i.call(a,c),s.channelCountMode=c}),t(a,"channelInterpretation",i=>()=>i.call(a),i=>c=>{i.call(a,c),s.channelInterpretation=c}),Object.defineProperty(a,"maxChannelCount",{get:()=>s.maxChannelCount}),a.connect(s),a};var cl=o=>o===null?null:o.hasOwnProperty("AudioWorkletNode")?o.AudioWorkletNode:null;var ul=o=>{let{port1:t}=new MessageChannel;try{t.postMessage(o)}finally{t.close()}};var ll=(o,t,e,r,n)=>(s,a,i,c,u,l)=>{if(i!==null)try{let h=new i(s,c,l),p=new Map,m=null;if(Object.defineProperties(h,{channelCount:{get:()=>l.channelCount,set:()=>{throw o()}},channelCountMode:{get:()=>"explicit",set:()=>{throw o()}},onprocessorerror:{get:()=>m,set:d=>{typeof m=="function"&&h.removeEventListener("processorerror",m),m=typeof d=="function"?d:null,typeof m=="function"&&h.addEventListener("processorerror",m)}}}),h.addEventListener=(d=>(...f)=>{if(f[0]==="processorerror"){let g=typeof f[1]=="function"?f[1]:typeof f[1]=="object"&&f[1]!==null&&typeof f[1].handleEvent=="function"?f[1].handleEvent:null;if(g!==null){let y=p.get(f[1]);y!==void 0?f[1]=y:(f[1]=S=>{S.type==="error"?(Object.defineProperties(S,{type:{value:"processorerror"}}),g(S)):g(new ErrorEvent(f[0],{...S}))},p.set(g,f[1]))}}return d.call(h,"error",f[1],f[2]),d.call(h,...f)})(h.addEventListener),h.removeEventListener=(d=>(...f)=>{if(f[0]==="processorerror"){let g=p.get(f[1]);g!==void 0&&(p.delete(f[1]),f[1]=g)}return d.call(h,"error",f[1],f[2]),d.call(h,f[0],f[1],f[2])})(h.removeEventListener),l.numberOfOutputs!==0){let d=e(s,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return h.connect(d).connect(s.destination),n(h,()=>d.disconnect(),()=>d.connect(s.destination))}return h}catch(h){throw h.code===11?r():h}if(u===void 0)throw r();return ul(l),t(s,a,u,l)};var An=(o,t)=>o===null?512:Math.max(512,Math.min(16384,Math.pow(2,Math.round(Math.log2(o*t)))));var hl=o=>new Promise((t,e)=>{let{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:s})=>{r.close(),n.close(),t(s)},r.onmessageerror=({data:s})=>{r.close(),n.close(),e(s)},n.postMessage(o)});var pl=async(o,t)=>{let e=await hl(t);return new o(e)};var ml=(o,t,e,r)=>{let n=Vr.get(o);n===void 0&&(n=new WeakMap,Vr.set(o,n));let s=pl(e,r);return n.set(t,s),s};var dl=(o,t,e,r,n,s,a,i,c,u,l,h,p)=>(m,d,f,g)=>{if(g.numberOfInputs===0&&g.numberOfOutputs===0)throw c();let y=Array.isArray(g.outputChannelCount)?g.outputChannelCount:Array.from(g.outputChannelCount);if(y.some(z=>z<1))throw c();if(y.length!==g.numberOfOutputs)throw t();if(g.channelCountMode!=="explicit")throw c();let S=g.channelCount*g.numberOfInputs,O=y.reduce((z,Q)=>z+Q,0),D=f.parameterDescriptors===void 0?0:f.parameterDescriptors.length;if(S+D>6||O>6)throw c();let _=new MessageChannel,b=[],T=[];for(let z=0;z<g.numberOfInputs;z+=1)b.push(a(m,{channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation,gain:1})),T.push(n(m,{channelCount:g.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:g.channelCount}));let v=[];if(f.parameterDescriptors!==void 0)for(let{defaultValue:z,maxValue:Q,minValue:Dt,name:vt}of f.parameterDescriptors){let at=s(m,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:g.parameterData[vt]!==void 0?g.parameterData[vt]:z===void 0?0:z});Object.defineProperties(at.offset,{defaultValue:{get:()=>z===void 0?0:z},maxValue:{get:()=>Q===void 0?Tt:Q},minValue:{get:()=>Dt===void 0?Nt:Dt}}),v.push(at)}let q=r(m,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,S+D)}),P=An(d,m.sampleRate),I=i(m,P,S+D,Math.max(1,O)),F=n(m,{channelCount:Math.max(1,O),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,O)}),B=[];for(let z=0;z<g.numberOfOutputs;z+=1)B.push(r(m,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:y[z]}));for(let z=0;z<g.numberOfInputs;z+=1){b[z].connect(T[z]);for(let Q=0;Q<g.channelCount;Q+=1)T[z].connect(q,Q,z*g.channelCount+Q)}let W=new jo(f.parameterDescriptors===void 0?[]:f.parameterDescriptors.map(({name:z},Q)=>{let Dt=v[Q];return Dt.connect(q,0,S+Q),Dt.start(0),[z,Dt.offset]}));q.connect(I);let L=g.channelInterpretation,w=null,C=g.numberOfOutputs===0?[I]:B,k={get bufferSize(){return P},get channelCount(){return g.channelCount},set channelCount(z){throw e()},get channelCountMode(){return g.channelCountMode},set channelCountMode(z){throw e()},get channelInterpretation(){return L},set channelInterpretation(z){for(let Q of b)Q.channelInterpretation=z;L=z},get context(){return I.context},get inputs(){return b},get numberOfInputs(){return g.numberOfInputs},get numberOfOutputs(){return g.numberOfOutputs},get onprocessorerror(){return w},set onprocessorerror(z){typeof w=="function"&&k.removeEventListener("processorerror",w),w=typeof z=="function"?z:null,typeof w=="function"&&k.addEventListener("processorerror",w)},get parameters(){return W},get port(){return _.port2},addEventListener(...z){return I.addEventListener(z[0],z[1],z[2])},connect:o.bind(null,C),disconnect:u.bind(null,C),dispatchEvent(...z){return I.dispatchEvent(z[0])},removeEventListener(...z){return I.removeEventListener(z[0],z[1],z[2])}},R=new Map;_.port1.addEventListener=(z=>(...Q)=>{if(Q[0]==="message"){let Dt=typeof Q[1]=="function"?Q[1]:typeof Q[1]=="object"&&Q[1]!==null&&typeof Q[1].handleEvent=="function"?Q[1].handleEvent:null;if(Dt!==null){let vt=R.get(Q[1]);vt!==void 0?Q[1]=vt:(Q[1]=at=>{l(m.currentTime,m.sampleRate,()=>Dt(at))},R.set(Dt,Q[1]))}}return z.call(_.port1,Q[0],Q[1],Q[2])})(_.port1.addEventListener),_.port1.removeEventListener=(z=>(...Q)=>{if(Q[0]==="message"){let Dt=R.get(Q[1]);Dt!==void 0&&(R.delete(Q[1]),Q[1]=Dt)}return z.call(_.port1,Q[0],Q[1],Q[2])})(_.port1.removeEventListener);let V=null;Object.defineProperty(_.port1,"onmessage",{get:()=>V,set:z=>{typeof V=="function"&&_.port1.removeEventListener("message",V),V=typeof z=="function"?z:null,typeof V=="function"&&(_.port1.addEventListener("message",V),_.port1.start())}}),f.prototype.port=_.port1;let M=null;ml(m,k,f,g).then(z=>M=z);let tt=Uo(g.numberOfInputs,g.channelCount),yt=Uo(g.numberOfOutputs,y),Y=f.parameterDescriptors===void 0?[]:f.parameterDescriptors.reduce((z,{name:Q})=>({...z,[Q]:new Float32Array(128)}),{}),nt=!0,lt=()=>{g.numberOfOutputs>0&&I.disconnect(F);for(let z=0,Q=0;z<g.numberOfOutputs;z+=1){let Dt=B[z];for(let vt=0;vt<y[z];vt+=1)F.disconnect(Dt,Q+vt,vt);Q+=y[z]}},U=new Map;I.onaudioprocess=({inputBuffer:z,outputBuffer:Q})=>{if(M!==null){let Dt=h(k);for(let vt=0;vt<P;vt+=128){for(let at=0;at<g.numberOfInputs;at+=1)for(let wt=0;wt<g.channelCount;wt+=1)zo(z,tt[at],wt,wt,vt);f.parameterDescriptors!==void 0&&f.parameterDescriptors.forEach(({name:at},wt)=>{zo(z,Y,at,S+wt,vt)});for(let at=0;at<g.numberOfInputs;at+=1)for(let wt=0;wt<y[at];wt+=1)yt[at][wt].byteLength===0&&(yt[at][wt]=new Float32Array(128));try{let at=tt.map((pe,Qe)=>{if(Dt[Qe].size>0)return U.set(Qe,P/128),pe;let As=U.get(Qe);return As===void 0?[]:(pe.every(sm=>sm.every(im=>im===0))&&(As===1?U.delete(Qe):U.set(Qe,As-1)),pe)});nt=l(m.currentTime+vt/m.sampleRate,m.sampleRate,()=>M.process(at,yt,Y));for(let pe=0,Qe=0;pe<g.numberOfOutputs;pe+=1){for(let Tr=0;Tr<y[pe];Tr+=1)wn(Q,yt[pe],Tr,Qe+Tr,vt);Qe+=y[pe]}}catch(at){nt=!1,k.dispatchEvent(new ErrorEvent("processorerror",{colno:at.colno,filename:at.filename,lineno:at.lineno,message:at.message}))}if(!nt){for(let at=0;at<g.numberOfInputs;at+=1){b[at].disconnect(T[at]);for(let wt=0;wt<g.channelCount;wt+=1)T[vt].disconnect(q,wt,at*g.channelCount+wt)}if(f.parameterDescriptors!==void 0){let at=f.parameterDescriptors.length;for(let wt=0;wt<at;wt+=1){let pe=v[wt];pe.disconnect(q,0,S+wt),pe.stop()}}q.disconnect(I),I.onaudioprocess=null,oe?lt():Io();break}}}};let oe=!1,Lt=a(m,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0}),Ro=()=>I.connect(Lt).connect(m.destination),Io=()=>{I.disconnect(Lt),Lt.disconnect()},rm=()=>{if(nt){Io(),g.numberOfOutputs>0&&I.connect(F);for(let z=0,Q=0;z<g.numberOfOutputs;z+=1){let Dt=B[z];for(let vt=0;vt<y[z];vt+=1)F.connect(Dt,Q+vt,vt);Q+=y[z]}}oe=!0},nm=()=>{nt&&(Ro(),lt()),oe=!1};return Ro(),p(k,rm,nm)};var Gs=(o,t)=>{let e=o.createBiquadFilter();return et(e,t),ct(e,t,"Q"),ct(e,t,"detune"),ct(e,t,"frequency"),ct(e,t,"gain"),it(e,t,"type"),e};var fl=(o,t)=>(e,r)=>{let n=e.createChannelMerger(r.numberOfInputs);return o!==null&&o.name==="webkitAudioContext"&&t(e,n),et(n,r),n};var gl=o=>{let t=o.numberOfOutputs;Object.defineProperty(o,"channelCount",{get:()=>t,set:e=>{if(e!==t)throw ft()}}),Object.defineProperty(o,"channelCountMode",{get:()=>"explicit",set:e=>{if(e!=="explicit")throw ft()}}),Object.defineProperty(o,"channelInterpretation",{get:()=>"discrete",set:e=>{if(e!=="discrete")throw ft()}})};var Xo=(o,t)=>{let e=o.createChannelSplitter(t.numberOfOutputs);return et(e,t),gl(e),e};var _l=(o,t,e,r,n)=>(s,a)=>{if(s.createConstantSource===void 0)return e(s,a);let i=s.createConstantSource();return et(i,a),ct(i,a,"offset"),t(r,()=>r(s))||$o(i),t(n,()=>n(s))||Yo(i),o(s,i),i};var ge=(o,t)=>(o.connect=t.connect.bind(t),o.disconnect=t.disconnect.bind(t),o);var xl=(o,t,e,r)=>(n,{offset:s,...a})=>{let i=n.createBuffer(1,2,44100),c=t(n,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),u=e(n,{...a,gain:s}),l=i.getChannelData(0);l[0]=1,l[1]=1,c.buffer=i,c.loop=!0;let h={get bufferSize(){},get channelCount(){return u.channelCount},set channelCount(d){u.channelCount=d},get channelCountMode(){return u.channelCountMode},set channelCountMode(d){u.channelCountMode=d},get channelInterpretation(){return u.channelInterpretation},set channelInterpretation(d){u.channelInterpretation=d},get context(){return u.context},get inputs(){return[]},get numberOfInputs(){return c.numberOfInputs},get numberOfOutputs(){return u.numberOfOutputs},get offset(){return u.gain},get onended(){return c.onended},set onended(d){c.onended=d},addEventListener(...d){return c.addEventListener(d[0],d[1],d[2])},dispatchEvent(...d){return c.dispatchEvent(d[0])},removeEventListener(...d){return c.removeEventListener(d[0],d[1],d[2])},start(d=0){c.start.call(c,d)},stop(d=0){c.stop.call(c,d)}},p=()=>c.connect(u),m=()=>c.disconnect(u);return o(n,c),r(ge(h,u),p,m)};var yl=(o,t)=>(e,r)=>{let n=e.createConvolver();if(et(n,r),r.disableNormalization===n.normalize&&(n.normalize=!r.disableNormalization),it(n,r,"buffer"),r.channelCount>2||(t(n,"channelCount",s=>()=>s.call(n),s=>a=>{if(a>2)throw o();return s.call(n,a)}),r.channelCountMode==="max"))throw o();return t(n,"channelCountMode",s=>()=>s.call(n),s=>a=>{if(a==="max")throw o();return s.call(n,a)}),n};var Ws=(o,t)=>{let e=o.createDelay(t.maxDelayTime);return et(e,t),ct(e,t,"delayTime"),e};var vl=o=>(t,e)=>{let r=t.createDynamicsCompressor();if(et(r,e),e.channelCount>2||e.channelCountMode==="max")throw o();return ct(r,e,"attack"),ct(r,e,"knee"),ct(r,e,"ratio"),ct(r,e,"release"),ct(r,e,"threshold"),r};var Qt=(o,t)=>{let e=o.createGain();return et(e,t),ct(e,t,"gain"),e};var bl=o=>(t,e,r)=>{if(t.createIIRFilter===void 0)return o(t,e,r);let n=t.createIIRFilter(r.feedforward,r.feedback);return et(n,r),n};function Jm(o,t){let e=t[0]*t[0]+t[1]*t[1];return[(o[0]*t[0]+o[1]*t[1])/e,(o[1]*t[0]-o[0]*t[1])/e]}function td(o,t){return[o[0]*t[0]-o[1]*t[1],o[0]*t[1]+o[1]*t[0]]}function wl(o,t){let e=[0,0];for(let r=o.length-1;r>=0;r-=1)e=td(e,t),e[0]+=o[r];return e}var Tl=(o,t,e,r)=>(n,s,{channelCount:a,channelCountMode:i,channelInterpretation:c,feedback:u,feedforward:l})=>{let h=An(s,n.sampleRate),p=u instanceof Float64Array?u:new Float64Array(u),m=l instanceof Float64Array?l:new Float64Array(l),d=p.length,f=m.length,g=Math.min(d,f);if(d===0||d>20)throw r();if(p[0]===0)throw t();if(f===0||f>20)throw r();if(m[0]===0)throw t();if(p[0]!==1){for(let v=0;v<f;v+=1)m[v]/=p[0];for(let v=1;v<d;v+=1)p[v]/=p[0]}let y=e(n,h,a,a);y.channelCount=a,y.channelCountMode=i,y.channelInterpretation=c;let S=32,O=[],D=[],_=[];for(let v=0;v<a;v+=1){O.push(0);let q=new Float32Array(S),P=new Float32Array(S);q.fill(0),P.fill(0),D.push(q),_.push(P)}y.onaudioprocess=v=>{let q=v.inputBuffer,P=v.outputBuffer,I=q.numberOfChannels;for(let F=0;F<I;F+=1){let B=q.getChannelData(F),W=P.getChannelData(F);O[F]=Sn(p,d,m,f,g,D[F],_[F],O[F],S,B,W)}};let b=n.sampleRate/2;return ge({get bufferSize(){return h},get channelCount(){return y.channelCount},set channelCount(v){y.channelCount=v},get channelCountMode(){return y.channelCountMode},set channelCountMode(v){y.channelCountMode=v},get channelInterpretation(){return y.channelInterpretation},set channelInterpretation(v){y.channelInterpretation=v},get context(){return y.context},get inputs(){return[y]},get numberOfInputs(){return y.numberOfInputs},get numberOfOutputs(){return y.numberOfOutputs},addEventListener(...v){return y.addEventListener(v[0],v[1],v[2])},dispatchEvent(...v){return y.dispatchEvent(v[0])},getFrequencyResponse(v,q,P){if(v.length!==q.length||q.length!==P.length)throw o();let I=v.length;for(let F=0;F<I;F+=1){let B=-Math.PI*(v[F]/b),W=[Math.cos(B),Math.sin(B)],L=wl(m,W),w=wl(p,W),C=Jm(L,w);q[F]=Math.sqrt(C[0]*C[0]+C[1]*C[1]),P[F]=Math.atan2(C[1],C[0])}},removeEventListener(...v){return y.removeEventListener(v[0],v[1],v[2])}},y)};var Sl=(o,t)=>o.createMediaElementSource(t.mediaElement);var Al=(o,t)=>{let e=o.createMediaStreamDestination();return et(e,t),e.numberOfOutputs===1&&Object.defineProperty(e,"numberOfOutputs",{get:()=>0}),e};var Cl=(o,{mediaStream:t})=>{let e=t.getAudioTracks();e.sort((s,a)=>s.id<a.id?-1:s.id>a.id?1:0);let r=e.slice(0,1),n=o.createMediaStreamSource(new MediaStream(r));return Object.defineProperty(n,"mediaStream",{value:t}),n};var Nl=(o,t)=>(e,{mediaStreamTrack:r})=>{if(typeof e.createMediaStreamTrackSource=="function")return e.createMediaStreamTrackSource(r);let n=new MediaStream([r]),s=e.createMediaStreamSource(n);if(r.kind!=="audio")throw o();if(t(e))throw new TypeError;return s};var kl=o=>o===null?null:o.hasOwnProperty("OfflineAudioContext")?o.OfflineAudioContext:o.hasOwnProperty("webkitOfflineAudioContext")?o.webkitOfflineAudioContext:null;var Ol=(o,t,e,r,n,s)=>(a,i)=>{let c=a.createOscillator();return et(c,i),ct(c,i,"detune"),ct(c,i,"frequency"),i.periodicWave!==void 0?c.setPeriodicWave(i.periodicWave):it(c,i,"type"),t(e,()=>e(a))||$o(c),t(r,()=>r(a))||s(c,a),t(n,()=>n(a))||Yo(c),o(a,c),c};var El=o=>(t,e)=>{let r=t.createPanner();return r.orientationX===void 0?o(t,e):(et(r,e),ct(r,e,"orientationX"),ct(r,e,"orientationY"),ct(r,e,"orientationZ"),ct(r,e,"positionX"),ct(r,e,"positionY"),ct(r,e,"positionZ"),it(r,e,"coneInnerAngle"),it(r,e,"coneOuterAngle"),it(r,e,"coneOuterGain"),it(r,e,"distanceModel"),it(r,e,"maxDistance"),it(r,e,"panningModel"),it(r,e,"refDistance"),it(r,e,"rolloffFactor"),r)};var Ml=(o,t,e,r,n,s,a,i,c,u)=>(l,{coneInnerAngle:h,coneOuterAngle:p,coneOuterGain:m,distanceModel:d,maxDistance:f,orientationX:g,orientationY:y,orientationZ:S,panningModel:O,positionX:D,positionY:_,positionZ:b,refDistance:T,rolloffFactor:v,...q})=>{let P=l.createPanner();if(q.channelCount>2||q.channelCountMode==="max")throw a();et(P,q);let I={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},F=e(l,{...I,channelInterpretation:"speakers",numberOfInputs:6}),B=r(l,{...q,gain:1}),W=r(l,{...I,gain:1}),L=r(l,{...I,gain:0}),w=r(l,{...I,gain:0}),C=r(l,{...I,gain:0}),k=r(l,{...I,gain:0}),R=r(l,{...I,gain:0}),V=n(l,256,6,1),M=s(l,{...I,curve:new Float32Array([1,1]),oversample:"none"}),J=[g,y,S],tt=[D,_,b],yt=new Float32Array(1);V.onaudioprocess=({inputBuffer:U})=>{let oe=[c(U,yt,0),c(U,yt,1),c(U,yt,2)];oe.some((Ro,Io)=>Ro!==J[Io])&&(P.setOrientation(...oe),J=oe);let Lt=[c(U,yt,3),c(U,yt,4),c(U,yt,5)];Lt.some((Ro,Io)=>Ro!==tt[Io])&&(P.setPosition(...Lt),tt=Lt)},Object.defineProperty(L.gain,"defaultValue",{get:()=>0}),Object.defineProperty(w.gain,"defaultValue",{get:()=>0}),Object.defineProperty(C.gain,"defaultValue",{get:()=>0}),Object.defineProperty(k.gain,"defaultValue",{get:()=>0}),Object.defineProperty(R.gain,"defaultValue",{get:()=>0});let Y={get bufferSize(){},get channelCount(){return P.channelCount},set channelCount(U){if(U>2)throw a();B.channelCount=U,P.channelCount=U},get channelCountMode(){return P.channelCountMode},set channelCountMode(U){if(U==="max")throw a();B.channelCountMode=U,P.channelCountMode=U},get channelInterpretation(){return P.channelInterpretation},set channelInterpretation(U){B.channelInterpretation=U,P.channelInterpretation=U},get coneInnerAngle(){return P.coneInnerAngle},set coneInnerAngle(U){P.coneInnerAngle=U},get coneOuterAngle(){return P.coneOuterAngle},set coneOuterAngle(U){P.coneOuterAngle=U},get coneOuterGain(){return P.coneOuterGain},set coneOuterGain(U){if(U<0||U>1)throw t();P.coneOuterGain=U},get context(){return P.context},get distanceModel(){return P.distanceModel},set distanceModel(U){P.distanceModel=U},get inputs(){return[B]},get maxDistance(){return P.maxDistance},set maxDistance(U){if(U<0)throw new RangeError;P.maxDistance=U},get numberOfInputs(){return P.numberOfInputs},get numberOfOutputs(){return P.numberOfOutputs},get orientationX(){return W.gain},get orientationY(){return L.gain},get orientationZ(){return w.gain},get panningModel(){return P.panningModel},set panningModel(U){P.panningModel=U},get positionX(){return C.gain},get positionY(){return k.gain},get positionZ(){return R.gain},get refDistance(){return P.refDistance},set refDistance(U){if(U<0)throw new RangeError;P.refDistance=U},get rolloffFactor(){return P.rolloffFactor},set rolloffFactor(U){if(U<0)throw new RangeError;P.rolloffFactor=U},addEventListener(...U){return B.addEventListener(U[0],U[1],U[2])},dispatchEvent(...U){return B.dispatchEvent(U[0])},removeEventListener(...U){return B.removeEventListener(U[0],U[1],U[2])}};h!==Y.coneInnerAngle&&(Y.coneInnerAngle=h),p!==Y.coneOuterAngle&&(Y.coneOuterAngle=p),m!==Y.coneOuterGain&&(Y.coneOuterGain=m),d!==Y.distanceModel&&(Y.distanceModel=d),f!==Y.maxDistance&&(Y.maxDistance=f),g!==Y.orientationX.value&&(Y.orientationX.value=g),y!==Y.orientationY.value&&(Y.orientationY.value=y),S!==Y.orientationZ.value&&(Y.orientationZ.value=S),O!==Y.panningModel&&(Y.panningModel=O),D!==Y.positionX.value&&(Y.positionX.value=D),_!==Y.positionY.value&&(Y.positionY.value=_),b!==Y.positionZ.value&&(Y.positionZ.value=b),T!==Y.refDistance&&(Y.refDistance=T),v!==Y.rolloffFactor&&(Y.rolloffFactor=v),(J[0]!==1||J[1]!==0||J[2]!==0)&&P.setOrientation(...J),(tt[0]!==0||tt[1]!==0||tt[2]!==0)&&P.setPosition(...tt);let nt=()=>{B.connect(P),o(B,M,0,0),M.connect(W).connect(F,0,0),M.connect(L).connect(F,0,1),M.connect(w).connect(F,0,2),M.connect(C).connect(F,0,3),M.connect(k).connect(F,0,4),M.connect(R).connect(F,0,5),F.connect(V).connect(l.destination)},lt=()=>{B.disconnect(P),i(B,M,0,0),M.disconnect(W),W.disconnect(F),M.disconnect(L),L.disconnect(F),M.disconnect(w),w.disconnect(F),M.disconnect(C),C.disconnect(F),M.disconnect(k),k.disconnect(F),M.disconnect(R),R.disconnect(F),F.disconnect(V),V.disconnect(l.destination)};return u(ge(Y,P),nt,lt)};var Fl=o=>(t,{disableNormalization:e,imag:r,real:n})=>{let s=r instanceof Float32Array?r:new Float32Array(r),a=n instanceof Float32Array?n:new Float32Array(n),i=t.createPeriodicWave(a,s,{disableNormalization:e});if(Array.from(r).length<2)throw o();return i};var Zo=(o,t,e,r)=>o.createScriptProcessor(t,e,r);var Dl=(o,t)=>(e,r)=>{let n=r.channelCountMode;if(n==="clamped-max")throw t();if(e.createStereoPanner===void 0)return o(e,r);let s=e.createStereoPanner();return et(s,r),ct(s,r,"pan"),Object.defineProperty(s,"channelCountMode",{get:()=>n,set:a=>{if(a!==n)throw t()}}),s};var Rl=(o,t,e,r,n,s)=>{let i=new Float32Array([1,1]),c=Math.PI/2,u={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},l={...u,oversample:"none"},h=(d,f,g,y)=>{let S=new Float32Array(16385),O=new Float32Array(16385);for(let q=0;q<16385;q+=1){let P=q/16384*c;S[q]=Math.cos(P),O[q]=Math.sin(P)}let D=e(d,{...u,gain:0}),_=r(d,{...l,curve:S}),b=r(d,{...l,curve:i}),T=e(d,{...u,gain:0}),v=r(d,{...l,curve:O});return{connectGraph(){f.connect(D),f.connect(b.inputs===void 0?b:b.inputs[0]),f.connect(T),b.connect(g),g.connect(_.inputs===void 0?_:_.inputs[0]),g.connect(v.inputs===void 0?v:v.inputs[0]),_.connect(D.gain),v.connect(T.gain),D.connect(y,0,0),T.connect(y,0,1)},disconnectGraph(){f.disconnect(D),f.disconnect(b.inputs===void 0?b:b.inputs[0]),f.disconnect(T),b.disconnect(g),g.disconnect(_.inputs===void 0?_:_.inputs[0]),g.disconnect(v.inputs===void 0?v:v.inputs[0]),_.disconnect(D.gain),v.disconnect(T.gain),D.disconnect(y,0,0),T.disconnect(y,0,1)}}},p=(d,f,g,y)=>{let S=new Float32Array(16385),O=new Float32Array(16385),D=new Float32Array(16385),_=new Float32Array(16385),b=Math.floor(16385/2);for(let C=0;C<16385;C+=1)if(C>b){let k=(C-b)/(16384-b)*c;S[C]=Math.cos(k),O[C]=Math.sin(k),D[C]=0,_[C]=1}else{let k=C/(16384-b)*c;S[C]=1,O[C]=0,D[C]=Math.cos(k),_[C]=Math.sin(k)}let T=t(d,{channelCount:2,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:2}),v=e(d,{...u,gain:0}),q=r(d,{...l,curve:S}),P=e(d,{...u,gain:0}),I=r(d,{...l,curve:O}),F=r(d,{...l,curve:i}),B=e(d,{...u,gain:0}),W=r(d,{...l,curve:D}),L=e(d,{...u,gain:0}),w=r(d,{...l,curve:_});return{connectGraph(){f.connect(T),f.connect(F.inputs===void 0?F:F.inputs[0]),T.connect(v,0),T.connect(P,0),T.connect(B,1),T.connect(L,1),F.connect(g),g.connect(q.inputs===void 0?q:q.inputs[0]),g.connect(I.inputs===void 0?I:I.inputs[0]),g.connect(W.inputs===void 0?W:W.inputs[0]),g.connect(w.inputs===void 0?w:w.inputs[0]),q.connect(v.gain),I.connect(P.gain),W.connect(B.gain),w.connect(L.gain),v.connect(y,0,0),B.connect(y,0,0),P.connect(y,0,1),L.connect(y,0,1)},disconnectGraph(){f.disconnect(T),f.disconnect(F.inputs===void 0?F:F.inputs[0]),T.disconnect(v,0),T.disconnect(P,0),T.disconnect(B,1),T.disconnect(L,1),F.disconnect(g),g.disconnect(q.inputs===void 0?q:q.inputs[0]),g.disconnect(I.inputs===void 0?I:I.inputs[0]),g.disconnect(W.inputs===void 0?W:W.inputs[0]),g.disconnect(w.inputs===void 0?w:w.inputs[0]),q.disconnect(v.gain),I.disconnect(P.gain),W.disconnect(B.gain),w.disconnect(L.gain),v.disconnect(y,0,0),B.disconnect(y,0,0),P.disconnect(y,0,1),L.disconnect(y,0,1)}}},m=(d,f,g,y,S)=>{if(f===1)return h(d,g,y,S);if(f===2)return p(d,g,y,S);throw n()};return(d,{channelCount:f,channelCountMode:g,pan:y,...S})=>{if(g==="max")throw n();let O=o(d,{...S,channelCount:1,channelCountMode:g,numberOfInputs:2}),D=e(d,{...S,channelCount:f,channelCountMode:g,gain:1}),_=e(d,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:y}),{connectGraph:b,disconnectGraph:T}=m(d,f,D,_,O);Object.defineProperty(_.gain,"defaultValue",{get:()=>0}),Object.defineProperty(_.gain,"maxValue",{get:()=>1}),Object.defineProperty(_.gain,"minValue",{get:()=>-1});let v={get bufferSize(){},get channelCount(){return D.channelCount},set channelCount(F){D.channelCount!==F&&(q&&T(),{connectGraph:b,disconnectGraph:T}=m(d,F,D,_,O),q&&b()),D.channelCount=F},get channelCountMode(){return D.channelCountMode},set channelCountMode(F){if(F==="clamped-max"||F==="max")throw n();D.channelCountMode=F},get channelInterpretation(){return D.channelInterpretation},set channelInterpretation(F){D.channelInterpretation=F},get context(){return D.context},get inputs(){return[D]},get numberOfInputs(){return D.numberOfInputs},get numberOfOutputs(){return D.numberOfOutputs},get pan(){return _.gain},addEventListener(...F){return D.addEventListener(F[0],F[1],F[2])},dispatchEvent(...F){return D.dispatchEvent(F[0])},removeEventListener(...F){return D.removeEventListener(F[0],F[1],F[2])}},q=!1,P=()=>{b(),q=!0},I=()=>{T(),q=!1};return s(ge(v,O),P,I)}};var Il=(o,t,e,r,n,s,a)=>(i,c)=>{let u=i.createWaveShaper();if(s!==null&&s.name==="webkitAudioContext"&&i.createGain().gain.automationRate===void 0)return e(i,c);et(u,c);let l=c.curve===null||c.curve instanceof Float32Array?c.curve:new Float32Array(c.curve);if(l!==null&&l.length<2)throw t();it(u,{curve:l},"curve"),it(u,c,"oversample");let h=null,p=!1;return a(u,"curve",f=>()=>f.call(u),f=>g=>(f.call(u,g),p&&(r(g)&&h===null?h=o(i,u):!r(g)&&h!==null&&(h(),h=null)),g)),n(u,()=>{p=!0,r(u.curve)&&(h=o(i,u))},()=>{p=!1,h!==null&&(h(),h=null)})};var Pl=(o,t,e,r,n)=>(s,{curve:a,oversample:i,...c})=>{let u=s.createWaveShaper(),l=s.createWaveShaper();et(u,c),et(l,c);let h=e(s,{...c,gain:1}),p=e(s,{...c,gain:-1}),m=e(s,{...c,gain:1}),d=e(s,{...c,gain:-1}),f=null,g=!1,y=null,S={get bufferSize(){},get channelCount(){return u.channelCount},set channelCount(_){h.channelCount=_,p.channelCount=_,u.channelCount=_,m.channelCount=_,l.channelCount=_,d.channelCount=_},get channelCountMode(){return u.channelCountMode},set channelCountMode(_){h.channelCountMode=_,p.channelCountMode=_,u.channelCountMode=_,m.channelCountMode=_,l.channelCountMode=_,d.channelCountMode=_},get channelInterpretation(){return u.channelInterpretation},set channelInterpretation(_){h.channelInterpretation=_,p.channelInterpretation=_,u.channelInterpretation=_,m.channelInterpretation=_,l.channelInterpretation=_,d.channelInterpretation=_},get context(){return u.context},get curve(){return y},set curve(_){if(_!==null&&_.length<2)throw t();if(_===null)u.curve=_,l.curve=_;else{let b=_.length,T=new Float32Array(b+2-b%2),v=new Float32Array(b+2-b%2);T[0]=_[0],v[0]=-_[b-1];let q=Math.ceil((b+1)/2),P=(b+1)/2-1;for(let I=1;I<q;I+=1){let F=I/q*P,B=Math.floor(F),W=Math.ceil(F);T[I]=B===W?_[B]:(1-(F-B))*_[B]+(1-(W-F))*_[W],v[I]=B===W?-_[b-1-B]:-((1-(F-B))*_[b-1-B])-(1-(W-F))*_[b-1-W]}T[q]=b%2===1?_[q-1]:(_[q-2]+_[q-1])/2,u.curve=T,l.curve=v}y=_,g&&(r(y)&&f===null?f=o(s,h):f!==null&&(f(),f=null))},get inputs(){return[h]},get numberOfInputs(){return u.numberOfInputs},get numberOfOutputs(){return u.numberOfOutputs},get oversample(){return u.oversample},set oversample(_){u.oversample=_,l.oversample=_},addEventListener(..._){return h.addEventListener(_[0],_[1],_[2])},dispatchEvent(..._){return h.dispatchEvent(_[0])},removeEventListener(..._){return h.removeEventListener(_[0],_[1],_[2])}};a!==null&&(S.curve=a instanceof Float32Array?a:new Float32Array(a)),i!==S.oversample&&(S.oversample=i);let O=()=>{h.connect(u).connect(m),h.connect(p).connect(l).connect(d).connect(m),g=!0,r(y)&&(f=o(s,h))},D=()=>{h.disconnect(u),u.disconnect(m),h.disconnect(p),p.disconnect(l),l.disconnect(d),d.disconnect(m),g=!1,f!==null&&(f(),f=null)};return n(ge(S,m),O,D)};var jt=()=>new DOMException("","NotSupportedError");var ed={numberOfChannels:1},ql=(o,t,e,r,n)=>class extends o{constructor(a,i,c){let u;if(typeof a=="number"&&i!==void 0&&c!==void 0)u={length:i,numberOfChannels:a,sampleRate:c};else if(typeof a=="object")u=a;else throw new Error("The given parameters are not valid.");let{length:l,numberOfChannels:h,sampleRate:p}={...ed,...u},m=r(h,l,p);t(we,()=>we(m))||m.addEventListener("statechange",(()=>{let d=0,f=g=>{this._state==="running"&&(d>0?(m.removeEventListener("statechange",f),g.stopImmediatePropagation(),this._waitForThePromiseToSettle(g)):d+=1)};return f})()),super(m,h),this._length=l,this._nativeOfflineAudioContext=m,this._state=null}get length(){return this._nativeOfflineAudioContext.length===void 0?this._length:this._nativeOfflineAudioContext.length}get state(){return this._state===null?this._nativeOfflineAudioContext.state:this._state}startRendering(){return this._state==="running"?Promise.reject(e()):(this._state="running",n(this.destination,this._nativeOfflineAudioContext).finally(()=>{this._state=null,to(this)}))}_waitForThePromiseToSettle(a){this._state===null?this._nativeOfflineAudioContext.dispatchEvent(a):setTimeout(()=>this._waitForThePromiseToSettle(a))}};var od={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,periodicWave:void 0,type:"sine"},Vl=(o,t,e,r,n,s,a)=>class extends o{constructor(c,u){let l=n(c),h={...od,...u},p=e(l,h),m=s(l),d=m?r():null,f=c.sampleRate/2;super(c,!1,p,d),this._detune=t(this,m,p.detune,153600,-153600),this._frequency=t(this,m,p.frequency,f,-f),this._nativeOscillatorNode=p,this._onended=null,this._oscillatorNodeRenderer=d,this._oscillatorNodeRenderer!==null&&h.periodicWave!==void 0&&(this._oscillatorNodeRenderer.periodicWave=h.periodicWave)}get detune(){return this._detune}get frequency(){return this._frequency}get onended(){return this._onended}set onended(c){let u=typeof c=="function"?a(this,c):null;this._nativeOscillatorNode.onended=u;let l=this._nativeOscillatorNode.onended;this._onended=l!==null&&l===u?c:l}get type(){return this._nativeOscillatorNode.type}set type(c){this._nativeOscillatorNode.type=c,this._oscillatorNodeRenderer!==null&&(this._oscillatorNodeRenderer.periodicWave=null)}setPeriodicWave(c){this._nativeOscillatorNode.setPeriodicWave(c),this._oscillatorNodeRenderer!==null&&(this._oscillatorNodeRenderer.periodicWave=c)}start(c=0){if(this._nativeOscillatorNode.start(c),this._oscillatorNodeRenderer!==null&&(this._oscillatorNodeRenderer.start=c),this.context.state!=="closed"){ve(this);let u=()=>{this._nativeOscillatorNode.removeEventListener("ended",u),Zt(this)&&Re(this)};this._nativeOscillatorNode.addEventListener("ended",u)}}stop(c=0){this._nativeOscillatorNode.stop(c),this._oscillatorNodeRenderer!==null&&(this._oscillatorNodeRenderer.stop=c)}};var Ll=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=null,i=null,c=null,u=async(l,h)=>{let p=e(l),m=st(p,h);if(!m){let d={channelCount:p.channelCount,channelCountMode:p.channelCountMode,channelInterpretation:p.channelInterpretation,detune:p.detune.value,frequency:p.frequency.value,periodicWave:a===null?void 0:a,type:p.type};p=t(h,d),i!==null&&p.start(i),c!==null&&p.stop(c)}return s.set(h,p),m?(await o(h,l.detune,p.detune),await o(h,l.frequency,p.frequency)):(await r(h,l.detune,p.detune),await r(h,l.frequency,p.frequency)),await n(l,h,p),p};return{set periodicWave(l){a=l},set start(l){i=l},set stop(l){c=l},render(l,h){let p=s.get(h);return p!==void 0?Promise.resolve(p):u(l,h)}}};var rd={channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:1,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1},Gl=(o,t,e,r,n,s,a)=>class extends o{constructor(c,u){let l=n(c),h={...rd,...u},p=e(l,h),m=s(l),d=m?r():null;super(c,!1,p,d),this._nativePannerNode=p,this._orientationX=t(this,m,p.orientationX,Tt,Nt),this._orientationY=t(this,m,p.orientationY,Tt,Nt),this._orientationZ=t(this,m,p.orientationZ,Tt,Nt),this._positionX=t(this,m,p.positionX,Tt,Nt),this._positionY=t(this,m,p.positionY,Tt,Nt),this._positionZ=t(this,m,p.positionZ,Tt,Nt),a(this,1)}get coneInnerAngle(){return this._nativePannerNode.coneInnerAngle}set coneInnerAngle(c){this._nativePannerNode.coneInnerAngle=c}get coneOuterAngle(){return this._nativePannerNode.coneOuterAngle}set coneOuterAngle(c){this._nativePannerNode.coneOuterAngle=c}get coneOuterGain(){return this._nativePannerNode.coneOuterGain}set coneOuterGain(c){this._nativePannerNode.coneOuterGain=c}get distanceModel(){return this._nativePannerNode.distanceModel}set distanceModel(c){this._nativePannerNode.distanceModel=c}get maxDistance(){return this._nativePannerNode.maxDistance}set maxDistance(c){this._nativePannerNode.maxDistance=c}get orientationX(){return this._orientationX}get orientationY(){return this._orientationY}get orientationZ(){return this._orientationZ}get panningModel(){return this._nativePannerNode.panningModel}set panningModel(c){this._nativePannerNode.panningModel=c}get positionX(){return this._positionX}get positionY(){return this._positionY}get positionZ(){return this._positionZ}get refDistance(){return this._nativePannerNode.refDistance}set refDistance(c){this._nativePannerNode.refDistance=c}get rolloffFactor(){return this._nativePannerNode.rolloffFactor}set rolloffFactor(c){this._nativePannerNode.rolloffFactor=c}};var Wl=(o,t,e,r,n,s,a,i,c,u)=>()=>{let l=new WeakMap,h=null,p=async(m,d)=>{let f=null,g=s(m),y={channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation},S={...y,coneInnerAngle:g.coneInnerAngle,coneOuterAngle:g.coneOuterAngle,coneOuterGain:g.coneOuterGain,distanceModel:g.distanceModel,maxDistance:g.maxDistance,panningModel:g.panningModel,refDistance:g.refDistance,rolloffFactor:g.rolloffFactor},O=st(g,d);if("bufferSize"in g)f=r(d,{...y,gain:1});else if(!O){let D={...S,orientationX:g.orientationX.value,orientationY:g.orientationY.value,orientationZ:g.orientationZ.value,positionX:g.positionX.value,positionY:g.positionY.value,positionZ:g.positionZ.value};g=n(d,D)}if(l.set(d,f===null?g:f),f!==null){if(h===null){if(a===null)throw new Error("Missing the native OfflineAudioContext constructor.");let I=new a(6,m.context.length,d.sampleRate),F=t(I,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6});F.connect(I.destination),h=(async()=>{let B=await Promise.all([m.orientationX,m.orientationY,m.orientationZ,m.positionX,m.positionY,m.positionZ].map(async(W,L)=>{let w=e(I,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:L===0?1:0});return await i(I,W,w.offset),w}));for(let W=0;W<6;W+=1)B[W].connect(F,0,W),B[W].start(0);return u(I)})()}let D=await h,_=r(d,{...y,gain:1});await c(m,d,_);let b=[];for(let I=0;I<D.numberOfChannels;I+=1)b.push(D.getChannelData(I));let T=[b[0][0],b[1][0],b[2][0]],v=[b[3][0],b[4][0],b[5][0]],q=r(d,{...y,gain:1}),P=n(d,{...S,orientationX:T[0],orientationY:T[1],orientationZ:T[2],positionX:v[0],positionY:v[1],positionZ:v[2]});_.connect(q).connect(P.inputs[0]),P.connect(f);for(let I=128;I<D.length;I+=128){let F=[b[0][I],b[1][I],b[2][I]],B=[b[3][I],b[4][I],b[5][I]];if(F.some((W,L)=>W!==T[L])||B.some((W,L)=>W!==v[L])){T=F,v=B;let W=I/d.sampleRate;q.gain.setValueAtTime(0,W),q=r(d,{...y,gain:0}),P=n(d,{...S,orientationX:T[0],orientationY:T[1],orientationZ:T[2],positionX:v[0],positionY:v[1],positionZ:v[2]}),q.gain.setValueAtTime(1,W),_.connect(q).connect(P.inputs[0]),P.connect(f)}}return f}return O?(await o(d,m.orientationX,g.orientationX),await o(d,m.orientationY,g.orientationY),await o(d,m.orientationZ,g.orientationZ),await o(d,m.positionX,g.positionX),await o(d,m.positionY,g.positionY),await o(d,m.positionZ,g.positionZ)):(await i(d,m.orientationX,g.orientationX),await i(d,m.orientationY,g.orientationY),await i(d,m.orientationZ,g.orientationZ),await i(d,m.positionX,g.positionX),await i(d,m.positionY,g.positionY),await i(d,m.positionZ,g.positionZ)),fe(g)?await c(m,d,g.inputs[0]):await c(m,d,g),g};return{render(m,d){let f=l.get(d);return f!==void 0?Promise.resolve(f):p(m,d)}}};var nd={disableNormalization:!1},Bl=(o,t,e,r)=>class jl{constructor(s,a){let i=t(s),c=r({...nd,...a}),u=o(i,c);return e.add(u),u}static[Symbol.hasInstance](s){return s!==null&&typeof s=="object"&&Object.getPrototypeOf(s)===jl.prototype||e.has(s)}};var zl=(o,t)=>(e,r,n)=>(o(r).replay(n),t(r,e,n));var Ul=(o,t,e)=>async(r,n,s)=>{let a=o(r);await Promise.all(a.activeInputs.map((i,c)=>Array.from(i).map(async([u,l])=>{let p=await t(u).render(u,n),m=r.context.destination;!e(u)&&(r!==m||!e(r))&&p.connect(s,l,c)})).reduce((i,c)=>[...i,...c],[]))};var Hl=(o,t,e)=>async(r,n,s)=>{let a=t(r);await Promise.all(Array.from(a.activeInputs).map(async([i,c])=>{let l=await o(i).render(i,n);e(i)||l.connect(s,c)}))};var $l=(o,t,e,r)=>n=>o(we,()=>we(n))?Promise.resolve(o(r,r)).then(s=>{if(!s){let a=e(n,512,0,1);n.oncomplete=()=>{a.onaudioprocess=null,a.disconnect()},a.onaudioprocess=()=>n.currentTime,a.connect(n.destination)}return n.startRendering()}):new Promise(s=>{let a=t(n,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});n.oncomplete=i=>{a.disconnect(),s(i.renderedBuffer)},a.connect(n.destination),n.startRendering()});var Yl=o=>(t,e)=>{o.set(t,e)};var Xl=o=>(t,e)=>o.set(t,e);var Zl=(o,t,e,r,n,s,a,i)=>(c,u)=>e(c).render(c,u).then(()=>Promise.all(Array.from(r(u)).map(l=>e(l).render(l,u)))).then(()=>n(u)).then(l=>(typeof l.copyFromChannel!="function"?(a(l),Lo(l)):t(s,()=>s(l))||i(l),o.add(l),l));var sd={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},Ql=(o,t,e,r,n,s)=>class extends o{constructor(i,c){let u=n(i),l={...sd,...c},h=e(u,l),p=s(u),m=p?r():null;super(i,!1,h,m),this._pan=t(this,p,h.pan)}get pan(){return this._pan}};var Kl=(o,t,e,r,n)=>()=>{let s=new WeakMap,a=async(i,c)=>{let u=e(i),l=st(u,c);if(!l){let h={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,pan:u.pan.value};u=t(c,h)}return s.set(c,u),l?await o(c,i.pan,u.pan):await r(c,i.pan,u.pan),fe(u)?await n(i,c,u.inputs[0]):await n(i,c,u),u};return{render(i,c){let u=s.get(c);return u!==void 0?Promise.resolve(u):a(i,c)}}};var Jl=o=>()=>{if(o===null)return!1;try{new o({length:1,sampleRate:44100})}catch{return!1}return!0};var th=(o,t)=>async()=>{if(o===null)return!0;if(t===null)return!1;let e=new Blob(['class A extends AudioWorkletProcessor{process(i){this.port.postMessage(i,[i[0][0].buffer])}}registerProcessor("a",A)'],{type:"application/javascript; charset=utf-8"}),r=new t(1,128,44100),n=URL.createObjectURL(e),s=!1,a=!1;try{await r.audioWorklet.addModule(n);let i=new o(r,"a",{numberOfOutputs:0}),c=r.createOscillator();i.port.onmessage=()=>s=!0,i.onprocessorerror=()=>a=!0,c.connect(i),c.start(0),await r.startRendering(),await new Promise(u=>setTimeout(u))}catch{}finally{URL.revokeObjectURL(n)}return s&&!a};var eh=(o,t)=>()=>{if(t===null)return Promise.resolve(!1);let e=new t(1,1,44100),r=o(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return new Promise(n=>{e.oncomplete=()=>{r.disconnect(),n(e.currentTime!==0)},e.startRendering()})};var Bs=()=>new DOMException("","UnknownError");var id={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},oh=(o,t,e,r,n,s,a)=>class extends o{constructor(c,u){let l=n(c),h={...id,...u},p=e(l,h),d=s(l)?r():null;super(c,!0,p,d),this._isCurveNullified=!1,this._nativeWaveShaperNode=p,a(this,1)}get curve(){return this._isCurveNullified?null:this._nativeWaveShaperNode.curve}set curve(c){if(c===null)this._isCurveNullified=!0,this._nativeWaveShaperNode.curve=new Float32Array([0,0]);else{if(c.length<2)throw t();this._isCurveNullified=!1,this._nativeWaveShaperNode.curve=c}}get oversample(){return this._nativeWaveShaperNode.oversample}set oversample(c){this._nativeWaveShaperNode.oversample=c}};var rh=(o,t,e)=>()=>{let r=new WeakMap,n=async(s,a)=>{let i=t(s);if(!st(i,a)){let u={channelCount:i.channelCount,channelCountMode:i.channelCountMode,channelInterpretation:i.channelInterpretation,curve:i.curve,oversample:i.oversample};i=o(a,u)}return r.set(a,i),fe(i)?await e(s,a,i.inputs[0]):await e(s,a,i),i};return{render(s,a){let i=r.get(a);return i!==void 0?Promise.resolve(i):n(s,a)}}};var nh=()=>typeof window>"u"?null:window;var sh=(o,t)=>e=>{e.copyFromChannel=(r,n,s=0)=>{let a=o(s),i=o(n);if(i>=e.numberOfChannels)throw t();let c=e.length,u=e.getChannelData(i),l=r.length;for(let h=a<0?-a:0;h+a<c&&h<l;h+=1)r[h]=u[h+a]},e.copyToChannel=(r,n,s=0)=>{let a=o(s),i=o(n);if(i>=e.numberOfChannels)throw t();let c=e.length,u=e.getChannelData(i),l=r.length;for(let h=a<0?-a:0;h+a<c&&h<l;h+=1)u[h+a]=r[h]}};var ih=o=>t=>{t.copyFromChannel=(e=>(r,n,s=0)=>{let a=o(s),i=o(n);if(a<t.length)return e.call(t,r,i,a)})(t.copyFromChannel),t.copyToChannel=(e=>(r,n,s=0)=>{let a=o(s),i=o(n);if(a<t.length)return e.call(t,r,i,a)})(t.copyToChannel)};var ah=o=>(t,e)=>{let r=e.createBuffer(1,1,44100);t.buffer===null&&(t.buffer=r),o(t,"buffer",n=>()=>{let s=n.call(t);return s===r?null:s},n=>s=>n.call(t,s===null?r:s))};var ch=(o,t)=>(e,r)=>{r.channelCount=1,r.channelCountMode="explicit",Object.defineProperty(r,"channelCount",{get:()=>1,set:()=>{throw o()}}),Object.defineProperty(r,"channelCountMode",{get:()=>"explicit",set:()=>{throw o()}});let n=e.createBufferSource();t(r,()=>{let i=r.numberOfInputs;for(let c=0;c<i;c+=1)n.connect(r,0,c)},()=>n.disconnect(r))};var js=(o,t,e)=>o.copyFromChannel===void 0?o.getChannelData(e)[0]:(o.copyFromChannel(t,e),t[0]);var zs=o=>{if(o===null)return!1;let t=o.length;return t%2!==0?o[Math.floor(t/2)]!==0:o[t/2-1]+o[t/2]!==0};var Qo=(o,t,e,r)=>{let n=o;for(;!n.hasOwnProperty(t);)n=Object.getPrototypeOf(n);let{get:s,set:a}=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(o,t,{get:e(s),set:r(a)})};var uh=o=>({...o,outputChannelCount:o.outputChannelCount!==void 0?o.outputChannelCount:o.numberOfInputs===1&&o.numberOfOutputs===1?[o.channelCount]:Array.from({length:o.numberOfOutputs},()=>1)});var lh=o=>({...o,channelCount:o.numberOfOutputs});var hh=o=>{let{imag:t,real:e}=o;return t===void 0?e===void 0?{...o,imag:[0,0],real:[0,0]}:{...o,imag:Array.from(e,()=>0),real:e}:e===void 0?{...o,imag:t,real:Array.from(t,()=>0)}:{...o,imag:t,real:e}};var Us=(o,t,e)=>{try{o.setValueAtTime(t,e)}catch(r){if(r.code!==9)throw r;Us(o,t,e+1e-7)}};var ph=o=>{let t=o.createBufferSource();t.start();try{t.start()}catch{return!0}return!1};var mh=o=>{let t=o.createBufferSource(),e=o.createBuffer(1,1,44100);t.buffer=e;try{t.start(0,1)}catch{return!1}return!0};var dh=o=>{let t=o.createBufferSource();t.start();try{t.stop()}catch{return!1}return!0};var Cn=o=>{let t=o.createOscillator();try{t.start(-1)}catch(e){return e instanceof RangeError}return!1};var Hs=o=>{let t=o.createBuffer(1,1,44100),e=o.createBufferSource();e.buffer=t,e.start(),e.stop();try{return e.stop(),!0}catch{return!1}};var Nn=o=>{let t=o.createOscillator();try{t.stop(-1)}catch(e){return e instanceof RangeError}return!1};var fh=o=>{let{port1:t,port2:e}=new MessageChannel;try{t.postMessage(o)}finally{t.close(),e.close()}};var gh=o=>{o.start=(t=>(e=0,r=0,n)=>{let s=o.buffer,a=s===null?r:Math.min(s.duration,r);s!==null&&a>s.duration-.5/o.context.sampleRate?t.call(o,e,0,0):t.call(o,e,a,n)})(o.start)};var $s=(o,t)=>{let e=t.createGain();o.connect(e);let r=(n=>()=>{n.call(o,e),o.removeEventListener("ended",r)})(o.disconnect);o.addEventListener("ended",r),ge(o,e),o.stop=(n=>{let s=!1;return(a=0)=>{if(s)try{n.call(o,a)}catch{e.gain.setValueAtTime(0,a)}else n.call(o,a),s=!0}})(o.stop)};var vo=(o,t)=>e=>{let r={value:o};return Object.defineProperties(e,{currentTarget:r,target:r}),typeof t=="function"?t.call(o,e):t.handleEvent.call(o,e)};var ad=sc(be),cd=fc(be),ud=hu(Ke),xh=new WeakMap,ld=Nu(xh),_e=Hc(new Map,new WeakMap),Ie=nh(),yh=ol(_e,de),Ys=Cu(Rt),zt=Ul(Rt,Ys,je),hd=yc(yh,ht,zt),mt=Eu(qo),ze=kl(Ie),pt=Uu(ze),vh=new WeakMap,bh=vu(vo),Ko=il(Ie),Xs=Wu(Ko),Zs=Bu(Ie),wh=ju(Ie),Gr=cl(Ie),kt=Pc(ic(dn),dc(ad,cd,Go,ud,Wo,Rt,ld,De,ht,be,Zt,je,Bo),_e,Pu(Pr,Wo,Rt,ht,xo,Zt),de,Ho,jt,cu(Go,Pr,Rt,ht,xo,mt,Zt,pt),du(vh,Rt,Mt),bh,mt,Xs,Zs,wh,pt,Gr),pd=xc(kt,hd,de,yh,mt,pt);var Qs=new WeakSet,_h=rl(Ie),Th=ou(new Uint32Array(1)),Ks=sh(Th,de),Js=ih(Th),ti=vc(Qs,_e,jt,_h,ze,Jl(_h),Ks,Js);var kn=gc(Qt),Sh=Hl(Ys,Je,je),Pe=Qc(Sh),Jo=sl(kn,_e,ph,mh,dh,Cn,Hs,Nn,gh,ah(Qo),$s),qe=zl(ku(Je),Sh),md=Tc(Pe,Jo,ht,qe,zt),Te=Vc(ac(fn),vh,Ir,Lc,re.createCancelAndHoldAutomationEvent,re.createCancelScheduledValuesAutomationEvent,re.createExponentialRampToValueAutomationEvent,re.createLinearRampToValueAutomationEvent,re.createSetTargetAutomationEvent,re.createSetValueAutomationEvent,re.createSetValueCurveAutomationEvent,Ko,Us),dd=wc(kt,md,Te,ft,Jo,mt,pt,vo);var fd=Mc(kt,Fc,de,ft,al(Qt,Qo),mt,pt,zt),gd=Uc(Pe,Gs,ht,qe,zt),bo=Xl(xh),_d=zc(kt,Te,gd,Ho,Gs,mt,pt,bo),oo=tl(be,Zs),xd=ch(ft,oo),ro=fl(Ko,xd),yd=Yc(ro,ht,zt),vd=$c(kt,yd,ro,mt,pt),bd=Zc(Xo,ht,zt),wd=Xc(kt,bd,Xo,mt,pt,lh),Td=xl(kn,Jo,Qt,oo),tr=_l(kn,_e,Td,Cn,Nn),Sd=eu(Pe,tr,ht,qe,zt),Ad=tu(kt,Te,Sd,tr,mt,pt,vo),Ah=yl(jt,Qo),Cd=nu(Ah,ht,zt),Nd=ru(kt,Cd,Ah,mt,pt,bo),kd=lu(Pe,Ws,ht,qe,zt),Od=uu(kt,Te,kd,Ws,mt,pt,bo),Ch=vl(jt),Ed=_u(Pe,Ch,ht,qe,zt),Md=gu(kt,Te,Ed,Ch,jt,mt,pt,bo),Fd=Su(Pe,Qt,ht,qe,zt),Dd=Tu(kt,Te,Fd,Qt,mt,pt),Rd=Tl(Ho,ft,Zo,jt),On=$l(_e,Qt,Zo,eh(Qt,ze)),Id=Iu(Jo,ht,ze,zt,On),Pd=bl(Rd),qd=Ru(kt,Pd,Id,mt,pt,bo),Vd=Dc(Te,ro,tr,Zo,jt,js,pt,Qo),Nh=new WeakMap,ei=Ku(fd,Vd,bh,pt,Nh,vo),kh=Ol(kn,_e,Cn,Hs,Nn,$s),Ld=Ll(Pe,kh,ht,qe,zt),Gd=Vl(kt,Te,kh,Ld,mt,pt,vo),Oh=Jc(Jo),Wd=Pl(Oh,ft,Qt,zs,oo),En=Il(Oh,ft,Wd,zs,oo,Ko,Qo),Bd=Ml(Go,ft,ro,Qt,Zo,En,jt,Wo,js,oo),Eh=El(Bd),jd=Wl(Pe,ro,tr,Qt,Eh,ht,ze,qe,zt,On),zd=Gl(kt,Te,Eh,jd,mt,pt,bo),Ud=Fl(de),Hd=Bl(Ud,mt,new WeakSet,hh),$d=Rl(ro,Xo,Qt,En,jt,oo),Mh=Dl($d,jt),Yd=Kl(Pe,Mh,ht,qe,zt),Xd=Ql(kt,Te,Mh,Yd,mt,pt),Zd=rh(En,ht,zt),Qd=oh(kt,ft,En,Zd,mt,pt,bo),Fh=Hu(Ie),oi=bu(Ie),Dh=new WeakMap,Kd=Mu(Dh,ze),Jd=Fh?mc(_e,jt,yu(Ie),oi,wu(nc),mt,Kd,pt,Gr,new WeakMap,new WeakMap,th(Gr,ze),Ie):void 0,tf=zu(Xs,pt),ef=au(Qs,_e,iu,xu,new WeakSet,mt,tf,Vo,we,Ks,Js),Rh=jc(Jd,pd,ti,dd,_d,vd,wd,Ad,Nd,ef,Od,Md,Dd,qd,ei,Gd,zd,Hd,Xd,Qd),of=$u(kt,Sl,mt,pt),rf=Yu(kt,Al,mt,pt),nf=Xu(kt,Cl,mt,pt),sf=Nl(ft,pt),af=Zu(kt,sf,mt),Ih=Ec(Rh,ft,jt,Bs,of,rf,nf,af,Ko);var ri=Fu(Nh),cf=_c(ri),Ph=Kc(de),uf=pu(ri),qh=fu(de),Vh=new WeakMap,lf=Au(Vh,Mt),hf=dl(Ph,de,ft,ro,Xo,tr,Qt,Zo,jt,qh,oi,lf,oo),pf=ll(ft,hf,Qt,jt,oo),mf=Bc(Pe,Ph,Jo,ro,Xo,tr,Qt,uf,qh,oi,ht,Gr,ze,qe,zt,On),df=Ou(Dh),ff=Yl(Vh),ni=Fh?Gc(cf,kt,Te,mf,pf,Rt,df,mt,pt,Gr,uh,ff,fh,vo):void 0;var OP=Qu(ft,jt,Bs,ei,Ko);var Lh=su(jt,ze),Gh=Zl(Qs,_e,Ys,ri,On,Vo,Ks,Js),EP=Ju(_e,ft,Lh,ei,Gh);var Wh=ql(Rh,_e,ft,Lh,Gh);var Bh=qu(qo,Xs),jh=Vu(Po,Zs),zh=Lu(Ir,wh),Uh=Gu(qo,pt);function Ot(o){return o===void 0}function Z(o){return o!==void 0}function Hh(o){return typeof o=="function"}function Gt(o){return typeof o=="number"}function Se(o){return Object.prototype.toString.call(o)==="[object Object]"&&o.constructor===Object}function Mn(o){return typeof o=="boolean"}function Et(o){return Array.isArray(o)}function Ut(o){return typeof o=="string"}function Wr(o){return Ut(o)&&/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i.test(o)}function j(o,t){if(!o)throw new Error(t)}function St(o,t,e=1/0){if(!(t<=o&&o<=e))throw new RangeError(`Value must be within [${t}, ${e}], got: ${o}`)}function Fn(o){!o.isOffline&&o.state!=="running"&&er('The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.')}var Yh=!1,$h=!1;function si(o){Yh=o}function Xh(o){Ot(o)&&Yh&&!$h&&($h=!0,er("Events scheduled inside of scheduled callbacks should use the passed in scheduling time. See https://github.com/Tonejs/Tone.js/wiki/Accurate-Timing"))}var Zh=console;function Qh(...o){Zh.log(...o)}function er(...o){Zh.warn(...o)}function Kh(o){return new Ih(o)}function Jh(o,t,e){return new Wh(o,t,e)}var Ht=typeof self=="object"?self:null,tp=Ht&&(Ht.hasOwnProperty("AudioContext")||Ht.hasOwnProperty("webkitAudioContext"));function ep(o,t,e){return j(Z(ni),"AudioWorkletNode only works in a secure context (https or localhost)"),new(o instanceof Ht?.BaseAudioContext?Ht?.AudioWorkletNode:ni)(o,t,e)}function $t(o,t,e,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(o,t,e,r);else for(var i=o.length-1;i>=0;i--)(a=o[i])&&(s=(n<3?a(s):n>3?a(t,e,s):a(t,e))||s);return n>3&&s&&Object.defineProperty(t,e,s),s}function ot(o,t,e,r){function n(s){return s instanceof e?s:new e(function(a){a(s)})}return new(e||(e=Promise))(function(s,a){function i(l){try{u(r.next(l))}catch(h){a(h)}}function c(l){try{u(r.throw(l))}catch(h){a(h)}}function u(l){l.done?s(l.value):n(l.value).then(i,c)}u((r=r.apply(o,t||[])).next())})}var Dn=class{constructor(t,e,r,n){this._callback=t,this._type=e,this._minimumUpdateInterval=Math.max(128/(n||44100),.001),this.updateInterval=r,this._createClock()}_createWorker(){let t=new Blob([`
|
|
5
|
+
// the initial timeout time
|
|
6
|
+
let timeoutTime = ${(this._updateInterval*1e3).toFixed(1)};
|
|
7
|
+
// onmessage callback
|
|
8
|
+
self.onmessage = function(msg){
|
|
9
|
+
timeoutTime = parseInt(msg.data);
|
|
10
|
+
};
|
|
11
|
+
// the tick function which posts a message
|
|
12
|
+
// and schedules a new tick
|
|
13
|
+
function tick(){
|
|
14
|
+
setTimeout(tick, timeoutTime);
|
|
15
|
+
self.postMessage('tick');
|
|
16
|
+
}
|
|
17
|
+
// call tick initially
|
|
18
|
+
tick();
|
|
19
|
+
`],{type:"text/javascript"}),e=URL.createObjectURL(t),r=new Worker(e);r.onmessage=this._callback.bind(this),this._worker=r}_createTimeout(){this._timeout=setTimeout(()=>{this._createTimeout(),this._callback()},this._updateInterval*1e3)}_createClock(){if(this._type==="worker")try{this._createWorker()}catch{this._type="timeout",this._createClock()}else this._type==="timeout"&&this._createTimeout()}_disposeClock(){this._timeout&&clearTimeout(this._timeout),this._worker&&(this._worker.terminate(),this._worker.onmessage=null)}get updateInterval(){return this._updateInterval}set updateInterval(t){var e;this._updateInterval=Math.max(t,this._minimumUpdateInterval),this._type==="worker"&&((e=this._worker)===null||e===void 0||e.postMessage(this._updateInterval*1e3))}get type(){return this._type}set type(t){this._disposeClock(),this._type=t,this._createClock()}dispose(){this._disposeClock()}};function Ae(o){return zh(o)}function Ve(o){return jh(o)}function or(o){return Uh(o)}function no(o){return Bh(o)}function op(o){return o instanceof ti}function xf(o,t){return o==="value"||Ae(t)||Ve(t)||op(t)}function xe(o,...t){if(!t.length)return o;let e=t.shift();if(Se(o)&&Se(e))for(let r in e)xf(r,e[r])?o[r]=e[r]:Se(e[r])?(o[r]||Object.assign(o,{[r]:{}}),xe(o[r],e[r])):Object.assign(o,{[r]:e[r]});return xe(o,...t)}function rp(o,t){return o.length===t.length&&o.every((e,r)=>t[r]===e)}function x(o,t,e=[],r){let n={},s=Array.from(t);if(Se(s[0])&&r&&!Reflect.has(s[0],r)&&(Object.keys(s[0]).some(i=>Reflect.has(o,i))||(xe(n,{[r]:s[0]}),e.splice(e.indexOf(r),1),s.shift())),s.length===1&&Se(s[0]))xe(n,s[0]);else for(let a=0;a<e.length;a++)Z(s[a])&&(n[e[a]]=s[a]);return xe(o,n)}function np(o){return o.constructor.getDefaults()}function ne(o,t){return Ot(o)?t:o}function Yt(o,t){return t.forEach(e=>{Reflect.has(o,e)&&delete o[e]}),o}var It=class{constructor(){this.debug=!1,this._wasDisposed=!1}static getDefaults(){return{}}log(...t){(this.debug||Ht&&this.toString()===Ht.TONE_DEBUG_CLASS)&&Qh(this,...t)}dispose(){return this._wasDisposed=!0,this}get disposed(){return this._wasDisposed}toString(){return this.name}};It.version=Sr;function Ue(o,t){return o>t+1e-6}function Br(o,t){return Ue(o,t)||Kt(o,t)}function wo(o,t){return o+1e-6<t}function Kt(o,t){return Math.abs(o-t)<1e-6}function ii(o,t,e){return Math.max(Math.min(o,e),t)}var Ft=class o extends It{constructor(){super(),this.name="Timeline",this._timeline=[];let t=x(o.getDefaults(),arguments,["memory"]);this.memory=t.memory,this.increasing=t.increasing}static getDefaults(){return{memory:1/0,increasing:!1}}get length(){return this._timeline.length}add(t){if(j(Reflect.has(t,"time"),"Timeline: events must have a time attribute"),t.time=t.time.valueOf(),this.increasing&&this.length){let e=this._timeline[this.length-1];j(Br(t.time,e.time),"The time must be greater than or equal to the last scheduled time"),this._timeline.push(t)}else{let e=this._search(t.time);this._timeline.splice(e+1,0,t)}if(this.length>this.memory){let e=this.length-this.memory;this._timeline.splice(0,e)}return this}remove(t){let e=this._timeline.indexOf(t);return e!==-1&&this._timeline.splice(e,1),this}get(t,e="time"){let r=this._search(t,e);return r!==-1?this._timeline[r]:null}peek(){return this._timeline[0]}shift(){return this._timeline.shift()}getAfter(t,e="time"){let r=this._search(t,e);return r+1<this._timeline.length?this._timeline[r+1]:null}getBefore(t){let e=this._timeline.length;if(e>0&&this._timeline[e-1].time<t)return this._timeline[e-1];let r=this._search(t);return r-1>=0?this._timeline[r-1]:null}cancel(t){if(this._timeline.length>1){let e=this._search(t);if(e>=0)if(Kt(this._timeline[e].time,t)){for(let r=e;r>=0&&Kt(this._timeline[r].time,t);r--)e=r;this._timeline=this._timeline.slice(0,e)}else this._timeline=this._timeline.slice(0,e+1);else this._timeline=[]}else this._timeline.length===1&&Br(this._timeline[0].time,t)&&(this._timeline=[]);return this}cancelBefore(t){let e=this._search(t);return e>=0&&(this._timeline=this._timeline.slice(e+1)),this}previousEvent(t){let e=this._timeline.indexOf(t);return e>0?this._timeline[e-1]:null}_search(t,e="time"){if(this._timeline.length===0)return-1;let r=0,n=this._timeline.length,s=n;if(n>0&&this._timeline[n-1][e]<=t)return n-1;for(;r<s;){let a=Math.floor(r+(s-r)/2),i=this._timeline[a],c=this._timeline[a+1];if(Kt(i[e],t)){for(let u=a;u<this._timeline.length;u++){let l=this._timeline[u];if(Kt(l[e],t))a=u;else break}return a}else{if(wo(i[e],t)&&Ue(c[e],t))return a;Ue(i[e],t)?s=a:r=a+1}}return-1}_iterate(t,e=0,r=this._timeline.length-1){this._timeline.slice(e,r+1).forEach(t)}forEach(t){return this._iterate(t),this}forEachBefore(t,e){let r=this._search(t);return r!==-1&&this._iterate(e,0,r),this}forEachAfter(t,e){let r=this._search(t);return this._iterate(e,r+1),this}forEachBetween(t,e,r){let n=this._search(t),s=this._search(e);return n!==-1&&s!==-1?(this._timeline[n].time!==t&&(n+=1),this._timeline[s].time===e&&(s-=1),this._iterate(r,n,s)):n===-1&&this._iterate(r,0,s),this}forEachFrom(t,e){let r=this._search(t);for(;r>=0&&this._timeline[r].time>=t;)r--;return this._iterate(e,r+1),this}forEachAtTime(t,e){let r=this._search(t);if(r!==-1&&Kt(this._timeline[r].time,t)){let n=r;for(let s=r;s>=0&&Kt(this._timeline[s].time,t);s--)n=s;this._iterate(s=>{e(s)},n,r)}return this}dispose(){return super.dispose(),this._timeline=[],this}};var sp=[];function so(o){sp.push(o)}function ip(o){sp.forEach(t=>t(o))}var ap=[];function io(o){ap.push(o)}function cp(o){ap.forEach(t=>t(o))}var ao=class o extends It{constructor(){super(...arguments),this.name="Emitter"}on(t,e){return t.split(/\W+/).forEach(n=>{Ot(this._events)&&(this._events={}),this._events.hasOwnProperty(n)||(this._events[n]=[]),this._events[n].push(e)}),this}once(t,e){let r=(...n)=>{e(...n),this.off(t,r)};return this.on(t,r),this}off(t,e){return t.split(/\W+/).forEach(n=>{if(Ot(this._events)&&(this._events={}),this._events.hasOwnProperty(n))if(Ot(e))this._events[n]=[];else{let s=this._events[n];for(let a=s.length-1;a>=0;a--)s[a]===e&&s.splice(a,1)}}),this}emit(t,...e){if(this._events&&this._events.hasOwnProperty(t)){let r=this._events[t].slice(0);for(let n=0,s=r.length;n<s;n++)r[n].apply(this,e)}return this}static mixin(t){["on","once","off","emit"].forEach(e=>{let r=Object.getOwnPropertyDescriptor(o.prototype,e);Object.defineProperty(t.prototype,e,r)})}dispose(){return super.dispose(),this._events=void 0,this}};var rr=class extends ao{constructor(){super(...arguments),this.isOffline=!1}toJSON(){return{}}};var To=class o extends rr{constructor(){var t,e;super(),this.name="Context",this._constants=new Map,this._timeouts=new Ft,this._timeoutIds=0,this._initialized=!1,this._closeStarted=!1,this.isOffline=!1,this._workletPromise=null;let r=x(o.getDefaults(),arguments,["context"]);r.context?(this._context=r.context,this._latencyHint=((t=arguments[0])===null||t===void 0?void 0:t.latencyHint)||""):(this._context=Kh({latencyHint:r.latencyHint}),this._latencyHint=r.latencyHint),this._ticker=new Dn(this.emit.bind(this,"tick"),r.clockSource,r.updateInterval,this._context.sampleRate),this.on("tick",this._timeoutLoop.bind(this)),this._context.onstatechange=()=>{this.emit("statechange",this.state)},this[!((e=arguments[0])===null||e===void 0)&&e.hasOwnProperty("updateInterval")?"_lookAhead":"lookAhead"]=r.lookAhead}static getDefaults(){return{clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.05}}initialize(){return this._initialized||(ip(this),this._initialized=!0),this}createAnalyser(){return this._context.createAnalyser()}createOscillator(){return this._context.createOscillator()}createBufferSource(){return this._context.createBufferSource()}createBiquadFilter(){return this._context.createBiquadFilter()}createBuffer(t,e,r){return this._context.createBuffer(t,e,r)}createChannelMerger(t){return this._context.createChannelMerger(t)}createChannelSplitter(t){return this._context.createChannelSplitter(t)}createConstantSource(){return this._context.createConstantSource()}createConvolver(){return this._context.createConvolver()}createDelay(t){return this._context.createDelay(t)}createDynamicsCompressor(){return this._context.createDynamicsCompressor()}createGain(){return this._context.createGain()}createIIRFilter(t,e){return this._context.createIIRFilter(t,e)}createPanner(){return this._context.createPanner()}createPeriodicWave(t,e,r){return this._context.createPeriodicWave(t,e,r)}createStereoPanner(){return this._context.createStereoPanner()}createWaveShaper(){return this._context.createWaveShaper()}createMediaStreamSource(t){return j(no(this._context),"Not available if OfflineAudioContext"),this._context.createMediaStreamSource(t)}createMediaElementSource(t){return j(no(this._context),"Not available if OfflineAudioContext"),this._context.createMediaElementSource(t)}createMediaStreamDestination(){return j(no(this._context),"Not available if OfflineAudioContext"),this._context.createMediaStreamDestination()}decodeAudioData(t){return this._context.decodeAudioData(t)}get currentTime(){return this._context.currentTime}get state(){return this._context.state}get sampleRate(){return this._context.sampleRate}get listener(){return this.initialize(),this._listener}set listener(t){j(!this._initialized,"The listener cannot be set after initialization."),this._listener=t}get transport(){return this.initialize(),this._transport}set transport(t){j(!this._initialized,"The transport cannot be set after initialization."),this._transport=t}get draw(){return this.initialize(),this._draw}set draw(t){j(!this._initialized,"Draw cannot be set after initialization."),this._draw=t}get destination(){return this.initialize(),this._destination}set destination(t){j(!this._initialized,"The destination cannot be set after initialization."),this._destination=t}createAudioWorkletNode(t,e){return ep(this.rawContext,t,e)}addAudioWorkletModule(t){return ot(this,void 0,void 0,function*(){j(Z(this.rawContext.audioWorklet),"AudioWorkletNode is only available in a secure context (https or localhost)"),this._workletPromise||(this._workletPromise=this.rawContext.audioWorklet.addModule(t)),yield this._workletPromise})}workletsAreReady(){return ot(this,void 0,void 0,function*(){(yield this._workletPromise)?this._workletPromise:Promise.resolve()})}get updateInterval(){return this._ticker.updateInterval}set updateInterval(t){this._ticker.updateInterval=t}get clockSource(){return this._ticker.type}set clockSource(t){this._ticker.type=t}get lookAhead(){return this._lookAhead}set lookAhead(t){this._lookAhead=t,this.updateInterval=t?t/2:.01}get latencyHint(){return this._latencyHint}get rawContext(){return this._context}now(){return this._context.currentTime+this._lookAhead}immediate(){return this._context.currentTime}resume(){return no(this._context)?this._context.resume():Promise.resolve()}close(){return ot(this,void 0,void 0,function*(){no(this._context)&&this.state!=="closed"&&!this._closeStarted&&(this._closeStarted=!0,yield this._context.close()),this._initialized&&cp(this)})}getConstant(t){if(this._constants.has(t))return this._constants.get(t);{let e=this._context.createBuffer(1,128,this._context.sampleRate),r=e.getChannelData(0);for(let s=0;s<r.length;s++)r[s]=t;let n=this._context.createBufferSource();return n.channelCount=1,n.channelCountMode="explicit",n.buffer=e,n.loop=!0,n.start(0),this._constants.set(t,n),n}}dispose(){return super.dispose(),this._ticker.dispose(),this._timeouts.dispose(),Object.keys(this._constants).map(t=>this._constants[t].disconnect()),this.close(),this}_timeoutLoop(){let t=this.now();this._timeouts.forEachBefore(t,e=>{e.callback(),this._timeouts.remove(e)})}setTimeout(t,e){this._timeoutIds++;let r=this.now();return this._timeouts.add({callback:t,id:this._timeoutIds,time:r+e}),this._timeoutIds}clearTimeout(t){return this._timeouts.forEach(e=>{e.id===t&&this._timeouts.remove(e)}),this}clearInterval(t){return this.clearTimeout(t)}setInterval(t,e){let r=++this._timeoutIds,n=()=>{let s=this.now();this._timeouts.add({callback:()=>{t(),n()},id:r,time:s+e})};return n(),r}};var Rn=class extends rr{constructor(){super(...arguments),this.lookAhead=0,this.latencyHint=0,this.isOffline=!1}createAnalyser(){return{}}createOscillator(){return{}}createBufferSource(){return{}}createBiquadFilter(){return{}}createBuffer(t,e,r){return{}}createChannelMerger(t){return{}}createChannelSplitter(t){return{}}createConstantSource(){return{}}createConvolver(){return{}}createDelay(t){return{}}createDynamicsCompressor(){return{}}createGain(){return{}}createIIRFilter(t,e){return{}}createPanner(){return{}}createPeriodicWave(t,e,r){return{}}createStereoPanner(){return{}}createWaveShaper(){return{}}createMediaStreamSource(t){return{}}createMediaElementSource(t){return{}}createMediaStreamDestination(){return{}}decodeAudioData(t){return Promise.resolve({})}createAudioWorkletNode(t,e){return{}}get rawContext(){return{}}addAudioWorkletModule(t){return ot(this,void 0,void 0,function*(){return Promise.resolve()})}resume(){return Promise.resolve()}setTimeout(t,e){return 0}clearTimeout(t){return this}setInterval(t,e){return 0}clearInterval(t){return this}getConstant(t){return{}}get currentTime(){return 0}get state(){return{}}get sampleRate(){return 0}get listener(){return{}}get transport(){return{}}get draw(){return{}}set draw(t){}get destination(){return{}}set destination(t){}now(){return 0}immediate(){return 0}};function G(o,t){Et(t)?t.forEach(e=>G(o,e)):Object.defineProperty(o,t,{enumerable:!0,writable:!1})}function So(o,t){Et(t)?t.forEach(e=>So(o,e)):Object.defineProperty(o,t,{writable:!0})}var X=()=>{};var At=class o extends It{constructor(){super(),this.name="ToneAudioBuffer",this.onload=X;let t=x(o.getDefaults(),arguments,["url","onload","onerror"]);this.reverse=t.reverse,this.onload=t.onload,Ut(t.url)?this.load(t.url).catch(t.onerror):t.url&&this.set(t.url)}static getDefaults(){return{onerror:X,onload:X,reverse:!1}}get sampleRate(){return this._buffer?this._buffer.sampleRate:dt().sampleRate}set(t){return t instanceof o?t.loaded?this._buffer=t.get():t.onload=()=>{this.set(t),this.onload(this)}:this._buffer=t,this._reversed&&this._reverse(),this}get(){return this._buffer}load(t){return ot(this,void 0,void 0,function*(){let e=o.load(t).then(r=>{this.set(r),this.onload(this)});o.downloads.push(e);try{yield e}finally{let r=o.downloads.indexOf(e);o.downloads.splice(r,1)}return this})}dispose(){return super.dispose(),this._buffer=void 0,this}fromArray(t){let e=Et(t)&&t[0].length>0,r=e?t.length:1,n=e?t[0].length:t.length,s=dt(),a=s.createBuffer(r,n,s.sampleRate),i=!e&&r===1?[t]:t;for(let c=0;c<r;c++)a.copyToChannel(i[c],c);return this._buffer=a,this}toMono(t){if(Gt(t))this.fromArray(this.toArray(t));else{let e=new Float32Array(this.length),r=this.numberOfChannels;for(let n=0;n<r;n++){let s=this.toArray(n);for(let a=0;a<s.length;a++)e[a]+=s[a]}e=e.map(n=>n/r),this.fromArray(e)}return this}toArray(t){if(Gt(t))return this.getChannelData(t);if(this.numberOfChannels===1)return this.toArray(0);{let e=[];for(let r=0;r<this.numberOfChannels;r++)e[r]=this.getChannelData(r);return e}}getChannelData(t){return this._buffer?this._buffer.getChannelData(t):new Float32Array(0)}slice(t,e=this.duration){j(this.loaded,"Buffer is not loaded");let r=Math.floor(t*this.sampleRate),n=Math.floor(e*this.sampleRate);j(r<n,"The start time must be less than the end time");let s=n-r,a=dt().createBuffer(this.numberOfChannels,s,this.sampleRate);for(let i=0;i<this.numberOfChannels;i++)a.copyToChannel(this.getChannelData(i).subarray(r,n),i);return new o(a)}_reverse(){if(this.loaded)for(let t=0;t<this.numberOfChannels;t++)this.getChannelData(t).reverse();return this}get loaded(){return this.length>0}get duration(){return this._buffer?this._buffer.duration:0}get length(){return this._buffer?this._buffer.length:0}get numberOfChannels(){return this._buffer?this._buffer.numberOfChannels:0}get reverse(){return this._reversed}set reverse(t){this._reversed!==t&&(this._reversed=t,this._reverse())}static fromArray(t){return new o().fromArray(t)}static fromUrl(t){return ot(this,void 0,void 0,function*(){return yield new o().load(t)})}static load(t){return ot(this,void 0,void 0,function*(){let e=o.baseUrl===""||o.baseUrl.endsWith("/")?o.baseUrl:o.baseUrl+"/",r=yield fetch(e+t);if(!r.ok)throw new Error(`could not load url: ${t}`);let n=yield r.arrayBuffer();return yield dt().decodeAudioData(n)})}static supportsType(t){let e=t.split("."),r=e[e.length-1];return document.createElement("audio").canPlayType("audio/"+r)!==""}static loaded(){return ot(this,void 0,void 0,function*(){for(yield Promise.resolve();o.downloads.length;)yield o.downloads[0]})}};At.baseUrl="";At.downloads=[];var Ce=class extends To{constructor(){super({clockSource:"offline",context:or(arguments[0])?arguments[0]:Jh(arguments[0],arguments[1]*arguments[2],arguments[2]),lookAhead:0,updateInterval:or(arguments[0])?128/arguments[0].sampleRate:128/arguments[2]}),this.name="OfflineContext",this._currentTime=0,this.isOffline=!0,this._duration=or(arguments[0])?arguments[0].length/arguments[0].sampleRate:arguments[1]}now(){return this._currentTime}get currentTime(){return this._currentTime}_renderClock(t){return ot(this,void 0,void 0,function*(){let e=0;for(;this._duration-this._currentTime>=0;){this.emit("tick"),this._currentTime+=128/this.sampleRate,e++;let r=Math.floor(this.sampleRate/128);t&&e%r===0&&(yield new Promise(n=>setTimeout(n,1)))}})}render(){return ot(this,arguments,void 0,function*(t=!0){yield this.workletsAreReady(),yield this._renderClock(t);let e=yield this._context.startRendering();return new At(e)})}close(){return Promise.resolve()}};var up=new Rn,Ao=up;function dt(){return Ao===up&&tp&&ai(new To),Ao}function ai(o,t=!1){t&&Ao.dispose(),no(o)?Ao=new To(o):or(o)?Ao=new Ce(o):Ao=o}function ci(){return Ao.resume()}if(Ht&&!Ht.TONE_SILENCE_LOGGING){let o="v";Sr==="dev"&&(o="");let t=` * Tone.js ${o}${Sr} * `;console.log(`%c${t}`,"background: #000; color: #fff")}function co(o){return Math.pow(10,o/20)}function nr(o){return 20*(Math.log(o)/Math.LN10)}function Co(o){return Math.pow(2,o/12)}var In=440;function lp(){return In}function hp(o){In=o}function No(o){return Math.round(ui(o))}function ui(o){return 69+12*Math.log2(o/In)}function Pn(o){return In*Math.pow(2,(o-69)/12)}var qn=class o extends It{constructor(t,e,r){super(),this.defaultUnits="s",this._val=e,this._units=r,this.context=t,this._expressions=this._getExpressions()}_getExpressions(){return{hz:{method:t=>this._frequencyToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)hz$/i},i:{method:t=>this._ticksToUnits(parseInt(t,10)),regexp:/^(\d+)i$/i},m:{method:t=>this._beatsToUnits(parseInt(t,10)*this._getTimeSignature()),regexp:/^(\d+)m$/i},n:{method:(t,e)=>{let r=parseInt(t,10),n=e==="."?1.5:1;return r===1?this._beatsToUnits(this._getTimeSignature())*n:this._beatsToUnits(4/r)*n},regexp:/^(\d+)n(\.?)$/i},number:{method:t=>this._expressions[this.defaultUnits].method.call(this,t),regexp:/^(\d+(?:\.\d+)?)$/},s:{method:t=>this._secondsToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)s$/},samples:{method:t=>parseInt(t,10)/this.context.sampleRate,regexp:/^(\d+)samples$/},t:{method:t=>{let e=parseInt(t,10);return this._beatsToUnits(8/(Math.floor(e)*3))},regexp:/^(\d+)t$/i},tr:{method:(t,e,r)=>{let n=0;return t&&t!=="0"&&(n+=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&e!=="0"&&(n+=this._beatsToUnits(parseFloat(e))),r&&r!=="0"&&(n+=this._beatsToUnits(parseFloat(r)/4)),n},regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/}}}valueOf(){if(this._val instanceof o&&this.fromType(this._val),Ot(this._val))return this._noArg();if(Ut(this._val)&&Ot(this._units)){for(let t in this._expressions)if(this._expressions[t].regexp.test(this._val.trim())){this._units=t;break}}else if(Se(this._val)){let t=0;for(let e in this._val)if(Z(this._val[e])){let r=this._val[e],n=new this.constructor(this.context,e).valueOf()*r;t+=n}return t}if(Z(this._units)){let t=this._expressions[this._units],e=this._val.toString().trim().match(t.regexp);return e?t.method.apply(this,e.slice(1)):t.method.call(this,this._val)}else return Ut(this._val)?parseFloat(this._val):this._val}_frequencyToUnits(t){return 1/t}_beatsToUnits(t){return 60/this._getBpm()*t}_secondsToUnits(t){return t}_ticksToUnits(t){return t*this._beatsToUnits(1)/this._getPPQ()}_noArg(){return this._now()}_getBpm(){return this.context.transport.bpm.value}_getTimeSignature(){return this.context.transport.timeSignature}_getPPQ(){return this.context.transport.PPQ}fromType(t){switch(this._units=void 0,this.defaultUnits){case"s":this._val=t.toSeconds();break;case"i":this._val=t.toTicks();break;case"hz":this._val=t.toFrequency();break;case"midi":this._val=t.toMidi();break}return this}toFrequency(){return 1/this.toSeconds()}toSamples(){return this.toSeconds()*this.context.sampleRate}toMilliseconds(){return this.toSeconds()*1e3}};var he=class o extends qn{constructor(){super(...arguments),this.name="TimeClass"}_getExpressions(){return Object.assign(super._getExpressions(),{now:{method:t=>this._now()+new this.constructor(this.context,t).valueOf(),regexp:/^\+(.+)/},quantize:{method:t=>{let e=new o(this.context,t).valueOf();return this._secondsToUnits(this.context.transport.nextSubdivision(e))},regexp:/^@(.+)/}})}quantize(t,e=1){let r=new this.constructor(this.context,t).valueOf(),n=this.valueOf(),i=Math.round(n/r)*r-n;return n+i*e}toNotation(){let t=this.toSeconds(),e=["1m"];for(let s=1;s<9;s++){let a=Math.pow(2,s);e.push(a+"n."),e.push(a+"n"),e.push(a+"t")}e.push("0");let r=e[0],n=new o(this.context,e[0]).toSeconds();return e.forEach(s=>{let a=new o(this.context,s).toSeconds();Math.abs(a-t)<Math.abs(n-t)&&(r=s,n=a)}),r}toBarsBeatsSixteenths(){let t=this._beatsToUnits(1),e=this.valueOf()/t;e=parseFloat(e.toFixed(4));let r=Math.floor(e/this._getTimeSignature()),n=e%1*4;e=Math.floor(e)%this._getTimeSignature();let s=n.toString();return s.length>3&&(n=parseFloat(parseFloat(s).toFixed(3))),[r,e,n].join(":")}toTicks(){let t=this._beatsToUnits(1);return this.valueOf()/t*this._getPPQ()}toSeconds(){return this.valueOf()}toMidi(){return No(this.toFrequency())}_now(){return this.context.now()}};var se=class o extends he{constructor(){super(...arguments),this.name="Frequency",this.defaultUnits="hz"}static get A4(){return lp()}static set A4(t){hp(t)}_getExpressions(){return Object.assign({},super._getExpressions(),{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method(t){return this.defaultUnits==="midi"?t:o.mtof(t)}},note:{regexp:/^([a-g]{1}(?:b|#|##|x|bb|###|#x|x#|bbb)?)(-?[0-9]+)/i,method(t,e){let n=yf[t.toLowerCase()]+(parseInt(e,10)+1)*12;return this.defaultUnits==="midi"?n:o.mtof(n)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method(t,e,r){let n=1;return t&&t!=="0"&&(n*=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&e!=="0"&&(n*=this._beatsToUnits(parseFloat(e))),r&&r!=="0"&&(n*=this._beatsToUnits(parseFloat(r)/4)),n}}})}transpose(t){return new o(this.context,this.valueOf()*Co(t))}harmonize(t){return t.map(e=>this.transpose(e))}toMidi(){return No(this.valueOf())}toNote(){let t=this.toFrequency(),e=Math.log2(t/o.A4),r=Math.round(12*e)+57,n=Math.floor(r/12);return n<0&&(r+=-12*n),vf[r%12]+n.toString()}toSeconds(){return 1/super.toSeconds()}toTicks(){let t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.floor(e*this._getPPQ())}_noArg(){return 0}_frequencyToUnits(t){return t}_ticksToUnits(t){return 1/(t*60/(this._getBpm()*this._getPPQ()))}_beatsToUnits(t){return 1/super._beatsToUnits(t)}_secondsToUnits(t){return 1/t}static mtof(t){return Pn(t)}static ftom(t){return No(t)}},yf={cbbb:-3,cbb:-2,cb:-1,c:0,"c#":1,cx:2,"c##":2,"c###":3,"cx#":3,"c#x":3,dbbb:-1,dbb:0,db:1,d:2,"d#":3,dx:4,"d##":4,"d###":5,"dx#":5,"d#x":5,ebbb:1,ebb:2,eb:3,e:4,"e#":5,ex:6,"e##":6,"e###":7,"ex#":7,"e#x":7,fbbb:2,fbb:3,fb:4,f:5,"f#":6,fx:7,"f##":7,"f###":8,"fx#":8,"f#x":8,gbbb:4,gbb:5,gb:6,g:7,"g#":8,gx:9,"g##":9,"g###":10,"gx#":10,"g#x":10,abbb:6,abb:7,ab:8,a:9,"a#":10,ax:11,"a##":11,"a###":12,"ax#":12,"a#x":12,bbbb:8,bbb:9,bb:10,b:11,"b#":12,bx:13,"b##":13,"b###":14,"bx#":14,"b#x":14},vf=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];var ye=class extends he{constructor(){super(...arguments),this.name="TransportTime"}_now(){return this.context.transport.seconds}};var gt=class o extends It{constructor(){super();let t=x(o.getDefaults(),arguments,["context"]);this.defaultContext?this.context=this.defaultContext:this.context=t.context}static getDefaults(){return{context:dt()}}now(){return this.context.currentTime+this.context.lookAhead}immediate(){return this.context.currentTime}get sampleTime(){return 1/this.context.sampleRate}get blockTime(){return 128/this.context.sampleRate}toSeconds(t){return Xh(t),new he(this.context,t).toSeconds()}toFrequency(t){return new se(this.context,t).toFrequency()}toTicks(t){return new ye(this.context,t).toTicks()}_getPartialProperties(t){let e=this.get();return Object.keys(e).forEach(r=>{Ot(t[r])&&delete e[r]}),e}get(){let t=np(this);return Object.keys(t).forEach(e=>{if(Reflect.has(this,e)){let r=this[e];Z(r)&&Z(r.value)&&Z(r.setValueAtTime)?t[e]=r.value:r instanceof o?t[e]=r._getPartialProperties(t[e]):Et(r)||Gt(r)||Ut(r)||Mn(r)?t[e]=r:delete t[e]}}),t}set(t){return Object.keys(t).forEach(e=>{Reflect.has(this,e)&&Z(this[e])&&(this[e]&&Z(this[e].value)&&Z(this[e].setValueAtTime)?this[e].value!==t[e]&&(this[e].value=t[e]):this[e]instanceof o?this[e].set(t[e]):this[e]=t[e])}),this}};var Ne=class extends Ft{constructor(t="stopped"){super(),this.name="StateTimeline",this._initial=t,this.setStateAtTime(this._initial,0)}getValueAtTime(t){let e=this.get(t);return e!==null?e.state:this._initial}setStateAtTime(t,e,r){return St(e,0),this.add(Object.assign({},r,{state:t,time:e})),this}getLastState(t,e){let r=this._search(e);for(let n=r;n>=0;n--){let s=this._timeline[n];if(s.state===t)return s}}getNextState(t,e){let r=this._search(e);if(r!==-1)for(let n=r;n<this._timeline.length;n++){let s=this._timeline[n];if(s.state===t)return s}}};var H=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments,["param","units","convert"]);for(super(t),this.name="Param",this.overridden=!1,this._minOutput=1e-7,j(Z(t.param)&&(Ae(t.param)||t.param instanceof o),"param must be an AudioParam");!Ae(t.param);)t.param=t.param._param;this._swappable=Z(t.swappable)?t.swappable:!1,this._swappable?(this.input=this.context.createGain(),this._param=t.param,this.input.connect(this._param)):this._param=this.input=t.param,this._events=new Ft(1e3),this._initialValue=this._param.defaultValue,this.units=t.units,this.convert=t.convert,this._minValue=t.minValue,this._maxValue=t.maxValue,Z(t.value)&&t.value!==this._toType(this._initialValue)&&this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(gt.getDefaults(),{convert:!0,units:"number"})}get value(){let t=this.now();return this.getValueAtTime(t)}set value(t){this.cancelScheduledValues(this.now()),this.setValueAtTime(t,this.now())}get minValue(){return Z(this._minValue)?this._minValue:this.units==="time"||this.units==="frequency"||this.units==="normalRange"||this.units==="positive"||this.units==="transportTime"||this.units==="ticks"||this.units==="bpm"||this.units==="hertz"||this.units==="samples"?0:this.units==="audioRange"?-1:this.units==="decibels"?-1/0:this._param.minValue}get maxValue(){return Z(this._maxValue)?this._maxValue:this.units==="normalRange"||this.units==="audioRange"?1:this._param.maxValue}_is(t,e){return this.units===e}_assertRange(t){return Z(this.maxValue)&&Z(this.minValue)&&St(t,this._fromType(this.minValue),this._fromType(this.maxValue)),t}_fromType(t){return this.convert&&!this.overridden?this._is(t,"time")?this.toSeconds(t):this._is(t,"decibels")?co(t):this._is(t,"frequency")?this.toFrequency(t):t:this.overridden?0:t}_toType(t){return this.convert&&this.units==="decibels"?nr(t):t}setValueAtTime(t,e){let r=this.toSeconds(e),n=this._fromType(t);return j(isFinite(n)&&isFinite(r),`Invalid argument(s) to setValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(n),this.log(this.units,"setValueAtTime",t,r),this._events.add({time:r,type:"setValueAtTime",value:n}),this._param.setValueAtTime(n,r),this}getValueAtTime(t){let e=Math.max(this.toSeconds(t),0),r=this._events.getAfter(e),n=this._events.get(e),s=this._initialValue;if(n===null)s=this._initialValue;else if(n.type==="setTargetAtTime"&&(r===null||r.type==="setValueAtTime")){let a=this._events.getBefore(n.time),i;a===null?i=this._initialValue:i=a.value,n.type==="setTargetAtTime"&&(s=this._exponentialApproach(n.time,i,n.value,n.constant,e))}else if(r===null)s=n.value;else if(r.type==="linearRampToValueAtTime"||r.type==="exponentialRampToValueAtTime"){let a=n.value;if(n.type==="setTargetAtTime"){let i=this._events.getBefore(n.time);i===null?a=this._initialValue:a=i.value}r.type==="linearRampToValueAtTime"?s=this._linearInterpolate(n.time,a,r.time,r.value,e):s=this._exponentialInterpolate(n.time,a,r.time,r.value,e)}else s=n.value;return this._toType(s)}setRampPoint(t){t=this.toSeconds(t);let e=this.getValueAtTime(t);return this.cancelAndHoldAtTime(t),this._fromType(e)===0&&(e=this._toType(this._minOutput)),this.setValueAtTime(e,t),this}linearRampToValueAtTime(t,e){let r=this._fromType(t),n=this.toSeconds(e);return j(isFinite(r)&&isFinite(n),`Invalid argument(s) to linearRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(r),this._events.add({time:n,type:"linearRampToValueAtTime",value:r}),this.log(this.units,"linearRampToValueAtTime",t,n),this._param.linearRampToValueAtTime(r,n),this}exponentialRampToValueAtTime(t,e){let r=this._fromType(t);r=Kt(r,0)?this._minOutput:r,this._assertRange(r);let n=this.toSeconds(e);return j(isFinite(r)&&isFinite(n),`Invalid argument(s) to exponentialRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({time:n,type:"exponentialRampToValueAtTime",value:r}),this.log(this.units,"exponentialRampToValueAtTime",t,n),this._param.exponentialRampToValueAtTime(r,n),this}exponentialRampTo(t,e,r){return r=this.toSeconds(r),this.setRampPoint(r),this.exponentialRampToValueAtTime(t,r+this.toSeconds(e)),this}linearRampTo(t,e,r){return r=this.toSeconds(r),this.setRampPoint(r),this.linearRampToValueAtTime(t,r+this.toSeconds(e)),this}targetRampTo(t,e,r){return r=this.toSeconds(r),this.setRampPoint(r),this.exponentialApproachValueAtTime(t,r,e),this}exponentialApproachValueAtTime(t,e,r){e=this.toSeconds(e),r=this.toSeconds(r);let n=Math.log(r+1)/Math.log(200);return this.setTargetAtTime(t,e,n),this.cancelAndHoldAtTime(e+r*.9),this.linearRampToValueAtTime(t,e+r),this}setTargetAtTime(t,e,r){let n=this._fromType(t);j(isFinite(r)&&r>0,"timeConstant must be a number greater than 0");let s=this.toSeconds(e);return this._assertRange(n),j(isFinite(n)&&isFinite(s),`Invalid argument(s) to setTargetAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({constant:r,time:s,type:"setTargetAtTime",value:n}),this.log(this.units,"setTargetAtTime",t,s,r),this._param.setTargetAtTime(n,s,r),this}setValueCurveAtTime(t,e,r,n=1){r=this.toSeconds(r),e=this.toSeconds(e);let s=this._fromType(t[0])*n;this.setValueAtTime(this._toType(s),e);let a=r/(t.length-1);for(let i=1;i<t.length;i++){let c=this._fromType(t[i])*n;this.linearRampToValueAtTime(this._toType(c),e+i*a)}return this}cancelScheduledValues(t){let e=this.toSeconds(t);return j(isFinite(e),`Invalid argument to cancelScheduledValues: ${JSON.stringify(t)}`),this._events.cancel(e),this._param.cancelScheduledValues(e),this.log(this.units,"cancelScheduledValues",e),this}cancelAndHoldAtTime(t){let e=this.toSeconds(t),r=this._fromType(this.getValueAtTime(e));j(isFinite(e),`Invalid argument to cancelAndHoldAtTime: ${JSON.stringify(t)}`),this.log(this.units,"cancelAndHoldAtTime",e,"value="+r);let n=this._events.get(e),s=this._events.getAfter(e);return n&&Kt(n.time,e)?s?(this._param.cancelScheduledValues(s.time),this._events.cancel(s.time)):(this._param.cancelAndHoldAtTime(e),this._events.cancel(e+this.sampleTime)):s&&(this._param.cancelScheduledValues(s.time),this._events.cancel(s.time),s.type==="linearRampToValueAtTime"?this.linearRampToValueAtTime(this._toType(r),e):s.type==="exponentialRampToValueAtTime"&&this.exponentialRampToValueAtTime(this._toType(r),e)),this._events.add({time:e,type:"setValueAtTime",value:r}),this._param.setValueAtTime(r,e),this}rampTo(t,e=.1,r){return this.units==="frequency"||this.units==="bpm"||this.units==="decibels"?this.exponentialRampTo(t,e,r):this.linearRampTo(t,e,r),this}apply(t){let e=this.context.currentTime;t.setValueAtTime(this.getValueAtTime(e),e);let r=this._events.get(e);if(r&&r.type==="setTargetAtTime"){let n=this._events.getAfter(r.time),s=n?n.time:e+2,a=(s-e)/10;for(let i=e;i<s;i+=a)t.linearRampToValueAtTime(this.getValueAtTime(i),i)}return this._events.forEachAfter(this.context.currentTime,n=>{n.type==="cancelScheduledValues"?t.cancelScheduledValues(n.time):n.type==="setTargetAtTime"?t.setTargetAtTime(n.value,n.time,n.constant):t[n.type](n.value,n.time)}),this}setParam(t){j(this._swappable,"The Param must be assigned as 'swappable' in the constructor");let e=this.input;return e.disconnect(this._param),this.apply(t),this._param=t,e.connect(this._param),this}dispose(){return super.dispose(),this._events.dispose(),this}get defaultValue(){return this._toType(this._param.defaultValue)}_exponentialApproach(t,e,r,n,s){return r+(e-r)*Math.exp(-(s-t)/n)}_linearInterpolate(t,e,r,n,s){return e+(n-e)*((s-t)/(r-t))}_exponentialInterpolate(t,e,r,n,s){return e*Math.pow(n/e,(s-t)/(r-t))}};var N=class o extends gt{constructor(){super(...arguments),this._internalChannels=[]}get numberOfInputs(){return Z(this.input)?Ae(this.input)||this.input instanceof H?1:this.input.numberOfInputs:0}get numberOfOutputs(){return Z(this.output)?this.output.numberOfOutputs:0}_isAudioNode(t){return Z(t)&&(t instanceof o||Ve(t))}_getInternalNodes(){let t=this._internalChannels.slice(0);return this._isAudioNode(this.input)&&t.push(this.input),this._isAudioNode(this.output)&&this.input!==this.output&&t.push(this.output),t}_setChannelProperties(t){this._getInternalNodes().forEach(r=>{r.channelCount=t.channelCount,r.channelCountMode=t.channelCountMode,r.channelInterpretation=t.channelInterpretation})}_getChannelProperties(){let t=this._getInternalNodes();j(t.length>0,"ToneAudioNode does not have any internal nodes");let e=t[0];return{channelCount:e.channelCount,channelCountMode:e.channelCountMode,channelInterpretation:e.channelInterpretation}}get channelCount(){return this._getChannelProperties().channelCount}set channelCount(t){let e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCount:t}))}get channelCountMode(){return this._getChannelProperties().channelCountMode}set channelCountMode(t){let e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCountMode:t}))}get channelInterpretation(){return this._getChannelProperties().channelInterpretation}set channelInterpretation(t){let e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelInterpretation:t}))}connect(t,e=0,r=0){return Wt(this,t,e,r),this}toDestination(){return this.connect(this.context.destination),this}toMaster(){return er("toMaster() has been renamed toDestination()"),this.toDestination()}disconnect(t,e=0,r=0){return li(this,t,e,r),this}chain(...t){return ie(this,...t),this}fan(...t){return t.forEach(e=>this.connect(e)),this}dispose(){return super.dispose(),Z(this.input)&&(this.input instanceof o?this.input.dispose():Ve(this.input)&&this.input.disconnect()),Z(this.output)&&(this.output instanceof o?this.output.dispose():Ve(this.output)&&this.output.disconnect()),this._internalChannels=[],this}};function ie(...o){let t=o.shift();o.reduce((e,r)=>(e instanceof N?e.connect(r):Ve(e)&&Wt(e,r),r),t)}function Wt(o,t,e=0,r=0){for(j(Z(o),"Cannot connect from undefined node"),j(Z(t),"Cannot connect to undefined node"),(t instanceof N||Ve(t))&&j(t.numberOfInputs>0,"Cannot connect to node with no inputs"),j(o.numberOfOutputs>0,"Cannot connect from node with no outputs");t instanceof N||t instanceof H;)Z(t.input)&&(t=t.input);for(;o instanceof N;)Z(o.output)&&(o=o.output);Ae(t)?o.connect(t,e):o.connect(t,e,r)}function li(o,t,e=0,r=0){if(Z(t))for(;t instanceof N;)t=t.input;for(;!Ve(o);)Z(o.output)&&(o=o.output);Ae(t)?o.disconnect(t,e):Ve(t)?o.disconnect(t,e,r):o.disconnect()}var A=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["gain","units"]);super(t),this.name="Gain",this._gainNode=this.context.createGain(),this.input=this._gainNode,this.output=this._gainNode,this.gain=new H({context:this.context,convert:t.convert,param:this._gainNode.gain,units:t.units,value:t.gain,minValue:t.minValue,maxValue:t.maxValue}),G(this,"gain")}static getDefaults(){return Object.assign(N.getDefaults(),{convert:!0,gain:1,units:"gain"})}dispose(){return super.dispose(),this._gainNode.disconnect(),this.gain.dispose(),this}};var ke=class extends N{constructor(t){super(t),this.onended=X,this._startTime=-1,this._stopTime=-1,this._timeout=-1,this.output=new A({context:this.context,gain:0}),this._gainNode=this.output,this.getStateAtTime=function(e){let r=this.toSeconds(e);return this._startTime!==-1&&r>=this._startTime&&(this._stopTime===-1||r<=this._stopTime)?"started":"stopped"},this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut,this._curve=t.curve,this.onended=t.onended}static getDefaults(){return Object.assign(N.getDefaults(),{curve:"linear",fadeIn:0,fadeOut:0,onended:X})}_startGain(t,e=1){j(this._startTime===-1,"Source cannot be started more than once");let r=this.toSeconds(this._fadeIn);return this._startTime=t+r,this._startTime=Math.max(this._startTime,this.context.currentTime),r>0?(this._gainNode.gain.setValueAtTime(0,t),this._curve==="linear"?this._gainNode.gain.linearRampToValueAtTime(e,t+r):this._gainNode.gain.exponentialApproachValueAtTime(e,t,r)):this._gainNode.gain.setValueAtTime(e,t),this}stop(t){return this.log("stop",t),this._stopGain(this.toSeconds(t)),this}_stopGain(t){j(this._startTime!==-1,"'start' must be called before 'stop'"),this.cancelStop();let e=this.toSeconds(this._fadeOut);return this._stopTime=this.toSeconds(t)+e,this._stopTime=Math.max(this._stopTime,this.now()),e>0?this._curve==="linear"?this._gainNode.gain.linearRampTo(0,e,t):this._gainNode.gain.targetRampTo(0,e,t):(this._gainNode.gain.cancelAndHoldAtTime(t),this._gainNode.gain.setValueAtTime(0,t)),this.context.clearTimeout(this._timeout),this._timeout=this.context.setTimeout(()=>{let r=this._curve==="exponential"?e*2:0;this._stopSource(this.now()+r),this._onended()},this._stopTime-this.context.currentTime),this}_onended(){if(this.onended!==X&&(this.onended(this),this.onended=X,!this.context.isOffline)){let t=()=>this.dispose();typeof requestIdleCallback<"u"?requestIdleCallback(t):setTimeout(t,10)}}get state(){return this.getStateAtTime(this.now())}cancelStop(){return this.log("cancelStop"),j(this._startTime!==-1,"Source is not started"),this._gainNode.gain.cancelScheduledValues(this._startTime+this.sampleTime),this.context.clearTimeout(this._timeout),this._stopTime=-1,this}dispose(){return super.dispose(),this._gainNode.dispose(),this.onended=X,this}};var jr=class o extends ke{constructor(){let t=x(o.getDefaults(),arguments,["offset"]);super(t),this.name="ToneConstantSource",this._source=this.context.createConstantSource(),Wt(this._source,this._gainNode),this.offset=new H({context:this.context,convert:t.convert,param:this._source.offset,units:t.units,value:t.offset,minValue:t.minValue,maxValue:t.maxValue})}static getDefaults(){return Object.assign(ke.getDefaults(),{convert:!0,offset:1,units:"number"})}start(t){let e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._source.start(e),this}_stopSource(t){this._source.stop(t)}dispose(){return super.dispose(),this.state==="started"&&this.stop(),this._source.disconnect(),this.offset.dispose(),this}};var $=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["value","units"]);super(t),this.name="Signal",this.override=!0,this.output=this._constantSource=new jr({context:this.context,convert:t.convert,offset:t.value,units:t.units,minValue:t.minValue,maxValue:t.maxValue}),this._constantSource.start(0),this.input=this._param=this._constantSource.offset}static getDefaults(){return Object.assign(N.getDefaults(),{convert:!0,units:"number",value:0})}connect(t,e=0,r=0){return ko(this,t,e,r),this}dispose(){return super.dispose(),this._param.dispose(),this._constantSource.dispose(),this}setValueAtTime(t,e){return this._param.setValueAtTime(t,e),this}getValueAtTime(t){return this._param.getValueAtTime(t)}setRampPoint(t){return this._param.setRampPoint(t),this}linearRampToValueAtTime(t,e){return this._param.linearRampToValueAtTime(t,e),this}exponentialRampToValueAtTime(t,e){return this._param.exponentialRampToValueAtTime(t,e),this}exponentialRampTo(t,e,r){return this._param.exponentialRampTo(t,e,r),this}linearRampTo(t,e,r){return this._param.linearRampTo(t,e,r),this}targetRampTo(t,e,r){return this._param.targetRampTo(t,e,r),this}exponentialApproachValueAtTime(t,e,r){return this._param.exponentialApproachValueAtTime(t,e,r),this}setTargetAtTime(t,e,r){return this._param.setTargetAtTime(t,e,r),this}setValueCurveAtTime(t,e,r,n){return this._param.setValueCurveAtTime(t,e,r,n),this}cancelScheduledValues(t){return this._param.cancelScheduledValues(t),this}cancelAndHoldAtTime(t){return this._param.cancelAndHoldAtTime(t),this}rampTo(t,e,r){return this._param.rampTo(t,e,r),this}get value(){return this._param.value}set value(t){this._param.value=t}get convert(){return this._param.convert}set convert(t){this._param.convert=t}get units(){return this._param.units}get overridden(){return this._param.overridden}set overridden(t){this._param.overridden=t}get maxValue(){return this._param.maxValue}get minValue(){return this._param.minValue}apply(t){return this._param.apply(t),this}};function ko(o,t,e,r){(t instanceof H||Ae(t)||t instanceof $&&t.override)&&(t.cancelScheduledValues(0),t.setValueAtTime(0,0),t instanceof $&&(t.overridden=!0)),Wt(o,t,e,r)}var Vn=class o extends H{constructor(){let t=x(o.getDefaults(),arguments,["value"]);super(t),this.name="TickParam",this._events=new Ft(1/0),this._multiplier=1,this._multiplier=t.multiplier,this._events.cancel(0),this._events.add({ticks:0,time:0,type:"setValueAtTime",value:this._fromType(t.value)}),this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(H.getDefaults(),{multiplier:1,units:"hertz",value:1})}setTargetAtTime(t,e,r){e=this.toSeconds(e),this.setRampPoint(e);let n=this._fromType(t),s=this._events.get(e),a=Math.round(Math.max(1/r,1));for(let i=0;i<=a;i++){let c=r*i+e,u=this._exponentialApproach(s.time,s.value,n,r,c);this.linearRampToValueAtTime(this._toType(u),c)}return this}setValueAtTime(t,e){let r=this.toSeconds(e);super.setValueAtTime(t,e);let n=this._events.get(r),s=this._events.previousEvent(n),a=this._getTicksUntilEvent(s,r);return n.ticks=Math.max(a,0),this}linearRampToValueAtTime(t,e){let r=this.toSeconds(e);super.linearRampToValueAtTime(t,e);let n=this._events.get(r),s=this._events.previousEvent(n),a=this._getTicksUntilEvent(s,r);return n.ticks=Math.max(a,0),this}exponentialRampToValueAtTime(t,e){e=this.toSeconds(e);let r=this._fromType(t),n=this._events.get(e),s=Math.round(Math.max((e-n.time)*10,1)),a=(e-n.time)/s;for(let i=0;i<=s;i++){let c=a*i+n.time,u=this._exponentialInterpolate(n.time,n.value,e,r,c);this.linearRampToValueAtTime(this._toType(u),c)}return this}_getTicksUntilEvent(t,e){if(t===null)t={ticks:0,time:0,type:"setValueAtTime",value:0};else if(Ot(t.ticks)){let a=this._events.previousEvent(t);t.ticks=this._getTicksUntilEvent(a,t.time)}let r=this._fromType(this.getValueAtTime(t.time)),n=this._fromType(this.getValueAtTime(e)),s=this._events.get(e);return s&&s.time===e&&s.type==="setValueAtTime"&&(n=this._fromType(this.getValueAtTime(e-this.sampleTime))),.5*(e-t.time)*(r+n)+t.ticks}getTicksAtTime(t){let e=this.toSeconds(t),r=this._events.get(e);return Math.max(this._getTicksUntilEvent(r,e),0)}getDurationOfTicks(t,e){let r=this.toSeconds(e),n=this.getTicksAtTime(e);return this.getTimeOfTick(n+t)-r}getTimeOfTick(t){let e=this._events.get(t,"ticks"),r=this._events.getAfter(t,"ticks");if(e&&e.ticks===t)return e.time;if(e&&r&&r.type==="linearRampToValueAtTime"&&e.value!==r.value){let n=this._fromType(this.getValueAtTime(e.time)),a=(this._fromType(this.getValueAtTime(r.time))-n)/(r.time-e.time),i=Math.sqrt(Math.pow(n,2)-2*a*(e.ticks-t)),c=(-n+i)/a,u=(-n-i)/a;return(c>0?c:u)+e.time}else return e?e.value===0?1/0:e.time+(t-e.ticks)/e.value:t/this._initialValue}ticksToTime(t,e){return this.getDurationOfTicks(t,e)}timeToTicks(t,e){let r=this.toSeconds(e),n=this.toSeconds(t),s=this.getTicksAtTime(r);return this.getTicksAtTime(r+n)-s}_fromType(t){return this.units==="bpm"&&this.multiplier?1/(60/t/this.multiplier):super._fromType(t)}_toType(t){return this.units==="bpm"&&this.multiplier?t/this.multiplier*60:super._toType(t)}get multiplier(){return this._multiplier}set multiplier(t){let e=this.value;this._multiplier=t,this.cancelScheduledValues(0),this.setValueAtTime(e,0)}};var Ln=class o extends ${constructor(){let t=x(o.getDefaults(),arguments,["value"]);super(t),this.name="TickSignal",this.input=this._param=new Vn({context:this.context,convert:t.convert,multiplier:t.multiplier,param:this._constantSource.offset,units:t.units,value:t.value})}static getDefaults(){return Object.assign($.getDefaults(),{multiplier:1,units:"hertz",value:1})}ticksToTime(t,e){return this._param.ticksToTime(t,e)}timeToTicks(t,e){return this._param.timeToTicks(t,e)}getTimeOfTick(t){return this._param.getTimeOfTick(t)}getDurationOfTicks(t,e){return this._param.getDurationOfTicks(t,e)}getTicksAtTime(t){return this._param.getTicksAtTime(t)}get multiplier(){return this._param.multiplier}set multiplier(t){this._param.multiplier=t}dispose(){return super.dispose(),this._param.dispose(),this}};var Gn=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments,["frequency"]);super(t),this.name="TickSource",this._state=new Ne,this._tickOffset=new Ft,this._ticksAtTime=new Ft,this._secondsAtTime=new Ft,this.frequency=new Ln({context:this.context,units:t.units,value:t.frequency}),G(this,"frequency"),this._state.setStateAtTime("stopped",0),this.setTicksAtTime(0,0)}static getDefaults(){return Object.assign({frequency:1,units:"hertz"},gt.getDefaults())}get state(){return this.getStateAtTime(this.now())}start(t,e){let r=this.toSeconds(t);return this._state.getValueAtTime(r)!=="started"&&(this._state.setStateAtTime("started",r),Z(e)&&this.setTicksAtTime(e,r),this._ticksAtTime.cancel(r),this._secondsAtTime.cancel(r)),this}stop(t){let e=this.toSeconds(t);if(this._state.getValueAtTime(e)==="stopped"){let r=this._state.get(e);r&&r.time>0&&(this._tickOffset.cancel(r.time),this._state.cancel(r.time))}return this._state.cancel(e),this._state.setStateAtTime("stopped",e),this.setTicksAtTime(0,e),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e),this}pause(t){let e=this.toSeconds(t);return this._state.getValueAtTime(e)==="started"&&(this._state.setStateAtTime("paused",e),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e)),this}cancel(t){return t=this.toSeconds(t),this._state.cancel(t),this._tickOffset.cancel(t),this._ticksAtTime.cancel(t),this._secondsAtTime.cancel(t),this}getTicksAtTime(t){let e=this.toSeconds(t),r=this._state.getLastState("stopped",e),n=this._ticksAtTime.get(e),s={state:"paused",time:e};this._state.add(s);let a=n||r,i=n?n.ticks:0,c=null;return this._state.forEachBetween(a.time,e+this.sampleTime,u=>{let l=a.time,h=this._tickOffset.get(u.time);h&&h.time>=a.time&&(i=h.ticks,l=h.time),a.state==="started"&&u.state!=="started"&&(i+=this.frequency.getTicksAtTime(u.time)-this.frequency.getTicksAtTime(l),u.time!==s.time&&(c={state:u.state,time:u.time,ticks:i})),a=u}),this._state.remove(s),c&&this._ticksAtTime.add(c),i}get ticks(){return this.getTicksAtTime(this.now())}set ticks(t){this.setTicksAtTime(t,this.now())}get seconds(){return this.getSecondsAtTime(this.now())}set seconds(t){let e=this.now(),r=this.frequency.timeToTicks(t,e);this.setTicksAtTime(r,e)}getSecondsAtTime(t){t=this.toSeconds(t);let e=this._state.getLastState("stopped",t),r={state:"paused",time:t};this._state.add(r);let n=this._secondsAtTime.get(t),s=n||e,a=n?n.seconds:0,i=null;return this._state.forEachBetween(s.time,t+this.sampleTime,c=>{let u=s.time,l=this._tickOffset.get(c.time);l&&l.time>=s.time&&(a=l.seconds,u=l.time),s.state==="started"&&c.state!=="started"&&(a+=c.time-u,c.time!==r.time&&(i={state:c.state,time:c.time,seconds:a})),s=c}),this._state.remove(r),i&&this._secondsAtTime.add(i),a}setTicksAtTime(t,e){return e=this.toSeconds(e),this._tickOffset.cancel(e),this._tickOffset.add({seconds:this.frequency.getDurationOfTicks(t,e),ticks:t,time:e}),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e),this}getStateAtTime(t){return t=this.toSeconds(t),this._state.getValueAtTime(t)}getTimeOfTick(t,e=this.now()){let r=this._tickOffset.get(e),n=this._state.get(e),s=Math.max(r.time,n.time),a=this.frequency.getTicksAtTime(s)+t-r.ticks;return this.frequency.getTimeOfTick(a)}forEachTickBetween(t,e,r){let n=this._state.get(t);this._state.forEachBetween(t,e,a=>{n&&n.state==="started"&&a.state!=="started"&&this.forEachTickBetween(Math.max(n.time,t),a.time-this.sampleTime,r),n=a});let s=null;if(n&&n.state==="started"){let a=Math.max(n.time,t),i=this.frequency.getTicksAtTime(a),c=this.frequency.getTicksAtTime(n.time),u=i-c,l=Math.ceil(u)-u;l=Kt(l,1)?0:l;let h=this.frequency.getTimeOfTick(i+l);for(;h<e;){try{r(h,Math.round(this.getTicksAtTime(h)))}catch(p){s=p;break}h+=this.frequency.getDurationOfTicks(1,h)}}if(s)throw s;return this}dispose(){return super.dispose(),this._state.dispose(),this._tickOffset.dispose(),this._ticksAtTime.dispose(),this._secondsAtTime.dispose(),this.frequency.dispose(),this}};var sr=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments,["callback","frequency"]);super(t),this.name="Clock",this.callback=X,this._lastUpdate=0,this._state=new Ne("stopped"),this._boundLoop=this._loop.bind(this),this.callback=t.callback,this._tickSource=new Gn({context:this.context,frequency:t.frequency,units:t.units}),this._lastUpdate=0,this.frequency=this._tickSource.frequency,G(this,"frequency"),this._state.setStateAtTime("stopped",0),this.context.on("tick",this._boundLoop)}static getDefaults(){return Object.assign(gt.getDefaults(),{callback:X,frequency:1,units:"hertz"})}get state(){return this._state.getValueAtTime(this.now())}start(t,e){Fn(this.context);let r=this.toSeconds(t);return this.log("start",r),this._state.getValueAtTime(r)!=="started"&&(this._state.setStateAtTime("started",r),this._tickSource.start(r,e),r<this._lastUpdate&&this.emit("start",r,e)),this}stop(t){let e=this.toSeconds(t);return this.log("stop",e),this._state.cancel(e),this._state.setStateAtTime("stopped",e),this._tickSource.stop(e),e<this._lastUpdate&&this.emit("stop",e),this}pause(t){let e=this.toSeconds(t);return this._state.getValueAtTime(e)==="started"&&(this._state.setStateAtTime("paused",e),this._tickSource.pause(e),e<this._lastUpdate&&this.emit("pause",e)),this}get ticks(){return Math.ceil(this.getTicksAtTime(this.now()))}set ticks(t){this._tickSource.ticks=t}get seconds(){return this._tickSource.seconds}set seconds(t){this._tickSource.seconds=t}getSecondsAtTime(t){return this._tickSource.getSecondsAtTime(t)}setTicksAtTime(t,e){return this._tickSource.setTicksAtTime(t,e),this}getTimeOfTick(t,e=this.now()){return this._tickSource.getTimeOfTick(t,e)}getTicksAtTime(t){return this._tickSource.getTicksAtTime(t)}nextTickTime(t,e){let r=this.toSeconds(e),n=this.getTicksAtTime(r);return this._tickSource.getTimeOfTick(n+t,r)}_loop(){let t=this._lastUpdate,e=this.now();this._lastUpdate=e,this.log("loop",t,e),t!==e&&(this._state.forEachBetween(t,e,r=>{switch(r.state){case"started":let n=this._tickSource.getTicksAtTime(r.time);this.emit("start",r.time,n);break;case"stopped":r.time!==0&&this.emit("stop",r.time);break;case"paused":this.emit("pause",r.time);break}}),this._tickSource.forEachTickBetween(t,e,(r,n)=>{this.callback(r,n)}))}getStateAtTime(t){let e=this.toSeconds(t);return this._state.getValueAtTime(e)}dispose(){return super.dispose(),this.context.off("tick",this._boundLoop),this._tickSource.dispose(),this._state.dispose(),this}};ao.mixin(sr);var He=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["delayTime","maxDelay"]);super(t),this.name="Delay";let e=this.toSeconds(t.maxDelay);this._maxDelay=Math.max(e,this.toSeconds(t.delayTime)),this._delayNode=this.input=this.output=this.context.createDelay(e),this.delayTime=new H({context:this.context,param:this._delayNode.delayTime,units:"time",value:t.delayTime,minValue:0,maxValue:this.maxDelay}),G(this,"delayTime")}static getDefaults(){return Object.assign(N.getDefaults(),{delayTime:0,maxDelay:1})}get maxDelay(){return this._maxDelay}dispose(){return super.dispose(),this._delayNode.disconnect(),this.delayTime.dispose(),this}};var ae=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["volume"]);super(t),this.name="Volume",this.input=this.output=new A({context:this.context,gain:t.volume,units:"decibels"}),this.volume=this.output.gain,G(this,"volume"),this._unmutedVolume=t.volume,this.mute=t.mute}static getDefaults(){return Object.assign(N.getDefaults(),{mute:!1,volume:0})}get mute(){return this.volume.value===-1/0}set mute(t){!this.mute&&t?(this._unmutedVolume=this.volume.value,this.volume.value=-1/0):this.mute&&!t&&(this.volume.value=this._unmutedVolume)}dispose(){return super.dispose(),this.input.dispose(),this.volume.dispose(),this}};var hi=class o extends N{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="Destination",this.input=new ae({context:this.context}),this.output=new A({context:this.context}),this.volume=this.input.volume,ie(this.input,this.output,this.context.rawContext.destination),this.mute=t.mute,this._internalChannels=[this.input,this.context.rawContext.destination,this.output]}static getDefaults(){return Object.assign(N.getDefaults(),{mute:!1,volume:0})}get mute(){return this.input.mute}set mute(t){this.input.mute=t}chain(...t){return this.input.disconnect(),t.unshift(this.input),t.push(this.output),ie(...t),this}get maxChannelCount(){return this.context.rawContext.destination.maxChannelCount}dispose(){return super.dispose(),this.volume.dispose(),this}};so(o=>{o.destination=new hi({context:o})});io(o=>{o.destination.dispose()});var pi=class extends N{constructor(){super(...arguments),this.name="Listener",this.positionX=new H({context:this.context,param:this.context.rawContext.listener.positionX}),this.positionY=new H({context:this.context,param:this.context.rawContext.listener.positionY}),this.positionZ=new H({context:this.context,param:this.context.rawContext.listener.positionZ}),this.forwardX=new H({context:this.context,param:this.context.rawContext.listener.forwardX}),this.forwardY=new H({context:this.context,param:this.context.rawContext.listener.forwardY}),this.forwardZ=new H({context:this.context,param:this.context.rawContext.listener.forwardZ}),this.upX=new H({context:this.context,param:this.context.rawContext.listener.upX}),this.upY=new H({context:this.context,param:this.context.rawContext.listener.upY}),this.upZ=new H({context:this.context,param:this.context.rawContext.listener.upZ})}static getDefaults(){return Object.assign(N.getDefaults(),{positionX:0,positionY:0,positionZ:0,forwardX:0,forwardY:0,forwardZ:-1,upX:0,upY:1,upZ:0})}dispose(){return super.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this.forwardX.dispose(),this.forwardY.dispose(),this.forwardZ.dispose(),this.upX.dispose(),this.upY.dispose(),this.upZ.dispose(),this}};so(o=>{o.listener=new pi({context:o})});io(o=>{o.listener.dispose()});var ir=class o extends It{constructor(){super(),this.name="ToneAudioBuffers",this._buffers=new Map,this._loadingCount=0;let t=x(o.getDefaults(),arguments,["urls","onload","baseUrl"],"urls");this.baseUrl=t.baseUrl,Object.keys(t.urls).forEach(e=>{this._loadingCount++;let r=t.urls[e];this.add(e,r,this._bufferLoaded.bind(this,t.onload),t.onerror)})}static getDefaults(){return{baseUrl:"",onerror:X,onload:X,urls:{}}}has(t){return this._buffers.has(t.toString())}get(t){return j(this.has(t),`ToneAudioBuffers has no buffer named: ${t}`),this._buffers.get(t.toString())}_bufferLoaded(t){this._loadingCount--,this._loadingCount===0&&t&&t()}get loaded(){return Array.from(this._buffers).every(([t,e])=>e.loaded)}add(t,e,r=X,n=X){return Ut(e)?(this.baseUrl&&e.trim().substring(0,11).toLowerCase()==="data:audio/"&&(this.baseUrl=""),this._buffers.set(t.toString(),new At(this.baseUrl+e,r,n))):this._buffers.set(t.toString(),new At(e,r,n)),this}dispose(){return super.dispose(),this._buffers.forEach(t=>t.dispose()),this._buffers.clear(),this}};var Pt=class extends ye{constructor(){super(...arguments),this.name="Ticks",this.defaultUnits="i"}_now(){return this.context.transport.ticks}_beatsToUnits(t){return this._getPPQ()*t}_secondsToUnits(t){return Math.floor(t/(60/this._getBpm())*this._getPPQ())}_ticksToUnits(t){return t}toTicks(){return this.valueOf()}toSeconds(){return this.valueOf()/this._getPPQ()*(60/this._getBpm())}};var mi=class extends gt{constructor(){super(...arguments),this.name="Draw",this.expiration=.25,this.anticipation=.008,this._events=new Ft,this._boundDrawLoop=this._drawLoop.bind(this),this._animationFrame=-1}schedule(t,e){return this._events.add({callback:t,time:this.toSeconds(e)}),this._events.length===1&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop)),this}cancel(t){return this._events.cancel(this.toSeconds(t)),this}_drawLoop(){let t=this.context.currentTime;this._events.forEachBefore(t+this.anticipation,e=>{t-e.time<=this.expiration&&e.callback(),this._events.remove(e)}),this._events.length>0&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop))}dispose(){return super.dispose(),this._events.dispose(),cancelAnimationFrame(this._animationFrame),this}};so(o=>{o.draw=new mi({context:o})});io(o=>{o.draw.dispose()});var Wn=class extends It{constructor(){super(...arguments),this.name="IntervalTimeline",this._root=null,this._length=0}add(t){j(Z(t.time),"Events must have a time property"),j(Z(t.duration),"Events must have a duration parameter"),t.time=t.time.valueOf();let e=new di(t.time,t.time+t.duration,t);for(this._root===null?this._root=e:this._root.insert(e),this._length++;e!==null;)e.updateHeight(),e.updateMax(),this._rebalance(e),e=e.parent;return this}remove(t){if(this._root!==null){let e=[];this._root.search(t.time,e);for(let r of e)if(r.event===t){this._removeNode(r),this._length--;break}}return this}get length(){return this._length}cancel(t){return this.forEachFrom(t,e=>this.remove(e)),this}_setRoot(t){this._root=t,this._root!==null&&(this._root.parent=null)}_replaceNodeInParent(t,e){t.parent!==null?(t.isLeftChild()?t.parent.left=e:t.parent.right=e,this._rebalance(t.parent)):this._setRoot(e)}_removeNode(t){if(t.left===null&&t.right===null)this._replaceNodeInParent(t,null);else if(t.right===null)this._replaceNodeInParent(t,t.left);else if(t.left===null)this._replaceNodeInParent(t,t.right);else{let e=t.getBalance(),r,n=null;if(e>0)if(t.left.right===null)r=t.left,r.right=t.right,n=r;else{for(r=t.left.right;r.right!==null;)r=r.right;r.parent&&(r.parent.right=r.left,n=r.parent,r.left=t.left,r.right=t.right)}else if(t.right.left===null)r=t.right,r.left=t.left,n=r;else{for(r=t.right.left;r.left!==null;)r=r.left;r.parent&&(r.parent.left=r.right,n=r.parent,r.left=t.left,r.right=t.right)}t.parent!==null?t.isLeftChild()?t.parent.left=r:t.parent.right=r:this._setRoot(r),n&&this._rebalance(n)}t.dispose()}_rotateLeft(t){let e=t.parent,r=t.isLeftChild(),n=t.right;n&&(t.right=n.left,n.left=t),e!==null?r?e.left=n:e.right=n:this._setRoot(n)}_rotateRight(t){let e=t.parent,r=t.isLeftChild(),n=t.left;n&&(t.left=n.right,n.right=t),e!==null?r?e.left=n:e.right=n:this._setRoot(n)}_rebalance(t){let e=t.getBalance();e>1&&t.left?t.left.getBalance()<0?this._rotateLeft(t.left):this._rotateRight(t):e<-1&&t.right&&(t.right.getBalance()>0?this._rotateRight(t.right):this._rotateLeft(t))}get(t){if(this._root!==null){let e=[];if(this._root.search(t,e),e.length>0){let r=e[0];for(let n=1;n<e.length;n++)e[n].low>r.low&&(r=e[n]);return r.event}}return null}forEach(t){if(this._root!==null){let e=[];this._root.traverse(r=>e.push(r)),e.forEach(r=>{r.event&&t(r.event)})}return this}forEachAtTime(t,e){if(this._root!==null){let r=[];this._root.search(t,r),r.forEach(n=>{n.event&&e(n.event)})}return this}forEachFrom(t,e){if(this._root!==null){let r=[];this._root.searchAfter(t,r),r.forEach(n=>{n.event&&e(n.event)})}return this}dispose(){return super.dispose(),this._root!==null&&this._root.traverse(t=>t.dispose()),this._root=null,this}},di=class{constructor(t,e,r){this._left=null,this._right=null,this.parent=null,this.height=0,this.event=r,this.low=t,this.high=e,this.max=this.high}insert(t){t.low<=this.low?this.left===null?this.left=t:this.left.insert(t):this.right===null?this.right=t:this.right.insert(t)}search(t,e){t>this.max||(this.left!==null&&this.left.search(t,e),this.low<=t&&this.high>t&&e.push(this),!(this.low>t)&&this.right!==null&&this.right.search(t,e))}searchAfter(t,e){this.low>=t&&(e.push(this),this.left!==null&&this.left.searchAfter(t,e)),this.right!==null&&this.right.searchAfter(t,e)}traverse(t){t(this),this.left!==null&&this.left.traverse(t),this.right!==null&&this.right.traverse(t)}updateHeight(){this.left!==null&&this.right!==null?this.height=Math.max(this.left.height,this.right.height)+1:this.right!==null?this.height=this.right.height+1:this.left!==null?this.height=this.left.height+1:this.height=0}updateMax(){this.max=this.high,this.left!==null&&(this.max=Math.max(this.max,this.left.max)),this.right!==null&&(this.max=Math.max(this.max,this.right.max))}getBalance(){let t=0;return this.left!==null&&this.right!==null?t=this.left.height-this.right.height:this.left!==null?t=this.left.height+1:this.right!==null&&(t=-(this.right.height+1)),t}isLeftChild(){return this.parent!==null&&this.parent.left===this}get left(){return this._left}set left(t){this._left=t,t!==null&&(t.parent=this),this.updateHeight(),this.updateMax()}get right(){return this._right}set right(t){this._right=t,t!==null&&(t.parent=this),this.updateHeight(),this.updateMax()}dispose(){this.parent=null,this._left=null,this._right=null,this.event=null}};var Bn=class extends It{constructor(t){super(),this.name="TimelineValue",this._timeline=new Ft({memory:10}),this._initialValue=t}set(t,e){return this._timeline.add({value:t,time:e}),this}get(t){let e=this._timeline.get(t);return e?e.value:this._initialValue}};var qt=class o extends N{constructor(){super(x(o.getDefaults(),arguments,["context"]))}connect(t,e=0,r=0){return ko(this,t,e,r),this}};var Xt=class o extends qt{constructor(){let t=x(o.getDefaults(),arguments,["mapping","length"]);super(t),this.name="WaveShaper",this._shaper=this.context.createWaveShaper(),this.input=this._shaper,this.output=this._shaper,Et(t.mapping)||t.mapping instanceof Float32Array?this.curve=Float32Array.from(t.mapping):Hh(t.mapping)&&this.setMap(t.mapping,t.length)}static getDefaults(){return Object.assign($.getDefaults(),{length:1024})}setMap(t,e=1024){let r=new Float32Array(e);for(let n=0,s=e;n<s;n++){let a=n/(s-1)*2-1;r[n]=t(a,n)}return this.curve=r,this}get curve(){return this._shaper.curve}set curve(t){this._shaper.curve=t}get oversample(){return this._shaper.oversample}set oversample(t){let e=["none","2x","4x"].some(r=>r.includes(t));j(e,"oversampling must be either 'none', '2x', or '4x'"),this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.disconnect(),this}};var ar=class o extends qt{constructor(){let t=x(o.getDefaults(),arguments,["value"]);super(t),this.name="Pow",this._exponentScaler=this.input=this.output=new Xt({context:this.context,mapping:this._expFunc(t.value),length:8192}),this._exponent=t.value}static getDefaults(){return Object.assign(qt.getDefaults(),{value:1})}_expFunc(t){return e=>Math.pow(Math.abs(e),t)}get value(){return this._exponent}set value(t){this._exponent=t,this._exponentScaler.setMap(this._expFunc(this._exponent))}dispose(){return super.dispose(),this._exponentScaler.dispose(),this}};var $e=class o{constructor(t,e){this.id=o._eventId++,this._remainderTime=0;let r=Object.assign(o.getDefaults(),e);this.transport=t,this.callback=r.callback,this._once=r.once,this.time=Math.floor(r.time),this._remainderTime=r.time-this.time}static getDefaults(){return{callback:X,once:!1,time:0}}get floatTime(){return this.time+this._remainderTime}invoke(t){if(this.callback){let e=this.transport.bpm.getDurationOfTicks(1,t);this.callback(t+this._remainderTime*e),this._once&&this.transport.clear(this.id)}}dispose(){return this.callback=void 0,this}};$e._eventId=0;var jn=class o extends $e{constructor(t,e){super(t,e),this._currentId=-1,this._nextId=-1,this._nextTick=this.time,this._boundRestart=this._restart.bind(this);let r=Object.assign(o.getDefaults(),e);this.duration=r.duration,this._interval=r.interval,this._nextTick=r.time,this.transport.on("start",this._boundRestart),this.transport.on("loopStart",this._boundRestart),this.transport.on("ticks",this._boundRestart),this.context=this.transport.context,this._restart()}static getDefaults(){return Object.assign({},$e.getDefaults(),{duration:1/0,interval:1,once:!1})}invoke(t){this._createEvents(t),super.invoke(t)}_createEvent(){return wo(this._nextTick,this.floatTime+this.duration)?this.transport.scheduleOnce(this.invoke.bind(this),new Pt(this.context,this._nextTick).toSeconds()):-1}_createEvents(t){wo(this._nextTick+this._interval,this.floatTime+this.duration)&&(this._nextTick+=this._interval,this._currentId=this._nextId,this._nextId=this.transport.scheduleOnce(this.invoke.bind(this),new Pt(this.context,this._nextTick).toSeconds()))}_restart(t){this.transport.clear(this._currentId),this.transport.clear(this._nextId),this._nextTick=this.floatTime;let e=this.transport.getTicksAtTime(t);Ue(e,this.time)&&(this._nextTick=this.floatTime+Math.ceil((e-this.floatTime)/this._interval)*this._interval),this._currentId=this._createEvent(),this._nextTick+=this._interval,this._nextId=this._createEvent()}dispose(){return super.dispose(),this.transport.clear(this._currentId),this.transport.clear(this._nextId),this.transport.off("start",this._boundRestart),this.transport.off("loopStart",this._boundRestart),this.transport.off("ticks",this._boundRestart),this}};var zn=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="Transport",this._loop=new Bn(!1),this._loopStart=0,this._loopEnd=0,this._scheduledEvents={},this._timeline=new Ft,this._repeatedEvents=new Wn,this._syncedSignals=[],this._swingAmount=0,this._ppq=t.ppq,this._clock=new sr({callback:this._processTick.bind(this),context:this.context,frequency:0,units:"bpm"}),this._bindClockEvents(),this.bpm=this._clock.frequency,this._clock.frequency.multiplier=t.ppq,this.bpm.setValueAtTime(t.bpm,0),G(this,"bpm"),this._timeSignature=t.timeSignature,this._swingTicks=t.ppq/2}static getDefaults(){return Object.assign(gt.getDefaults(),{bpm:120,loopEnd:"4m",loopStart:0,ppq:192,swing:0,swingSubdivision:"8n",timeSignature:4})}_processTick(t,e){if(this._loop.get(t)&&e>=this._loopEnd&&(this.emit("loopEnd",t),this._clock.setTicksAtTime(this._loopStart,t),e=this._loopStart,this.emit("loopStart",t,this._clock.getSecondsAtTime(t)),this.emit("loop",t)),this._swingAmount>0&&e%this._ppq!==0&&e%(this._swingTicks*2)!==0){let r=e%(this._swingTicks*2)/(this._swingTicks*2),n=Math.sin(r*Math.PI)*this._swingAmount;t+=new Pt(this.context,this._swingTicks*2/3).toSeconds()*n}si(!0),this._timeline.forEachAtTime(e,r=>r.invoke(t)),si(!1)}schedule(t,e){let r=new $e(this,{callback:t,time:new ye(this.context,e).toTicks()});return this._addEvent(r,this._timeline)}scheduleRepeat(t,e,r,n=1/0){let s=new jn(this,{callback:t,duration:new he(this.context,n).toTicks(),interval:new he(this.context,e).toTicks(),time:new ye(this.context,r).toTicks()});return this._addEvent(s,this._repeatedEvents)}scheduleOnce(t,e){let r=new $e(this,{callback:t,once:!0,time:new ye(this.context,e).toTicks()});return this._addEvent(r,this._timeline)}clear(t){if(this._scheduledEvents.hasOwnProperty(t)){let e=this._scheduledEvents[t.toString()];e.timeline.remove(e.event),e.event.dispose(),delete this._scheduledEvents[t.toString()]}return this}_addEvent(t,e){return this._scheduledEvents[t.id.toString()]={event:t,timeline:e},e.add(t),t.id}cancel(t=0){let e=this.toTicks(t);return this._timeline.forEachFrom(e,r=>this.clear(r.id)),this._repeatedEvents.forEachFrom(e,r=>this.clear(r.id)),this}_bindClockEvents(){this._clock.on("start",(t,e)=>{e=new Pt(this.context,e).toSeconds(),this.emit("start",t,e)}),this._clock.on("stop",t=>{this.emit("stop",t)}),this._clock.on("pause",t=>{this.emit("pause",t)})}get state(){return this._clock.getStateAtTime(this.now())}start(t,e){this.context.resume();let r;return Z(e)&&(r=this.toTicks(e)),this._clock.start(t,r),this}stop(t){return this._clock.stop(t),this}pause(t){return this._clock.pause(t),this}toggle(t){return t=this.toSeconds(t),this._clock.getStateAtTime(t)!=="started"?this.start(t):this.stop(t),this}get timeSignature(){return this._timeSignature}set timeSignature(t){Et(t)&&(t=t[0]/t[1]*4),this._timeSignature=t}get loopStart(){return new he(this.context,this._loopStart,"i").toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t)}get loopEnd(){return new he(this.context,this._loopEnd,"i").toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t)}get loop(){return this._loop.get(this.now())}set loop(t){this._loop.set(t,this.now())}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get swing(){return this._swingAmount}set swing(t){this._swingAmount=t}get swingSubdivision(){return new Pt(this.context,this._swingTicks).toNotation()}set swingSubdivision(t){this._swingTicks=this.toTicks(t)}get position(){let t=this.now(),e=this._clock.getTicksAtTime(t);return new Pt(this.context,e).toBarsBeatsSixteenths()}set position(t){let e=this.toTicks(t);this.ticks=e}get seconds(){return this._clock.seconds}set seconds(t){let e=this.now(),r=this._clock.frequency.timeToTicks(t,e);this.ticks=r}get progress(){if(this.loop){let t=this.now();return(this._clock.getTicksAtTime(t)-this._loopStart)/(this._loopEnd-this._loopStart)}else return 0}get ticks(){return this._clock.ticks}set ticks(t){if(this._clock.ticks!==t){let e=this.now();if(this.state==="started"){let r=this._clock.getTicksAtTime(e),n=this._clock.frequency.getDurationOfTicks(Math.ceil(r)-r,e),s=e+n;this.emit("stop",s),this._clock.setTicksAtTime(t,s),this.emit("start",s,this._clock.getSecondsAtTime(s))}else this.emit("ticks",e),this._clock.setTicksAtTime(t,e)}}getTicksAtTime(t){return this._clock.getTicksAtTime(t)}getSecondsAtTime(t){return this._clock.getSecondsAtTime(t)}get PPQ(){return this._clock.frequency.multiplier}set PPQ(t){this._clock.frequency.multiplier=t}nextSubdivision(t){if(t=this.toTicks(t),this.state!=="started")return 0;{let e=this.now(),r=this.getTicksAtTime(e),n=t-r%t;return this._clock.nextTickTime(n,e)}}syncSignal(t,e){let r=this.now(),n=this.bpm,s=1/(60/n.getValueAtTime(r)/this.PPQ),a=[];if(t.units==="time"){let c=.015625/s,u=new A(c),l=new ar(-1),h=new A(c);n.chain(u,l,h),n=h,s=1/s,a=[u,l,h]}e||(t.getValueAtTime(r)!==0?e=t.getValueAtTime(r)/s:e=0);let i=new A(e);return n.connect(i),i.connect(t._param),a.push(i),this._syncedSignals.push({initial:t.value,nodes:a,signal:t}),t.value=0,this}unsyncSignal(t){for(let e=this._syncedSignals.length-1;e>=0;e--){let r=this._syncedSignals[e];r.signal===t&&(r.nodes.forEach(n=>n.dispose()),r.signal.value=r.initial,this._syncedSignals.splice(e,1))}return this}dispose(){return super.dispose(),this._clock.dispose(),So(this,"bpm"),this._timeline.dispose(),this._repeatedEvents.dispose(),this}};ao.mixin(zn);so(o=>{o.transport=new zn({context:o})});io(o=>{o.transport.dispose()});var rt=class extends N{constructor(t){super(t),this.input=void 0,this._state=new Ne("stopped"),this._synced=!1,this._scheduled=[],this._syncedStart=X,this._syncedStop=X,this._state.memory=100,this._state.increasing=!0,this._volume=this.output=new ae({context:this.context,mute:t.mute,volume:t.volume}),this.volume=this._volume.volume,G(this,"volume"),this.onstop=t.onstop}static getDefaults(){return Object.assign(N.getDefaults(),{mute:!1,onstop:X,volume:0})}get state(){return this._synced?this.context.transport.state==="started"?this._state.getValueAtTime(this.context.transport.seconds):"stopped":this._state.getValueAtTime(this.now())}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}_clampToCurrentTime(t){return this._synced?t:Math.max(t,this.context.currentTime)}start(t,e,r){let n=Ot(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(n=this._clampToCurrentTime(n),!this._synced&&this._state.getValueAtTime(n)==="started")j(Ue(n,this._state.get(n).time),"Start time must be strictly greater than previous start time"),this._state.cancel(n),this._state.setStateAtTime("started",n),this.log("restart",n),this.restart(n,e,r);else if(this.log("start",n),this._state.setStateAtTime("started",n),this._synced){let s=this._state.get(n);s&&(s.offset=this.toSeconds(ne(e,0)),s.duration=r?this.toSeconds(r):void 0);let a=this.context.transport.schedule(i=>{this._start(i,e,r)},n);this._scheduled.push(a),this.context.transport.state==="started"&&this.context.transport.getSecondsAtTime(this.immediate())>n&&this._syncedStart(this.now(),this.context.transport.seconds)}else Fn(this.context),this._start(n,e,r);return this}stop(t){let e=Ot(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(e=this._clampToCurrentTime(e),this._state.getValueAtTime(e)==="started"||Z(this._state.getNextState("started",e))){if(this.log("stop",e),!this._synced)this._stop(e);else{let r=this.context.transport.schedule(this._stop.bind(this),e);this._scheduled.push(r)}this._state.cancel(e),this._state.setStateAtTime("stopped",e)}return this}restart(t,e,r){return t=this.toSeconds(t),this._state.getValueAtTime(t)==="started"&&(this._state.cancel(t),this._restart(t,e,r)),this}sync(){return this._synced||(this._synced=!0,this._syncedStart=(t,e)=>{if(Ue(e,0)){let r=this._state.get(e);if(r&&r.state==="started"&&r.time!==e){let n=e-this.toSeconds(r.time),s;r.duration&&(s=this.toSeconds(r.duration)-n),this._start(t,this.toSeconds(r.offset)+n,s)}}},this._syncedStop=t=>{let e=this.context.transport.getSecondsAtTime(Math.max(t-this.sampleTime,0));this._state.getValueAtTime(e)==="started"&&this._stop(t)},this.context.transport.on("start",this._syncedStart),this.context.transport.on("loopStart",this._syncedStart),this.context.transport.on("stop",this._syncedStop),this.context.transport.on("pause",this._syncedStop),this.context.transport.on("loopEnd",this._syncedStop)),this}unsync(){return this._synced&&(this.context.transport.off("stop",this._syncedStop),this.context.transport.off("pause",this._syncedStop),this.context.transport.off("loopEnd",this._syncedStop),this.context.transport.off("start",this._syncedStart),this.context.transport.off("loopStart",this._syncedStart)),this._synced=!1,this._scheduled.forEach(t=>this.context.transport.clear(t)),this._scheduled=[],this._state.cancel(0),this._stop(0),this}dispose(){return super.dispose(),this.onstop=X,this.unsync(),this._volume.dispose(),this._state.dispose(),this}};var Le=class o extends ke{constructor(){let t=x(o.getDefaults(),arguments,["url","onload"]);super(t),this.name="ToneBufferSource",this._source=this.context.createBufferSource(),this._internalChannels=[this._source],this._sourceStarted=!1,this._sourceStopped=!1,Wt(this._source,this._gainNode),this._source.onended=()=>this._stopSource(),this.playbackRate=new H({context:this.context,param:this._source.playbackRate,units:"positive",value:t.playbackRate}),this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this._buffer=new At(t.url,t.onload,t.onerror),this._internalChannels.push(this._source)}static getDefaults(){return Object.assign(ke.getDefaults(),{url:new At,loop:!1,loopEnd:0,loopStart:0,onload:X,onerror:X,playbackRate:1})}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t}get curve(){return this._curve}set curve(t){this._curve=t}start(t,e,r,n=1){j(this.buffer.loaded,"buffer is either not set or not loaded");let s=this.toSeconds(t);this._startGain(s,n),this.loop?e=ne(e,this.loopStart):e=ne(e,0);let a=Math.max(this.toSeconds(e),0);if(this.loop){let i=this.toSeconds(this.loopEnd)||this.buffer.duration,c=this.toSeconds(this.loopStart),u=i-c;Br(a,i)&&(a=(a-c)%u+c),Kt(a,this.buffer.duration)&&(a=0)}if(this._source.buffer=this.buffer.get(),this._source.loopEnd=this.toSeconds(this.loopEnd)||this.buffer.duration,wo(a,this.buffer.duration)&&(this._sourceStarted=!0,this._source.start(s,a)),Z(r)){let i=this.toSeconds(r);i=Math.max(i,0),this.stop(s+i)}return this}_stopSource(t){!this._sourceStopped&&this._sourceStarted&&(this._sourceStopped=!0,this._source.stop(this.toSeconds(t)),this._onended())}get loopStart(){return this._source.loopStart}set loopStart(t){this._source.loopStart=this.toSeconds(t)}get loopEnd(){return this._source.loopEnd}set loopEnd(t){this._source.loopEnd=this.toSeconds(t)}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._source.loop}set loop(t){this._source.loop=t,this._sourceStarted&&this.cancelStop()}dispose(){return super.dispose(),this._source.onended=null,this._source.disconnect(),this._buffer.dispose(),this.playbackRate.dispose(),this}};var Jt=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["type"]);super(t),this.name="Noise",this._source=null,this._playbackRate=t.playbackRate,this.type=t.type,this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut}static getDefaults(){return Object.assign(rt.getDefaults(),{fadeIn:0,fadeOut:0,playbackRate:1,type:"white"})}get type(){return this._type}set type(t){if(j(t in pp,"Noise: invalid type: "+t),this._type!==t&&(this._type=t,this.state==="started")){let e=this.now();this._stop(e),this._start(e)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._source&&(this._source.playbackRate.value=t)}_start(t){let e=pp[this._type];this._source=new Le({url:e,context:this.context,fadeIn:this._fadeIn,fadeOut:this._fadeOut,loop:!0,onended:()=>this.onstop(this),playbackRate:this._playbackRate}).connect(this.output),this._source.start(this.toSeconds(t),Math.random()*(e.duration-.001))}_stop(t){this._source&&(this._source.stop(this.toSeconds(t)),this._source=null)}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this._source&&(this._source.fadeIn=this._fadeIn)}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this._source&&(this._source.fadeOut=this._fadeOut)}_restart(t){this._stop(t),this._start(t)}dispose(){return super.dispose(),this._source&&this._source.disconnect(),this}},cr=44100*5,fi=2,Ye={brown:null,pink:null,white:null},pp={get brown(){if(!Ye.brown){let o=[];for(let t=0;t<fi;t++){let e=new Float32Array(cr);o[t]=e;let r=0;for(let n=0;n<cr;n++){let s=Math.random()*2-1;e[n]=(r+.02*s)/1.02,r=e[n],e[n]*=3.5}}Ye.brown=new At().fromArray(o)}return Ye.brown},get pink(){if(!Ye.pink){let o=[];for(let t=0;t<fi;t++){let e=new Float32Array(cr);o[t]=e;let r,n,s,a,i,c,u;r=n=s=a=i=c=u=0;for(let l=0;l<cr;l++){let h=Math.random()*2-1;r=.99886*r+h*.0555179,n=.99332*n+h*.0750759,s=.969*s+h*.153852,a=.8665*a+h*.3104856,i=.55*i+h*.5329522,c=-.7616*c-h*.016898,e[l]=r+n+s+a+i+c+u+h*.5362,e[l]*=.11,u=h*.115926}}Ye.pink=new At().fromArray(o)}return Ye.pink},get white(){if(!Ye.white){let o=[];for(let t=0;t<fi;t++){let e=new Float32Array(cr);o[t]=e;for(let r=0;r<cr;r++)e[r]=Math.random()*2-1}Ye.white=new At().fromArray(o)}return Ye.white}};function ce(o,t){return ot(this,void 0,void 0,function*(){let e=t/o.context.sampleRate,r=new Ce(1,e,o.context.sampleRate);return new o.constructor(Object.assign(o.get(),{frequency:2/e,detune:0,context:r})).toDestination().start(0),(yield r.render()).getChannelData(0)})}var zr=class o extends ke{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type"]);super(t),this.name="ToneOscillatorNode",this._oscillator=this.context.createOscillator(),this._internalChannels=[this._oscillator],Wt(this._oscillator,this._gainNode),this.type=t.type,this.frequency=new H({context:this.context,param:this._oscillator.frequency,units:"frequency",value:t.frequency}),this.detune=new H({context:this.context,param:this._oscillator.detune,units:"cents",value:t.detune}),G(this,["frequency","detune"])}static getDefaults(){return Object.assign(ke.getDefaults(),{detune:0,frequency:440,type:"sine"})}start(t){let e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._oscillator.start(e),this}_stopSource(t){this._oscillator.stop(t)}setPeriodicWave(t){return this._oscillator.setPeriodicWave(t),this}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t}dispose(){return super.dispose(),this.state==="started"&&this.stop(),this._oscillator.disconnect(),this.frequency.dispose(),this.detune.dispose(),this}};var ut=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type"]);super(t),this.name="Oscillator",this._oscillator=null,this.frequency=new $({context:this.context,units:"frequency",value:t.frequency}),G(this,"frequency"),this.detune=new $({context:this.context,units:"cents",value:t.detune}),G(this,"detune"),this._partials=t.partials,this._partialCount=t.partialCount,this._type=t.type,t.partialCount&&t.type!=="custom"&&(this._type=this.baseType+t.partialCount.toString()),this.phase=t.phase}static getDefaults(){return Object.assign(rt.getDefaults(),{detune:0,frequency:440,partialCount:0,partials:[],phase:0,type:"sine"})}_start(t){let e=this.toSeconds(t),r=new zr({context:this.context,onended:()=>this.onstop(this)});this._oscillator=r,this._wave?this._oscillator.setPeriodicWave(this._wave):this._oscillator.type=this._type,this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(e)}_stop(t){let e=this.toSeconds(t);this._oscillator&&this._oscillator.stop(e)}_restart(t){let e=this.toSeconds(t);return this.log("restart",e),this._oscillator&&this._oscillator.cancelStop(),this._state.cancel(e),this}syncFrequency(){return this.context.transport.syncSignal(this.frequency),this}unsyncFrequency(){return this.context.transport.unsyncSignal(this.frequency),this}_getCachedPeriodicWave(){if(this._type==="custom")return o._periodicWaveCache.find(e=>e.phase===this._phase&&rp(e.partials,this._partials));{let t=o._periodicWaveCache.find(e=>e.type===this._type&&e.phase===this._phase);return this._partialCount=t?t.partialCount:this._partialCount,t}}get type(){return this._type}set type(t){this._type=t;let e=["sine","square","sawtooth","triangle"].indexOf(t)!==-1;if(this._phase===0&&e)this._wave=void 0,this._partialCount=0,this._oscillator!==null&&(this._oscillator.type=t);else{let r=this._getCachedPeriodicWave();if(Z(r)){let{partials:n,wave:s}=r;this._wave=s,this._partials=n,this._oscillator!==null&&this._oscillator.setPeriodicWave(this._wave)}else{let[n,s]=this._getRealImaginary(t,this._phase),a=this.context.createPeriodicWave(n,s);this._wave=a,this._oscillator!==null&&this._oscillator.setPeriodicWave(this._wave),o._periodicWaveCache.push({imag:s,partialCount:this._partialCount,partials:this._partials,phase:this._phase,real:n,type:this._type,wave:this._wave}),o._periodicWaveCache.length>100&&o._periodicWaveCache.shift()}}}get baseType(){return this._type.replace(this.partialCount.toString(),"")}set baseType(t){this.partialCount&&this._type!=="custom"&&t!=="custom"?this.type=t+this.partialCount:this.type=t}get partialCount(){return this._partialCount}set partialCount(t){St(t,0);let e=this._type,r=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);if(r&&(e=r[1]),this._type!=="custom")t===0?this.type=e:this.type=e+t.toString();else{let n=new Float32Array(t);this._partials.forEach((s,a)=>n[a]=s),this._partials=Array.from(n),this.type=this._type}}_getRealImaginary(t,e){let n=2048,s=new Float32Array(n),a=new Float32Array(n),i=1;if(t==="custom"){if(i=this._partials.length+1,this._partialCount=this._partials.length,n=i,this._partials.length===0)return[s,a]}else{let c=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(t);c?(i=parseInt(c[2],10)+1,this._partialCount=parseInt(c[2],10),t=c[1],i=Math.max(i,2),n=i):this._partialCount=0,this._partials=[]}for(let c=1;c<n;++c){let u=2/(c*Math.PI),l;switch(t){case"sine":l=c<=i?1:0,this._partials[c-1]=l;break;case"square":l=c&1?2*u:0,this._partials[c-1]=l;break;case"sawtooth":l=u*(c&1?1:-1),this._partials[c-1]=l;break;case"triangle":c&1?l=2*(u*u)*(c-1>>1&1?-1:1):l=0,this._partials[c-1]=l;break;case"custom":l=this._partials[c-1];break;default:throw new TypeError("Oscillator: invalid type: "+t)}l!==0?(s[c]=-l*Math.sin(e*c),a[c]=l*Math.cos(e*c)):(s[c]=0,a[c]=0)}return[s,a]}_inverseFFT(t,e,r){let n=0,s=t.length;for(let a=0;a<s;a++)n+=t[a]*Math.cos(a*r)+e[a]*Math.sin(a*r);return n}getInitialValue(){let[t,e]=this._getRealImaginary(this._type,0),r=0,n=Math.PI*2,s=32;for(let a=0;a<s;a++)r=Math.max(this._inverseFFT(t,e,a/s*n),r);return ii(-this._inverseFFT(t,e,this._phase)/r,-1,1)}get partials(){return this._partials.slice(0,this.partialCount)}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this.type="custom")}get phase(){return this._phase*(180/Math.PI)}set phase(t){this._phase=t*Math.PI/180,this.type=this._type}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this._oscillator!==null&&this._oscillator.dispose(),this._wave=void 0,this.frequency.dispose(),this.detune.dispose(),this}};ut._periodicWaveCache=[];var Oo=class extends qt{constructor(){super(...arguments),this.name="AudioToGain",this._norm=new Xt({context:this.context,mapping:t=>(t+1)/2}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}};var bt=class o extends ${constructor(){let t=x(o.getDefaults(),arguments,["value"]);super(t),this.name="Multiply",this.override=!1,this._mult=this.input=this.output=new A({context:this.context,minValue:t.minValue,maxValue:t.maxValue}),this.factor=this._param=this._mult.gain,this.factor.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign($.getDefaults(),{value:0})}dispose(){return super.dispose(),this._mult.dispose(),this}};var Ur=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type","modulationType"]);super(t),this.name="AMOscillator",this._modulationScale=new Oo({context:this.context}),this._modulationNode=new A({context:this.context}),this._carrier=new ut({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.frequency=this._carrier.frequency,this.detune=this._carrier.detune,this._modulator=new ut({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new bt({context:this.context,units:"positive",value:t.harmonicity}),this.frequency.chain(this.harmonicity,this._modulator.frequency),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output),G(this,["frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(ut.getDefaults(),{harmonicity:1,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){this._modulator.restart(t),this._carrier.restart(t)}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this._modulationScale.dispose(),this}};var ur=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type","modulationType"]);super(t),this.name="FMOscillator",this._modulationNode=new A({context:this.context,gain:0}),this._carrier=new ut({context:this.context,detune:t.detune,frequency:0,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.detune=this._carrier.detune,this.frequency=new $({context:this.context,units:"frequency",value:t.frequency}),this._modulator=new ut({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new bt({context:this.context,units:"positive",value:t.harmonicity}),this.modulationIndex=new bt({context:this.context,units:"positive",value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output),this.detune.connect(this._modulator.detune),G(this,["modulationIndex","frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(ut.getDefaults(),{harmonicity:1,modulationIndex:2,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){return this._modulator.restart(t),this._carrier.restart(t),this}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this.frequency.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this.modulationIndex.dispose(),this}};var Eo=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","width"]);super(t),this.name="PulseOscillator",this._widthGate=new A({context:this.context,gain:0}),this._thresh=new Xt({context:this.context,mapping:e=>e<=0?-1:1}),this.width=new $({context:this.context,units:"audioRange",value:t.width}),this._triangle=new ut({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:"triangle"}),this.frequency=this._triangle.frequency,this.detune=this._triangle.detune,this._triangle.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh),G(this,["width","frequency","detune"])}static getDefaults(){return Object.assign(rt.getDefaults(),{detune:0,frequency:440,phase:0,type:"pulse",width:.2})}_start(t){t=this.toSeconds(t),this._triangle.start(t),this._widthGate.gain.setValueAtTime(1,t)}_stop(t){t=this.toSeconds(t),this._triangle.stop(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(0,t)}_restart(t){this._triangle.restart(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(1,t)}get phase(){return this._triangle.phase}set phase(t){this._triangle.phase=t}get type(){return"pulse"}get baseType(){return"pulse"}get partials(){return[]}get partialCount(){return 0}set carrierType(t){this._triangle.type=t}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this._triangle.dispose(),this.width.dispose(),this._widthGate.dispose(),this._thresh.dispose(),this}};var Hr=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type","spread"]);super(t),this.name="FatOscillator",this._oscillators=[],this.frequency=new $({context:this.context,units:"frequency",value:t.frequency}),this.detune=new $({context:this.context,units:"cents",value:t.detune}),this._spread=t.spread,this._type=t.type,this._phase=t.phase,this._partials=t.partials,this._partialCount=t.partialCount,this.count=t.count,G(this,["frequency","detune"])}static getDefaults(){return Object.assign(ut.getDefaults(),{count:3,spread:20,type:"sawtooth"})}_start(t){t=this.toSeconds(t),this._forEach(e=>e.start(t))}_stop(t){t=this.toSeconds(t),this._forEach(e=>e.stop(t))}_restart(t){this._forEach(e=>e.restart(t))}_forEach(t){for(let e=0;e<this._oscillators.length;e++)t(this._oscillators[e],e)}get type(){return this._type}set type(t){this._type=t,this._forEach(e=>e.type=t)}get spread(){return this._spread}set spread(t){if(this._spread=t,this._oscillators.length>1){let e=-t/2,r=t/(this._oscillators.length-1);this._forEach((n,s)=>n.detune.value=e+r*s)}}get count(){return this._oscillators.length}set count(t){if(St(t,1),this._oscillators.length!==t){this._forEach(e=>e.dispose()),this._oscillators=[];for(let e=0;e<t;e++){let r=new ut({context:this.context,volume:-6-t*1.1,type:this._type,phase:this._phase+e/t*360,partialCount:this._partialCount,onstop:e===0?()=>this.onstop(this):X});this.type==="custom"&&(r.partials=this._partials),this.frequency.connect(r.frequency),this.detune.connect(r.detune),r.detune.overridden=!1,r.connect(this.output),this._oscillators[e]=r}this.spread=this._spread,this.state==="started"&&this._forEach(e=>e.start())}}get phase(){return this._phase}set phase(t){this._phase=t,this._forEach((e,r)=>e.phase=this._phase+r/this.count*360)}get baseType(){return this._oscillators[0].baseType}set baseType(t){this._forEach(e=>e.baseType=t),this._type=this._oscillators[0].type}get partials(){return this._oscillators[0].partials}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this._type="custom",this._forEach(e=>e.partials=t))}get partialCount(){return this._oscillators[0].partialCount}set partialCount(t){this._partialCount=t,this._forEach(e=>e.partialCount=t),this._type=this._oscillators[0].type}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this._forEach(t=>t.dispose()),this}};var $r=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","modulationFrequency"]);super(t),this.name="PWMOscillator",this.sourceType="pwm",this._scale=new bt({context:this.context,value:2}),this._pulse=new Eo({context:this.context,frequency:t.modulationFrequency}),this._pulse.carrierType="sine",this.modulationFrequency=this._pulse.frequency,this._modulator=new ut({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase}),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),G(this,["modulationFrequency","frequency","detune"])}static getDefaults(){return Object.assign(rt.getDefaults(),{detune:0,frequency:440,modulationFrequency:.4,phase:0,type:"pwm"})}_start(t){t=this.toSeconds(t),this._modulator.start(t),this._pulse.start(t)}_stop(t){t=this.toSeconds(t),this._modulator.stop(t),this._pulse.stop(t)}_restart(t){this._modulator.restart(t),this._pulse.restart(t)}get type(){return"pwm"}get baseType(){return"pwm"}get partials(){return[]}get partialCount(){return 0}get phase(){return this._modulator.phase}set phase(t){this._modulator.phase=t}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this._pulse.dispose(),this._scale.dispose(),this._modulator.dispose(),this}};var mp={am:Ur,fat:Hr,fm:ur,oscillator:ut,pulse:Eo,pwm:$r},Xe=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type"]);super(t),this.name="OmniOscillator",this.frequency=new $({context:this.context,units:"frequency",value:t.frequency}),this.detune=new $({context:this.context,units:"cents",value:t.detune}),G(this,["frequency","detune"]),this.set(t)}static getDefaults(){return Object.assign(ut.getDefaults(),ur.getDefaults(),Ur.getDefaults(),Hr.getDefaults(),Eo.getDefaults(),$r.getDefaults())}_start(t){this._oscillator.start(t)}_stop(t){this._oscillator.stop(t)}_restart(t){return this._oscillator.restart(t),this}get type(){let t="";return["am","fm","fat"].some(e=>this._sourceType===e)&&(t=this._sourceType),t+this._oscillator.type}set type(t){t.substr(0,2)==="fm"?(this._createNewOscillator("fm"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):t.substr(0,2)==="am"?(this._createNewOscillator("am"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):t.substr(0,3)==="fat"?(this._createNewOscillator("fat"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(3)):t==="pwm"?(this._createNewOscillator("pwm"),this._oscillator=this._oscillator):t==="pulse"?this._createNewOscillator("pulse"):(this._createNewOscillator("oscillator"),this._oscillator=this._oscillator,this._oscillator.type=t)}get partials(){return this._oscillator.partials}set partials(t){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&(this._oscillator.partials=t)}get partialCount(){return this._oscillator.partialCount}set partialCount(t){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&(this._oscillator.partialCount=t)}set(t){return Reflect.has(t,"type")&&t.type&&(this.type=t.type),super.set(t),this}_createNewOscillator(t){if(t!==this._sourceType){this._sourceType=t;let e=mp[t],r=this.now();if(this._oscillator){let n=this._oscillator;n.stop(r),this.context.setTimeout(()=>n.dispose(),this.blockTime)}this._oscillator=new e({context:this.context}),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this._oscillator.onstop=()=>this.onstop(this),this.state==="started"&&this._oscillator.start(r)}}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t}get sourceType(){return this._sourceType}set sourceType(t){let e="sine";this._oscillator.type!=="pwm"&&this._oscillator.type!=="pulse"&&(e=this._oscillator.type),t==="fm"?this.type="fm"+e:t==="am"?this.type="am"+e:t==="fat"?this.type="fat"+e:t==="oscillator"?this.type=e:t==="pulse"?this.type="pulse":t==="pwm"&&(this.type="pwm")}_getOscType(t,e){return t instanceof mp[e]}get baseType(){return this._oscillator.baseType}set baseType(t){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&t!=="pulse"&&t!=="pwm"&&(this._oscillator.baseType=t)}get width(){if(this._getOscType(this._oscillator,"pulse"))return this._oscillator.width}get count(){if(this._getOscType(this._oscillator,"fat"))return this._oscillator.count}set count(t){this._getOscType(this._oscillator,"fat")&&Gt(t)&&(this._oscillator.count=t)}get spread(){if(this._getOscType(this._oscillator,"fat"))return this._oscillator.spread}set spread(t){this._getOscType(this._oscillator,"fat")&&Gt(t)&&(this._oscillator.spread=t)}get modulationType(){if(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))return this._oscillator.modulationType}set modulationType(t){(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))&&Ut(t)&&(this._oscillator.modulationType=t)}get modulationIndex(){if(this._getOscType(this._oscillator,"fm"))return this._oscillator.modulationIndex}get harmonicity(){if(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))return this._oscillator.harmonicity}get modulationFrequency(){if(this._getOscType(this._oscillator,"pwm"))return this._oscillator.modulationFrequency}asArray(){return ot(this,arguments,void 0,function*(t=1024){return ce(this,t)})}dispose(){return super.dispose(),this.detune.dispose(),this.frequency.dispose(),this._oscillator.dispose(),this}};var Mo=class o extends ${constructor(){super(x(o.getDefaults(),arguments,["value"])),this.override=!1,this.name="Add",this._sum=new A({context:this.context}),this.input=this._sum,this.output=this._sum,this.addend=this._param,ie(this._constantSource,this._sum)}static getDefaults(){return Object.assign($.getDefaults(),{value:0})}dispose(){return super.dispose(),this._sum.dispose(),this}};var uo=class o extends qt{constructor(){let t=x(o.getDefaults(),arguments,["min","max"]);super(t),this.name="Scale",this._mult=this.input=new bt({context:this.context,value:t.max-t.min}),this._add=this.output=new Mo({context:this.context,value:t.min}),this._min=t.min,this._max=t.max,this.input.connect(this.output)}static getDefaults(){return Object.assign(qt.getDefaults(),{max:1,min:0})}get min(){return this._min}set min(t){this._min=t,this._setRange()}get max(){return this._max}set max(t){this._max=t,this._setRange()}_setRange(){this._add.value=this._min,this._mult.value=this._max-this._min}dispose(){return super.dispose(),this._add.dispose(),this._mult.dispose(),this}};var Un=class o extends qt{constructor(){super(x(o.getDefaults(),arguments)),this.name="Zero",this._gain=new A({context:this.context}),this.output=this._gain,this.input=void 0,Wt(this.context.getConstant(0),this._gain)}dispose(){return super.dispose(),li(this.context.getConstant(0),this._gain),this}};var Oe=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["frequency","min","max"]);super(t),this.name="LFO",this._stoppedValue=0,this._units="number",this.convert=!0,this._fromType=H.prototype._fromType,this._toType=H.prototype._toType,this._is=H.prototype._is,this._clampValue=H.prototype._clampValue,this._oscillator=new ut(t),this.frequency=this._oscillator.frequency,this._amplitudeGain=new A({context:this.context,gain:t.amplitude,units:"normalRange"}),this.amplitude=this._amplitudeGain.gain,this._stoppedSignal=new $({context:this.context,units:"audioRange",value:0}),this._zeros=new Un({context:this.context}),this._a2g=new Oo({context:this.context}),this._scaler=this.output=new uo({context:this.context,max:t.max,min:t.min}),this.units=t.units,this.min=t.min,this.max=t.max,this._oscillator.chain(this._amplitudeGain,this._a2g,this._scaler),this._zeros.connect(this._a2g),this._stoppedSignal.connect(this._a2g),G(this,["amplitude","frequency"]),this.phase=t.phase}static getDefaults(){return Object.assign(ut.getDefaults(),{amplitude:1,frequency:"4n",max:1,min:0,type:"sine",units:"number"})}start(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(0,t),this._oscillator.start(t),this}stop(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(this._stoppedValue,t),this._oscillator.stop(t),this}sync(){return this._oscillator.sync(),this._oscillator.syncFrequency(),this}unsync(){return this._oscillator.unsync(),this._oscillator.unsyncFrequency(),this}_setStoppedValue(){this._stoppedValue=this._oscillator.getInitialValue(),this._stoppedSignal.value=this._stoppedValue}get min(){return this._toType(this._scaler.min)}set min(t){t=this._fromType(t),this._scaler.min=t}get max(){return this._toType(this._scaler.max)}set max(t){t=this._fromType(t),this._scaler.max=t}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t,this._setStoppedValue()}get partials(){return this._oscillator.partials}set partials(t){this._oscillator.partials=t,this._setStoppedValue()}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t,this._setStoppedValue()}get units(){return this._units}set units(t){let e=this.min,r=this.max;this._units=t,this.min=e,this.max=r}get state(){return this._oscillator.state}connect(t,e,r){return(t instanceof H||t instanceof $)&&(this.convert=t.convert,this.units=t.units),ko(this,t,e,r),this}dispose(){return super.dispose(),this._oscillator.dispose(),this._stoppedSignal.dispose(),this._zeros.dispose(),this._scaler.dispose(),this._a2g.dispose(),this._amplitudeGain.dispose(),this.amplitude.dispose(),this}};function Hn(o,t=1/0){let e=new WeakMap;return function(r,n){Reflect.defineProperty(r,n,{configurable:!0,enumerable:!0,get:function(){return e.get(this)},set:function(s){St(s,o,t),e.set(this,s)}})}}function ue(o,t=1/0){let e=new WeakMap;return function(r,n){Reflect.defineProperty(r,n,{configurable:!0,enumerable:!0,get:function(){return e.get(this)},set:function(s){St(this.toSeconds(s),o,t),e.set(this,s)}})}}var Yr=class o extends rt{constructor(){let t=x(o.getDefaults(),arguments,["url","onload"]);super(t),this.name="Player",this._activeSources=new Set,this._buffer=new At({onload:this._onload.bind(this,t.onload),onerror:t.onerror,reverse:t.reverse,url:t.url}),this.autostart=t.autostart,this._loop=t.loop,this._loopStart=t.loopStart,this._loopEnd=t.loopEnd,this._playbackRate=t.playbackRate,this.fadeIn=t.fadeIn,this.fadeOut=t.fadeOut}static getDefaults(){return Object.assign(rt.getDefaults(),{autostart:!1,fadeIn:0,fadeOut:0,loop:!1,loopEnd:0,loopStart:0,onload:X,onerror:X,playbackRate:1,reverse:!1})}load(t){return ot(this,void 0,void 0,function*(){return yield this._buffer.load(t),this._onload(),this})}_onload(t=X){t(),this.autostart&&this.start()}_onSourceEnd(t){this.onstop(this),this._activeSources.delete(t),this._activeSources.size===0&&!this._synced&&this._state.getValueAtTime(this.now())==="started"&&(this._state.cancel(this.now()),this._state.setStateAtTime("stopped",this.now()))}start(t,e,r){return super.start(t,e,r),this}_start(t,e,r){this._loop?e=ne(e,this._loopStart):e=ne(e,0);let n=this.toSeconds(e),s=r;r=ne(r,Math.max(this._buffer.duration-n,0));let a=this.toSeconds(r);a=a/this._playbackRate,t=this.toSeconds(t);let i=new Le({url:this._buffer,context:this.context,fadeIn:this.fadeIn,fadeOut:this.fadeOut,loop:this._loop,loopEnd:this._loopEnd,loopStart:this._loopStart,onended:this._onSourceEnd.bind(this),playbackRate:this._playbackRate}).connect(this.output);!this._loop&&!this._synced&&(this._state.cancel(t+a),this._state.setStateAtTime("stopped",t+a,{implicitEnd:!0})),this._activeSources.add(i),this._loop&&Ot(s)?i.start(t,n):i.start(t,n,a-this.toSeconds(this.fadeOut))}_stop(t){let e=this.toSeconds(t);this._activeSources.forEach(r=>r.stop(e))}restart(t,e,r){return super.restart(t,e,r),this}_restart(t,e,r){var n;(n=[...this._activeSources].pop())===null||n===void 0||n.stop(t),this._start(t,e,r)}seek(t,e){let r=this.toSeconds(e);if(this._state.getValueAtTime(r)==="started"){let n=this.toSeconds(t);this._stop(r),this._start(r,n)}return this}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get loopStart(){return this._loopStart}set loopStart(t){this._loopStart=t,this.buffer.loaded&&St(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach(e=>{e.loopStart=t})}get loopEnd(){return this._loopEnd}set loopEnd(t){this._loopEnd=t,this.buffer.loaded&&St(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach(e=>{e.loopEnd=t})}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._loop}set loop(t){if(this._loop!==t&&(this._loop=t,this._activeSources.forEach(e=>{e.loop=t}),t)){let e=this._state.getNextState("stopped",this.now());e&&this._state.cancel(e.time)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t;let e=this.now(),r=this._state.getNextState("stopped",e);r&&r.implicitEnd&&(this._state.cancel(r.time),this._activeSources.forEach(n=>n.cancelStop())),this._activeSources.forEach(n=>{n.playbackRate.setValueAtTime(t,e)})}get reverse(){return this._buffer.reverse}set reverse(t){this._buffer.reverse=t}get loaded(){return this._buffer.loaded}dispose(){return super.dispose(),this._activeSources.forEach(t=>t.dispose()),this._activeSources.clear(),this._buffer.dispose(),this}};$t([ue(0)],Yr.prototype,"fadeIn",void 0);$t([ue(0)],Yr.prototype,"fadeOut",void 0);var $n=class extends qt{constructor(){super(...arguments),this.name="GainToAudio",this._norm=new Xt({context:this.context,mapping:t=>Math.abs(t)*2-1}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}};var Bt=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["attack","decay","sustain","release"]);super(t),this.name="Envelope",this._sig=new $({context:this.context,value:0}),this.output=this._sig,this.input=void 0,this.attack=t.attack,this.decay=t.decay,this.sustain=t.sustain,this.release=t.release,this.attackCurve=t.attackCurve,this.releaseCurve=t.releaseCurve,this.decayCurve=t.decayCurve}static getDefaults(){return Object.assign(N.getDefaults(),{attack:.01,attackCurve:"linear",decay:.1,decayCurve:"exponential",release:1,releaseCurve:"exponential",sustain:.5})}get value(){return this.getValueAtTime(this.now())}_getCurve(t,e){if(Ut(t))return t;{let r;for(r in Yn)if(Yn[r][e]===t)return r;return t}}_setCurve(t,e,r){if(Ut(r)&&Reflect.has(Yn,r)){let n=Yn[r];Se(n)?t!=="_decayCurve"&&(this[t]=n[e]):this[t]=n}else if(Et(r)&&t!=="_decayCurve")this[t]=r;else throw new Error("Envelope: invalid curve: "+r)}get attackCurve(){return this._getCurve(this._attackCurve,"In")}set attackCurve(t){this._setCurve("_attackCurve","In",t)}get releaseCurve(){return this._getCurve(this._releaseCurve,"Out")}set releaseCurve(t){this._setCurve("_releaseCurve","Out",t)}get decayCurve(){return this._getCurve(this._decayCurve,"Out")}set decayCurve(t){this._setCurve("_decayCurve","Out",t)}triggerAttack(t,e=1){this.log("triggerAttack",t,e),t=this.toSeconds(t);let n=this.toSeconds(this.attack),s=this.toSeconds(this.decay),a=this.getValueAtTime(t);if(a>0){let i=1/n;n=(1-a)/i}if(n<this.sampleTime)this._sig.cancelScheduledValues(t),this._sig.setValueAtTime(e,t);else if(this._attackCurve==="linear")this._sig.linearRampTo(e,n,t);else if(this._attackCurve==="exponential")this._sig.targetRampTo(e,n,t);else{this._sig.cancelAndHoldAtTime(t);let i=this._attackCurve;for(let c=1;c<i.length;c++)if(i[c-1]<=a&&a<=i[c]){i=this._attackCurve.slice(c),i[0]=a;break}this._sig.setValueCurveAtTime(i,t,n,e)}if(s&&this.sustain<1){let i=e*this.sustain,c=t+n;this.log("decay",c),this._decayCurve==="linear"?this._sig.linearRampToValueAtTime(i,s+c):this._sig.exponentialApproachValueAtTime(i,c,s)}return this}triggerRelease(t){this.log("triggerRelease",t),t=this.toSeconds(t);let e=this.getValueAtTime(t);if(e>0){let r=this.toSeconds(this.release);r<this.sampleTime?this._sig.setValueAtTime(0,t):this._releaseCurve==="linear"?this._sig.linearRampTo(0,r,t):this._releaseCurve==="exponential"?this._sig.targetRampTo(0,r,t):(j(Et(this._releaseCurve),"releaseCurve must be either 'linear', 'exponential' or an array"),this._sig.cancelAndHoldAtTime(t),this._sig.setValueCurveAtTime(this._releaseCurve,t,r,e))}return this}getValueAtTime(t){return this._sig.getValueAtTime(t)}triggerAttackRelease(t,e,r=1){return e=this.toSeconds(e),this.triggerAttack(e,r),this.triggerRelease(e+this.toSeconds(t)),this}cancel(t){return this._sig.cancelScheduledValues(this.toSeconds(t)),this}connect(t,e=0,r=0){return ko(this,t,e,r),this}asArray(){return ot(this,arguments,void 0,function*(t=1024){let e=t/this.context.sampleRate,r=new Ce(1,e,this.context.sampleRate),n=this.toSeconds(this.attack)+this.toSeconds(this.decay),s=n+this.toSeconds(this.release),a=s*.1,i=s+a,c=new this.constructor(Object.assign(this.get(),{attack:e*this.toSeconds(this.attack)/i,decay:e*this.toSeconds(this.decay)/i,release:e*this.toSeconds(this.release)/i,context:r}));return c._sig.toDestination(),c.triggerAttackRelease(e*(n+a)/i,0),(yield r.render()).getChannelData(0)})}dispose(){return super.dispose(),this._sig.dispose(),this}};$t([ue(0)],Bt.prototype,"attack",void 0);$t([ue(0)],Bt.prototype,"decay",void 0);$t([Hn(0,1)],Bt.prototype,"sustain",void 0);$t([ue(0)],Bt.prototype,"release",void 0);var Yn=(()=>{let t,e,r=[];for(t=0;t<128;t++)r[t]=Math.sin(t/127*(Math.PI/2));let n=[],s=6.4;for(t=0;t<127;t++){e=t/127;let p=Math.sin(e*(Math.PI*2)*s-Math.PI/2)+1;n[t]=p/10+e*.83}n[127]=1;let a=[],i=5;for(t=0;t<128;t++)a[t]=Math.ceil(t/127*i)/i;let c=[];for(t=0;t<128;t++)e=t/127,c[t]=.5*(1-Math.cos(Math.PI*e));let u=[];for(t=0;t<128;t++){e=t/127;let p=Math.pow(e,3)*4+.2,m=Math.cos(p*Math.PI*2*e);u[t]=Math.abs(m*(1-e))}function l(p){let m=new Array(p.length);for(let d=0;d<p.length;d++)m[d]=1-p[d];return m}function h(p){return p.slice(0).reverse()}return{bounce:{In:l(u),Out:u},cosine:{In:r,Out:h(r)},exponential:"exponential",linear:"linear",ripple:{In:n,Out:l(n)},sine:{In:c,Out:l(c)},step:{In:a,Out:l(a)}}})();var te=class o extends N{constructor(){let t=x(o.getDefaults(),arguments);super(t),this._scheduledEvents=[],this._synced=!1,this._original_triggerAttack=this.triggerAttack,this._original_triggerRelease=this.triggerRelease,this._syncedRelease=e=>this._original_triggerRelease(e),this._volume=this.output=new ae({context:this.context,volume:t.volume}),this.volume=this._volume.volume,G(this,"volume")}static getDefaults(){return Object.assign(N.getDefaults(),{volume:0})}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",0),this.context.transport.on("stop",this._syncedRelease),this.context.transport.on("pause",this._syncedRelease),this.context.transport.on("loopEnd",this._syncedRelease)),this}_syncState(){let t=!1;return this._synced||(this._synced=!0,t=!0),t}_syncMethod(t,e){let r=this["_original_"+t]=this[t];this[t]=(...n)=>{let s=n[e],a=this.context.transport.schedule(i=>{n[e]=i,r.apply(this,n)},s);this._scheduledEvents.push(a)}}unsync(){return this._scheduledEvents.forEach(t=>this.context.transport.clear(t)),this._scheduledEvents=[],this._synced&&(this._synced=!1,this.triggerAttack=this._original_triggerAttack,this.triggerRelease=this._original_triggerRelease,this.context.transport.off("stop",this._syncedRelease),this.context.transport.off("pause",this._syncedRelease),this.context.transport.off("loopEnd",this._syncedRelease)),this}triggerAttackRelease(t,e,r,n){let s=this.toSeconds(r),a=this.toSeconds(e);return this.triggerAttack(t,s,n),this.triggerRelease(s+a),this}dispose(){return super.dispose(),this._volume.dispose(),this.unsync(),this._scheduledEvents=[],this}};var ee=class o extends te{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.portamento=t.portamento,this.onsilence=t.onsilence}static getDefaults(){return Object.assign(te.getDefaults(),{detune:0,onsilence:X,portamento:0})}triggerAttack(t,e,r=1){this.log("triggerAttack",t,e,r);let n=this.toSeconds(e);return this._triggerEnvelopeAttack(n,r),this.setNote(t,n),this}triggerRelease(t){this.log("triggerRelease",t);let e=this.toSeconds(t);return this._triggerEnvelopeRelease(e),this}setNote(t,e){let r=this.toSeconds(e),n=t instanceof se?t.toFrequency():t;if(this.portamento>0&&this.getLevelAtTime(r)>.05){let s=this.toSeconds(this.portamento);this.frequency.exponentialRampTo(n,s,r)}else this.frequency.setValueAtTime(n,r);return this}};$t([ue(0)],ee.prototype,"portamento",void 0);var Ge=class o extends Bt{constructor(){super(x(o.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="AmplitudeEnvelope",this._gainNode=new A({context:this.context,gain:0}),this.output=this._gainNode,this.input=this._gainNode,this._sig.connect(this._gainNode.gain),this.output=this._gainNode,this.input=this._gainNode}dispose(){return super.dispose(),this._gainNode.dispose(),this}};var Ee=class o extends ee{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="Synth",this.oscillator=new Xe(Object.assign({context:this.context,detune:t.detune,onstop:()=>this.onsilence(this)},t.oscillator)),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new Ge(Object.assign({context:this.context},t.envelope)),this.oscillator.chain(this.envelope,this.output),G(this,["oscillator","frequency","detune","envelope"])}static getDefaults(){return Object.assign(ee.getDefaults(),{envelope:Object.assign(Yt(Bt.getDefaults(),Object.keys(N.getDefaults())),{attack:.005,decay:.1,release:1,sustain:.3}),oscillator:Object.assign(Yt(Xe.getDefaults(),[...Object.keys(rt.getDefaults()),"frequency","detune"]),{type:"triangle"})})}_triggerEnvelopeAttack(t,e){if(this.envelope.triggerAttack(t,e),this.oscillator.start(t),this.envelope.sustain===0){let r=this.toSeconds(this.envelope.attack),n=this.toSeconds(this.envelope.decay);this.oscillator.stop(t+r+n)}}_triggerEnvelopeRelease(t){this.envelope.triggerRelease(t),this.oscillator.stop(t+this.toSeconds(this.envelope.release))}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this.oscillator.dispose(),this.envelope.dispose(),this}};var lr=class o extends ee{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="ModulationSynth",this._carrier=new Ee({context:this.context,oscillator:t.oscillator,envelope:t.envelope,onsilence:()=>this.onsilence(this),volume:-10}),this._modulator=new Ee({context:this.context,oscillator:t.modulation,envelope:t.modulationEnvelope,volume:-10}),this.oscillator=this._carrier.oscillator,this.envelope=this._carrier.envelope,this.modulation=this._modulator.oscillator,this.modulationEnvelope=this._modulator.envelope,this.frequency=new $({context:this.context,units:"frequency"}),this.detune=new $({context:this.context,value:t.detune,units:"cents"}),this.harmonicity=new bt({context:this.context,value:t.harmonicity,minValue:0}),this._modulationNode=new A({context:this.context,gain:0}),G(this,["frequency","harmonicity","oscillator","envelope","modulation","modulationEnvelope","detune"])}static getDefaults(){return Object.assign(ee.getDefaults(),{harmonicity:3,oscillator:Object.assign(Yt(Xe.getDefaults(),[...Object.keys(rt.getDefaults()),"frequency","detune"]),{type:"sine"}),envelope:Object.assign(Yt(Bt.getDefaults(),Object.keys(N.getDefaults())),{attack:.01,decay:.01,sustain:1,release:.5}),modulation:Object.assign(Yt(Xe.getDefaults(),[...Object.keys(rt.getDefaults()),"frequency","detune"]),{type:"square"}),modulationEnvelope:Object.assign(Yt(Bt.getDefaults(),Object.keys(N.getDefaults())),{attack:.5,decay:0,sustain:1,release:.5})})}_triggerEnvelopeAttack(t,e){this._carrier._triggerEnvelopeAttack(t,e),this._modulator._triggerEnvelopeAttack(t,e)}_triggerEnvelopeRelease(t){return this._carrier._triggerEnvelopeRelease(t),this._modulator._triggerEnvelopeRelease(t),this}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this._carrier.dispose(),this._modulator.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._modulationNode.dispose(),this}};var Xr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type"]);super(t),this.name="BiquadFilter",this._filter=this.context.createBiquadFilter(),this.input=this.output=this._filter,this.Q=new H({context:this.context,units:"number",value:t.Q,param:this._filter.Q}),this.frequency=new H({context:this.context,units:"frequency",value:t.frequency,param:this._filter.frequency}),this.detune=new H({context:this.context,units:"cents",value:t.detune,param:this._filter.detune}),this.gain=new H({context:this.context,units:"decibels",convert:!1,value:t.gain,param:this._filter.gain}),this.type=t.type}static getDefaults(){return Object.assign(N.getDefaults(),{Q:1,type:"lowpass",frequency:350,detune:0,gain:0})}get type(){return this._filter.type}set type(t){j(["lowpass","highpass","bandpass","lowshelf","highshelf","notch","allpass","peaking"].indexOf(t)!==-1,`Invalid filter type: ${t}`),this._filter.type=t}getFrequencyResponse(t=128){let e=new Float32Array(t);for(let a=0;a<t;a++){let c=Math.pow(a/t,2)*19980+20;e[a]=c}let r=new Float32Array(t),n=new Float32Array(t),s=this.context.createBiquadFilter();return s.type=this.type,s.Q.value=this.Q.value,s.frequency.value=this.frequency.value,s.gain.value=this.gain.value,s.getFrequencyResponse(e,r,n),r}dispose(){return super.dispose(),this._filter.disconnect(),this.Q.dispose(),this.frequency.dispose(),this.gain.dispose(),this.detune.dispose(),this}};var Vt=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type","rolloff"]);super(t),this.name="Filter",this.input=new A({context:this.context}),this.output=new A({context:this.context}),this._filters=[],this._filters=[],this.Q=new $({context:this.context,units:"positive",value:t.Q}),this.frequency=new $({context:this.context,units:"frequency",value:t.frequency}),this.detune=new $({context:this.context,units:"cents",value:t.detune}),this.gain=new $({context:this.context,units:"decibels",convert:!1,value:t.gain}),this._type=t.type,this.rolloff=t.rolloff,G(this,["detune","frequency","gain","Q"])}static getDefaults(){return Object.assign(N.getDefaults(),{Q:1,detune:0,frequency:350,gain:0,rolloff:-12,type:"lowpass"})}get type(){return this._type}set type(t){j(["lowpass","highpass","bandpass","lowshelf","highshelf","notch","allpass","peaking"].indexOf(t)!==-1,`Invalid filter type: ${t}`),this._type=t,this._filters.forEach(r=>r.type=t)}get rolloff(){return this._rolloff}set rolloff(t){let e=Gt(t)?t:parseInt(t,10),r=[-12,-24,-48,-96],n=r.indexOf(e);j(n!==-1,`rolloff can only be ${r.join(", ")}`),n+=1,this._rolloff=e,this.input.disconnect(),this._filters.forEach(s=>s.disconnect()),this._filters=new Array(n);for(let s=0;s<n;s++){let a=new Xr({context:this.context});a.type=this._type,this.frequency.connect(a.frequency),this.detune.connect(a.detune),this.Q.connect(a.Q),this.gain.connect(a.gain),this._filters[s]=a}this._internalChannels=this._filters,ie(this.input,...this._internalChannels,this.output)}getFrequencyResponse(t=128){let e=new Xr({context:this.context,frequency:this.frequency.value,gain:this.gain.value,Q:this.Q.value,type:this._type,detune:this.detune.value}),r=new Float32Array(t).map(()=>1);return this._filters.forEach(()=>{e.getFrequencyResponse(t).forEach((s,a)=>r[a]*=s)}),e.dispose(),r}dispose(){return super.dispose(),this._filters.forEach(t=>{t.dispose()}),So(this,["detune","frequency","gain","Q"]),this.frequency.dispose(),this.Q.dispose(),this.detune.dispose(),this.gain.dispose(),this}};var Xn=class o extends lr{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="FMSynth",this.modulationIndex=new bt({context:this.context,value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this.detune.fan(this._carrier.detune,this._modulator.detune),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output)}static getDefaults(){return Object.assign(lr.getDefaults(),{modulationIndex:10})}dispose(){return super.dispose(),this.modulationIndex.dispose(),this}};var hr=class o extends Ee{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="MembraneSynth",this.portamento=0,this.pitchDecay=t.pitchDecay,this.octaves=t.octaves,G(this,["oscillator","envelope"])}static getDefaults(){return xe(ee.getDefaults(),Ee.getDefaults(),{envelope:{attack:.001,attackCurve:"exponential",decay:.4,release:1.4,sustain:.01},octaves:10,oscillator:{type:"sine"},pitchDecay:.05})}setNote(t,e){let r=this.toSeconds(e),n=this.toFrequency(t instanceof se?t.toFrequency():t),s=n*this.octaves;return this.oscillator.frequency.setValueAtTime(s,r),this.oscillator.frequency.exponentialRampToValueAtTime(n,r+this.toSeconds(this.pitchDecay)),this}dispose(){return super.dispose(),this}};$t([Hn(0)],hr.prototype,"octaves",void 0);$t([ue(0)],hr.prototype,"pitchDecay",void 0);var Zn=class o extends te{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="NoiseSynth",this.noise=new Jt(Object.assign({context:this.context},t.noise)),this.envelope=new Ge(Object.assign({context:this.context},t.envelope)),this.noise.chain(this.envelope,this.output)}static getDefaults(){return Object.assign(te.getDefaults(),{envelope:Object.assign(Yt(Bt.getDefaults(),Object.keys(N.getDefaults())),{decay:.1,sustain:0}),noise:Object.assign(Yt(Jt.getDefaults(),Object.keys(rt.getDefaults())),{type:"white"})})}triggerAttack(t,e=1){return t=this.toSeconds(t),this.envelope.triggerAttack(t,e),this.noise.start(t),this.envelope.sustain===0&&this.noise.stop(t+this.toSeconds(this.envelope.attack)+this.toSeconds(this.envelope.decay)),this}triggerRelease(t){return t=this.toSeconds(t),this.envelope.triggerRelease(t),this.noise.stop(t+this.toSeconds(this.envelope.release)),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",0),this._syncMethod("triggerRelease",0)),this}triggerAttackRelease(t,e,r=1){return e=this.toSeconds(e),t=this.toSeconds(t),this.triggerAttack(e,r),this.triggerRelease(e+t),this}dispose(){return super.dispose(),this.noise.dispose(),this.envelope.dispose(),this}};var _i=new Set;function pr(o){_i.add(o)}function Qn(o,t){let e=`registerProcessor("${o}", ${t})`;_i.add(e)}function dp(){return Array.from(_i).join(`
|
|
20
|
+
`)}var Zr=class extends N{constructor(t){super(t),this.name="ToneAudioWorklet",this.workletOptions={},this.onprocessorerror=X;let e=URL.createObjectURL(new Blob([dp()],{type:"text/javascript"})),r=this._audioWorkletName();this._dummyGain=this.context.createGain(),this._dummyParam=this._dummyGain.gain,this.context.addAudioWorkletModule(e).then(()=>{this.disposed||(this._worklet=this.context.createAudioWorkletNode(r,this.workletOptions),this._worklet.onprocessorerror=this.onprocessorerror.bind(this),this.onReady(this._worklet))})}dispose(){return super.dispose(),this._dummyGain.disconnect(),this._worklet&&(this._worklet.port.postMessage("dispose"),this._worklet.disconnect()),this}};var wf=`
|
|
21
|
+
/**
|
|
22
|
+
* The base AudioWorkletProcessor for use in Tone.js. Works with the {@link ToneAudioWorklet}.
|
|
23
|
+
*/
|
|
24
|
+
class ToneAudioWorkletProcessor extends AudioWorkletProcessor {
|
|
25
|
+
|
|
26
|
+
constructor(options) {
|
|
27
|
+
|
|
28
|
+
super(options);
|
|
29
|
+
/**
|
|
30
|
+
* If the processor was disposed or not. Keep alive until it's disposed.
|
|
31
|
+
*/
|
|
32
|
+
this.disposed = false;
|
|
33
|
+
/**
|
|
34
|
+
* The number of samples in the processing block
|
|
35
|
+
*/
|
|
36
|
+
this.blockSize = 128;
|
|
37
|
+
/**
|
|
38
|
+
* the sample rate
|
|
39
|
+
*/
|
|
40
|
+
this.sampleRate = sampleRate;
|
|
41
|
+
|
|
42
|
+
this.port.onmessage = (event) => {
|
|
43
|
+
// when it receives a dispose
|
|
44
|
+
if (event.data === "dispose") {
|
|
45
|
+
this.disposed = true;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;pr(wf);var Tf=`
|
|
51
|
+
/**
|
|
52
|
+
* Abstract class for a single input/output processor.
|
|
53
|
+
* has a 'generate' function which processes one sample at a time
|
|
54
|
+
*/
|
|
55
|
+
class SingleIOProcessor extends ToneAudioWorkletProcessor {
|
|
56
|
+
|
|
57
|
+
constructor(options) {
|
|
58
|
+
super(Object.assign(options, {
|
|
59
|
+
numberOfInputs: 1,
|
|
60
|
+
numberOfOutputs: 1
|
|
61
|
+
}));
|
|
62
|
+
/**
|
|
63
|
+
* Holds the name of the parameter and a single value of that
|
|
64
|
+
* parameter at the current sample
|
|
65
|
+
* @type { [name: string]: number }
|
|
66
|
+
*/
|
|
67
|
+
this.params = {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generate an output sample from the input sample and parameters
|
|
72
|
+
* @abstract
|
|
73
|
+
* @param input number
|
|
74
|
+
* @param channel number
|
|
75
|
+
* @param parameters { [name: string]: number }
|
|
76
|
+
* @returns number
|
|
77
|
+
*/
|
|
78
|
+
generate(){}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Update the private params object with the
|
|
82
|
+
* values of the parameters at the given index
|
|
83
|
+
* @param parameters { [name: string]: Float32Array },
|
|
84
|
+
* @param index number
|
|
85
|
+
*/
|
|
86
|
+
updateParams(parameters, index) {
|
|
87
|
+
for (const paramName in parameters) {
|
|
88
|
+
const param = parameters[paramName];
|
|
89
|
+
if (param.length > 1) {
|
|
90
|
+
this.params[paramName] = parameters[paramName][index];
|
|
91
|
+
} else {
|
|
92
|
+
this.params[paramName] = parameters[paramName][0];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Process a single frame of the audio
|
|
99
|
+
* @param inputs Float32Array[][]
|
|
100
|
+
* @param outputs Float32Array[][]
|
|
101
|
+
*/
|
|
102
|
+
process(inputs, outputs, parameters) {
|
|
103
|
+
const input = inputs[0];
|
|
104
|
+
const output = outputs[0];
|
|
105
|
+
// get the parameter values
|
|
106
|
+
const channelCount = Math.max(input && input.length || 0, output.length);
|
|
107
|
+
for (let sample = 0; sample < this.blockSize; sample++) {
|
|
108
|
+
this.updateParams(parameters, sample);
|
|
109
|
+
for (let channel = 0; channel < channelCount; channel++) {
|
|
110
|
+
const inputSample = input && input.length ? input[channel][sample] : 0;
|
|
111
|
+
output[channel][sample] = this.generate(inputSample, channel, this.params);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return !this.disposed;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
`;pr(Tf);var Sf=`
|
|
118
|
+
/**
|
|
119
|
+
* A multichannel buffer for use within an AudioWorkletProcessor as a delay line
|
|
120
|
+
*/
|
|
121
|
+
class DelayLine {
|
|
122
|
+
|
|
123
|
+
constructor(size, channels) {
|
|
124
|
+
this.buffer = [];
|
|
125
|
+
this.writeHead = []
|
|
126
|
+
this.size = size;
|
|
127
|
+
|
|
128
|
+
// create the empty channels
|
|
129
|
+
for (let i = 0; i < channels; i++) {
|
|
130
|
+
this.buffer[i] = new Float32Array(this.size);
|
|
131
|
+
this.writeHead[i] = 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Push a value onto the end
|
|
137
|
+
* @param channel number
|
|
138
|
+
* @param value number
|
|
139
|
+
*/
|
|
140
|
+
push(channel, value) {
|
|
141
|
+
this.writeHead[channel] += 1;
|
|
142
|
+
if (this.writeHead[channel] > this.size) {
|
|
143
|
+
this.writeHead[channel] = 0;
|
|
144
|
+
}
|
|
145
|
+
this.buffer[channel][this.writeHead[channel]] = value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get the recorded value of the channel given the delay
|
|
150
|
+
* @param channel number
|
|
151
|
+
* @param delay number delay samples
|
|
152
|
+
*/
|
|
153
|
+
get(channel, delay) {
|
|
154
|
+
let readHead = this.writeHead[channel] - Math.floor(delay);
|
|
155
|
+
if (readHead < 0) {
|
|
156
|
+
readHead += this.size;
|
|
157
|
+
}
|
|
158
|
+
return this.buffer[channel][readHead];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
`;pr(Sf);var xi="feedback-comb-filter",Af=`
|
|
162
|
+
class FeedbackCombFilterWorklet extends SingleIOProcessor {
|
|
163
|
+
|
|
164
|
+
constructor(options) {
|
|
165
|
+
super(options);
|
|
166
|
+
this.delayLine = new DelayLine(this.sampleRate, options.channelCount || 2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static get parameterDescriptors() {
|
|
170
|
+
return [{
|
|
171
|
+
name: "delayTime",
|
|
172
|
+
defaultValue: 0.1,
|
|
173
|
+
minValue: 0,
|
|
174
|
+
maxValue: 1,
|
|
175
|
+
automationRate: "k-rate"
|
|
176
|
+
}, {
|
|
177
|
+
name: "feedback",
|
|
178
|
+
defaultValue: 0.5,
|
|
179
|
+
minValue: 0,
|
|
180
|
+
maxValue: 0.9999,
|
|
181
|
+
automationRate: "k-rate"
|
|
182
|
+
}];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
generate(input, channel, parameters) {
|
|
186
|
+
const delayedSample = this.delayLine.get(channel, parameters.delayTime * this.sampleRate);
|
|
187
|
+
this.delayLine.push(channel, input + delayedSample * parameters.feedback);
|
|
188
|
+
return delayedSample;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
`;Qn(xi,Af);var Qr=class o extends Zr{constructor(){let t=x(o.getDefaults(),arguments,["delayTime","resonance"]);super(t),this.name="FeedbackCombFilter",this.input=new A({context:this.context}),this.output=new A({context:this.context}),this.delayTime=new H({context:this.context,value:t.delayTime,units:"time",minValue:0,maxValue:1,param:this._dummyParam,swappable:!0}),this.resonance=new H({context:this.context,value:t.resonance,units:"normalRange",param:this._dummyParam,swappable:!0}),G(this,["resonance","delayTime"])}_audioWorkletName(){return xi}static getDefaults(){return Object.assign(N.getDefaults(),{delayTime:.1,resonance:.5})}onReady(t){ie(this.input,t,this.output);let e=t.parameters.get("delayTime");this.delayTime.setParam(e);let r=t.parameters.get("feedback");this.resonance.setParam(r)}dispose(){return super.dispose(),this.input.dispose(),this.output.dispose(),this.delayTime.dispose(),this.resonance.dispose(),this}};var Kr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["frequency","type"]);super(t),this.name="OnePoleFilter",this._frequency=t.frequency,this._type=t.type,this.input=new A({context:this.context}),this.output=new A({context:this.context}),this._createFilter()}static getDefaults(){return Object.assign(N.getDefaults(),{frequency:880,type:"lowpass"})}_createFilter(){let t=this._filter,e=this.toFrequency(this._frequency),r=1/(2*Math.PI*e);if(this._type==="lowpass"){let n=1/(r*this.context.sampleRate),s=n-1;this._filter=this.context.createIIRFilter([n,0],[1,s])}else{let n=1/(r*this.context.sampleRate)-1;this._filter=this.context.createIIRFilter([1,-1],[1,n])}this.input.chain(this._filter,this.output),t&&this.context.setTimeout(()=>{this.disposed||(this.input.disconnect(t),t.disconnect())},this.blockTime)}get frequency(){return this._frequency}set frequency(t){this._frequency=t,this._createFilter()}get type(){return this._type}set type(t){this._type=t,this._createFilter()}getFrequencyResponse(t=128){let e=new Float32Array(t);for(let s=0;s<t;s++){let i=Math.pow(s/t,2)*19980+20;e[s]=i}let r=new Float32Array(t),n=new Float32Array(t);return this._filter.getFrequencyResponse(e,r,n),r}dispose(){return super.dispose(),this.input.dispose(),this.output.dispose(),this._filter.disconnect(),this}};var Jr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["delayTime","resonance","dampening"]);super(t),this.name="LowpassCombFilter",this._combFilter=this.output=new Qr({context:this.context,delayTime:t.delayTime,resonance:t.resonance}),this.delayTime=this._combFilter.delayTime,this.resonance=this._combFilter.resonance,this._lowpass=this.input=new Kr({context:this.context,frequency:t.dampening,type:"lowpass"}),this._lowpass.connect(this._combFilter)}static getDefaults(){return Object.assign(N.getDefaults(),{dampening:3e3,delayTime:.1,resonance:.5})}get dampening(){return this._lowpass.frequency}set dampening(t){this._lowpass.frequency=t}dispose(){return super.dispose(),this._combFilter.dispose(),this._lowpass.dispose(),this}};var Kn=class o extends te{constructor(){let t=x(o.getDefaults(),arguments);super(t),this.name="PluckSynth",this._noise=new Jt({context:this.context,type:"pink"}),this.attackNoise=t.attackNoise,this._lfcf=new Jr({context:this.context,dampening:t.dampening,resonance:t.resonance}),this.resonance=t.resonance,this.release=t.release,this._noise.connect(this._lfcf),this._lfcf.connect(this.output)}static getDefaults(){return xe(te.getDefaults(),{attackNoise:1,dampening:4e3,resonance:.7,release:1})}get dampening(){return this._lfcf.dampening}set dampening(t){this._lfcf.dampening=t}triggerAttack(t,e){let r=this.toFrequency(t);e=this.toSeconds(e);let n=1/r;return this._lfcf.delayTime.setValueAtTime(n,e),this._noise.start(e),this._noise.stop(e+n*this.attackNoise),this._lfcf.resonance.cancelScheduledValues(e),this._lfcf.resonance.setValueAtTime(this.resonance,e),this}triggerRelease(t){return this._lfcf.resonance.linearRampTo(0,this.release,t),this}dispose(){return super.dispose(),this._noise.dispose(),this._lfcf.dispose(),this}};var Jn=class o extends te{constructor(){let t=x(o.getDefaults(),arguments,["urls","onload","baseUrl"],"urls");super(t),this.name="Sampler",this._activeSources=new Map;let e={};Object.keys(t.urls).forEach(r=>{let n=parseInt(r,10);if(j(Wr(r)||Gt(n)&&isFinite(n),`url key is neither a note or midi pitch: ${r}`),Wr(r)){let s=new se(this.context,r).toMidi();e[s]=t.urls[r]}else Gt(n)&&isFinite(n)&&(e[n]=t.urls[n])}),this._buffers=new ir({urls:e,onload:t.onload,baseUrl:t.baseUrl,onerror:t.onerror}),this.attack=t.attack,this.release=t.release,this.curve=t.curve,this._buffers.loaded&&Promise.resolve().then(t.onload)}static getDefaults(){return Object.assign(te.getDefaults(),{attack:0,baseUrl:"",curve:"exponential",onload:X,onerror:X,release:.1,urls:{}})}_findClosest(t){let r=0;for(;r<96;){if(this._buffers.has(t+r))return-r;if(this._buffers.has(t-r))return r;r++}throw new Error(`No available buffers for note: ${t}`)}triggerAttack(t,e,r=1){return this.log("triggerAttack",t,e,r),Array.isArray(t)||(t=[t]),t.forEach(n=>{let s=ui(new se(this.context,n).toFrequency()),a=Math.round(s),i=s-a,c=this._findClosest(a),u=a-c,l=this._buffers.get(u),h=Co(c+i),p=new Le({url:l,context:this.context,curve:this.curve,fadeIn:this.attack,fadeOut:this.release,playbackRate:h}).connect(this.output);p.start(e,0,l.duration/h,r),Et(this._activeSources.get(a))||this._activeSources.set(a,[]),this._activeSources.get(a).push(p),p.onended=()=>{if(this._activeSources&&this._activeSources.has(a)){let m=this._activeSources.get(a),d=m.indexOf(p);d!==-1&&m.splice(d,1)}}}),this}triggerRelease(t,e){return this.log("triggerRelease",t,e),Array.isArray(t)||(t=[t]),t.forEach(r=>{let n=new se(this.context,r).toMidi();if(this._activeSources.has(n)&&this._activeSources.get(n).length){let s=this._activeSources.get(n);e=this.toSeconds(e),s.forEach(a=>{a.stop(e)}),this._activeSources.set(n,[])}}),this}releaseAll(t){let e=this.toSeconds(t);return this._activeSources.forEach(r=>{for(;r.length;)r.shift().stop(e)}),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}triggerAttackRelease(t,e,r,n=1){let s=this.toSeconds(r);return this.triggerAttack(t,s,n),Et(e)?(j(Et(t),"notes must be an array when duration is array"),t.forEach((a,i)=>{let c=e[Math.min(i,e.length-1)];this.triggerRelease(a,s+this.toSeconds(c))})):this.triggerRelease(t,s+this.toSeconds(e)),this}add(t,e,r){if(j(Wr(t)||isFinite(t),`note must be a pitch or midi: ${t}`),Wr(t)){let n=new se(this.context,t).toMidi();this._buffers.add(n,e,r)}else this._buffers.add(t,e,r);return this}get loaded(){return this._buffers.loaded}dispose(){return super.dispose(),this._buffers.dispose(),this._activeSources.forEach(t=>{t.forEach(e=>e.dispose())}),this._activeSources.clear(),this}};$t([ue(0)],Jn.prototype,"attack",void 0);$t([ue(0)],Jn.prototype,"release",void 0);var mr=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments,["callback","value"]);super(t),this.name="ToneEvent",this._state=new Ne("stopped"),this._startOffset=0,this._loop=t.loop,this.callback=t.callback,this.value=t.value,this._loopStart=this.toTicks(t.loopStart),this._loopEnd=this.toTicks(t.loopEnd),this._playbackRate=t.playbackRate,this._probability=t.probability,this._humanize=t.humanize,this.mute=t.mute,this._playbackRate=t.playbackRate,this._state.increasing=!0,this._rescheduleEvents()}static getDefaults(){return Object.assign(gt.getDefaults(),{callback:X,humanize:!1,loop:!1,loopEnd:"1m",loopStart:0,mute:!1,playbackRate:1,probability:1,value:null})}_rescheduleEvents(t=-1){this._state.forEachFrom(t,e=>{let r;if(e.state==="started"){e.id!==-1&&this.context.transport.clear(e.id);let n=e.time+Math.round(this.startOffset/this._playbackRate);if(this._loop===!0||Gt(this._loop)&&this._loop>1){r=1/0,Gt(this._loop)&&(r=this._loop*this._getLoopDuration());let s=this._state.getAfter(n);s!==null&&(r=Math.min(r,s.time-n)),r!==1/0&&(r=new Pt(this.context,r));let a=new Pt(this.context,this._getLoopDuration());e.id=this.context.transport.scheduleRepeat(this._tick.bind(this),a,new Pt(this.context,n),r)}else e.id=this.context.transport.schedule(this._tick.bind(this),new Pt(this.context,n))}})}get state(){return this._state.getValueAtTime(this.context.transport.ticks)}get startOffset(){return this._startOffset}set startOffset(t){this._startOffset=t}get probability(){return this._probability}set probability(t){this._probability=t}get humanize(){return this._humanize}set humanize(t){this._humanize=t}start(t){let e=this.toTicks(t);return this._state.getValueAtTime(e)==="stopped"&&(this._state.add({id:-1,state:"started",time:e}),this._rescheduleEvents(e)),this}stop(t){this.cancel(t);let e=this.toTicks(t);if(this._state.getValueAtTime(e)==="started"){this._state.setStateAtTime("stopped",e,{id:-1});let r=this._state.getBefore(e),n=e;r!==null&&(n=r.time),this._rescheduleEvents(n)}return this}cancel(t){t=ne(t,-1/0);let e=this.toTicks(t);return this._state.forEachFrom(e,r=>{this.context.transport.clear(r.id)}),this._state.cancel(e),this}_tick(t){let e=this.context.transport.getTicksAtTime(t);if(!this.mute&&this._state.getValueAtTime(e)==="started"){if(this.probability<1&&Math.random()>this.probability)return;if(this.humanize){let r=.02;Mn(this.humanize)||(r=this.toSeconds(this.humanize)),t+=(Math.random()*2-1)*r}this.callback(t,this.value)}}_getLoopDuration(){return(this._loopEnd-this._loopStart)/this._playbackRate}get loop(){return this._loop}set loop(t){this._loop=t,this._rescheduleEvents()}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._rescheduleEvents()}get loopEnd(){return new Pt(this.context,this._loopEnd).toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t),this._loop&&this._rescheduleEvents()}get loopStart(){return new Pt(this.context,this._loopStart).toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t),this._loop&&this._rescheduleEvents()}get progress(){if(this._loop){let t=this.context.transport.ticks,e=this._state.get(t);if(e!==null&&e.state==="started"){let r=this._getLoopDuration();return(t-e.time)%r/r}else return 0}else return 0}dispose(){return super.dispose(),this.cancel(),this._state.dispose(),this}};var tn=class o extends gt{constructor(){let t=x(o.getDefaults(),arguments,["callback","interval"]);super(t),this.name="Loop",this._event=new mr({context:this.context,callback:this._tick.bind(this),loop:!0,loopEnd:t.interval,playbackRate:t.playbackRate,probability:t.probability,humanize:t.humanize}),this.callback=t.callback,this.iterations=t.iterations}static getDefaults(){return Object.assign(gt.getDefaults(),{interval:"4n",callback:X,playbackRate:1,iterations:1/0,probability:1,mute:!1,humanize:!1})}start(t){return this._event.start(t),this}stop(t){return this._event.stop(t),this}cancel(t){return this._event.cancel(t),this}_tick(t){this.callback(t)}get state(){return this._event.state}get progress(){return this._event.progress}get interval(){return this._event.loopEnd}set interval(t){this._event.loopEnd=t}get playbackRate(){return this._event.playbackRate}set playbackRate(t){this._event.playbackRate=t}get humanize(){return this._event.humanize}set humanize(t){this._event.humanize=t}get probability(){return this._event.probability}set probability(t){this._event.probability=t}get mute(){return this._event.mute}set mute(t){this._event.mute=t}get iterations(){return this._event.loop===!0?1/0:this._event.loop}set iterations(t){t===1/0?this._event.loop=!0:this._event.loop=t}dispose(){return super.dispose(),this._event.dispose(),this}};var dr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["fade"]);super(t),this.name="CrossFade",this._panner=this.context.createStereoPanner(),this._split=this.context.createChannelSplitter(2),this._g2a=new $n({context:this.context}),this.a=new A({context:this.context,gain:0}),this.b=new A({context:this.context,gain:0}),this.output=new A({context:this.context}),this._internalChannels=[this.a,this.b],this.fade=new $({context:this.context,units:"normalRange",value:t.fade}),G(this,"fade"),this.context.getConstant(1).connect(this._panner),this._panner.connect(this._split),this._panner.channelCount=1,this._panner.channelCountMode="explicit",Wt(this._split,this.a.gain,0),Wt(this._split,this.b.gain,1),this.fade.chain(this._g2a,this._panner.pan),this.a.connect(this.output),this.b.connect(this.output)}static getDefaults(){return Object.assign(N.getDefaults(),{fade:.5})}dispose(){return super.dispose(),this.a.dispose(),this.b.dispose(),this.output.dispose(),this.fade.dispose(),this._g2a.dispose(),this._panner.disconnect(),this._split.disconnect(),this}};var le=class extends N{constructor(t){super(t),this.name="Effect",this._dryWet=new dr({context:this.context}),this.wet=this._dryWet.fade,this.effectSend=new A({context:this.context}),this.effectReturn=new A({context:this.context}),this.input=new A({context:this.context}),this.output=this._dryWet,this.input.fan(this._dryWet.a,this.effectSend),this.effectReturn.connect(this._dryWet.b),this.wet.setValueAtTime(t.wet,0),this._internalChannels=[this.effectReturn,this.effectSend],G(this,"wet")}static getDefaults(){return Object.assign(N.getDefaults(),{wet:1})}connectEffect(t){return this._internalChannels.push(t),this.effectSend.chain(t,this.effectReturn),this}dispose(){return super.dispose(),this._dryWet.dispose(),this.effectSend.dispose(),this.effectReturn.dispose(),this.wet.dispose(),this}};var en=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["pan"]);super(t),this.name="Panner",this._panner=this.context.createStereoPanner(),this.input=this._panner,this.output=this._panner,this.pan=new H({context:this.context,param:this._panner.pan,value:t.pan,minValue:-1,maxValue:1}),this._panner.channelCount=t.channelCount,this._panner.channelCountMode="explicit",G(this,"pan")}static getDefaults(){return Object.assign(N.getDefaults(),{pan:0,channelCount:1})}dispose(){return super.dispose(),this._panner.disconnect(),this.pan.dispose(),this}};var fp="bit-crusher",kf=`
|
|
192
|
+
class BitCrusherWorklet extends SingleIOProcessor {
|
|
193
|
+
|
|
194
|
+
static get parameterDescriptors() {
|
|
195
|
+
return [{
|
|
196
|
+
name: "bits",
|
|
197
|
+
defaultValue: 12,
|
|
198
|
+
minValue: 1,
|
|
199
|
+
maxValue: 16,
|
|
200
|
+
automationRate: 'k-rate'
|
|
201
|
+
}];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
generate(input, _channel, parameters) {
|
|
205
|
+
const step = Math.pow(0.5, parameters.bits - 1);
|
|
206
|
+
const val = step * Math.floor(input / step + 0.5);
|
|
207
|
+
return val;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
`;Qn(fp,kf);var lo=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["channels"]);super(t),this.name="Split",this._splitter=this.input=this.output=this.context.createChannelSplitter(t.channels),this._internalChannels=[this._splitter]}static getDefaults(){return Object.assign(N.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._splitter.disconnect(),this}};var We=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["channels"]);super(t),this.name="Merge",this._merger=this.output=this.input=this.context.createChannelMerger(t.channels)}static getDefaults(){return Object.assign(N.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._merger.disconnect(),this}};var Y8=[1557/44100,1617/44100,1491/44100,1422/44100,1277/44100,1356/44100,1188/44100,1116/44100];var o$=[1687/25e3,1601/25e3,2053/25e3,2251/25e3];var es=class o extends le{constructor(){let t=x(o.getDefaults(),arguments,["decay"]);super(t),this.name="Reverb",this._convolver=this.context.createConvolver(),this.ready=Promise.resolve();let e=this.toSeconds(t.decay);St(e,.001),this._decay=e;let r=this.toSeconds(t.preDelay);St(r,0),this._preDelay=r,this.generate(),this.connectEffect(this._convolver)}static getDefaults(){return Object.assign(le.getDefaults(),{decay:1.5,preDelay:.01})}get decay(){return this._decay}set decay(t){t=this.toSeconds(t),St(t,.001),this._decay=t,this.generate()}get preDelay(){return this._preDelay}set preDelay(t){t=this.toSeconds(t),St(t,0),this._preDelay=t,this.generate()}generate(){return ot(this,void 0,void 0,function*(){let t=this.ready,e=new Ce(2,this._decay+this._preDelay,this.context.sampleRate),r=new Jt({context:e}),n=new Jt({context:e}),s=new We({context:e});r.connect(s,0,0),n.connect(s,0,1);let a=new A({context:e}).toDestination();s.connect(a),r.start(0),n.start(0),a.gain.setValueAtTime(0,0),a.gain.setValueAtTime(1,this._preDelay),a.gain.exponentialApproachValueAtTime(0,this._preDelay,this.decay);let i=e.render();return this.ready=i.then(X),yield t,this._convolver.buffer=(yield i).get(),this})}dispose(){return super.dispose(),this._convolver.disconnect(),this}};var fr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["solo"]);super(t),this.name="Solo",this.input=this.output=new A({context:this.context}),o._allSolos.has(this.context)||o._allSolos.set(this.context,new Set),o._allSolos.get(this.context).add(this),this.solo=t.solo}static getDefaults(){return Object.assign(N.getDefaults(),{solo:!1})}get solo(){return this._isSoloed()}set solo(t){t?this._addSolo():this._removeSolo(),o._allSolos.get(this.context).forEach(e=>e._updateSolo())}get muted(){return this.input.gain.value===0}_addSolo(){o._soloed.has(this.context)||o._soloed.set(this.context,new Set),o._soloed.get(this.context).add(this)}_removeSolo(){o._soloed.has(this.context)&&o._soloed.get(this.context).delete(this)}_isSoloed(){return o._soloed.has(this.context)&&o._soloed.get(this.context).has(this)}_noSolos(){return!o._soloed.has(this.context)||o._soloed.has(this.context)&&o._soloed.get(this.context).size===0}_updateSolo(){this._isSoloed()?this.input.gain.value=1:this._noSolos()?this.input.gain.value=1:this.input.gain.value=0}dispose(){return super.dispose(),o._allSolos.get(this.context).delete(this),this._removeSolo(),this}};fr._allSolos=new Map;fr._soloed=new Map;var os=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["pan","volume"]);super(t),this.name="PanVol",this._panner=this.input=new en({context:this.context,pan:t.pan,channelCount:t.channelCount}),this.pan=this._panner.pan,this._volume=this.output=new ae({context:this.context,volume:t.volume}),this.volume=this._volume.volume,this._panner.connect(this._volume),this.mute=t.mute,G(this,["pan","volume"])}static getDefaults(){return Object.assign(N.getDefaults(),{mute:!1,pan:0,volume:0,channelCount:1})}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}dispose(){return super.dispose(),this._panner.dispose(),this.pan.dispose(),this._volume.dispose(),this.volume.dispose(),this}};var vi=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["volume","pan"]);super(t),this.name="Channel",this._solo=this.input=new fr({solo:t.solo,context:this.context}),this._panVol=this.output=new os({context:this.context,pan:t.pan,volume:t.volume,mute:t.mute,channelCount:t.channelCount}),this.pan=this._panVol.pan,this.volume=this._panVol.volume,this._solo.connect(this._panVol),G(this,["pan","volume"])}static getDefaults(){return Object.assign(N.getDefaults(),{pan:0,volume:0,mute:!1,solo:!1,channelCount:1})}get solo(){return this._solo.solo}set solo(t){this._solo.solo=t}get muted(){return this._solo.muted||this.mute}get mute(){return this._panVol.mute}set mute(t){this._panVol.mute=t}_getBus(t){return o.buses.has(t)||o.buses.set(t,new A({context:this.context})),o.buses.get(t)}send(t,e=0){let r=this._getBus(t),n=new A({context:this.context,units:"decibels",gain:e});return this.connect(n),n.connect(r),n}receive(t){return this._getBus(t).connect(this),this}dispose(){return super.dispose(),this._panVol.dispose(),this.pan.dispose(),this.volume.dispose(),this._solo.dispose(),this}};vi.buses=new Map;var gr=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["positionX","positionY","positionZ"]);super(t),this.name="Panner3D",this._panner=this.input=this.output=this.context.createPanner(),this.panningModel=t.panningModel,this.maxDistance=t.maxDistance,this.distanceModel=t.distanceModel,this.coneOuterGain=t.coneOuterGain,this.coneOuterAngle=t.coneOuterAngle,this.coneInnerAngle=t.coneInnerAngle,this.refDistance=t.refDistance,this.rolloffFactor=t.rolloffFactor,this.positionX=new H({context:this.context,param:this._panner.positionX,value:t.positionX}),this.positionY=new H({context:this.context,param:this._panner.positionY,value:t.positionY}),this.positionZ=new H({context:this.context,param:this._panner.positionZ,value:t.positionZ}),this.orientationX=new H({context:this.context,param:this._panner.orientationX,value:t.orientationX}),this.orientationY=new H({context:this.context,param:this._panner.orientationY,value:t.orientationY}),this.orientationZ=new H({context:this.context,param:this._panner.orientationZ,value:t.orientationZ})}static getDefaults(){return Object.assign(N.getDefaults(),{coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:0,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1})}setPosition(t,e,r){return this.positionX.value=t,this.positionY.value=e,this.positionZ.value=r,this}setOrientation(t,e,r){return this.orientationX.value=t,this.orientationY.value=e,this.orientationZ.value=r,this}get panningModel(){return this._panner.panningModel}set panningModel(t){this._panner.panningModel=t}get refDistance(){return this._panner.refDistance}set refDistance(t){this._panner.refDistance=t}get rolloffFactor(){return this._panner.rolloffFactor}set rolloffFactor(t){this._panner.rolloffFactor=t}get distanceModel(){return this._panner.distanceModel}set distanceModel(t){this._panner.distanceModel=t}get coneInnerAngle(){return this._panner.coneInnerAngle}set coneInnerAngle(t){this._panner.coneInnerAngle=t}get coneOuterAngle(){return this._panner.coneOuterAngle}set coneOuterAngle(t){this._panner.coneOuterAngle=t}get coneOuterGain(){return this._panner.coneOuterGain}set coneOuterGain(t){this._panner.coneOuterGain=t}get maxDistance(){return this._panner.maxDistance}set maxDistance(t){this._panner.maxDistance=t}dispose(){return super.dispose(),this._panner.disconnect(),this.orientationX.dispose(),this.orientationY.dispose(),this.orientationZ.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this}};var _r=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["threshold","ratio"]);super(t),this.name="Compressor",this._compressor=this.context.createDynamicsCompressor(),this.input=this._compressor,this.output=this._compressor,this.threshold=new H({minValue:this._compressor.threshold.minValue,maxValue:this._compressor.threshold.maxValue,context:this.context,convert:!1,param:this._compressor.threshold,units:"decibels",value:t.threshold}),this.attack=new H({minValue:this._compressor.attack.minValue,maxValue:this._compressor.attack.maxValue,context:this.context,param:this._compressor.attack,units:"time",value:t.attack}),this.release=new H({minValue:this._compressor.release.minValue,maxValue:this._compressor.release.maxValue,context:this.context,param:this._compressor.release,units:"time",value:t.release}),this.knee=new H({minValue:this._compressor.knee.minValue,maxValue:this._compressor.knee.maxValue,context:this.context,convert:!1,param:this._compressor.knee,units:"decibels",value:t.knee}),this.ratio=new H({minValue:this._compressor.ratio.minValue,maxValue:this._compressor.ratio.maxValue,context:this.context,convert:!1,param:this._compressor.ratio,units:"positive",value:t.ratio}),G(this,["knee","release","attack","ratio","threshold"])}static getDefaults(){return Object.assign(N.getDefaults(),{attack:.003,knee:30,ratio:12,release:.25,threshold:-24})}get reduction(){return this._compressor.reduction}dispose(){return super.dispose(),this._compressor.disconnect(),this.attack.dispose(),this.release.dispose(),this.threshold.dispose(),this.ratio.dispose(),this.knee.dispose(),this}};var rs=class o extends N{constructor(){let t=x(o.getDefaults(),arguments,["threshold"]);super(t),this.name="Limiter",this._compressor=this.input=this.output=new _r({context:this.context,ratio:20,attack:.003,release:.01,threshold:t.threshold}),this.threshold=this._compressor.threshold,G(this,"threshold")}static getDefaults(){return Object.assign(N.getDefaults(),{threshold:-12})}get reduction(){return this._compressor.reduction}dispose(){return super.dispose(),this._compressor.dispose(),this.threshold.dispose(),this}};function Ct(){return dt().now()}var W7=dt().transport;function ns(){return dt().transport}var B7=dt().destination,j7=dt().destination;var z7=dt().listener;function gp(){return dt().listener}var U7=dt().draw;var H7=dt();var E=(o,t,e)=>Math.min(e,Math.max(t,o)),K=(o,t,e)=>o+(t-o)*e,Me=(o,t,e)=>E((o-t)/(e-t),0,1);function _p(o){let t=2166136261;for(let e=0;e<o.length;e++)t^=o.charCodeAt(e),t=Math.imul(t,16777619);return t>>>0}var Fo={pentMajor:[0,2,4,7,9],pentMinor:[0,3,5,7,10],dorian:[0,2,3,5,7,9,10],lydian:[0,2,4,6,7,9,11],mixolydian:[0,2,4,5,7,9,10]},xp=Object.keys(Fo),If=3,Pf=48,qf={C:0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11},bi=["C","C#","D","Eb","E","F","F#","G","Ab","A","Bb","B"];function ss(o){let e=_p(o||"localhost"),r=e%12,n=xp[(e>>>4)%xp.length],s=Fo[n];return{root:r,scaleName:n,scale:s,label:`${bi[r]} ${n}`}}function on(o){let t=o.trim().match(/^([A-Ga-g][#b]?)\s+(\w+)$/);if(!t)return null;let e=t[1].charAt(0).toUpperCase()+t[1].slice(1),r=qf[e],n=t[2],s=Fo[n];return r===void 0||!s?null:{root:r,scaleName:n,scale:s,label:`${bi[r]} ${n}`}}function is(o,t,e=0){let r=t.scale.length*If,n=Math.round(E(o,0,1)*(r-1))+Math.round(e);n=E(n,0,r-1);let s=Math.floor(n/t.scale.length),a=t.scale[n%t.scale.length];return Pf+t.root+s*12+a}var xr=o=>440*Math.pow(2,(o-69)/12);function as(o,t,e){if(e===0)return o;let r=t.scale.map(a=>(a+t.root)%12),n=e>0?1:-1,s=o;for(let a=0;a<Math.abs(e);a++)do s+=n;while(!r.includes((s%12+12)%12)&&s>12&&s<120);return E(s,12,120)}function rn(o){let t=(o%12+12)%12;return`${bi[t]}${Math.floor(o/12)-1}`}var Ci={};go(Ci,{fmIndex:()=>vp,foldCurve:()=>Si,foldFromBorder:()=>yp,lfoFromCss:()=>wp,massBonusFromFontWeight:()=>wi,patchFrom:()=>Ti,portamentoFromTransition:()=>Tp,ribbonSteps:()=>Ai,unisonFromMass:()=>bp});function yp(o,t){let e=E(o/6,0,1)*(.25+.75*E(t,0,1));return{drive:e,mix:e>.01?.25+.55*e:0}}var vp=(o,t)=>1.5*E(o,0,1)*E(t,0,1);function bp(o){let t=E(o,0,1);return t>=.45?{detuneCents:4+10*t,mix:.4}:{detuneCents:0,mix:0}}function wp(o,t){return o>.05?{rateHz:E(1/o,.08,8),shape:t==="dashed"||t==="dotted"?"square":"sine",vibratoCents:6,tremolo:.18,filterDepth:.25}:t==="dashed"||t==="dotted"?{rateHz:t==="dotted"?7:3.5,shape:"square",vibratoCents:0,tremolo:.3,filterDepth:.35}:{rateHz:0,shape:"sine",vibratoCents:0,tremolo:0,filterDepth:0}}var Tp=o=>E(o/2,0,.25),wi=o=>E((o-400)/300,0,1)*.12;function Ti(o,t){return{fold:yp(t.borderWidthPx,o.edge),fm:{index:vp(o.texture,o.edge)},unison:bp(o.mass),lfo:wp(t.animationS,t.borderStyle),portamentoS:Tp(t.transitionS)}}function Si(o=2049){let t=new Float32Array(o);for(let e=0;e<o;e++){let r=e/(o-1)*2-1;t[e]=Math.sin(2.5*(Math.PI/2)*r)}return t}function Ai(o,t,e){let r=E(o/(t*.6),-1,1);return Math.round(r*e)}var Pi={};go(Pi,{attackScaleFromWarmth:()=>Oi,brightnessFromLuminance:()=>Ni,chromaOf:()=>po,modeFromPalette:()=>Fi,pagePalette:()=>Di,parseCssColor:()=>ho,rgbToHsl:()=>Sp,richnessFromSaturation:()=>Mi,roomToneScaleFromWarmth:()=>Ri,subBonusFromWarmth:()=>Ei,tempoScaleFromWarmth:()=>Ii,velocityFromLuminance:()=>ki,warmthFromHue:()=>Ap});function ho(o){let t=o.trim().match(/^rgba?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)$/);return t?{r:E(parseFloat(t[1])/255,0,1),g:E(parseFloat(t[2])/255,0,1),b:E(parseFloat(t[3])/255,0,1),a:t[4]===void 0?1:E(parseFloat(t[4]),0,1)}:null}function Sp({r:o,g:t,b:e}){let r=Math.max(o,t,e),n=Math.min(o,t,e),s=(r+n)/2,a=r-n;if(a<1e-6)return{h:0,s:0,l:s};let i=a/(1-Math.abs(2*s-1)),c;return r===o?c=(t-e)/a%6:r===t?c=(e-o)/a+2:c=(o-t)/a+4,c*=60,c<0&&(c+=360),{h:c,s:E(i,0,1),l:s}}function Ap(o,t){let e=.5+.5*Math.cos((o-30)*Math.PI/180);return K(.5,e,E(t*2,0,1))}function po(o){if(!o||o.a<.05)return{warmth:.5,saturation:0,luminance:.5};let{h:t,s:e,l:r}=Sp(o);return{warmth:Ap(t,e),saturation:e,luminance:r}}var Ni=o=>K(.78,1.22,E(o,0,1)),ki=o=>K(.92,1.06,E(o,0,1)),Oi=o=>K(1.18,.82,E(o,0,1)),Ei=o=>.08*E(o,0,1),Mi=o=>.35*E(o,0,1);function Fi(o){return o.warmth>=.55?o.luminance>=.5?"lydian":"mixolydian":o.warmth<=.45?o.luminance>=.5?"dorian":"pentMinor":null}function Di(o,t){return{warmth:o.warmth*.7+t.warmth*.3,saturation:o.saturation*.7+t.saturation*.3,luminance:o.luminance*.7+t.luminance*.3}}var Ri=o=>K(.85,1.25,E(o,0,1)),Ii=o=>K(.94,1.06,E(o,0,1));var Xi={};go(Xi,{DUCK_RECOVERY_MS:()=>Cp,ECHO_MIN_AHEAD_S:()=>Bi,ECHO_TRANSPOSE:()=>Gi,ECHO_VELOCITY_SCALE:()=>Wi,PHRASE_MAX_NOTES:()=>$i,PHRASE_MIN_NOTES:()=>nn,PHRASE_PROBABILITY:()=>Hi,decayCount:()=>zi,duckFactor:()=>Ui,echoGridS:()=>ji,nextGridOffset:()=>Vi,phraseWindow:()=>Yi,readingOrderKey:()=>cs,secondsPerBeat:()=>yr,strumStepS:()=>Li,tempoFromPage:()=>qi});function qi(o,t){let e=K(66,104,E(o/120,0,1));return Math.round(E(e*t,56,116))}var yr=o=>60/Math.max(1,o);function Vi(o,t,e){if(t<=0)return e;let r=t-(o%t+t)%t;for(;r<e;)r+=t;return r}var Li=o=>yr(o)/8,Gi=12,Wi=.22,Bi=.08,ji=o=>yr(o)/2,Cp=2e3,zi=(o,t)=>Math.max(0,o-t/Cp),Ui=o=>Math.max(.4,Math.pow(.85,Math.max(0,o))),Hi=.55,nn=2,$i=4,cs=(o,t)=>Math.round(o/80)*1e5+E(t,0,99999);function Yi(o,t,e){return Math.round(E(e,0,1)*Math.max(0,o-t))}var Zi={name:"aurora",defaults:{synthKind:"matter",octaveShift:0,baseVelocity:.8,releaseScale:1},roles:{toggle:{synthKind:"matter",baseVelocity:.7,releaseScale:.8},button:{synthKind:"matter",baseVelocity:.9},link:{synthKind:"matter",octaveShift:1,baseVelocity:.6,releaseScale:.7},input:{synthKind:"matter",baseVelocity:.55,releaseScale:1.6},heading:{synthKind:"fm",octaveShift:0,baseVelocity:.75,releaseScale:2.2},media:{synthKind:"membrane",octaveShift:-1,baseVelocity:.8},item:{synthKind:"matter",baseVelocity:.6,releaseScale:.8},text:{synthKind:"matter",baseVelocity:.35,releaseScale:1.8}}},Vf={name:"mono",defaults:{synthKind:"synth",octaveShift:0,baseVelocity:.7,releaseScale:.5},roles:{toggle:{synthKind:"noise",baseVelocity:.6},button:{synthKind:"synth",pinWave:"square",baseVelocity:.7,releaseScale:.4},link:{synthKind:"noise",baseVelocity:.45,releaseScale:.3},input:{synthKind:"synth",pinWave:"sine",octaveShift:-1,baseVelocity:.5},heading:{synthKind:"synth",pinWave:"sine",octaveShift:1,baseVelocity:.6},media:{synthKind:"noise",baseVelocity:.55},item:{synthKind:"noise",baseVelocity:.4,releaseScale:.3},text:{synthKind:"synth",pinWave:"sine",baseVelocity:0}}},Lf={name:"paper",defaults:{synthKind:"pluck",octaveShift:0,baseVelocity:.8,releaseScale:1},roles:{toggle:{synthKind:"pluck",baseVelocity:.7},button:{synthKind:"pluck",baseVelocity:.9},link:{synthKind:"pluck",octaveShift:1,baseVelocity:.65},input:{synthKind:"synth",pinWave:"triangle",baseVelocity:.5,releaseScale:1.4},heading:{synthKind:"pluck",octaveShift:-1,baseVelocity:.85,releaseScale:1.6},media:{synthKind:"membrane",octaveShift:-1,baseVelocity:.7},item:{synthKind:"pluck",baseVelocity:.6},text:{synthKind:"synth",pinWave:"sine",baseVelocity:.3,releaseScale:1.6}}},Qi={aurora:Zi,mono:Vf,paper:Lf};function Np(o){return o?typeof o=="string"?Qi[o]??Zi:o:Zi}var kp="sonarium:muted",Op=()=>{try{return localStorage.getItem(kp)==="1"}catch{return!1}},Ki=o=>{try{localStorage.setItem(kp,o?"1":"0")}catch{}};function Ep(o){let t=document.createElement("div");t.setAttribute("data-sonic","off");let e=t.attachShadow({mode:"open"});e.innerHTML=`
|
|
211
|
+
<style>
|
|
212
|
+
button {
|
|
213
|
+
position: fixed; right: 16px; bottom: 16px; z-index: 2147483646;
|
|
214
|
+
width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25);
|
|
215
|
+
background: rgba(20, 22, 30, .82); color: #fff; font-size: 18px; line-height: 1;
|
|
216
|
+
cursor: pointer; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
|
|
217
|
+
box-shadow: 0 4px 16px rgba(0,0,0,.35); transition: transform .15s ease, opacity .3s ease;
|
|
218
|
+
}
|
|
219
|
+
button:hover { transform: scale(1.08); }
|
|
220
|
+
button:focus-visible { outline: 2px solid #7cd4fd; outline-offset: 2px; }
|
|
221
|
+
button.armed { animation: pulse 1.6s ease-in-out infinite; }
|
|
222
|
+
@keyframes pulse { 0%,100% { box-shadow: 0 4px 16px rgba(0,0,0,.35); } 50% { box-shadow: 0 0 0 10px rgba(124,212,253,.18); } }
|
|
223
|
+
</style>
|
|
224
|
+
<button type="button" class="armed" aria-label="Enable sound" title="Sonarium \u2014 enable sound">\u{1F507}</button>
|
|
225
|
+
`;let r=e.querySelector("button");return r.addEventListener("click",n=>{n.stopPropagation(),o()}),document.body.appendChild(t),{setState(n){r.classList.toggle("armed",n==="armed"),n==="on"?(r.textContent="\u{1F50A}",r.setAttribute("aria-label","Mute Sonarium")):n==="muted"?(r.textContent="\u{1F507}",r.setAttribute("aria-label","Unmute Sonarium")):(r.textContent="\u{1F507}",r.setAttribute("aria-label","Enable sound"))},dispose(){t.remove()}}}var _t=Math.PI/180;function mo(o,t,e=0){let r=Math.min(1,Math.max(0,e)),n=Math.cos(t),s=1-r;return{w:1+.41*r,y:s*Math.sin(o)*n,z:s*Math.sin(t),x:s*Math.cos(o)*n}}function Ji(o,t){let e=Math.cos(t);return[Math.cos(o)*e,Math.sin(o)*e,Math.sin(t)]}var xt=1/Math.sqrt(3),sn=[{dir:[xt,xt,xt],label:"front-left-up"},{dir:[xt,-xt,xt],label:"front-right-up"},{dir:[xt,xt,-xt],label:"front-left-down"},{dir:[xt,-xt,-xt],label:"front-right-down"},{dir:[-xt,xt,xt],label:"back-left-up"},{dir:[-xt,-xt,xt],label:"back-right-up"},{dir:[-xt,xt,-xt],label:"back-left-down"},{dir:[-xt,-xt,-xt],label:"back-right-down"}],Gf=1,ta=1/Math.sqrt(3);function us(o){let t=o.length;return o.map(({dir:e})=>({w:1/t*Gf,x:3/t*ta*e[0],y:3/t*ta*e[1],z:3/t*ta*e[2]}))}function Mp(o,t){return o.map(e=>e.w*t.w+e.y*t.y+e.z*t.z+e.x*t.x)}var Fp=[[1,0,0],[0,1,0],[0,0,1]];function ea(o,t){let e=[[0,0,0],[0,0,0],[0,0,0]];for(let r=0;r<3;r++)for(let n=0;n<3;n++)e[r][n]=o[r][0]*t[0][n]+o[r][1]*t[1][n]+o[r][2]*t[2][n];return e}function ls(o,t,e=0){let r=Math.cos(o),n=Math.sin(o),s=Math.cos(t),a=Math.sin(t),i=Math.cos(e),c=Math.sin(e),u=[[r,-n,0],[n,r,0],[0,0,1]],l=[[s,0,a],[0,1,0],[-a,0,s]],h=[[1,0,0],[0,i,-c],[0,c,i]];return ea(ea(u,l),h)}function Dp(o,t){return[o[0][0]*t[0]+o[0][1]*t[1]+o[0][2]*t[2],o[1][0]*t[0]+o[1][1]*t[1]+o[1][2]*t[2],o[2][0]*t[0]+o[2][1]*t[1]+o[2][2]*t[2]]}function hs(o,t){let e=ls(0,t,0),r=ls(o,0,0);return ea(e,r)}var ps=2.5,ms=class{constructor(t,e){this.nodes=[];this.inputs={w:new A(1),y:new A(1),z:new A(1),x:new A(1)},this.outW=new A(1),this.outXYZ=[new A(1),new A(1),new A(1)],this.inputs.w.connect(this.outW);let r=[this.inputs.x,this.inputs.y,this.inputs.z];this.rot=[];for(let n=0;n<3;n++){let s=[];for(let a=0;a<3;a++){let i=new A(Fp[n][a]);r[a].connect(i),i.connect(this.outXYZ[n]),s.push(i)}this.rot.push(s)}e==="stereo"?this.buildStereoDecode(t):this.buildVirtualSpeakerDecode(t),this.nodes.push(this.inputs.w,this.inputs.y,this.inputs.z,this.inputs.x,this.outW,...this.outXYZ,...this.rot.flat())}buildVirtualSpeakerDecode(t){us(sn).forEach((r,n)=>{let s=sn[n].dir,a=new A(1),i=new A(r.w),c=new A(r.x),u=new A(r.y),l=new A(r.z);this.outW.connect(i),this.outXYZ[0].connect(c),this.outXYZ[1].connect(u),this.outXYZ[2].connect(l),i.connect(a),c.connect(a),u.connect(a),l.connect(a);let h=new gr({panningModel:"HRTF",distanceModel:"inverse",refDistance:ps,rolloffFactor:0,positionX:-s[1]*ps,positionY:s[2]*ps,positionZ:-s[0]*ps});a.connect(h),h.connect(t),this.nodes.push(a,i,c,u,l,h)})}buildStereoDecode(t){let e=new A(1),r=new A(1),n=new A(.5),s=new A(.5),a=new A(.5),i=new A(-.5);this.outW.connect(n),this.outW.connect(s),this.outXYZ[1].connect(a),this.outXYZ[1].connect(i),n.connect(e),a.connect(e),s.connect(r),i.connect(r);let c=new We;e.connect(c,0,0),r.connect(c,0,1),c.connect(t),this.nodes.push(e,r,n,s,a,i,c)}setRotation(t,e=.04){for(let r=0;r<3;r++)for(let n=0;n<3;n++)this.rot[r][n].gain.rampTo(t[r][n],e)}dispose(){for(let t of this.nodes)t.dispose();this.nodes=[]}};var fo=class{constructor(t){this.input=new A(1),this.gw=new A(1),this.gy=new A(0),this.gz=new A(0),this.gx=new A(1),this.input.connect(this.gw),this.input.connect(this.gy),this.input.connect(this.gz),this.input.connect(this.gx),this.gw.connect(t.w),this.gy.connect(t.y),this.gz.connect(t.z),this.gx.connect(t.x)}set(t,e,r,n=.015){let s=r??Ct();this.gw.gain.rampTo(t.w*e,n,s),this.gy.gain.rampTo(t.y*e,n,s),this.gz.gain.rampTo(t.z*e,n,s),this.gx.gain.rampTo(t.x*e,n,s)}dispose(){this.input.dispose(),this.gw.dispose(),this.gy.dispose(),this.gz.dispose(),this.gx.dispose()}};var sa={};go(sa,{AZ_MAX:()=>Rp,EL_MAX:()=>Ip,directivityFromRoundness:()=>na,extentFromSize:()=>ra,reflectionScaleFromViewport:()=>ds,sphereFromRect:()=>oa});var Rp=70*_t,Ip=45*_t;function oa(o,t,e){let r=Me(o.x+o.w/2,0,t),n=Me(o.y+o.h/2,0,e);return{azimuth:-(2*r-1)*Rp,elevation:(1-2*n)*Ip}}function ra(o){return E(.05+.75*Math.pow(E(o,0,1),1.2),0,.95)}function na(o){return E(1-o,0,1)}function ds(o){return .6+Me(o,360,2200)*1}var ia={presence:.7,roomPresence:.5,envelopment:.55,warmth:.5,brilliance:.5};function an(o){let t={...ia,...o??{}};for(let e of Object.keys(t))t[e]=E(t[e],0,1);return t}var Pp=o=>K(.5,1.2,E(o,0,1)),cn=o=>K(0,1.6,E(o,0,1)),qp=o=>E(o,0,1),Vp=o=>K(.7,1.25,E(o,0,1)),aa=o=>K(-3,3,E(o,0,1)),ca=o=>K(-4,3,E(o,0,1)),Lp=o=>K(.75,1.1,E(o,0,1)),Gp=o=>K(1.35,.8,E(o,0,1)),Wp=o=>K(.85,1.15,E(o,0,1));var Bp=[.013,.019,.027,.034],Wf=[1,.85,.7,.6],Bf=[[110*_t,30*_t],[-110*_t,30*_t],[110*_t,-30*_t],[-110*_t,-30*_t]],fs=class{constructor(t,e,r,n){this.delays=[];this.nodes=[];this.erIn=new A(1),this.erMaster=new A(.22*cn(n.roomPresence)),this.erIn.connect(this.erMaster);let s=ds(r);Bp.forEach((a,i)=>{let c=new He({delayTime:a*s,maxDelay:.12}),u=new A(Wf[i]),l=new fo(t),[h,p]=Bf[i];l.set(mo(h,p,.35),1),this.erMaster.connect(c),c.connect(u),u.connect(l.input),this.delays.push(c),this.nodes.push(c,u,l)}),this.split=new lo,e.connect(this.split),this.tailL=new fo(t),this.tailR=new fo(t),this.split.connect(this.tailL.input,0),this.split.connect(this.tailR.input,1),this.applyTail(n),this.nodes.push(this.erIn,this.erMaster,this.split,this.tailL,this.tailR)}applyTail(t){let e=qp(t.envelopment),r=Vp(t.envelopment);this.tailL.set(mo(120*_t,0,e),r),this.tailR.set(mo(-120*_t,0,e),r)}setFactors(t){this.erMaster.gain.rampTo(.22*cn(t.roomPresence),.1),this.applyTail(t)}setViewport(t){let e=ds(t);this.delays.forEach((r,n)=>r.delayTime.rampTo(Bp[n]*e,.3))}dispose(){for(let t of this.nodes)t.dispose();this.nodes=[]}};var gs=class{constructor(t,e,r,n){this.room=t;this.kind="ambisonic";this.factors=an(n),this.bus=new ms(t.spatialIn,e),this.foaRoom=new fs(this.bus.inputs,t.reverb,r,this.factors)}createOutput(){let t=new fo(this.bus.inputs),e=new A(.15),r=new Vt({type:"lowpass",frequency:5e3,rolloff:-12});t.input.connect(e),e.connect(r),r.connect(this.room.reverb),t.input.connect(this.foaRoom.erIn);let n=this;return{input:t.input,setPlacement(s,a){let i=a??Ct(),c=s.sphere,u=s.voice.reverb,l=E(c.extent+u.extentBonus,0,.95),h=mo(c.azimuth,c.elevation,l),p=Pp(n.factors.presence)*Lp(c.directivity);t.set(h,p,a);let m=E(s.reverbSend*Gp(c.directivity)*cn(n.factors.roomPresence),0,1.5);r.frequency.rampTo(u.sendCutoffHz,.02,i),e.gain.cancelScheduledValues(i),u.bloom>.35?(e.gain.setValueAtTime(m*.35,i),e.gain.rampTo(m,Math.max(.08,s.durationS),i)):e.gain.rampTo(m,.02,i)},dispose(){t.dispose(),e.dispose(),r.dispose()}}}setFactors(t){this.factors=t,this.foaRoom.setFactors(t),this.room.setFactors(t)}setRotation(t){this.bus.setRotation(t)}onViewport(t){this.foaRoom.setViewport(t)}dispose(){this.foaRoom.dispose(),this.bus.dispose()}},_s=class{constructor(t,e){this.room=t;this.panningModel=e;this.kind="panner"}createOutput(){let t=new gr({panningModel:this.panningModel,distanceModel:"inverse",refDistance:1,rolloffFactor:.4,positionX:0,positionY:0,positionZ:-2}),e=new A(1),r=new A(.18),n=new Vt({type:"lowpass",frequency:5e3,rolloff:-12});return t.connect(e),t.connect(r),r.connect(n),e.connect(this.room.buses.dryIn),n.connect(this.room.buses.wetIn),{input:t,setPlacement(s,a){let i=a??Ct();t.positionX.rampTo(s.pan.x,.02,i),t.positionY.rampTo(s.pan.y,.02,i),t.positionZ.rampTo(s.pan.z,.02,i),n.frequency.rampTo(s.voice.reverb.sendCutoffHz,.02,i),r.gain.rampTo(E(s.reverbSend,0,1),.02,i)},dispose(){t.dispose(),e.dispose(),r.dispose(),n.dispose()}}}setFactors(t){this.room.setFactors(t)}setRotation(){}onViewport(){}dispose(){}};var jf=40*_t,zf=20*_t,Uf=35*_t,Hf=25*_t,xs=class{constructor(t,e){this.backend=t;this.mode=e;this.target={yaw:0,pitch:0};this.tilt={yaw:0,pitch:0};this.look={yaw:0,pitch:0};this.raf=0;this.running=!1}start(){if(this.running)return;this.running=!0;let t=()=>{if(!this.running)return;let e=E(this.target.yaw+this.tilt.yaw,-Math.PI/2,Math.PI/2),r=E(this.target.pitch+this.tilt.pitch,-Math.PI/3,Math.PI/3),n=K(this.look.yaw,e,.1),s=K(this.look.pitch,r,.1);(Math.abs(n-this.look.yaw)>1e-4||Math.abs(s-this.look.pitch)>1e-4)&&(this.look.yaw=n,this.look.pitch=s,this.backend.setRotation(hs(this.look.yaw,this.look.pitch))),this.raf=requestAnimationFrame(t)};this.raf=requestAnimationFrame(t)}pointTo(t,e){this.mode==="pointer"&&(this.target.yaw=(2*E(t,0,1)-1)*jf,this.target.pitch=(1-2*E(e,0,1))*zf)}tiltTo(t,e){this.tilt.yaw=E(t/45,-1,1)*Uf,this.tilt.pitch=E((e-40)/45,-1,1)*-Hf}lookAt(t,e){this.target.yaw=t,this.target.pitch=e}get state(){return{yaw:this.look.yaw,pitch:this.look.pitch}}dispose(){this.running=!1,cancelAnimationFrame(this.raf)}};var Oa={};go(Oa,{ROOM_HALF_H:()=>br,ROOM_HALF_W:()=>vr,ambienceCutoffFromViewport:()=>ys,attackFromRoundness:()=>_a,brightnessTilt:()=>ha,cutoffFromDepth:()=>Ta,degreeFromSize:()=>ma,durationFromElongation:()=>va,panX:()=>ua,panY:()=>la,pitchNudgeFromRoundness:()=>ya,qFromRoundness:()=>xa,reverbFromViewport:()=>ka,roundness:()=>fa,sendFromShadowBlur:()=>ba,sizeT:()=>pa,stepsFromHeadingLevel:()=>Na,stepsFromSiblingIndex:()=>Ca,velocityFromDepth:()=>Sa,velocityFromSize:()=>da,waveFromRoundness:()=>ga,zBonusFromZIndex:()=>Aa,zFromDepth:()=>wa});var vr=8,br=4;function ua(o,t){return(2*Me(o.x+o.w/2,0,t)-1)*vr}function la(o,t){return(1-2*Me(o.y+o.h/2,0,t))*br}function ha(o,t){return K(1.45,.7,Me(o.y+o.h/2,0,t))}function pa(o,t,e){let r=Math.max(1,o.w*o.h),n=Math.max(1,t*e);return Me(Math.log(1+100*r/n),0,Math.log(101))}var ma=o=>.1+.75*(1-o),da=o=>K(.85,1.25,o);function fa(o,t){let e=Math.min(t.w,t.h)/2;return e<=0?0:E(o/e,0,1)}function ga(o){return o<.15?"square":o<.45?"sawtooth":o<.8?"triangle":"sine"}var _a=o=>K(.002,.045,o),xa=o=>K(2.4,.5,o),ya=o=>(1-o)*1;function va(o){let t=Math.max(o.w,o.h)/Math.max(1,Math.min(o.w,o.h));return E(.18*Math.sqrt(t),.12,1.6)}var ba=o=>E(o/40,0,.5),wa=o=>-(1+.7*Math.min(o,10)),Ta=o=>Math.max(700,9e3*Math.pow(.82,o)),Sa=o=>Math.max(.55,Math.pow(.97,o)),Aa=o=>E(o/50,0,1)*.8,Ca=(o,t=7)=>o%Math.max(1,t),Na=o=>-(7-E(o,1,6))*2;function ka(o){let t=Me(o,360,2200);return{decay:K(.6,4.5,t),wet:K(.08,.32,t)}}var ys=o=>K(400,1400,Me(o,360,2200));var vs=class{constructor(t){this.mode=t;this.target={x:0,y:0};this.tilt={x:0,y:0};this.pos={x:0,y:0};this.raf=0;this.running=!1}start(){if(this.running)return;this.running=!0;let t=gp();t.forwardX.value=0,t.forwardY.value=0,t.forwardZ.value=-1,t.upY.value=1;let e=()=>{if(!this.running)return;let r=E(this.target.x+this.tilt.x,-vr,vr),n=E(this.target.y+this.tilt.y,-br,br);this.pos.x=K(this.pos.x,r,.12),this.pos.y=K(this.pos.y,n,.12);try{t.positionX.value=this.pos.x,t.positionY.value=this.pos.y,t.positionZ.value=0}catch{}this.raf=requestAnimationFrame(e)};this.raf=requestAnimationFrame(e)}pointTo(t,e){this.mode==="pointer"&&(this.target.x=(2*E(t,0,1)-1)*vr*.8,this.target.y=(1-2*E(e,0,1))*br*.8)}tiltTo(t,e){this.tilt.x=E(t/45,-1,1)*4,this.tilt.y=E((e-40)/45,-1,1)*-2}dispose(){this.running=!1,cancelAnimationFrame(this.raf)}};var un=class{constructor(t,e,r){this.opts=t;this.wetGain=null;this.noise=null;this.noiseFilter=null;this.noiseGain=null;this.rushGain=null;this.resizeTimer=null;this.mutedNow=!1;this.toneScale=1;this.limiter=new rs(-1).toDestination(),this.master=new ae(t.volumeDb).connect(this.limiter),this.highShelf=new Vt({type:"highshelf",frequency:4e3,gain:ca(r.brilliance)}).connect(this.master),this.lowShelf=new Vt({type:"lowshelf",frequency:250,gain:aa(r.warmth)}).connect(this.highShelf),this.spatialIn=new A(1).connect(this.lowShelf);let{decay:n,wet:s}=this.roomParams(e);this.reverb=new es({decay:n,preDelay:.02,wet:1}),t.mode==="panner"&&(this.wetGain=new A(s).connect(this.spatialIn),this.reverb.connect(this.wetGain)),this.buses={dryIn:this.spatialIn,wetIn:this.reverb}}setFactors(t){this.lowShelf.gain.rampTo(aa(t.warmth),.1),this.highShelf.gain.rampTo(ca(t.brilliance),.1)}roomParams(t){return this.opts.reverb!=="auto"?{decay:E(Number(this.opts.reverb)||1.5,.1,12),wet:.25}:ka(t)}resize(t){this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>{let{decay:e,wet:r}=this.roomParams(t);try{this.reverb.decay=e,this.wetGain?.gain.rampTo(r,.3),this.noiseFilter?.frequency.rampTo(ys(t)*this.toneScale,.5)}catch(n){console.warn("[sonarium] room resize failed",n)}},400)}startAmbience(t,e,r=1){e<=0||(this.toneScale=r,this.noise=new Jt("brown"),this.noiseFilter=new Vt({frequency:ys(t)*r,type:"lowpass"}),this.noiseGain=new A(co(-46)*E(e/.12,0,3)),this.noise.connect(this.noiseFilter),this.noiseFilter.connect(this.noiseGain),this.noiseGain.connect(this.spatialIn),this.rushGain=new A(0),this.noiseFilter.connect(this.rushGain),this.rushGain.connect(this.spatialIn),this.noise.start())}rush(t){if(!this.rushGain||this.mutedNow)return;let e=Ct();this.rushGain.gain.cancelScheduledValues(e),this.rushGain.gain.rampTo(t,.05,e),this.rushGain.gain.rampTo(0,.45,e+.07)}setHidden(t){this.mutedNow||this.master.volume.rampTo(t?-1/0:this.opts.volumeDb,.3)}setMuted(t){this.mutedNow=t,this.master.volume.rampTo(t?-1/0:this.opts.volumeDb,.15)}dispose(){this.resizeTimer&&clearTimeout(this.resizeTimer),this.noise?.dispose(),this.noiseFilter?.dispose(),this.noiseGain?.dispose(),this.rushGain?.dispose(),this.reverb.dispose(),this.wetGain?.dispose(),this.spatialIn.dispose(),this.lowShelf.dispose(),this.highShelf.dispose(),this.master.dispose(),this.limiter.dispose()}};var Wa={};go(Wa,{PARTIAL_COUNT:()=>bs,airRushGain:()=>Ga,breath:()=>Da,deriveMatter:()=>Ea,detuneJitterCents:()=>Ra,envelopeWeave:()=>qa,filterWeave:()=>Va,genPartials:()=>Ma,glideS:()=>Pa,reverbWeave:()=>La,subShimmer:()=>Ia,transient:()=>Fa});function Ea(o){let t=E(E(o.shadowBlurPx/40,0,.4)+(1-E(o.opacity,0,1))*.6+(o.dashedBorder?.15:0)+(o.isMedia?.35:0)+E(o.backdropBlurPx/40,0,.2),0,1);return{edge:E(1-o.roundness,0,1),mass:E(o.sizeT+(o.massBonus??0),0,1),texture:t,air:E(Math.min(o.depth,10)/10,0,1)}}var bs=24;function Ma(o,t,e=0){let r=Math.max(.8,1+2.6*(1-E(o,0,1))-E(e,0,.5)),n=K(1,.12,E((t-1)/4,0,1)),s=new Float32Array(bs),a=0;for(let c=1;c<=bs;c++){let u=(c%2===1?1:n)/Math.pow(c,r);s[c-1]=u,a+=u*u}let i=1/Math.sqrt(a||1);for(let c=0;c<bs;c++)s[c]=s[c]*i;return s}function Fa(o){let t=E(o,0,1);return{lengthS:K(.005,.025,t),hpHz:2e3+4e3*t,level:.7*t}}function Da(o){let t=E(o,0,1);return{level:.22*t,bpRatio:K(2.5,1.2,t)}}var Ra=o=>6*E(o,0,1);function Ia(o){let t=E(o,0,1);return{interval:t>=.45?-12:12,level:K(.1,.38,E(Math.abs(t-.45)*2,0,1))}}var Pa=o=>K(.028,0,E(o,0,1));function qa(o,t){let e=E(o,0,1),r=E(t,0,1);return{attackS:K(.045,.002,e)+.008*r,decayS:K(.4,.12,e),sustain:K(.35,.15,e),releaseScale:K(.8,1.5,r)}}function Va(o){let t=E(o,0,1);return{q:K(.5,2.4,t),biteAmount:1+3*t,biteDecayS:K(.15,.06,t)}}function La(o,t,e){let r=E(o,0,1),n=E(t,0,1),s=E(e,0,1);return{sendScale:K(1.3,.7,r)*K(.85,1.15,n),sendCutoffHz:K(1200,7e3,r),bloom:1-r,extentBonus:.15*s}}var Ga=o=>E(o*.06,0,.18);var zp=/^H[1-6]$/;function ws(o){let t=(o.getAttribute("role")||"").toLowerCase(),e=o.dataset?.sonicRole;if(e)return e;let r=o.tagName,n=(o.getAttribute("type")||"").toLowerCase();return r==="INPUT"&&(n==="checkbox"||n==="radio")||t==="switch"||t==="checkbox"||r==="SUMMARY"?"toggle":r==="BUTTON"||t==="button"||r==="INPUT"&&(n==="button"||n==="submit"||n==="reset")?"button":r==="A"&&o.hasAttribute("href")||t==="link"?"link":r==="INPUT"||r==="TEXTAREA"||r==="SELECT"||o.isContentEditable?"input":zp.test(r)||t==="heading"?"heading":r==="IMG"||r==="VIDEO"||r==="SVG"||r==="CANVAS"||r==="PICTURE"||r==="AUDIO"?"media":r==="LI"||r==="TR"||["listitem","option","menuitem","tab"].includes(t)?"item":["NAV","SECTION","ARTICLE","ASIDE","FORM","FIELDSET","HEADER","FOOTER","MAIN","DIALOG"].includes(r)||["navigation","region","group","list","menu","tablist","dialog"].includes(t)?"container":r==="P"||r==="BLOCKQUOTE"||r==="LABEL"||r==="SPAN"?"text":"container"}function $f(o,t){let e=0,r=o;for(;r&&r!==t&&e<32;)r=r.parentElement,e++;return e}function Yf(o){let t=o.parentElement;if(!t)return 0;let e=0;for(let r of Array.from(t.children)){if(r===o)return e;(r.tagName===o.tagName||ws(r)===ws(o))&&e++}return 0}function Xf(o,t){return{...t.defaults,...t.roles[o]??{}}}function Zf(o){let t=o;for(;t;){if(t.dataset?.sonic==="quiet")return!0;t=t.parentElement}return!1}var Qf=/^([A-Ga-g][#b]?)(-?\d)$/;function Kf(o){if(!o)return null;let t=o.trim().match(Qf);if(!t)return null;let e={C:0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11},r=t[1].charAt(0).toUpperCase()+t[1].slice(1),n=e[r];return n===void 0?null:(parseInt(t[2],10)+1)*12+n}function ln(o,t){return o.getPropertyValue(t).trim()}function Up(o,t){let{key:e,theme:r,vw:n,vh:s}=t,a=o,i={},c=getComputedStyle(o),u=o.getBoundingClientRect(),l={x:u.x,y:u.y,w:Math.max(1,u.width),h:Math.max(1,u.height)},h=a.dataset?.sonicRole||ln(c,"--sonic-role")||ws(o),p=Xf(h,r);i.role=`<${o.tagName.toLowerCase()}> reads as "${h}" \u2192 ${p.synthKind} voice (theme ${r.name})`;let m=c.borderTopLeftRadius,d=m.endsWith("%")?(parseFloat(m)||0)/100*Math.min(l.w,l.h):parseFloat(m)||0,f=parseFloat(c.opacity),g=eg(c.boxShadow),y=c.position!=="static"&&parseInt(c.zIndex,10)||0,S=$f(o,t.root),O={x:ua(l,n),y:la(l,s),z:wa(S)+Aa(y)};i.position=`center (${Math.round(l.x+l.w/2)}, ${Math.round(l.y+l.h/2)}) px \u2192 (${O.x.toFixed(1)}, ${O.y.toFixed(1)}) m; depth ${S} \u2192 ${O.z.toFixed(1)} m away`;let D=pa(l,n,s),_=ma(D),b=fa(d,l),T=Ca(Yf(o),e.scale.length)+ya(b);if(h==="heading"){let Lt=zp.test(o.tagName)?parseInt(o.tagName[1],10):2;T+=Na(Lt)}T+=p.octaveShift*e.scale.length;let v=Kf(a.dataset?.sonicNote??ln(c,"--sonic-note")??void 0),q=v??is(_,e,T);i.pitch=v!==null?`pinned by data-sonic-note \u2192 ${rn(q)}`:`area ${(l.w*l.h/1e3).toFixed(1)}k px\xB2 (size ${D.toFixed(2)}) + sibling/heading offsets \u2192 ${rn(q)} in ${e.label}`;let P=a.dataset?.sonicWave||ln(c,"--sonic-wave")||p.pinWave||ga(b),I=_a(b);i.timbre=`roundness ${b.toFixed(2)} (radius ${d}px) \u2192 ${P} wave, ${(I*1e3).toFixed(0)} ms attack`;let F=va(l);i.duration=`aspect ${(Math.max(l.w,l.h)/Math.min(l.w,l.h)).toFixed(1)}:1 \u2192 ${F.toFixed(2)} s`;let B=oa(l,n,s),W=parseFloat(a.dataset?.sonicExtent??ln(c,"--sonic-extent")),L={azimuth:B.azimuth,elevation:B.elevation,extent:isNaN(W)?ra(D):E(W,0,1),directivity:na(b)};i.sphere=`az ${(L.azimuth/_t).toFixed(0)}\xB0, el ${(L.elevation/_t).toFixed(0)}\xB0, extent ${L.extent.toFixed(2)} (size wraps the listener), directivity ${L.directivity.toFixed(2)} (sharp beams, round radiates)`;let w=Jf(o,c,h),C=Ta(S)*ha(l,s)*Wp(L.directivity)*Ni(w.luminance);i.filter=`depth ${S} + vertical position + directivity + luminance \u2192 low-pass ${Math.round(C)} Hz`;let k=p.baseVelocity*da(D)*Sa(S)*(isNaN(f)?1:f)*ki(w.luminance),R=ln(c,"--sonic");(Zf(o)||R==="quiet")&&(k*=.4),R==="off"&&(k=0,i.silenced="--sonic: off (aural stylesheet)"),k=E(k,0,1.5);let V=Math.max(l.w,l.h)/Math.max(1,Math.min(l.w,l.h)),J=(h==="text"||h==="heading"||h==="link"||h==="button")&&parseInt(c.fontWeight,10)||400,tt=Ea({roundness:b,sizeT:D,depth:S,shadowBlurPx:g,opacity:isNaN(f)?1:f,dashedBorder:c.borderTopStyle==="dashed"||c.borderTopStyle==="dotted",isMedia:h==="media",backdropBlurPx:tg(c),massBonus:wi(J)}),yt={animationS:c.animationName&&c.animationName!=="none"?jp(c.animationDuration):0,borderStyle:["solid","dashed","dotted"].includes(c.borderTopStyle)?c.borderTopStyle:"none",borderWidthPx:parseFloat(c.borderTopWidth)||0,transitionS:jp(c.transitionDuration)},Y=Ti(tt,yt),nt=qa(tt.edge,tt.mass),lt=Ia(tt.mass),U={matter:tt,partials:Array.from(Ma(tt.edge,V,Mi(w.saturation))),transient:Fa(tt.edge),breath:Da(tt.texture),subShimmer:{interval:lt.interval,level:lt.level+(lt.interval<0?Ei(w.warmth):0)},glideS:Pa(tt.edge),jitterCents:Ra(tt.texture),envelope:{...nt,attackS:nt.attackS*Oi(w.warmth)},filter:Va(tt.edge),reverb:La(tt.edge,tt.mass,tt.texture),patch:Y};(Y.fold.mix>.05||Y.fm.index>.05||Y.lfo.rateHz>.01||Y.unison.mix>0)&&(i.patch=[Y.fold.mix>.05?`border drives the wavefolder \xD7${Y.fold.drive.toFixed(2)}`:"",Y.fm.index>.05?`FM ring ${Y.fm.index.toFixed(2)}`:"",Y.unison.mix>0?`unison +${Y.unison.detuneCents.toFixed(0)}\xA2`:"",Y.lfo.rateHz>.01?`${Y.lfo.shape} LFO ${Y.lfo.rateHz.toFixed(2)} Hz (${yt.animationS>0?"css animation":"dashed border"})`:""].filter(Boolean).join(" \xB7 ")),i.chroma=`warmth ${w.warmth.toFixed(2)} \xB7 sat ${w.saturation.toFixed(2)} \xB7 lum ${w.luminance.toFixed(2)} \u2192 ${w.warmth>.6?"eager onset, full body":w.warmth<.4?"cool, unhurried onset":"neutral temperament"}${w.saturation>.5?", vivid spectrum":""}`,i.matter=`edge ${tt.edge.toFixed(2)} \xB7 mass ${tt.mass.toFixed(2)} \xB7 texture ${tt.texture.toFixed(2)} \xB7 air ${tt.air.toFixed(2)} \u2192 ${U.transient.level>.1?"clicky":"soft"}, ${U.breath.level>.05?"breathy":"clean"}, ${U.subShimmer.interval<0?"chest sub":"sparkle +8va"}, ${U.reverb.bloom>.5?"blooms into the room":"dry strike"}`;let oe=E((.18+ba(g)+.05*Math.min(S,10)*.5)*U.reverb.sendScale,0,1.2);return{role:h,rect:l,pan:O,sphere:L,midi:q,freqHz:xr(q),degree:_,wave:P,attack:I,release:.3*p.releaseScale,durationS:F,filterHz:C,filterQ:xa(b),velocityScale:k,reverbSend:oe,synthKind:p.synthKind,octaveShift:p.octaveShift,voice:U,chroma:w,reasons:i}}function Jf(o,t,e){if(e==="text"||e==="heading"||e==="link")return po(ho(t.color));let r=o,n=t;for(let s=0;r&&s<6;s++){let a=ho((n??getComputedStyle(r)).backgroundColor);if(a&&a.a>=.05)return po(a);r=r.parentElement,n=void 0}return po(ho(getComputedStyle(document.documentElement).backgroundColor))}function jp(o){let t=(o||"").split(",")[0]?.trim()??"";if(!t)return 0;let e=parseFloat(t);return isNaN(e)?0:t.endsWith("ms")?e/1e3:e}function tg(o){let e=(o.backdropFilter||o.webkitBackdropFilter||"").match(/blur\((\d+(\.\d+)?)px\)/);return e?parseFloat(e[1]):0}function eg(o){if(!o||o==="none")return 0;let t=0;for(let e of o.split(/,(?![^(]*\))/)){let r=e.match(/-?\d+(\.\d+)?px/g);r&&r.length>=3&&(t=Math.max(t,parseFloat(r[2])))}return t}var wr=["button","[role=button]","input","textarea","select","[contenteditable]","a[href]","[role=link]","summary","[role=switch]","[role=checkbox]","h1","h2","h3","h4","h5","h6","[role=heading]","img","video","canvas","svg","picture","li","tr","[role=listitem]","[role=option]","[role=menuitem]","[role=tab]","nav","section","article","aside","form","fieldset","dialog","[data-sonic-role]","[data-sonic-note]"].join(","),Hp=400,Ts=class{constructor(t,e){this.env=t;this.cb=e;this.registry=new Map;this.io=null;this.mo=null;this.capWarned=!1;this.initialScanDone=!1;this.mutationTimer=null}scan(){typeof IntersectionObserver<"u"&&(this.io=new IntersectionObserver(t=>{for(let e of t){let r=this.registry.get(e.target);if(!r)continue;let n=r.visible;r.visible=e.isIntersecting,e.isIntersecting&&(r.profile=null),e.isIntersecting&&!n&&this.initialScanDone&&this.cb.onAppear(e.target)}},{threshold:.15})),this.register(this.env.root);for(let t of Array.from(this.env.root.querySelectorAll(wr)))this.register(t);typeof MutationObserver<"u"&&(this.mo=new MutationObserver(t=>this.queueMutations(t)),this.mo.observe(this.env.root,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class","style","data-sonic","data-sonic-note","data-sonic-wave","data-sonic-role"]})),setTimeout(()=>{this.initialScanDone=!0},300)}register(t){if(!(this.registry.has(t)||this.isOff(t))){if(this.registry.size>=Hp){this.capWarned||(this.capWarned=!0,console.warn(`[sonarium] page exceeds ${Hp} tracked elements; extra elements stay silent`));return}this.registry.set(t,{profile:null,visible:!1}),this.io?.observe(t)}}unregister(t){this.registry.has(t)&&(this.registry.delete(t),this.io?.unobserve(t))}isOff(t){let e=t;for(;e;){if(e.dataset?.sonic==="off")return!0;e=e.parentElement}return!1}queueMutations(t){this.mutationTimer&&clearTimeout(this.mutationTimer);let e=t;this.mutationTimer=setTimeout(()=>{for(let r of e){if(r.type==="attributes"&&r.target instanceof Element){let n=this.registry.get(r.target);n&&(n.profile=null);continue}for(let n of Array.from(r.addedNodes))if(n instanceof Element){n.matches?.(wr)&&this.register(n);for(let s of Array.from(n.querySelectorAll?.(wr)??[]))this.register(s)}for(let n of Array.from(r.removedNodes))if(n instanceof Element){this.unregister(n);for(let s of Array.from(n.querySelectorAll?.(wr)??[]))this.unregister(s)}}},150)}profileFor(t){if(this.isOff(t))return null;let e=this.registry.get(t);return e?(e.profile||(e.profile=$p(t,this.env)),e.profile):$p(t,this.env)}invalidateRects(){for(let t of this.registry.values())t.profile=null}visibleElements(){let t=[];for(let[e,r]of this.registry)r.visible&&t.push(e);return t}resolve(t){let e=t;for(;e;){if(this.registry.has(e))return e;e=e.parentElement}return null}updateEnv(t,e){this.env.vw=t,this.env.vh=e}dispose(){this.mutationTimer&&clearTimeout(this.mutationTimer),this.io?.disconnect(),this.mo?.disconnect(),this.registry.clear()}};function $p(o,t){try{return Up(o,t)}catch(e){return console.warn("[sonarium] profile failed",e),null}}var og=Si(),Do=class{constructor(){this.startedSources=!1;this.held=!1;this.out=new A(1),this.mix=new A(.9),this.oscA=new ut({frequency:220}),this.oscA2=new ut({frequency:220}),this.oscB=new ut({frequency:110,type:"sine"}),this.oscBGain=new A(.2),this.foldPre=new A(.3),this.foldShaper=new Xt(og),this.foldWet=new A(0),this.foldDry=new A(1),this.oscA.connect(this.foldPre),this.foldPre.connect(this.foldShaper),this.foldShaper.connect(this.foldWet),this.foldWet.connect(this.mix),this.oscA.connect(this.foldDry),this.foldDry.connect(this.mix),this.unisonGain=new A(0),this.oscA2.connect(this.unisonGain),this.unisonGain.connect(this.mix),this.fmGain=new A(0),this.oscB.connect(this.fmGain),this.fmGain.connect(this.oscA.frequency),this.oscB.connect(this.oscBGain),this.oscBGain.connect(this.mix),this.breathNoise=new Jt("pink"),this.breathFilter=new Vt({type:"bandpass",frequency:600,Q:1.1}),this.breathGain=new A(0),this.breathNoise.connect(this.breathFilter),this.breathFilter.connect(this.breathGain),this.breathGain.connect(this.mix),this.ampEnv=new Ge({attack:.01,decay:.2,sustain:.25,release:.3}),this.mix.connect(this.ampEnv),this.ampEnv.connect(this.out),this.burstNoise=new Jt("white"),this.burstFilter=new Vt({type:"highpass",frequency:3e3}),this.burstEnv=new Ge({attack:.001,decay:.02,sustain:0,release:.02}),this.burstNoise.connect(this.burstFilter),this.burstFilter.connect(this.burstEnv),this.burstEnv.connect(this.out),this.lfo=new Oe({frequency:.5,min:-1,max:1,type:"sine"}),this.lfoVib=new A(0),this.lfoTrem=new A(0),this.modFilterOut=new A(0),this.lfo.connect(this.lfoVib),this.lfo.connect(this.lfoTrem),this.lfo.connect(this.modFilterOut),this.lfoVib.connect(this.oscA.detune),this.lfoVib.connect(this.oscA2.detune),this.lfoTrem.connect(this.mix.gain)}connect(t){return this.out.connect(t),this}ensureRunning(t){this.startedSources||(this.startedSources=!0,this.oscA.start(t),this.oscA2.start(t),this.oscB.start(t),this.breathNoise.start(t),this.burstNoise.start(t),this.lfo.start(t))}sleep(){if(!(!this.startedSources||this.held)){this.startedSources=!1;try{this.oscA.stop(),this.oscA2.stop(),this.oscB.stop(),this.breathNoise.stop(),this.burstNoise.stop(),this.lfo.stop()}catch{}}}applyVoice(t,e,r){let n=t.voice;this.ensureRunning(e),this.oscA.partials=n.partials,this.oscA2.partials=n.partials;let s=(Math.random()*2-1)*n.jitterCents;this.oscA.detune.setValueAtTime(s,e);let a=n.glideS+n.patch.portamentoS;a>.002&&!this.held?(this.oscA.frequency.setValueAtTime(t.freqHz*.917,e),this.oscA.frequency.rampTo(t.freqHz,a,e)):this.oscA.frequency.setValueAtTime(t.freqHz,e),this.oscA2.frequency.setValueAtTime(t.freqHz,e),this.oscA2.detune.setValueAtTime(s+n.patch.unison.detuneCents,e),this.unisonGain.gain.rampTo(n.patch.unison.mix,.02,e),this.oscB.frequency.setValueAtTime(t.freqHz*Math.pow(2,n.subShimmer.interval/12),e),this.oscBGain.gain.rampTo(n.subShimmer.level,.02,e),this.foldPre.gain.rampTo(.3+n.patch.fold.drive*1.2,.02,e),this.foldWet.gain.rampTo(n.patch.fold.mix,.02,e),this.foldDry.gain.rampTo(1-n.patch.fold.mix*.7,.02,e),this.fmGain.gain.rampTo(n.patch.fm.index*t.freqHz,.02,e);let i=n.patch.lfo.rateHz>.01;this.lfo.frequency.value=Math.max(.01,n.patch.lfo.rateHz),this.lfo.type=n.patch.lfo.shape,this.lfoVib.gain.rampTo(i?n.patch.lfo.vibratoCents:0,.05,e),this.lfoTrem.gain.rampTo(i?.9*n.patch.lfo.tremolo:0,.05,e),this.modFilterOut.gain.rampTo(i?n.patch.lfo.filterDepth*r:0,.05,e),this.breathFilter.frequency.rampTo(Math.min(8e3,t.freqHz*n.breath.bpRatio),.02,e),this.breathGain.gain.rampTo(n.breath.level,.02,e),this.ampEnv.attack=n.envelope.attackS,this.ampEnv.decay=n.envelope.decayS,this.ampEnv.sustain=n.envelope.sustain,this.ampEnv.release=.3*t.releaseScaleBase*n.envelope.releaseScale}trigger(t,e,r=4e3){this.applyVoice(t,e,r),this.ampEnv.triggerAttackRelease(t.durationS,e,t.velocity),t.voice.transient.level>.02&&(this.burstFilter.frequency.setValueAtTime(t.voice.transient.hpHz,e),this.burstEnv.decay=t.voice.transient.lengthS,this.burstEnv.triggerAttackRelease(t.voice.transient.lengthS,e,t.velocity*t.voice.transient.level))}gateOn(t,e,r=4e3){this.applyVoice(t,e,r),this.held=!0,this.ampEnv.sustain=Math.max(.4,t.voice.envelope.sustain),this.ampEnv.triggerAttack(e,t.velocity)}setFreq(t,e,r,n){let s=Math.max(.015,e);this.oscA.frequency.rampTo(t,s),this.oscA2.frequency.rampTo(t,s),this.oscB.frequency.rampTo(t*Math.pow(2,r/12),s),this.fmGain.gain.rampTo(n*t,s)}gateOff(t){return this.held=!1,this.ampEnv.triggerRelease(t??Ct()),this.ampEnv.release}releaseTail(){return this.ampEnv.release}dispose(){for(let t of[this.oscA,this.oscA2,this.oscB,this.oscBGain,this.fmGain,this.foldPre,this.foldShaper,this.foldWet,this.foldDry,this.unisonGain,this.breathNoise,this.breathFilter,this.breathGain,this.burstNoise,this.burstFilter,this.burstEnv,this.lfo,this.lfoVib,this.lfoTrem,this.modFilterOut,this.ampEnv,this.mix,this.out])t.dispose()}};var hn=class{constructor(t,e){this.backend=t;this.maxVoices=e;this.lanes=[];this.maxVoices=E(e,4,24),this.sleepTimer=setInterval(()=>{let r=Ct();for(let n of this.lanes)n.synth instanceof Do&&n.busyUntil<r-30&&n.synth.sleep()},1e4)}createSynth(t){switch(t){case"matter":return new Do;case"fm":return new Xn({harmonicity:3,modulationIndex:8,envelope:{attack:.01,decay:.3,sustain:.1,release:1.4},modulationEnvelope:{attack:.01,decay:.4,sustain:.2,release:1}});case"pluck":return new Kn({attackNoise:1,dampening:3e3,resonance:.92});case"membrane":return new hr({pitchDecay:.04,octaves:5,envelope:{attack:.001,decay:.35,sustain:.01,release:.6}});case"noise":return new Zn({noise:{type:"white"},envelope:{attack:.001,decay:.06,sustain:0,release:.05}});default:return new Ee({oscillator:{type:"triangle"},envelope:{attack:.01,decay:.1,sustain:.25,release:.3}})}}createLane(t){let e=this.createSynth(t),r=new Vt({frequency:4e3,type:"lowpass",rolloff:-12,Q:1}),n=this.backend.createOutput();e.connect(r),r.connect(n.input),e instanceof Do&&e.modFilterOut.connect(r.frequency);let s={kind:t,synth:e,filter:r,out:n,busyUntil:0};return this.lanes.push(s),s}acquire(t){let e=Ct(),r=null,n=null,s=null;for(let i of this.lanes){if(i.kind===t){if(i.busyUntil<=e){r=i;break}(!n||i.busyUntil<n.busyUntil)&&(n=i)}(!s||i.busyUntil<s.busyUntil)&&(s=i)}if(r)return r;if(this.lanes.length<this.maxVoices)return this.createLane(t);if(n)return n;let a=s??this.lanes[0];return a.synth.dispose(),a.synth=this.createSynth(t),a.synth.connect(a.filter),a.kind=t,a}trigger(t,e,r){let n=e*t.velocityScale;if(n<=.01)return;let s=r??Ct(),a=E(n,.03,1),i=this.acquire(t.synthKind),c=Math.max(200,t.filterHz);if(i.kind==="matter"){let l=t.voice;i.filter.Q.rampTo(l.filter.q,.02,s),i.filter.frequency.cancelScheduledValues(s),i.filter.frequency.setValueAtTime(Math.min(12e3,c*l.filter.biteAmount),s),i.filter.frequency.exponentialRampTo(c,l.filter.biteDecayS,s)}else i.filter.frequency.rampTo(c,.02,s),i.filter.Q.rampTo(t.filterQ,.02,s);i.out.setPlacement(t,s);let u=t.durationS;try{switch(i.kind){case"matter":{let l=i.synth;l.trigger({freqHz:t.freqHz,velocity:a,durationS:u,releaseScaleBase:t.release/.3,voice:t.voice},s,c),i.busyUntil=s+u+l.releaseTail();return}case"noise":{i.synth.triggerAttackRelease(Math.min(u,.2),s,a);break}case"pluck":{let l=i.synth;l.set({dampening:E(t.filterHz,400,7e3)}),l.triggerAttackRelease(t.freqHz,u,s,a);break}case"membrane":{let l=i.synth;l.set({envelope:{attack:Math.max(.001,t.attack/4),release:t.release}}),l.triggerAttackRelease(Math.max(30,t.freqHz/4),u,s,a);break}case"fm":{let l=i.synth;l.set({envelope:{attack:t.attack,release:t.release*2}}),l.triggerAttackRelease(t.freqHz,u,s,a);break}default:{let l=i.synth;l.set({oscillator:{type:t.wave},envelope:{attack:t.attack,decay:.08,sustain:.25,release:t.release}}),l.triggerAttackRelease(t.freqHz,u,s,a)}}i.busyUntil=s+u+t.release}catch(l){console.warn("[sonarium] trigger failed",l)}}get activeCount(){let t=Ct();return this.lanes.filter(e=>e.busyUntil>t).length}sustain(t,e){let r=e*t.velocityScale;if(r<=.01)return null;let n=this.acquire("matter");if(!(n.synth instanceof Do))return null;let s=n.synth,a=Ct(),i=Math.max(200,t.filterHz);n.filter.Q.rampTo(t.voice.filter.q,.02,a),n.filter.frequency.cancelScheduledValues(a),n.filter.frequency.setValueAtTime(Math.min(12e3,i*t.voice.filter.biteAmount),a),n.filter.frequency.exponentialRampTo(i,t.voice.filter.biteDecayS,a),n.out.setPlacement(t,a),s.gateOn({freqHz:t.freqHz,velocity:E(r,.03,1),durationS:9999,releaseScaleBase:t.release/.3,voice:t.voice},a,i),n.busyUntil=a+9999;let c=t.voice;return{setFreq(u,l){s.setFreq(u,l,c.subShimmer.interval,c.patch.fm.index)},release(){let u=s.gateOff();n.busyUntil=Ct()+u}}}dispose(){clearInterval(this.sleepTimer);for(let t of this.lanes)t.synth.dispose(),t.filter.dispose(),t.out.dispose();this.lanes=[]}};var rg=new Set(["button","link","toggle","input","item","heading","media","text"]),ng=80,sg=250,ig=400,ag=4;function Yp(o){let t=new WeakMap,e=-1/0,r=-1/0,n=c=>{r=performance.now(),o.rig?.pointTo(c.clientX/window.innerWidth,c.clientY/window.innerHeight)},s=()=>{e=performance.now()},a=(c,u)=>{let l=c;for(let h=0;l&&h<=ag;h++){if(l===u)return!0;l=l.parentElement}return!1},i=c=>{let u=performance.now();if(u-e<sg||u-r>ig)return;let l=c.target,h=o.scanner?.resolve(l);if(!h||!l||!a(l,h))return;let p=o.scanner.profileFor(h);!p||!rg.has(p.role)||u-(t.get(h)??-1/0)<ng||(t.set(h,u),o.excite(h,.25,"preview"))};return window.addEventListener("pointermove",n,{passive:!0}),window.addEventListener("pointerover",i,{passive:!0}),window.addEventListener("scroll",s,{passive:!0,capture:!0}),()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerover",i),window.removeEventListener("scroll",s,{capture:!0})}}var cg=80;function Xp(o){let t=new WeakMap,e=a=>{let i=o.scanner?.resolve(a);if(!i)return;let c=performance.now();if(c-(t.get(i)??-1/0)<cg)return;t.set(i,c);let u=o.scanner.profileFor(i);if(u&&u.role!=="toggle"){if(u.role==="container"){let l=Array.from(i.querySelectorAll(wr)).filter(h=>h.parentElement&&o.scanner.resolve(h)===h).filter(h=>{let p=h.getBoundingClientRect();return p.width>0&&p.bottom>0&&p.top<window.innerHeight});if(l.length>=2){o.strum(l,.5);return}}o.excite(i,.75,"hit")}},r=a=>e(a.target),n=a=>e(a.target),s=a=>{let i=a.target;if(!(i instanceof HTMLInputElement)||i.type!=="checkbox"&&i.type!=="radio")return;let c=i.checked;o.excite(i,.5,c?"toggle-on":"toggle-off")};return window.addEventListener("pointerdown",r,{passive:!0}),window.addEventListener("click",n,{passive:!0}),window.addEventListener("change",s,{passive:!0}),()=>{window.removeEventListener("pointerdown",r),window.removeEventListener("click",n),window.removeEventListener("change",s)}}var Zp=[0,2,4,7,9,12,14,16];function Qp(o){let t=0,e=-1/0,r=()=>{e=performance.now()},n=a=>{if(performance.now()-e<500)return;let i=o.scanner?.resolve(a.target);i&&o.excite(i,.35,"preview")},s=a=>{let i=a.target;if(!(i instanceof HTMLElement&&(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i.isContentEditable)))return;let u=performance.now();if(u-t<30)return;t=u;let l=i.value?.length??i.textContent?.length??0,h=Zp[Math.min(Zp.length-1,Math.floor(l/4))];o.excite(i,.15,"tick",void 0,h)};return window.addEventListener("pointerdown",r,{passive:!0,capture:!0}),window.addEventListener("focusin",n,{passive:!0}),window.addEventListener("keydown",s,{passive:!0}),()=>{window.removeEventListener("pointerdown",r,{capture:!0}),window.removeEventListener("focusin",n),window.removeEventListener("keydown",s)}}function Kp(o){let t=!1,e=window.scrollY,r=performance.now(),n=()=>{t||(t=!0,requestAnimationFrame(()=>{t=!1,o.geometryChanged();let i=performance.now(),c=Math.max(1,i-r),u=Math.abs(window.scrollY-e)/c;e=window.scrollY,r=i,o.airRush(Ga(u))}))},s=!1,a=()=>{s||(s=!0,requestAnimationFrame(()=>{s=!1,o.roomResized()}))};return window.addEventListener("scroll",n,{passive:!0,capture:!0}),window.addEventListener("resize",a,{passive:!0}),()=>{window.removeEventListener("scroll",n,{capture:!0}),window.removeEventListener("resize",a)}}function Jp(o){if(typeof DeviceOrientationEvent>"u")return()=>{};let t=0,e=!1,r=i=>{i.gamma==null||i.beta==null||o.rig?.tiltTo(i.gamma,i.beta)},n=i=>{let c=i.accelerationIncludingGravity;if(!c||c.x==null||c.y==null||c.z==null)return;let u=Math.abs(Math.sqrt(c.x*c.x+c.y*c.y+c.z*c.z)-9.81),l=performance.now();if(!(l-t<=600)){if(u>18){t=l,o.strum(o.scanner.visibleElements(),.5);return}Math.abs(c.x)>12&&Math.abs(c.x)>2*Math.abs(c.y)&&(t=l,o.strum(o.scanner.visibleElements(),.4,"strum",c.x>0))}},s=()=>{e||(e=!0,window.addEventListener("deviceorientation",r,{passive:!0}),window.addEventListener("devicemotion",n,{passive:!0}))},a=DeviceOrientationEvent.requestPermission;return typeof a=="function"?a.call(DeviceOrientationEvent).then(i=>{i==="granted"&&s()}).catch(()=>{}):s(),()=>{e&&(window.removeEventListener("deviceorientation",r),window.removeEventListener("devicemotion",n))}}function tm(o){let t=null,e=s=>{if(!s.isPrimary)return;let a=o.scanner?.resolve(s.target);if(!a)return;let i=o.scanner.profileFor(a);!i||i.role==="container"||i.role==="text"||(t={x0:s.clientX,el:a,handle:null})},r=s=>{if(!t)return;let a=s.clientX-t.x0;if(!t.handle){if(Math.abs(a)<14)return;if(t.handle=o.ribbon(t.el),!t.handle){t=null;return}}t.handle.move(a)},n=()=>{t?.handle?.release(),t=null};return window.addEventListener("pointerdown",e,{passive:!0}),window.addEventListener("pointermove",r,{passive:!0}),window.addEventListener("pointerup",n,{passive:!0}),window.addEventListener("pointercancel",n,{passive:!0}),()=>{n(),window.removeEventListener("pointerdown",e),window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",n),window.removeEventListener("pointercancel",n)}}var ug={button:0,link:1,toggle:2,input:3,heading:4,media:5,item:6,text:7,container:8};function em(o){let t=navigator;if(typeof t.requestMIDIAccess!="function")return()=>{};let e=null,r=null;return t.requestMIDIAccess().then(n=>{e=n.outputs.values().next().value??null,e&&(r=o.on("trigger",a=>{let i=a,c=Math.max(0,Math.min(127,Math.round(i.profile.midi))),u=Math.max(1,Math.min(127,Math.round(i.velocity*i.profile.velocityScale*127))),l=ug[i.profile.role]??9;try{e.send([144|l,c,u]),setTimeout(()=>{try{e?.send([128|l,c,0])}catch{}},Math.min(4e3,i.profile.durationS*1e3+60))}catch{}}))}).catch(()=>{}),()=>r?.()}var Ss=class{constructor(t={}){this.state="idle";this.muted=!1;this.pool=null;this.room=null;this.rig=null;this.backend=null;this.phraseLoop=null;this.activity=new WeakMap;this.gate=null;this.detachers=[];this.listeners=new Map;this.unlockHandler=null;this.appearBucket=6;this.bucketTimer=null;this.starting=!1;if(typeof window>"u"||typeof document>"u")throw new Error("[sonarium] requires a browser environment (create() in the client only)");let e=(t.respectReducedMotion??!0)&&typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,r=getComputedStyle(document.documentElement),n=getComputedStyle(document.body);this.palette=Di(po(ho(n.backgroundColor)),po(ho(n.color)));let s=r.getPropertyValue("--sonic-key").trim(),a=(t.key&&t.key!=="auto"?on(t.key):null)??(s?on(s):null);if(!a){let c=ss(location.hostname),u=Fi(this.palette);a=u?{...c,scaleName:u,scale:Fo[u],label:`${c.label.split(" ")[0]} ${u}`}:c}this.opts={root:t.root??document.body,theme:Np(t.theme),key:a,listener:t.listener??"pointer",ambient:e?0:E(t.ambient??.12,0,1),motion:t.motion??!0,gate:t.gate??"chip",volume:t.volume??-10,maxVoices:E(t.maxVoices??18,4,24),panning:t.panning==="equalpower"?"equalpower":"HRTF",spatial:t.spatial==="panner"?"panner":"ambisonic",reverb:t.reverb??"auto",velocityFactor:e?.7:1,midi:t.midi===!0},this.factors=an(t.perceptual),this.env={root:this.opts.root,key:this.opts.key,theme:this.opts.theme,vw:window.innerWidth,vh:window.innerHeight},this.muted=Op(),this.scanner=new Ts(this.env,{onAppear:c=>this.whisper(c)}),this.scanner.scan();let i=parseFloat(r.getPropertyValue("--sonic-tempo"));this.tempo=i>0?E(Math.round(i),30,200):qi(this.scanner.registry.size,Ii(this.palette.warmth)),this.arm()}arm(){this.state="armed",this.opts.gate==="chip"&&(this.gate=Ep(()=>this.toggleMute()),this.gate.setState(this.muted?"muted":"armed")),this.muted||(this.unlockHandler=()=>{this.start()},window.addEventListener("pointerdown",this.unlockHandler,{capture:!0}),window.addEventListener("keydown",this.unlockHandler,{capture:!0}),window.addEventListener("click",this.unlockHandler,{capture:!0}))}removeUnlockListeners(){this.unlockHandler&&(window.removeEventListener("pointerdown",this.unlockHandler,{capture:!0}),window.removeEventListener("keydown",this.unlockHandler,{capture:!0}),window.removeEventListener("click",this.unlockHandler,{capture:!0}),this.unlockHandler=null)}async start(){if(this.state==="running"||this.state==="disposed"||this.starting)return;this.starting=!0;try{await Promise.race([ci(),new Promise(e=>setTimeout(e,1500))])}catch(e){console.warn("[sonarium] audio context could not start yet",e)}finally{this.starting=!1}if(dt().state!=="running"||this.state==="disposed")return;this.state="running",this.removeUnlockListeners(),this.gate?.setState(this.muted?"muted":"on"),this.buildAudioGraph(),this.muted&&this.room?.setMuted(!0),this.detachers.push(Yp(this),Xp(this),Qp(this),Kp(this),tm(this)),this.opts.motion&&this.detachers.push(Jp(this)),this.opts.midi&&this.detachers.push(em(this));let t=()=>this.room?.setHidden(document.hidden);document.addEventListener("visibilitychange",t),this.detachers.push(()=>document.removeEventListener("visibilitychange",t)),this.bucketTimer=setInterval(()=>{this.appearBucket=Math.min(6,this.appearBucket+6)},1e3),ns().bpm.value=this.tempo,ns().start(),this.room?.startAmbience(this.env.vw,this.opts.ambient,Ri(this.palette.warmth)),this.opts.ambient>0&&(this.phraseLoop=new tn(e=>this.playPhrase(e),"1m"),this.phraseLoop.start("1m")),this.playIntroMotif(),this.emit("start")}playPhrase(t){if(this.state!=="running"||this.muted||document.hidden||((t===void 0||!Number.isFinite(t))&&(t=Ct()),Math.random()>Hi))return;let e=this.scanner.visibleElements().map(c=>({el:c,p:this.scanner.profileFor(c)})).filter(c=>!!c.p&&c.p.role!=="container"&&c.p.velocityScale>.01).sort((c,u)=>cs(c.p.rect.y,c.p.rect.x)-cs(u.p.rect.y,u.p.rect.x));if(e.length<nn)return;let r=Math.min(e.length,nn+Math.floor(Math.random()*($i-nn+1))),n=Math.max(1,document.documentElement.scrollHeight-window.innerHeight),s=Yi(e.length,r,window.scrollY/n),a=yr(this.tempo)/2,i=.07*(this.opts.ambient/.12);e.slice(s,s+r).forEach(({el:c},u)=>this.excite(c,i,"phrase",t+u*a))}buildAudioGraph(){let t={volumeDb:this.opts.volume,reverb:this.opts.reverb,ambient:this.opts.ambient};if(this.opts.spatial==="ambisonic")try{this.room=new un({...t,mode:"ambisonic"},this.env.vw,this.factors);let e=this.opts.panning==="equalpower"?"stereo":"binaural";this.backend=new gs(this.room,e,this.env.vw,this.factors),this.rig=new xs(this.backend,this.opts.listener),this.rig.start(),this.pool=new hn(this.backend,this.opts.maxVoices);return}catch(e){console.warn("[sonarium] ambisonic backend unavailable, falling back to panner",e),this.room?.dispose(),this.room=null}this.room=new un({...t,mode:"panner"},this.env.vw,this.factors),this.backend=new _s(this.room,this.opts.panning),this.rig=new vs(this.opts.listener),this.rig.start(),this.pool=new hn(this.backend,this.opts.maxVoices)}ribbon(t){if(this.state!=="running"||this.muted||!this.pool)return null;let e=this.scanner.resolve(t)??t,r=this.scanner.profileFor(e);if(!r)return null;let n=this.pool.sustain(r,.6);if(!n)return null;this.emit("trigger",{el:e,profile:r,velocity:.6,articulation:"ribbon"});let s=this.opts.key,a=.03+r.voice.patch.portamentoS,i=r.midi;return{move:c=>{let u=as(r.midi,s,Ai(c,this.env.vw,s.scale.length));u!==i&&(i=u,n.setFreq(xr(u),a))},release:()=>n.release()}}airRush(t){this.state!=="running"||this.muted||t<=.005||this.room?.rush(t)}setPerceptual(t){this.factors=an({...this.factors,...t}),this.backend?.setFactors(this.factors)}toggleMute(){if(this.state!=="running"){this.muted=!1,Ki(!1),this.start();return}this.muted=!this.muted,Ki(this.muted),this.room?.setMuted(this.muted),this.gate?.setState(this.muted?"muted":"on"),this.emit("mute",this.muted)}dispose(){if(this.state!=="disposed"){this.state="disposed",this.removeUnlockListeners(),this.bucketTimer&&clearInterval(this.bucketTimer),this.phraseLoop?.dispose();for(let t of this.detachers.splice(0))try{t()}catch{}this.scanner?.dispose(),this.rig?.dispose(),this.pool?.dispose(),this.backend?.dispose(),this.room?.dispose(),this.gate?.dispose(),this.emit("dispose"),this.listeners.clear()}}excite(t,e,r,n,s=0){if(this.state!=="running"||this.muted||!this.pool)return;n!==void 0&&!Number.isFinite(n)&&(n=void 0);let a=this.scanner.resolve(t)??t,i=this.scanner.profileFor(a);if(i){if(r!=="motif"&&r!=="echo"&&r!=="phrase"&&r!=="whisper"){let c=performance.now(),u=this.activity.get(a)??{c:0,t:c};u.c=zi(u.c,c-u.t)+1,u.t=c,this.activity.set(a,u),e*=Ui(u.c-1)}if(s!==0&&(i={...i,midi:i.midi+s,freqHz:i.freqHz*Math.pow(2,s/12)}),r==="tick"&&(i={...i,durationS:Math.min(i.durationS,.07),release:.05}),r==="toggle-on"||r==="toggle-off"){let c=r==="toggle-on"?1:-1,u={...i,durationS:.12};this.pool.trigger(u,e*this.opts.velocityFactor,n);let l={...i,midi:i.midi+c*7,freqHz:i.freqHz*Math.pow(2,c*7/12),durationS:.16};this.pool.trigger(l,e*this.opts.velocityFactor,(n??Ct())+.09)}else this.pool.trigger(i,e*this.opts.velocityFactor,n);if(r==="hit"&&e>=.55){let c=Vi(ns().seconds,ji(this.tempo),Bi);this.excite(a,e*Wi,"echo",Ct()+c,Gi)}this.emit("trigger",{el:a,profile:i,velocity:e,articulation:r})}}strum(t,e,r="strum",n=!1){if(this.state!=="running"||!this.pool)return;let s=t.map(c=>({el:c,p:this.scanner.profileFor(c)})).filter(c=>!!c.p).sort((c,u)=>n?u.p.rect.x-c.p.rect.x:c.p.rect.x-u.p.rect.x).slice(0,6),a=Ct(),i=Li(this.tempo);s.forEach(({el:c},u)=>this.excite(c,e,r,a+u*i))}whisper(t){this.appearBucket<=0||(this.appearBucket--,this.excite(t,.12,"whisper"))}playIntroMotif(){let t=Array.from(this.opts.root.querySelectorAll("h1, h2, nav, main, [role=banner], header, button, [role=button]")).filter(a=>{let i=a.getBoundingClientRect();return i.width>0&&i.height>0&&i.top<this.env.vh}),e=t.map(a=>({el:a,area:a.getBoundingClientRect().width*a.getBoundingClientRect().height})).sort((a,i)=>i.area-a.area).slice(0,5).map(a=>a.el),r=t.filter(a=>e.includes(a)),n=Ct()+.1,s=yr(this.tempo)/4;r.forEach((a,i)=>this.excite(a,.3,"motif",n+i*s))}describe(t){return this.scanner.profileFor(t)}geometryChanged(){this.env.vw=window.innerWidth,this.env.vh=window.innerHeight,this.scanner?.updateEnv(this.env.vw,this.env.vh),this.scanner?.invalidateRects()}roomResized(){this.geometryChanged(),this.room?.resize(this.env.vw),this.backend?.onViewport(this.env.vw)}on(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>this.listeners.get(t)?.delete(e)}emit(t,e){for(let r of this.listeners.get(t)??[])try{r(e)}catch(n){console.warn("[sonarium] listener error",n)}}};var lg="0.6.0";function om(o={}){return new Ss(o)}function hg(){if(typeof document>"u")return;let o=document.currentScript;if(!o||o.dataset.auto===void 0)return;let t={};o.dataset.theme&&(t.theme=o.dataset.theme),o.dataset.key&&(t.key=o.dataset.key),o.dataset.ambient&&(t.ambient=parseFloat(o.dataset.ambient)),o.dataset.listener&&(t.listener=o.dataset.listener),o.dataset.volume&&(t.volume=parseFloat(o.dataset.volume)),o.dataset.panning&&(t.panning=o.dataset.panning);let e=()=>{try{let r=om(t);window.sonarium=r}catch(r){console.warn("[sonarium] auto-init failed",r)}};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}hg();return pm(pg);})();
|
|
226
|
+
/*! Bundled license information:
|
|
227
|
+
|
|
228
|
+
tone/build/esm/core/Tone.js:
|
|
229
|
+
(**
|
|
230
|
+
* Tone.js
|
|
231
|
+
* @author Yotam Mann
|
|
232
|
+
* @license http://opensource.org/licenses/MIT MIT License
|
|
233
|
+
* @copyright 2014-2024 Yotam Mann
|
|
234
|
+
*)
|
|
235
|
+
*/
|
|
236
|
+
//# sourceMappingURL=sonarium.iife.js.map
|