270 lines
245 KiB
JavaScript
270 lines
245 KiB
JavaScript
import{a as Yr,b as Zr,i as $r}from"./lit-element-BUNo9pnf.js";import{t as Xr}from"./custom-element-BhZVzxrc.js";import{r as Fi}from"./state-C9toMb2g.js";import{e as Hr}from"./query-BApjzB0v.js";import{E as Qr,p as ut,M as Pt,T as Vt,n as hi,l as di,V as Fe,R as Kr,S as Jr,P as eo,i as Dn,G as bs,a as pi,k as fi,W as to,A as no,D as so}from"./three.module-Unazwo7z.js";import{a as de,b as Be}from"./tslib.es6-h7HTSAm4.js";import"./property-MreHcJY-.js";const mi={type:"change"},Cs={type:"start"},gi={type:"end"};class io extends Qr{constructor(e,t){super(),t===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),t===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=e,this.domElement=t,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new ut,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:Pt.ROTATE,MIDDLE:Pt.DOLLY,RIGHT:Pt.PAN},this.touches={ONE:Vt.ROTATE,TWO:Vt.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return a.phi},this.getAzimuthalAngle=function(){return a.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(T){T.addEventListener("keydown",Se),this._domElementKeyEvents=T},this.saveState=function(){n.target0.copy(n.target),n.position0.copy(n.object.position),n.zoom0=n.object.zoom},this.reset=function(){n.target.copy(n.target0),n.object.position.copy(n.position0),n.object.zoom=n.zoom0,n.object.updateProjectionMatrix(),n.dispatchEvent(mi),n.update(),r=i.NONE},this.update=function(){const T=new ut,W=new di().setFromUnitVectors(e.up,new ut(0,1,0)),me=W.clone().invert(),ye=new ut,Ve=new di,Rt=2*Math.PI;return function(){const ui=n.object.position;T.copy(ui).sub(n.target),T.applyQuaternion(W),a.setFromVector3(T),n.autoRotate&&r===i.NONE&&O(b()),n.enableDamping?(a.theta+=c.theta*n.dampingFactor,a.phi+=c.phi*n.dampingFactor):(a.theta+=c.theta,a.phi+=c.phi);let Je=n.minAzimuthAngle,et=n.maxAzimuthAngle;return isFinite(Je)&&isFinite(et)&&(Je<-Math.PI?Je+=Rt:Je>Math.PI&&(Je-=Rt),et<-Math.PI?et+=Rt:et>Math.PI&&(et-=Rt),Je<=et?a.theta=Math.max(Je,Math.min(et,a.theta)):a.theta=a.theta>(Je+et)/2?Math.max(Je,a.theta):Math.min(et,a.theta)),a.phi=Math.max(n.minPolarAngle,Math.min(n.maxPolarAngle,a.phi)),a.makeSafe(),a.radius*=l,a.radius=Math.max(n.minDistance,Math.min(n.maxDistance,a.radius)),n.enableDamping===!0?n.target.addScaledVector(u,n.dampingFactor):n.target.add(u),T.setFromSpherical(a),T.applyQuaternion(me),ui.copy(n.target).add(T),n.object.lookAt(n.target),n.enableDamping===!0?(c.theta*=1-n.dampingFactor,c.phi*=1-n.dampingFactor,u.multiplyScalar(1-n.dampingFactor)):(c.set(0,0,0),u.set(0,0,0)),l=1,h||ye.distanceToSquared(n.object.position)>o||8*(1-Ve.dot(n.object.quaternion))>o?(n.dispatchEvent(mi),ye.copy(n.object.position),Ve.copy(n.object.quaternion),h=!1,!0):!1}}(),this.dispose=function(){n.domElement.removeEventListener("contextmenu",Dt),n.domElement.removeEventListener("pointerdown",En),n.domElement.removeEventListener("pointercancel",oe),n.domElement.removeEventListener("wheel",te),n.domElement.removeEventListener("pointermove",I),n.domElement.removeEventListener("pointerup",q),n._domElementKeyEvents!==null&&n._domElementKeyEvents.removeEventListener("keydown",Se)};const n=this,i={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let r=i.NONE;const o=1e-6,a=new hi,c=new hi;let l=1;const u=new ut;let h=!1;const p=new Fe,f=new Fe,d=new Fe,g=new Fe,_=new Fe,y=new Fe,C=new Fe,S=new Fe,k=new Fe,m=[],w={};function b(){return 2*Math.PI/60/60*n.autoRotateSpeed}function v(){return Math.pow(.95,n.zoomSpeed)}function O(T){c.theta-=T}function N(T){c.phi-=T}const x=function(){const T=new ut;return function(me,ye){T.setFromMatrixColumn(ye,0),T.multiplyScalar(-me),u.add(T)}}(),A=function(){const T=new ut;return function(me,ye){n.screenSpacePanning===!0?T.setFromMatrixColumn(ye,1):(T.setFromMatrixColumn(ye,0),T.crossVectors(n.object.up,T)),T.multiplyScalar(me),u.add(T)}}(),M=function(){const T=new ut;return function(me,ye){const Ve=n.domElement;if(n.object.isPerspectiveCamera){const Rt=n.object.position;T.copy(Rt).sub(n.target);let In=T.length();In*=Math.tan(n.object.fov/2*Math.PI/180),x(2*me*In/Ve.clientHeight,n.object.matrix),A(2*ye*In/Ve.clientHeight,n.object.matrix)}else n.object.isOrthographicCamera?(x(me*(n.object.right-n.object.left)/n.object.zoom/Ve.clientWidth,n.object.matrix),A(ye*(n.object.top-n.object.bottom)/n.object.zoom/Ve.clientHeight,n.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),n.enablePan=!1)}}();function D(T){n.object.isPerspectiveCamera?l/=T:n.object.isOrthographicCamera?(n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom*T)),n.object.updateProjectionMatrix(),h=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function F(T){n.object.isPerspectiveCamera?l*=T:n.object.isOrthographicCamera?(n.object.zoom=Math.max(n.minZoom,Math.min(n.maxZoom,n.object.zoom/T)),n.object.updateProjectionMatrix(),h=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),n.enableZoom=!1)}function R(T){p.set(T.clientX,T.clientY)}function P(T){C.set(T.clientX,T.clientY)}function z(T){g.set(T.clientX,T.clientY)}function L(T){f.set(T.clientX,T.clientY),d.subVectors(f,p).multiplyScalar(n.rotateSpeed);const W=n.domElement;O(2*Math.PI*d.x/W.clientHeight),N(2*Math.PI*d.y/W.clientHeight),p.copy(f),n.update()}function U(T){S.set(T.clientX,T.clientY),k.subVectors(S,C),k.y>0?D(v()):k.y<0&&F(v()),C.copy(S),n.update()}function j(T){_.set(T.clientX,T.clientY),y.subVectors(_,g).multiplyScalar(n.panSpeed),M(y.x,y.y),g.copy(_),n.update()}function X(T){T.deltaY<0?F(v()):T.deltaY>0&&D(v()),n.update()}function Ce(T){let W=!1;switch(T.code){case n.keys.UP:M(0,n.keyPanSpeed),W=!0;break;case n.keys.BOTTOM:M(0,-n.keyPanSpeed),W=!0;break;case n.keys.LEFT:M(n.keyPanSpeed,0),W=!0;break;case n.keys.RIGHT:M(-n.keyPanSpeed,0),W=!0;break}W&&(T.preventDefault(),n.update())}function we(){if(m.length===1)p.set(m[0].pageX,m[0].pageY);else{const T=.5*(m[0].pageX+m[1].pageX),W=.5*(m[0].pageY+m[1].pageY);p.set(T,W)}}function G(){if(m.length===1)g.set(m[0].pageX,m[0].pageY);else{const T=.5*(m[0].pageX+m[1].pageX),W=.5*(m[0].pageY+m[1].pageY);g.set(T,W)}}function K(){const T=m[0].pageX-m[1].pageX,W=m[0].pageY-m[1].pageY,me=Math.sqrt(T*T+W*W);C.set(0,me)}function _e(){n.enableZoom&&K(),n.enablePan&&G()}function V(){n.enableZoom&&K(),n.enableRotate&&we()}function Ge(T){if(m.length==1)f.set(T.pageX,T.pageY);else{const me=ws(T),ye=.5*(T.pageX+me.x),Ve=.5*(T.pageY+me.y);f.set(ye,Ve)}d.subVectors(f,p).multiplyScalar(n.rotateSpeed);const W=n.domElement;O(2*Math.PI*d.x/W.clientHeight),N(2*Math.PI*d.y/W.clientHeight),p.copy(f)}function Ye(T){if(m.length===1)_.set(T.pageX,T.pageY);else{const W=ws(T),me=.5*(T.pageX+W.x),ye=.5*(T.pageY+W.y);_.set(me,ye)}y.subVectors(_,g).multiplyScalar(n.panSpeed),M(y.x,y.y),g.copy(_)}function Ke(T){const W=ws(T),me=T.pageX-W.x,ye=T.pageY-W.y,Ve=Math.sqrt(me*me+ye*ye);S.set(0,Ve),k.set(0,Math.pow(S.y/C.y,n.zoomSpeed)),D(k.y),C.copy(S)}function lt(T){n.enableZoom&&Ke(T),n.enablePan&&Ye(T)}function vs(T){n.enableZoom&&Ke(T),n.enableRotate&&Ge(T)}function En(T){n.enabled!==!1&&(m.length===0&&(n.domElement.setPointerCapture(T.pointerId),n.domElement.addEventListener("pointermove",I),n.domElement.addEventListener("pointerup",q)),Ts(T),T.pointerType==="touch"?Ze(T):ee(T))}function I(T){n.enabled!==!1&&(T.pointerType==="touch"?Tt(T):$(T))}function q(T){Mn(T),m.length===0&&(n.domElement.releasePointerCapture(T.pointerId),n.domElement.removeEventListener("pointermove",I),n.domElement.removeEventListener("pointerup",q)),n.dispatchEvent(gi),r=i.NONE}function oe(T){Mn(T)}function ee(T){let W;switch(T.button){case 0:W=n.mouseButtons.LEFT;break;case 1:W=n.mouseButtons.MIDDLE;break;case 2:W=n.mouseButtons.RIGHT;break;default:W=-1}switch(W){case Pt.DOLLY:if(n.enableZoom===!1)return;P(T),r=i.DOLLY;break;case Pt.ROTATE:if(T.ctrlKey||T.metaKey||T.shiftKey){if(n.enablePan===!1)return;z(T),r=i.PAN}else{if(n.enableRotate===!1)return;R(T),r=i.ROTATE}break;case Pt.PAN:if(T.ctrlKey||T.metaKey||T.shiftKey){if(n.enableRotate===!1)return;R(T),r=i.ROTATE}else{if(n.enablePan===!1)return;z(T),r=i.PAN}break;default:r=i.NONE}r!==i.NONE&&n.dispatchEvent(Cs)}function $(T){if(n.enabled!==!1)switch(r){case i.ROTATE:if(n.enableRotate===!1)return;L(T);break;case i.DOLLY:if(n.enableZoom===!1)return;U(T);break;case i.PAN:if(n.enablePan===!1)return;j(T);break}}function te(T){n.enabled===!1||n.enableZoom===!1||r!==i.NONE||(T.preventDefault(),n.dispatchEvent(Cs),X(T),n.dispatchEvent(gi))}function Se(T){n.enabled===!1||n.enablePan===!1||Ce(T)}function Ze(T){switch(li(T),m.length){case 1:switch(n.touches.ONE){case Vt.ROTATE:if(n.enableRotate===!1)return;we(),r=i.TOUCH_ROTATE;break;case Vt.PAN:if(n.enablePan===!1)return;G(),r=i.TOUCH_PAN;break;default:r=i.NONE}break;case 2:switch(n.touches.TWO){case Vt.DOLLY_PAN:if(n.enableZoom===!1&&n.enablePan===!1)return;_e(),r=i.TOUCH_DOLLY_PAN;break;case Vt.DOLLY_ROTATE:if(n.enableZoom===!1&&n.enableRotate===!1)return;V(),r=i.TOUCH_DOLLY_ROTATE;break;default:r=i.NONE}break;default:r=i.NONE}r!==i.NONE&&n.dispatchEvent(Cs)}function Tt(T){switch(li(T),r){case i.TOUCH_ROTATE:if(n.enableRotate===!1)return;Ge(T),n.update();break;case i.TOUCH_PAN:if(n.enablePan===!1)return;Ye(T),n.update();break;case i.TOUCH_DOLLY_PAN:if(n.enableZoom===!1&&n.enablePan===!1)return;lt(T),n.update();break;case i.TOUCH_DOLLY_ROTATE:if(n.enableZoom===!1&&n.enableRotate===!1)return;vs(T),n.update();break;default:r=i.NONE}}function Dt(T){n.enabled!==!1&&T.preventDefault()}function Ts(T){m.push(T)}function Mn(T){delete w[T.pointerId];for(let W=0;W<m.length;W++)if(m[W].pointerId==T.pointerId){m.splice(W,1);return}}function li(T){let W=w[T.pointerId];W===void 0&&(W=new Fe,w[T.pointerId]=W),W.set(T.pageX,T.pageY)}function ws(T){const W=T.pointerId===m[0].pointerId?m[1]:m[0];return w[W.pointerId]}n.domElement.addEventListener("contextmenu",Dt),n.domElement.addEventListener("pointerdown",En),n.domElement.addEventListener("pointercancel",oe),n.domElement.addEventListener("wheel",te,{passive:!1}),this.update()}}const Li="14.9.17",_i=(s,e,t)=>({endTime:e,insertTime:t,type:"exponentialRampToValue",value:s}),yi=(s,e,t)=>({endTime:e,insertTime:t,type:"linearRampToValue",value:s}),As=(s,e)=>({startTime:e,type:"setValue",value:s}),qi=(s,e,t)=>({duration:t,startTime:e,type:"setValueCurve",values:s}),Wi=(s,e,{startTime:t,target:n,timeConstant:i})=>n+(e-n)*Math.exp((t-s)/i),qt=s=>s.type==="exponentialRampToValue",jn=s=>s.type==="linearRampToValue",dt=s=>qt(s)||jn(s),Vs=s=>s.type==="setValue",tt=s=>s.type==="setValueCurve",Bn=(s,e,t,n)=>{const i=s[e];return i===void 0?n:dt(i)||Vs(i)?i.value:tt(i)?i.values[i.values.length-1]:Wi(t,Bn(s,e-1,i.startTime,n),i)},vi=(s,e,t,n,i)=>t===void 0?[n.insertTime,i]:dt(t)?[t.endTime,t.value]:Vs(t)?[t.startTime,t.value]:tt(t)?[t.startTime+t.duration,t.values[t.values.length-1]]:[t.startTime,Bn(s,e-1,t.startTime,i)],ks=s=>s.type==="cancelAndHold",xs=s=>s.type==="cancelScheduledValues",ht=s=>ks(s)||xs(s)?s.cancelTime:qt(s)||jn(s)?s.endTime:s.startTime,Ti=(s,e,t,{endTime:n,value:i})=>t===i?i:0<t&&0<i||t<0&&i<0?t*(i/t)**((s-e)/(n-e)):s<n?t:i,wi=(s,e,t,{endTime:n,value:i})=>t+(s-e)/(n-e)*(i-t),ji=(s,e)=>{const t=Math.floor(e);if(t===e)return s[t];const n=Math.ceil(e);return(1-(e-t))*s[t]+(1-(n-e))*s[n]},ro=(s,{duration:e,startTime:t,values:n})=>{const i=(s-t)/e*(n.length-1);return ji(n,i)},oo=(s,e,t)=>{const n=s.length,i=Math.max(1,Math.floor(t/e*n))+1,r=s instanceof Float32Array?new Float32Array(i):s.slice(0,i);for(let o=0;o<i;o+=1){const c=o/(i-1)*t/e*(n-1);r[o]=ji(s,c)}return r},Rn=s=>s.type==="setTarget";class ao{constructor(e){this._automationEvents=[],this._currenTime=0,this._defaultValue=e}[Symbol.iterator](){return this._automationEvents[Symbol.iterator]()}add(e){const t=ht(e);if(ks(e)||xs(e)){const n=this._automationEvents.findIndex(r=>xs(e)&&tt(r)?r.startTime+r.duration>=t:ht(r)>=t),i=this._automationEvents[n];if(n!==-1&&(this._automationEvents=this._automationEvents.slice(0,n)),ks(e)){const r=this._automationEvents[this._automationEvents.length-1];if(i!==void 0&&dt(i)){if(r!==void 0&&Rn(r))throw new Error("The internal list is malformed.");const o=r===void 0?i.insertTime:tt(r)?r.startTime+r.duration:ht(r),a=r===void 0?this._defaultValue:tt(r)?r.values[r.values.length-1]:r.value,c=qt(i)?Ti(t,o,a,i):wi(t,o,a,i),l=qt(i)?_i(c,t,this._currenTime):yi(c,t,this._currenTime);this._automationEvents.push(l)}if(r!==void 0&&Rn(r)&&this._automationEvents.push(As(this.getValue(t),t)),r!==void 0&&tt(r)&&r.startTime+r.duration>t){const o=t-r.startTime;this._automationEvents[this._automationEvents.length-1]=qi(oo(r.values,r.duration,o),r.startTime,o)}}}else{const n=this._automationEvents.findIndex(o=>ht(o)>t),i=n===-1?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[n-1];if(i!==void 0&&tt(i)&&ht(i)+i.duration>t)return!1;const r=qt(e)?_i(e.value,e.endTime,this._currenTime):jn(e)?yi(e.value,t,this._currenTime):e;if(n===-1)this._automationEvents.push(r);else{if(tt(e)&&t+e.duration>ht(this._automationEvents[n]))return!1;this._automationEvents.splice(n,0,r)}}return!0}flush(e){const t=this._automationEvents.findIndex(n=>ht(n)>e);if(t>1){const n=this._automationEvents.slice(t-1),i=n[0];Rn(i)&&n.unshift(As(Bn(this._automationEvents,t-2,i.startTime,this._defaultValue),i.startTime)),this._automationEvents=n}}getValue(e){if(this._automationEvents.length===0)return this._defaultValue;const t=this._automationEvents.findIndex(o=>ht(o)>e),n=this._automationEvents[t],i=(t===-1?this._automationEvents.length:t)-1,r=this._automationEvents[i];if(r!==void 0&&Rn(r)&&(n===void 0||!dt(n)||n.insertTime>e))return Wi(e,Bn(this._automationEvents,i-1,r.startTime,this._defaultValue),r);if(r!==void 0&&Vs(r)&&(n===void 0||!dt(n)))return r.value;if(r!==void 0&&tt(r)&&(n===void 0||!dt(n)||r.startTime+r.duration>e))return e<r.startTime+r.duration?ro(e,r):r.values[r.values.length-1];if(r!==void 0&&dt(r)&&(n===void 0||!dt(n)))return r.value;if(n!==void 0&&qt(n)){const[o,a]=vi(this._automationEvents,i,r,n,this._defaultValue);return Ti(e,o,a,n)}if(n!==void 0&&jn(n)){const[o,a]=vi(this._automationEvents,i,r,n,this._defaultValue);return wi(e,o,a,n)}return this._defaultValue}}const co=s=>({cancelTime:s,type:"cancelAndHold"}),lo=s=>({cancelTime:s,type:"cancelScheduledValues"}),uo=(s,e)=>({endTime:e,type:"exponentialRampToValue",value:s}),ho=(s,e)=>({endTime:e,type:"linearRampToValue",value:s}),po=(s,e,t)=>({startTime:e,target:s,timeConstant:t,type:"setTarget"}),fo=()=>new DOMException("","AbortError"),mo=s=>(e,t,[n,i,r],o)=>{s(e[i],[t,n,r],a=>a[0]===t&&a[1]===n,o)},go=s=>(e,t,n)=>{const i=[];for(let r=0;r<n.numberOfInputs;r+=1)i.push(new Set);s.set(e,{activeInputs:i,outputs:new Set,passiveInputs:new WeakMap,renderer:t})},_o=s=>(e,t)=>{s.set(e,{activeInputs:new Set,passiveInputs:new WeakMap,renderer:t})},Ut=new WeakSet,Bi=new WeakMap,Fs=new WeakMap,Ui=new WeakMap,Ls=new WeakMap,cs=new WeakMap,zi=new WeakMap,Ns=new WeakMap,Os=new WeakMap,Es=new WeakMap,Gi={construct(){return Gi}},yo=s=>{try{const e=new Proxy(s,Gi);new e}catch{return!1}return!0},bi=/^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]*);?/,Ci=(s,e)=>{const t=[];let n=s.replace(/^[\s]+/,""),i=n.match(bi);for(;i!==null;){const r=i[1].slice(1,-1),o=i[0].replace(/([\s]+)?;?$/,"").replace(r,new URL(r,e).toString());t.push(o),n=n.slice(i[0].length).replace(/^[\s]+/,""),i=n.match(bi)}return[t.join(";"),n]},Si=s=>{if(s!==void 0&&!Array.isArray(s))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},Ai=s=>{if(!yo(s))throw new TypeError("The given value for processorCtor should be a constructor.");if(s.prototype===null||typeof s.prototype!="object")throw new TypeError("The given value for processorCtor should have a prototype.")},vo=(s,e,t,n,i,r,o,a,c,l,u,h,p)=>{let f=0;return(d,g,_={credentials:"omit"})=>{const y=u.get(d);if(y!==void 0&&y.has(g))return Promise.resolve();const C=l.get(d);if(C!==void 0){const m=C.get(g);if(m!==void 0)return m}const S=r(d),k=S.audioWorklet===void 0?i(g).then(([m,w])=>{const[b,v]=Ci(m,w),O=`${b};((a,b)=>{(a[b]=a[b]||[]).push((AudioWorkletProcessor,global,registerProcessor,sampleRate,self,window)=>{${v}
|
|
})})(window,'_AWGS')`;return t(O)}).then(()=>{const m=p._AWGS.pop();if(m===void 0)throw new SyntaxError;n(S.currentTime,S.sampleRate,()=>m(class{},void 0,(w,b)=>{if(w.trim()==="")throw e();const v=Os.get(S);if(v!==void 0){if(v.has(w))throw e();Ai(b),Si(b.parameterDescriptors),v.set(w,b)}else Ai(b),Si(b.parameterDescriptors),Os.set(S,new Map([[w,b]]))},S.sampleRate,void 0,void 0))}):Promise.all([i(g),Promise.resolve(s(h,h))]).then(([[m,w],b])=>{const v=f+1;f=v;const[O,N]=Ci(m,w),D=`${O};((AudioWorkletProcessor,registerProcessor)=>{${N}
|
|
})(${b?"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{${b?"":"__c = (a) => a.forEach(e=>this.__b.add(e.buffer));"}process(i,o,p){${b?"":"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}})`,F=new Blob([D],{type:"application/javascript; charset=utf-8"}),R=URL.createObjectURL(F);return S.audioWorklet.addModule(R,_).then(()=>{if(a(S))return S;const P=o(S);return P.audioWorklet.addModule(R,_).then(()=>P)}).then(P=>{if(c===null)throw new SyntaxError;try{new c(P,`__sac${v}`)}catch{throw new SyntaxError}}).finally(()=>URL.revokeObjectURL(R))});return C===void 0?l.set(d,new Map([[g,k]])):C.set(g,k),k.then(()=>{const m=u.get(d);m===void 0?u.set(d,new Set([g])):m.add(g)}).finally(()=>{const m=l.get(d);m!==void 0&&m.delete(g)}),k}},je=(s,e)=>{const t=s.get(e);if(t===void 0)throw new Error("A value with the given key could not be found.");return t},ls=(s,e)=>{const t=Array.from(s).filter(e);if(t.length>1)throw Error("More than one element was found.");if(t.length===0)throw Error("No element was found.");const[n]=t;return s.delete(n),n},Yi=(s,e,t,n)=>{const i=je(s,e),r=ls(i,o=>o[0]===t&&o[1]===n);return i.size===0&&s.delete(e),r},Tn=s=>je(zi,s),zt=s=>{if(Ut.has(s))throw new Error("The AudioNode is already stored.");Ut.add(s),Tn(s).forEach(e=>e(!0))},Zi=s=>"port"in s,wn=s=>{if(!Ut.has(s))throw new Error("The AudioNode is not stored.");Ut.delete(s),Tn(s).forEach(e=>e(!1))},Ms=(s,e)=>{!Zi(s)&&e.every(t=>t.size===0)&&wn(s)},To=(s,e,t,n,i,r,o,a,c,l,u,h,p)=>{const f=new WeakMap;return(d,g,_,y,C)=>{const{activeInputs:S,passiveInputs:k}=r(g),{outputs:m}=r(d),w=a(d),b=v=>{const O=c(g),N=c(d);if(v){const x=Yi(k,d,_,y);s(S,d,x,!1),!C&&!h(d)&&t(N,O,_,y),p(g)&&zt(g)}else{const x=n(S,d,_,y);e(k,y,x,!1),!C&&!h(d)&&i(N,O,_,y);const A=o(g);if(A===0)u(g)&&Ms(g,S);else{const M=f.get(g);M!==void 0&&clearTimeout(M),f.set(g,setTimeout(()=>{u(g)&&Ms(g,S)},A*1e3))}}};return l(m,[g,_,y],v=>v[0]===g&&v[1]===_&&v[2]===y,!0)?(w.add(b),u(d)?s(S,d,[_,y,b],!0):e(k,y,[d,_,b],!0),!0):!1}},wo=s=>(e,t,[n,i,r],o)=>{const a=e.get(n);a===void 0?e.set(n,new Set([[i,t,r]])):s(a,[i,t,r],c=>c[0]===i&&c[1]===t,o)},bo=s=>(e,t)=>{const n=s(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});t.connect(n).connect(e.destination);const i=()=>{t.removeEventListener("ended",i),t.disconnect(n),n.disconnect()};t.addEventListener("ended",i)},Co=s=>(e,t)=>{s(e).add(t)},So={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},Ao=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=i(a),u={...So,...c},h=n(l,u),p=r(l)?e():null;super(a,!1,h,p),this._nativeAnalyserNode=h}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(a){this._nativeAnalyserNode.fftSize=a}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(a){const c=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=a,!(a>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=c,t()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(a){const c=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=a,!(this._nativeAnalyserNode.maxDecibels>a))throw this._nativeAnalyserNode.minDecibels=c,t()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(a){this._nativeAnalyserNode.smoothingTimeConstant=a}getByteFrequencyData(a){this._nativeAnalyserNode.getByteFrequencyData(a)}getByteTimeDomainData(a){this._nativeAnalyserNode.getByteTimeDomainData(a)}getFloatFrequencyData(a){this._nativeAnalyserNode.getFloatFrequencyData(a)}getFloatTimeDomainData(a){this._nativeAnalyserNode.getFloatTimeDomainData(a)}},be=(s,e)=>s.context===e,ko=(s,e,t)=>()=>{const n=new WeakMap,i=async(r,o)=>{let a=e(r);if(!be(a,o)){const l={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,fftSize:a.fftSize,maxDecibels:a.maxDecibels,minDecibels:a.minDecibels,smoothingTimeConstant:a.smoothingTimeConstant};a=s(o,l)}return n.set(o,a),await t(r,o,a),a};return{render(r,o){const a=n.get(o);return a!==void 0?Promise.resolve(a):i(r,o)}}},Un=s=>{try{s.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0},Xe=()=>new DOMException("","IndexSizeError"),qs=s=>{s.getChannelData=(e=>t=>{try{return e.call(s,t)}catch(n){throw n.code===12?Xe():n}})(s.getChannelData)},xo={numberOfChannels:1},No=(s,e,t,n,i,r,o,a)=>{let c=null;return class $i{constructor(u){if(i===null)throw new Error("Missing the native OfflineAudioContext constructor.");const{length:h,numberOfChannels:p,sampleRate:f}={...xo,...u};c===null&&(c=new i(1,1,44100));const d=n!==null&&e(r,r)?new n({length:h,numberOfChannels:p,sampleRate:f}):c.createBuffer(p,h,f);if(d.numberOfChannels===0)throw t();return typeof d.copyFromChannel!="function"?(o(d),qs(d)):e(Un,()=>Un(d))||a(d),s.add(d),d}static[Symbol.hasInstance](u){return u!==null&&typeof u=="object"&&Object.getPrototypeOf(u)===$i.prototype||s.has(u)}}},Ne=-34028234663852886e22,Ae=-Ne,nt=s=>Ut.has(s),Oo={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},Eo=(s,e,t,n,i,r,o,a)=>class extends s{constructor(l,u){const h=r(l),p={...Oo,...u},f=i(h,p),d=o(h),g=d?e():null;super(l,!1,f,g),this._audioBufferSourceNodeRenderer=g,this._isBufferNullified=!1,this._isBufferSet=p.buffer!==null,this._nativeAudioBufferSourceNode=f,this._onended=null,this._playbackRate=t(this,d,f.playbackRate,Ae,Ne)}get buffer(){return this._isBufferNullified?null:this._nativeAudioBufferSourceNode.buffer}set buffer(l){if(this._nativeAudioBufferSourceNode.buffer=l,l!==null){if(this._isBufferSet)throw n();this._isBufferSet=!0}}get loop(){return this._nativeAudioBufferSourceNode.loop}set loop(l){this._nativeAudioBufferSourceNode.loop=l}get loopEnd(){return this._nativeAudioBufferSourceNode.loopEnd}set loopEnd(l){this._nativeAudioBufferSourceNode.loopEnd=l}get loopStart(){return this._nativeAudioBufferSourceNode.loopStart}set loopStart(l){this._nativeAudioBufferSourceNode.loopStart=l}get onended(){return this._onended}set onended(l){const u=typeof l=="function"?a(this,l):null;this._nativeAudioBufferSourceNode.onended=u;const h=this._nativeAudioBufferSourceNode.onended;this._onended=h!==null&&h===u?l:h}get playbackRate(){return this._playbackRate}start(l=0,u=0,h){if(this._nativeAudioBufferSourceNode.start(l,u,h),this._audioBufferSourceNodeRenderer!==null&&(this._audioBufferSourceNodeRenderer.start=h===void 0?[l,u]:[l,u,h]),this.context.state!=="closed"){zt(this);const p=()=>{this._nativeAudioBufferSourceNode.removeEventListener("ended",p),nt(this)&&wn(this)};this._nativeAudioBufferSourceNode.addEventListener("ended",p)}}stop(l=0){this._nativeAudioBufferSourceNode.stop(l),this._audioBufferSourceNodeRenderer!==null&&(this._audioBufferSourceNodeRenderer.stop=l)}},Mo=(s,e,t,n,i)=>()=>{const r=new WeakMap;let o=null,a=null;const c=async(l,u)=>{let h=t(l);const p=be(h,u);if(!p){const f={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=e(u,f),o!==null&&h.start(...o),a!==null&&h.stop(a)}return r.set(u,h),p?await s(u,l.playbackRate,h.playbackRate):await n(u,l.playbackRate,h.playbackRate),await i(l,u,h),h};return{set start(l){o=l},set stop(l){a=l},render(l,u){const h=r.get(u);return h!==void 0?Promise.resolve(h):c(l,u)}}},Io=s=>"playbackRate"in s,Do=s=>"frequency"in s&&"gain"in s,Ro=s=>"offset"in s,Po=s=>!("frequency"in s)&&"gain"in s,Vo=s=>"detune"in s&&"frequency"in s&&!("gain"in s),Fo=s=>"pan"in s,ke=s=>je(Bi,s),bn=s=>je(Ui,s),Is=(s,e)=>{const{activeInputs:t}=ke(s);t.forEach(i=>i.forEach(([r])=>{e.includes(s)||Is(r,[...e,s])}));const n=Io(s)?[s.playbackRate]:Zi(s)?Array.from(s.parameters.values()):Do(s)?[s.Q,s.detune,s.frequency,s.gain]:Ro(s)?[s.offset]:Po(s)?[s.gain]:Vo(s)?[s.detune,s.frequency]:Fo(s)?[s.pan]:[];for(const i of n){const r=bn(i);r!==void 0&&r.activeInputs.forEach(([o])=>Is(o,e))}nt(s)&&wn(s)},Xi=s=>{Is(s.destination,[])},Lo=s=>s===void 0||typeof s=="number"||typeof s=="string"&&(s==="balanced"||s==="interactive"||s==="playback"),qo=(s,e,t,n,i,r,o,a,c)=>class extends s{constructor(u={}){if(c===null)throw new Error("Missing the native AudioContext constructor.");let h;try{h=new c(u)}catch(d){throw d.code===12&&d.message==="sampleRate is not in range"?t():d}if(h===null)throw n();if(!Lo(u.latencyHint))throw new TypeError(`The provided value '${u.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(u.sampleRate!==void 0&&h.sampleRate!==u.sampleRate)throw t();super(h,2);const{latencyHint:p}=u,{sampleRate:f}=h;if(this._baseLatency=typeof h.baseLatency=="number"?h.baseLatency:p==="balanced"?512/f:p==="interactive"||p===void 0?256/f:p==="playback"?1024/f:Math.max(2,Math.min(128,Math.round(p*f/128)))*128/f,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";const 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 e()}):(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()),Xi(this)}))}createMediaElementSource(u){return new i(this,{mediaElement:u})}createMediaStreamDestination(){return new r(this)}createMediaStreamSource(u){return new o(this,{mediaStream:u})}createMediaStreamTrackSource(u){return new a(this,{mediaStreamTrack:u})}resume(){return this._state==="suspended"?new Promise((u,h)=>{const p=()=>{this._nativeAudioContext.removeEventListener("statechange",p),this._nativeAudioContext.state==="running"?u():this.resume().then(u,h)};this._nativeAudioContext.addEventListener("statechange",p)}):this._nativeAudioContext.resume().catch(u=>{throw u===void 0||u.code===15?e():u})}suspend(){return this._nativeAudioContext.suspend().catch(u=>{throw u===void 0?e():u})}},Wo=(s,e,t,n,i,r,o,a)=>class extends s{constructor(l,u){const h=r(l),p=o(h),f=i(h,u,p),d=p?e(a):null;super(l,!1,f,d),this._isNodeOfNativeOfflineAudioContext=p,this._nativeAudioDestinationNode=f}get channelCount(){return this._nativeAudioDestinationNode.channelCount}set channelCount(l){if(this._isNodeOfNativeOfflineAudioContext)throw n();if(l>this._nativeAudioDestinationNode.maxChannelCount)throw t();this._nativeAudioDestinationNode.channelCount=l}get channelCountMode(){return this._nativeAudioDestinationNode.channelCountMode}set channelCountMode(l){if(this._isNodeOfNativeOfflineAudioContext)throw n();this._nativeAudioDestinationNode.channelCountMode=l}get maxChannelCount(){return this._nativeAudioDestinationNode.maxChannelCount}},jo=s=>{const e=new WeakMap,t=async(n,i)=>{const r=i.destination;return e.set(i,r),await s(n,i,r),r};return{render(n,i){const r=e.get(i);return r!==void 0?Promise.resolve(r):t(n,i)}}},Bo=(s,e,t,n,i,r,o,a)=>(c,l)=>{const u=l.listener,h=()=>{const m=new Float32Array(1),w=e(l,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:9}),b=o(l);let v=!1,O=[0,0,-1,0,1,0],N=[0,0,0];const x=()=>{if(v)return;v=!0;const F=n(l,256,9,0);F.onaudioprocess=({inputBuffer:R})=>{const P=[r(R,m,0),r(R,m,1),r(R,m,2),r(R,m,3),r(R,m,4),r(R,m,5)];P.some((L,U)=>L!==O[U])&&(u.setOrientation(...P),O=P);const z=[r(R,m,6),r(R,m,7),r(R,m,8)];z.some((L,U)=>L!==N[U])&&(u.setPosition(...z),N=z)},w.connect(F)},A=F=>R=>{R!==O[F]&&(O[F]=R,u.setOrientation(...O))},M=F=>R=>{R!==N[F]&&(N[F]=R,u.setPosition(...N))},D=(F,R,P)=>{const z=t(l,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:R});z.connect(w,0,F),z.start(),Object.defineProperty(z.offset,"defaultValue",{get(){return R}});const L=s({context:c},b,z.offset,Ae,Ne);return a(L,"value",U=>()=>U.call(L),U=>j=>{try{U.call(L,j)}catch(X){if(X.code!==9)throw X}x(),b&&P(j)}),L.cancelAndHoldAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.cancelAndHoldAtTime),L.cancelScheduledValues=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.cancelScheduledValues),L.exponentialRampToValueAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.exponentialRampToValueAtTime),L.linearRampToValueAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.linearRampToValueAtTime),L.setTargetAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.setTargetAtTime),L.setValueAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.setValueAtTime),L.setValueCurveAtTime=(U=>b?()=>{throw i()}:(...j)=>{const X=U.apply(L,j);return x(),X})(L.setValueCurveAtTime),L};return{forwardX:D(0,0,A(0)),forwardY:D(1,0,A(1)),forwardZ:D(2,-1,A(2)),positionX:D(6,0,M(0)),positionY:D(7,0,M(1)),positionZ:D(8,0,M(2)),upX:D(3,0,A(3)),upY:D(4,1,A(4)),upZ:D(5,0,A(5))}},{forwardX:p,forwardY:f,forwardZ:d,positionX:g,positionY:_,positionZ:y,upX:C,upY:S,upZ:k}=u.forwardX===void 0?h():u;return{get forwardX(){return p},get forwardY(){return f},get forwardZ(){return d},get positionX(){return g},get positionY(){return _},get positionZ(){return y},get upX(){return C},get upY(){return S},get upZ(){return k}}},zn=s=>"context"in s,Cn=s=>zn(s[0]),Et=(s,e,t,n)=>{for(const i of s)if(t(i)){if(n)return!1;throw Error("The set contains at least one similar element.")}return s.add(e),!0},ki=(s,e,[t,n],i)=>{Et(s,[e,t,n],r=>r[0]===e&&r[1]===t,i)},xi=(s,[e,t,n],i)=>{const r=s.get(e);r===void 0?s.set(e,new Set([[t,n]])):Et(r,[t,n],o=>o[0]===t,i)},Kt=s=>"inputs"in s,Gn=(s,e,t,n)=>{if(Kt(e)){const i=e.inputs[n];return s.connect(i,t,0),[i,t,0]}return s.connect(e,t,n),[e,t,n]},Hi=(s,e,t)=>{for(const n of s)if(n[0]===e&&n[1]===t)return s.delete(n),n;return null},Uo=(s,e,t)=>ls(s,n=>n[0]===e&&n[1]===t),Qi=(s,e)=>{if(!Tn(s).delete(e))throw new Error("Missing the expected event listener.")},Ki=(s,e,t)=>{const n=je(s,e),i=ls(n,r=>r[0]===t);return n.size===0&&s.delete(e),i},Yn=(s,e,t,n)=>{Kt(e)?s.disconnect(e.inputs[n],t,0):s.disconnect(e,t,n)},se=s=>je(Fs,s),on=s=>je(Ls,s),kt=s=>Ns.has(s),qn=s=>!Ut.has(s),Ni=(s,e)=>new Promise(t=>{if(e!==null)t(!0);else{const n=s.createScriptProcessor(256,1,1),i=s.createGain(),r=s.createBuffer(1,2,44100),o=r.getChannelData(0);o[0]=1,o[1]=1;const a=s.createBufferSource();a.buffer=r,a.loop=!0,a.connect(n).connect(s.destination),a.connect(i),a.disconnect(i),n.onaudioprocess=c=>{const l=c.inputBuffer.getChannelData(0);Array.prototype.some.call(l,u=>u===1)?t(!0):t(!1),a.stop(),n.onaudioprocess=null,a.disconnect(n),n.disconnect(s.destination)},a.start()}}),Ss=(s,e)=>{const t=new Map;for(const n of s)for(const i of n){const r=t.get(i);t.set(i,r===void 0?1:r+1)}t.forEach((n,i)=>e(i,n))},Zn=s=>"context"in s,zo=s=>{const e=new Map;s.connect=(t=>(n,i=0,r=0)=>{const o=Zn(n)?t(n,i,r):t(n,i),a=e.get(n);return a===void 0?e.set(n,[{input:r,output:i}]):a.every(c=>c.input!==r||c.output!==i)&&a.push({input:r,output:i}),o})(s.connect.bind(s)),s.disconnect=(t=>(n,i,r)=>{if(t.apply(s),n===void 0)e.clear();else if(typeof n=="number")for(const[o,a]of e){const c=a.filter(l=>l.output!==n);c.length===0?e.delete(o):e.set(o,c)}else if(e.has(n))if(i===void 0)e.delete(n);else{const o=e.get(n);if(o!==void 0){const a=o.filter(c=>c.output!==i&&(c.input!==r||r===void 0));a.length===0?e.delete(n):e.set(n,a)}}for(const[o,a]of e)a.forEach(c=>{Zn(o)?s.connect(o,c.output,c.input):s.connect(o,c.output)})})(s.disconnect)},Go=(s,e,t,n)=>{const{activeInputs:i,passiveInputs:r}=bn(e),{outputs:o}=ke(s),a=Tn(s),c=l=>{const u=se(s),h=on(e);if(l){const p=Ki(r,s,t);ki(i,s,p,!1),!n&&!kt(s)&&u.connect(h,t)}else{const p=Uo(i,s,t);xi(r,p,!1),!n&&!kt(s)&&u.disconnect(h,t)}};return Et(o,[e,t],l=>l[0]===e&&l[1]===t,!0)?(a.add(c),nt(s)?ki(i,s,[t,c],!0):xi(r,[s,t,c],!0),!0):!1},Yo=(s,e,t,n)=>{const{activeInputs:i,passiveInputs:r}=ke(e),o=Hi(i[n],s,t);return o===null?[Yi(r,s,t,n)[2],!1]:[o[2],!0]},Zo=(s,e,t)=>{const{activeInputs:n,passiveInputs:i}=bn(e),r=Hi(n,s,t);return r===null?[Ki(i,s,t)[1],!1]:[r[2],!0]},Ws=(s,e,t,n,i)=>{const[r,o]=Yo(s,t,n,i);if(r!==null&&(Qi(s,r),o&&!e&&!kt(s)&&Yn(se(s),se(t),n,i)),nt(t)){const{activeInputs:a}=ke(t);Ms(t,a)}},js=(s,e,t,n)=>{const[i,r]=Zo(s,t,n);i!==null&&(Qi(s,i),r&&!e&&!kt(s)&&se(s).disconnect(on(t),n))},$o=(s,e)=>{const t=ke(s),n=[];for(const i of t.outputs)Cn(i)?Ws(s,e,...i):js(s,e,...i),n.push(i[0]);return t.outputs.clear(),n},Xo=(s,e,t)=>{const n=ke(s),i=[];for(const r of n.outputs)r[1]===t&&(Cn(r)?Ws(s,e,...r):js(s,e,...r),i.push(r[0]),n.outputs.delete(r));return i},Ho=(s,e,t,n,i)=>{const r=ke(s);return Array.from(r.outputs).filter(o=>o[0]===t&&(n===void 0||o[1]===n)&&(i===void 0||o[2]===i)).map(o=>(Cn(o)?Ws(s,e,...o):js(s,e,...o),r.outputs.delete(o),o[0]))},Qo=(s,e,t,n,i,r,o,a,c,l,u,h,p,f,d,g)=>class extends l{constructor(y,C,S,k){super(S),this._context=y,this._nativeAudioNode=S;const m=u(y);h(m)&&t(Ni,()=>Ni(m,g))!==!0&&zo(S),Fs.set(this,S),zi.set(this,new Set),y.state!=="closed"&&C&&zt(this),s(this,k,S)}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,C=0,S=0){if(C<0||C>=this._nativeAudioNode.numberOfOutputs)throw i();const k=u(this._context),m=d(k);if(p(y)||f(y))throw r();if(zn(y)){const v=se(y);try{const N=Gn(this._nativeAudioNode,v,C,S),x=qn(this);(m||x)&&this._nativeAudioNode.disconnect(...N),this.context.state!=="closed"&&!x&&qn(y)&&zt(y)}catch(N){throw N.code===12?r():N}if(e(this,y,C,S,m)){const N=c([this],y);Ss(N,n(m))}return y}const w=on(y);if(w.name==="playbackRate"&&w.maxValue===1024)throw o();try{this._nativeAudioNode.connect(w,C),(m||qn(this))&&this._nativeAudioNode.disconnect(w,C)}catch(v){throw v.code===12?r():v}if(Go(this,y,C,m)){const v=c([this],y);Ss(v,n(m))}}disconnect(y,C,S){let k;const m=u(this._context),w=d(m);if(y===void 0)k=$o(this,w);else if(typeof y=="number"){if(y<0||y>=this.numberOfOutputs)throw i();k=Xo(this,w,y)}else{if(C!==void 0&&(C<0||C>=this.numberOfOutputs)||zn(y)&&S!==void 0&&(S<0||S>=y.numberOfInputs))throw i();if(k=Ho(this,w,y,C,S),k.length===0)throw r()}for(const b of k){const v=c([this],b);Ss(v,a)}}},Ko=(s,e,t,n,i,r,o,a,c,l,u,h,p)=>(f,d,g,_=null,y=null)=>{const C=g.value,S=new ao(C),k=d?n(S):null,m={get defaultValue(){return C},get maxValue(){return _===null?g.maxValue:_},get minValue(){return y===null?g.minValue:y},get value(){return g.value},set value(w){g.value=w,m.setValueAtTime(w,f.context.currentTime)},cancelAndHoldAtTime(w){if(typeof g.cancelAndHoldAtTime=="function")k===null&&S.flush(f.context.currentTime),S.add(i(w)),g.cancelAndHoldAtTime(w);else{const b=Array.from(S).pop();k===null&&S.flush(f.context.currentTime),S.add(i(w));const v=Array.from(S).pop();g.cancelScheduledValues(w),b!==v&&v!==void 0&&(v.type==="exponentialRampToValue"?g.exponentialRampToValueAtTime(v.value,v.endTime):v.type==="linearRampToValue"?g.linearRampToValueAtTime(v.value,v.endTime):v.type==="setValue"?g.setValueAtTime(v.value,v.startTime):v.type==="setValueCurve"&&g.setValueCurveAtTime(v.values,v.startTime,v.duration))}return m},cancelScheduledValues(w){return k===null&&S.flush(f.context.currentTime),S.add(r(w)),g.cancelScheduledValues(w),m},exponentialRampToValueAtTime(w,b){if(w===0)throw new RangeError;if(!Number.isFinite(b)||b<0)throw new RangeError;const v=f.context.currentTime;return k===null&&S.flush(v),Array.from(S).length===0&&(S.add(l(C,v)),g.setValueAtTime(C,v)),S.add(o(w,b)),g.exponentialRampToValueAtTime(w,b),m},linearRampToValueAtTime(w,b){const v=f.context.currentTime;return k===null&&S.flush(v),Array.from(S).length===0&&(S.add(l(C,v)),g.setValueAtTime(C,v)),S.add(a(w,b)),g.linearRampToValueAtTime(w,b),m},setTargetAtTime(w,b,v){return k===null&&S.flush(f.context.currentTime),S.add(c(w,b,v)),g.setTargetAtTime(w,b,v),m},setValueAtTime(w,b){return k===null&&S.flush(f.context.currentTime),S.add(l(w,b)),g.setValueAtTime(w,b),m},setValueCurveAtTime(w,b,v){const O=w instanceof Float32Array?w:new Float32Array(w);if(h!==null&&h.name==="webkitAudioContext"){const N=b+v,x=f.context.sampleRate,A=Math.ceil(b*x),M=Math.floor(N*x),D=M-A,F=new Float32Array(D);for(let P=0;P<D;P+=1){const z=(O.length-1)/v*((A+P)/x-b),L=Math.floor(z),U=Math.ceil(z);F[P]=L===U?O[L]:(1-(z-L))*O[L]+(1-(U-z))*O[U]}k===null&&S.flush(f.context.currentTime),S.add(u(F,b,v)),g.setValueCurveAtTime(F,b,v);const R=M/x;R<N&&p(m,F[F.length-1],R),p(m,O[O.length-1],N)}else k===null&&S.flush(f.context.currentTime),S.add(u(O,b,v)),g.setValueCurveAtTime(O,b,v);return m}};return t.set(m,g),e.set(m,f),s(m,k),m},Jo=s=>({replay(e){for(const t of s)if(t.type==="exponentialRampToValue"){const{endTime:n,value:i}=t;e.exponentialRampToValueAtTime(i,n)}else if(t.type==="linearRampToValue"){const{endTime:n,value:i}=t;e.linearRampToValueAtTime(i,n)}else if(t.type==="setTarget"){const{startTime:n,target:i,timeConstant:r}=t;e.setTargetAtTime(i,n,r)}else if(t.type==="setValue"){const{startTime:n,value:i}=t;e.setValueAtTime(i,n)}else if(t.type==="setValueCurve"){const{duration:n,startTime:i,values:r}=t;e.setValueCurveAtTime(r,i,n)}else throw new Error("Can't apply an unknown automation.")}});class Ji{constructor(e){this._map=new Map(e)}get size(){return this._map.size}entries(){return this._map.entries()}forEach(e,t=null){return this._map.forEach((n,i)=>e.call(t,n,i,this))}get(e){return this._map.get(e)}has(e){return this._map.has(e)}keys(){return this._map.keys()}values(){return this._map.values()}}const ea={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:1,numberOfOutputs:1,parameterData:{},processorOptions:{}},ta=(s,e,t,n,i,r,o,a,c,l,u,h,p,f)=>class extends e{constructor(g,_,y){var C;const S=a(g),k=c(S),m=u({...ea,...y});p(m);const w=Os.get(S),b=w==null?void 0:w.get(_),v=k||S.state!=="closed"?S:(C=o(S))!==null&&C!==void 0?C:S,O=i(v,k?null:g.baseLatency,l,_,b,m),N=k?n(_,m,b):null;super(g,!0,O,N);const x=[];O.parameters.forEach((M,D)=>{const F=t(this,k,M);x.push([D,F])}),this._nativeAudioWorkletNode=O,this._onprocessorerror=null,this._parameters=new Ji(x),k&&s(S,this);const{activeInputs:A}=r(this);h(O,A)}get onprocessorerror(){return this._onprocessorerror}set onprocessorerror(g){const _=typeof g=="function"?f(this,g):null;this._nativeAudioWorkletNode.onprocessorerror=_;const y=this._nativeAudioWorkletNode.onprocessorerror;this._onprocessorerror=y!==null&&y===_?g:y}get parameters(){return this._parameters===null?this._nativeAudioWorkletNode.parameters:this._parameters}get port(){return this._nativeAudioWorkletNode.port}};function $n(s,e,t,n,i){if(typeof s.copyFromChannel=="function")e[t].byteLength===0&&(e[t]=new Float32Array(128)),s.copyFromChannel(e[t],n,i);else{const r=s.getChannelData(n);if(e[t].byteLength===0)e[t]=r.slice(i,i+128);else{const o=new Float32Array(r.buffer,i*Float32Array.BYTES_PER_ELEMENT,128);e[t].set(o)}}}const er=(s,e,t,n,i)=>{typeof s.copyToChannel=="function"?e[t].byteLength!==0&&s.copyToChannel(e[t],n,i):e[t].byteLength!==0&&s.getChannelData(n).set(e[t],i)},Xn=(s,e)=>{const t=[];for(let n=0;n<s;n+=1){const i=[],r=typeof e=="number"?e:e[n];for(let o=0;o<r;o+=1)i.push(new Float32Array(128));t.push(i)}return t},na=(s,e)=>{const t=je(Es,s),n=se(e);return je(t,n)},sa=async(s,e,t,n,i,r,o)=>{const a=e===null?Math.ceil(s.context.length/128)*128:e.length,c=n.channelCount*n.numberOfInputs,l=i.reduce((_,y)=>_+y,0),u=l===0?null:t.createBuffer(l,a,t.sampleRate);if(r===void 0)throw new Error("Missing the processor constructor.");const h=ke(s),p=await na(t,s),f=Xn(n.numberOfInputs,n.channelCount),d=Xn(n.numberOfOutputs,i),g=Array.from(s.parameters.keys()).reduce((_,y)=>({..._,[y]:new Float32Array(128)}),{});for(let _=0;_<a;_+=128){if(n.numberOfInputs>0&&e!==null)for(let y=0;y<n.numberOfInputs;y+=1)for(let C=0;C<n.channelCount;C+=1)$n(e,f[y],C,C,_);r.parameterDescriptors!==void 0&&e!==null&&r.parameterDescriptors.forEach(({name:y},C)=>{$n(e,g,y,c+C,_)});for(let y=0;y<n.numberOfInputs;y+=1)for(let C=0;C<i[y];C+=1)d[y][C].byteLength===0&&(d[y][C]=new Float32Array(128));try{const y=f.map((S,k)=>h.activeInputs[k].size===0?[]:S),C=o(_/t.sampleRate,t.sampleRate,()=>p.process(y,d,g));if(u!==null)for(let S=0,k=0;S<n.numberOfOutputs;S+=1){for(let m=0;m<i[S];m+=1)er(u,d[S],m,k+m,_);k+=i[S]}if(!C)break}catch(y){s.dispatchEvent(new ErrorEvent("processorerror",{colno:y.colno,filename:y.filename,lineno:y.lineno,message:y.message}));break}}return u},ia=(s,e,t,n,i,r,o,a,c,l,u,h,p,f,d,g)=>(_,y,C)=>{const S=new WeakMap;let k=null;const m=async(w,b)=>{let v=u(w),O=null;const N=be(v,b),x=Array.isArray(y.outputChannelCount)?y.outputChannelCount:Array.from(y.outputChannelCount);if(h===null){const A=x.reduce((R,P)=>R+P,0),M=i(b,{channelCount:Math.max(1,A),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,A)}),D=[];for(let R=0;R<w.numberOfOutputs;R+=1)D.push(n(b,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:x[R]}));const F=o(b,{channelCount:y.channelCount,channelCountMode:y.channelCountMode,channelInterpretation:y.channelInterpretation,gain:1});F.connect=e.bind(null,D),F.disconnect=c.bind(null,D),O=[M,D,F]}else N||(v=new h(b,_));if(S.set(b,O===null?v:O[2]),O!==null){if(k===null){if(C===void 0)throw new Error("Missing the processor constructor.");if(p===null)throw new Error("Missing the native OfflineAudioContext constructor.");const P=w.channelCount*w.numberOfInputs,z=C.parameterDescriptors===void 0?0:C.parameterDescriptors.length,L=P+z;k=sa(w,L===0?null:await(async()=>{const j=new p(L,Math.ceil(w.context.length/128)*128,b.sampleRate),X=[],Ce=[];for(let K=0;K<y.numberOfInputs;K+=1)X.push(o(j,{channelCount:y.channelCount,channelCountMode:y.channelCountMode,channelInterpretation:y.channelInterpretation,gain:1})),Ce.push(i(j,{channelCount:y.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:y.channelCount}));const we=await Promise.all(Array.from(w.parameters.values()).map(async K=>{const _e=r(j,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:K.value});return await f(j,K,_e.offset),_e})),G=n(j,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,P+z)});for(let K=0;K<y.numberOfInputs;K+=1){X[K].connect(Ce[K]);for(let _e=0;_e<y.channelCount;_e+=1)Ce[K].connect(G,_e,K*y.channelCount+_e)}for(const[K,_e]of we.entries())_e.connect(G,0,P+K),_e.start(0);return G.connect(j.destination),await Promise.all(X.map(K=>d(w,j,K))),g(j)})(),b,y,x,C,l)}const A=await k,M=t(b,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),[D,F,R]=O;A!==null&&(M.buffer=A,M.start(0)),M.connect(D);for(let P=0,z=0;P<w.numberOfOutputs;P+=1){const L=F[P];for(let U=0;U<x[P];U+=1)D.connect(L,z+U,U);z+=x[P]}return R}if(N)for(const[A,M]of w.parameters.entries())await s(b,M,v.parameters.get(A));else for(const[A,M]of w.parameters.entries())await f(b,M,v.parameters.get(A));return await d(w,b,v),v};return{render(w,b){a(b,w);const v=S.get(b);return v!==void 0?Promise.resolve(v):m(w,b)}}},ra=(s,e,t,n,i,r,o,a,c,l,u,h,p,f,d,g,_,y,C,S)=>class extends d{constructor(m,w){super(m,w),this._nativeContext=m,this._audioWorklet=s===void 0?void 0:{addModule:(b,v)=>s(this,b,v)}}get audioWorklet(){return this._audioWorklet}createAnalyser(){return new e(this)}createBiquadFilter(){return new i(this)}createBuffer(m,w,b){return new t({length:w,numberOfChannels:m,sampleRate:b})}createBufferSource(){return new n(this)}createChannelMerger(m=6){return new r(this,{numberOfInputs:m})}createChannelSplitter(m=6){return new o(this,{numberOfOutputs:m})}createConstantSource(){return new a(this)}createConvolver(){return new c(this)}createDelay(m=1){return new u(this,{maxDelayTime:m})}createDynamicsCompressor(){return new h(this)}createGain(){return new p(this)}createIIRFilter(m,w){return new f(this,{feedback:w,feedforward:m})}createOscillator(){return new g(this)}createPanner(){return new _(this)}createPeriodicWave(m,w,b={disableNormalization:!1}){return new y(this,{...b,imag:w,real:m})}createStereoPanner(){return new C(this)}createWaveShaper(){return new S(this)}decodeAudioData(m,w,b){return l(this._nativeContext,m).then(v=>(typeof w=="function"&&w(v),v),v=>{throw typeof b=="function"&&b(v),v})}},oa={Q:1,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:350,gain:0,type:"lowpass"},aa=(s,e,t,n,i,r,o,a)=>class extends s{constructor(l,u){const h=r(l),p={...oa,...u},f=i(h,p),d=o(h),g=d?t():null;super(l,!1,f,g),this._Q=e(this,d,f.Q,Ae,Ne),this._detune=e(this,d,f.detune,1200*Math.log2(Ae),-1200*Math.log2(Ae)),this._frequency=e(this,d,f.frequency,l.sampleRate/2,0),this._gain=e(this,d,f.gain,40*Math.log10(Ae),Ne),this._nativeBiquadFilterNode=f,a(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(l){this._nativeBiquadFilterNode.type=l}getFrequencyResponse(l,u,h){try{this._nativeBiquadFilterNode.getFrequencyResponse(l,u,h)}catch(p){throw p.code===11?n():p}if(l.length!==u.length||u.length!==h.length)throw n()}},ca=(s,e,t,n,i)=>()=>{const r=new WeakMap,o=async(a,c)=>{let l=t(a);const u=be(l,c);if(!u){const h={Q:l.Q.value,channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,detune:l.detune.value,frequency:l.frequency.value,gain:l.gain.value,type:l.type};l=e(c,h)}return r.set(c,l),u?(await s(c,a.Q,l.Q),await s(c,a.detune,l.detune),await s(c,a.frequency,l.frequency),await s(c,a.gain,l.gain)):(await n(c,a.Q,l.Q),await n(c,a.detune,l.detune),await n(c,a.frequency,l.frequency),await n(c,a.gain,l.gain)),await i(a,c,l),l};return{render(a,c){const l=r.get(c);return l!==void 0?Promise.resolve(l):o(a,c)}}},la=(s,e)=>(t,n)=>{const i=e.get(t);if(i!==void 0)return i;const r=s.get(t);if(r!==void 0)return r;try{const o=n();return o instanceof Promise?(s.set(t,o),o.catch(()=>!1).then(a=>(s.delete(t),e.set(t,a),a))):(e.set(t,o),o)}catch{return e.set(t,!1),!1}},ua={channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6},ha=(s,e,t,n,i)=>class extends s{constructor(o,a){const c=n(o),l={...ua,...a},u=t(c,l),h=i(c)?e():null;super(o,!1,u,h)}},da=(s,e,t)=>()=>{const n=new WeakMap,i=async(r,o)=>{let a=e(r);if(!be(a,o)){const l={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfInputs:a.numberOfInputs};a=s(o,l)}return n.set(o,a),await t(r,o,a),a};return{render(r,o){const a=n.get(o);return a!==void 0?Promise.resolve(a):i(r,o)}}},pa={channelCount:6,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:6},fa=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=n(a),u=r({...pa,...c}),h=t(l,u),p=i(l)?e():null;super(a,!1,h,p)}},ma=(s,e,t)=>()=>{const n=new WeakMap,i=async(r,o)=>{let a=e(r);if(!be(a,o)){const l={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfOutputs:a.numberOfOutputs};a=s(o,l)}return n.set(o,a),await t(r,o,a),a};return{render(r,o){const a=n.get(o);return a!==void 0?Promise.resolve(a):i(r,o)}}},ga=s=>(e,t,n)=>s(t,e,n),_a=s=>(e,t,n=0,i=0)=>{const r=e[n];if(r===void 0)throw s();return Zn(t)?r.connect(t,0,i):r.connect(t,0)},ya=s=>(e,t)=>{const n=s(e,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),i=e.createBuffer(1,2,44100);return n.buffer=i,n.loop=!0,n.connect(t),n.start(),()=>{n.stop(),n.disconnect(t)}},va={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",offset:1},Ta=(s,e,t,n,i,r,o)=>class extends s{constructor(c,l){const u=i(c),h={...va,...l},p=n(u,h),f=r(u),d=f?t():null;super(c,!1,p,d),this._constantSourceNodeRenderer=d,this._nativeConstantSourceNode=p,this._offset=e(this,f,p.offset,Ae,Ne),this._onended=null}get offset(){return this._offset}get onended(){return this._onended}set onended(c){const l=typeof c=="function"?o(this,c):null;this._nativeConstantSourceNode.onended=l;const u=this._nativeConstantSourceNode.onended;this._onended=u!==null&&u===l?c:u}start(c=0){if(this._nativeConstantSourceNode.start(c),this._constantSourceNodeRenderer!==null&&(this._constantSourceNodeRenderer.start=c),this.context.state!=="closed"){zt(this);const l=()=>{this._nativeConstantSourceNode.removeEventListener("ended",l),nt(this)&&wn(this)};this._nativeConstantSourceNode.addEventListener("ended",l)}}stop(c=0){this._nativeConstantSourceNode.stop(c),this._constantSourceNodeRenderer!==null&&(this._constantSourceNodeRenderer.stop=c)}},wa=(s,e,t,n,i)=>()=>{const r=new WeakMap;let o=null,a=null;const c=async(l,u)=>{let h=t(l);const p=be(h,u);if(!p){const f={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,offset:h.offset.value};h=e(u,f),o!==null&&h.start(o),a!==null&&h.stop(a)}return r.set(u,h),p?await s(u,l.offset,h.offset):await n(u,l.offset,h.offset),await i(l,u,h),h};return{set start(l){o=l},set stop(l){a=l},render(l,u){const h=r.get(u);return h!==void 0?Promise.resolve(h):c(l,u)}}},ba=s=>e=>(s[0]=e,s[0]),Ca={buffer:null,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",disableNormalization:!1},Sa=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=n(a),u={...Ca,...c},h=t(l,u),f=i(l)?e():null;super(a,!1,h,f),this._isBufferNullified=!1,this._nativeConvolverNode=h,u.buffer!==null&&r(this,u.buffer.duration)}get buffer(){return this._isBufferNullified?null:this._nativeConvolverNode.buffer}set buffer(a){if(this._nativeConvolverNode.buffer=a,a===null&&this._nativeConvolverNode.buffer!==null){const c=this._nativeConvolverNode.context;this._nativeConvolverNode.buffer=c.createBuffer(1,1,c.sampleRate),this._isBufferNullified=!0,r(this,0)}else this._isBufferNullified=!1,r(this,this._nativeConvolverNode.buffer===null?0:this._nativeConvolverNode.buffer.duration)}get normalize(){return this._nativeConvolverNode.normalize}set normalize(a){this._nativeConvolverNode.normalize=a}},Aa=(s,e,t)=>()=>{const n=new WeakMap,i=async(r,o)=>{let a=e(r);if(!be(a,o)){const l={buffer:a.buffer,channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,disableNormalization:!a.normalize};a=s(o,l)}return n.set(o,a),Kt(a)?await t(r,o,a.inputs[0]):await t(r,o,a),a};return{render(r,o){const a=n.get(o);return a!==void 0?Promise.resolve(a):i(r,o)}}},ka=(s,e)=>(t,n,i)=>{if(e===null)throw new Error("Missing the native OfflineAudioContext constructor.");try{return new e(t,n,i)}catch(r){throw r.name==="SyntaxError"?s():r}},xa=()=>new DOMException("","DataCloneError"),Oi=s=>{const{port1:e,port2:t}=new MessageChannel;return new Promise(n=>{const i=()=>{t.onmessage=null,e.close(),t.close(),n()};t.onmessage=()=>i();try{e.postMessage(s,[s])}catch{}finally{i()}})},Na=(s,e,t,n,i,r,o,a,c,l,u)=>(h,p)=>{const f=o(h)?h:r(h);if(i.has(p)){const d=t();return Promise.reject(d)}try{i.add(p)}catch{}return e(c,()=>c(f))?f.decodeAudioData(p).then(d=>(Oi(p).catch(()=>{}),e(a,()=>a(d))||u(d),s.add(d),d)):new Promise((d,g)=>{const _=async()=>{try{await Oi(p)}catch{}},y=C=>{g(C),_()};try{f.decodeAudioData(p,C=>{typeof C.copyFromChannel!="function"&&(l(C),qs(C)),s.add(C),_().then(()=>d(C))},C=>{y(C===null?n():C)})}catch(C){y(C)}})},Oa=(s,e,t,n,i,r,o,a)=>(c,l)=>{const u=e.get(c);if(u===void 0)throw new Error("Missing the expected cycle count.");const h=r(c.context),p=a(h);if(u===l){if(e.delete(c),!p&&o(c)){const f=n(c),{outputs:d}=t(c);for(const g of d)if(Cn(g)){const _=n(g[0]);s(f,_,g[1],g[2])}else{const _=i(g[0]);f.connect(_,g[1])}}}else e.set(c,u-l)},Ea={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",delayTime:0,maxDelayTime:1},Ma=(s,e,t,n,i,r,o)=>class extends s{constructor(c,l){const u=i(c),h={...Ea,...l},p=n(u,h),f=r(u),d=f?t(h.maxDelayTime):null;super(c,!1,p,d),this._delayTime=e(this,f,p.delayTime),o(this,h.maxDelayTime)}get delayTime(){return this._delayTime}},Ia=(s,e,t,n,i)=>r=>{const o=new WeakMap,a=async(c,l)=>{let u=t(c);const h=be(u,l);if(!h){const p={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,delayTime:u.delayTime.value,maxDelayTime:r};u=e(l,p)}return o.set(l,u),h?await s(l,c.delayTime,u.delayTime):await n(l,c.delayTime,u.delayTime),await i(c,l,u),u};return{render(c,l){const u=o.get(l);return u!==void 0?Promise.resolve(u):a(c,l)}}},Da=s=>(e,t,n,i)=>s(e[i],r=>r[0]===t&&r[1]===n),Ra=s=>(e,t)=>{s(e).delete(t)},Pa=s=>"delayTime"in s,Va=(s,e,t)=>function n(i,r){const o=zn(r)?r:t(s,r);if(Pa(o))return[];if(i[0]===o)return[i];if(i.includes(o))return[];const{outputs:a}=e(o);return Array.from(a).map(c=>n([...i,o],c[0])).reduce((c,l)=>c.concat(l),[])},Pn=(s,e,t)=>{const n=e[t];if(n===void 0)throw s();return n},Fa=s=>(e,t=void 0,n=void 0,i=0)=>t===void 0?e.forEach(r=>r.disconnect()):typeof t=="number"?Pn(s,e,t).disconnect():Zn(t)?n===void 0?e.forEach(r=>r.disconnect(t)):i===void 0?Pn(s,e,n).disconnect(t,0):Pn(s,e,n).disconnect(t,0,i):n===void 0?e.forEach(r=>r.disconnect(t)):Pn(s,e,n).disconnect(t,0),La={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},qa=(s,e,t,n,i,r,o,a)=>class extends s{constructor(l,u){const h=r(l),p={...La,...u},f=n(h,p),d=o(h),g=d?t():null;super(l,!1,f,g),this._attack=e(this,d,f.attack),this._knee=e(this,d,f.knee),this._nativeDynamicsCompressorNode=f,this._ratio=e(this,d,f.ratio),this._release=e(this,d,f.release),this._threshold=e(this,d,f.threshold),a(this,.006)}get attack(){return this._attack}get channelCount(){return this._nativeDynamicsCompressorNode.channelCount}set channelCount(l){const u=this._nativeDynamicsCompressorNode.channelCount;if(this._nativeDynamicsCompressorNode.channelCount=l,l>2)throw this._nativeDynamicsCompressorNode.channelCount=u,i()}get channelCountMode(){return this._nativeDynamicsCompressorNode.channelCountMode}set channelCountMode(l){const u=this._nativeDynamicsCompressorNode.channelCountMode;if(this._nativeDynamicsCompressorNode.channelCountMode=l,l==="max")throw this._nativeDynamicsCompressorNode.channelCountMode=u,i()}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}},Wa=(s,e,t,n,i)=>()=>{const r=new WeakMap,o=async(a,c)=>{let l=t(a);const u=be(l,c);if(!u){const h={attack:l.attack.value,channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,knee:l.knee.value,ratio:l.ratio.value,release:l.release.value,threshold:l.threshold.value};l=e(c,h)}return r.set(c,l),u?(await s(c,a.attack,l.attack),await s(c,a.knee,l.knee),await s(c,a.ratio,l.ratio),await s(c,a.release,l.release),await s(c,a.threshold,l.threshold)):(await n(c,a.attack,l.attack),await n(c,a.knee,l.knee),await n(c,a.ratio,l.ratio),await n(c,a.release,l.release),await n(c,a.threshold,l.threshold)),await i(a,c,l),l};return{render(a,c){const l=r.get(c);return l!==void 0?Promise.resolve(l):o(a,c)}}},ja=()=>new DOMException("","EncodingError"),Ba=s=>e=>new Promise((t,n)=>{if(s===null){n(new SyntaxError);return}const i=s.document.head;if(i===null)n(new SyntaxError);else{const r=s.document.createElement("script"),o=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(o),c=s.onerror,l=()=>{s.onerror=c,URL.revokeObjectURL(a)};s.onerror=(u,h,p,f,d)=>{if(h===a||h===s.location.href&&p===1&&f===1)return l(),n(d),!1;if(c!==null)return c(u,h,p,f,d)},r.onerror=()=>{l(),n(new SyntaxError)},r.onload=()=>{l(),t()},r.src=a,r.type="module",i.appendChild(r)}}),Ua=s=>class{constructor(t){this._nativeEventTarget=t,this._listeners=new WeakMap}addEventListener(t,n,i){if(n!==null){let r=this._listeners.get(n);r===void 0&&(r=s(this,n),typeof n=="function"&&this._listeners.set(n,r)),this._nativeEventTarget.addEventListener(t,r,i)}}dispatchEvent(t){return this._nativeEventTarget.dispatchEvent(t)}removeEventListener(t,n,i){const r=n===null?void 0:this._listeners.get(n);this._nativeEventTarget.removeEventListener(t,r===void 0?null:r,i)}},za=s=>(e,t,n)=>{Object.defineProperties(s,{currentFrame:{configurable:!0,get(){return Math.round(e*t)}},currentTime:{configurable:!0,get(){return e}}});try{return n()}finally{s!==null&&(delete s.currentFrame,delete s.currentTime)}},Ga=s=>async e=>{try{const t=await fetch(e);if(t.ok)return[await t.text(),t.url]}catch{}throw s()},Ya={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},Za=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=i(a),u={...Ya,...c},h=n(l,u),p=r(l),f=p?t():null;super(a,!1,h,f),this._gain=e(this,p,h.gain,Ae,Ne)}get gain(){return this._gain}},$a=(s,e,t,n,i)=>()=>{const r=new WeakMap,o=async(a,c)=>{let l=t(a);const u=be(l,c);if(!u){const h={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,gain:l.gain.value};l=e(c,h)}return r.set(c,l),u?await s(c,a.gain,l.gain):await n(c,a.gain,l.gain),await i(a,c,l),l};return{render(a,c){const l=r.get(c);return l!==void 0?Promise.resolve(l):o(a,c)}}},Xa=(s,e)=>t=>e(s,t),Ha=s=>e=>{const t=s(e);if(t.renderer===null)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return t.renderer},Qa=s=>e=>{var t;return(t=s.get(e))!==null&&t!==void 0?t:0},Ka=s=>e=>{const t=s(e);if(t.renderer===null)throw new Error("Missing the renderer of the given AudioParam in the audio graph.");return t.renderer},Ja=s=>e=>s.get(e),ge=()=>new DOMException("","InvalidStateError"),ec=s=>e=>{const t=s.get(e);if(t===void 0)throw ge();return t},tc=(s,e)=>t=>{let n=s.get(t);if(n!==void 0)return n;if(e===null)throw new Error("Missing the native OfflineAudioContext constructor.");return n=new e(1,1,44100),s.set(t,n),n},nc=s=>e=>{const t=s.get(e);if(t===void 0)throw new Error("The context has no set of AudioWorkletNodes.");return t},us=()=>new DOMException("","InvalidAccessError"),sc=s=>{s.getFrequencyResponse=(e=>(t,n,i)=>{if(t.length!==n.length||n.length!==i.length)throw us();return e.call(s,t,n,i)})(s.getFrequencyResponse)},ic={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},rc=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=n(a),u=i(l),h={...ic,...c},p=e(l,u?null:a.baseLatency,h),f=u?t(h.feedback,h.feedforward):null;super(a,!1,p,f),sc(p),this._nativeIIRFilterNode=p,r(this,1)}getFrequencyResponse(a,c,l){return this._nativeIIRFilterNode.getFrequencyResponse(a,c,l)}},tr=(s,e,t,n,i,r,o,a,c,l,u)=>{const h=l.length;let p=a;for(let f=0;f<h;f+=1){let d=t[0]*l[f];for(let g=1;g<i;g+=1){const _=p-g&c-1;d+=t[g]*r[_],d-=s[g]*o[_]}for(let g=i;g<n;g+=1)d+=t[g]*r[p-g&c-1];for(let g=i;g<e;g+=1)d-=s[g]*o[p-g&c-1];r[p]=l[f],o[p]=d,p=p+1&c-1,u[f]=d}return p},oc=(s,e,t,n)=>{const i=t instanceof Float64Array?t:new Float64Array(t),r=n instanceof Float64Array?n:new Float64Array(n),o=i.length,a=r.length,c=Math.min(o,a);if(i[0]!==1){for(let d=0;d<o;d+=1)r[d]/=i[0];for(let d=1;d<a;d+=1)i[d]/=i[0]}const l=32,u=new Float32Array(l),h=new Float32Array(l),p=e.createBuffer(s.numberOfChannels,s.length,s.sampleRate),f=s.numberOfChannels;for(let d=0;d<f;d+=1){const g=s.getChannelData(d),_=p.getChannelData(d);u.fill(0),h.fill(0),tr(i,o,r,a,c,u,h,0,l,g,_)}return p},ac=(s,e,t,n,i)=>(r,o)=>{const a=new WeakMap;let c=null;const l=async(u,h)=>{let p=null,f=e(u);const d=be(f,h);if(h.createIIRFilter===void 0?p=s(h,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}):d||(f=h.createIIRFilter(o,r)),a.set(h,p===null?f:p),p!==null){if(c===null){if(t===null)throw new Error("Missing the native OfflineAudioContext constructor.");const _=new t(u.context.destination.channelCount,u.context.length,h.sampleRate);c=(async()=>{await n(u,_,_.destination);const y=await i(_);return oc(y,h,r,o)})()}const g=await c;return p.buffer=g,p.start(0),p}return await n(u,h,f),f};return{render(u,h){const p=a.get(h);return p!==void 0?Promise.resolve(p):l(u,h)}}},cc=(s,e,t,n,i,r)=>o=>(a,c)=>{const l=s.get(a);if(l===void 0){if(!o&&r(a)){const u=n(a),{outputs:h}=t(a);for(const p of h)if(Cn(p)){const f=n(p[0]);e(u,f,p[1],p[2])}else{const f=i(p[0]);u.disconnect(f,p[1])}}s.set(a,c)}else s.set(a,l+c)},lc=(s,e)=>t=>{const n=s.get(t);return e(n)||e(t)},uc=(s,e)=>t=>s.has(t)||e(t),hc=(s,e)=>t=>s.has(t)||e(t),dc=(s,e)=>t=>{const n=s.get(t);return e(n)||e(t)},pc=s=>e=>s!==null&&e instanceof s,fc=s=>e=>s!==null&&typeof s.AudioNode=="function"&&e instanceof s.AudioNode,mc=s=>e=>s!==null&&typeof s.AudioParam=="function"&&e instanceof s.AudioParam,gc=(s,e)=>t=>s(t)||e(t),_c=s=>e=>s!==null&&e instanceof s,yc=s=>s!==null&&s.isSecureContext,vc=(s,e,t,n)=>class extends s{constructor(r,o){const a=t(r),c=e(a,o);if(n(a))throw TypeError();super(r,!0,c,null),this._nativeMediaElementAudioSourceNode=c}get mediaElement(){return this._nativeMediaElementAudioSourceNode.mediaElement}},Tc={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers"},wc=(s,e,t,n)=>class extends s{constructor(r,o){const a=t(r);if(n(a))throw new TypeError;const c={...Tc,...o},l=e(a,c);super(r,!1,l,null),this._nativeMediaStreamAudioDestinationNode=l}get stream(){return this._nativeMediaStreamAudioDestinationNode.stream}},bc=(s,e,t,n)=>class extends s{constructor(r,o){const a=t(r),c=e(a,o);if(n(a))throw new TypeError;super(r,!0,c,null),this._nativeMediaStreamAudioSourceNode=c}get mediaStream(){return this._nativeMediaStreamAudioSourceNode.mediaStream}},Cc=(s,e,t)=>class extends s{constructor(i,r){const o=t(i),a=e(o,r);super(i,!0,a,null)}},Sc=(s,e,t,n,i,r)=>class extends t{constructor(a,c){super(a),this._nativeContext=a,cs.set(this,a),n(a)&&i.set(a,new Set),this._destination=new s(this,c),this._listener=e(this,a),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(a){const c=typeof a=="function"?r(this,a):null;this._nativeContext.onstatechange=c;const l=this._nativeContext.onstatechange;this._onstatechange=l!==null&&l===c?a:l}get sampleRate(){return this._nativeContext.sampleRate}get state(){return this._nativeContext.state}},an=s=>{const e=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{const t=s.decodeAudioData(e.buffer,()=>{});return t===void 0?!1:(t.catch(()=>{}),!0)}catch{}return!1},Ac=(s,e)=>(t,n,i)=>{const r=new Set;return t.connect=(o=>(a,c=0,l=0)=>{const u=r.size===0;if(e(a))return o.call(t,a,c,l),s(r,[a,c,l],h=>h[0]===a&&h[1]===c&&h[2]===l,!0),u&&n(),a;o.call(t,a,c),s(r,[a,c],h=>h[0]===a&&h[1]===c,!0),u&&n()})(t.connect),t.disconnect=(o=>(a,c,l)=>{const u=r.size>0;if(a===void 0)o.apply(t),r.clear();else if(typeof a=="number"){o.call(t,a);for(const p of r)p[1]===a&&r.delete(p)}else{e(a)?o.call(t,a,c,l):o.call(t,a,c);for(const p of r)p[0]===a&&(c===void 0||p[1]===c)&&(l===void 0||p[2]===l)&&r.delete(p)}const h=r.size===0;u&&h&&i()})(t.disconnect),t},re=(s,e,t)=>{const n=e[t];n!==void 0&&n!==s[t]&&(s[t]=n)},pe=(s,e)=>{re(s,e,"channelCount"),re(s,e,"channelCountMode"),re(s,e,"channelInterpretation")},Ei=s=>typeof s.getFloatTimeDomainData=="function",kc=s=>{s.getFloatTimeDomainData=e=>{const t=new Uint8Array(e.length);s.getByteTimeDomainData(t);const n=Math.max(t.length,s.fftSize);for(let i=0;i<n;i+=1)e[i]=(t[i]-128)*.0078125;return e}},xc=(s,e)=>(t,n)=>{const i=t.createAnalyser();if(pe(i,n),!(n.maxDecibels>n.minDecibels))throw e();return re(i,n,"fftSize"),re(i,n,"maxDecibels"),re(i,n,"minDecibels"),re(i,n,"smoothingTimeConstant"),s(Ei,()=>Ei(i))||kc(i),i},Nc=s=>s===null?null:s.hasOwnProperty("AudioBuffer")?s.AudioBuffer:null,ae=(s,e,t)=>{const n=e[t];n!==void 0&&n!==s[t].value&&(s[t].value=n)},Oc=s=>{s.start=(e=>{let t=!1;return(n=0,i=0,r)=>{if(t)throw ge();e.call(s,n,i,r),t=!0}})(s.start)},Bs=s=>{s.start=(e=>(t=0,n=0,i)=>{if(typeof i=="number"&&i<0||n<0||t<0)throw new RangeError("The parameters can't be negative.");e.call(s,t,n,i)})(s.start)},Us=s=>{s.stop=(e=>(t=0)=>{if(t<0)throw new RangeError("The parameter can't be negative.");e.call(s,t)})(s.stop)},Ec=(s,e,t,n,i,r,o,a,c,l,u)=>(h,p)=>{const f=h.createBufferSource();return pe(f,p),ae(f,p,"playbackRate"),re(f,p,"buffer"),re(f,p,"loop"),re(f,p,"loopEnd"),re(f,p,"loopStart"),e(t,()=>t(h))||Oc(f),e(n,()=>n(h))||c(f),e(i,()=>i(h))||l(f,h),e(r,()=>r(h))||Bs(f),e(o,()=>o(h))||u(f,h),e(a,()=>a(h))||Us(f),s(h,f),f},Mc=s=>s===null?null:s.hasOwnProperty("AudioContext")?s.AudioContext:s.hasOwnProperty("webkitAudioContext")?s.webkitAudioContext:null,Ic=(s,e)=>(t,n,i)=>{const r=t.destination;if(r.channelCount!==n)try{r.channelCount=n}catch{}i&&r.channelCountMode!=="explicit"&&(r.channelCountMode="explicit"),r.maxChannelCount===0&&Object.defineProperty(r,"maxChannelCount",{value:n});const o=s(t,{channelCount:n,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,gain:1});return e(o,"channelCount",a=>()=>a.call(o),a=>c=>{a.call(o,c);try{r.channelCount=c}catch(l){if(c>r.maxChannelCount)throw l}}),e(o,"channelCountMode",a=>()=>a.call(o),a=>c=>{a.call(o,c),r.channelCountMode=c}),e(o,"channelInterpretation",a=>()=>a.call(o),a=>c=>{a.call(o,c),r.channelInterpretation=c}),Object.defineProperty(o,"maxChannelCount",{get:()=>r.maxChannelCount}),o.connect(r),o},Dc=s=>s===null?null:s.hasOwnProperty("AudioWorkletNode")?s.AudioWorkletNode:null,Rc=s=>{const{port1:e}=new MessageChannel;try{e.postMessage(s)}finally{e.close()}},Pc=(s,e,t,n,i)=>(r,o,a,c,l,u)=>{if(a!==null)try{const h=new a(r,c,u),p=new Map;let f=null;if(Object.defineProperties(h,{channelCount:{get:()=>u.channelCount,set:()=>{throw s()}},channelCountMode:{get:()=>"explicit",set:()=>{throw s()}},onprocessorerror:{get:()=>f,set:d=>{typeof f=="function"&&h.removeEventListener("processorerror",f),f=typeof d=="function"?d:null,typeof f=="function"&&h.addEventListener("processorerror",f)}}}),h.addEventListener=(d=>(...g)=>{if(g[0]==="processorerror"){const _=typeof g[1]=="function"?g[1]:typeof g[1]=="object"&&g[1]!==null&&typeof g[1].handleEvent=="function"?g[1].handleEvent:null;if(_!==null){const y=p.get(g[1]);y!==void 0?g[1]=y:(g[1]=C=>{C.type==="error"?(Object.defineProperties(C,{type:{value:"processorerror"}}),_(C)):_(new ErrorEvent(g[0],{...C}))},p.set(_,g[1]))}}return d.call(h,"error",g[1],g[2]),d.call(h,...g)})(h.addEventListener),h.removeEventListener=(d=>(...g)=>{if(g[0]==="processorerror"){const _=p.get(g[1]);_!==void 0&&(p.delete(g[1]),g[1]=_)}return d.call(h,"error",g[1],g[2]),d.call(h,g[0],g[1],g[2])})(h.removeEventListener),u.numberOfOutputs!==0){const d=t(r,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return h.connect(d).connect(r.destination),i(h,()=>d.disconnect(),()=>d.connect(r.destination))}return h}catch(h){throw h.code===11?n():h}if(l===void 0)throw n();return Rc(u),e(r,o,l,u)},nr=(s,e)=>s===null?512:Math.max(512,Math.min(16384,Math.pow(2,Math.round(Math.log2(s*e))))),Vc=s=>new Promise((e,t)=>{const{port1:n,port2:i}=new MessageChannel;n.onmessage=({data:r})=>{n.close(),i.close(),e(r)},n.onmessageerror=({data:r})=>{n.close(),i.close(),t(r)},i.postMessage(s)}),Fc=async(s,e)=>{const t=await Vc(e);return new s(t)},Lc=(s,e,t,n)=>{let i=Es.get(s);i===void 0&&(i=new WeakMap,Es.set(s,i));const r=Fc(t,n);return i.set(e,r),r},qc=(s,e,t,n,i,r,o,a,c,l,u,h,p)=>(f,d,g,_)=>{if(_.numberOfInputs===0&&_.numberOfOutputs===0)throw c();const y=Array.isArray(_.outputChannelCount)?_.outputChannelCount:Array.from(_.outputChannelCount);if(y.some(I=>I<1))throw c();if(y.length!==_.numberOfOutputs)throw e();if(_.channelCountMode!=="explicit")throw c();const C=_.channelCount*_.numberOfInputs,S=y.reduce((I,q)=>I+q,0),k=g.parameterDescriptors===void 0?0:g.parameterDescriptors.length;if(C+k>6||S>6)throw c();const m=new MessageChannel,w=[],b=[];for(let I=0;I<_.numberOfInputs;I+=1)w.push(o(f,{channelCount:_.channelCount,channelCountMode:_.channelCountMode,channelInterpretation:_.channelInterpretation,gain:1})),b.push(i(f,{channelCount:_.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:_.channelCount}));const v=[];if(g.parameterDescriptors!==void 0)for(const{defaultValue:I,maxValue:q,minValue:oe,name:ee}of g.parameterDescriptors){const $=r(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:_.parameterData[ee]!==void 0?_.parameterData[ee]:I===void 0?0:I});Object.defineProperties($.offset,{defaultValue:{get:()=>I===void 0?0:I},maxValue:{get:()=>q===void 0?Ae:q},minValue:{get:()=>oe===void 0?Ne:oe}}),v.push($)}const O=n(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,C+k)}),N=nr(d,f.sampleRate),x=a(f,N,C+k,Math.max(1,S)),A=i(f,{channelCount:Math.max(1,S),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,S)}),M=[];for(let I=0;I<_.numberOfOutputs;I+=1)M.push(n(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:y[I]}));for(let I=0;I<_.numberOfInputs;I+=1){w[I].connect(b[I]);for(let q=0;q<_.channelCount;q+=1)b[I].connect(O,q,I*_.channelCount+q)}const D=new Ji(g.parameterDescriptors===void 0?[]:g.parameterDescriptors.map(({name:I},q)=>{const oe=v[q];return oe.connect(O,0,C+q),oe.start(0),[I,oe.offset]}));O.connect(x);let F=_.channelInterpretation,R=null;const P=_.numberOfOutputs===0?[x]:M,z={get bufferSize(){return N},get channelCount(){return _.channelCount},set channelCount(I){throw t()},get channelCountMode(){return _.channelCountMode},set channelCountMode(I){throw t()},get channelInterpretation(){return F},set channelInterpretation(I){for(const q of w)q.channelInterpretation=I;F=I},get context(){return x.context},get inputs(){return w},get numberOfInputs(){return _.numberOfInputs},get numberOfOutputs(){return _.numberOfOutputs},get onprocessorerror(){return R},set onprocessorerror(I){typeof R=="function"&&z.removeEventListener("processorerror",R),R=typeof I=="function"?I:null,typeof R=="function"&&z.addEventListener("processorerror",R)},get parameters(){return D},get port(){return m.port2},addEventListener(...I){return x.addEventListener(I[0],I[1],I[2])},connect:s.bind(null,P),disconnect:l.bind(null,P),dispatchEvent(...I){return x.dispatchEvent(I[0])},removeEventListener(...I){return x.removeEventListener(I[0],I[1],I[2])}},L=new Map;m.port1.addEventListener=(I=>(...q)=>{if(q[0]==="message"){const oe=typeof q[1]=="function"?q[1]:typeof q[1]=="object"&&q[1]!==null&&typeof q[1].handleEvent=="function"?q[1].handleEvent:null;if(oe!==null){const ee=L.get(q[1]);ee!==void 0?q[1]=ee:(q[1]=$=>{u(f.currentTime,f.sampleRate,()=>oe($))},L.set(oe,q[1]))}}return I.call(m.port1,q[0],q[1],q[2])})(m.port1.addEventListener),m.port1.removeEventListener=(I=>(...q)=>{if(q[0]==="message"){const oe=L.get(q[1]);oe!==void 0&&(L.delete(q[1]),q[1]=oe)}return I.call(m.port1,q[0],q[1],q[2])})(m.port1.removeEventListener);let U=null;Object.defineProperty(m.port1,"onmessage",{get:()=>U,set:I=>{typeof U=="function"&&m.port1.removeEventListener("message",U),U=typeof I=="function"?I:null,typeof U=="function"&&(m.port1.addEventListener("message",U),m.port1.start())}}),g.prototype.port=m.port1;let j=null;Lc(f,z,g,_).then(I=>j=I);const Ce=Xn(_.numberOfInputs,_.channelCount),we=Xn(_.numberOfOutputs,y),G=g.parameterDescriptors===void 0?[]:g.parameterDescriptors.reduce((I,{name:q})=>({...I,[q]:new Float32Array(128)}),{});let K=!0;const _e=()=>{_.numberOfOutputs>0&&x.disconnect(A);for(let I=0,q=0;I<_.numberOfOutputs;I+=1){const oe=M[I];for(let ee=0;ee<y[I];ee+=1)A.disconnect(oe,q+ee,ee);q+=y[I]}},V=new Map;x.onaudioprocess=({inputBuffer:I,outputBuffer:q})=>{if(j!==null){const oe=h(z);for(let ee=0;ee<N;ee+=128){for(let $=0;$<_.numberOfInputs;$+=1)for(let te=0;te<_.channelCount;te+=1)$n(I,Ce[$],te,te,ee);g.parameterDescriptors!==void 0&&g.parameterDescriptors.forEach(({name:$},te)=>{$n(I,G,$,C+te,ee)});for(let $=0;$<_.numberOfInputs;$+=1)for(let te=0;te<y[$];te+=1)we[$][te].byteLength===0&&(we[$][te]=new Float32Array(128));try{const $=Ce.map((Se,Ze)=>{if(oe[Ze].size>0)return V.set(Ze,N/128),Se;const Dt=V.get(Ze);return Dt===void 0?[]:(Se.every(Ts=>Ts.every(Mn=>Mn===0))&&(Dt===1?V.delete(Ze):V.set(Ze,Dt-1)),Se)});K=u(f.currentTime+ee/f.sampleRate,f.sampleRate,()=>j.process($,we,G));for(let Se=0,Ze=0;Se<_.numberOfOutputs;Se+=1){for(let Tt=0;Tt<y[Se];Tt+=1)er(q,we[Se],Tt,Ze+Tt,ee);Ze+=y[Se]}}catch($){K=!1,z.dispatchEvent(new ErrorEvent("processorerror",{colno:$.colno,filename:$.filename,lineno:$.lineno,message:$.message}))}if(!K){for(let $=0;$<_.numberOfInputs;$+=1){w[$].disconnect(b[$]);for(let te=0;te<_.channelCount;te+=1)b[ee].disconnect(O,te,$*_.channelCount+te)}if(g.parameterDescriptors!==void 0){const $=g.parameterDescriptors.length;for(let te=0;te<$;te+=1){const Se=v[te];Se.disconnect(O,0,C+te),Se.stop()}}O.disconnect(x),x.onaudioprocess=null,Ge?_e():lt();break}}}};let Ge=!1;const Ye=o(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0}),Ke=()=>x.connect(Ye).connect(f.destination),lt=()=>{x.disconnect(Ye),Ye.disconnect()},vs=()=>{if(K){lt(),_.numberOfOutputs>0&&x.connect(A);for(let I=0,q=0;I<_.numberOfOutputs;I+=1){const oe=M[I];for(let ee=0;ee<y[I];ee+=1)A.connect(oe,q+ee,ee);q+=y[I]}}Ge=!0},En=()=>{K&&(Ke(),_e()),Ge=!1};return Ke(),p(z,vs,En)},sr=(s,e)=>{const t=s.createBiquadFilter();return pe(t,e),ae(t,e,"Q"),ae(t,e,"detune"),ae(t,e,"frequency"),ae(t,e,"gain"),re(t,e,"type"),t},Wc=(s,e)=>(t,n)=>{const i=t.createChannelMerger(n.numberOfInputs);return s!==null&&s.name==="webkitAudioContext"&&e(t,i),pe(i,n),i},jc=s=>{const e=s.numberOfOutputs;Object.defineProperty(s,"channelCount",{get:()=>e,set:t=>{if(t!==e)throw ge()}}),Object.defineProperty(s,"channelCountMode",{get:()=>"explicit",set:t=>{if(t!=="explicit")throw ge()}}),Object.defineProperty(s,"channelInterpretation",{get:()=>"discrete",set:t=>{if(t!=="discrete")throw ge()}})},Sn=(s,e)=>{const t=s.createChannelSplitter(e.numberOfOutputs);return pe(t,e),jc(t),t},Bc=(s,e,t,n,i)=>(r,o)=>{if(r.createConstantSource===void 0)return t(r,o);const a=r.createConstantSource();return pe(a,o),ae(a,o,"offset"),e(n,()=>n(r))||Bs(a),e(i,()=>i(r))||Us(a),s(r,a),a},Jt=(s,e)=>(s.connect=e.connect.bind(e),s.disconnect=e.disconnect.bind(e),s),Uc=(s,e,t,n)=>(i,{offset:r,...o})=>{const a=i.createBuffer(1,2,44100),c=e(i,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),l=t(i,{...o,gain:r}),u=a.getChannelData(0);u[0]=1,u[1]=1,c.buffer=a,c.loop=!0;const h={get bufferSize(){},get channelCount(){return l.channelCount},set channelCount(d){l.channelCount=d},get channelCountMode(){return l.channelCountMode},set channelCountMode(d){l.channelCountMode=d},get channelInterpretation(){return l.channelInterpretation},set channelInterpretation(d){l.channelInterpretation=d},get context(){return l.context},get inputs(){return[]},get numberOfInputs(){return c.numberOfInputs},get numberOfOutputs(){return l.numberOfOutputs},get offset(){return l.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(l),f=()=>c.disconnect(l);return s(i,c),n(Jt(h,l),p,f)},zc=(s,e)=>(t,n)=>{const i=t.createConvolver();if(pe(i,n),n.disableNormalization===i.normalize&&(i.normalize=!n.disableNormalization),re(i,n,"buffer"),n.channelCount>2||(e(i,"channelCount",r=>()=>r.call(i),r=>o=>{if(o>2)throw s();return r.call(i,o)}),n.channelCountMode==="max"))throw s();return e(i,"channelCountMode",r=>()=>r.call(i),r=>o=>{if(o==="max")throw s();return r.call(i,o)}),i},ir=(s,e)=>{const t=s.createDelay(e.maxDelayTime);return pe(t,e),ae(t,e,"delayTime"),t},Gc=s=>(e,t)=>{const n=e.createDynamicsCompressor();if(pe(n,t),t.channelCount>2||t.channelCountMode==="max")throw s();return ae(n,t,"attack"),ae(n,t,"knee"),ae(n,t,"ratio"),ae(n,t,"release"),ae(n,t,"threshold"),n},Ee=(s,e)=>{const t=s.createGain();return pe(t,e),ae(t,e,"gain"),t},Yc=s=>(e,t,n)=>{if(e.createIIRFilter===void 0)return s(e,t,n);const i=e.createIIRFilter(n.feedforward,n.feedback);return pe(i,n),i};function Zc(s,e){const t=e[0]*e[0]+e[1]*e[1];return[(s[0]*e[0]+s[1]*e[1])/t,(s[1]*e[0]-s[0]*e[1])/t]}function $c(s,e){return[s[0]*e[0]-s[1]*e[1],s[0]*e[1]+s[1]*e[0]]}function Mi(s,e){let t=[0,0];for(let n=s.length-1;n>=0;n-=1)t=$c(t,e),t[0]+=s[n];return t}const Xc=(s,e,t,n)=>(i,r,{channelCount:o,channelCountMode:a,channelInterpretation:c,feedback:l,feedforward:u})=>{const h=nr(r,i.sampleRate),p=l instanceof Float64Array?l:new Float64Array(l),f=u instanceof Float64Array?u:new Float64Array(u),d=p.length,g=f.length,_=Math.min(d,g);if(d===0||d>20)throw n();if(p[0]===0)throw e();if(g===0||g>20)throw n();if(f[0]===0)throw e();if(p[0]!==1){for(let v=0;v<g;v+=1)f[v]/=p[0];for(let v=1;v<d;v+=1)p[v]/=p[0]}const y=t(i,h,o,o);y.channelCount=o,y.channelCountMode=a,y.channelInterpretation=c;const C=32,S=[],k=[],m=[];for(let v=0;v<o;v+=1){S.push(0);const O=new Float32Array(C),N=new Float32Array(C);O.fill(0),N.fill(0),k.push(O),m.push(N)}y.onaudioprocess=v=>{const O=v.inputBuffer,N=v.outputBuffer,x=O.numberOfChannels;for(let A=0;A<x;A+=1){const M=O.getChannelData(A),D=N.getChannelData(A);S[A]=tr(p,d,f,g,_,k[A],m[A],S[A],C,M,D)}};const w=i.sampleRate/2;return Jt({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,O,N){if(v.length!==O.length||O.length!==N.length)throw s();const x=v.length;for(let A=0;A<x;A+=1){const M=-Math.PI*(v[A]/w),D=[Math.cos(M),Math.sin(M)],F=Mi(f,D),R=Mi(p,D),P=Zc(F,R);O[A]=Math.sqrt(P[0]*P[0]+P[1]*P[1]),N[A]=Math.atan2(P[1],P[0])}},removeEventListener(...v){return y.removeEventListener(v[0],v[1],v[2])}},y)},Hc=(s,e)=>s.createMediaElementSource(e.mediaElement),Qc=(s,e)=>{const t=s.createMediaStreamDestination();return pe(t,e),t.numberOfOutputs===1&&Object.defineProperty(t,"numberOfOutputs",{get:()=>0}),t},Kc=(s,{mediaStream:e})=>{const t=e.getAudioTracks();t.sort((r,o)=>r.id<o.id?-1:r.id>o.id?1:0);const n=t.slice(0,1),i=s.createMediaStreamSource(new MediaStream(n));return Object.defineProperty(i,"mediaStream",{value:e}),i},Jc=(s,e)=>(t,{mediaStreamTrack:n})=>{if(typeof t.createMediaStreamTrackSource=="function")return t.createMediaStreamTrackSource(n);const i=new MediaStream([n]),r=t.createMediaStreamSource(i);if(n.kind!=="audio")throw s();if(e(t))throw new TypeError;return r},el=s=>s===null?null:s.hasOwnProperty("OfflineAudioContext")?s.OfflineAudioContext:s.hasOwnProperty("webkitOfflineAudioContext")?s.webkitOfflineAudioContext:null,tl=(s,e,t,n,i,r)=>(o,a)=>{const c=o.createOscillator();return pe(c,a),ae(c,a,"detune"),ae(c,a,"frequency"),a.periodicWave!==void 0?c.setPeriodicWave(a.periodicWave):re(c,a,"type"),e(t,()=>t(o))||Bs(c),e(n,()=>n(o))||r(c,o),e(i,()=>i(o))||Us(c),s(o,c),c},nl=s=>(e,t)=>{const n=e.createPanner();return n.orientationX===void 0?s(e,t):(pe(n,t),ae(n,t,"orientationX"),ae(n,t,"orientationY"),ae(n,t,"orientationZ"),ae(n,t,"positionX"),ae(n,t,"positionY"),ae(n,t,"positionZ"),re(n,t,"coneInnerAngle"),re(n,t,"coneOuterAngle"),re(n,t,"coneOuterGain"),re(n,t,"distanceModel"),re(n,t,"maxDistance"),re(n,t,"panningModel"),re(n,t,"refDistance"),re(n,t,"rolloffFactor"),n)},sl=(s,e,t,n,i,r,o,a,c,l)=>(u,{coneInnerAngle:h,coneOuterAngle:p,coneOuterGain:f,distanceModel:d,maxDistance:g,orientationX:_,orientationY:y,orientationZ:C,panningModel:S,positionX:k,positionY:m,positionZ:w,refDistance:b,rolloffFactor:v,...O})=>{const N=u.createPanner();if(O.channelCount>2||O.channelCountMode==="max")throw o();pe(N,O);const x={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},A=t(u,{...x,channelInterpretation:"speakers",numberOfInputs:6}),M=n(u,{...O,gain:1}),D=n(u,{...x,gain:1}),F=n(u,{...x,gain:0}),R=n(u,{...x,gain:0}),P=n(u,{...x,gain:0}),z=n(u,{...x,gain:0}),L=n(u,{...x,gain:0}),U=i(u,256,6,1),j=r(u,{...x,curve:new Float32Array([1,1]),oversample:"none"});let X=[_,y,C],Ce=[k,m,w];const we=new Float32Array(1);U.onaudioprocess=({inputBuffer:V})=>{const Ge=[c(V,we,0),c(V,we,1),c(V,we,2)];Ge.some((Ke,lt)=>Ke!==X[lt])&&(N.setOrientation(...Ge),X=Ge);const Ye=[c(V,we,3),c(V,we,4),c(V,we,5)];Ye.some((Ke,lt)=>Ke!==Ce[lt])&&(N.setPosition(...Ye),Ce=Ye)},Object.defineProperty(F.gain,"defaultValue",{get:()=>0}),Object.defineProperty(R.gain,"defaultValue",{get:()=>0}),Object.defineProperty(P.gain,"defaultValue",{get:()=>0}),Object.defineProperty(z.gain,"defaultValue",{get:()=>0}),Object.defineProperty(L.gain,"defaultValue",{get:()=>0});const G={get bufferSize(){},get channelCount(){return N.channelCount},set channelCount(V){if(V>2)throw o();M.channelCount=V,N.channelCount=V},get channelCountMode(){return N.channelCountMode},set channelCountMode(V){if(V==="max")throw o();M.channelCountMode=V,N.channelCountMode=V},get channelInterpretation(){return N.channelInterpretation},set channelInterpretation(V){M.channelInterpretation=V,N.channelInterpretation=V},get coneInnerAngle(){return N.coneInnerAngle},set coneInnerAngle(V){N.coneInnerAngle=V},get coneOuterAngle(){return N.coneOuterAngle},set coneOuterAngle(V){N.coneOuterAngle=V},get coneOuterGain(){return N.coneOuterGain},set coneOuterGain(V){if(V<0||V>1)throw e();N.coneOuterGain=V},get context(){return N.context},get distanceModel(){return N.distanceModel},set distanceModel(V){N.distanceModel=V},get inputs(){return[M]},get maxDistance(){return N.maxDistance},set maxDistance(V){if(V<0)throw new RangeError;N.maxDistance=V},get numberOfInputs(){return N.numberOfInputs},get numberOfOutputs(){return N.numberOfOutputs},get orientationX(){return D.gain},get orientationY(){return F.gain},get orientationZ(){return R.gain},get panningModel(){return N.panningModel},set panningModel(V){N.panningModel=V},get positionX(){return P.gain},get positionY(){return z.gain},get positionZ(){return L.gain},get refDistance(){return N.refDistance},set refDistance(V){if(V<0)throw new RangeError;N.refDistance=V},get rolloffFactor(){return N.rolloffFactor},set rolloffFactor(V){if(V<0)throw new RangeError;N.rolloffFactor=V},addEventListener(...V){return M.addEventListener(V[0],V[1],V[2])},dispatchEvent(...V){return M.dispatchEvent(V[0])},removeEventListener(...V){return M.removeEventListener(V[0],V[1],V[2])}};h!==G.coneInnerAngle&&(G.coneInnerAngle=h),p!==G.coneOuterAngle&&(G.coneOuterAngle=p),f!==G.coneOuterGain&&(G.coneOuterGain=f),d!==G.distanceModel&&(G.distanceModel=d),g!==G.maxDistance&&(G.maxDistance=g),_!==G.orientationX.value&&(G.orientationX.value=_),y!==G.orientationY.value&&(G.orientationY.value=y),C!==G.orientationZ.value&&(G.orientationZ.value=C),S!==G.panningModel&&(G.panningModel=S),k!==G.positionX.value&&(G.positionX.value=k),m!==G.positionY.value&&(G.positionY.value=m),w!==G.positionZ.value&&(G.positionZ.value=w),b!==G.refDistance&&(G.refDistance=b),v!==G.rolloffFactor&&(G.rolloffFactor=v),(X[0]!==1||X[1]!==0||X[2]!==0)&&N.setOrientation(...X),(Ce[0]!==0||Ce[1]!==0||Ce[2]!==0)&&N.setPosition(...Ce);const K=()=>{M.connect(N),s(M,j,0,0),j.connect(D).connect(A,0,0),j.connect(F).connect(A,0,1),j.connect(R).connect(A,0,2),j.connect(P).connect(A,0,3),j.connect(z).connect(A,0,4),j.connect(L).connect(A,0,5),A.connect(U).connect(u.destination)},_e=()=>{M.disconnect(N),a(M,j,0,0),j.disconnect(D),D.disconnect(A),j.disconnect(F),F.disconnect(A),j.disconnect(R),R.disconnect(A),j.disconnect(P),P.disconnect(A),j.disconnect(z),z.disconnect(A),j.disconnect(L),L.disconnect(A),A.disconnect(U),U.disconnect(u.destination)};return l(Jt(G,N),K,_e)},il=s=>(e,{disableNormalization:t,imag:n,real:i})=>{const r=n instanceof Float32Array?n:new Float32Array(n),o=i instanceof Float32Array?i:new Float32Array(i),a=e.createPeriodicWave(o,r,{disableNormalization:t});if(Array.from(n).length<2)throw s();return a},An=(s,e,t,n)=>s.createScriptProcessor(e,t,n),rl=(s,e)=>(t,n)=>{const i=n.channelCountMode;if(i==="clamped-max")throw e();if(t.createStereoPanner===void 0)return s(t,n);const r=t.createStereoPanner();return pe(r,n),ae(r,n,"pan"),Object.defineProperty(r,"channelCountMode",{get:()=>i,set:o=>{if(o!==i)throw e()}}),r},ol=(s,e,t,n,i,r)=>{const a=new Float32Array([1,1]),c=Math.PI/2,l={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},u={...l,oversample:"none"},h=(d,g,_,y)=>{const C=new Float32Array(16385),S=new Float32Array(16385);for(let O=0;O<16385;O+=1){const N=O/16384*c;C[O]=Math.cos(N),S[O]=Math.sin(N)}const k=t(d,{...l,gain:0}),m=n(d,{...u,curve:C}),w=n(d,{...u,curve:a}),b=t(d,{...l,gain:0}),v=n(d,{...u,curve:S});return{connectGraph(){g.connect(k),g.connect(w.inputs===void 0?w:w.inputs[0]),g.connect(b),w.connect(_),_.connect(m.inputs===void 0?m:m.inputs[0]),_.connect(v.inputs===void 0?v:v.inputs[0]),m.connect(k.gain),v.connect(b.gain),k.connect(y,0,0),b.connect(y,0,1)},disconnectGraph(){g.disconnect(k),g.disconnect(w.inputs===void 0?w:w.inputs[0]),g.disconnect(b),w.disconnect(_),_.disconnect(m.inputs===void 0?m:m.inputs[0]),_.disconnect(v.inputs===void 0?v:v.inputs[0]),m.disconnect(k.gain),v.disconnect(b.gain),k.disconnect(y,0,0),b.disconnect(y,0,1)}}},p=(d,g,_,y)=>{const C=new Float32Array(16385),S=new Float32Array(16385),k=new Float32Array(16385),m=new Float32Array(16385),w=Math.floor(16385/2);for(let P=0;P<16385;P+=1)if(P>w){const z=(P-w)/(16384-w)*c;C[P]=Math.cos(z),S[P]=Math.sin(z),k[P]=0,m[P]=1}else{const z=P/(16384-w)*c;C[P]=1,S[P]=0,k[P]=Math.cos(z),m[P]=Math.sin(z)}const b=e(d,{channelCount:2,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:2}),v=t(d,{...l,gain:0}),O=n(d,{...u,curve:C}),N=t(d,{...l,gain:0}),x=n(d,{...u,curve:S}),A=n(d,{...u,curve:a}),M=t(d,{...l,gain:0}),D=n(d,{...u,curve:k}),F=t(d,{...l,gain:0}),R=n(d,{...u,curve:m});return{connectGraph(){g.connect(b),g.connect(A.inputs===void 0?A:A.inputs[0]),b.connect(v,0),b.connect(N,0),b.connect(M,1),b.connect(F,1),A.connect(_),_.connect(O.inputs===void 0?O:O.inputs[0]),_.connect(x.inputs===void 0?x:x.inputs[0]),_.connect(D.inputs===void 0?D:D.inputs[0]),_.connect(R.inputs===void 0?R:R.inputs[0]),O.connect(v.gain),x.connect(N.gain),D.connect(M.gain),R.connect(F.gain),v.connect(y,0,0),M.connect(y,0,0),N.connect(y,0,1),F.connect(y,0,1)},disconnectGraph(){g.disconnect(b),g.disconnect(A.inputs===void 0?A:A.inputs[0]),b.disconnect(v,0),b.disconnect(N,0),b.disconnect(M,1),b.disconnect(F,1),A.disconnect(_),_.disconnect(O.inputs===void 0?O:O.inputs[0]),_.disconnect(x.inputs===void 0?x:x.inputs[0]),_.disconnect(D.inputs===void 0?D:D.inputs[0]),_.disconnect(R.inputs===void 0?R:R.inputs[0]),O.disconnect(v.gain),x.disconnect(N.gain),D.disconnect(M.gain),R.disconnect(F.gain),v.disconnect(y,0,0),M.disconnect(y,0,0),N.disconnect(y,0,1),F.disconnect(y,0,1)}}},f=(d,g,_,y,C)=>{if(g===1)return h(d,_,y,C);if(g===2)return p(d,_,y,C);throw i()};return(d,{channelCount:g,channelCountMode:_,pan:y,...C})=>{if(_==="max")throw i();const S=s(d,{...C,channelCount:1,channelCountMode:_,numberOfInputs:2}),k=t(d,{...C,channelCount:g,channelCountMode:_,gain:1}),m=t(d,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:y});let{connectGraph:w,disconnectGraph:b}=f(d,g,k,m,S);Object.defineProperty(m.gain,"defaultValue",{get:()=>0}),Object.defineProperty(m.gain,"maxValue",{get:()=>1}),Object.defineProperty(m.gain,"minValue",{get:()=>-1});const v={get bufferSize(){},get channelCount(){return k.channelCount},set channelCount(A){k.channelCount!==A&&(O&&b(),{connectGraph:w,disconnectGraph:b}=f(d,A,k,m,S),O&&w()),k.channelCount=A},get channelCountMode(){return k.channelCountMode},set channelCountMode(A){if(A==="clamped-max"||A==="max")throw i();k.channelCountMode=A},get channelInterpretation(){return k.channelInterpretation},set channelInterpretation(A){k.channelInterpretation=A},get context(){return k.context},get inputs(){return[k]},get numberOfInputs(){return k.numberOfInputs},get numberOfOutputs(){return k.numberOfOutputs},get pan(){return m.gain},addEventListener(...A){return k.addEventListener(A[0],A[1],A[2])},dispatchEvent(...A){return k.dispatchEvent(A[0])},removeEventListener(...A){return k.removeEventListener(A[0],A[1],A[2])}};let O=!1;const N=()=>{w(),O=!0},x=()=>{b(),O=!1};return r(Jt(v,S),N,x)}},al=(s,e,t,n,i,r,o)=>(a,c)=>{const l=a.createWaveShaper();if(r!==null&&r.name==="webkitAudioContext"&&a.createGain().gain.automationRate===void 0)return t(a,c);pe(l,c);const u=c.curve===null||c.curve instanceof Float32Array?c.curve:new Float32Array(c.curve);if(u!==null&&u.length<2)throw e();re(l,{curve:u},"curve"),re(l,c,"oversample");let h=null,p=!1;return o(l,"curve",g=>()=>g.call(l),g=>_=>(g.call(l,_),p&&(n(_)&&h===null?h=s(a,l):!n(_)&&h!==null&&(h(),h=null)),_)),i(l,()=>{p=!0,n(l.curve)&&(h=s(a,l))},()=>{p=!1,h!==null&&(h(),h=null)})},cl=(s,e,t,n,i)=>(r,{curve:o,oversample:a,...c})=>{const l=r.createWaveShaper(),u=r.createWaveShaper();pe(l,c),pe(u,c);const h=t(r,{...c,gain:1}),p=t(r,{...c,gain:-1}),f=t(r,{...c,gain:1}),d=t(r,{...c,gain:-1});let g=null,_=!1,y=null;const C={get bufferSize(){},get channelCount(){return l.channelCount},set channelCount(m){h.channelCount=m,p.channelCount=m,l.channelCount=m,f.channelCount=m,u.channelCount=m,d.channelCount=m},get channelCountMode(){return l.channelCountMode},set channelCountMode(m){h.channelCountMode=m,p.channelCountMode=m,l.channelCountMode=m,f.channelCountMode=m,u.channelCountMode=m,d.channelCountMode=m},get channelInterpretation(){return l.channelInterpretation},set channelInterpretation(m){h.channelInterpretation=m,p.channelInterpretation=m,l.channelInterpretation=m,f.channelInterpretation=m,u.channelInterpretation=m,d.channelInterpretation=m},get context(){return l.context},get curve(){return y},set curve(m){if(m!==null&&m.length<2)throw e();if(m===null)l.curve=m,u.curve=m;else{const w=m.length,b=new Float32Array(w+2-w%2),v=new Float32Array(w+2-w%2);b[0]=m[0],v[0]=-m[w-1];const O=Math.ceil((w+1)/2),N=(w+1)/2-1;for(let x=1;x<O;x+=1){const A=x/O*N,M=Math.floor(A),D=Math.ceil(A);b[x]=M===D?m[M]:(1-(A-M))*m[M]+(1-(D-A))*m[D],v[x]=M===D?-m[w-1-M]:-((1-(A-M))*m[w-1-M])-(1-(D-A))*m[w-1-D]}b[O]=w%2===1?m[O-1]:(m[O-2]+m[O-1])/2,l.curve=b,u.curve=v}y=m,_&&(n(y)&&g===null?g=s(r,h):g!==null&&(g(),g=null))},get inputs(){return[h]},get numberOfInputs(){return l.numberOfInputs},get numberOfOutputs(){return l.numberOfOutputs},get oversample(){return l.oversample},set oversample(m){l.oversample=m,u.oversample=m},addEventListener(...m){return h.addEventListener(m[0],m[1],m[2])},dispatchEvent(...m){return h.dispatchEvent(m[0])},removeEventListener(...m){return h.removeEventListener(m[0],m[1],m[2])}};o!==null&&(C.curve=o instanceof Float32Array?o:new Float32Array(o)),a!==C.oversample&&(C.oversample=a);const S=()=>{h.connect(l).connect(f),h.connect(p).connect(u).connect(d).connect(f),_=!0,n(y)&&(g=s(r,h))},k=()=>{h.disconnect(l),l.disconnect(f),h.disconnect(p),p.disconnect(u),u.disconnect(d),d.disconnect(f),_=!1,g!==null&&(g(),g=null)};return i(Jt(C,f),S,k)},xe=()=>new DOMException("","NotSupportedError"),ll={numberOfChannels:1},ul=(s,e,t,n,i)=>class extends s{constructor(o,a,c){let l;if(typeof o=="number"&&a!==void 0&&c!==void 0)l={length:a,numberOfChannels:o,sampleRate:c};else if(typeof o=="object")l=o;else throw new Error("The given parameters are not valid.");const{length:u,numberOfChannels:h,sampleRate:p}={...ll,...l},f=n(h,u,p);e(an,()=>an(f))||f.addEventListener("statechange",(()=>{let d=0;const g=_=>{this._state==="running"&&(d>0?(f.removeEventListener("statechange",g),_.stopImmediatePropagation(),this._waitForThePromiseToSettle(_)):d+=1)};return g})()),super(f,h),this._length=u,this._nativeOfflineAudioContext=f,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",i(this.destination,this._nativeOfflineAudioContext).finally(()=>{this._state=null,Xi(this)}))}_waitForThePromiseToSettle(o){this._state===null?this._nativeOfflineAudioContext.dispatchEvent(o):setTimeout(()=>this._waitForThePromiseToSettle(o))}},hl={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,periodicWave:void 0,type:"sine"},dl=(s,e,t,n,i,r,o)=>class extends s{constructor(c,l){const u=i(c),h={...hl,...l},p=t(u,h),f=r(u),d=f?n():null,g=c.sampleRate/2;super(c,!1,p,d),this._detune=e(this,f,p.detune,153600,-153600),this._frequency=e(this,f,p.frequency,g,-g),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){const l=typeof c=="function"?o(this,c):null;this._nativeOscillatorNode.onended=l;const u=this._nativeOscillatorNode.onended;this._onended=u!==null&&u===l?c:u}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"){zt(this);const l=()=>{this._nativeOscillatorNode.removeEventListener("ended",l),nt(this)&&wn(this)};this._nativeOscillatorNode.addEventListener("ended",l)}}stop(c=0){this._nativeOscillatorNode.stop(c),this._oscillatorNodeRenderer!==null&&(this._oscillatorNodeRenderer.stop=c)}},pl=(s,e,t,n,i)=>()=>{const r=new WeakMap;let o=null,a=null,c=null;const l=async(u,h)=>{let p=t(u);const f=be(p,h);if(!f){const d={channelCount:p.channelCount,channelCountMode:p.channelCountMode,channelInterpretation:p.channelInterpretation,detune:p.detune.value,frequency:p.frequency.value,periodicWave:o===null?void 0:o,type:p.type};p=e(h,d),a!==null&&p.start(a),c!==null&&p.stop(c)}return r.set(h,p),f?(await s(h,u.detune,p.detune),await s(h,u.frequency,p.frequency)):(await n(h,u.detune,p.detune),await n(h,u.frequency,p.frequency)),await i(u,h,p),p};return{set periodicWave(u){o=u},set start(u){a=u},set stop(u){c=u},render(u,h){const p=r.get(h);return p!==void 0?Promise.resolve(p):l(u,h)}}},fl={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},ml=(s,e,t,n,i,r,o)=>class extends s{constructor(c,l){const u=i(c),h={...fl,...l},p=t(u,h),f=r(u),d=f?n():null;super(c,!1,p,d),this._nativePannerNode=p,this._orientationX=e(this,f,p.orientationX,Ae,Ne),this._orientationY=e(this,f,p.orientationY,Ae,Ne),this._orientationZ=e(this,f,p.orientationZ,Ae,Ne),this._positionX=e(this,f,p.positionX,Ae,Ne),this._positionY=e(this,f,p.positionY,Ae,Ne),this._positionZ=e(this,f,p.positionZ,Ae,Ne),o(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}},gl=(s,e,t,n,i,r,o,a,c,l)=>()=>{const u=new WeakMap;let h=null;const p=async(f,d)=>{let g=null,_=r(f);const y={channelCount:_.channelCount,channelCountMode:_.channelCountMode,channelInterpretation:_.channelInterpretation},C={...y,coneInnerAngle:_.coneInnerAngle,coneOuterAngle:_.coneOuterAngle,coneOuterGain:_.coneOuterGain,distanceModel:_.distanceModel,maxDistance:_.maxDistance,panningModel:_.panningModel,refDistance:_.refDistance,rolloffFactor:_.rolloffFactor},S=be(_,d);if("bufferSize"in _)g=n(d,{...y,gain:1});else if(!S){const k={...C,orientationX:_.orientationX.value,orientationY:_.orientationY.value,orientationZ:_.orientationZ.value,positionX:_.positionX.value,positionY:_.positionY.value,positionZ:_.positionZ.value};_=i(d,k)}if(u.set(d,g===null?_:g),g!==null){if(h===null){if(o===null)throw new Error("Missing the native OfflineAudioContext constructor.");const x=new o(6,f.context.length,d.sampleRate),A=e(x,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6});A.connect(x.destination),h=(async()=>{const M=await Promise.all([f.orientationX,f.orientationY,f.orientationZ,f.positionX,f.positionY,f.positionZ].map(async(D,F)=>{const R=t(x,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:F===0?1:0});return await a(x,D,R.offset),R}));for(let D=0;D<6;D+=1)M[D].connect(A,0,D),M[D].start(0);return l(x)})()}const k=await h,m=n(d,{...y,gain:1});await c(f,d,m);const w=[];for(let x=0;x<k.numberOfChannels;x+=1)w.push(k.getChannelData(x));let b=[w[0][0],w[1][0],w[2][0]],v=[w[3][0],w[4][0],w[5][0]],O=n(d,{...y,gain:1}),N=i(d,{...C,orientationX:b[0],orientationY:b[1],orientationZ:b[2],positionX:v[0],positionY:v[1],positionZ:v[2]});m.connect(O).connect(N.inputs[0]),N.connect(g);for(let x=128;x<k.length;x+=128){const A=[w[0][x],w[1][x],w[2][x]],M=[w[3][x],w[4][x],w[5][x]];if(A.some((D,F)=>D!==b[F])||M.some((D,F)=>D!==v[F])){b=A,v=M;const D=x/d.sampleRate;O.gain.setValueAtTime(0,D),O=n(d,{...y,gain:0}),N=i(d,{...C,orientationX:b[0],orientationY:b[1],orientationZ:b[2],positionX:v[0],positionY:v[1],positionZ:v[2]}),O.gain.setValueAtTime(1,D),m.connect(O).connect(N.inputs[0]),N.connect(g)}}return g}return S?(await s(d,f.orientationX,_.orientationX),await s(d,f.orientationY,_.orientationY),await s(d,f.orientationZ,_.orientationZ),await s(d,f.positionX,_.positionX),await s(d,f.positionY,_.positionY),await s(d,f.positionZ,_.positionZ)):(await a(d,f.orientationX,_.orientationX),await a(d,f.orientationY,_.orientationY),await a(d,f.orientationZ,_.orientationZ),await a(d,f.positionX,_.positionX),await a(d,f.positionY,_.positionY),await a(d,f.positionZ,_.positionZ)),Kt(_)?await c(f,d,_.inputs[0]):await c(f,d,_),_};return{render(f,d){const g=u.get(d);return g!==void 0?Promise.resolve(g):p(f,d)}}},_l={disableNormalization:!1},yl=(s,e,t,n)=>class rr{constructor(r,o){const a=e(r),c=n({..._l,...o}),l=s(a,c);return t.add(l),l}static[Symbol.hasInstance](r){return r!==null&&typeof r=="object"&&Object.getPrototypeOf(r)===rr.prototype||t.has(r)}},vl=(s,e)=>(t,n,i)=>(s(n).replay(i),e(n,t,i)),Tl=(s,e,t)=>async(n,i,r)=>{const o=s(n);await Promise.all(o.activeInputs.map((a,c)=>Array.from(a).map(async([l,u])=>{const p=await e(l).render(l,i),f=n.context.destination;!t(l)&&(n!==f||!t(n))&&p.connect(r,u,c)})).reduce((a,c)=>[...a,...c],[]))},wl=(s,e,t)=>async(n,i,r)=>{const o=e(n);await Promise.all(Array.from(o.activeInputs).map(async([a,c])=>{const u=await s(a).render(a,i);t(a)||u.connect(r,c)}))},bl=(s,e,t,n)=>i=>s(an,()=>an(i))?Promise.resolve(s(n,n)).then(r=>{if(!r){const o=t(i,512,0,1);i.oncomplete=()=>{o.onaudioprocess=null,o.disconnect()},o.onaudioprocess=()=>i.currentTime,o.connect(i.destination)}return i.startRendering()}):new Promise(r=>{const o=e(i,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});i.oncomplete=a=>{o.disconnect(),r(a.renderedBuffer)},o.connect(i.destination),i.startRendering()}),Cl=s=>(e,t)=>{s.set(e,t)},Sl=s=>(e,t)=>s.set(e,t),Al=(s,e,t,n,i,r,o,a)=>(c,l)=>t(c).render(c,l).then(()=>Promise.all(Array.from(n(l)).map(u=>t(u).render(u,l)))).then(()=>i(l)).then(u=>(typeof u.copyFromChannel!="function"?(o(u),qs(u)):e(r,()=>r(u))||a(u),s.add(u),u)),kl={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},xl=(s,e,t,n,i,r)=>class extends s{constructor(a,c){const l=i(a),u={...kl,...c},h=t(l,u),p=r(l),f=p?n():null;super(a,!1,h,f),this._pan=e(this,p,h.pan)}get pan(){return this._pan}},Nl=(s,e,t,n,i)=>()=>{const r=new WeakMap,o=async(a,c)=>{let l=t(a);const u=be(l,c);if(!u){const h={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,pan:l.pan.value};l=e(c,h)}return r.set(c,l),u?await s(c,a.pan,l.pan):await n(c,a.pan,l.pan),Kt(l)?await i(a,c,l.inputs[0]):await i(a,c,l),l};return{render(a,c){const l=r.get(c);return l!==void 0?Promise.resolve(l):o(a,c)}}},Ol=s=>()=>{if(s===null)return!1;try{new s({length:1,sampleRate:44100})}catch{return!1}return!0},El=(s,e)=>async()=>{if(s===null)return!0;if(e===null)return!1;const t=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"}),n=new e(1,128,44100),i=URL.createObjectURL(t);let r=!1,o=!1;try{await n.audioWorklet.addModule(i);const a=new s(n,"a",{numberOfOutputs:0}),c=n.createOscillator();a.port.onmessage=()=>r=!0,a.onprocessorerror=()=>o=!0,c.connect(a),c.start(0),await n.startRendering(),await new Promise(l=>setTimeout(l))}catch{}finally{URL.revokeObjectURL(i)}return r&&!o},Ml=(s,e)=>()=>{if(e===null)return Promise.resolve(!1);const t=new e(1,1,44100),n=s(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return new Promise(i=>{t.oncomplete=()=>{n.disconnect(),i(t.currentTime!==0)},t.startRendering()})},Il=()=>new DOMException("","UnknownError"),Dl={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},Rl=(s,e,t,n,i,r,o)=>class extends s{constructor(c,l){const u=i(c),h={...Dl,...l},p=t(u,h),d=r(u)?n():null;super(c,!0,p,d),this._isCurveNullified=!1,this._nativeWaveShaperNode=p,o(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 e();this._isCurveNullified=!1,this._nativeWaveShaperNode.curve=c}}get oversample(){return this._nativeWaveShaperNode.oversample}set oversample(c){this._nativeWaveShaperNode.oversample=c}},Pl=(s,e,t)=>()=>{const n=new WeakMap,i=async(r,o)=>{let a=e(r);if(!be(a,o)){const l={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,curve:a.curve,oversample:a.oversample};a=s(o,l)}return n.set(o,a),Kt(a)?await t(r,o,a.inputs[0]):await t(r,o,a),a};return{render(r,o){const a=n.get(o);return a!==void 0?Promise.resolve(a):i(r,o)}}},Vl=()=>typeof window>"u"?null:window,Fl=(s,e)=>t=>{t.copyFromChannel=(n,i,r=0)=>{const o=s(r),a=s(i);if(a>=t.numberOfChannels)throw e();const c=t.length,l=t.getChannelData(a),u=n.length;for(let h=o<0?-o:0;h+o<c&&h<u;h+=1)n[h]=l[h+o]},t.copyToChannel=(n,i,r=0)=>{const o=s(r),a=s(i);if(a>=t.numberOfChannels)throw e();const c=t.length,l=t.getChannelData(a),u=n.length;for(let h=o<0?-o:0;h+o<c&&h<u;h+=1)l[h+o]=n[h]}},Ll=s=>e=>{e.copyFromChannel=(t=>(n,i,r=0)=>{const o=s(r),a=s(i);if(o<e.length)return t.call(e,n,a,o)})(e.copyFromChannel),e.copyToChannel=(t=>(n,i,r=0)=>{const o=s(r),a=s(i);if(o<e.length)return t.call(e,n,a,o)})(e.copyToChannel)},ql=s=>(e,t)=>{const n=t.createBuffer(1,1,44100);e.buffer===null&&(e.buffer=n),s(e,"buffer",i=>()=>{const r=i.call(e);return r===n?null:r},i=>r=>i.call(e,r===null?n:r))},Wl=(s,e)=>(t,n)=>{n.channelCount=1,n.channelCountMode="explicit",Object.defineProperty(n,"channelCount",{get:()=>1,set:()=>{throw s()}}),Object.defineProperty(n,"channelCountMode",{get:()=>"explicit",set:()=>{throw s()}});const i=t.createBufferSource();e(n,()=>{const a=n.numberOfInputs;for(let c=0;c<a;c+=1)i.connect(n,0,c)},()=>i.disconnect(n))},or=(s,e,t)=>s.copyFromChannel===void 0?s.getChannelData(t)[0]:(s.copyFromChannel(e,t),e[0]),ar=s=>{if(s===null)return!1;const e=s.length;return e%2!==0?s[Math.floor(e/2)]!==0:s[e/2-1]+s[e/2]!==0},kn=(s,e,t,n)=>{let i=s;for(;!i.hasOwnProperty(e);)i=Object.getPrototypeOf(i);const{get:r,set:o}=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(s,e,{get:t(r),set:n(o)})},jl=s=>({...s,outputChannelCount:s.outputChannelCount!==void 0?s.outputChannelCount:s.numberOfInputs===1&&s.numberOfOutputs===1?[s.channelCount]:Array.from({length:s.numberOfOutputs},()=>1)}),Bl=s=>({...s,channelCount:s.numberOfOutputs}),Ul=s=>{const{imag:e,real:t}=s;return e===void 0?t===void 0?{...s,imag:[0,0],real:[0,0]}:{...s,imag:Array.from(t,()=>0),real:t}:t===void 0?{...s,imag:e,real:Array.from(e,()=>0)}:{...s,imag:e,real:t}},cr=(s,e,t)=>{try{s.setValueAtTime(e,t)}catch(n){if(n.code!==9)throw n;cr(s,e,t+1e-7)}},zl=s=>{const e=s.createBufferSource();e.start();try{e.start()}catch{return!0}return!1},Gl=s=>{const e=s.createBufferSource(),t=s.createBuffer(1,1,44100);e.buffer=t;try{e.start(0,1)}catch{return!1}return!0},Yl=s=>{const e=s.createBufferSource();e.start();try{e.stop()}catch{return!1}return!0},zs=s=>{const e=s.createOscillator();try{e.start(-1)}catch(t){return t instanceof RangeError}return!1},lr=s=>{const e=s.createBuffer(1,1,44100),t=s.createBufferSource();t.buffer=e,t.start(),t.stop();try{return t.stop(),!0}catch{return!1}},Gs=s=>{const e=s.createOscillator();try{e.stop(-1)}catch(t){return t instanceof RangeError}return!1},Zl=s=>{const{port1:e,port2:t}=new MessageChannel;try{e.postMessage(s)}finally{e.close(),t.close()}},$l=s=>{s.start=(e=>(t=0,n=0,i)=>{const r=s.buffer,o=r===null?n:Math.min(r.duration,n);r!==null&&o>r.duration-.5/s.context.sampleRate?e.call(s,t,0,0):e.call(s,t,o,i)})(s.start)},ur=(s,e)=>{const t=e.createGain();s.connect(t);const n=(i=>()=>{i.call(s,t),s.removeEventListener("ended",n)})(s.disconnect);s.addEventListener("ended",n),Jt(s,t),s.stop=(i=>{let r=!1;return(o=0)=>{if(r)try{i.call(s,o)}catch{t.gain.setValueAtTime(0,o)}else i.call(s,o),r=!0}})(s.stop)},en=(s,e)=>t=>{const n={value:s};return Object.defineProperties(t,{currentTarget:n,target:n}),typeof e=="function"?e.call(s,t):e.handleEvent.call(s,t)},Xl=mo(Et),Hl=wo(Et),Ql=Da(ls),hr=new WeakMap,Kl=Qa(hr),Ue=la(new Map,new WeakMap),$e=Vl(),dr=xc(Ue,Xe),Ys=Ha(ke),Te=Tl(ke,Ys,kt),Jl=ko(dr,se,Te),J=ec(cs),ot=el($e),Q=_c(ot),pr=new WeakMap,fr=Ua(en),xn=Mc($e),Zs=pc(xn),$s=fc($e),mr=mc($e),cn=Dc($e),he=Qo(go(Bi),To(Xl,Hl,Gn,Ql,Yn,ke,Kl,Tn,se,Et,nt,kt,qn),Ue,cc(Ns,Yn,ke,se,on,nt),Xe,us,xe,Oa(Gn,Ns,ke,se,on,J,nt,Q),Va(pr,ke,je),fr,J,Zs,$s,mr,Q,cn),eu=Ao(he,Jl,Xe,dr,J,Q),Xs=new WeakSet,Ii=Nc($e),gr=ba(new Uint32Array(1)),Hs=Fl(gr,Xe),Qs=Ll(gr),_r=No(Xs,Ue,xe,Ii,ot,Ol(Ii),Hs,Qs),hs=bo(Ee),yr=wl(Ys,bn,kt),He=ga(yr),tn=Ec(hs,Ue,zl,Gl,Yl,zs,lr,Gs,$l,ql(kn),ur),Qe=vl(Ka(bn),yr),tu=Mo(He,tn,se,Qe,Te),ze=Ko(_o(Ui),pr,Ls,Jo,co,lo,uo,ho,po,As,qi,xn,cr),nu=Eo(he,tu,ze,ge,tn,J,Q,en),su=Wo(he,jo,Xe,ge,Ic(Ee,kn),J,Q,Te),iu=ca(He,sr,se,Qe,Te),Mt=Sl(hr),ru=aa(he,ze,iu,us,sr,J,Q,Mt),yt=Ac(Et,$s),ou=Wl(ge,yt),vt=Wc(xn,ou),au=da(vt,se,Te),cu=ha(he,au,vt,J,Q),lu=ma(Sn,se,Te),uu=fa(he,lu,Sn,J,Q,Bl),hu=Uc(hs,tn,Ee,yt),nn=Bc(hs,Ue,hu,zs,Gs),du=wa(He,nn,se,Qe,Te),pu=Ta(he,ze,du,nn,J,Q,en),vr=zc(xe,kn),fu=Aa(vr,se,Te),mu=Sa(he,fu,vr,J,Q,Mt),gu=Ia(He,ir,se,Qe,Te),_u=Ma(he,ze,gu,ir,J,Q,Mt),Tr=Gc(xe),yu=Wa(He,Tr,se,Qe,Te),vu=qa(he,ze,yu,Tr,xe,J,Q,Mt),Tu=$a(He,Ee,se,Qe,Te),wu=Za(he,ze,Tu,Ee,J,Q),bu=Xc(us,ge,An,xe),ds=bl(Ue,Ee,An,Ml(Ee,ot)),Cu=ac(tn,se,ot,Te,ds),Su=Yc(bu),Au=rc(he,Su,Cu,J,Q,Mt),ku=Bo(ze,vt,nn,An,xe,or,Q,kn),wr=new WeakMap,xu=Sc(su,ku,fr,Q,wr,en),br=tl(hs,Ue,zs,lr,Gs,ur),Nu=pl(He,br,se,Qe,Te),Ou=dl(he,ze,br,Nu,J,Q,en),Cr=ya(tn),Eu=cl(Cr,ge,Ee,ar,yt),ps=al(Cr,ge,Eu,ar,yt,xn,kn),Mu=sl(Gn,ge,vt,Ee,An,ps,xe,Yn,or,yt),Sr=nl(Mu),Iu=gl(He,vt,nn,Ee,Sr,se,ot,Qe,Te,ds),Du=ml(he,ze,Sr,Iu,J,Q,Mt),Ru=il(Xe),Pu=yl(Ru,J,new WeakSet,Ul),Vu=ol(vt,Sn,Ee,ps,xe,yt),Ar=rl(Vu,xe),Fu=Nl(He,Ar,se,Qe,Te),Lu=xl(he,ze,Ar,Fu,J,Q),qu=Pl(ps,se,Te),Wu=Rl(he,ge,ps,qu,J,Q,Mt),kr=yc($e),Ks=za($e),xr=new WeakMap,ju=tc(xr,ot),Bu=kr?vo(Ue,xe,Ba($e),Ks,Ga(fo),J,ju,Q,cn,new WeakMap,new WeakMap,El(cn,ot),$e):void 0,Uu=gc(Zs,Q),zu=Na(Xs,Ue,xa,ja,new WeakSet,J,Uu,Un,an,Hs,Qs),Nr=ra(Bu,eu,_r,nu,ru,cu,uu,pu,mu,zu,_u,vu,wu,Au,xu,Ou,Du,Pu,Lu,Wu),Gu=vc(he,Hc,J,Q),Yu=wc(he,Qc,J,Q),Zu=bc(he,Kc,J,Q),$u=Jc(ge,Q),Xu=Cc(he,$u,J),Hu=qo(Nr,ge,xe,Il,Gu,Yu,Zu,Xu,xn),Js=nc(wr),Qu=Co(Js),Or=_a(Xe),Ku=Ra(Js),Er=Fa(Xe),Mr=new WeakMap,Ju=Xa(Mr,je),eh=qc(Or,Xe,ge,vt,Sn,nn,Ee,An,xe,Er,Ks,Ju,yt),th=Pc(ge,eh,Ee,xe,yt),nh=ia(He,Or,tn,vt,Sn,nn,Ee,Ku,Er,Ks,se,cn,ot,Qe,Te,ds),sh=Ja(xr),ih=Cl(Mr),Di=kr?ta(Qu,he,ze,nh,th,ke,sh,J,Q,cn,jl,ih,Zl,en):void 0,rh=ka(xe,ot),oh=Al(Xs,Ue,Ys,Js,ds,Un,Hs,Qs),ah=ul(Nr,Ue,ge,rh,oh),ch=lc(cs,Zs),lh=uc(Fs,$s),uh=hc(Ls,mr),hh=dc(cs,Q);function Re(s){return s===void 0}function Z(s){return s!==void 0}function dh(s){return typeof s=="function"}function ft(s){return typeof s=="number"}function Ct(s){return Object.prototype.toString.call(s)==="[object Object]"&&s.constructor===Object}function ph(s){return typeof s=="boolean"}function Ie(s){return Array.isArray(s)}function st(s){return typeof s=="string"}function Vn(s){return st(s)&&/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i.test(s)}function B(s,e){if(!s)throw new Error(e)}function mt(s,e,t=1/0){if(!(e<=s&&s<=t))throw new RangeError(`Value must be within [${e}, ${t}], got: ${s}`)}function Ir(s){!s.isOffline&&s.state!=="running"&&fs('The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.')}let Dr=!1,Ri=!1;function Pi(s){Dr=s}function fh(s){Re(s)&&Dr&&!Ri&&(Ri=!0,fs("Events scheduled inside of scheduled callbacks should use the passed in scheduling time. See https://github.com/Tonejs/Tone.js/wiki/Accurate-Timing"))}let Rr=console;function mh(...s){Rr.log(...s)}function fs(...s){Rr.warn(...s)}function gh(s){return new Hu(s)}function _h(s,e,t){return new ah(s,e,t)}const St=typeof self=="object"?self:null,yh=St&&(St.hasOwnProperty("AudioContext")||St.hasOwnProperty("webkitAudioContext"));function vh(s,e,t){return B(Z(Di),"This node only works in a secure context (https or localhost)"),new Di(s,e,t)}class Th{constructor(e,t,n,i){this._callback=e,this._type=t,this._minimumUpdateInterval=Math.max(128/(i||44100),.001),this.updateInterval=n,this._createClock()}_createWorker(){const e=new Blob([`
|
|
// the initial timeout time
|
|
let timeoutTime = ${(this._updateInterval*1e3).toFixed(1)};
|
|
// onmessage callback
|
|
self.onmessage = function(msg){
|
|
timeoutTime = parseInt(msg.data);
|
|
};
|
|
// the tick function which posts a message
|
|
// and schedules a new tick
|
|
function tick(){
|
|
setTimeout(tick, timeoutTime);
|
|
self.postMessage('tick');
|
|
}
|
|
// call tick initially
|
|
tick();
|
|
`],{type:"text/javascript"}),t=URL.createObjectURL(e),n=new Worker(t);n.onmessage=this._callback.bind(this),this._worker=n}_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(e){var t;this._updateInterval=Math.max(e,this._minimumUpdateInterval),this._type==="worker"&&((t=this._worker)===null||t===void 0||t.postMessage(this._updateInterval*1e3))}get type(){return this._type}set type(e){this._disposeClock(),this._type=e,this._createClock()}dispose(){this._disposeClock()}}function xt(s){return uh(s)}function pt(s){return lh(s)}function Wn(s){return hh(s)}function Lt(s){return ch(s)}function wh(s){return s instanceof _r}function bh(s,e){return s==="value"||xt(e)||pt(e)||wh(e)}function At(s,...e){if(!e.length)return s;const t=e.shift();if(Ct(s)&&Ct(t))for(const n in t)bh(n,t[n])?s[n]=t[n]:Ct(t[n])?(s[n]||Object.assign(s,{[n]:{}}),At(s[n],t[n])):Object.assign(s,{[n]:t[n]});return At(s,...e)}function Ch(s,e){return s.length===e.length&&s.every((t,n)=>e[n]===t)}function E(s,e,t=[],n){const i={},r=Array.from(e);if(Ct(r[0])&&n&&!Reflect.has(r[0],n)&&(Object.keys(r[0]).some(a=>Reflect.has(s,a))||(At(i,{[n]:r[0]}),t.splice(t.indexOf(n),1),r.shift())),r.length===1&&Ct(r[0]))At(i,r[0]);else for(let o=0;o<t.length;o++)Z(r[o])&&(i[t[o]]=r[o]);return At(s,i)}function Sh(s){return s.constructor.getDefaults()}function Bt(s,e){return Re(s)?e:s}function Ds(s,e){return e.forEach(t=>{Reflect.has(s,t)&&delete s[t]}),s}/**
|
|
* Tone.js
|
|
* @author Yotam Mann
|
|
* @license http://opensource.org/licenses/MIT MIT License
|
|
* @copyright 2014-2019 Yotam Mann
|
|
*/class at{constructor(){this.debug=!1,this._wasDisposed=!1}static getDefaults(){return{}}log(...e){(this.debug||St&&this.toString()===St.TONE_DEBUG_CLASS)&&mh(this,...e)}dispose(){return this._wasDisposed=!0,this}get disposed(){return this._wasDisposed}toString(){return this.name}}at.version=Li;const ei=1e-6;function Gt(s,e){return s>e+ei}function Rs(s,e){return Gt(s,e)||Le(s,e)}function Hn(s,e){return s+ei<e}function Le(s,e){return Math.abs(s-e)<ei}function Ah(s,e,t){return Math.max(Math.min(s,t),e)}class Pe extends at{constructor(){super(),this.name="Timeline",this._timeline=[];const e=E(Pe.getDefaults(),arguments,["memory"]);this.memory=e.memory,this.increasing=e.increasing}static getDefaults(){return{memory:1/0,increasing:!1}}get length(){return this._timeline.length}add(e){if(B(Reflect.has(e,"time"),"Timeline: events must have a time attribute"),e.time=e.time.valueOf(),this.increasing&&this.length){const t=this._timeline[this.length-1];B(Rs(e.time,t.time),"The time must be greater than or equal to the last scheduled time"),this._timeline.push(e)}else{const t=this._search(e.time);this._timeline.splice(t+1,0,e)}if(this.length>this.memory){const t=this.length-this.memory;this._timeline.splice(0,t)}return this}remove(e){const t=this._timeline.indexOf(e);return t!==-1&&this._timeline.splice(t,1),this}get(e,t="time"){const n=this._search(e,t);return n!==-1?this._timeline[n]:null}peek(){return this._timeline[0]}shift(){return this._timeline.shift()}getAfter(e,t="time"){const n=this._search(e,t);return n+1<this._timeline.length?this._timeline[n+1]:null}getBefore(e){const t=this._timeline.length;if(t>0&&this._timeline[t-1].time<e)return this._timeline[t-1];const n=this._search(e);return n-1>=0?this._timeline[n-1]:null}cancel(e){if(this._timeline.length>1){let t=this._search(e);if(t>=0)if(Le(this._timeline[t].time,e)){for(let n=t;n>=0&&Le(this._timeline[n].time,e);n--)t=n;this._timeline=this._timeline.slice(0,t)}else this._timeline=this._timeline.slice(0,t+1);else this._timeline=[]}else this._timeline.length===1&&Rs(this._timeline[0].time,e)&&(this._timeline=[]);return this}cancelBefore(e){const t=this._search(e);return t>=0&&(this._timeline=this._timeline.slice(t+1)),this}previousEvent(e){const t=this._timeline.indexOf(e);return t>0?this._timeline[t-1]:null}_search(e,t="time"){if(this._timeline.length===0)return-1;let n=0;const i=this._timeline.length;let r=i;if(i>0&&this._timeline[i-1][t]<=e)return i-1;for(;n<r;){let o=Math.floor(n+(r-n)/2);const a=this._timeline[o],c=this._timeline[o+1];if(Le(a[t],e)){for(let l=o;l<this._timeline.length;l++){const u=this._timeline[l];if(Le(u[t],e))o=l;else break}return o}else{if(Hn(a[t],e)&&Gt(c[t],e))return o;Gt(a[t],e)?r=o:n=o+1}}return-1}_iterate(e,t=0,n=this._timeline.length-1){this._timeline.slice(t,n+1).forEach(e)}forEach(e){return this._iterate(e),this}forEachBefore(e,t){const n=this._search(e);return n!==-1&&this._iterate(t,0,n),this}forEachAfter(e,t){const n=this._search(e);return this._iterate(t,n+1),this}forEachBetween(e,t,n){let i=this._search(e),r=this._search(t);return i!==-1&&r!==-1?(this._timeline[i].time!==e&&(i+=1),this._timeline[r].time===t&&(r-=1),this._iterate(n,i,r)):i===-1&&this._iterate(n,0,r),this}forEachFrom(e,t){let n=this._search(e);for(;n>=0&&this._timeline[n].time>=e;)n--;return this._iterate(t,n+1),this}forEachAtTime(e,t){const n=this._search(e);if(n!==-1&&Le(this._timeline[n].time,e)){let i=n;for(let r=n;r>=0&&Le(this._timeline[r].time,e);r--)i=r;this._iterate(r=>{t(r)},i,n)}return this}dispose(){return super.dispose(),this._timeline=[],this}}const Pr=[];function ms(s){Pr.push(s)}function kh(s){Pr.forEach(e=>e(s))}const Vr=[];function gs(s){Vr.push(s)}function xh(s){Vr.forEach(e=>e(s))}class Nn extends at{constructor(){super(...arguments),this.name="Emitter"}on(e,t){return e.split(/\W+/).forEach(i=>{Re(this._events)&&(this._events={}),this._events.hasOwnProperty(i)||(this._events[i]=[]),this._events[i].push(t)}),this}once(e,t){const n=(...i)=>{t(...i),this.off(e,n)};return this.on(e,n),this}off(e,t){return e.split(/\W+/).forEach(i=>{if(Re(this._events)&&(this._events={}),this._events.hasOwnProperty(i))if(Re(t))this._events[i]=[];else{const r=this._events[i];for(let o=r.length-1;o>=0;o--)r[o]===t&&r.splice(o,1)}}),this}emit(e,...t){if(this._events&&this._events.hasOwnProperty(e)){const n=this._events[e].slice(0);for(let i=0,r=n.length;i<r;i++)n[i].apply(this,t)}return this}static mixin(e){["on","once","off","emit"].forEach(t=>{const n=Object.getOwnPropertyDescriptor(Nn.prototype,t);Object.defineProperty(e.prototype,t,n)})}dispose(){return super.dispose(),this._events=void 0,this}}class Fr extends Nn{constructor(){super(...arguments),this.isOffline=!1}toJSON(){return{}}}class On extends Fr{constructor(){var e,t;super(),this.name="Context",this._constants=new Map,this._timeouts=new Pe,this._timeoutIds=0,this._initialized=!1,this._closeStarted=!1,this.isOffline=!1,this._workletPromise=null;const n=E(On.getDefaults(),arguments,["context"]);n.context?(this._context=n.context,this._latencyHint=((e=arguments[0])===null||e===void 0?void 0:e.latencyHint)||""):(this._context=gh({latencyHint:n.latencyHint}),this._latencyHint=n.latencyHint),this._ticker=new Th(this.emit.bind(this,"tick"),n.clockSource,n.updateInterval,this._context.sampleRate),this.on("tick",this._timeoutLoop.bind(this)),this._context.onstatechange=()=>{this.emit("statechange",this.state)},this[!((t=arguments[0])===null||t===void 0)&&t.hasOwnProperty("updateInterval")?"_lookAhead":"lookAhead"]=n.lookAhead}static getDefaults(){return{clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.05}}initialize(){return this._initialized||(kh(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(e,t,n){return this._context.createBuffer(e,t,n)}createChannelMerger(e){return this._context.createChannelMerger(e)}createChannelSplitter(e){return this._context.createChannelSplitter(e)}createConstantSource(){return this._context.createConstantSource()}createConvolver(){return this._context.createConvolver()}createDelay(e){return this._context.createDelay(e)}createDynamicsCompressor(){return this._context.createDynamicsCompressor()}createGain(){return this._context.createGain()}createIIRFilter(e,t){return this._context.createIIRFilter(e,t)}createPanner(){return this._context.createPanner()}createPeriodicWave(e,t,n){return this._context.createPeriodicWave(e,t,n)}createStereoPanner(){return this._context.createStereoPanner()}createWaveShaper(){return this._context.createWaveShaper()}createMediaStreamSource(e){return B(Lt(this._context),"Not available if OfflineAudioContext"),this._context.createMediaStreamSource(e)}createMediaElementSource(e){return B(Lt(this._context),"Not available if OfflineAudioContext"),this._context.createMediaElementSource(e)}createMediaStreamDestination(){return B(Lt(this._context),"Not available if OfflineAudioContext"),this._context.createMediaStreamDestination()}decodeAudioData(e){return this._context.decodeAudioData(e)}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(e){B(!this._initialized,"The listener cannot be set after initialization."),this._listener=e}get transport(){return this.initialize(),this._transport}set transport(e){B(!this._initialized,"The transport cannot be set after initialization."),this._transport=e}get draw(){return this.initialize(),this._draw}set draw(e){B(!this._initialized,"Draw cannot be set after initialization."),this._draw=e}get destination(){return this.initialize(),this._destination}set destination(e){B(!this._initialized,"The destination cannot be set after initialization."),this._destination=e}createAudioWorkletNode(e,t){return vh(this.rawContext,e,t)}addAudioWorkletModule(e){return de(this,void 0,void 0,function*(){B(Z(this.rawContext.audioWorklet),"AudioWorkletNode is only available in a secure context (https or localhost)"),this._workletPromise||(this._workletPromise=this.rawContext.audioWorklet.addModule(e)),yield this._workletPromise})}workletsAreReady(){return de(this,void 0,void 0,function*(){(yield this._workletPromise)?this._workletPromise:Promise.resolve()})}get updateInterval(){return this._ticker.updateInterval}set updateInterval(e){this._ticker.updateInterval=e}get clockSource(){return this._ticker.type}set clockSource(e){this._ticker.type=e}get lookAhead(){return this._lookAhead}set lookAhead(e){this._lookAhead=e,this.updateInterval=e?e/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 Lt(this._context)?this._context.resume():Promise.resolve()}close(){return de(this,void 0,void 0,function*(){Lt(this._context)&&this.state!=="closed"&&!this._closeStarted&&(this._closeStarted=!0,yield this._context.close()),this._initialized&&xh(this)})}getConstant(e){if(this._constants.has(e))return this._constants.get(e);{const t=this._context.createBuffer(1,128,this._context.sampleRate),n=t.getChannelData(0);for(let r=0;r<n.length;r++)n[r]=e;const i=this._context.createBufferSource();return i.channelCount=1,i.channelCountMode="explicit",i.buffer=t,i.loop=!0,i.start(0),this._constants.set(e,i),i}}dispose(){return super.dispose(),this._ticker.dispose(),this._timeouts.dispose(),Object.keys(this._constants).map(e=>this._constants[e].disconnect()),this.close(),this}_timeoutLoop(){const e=this.now();let t=this._timeouts.peek();for(;this._timeouts.length&&t&&t.time<=e;)t.callback(),this._timeouts.shift(),t=this._timeouts.peek()}setTimeout(e,t){this._timeoutIds++;const n=this.now();return this._timeouts.add({callback:e,id:this._timeoutIds,time:n+t}),this._timeoutIds}clearTimeout(e){return this._timeouts.forEach(t=>{t.id===e&&this._timeouts.remove(t)}),this}clearInterval(e){return this.clearTimeout(e)}setInterval(e,t){const n=++this._timeoutIds,i=()=>{const r=this.now();this._timeouts.add({callback:()=>{e(),i()},id:n,time:r+t})};return i(),n}}class Nh extends Fr{constructor(){super(...arguments),this.lookAhead=0,this.latencyHint=0,this.isOffline=!1}createAnalyser(){return{}}createOscillator(){return{}}createBufferSource(){return{}}createBiquadFilter(){return{}}createBuffer(e,t,n){return{}}createChannelMerger(e){return{}}createChannelSplitter(e){return{}}createConstantSource(){return{}}createConvolver(){return{}}createDelay(e){return{}}createDynamicsCompressor(){return{}}createGain(){return{}}createIIRFilter(e,t){return{}}createPanner(){return{}}createPeriodicWave(e,t,n){return{}}createStereoPanner(){return{}}createWaveShaper(){return{}}createMediaStreamSource(e){return{}}createMediaElementSource(e){return{}}createMediaStreamDestination(){return{}}decodeAudioData(e){return Promise.resolve({})}createAudioWorkletNode(e,t){return{}}get rawContext(){return{}}addAudioWorkletModule(e){return de(this,void 0,void 0,function*(){return Promise.resolve()})}resume(){return Promise.resolve()}setTimeout(e,t){return 0}clearTimeout(e){return this}setInterval(e,t){return 0}clearInterval(e){return this}getConstant(e){return{}}get currentTime(){return 0}get state(){return{}}get sampleRate(){return 0}get listener(){return{}}get transport(){return{}}get draw(){return{}}set draw(e){}get destination(){return{}}set destination(e){}now(){return 0}immediate(){return 0}}function ce(s,e){Ie(e)?e.forEach(t=>ce(s,t)):Object.defineProperty(s,e,{enumerable:!0,writable:!1})}function Lr(s,e){Ie(e)?e.forEach(t=>Lr(s,t)):Object.defineProperty(s,e,{writable:!0})}const H=()=>{};class ne extends at{constructor(){super(),this.name="ToneAudioBuffer",this.onload=H;const e=E(ne.getDefaults(),arguments,["url","onload","onerror"]);this.reverse=e.reverse,this.onload=e.onload,st(e.url)?this.load(e.url).catch(e.onerror):e.url&&this.set(e.url)}static getDefaults(){return{onerror:H,onload:H,reverse:!1}}get sampleRate(){return this._buffer?this._buffer.sampleRate:qe().sampleRate}set(e){return e instanceof ne?e.loaded?this._buffer=e.get():e.onload=()=>{this.set(e),this.onload(this)}:this._buffer=e,this._reversed&&this._reverse(),this}get(){return this._buffer}load(e){return de(this,void 0,void 0,function*(){const t=ne.load(e).then(n=>{this.set(n),this.onload(this)});ne.downloads.push(t);try{yield t}finally{const n=ne.downloads.indexOf(t);ne.downloads.splice(n,1)}return this})}dispose(){return super.dispose(),this._buffer=void 0,this}fromArray(e){const t=Ie(e)&&e[0].length>0,n=t?e.length:1,i=t?e[0].length:e.length,r=qe(),o=r.createBuffer(n,i,r.sampleRate),a=!t&&n===1?[e]:e;for(let c=0;c<n;c++)o.copyToChannel(a[c],c);return this._buffer=o,this}toMono(e){if(ft(e))this.fromArray(this.toArray(e));else{let t=new Float32Array(this.length);const n=this.numberOfChannels;for(let i=0;i<n;i++){const r=this.toArray(i);for(let o=0;o<r.length;o++)t[o]+=r[o]}t=t.map(i=>i/n),this.fromArray(t)}return this}toArray(e){if(ft(e))return this.getChannelData(e);if(this.numberOfChannels===1)return this.toArray(0);{const t=[];for(let n=0;n<this.numberOfChannels;n++)t[n]=this.getChannelData(n);return t}}getChannelData(e){return this._buffer?this._buffer.getChannelData(e):new Float32Array(0)}slice(e,t=this.duration){B(this.loaded,"Buffer is not loaded");const n=Math.floor(e*this.sampleRate),i=Math.floor(t*this.sampleRate);B(n<i,"The start time must be less than the end time");const r=i-n,o=qe().createBuffer(this.numberOfChannels,r,this.sampleRate);for(let a=0;a<this.numberOfChannels;a++)o.copyToChannel(this.getChannelData(a).subarray(n,i),a);return new ne(o)}_reverse(){if(this.loaded)for(let e=0;e<this.numberOfChannels;e++)this.getChannelData(e).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(e){this._reversed!==e&&(this._reversed=e,this._reverse())}static fromArray(e){return new ne().fromArray(e)}static fromUrl(e){return de(this,void 0,void 0,function*(){return yield new ne().load(e)})}static load(e){return de(this,void 0,void 0,function*(){const t=e.match(/\[([^\]\[]+\|.+)\]$/);if(t){const c=t[1].split("|");let l=c[0];for(const u of c)if(ne.supportsType(u)){l=u;break}e=e.replace(t[0],l)}const n=ne.baseUrl===""||ne.baseUrl.endsWith("/")?ne.baseUrl:ne.baseUrl+"/",i=document.createElement("a");i.href=n+e,i.pathname=(i.pathname+i.hash).split("/").map(encodeURIComponent).join("/");const r=yield fetch(i.href);if(!r.ok)throw new Error(`could not load url: ${e}`);const o=yield r.arrayBuffer();return yield qe().decodeAudioData(o)})}static supportsType(e){const t=e.split("."),n=t[t.length-1];return document.createElement("audio").canPlayType("audio/"+n)!==""}static loaded(){return de(this,void 0,void 0,function*(){for(yield Promise.resolve();ne.downloads.length;)yield ne.downloads[0]})}}ne.baseUrl="";ne.downloads=[];class ti extends On{constructor(){super({clockSource:"offline",context:Wn(arguments[0])?arguments[0]:_h(arguments[0],arguments[1]*arguments[2],arguments[2]),lookAhead:0,updateInterval:Wn(arguments[0])?128/arguments[0].sampleRate:128/arguments[2]}),this.name="OfflineContext",this._currentTime=0,this.isOffline=!0,this._duration=Wn(arguments[0])?arguments[0].length/arguments[0].sampleRate:arguments[1]}now(){return this._currentTime}get currentTime(){return this._currentTime}_renderClock(e){return de(this,void 0,void 0,function*(){let t=0;for(;this._duration-this._currentTime>=0;){this.emit("tick"),this._currentTime+=128/this.sampleRate,t++;const n=Math.floor(this.sampleRate/128);e&&t%n===0&&(yield new Promise(i=>setTimeout(i,1)))}})}render(e=!0){return de(this,void 0,void 0,function*(){yield this.workletsAreReady(),yield this._renderClock(e);const t=yield this._context.startRendering();return new ne(t)})}close(){return Promise.resolve()}}const qr=new Nh;let Wt=qr;function qe(){return Wt===qr&&yh&&Oh(new On),Wt}function Oh(s,e=!1){e&&Wt.dispose(),Lt(s)?Wt=new On(s):Wn(s)?Wt=new ti(s):Wt=s}if(St&&!St.TONE_SILENCE_LOGGING){const e=` * Tone.js v${Li} * `;console.log(`%c${e}`,"background: #000; color: #fff")}function Eh(s){return Math.pow(10,s/20)}function Mh(s){return 20*(Math.log(s)/Math.LN10)}function Wr(s){return Math.pow(2,s/12)}let _s=440;function Ih(){return _s}function Dh(s){_s=s}function bt(s){return Math.round(jr(s))}function jr(s){return 69+12*Math.log2(s/_s)}function Br(s){return _s*Math.pow(2,(s-69)/12)}class ni extends at{constructor(e,t,n){super(),this.defaultUnits="s",this._val=t,this._units=n,this.context=e,this._expressions=this._getExpressions()}_getExpressions(){return{hz:{method:e=>this._frequencyToUnits(parseFloat(e)),regexp:/^(\d+(?:\.\d+)?)hz$/i},i:{method:e=>this._ticksToUnits(parseInt(e,10)),regexp:/^(\d+)i$/i},m:{method:e=>this._beatsToUnits(parseInt(e,10)*this._getTimeSignature()),regexp:/^(\d+)m$/i},n:{method:(e,t)=>{const n=parseInt(e,10),i=t==="."?1.5:1;return n===1?this._beatsToUnits(this._getTimeSignature())*i:this._beatsToUnits(4/n)*i},regexp:/^(\d+)n(\.?)$/i},number:{method:e=>this._expressions[this.defaultUnits].method.call(this,e),regexp:/^(\d+(?:\.\d+)?)$/},s:{method:e=>this._secondsToUnits(parseFloat(e)),regexp:/^(\d+(?:\.\d+)?)s$/},samples:{method:e=>parseInt(e,10)/this.context.sampleRate,regexp:/^(\d+)samples$/},t:{method:e=>{const t=parseInt(e,10);return this._beatsToUnits(8/(Math.floor(t)*3))},regexp:/^(\d+)t$/i},tr:{method:(e,t,n)=>{let i=0;return e&&e!=="0"&&(i+=this._beatsToUnits(this._getTimeSignature()*parseFloat(e))),t&&t!=="0"&&(i+=this._beatsToUnits(parseFloat(t))),n&&n!=="0"&&(i+=this._beatsToUnits(parseFloat(n)/4)),i},regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/}}}valueOf(){if(this._val instanceof ni&&this.fromType(this._val),Re(this._val))return this._noArg();if(st(this._val)&&Re(this._units)){for(const e in this._expressions)if(this._expressions[e].regexp.test(this._val.trim())){this._units=e;break}}else if(Ct(this._val)){let e=0;for(const t in this._val)if(Z(this._val[t])){const n=this._val[t],i=new this.constructor(this.context,t).valueOf()*n;e+=i}return e}if(Z(this._units)){const e=this._expressions[this._units],t=this._val.toString().trim().match(e.regexp);return t?e.method.apply(this,t.slice(1)):e.method.call(this,this._val)}else return st(this._val)?parseFloat(this._val):this._val}_frequencyToUnits(e){return 1/e}_beatsToUnits(e){return 60/this._getBpm()*e}_secondsToUnits(e){return e}_ticksToUnits(e){return e*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(e){switch(this._units=void 0,this.defaultUnits){case"s":this._val=e.toSeconds();break;case"i":this._val=e.toTicks();break;case"hz":this._val=e.toFrequency();break;case"midi":this._val=e.toMidi();break}return this}toFrequency(){return 1/this.toSeconds()}toSamples(){return this.toSeconds()*this.context.sampleRate}toMilliseconds(){return this.toSeconds()*1e3}}class We extends ni{constructor(){super(...arguments),this.name="TimeClass"}_getExpressions(){return Object.assign(super._getExpressions(),{now:{method:e=>this._now()+new this.constructor(this.context,e).valueOf(),regexp:/^\+(.+)/},quantize:{method:e=>{const t=new We(this.context,e).valueOf();return this._secondsToUnits(this.context.transport.nextSubdivision(t))},regexp:/^@(.+)/}})}quantize(e,t=1){const n=new this.constructor(this.context,e).valueOf(),i=this.valueOf(),a=Math.round(i/n)*n-i;return i+a*t}toNotation(){const e=this.toSeconds(),t=["1m"];for(let r=1;r<9;r++){const o=Math.pow(2,r);t.push(o+"n."),t.push(o+"n"),t.push(o+"t")}t.push("0");let n=t[0],i=new We(this.context,t[0]).toSeconds();return t.forEach(r=>{const o=new We(this.context,r).toSeconds();Math.abs(o-e)<Math.abs(i-e)&&(n=r,i=o)}),n}toBarsBeatsSixteenths(){const e=this._beatsToUnits(1);let t=this.valueOf()/e;t=parseFloat(t.toFixed(4));const n=Math.floor(t/this._getTimeSignature());let i=t%1*4;t=Math.floor(t)%this._getTimeSignature();const r=i.toString();return r.length>3&&(i=parseFloat(parseFloat(r).toFixed(3))),[n,t,i].join(":")}toTicks(){const e=this._beatsToUnits(1);return this.valueOf()/e*this._getPPQ()}toSeconds(){return this.valueOf()}toMidi(){return bt(this.toFrequency())}_now(){return this.context.now()}}class Me extends We{constructor(){super(...arguments),this.name="Frequency",this.defaultUnits="hz"}static get A4(){return Ih()}static set A4(e){Dh(e)}_getExpressions(){return Object.assign({},super._getExpressions(),{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method(e){return this.defaultUnits==="midi"?e:Me.mtof(e)}},note:{regexp:/^([a-g]{1}(?:b|#|##|x|bb|###|#x|x#|bbb)?)(-?[0-9]+)/i,method(e,t){const i=Rh[e.toLowerCase()]+(parseInt(t,10)+1)*12;return this.defaultUnits==="midi"?i:Me.mtof(i)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method(e,t,n){let i=1;return e&&e!=="0"&&(i*=this._beatsToUnits(this._getTimeSignature()*parseFloat(e))),t&&t!=="0"&&(i*=this._beatsToUnits(parseFloat(t))),n&&n!=="0"&&(i*=this._beatsToUnits(parseFloat(n)/4)),i}}})}transpose(e){return new Me(this.context,this.valueOf()*Wr(e))}harmonize(e){return e.map(t=>this.transpose(t))}toMidi(){return bt(this.valueOf())}toNote(){const e=this.toFrequency(),t=Math.log2(e/Me.A4);let n=Math.round(12*t)+57;const i=Math.floor(n/12);return i<0&&(n+=-12*i),Ph[n%12]+i.toString()}toSeconds(){return 1/super.toSeconds()}toTicks(){const e=this._beatsToUnits(1),t=this.valueOf()/e;return Math.floor(t*this._getPPQ())}_noArg(){return 0}_frequencyToUnits(e){return e}_ticksToUnits(e){return 1/(e*60/(this._getBpm()*this._getPPQ()))}_beatsToUnits(e){return 1/super._beatsToUnits(e)}_secondsToUnits(e){return 1/e}static mtof(e){return Br(e)}static ftom(e){return bt(e)}}const Rh={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},Ph=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];class rn extends We{constructor(){super(...arguments),this.name="TransportTime"}_now(){return this.context.transport.seconds}}class Oe extends at{constructor(){super();const e=E(Oe.getDefaults(),arguments,["context"]);this.defaultContext?this.context=this.defaultContext:this.context=e.context}static getDefaults(){return{context:qe()}}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(e){return fh(e),new We(this.context,e).toSeconds()}toFrequency(e){return new Me(this.context,e).toFrequency()}toTicks(e){return new rn(this.context,e).toTicks()}_getPartialProperties(e){const t=this.get();return Object.keys(t).forEach(n=>{Re(e[n])&&delete t[n]}),t}get(){const e=Sh(this);return Object.keys(e).forEach(t=>{if(Reflect.has(this,t)){const n=this[t];Z(n)&&Z(n.value)&&Z(n.setValueAtTime)?e[t]=n.value:n instanceof Oe?e[t]=n._getPartialProperties(e[t]):Ie(n)||ft(n)||st(n)||ph(n)?e[t]=n:delete e[t]}}),e}set(e){return Object.keys(e).forEach(t=>{Reflect.has(this,t)&&Z(this[t])&&(this[t]&&Z(this[t].value)&&Z(this[t].setValueAtTime)?this[t].value!==e[t]&&(this[t].value=e[t]):this[t]instanceof Oe?this[t].set(e[t]):this[t]=e[t])}),this}}class si extends Pe{constructor(e="stopped"){super(),this.name="StateTimeline",this._initial=e,this.setStateAtTime(this._initial,0)}getValueAtTime(e){const t=this.get(e);return t!==null?t.state:this._initial}setStateAtTime(e,t,n){return mt(t,0),this.add(Object.assign({},n,{state:e,time:t})),this}getLastState(e,t){const n=this._search(t);for(let i=n;i>=0;i--){const r=this._timeline[i];if(r.state===e)return r}}getNextState(e,t){const n=this._search(t);if(n!==-1)for(let i=n;i<this._timeline.length;i++){const r=this._timeline[i];if(r.state===e)return r}}}class ie extends Oe{constructor(){super(E(ie.getDefaults(),arguments,["param","units","convert"])),this.name="Param",this.overridden=!1,this._minOutput=1e-7;const e=E(ie.getDefaults(),arguments,["param","units","convert"]);for(B(Z(e.param)&&(xt(e.param)||e.param instanceof ie),"param must be an AudioParam");!xt(e.param);)e.param=e.param._param;this._swappable=Z(e.swappable)?e.swappable:!1,this._swappable?(this.input=this.context.createGain(),this._param=e.param,this.input.connect(this._param)):this._param=this.input=e.param,this._events=new Pe(1e3),this._initialValue=this._param.defaultValue,this.units=e.units,this.convert=e.convert,this._minValue=e.minValue,this._maxValue=e.maxValue,Z(e.value)&&e.value!==this._toType(this._initialValue)&&this.setValueAtTime(e.value,0)}static getDefaults(){return Object.assign(Oe.getDefaults(),{convert:!0,units:"number"})}get value(){const e=this.now();return this.getValueAtTime(e)}set value(e){this.cancelScheduledValues(this.now()),this.setValueAtTime(e,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(e,t){return this.units===t}_assertRange(e){return Z(this.maxValue)&&Z(this.minValue)&&mt(e,this._fromType(this.minValue),this._fromType(this.maxValue)),e}_fromType(e){return this.convert&&!this.overridden?this._is(e,"time")?this.toSeconds(e):this._is(e,"decibels")?Eh(e):this._is(e,"frequency")?this.toFrequency(e):e:this.overridden?0:e}_toType(e){return this.convert&&this.units==="decibels"?Mh(e):e}setValueAtTime(e,t){const n=this.toSeconds(t),i=this._fromType(e);return B(isFinite(i)&&isFinite(n),`Invalid argument(s) to setValueAtTime: ${JSON.stringify(e)}, ${JSON.stringify(t)}`),this._assertRange(i),this.log(this.units,"setValueAtTime",e,n),this._events.add({time:n,type:"setValueAtTime",value:i}),this._param.setValueAtTime(i,n),this}getValueAtTime(e){const t=Math.max(this.toSeconds(e),0),n=this._events.getAfter(t),i=this._events.get(t);let r=this._initialValue;if(i===null)r=this._initialValue;else if(i.type==="setTargetAtTime"&&(n===null||n.type==="setValueAtTime")){const o=this._events.getBefore(i.time);let a;o===null?a=this._initialValue:a=o.value,i.type==="setTargetAtTime"&&(r=this._exponentialApproach(i.time,a,i.value,i.constant,t))}else if(n===null)r=i.value;else if(n.type==="linearRampToValueAtTime"||n.type==="exponentialRampToValueAtTime"){let o=i.value;if(i.type==="setTargetAtTime"){const a=this._events.getBefore(i.time);a===null?o=this._initialValue:o=a.value}n.type==="linearRampToValueAtTime"?r=this._linearInterpolate(i.time,o,n.time,n.value,t):r=this._exponentialInterpolate(i.time,o,n.time,n.value,t)}else r=i.value;return this._toType(r)}setRampPoint(e){e=this.toSeconds(e);let t=this.getValueAtTime(e);return this.cancelAndHoldAtTime(e),this._fromType(t)===0&&(t=this._toType(this._minOutput)),this.setValueAtTime(t,e),this}linearRampToValueAtTime(e,t){const n=this._fromType(e),i=this.toSeconds(t);return B(isFinite(n)&&isFinite(i),`Invalid argument(s) to linearRampToValueAtTime: ${JSON.stringify(e)}, ${JSON.stringify(t)}`),this._assertRange(n),this._events.add({time:i,type:"linearRampToValueAtTime",value:n}),this.log(this.units,"linearRampToValueAtTime",e,i),this._param.linearRampToValueAtTime(n,i),this}exponentialRampToValueAtTime(e,t){let n=this._fromType(e);n=Le(n,0)?this._minOutput:n,this._assertRange(n);const i=this.toSeconds(t);return B(isFinite(n)&&isFinite(i),`Invalid argument(s) to exponentialRampToValueAtTime: ${JSON.stringify(e)}, ${JSON.stringify(t)}`),this._events.add({time:i,type:"exponentialRampToValueAtTime",value:n}),this.log(this.units,"exponentialRampToValueAtTime",e,i),this._param.exponentialRampToValueAtTime(n,i),this}exponentialRampTo(e,t,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialRampToValueAtTime(e,n+this.toSeconds(t)),this}linearRampTo(e,t,n){return n=this.toSeconds(n),this.setRampPoint(n),this.linearRampToValueAtTime(e,n+this.toSeconds(t)),this}targetRampTo(e,t,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialApproachValueAtTime(e,n,t),this}exponentialApproachValueAtTime(e,t,n){t=this.toSeconds(t),n=this.toSeconds(n);const i=Math.log(n+1)/Math.log(200);return this.setTargetAtTime(e,t,i),this.cancelAndHoldAtTime(t+n*.9),this.linearRampToValueAtTime(e,t+n),this}setTargetAtTime(e,t,n){const i=this._fromType(e);B(isFinite(n)&&n>0,"timeConstant must be a number greater than 0");const r=this.toSeconds(t);return this._assertRange(i),B(isFinite(i)&&isFinite(r),`Invalid argument(s) to setTargetAtTime: ${JSON.stringify(e)}, ${JSON.stringify(t)}`),this._events.add({constant:n,time:r,type:"setTargetAtTime",value:i}),this.log(this.units,"setTargetAtTime",e,r,n),this._param.setTargetAtTime(i,r,n),this}setValueCurveAtTime(e,t,n,i=1){n=this.toSeconds(n),t=this.toSeconds(t);const r=this._fromType(e[0])*i;this.setValueAtTime(this._toType(r),t);const o=n/(e.length-1);for(let a=1;a<e.length;a++){const c=this._fromType(e[a])*i;this.linearRampToValueAtTime(this._toType(c),t+a*o)}return this}cancelScheduledValues(e){const t=this.toSeconds(e);return B(isFinite(t),`Invalid argument to cancelScheduledValues: ${JSON.stringify(e)}`),this._events.cancel(t),this._param.cancelScheduledValues(t),this.log(this.units,"cancelScheduledValues",t),this}cancelAndHoldAtTime(e){const t=this.toSeconds(e),n=this._fromType(this.getValueAtTime(t));B(isFinite(t),`Invalid argument to cancelAndHoldAtTime: ${JSON.stringify(e)}`),this.log(this.units,"cancelAndHoldAtTime",t,"value="+n);const i=this._events.get(t),r=this._events.getAfter(t);return i&&Le(i.time,t)?r?(this._param.cancelScheduledValues(r.time),this._events.cancel(r.time)):(this._param.cancelAndHoldAtTime(t),this._events.cancel(t+this.sampleTime)):r&&(this._param.cancelScheduledValues(r.time),this._events.cancel(r.time),r.type==="linearRampToValueAtTime"?this.linearRampToValueAtTime(this._toType(n),t):r.type==="exponentialRampToValueAtTime"&&this.exponentialRampToValueAtTime(this._toType(n),t)),this._events.add({time:t,type:"setValueAtTime",value:n}),this._param.setValueAtTime(n,t),this}rampTo(e,t=.1,n){return this.units==="frequency"||this.units==="bpm"||this.units==="decibels"?this.exponentialRampTo(e,t,n):this.linearRampTo(e,t,n),this}apply(e){const t=this.context.currentTime;e.setValueAtTime(this.getValueAtTime(t),t);const n=this._events.get(t);if(n&&n.type==="setTargetAtTime"){const i=this._events.getAfter(n.time),r=i?i.time:t+2,o=(r-t)/10;for(let a=t;a<r;a+=o)e.linearRampToValueAtTime(this.getValueAtTime(a),a)}return this._events.forEachAfter(this.context.currentTime,i=>{i.type==="cancelScheduledValues"?e.cancelScheduledValues(i.time):i.type==="setTargetAtTime"?e.setTargetAtTime(i.value,i.time,i.constant):e[i.type](i.value,i.time)}),this}setParam(e){B(this._swappable,"The Param must be assigned as 'swappable' in the constructor");const t=this.input;return t.disconnect(this._param),this.apply(e),this._param=e,t.connect(this._param),this}dispose(){return super.dispose(),this._events.dispose(),this}get defaultValue(){return this._toType(this._param.defaultValue)}_exponentialApproach(e,t,n,i,r){return n+(t-n)*Math.exp(-(r-e)/i)}_linearInterpolate(e,t,n,i,r){return t+(i-t)*((r-e)/(n-e))}_exponentialInterpolate(e,t,n,i,r){return t*Math.pow(i/t,(r-e)/(n-e))}}class Y extends Oe{constructor(){super(...arguments),this._internalChannels=[]}get numberOfInputs(){return Z(this.input)?xt(this.input)||this.input instanceof ie?1:this.input.numberOfInputs:0}get numberOfOutputs(){return Z(this.output)?this.output.numberOfOutputs:0}_isAudioNode(e){return Z(e)&&(e instanceof Y||pt(e))}_getInternalNodes(){const e=this._internalChannels.slice(0);return this._isAudioNode(this.input)&&e.push(this.input),this._isAudioNode(this.output)&&this.input!==this.output&&e.push(this.output),e}_setChannelProperties(e){this._getInternalNodes().forEach(n=>{n.channelCount=e.channelCount,n.channelCountMode=e.channelCountMode,n.channelInterpretation=e.channelInterpretation})}_getChannelProperties(){const e=this._getInternalNodes();B(e.length>0,"ToneAudioNode does not have any internal nodes");const t=e[0];return{channelCount:t.channelCount,channelCountMode:t.channelCountMode,channelInterpretation:t.channelInterpretation}}get channelCount(){return this._getChannelProperties().channelCount}set channelCount(e){const t=this._getChannelProperties();this._setChannelProperties(Object.assign(t,{channelCount:e}))}get channelCountMode(){return this._getChannelProperties().channelCountMode}set channelCountMode(e){const t=this._getChannelProperties();this._setChannelProperties(Object.assign(t,{channelCountMode:e}))}get channelInterpretation(){return this._getChannelProperties().channelInterpretation}set channelInterpretation(e){const t=this._getChannelProperties();this._setChannelProperties(Object.assign(t,{channelInterpretation:e}))}connect(e,t=0,n=0){return sn(this,e,t,n),this}toDestination(){return this.connect(this.context.destination),this}toMaster(){return fs("toMaster() has been renamed toDestination()"),this.toDestination()}disconnect(e,t=0,n=0){return Vh(this,e,t,n),this}chain(...e){return Ps(this,...e),this}fan(...e){return e.forEach(t=>this.connect(t)),this}dispose(){return super.dispose(),Z(this.input)&&(this.input instanceof Y?this.input.dispose():pt(this.input)&&this.input.disconnect()),Z(this.output)&&(this.output instanceof Y?this.output.dispose():pt(this.output)&&this.output.disconnect()),this._internalChannels=[],this}}function Ps(...s){const e=s.shift();s.reduce((t,n)=>(t instanceof Y?t.connect(n):pt(t)&&sn(t,n),n),e)}function sn(s,e,t=0,n=0){for(B(Z(s),"Cannot connect from undefined node"),B(Z(e),"Cannot connect to undefined node"),(e instanceof Y||pt(e))&&B(e.numberOfInputs>0,"Cannot connect to node with no inputs"),B(s.numberOfOutputs>0,"Cannot connect from node with no outputs");e instanceof Y||e instanceof ie;)Z(e.input)&&(e=e.input);for(;s instanceof Y;)Z(s.output)&&(s=s.output);xt(e)?s.connect(e,t):s.connect(e,t,n)}function Vh(s,e,t=0,n=0){if(Z(e))for(;e instanceof Y;)e=e.input;for(;!pt(s);)Z(s.output)&&(s=s.output);xt(e)?s.disconnect(e,t):pt(e)?s.disconnect(e,t,n):s.disconnect()}class ve extends Y{constructor(){super(E(ve.getDefaults(),arguments,["gain","units"])),this.name="Gain",this._gainNode=this.context.createGain(),this.input=this._gainNode,this.output=this._gainNode;const e=E(ve.getDefaults(),arguments,["gain","units"]);this.gain=new ie({context:this.context,convert:e.convert,param:this._gainNode.gain,units:e.units,value:e.gain,minValue:e.minValue,maxValue:e.maxValue}),ce(this,"gain")}static getDefaults(){return Object.assign(Y.getDefaults(),{convert:!0,gain:1,units:"gain"})}dispose(){return super.dispose(),this._gainNode.disconnect(),this.gain.dispose(),this}}class Yt extends Y{constructor(e){super(e),this.onended=H,this._startTime=-1,this._stopTime=-1,this._timeout=-1,this.output=new ve({context:this.context,gain:0}),this._gainNode=this.output,this.getStateAtTime=function(t){const n=this.toSeconds(t);return this._startTime!==-1&&n>=this._startTime&&(this._stopTime===-1||n<=this._stopTime)?"started":"stopped"},this._fadeIn=e.fadeIn,this._fadeOut=e.fadeOut,this._curve=e.curve,this.onended=e.onended}static getDefaults(){return Object.assign(Y.getDefaults(),{curve:"linear",fadeIn:0,fadeOut:0,onended:H})}_startGain(e,t=1){B(this._startTime===-1,"Source cannot be started more than once");const n=this.toSeconds(this._fadeIn);return this._startTime=e+n,this._startTime=Math.max(this._startTime,this.context.currentTime),n>0?(this._gainNode.gain.setValueAtTime(0,e),this._curve==="linear"?this._gainNode.gain.linearRampToValueAtTime(t,e+n):this._gainNode.gain.exponentialApproachValueAtTime(t,e,n)):this._gainNode.gain.setValueAtTime(t,e),this}stop(e){return this.log("stop",e),this._stopGain(this.toSeconds(e)),this}_stopGain(e){B(this._startTime!==-1,"'start' must be called before 'stop'"),this.cancelStop();const t=this.toSeconds(this._fadeOut);return this._stopTime=this.toSeconds(e)+t,this._stopTime=Math.max(this._stopTime,this.now()),t>0?this._curve==="linear"?this._gainNode.gain.linearRampTo(0,t,e):this._gainNode.gain.targetRampTo(0,t,e):(this._gainNode.gain.cancelAndHoldAtTime(e),this._gainNode.gain.setValueAtTime(0,e)),this.context.clearTimeout(this._timeout),this._timeout=this.context.setTimeout(()=>{const n=this._curve==="exponential"?t*2:0;this._stopSource(this.now()+n),this._onended()},this._stopTime-this.context.currentTime),this}_onended(){if(this.onended!==H&&(this.onended(this),this.onended=H,!this.context.isOffline)){const e=()=>this.dispose();typeof window.requestIdleCallback<"u"?window.requestIdleCallback(e):setTimeout(e,1e3)}}get state(){return this.getStateAtTime(this.now())}cancelStop(){return this.log("cancelStop"),B(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=H,this}}class Qn extends Yt{constructor(){super(E(Qn.getDefaults(),arguments,["offset"])),this.name="ToneConstantSource",this._source=this.context.createConstantSource();const e=E(Qn.getDefaults(),arguments,["offset"]);sn(this._source,this._gainNode),this.offset=new ie({context:this.context,convert:e.convert,param:this._source.offset,units:e.units,value:e.offset,minValue:e.minValue,maxValue:e.maxValue})}static getDefaults(){return Object.assign(Yt.getDefaults(),{convert:!0,offset:1,units:"number"})}start(e){const t=this.toSeconds(e);return this.log("start",t),this._startGain(t),this._source.start(t),this}_stopSource(e){this._source.stop(e)}dispose(){return super.dispose(),this.state==="started"&&this.stop(),this._source.disconnect(),this.offset.dispose(),this}}class fe extends Y{constructor(){super(E(fe.getDefaults(),arguments,["value","units"])),this.name="Signal",this.override=!0;const e=E(fe.getDefaults(),arguments,["value","units"]);this.output=this._constantSource=new Qn({context:this.context,convert:e.convert,offset:e.value,units:e.units,minValue:e.minValue,maxValue:e.maxValue}),this._constantSource.start(0),this.input=this._param=this._constantSource.offset}static getDefaults(){return Object.assign(Y.getDefaults(),{convert:!0,units:"number",value:0})}connect(e,t=0,n=0){return ii(this,e,t,n),this}dispose(){return super.dispose(),this._param.dispose(),this._constantSource.dispose(),this}setValueAtTime(e,t){return this._param.setValueAtTime(e,t),this}getValueAtTime(e){return this._param.getValueAtTime(e)}setRampPoint(e){return this._param.setRampPoint(e),this}linearRampToValueAtTime(e,t){return this._param.linearRampToValueAtTime(e,t),this}exponentialRampToValueAtTime(e,t){return this._param.exponentialRampToValueAtTime(e,t),this}exponentialRampTo(e,t,n){return this._param.exponentialRampTo(e,t,n),this}linearRampTo(e,t,n){return this._param.linearRampTo(e,t,n),this}targetRampTo(e,t,n){return this._param.targetRampTo(e,t,n),this}exponentialApproachValueAtTime(e,t,n){return this._param.exponentialApproachValueAtTime(e,t,n),this}setTargetAtTime(e,t,n){return this._param.setTargetAtTime(e,t,n),this}setValueCurveAtTime(e,t,n,i){return this._param.setValueCurveAtTime(e,t,n,i),this}cancelScheduledValues(e){return this._param.cancelScheduledValues(e),this}cancelAndHoldAtTime(e){return this._param.cancelAndHoldAtTime(e),this}rampTo(e,t,n){return this._param.rampTo(e,t,n),this}get value(){return this._param.value}set value(e){this._param.value=e}get convert(){return this._param.convert}set convert(e){this._param.convert=e}get units(){return this._param.units}get overridden(){return this._param.overridden}set overridden(e){this._param.overridden=e}get maxValue(){return this._param.maxValue}get minValue(){return this._param.minValue}apply(e){return this._param.apply(e),this}}function ii(s,e,t,n){(e instanceof ie||xt(e)||e instanceof fe&&e.override)&&(e.cancelScheduledValues(0),e.setValueAtTime(0,0),e instanceof fe&&(e.overridden=!0)),sn(s,e,t,n)}class Kn extends ie{constructor(){super(E(Kn.getDefaults(),arguments,["value"])),this.name="TickParam",this._events=new Pe(1/0),this._multiplier=1;const e=E(Kn.getDefaults(),arguments,["value"]);this._multiplier=e.multiplier,this._events.cancel(0),this._events.add({ticks:0,time:0,type:"setValueAtTime",value:this._fromType(e.value)}),this.setValueAtTime(e.value,0)}static getDefaults(){return Object.assign(ie.getDefaults(),{multiplier:1,units:"hertz",value:1})}setTargetAtTime(e,t,n){t=this.toSeconds(t),this.setRampPoint(t);const i=this._fromType(e),r=this._events.get(t),o=Math.round(Math.max(1/n,1));for(let a=0;a<=o;a++){const c=n*a+t,l=this._exponentialApproach(r.time,r.value,i,n,c);this.linearRampToValueAtTime(this._toType(l),c)}return this}setValueAtTime(e,t){const n=this.toSeconds(t);super.setValueAtTime(e,t);const i=this._events.get(n),r=this._events.previousEvent(i),o=this._getTicksUntilEvent(r,n);return i.ticks=Math.max(o,0),this}linearRampToValueAtTime(e,t){const n=this.toSeconds(t);super.linearRampToValueAtTime(e,t);const i=this._events.get(n),r=this._events.previousEvent(i),o=this._getTicksUntilEvent(r,n);return i.ticks=Math.max(o,0),this}exponentialRampToValueAtTime(e,t){t=this.toSeconds(t);const n=this._fromType(e),i=this._events.get(t),r=Math.round(Math.max((t-i.time)*10,1)),o=(t-i.time)/r;for(let a=0;a<=r;a++){const c=o*a+i.time,l=this._exponentialInterpolate(i.time,i.value,t,n,c);this.linearRampToValueAtTime(this._toType(l),c)}return this}_getTicksUntilEvent(e,t){if(e===null)e={ticks:0,time:0,type:"setValueAtTime",value:0};else if(Re(e.ticks)){const o=this._events.previousEvent(e);e.ticks=this._getTicksUntilEvent(o,e.time)}const n=this._fromType(this.getValueAtTime(e.time));let i=this._fromType(this.getValueAtTime(t));const r=this._events.get(t);return r&&r.time===t&&r.type==="setValueAtTime"&&(i=this._fromType(this.getValueAtTime(t-this.sampleTime))),.5*(t-e.time)*(n+i)+e.ticks}getTicksAtTime(e){const t=this.toSeconds(e),n=this._events.get(t);return Math.max(this._getTicksUntilEvent(n,t),0)}getDurationOfTicks(e,t){const n=this.toSeconds(t),i=this.getTicksAtTime(t);return this.getTimeOfTick(i+e)-n}getTimeOfTick(e){const t=this._events.get(e,"ticks"),n=this._events.getAfter(e,"ticks");if(t&&t.ticks===e)return t.time;if(t&&n&&n.type==="linearRampToValueAtTime"&&t.value!==n.value){const i=this._fromType(this.getValueAtTime(t.time)),o=(this._fromType(this.getValueAtTime(n.time))-i)/(n.time-t.time),a=Math.sqrt(Math.pow(i,2)-2*o*(t.ticks-e)),c=(-i+a)/o,l=(-i-a)/o;return(c>0?c:l)+t.time}else return t?t.value===0?1/0:t.time+(e-t.ticks)/t.value:e/this._initialValue}ticksToTime(e,t){return this.getDurationOfTicks(e,t)}timeToTicks(e,t){const n=this.toSeconds(t),i=this.toSeconds(e),r=this.getTicksAtTime(n);return this.getTicksAtTime(n+i)-r}_fromType(e){return this.units==="bpm"&&this.multiplier?1/(60/e/this.multiplier):super._fromType(e)}_toType(e){return this.units==="bpm"&&this.multiplier?e/this.multiplier*60:super._toType(e)}get multiplier(){return this._multiplier}set multiplier(e){const t=this.value;this._multiplier=e,this.cancelScheduledValues(0),this.setValueAtTime(t,0)}}class Jn extends fe{constructor(){super(E(Jn.getDefaults(),arguments,["value"])),this.name="TickSignal";const e=E(Jn.getDefaults(),arguments,["value"]);this.input=this._param=new Kn({context:this.context,convert:e.convert,multiplier:e.multiplier,param:this._constantSource.offset,units:e.units,value:e.value})}static getDefaults(){return Object.assign(fe.getDefaults(),{multiplier:1,units:"hertz",value:1})}ticksToTime(e,t){return this._param.ticksToTime(e,t)}timeToTicks(e,t){return this._param.timeToTicks(e,t)}getTimeOfTick(e){return this._param.getTimeOfTick(e)}getDurationOfTicks(e,t){return this._param.getDurationOfTicks(e,t)}getTicksAtTime(e){return this._param.getTicksAtTime(e)}get multiplier(){return this._param.multiplier}set multiplier(e){this._param.multiplier=e}dispose(){return super.dispose(),this._param.dispose(),this}}class es extends Oe{constructor(){super(E(es.getDefaults(),arguments,["frequency"])),this.name="TickSource",this._state=new si,this._tickOffset=new Pe,this._ticksAtTime=new Pe,this._secondsAtTime=new Pe;const e=E(es.getDefaults(),arguments,["frequency"]);this.frequency=new Jn({context:this.context,units:e.units,value:e.frequency}),ce(this,"frequency"),this._state.setStateAtTime("stopped",0),this.setTicksAtTime(0,0)}static getDefaults(){return Object.assign({frequency:1,units:"hertz"},Oe.getDefaults())}get state(){return this.getStateAtTime(this.now())}start(e,t){const n=this.toSeconds(e);return this._state.getValueAtTime(n)!=="started"&&(this._state.setStateAtTime("started",n),Z(t)&&this.setTicksAtTime(t,n),this._ticksAtTime.cancel(n),this._secondsAtTime.cancel(n)),this}stop(e){const t=this.toSeconds(e);if(this._state.getValueAtTime(t)==="stopped"){const n=this._state.get(t);n&&n.time>0&&(this._tickOffset.cancel(n.time),this._state.cancel(n.time))}return this._state.cancel(t),this._state.setStateAtTime("stopped",t),this.setTicksAtTime(0,t),this._ticksAtTime.cancel(t),this._secondsAtTime.cancel(t),this}pause(e){const t=this.toSeconds(e);return this._state.getValueAtTime(t)==="started"&&(this._state.setStateAtTime("paused",t),this._ticksAtTime.cancel(t),this._secondsAtTime.cancel(t)),this}cancel(e){return e=this.toSeconds(e),this._state.cancel(e),this._tickOffset.cancel(e),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e),this}getTicksAtTime(e){const t=this.toSeconds(e),n=this._state.getLastState("stopped",t),i=this._ticksAtTime.get(t),r={state:"paused",time:t};this._state.add(r);let o=i||n,a=i?i.ticks:0,c=null;return this._state.forEachBetween(o.time,t+this.sampleTime,l=>{let u=o.time;const h=this._tickOffset.get(l.time);h&&h.time>=o.time&&(a=h.ticks,u=h.time),o.state==="started"&&l.state!=="started"&&(a+=this.frequency.getTicksAtTime(l.time)-this.frequency.getTicksAtTime(u),l.time!==r.time&&(c={state:l.state,time:l.time,ticks:a})),o=l}),this._state.remove(r),c&&this._ticksAtTime.add(c),a}get ticks(){return this.getTicksAtTime(this.now())}set ticks(e){this.setTicksAtTime(e,this.now())}get seconds(){return this.getSecondsAtTime(this.now())}set seconds(e){const t=this.now(),n=this.frequency.timeToTicks(e,t);this.setTicksAtTime(n,t)}getSecondsAtTime(e){e=this.toSeconds(e);const t=this._state.getLastState("stopped",e),n={state:"paused",time:e};this._state.add(n);const i=this._secondsAtTime.get(e);let r=i||t,o=i?i.seconds:0,a=null;return this._state.forEachBetween(r.time,e+this.sampleTime,c=>{let l=r.time;const u=this._tickOffset.get(c.time);u&&u.time>=r.time&&(o=u.seconds,l=u.time),r.state==="started"&&c.state!=="started"&&(o+=c.time-l,c.time!==n.time&&(a={state:c.state,time:c.time,seconds:o})),r=c}),this._state.remove(n),a&&this._secondsAtTime.add(a),o}setTicksAtTime(e,t){return t=this.toSeconds(t),this._tickOffset.cancel(t),this._tickOffset.add({seconds:this.frequency.getDurationOfTicks(e,t),ticks:e,time:t}),this._ticksAtTime.cancel(t),this._secondsAtTime.cancel(t),this}getStateAtTime(e){return e=this.toSeconds(e),this._state.getValueAtTime(e)}getTimeOfTick(e,t=this.now()){const n=this._tickOffset.get(t),i=this._state.get(t),r=Math.max(n.time,i.time),o=this.frequency.getTicksAtTime(r)+e-n.ticks;return this.frequency.getTimeOfTick(o)}forEachTickBetween(e,t,n){let i=this._state.get(e);this._state.forEachBetween(e,t,o=>{i&&i.state==="started"&&o.state!=="started"&&this.forEachTickBetween(Math.max(i.time,e),o.time-this.sampleTime,n),i=o});let r=null;if(i&&i.state==="started"){const o=Math.max(i.time,e),a=this.frequency.getTicksAtTime(o),c=this.frequency.getTicksAtTime(i.time),l=a-c;let u=Math.ceil(l)-l;u=Le(u,1)?0:u;let h=this.frequency.getTimeOfTick(a+u);for(;h<t;){try{n(h,Math.round(this.getTicksAtTime(h)))}catch(p){r=p;break}h+=this.frequency.getDurationOfTicks(1,h)}}if(r)throw r;return this}dispose(){return super.dispose(),this._state.dispose(),this._tickOffset.dispose(),this._ticksAtTime.dispose(),this._secondsAtTime.dispose(),this.frequency.dispose(),this}}class ln extends Oe{constructor(){super(E(ln.getDefaults(),arguments,["callback","frequency"])),this.name="Clock",this.callback=H,this._lastUpdate=0,this._state=new si("stopped"),this._boundLoop=this._loop.bind(this);const e=E(ln.getDefaults(),arguments,["callback","frequency"]);this.callback=e.callback,this._tickSource=new es({context:this.context,frequency:e.frequency,units:e.units}),this._lastUpdate=0,this.frequency=this._tickSource.frequency,ce(this,"frequency"),this._state.setStateAtTime("stopped",0),this.context.on("tick",this._boundLoop)}static getDefaults(){return Object.assign(Oe.getDefaults(),{callback:H,frequency:1,units:"hertz"})}get state(){return this._state.getValueAtTime(this.now())}start(e,t){Ir(this.context);const n=this.toSeconds(e);return this.log("start",n),this._state.getValueAtTime(n)!=="started"&&(this._state.setStateAtTime("started",n),this._tickSource.start(n,t),n<this._lastUpdate&&this.emit("start",n,t)),this}stop(e){const t=this.toSeconds(e);return this.log("stop",t),this._state.cancel(t),this._state.setStateAtTime("stopped",t),this._tickSource.stop(t),t<this._lastUpdate&&this.emit("stop",t),this}pause(e){const t=this.toSeconds(e);return this._state.getValueAtTime(t)==="started"&&(this._state.setStateAtTime("paused",t),this._tickSource.pause(t),t<this._lastUpdate&&this.emit("pause",t)),this}get ticks(){return Math.ceil(this.getTicksAtTime(this.now()))}set ticks(e){this._tickSource.ticks=e}get seconds(){return this._tickSource.seconds}set seconds(e){this._tickSource.seconds=e}getSecondsAtTime(e){return this._tickSource.getSecondsAtTime(e)}setTicksAtTime(e,t){return this._tickSource.setTicksAtTime(e,t),this}getTimeOfTick(e,t=this.now()){return this._tickSource.getTimeOfTick(e,t)}getTicksAtTime(e){return this._tickSource.getTicksAtTime(e)}nextTickTime(e,t){const n=this.toSeconds(t),i=this.getTicksAtTime(n);return this._tickSource.getTimeOfTick(i+e,n)}_loop(){const e=this._lastUpdate,t=this.now();this._lastUpdate=t,this.log("loop",e,t),e!==t&&(this._state.forEachBetween(e,t,n=>{switch(n.state){case"started":const i=this._tickSource.getTicksAtTime(n.time);this.emit("start",n.time,i);break;case"stopped":n.time!==0&&this.emit("stop",n.time);break;case"paused":this.emit("pause",n.time);break}}),this._tickSource.forEachTickBetween(e,t,(n,i)=>{this.callback(n,i)}))}getStateAtTime(e){const t=this.toSeconds(e);return this._state.getValueAtTime(t)}dispose(){return super.dispose(),this.context.off("tick",this._boundLoop),this._tickSource.dispose(),this._state.dispose(),this}}Nn.mixin(ln);class ri extends at{constructor(){super(),this.name="ToneAudioBuffers",this._buffers=new Map,this._loadingCount=0;const e=E(ri.getDefaults(),arguments,["urls","onload","baseUrl"],"urls");this.baseUrl=e.baseUrl,Object.keys(e.urls).forEach(t=>{this._loadingCount++;const n=e.urls[t];this.add(t,n,this._bufferLoaded.bind(this,e.onload),e.onerror)})}static getDefaults(){return{baseUrl:"",onerror:H,onload:H,urls:{}}}has(e){return this._buffers.has(e.toString())}get(e){return B(this.has(e),`ToneAudioBuffers has no buffer named: ${e}`),this._buffers.get(e.toString())}_bufferLoaded(e){this._loadingCount--,this._loadingCount===0&&e&&e()}get loaded(){return Array.from(this._buffers).every(([e,t])=>t.loaded)}add(e,t,n=H,i=H){return st(t)?(this.baseUrl&&t.trim().substring(0,11).toLowerCase()==="data:audio/"&&(this.baseUrl=""),this._buffers.set(e.toString(),new ne(this.baseUrl+t,n,i))):this._buffers.set(e.toString(),new ne(t,n,i)),this}dispose(){return super.dispose(),this._buffers.forEach(e=>e.dispose()),this._buffers.clear(),this}}class ts extends Me{constructor(){super(...arguments),this.name="MidiClass",this.defaultUnits="midi"}_frequencyToUnits(e){return bt(super._frequencyToUnits(e))}_ticksToUnits(e){return bt(super._ticksToUnits(e))}_beatsToUnits(e){return bt(super._beatsToUnits(e))}_secondsToUnits(e){return bt(super._secondsToUnits(e))}toMidi(){return this.valueOf()}toFrequency(){return Br(this.toMidi())}transpose(e){return new ts(this.context,this.toMidi()+e)}}class jt extends rn{constructor(){super(...arguments),this.name="Ticks",this.defaultUnits="i"}_now(){return this.context.transport.ticks}_beatsToUnits(e){return this._getPPQ()*e}_secondsToUnits(e){return Math.floor(e/(60/this._getBpm())*this._getPPQ())}_ticksToUnits(e){return e}toTicks(){return this.valueOf()}toSeconds(){return this.valueOf()/this._getPPQ()*(60/this._getBpm())}}class Fh extends Oe{constructor(){super(...arguments),this.name="Draw",this.expiration=.25,this.anticipation=.008,this._events=new Pe,this._boundDrawLoop=this._drawLoop.bind(this),this._animationFrame=-1}schedule(e,t){return this._events.add({callback:e,time:this.toSeconds(t)}),this._events.length===1&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop)),this}cancel(e){return this._events.cancel(this.toSeconds(e)),this}_drawLoop(){const e=this.context.currentTime;for(;this._events.length&&this._events.peek().time-this.anticipation<=e;){const t=this._events.shift();t&&e-t.time<=this.expiration&&t.callback()}this._events.length>0&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop))}dispose(){return super.dispose(),this._events.dispose(),cancelAnimationFrame(this._animationFrame),this}}ms(s=>{s.draw=new Fh({context:s})});gs(s=>{s.draw.dispose()});class Lh extends at{constructor(){super(...arguments),this.name="IntervalTimeline",this._root=null,this._length=0}add(e){B(Z(e.time),"Events must have a time property"),B(Z(e.duration),"Events must have a duration parameter"),e.time=e.time.valueOf();let t=new qh(e.time,e.time+e.duration,e);for(this._root===null?this._root=t:this._root.insert(t),this._length++;t!==null;)t.updateHeight(),t.updateMax(),this._rebalance(t),t=t.parent;return this}remove(e){if(this._root!==null){const t=[];this._root.search(e.time,t);for(const n of t)if(n.event===e){this._removeNode(n),this._length--;break}}return this}get length(){return this._length}cancel(e){return this.forEachFrom(e,t=>this.remove(t)),this}_setRoot(e){this._root=e,this._root!==null&&(this._root.parent=null)}_replaceNodeInParent(e,t){e.parent!==null?(e.isLeftChild()?e.parent.left=t:e.parent.right=t,this._rebalance(e.parent)):this._setRoot(t)}_removeNode(e){if(e.left===null&&e.right===null)this._replaceNodeInParent(e,null);else if(e.right===null)this._replaceNodeInParent(e,e.left);else if(e.left===null)this._replaceNodeInParent(e,e.right);else{const t=e.getBalance();let n,i=null;if(t>0)if(e.left.right===null)n=e.left,n.right=e.right,i=n;else{for(n=e.left.right;n.right!==null;)n=n.right;n.parent&&(n.parent.right=n.left,i=n.parent,n.left=e.left,n.right=e.right)}else if(e.right.left===null)n=e.right,n.left=e.left,i=n;else{for(n=e.right.left;n.left!==null;)n=n.left;n.parent&&(n.parent.left=n.right,i=n.parent,n.left=e.left,n.right=e.right)}e.parent!==null?e.isLeftChild()?e.parent.left=n:e.parent.right=n:this._setRoot(n),i&&this._rebalance(i)}e.dispose()}_rotateLeft(e){const t=e.parent,n=e.isLeftChild(),i=e.right;i&&(e.right=i.left,i.left=e),t!==null?n?t.left=i:t.right=i:this._setRoot(i)}_rotateRight(e){const t=e.parent,n=e.isLeftChild(),i=e.left;i&&(e.left=i.right,i.right=e),t!==null?n?t.left=i:t.right=i:this._setRoot(i)}_rebalance(e){const t=e.getBalance();t>1&&e.left?e.left.getBalance()<0?this._rotateLeft(e.left):this._rotateRight(e):t<-1&&e.right&&(e.right.getBalance()>0?this._rotateRight(e.right):this._rotateLeft(e))}get(e){if(this._root!==null){const t=[];if(this._root.search(e,t),t.length>0){let n=t[0];for(let i=1;i<t.length;i++)t[i].low>n.low&&(n=t[i]);return n.event}}return null}forEach(e){if(this._root!==null){const t=[];this._root.traverse(n=>t.push(n)),t.forEach(n=>{n.event&&e(n.event)})}return this}forEachAtTime(e,t){if(this._root!==null){const n=[];this._root.search(e,n),n.forEach(i=>{i.event&&t(i.event)})}return this}forEachFrom(e,t){if(this._root!==null){const n=[];this._root.searchAfter(e,n),n.forEach(i=>{i.event&&t(i.event)})}return this}dispose(){return super.dispose(),this._root!==null&&this._root.traverse(e=>e.dispose()),this._root=null,this}}class qh{constructor(e,t,n){this._left=null,this._right=null,this.parent=null,this.height=0,this.event=n,this.low=e,this.high=t,this.max=this.high}insert(e){e.low<=this.low?this.left===null?this.left=e:this.left.insert(e):this.right===null?this.right=e:this.right.insert(e)}search(e,t){e>this.max||(this.left!==null&&this.left.search(e,t),this.low<=e&&this.high>e&&t.push(this),!(this.low>e)&&this.right!==null&&this.right.search(e,t))}searchAfter(e,t){this.low>=e&&(t.push(this),this.left!==null&&this.left.searchAfter(e,t)),this.right!==null&&this.right.searchAfter(e,t)}traverse(e){e(this),this.left!==null&&this.left.traverse(e),this.right!==null&&this.right.traverse(e)}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 e=0;return this.left!==null&&this.right!==null?e=this.left.height-this.right.height:this.left!==null?e=this.left.height+1:this.right!==null&&(e=-(this.right.height+1)),e}isLeftChild(){return this.parent!==null&&this.parent.left===this}get left(){return this._left}set left(e){this._left=e,e!==null&&(e.parent=this),this.updateHeight(),this.updateMax()}get right(){return this._right}set right(e){this._right=e,e!==null&&(e.parent=this),this.updateHeight(),this.updateMax()}dispose(){this.parent=null,this._left=null,this._right=null,this.event=null}}class Nt extends Y{constructor(){super(E(Nt.getDefaults(),arguments,["volume"])),this.name="Volume";const e=E(Nt.getDefaults(),arguments,["volume"]);this.input=this.output=new ve({context:this.context,gain:e.volume,units:"decibels"}),this.volume=this.output.gain,ce(this,"volume"),this._unmutedVolume=e.volume,this.mute=e.mute}static getDefaults(){return Object.assign(Y.getDefaults(),{mute:!1,volume:0})}get mute(){return this.volume.value===-1/0}set mute(e){!this.mute&&e?(this._unmutedVolume=this.volume.value,this.volume.value=-1/0):this.mute&&!e&&(this.volume.value=this._unmutedVolume)}dispose(){return super.dispose(),this.input.dispose(),this.volume.dispose(),this}}class ns extends Y{constructor(){super(E(ns.getDefaults(),arguments)),this.name="Destination",this.input=new Nt({context:this.context}),this.output=new ve({context:this.context}),this.volume=this.input.volume;const e=E(ns.getDefaults(),arguments);Ps(this.input,this.output,this.context.rawContext.destination),this.mute=e.mute,this._internalChannels=[this.input,this.context.rawContext.destination,this.output]}static getDefaults(){return Object.assign(Y.getDefaults(),{mute:!1,volume:0})}get mute(){return this.input.mute}set mute(e){this.input.mute=e}chain(...e){return this.input.disconnect(),e.unshift(this.input),e.push(this.output),Ps(...e),this}get maxChannelCount(){return this.context.rawContext.destination.maxChannelCount}dispose(){return super.dispose(),this.volume.dispose(),this}}ms(s=>{s.destination=new ns({context:s})});gs(s=>{s.destination.dispose()});class Wh extends at{constructor(e){super(),this.name="TimelineValue",this._timeline=new Pe({memory:10}),this._initialValue=e}set(e,t){return this._timeline.add({value:e,time:t}),this}get(e){const t=this._timeline.get(e);return t?t.value:this._initialValue}}class Zt extends Y{constructor(){super(Object.assign(E(Zt.getDefaults(),arguments,["context"])))}connect(e,t=0,n=0){return ii(this,e,t,n),this}}class $t extends Zt{constructor(){super(Object.assign(E($t.getDefaults(),arguments,["mapping","length"]))),this.name="WaveShaper",this._shaper=this.context.createWaveShaper(),this.input=this._shaper,this.output=this._shaper;const e=E($t.getDefaults(),arguments,["mapping","length"]);Ie(e.mapping)||e.mapping instanceof Float32Array?this.curve=Float32Array.from(e.mapping):dh(e.mapping)&&this.setMap(e.mapping,e.length)}static getDefaults(){return Object.assign(fe.getDefaults(),{length:1024})}setMap(e,t=1024){const n=new Float32Array(t);for(let i=0,r=t;i<r;i++){const o=i/(r-1)*2-1;n[i]=e(o,i)}return this.curve=n,this}get curve(){return this._shaper.curve}set curve(e){this._shaper.curve=e}get oversample(){return this._shaper.oversample}set oversample(e){const t=["none","2x","4x"].some(n=>n.includes(e));B(t,"oversampling must be either 'none', '2x', or '4x'"),this._shaper.oversample=e}dispose(){return super.dispose(),this._shaper.disconnect(),this}}class ss extends Zt{constructor(){super(Object.assign(E(ss.getDefaults(),arguments,["value"]))),this.name="Pow";const e=E(ss.getDefaults(),arguments,["value"]);this._exponentScaler=this.input=this.output=new $t({context:this.context,mapping:this._expFunc(e.value),length:8192}),this._exponent=e.value}static getDefaults(){return Object.assign(Zt.getDefaults(),{value:1})}_expFunc(e){return t=>Math.pow(Math.abs(t),e)}get value(){return this._exponent}set value(e){this._exponent=e,this._exponentScaler.setMap(this._expFunc(this._exponent))}dispose(){return super.dispose(),this._exponentScaler.dispose(),this}}class gt{constructor(e,t){this.id=gt._eventId++,this._remainderTime=0;const n=Object.assign(gt.getDefaults(),t);this.transport=e,this.callback=n.callback,this._once=n.once,this.time=Math.floor(n.time),this._remainderTime=n.time-this.time}static getDefaults(){return{callback:H,once:!1,time:0}}get floatTime(){return this.time+this._remainderTime}invoke(e){if(this.callback){const t=this.transport.bpm.getDurationOfTicks(1,e);this.callback(e+this._remainderTime*t),this._once&&this.transport.clear(this.id)}}dispose(){return this.callback=void 0,this}}gt._eventId=0;class oi extends gt{constructor(e,t){super(e,t),this._currentId=-1,this._nextId=-1,this._nextTick=this.time,this._boundRestart=this._restart.bind(this);const n=Object.assign(oi.getDefaults(),t);this.duration=n.duration,this._interval=n.interval,this._nextTick=n.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({},gt.getDefaults(),{duration:1/0,interval:1,once:!1})}invoke(e){this._createEvents(e),super.invoke(e)}_createEvent(){return Hn(this._nextTick,this.floatTime+this.duration)?this.transport.scheduleOnce(this.invoke.bind(this),new jt(this.context,this._nextTick).toSeconds()):-1}_createEvents(e){Hn(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 jt(this.context,this._nextTick).toSeconds()))}_restart(e){this.transport.clear(this._currentId),this.transport.clear(this._nextId),this._nextTick=this.floatTime;const t=this.transport.getTicksAtTime(e);Gt(t,this.time)&&(this._nextTick=this.floatTime+Math.ceil((t-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}}class un extends Oe{constructor(){super(E(un.getDefaults(),arguments)),this.name="Transport",this._loop=new Wh(!1),this._loopStart=0,this._loopEnd=0,this._scheduledEvents={},this._timeline=new Pe,this._repeatedEvents=new Lh,this._syncedSignals=[],this._swingAmount=0;const e=E(un.getDefaults(),arguments);this._ppq=e.ppq,this._clock=new ln({callback:this._processTick.bind(this),context:this.context,frequency:0,units:"bpm"}),this._bindClockEvents(),this.bpm=this._clock.frequency,this._clock.frequency.multiplier=e.ppq,this.bpm.setValueAtTime(e.bpm,0),ce(this,"bpm"),this._timeSignature=e.timeSignature,this._swingTicks=e.ppq/2}static getDefaults(){return Object.assign(Oe.getDefaults(),{bpm:120,loopEnd:"4m",loopStart:0,ppq:192,swing:0,swingSubdivision:"8n",timeSignature:4})}_processTick(e,t){if(this._loop.get(e)&&t>=this._loopEnd&&(this.emit("loopEnd",e),this._clock.setTicksAtTime(this._loopStart,e),t=this._loopStart,this.emit("loopStart",e,this._clock.getSecondsAtTime(e)),this.emit("loop",e)),this._swingAmount>0&&t%this._ppq!==0&&t%(this._swingTicks*2)!==0){const n=t%(this._swingTicks*2)/(this._swingTicks*2),i=Math.sin(n*Math.PI)*this._swingAmount;e+=new jt(this.context,this._swingTicks*2/3).toSeconds()*i}Pi(!0),this._timeline.forEachAtTime(t,n=>n.invoke(e)),Pi(!1)}schedule(e,t){const n=new gt(this,{callback:e,time:new rn(this.context,t).toTicks()});return this._addEvent(n,this._timeline)}scheduleRepeat(e,t,n,i=1/0){const r=new oi(this,{callback:e,duration:new We(this.context,i).toTicks(),interval:new We(this.context,t).toTicks(),time:new rn(this.context,n).toTicks()});return this._addEvent(r,this._repeatedEvents)}scheduleOnce(e,t){const n=new gt(this,{callback:e,once:!0,time:new rn(this.context,t).toTicks()});return this._addEvent(n,this._timeline)}clear(e){if(this._scheduledEvents.hasOwnProperty(e)){const t=this._scheduledEvents[e.toString()];t.timeline.remove(t.event),t.event.dispose(),delete this._scheduledEvents[e.toString()]}return this}_addEvent(e,t){return this._scheduledEvents[e.id.toString()]={event:e,timeline:t},t.add(e),e.id}cancel(e=0){const t=this.toTicks(e);return this._timeline.forEachFrom(t,n=>this.clear(n.id)),this._repeatedEvents.forEachFrom(t,n=>this.clear(n.id)),this}_bindClockEvents(){this._clock.on("start",(e,t)=>{t=new jt(this.context,t).toSeconds(),this.emit("start",e,t)}),this._clock.on("stop",e=>{this.emit("stop",e)}),this._clock.on("pause",e=>{this.emit("pause",e)})}get state(){return this._clock.getStateAtTime(this.now())}start(e,t){this.context.resume();let n;return Z(t)&&(n=this.toTicks(t)),this._clock.start(e,n),this}stop(e){return this._clock.stop(e),this}pause(e){return this._clock.pause(e),this}toggle(e){return e=this.toSeconds(e),this._clock.getStateAtTime(e)!=="started"?this.start(e):this.stop(e),this}get timeSignature(){return this._timeSignature}set timeSignature(e){Ie(e)&&(e=e[0]/e[1]*4),this._timeSignature=e}get loopStart(){return new We(this.context,this._loopStart,"i").toSeconds()}set loopStart(e){this._loopStart=this.toTicks(e)}get loopEnd(){return new We(this.context,this._loopEnd,"i").toSeconds()}set loopEnd(e){this._loopEnd=this.toTicks(e)}get loop(){return this._loop.get(this.now())}set loop(e){this._loop.set(e,this.now())}setLoopPoints(e,t){return this.loopStart=e,this.loopEnd=t,this}get swing(){return this._swingAmount}set swing(e){this._swingAmount=e}get swingSubdivision(){return new jt(this.context,this._swingTicks).toNotation()}set swingSubdivision(e){this._swingTicks=this.toTicks(e)}get position(){const e=this.now(),t=this._clock.getTicksAtTime(e);return new jt(this.context,t).toBarsBeatsSixteenths()}set position(e){const t=this.toTicks(e);this.ticks=t}get seconds(){return this._clock.seconds}set seconds(e){const t=this.now(),n=this._clock.frequency.timeToTicks(e,t);this.ticks=n}get progress(){if(this.loop){const e=this.now();return(this._clock.getTicksAtTime(e)-this._loopStart)/(this._loopEnd-this._loopStart)}else return 0}get ticks(){return this._clock.ticks}set ticks(e){if(this._clock.ticks!==e){const t=this.now();if(this.state==="started"){const n=this._clock.getTicksAtTime(t),i=this._clock.frequency.getDurationOfTicks(Math.ceil(n)-n,t),r=t+i;this.emit("stop",r),this._clock.setTicksAtTime(e,r),this.emit("start",r,this._clock.getSecondsAtTime(r))}else this.emit("ticks",t),this._clock.setTicksAtTime(e,t)}}getTicksAtTime(e){return this._clock.getTicksAtTime(e)}getSecondsAtTime(e){return this._clock.getSecondsAtTime(e)}get PPQ(){return this._clock.frequency.multiplier}set PPQ(e){this._clock.frequency.multiplier=e}nextSubdivision(e){if(e=this.toTicks(e),this.state!=="started")return 0;{const t=this.now(),n=this.getTicksAtTime(t),i=e-n%e;return this._clock.nextTickTime(i,t)}}syncSignal(e,t){const n=this.now();let i=this.bpm,r=1/(60/i.getValueAtTime(n)/this.PPQ),o=[];if(e.units==="time"){const c=.015625/r,l=new ve(c),u=new ss(-1),h=new ve(c);i.chain(l,u,h),i=h,r=1/r,o=[l,u,h]}t||(e.getValueAtTime(n)!==0?t=e.getValueAtTime(n)/r:t=0);const a=new ve(t);return i.connect(a),a.connect(e._param),o.push(a),this._syncedSignals.push({initial:e.value,nodes:o,signal:e}),e.value=0,this}unsyncSignal(e){for(let t=this._syncedSignals.length-1;t>=0;t--){const n=this._syncedSignals[t];n.signal===e&&(n.nodes.forEach(i=>i.dispose()),n.signal.value=n.initial,this._syncedSignals.splice(t,1))}return this}dispose(){return super.dispose(),this._clock.dispose(),Lr(this,"bpm"),this._timeline.dispose(),this._repeatedEvents.dispose(),this}}Nn.mixin(un);ms(s=>{s.transport=new un({context:s})});gs(s=>{s.transport.dispose()});class De extends Y{constructor(e){super(e),this.input=void 0,this._state=new si("stopped"),this._synced=!1,this._scheduled=[],this._syncedStart=H,this._syncedStop=H,this._state.memory=100,this._state.increasing=!0,this._volume=this.output=new Nt({context:this.context,mute:e.mute,volume:e.volume}),this.volume=this._volume.volume,ce(this,"volume"),this.onstop=e.onstop}static getDefaults(){return Object.assign(Y.getDefaults(),{mute:!1,onstop:H,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(e){this._volume.mute=e}_clampToCurrentTime(e){return this._synced?e:Math.max(e,this.context.currentTime)}start(e,t,n){let i=Re(e)&&this._synced?this.context.transport.seconds:this.toSeconds(e);if(i=this._clampToCurrentTime(i),!this._synced&&this._state.getValueAtTime(i)==="started")B(Gt(i,this._state.get(i).time),"Start time must be strictly greater than previous start time"),this._state.cancel(i),this._state.setStateAtTime("started",i),this.log("restart",i),this.restart(i,t,n);else if(this.log("start",i),this._state.setStateAtTime("started",i),this._synced){const r=this._state.get(i);r&&(r.offset=this.toSeconds(Bt(t,0)),r.duration=n?this.toSeconds(n):void 0);const o=this.context.transport.schedule(a=>{this._start(a,t,n)},i);this._scheduled.push(o),this.context.transport.state==="started"&&this.context.transport.getSecondsAtTime(this.immediate())>i&&this._syncedStart(this.now(),this.context.transport.seconds)}else Ir(this.context),this._start(i,t,n);return this}stop(e){let t=Re(e)&&this._synced?this.context.transport.seconds:this.toSeconds(e);if(t=this._clampToCurrentTime(t),this._state.getValueAtTime(t)==="started"||Z(this._state.getNextState("started",t))){if(this.log("stop",t),!this._synced)this._stop(t);else{const n=this.context.transport.schedule(this._stop.bind(this),t);this._scheduled.push(n)}this._state.cancel(t),this._state.setStateAtTime("stopped",t)}return this}restart(e,t,n){return e=this.toSeconds(e),this._state.getValueAtTime(e)==="started"&&(this._state.cancel(e),this._restart(e,t,n)),this}sync(){return this._synced||(this._synced=!0,this._syncedStart=(e,t)=>{if(Gt(t,0)){const n=this._state.get(t);if(n&&n.state==="started"&&n.time!==t){const i=t-this.toSeconds(n.time);let r;n.duration&&(r=this.toSeconds(n.duration)-i),this._start(e,this.toSeconds(n.offset)+i,r)}}},this._syncedStop=e=>{const t=this.context.transport.getSecondsAtTime(Math.max(e-this.sampleTime,0));this._state.getValueAtTime(t)==="started"&&this._stop(e)},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(e=>this.context.transport.clear(e)),this._scheduled=[],this._state.cancel(0),this._stop(0),this}dispose(){return super.dispose(),this.onstop=H,this.unsync(),this._volume.dispose(),this._state.dispose(),this}}class hn extends Yt{constructor(){super(E(hn.getDefaults(),arguments,["url","onload"])),this.name="ToneBufferSource",this._source=this.context.createBufferSource(),this._internalChannels=[this._source],this._sourceStarted=!1,this._sourceStopped=!1;const e=E(hn.getDefaults(),arguments,["url","onload"]);sn(this._source,this._gainNode),this._source.onended=()=>this._stopSource(),this.playbackRate=new ie({context:this.context,param:this._source.playbackRate,units:"positive",value:e.playbackRate}),this.loop=e.loop,this.loopStart=e.loopStart,this.loopEnd=e.loopEnd,this._buffer=new ne(e.url,e.onload,e.onerror),this._internalChannels.push(this._source)}static getDefaults(){return Object.assign(Yt.getDefaults(),{url:new ne,loop:!1,loopEnd:0,loopStart:0,onload:H,onerror:H,playbackRate:1})}get fadeIn(){return this._fadeIn}set fadeIn(e){this._fadeIn=e}get fadeOut(){return this._fadeOut}set fadeOut(e){this._fadeOut=e}get curve(){return this._curve}set curve(e){this._curve=e}start(e,t,n,i=1){B(this.buffer.loaded,"buffer is either not set or not loaded");const r=this.toSeconds(e);this._startGain(r,i),this.loop?t=Bt(t,this.loopStart):t=Bt(t,0);let o=Math.max(this.toSeconds(t),0);if(this.loop){const a=this.toSeconds(this.loopEnd)||this.buffer.duration,c=this.toSeconds(this.loopStart),l=a-c;Rs(o,a)&&(o=(o-c)%l+c),Le(o,this.buffer.duration)&&(o=0)}if(this._source.buffer=this.buffer.get(),this._source.loopEnd=this.toSeconds(this.loopEnd)||this.buffer.duration,Hn(o,this.buffer.duration)&&(this._sourceStarted=!0,this._source.start(r,o)),Z(n)){let a=this.toSeconds(n);a=Math.max(a,0),this.stop(r+a)}return this}_stopSource(e){!this._sourceStopped&&this._sourceStarted&&(this._sourceStopped=!0,this._source.stop(this.toSeconds(e)),this._onended())}get loopStart(){return this._source.loopStart}set loopStart(e){this._source.loopStart=this.toSeconds(e)}get loopEnd(){return this._source.loopEnd}set loopEnd(e){this._source.loopEnd=this.toSeconds(e)}get buffer(){return this._buffer}set buffer(e){this._buffer.set(e)}get loop(){return this._source.loop}set loop(e){this._source.loop=e,this._sourceStarted&&this.cancelStop()}dispose(){return super.dispose(),this._source.onended=null,this._source.disconnect(),this._buffer.dispose(),this.playbackRate.dispose(),this}}function It(s,e){return de(this,void 0,void 0,function*(){const t=e/s.context.sampleRate,n=new ti(1,t,s.context.sampleRate);return new s.constructor(Object.assign(s.get(),{frequency:2/t,detune:0,context:n})).toDestination().start(0),(yield n.render()).getChannelData(0)})}class is extends Yt{constructor(){super(E(is.getDefaults(),arguments,["frequency","type"])),this.name="ToneOscillatorNode",this._oscillator=this.context.createOscillator(),this._internalChannels=[this._oscillator];const e=E(is.getDefaults(),arguments,["frequency","type"]);sn(this._oscillator,this._gainNode),this.type=e.type,this.frequency=new ie({context:this.context,param:this._oscillator.frequency,units:"frequency",value:e.frequency}),this.detune=new ie({context:this.context,param:this._oscillator.detune,units:"cents",value:e.detune}),ce(this,["frequency","detune"])}static getDefaults(){return Object.assign(Yt.getDefaults(),{detune:0,frequency:440,type:"sine"})}start(e){const t=this.toSeconds(e);return this.log("start",t),this._startGain(t),this._oscillator.start(t),this}_stopSource(e){this._oscillator.stop(e)}setPeriodicWave(e){return this._oscillator.setPeriodicWave(e),this}get type(){return this._oscillator.type}set type(e){this._oscillator.type=e}dispose(){return super.dispose(),this.state==="started"&&this.stop(),this._oscillator.disconnect(),this.frequency.dispose(),this.detune.dispose(),this}}class ue extends De{constructor(){super(E(ue.getDefaults(),arguments,["frequency","type"])),this.name="Oscillator",this._oscillator=null;const e=E(ue.getDefaults(),arguments,["frequency","type"]);this.frequency=new fe({context:this.context,units:"frequency",value:e.frequency}),ce(this,"frequency"),this.detune=new fe({context:this.context,units:"cents",value:e.detune}),ce(this,"detune"),this._partials=e.partials,this._partialCount=e.partialCount,this._type=e.type,e.partialCount&&e.type!=="custom"&&(this._type=this.baseType+e.partialCount.toString()),this.phase=e.phase}static getDefaults(){return Object.assign(De.getDefaults(),{detune:0,frequency:440,partialCount:0,partials:[],phase:0,type:"sine"})}_start(e){const t=this.toSeconds(e),n=new is({context:this.context,onended:()=>this.onstop(this)});this._oscillator=n,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(t)}_stop(e){const t=this.toSeconds(e);this._oscillator&&this._oscillator.stop(t)}_restart(e){const t=this.toSeconds(e);return this.log("restart",t),this._oscillator&&this._oscillator.cancelStop(),this._state.cancel(t),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 ue._periodicWaveCache.find(t=>t.phase===this._phase&&Ch(t.partials,this._partials));{const e=ue._periodicWaveCache.find(t=>t.type===this._type&&t.phase===this._phase);return this._partialCount=e?e.partialCount:this._partialCount,e}}get type(){return this._type}set type(e){this._type=e;const t=["sine","square","sawtooth","triangle"].indexOf(e)!==-1;if(this._phase===0&&t)this._wave=void 0,this._partialCount=0,this._oscillator!==null&&(this._oscillator.type=e);else{const n=this._getCachedPeriodicWave();if(Z(n)){const{partials:i,wave:r}=n;this._wave=r,this._partials=i,this._oscillator!==null&&this._oscillator.setPeriodicWave(this._wave)}else{const[i,r]=this._getRealImaginary(e,this._phase),o=this.context.createPeriodicWave(i,r);this._wave=o,this._oscillator!==null&&this._oscillator.setPeriodicWave(this._wave),ue._periodicWaveCache.push({imag:r,partialCount:this._partialCount,partials:this._partials,phase:this._phase,real:i,type:this._type,wave:this._wave}),ue._periodicWaveCache.length>100&&ue._periodicWaveCache.shift()}}}get baseType(){return this._type.replace(this.partialCount.toString(),"")}set baseType(e){this.partialCount&&this._type!=="custom"&&e!=="custom"?this.type=e+this.partialCount:this.type=e}get partialCount(){return this._partialCount}set partialCount(e){mt(e,0);let t=this._type;const n=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);if(n&&(t=n[1]),this._type!=="custom")e===0?this.type=t:this.type=t+e.toString();else{const i=new Float32Array(e);this._partials.forEach((r,o)=>i[o]=r),this._partials=Array.from(i),this.type=this._type}}_getRealImaginary(e,t){let i=2048;const r=new Float32Array(i),o=new Float32Array(i);let a=1;if(e==="custom"){if(a=this._partials.length+1,this._partialCount=this._partials.length,i=a,this._partials.length===0)return[r,o]}else{const c=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(e);c?(a=parseInt(c[2],10)+1,this._partialCount=parseInt(c[2],10),e=c[1],a=Math.max(a,2),i=a):this._partialCount=0,this._partials=[]}for(let c=1;c<i;++c){const l=2/(c*Math.PI);let u;switch(e){case"sine":u=c<=a?1:0,this._partials[c-1]=u;break;case"square":u=c&1?2*l:0,this._partials[c-1]=u;break;case"sawtooth":u=l*(c&1?1:-1),this._partials[c-1]=u;break;case"triangle":c&1?u=2*(l*l)*(c-1>>1&1?-1:1):u=0,this._partials[c-1]=u;break;case"custom":u=this._partials[c-1];break;default:throw new TypeError("Oscillator: invalid type: "+e)}u!==0?(r[c]=-u*Math.sin(t*c),o[c]=u*Math.cos(t*c)):(r[c]=0,o[c]=0)}return[r,o]}_inverseFFT(e,t,n){let i=0;const r=e.length;for(let o=0;o<r;o++)i+=e[o]*Math.cos(o*n)+t[o]*Math.sin(o*n);return i}getInitialValue(){const[e,t]=this._getRealImaginary(this._type,0);let n=0;const i=Math.PI*2,r=32;for(let o=0;o<r;o++)n=Math.max(this._inverseFFT(e,t,o/r*i),n);return Ah(-this._inverseFFT(e,t,this._phase)/n,-1,1)}get partials(){return this._partials.slice(0,this.partialCount)}set partials(e){this._partials=e,this._partialCount=this._partials.length,e.length&&(this.type="custom")}get phase(){return this._phase*(180/Math.PI)}set phase(e){this._phase=e*Math.PI/180,this.type=this._type}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this._oscillator!==null&&this._oscillator.dispose(),this._wave=void 0,this.frequency.dispose(),this.detune.dispose(),this}}ue._periodicWaveCache=[];class jh extends Zt{constructor(){super(...arguments),this.name="AudioToGain",this._norm=new $t({context:this.context,mapping:e=>(e+1)/2}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class Ot extends fe{constructor(){super(Object.assign(E(Ot.getDefaults(),arguments,["value"]))),this.name="Multiply",this.override=!1;const e=E(Ot.getDefaults(),arguments,["value"]);this._mult=this.input=this.output=new ve({context:this.context,minValue:e.minValue,maxValue:e.maxValue}),this.factor=this._param=this._mult.gain,this.factor.setValueAtTime(e.value,0)}static getDefaults(){return Object.assign(fe.getDefaults(),{value:0})}dispose(){return super.dispose(),this._mult.dispose(),this}}class dn extends De{constructor(){super(E(dn.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="AMOscillator",this._modulationScale=new jh({context:this.context}),this._modulationNode=new ve({context:this.context});const e=E(dn.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new ue({context:this.context,detune:e.detune,frequency:e.frequency,onstop:()=>this.onstop(this),phase:e.phase,type:e.type}),this.frequency=this._carrier.frequency,this.detune=this._carrier.detune,this._modulator=new ue({context:this.context,phase:e.phase,type:e.modulationType}),this.harmonicity=new Ot({context:this.context,units:"positive",value:e.harmonicity}),this.frequency.chain(this.harmonicity,this._modulator.frequency),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output),ce(this,["frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(ue.getDefaults(),{harmonicity:1,modulationType:"square"})}_start(e){this._modulator.start(e),this._carrier.start(e)}_stop(e){this._modulator.stop(e),this._carrier.stop(e)}_restart(e){this._modulator.restart(e),this._carrier.restart(e)}get type(){return this._carrier.type}set type(e){this._carrier.type=e}get baseType(){return this._carrier.baseType}set baseType(e){this._carrier.baseType=e}get partialCount(){return this._carrier.partialCount}set partialCount(e){this._carrier.partialCount=e}get modulationType(){return this._modulator.type}set modulationType(e){this._modulator.type=e}get phase(){return this._carrier.phase}set phase(e){this._carrier.phase=e,this._modulator.phase=e}get partials(){return this._carrier.partials}set partials(e){this._carrier.partials=e}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}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}}class pn extends De{constructor(){super(E(pn.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="FMOscillator",this._modulationNode=new ve({context:this.context,gain:0});const e=E(pn.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new ue({context:this.context,detune:e.detune,frequency:0,onstop:()=>this.onstop(this),phase:e.phase,type:e.type}),this.detune=this._carrier.detune,this.frequency=new fe({context:this.context,units:"frequency",value:e.frequency}),this._modulator=new ue({context:this.context,phase:e.phase,type:e.modulationType}),this.harmonicity=new Ot({context:this.context,units:"positive",value:e.harmonicity}),this.modulationIndex=new Ot({context:this.context,units:"positive",value:e.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),ce(this,["modulationIndex","frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(ue.getDefaults(),{harmonicity:1,modulationIndex:2,modulationType:"square"})}_start(e){this._modulator.start(e),this._carrier.start(e)}_stop(e){this._modulator.stop(e),this._carrier.stop(e)}_restart(e){return this._modulator.restart(e),this._carrier.restart(e),this}get type(){return this._carrier.type}set type(e){this._carrier.type=e}get baseType(){return this._carrier.baseType}set baseType(e){this._carrier.baseType=e}get partialCount(){return this._carrier.partialCount}set partialCount(e){this._carrier.partialCount=e}get modulationType(){return this._modulator.type}set modulationType(e){this._modulator.type=e}get phase(){return this._carrier.phase}set phase(e){this._carrier.phase=e,this._modulator.phase=e}get partials(){return this._carrier.partials}set partials(e){this._carrier.partials=e}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this.frequency.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this.modulationIndex.dispose(),this}}class Xt extends De{constructor(){super(E(Xt.getDefaults(),arguments,["frequency","width"])),this.name="PulseOscillator",this._widthGate=new ve({context:this.context,gain:0}),this._thresh=new $t({context:this.context,mapping:t=>t<=0?-1:1});const e=E(Xt.getDefaults(),arguments,["frequency","width"]);this.width=new fe({context:this.context,units:"audioRange",value:e.width}),this._triangle=new ue({context:this.context,detune:e.detune,frequency:e.frequency,onstop:()=>this.onstop(this),phase:e.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),ce(this,["width","frequency","detune"])}static getDefaults(){return Object.assign(De.getDefaults(),{detune:0,frequency:440,phase:0,type:"pulse",width:.2})}_start(e){e=this.toSeconds(e),this._triangle.start(e),this._widthGate.gain.setValueAtTime(1,e)}_stop(e){e=this.toSeconds(e),this._triangle.stop(e),this._widthGate.gain.cancelScheduledValues(e),this._widthGate.gain.setValueAtTime(0,e)}_restart(e){this._triangle.restart(e),this._widthGate.gain.cancelScheduledValues(e),this._widthGate.gain.setValueAtTime(1,e)}get phase(){return this._triangle.phase}set phase(e){this._triangle.phase=e}get type(){return"pulse"}get baseType(){return"pulse"}get partials(){return[]}get partialCount(){return 0}set carrierType(e){this._triangle.type=e}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this._triangle.dispose(),this.width.dispose(),this._widthGate.dispose(),this._thresh.dispose(),this}}class fn extends De{constructor(){super(E(fn.getDefaults(),arguments,["frequency","type","spread"])),this.name="FatOscillator",this._oscillators=[];const e=E(fn.getDefaults(),arguments,["frequency","type","spread"]);this.frequency=new fe({context:this.context,units:"frequency",value:e.frequency}),this.detune=new fe({context:this.context,units:"cents",value:e.detune}),this._spread=e.spread,this._type=e.type,this._phase=e.phase,this._partials=e.partials,this._partialCount=e.partialCount,this.count=e.count,ce(this,["frequency","detune"])}static getDefaults(){return Object.assign(ue.getDefaults(),{count:3,spread:20,type:"sawtooth"})}_start(e){e=this.toSeconds(e),this._forEach(t=>t.start(e))}_stop(e){e=this.toSeconds(e),this._forEach(t=>t.stop(e))}_restart(e){this._forEach(t=>t.restart(e))}_forEach(e){for(let t=0;t<this._oscillators.length;t++)e(this._oscillators[t],t)}get type(){return this._type}set type(e){this._type=e,this._forEach(t=>t.type=e)}get spread(){return this._spread}set spread(e){if(this._spread=e,this._oscillators.length>1){const t=-e/2,n=e/(this._oscillators.length-1);this._forEach((i,r)=>i.detune.value=t+n*r)}}get count(){return this._oscillators.length}set count(e){if(mt(e,1),this._oscillators.length!==e){this._forEach(t=>t.dispose()),this._oscillators=[];for(let t=0;t<e;t++){const n=new ue({context:this.context,volume:-6-e*1.1,type:this._type,phase:this._phase+t/e*360,partialCount:this._partialCount,onstop:t===0?()=>this.onstop(this):H});this.type==="custom"&&(n.partials=this._partials),this.frequency.connect(n.frequency),this.detune.connect(n.detune),n.detune.overridden=!1,n.connect(this.output),this._oscillators[t]=n}this.spread=this._spread,this.state==="started"&&this._forEach(t=>t.start())}}get phase(){return this._phase}set phase(e){this._phase=e,this._forEach((t,n)=>t.phase=this._phase+n/this.count*360)}get baseType(){return this._oscillators[0].baseType}set baseType(e){this._forEach(t=>t.baseType=e),this._type=this._oscillators[0].type}get partials(){return this._oscillators[0].partials}set partials(e){this._partials=e,this._partialCount=this._partials.length,e.length&&(this._type="custom",this._forEach(t=>t.partials=e))}get partialCount(){return this._oscillators[0].partialCount}set partialCount(e){this._partialCount=e,this._forEach(t=>t.partialCount=e),this._type=this._oscillators[0].type}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this._forEach(e=>e.dispose()),this}}class mn extends De{constructor(){super(E(mn.getDefaults(),arguments,["frequency","modulationFrequency"])),this.name="PWMOscillator",this.sourceType="pwm",this._scale=new Ot({context:this.context,value:2});const e=E(mn.getDefaults(),arguments,["frequency","modulationFrequency"]);this._pulse=new Xt({context:this.context,frequency:e.modulationFrequency}),this._pulse.carrierType="sine",this.modulationFrequency=this._pulse.frequency,this._modulator=new ue({context:this.context,detune:e.detune,frequency:e.frequency,onstop:()=>this.onstop(this),phase:e.phase}),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),ce(this,["modulationFrequency","frequency","detune"])}static getDefaults(){return Object.assign(De.getDefaults(),{detune:0,frequency:440,modulationFrequency:.4,phase:0,type:"pwm"})}_start(e){e=this.toSeconds(e),this._modulator.start(e),this._pulse.start(e)}_stop(e){e=this.toSeconds(e),this._modulator.stop(e),this._pulse.stop(e)}_restart(e){this._modulator.restart(e),this._pulse.restart(e)}get type(){return"pwm"}get baseType(){return"pwm"}get partials(){return[]}get partialCount(){return 0}get phase(){return this._modulator.phase}set phase(e){this._modulator.phase=e}asArray(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this._pulse.dispose(),this._scale.dispose(),this._modulator.dispose(),this}}const Vi={am:dn,fat:fn,fm:pn,oscillator:ue,pulse:Xt,pwm:mn};class gn extends De{constructor(){super(E(gn.getDefaults(),arguments,["frequency","type"])),this.name="OmniOscillator";const e=E(gn.getDefaults(),arguments,["frequency","type"]);this.frequency=new fe({context:this.context,units:"frequency",value:e.frequency}),this.detune=new fe({context:this.context,units:"cents",value:e.detune}),ce(this,["frequency","detune"]),this.set(e)}static getDefaults(){return Object.assign(ue.getDefaults(),pn.getDefaults(),dn.getDefaults(),fn.getDefaults(),Xt.getDefaults(),mn.getDefaults())}_start(e){this._oscillator.start(e)}_stop(e){this._oscillator.stop(e)}_restart(e){return this._oscillator.restart(e),this}get type(){let e="";return["am","fm","fat"].some(t=>this._sourceType===t)&&(e=this._sourceType),e+this._oscillator.type}set type(e){e.substr(0,2)==="fm"?(this._createNewOscillator("fm"),this._oscillator=this._oscillator,this._oscillator.type=e.substr(2)):e.substr(0,2)==="am"?(this._createNewOscillator("am"),this._oscillator=this._oscillator,this._oscillator.type=e.substr(2)):e.substr(0,3)==="fat"?(this._createNewOscillator("fat"),this._oscillator=this._oscillator,this._oscillator.type=e.substr(3)):e==="pwm"?(this._createNewOscillator("pwm"),this._oscillator=this._oscillator):e==="pulse"?this._createNewOscillator("pulse"):(this._createNewOscillator("oscillator"),this._oscillator=this._oscillator,this._oscillator.type=e)}get partials(){return this._oscillator.partials}set partials(e){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&(this._oscillator.partials=e)}get partialCount(){return this._oscillator.partialCount}set partialCount(e){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&(this._oscillator.partialCount=e)}set(e){return Reflect.has(e,"type")&&e.type&&(this.type=e.type),super.set(e),this}_createNewOscillator(e){if(e!==this._sourceType){this._sourceType=e;const t=Vi[e],n=this.now();if(this._oscillator){const i=this._oscillator;i.stop(n),this.context.setTimeout(()=>i.dispose(),this.blockTime)}this._oscillator=new t({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(n)}}get phase(){return this._oscillator.phase}set phase(e){this._oscillator.phase=e}get sourceType(){return this._sourceType}set sourceType(e){let t="sine";this._oscillator.type!=="pwm"&&this._oscillator.type!=="pulse"&&(t=this._oscillator.type),e==="fm"?this.type="fm"+t:e==="am"?this.type="am"+t:e==="fat"?this.type="fat"+t:e==="oscillator"?this.type=t:e==="pulse"?this.type="pulse":e==="pwm"&&(this.type="pwm")}_getOscType(e,t){return e instanceof Vi[t]}get baseType(){return this._oscillator.baseType}set baseType(e){!this._getOscType(this._oscillator,"pulse")&&!this._getOscType(this._oscillator,"pwm")&&e!=="pulse"&&e!=="pwm"&&(this._oscillator.baseType=e)}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(e){this._getOscType(this._oscillator,"fat")&&ft(e)&&(this._oscillator.count=e)}get spread(){if(this._getOscType(this._oscillator,"fat"))return this._oscillator.spread}set spread(e){this._getOscType(this._oscillator,"fat")&&ft(e)&&(this._oscillator.spread=e)}get modulationType(){if(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))return this._oscillator.modulationType}set modulationType(e){(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))&&st(e)&&(this._oscillator.modulationType=e)}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(e=1024){return de(this,void 0,void 0,function*(){return It(this,e)})}dispose(){return super.dispose(),this.detune.dispose(),this.frequency.dispose(),this._oscillator.dispose(),this}}function Ur(s,e=1/0){const t=new WeakMap;return function(n,i){Reflect.defineProperty(n,i,{configurable:!0,enumerable:!0,get:function(){return t.get(this)},set:function(r){mt(r,s,e),t.set(this,r)}})}}function ct(s,e=1/0){const t=new WeakMap;return function(n,i){Reflect.defineProperty(n,i,{configurable:!0,enumerable:!0,get:function(){return t.get(this)},set:function(r){mt(this.toSeconds(r),s,e),t.set(this,r)}})}}class _n extends De{constructor(){super(E(_n.getDefaults(),arguments,["url","onload"])),this.name="Player",this._activeSources=new Set;const e=E(_n.getDefaults(),arguments,["url","onload"]);this._buffer=new ne({onload:this._onload.bind(this,e.onload),onerror:e.onerror,reverse:e.reverse,url:e.url}),this.autostart=e.autostart,this._loop=e.loop,this._loopStart=e.loopStart,this._loopEnd=e.loopEnd,this._playbackRate=e.playbackRate,this.fadeIn=e.fadeIn,this.fadeOut=e.fadeOut}static getDefaults(){return Object.assign(De.getDefaults(),{autostart:!1,fadeIn:0,fadeOut:0,loop:!1,loopEnd:0,loopStart:0,onload:H,onerror:H,playbackRate:1,reverse:!1})}load(e){return de(this,void 0,void 0,function*(){return yield this._buffer.load(e),this._onload(),this})}_onload(e=H){e(),this.autostart&&this.start()}_onSourceEnd(e){this.onstop(this),this._activeSources.delete(e),this._activeSources.size===0&&!this._synced&&this._state.getValueAtTime(this.now())==="started"&&(this._state.cancel(this.now()),this._state.setStateAtTime("stopped",this.now()))}start(e,t,n){return super.start(e,t,n),this}_start(e,t,n){this._loop?t=Bt(t,this._loopStart):t=Bt(t,0);const i=this.toSeconds(t),r=n;n=Bt(n,Math.max(this._buffer.duration-i,0));let o=this.toSeconds(n);o=o/this._playbackRate,e=this.toSeconds(e);const a=new hn({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(e+o),this._state.setStateAtTime("stopped",e+o,{implicitEnd:!0})),this._activeSources.add(a),this._loop&&Re(r)?a.start(e,i):a.start(e,i,o-this.toSeconds(this.fadeOut))}_stop(e){const t=this.toSeconds(e);this._activeSources.forEach(n=>n.stop(t))}restart(e,t,n){return super.restart(e,t,n),this}_restart(e,t,n){var i;(i=[...this._activeSources].pop())===null||i===void 0||i.stop(e),this._start(e,t,n)}seek(e,t){const n=this.toSeconds(t);if(this._state.getValueAtTime(n)==="started"){const i=this.toSeconds(e);this._stop(n),this._start(n,i)}return this}setLoopPoints(e,t){return this.loopStart=e,this.loopEnd=t,this}get loopStart(){return this._loopStart}set loopStart(e){this._loopStart=e,this.buffer.loaded&&mt(this.toSeconds(e),0,this.buffer.duration),this._activeSources.forEach(t=>{t.loopStart=e})}get loopEnd(){return this._loopEnd}set loopEnd(e){this._loopEnd=e,this.buffer.loaded&&mt(this.toSeconds(e),0,this.buffer.duration),this._activeSources.forEach(t=>{t.loopEnd=e})}get buffer(){return this._buffer}set buffer(e){this._buffer.set(e)}get loop(){return this._loop}set loop(e){if(this._loop!==e&&(this._loop=e,this._activeSources.forEach(t=>{t.loop=e}),e)){const t=this._state.getNextState("stopped",this.now());t&&this._state.cancel(t.time)}}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate=e;const t=this.now(),n=this._state.getNextState("stopped",t);n&&n.implicitEnd&&(this._state.cancel(n.time),this._activeSources.forEach(i=>i.cancelStop())),this._activeSources.forEach(i=>{i.playbackRate.setValueAtTime(e,t)})}get reverse(){return this._buffer.reverse}set reverse(e){this._buffer.reverse=e}get loaded(){return this._buffer.loaded}dispose(){return super.dispose(),this._activeSources.forEach(e=>e.dispose()),this._activeSources.clear(),this._buffer.dispose(),this}}Be([ct(0)],_n.prototype,"fadeIn",void 0);Be([ct(0)],_n.prototype,"fadeOut",void 0);class it extends Y{constructor(){super(E(it.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="Envelope",this._sig=new fe({context:this.context,value:0}),this.output=this._sig,this.input=void 0;const e=E(it.getDefaults(),arguments,["attack","decay","sustain","release"]);this.attack=e.attack,this.decay=e.decay,this.sustain=e.sustain,this.release=e.release,this.attackCurve=e.attackCurve,this.releaseCurve=e.releaseCurve,this.decayCurve=e.decayCurve}static getDefaults(){return Object.assign(Y.getDefaults(),{attack:.01,attackCurve:"linear",decay:.1,decayCurve:"exponential",release:1,releaseCurve:"exponential",sustain:.5})}get value(){return this.getValueAtTime(this.now())}_getCurve(e,t){if(st(e))return e;{let n;for(n in Fn)if(Fn[n][t]===e)return n;return e}}_setCurve(e,t,n){if(st(n)&&Reflect.has(Fn,n)){const i=Fn[n];Ct(i)?e!=="_decayCurve"&&(this[e]=i[t]):this[e]=i}else if(Ie(n)&&e!=="_decayCurve")this[e]=n;else throw new Error("Envelope: invalid curve: "+n)}get attackCurve(){return this._getCurve(this._attackCurve,"In")}set attackCurve(e){this._setCurve("_attackCurve","In",e)}get releaseCurve(){return this._getCurve(this._releaseCurve,"Out")}set releaseCurve(e){this._setCurve("_releaseCurve","Out",e)}get decayCurve(){return this._getCurve(this._decayCurve,"Out")}set decayCurve(e){this._setCurve("_decayCurve","Out",e)}triggerAttack(e,t=1){this.log("triggerAttack",e,t),e=this.toSeconds(e);let i=this.toSeconds(this.attack);const r=this.toSeconds(this.decay),o=this.getValueAtTime(e);if(o>0){const a=1/i;i=(1-o)/a}if(i<this.sampleTime)this._sig.cancelScheduledValues(e),this._sig.setValueAtTime(t,e);else if(this._attackCurve==="linear")this._sig.linearRampTo(t,i,e);else if(this._attackCurve==="exponential")this._sig.targetRampTo(t,i,e);else{this._sig.cancelAndHoldAtTime(e);let a=this._attackCurve;for(let c=1;c<a.length;c++)if(a[c-1]<=o&&o<=a[c]){a=this._attackCurve.slice(c),a[0]=o;break}this._sig.setValueCurveAtTime(a,e,i,t)}if(r&&this.sustain<1){const a=t*this.sustain,c=e+i;this.log("decay",c),this._decayCurve==="linear"?this._sig.linearRampToValueAtTime(a,r+c):this._sig.exponentialApproachValueAtTime(a,c,r)}return this}triggerRelease(e){this.log("triggerRelease",e),e=this.toSeconds(e);const t=this.getValueAtTime(e);if(t>0){const n=this.toSeconds(this.release);n<this.sampleTime?this._sig.setValueAtTime(0,e):this._releaseCurve==="linear"?this._sig.linearRampTo(0,n,e):this._releaseCurve==="exponential"?this._sig.targetRampTo(0,n,e):(B(Ie(this._releaseCurve),"releaseCurve must be either 'linear', 'exponential' or an array"),this._sig.cancelAndHoldAtTime(e),this._sig.setValueCurveAtTime(this._releaseCurve,e,n,t))}return this}getValueAtTime(e){return this._sig.getValueAtTime(e)}triggerAttackRelease(e,t,n=1){return t=this.toSeconds(t),this.triggerAttack(t,n),this.triggerRelease(t+this.toSeconds(e)),this}cancel(e){return this._sig.cancelScheduledValues(this.toSeconds(e)),this}connect(e,t=0,n=0){return ii(this,e,t,n),this}asArray(e=1024){return de(this,void 0,void 0,function*(){const t=e/this.context.sampleRate,n=new ti(1,t,this.context.sampleRate),i=this.toSeconds(this.attack)+this.toSeconds(this.decay),r=i+this.toSeconds(this.release),o=r*.1,a=r+o,c=new this.constructor(Object.assign(this.get(),{attack:t*this.toSeconds(this.attack)/a,decay:t*this.toSeconds(this.decay)/a,release:t*this.toSeconds(this.release)/a,context:n}));return c._sig.toDestination(),c.triggerAttackRelease(t*(i+o)/a,0),(yield n.render()).getChannelData(0)})}dispose(){return super.dispose(),this._sig.dispose(),this}}Be([ct(0)],it.prototype,"attack",void 0);Be([ct(0)],it.prototype,"decay",void 0);Be([Ur(0,1)],it.prototype,"sustain",void 0);Be([ct(0)],it.prototype,"release",void 0);const Fn=(()=>{let e,t;const n=[];for(e=0;e<128;e++)n[e]=Math.sin(e/127*(Math.PI/2));const i=[],r=6.4;for(e=0;e<127;e++){t=e/127;const p=Math.sin(t*(Math.PI*2)*r-Math.PI/2)+1;i[e]=p/10+t*.83}i[127]=1;const o=[],a=5;for(e=0;e<128;e++)o[e]=Math.ceil(e/127*a)/a;const c=[];for(e=0;e<128;e++)t=e/127,c[e]=.5*(1-Math.cos(Math.PI*t));const l=[];for(e=0;e<128;e++){t=e/127;const p=Math.pow(t,3)*4+.2,f=Math.cos(p*Math.PI*2*t);l[e]=Math.abs(f*(1-t))}function u(p){const f=new Array(p.length);for(let d=0;d<p.length;d++)f[d]=1-p[d];return f}function h(p){return p.slice(0).reverse()}return{bounce:{In:u(l),Out:l},cosine:{In:n,Out:h(n)},exponential:"exponential",linear:"linear",ripple:{In:i,Out:u(i)},sine:{In:c,Out:u(c)},step:{In:o,Out:u(o)}}})();class rt extends Y{constructor(){super(E(rt.getDefaults(),arguments)),this._scheduledEvents=[],this._synced=!1,this._original_triggerAttack=this.triggerAttack,this._original_triggerRelease=this.triggerRelease,this._syncedRelease=t=>this._original_triggerRelease(t);const e=E(rt.getDefaults(),arguments);this._volume=this.output=new Nt({context:this.context,volume:e.volume}),this.volume=this._volume.volume,ce(this,"volume")}static getDefaults(){return Object.assign(Y.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 e=!1;return this._synced||(this._synced=!0,e=!0),e}_syncMethod(e,t){const n=this["_original_"+e]=this[e];this[e]=(...i)=>{const r=i[t],o=this.context.transport.schedule(a=>{i[t]=a,n.apply(this,i)},r);this._scheduledEvents.push(o)}}unsync(){return this._scheduledEvents.forEach(e=>this.context.transport.clear(e)),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(e,t,n,i){const r=this.toSeconds(n),o=this.toSeconds(t);return this.triggerAttack(e,r,i),this.triggerRelease(r+o),this}dispose(){return super.dispose(),this._volume.dispose(),this.unsync(),this._scheduledEvents=[],this}}class _t extends rt{constructor(){super(E(_t.getDefaults(),arguments));const e=E(_t.getDefaults(),arguments);this.portamento=e.portamento,this.onsilence=e.onsilence}static getDefaults(){return Object.assign(rt.getDefaults(),{detune:0,onsilence:H,portamento:0})}triggerAttack(e,t,n=1){this.log("triggerAttack",e,t,n);const i=this.toSeconds(t);return this._triggerEnvelopeAttack(i,n),this.setNote(e,i),this}triggerRelease(e){this.log("triggerRelease",e);const t=this.toSeconds(e);return this._triggerEnvelopeRelease(t),this}setNote(e,t){const n=this.toSeconds(t),i=e instanceof Me?e.toFrequency():e;if(this.portamento>0&&this.getLevelAtTime(n)>.05){const r=this.toSeconds(this.portamento);this.frequency.exponentialRampTo(i,r,n)}else this.frequency.setValueAtTime(i,n);return this}}Be([ct(0)],_t.prototype,"portamento",void 0);class ai extends it{constructor(){super(E(ai.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="AmplitudeEnvelope",this._gainNode=new ve({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}}class Ht extends _t{constructor(){super(E(Ht.getDefaults(),arguments)),this.name="Synth";const e=E(Ht.getDefaults(),arguments);this.oscillator=new gn(Object.assign({context:this.context,detune:e.detune,onstop:()=>this.onsilence(this)},e.oscillator)),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new ai(Object.assign({context:this.context},e.envelope)),this.oscillator.chain(this.envelope,this.output),ce(this,["oscillator","frequency","detune","envelope"])}static getDefaults(){return Object.assign(_t.getDefaults(),{envelope:Object.assign(Ds(it.getDefaults(),Object.keys(Y.getDefaults())),{attack:.005,decay:.1,release:1,sustain:.3}),oscillator:Object.assign(Ds(gn.getDefaults(),[...Object.keys(De.getDefaults()),"frequency","detune"]),{type:"triangle"})})}_triggerEnvelopeAttack(e,t){if(this.envelope.triggerAttack(e,t),this.oscillator.start(e),this.envelope.sustain===0){const n=this.toSeconds(this.envelope.attack),i=this.toSeconds(this.envelope.decay);this.oscillator.stop(e+n+i)}}_triggerEnvelopeRelease(e){this.envelope.triggerRelease(e),this.oscillator.stop(e+this.toSeconds(this.envelope.release))}getLevelAtTime(e){return e=this.toSeconds(e),this.envelope.getValueAtTime(e)}dispose(){return super.dispose(),this.oscillator.dispose(),this.envelope.dispose(),this}}class yn extends Ht{constructor(){super(E(yn.getDefaults(),arguments)),this.name="MembraneSynth",this.portamento=0;const e=E(yn.getDefaults(),arguments);this.pitchDecay=e.pitchDecay,this.octaves=e.octaves,ce(this,["oscillator","envelope"])}static getDefaults(){return At(_t.getDefaults(),Ht.getDefaults(),{envelope:{attack:.001,attackCurve:"exponential",decay:.4,release:1.4,sustain:.01},octaves:10,oscillator:{type:"sine"},pitchDecay:.05})}setNote(e,t){const n=this.toSeconds(t),i=this.toFrequency(e instanceof Me?e.toFrequency():e),r=i*this.octaves;return this.oscillator.frequency.setValueAtTime(r,n),this.oscillator.frequency.exponentialRampToValueAtTime(i,n+this.toSeconds(this.pitchDecay)),this}dispose(){return super.dispose(),this}}Be([Ur(0)],yn.prototype,"octaves",void 0);Be([ct(0)],yn.prototype,"pitchDecay",void 0);const zr=new Set;function ci(s){zr.add(s)}function Gr(s,e){const t=`registerProcessor("${s}", ${e})`;zr.add(t)}const Bh=`
|
|
/**
|
|
* The base AudioWorkletProcessor for use in Tone.js. Works with the {@link ToneAudioWorklet}.
|
|
*/
|
|
class ToneAudioWorkletProcessor extends AudioWorkletProcessor {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
/**
|
|
* If the processor was disposed or not. Keep alive until it's disposed.
|
|
*/
|
|
this.disposed = false;
|
|
/**
|
|
* The number of samples in the processing block
|
|
*/
|
|
this.blockSize = 128;
|
|
/**
|
|
* the sample rate
|
|
*/
|
|
this.sampleRate = sampleRate;
|
|
|
|
this.port.onmessage = (event) => {
|
|
// when it receives a dispose
|
|
if (event.data === "dispose") {
|
|
this.disposed = true;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
`;ci(Bh);const Uh=`
|
|
/**
|
|
* Abstract class for a single input/output processor.
|
|
* has a 'generate' function which processes one sample at a time
|
|
*/
|
|
class SingleIOProcessor extends ToneAudioWorkletProcessor {
|
|
|
|
constructor(options) {
|
|
super(Object.assign(options, {
|
|
numberOfInputs: 1,
|
|
numberOfOutputs: 1
|
|
}));
|
|
/**
|
|
* Holds the name of the parameter and a single value of that
|
|
* parameter at the current sample
|
|
* @type { [name: string]: number }
|
|
*/
|
|
this.params = {}
|
|
}
|
|
|
|
/**
|
|
* Generate an output sample from the input sample and parameters
|
|
* @abstract
|
|
* @param input number
|
|
* @param channel number
|
|
* @param parameters { [name: string]: number }
|
|
* @returns number
|
|
*/
|
|
generate(){}
|
|
|
|
/**
|
|
* Update the private params object with the
|
|
* values of the parameters at the given index
|
|
* @param parameters { [name: string]: Float32Array },
|
|
* @param index number
|
|
*/
|
|
updateParams(parameters, index) {
|
|
for (const paramName in parameters) {
|
|
const param = parameters[paramName];
|
|
if (param.length > 1) {
|
|
this.params[paramName] = parameters[paramName][index];
|
|
} else {
|
|
this.params[paramName] = parameters[paramName][0];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Process a single frame of the audio
|
|
* @param inputs Float32Array[][]
|
|
* @param outputs Float32Array[][]
|
|
*/
|
|
process(inputs, outputs, parameters) {
|
|
const input = inputs[0];
|
|
const output = outputs[0];
|
|
// get the parameter values
|
|
const channelCount = Math.max(input && input.length || 0, output.length);
|
|
for (let sample = 0; sample < this.blockSize; sample++) {
|
|
this.updateParams(parameters, sample);
|
|
for (let channel = 0; channel < channelCount; channel++) {
|
|
const inputSample = input && input.length ? input[channel][sample] : 0;
|
|
output[channel][sample] = this.generate(inputSample, channel, this.params);
|
|
}
|
|
}
|
|
return !this.disposed;
|
|
}
|
|
};
|
|
`;ci(Uh);const zh=`
|
|
/**
|
|
* A multichannel buffer for use within an AudioWorkletProcessor as a delay line
|
|
*/
|
|
class DelayLine {
|
|
|
|
constructor(size, channels) {
|
|
this.buffer = [];
|
|
this.writeHead = []
|
|
this.size = size;
|
|
|
|
// create the empty channels
|
|
for (let i = 0; i < channels; i++) {
|
|
this.buffer[i] = new Float32Array(this.size);
|
|
this.writeHead[i] = 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Push a value onto the end
|
|
* @param channel number
|
|
* @param value number
|
|
*/
|
|
push(channel, value) {
|
|
this.writeHead[channel] += 1;
|
|
if (this.writeHead[channel] > this.size) {
|
|
this.writeHead[channel] = 0;
|
|
}
|
|
this.buffer[channel][this.writeHead[channel]] = value;
|
|
}
|
|
|
|
/**
|
|
* Get the recorded value of the channel given the delay
|
|
* @param channel number
|
|
* @param delay number delay samples
|
|
*/
|
|
get(channel, delay) {
|
|
let readHead = this.writeHead[channel] - Math.floor(delay);
|
|
if (readHead < 0) {
|
|
readHead += this.size;
|
|
}
|
|
return this.buffer[channel][readHead];
|
|
}
|
|
}
|
|
`;ci(zh);const Gh="feedback-comb-filter",Yh=`
|
|
class FeedbackCombFilterWorklet extends SingleIOProcessor {
|
|
|
|
constructor(options) {
|
|
super(options);
|
|
this.delayLine = new DelayLine(this.sampleRate, options.channelCount || 2);
|
|
}
|
|
|
|
static get parameterDescriptors() {
|
|
return [{
|
|
name: "delayTime",
|
|
defaultValue: 0.1,
|
|
minValue: 0,
|
|
maxValue: 1,
|
|
automationRate: "k-rate"
|
|
}, {
|
|
name: "feedback",
|
|
defaultValue: 0.5,
|
|
minValue: 0,
|
|
maxValue: 0.9999,
|
|
automationRate: "k-rate"
|
|
}];
|
|
}
|
|
|
|
generate(input, channel, parameters) {
|
|
const delayedSample = this.delayLine.get(channel, parameters.delayTime * this.sampleRate);
|
|
this.delayLine.push(channel, input + delayedSample * parameters.feedback);
|
|
return delayedSample;
|
|
}
|
|
}
|
|
`;Gr(Gh,Yh);class rs extends rt{constructor(){super(E(rs.getDefaults(),arguments,["voice","options"])),this.name="PolySynth",this._availableVoices=[],this._activeVoices=[],this._voices=[],this._gcTimeout=-1,this._averageActiveVoices=0,this._syncedRelease=i=>this.releaseAll(i);const e=E(rs.getDefaults(),arguments,["voice","options"]);B(!ft(e.voice),"DEPRECATED: The polyphony count is no longer the first argument.");const t=e.voice.getDefaults();this.options=Object.assign(t,e.options),this.voice=e.voice,this.maxPolyphony=e.maxPolyphony,this._dummyVoice=this._getNextAvailableVoice();const n=this._voices.indexOf(this._dummyVoice);this._voices.splice(n,1),this._gcTimeout=this.context.setInterval(this._collectGarbage.bind(this),1)}static getDefaults(){return Object.assign(rt.getDefaults(),{maxPolyphony:32,options:{},voice:Ht})}get activeVoices(){return this._activeVoices.length}_makeVoiceAvailable(e){this._availableVoices.push(e);const t=this._activeVoices.findIndex(n=>n.voice===e);this._activeVoices.splice(t,1)}_getNextAvailableVoice(){if(this._availableVoices.length)return this._availableVoices.shift();if(this._voices.length<this.maxPolyphony){const e=new this.voice(Object.assign(this.options,{context:this.context,onsilence:this._makeVoiceAvailable.bind(this)}));return B(e instanceof _t,"Voice must extend Monophonic class"),e.connect(this.output),this._voices.push(e),e}else fs("Max polyphony exceeded. Note dropped.")}_collectGarbage(){if(this._averageActiveVoices=Math.max(this._averageActiveVoices*.95,this.activeVoices),this._availableVoices.length&&this._voices.length>Math.ceil(this._averageActiveVoices+1)){const e=this._availableVoices.shift(),t=this._voices.indexOf(e);this._voices.splice(t,1),this.context.isOffline||e.dispose()}}_triggerAttack(e,t,n){e.forEach(i=>{const r=new ts(this.context,i).toMidi(),o=this._getNextAvailableVoice();o&&(o.triggerAttack(i,t,n),this._activeVoices.push({midi:r,voice:o,released:!1}),this.log("triggerAttack",i,t))})}_triggerRelease(e,t){e.forEach(n=>{const i=new ts(this.context,n).toMidi(),r=this._activeVoices.find(({midi:o,released:a})=>o===i&&!a);r&&(r.voice.triggerRelease(t),r.released=!0,this.log("triggerRelease",n,t))})}_scheduleEvent(e,t,n,i){B(!this.disposed,"Synth was already disposed"),n<=this.now()?e==="attack"?this._triggerAttack(t,n,i):this._triggerRelease(t,n):this.context.setTimeout(()=>{this.disposed||this._scheduleEvent(e,t,n,i)},n-this.now())}triggerAttack(e,t,n){Array.isArray(e)||(e=[e]);const i=this.toSeconds(t);return this._scheduleEvent("attack",e,i,n),this}triggerRelease(e,t){Array.isArray(e)||(e=[e]);const n=this.toSeconds(t);return this._scheduleEvent("release",e,n),this}triggerAttackRelease(e,t,n,i){const r=this.toSeconds(n);if(this.triggerAttack(e,r,i),Ie(t)){B(Ie(e),"If the duration is an array, the notes must also be an array"),e=e;for(let o=0;o<e.length;o++){const a=t[Math.min(o,t.length-1)],c=this.toSeconds(a);B(c>0,"The duration must be greater than 0"),this.triggerRelease(e[o],r+c)}}else{const o=this.toSeconds(t);B(o>0,"The duration must be greater than 0"),this.triggerRelease(e,r+o)}return this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1),this.context.transport.on("stop",this._syncedRelease),this.context.transport.on("pause",this._syncedRelease),this.context.transport.on("loopEnd",this._syncedRelease)),this}set(e){const t=Ds(e,["onsilence","context"]);return this.options=At(this.options,t),this._voices.forEach(n=>n.set(t)),this._dummyVoice.set(t),this}get(){return this._dummyVoice.get()}releaseAll(e){const t=this.toSeconds(e);return this._activeVoices.forEach(({voice:n})=>{n.triggerRelease(t)}),this}dispose(){return super.dispose(),this._dummyVoice.dispose(),this._voices.forEach(e=>e.dispose()),this._activeVoices=[],this._availableVoices=[],this.context.clearInterval(this._gcTimeout),this}}class vn extends rt{constructor(){super(E(vn.getDefaults(),arguments,["urls","onload","baseUrl"],"urls")),this.name="Sampler",this._activeSources=new Map;const e=E(vn.getDefaults(),arguments,["urls","onload","baseUrl"],"urls"),t={};Object.keys(e.urls).forEach(n=>{const i=parseInt(n,10);if(B(Vn(n)||ft(i)&&isFinite(i),`url key is neither a note or midi pitch: ${n}`),Vn(n)){const r=new Me(this.context,n).toMidi();t[r]=e.urls[n]}else ft(i)&&isFinite(i)&&(t[i]=e.urls[i])}),this._buffers=new ri({urls:t,onload:e.onload,baseUrl:e.baseUrl,onerror:e.onerror}),this.attack=e.attack,this.release=e.release,this.curve=e.curve,this._buffers.loaded&&Promise.resolve().then(e.onload)}static getDefaults(){return Object.assign(rt.getDefaults(),{attack:0,baseUrl:"",curve:"exponential",onload:H,onerror:H,release:.1,urls:{}})}_findClosest(e){let n=0;for(;n<96;){if(this._buffers.has(e+n))return-n;if(this._buffers.has(e-n))return n;n++}throw new Error(`No available buffers for note: ${e}`)}triggerAttack(e,t,n=1){return this.log("triggerAttack",e,t,n),Array.isArray(e)||(e=[e]),e.forEach(i=>{const r=jr(new Me(this.context,i).toFrequency()),o=Math.round(r),a=r-o,c=this._findClosest(o),l=o-c,u=this._buffers.get(l),h=Wr(c+a),p=new hn({url:u,context:this.context,curve:this.curve,fadeIn:this.attack,fadeOut:this.release,playbackRate:h}).connect(this.output);p.start(t,0,u.duration/h,n),Ie(this._activeSources.get(o))||this._activeSources.set(o,[]),this._activeSources.get(o).push(p),p.onended=()=>{if(this._activeSources&&this._activeSources.has(o)){const f=this._activeSources.get(o),d=f.indexOf(p);d!==-1&&f.splice(d,1)}}}),this}triggerRelease(e,t){return this.log("triggerRelease",e,t),Array.isArray(e)||(e=[e]),e.forEach(n=>{const i=new Me(this.context,n).toMidi();if(this._activeSources.has(i)&&this._activeSources.get(i).length){const r=this._activeSources.get(i);t=this.toSeconds(t),r.forEach(o=>{o.stop(t)}),this._activeSources.set(i,[])}}),this}releaseAll(e){const t=this.toSeconds(e);return this._activeSources.forEach(n=>{for(;n.length;)n.shift().stop(t)}),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}triggerAttackRelease(e,t,n,i=1){const r=this.toSeconds(n);return this.triggerAttack(e,r,i),Ie(t)?(B(Ie(e),"notes must be an array when duration is array"),e.forEach((o,a)=>{const c=t[Math.min(a,t.length-1)];this.triggerRelease(o,r+this.toSeconds(c))})):this.triggerRelease(e,r+this.toSeconds(t)),this}add(e,t,n){if(B(Vn(e)||isFinite(e),`note must be a pitch or midi: ${e}`),Vn(e)){const i=new Me(this.context,e).toMidi();this._buffers.add(i,t,n)}else this._buffers.add(e,t,n);return this}get loaded(){return this._buffers.loaded}dispose(){return super.dispose(),this._buffers.dispose(),this._activeSources.forEach(e=>{e.forEach(t=>t.dispose())}),this._activeSources.clear(),this}}Be([ct(0)],vn.prototype,"attack",void 0);Be([ct(0)],vn.prototype,"release",void 0);class os extends Y{constructor(){super(Object.assign(E(os.getDefaults(),arguments,["pan"]))),this.name="Panner",this._panner=this.context.createStereoPanner(),this.input=this._panner,this.output=this._panner;const e=E(os.getDefaults(),arguments,["pan"]);this.pan=new ie({context:this.context,param:this._panner.pan,value:e.pan,minValue:-1,maxValue:1}),this._panner.channelCount=e.channelCount,this._panner.channelCountMode="explicit",ce(this,"pan")}static getDefaults(){return Object.assign(Y.getDefaults(),{pan:0,channelCount:1})}dispose(){return super.dispose(),this._panner.disconnect(),this.pan.dispose(),this}}const Zh="bit-crusher",$h=`
|
|
class BitCrusherWorklet extends SingleIOProcessor {
|
|
|
|
static get parameterDescriptors() {
|
|
return [{
|
|
name: "bits",
|
|
defaultValue: 12,
|
|
minValue: 1,
|
|
maxValue: 16,
|
|
automationRate: 'k-rate'
|
|
}];
|
|
}
|
|
|
|
generate(input, _channel, parameters) {
|
|
const step = Math.pow(0.5, parameters.bits - 1);
|
|
const val = step * Math.floor(input / step + 0.5);
|
|
return val;
|
|
}
|
|
}
|
|
`;Gr(Zh,$h);class le extends Y{constructor(){super(E(le.getDefaults(),arguments,["solo"])),this.name="Solo";const e=E(le.getDefaults(),arguments,["solo"]);this.input=this.output=new ve({context:this.context}),le._allSolos.has(this.context)||le._allSolos.set(this.context,new Set),le._allSolos.get(this.context).add(this),this.solo=e.solo}static getDefaults(){return Object.assign(Y.getDefaults(),{solo:!1})}get solo(){return this._isSoloed()}set solo(e){e?this._addSolo():this._removeSolo(),le._allSolos.get(this.context).forEach(t=>t._updateSolo())}get muted(){return this.input.gain.value===0}_addSolo(){le._soloed.has(this.context)||le._soloed.set(this.context,new Set),le._soloed.get(this.context).add(this)}_removeSolo(){le._soloed.has(this.context)&&le._soloed.get(this.context).delete(this)}_isSoloed(){return le._soloed.has(this.context)&&le._soloed.get(this.context).has(this)}_noSolos(){return!le._soloed.has(this.context)||le._soloed.has(this.context)&&le._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(),le._allSolos.get(this.context).delete(this),this._removeSolo(),this}}le._allSolos=new Map;le._soloed=new Map;class as extends Y{constructor(){super(E(as.getDefaults(),arguments,["pan","volume"])),this.name="PanVol";const e=E(as.getDefaults(),arguments,["pan","volume"]);this._panner=this.input=new os({context:this.context,pan:e.pan,channelCount:e.channelCount}),this.pan=this._panner.pan,this._volume=this.output=new Nt({context:this.context,volume:e.volume}),this.volume=this._volume.volume,this._panner.connect(this._volume),this.mute=e.mute,ce(this,["pan","volume"])}static getDefaults(){return Object.assign(Y.getDefaults(),{mute:!1,pan:0,volume:0,channelCount:1})}get mute(){return this._volume.mute}set mute(e){this._volume.mute=e}dispose(){return super.dispose(),this._panner.dispose(),this.pan.dispose(),this._volume.dispose(),this.volume.dispose(),this}}class wt extends Y{constructor(){super(E(wt.getDefaults(),arguments,["volume","pan"])),this.name="Channel";const e=E(wt.getDefaults(),arguments,["volume","pan"]);this._solo=this.input=new le({solo:e.solo,context:this.context}),this._panVol=this.output=new as({context:this.context,pan:e.pan,volume:e.volume,mute:e.mute,channelCount:e.channelCount}),this.pan=this._panVol.pan,this.volume=this._panVol.volume,this._solo.connect(this._panVol),ce(this,["pan","volume"])}static getDefaults(){return Object.assign(Y.getDefaults(),{pan:0,volume:0,mute:!1,solo:!1,channelCount:1})}get solo(){return this._solo.solo}set solo(e){this._solo.solo=e}get muted(){return this._solo.muted||this.mute}get mute(){return this._panVol.mute}set mute(e){this._panVol.mute=e}_getBus(e){return wt.buses.has(e)||wt.buses.set(e,new ve({context:this.context})),wt.buses.get(e)}send(e,t=0){const n=this._getBus(e),i=new ve({context:this.context,units:"decibels",gain:t});return this.connect(i),i.connect(n),i}receive(e){return this._getBus(e).connect(this),this}dispose(){return super.dispose(),this._panVol.dispose(),this.pan.dispose(),this.volume.dispose(),this._solo.dispose(),this}}wt.buses=new Map;class Xh extends Y{constructor(){super(...arguments),this.name="Listener",this.positionX=new ie({context:this.context,param:this.context.rawContext.listener.positionX}),this.positionY=new ie({context:this.context,param:this.context.rawContext.listener.positionY}),this.positionZ=new ie({context:this.context,param:this.context.rawContext.listener.positionZ}),this.forwardX=new ie({context:this.context,param:this.context.rawContext.listener.forwardX}),this.forwardY=new ie({context:this.context,param:this.context.rawContext.listener.forwardY}),this.forwardZ=new ie({context:this.context,param:this.context.rawContext.listener.forwardZ}),this.upX=new ie({context:this.context,param:this.context.rawContext.listener.upX}),this.upY=new ie({context:this.context,param:this.context.rawContext.listener.upY}),this.upZ=new ie({context:this.context,param:this.context.rawContext.listener.upZ})}static getDefaults(){return Object.assign(Y.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}}ms(s=>{s.listener=new Xh({context:s})});gs(s=>{s.listener.dispose()});qe().transport;qe().destination;qe().destination;qe().listener;qe().draw;qe();var Hh=Object.defineProperty,Qh=Object.getOwnPropertyDescriptor,ys=(s,e,t,n)=>{for(var i=n>1?void 0:n?Qh(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Hh(e,t,i),i};let Qt=class extends Yr{constructor(){super(...arguments),this.octave=2,this.note="",this.synth=new rs().toDestination(),this.raycaster=new Kr,this.scene=new Jr,this.camera=new eo(70,1,.001,10),this.onKeyUp=()=>{},this.noteMap={C:"C#",D:"D#",F:"F#",G:"G#",A:"A#"},this.keyOptions={depth:.1,width:.2,height:.4}}get context(){const s=this.canvas.getContext("2d");return s.imageSmoothingEnabled=!0,s}render(){const s=(e,t)=>{const n=this.canvas.getBoundingClientRect(),i=e-n.left,r=t-n.top,o=i/n.width*2-1,a=-(r/n.height)*2+1;this.findNote(new Fe(o,a))};return Zr`<main>
|
|
<canvas
|
|
@touchstart=${e=>{e.preventDefault();for(const t of e.touches)s(t.clientX,t.clientY)}}
|
|
@touchmove=${e=>e.preventDefault()}
|
|
@touchcancel=${()=>this.onKeyUp()}
|
|
@touchend=${()=>this.onKeyUp()}
|
|
@mousedown=${e=>{e.preventDefault(),s(e.clientX,e.clientY)}}
|
|
@mouseup=${()=>this.onKeyUp()}
|
|
></canvas>
|
|
<div class="controls">
|
|
OCTAVE: ${Ft[this.octave]}
|
|
<button
|
|
?disabled=${this.octave===0}
|
|
@click=${()=>this.octave-=1}
|
|
>
|
|
-
|
|
</button>
|
|
<button
|
|
?disabled=${this.octave===Ft.length-1}
|
|
@click=${()=>this.octave+=1}
|
|
>
|
|
+
|
|
</button>
|
|
</div>
|
|
<div class="note">NOTE: ${this.note}</div>
|
|
</main>`}findNote(s){var n;this.raycaster.setFromCamera(s,this.camera);const e=this.raycaster.intersectObjects(this.scene.children,!0),t=e.length>0?e[0]:null;if((n=t==null?void 0:t.object)!=null&&n.userData&&t.object instanceof Dn){t.object.material.color.set("gray");const{note:i}=t.object.userData;this.playNote(i,r=>{var o;(o=t==null?void 0:t.object)==null||o.material.color.set(r)})}}playNote(s,e){this.note=s;const t=s.includes("#")?"black":"white";this.synth.triggerAttackRelease(s,"8n"),this.onKeyUp=()=>{e(t)}}findNode(s,e){for(const t of e){if(t instanceof Dn)return t;if(t instanceof bs){const n=this.findNode(s,t.children);if(n)return n}}return null}buildPiano(){const s=new bs;for(let e=0;e<Ft.length;e++){const t=this.buildOctave(e,Ft[e]);s.add(t)}s.position.x-=2.5,this.scene.add(s)}buildOctave(s,e){const t=new bs;for(let n=0;n<Ln.length;n++){const i=`${Ln[n]}${e}`,r=this.buildPianoKey(n*.2,i);if(Object.keys(this.noteMap).includes(Ln[n])){const o=`${this.noteMap[Ln[n]]}${e}`,a=this.buildAccidental(n*.2,o);a.castShadow=!0,a.receiveShadow=!1,t.add(a)}r.castShadow=!0,r.receiveShadow=!1,t.add(r)}return t.position.x+=1.4*s,t}buildPianoKey(s,e){const t=new pi(this.keyOptions.width*.8,this.keyOptions.height,this.keyOptions.depth),n=new fi({color:"white"}),i=new Dn(t,n);return i.position.x+=s,i.userData.note=e,i}buildAccidental(s,e){const t=new pi(this.keyOptions.width*.8,this.keyOptions.height*.6,this.keyOptions.depth),n=new fi({color:"black"}),i=new Dn(t,n);return i.position.x+=s+.1,i.position.y+=.08,i.position.z+=.1,i.userData.note=e,i}paint(){this.renderer.render(this.scene,this.camera),this.controls.update()}firstUpdated(){this.camera.position.z=1,this.renderer=new to({antialias:!0,canvas:this.canvas,alpha:!0}),this.controls=new io(this.camera,this.renderer.domElement),this.controls.screenSpacePanning=!0,this.controls.enableKeys=!0;const s=this.offsetWidth||window.innerWidth,e=this.offsetHeight||window.innerHeight;this.renderer.setSize(s,e),this.camera.aspect=s/e,this.camera.updateProjectionMatrix(),this.renderer.setAnimationLoop(()=>this.paint()),this.renderer.setClearColor("red",1);const t=new no(4210752);this.scene.add(t);const n=new so(4210752,100);n.position.set(10,4,.7),n.castShadow=!0,this.scene.add(n),n.shadow.mapSize.width=512,n.shadow.mapSize.height=512,n.shadow.camera.near=.5,n.shadow.camera.far=500,this.buildPiano(),document.addEventListener("keydown",i=>{const r=i.key;r==="z"&&this.octave!=0&&(this.octave-=1),r==="x"&&this.octave!=Ft.length-1&&(this.octave+=1);const o=a=>{this.playNote(`${a}${Ft[this.octave]}`,()=>{})};r==="a"&&o("C"),r==="w"&&o("C#"),r==="s"&&o("D"),r==="E"&&o("D#"),r==="d"&&o("E"),r==="f"&&o("F"),r==="t"&&o("F#"),r==="g"&&o("G"),r==="y"&&o("G#"),r==="h"&&o("A"),r==="u"&&o("A#"),r==="j"&&o("B"),r==="k"&&o("C"),r==="o"&&o("C#"),r==="l"&&o("D"),r==="p"&&o("D#")},!1),window.addEventListener("resize",()=>{const i=this.offsetWidth||window.innerWidth,r=this.offsetHeight||window.innerHeight;this.renderer.setSize(i,r),this.camera.aspect=i/r,this.camera.updateProjectionMatrix()},!1)}};Qt.styles=$r`
|
|
main {
|
|
width: 100%;
|
|
height: 100vh;
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
-moz-user-select: none;
|
|
position: relative;
|
|
}
|
|
canvas {
|
|
width: 100%;
|
|
height: 100%;
|
|
z-index: 0;
|
|
display: block;
|
|
}
|
|
.controls {
|
|
z-index: 1;
|
|
position: absolute;
|
|
color: white;
|
|
font-size: 18px;
|
|
right: 10px;
|
|
top: 10px;
|
|
}
|
|
.note {
|
|
z-index: 1;
|
|
position: absolute;
|
|
color: white;
|
|
font-size: 18px;
|
|
left: 10px;
|
|
top: 10px;
|
|
}
|
|
`;ys([Hr("canvas")],Qt.prototype,"canvas",2);ys([Fi()],Qt.prototype,"octave",2);ys([Fi()],Qt.prototype,"note",2);Qt=ys([Xr("piano-component")],Qt);const Ln=["C","D","E","F","G","A","B"],Ft=[2,3,4,5];export{Qt as PianoComponent};
|