Files
p5js/js/addons/p5.sound.min.js
Jürg Hallenbarter 10c9cad0a6 init
2026-04-01 06:34:17 +00:00

8 lines
224 KiB
JavaScript

!function(){"use strict";const t="15.0.2",e=(t,e,n)=>({endTime:e,insertTime:n,type:"exponentialRampToValue",value:t}),n=(t,e,n)=>({endTime:e,insertTime:n,type:"linearRampToValue",value:t}),s=(t,e)=>({startTime:e,type:"setValue",value:t}),i=(t,e,n)=>({duration:n,startTime:e,type:"setValueCurve",values:t}),o=(t,e,{startTime:n,target:s,timeConstant:i})=>s+(e-s)*Math.exp((n-t)/i),r=t=>"exponentialRampToValue"===t.type,a=t=>"linearRampToValue"===t.type,c=t=>r(t)||a(t),h=t=>"setValue"===t.type,u=t=>"setValueCurve"===t.type,l=(t,e,n,s)=>{const i=t[e];return void 0===i?s:c(i)||h(i)?i.value:u(i)?i.values[i.values.length-1]:o(n,l(t,e-1,i.startTime,s),i)},d=(t,e,n,s,i)=>void 0===n?[s.insertTime,i]:c(n)?[n.endTime,n.value]:h(n)?[n.startTime,n.value]:u(n)?[n.startTime+n.duration,n.values[n.values.length-1]]:[n.startTime,l(t,e-1,n.startTime,i)],p=t=>"cancelAndHold"===t.type,f=t=>"cancelScheduledValues"===t.type,m=t=>p(t)||f(t)?t.cancelTime:r(t)||a(t)?t.endTime:t.startTime,_=(t,e,n,{endTime:s,value:i})=>n===i?i:0<n&&0<i||n<0&&i<0?n*(i/n)**((t-e)/(s-e)):0,g=(t,e,n,{endTime:s,value:i})=>n+(t-e)/(s-e)*(i-n),v=(t,{duration:e,startTime:n,values:s})=>((t,e)=>{const n=Math.floor(e),s=Math.ceil(e);return n===s?t[n]:(1-(e-n))*t[n]+(1-(s-e))*t[s]})(s,(t-n)/e*(s.length-1)),y=t=>"setTarget"===t.type;class x{constructor(t){this._automationEvents=[],this._currenTime=0,this._defaultValue=t}[Symbol.iterator](){return this._automationEvents[Symbol.iterator]()}add(t){const o=m(t);if(p(t)||f(t)){const a=this._automationEvents.findIndex((e=>f(t)&&u(e)?e.startTime+e.duration>=o:m(e)>=o)),h=this._automationEvents[a];if(-1!==a&&(this._automationEvents=this._automationEvents.slice(0,a)),p(t)){const t=this._automationEvents[this._automationEvents.length-1];if(void 0!==h&&c(h)){if(void 0!==t&&y(t))throw new Error("The internal list is malformed.");const s=void 0===t?h.insertTime:u(t)?t.startTime+t.duration:m(t),i=void 0===t?this._defaultValue:u(t)?t.values[t.values.length-1]:t.value,a=r(h)?_(o,s,i,h):g(o,s,i,h),c=r(h)?e(a,o,this._currenTime):n(a,o,this._currenTime);this._automationEvents.push(c)}if(void 0!==t&&y(t)&&this._automationEvents.push(s(this.getValue(o),o)),void 0!==t&&u(t)&&t.startTime+t.duration>o){const e=o-t.startTime,n=(t.values.length-1)/t.duration,s=Math.max(2,1+Math.ceil(e*n)),r=e/(s-1)*n,a=t.values.slice(0,s);if(r<1)for(let e=1;e<s;e+=1){const n=r*e%1;a[e]=t.values[e-1]*(1-n)+t.values[e]*n}this._automationEvents[this._automationEvents.length-1]=i(a,t.startTime,e)}}}else{const s=this._automationEvents.findIndex((t=>m(t)>o)),i=-1===s?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[s-1];if(void 0!==i&&u(i)&&m(i)+i.duration>o)return!1;const c=r(t)?e(t.value,t.endTime,this._currenTime):a(t)?n(t.value,o,this._currenTime):t;if(-1===s)this._automationEvents.push(c);else{if(u(t)&&o+t.duration>m(this._automationEvents[s]))return!1;this._automationEvents.splice(s,0,c)}}return!0}flush(t){const e=this._automationEvents.findIndex((e=>m(e)>t));if(e>1){const t=this._automationEvents.slice(e-1),n=t[0];y(n)&&t.unshift(s(l(this._automationEvents,e-2,n.startTime,this._defaultValue),n.startTime)),this._automationEvents=t}}getValue(t){if(0===this._automationEvents.length)return this._defaultValue;const e=this._automationEvents.findIndex((e=>m(e)>t)),n=this._automationEvents[e],s=(-1===e?this._automationEvents.length:e)-1,i=this._automationEvents[s];if(void 0!==i&&y(i)&&(void 0===n||!c(n)||n.insertTime>t))return o(t,l(this._automationEvents,s-1,i.startTime,this._defaultValue),i);if(void 0!==i&&h(i)&&(void 0===n||!c(n)))return i.value;if(void 0!==i&&u(i)&&(void 0===n||!c(n)||i.startTime+i.duration>t))return t<i.startTime+i.duration?v(t,i):i.values[i.values.length-1];if(void 0!==i&&c(i)&&(void 0===n||!c(n)))return i.value;if(void 0!==n&&r(n)){const[e,o]=d(this._automationEvents,s,i,n,this._defaultValue);return _(t,e,o,n)}if(void 0!==n&&a(n)){const[e,o]=d(this._automationEvents,s,i,n,this._defaultValue);return g(t,e,o,n)}return this._defaultValue}}const w=new WeakSet,T=new WeakMap,b=new WeakMap,C=new WeakMap,A=new WeakMap,S=new WeakMap,k=new WeakMap,O=new WeakMap,M=new WeakMap,D=new WeakMap,I={construct:()=>I},E=/^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]*);?/,R=(t,e)=>{const n=[];let s=t.replace(/^[\s]+/,""),i=s.match(E);for(;null!==i;){const t=i[1].slice(1,-1),o=i[0].replace(/([\s]+)?;?$/,"").replace(t,new URL(t,e).toString());n.push(o),s=s.slice(i[0].length).replace(/^[\s]+/,""),i=s.match(E)}return[n.join(";"),s]},N=t=>{if(void 0!==t&&!Array.isArray(t))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},V=t=>{if(!(t=>{try{new new Proxy(t,I)}catch{return!1}return!0})(t))throw new TypeError("The given value for processorCtor should be a constructor.");if(null===t.prototype||"object"!=typeof t.prototype)throw new TypeError("The given value for processorCtor should have a prototype.")},P=(t,e)=>{const n=t.get(e);if(void 0===n)throw new Error("A value with the given key could not be found.");return n},F=(t,e)=>{const n=Array.from(t).filter(e);if(n.length>1)throw Error("More than one element was found.");if(0===n.length)throw Error("No element was found.");const[s]=n;return t.delete(s),s},q=(t,e,n,s)=>{const i=P(t,e),o=F(i,(t=>t[0]===n&&t[1]===s));return 0===i.size&&t.delete(e),o},B=t=>P(k,t),W=t=>{if(w.has(t))throw new Error("The AudioNode is already stored.");w.add(t),B(t).forEach((t=>t(!0)))},j=t=>"port"in t,z=t=>{if(!w.has(t))throw new Error("The AudioNode is not stored.");w.delete(t),B(t).forEach((t=>t(!1)))},L=(t,e)=>{!j(t)&&e.every((t=>0===t.size))&&z(t)},U={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},X=(t,e)=>t.context===e,Y=t=>{try{t.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0},Z=()=>new DOMException("","IndexSizeError"),G=t=>{var e;t.getChannelData=(e=t.getChannelData,n=>{try{return e.call(t,n)}catch(t){if(12===t.code)throw Z();throw t}})},$={numberOfChannels:1},H=-34028234663852886e22,Q=-H,J=t=>w.has(t),K={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},tt=t=>P(T,t),et=t=>P(C,t),nt=(t,e)=>{const{activeInputs:n}=tt(t);n.forEach((n=>n.forEach((([n])=>{e.includes(t)||nt(n,[...e,t])}))));const s=(t=>"playbackRate"in t)(t)?[t.playbackRate]:j(t)?Array.from(t.parameters.values()):(t=>"frequency"in t&&"gain"in t)(t)?[t.Q,t.detune,t.frequency,t.gain]:(t=>"offset"in t)(t)?[t.offset]:(t=>!("frequency"in t)&&"gain"in t)(t)?[t.gain]:(t=>"detune"in t&&"frequency"in t)(t)?[t.detune,t.frequency]:(t=>"pan"in t)(t)?[t.pan]:[];for(const t of s){const n=et(t);void 0!==n&&n.activeInputs.forEach((([t])=>nt(t,e)))}J(t)&&z(t)},st=t=>{nt(t.destination,[])},it=t=>"context"in t,ot=t=>it(t[0]),rt=(t,e,n,s)=>{for(const e of t)if(n(e)){if(s)return!1;throw Error("The set contains at least one similar element.")}return t.add(e),!0},at=(t,e,[n,s],i)=>{rt(t,[e,n,s],(t=>t[0]===e&&t[1]===n),i)},ct=(t,[e,n,s],i)=>{const o=t.get(e);void 0===o?t.set(e,new Set([[n,s]])):rt(o,[n,s],(t=>t[0]===n),i)},ht=t=>"inputs"in t,ut=(t,e,n,s)=>{if(ht(e)){const i=e.inputs[s];return t.connect(i,n,0),[i,n,0]}return t.connect(e,n,s),[e,n,s]},lt=(t,e,n)=>{for(const s of t)if(s[0]===e&&s[1]===n)return t.delete(s),s;return null},dt=(t,e)=>{if(!B(t).delete(e))throw new Error("Missing the expected event listener.")},pt=(t,e,n)=>{const s=P(t,e),i=F(s,(t=>t[0]===n));return 0===s.size&&t.delete(e),i},ft=(t,e,n,s)=>{ht(e)?t.disconnect(e.inputs[s],n,0):t.disconnect(e,n,s)},mt=t=>P(b,t),_t=t=>P(A,t),gt=t=>O.has(t),vt=t=>!w.has(t),yt=(t,e)=>new Promise((n=>{if(null!==e)n(!0);else{const e=t.createScriptProcessor(256,1,1),s=t.createGain(),i=t.createBuffer(1,2,44100),o=i.getChannelData(0);o[0]=1,o[1]=1;const r=t.createBufferSource();r.buffer=i,r.loop=!0,r.connect(e).connect(t.destination),r.connect(s),r.disconnect(s),e.onaudioprocess=s=>{const i=s.inputBuffer.getChannelData(0);Array.prototype.some.call(i,(t=>1===t))?n(!0):n(!1),r.stop(),e.onaudioprocess=null,r.disconnect(e),e.disconnect(t.destination)},r.start()}})),xt=(t,e)=>{const n=new Map;for(const e of t)for(const t of e){const e=n.get(t);n.set(t,void 0===e?1:e+1)}n.forEach(((t,n)=>e(n,t)))},wt=t=>"context"in t,Tt=(t,e,n,s)=>{const{activeInputs:i,passiveInputs:o}=et(e),{outputs:r}=tt(t),a=B(t),c=r=>{const a=mt(t),c=_t(e);if(r){const e=pt(o,t,n);at(i,t,e,!1),s||gt(t)||a.connect(c,n)}else{const e=((t,e,n)=>F(t,(t=>t[0]===e&&t[1]===n)))(i,t,n);ct(o,e,!1),s||gt(t)||a.disconnect(c,n)}};return!!rt(r,[e,n],(t=>t[0]===e&&t[1]===n),!0)&&(a.add(c),J(t)?at(i,t,[n,c],!0):ct(o,[t,n,c],!0),!0)},bt=(t,e,n,s,i)=>{const[o,r]=((t,e,n,s)=>{const{activeInputs:i,passiveInputs:o}=tt(e),r=lt(i[s],t,n);if(null===r)return[q(o,t,n,s)[2],!1];return[r[2],!0]})(t,n,s,i);if(null!==o&&(dt(t,o),!r||e||gt(t)||ft(mt(t),mt(n),s,i)),J(n)){const{activeInputs:t}=tt(n);L(n,t)}},Ct=(t,e,n,s)=>{const[i,o]=((t,e,n)=>{const{activeInputs:s,passiveInputs:i}=et(e),o=lt(s,t,n);if(null===o)return[pt(i,t,n)[1],!1];return[o[2],!0]})(t,n,s);null!==i&&(dt(t,i),!o||e||gt(t)||mt(t).disconnect(_t(n),s))};class At{constructor(t){this._map=new Map(t)}get size(){return this._map.size}entries(){return this._map.entries()}forEach(t,e=null){return this._map.forEach(((n,s)=>t.call(e,n,s,this)))}get(t){return this._map.get(t)}has(t){return this._map.has(t)}keys(){return this._map.keys()}values(){return this._map.values()}}const St={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:1,numberOfOutputs:1,parameterData:{},processorOptions:{}};function kt(t,e,n,s,i){if("function"==typeof t.copyFromChannel)0===e[n].byteLength&&(e[n]=new Float32Array(128)),t.copyFromChannel(e[n],s,i);else{const o=t.getChannelData(s);if(0===e[n].byteLength)e[n]=o.slice(i,i+128);else{const t=new Float32Array(o.buffer,i*Float32Array.BYTES_PER_ELEMENT,128);e[n].set(t)}}}const Ot=(t,e,n,s,i)=>{"function"==typeof t.copyToChannel?0!==e[n].byteLength&&t.copyToChannel(e[n],s,i):0!==e[n].byteLength&&t.getChannelData(s).set(e[n],i)},Mt=(t,e)=>{const n=[];for(let s=0;s<t;s+=1){const t=[],i="number"==typeof e?e:e[s];for(let e=0;e<i;e+=1)t.push(new Float32Array(128));n.push(t)}return n},Dt=async(t,e,n,s,i,o,r)=>{const a=null===e?128*Math.ceil(t.context.length/128):e.length,c=s.channelCount*s.numberOfInputs,h=i.reduce(((t,e)=>t+e),0),u=0===h?null:n.createBuffer(h,a,n.sampleRate);if(void 0===o)throw new Error("Missing the processor constructor.");const l=tt(t),d=await((t,e)=>{const n=P(D,t),s=mt(e);return P(n,s)})(n,t),p=Mt(s.numberOfInputs,s.channelCount),f=Mt(s.numberOfOutputs,i),m=Array.from(t.parameters.keys()).reduce(((t,e)=>({...t,[e]:new Float32Array(128)})),{});for(let h=0;h<a;h+=128){if(s.numberOfInputs>0&&null!==e)for(let t=0;t<s.numberOfInputs;t+=1)for(let n=0;n<s.channelCount;n+=1)kt(e,p[t],n,n,h);void 0!==o.parameterDescriptors&&null!==e&&o.parameterDescriptors.forEach((({name:t},n)=>{kt(e,m,t,c+n,h)}));for(let t=0;t<s.numberOfInputs;t+=1)for(let e=0;e<i[t];e+=1)0===f[t][e].byteLength&&(f[t][e]=new Float32Array(128));try{const t=p.map(((t,e)=>0===l.activeInputs[e].size?[]:t)),e=r(h/n.sampleRate,n.sampleRate,(()=>d.process(t,f,m)));if(null!==u)for(let t=0,e=0;t<s.numberOfOutputs;t+=1){for(let n=0;n<i[t];n+=1)Ot(u,f[t],n,e+n,h);e+=i[t]}if(!e)break}catch(e){t.dispatchEvent(new ErrorEvent("processorerror",{colno:e.colno,filename:e.filename,lineno:e.lineno,message:e.message}));break}}return u},It={Q:1,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:350,gain:0,type:"lowpass"},Et={channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6},Rt={channelCount:6,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:6},Nt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",offset:1},Vt={buffer:null,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",disableNormalization:!1},Pt=t=>{const{port1:e,port2:n}=new MessageChannel;return new Promise((s=>{const i=()=>{n.onmessage=null,e.close(),n.close(),s()};n.onmessage=()=>i();try{e.postMessage(t,[t])}catch{}finally{i()}}))},Ft={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",delayTime:0,maxDelayTime:1},qt=(t,e,n)=>{const s=e[n];if(void 0===s)throw t();return s},Bt={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},Wt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},jt=()=>new DOMException("","InvalidStateError"),zt=()=>new DOMException("","InvalidAccessError"),Lt={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},Ut=(t,e,n,s,i,o,r,a,c,h,u)=>{const l=h.length;let d=a;for(let a=0;a<l;a+=1){let l=n[0]*h[a];for(let e=1;e<i;e+=1){const s=d-e&c-1;l+=n[e]*o[s],l-=t[e]*r[s]}for(let t=i;t<s;t+=1)l+=n[t]*o[d-t&c-1];for(let n=i;n<e;n+=1)l-=t[n]*r[d-n&c-1];o[d]=h[a],r[d]=l,d=d+1&c-1,u[a]=l}return d},Xt={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers"},Yt=t=>{const e=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{const n=t.decodeAudioData(e.buffer,(()=>{}));return void 0!==n&&(n.catch((()=>{})),!0)}catch{}return!1},Zt=(t,e,n)=>{const s=e[n];void 0!==s&&s!==t[n]&&(t[n]=s)},Gt=(t,e)=>{Zt(t,e,"channelCount"),Zt(t,e,"channelCountMode"),Zt(t,e,"channelInterpretation")},$t=t=>"function"==typeof t.getFloatTimeDomainData,Ht=(t,e,n)=>{const s=e[n];void 0!==s&&s!==t[n].value&&(t[n].value=s)},Qt=t=>{t.start=(e=>(n=0,s=0,i)=>{if("number"==typeof i&&i<0||s<0||n<0)throw new RangeError("The parameters can't be negative.");e.call(t,n,s,i)})(t.start)},Jt=t=>{var e;t.stop=(e=t.stop,(n=0)=>{if(n<0)throw new RangeError("The parameter can't be negative.");e.call(t,n)})},Kt=(t,e)=>null===t?512:Math.max(512,Math.min(16384,Math.pow(2,Math.round(Math.log2(t*e))))),te=async(t,e)=>{const n=await(t=>new Promise(((e,n)=>{const{port1:s,port2:i}=new MessageChannel;s.onmessage=({data:t})=>{s.close(),i.close(),e(t)},s.onmessageerror=({data:t})=>{s.close(),i.close(),n(t)},i.postMessage(t)})))(e);return new t(n)},ee=(t,e)=>{const n=t.createBiquadFilter();return Gt(n,e),Ht(n,e,"Q"),Ht(n,e,"detune"),Ht(n,e,"frequency"),Ht(n,e,"gain"),Zt(n,e,"type"),n},ne=(t,e)=>{const n=t.createChannelSplitter(e.numberOfOutputs);return Gt(n,e),(t=>{const e=t.numberOfOutputs;Object.defineProperty(t,"channelCount",{get:()=>e,set:t=>{if(t!==e)throw jt()}}),Object.defineProperty(t,"channelCountMode",{get:()=>"explicit",set:t=>{if("explicit"!==t)throw jt()}}),Object.defineProperty(t,"channelInterpretation",{get:()=>"discrete",set:t=>{if("discrete"!==t)throw jt()}})})(n),n},se=(t,e)=>(t.connect=e.connect.bind(e),t.disconnect=e.disconnect.bind(e),t),ie=(t,e)=>{const n=t.createDelay(e.maxDelayTime);return Gt(n,e),Ht(n,e,"delayTime"),n},oe=(t,e)=>{const n=t.createGain();return Gt(n,e),Ht(n,e,"gain"),n};function re(t,e){const n=e[0]*e[0]+e[1]*e[1];return[(t[0]*e[0]+t[1]*e[1])/n,(t[1]*e[0]-t[0]*e[1])/n]}function ae(t,e){let n=[0,0];for(let o=t.length-1;o>=0;o-=1)i=e,n=[(s=n)[0]*i[0]-s[1]*i[1],s[0]*i[1]+s[1]*i[0]],n[0]+=t[o];var s,i;return n}const ce=(t,e,n,s)=>t.createScriptProcessor(e,n,s),he=()=>new DOMException("","NotSupportedError"),ue={numberOfChannels:1},le={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,periodicWave:void 0,type:"sine"},de={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},pe={disableNormalization:!1},fe={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},me={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},_e=(t,e,n)=>void 0===t.copyFromChannel?t.getChannelData(n)[0]:(t.copyFromChannel(e,n),e[0]),ge=t=>{if(null===t)return!1;const e=t.length;return e%2!=0?0!==t[Math.floor(e/2)]:t[e/2-1]+t[e/2]!==0},ve=(t,e,n,s)=>{let i=t;for(;!i.hasOwnProperty(e);)i=Object.getPrototypeOf(i);const{get:o,set:r}=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,{get:n(o),set:s(r)})},ye=(t,e,n)=>{try{t.setValueAtTime(e,n)}catch(s){if(9!==s.code)throw s;ye(t,e,n+1e-7)}},xe=t=>{const e=t.createOscillator();try{e.start(-1)}catch(t){return t instanceof RangeError}return!1},we=t=>{const e=t.createBuffer(1,1,44100),n=t.createBufferSource();n.buffer=e,n.start(),n.stop();try{return n.stop(),!0}catch{return!1}},Te=t=>{const e=t.createOscillator();try{e.stop(-1)}catch(t){return t instanceof RangeError}return!1},be=(t,e)=>{const n=e.createGain();t.connect(n);const s=(e=>()=>{e.call(t,n),t.removeEventListener("ended",s)})(t.disconnect);t.addEventListener("ended",s),se(t,n),t.stop=(e=>{let s=!1;return(i=0)=>{if(s)try{e.call(t,i)}catch{n.gain.setValueAtTime(0,i)}else e.call(t,i),s=!0}})(t.stop)},Ce=(t,e)=>n=>{const s={value:t};return Object.defineProperties(n,{currentTarget:s,target:s}),"function"==typeof e?e.call(t,n):e.handleEvent.call(t,n)},Ae=(t=>(e,n,[s,i,o],r)=>{t(e[i],[n,s,o],(t=>t[0]===n&&t[1]===s),r)})(rt),Se=(t=>(e,n,[s,i,o],r)=>{const a=e.get(s);void 0===a?e.set(s,new Set([[i,n,o]])):t(a,[i,n,o],(t=>t[0]===i&&t[1]===n),r)})(rt),ke=(t=>(e,n,s,i)=>t(e[i],(t=>t[0]===n&&t[1]===s)))(F),Oe=new WeakMap,Me=(t=>e=>{var n;return null!==(n=t.get(e))&&void 0!==n?n:0})(Oe),De=(Ie=new Map,Ee=new WeakMap,(t,e)=>{const n=Ee.get(t);if(void 0!==n)return n;const s=Ie.get(t);if(void 0!==s)return s;try{const n=e();return n instanceof Promise?(Ie.set(t,n),n.catch((()=>!1)).then((e=>(Ie.delete(t),Ee.set(t,e),e)))):(Ee.set(t,n),n)}catch{return Ee.set(t,!1),!1}});var Ie,Ee;const Re="undefined"==typeof window?null:window,Ne=((t,e)=>(n,s)=>{const i=n.createAnalyser();if(Gt(i,s),!(s.maxDecibels>s.minDecibels))throw e();return Zt(i,s,"fftSize"),Zt(i,s,"maxDecibels"),Zt(i,s,"minDecibels"),Zt(i,s,"smoothingTimeConstant"),t($t,(()=>$t(i)))||(t=>{t.getFloatTimeDomainData=e=>{const n=new Uint8Array(e.length);t.getByteTimeDomainData(n);const s=Math.max(n.length,t.fftSize);for(let t=0;t<s;t+=1)e[t]=.0078125*(n[t]-128);return e}})(i),i})(De,Z),Ve=(t=>e=>{const n=t(e);if(null===n.renderer)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return n.renderer})(tt),Pe=((t,e,n)=>async(s,i,o)=>{const r=t(s);await Promise.all(r.activeInputs.map(((t,r)=>Array.from(t).map((async([t,a])=>{const c=e(t),h=await c.render(t,i),u=s.context.destination;n(t)||s===u&&n(s)||h.connect(o,a,r)})))).reduce(((t,e)=>[...t,...e]),[]))})(tt,Ve,gt),Fe=((t,e,n)=>()=>{const s=new WeakMap;return{render(i,o){const r=s.get(o);return void 0!==r?Promise.resolve(r):(async(i,o)=>{let r=e(i);if(!X(r,o)){const e={channelCount:r.channelCount,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,fftSize:r.fftSize,maxDecibels:r.maxDecibels,minDecibels:r.minDecibels,smoothingTimeConstant:r.smoothingTimeConstant};r=t(o,e)}return s.set(o,r),await n(i,o,r),r})(i,o)}}})(Ne,mt,Pe),qe=(Be=S,t=>{const e=Be.get(t);if(void 0===e)throw jt();return e});var Be;const We=(t=>null===t?null:t.hasOwnProperty("OfflineAudioContext")?t.OfflineAudioContext:t.hasOwnProperty("webkitOfflineAudioContext")?t.webkitOfflineAudioContext:null)(Re),je=(t=>e=>null!==t&&e instanceof t)(We),ze=new WeakMap,Le=(t=>class{constructor(t){this._nativeEventTarget=t,this._listeners=new WeakMap}addEventListener(e,n,s){if(null!==n){let i=this._listeners.get(n);void 0===i&&(i=t(this,n),"function"==typeof n&&this._listeners.set(n,i)),this._nativeEventTarget.addEventListener(e,i,s)}}dispatchEvent(t){return this._nativeEventTarget.dispatchEvent(t)}removeEventListener(t,e,n){const s=null===e?void 0:this._listeners.get(e);this._nativeEventTarget.removeEventListener(t,void 0===s?null:s,n)}})(Ce),Ue=(t=>null===t?null:t.hasOwnProperty("AudioContext")?t.AudioContext:t.hasOwnProperty("webkitAudioContext")?t.webkitAudioContext:null)(Re),Xe=(t=>e=>null!==t&&e instanceof t)(Ue),Ye=(t=>e=>null!==t&&"function"==typeof t.AudioNode&&e instanceof t.AudioNode)(Re),Ze=(t=>e=>null!==t&&"function"==typeof t.AudioParam&&e instanceof t.AudioParam)(Re),Ge=(t=>null===t?null:t.hasOwnProperty("AudioWorkletNode")?t.AudioWorkletNode:null)(Re),$e=((t,e,n,s,i,o,r,a,c,h,u,l,d,p,f,m)=>class extends h{constructor(e,s,i,o){super(i),this._context=e,this._nativeAudioNode=i;const r=u(e);l(r)&&!0!==n(yt,(()=>yt(r,m)))&&(t=>{const e=new Map;t.connect=(t=>(n,s=0,i=0)=>{const o=wt(n)?t(n,s,i):t(n,s),r=e.get(n);return void 0===r?e.set(n,[{input:i,output:s}]):r.every((t=>t.input!==i||t.output!==s))&&r.push({input:i,output:s}),o})(t.connect.bind(t)),t.disconnect=(n=>(s,i,o)=>{if(n.apply(t),void 0===s)e.clear();else if("number"==typeof s)for(const[t,n]of e){const i=n.filter((t=>t.output!==s));0===i.length?e.delete(t):e.set(t,i)}else if(e.has(s))if(void 0===i)e.delete(s);else{const t=e.get(s);if(void 0!==t){const n=t.filter((t=>t.output!==i&&(t.input!==o||void 0===o)));0===n.length?e.delete(s):e.set(s,n)}}for(const[n,s]of e)s.forEach((e=>{wt(n)?t.connect(n,e.output,e.input):t.connect(n,e.output)}))})(t.disconnect)})(i),b.set(this,i),k.set(this,new Set),"closed"!==e.state&&s&&W(this),t(this,o,i)}get channelCount(){return this._nativeAudioNode.channelCount}set channelCount(t){this._nativeAudioNode.channelCount=t}get channelCountMode(){return this._nativeAudioNode.channelCountMode}set channelCountMode(t){this._nativeAudioNode.channelCountMode=t}get channelInterpretation(){return this._nativeAudioNode.channelInterpretation}set channelInterpretation(t){this._nativeAudioNode.channelInterpretation=t}get context(){return this._context}get numberOfInputs(){return this._nativeAudioNode.numberOfInputs}get numberOfOutputs(){return this._nativeAudioNode.numberOfOutputs}connect(t,n=0,a=0){if(n<0||n>=this._nativeAudioNode.numberOfOutputs)throw i();const h=u(this._context),l=f(h);if(d(t)||p(t))throw o();if(it(t)){const i=mt(t);try{const e=ut(this._nativeAudioNode,i,n,a),s=vt(this);(l||s)&&this._nativeAudioNode.disconnect(...e),"closed"!==this.context.state&&!s&&vt(t)&&W(t)}catch(t){if(12===t.code)throw o();throw t}if(e(this,t,n,a,l)){const e=c([this],t);xt(e,s(l))}return t}const m=_t(t);if("playbackRate"===m.name&&1024===m.maxValue)throw r();try{this._nativeAudioNode.connect(m,n),(l||vt(this))&&this._nativeAudioNode.disconnect(m,n)}catch(t){if(12===t.code)throw o();throw t}if(Tt(this,t,n,l)){const e=c([this],t);xt(e,s(l))}}disconnect(t,e,n){let s;const r=u(this._context),h=f(r);if(void 0===t)s=((t,e)=>{const n=tt(t),s=[];for(const i of n.outputs)ot(i)?bt(t,e,...i):Ct(t,e,...i),s.push(i[0]);return n.outputs.clear(),s})(this,h);else if("number"==typeof t){if(t<0||t>=this.numberOfOutputs)throw i();s=((t,e,n)=>{const s=tt(t),i=[];for(const o of s.outputs)o[1]===n&&(ot(o)?bt(t,e,...o):Ct(t,e,...o),i.push(o[0]),s.outputs.delete(o));return i})(this,h,t)}else{if(void 0!==e&&(e<0||e>=this.numberOfOutputs))throw i();if(it(t)&&void 0!==n&&(n<0||n>=t.numberOfInputs))throw i();if(s=((t,e,n,s,i)=>{const o=tt(t);return Array.from(o.outputs).filter((t=>!(t[0]!==n||void 0!==s&&t[1]!==s||void 0!==i&&t[2]!==i))).map((n=>(ot(n)?bt(t,e,...n):Ct(t,e,...n),o.outputs.delete(n),n[0])))})(this,h,t,e,n),0===s.length)throw o()}for(const t of s){const e=c([this],t);xt(e,a)}}})((He=T,(t,e,n)=>{const s=[];for(let t=0;t<n.numberOfInputs;t+=1)s.push(new Set);He.set(t,{activeInputs:s,outputs:new Set,passiveInputs:new WeakMap,renderer:e})}),((t,e,n,s,i,o,r,a,c,h,u,l,d)=>{const p=new WeakMap;return(f,m,_,g,v)=>{const{activeInputs:y,passiveInputs:x}=o(m),{outputs:w}=o(f),T=a(f),b=o=>{const a=c(m),h=c(f);if(o){const e=q(x,f,_,g);t(y,f,e,!1),v||l(f)||n(h,a,_,g),d(m)&&W(m)}else{const t=s(y,f,_,g);e(x,g,t,!1),v||l(f)||i(h,a,_,g);const n=r(m);if(0===n)u(m)&&L(m,y);else{const t=p.get(m);void 0!==t&&clearTimeout(t),p.set(m,setTimeout((()=>{u(m)&&L(m,y)}),1e3*n))}}};return!!h(w,[m,_,g],(t=>t[0]===m&&t[1]===_&&t[2]===g),!0)&&(T.add(b),u(f)?t(y,f,[_,g,b],!0):e(x,g,[f,_,b],!0),!0)}})(Ae,Se,ut,ke,ft,tt,Me,B,mt,rt,J,gt,vt),De,((t,e,n,s,i,o)=>r=>(a,c)=>{const h=t.get(a);if(void 0===h){if(!r&&o(a)){const t=s(a),{outputs:o}=n(a);for(const n of o)if(ot(n)){const i=s(n[0]);e(t,i,n[1],n[2])}else{const e=i(n[0]);t.disconnect(e,n[1])}}t.set(a,c)}else t.set(a,h+c)})(O,ft,tt,mt,_t,J),Z,zt,he,((t,e,n,s,i,o,r,a)=>(c,h)=>{const u=e.get(c);if(void 0===u)throw new Error("Missing the expected cycle count.");const l=o(c.context),d=a(l);if(u===h){if(e.delete(c),!d&&r(c)){const e=s(c),{outputs:o}=n(c);for(const n of o)if(ot(n)){const i=s(n[0]);t(e,i,n[1],n[2])}else{const t=i(n[0]);e.connect(t,n[1])}}}else e.set(c,u-h)})(ut,O,tt,mt,_t,qe,J,je),((t,e,n)=>function s(i,o){const r=it(o)?o:n(t,o);if((t=>"delayTime"in t)(r))return[];if(i[0]===r)return[i];if(i.includes(r))return[];const{outputs:a}=e(r);return Array.from(a).map((t=>s([...i,r],t[0]))).reduce(((t,e)=>t.concat(e)),[])})(ze,tt,P),Le,qe,Xe,Ye,Ze,je,Ge);var He;const Qe=((t,e,n,s,i,o)=>class extends t{constructor(t,n){const r=i(t),a={...U,...n},c=s(r,a);super(t,!1,c,o(r)?e():null),this._nativeAnalyserNode=c}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(t){this._nativeAnalyserNode.fftSize=t}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(t){const e=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=t,!(t>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=e,n()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(t){const e=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=t,!(this._nativeAnalyserNode.maxDecibels>t))throw this._nativeAnalyserNode.minDecibels=e,n()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(t){this._nativeAnalyserNode.smoothingTimeConstant=t}getByteFrequencyData(t){this._nativeAnalyserNode.getByteFrequencyData(t)}getByteTimeDomainData(t){this._nativeAnalyserNode.getByteTimeDomainData(t)}getFloatFrequencyData(t){this._nativeAnalyserNode.getFloatFrequencyData(t)}getFloatTimeDomainData(t){this._nativeAnalyserNode.getFloatTimeDomainData(t)}})($e,Fe,Z,Ne,qe,je),Je=new WeakSet,Ke=(t=>null===t?null:t.hasOwnProperty("AudioBuffer")?t.AudioBuffer:null)(Re),tn=(en=new Uint32Array(1),t=>(en[0]=t,en[0]));var en;const nn=((t,e)=>n=>{n.copyFromChannel=(s,i,o=0)=>{const r=t(o),a=t(i);if(a>=n.numberOfChannels)throw e();const c=n.length,h=n.getChannelData(a),u=s.length;for(let t=r<0?-r:0;t+r<c&&t<u;t+=1)s[t]=h[t+r]},n.copyToChannel=(s,i,o=0)=>{const r=t(o),a=t(i);if(a>=n.numberOfChannels)throw e();const c=n.length,h=n.getChannelData(a),u=s.length;for(let t=r<0?-r:0;t+r<c&&t<u;t+=1)h[t+r]=s[t]}})(tn,Z),sn=(t=>e=>{e.copyFromChannel=(n=>(s,i,o=0)=>{const r=t(o),a=t(i);if(r<e.length)return n.call(e,s,a,r)})(e.copyFromChannel),e.copyToChannel=(n=>(s,i,o=0)=>{const r=t(o),a=t(i);if(r<e.length)return n.call(e,s,a,r)})(e.copyToChannel)})(tn),on=((t,e,n,s,i,o,r,a)=>{let c=null;return class h{constructor(h){if(null===i)throw new Error("Missing the native OfflineAudioContext constructor.");const{length:u,numberOfChannels:l,sampleRate:d}={...$,...h};null===c&&(c=new i(1,1,44100));const p=null!==s&&e(o,o)?new s({length:u,numberOfChannels:l,sampleRate:d}):c.createBuffer(l,u,d);if(0===p.numberOfChannels)throw n();return"function"!=typeof p.copyFromChannel?(r(p),G(p)):e(Y,(()=>Y(p)))||a(p),t.add(p),p}static[Symbol.hasInstance](e){return null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===h.prototype||t.has(e)}}})(Je,De,he,Ke,We,(t=>()=>{if(null===t)return!1;try{new t({length:1,sampleRate:44100})}catch{return!1}return!0})(Ke),nn,sn),rn=(t=>(e,n)=>{const s=t(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});n.connect(s).connect(e.destination);const i=()=>{n.removeEventListener("ended",i),n.disconnect(s),s.disconnect()};n.addEventListener("ended",i)})(oe),an=((t,e,n)=>async(s,i,o)=>{const r=e(s);await Promise.all(Array.from(r.activeInputs).map((async([e,s])=>{const r=t(e),a=await r.render(e,i);n(e)||a.connect(o,s)})))})(Ve,et,gt),cn=(t=>(e,n,s)=>t(n,e,s))(an),hn=((t,e,n,s,i,o,r,a,c,h,u)=>(l,d)=>{const p=l.createBufferSource();return Gt(p,d),Ht(p,d,"playbackRate"),Zt(p,d,"buffer"),Zt(p,d,"loop"),Zt(p,d,"loopEnd"),Zt(p,d,"loopStart"),e(n,(()=>n(l)))||(t=>{t.start=(e=>{let n=!1;return(s=0,i=0,o)=>{if(n)throw jt();e.call(t,s,i,o),n=!0}})(t.start)})(p),e(s,(()=>s(l)))||c(p),e(i,(()=>i(l)))||h(p,l),e(o,(()=>o(l)))||Qt(p),e(r,(()=>r(l)))||u(p,l),e(a,(()=>a(l)))||Jt(p),t(l,p),p})(rn,De,(t=>{const e=t.createBufferSource();e.start();try{e.start()}catch{return!0}return!1}),(t=>{const e=t.createBufferSource(),n=t.createBuffer(1,1,44100);e.buffer=n;try{e.start(0,1)}catch{return!1}return!0}),(t=>{const e=t.createBufferSource();e.start();try{e.stop()}catch{return!1}return!0}),xe,we,Te,(t=>{t.start=(e=>(n=0,s=0,i)=>{const o=t.buffer,r=null===o?s:Math.min(o.duration,s);null!==o&&r>o.duration-.5/t.context.sampleRate?e.call(t,n,0,0):e.call(t,n,r,i)})(t.start)}),(t=>(e,n)=>{const s=n.createBuffer(1,1,44100);null===e.buffer&&(e.buffer=s),t(e,"buffer",(t=>()=>{const n=t.call(e);return n===s?null:n}),(t=>n=>t.call(e,null===n?s:n)))})(ve),be),un=((t,e)=>(n,s,i)=>(t(s).replay(i),e(s,n,i)))((t=>e=>{const n=t(e);if(null===n.renderer)throw new Error("Missing the renderer of the given AudioParam in the audio graph.");return n.renderer})(et),an),ln=((t,e,n,s,i)=>()=>{const o=new WeakMap;let r=null,a=null;return{set start(t){r=t},set stop(t){a=t},render(c,h){const u=o.get(h);return void 0!==u?Promise.resolve(u):(async(c,h)=>{let u=n(c);const l=X(u,h);if(!l){const t={buffer:u.buffer,channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,loop:u.loop,loopEnd:u.loopEnd,loopStart:u.loopStart,playbackRate:u.playbackRate.value};u=e(h,t),null!==r&&u.start(...r),null!==a&&u.stop(a)}return o.set(h,u),l?await t(h,c.playbackRate,u.playbackRate):await s(h,c.playbackRate,u.playbackRate),await i(c,h,u),u})(c,h)}}})(cn,hn,mt,un,Pe),dn=((t,e,n,s,i,o,r,a,c,h,u,l,d)=>(p,f,m,_=null,g=null)=>{const v=m.value,y=new x(v),w=f?s(y):null,T={get defaultValue(){return v},get maxValue(){return null===_?m.maxValue:_},get minValue(){return null===g?m.minValue:g},get value(){return m.value},set value(t){m.value=t,T.setValueAtTime(t,p.context.currentTime)},cancelAndHoldAtTime(t){if("function"==typeof m.cancelAndHoldAtTime)null===w&&y.flush(p.context.currentTime),y.add(i(t)),m.cancelAndHoldAtTime(t);else{const e=Array.from(y).pop();null===w&&y.flush(p.context.currentTime),y.add(i(t));const n=Array.from(y).pop();m.cancelScheduledValues(t),e!==n&&void 0!==n&&("exponentialRampToValue"===n.type?m.exponentialRampToValueAtTime(n.value,n.endTime):"linearRampToValue"===n.type?m.linearRampToValueAtTime(n.value,n.endTime):"setValue"===n.type?m.setValueAtTime(n.value,n.startTime):"setValueCurve"===n.type&&m.setValueCurveAtTime(n.values,n.startTime,n.duration))}return T},cancelScheduledValues:t=>(null===w&&y.flush(p.context.currentTime),y.add(o(t)),m.cancelScheduledValues(t),T),exponentialRampToValueAtTime(t,e){if(0===t)throw new RangeError;if(!Number.isFinite(e)||e<0)throw new RangeError;const n=p.context.currentTime;return null===w&&y.flush(n),0===Array.from(y).length&&(y.add(h(v,n)),m.setValueAtTime(v,n)),y.add(r(t,e)),m.exponentialRampToValueAtTime(t,e),T},linearRampToValueAtTime(t,e){const n=p.context.currentTime;return null===w&&y.flush(n),0===Array.from(y).length&&(y.add(h(v,n)),m.setValueAtTime(v,n)),y.add(a(t,e)),m.linearRampToValueAtTime(t,e),T},setTargetAtTime:(t,e,n)=>(null===w&&y.flush(p.context.currentTime),y.add(c(t,e,n)),m.setTargetAtTime(t,e,n),T),setValueAtTime:(t,e)=>(null===w&&y.flush(p.context.currentTime),y.add(h(t,e)),m.setValueAtTime(t,e),T),setValueCurveAtTime(t,e,n){const s=t instanceof Float32Array?t:new Float32Array(t);if(null!==l&&"webkitAudioContext"===l.name){const t=e+n,i=p.context.sampleRate,o=Math.ceil(e*i),r=Math.floor(t*i),a=r-o,c=new Float32Array(a);for(let t=0;t<a;t+=1){const r=(s.length-1)/n*((o+t)/i-e),a=Math.floor(r),h=Math.ceil(r);c[t]=a===h?s[a]:(1-(r-a))*s[a]+(1-(h-r))*s[h]}null===w&&y.flush(p.context.currentTime),y.add(u(c,e,n)),m.setValueCurveAtTime(c,e,n);const h=r/i;h<t&&d(T,c[c.length-1],h),d(T,s[s.length-1],t)}else null===w&&y.flush(p.context.currentTime),y.add(u(s,e,n)),m.setValueCurveAtTime(s,e,n);return T}};return n.set(T,m),e.set(T,p),t(T,w),T})((pn=C,(t,e)=>{pn.set(t,{activeInputs:new Set,passiveInputs:new WeakMap,renderer:e})}),ze,A,(t=>({replay(e){for(const n of t)if("exponentialRampToValue"===n.type){const{endTime:t,value:s}=n;e.exponentialRampToValueAtTime(s,t)}else if("linearRampToValue"===n.type){const{endTime:t,value:s}=n;e.linearRampToValueAtTime(s,t)}else if("setTarget"===n.type){const{startTime:t,target:s,timeConstant:i}=n;e.setTargetAtTime(s,t,i)}else if("setValue"===n.type){const{startTime:t,value:s}=n;e.setValueAtTime(s,t)}else{if("setValueCurve"!==n.type)throw new Error("Can't apply an unknown automation.");{const{duration:t,startTime:s,values:i}=n;e.setValueCurveAtTime(i,s,t)}}}})),(t=>({cancelTime:t,type:"cancelAndHold"})),(t=>({cancelTime:t,type:"cancelScheduledValues"})),((t,e)=>({endTime:e,type:"exponentialRampToValue",value:t})),((t,e)=>({endTime:e,type:"linearRampToValue",value:t})),((t,e,n)=>({startTime:e,target:t,timeConstant:n,type:"setTarget"})),s,i,Ue,ye);var pn;const fn=((t,e,n,s,i,o,r,a)=>class extends t{constructor(t,s){const a=o(t),c={...K,...s},h=i(a,c),u=r(a),l=u?e():null;super(t,!1,h,l),this._audioBufferSourceNodeRenderer=l,this._isBufferNullified=!1,this._isBufferSet=null!==c.buffer,this._nativeAudioBufferSourceNode=h,this._onended=null,this._playbackRate=n(this,u,h.playbackRate,Q,H)}get buffer(){return this._isBufferNullified?null:this._nativeAudioBufferSourceNode.buffer}set buffer(t){if(this._nativeAudioBufferSourceNode.buffer=t,null!==t){if(this._isBufferSet)throw s();this._isBufferSet=!0}}get loop(){return this._nativeAudioBufferSourceNode.loop}set loop(t){this._nativeAudioBufferSourceNode.loop=t}get loopEnd(){return this._nativeAudioBufferSourceNode.loopEnd}set loopEnd(t){this._nativeAudioBufferSourceNode.loopEnd=t}get loopStart(){return this._nativeAudioBufferSourceNode.loopStart}set loopStart(t){this._nativeAudioBufferSourceNode.loopStart=t}get onended(){return this._onended}set onended(t){const e="function"==typeof t?a(this,t):null;this._nativeAudioBufferSourceNode.onended=e;const n=this._nativeAudioBufferSourceNode.onended;this._onended=null!==n&&n===e?t:n}get playbackRate(){return this._playbackRate}start(t=0,e=0,n){if(this._nativeAudioBufferSourceNode.start(t,e,n),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.start=void 0===n?[t,e]:[t,e,n]),"closed"!==this.context.state){W(this);const t=()=>{this._nativeAudioBufferSourceNode.removeEventListener("ended",t),J(this)&&z(this)};this._nativeAudioBufferSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeAudioBufferSourceNode.stop(t),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.stop=t)}})($e,ln,dn,jt,hn,qe,je,Ce),mn=((t,e,n,s,i,o,r,a)=>class extends t{constructor(t,n){const s=o(t),c=r(s),h=i(s,n,c);super(t,!1,h,c?e(a):null),this._isNodeOfNativeOfflineAudioContext=c,this._nativeAudioDestinationNode=h}get channelCount(){return this._nativeAudioDestinationNode.channelCount}set channelCount(t){if(this._isNodeOfNativeOfflineAudioContext)throw s();if(t>this._nativeAudioDestinationNode.maxChannelCount)throw n();this._nativeAudioDestinationNode.channelCount=t}get channelCountMode(){return this._nativeAudioDestinationNode.channelCountMode}set channelCountMode(t){if(this._isNodeOfNativeOfflineAudioContext)throw s();this._nativeAudioDestinationNode.channelCountMode=t}get maxChannelCount(){return this._nativeAudioDestinationNode.maxChannelCount}})($e,(t=>{const e=new WeakMap;return{render(n,s){const i=e.get(s);return void 0!==i?Promise.resolve(i):(async(n,s)=>{const i=s.destination;return e.set(s,i),await t(n,s,i),i})(n,s)}}}),Z,jt,((t,e)=>(n,s,i)=>{const o=n.destination;if(o.channelCount!==s)try{o.channelCount=s}catch{}i&&"explicit"!==o.channelCountMode&&(o.channelCountMode="explicit"),0===o.maxChannelCount&&Object.defineProperty(o,"maxChannelCount",{value:s});const r=t(n,{channelCount:s,channelCountMode:o.channelCountMode,channelInterpretation:o.channelInterpretation,gain:1});return e(r,"channelCount",(t=>()=>t.call(r)),(t=>e=>{t.call(r,e);try{o.channelCount=e}catch(t){if(e>o.maxChannelCount)throw t}})),e(r,"channelCountMode",(t=>()=>t.call(r)),(t=>e=>{t.call(r,e),o.channelCountMode=e})),e(r,"channelInterpretation",(t=>()=>t.call(r)),(t=>e=>{t.call(r,e),o.channelInterpretation=e})),Object.defineProperty(r,"maxChannelCount",{get:()=>o.maxChannelCount}),r.connect(o),r})(oe,ve),qe,je,Pe),_n=((t,e,n,s,i)=>()=>{const o=new WeakMap;return{render(r,a){const c=o.get(a);return void 0!==c?Promise.resolve(c):(async(r,a)=>{let c=n(r);const h=X(c,a);if(!h){const t={Q:c.Q.value,channelCount:c.channelCount,channelCountMode:c.channelCountMode,channelInterpretation:c.channelInterpretation,detune:c.detune.value,frequency:c.frequency.value,gain:c.gain.value,type:c.type};c=e(a,t)}return o.set(a,c),h?(await t(a,r.Q,c.Q),await t(a,r.detune,c.detune),await t(a,r.frequency,c.frequency),await t(a,r.gain,c.gain)):(await s(a,r.Q,c.Q),await s(a,r.detune,c.detune),await s(a,r.frequency,c.frequency),await s(a,r.gain,c.gain)),await i(r,a,c),c})(r,a)}}})(cn,ee,mt,un,Pe),gn=(t=>(e,n)=>t.set(e,n))(Oe),vn=((t,e,n,s,i,o,r,a)=>class extends t{constructor(t,s){const c=o(t),h={...It,...s},u=i(c,h),l=r(c);super(t,!1,u,l?n():null),this._Q=e(this,l,u.Q,Q,H),this._detune=e(this,l,u.detune,1200*Math.log2(Q),-1200*Math.log2(Q)),this._frequency=e(this,l,u.frequency,t.sampleRate/2,0),this._gain=e(this,l,u.gain,40*Math.log10(Q),H),this._nativeBiquadFilterNode=u,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(t){this._nativeBiquadFilterNode.type=t}getFrequencyResponse(t,e,n){try{this._nativeBiquadFilterNode.getFrequencyResponse(t,e,n)}catch(t){if(11===t.code)throw s();throw t}if(t.length!==e.length||e.length!==n.length)throw s()}})($e,dn,_n,zt,ee,qe,je,gn),yn=((t,e)=>(n,s,i)=>{const o=new Set;return n.connect=(i=>(r,a=0,c=0)=>{const h=0===o.size;if(e(r))return i.call(n,r,a,c),t(o,[r,a,c],(t=>t[0]===r&&t[1]===a&&t[2]===c),!0),h&&s(),r;i.call(n,r,a),t(o,[r,a],(t=>t[0]===r&&t[1]===a),!0),h&&s()})(n.connect),n.disconnect=(t=>(s,r,a)=>{const c=o.size>0;if(void 0===s)t.apply(n),o.clear();else if("number"==typeof s){t.call(n,s);for(const t of o)t[1]===s&&o.delete(t)}else{e(s)?t.call(n,s,r,a):t.call(n,s,r);for(const t of o)t[0]!==s||void 0!==r&&t[1]!==r||void 0!==a&&t[2]!==a||o.delete(t)}const h=0===o.size;c&&h&&i()})(n.disconnect),n})(rt,Ye),xn=((t,e)=>(n,s)=>{s.channelCount=1,s.channelCountMode="explicit",Object.defineProperty(s,"channelCount",{get:()=>1,set:()=>{throw t()}}),Object.defineProperty(s,"channelCountMode",{get:()=>"explicit",set:()=>{throw t()}});const i=n.createBufferSource();e(s,(()=>{const t=s.numberOfInputs;for(let e=0;e<t;e+=1)i.connect(s,0,e)}),(()=>i.disconnect(s)))})(jt,yn),wn=((t,e)=>(n,s)=>{const i=n.createChannelMerger(s.numberOfInputs);return null!==t&&"webkitAudioContext"===t.name&&e(n,i),Gt(i,s),i})(Ue,xn),Tn=((t,e,n)=>()=>{const s=new WeakMap;return{render(i,o){const r=s.get(o);return void 0!==r?Promise.resolve(r):(async(i,o)=>{let r=e(i);if(!X(r,o)){const e={channelCount:r.channelCount,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,numberOfInputs:r.numberOfInputs};r=t(o,e)}return s.set(o,r),await n(i,o,r),r})(i,o)}}})(wn,mt,Pe),bn=((t,e,n,s,i)=>class extends t{constructor(t,o){const r=s(t),a={...Et,...o};super(t,!1,n(r,a),i(r)?e():null)}})($e,Tn,wn,qe,je),Cn=((t,e,n)=>()=>{const s=new WeakMap;return{render(i,o){const r=s.get(o);return void 0!==r?Promise.resolve(r):(async(i,o)=>{let r=e(i);if(!X(r,o)){const e={channelCount:r.channelCount,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,numberOfOutputs:r.numberOfOutputs};r=t(o,e)}return s.set(o,r),await n(i,o,r),r})(i,o)}}})(ne,mt,Pe),An=((t,e,n,s,i,o)=>class extends t{constructor(t,r){const a=s(t),c=o({...Rt,...r});super(t,!1,n(a,c),i(a)?e():null)}})($e,Cn,ne,qe,je,(t=>({...t,channelCount:t.numberOfOutputs}))),Sn=((t,e,n,s)=>(i,{offset:o,...r})=>{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}),h=n(i,{...r,gain:o}),u=a.getChannelData(0);u[0]=1,u[1]=1,c.buffer=a,c.loop=!0;const l={get bufferSize(){},get channelCount(){return h.channelCount},set channelCount(t){h.channelCount=t},get channelCountMode(){return h.channelCountMode},set channelCountMode(t){h.channelCountMode=t},get channelInterpretation(){return h.channelInterpretation},set channelInterpretation(t){h.channelInterpretation=t},get context(){return h.context},get inputs(){return[]},get numberOfInputs(){return c.numberOfInputs},get numberOfOutputs(){return h.numberOfOutputs},get offset(){return h.gain},get onended(){return c.onended},set onended(t){c.onended=t},addEventListener:(...t)=>c.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>c.dispatchEvent(t[0]),removeEventListener:(...t)=>c.removeEventListener(t[0],t[1],t[2]),start(t=0){c.start.call(c,t)},stop(t=0){c.stop.call(c,t)}};return t(i,c),s(se(l,h),(()=>c.connect(h)),(()=>c.disconnect(h)))})(rn,hn,oe,yn),kn=((t,e,n,s,i)=>(o,r)=>{if(void 0===o.createConstantSource)return n(o,r);const a=o.createConstantSource();return Gt(a,r),Ht(a,r,"offset"),e(s,(()=>s(o)))||Qt(a),e(i,(()=>i(o)))||Jt(a),t(o,a),a})(rn,De,Sn,xe,Te),On=((t,e,n,s,i)=>()=>{const o=new WeakMap;let r=null,a=null;return{set start(t){r=t},set stop(t){a=t},render(c,h){const u=o.get(h);return void 0!==u?Promise.resolve(u):(async(c,h)=>{let u=n(c);const l=X(u,h);if(!l){const t={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,offset:u.offset.value};u=e(h,t),null!==r&&u.start(r),null!==a&&u.stop(a)}return o.set(h,u),l?await t(h,c.offset,u.offset):await s(h,c.offset,u.offset),await i(c,h,u),u})(c,h)}}})(cn,kn,mt,un,Pe),Mn=((t,e,n,s,i,o,r)=>class extends t{constructor(t,r){const a=i(t),c={...Nt,...r},h=s(a,c),u=o(a),l=u?n():null;super(t,!1,h,l),this._constantSourceNodeRenderer=l,this._nativeConstantSourceNode=h,this._offset=e(this,u,h.offset,Q,H),this._onended=null}get offset(){return this._offset}get onended(){return this._onended}set onended(t){const e="function"==typeof t?r(this,t):null;this._nativeConstantSourceNode.onended=e;const n=this._nativeConstantSourceNode.onended;this._onended=null!==n&&n===e?t:n}start(t=0){if(this._nativeConstantSourceNode.start(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.start=t),"closed"!==this.context.state){W(this);const t=()=>{this._nativeConstantSourceNode.removeEventListener("ended",t),J(this)&&z(this)};this._nativeConstantSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeConstantSourceNode.stop(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.stop=t)}})($e,dn,On,kn,qe,je,Ce),Dn=((t,e)=>(n,s)=>{const i=n.createConvolver();if(Gt(i,s),s.disableNormalization===i.normalize&&(i.normalize=!s.disableNormalization),Zt(i,s,"buffer"),s.channelCount>2)throw t();if(e(i,"channelCount",(t=>()=>t.call(i)),(e=>n=>{if(n>2)throw t();return e.call(i,n)})),"max"===s.channelCountMode)throw t();return e(i,"channelCountMode",(t=>()=>t.call(i)),(e=>n=>{if("max"===n)throw t();return e.call(i,n)})),i})(he,ve),In=((t,e,n)=>()=>{const s=new WeakMap;return{render(i,o){const r=s.get(o);return void 0!==r?Promise.resolve(r):(async(i,o)=>{let r=e(i);if(!X(r,o)){const e={buffer:r.buffer,channelCount:r.channelCount,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,disableNormalization:!r.normalize};r=t(o,e)}return s.set(o,r),ht(r)?await n(i,o,r.inputs[0]):await n(i,o,r),r})(i,o)}}})(Dn,mt,Pe),En=((t,e,n,s,i,o)=>class extends t{constructor(t,r){const a=s(t),c={...Vt,...r},h=n(a,c);super(t,!1,h,i(a)?e():null),this._isBufferNullified=!1,this._nativeConvolverNode=h,null!==c.buffer&&o(this,c.buffer.duration)}get buffer(){return this._isBufferNullified?null:this._nativeConvolverNode.buffer}set buffer(t){if(this._nativeConvolverNode.buffer=t,null===t&&null!==this._nativeConvolverNode.buffer){const t=this._nativeConvolverNode.context;this._nativeConvolverNode.buffer=t.createBuffer(1,1,t.sampleRate),this._isBufferNullified=!0,o(this,0)}else this._isBufferNullified=!1,o(this,null===this._nativeConvolverNode.buffer?0:this._nativeConvolverNode.buffer.duration)}get normalize(){return this._nativeConvolverNode.normalize}set normalize(t){this._nativeConvolverNode.normalize=t}})($e,In,Dn,qe,je,gn),Rn=((t,e,n,s,i)=>o=>{const r=new WeakMap;return{render(a,c){const h=r.get(c);return void 0!==h?Promise.resolve(h):(async(a,c)=>{let h=n(a);const u=X(h,c);if(!u){const t={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,delayTime:h.delayTime.value,maxDelayTime:o};h=e(c,t)}return r.set(c,h),u?await t(c,a.delayTime,h.delayTime):await s(c,a.delayTime,h.delayTime),await i(a,c,h),h})(a,c)}}})(cn,ie,mt,un,Pe),Nn=((t,e,n,s,i,o,r)=>class extends t{constructor(t,a){const c=i(t),h={...Ft,...a},u=s(c,h),l=o(c);super(t,!1,u,l?n(h.maxDelayTime):null),this._delayTime=e(this,l,u.delayTime),r(this,h.maxDelayTime)}get delayTime(){return this._delayTime}})($e,dn,Rn,ie,qe,je,gn),Vn=(t=>(e,n)=>{const s=e.createDynamicsCompressor();if(Gt(s,n),n.channelCount>2)throw t();if("max"===n.channelCountMode)throw t();return Ht(s,n,"attack"),Ht(s,n,"knee"),Ht(s,n,"ratio"),Ht(s,n,"release"),Ht(s,n,"threshold"),s})(he),Pn=((t,e,n,s,i)=>()=>{const o=new WeakMap;return{render(r,a){const c=o.get(a);return void 0!==c?Promise.resolve(c):(async(r,a)=>{let c=n(r);const h=X(c,a);if(!h){const t={attack:c.attack.value,channelCount:c.channelCount,channelCountMode:c.channelCountMode,channelInterpretation:c.channelInterpretation,knee:c.knee.value,ratio:c.ratio.value,release:c.release.value,threshold:c.threshold.value};c=e(a,t)}return o.set(a,c),h?(await t(a,r.attack,c.attack),await t(a,r.knee,c.knee),await t(a,r.ratio,c.ratio),await t(a,r.release,c.release),await t(a,r.threshold,c.threshold)):(await s(a,r.attack,c.attack),await s(a,r.knee,c.knee),await s(a,r.ratio,c.ratio),await s(a,r.release,c.release),await s(a,r.threshold,c.threshold)),await i(r,a,c),c})(r,a)}}})(cn,Vn,mt,un,Pe),Fn=((t,e,n,s,i,o,r,a)=>class extends t{constructor(t,i){const c=o(t),h={...Bt,...i},u=s(c,h),l=r(c);super(t,!1,u,l?n():null),this._attack=e(this,l,u.attack),this._knee=e(this,l,u.knee),this._nativeDynamicsCompressorNode=u,this._ratio=e(this,l,u.ratio),this._release=e(this,l,u.release),this._threshold=e(this,l,u.threshold),a(this,.006)}get attack(){return this._attack}get channelCount(){return this._nativeDynamicsCompressorNode.channelCount}set channelCount(t){const e=this._nativeDynamicsCompressorNode.channelCount;if(this._nativeDynamicsCompressorNode.channelCount=t,t>2)throw this._nativeDynamicsCompressorNode.channelCount=e,i()}get channelCountMode(){return this._nativeDynamicsCompressorNode.channelCountMode}set channelCountMode(t){const e=this._nativeDynamicsCompressorNode.channelCountMode;if(this._nativeDynamicsCompressorNode.channelCountMode=t,"max"===t)throw this._nativeDynamicsCompressorNode.channelCountMode=e,i()}get knee(){return this._knee}get ratio(){return this._ratio}get reduction(){return"number"==typeof this._nativeDynamicsCompressorNode.reduction.value?this._nativeDynamicsCompressorNode.reduction.value:this._nativeDynamicsCompressorNode.reduction}get release(){return this._release}get threshold(){return this._threshold}})($e,dn,Pn,Vn,he,qe,je,gn),qn=((t,e,n,s,i)=>()=>{const o=new WeakMap;return{render(r,a){const c=o.get(a);return void 0!==c?Promise.resolve(c):(async(r,a)=>{let c=n(r);const h=X(c,a);if(!h){const t={channelCount:c.channelCount,channelCountMode:c.channelCountMode,channelInterpretation:c.channelInterpretation,gain:c.gain.value};c=e(a,t)}return o.set(a,c),h?await t(a,r.gain,c.gain):await s(a,r.gain,c.gain),await i(r,a,c),c})(r,a)}}})(cn,oe,mt,un,Pe),Bn=((t,e,n,s,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...Wt,...r},h=s(a,c),u=o(a);super(t,!1,h,u?n():null),this._gain=e(this,u,h.gain,Q,H)}get gain(){return this._gain}})($e,dn,qn,oe,qe,je),Wn=((t,e,n,s)=>(i,o,{channelCount:r,channelCountMode:a,channelInterpretation:c,feedback:h,feedforward:u})=>{const l=Kt(o,i.sampleRate),d=h instanceof Float64Array?h:new Float64Array(h),p=u instanceof Float64Array?u:new Float64Array(u),f=d.length,m=p.length,_=Math.min(f,m);if(0===f||f>20)throw s();if(0===d[0])throw e();if(0===m||m>20)throw s();if(0===p[0])throw e();if(1!==d[0]){for(let t=0;t<m;t+=1)p[t]/=d[0];for(let t=1;t<f;t+=1)d[t]/=d[0]}const g=n(i,l,r,r);g.channelCount=r,g.channelCountMode=a,g.channelInterpretation=c;const v=[],y=[],x=[];for(let t=0;t<r;t+=1){v.push(0);const t=new Float32Array(32),e=new Float32Array(32);t.fill(0),e.fill(0),y.push(t),x.push(e)}g.onaudioprocess=t=>{const e=t.inputBuffer,n=t.outputBuffer,s=e.numberOfChannels;for(let t=0;t<s;t+=1){const s=e.getChannelData(t),i=n.getChannelData(t);v[t]=Ut(d,f,p,m,_,y[t],x[t],v[t],32,s,i)}};const w=i.sampleRate/2;return se({get bufferSize(){return l},get channelCount(){return g.channelCount},set channelCount(t){g.channelCount=t},get channelCountMode(){return g.channelCountMode},set channelCountMode(t){g.channelCountMode=t},get channelInterpretation(){return g.channelInterpretation},set channelInterpretation(t){g.channelInterpretation=t},get context(){return g.context},get inputs(){return[g]},get numberOfInputs(){return g.numberOfInputs},get numberOfOutputs(){return g.numberOfOutputs},addEventListener:(...t)=>g.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>g.dispatchEvent(t[0]),getFrequencyResponse(e,n,s){if(e.length!==n.length||n.length!==s.length)throw t();const i=e.length;for(let t=0;t<i;t+=1){const i=-Math.PI*(e[t]/w),o=[Math.cos(i),Math.sin(i)],r=re(ae(p,o),ae(d,o));n[t]=Math.sqrt(r[0]*r[0]+r[1]*r[1]),s[t]=Math.atan2(r[1],r[0])}},removeEventListener:(...t)=>g.removeEventListener(t[0],t[1],t[2])},g)})(zt,jt,ce,he),jn=((t,e,n,s)=>i=>t(Yt,(()=>Yt(i)))?Promise.resolve(t(s,s)).then((t=>{if(!t){const t=n(i,512,0,1);i.oncomplete=()=>{t.onaudioprocess=null,t.disconnect()},t.onaudioprocess=()=>i.currentTime,t.connect(i.destination)}return i.startRendering()})):new Promise((t=>{const n=e(i,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});i.oncomplete=e=>{n.disconnect(),t(e.renderedBuffer)},n.connect(i.destination),i.startRendering()})))(De,oe,ce,((t,e)=>()=>{if(null===e)return Promise.resolve(!1);const n=new e(1,1,44100),s=t(n,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return new Promise((t=>{n.oncomplete=()=>{s.disconnect(),t(0!==n.currentTime)},n.startRendering()}))})(oe,We)),zn=((t,e,n,s,i)=>(o,r)=>{const a=new WeakMap;let c=null;const h=async(h,u)=>{let l=null,d=e(h);const p=X(d,u);if(void 0===u.createIIRFilter?l=t(u,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}):p||(d=u.createIIRFilter(r,o)),a.set(u,null===l?d:l),null!==l){if(null===c){if(null===n)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new n(h.context.destination.channelCount,h.context.length,u.sampleRate);c=(async()=>{await s(h,t,t.destination);return((t,e,n,s)=>{const i=n instanceof Float64Array?n:new Float64Array(n),o=s instanceof Float64Array?s:new Float64Array(s),r=i.length,a=o.length,c=Math.min(r,a);if(1!==i[0]){for(let t=0;t<r;t+=1)o[t]/=i[0];for(let t=1;t<a;t+=1)i[t]/=i[0]}const h=new Float32Array(32),u=new Float32Array(32),l=e.createBuffer(t.numberOfChannels,t.length,t.sampleRate),d=t.numberOfChannels;for(let e=0;e<d;e+=1){const n=t.getChannelData(e),s=l.getChannelData(e);h.fill(0),u.fill(0),Ut(i,r,o,a,c,h,u,0,32,n,s)}return l})(await i(t),u,o,r)})()}const t=await c;return l.buffer=t,l.start(0),l}return await s(h,u,d),d};return{render(t,e){const n=a.get(e);return void 0!==n?Promise.resolve(n):h(t,e)}}})(hn,mt,We,Pe,jn),Ln=(t=>(e,n,s)=>{if(void 0===e.createIIRFilter)return t(e,n,s);const i=e.createIIRFilter(s.feedforward,s.feedback);return Gt(i,s),i})(Wn),Un=((t,e,n,s,i,o)=>class extends t{constructor(t,r){const a=s(t),c=i(a),h={...Lt,...r},u=e(a,c?null:t.baseLatency,h);super(t,!1,u,c?n(h.feedback,h.feedforward):null),(t=>{var e;t.getFrequencyResponse=(e=t.getFrequencyResponse,(n,s,i)=>{if(n.length!==s.length||s.length!==i.length)throw zt();return e.call(t,n,s,i)})})(u),this._nativeIIRFilterNode=u,o(this,1)}getFrequencyResponse(t,e,n){return this._nativeIIRFilterNode.getFrequencyResponse(t,e,n)}})($e,Ln,zn,qe,je,gn),Xn=((t,e,n,s,i,o,r,a)=>(c,h)=>{const u=h.listener,{forwardX:l,forwardY:d,forwardZ:p,positionX:f,positionY:m,positionZ:_,upX:g,upY:v,upZ:y}=void 0===u.forwardX?(()=>{const l=new Float32Array(1),d=e(h,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:9}),p=r(h);let f=!1,m=[0,0,-1,0,1,0],_=[0,0,0];const g=()=>{if(f)return;f=!0;const t=s(h,256,9,0);t.onaudioprocess=({inputBuffer:t})=>{const e=[o(t,l,0),o(t,l,1),o(t,l,2),o(t,l,3),o(t,l,4),o(t,l,5)];e.some(((t,e)=>t!==m[e]))&&(u.setOrientation(...e),m=e);const n=[o(t,l,6),o(t,l,7),o(t,l,8)];n.some(((t,e)=>t!==_[e]))&&(u.setPosition(...n),_=n)},d.connect(t)},v=t=>e=>{e!==m[t]&&(m[t]=e,u.setOrientation(...m))},y=t=>e=>{e!==_[t]&&(_[t]=e,u.setPosition(..._))},x=(e,s,o)=>{const r=n(h,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:s});r.connect(d,0,e),r.start(),Object.defineProperty(r.offset,"defaultValue",{get:()=>s});const u=t({context:c},p,r.offset,Q,H);var l,f,m,_,v,y,x;return a(u,"value",(t=>()=>t.call(u)),(t=>e=>{try{t.call(u,e)}catch(t){if(9!==t.code)throw t}g(),p&&o(e)})),u.cancelAndHoldAtTime=(l=u.cancelAndHoldAtTime,p?()=>{throw i()}:(...t)=>{const e=l.apply(u,t);return g(),e}),u.cancelScheduledValues=(f=u.cancelScheduledValues,p?()=>{throw i()}:(...t)=>{const e=f.apply(u,t);return g(),e}),u.exponentialRampToValueAtTime=(m=u.exponentialRampToValueAtTime,p?()=>{throw i()}:(...t)=>{const e=m.apply(u,t);return g(),e}),u.linearRampToValueAtTime=(_=u.linearRampToValueAtTime,p?()=>{throw i()}:(...t)=>{const e=_.apply(u,t);return g(),e}),u.setTargetAtTime=(v=u.setTargetAtTime,p?()=>{throw i()}:(...t)=>{const e=v.apply(u,t);return g(),e}),u.setValueAtTime=(y=u.setValueAtTime,p?()=>{throw i()}:(...t)=>{const e=y.apply(u,t);return g(),e}),u.setValueCurveAtTime=(x=u.setValueCurveAtTime,p?()=>{throw i()}:(...t)=>{const e=x.apply(u,t);return g(),e}),u};return{forwardX:x(0,0,v(0)),forwardY:x(1,0,v(1)),forwardZ:x(2,-1,v(2)),positionX:x(6,0,y(0)),positionY:x(7,0,y(1)),positionZ:x(8,0,y(2)),upX:x(3,0,v(3)),upY:x(4,1,v(4)),upZ:x(5,0,v(5))}})():u;return{get forwardX(){return l},get forwardY(){return d},get forwardZ(){return p},get positionX(){return f},get positionY(){return m},get positionZ(){return _},get upX(){return g},get upY(){return v},get upZ(){return y}}})(dn,wn,kn,ce,he,_e,je,ve),Yn=new WeakMap,Zn=((t,e,n,s,i,o)=>class extends n{constructor(n,o){super(n),this._nativeContext=n,S.set(this,n),s(n)&&i.set(n,new Set),this._destination=new t(this,o),this._listener=e(this,n),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(t){const e="function"==typeof t?o(this,t):null;this._nativeContext.onstatechange=e;const n=this._nativeContext.onstatechange;this._onstatechange=null!==n&&n===e?t:n}get sampleRate(){return this._nativeContext.sampleRate}get state(){return this._nativeContext.state}})(mn,Xn,Le,je,Yn,Ce),Gn=((t,e,n,s,i,o)=>(r,a)=>{const c=r.createOscillator();return Gt(c,a),Ht(c,a,"detune"),Ht(c,a,"frequency"),void 0!==a.periodicWave?c.setPeriodicWave(a.periodicWave):Zt(c,a,"type"),e(n,(()=>n(r)))||Qt(c),e(s,(()=>s(r)))||o(c,r),e(i,(()=>i(r)))||Jt(c),t(r,c),c})(rn,De,xe,we,Te,be),$n=((t,e,n,s,i)=>()=>{const o=new WeakMap;let r=null,a=null,c=null;return{set periodicWave(t){r=t},set start(t){a=t},set stop(t){c=t},render(h,u){const l=o.get(u);return void 0!==l?Promise.resolve(l):(async(h,u)=>{let l=n(h);const d=X(l,u);if(!d){const t={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,detune:l.detune.value,frequency:l.frequency.value,periodicWave:null===r?void 0:r,type:l.type};l=e(u,t),null!==a&&l.start(a),null!==c&&l.stop(c)}return o.set(u,l),d?(await t(u,h.detune,l.detune),await t(u,h.frequency,l.frequency)):(await s(u,h.detune,l.detune),await s(u,h.frequency,l.frequency)),await i(h,u,l),l})(h,u)}}})(cn,Gn,mt,un,Pe),Hn=((t,e,n,s,i,o,r)=>class extends t{constructor(t,r){const a=i(t),c={...le,...r},h=n(a,c),u=o(a),l=u?s():null,d=t.sampleRate/2;super(t,!1,h,l),this._detune=e(this,u,h.detune,153600,-153600),this._frequency=e(this,u,h.frequency,d,-d),this._nativeOscillatorNode=h,this._onended=null,this._oscillatorNodeRenderer=l,null!==this._oscillatorNodeRenderer&&void 0!==c.periodicWave&&(this._oscillatorNodeRenderer.periodicWave=c.periodicWave)}get detune(){return this._detune}get frequency(){return this._frequency}get onended(){return this._onended}set onended(t){const e="function"==typeof t?r(this,t):null;this._nativeOscillatorNode.onended=e;const n=this._nativeOscillatorNode.onended;this._onended=null!==n&&n===e?t:n}get type(){return this._nativeOscillatorNode.type}set type(t){this._nativeOscillatorNode.type=t,null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=null)}setPeriodicWave(t){this._nativeOscillatorNode.setPeriodicWave(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=t)}start(t=0){if(this._nativeOscillatorNode.start(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.start=t),"closed"!==this.context.state){W(this);const t=()=>{this._nativeOscillatorNode.removeEventListener("ended",t),J(this)&&z(this)};this._nativeOscillatorNode.addEventListener("ended",t)}}stop(t=0){this._nativeOscillatorNode.stop(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.stop=t)}})($e,dn,Gn,$n,qe,je,Ce),Qn=(t=>(e,n)=>{const s=t(e,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),i=e.createBuffer(1,2,44100);return s.buffer=i,s.loop=!0,s.connect(n),s.start(),()=>{s.stop(),s.disconnect(n)}})(hn),Jn=((t,e,n,s,i)=>(o,{curve:r,oversample:a,...c})=>{const h=o.createWaveShaper(),u=o.createWaveShaper();Gt(h,c),Gt(u,c);const l=n(o,{...c,gain:1}),d=n(o,{...c,gain:-1}),p=n(o,{...c,gain:1}),f=n(o,{...c,gain:-1});let m=null,_=!1,g=null;const v={get bufferSize(){},get channelCount(){return h.channelCount},set channelCount(t){l.channelCount=t,d.channelCount=t,h.channelCount=t,p.channelCount=t,u.channelCount=t,f.channelCount=t},get channelCountMode(){return h.channelCountMode},set channelCountMode(t){l.channelCountMode=t,d.channelCountMode=t,h.channelCountMode=t,p.channelCountMode=t,u.channelCountMode=t,f.channelCountMode=t},get channelInterpretation(){return h.channelInterpretation},set channelInterpretation(t){l.channelInterpretation=t,d.channelInterpretation=t,h.channelInterpretation=t,p.channelInterpretation=t,u.channelInterpretation=t,f.channelInterpretation=t},get context(){return h.context},get curve(){return g},set curve(n){if(null!==n&&n.length<2)throw e();if(null===n)h.curve=n,u.curve=n;else{const t=n.length,e=new Float32Array(t+2-t%2),s=new Float32Array(t+2-t%2);e[0]=n[0],s[0]=-n[t-1];const i=Math.ceil((t+1)/2),o=(t+1)/2-1;for(let r=1;r<i;r+=1){const a=r/i*o,c=Math.floor(a),h=Math.ceil(a);e[r]=c===h?n[c]:(1-(a-c))*n[c]+(1-(h-a))*n[h],s[r]=c===h?-n[t-1-c]:-(1-(a-c))*n[t-1-c]-(1-(h-a))*n[t-1-h]}e[i]=t%2==1?n[i-1]:(n[i-2]+n[i-1])/2,h.curve=e,u.curve=s}g=n,_&&(s(g)&&null===m?m=t(o,l):null!==m&&(m(),m=null))},get inputs(){return[l]},get numberOfInputs(){return h.numberOfInputs},get numberOfOutputs(){return h.numberOfOutputs},get oversample(){return h.oversample},set oversample(t){h.oversample=t,u.oversample=t},addEventListener:(...t)=>l.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>l.dispatchEvent(t[0]),removeEventListener:(...t)=>l.removeEventListener(t[0],t[1],t[2])};null!==r&&(v.curve=r instanceof Float32Array?r:new Float32Array(r)),a!==v.oversample&&(v.oversample=a);return i(se(v,p),(()=>{l.connect(h).connect(p),l.connect(d).connect(u).connect(f).connect(p),_=!0,s(g)&&(m=t(o,l))}),(()=>{l.disconnect(h),h.disconnect(p),l.disconnect(d),d.disconnect(u),u.disconnect(f),f.disconnect(p),_=!1,null!==m&&(m(),m=null)}))})(Qn,jt,oe,ge,yn),Kn=((t,e,n,s,i,o,r)=>(a,c)=>{const h=a.createWaveShaper();if(null!==o&&"webkitAudioContext"===o.name&&void 0===a.createGain().gain.automationRate)return n(a,c);Gt(h,c);const u=null===c.curve||c.curve instanceof Float32Array?c.curve:new Float32Array(c.curve);if(null!==u&&u.length<2)throw e();Zt(h,{curve:u},"curve"),Zt(h,c,"oversample");let l=null,d=!1;r(h,"curve",(t=>()=>t.call(h)),(e=>n=>(e.call(h,n),d&&(s(n)&&null===l?l=t(a,h):s(n)||null===l||(l(),l=null)),n)));return i(h,(()=>{d=!0,s(h.curve)&&(l=t(a,h))}),(()=>{d=!1,null!==l&&(l(),l=null)}))})(Qn,jt,Jn,ge,yn,Ue,ve),ts=((t,e,n,s,i,o,r,a,c,h)=>(u,{coneInnerAngle:l,coneOuterAngle:d,coneOuterGain:p,distanceModel:f,maxDistance:m,orientationX:_,orientationY:g,orientationZ:v,panningModel:y,positionX:x,positionY:w,positionZ:T,refDistance:b,rolloffFactor:C,...A})=>{const S=u.createPanner();if(A.channelCount>2)throw r();if("max"===A.channelCountMode)throw r();Gt(S,A);const k={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},O=n(u,{...k,channelInterpretation:"speakers",numberOfInputs:6}),M=s(u,{...A,gain:1}),D=s(u,{...k,gain:1}),I=s(u,{...k,gain:0}),E=s(u,{...k,gain:0}),R=s(u,{...k,gain:0}),N=s(u,{...k,gain:0}),V=s(u,{...k,gain:0}),P=i(u,256,6,1),F=o(u,{...k,curve:new Float32Array([1,1]),oversample:"none"});let q=[_,g,v],B=[x,w,T];const W=new Float32Array(1);P.onaudioprocess=({inputBuffer:t})=>{const e=[c(t,W,0),c(t,W,1),c(t,W,2)];e.some(((t,e)=>t!==q[e]))&&(S.setOrientation(...e),q=e);const n=[c(t,W,3),c(t,W,4),c(t,W,5)];n.some(((t,e)=>t!==B[e]))&&(S.setPosition(...n),B=n)},Object.defineProperty(I.gain,"defaultValue",{get:()=>0}),Object.defineProperty(E.gain,"defaultValue",{get:()=>0}),Object.defineProperty(R.gain,"defaultValue",{get:()=>0}),Object.defineProperty(N.gain,"defaultValue",{get:()=>0}),Object.defineProperty(V.gain,"defaultValue",{get:()=>0});const j={get bufferSize(){},get channelCount(){return S.channelCount},set channelCount(t){if(t>2)throw r();M.channelCount=t,S.channelCount=t},get channelCountMode(){return S.channelCountMode},set channelCountMode(t){if("max"===t)throw r();M.channelCountMode=t,S.channelCountMode=t},get channelInterpretation(){return S.channelInterpretation},set channelInterpretation(t){M.channelInterpretation=t,S.channelInterpretation=t},get coneInnerAngle(){return S.coneInnerAngle},set coneInnerAngle(t){S.coneInnerAngle=t},get coneOuterAngle(){return S.coneOuterAngle},set coneOuterAngle(t){S.coneOuterAngle=t},get coneOuterGain(){return S.coneOuterGain},set coneOuterGain(t){if(t<0||t>1)throw e();S.coneOuterGain=t},get context(){return S.context},get distanceModel(){return S.distanceModel},set distanceModel(t){S.distanceModel=t},get inputs(){return[M]},get maxDistance(){return S.maxDistance},set maxDistance(t){if(t<0)throw new RangeError;S.maxDistance=t},get numberOfInputs(){return S.numberOfInputs},get numberOfOutputs(){return S.numberOfOutputs},get orientationX(){return D.gain},get orientationY(){return I.gain},get orientationZ(){return E.gain},get panningModel(){return S.panningModel},set panningModel(t){S.panningModel=t},get positionX(){return R.gain},get positionY(){return N.gain},get positionZ(){return V.gain},get refDistance(){return S.refDistance},set refDistance(t){if(t<0)throw new RangeError;S.refDistance=t},get rolloffFactor(){return S.rolloffFactor},set rolloffFactor(t){if(t<0)throw new RangeError;S.rolloffFactor=t},addEventListener:(...t)=>M.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>M.dispatchEvent(t[0]),removeEventListener:(...t)=>M.removeEventListener(t[0],t[1],t[2])};l!==j.coneInnerAngle&&(j.coneInnerAngle=l),d!==j.coneOuterAngle&&(j.coneOuterAngle=d),p!==j.coneOuterGain&&(j.coneOuterGain=p),f!==j.distanceModel&&(j.distanceModel=f),m!==j.maxDistance&&(j.maxDistance=m),_!==j.orientationX.value&&(j.orientationX.value=_),g!==j.orientationY.value&&(j.orientationY.value=g),v!==j.orientationZ.value&&(j.orientationZ.value=v),y!==j.panningModel&&(j.panningModel=y),x!==j.positionX.value&&(j.positionX.value=x),w!==j.positionY.value&&(j.positionY.value=w),T!==j.positionZ.value&&(j.positionZ.value=T),b!==j.refDistance&&(j.refDistance=b),C!==j.rolloffFactor&&(j.rolloffFactor=C),1===q[0]&&0===q[1]&&0===q[2]||S.setOrientation(...q),0===B[0]&&0===B[1]&&0===B[2]||S.setPosition(...B);return h(se(j,S),(()=>{M.connect(S),t(M,F,0,0),F.connect(D).connect(O,0,0),F.connect(I).connect(O,0,1),F.connect(E).connect(O,0,2),F.connect(R).connect(O,0,3),F.connect(N).connect(O,0,4),F.connect(V).connect(O,0,5),O.connect(P).connect(u.destination)}),(()=>{M.disconnect(S),a(M,F,0,0),F.disconnect(D),D.disconnect(O),F.disconnect(I),I.disconnect(O),F.disconnect(E),E.disconnect(O),F.disconnect(R),R.disconnect(O),F.disconnect(N),N.disconnect(O),F.disconnect(V),V.disconnect(O),O.disconnect(P),P.disconnect(u.destination)}))})(ut,jt,wn,oe,ce,Kn,he,ft,_e,yn),es=(t=>(e,n)=>{const s=e.createPanner();return void 0===s.orientationX?t(e,n):(Gt(s,n),Ht(s,n,"orientationX"),Ht(s,n,"orientationY"),Ht(s,n,"orientationZ"),Ht(s,n,"positionX"),Ht(s,n,"positionY"),Ht(s,n,"positionZ"),Zt(s,n,"coneInnerAngle"),Zt(s,n,"coneOuterAngle"),Zt(s,n,"coneOuterGain"),Zt(s,n,"distanceModel"),Zt(s,n,"maxDistance"),Zt(s,n,"panningModel"),Zt(s,n,"refDistance"),Zt(s,n,"rolloffFactor"),s)})(ts),ns=((t,e,n,s,i,o,r,a,c,h)=>()=>{const u=new WeakMap;let l=null;return{render(d,p){const f=u.get(p);return void 0!==f?Promise.resolve(f):(async(d,p)=>{let f=null,m=o(d);const _={channelCount:m.channelCount,channelCountMode:m.channelCountMode,channelInterpretation:m.channelInterpretation},g={..._,coneInnerAngle:m.coneInnerAngle,coneOuterAngle:m.coneOuterAngle,coneOuterGain:m.coneOuterGain,distanceModel:m.distanceModel,maxDistance:m.maxDistance,panningModel:m.panningModel,refDistance:m.refDistance,rolloffFactor:m.rolloffFactor},v=X(m,p);if("bufferSize"in m)f=s(p,{..._,gain:1});else if(!v){const t={...g,orientationX:m.orientationX.value,orientationY:m.orientationY.value,orientationZ:m.orientationZ.value,positionX:m.positionX.value,positionY:m.positionY.value,positionZ:m.positionZ.value};m=i(p,t)}if(u.set(p,null===f?m:f),null!==f){if(null===l){if(null===r)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new r(6,d.context.length,p.sampleRate),s=e(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6});s.connect(t.destination),l=(async()=>{const e=await Promise.all([d.orientationX,d.orientationY,d.orientationZ,d.positionX,d.positionY,d.positionZ].map((async(e,s)=>{const i=n(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:0===s?1:0});return await a(t,e,i.offset),i})));for(let t=0;t<6;t+=1)e[t].connect(s,0,t),e[t].start(0);return h(t)})()}const t=await l,o=s(p,{..._,gain:1});await c(d,p,o);const u=[];for(let e=0;e<t.numberOfChannels;e+=1)u.push(t.getChannelData(e));let m=[u[0][0],u[1][0],u[2][0]],v=[u[3][0],u[4][0],u[5][0]],y=s(p,{..._,gain:1}),x=i(p,{...g,orientationX:m[0],orientationY:m[1],orientationZ:m[2],positionX:v[0],positionY:v[1],positionZ:v[2]});o.connect(y).connect(x.inputs[0]),x.connect(f);for(let e=128;e<t.length;e+=128){const t=[u[0][e],u[1][e],u[2][e]],n=[u[3][e],u[4][e],u[5][e]];if(t.some(((t,e)=>t!==m[e]))||n.some(((t,e)=>t!==v[e]))){m=t,v=n;const r=e/p.sampleRate;y.gain.setValueAtTime(0,r),y=s(p,{..._,gain:0}),x=i(p,{...g,orientationX:m[0],orientationY:m[1],orientationZ:m[2],positionX:v[0],positionY:v[1],positionZ:v[2]}),y.gain.setValueAtTime(1,r),o.connect(y).connect(x.inputs[0]),x.connect(f)}}return f}return v?(await t(p,d.orientationX,m.orientationX),await t(p,d.orientationY,m.orientationY),await t(p,d.orientationZ,m.orientationZ),await t(p,d.positionX,m.positionX),await t(p,d.positionY,m.positionY),await t(p,d.positionZ,m.positionZ)):(await a(p,d.orientationX,m.orientationX),await a(p,d.orientationY,m.orientationY),await a(p,d.orientationZ,m.orientationZ),await a(p,d.positionX,m.positionX),await a(p,d.positionY,m.positionY),await a(p,d.positionZ,m.positionZ)),ht(m)?await c(d,p,m.inputs[0]):await c(d,p,m),m})(d,p)}}})(cn,wn,kn,oe,es,mt,We,un,Pe,jn),ss=((t,e,n,s,i,o,r)=>class extends t{constructor(t,a){const c=i(t),h={...de,...a},u=n(c,h),l=o(c);super(t,!1,u,l?s():null),this._nativePannerNode=u,this._orientationX=e(this,l,u.orientationX,Q,H),this._orientationY=e(this,l,u.orientationY,Q,H),this._orientationZ=e(this,l,u.orientationZ,Q,H),this._positionX=e(this,l,u.positionX,Q,H),this._positionY=e(this,l,u.positionY,Q,H),this._positionZ=e(this,l,u.positionZ,Q,H),r(this,1)}get coneInnerAngle(){return this._nativePannerNode.coneInnerAngle}set coneInnerAngle(t){this._nativePannerNode.coneInnerAngle=t}get coneOuterAngle(){return this._nativePannerNode.coneOuterAngle}set coneOuterAngle(t){this._nativePannerNode.coneOuterAngle=t}get coneOuterGain(){return this._nativePannerNode.coneOuterGain}set coneOuterGain(t){this._nativePannerNode.coneOuterGain=t}get distanceModel(){return this._nativePannerNode.distanceModel}set distanceModel(t){this._nativePannerNode.distanceModel=t}get maxDistance(){return this._nativePannerNode.maxDistance}set maxDistance(t){this._nativePannerNode.maxDistance=t}get orientationX(){return this._orientationX}get orientationY(){return this._orientationY}get orientationZ(){return this._orientationZ}get panningModel(){return this._nativePannerNode.panningModel}set panningModel(t){this._nativePannerNode.panningModel=t}get positionX(){return this._positionX}get positionY(){return this._positionY}get positionZ(){return this._positionZ}get refDistance(){return this._nativePannerNode.refDistance}set refDistance(t){this._nativePannerNode.refDistance=t}get rolloffFactor(){return this._nativePannerNode.rolloffFactor}set rolloffFactor(t){this._nativePannerNode.rolloffFactor=t}})($e,dn,es,ns,qe,je,gn),is=(t=>(e,{disableNormalization:n,imag:s,real:i})=>{const o=s instanceof Float32Array?s:new Float32Array(s),r=i instanceof Float32Array?i:new Float32Array(i),a=e.createPeriodicWave(r,o,{disableNormalization:n});if(Array.from(s).length<2)throw t();return a})(Z),os=((t,e,n,s)=>class i{constructor(i,o){const r=e(i),a=s({...pe,...o}),c=t(r,a);return n.add(c),c}static[Symbol.hasInstance](t){return null!==t&&"object"==typeof t&&Object.getPrototypeOf(t)===i.prototype||n.has(t)}})(is,qe,new WeakSet,(t=>{const{imag:e,real:n}=t;return void 0===e?void 0===n?{...t,imag:[0,0],real:[0,0]}:{...t,imag:Array.from(n,(()=>0)),real:n}:void 0===n?{...t,imag:e,real:Array.from(e,(()=>0))}:{...t,imag:e,real:n}})),rs=((t,e,n,s,i,o)=>{const r=16385,a=new Float32Array([1,1]),c=Math.PI/2,h={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},u={...h,oversample:"none"},l=(t,o,l,d,p)=>{if(1===o)return((t,e,i,o)=>{const l=new Float32Array(r),d=new Float32Array(r);for(let t=0;t<r;t+=1){const e=t/16384*c;l[t]=Math.cos(e),d[t]=Math.sin(e)}const p=n(t,{...h,gain:0}),f=s(t,{...u,curve:l}),m=s(t,{...u,curve:a}),_=n(t,{...h,gain:0}),g=s(t,{...u,curve:d});return{connectGraph(){e.connect(p),e.connect(void 0===m.inputs?m:m.inputs[0]),e.connect(_),m.connect(i),i.connect(void 0===f.inputs?f:f.inputs[0]),i.connect(void 0===g.inputs?g:g.inputs[0]),f.connect(p.gain),g.connect(_.gain),p.connect(o,0,0),_.connect(o,0,1)},disconnectGraph(){e.disconnect(p),e.disconnect(void 0===m.inputs?m:m.inputs[0]),e.disconnect(_),m.disconnect(i),i.disconnect(void 0===f.inputs?f:f.inputs[0]),i.disconnect(void 0===g.inputs?g:g.inputs[0]),f.disconnect(p.gain),g.disconnect(_.gain),p.disconnect(o,0,0),_.disconnect(o,0,1)}}})(t,l,d,p);if(2===o)return((t,i,o,l)=>{const d=new Float32Array(r),p=new Float32Array(r),f=new Float32Array(r),m=new Float32Array(r),_=Math.floor(8192.5);for(let t=0;t<r;t+=1)if(t>_){const e=(t-_)/(16384-_)*c;d[t]=Math.cos(e),p[t]=Math.sin(e),f[t]=0,m[t]=1}else{const e=t/(16384-_)*c;d[t]=1,p[t]=0,f[t]=Math.cos(e),m[t]=Math.sin(e)}const g=e(t,{channelCount:2,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:2}),v=n(t,{...h,gain:0}),y=s(t,{...u,curve:d}),x=n(t,{...h,gain:0}),w=s(t,{...u,curve:p}),T=s(t,{...u,curve:a}),b=n(t,{...h,gain:0}),C=s(t,{...u,curve:f}),A=n(t,{...h,gain:0}),S=s(t,{...u,curve:m});return{connectGraph(){i.connect(g),i.connect(void 0===T.inputs?T:T.inputs[0]),g.connect(v,0),g.connect(x,0),g.connect(b,1),g.connect(A,1),T.connect(o),o.connect(void 0===y.inputs?y:y.inputs[0]),o.connect(void 0===w.inputs?w:w.inputs[0]),o.connect(void 0===C.inputs?C:C.inputs[0]),o.connect(void 0===S.inputs?S:S.inputs[0]),y.connect(v.gain),w.connect(x.gain),C.connect(b.gain),S.connect(A.gain),v.connect(l,0,0),b.connect(l,0,0),x.connect(l,0,1),A.connect(l,0,1)},disconnectGraph(){i.disconnect(g),i.disconnect(void 0===T.inputs?T:T.inputs[0]),g.disconnect(v,0),g.disconnect(x,0),g.disconnect(b,1),g.disconnect(A,1),T.disconnect(o),o.disconnect(void 0===y.inputs?y:y.inputs[0]),o.disconnect(void 0===w.inputs?w:w.inputs[0]),o.disconnect(void 0===C.inputs?C:C.inputs[0]),o.disconnect(void 0===S.inputs?S:S.inputs[0]),y.disconnect(v.gain),w.disconnect(x.gain),C.disconnect(b.gain),S.disconnect(A.gain),v.disconnect(l,0,0),b.disconnect(l,0,0),x.disconnect(l,0,1),A.disconnect(l,0,1)}}})(t,l,d,p);throw i()};return(e,{channelCount:s,channelCountMode:r,pan:a,...c})=>{if("max"===r)throw i();const h=t(e,{...c,channelCount:1,channelCountMode:r,numberOfInputs:2}),u=n(e,{...c,channelCount:s,channelCountMode:r,gain:1}),d=n(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:a});let{connectGraph:p,disconnectGraph:f}=l(e,s,u,d,h);Object.defineProperty(d.gain,"defaultValue",{get:()=>0}),Object.defineProperty(d.gain,"maxValue",{get:()=>1}),Object.defineProperty(d.gain,"minValue",{get:()=>-1});const m={get bufferSize(){},get channelCount(){return u.channelCount},set channelCount(t){u.channelCount!==t&&(_&&f(),({connectGraph:p,disconnectGraph:f}=l(e,t,u,d,h)),_&&p()),u.channelCount=t},get channelCountMode(){return u.channelCountMode},set channelCountMode(t){if("clamped-max"===t||"max"===t)throw i();u.channelCountMode=t},get channelInterpretation(){return u.channelInterpretation},set channelInterpretation(t){u.channelInterpretation=t},get context(){return u.context},get inputs(){return[u]},get numberOfInputs(){return u.numberOfInputs},get numberOfOutputs(){return u.numberOfOutputs},get pan(){return d.gain},addEventListener:(...t)=>u.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>u.dispatchEvent(t[0]),removeEventListener:(...t)=>u.removeEventListener(t[0],t[1],t[2])};let _=!1;return o(se(m,h),(()=>{p(),_=!0}),(()=>{f(),_=!1}))}})(wn,ne,oe,Kn,he,yn),as=((t,e)=>(n,s)=>{const i=s.channelCountMode;if("clamped-max"===i)throw e();if(void 0===n.createStereoPanner)return t(n,s);const o=n.createStereoPanner();return Gt(o,s),Ht(o,s,"pan"),Object.defineProperty(o,"channelCountMode",{get:()=>i,set:t=>{if(t!==i)throw e()}}),o})(rs,he),cs=((t,e,n,s,i)=>()=>{const o=new WeakMap;return{render(r,a){const c=o.get(a);return void 0!==c?Promise.resolve(c):(async(r,a)=>{let c=n(r);const h=X(c,a);if(!h){const t={channelCount:c.channelCount,channelCountMode:c.channelCountMode,channelInterpretation:c.channelInterpretation,pan:c.pan.value};c=e(a,t)}return o.set(a,c),h?await t(a,r.pan,c.pan):await s(a,r.pan,c.pan),ht(c)?await i(r,a,c.inputs[0]):await i(r,a,c),c})(r,a)}}})(cn,as,mt,un,Pe),hs=((t,e,n,s,i,o)=>class extends t{constructor(t,r){const a=i(t),c={...fe,...r},h=n(a,c),u=o(a);super(t,!1,h,u?s():null),this._pan=e(this,u,h.pan)}get pan(){return this._pan}})($e,dn,as,cs,qe,je),us=((t,e,n)=>()=>{const s=new WeakMap;return{render(i,o){const r=s.get(o);return void 0!==r?Promise.resolve(r):(async(i,o)=>{let r=e(i);if(!X(r,o)){const e={channelCount:r.channelCount,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,curve:r.curve,oversample:r.oversample};r=t(o,e)}return s.set(o,r),ht(r)?await n(i,o,r.inputs[0]):await n(i,o,r),r})(i,o)}}})(Kn,mt,Pe),ls=((t,e,n,s,i,o,r)=>class extends t{constructor(t,e){const a=i(t),c={...me,...e},h=n(a,c);super(t,!0,h,o(a)?s():null),this._isCurveNullified=!1,this._nativeWaveShaperNode=h,r(this,1)}get curve(){return this._isCurveNullified?null:this._nativeWaveShaperNode.curve}set curve(t){if(null===t)this._isCurveNullified=!0,this._nativeWaveShaperNode.curve=new Float32Array([0,0]);else{if(t.length<2)throw e();this._isCurveNullified=!1,this._nativeWaveShaperNode.curve=t}}get oversample(){return this._nativeWaveShaperNode.oversample}set oversample(t){this._nativeWaveShaperNode.oversample=t}})($e,jt,Kn,us,qe,je,gn),ds=(t=>null!==t&&t.isSecureContext)(Re),ps=(t=>(e,n,s)=>{Object.defineProperties(t,{currentFrame:{configurable:!0,get:()=>Math.round(e*n)},currentTime:{configurable:!0,get:()=>e}});try{return s()}finally{null!==t&&(delete t.currentFrame,delete t.currentTime)}})(Re),fs=new WeakMap,ms=((t,e)=>n=>{let s=t.get(n);if(void 0!==s)return s;if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");return s=new e(1,1,44100),t.set(n,s),s})(fs,We),_s=ds?((t,e,n,s,i,o,r,a,c,h,u,l,d)=>{let p=0;return(f,m,_={credentials:"omit"})=>{const g=u.get(f);if(void 0!==g&&g.has(m))return Promise.resolve();const v=h.get(f);if(void 0!==v){const t=v.get(m);if(void 0!==t)return t}const y=o(f),x=void 0===y.audioWorklet?i(m).then((([t,e])=>{const[s,i]=R(t,e);return n(`${s};((a,b)=>{(a[b]=a[b]||[]).push((AudioWorkletProcessor,global,registerProcessor,sampleRate,self,window)=>{${i}\n})})(window,'_AWGS')`)})).then((()=>{const t=d._AWGS.pop();if(void 0===t)throw new SyntaxError;s(y.currentTime,y.sampleRate,(()=>t(class{},void 0,((t,n)=>{if(""===t.trim())throw e();const s=M.get(y);if(void 0!==s){if(s.has(t))throw e();V(n),N(n.parameterDescriptors),s.set(t,n)}else V(n),N(n.parameterDescriptors),M.set(y,new Map([[t,n]]))}),y.sampleRate,void 0,void 0)))})):Promise.all([i(m),Promise.resolve(t(l,l))]).then((([[t,e],n])=>{const s=p+1;p=s;const[i,o]=R(t,e),h=new Blob([`${i};((AudioWorkletProcessor,registerProcessor)=>{${o}\n})(${n?"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{${n?"":"__c = (a) => a.forEach(e=>this.__b.add(e.buffer));"}process(i,o,p){${n?"":"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${s}',class extends AudioWorkletProcessor{process(){return !1}})`],{type:"application/javascript; charset=utf-8"}),u=URL.createObjectURL(h);return y.audioWorklet.addModule(u,_).then((()=>{if(a(y))return y;const t=r(y);return t.audioWorklet.addModule(u,_).then((()=>t))})).then((t=>{if(null===c)throw new SyntaxError;try{new c(t,`__sac${s}`)}catch{throw new SyntaxError}})).finally((()=>URL.revokeObjectURL(u)))}));return void 0===v?h.set(f,new Map([[m,x]])):v.set(m,x),x.then((()=>{const t=u.get(f);void 0===t?u.set(f,new Set([m])):t.add(m)})).finally((()=>{const t=h.get(f);void 0!==t&&t.delete(m)})),x}})(De,he,(t=>e=>new Promise(((n,s)=>{if(null===t)return void s(new SyntaxError);const i=t.document.head;if(null===i)s(new SyntaxError);else{const o=t.document.createElement("script"),r=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(r),c=t.onerror,h=()=>{t.onerror=c,URL.revokeObjectURL(a)};t.onerror=(e,n,i,o,r)=>n===a||n===t.location.href&&1===i&&1===o?(h(),s(r),!1):null!==c?c(e,n,i,o,r):void 0,o.onerror=()=>{h(),s(new SyntaxError)},o.onload=()=>{h(),n()},o.src=a,o.type="module",i.appendChild(o)}})))(Re),ps,(t=>async e=>{try{const t=await fetch(e);if(t.ok)return[await t.text(),t.url]}catch{}throw t()})((()=>new DOMException("","AbortError"))),qe,ms,je,Ge,new WeakMap,new WeakMap,((t,e)=>async()=>{if(null===t)return!0;if(null===e)return!1;const n=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"}),s=new e(1,128,44100),i=URL.createObjectURL(n);let o=!1,r=!1;try{await s.audioWorklet.addModule(i);const e=new t(s,"a",{numberOfOutputs:0}),n=s.createOscillator();e.port.onmessage=()=>o=!0,e.onprocessorerror=()=>r=!0,n.connect(e),n.start(0),await s.startRendering(),await new Promise((t=>setTimeout(t)))}catch{}finally{URL.revokeObjectURL(i)}return o&&!r})(Ge,We),Re):void 0,gs=((t,e)=>n=>t(n)||e(n))(Xe,je),vs=((t,e,n,s,i,o,r,a,c,h,u)=>(l,d)=>{const p=r(l)?l:o(l);if(i.has(d)){const t=n();return Promise.reject(t)}try{i.add(d)}catch{}return e(c,(()=>c(p)))?p.decodeAudioData(d).then((n=>(Pt(d).catch((()=>{})),e(a,(()=>a(n)))||u(n),t.add(n),n))):new Promise(((e,n)=>{const i=async()=>{try{await Pt(d)}catch{}},o=t=>{n(t),i()};try{p.decodeAudioData(d,(n=>{"function"!=typeof n.copyFromChannel&&(h(n),G(n)),t.add(n),i().then((()=>e(n)))}),(t=>{o(null===t?s():t)}))}catch(t){o(t)}}))})(Je,De,(()=>new DOMException("","DataCloneError")),(()=>new DOMException("","EncodingError")),new WeakSet,qe,gs,Y,Yt,nn,sn),ys=((t,e,n,s,i,o,r,a,c,h,u,l,d,p,f,m,_,g,v,y)=>class extends f{constructor(e,n){super(e,n),this._nativeContext=e,this._audioWorklet=void 0===t?void 0:{addModule:(e,n)=>t(this,e,n)}}get audioWorklet(){return this._audioWorklet}createAnalyser(){return new e(this)}createBiquadFilter(){return new i(this)}createBuffer(t,e,s){return new n({length:e,numberOfChannels:t,sampleRate:s})}createBufferSource(){return new s(this)}createChannelMerger(t=6){return new o(this,{numberOfInputs:t})}createChannelSplitter(t=6){return new r(this,{numberOfOutputs:t})}createConstantSource(){return new a(this)}createConvolver(){return new c(this)}createDelay(t=1){return new u(this,{maxDelayTime:t})}createDynamicsCompressor(){return new l(this)}createGain(){return new d(this)}createIIRFilter(t,e){return new p(this,{feedback:e,feedforward:t})}createOscillator(){return new m(this)}createPanner(){return new _(this)}createPeriodicWave(t,e,n={disableNormalization:!1}){return new g(this,{...n,imag:e,real:t})}createStereoPanner(){return new v(this)}createWaveShaper(){return new y(this)}decodeAudioData(t,e,n){return h(this._nativeContext,t).then((t=>("function"==typeof e&&e(t),t)),(t=>{throw"function"==typeof n&&n(t),t}))}})(_s,Qe,on,fn,vn,bn,An,Mn,En,vs,Nn,Fn,Bn,Un,Zn,Hn,ss,os,hs,ls),xs=((t,e,n,s)=>class extends t{constructor(t,i){const o=n(t),r=e(o,i);if(s(o))throw TypeError();super(t,!0,r,null),this._nativeMediaElementAudioSourceNode=r}get mediaElement(){return this._nativeMediaElementAudioSourceNode.mediaElement}})($e,((t,e)=>t.createMediaElementSource(e.mediaElement)),qe,je),ws=((t,e,n,s)=>class extends t{constructor(t,i){const o=n(t);if(s(o))throw new TypeError;const r={...Xt,...i},a=e(o,r);super(t,!1,a,null),this._nativeMediaStreamAudioDestinationNode=a}get stream(){return this._nativeMediaStreamAudioDestinationNode.stream}})($e,((t,e)=>{const n=t.createMediaStreamDestination();return Gt(n,e),1===n.numberOfOutputs&&Object.defineProperty(n,"numberOfOutputs",{get:()=>0}),n}),qe,je),Ts=((t,e,n,s)=>class extends t{constructor(t,i){const o=n(t),r=e(o,i);if(s(o))throw new TypeError;super(t,!0,r,null),this._nativeMediaStreamAudioSourceNode=r}get mediaStream(){return this._nativeMediaStreamAudioSourceNode.mediaStream}})($e,((t,{mediaStream:e})=>{const n=e.getAudioTracks();n.sort(((t,e)=>t.id<e.id?-1:t.id>e.id?1:0));const s=n.slice(0,1),i=t.createMediaStreamSource(new MediaStream(s));return Object.defineProperty(i,"mediaStream",{value:e}),i}),qe,je),bs=((t,e)=>(n,{mediaStreamTrack:s})=>{if("function"==typeof n.createMediaStreamTrackSource)return n.createMediaStreamTrackSource(s);const i=new MediaStream([s]),o=n.createMediaStreamSource(i);if("audio"!==s.kind)throw t();if(e(n))throw new TypeError;return o})(jt,je),Cs=((t,e,n)=>class extends t{constructor(t,s){const i=n(t);super(t,!0,e(i,s),null)}})($e,bs,qe),As=((t,e,n,s,i,o,r,a,c)=>class extends t{constructor(t={}){if(null===c)throw new Error("Missing the native AudioContext constructor.");let e;try{e=new c(t)}catch(t){if(12===t.code&&"sampleRate is not in range"===t.message)throw n();throw t}if(null===e)throw s();if(!(t=>void 0===t||"number"==typeof t||"string"==typeof t&&("balanced"===t||"interactive"===t||"playback"===t))(t.latencyHint))throw new TypeError(`The provided value '${t.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(void 0!==t.sampleRate&&e.sampleRate!==t.sampleRate)throw n();super(e,2);const{latencyHint:i}=t,{sampleRate:o}=e;if(this._baseLatency="number"==typeof e.baseLatency?e.baseLatency:"balanced"===i?512/o:"interactive"===i||void 0===i?256/o:"playback"===i?1024/o:128*Math.max(2,Math.min(128,Math.round(i*o/128)))/o,this._nativeAudioContext=e,"webkitAudioContext"===c.name?(this._nativeGainNode=e.createGain(),this._nativeOscillatorNode=e.createOscillator(),this._nativeGainNode.gain.value=1e-37,this._nativeOscillatorNode.connect(this._nativeGainNode).connect(e.destination),this._nativeOscillatorNode.start()):(this._nativeGainNode=null,this._nativeOscillatorNode=null),this._state=null,"running"===e.state){this._state="suspended";const t=()=>{"suspended"===this._state&&(this._state=null),e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}}get baseLatency(){return this._baseLatency}get state(){return null!==this._state?this._state:this._nativeAudioContext.state}close(){return"closed"===this.state?this._nativeAudioContext.close().then((()=>{throw e()})):("suspended"===this._state&&(this._state=null),this._nativeAudioContext.close().then((()=>{null!==this._nativeGainNode&&null!==this._nativeOscillatorNode&&(this._nativeOscillatorNode.stop(),this._nativeGainNode.disconnect(),this._nativeOscillatorNode.disconnect()),st(this)})))}createMediaElementSource(t){return new i(this,{mediaElement:t})}createMediaStreamDestination(){return new o(this)}createMediaStreamSource(t){return new r(this,{mediaStream:t})}createMediaStreamTrackSource(t){return new a(this,{mediaStreamTrack:t})}resume(){return"suspended"===this._state?new Promise(((t,e)=>{const n=()=>{this._nativeAudioContext.removeEventListener("statechange",n),"running"===this._nativeAudioContext.state?t():this.resume().then(t,e)};this._nativeAudioContext.addEventListener("statechange",n)})):this._nativeAudioContext.resume().catch((t=>{if(void 0===t||15===t.code)throw e();throw t}))}suspend(){return this._nativeAudioContext.suspend().catch((t=>{if(void 0===t)throw e();throw t}))}})(ys,jt,he,(()=>new DOMException("","UnknownError")),xs,ws,Ts,Cs,Ue),Ss=(t=>e=>{const n=t.get(e);if(void 0===n)throw new Error("The context has no set of AudioWorkletNodes.");return n})(Yn),ks=(t=>(e,n)=>{t(e).add(n)})(Ss),Os=(t=>(e,n,s=0,i=0)=>{const o=e[s];if(void 0===o)throw t();return wt(n)?o.connect(n,0,i):o.connect(n,0)})(Z),Ms=(t=>(e,n)=>{t(e).delete(n)})(Ss),Ds=(t=>(e,n=void 0,s=void 0,i=0)=>void 0===n?e.forEach((t=>t.disconnect())):"number"==typeof n?qt(t,e,n).disconnect():wt(n)?void 0===s?e.forEach((t=>t.disconnect(n))):void 0===i?qt(t,e,s).disconnect(n,0):qt(t,e,s).disconnect(n,0,i):void 0===s?e.forEach((t=>t.disconnect(n))):qt(t,e,s).disconnect(n,0))(Z),Is=new WeakMap,Es=((t,e)=>n=>e(t,n))(Is,P),Rs=((t,e,n,s,i,o,r,a,c,h,u,l,d)=>(p,f,m,_)=>{if(0===_.numberOfInputs&&0===_.numberOfOutputs)throw c();const g=Array.isArray(_.outputChannelCount)?_.outputChannelCount:Array.from(_.outputChannelCount);if(g.some((t=>t<1)))throw c();if(g.length!==_.numberOfOutputs)throw e();if("explicit"!==_.channelCountMode)throw c();const v=_.channelCount*_.numberOfInputs,y=g.reduce(((t,e)=>t+e),0),x=void 0===m.parameterDescriptors?0:m.parameterDescriptors.length;if(v+x>6||y>6)throw c();const w=new MessageChannel,T=[],b=[];for(let t=0;t<_.numberOfInputs;t+=1)T.push(r(p,{channelCount:_.channelCount,channelCountMode:_.channelCountMode,channelInterpretation:_.channelInterpretation,gain:1})),b.push(i(p,{channelCount:_.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:_.channelCount}));const C=[];if(void 0!==m.parameterDescriptors)for(const{defaultValue:t,maxValue:e,minValue:n,name:s}of m.parameterDescriptors){const i=o(p,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:void 0!==_.parameterData[s]?_.parameterData[s]:void 0===t?0:t});Object.defineProperties(i.offset,{defaultValue:{get:()=>void 0===t?0:t},maxValue:{get:()=>void 0===e?Q:e},minValue:{get:()=>void 0===n?H:n}}),C.push(i)}const A=s(p,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,v+x)}),S=Kt(f,p.sampleRate),k=a(p,S,v+x,Math.max(1,y)),O=i(p,{channelCount:Math.max(1,y),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,y)}),M=[];for(let t=0;t<_.numberOfOutputs;t+=1)M.push(s(p,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:g[t]}));for(let t=0;t<_.numberOfInputs;t+=1){T[t].connect(b[t]);for(let e=0;e<_.channelCount;e+=1)b[t].connect(A,e,t*_.channelCount+e)}const I=new At(void 0===m.parameterDescriptors?[]:m.parameterDescriptors.map((({name:t},e)=>{const n=C[e];return n.connect(A,0,v+e),n.start(0),[t,n.offset]})));A.connect(k);let E=_.channelInterpretation,R=null;const N=0===_.numberOfOutputs?[k]:M,V={get bufferSize(){return S},get channelCount(){return _.channelCount},set channelCount(t){throw n()},get channelCountMode(){return _.channelCountMode},set channelCountMode(t){throw n()},get channelInterpretation(){return E},set channelInterpretation(t){for(const e of T)e.channelInterpretation=t;E=t},get context(){return k.context},get inputs(){return T},get numberOfInputs(){return _.numberOfInputs},get numberOfOutputs(){return _.numberOfOutputs},get onprocessorerror(){return R},set onprocessorerror(t){"function"==typeof R&&V.removeEventListener("processorerror",R),R="function"==typeof t?t:null,"function"==typeof R&&V.addEventListener("processorerror",R)},get parameters(){return I},get port(){return w.port2},addEventListener:(...t)=>k.addEventListener(t[0],t[1],t[2]),connect:t.bind(null,N),disconnect:h.bind(null,N),dispatchEvent:(...t)=>k.dispatchEvent(t[0]),removeEventListener:(...t)=>k.removeEventListener(t[0],t[1],t[2])},P=new Map;var F,q;w.port1.addEventListener=(F=w.port1.addEventListener,(...t)=>{if("message"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const n=P.get(t[1]);void 0!==n?t[1]=n:(t[1]=t=>{u(p.currentTime,p.sampleRate,(()=>e(t)))},P.set(e,t[1]))}}return F.call(w.port1,t[0],t[1],t[2])}),w.port1.removeEventListener=(q=w.port1.removeEventListener,(...t)=>{if("message"===t[0]){const e=P.get(t[1]);void 0!==e&&(P.delete(t[1]),t[1]=e)}return q.call(w.port1,t[0],t[1],t[2])});let B=null;Object.defineProperty(w.port1,"onmessage",{get:()=>B,set:t=>{"function"==typeof B&&w.port1.removeEventListener("message",B),B="function"==typeof t?t:null,"function"==typeof B&&(w.port1.addEventListener("message",B),w.port1.start())}}),m.prototype.port=w.port1;let W=null;const j=((t,e,n,s)=>{let i=D.get(t);void 0===i&&(i=new WeakMap,D.set(t,i));const o=te(n,s);return i.set(e,o),o})(p,V,m,_);j.then((t=>W=t));const z=Mt(_.numberOfInputs,_.channelCount),L=Mt(_.numberOfOutputs,g),U=void 0===m.parameterDescriptors?[]:m.parameterDescriptors.reduce(((t,{name:e})=>({...t,[e]:new Float32Array(128)})),{});let X=!0;const Y=()=>{_.numberOfOutputs>0&&k.disconnect(O);for(let t=0,e=0;t<_.numberOfOutputs;t+=1){const n=M[t];for(let s=0;s<g[t];s+=1)O.disconnect(n,e+s,s);e+=g[t]}},Z=new Map;k.onaudioprocess=({inputBuffer:t,outputBuffer:e})=>{if(null!==W){const n=l(V);for(let s=0;s<S;s+=128){for(let e=0;e<_.numberOfInputs;e+=1)for(let n=0;n<_.channelCount;n+=1)kt(t,z[e],n,n,s);void 0!==m.parameterDescriptors&&m.parameterDescriptors.forEach((({name:e},n)=>{kt(t,U,e,v+n,s)}));for(let t=0;t<_.numberOfInputs;t+=1)for(let e=0;e<g[t];e+=1)0===L[t][e].byteLength&&(L[t][e]=new Float32Array(128));try{const t=z.map(((t,e)=>{if(n[e].size>0)return Z.set(e,S/128),t;const s=Z.get(e);return void 0===s?[]:(t.every((t=>t.every((t=>0===t))))&&(1===s?Z.delete(e):Z.set(e,s-1)),t)})),i=u(p.currentTime+s/p.sampleRate,p.sampleRate,(()=>W.process(t,L,U)));X=i;for(let t=0,n=0;t<_.numberOfOutputs;t+=1){for(let i=0;i<g[t];i+=1)Ot(e,L[t],i,n+i,s);n+=g[t]}}catch(t){X=!1,V.dispatchEvent(new ErrorEvent("processorerror",{colno:t.colno,filename:t.filename,lineno:t.lineno,message:t.message}))}if(!X){for(let t=0;t<_.numberOfInputs;t+=1){T[t].disconnect(b[t]);for(let e=0;e<_.channelCount;e+=1)b[s].disconnect(A,e,t*_.channelCount+e)}if(void 0!==m.parameterDescriptors){const t=m.parameterDescriptors.length;for(let e=0;e<t;e+=1){const t=C[e];t.disconnect(A,0,v+e),t.stop()}}A.disconnect(k),k.onaudioprocess=null,G?Y():K();break}}}};let G=!1;const $=r(p,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0}),J=()=>k.connect($).connect(p.destination),K=()=>{k.disconnect($),$.disconnect()};return J(),d(V,(()=>{if(X){K(),_.numberOfOutputs>0&&k.connect(O);for(let t=0,e=0;t<_.numberOfOutputs;t+=1){const n=M[t];for(let s=0;s<g[t];s+=1)O.connect(n,e+s,s);e+=g[t]}}G=!0}),(()=>{X&&(J(),Y()),G=!1}))})(Os,Z,jt,wn,ne,kn,oe,ce,he,Ds,ps,Es,yn),Ns=((t,e,n,s,i)=>(o,r,a,c,h,u)=>{if(null!==a)try{const e=new a(o,c,u),s=new Map;let r=null;if(Object.defineProperties(e,{channelCount:{get:()=>u.channelCount,set:()=>{throw t()}},channelCountMode:{get:()=>"explicit",set:()=>{throw t()}},onprocessorerror:{get:()=>r,set:t=>{"function"==typeof r&&e.removeEventListener("processorerror",r),r="function"==typeof t?t:null,"function"==typeof r&&e.addEventListener("processorerror",r)}}}),e.addEventListener=(d=e.addEventListener,(...t)=>{if("processorerror"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const n=s.get(t[1]);void 0!==n?t[1]=n:(t[1]=n=>{"error"===n.type?(Object.defineProperties(n,{type:{value:"processorerror"}}),e(n)):e(new ErrorEvent(t[0],{...n}))},s.set(e,t[1]))}}return d.call(e,"error",t[1],t[2]),d.call(e,...t)}),e.removeEventListener=(l=e.removeEventListener,(...t)=>{if("processorerror"===t[0]){const e=s.get(t[1]);void 0!==e&&(s.delete(t[1]),t[1]=e)}return l.call(e,"error",t[1],t[2]),l.call(e,t[0],t[1],t[2])}),0!==u.numberOfOutputs){const t=n(o,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});e.connect(t).connect(o.destination);return i(e,(()=>t.disconnect()),(()=>t.connect(o.destination)))}return e}catch(t){if(11===t.code)throw s();throw t}var l,d;if(void 0===h)throw s();return(t=>{const{port1:e}=new MessageChannel;try{e.postMessage(t)}finally{e.close()}})(u),e(o,r,h,u)})(jt,Rs,oe,he,yn),Vs=((t,e,n,s,i,o,r,a,c,h,u,l,d,p,f,m)=>(_,g,v)=>{const y=new WeakMap;let x=null;return{render(w,T){a(T,w);const b=y.get(T);return void 0!==b?Promise.resolve(b):(async(a,w)=>{let T=u(a),b=null;const C=X(T,w),A=Array.isArray(g.outputChannelCount)?g.outputChannelCount:Array.from(g.outputChannelCount);if(null===l){const t=A.reduce(((t,e)=>t+e),0),n=i(w,{channelCount:Math.max(1,t),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,t)}),o=[];for(let t=0;t<a.numberOfOutputs;t+=1)o.push(s(w,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:A[t]}));const h=r(w,{channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation,gain:1});h.connect=e.bind(null,o),h.disconnect=c.bind(null,o),b=[n,o,h]}else C||(T=new l(w,_));if(y.set(w,null===b?T:b[2]),null!==b){if(null===x){if(void 0===v)throw new Error("Missing the processor constructor.");if(null===d)throw new Error("Missing the native OfflineAudioContext constructor.");const t=a.channelCount*a.numberOfInputs,e=void 0===v.parameterDescriptors?0:v.parameterDescriptors.length,n=t+e,c=async()=>{const c=new d(n,128*Math.ceil(a.context.length/128),w.sampleRate),h=[],u=[];for(let t=0;t<g.numberOfInputs;t+=1)h.push(r(c,{channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation,gain:1})),u.push(i(c,{channelCount:g.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:g.channelCount}));const l=await Promise.all(Array.from(a.parameters.values()).map((async t=>{const e=o(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:t.value});return await p(c,t,e.offset),e}))),_=s(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,t+e)});for(let t=0;t<g.numberOfInputs;t+=1){h[t].connect(u[t]);for(let e=0;e<g.channelCount;e+=1)u[t].connect(_,e,t*g.channelCount+e)}for(const[e,n]of l.entries())n.connect(_,0,t+e),n.start(0);return _.connect(c.destination),await Promise.all(h.map((t=>f(a,c,t)))),m(c)};x=Dt(a,0===n?null:await c(),w,g,A,v,h)}const t=await x,e=n(w,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),[c,u,l]=b;null!==t&&(e.buffer=t,e.start(0)),e.connect(c);for(let t=0,e=0;t<a.numberOfOutputs;t+=1){const n=u[t];for(let s=0;s<A[t];s+=1)c.connect(n,e+s,s);e+=A[t]}return l}if(C)for(const[e,n]of a.parameters.entries())await t(w,n,T.parameters.get(e));else for(const[t,e]of a.parameters.entries())await p(w,e,T.parameters.get(t));return await f(a,w,T),T})(w,T)}}})(cn,Os,hn,wn,ne,kn,oe,Ms,Ds,ps,mt,Ge,We,un,Pe,jn),Ps=(t=>e=>t.get(e))(fs),Fs=(t=>(e,n)=>{t.set(e,n)})(Is),qs=ds?((t,e,n,s,i,o,r,a,c,h,u,l,d,p)=>class extends e{constructor(e,p,f){var m;const _=a(e),g=c(_),v=u({...St,...f});d(v);const y=M.get(_),x=null==y?void 0:y.get(p),w=g||"closed"!==_.state?_:null!==(m=r(_))&&void 0!==m?m:_,T=i(w,g?null:e.baseLatency,h,p,x,v);super(e,!0,T,g?s(p,v,x):null);const b=[];T.parameters.forEach(((t,e)=>{const s=n(this,g,t);b.push([e,s])})),this._nativeAudioWorkletNode=T,this._onprocessorerror=null,this._parameters=new At(b),g&&t(_,this);const{activeInputs:C}=o(this);l(T,C)}get onprocessorerror(){return this._onprocessorerror}set onprocessorerror(t){const e="function"==typeof t?p(this,t):null;this._nativeAudioWorkletNode.onprocessorerror=e;const n=this._nativeAudioWorkletNode.onprocessorerror;this._onprocessorerror=null!==n&&n===e?t:n}get parameters(){return null===this._parameters?this._nativeAudioWorkletNode.parameters:this._parameters}get port(){return this._nativeAudioWorkletNode.port}})(ks,$e,dn,Vs,Ns,tt,Ps,qe,je,Ge,(t=>({...t,outputChannelCount:void 0!==t.outputChannelCount?t.outputChannelCount:1===t.numberOfInputs&&1===t.numberOfOutputs?[t.channelCount]:Array.from({length:t.numberOfOutputs},(()=>1))})),Fs,(t=>{const{port1:e,port2:n}=new MessageChannel;try{e.postMessage(t)}finally{e.close(),n.close()}}),Ce):void 0,Bs=((t,e)=>(n,s,i)=>{if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");try{return new e(n,s,i)}catch(e){if("SyntaxError"===e.name)throw t();throw e}})(he,We),Ws=((t,e,n,s,i,o,r,a)=>(c,h)=>n(c).render(c,h).then((()=>Promise.all(Array.from(s(h)).map((t=>n(t).render(t,h)))))).then((()=>i(h))).then((n=>("function"!=typeof n.copyFromChannel?(r(n),G(n)):e(o,(()=>o(n)))||a(n),t.add(n),n))))(Je,De,Ve,Ss,jn,Y,nn,sn),js=((t,e,n,s,i)=>class extends t{constructor(t,n,i){let o;if("number"==typeof t&&void 0!==n&&void 0!==i)o={length:n,numberOfChannels:t,sampleRate:i};else{if("object"!=typeof t)throw new Error("The given parameters are not valid.");o=t}const{length:r,numberOfChannels:a,sampleRate:c}={...ue,...o},h=s(a,r,c);e(Yt,(()=>Yt(h)))||h.addEventListener("statechange",(()=>{let t=0;const e=n=>{"running"===this._state&&(t>0?(h.removeEventListener("statechange",e),n.stopImmediatePropagation(),this._waitForThePromiseToSettle(n)):t+=1)};return e})()),super(h,a),this._length=r,this._nativeOfflineAudioContext=h,this._state=null}get length(){return void 0===this._nativeOfflineAudioContext.length?this._length:this._nativeOfflineAudioContext.length}get state(){return null===this._state?this._nativeOfflineAudioContext.state:this._state}startRendering(){return"running"===this._state?Promise.reject(n()):(this._state="running",i(this.destination,this._nativeOfflineAudioContext).finally((()=>{this._state=null,st(this)})))}_waitForThePromiseToSettle(t){null===this._state?this._nativeOfflineAudioContext.dispatchEvent(t):setTimeout((()=>this._waitForThePromiseToSettle(t)))}})(ys,De,jt,Bs,Ws),zs=((t,e)=>n=>{const s=t.get(n);return e(s)||e(n)})(S,Xe),Ls=((t,e)=>n=>t.has(n)||e(n))(b,Ye),Us=((t,e)=>n=>t.has(n)||e(n))(A,Ze),Xs=((t,e)=>n=>{const s=t.get(n);return e(s)||e(n)})(S,je);function Ys(t){return void 0===t}function Zs(t){return void 0!==t}function Gs(t){return"number"==typeof t}function $s(t){return"[object Object]"===Object.prototype.toString.call(t)&&t.constructor===Object}function Hs(t){return Array.isArray(t)}function Qs(t){return"string"==typeof t}function Js(t,e){if(!t)throw new Error(e)}function Ks(t,e,n=1/0){if(!(e<=t&&t<=n))throw new RangeError(`Value must be within [${e}, ${n}], got: ${t}`)}function ti(t){t.isOffline||"running"===t.state||oi('The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.')}let ei=!1,ni=!1;function si(t){ei=t}let ii=console;function oi(...t){ii.warn(...t)}const ri="object"==typeof self?self:null,ai=ri&&(ri.hasOwnProperty("AudioContext")||ri.hasOwnProperty("webkitAudioContext"));function ci(t,e,n,s){var i,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(o<3?i(r):o>3?i(e,n,r):i(e,n))||r);return o>3&&r&&Object.defineProperty(e,n,r),r}function hi(t,e,n,s){return new(n||(n=Promise))((function(i,o){function r(t){try{c(s.next(t))}catch(t){o(t)}}function a(t){try{c(s.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,a)}c((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class ui{constructor(t,e,n,s){this._callback=t,this._type=e,this._minimumUpdateInterval=Math.max(128/(s||44100),.001),this.updateInterval=n,this._createClock()}_createWorker(){const t=new Blob([`\n\t\t\t// the initial timeout time\n\t\t\tlet timeoutTime = ${(1e3*this._updateInterval).toFixed(1)};\n\t\t\t// onmessage callback\n\t\t\tself.onmessage = function(msg){\n\t\t\t\ttimeoutTime = parseInt(msg.data);\n\t\t\t};\n\t\t\t// the tick function which posts a message\n\t\t\t// and schedules a new tick\n\t\t\tfunction tick(){\n\t\t\t\tsetTimeout(tick, timeoutTime);\n\t\t\t\tself.postMessage('tick');\n\t\t\t}\n\t\t\t// call tick initially\n\t\t\ttick();\n\t\t\t`],{type:"text/javascript"}),e=URL.createObjectURL(t),n=new Worker(e);n.onmessage=this._callback.bind(this),this._worker=n}_createTimeout(){this._timeout=setTimeout((()=>{this._createTimeout(),this._callback()}),1e3*this._updateInterval)}_createClock(){if("worker"===this._type)try{this._createWorker()}catch(t){this._type="timeout",this._createClock()}else"timeout"===this._type&&this._createTimeout()}_disposeClock(){this._timeout&&clearTimeout(this._timeout),this._worker&&(this._worker.terminate(),this._worker.onmessage=null)}get updateInterval(){return this._updateInterval}set updateInterval(t){var e;this._updateInterval=Math.max(t,this._minimumUpdateInterval),"worker"===this._type&&(null===(e=this._worker)||void 0===e||e.postMessage(1e3*this._updateInterval))}get type(){return this._type}set type(t){this._disposeClock(),this._type=t,this._createClock()}dispose(){this._disposeClock()}}function li(t){return Us(t)}function di(t){return Ls(t)}function pi(t){return Xs(t)}function fi(t){return zs(t)}function mi(t,e){return"value"===t||li(e)||di(e)||function(t){return t instanceof on}(e)}function _i(t,...e){if(!e.length)return t;const n=e.shift();if($s(t)&&$s(n))for(const e in n)mi(e,n[e])?t[e]=n[e]:$s(n[e])?(t[e]||Object.assign(t,{[e]:{}}),_i(t[e],n[e])):Object.assign(t,{[e]:n[e]});return _i(t,...e)}function gi(t,e,n=[],s){const i={},o=Array.from(e);if($s(o[0])&&s&&!Reflect.has(o[0],s)){Object.keys(o[0]).some((e=>Reflect.has(t,e)))||(_i(i,{[s]:o[0]}),n.splice(n.indexOf(s),1),o.shift())}if(1===o.length&&$s(o[0]))_i(i,o[0]);else for(let t=0;t<n.length;t++)Zs(o[t])&&(i[n[t]]=o[t]);return _i(t,i)}function vi(t,e){return Ys(t)?e:t}
/**
* Tone.js
* @author Yotam Mann
* @license http://opensource.org/licenses/MIT MIT License
* @copyright 2014-2024 Yotam Mann
*/class yi{constructor(){this.debug=!1,this._wasDisposed=!1}static getDefaults(){return{}}log(...t){(this.debug||ri&&this.toString()===ri.TONE_DEBUG_CLASS)&&function(...t){ii.log(...t)}(this,...t)}dispose(){return this._wasDisposed=!0,this}get disposed(){return this._wasDisposed}toString(){return this.name}}yi.version=t;const xi=1e-6;function wi(t,e){return t>e+xi}function Ti(t,e){return wi(t,e)||Ci(t,e)}function bi(t,e){return t+xi<e}function Ci(t,e){return Math.abs(t-e)<xi}class Ai extends yi{constructor(){super(),this.name="Timeline",this._timeline=[];const t=gi(Ai.getDefaults(),arguments,["memory"]);this.memory=t.memory,this.increasing=t.increasing}static getDefaults(){return{memory:1/0,increasing:!1}}get length(){return this._timeline.length}add(t){if(Js(Reflect.has(t,"time"),"Timeline: events must have a time attribute"),t.time=t.time.valueOf(),this.increasing&&this.length){const e=this._timeline[this.length-1];Js(Ti(t.time,e.time),"The time must be greater than or equal to the last scheduled time"),this._timeline.push(t)}else{const e=this._search(t.time);this._timeline.splice(e+1,0,t)}if(this.length>this.memory){const t=this.length-this.memory;this._timeline.splice(0,t)}return this}remove(t){const e=this._timeline.indexOf(t);return-1!==e&&this._timeline.splice(e,1),this}get(t,e="time"){const n=this._search(t,e);return-1!==n?this._timeline[n]:null}peek(){return this._timeline[0]}shift(){return this._timeline.shift()}getAfter(t,e="time"){const n=this._search(t,e);return n+1<this._timeline.length?this._timeline[n+1]:null}getBefore(t){const e=this._timeline.length;if(e>0&&this._timeline[e-1].time<t)return this._timeline[e-1];const n=this._search(t);return n-1>=0?this._timeline[n-1]:null}cancel(t){if(this._timeline.length>1){let e=this._search(t);if(e>=0)if(Ci(this._timeline[e].time,t)){for(let n=e;n>=0&&Ci(this._timeline[n].time,t);n--)e=n;this._timeline=this._timeline.slice(0,e)}else this._timeline=this._timeline.slice(0,e+1);else this._timeline=[]}else 1===this._timeline.length&&Ti(this._timeline[0].time,t)&&(this._timeline=[]);return this}cancelBefore(t){const e=this._search(t);return e>=0&&(this._timeline=this._timeline.slice(e+1)),this}previousEvent(t){const e=this._timeline.indexOf(t);return e>0?this._timeline[e-1]:null}_search(t,e="time"){if(0===this._timeline.length)return-1;let n=0;const s=this._timeline.length;let i=s;if(s>0&&this._timeline[s-1][e]<=t)return s-1;for(;n<i;){let s=Math.floor(n+(i-n)/2);const o=this._timeline[s],r=this._timeline[s+1];if(Ci(o[e],t)){for(let n=s;n<this._timeline.length;n++){if(!Ci(this._timeline[n][e],t))break;s=n}return s}if(bi(o[e],t)&&wi(r[e],t))return s;wi(o[e],t)?i=s:n=s+1}return-1}_iterate(t,e=0,n=this._timeline.length-1){this._timeline.slice(e,n+1).forEach(t)}forEach(t){return this._iterate(t),this}forEachBefore(t,e){const n=this._search(t);return-1!==n&&this._iterate(e,0,n),this}forEachAfter(t,e){const n=this._search(t);return this._iterate(e,n+1),this}forEachBetween(t,e,n){let s=this._search(t),i=this._search(e);return-1!==s&&-1!==i?(this._timeline[s].time!==t&&(s+=1),this._timeline[i].time===e&&(i-=1),this._iterate(n,s,i)):-1===s&&this._iterate(n,0,i),this}forEachFrom(t,e){let n=this._search(t);for(;n>=0&&this._timeline[n].time>=t;)n--;return this._iterate(e,n+1),this}forEachAtTime(t,e){const n=this._search(t);if(-1!==n&&Ci(this._timeline[n].time,t)){let s=n;for(let e=n;e>=0&&Ci(this._timeline[e].time,t);e--)s=e;this._iterate((t=>{e(t)}),s,n)}return this}dispose(){return super.dispose(),this._timeline=[],this}}const Si=[];function ki(t){Si.push(t)}const Oi=[];function Mi(t){Oi.push(t)}class Di extends yi{constructor(){super(...arguments),this.name="Emitter"}on(t,e){return t.split(/\W+/).forEach((t=>{Ys(this._events)&&(this._events={}),this._events.hasOwnProperty(t)||(this._events[t]=[]),this._events[t].push(e)})),this}once(t,e){const n=(...s)=>{e(...s),this.off(t,n)};return this.on(t,n),this}off(t,e){return t.split(/\W+/).forEach((t=>{if(Ys(this._events)&&(this._events={}),this._events.hasOwnProperty(t))if(Ys(e))this._events[t]=[];else{const n=this._events[t];for(let t=n.length-1;t>=0;t--)n[t]===e&&n.splice(t,1)}})),this}emit(t,...e){if(this._events&&this._events.hasOwnProperty(t)){const n=this._events[t].slice(0);for(let t=0,s=n.length;t<s;t++)n[t].apply(this,e)}return this}static mixin(t){["on","once","off","emit"].forEach((e=>{const n=Object.getOwnPropertyDescriptor(Di.prototype,e);Object.defineProperty(t.prototype,e,n)}))}dispose(){return super.dispose(),this._events=void 0,this}}class Ii extends Di{constructor(){super(...arguments),this.isOffline=!1}toJSON(){return{}}}class Ei extends Ii{constructor(){var t,e;super(),this.name="Context",this._constants=new Map,this._timeouts=new Ai,this._timeoutIds=0,this._initialized=!1,this._closeStarted=!1,this.isOffline=!1,this._workletPromise=null;const n=gi(Ei.getDefaults(),arguments,["context"]);n.context?(this._context=n.context,this._latencyHint=(null===(t=arguments[0])||void 0===t?void 0:t.latencyHint)||""):(this._context=function(t){return new As(t)}({latencyHint:n.latencyHint}),this._latencyHint=n.latencyHint),this._ticker=new ui(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[(null===(e=arguments[0])||void 0===e?void 0:e.hasOwnProperty("updateInterval"))?"_lookAhead":"lookAhead"]=n.lookAhead}static getDefaults(){return{clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.05}}initialize(){var t;return this._initialized||(t=this,Si.forEach((e=>e(t))),this._initialized=!0),this}createAnalyser(){return this._context.createAnalyser()}createOscillator(){return this._context.createOscillator()}createBufferSource(){return this._context.createBufferSource()}createBiquadFilter(){return this._context.createBiquadFilter()}createBuffer(t,e,n){return this._context.createBuffer(t,e,n)}createChannelMerger(t){return this._context.createChannelMerger(t)}createChannelSplitter(t){return this._context.createChannelSplitter(t)}createConstantSource(){return this._context.createConstantSource()}createConvolver(){return this._context.createConvolver()}createDelay(t){return this._context.createDelay(t)}createDynamicsCompressor(){return this._context.createDynamicsCompressor()}createGain(){return this._context.createGain()}createIIRFilter(t,e){return this._context.createIIRFilter(t,e)}createPanner(){return this._context.createPanner()}createPeriodicWave(t,e,n){return this._context.createPeriodicWave(t,e,n)}createStereoPanner(){return this._context.createStereoPanner()}createWaveShaper(){return this._context.createWaveShaper()}createMediaStreamSource(t){Js(fi(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamSource(t)}createMediaElementSource(t){Js(fi(this._context),"Not available if OfflineAudioContext");return this._context.createMediaElementSource(t)}createMediaStreamDestination(){Js(fi(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamDestination()}decodeAudioData(t){return this._context.decodeAudioData(t)}get currentTime(){return this._context.currentTime}get state(){return this._context.state}get sampleRate(){return this._context.sampleRate}get listener(){return this.initialize(),this._listener}set listener(t){Js(!this._initialized,"The listener cannot be set after initialization."),this._listener=t}get transport(){return this.initialize(),this._transport}set transport(t){Js(!this._initialized,"The transport cannot be set after initialization."),this._transport=t}get draw(){return this.initialize(),this._draw}set draw(t){Js(!this._initialized,"Draw cannot be set after initialization."),this._draw=t}get destination(){return this.initialize(),this._destination}set destination(t){Js(!this._initialized,"The destination cannot be set after initialization."),this._destination=t}createAudioWorkletNode(t,e){return function(t,e,n){return Js(Zs(qs),"AudioWorkletNode only works in a secure context (https or localhost)"),new(t instanceof(null==ri?void 0:ri.BaseAudioContext)?null==ri?void 0:ri.AudioWorkletNode:qs)(t,e,n)}(this.rawContext,t,e)}addAudioWorkletModule(t){return hi(this,void 0,void 0,(function*(){Js(Zs(this.rawContext.audioWorklet),"AudioWorkletNode is only available in a secure context (https or localhost)"),this._workletPromise||(this._workletPromise=this.rawContext.audioWorklet.addModule(t)),yield this._workletPromise}))}workletsAreReady(){return hi(this,void 0,void 0,(function*(){(yield this._workletPromise)?this._workletPromise:Promise.resolve()}))}get updateInterval(){return this._ticker.updateInterval}set updateInterval(t){this._ticker.updateInterval=t}get clockSource(){return this._ticker.type}set clockSource(t){this._ticker.type=t}get lookAhead(){return this._lookAhead}set lookAhead(t){this._lookAhead=t,this.updateInterval=t?t/2:.01}get latencyHint(){return this._latencyHint}get rawContext(){return this._context}now(){return this._context.currentTime+this._lookAhead}immediate(){return this._context.currentTime}resume(){return fi(this._context)?this._context.resume():Promise.resolve()}close(){return hi(this,void 0,void 0,(function*(){var t;fi(this._context)&&"closed"!==this.state&&!this._closeStarted&&(this._closeStarted=!0,yield this._context.close()),this._initialized&&(t=this,Oi.forEach((e=>e(t))))}))}getConstant(t){if(this._constants.has(t))return this._constants.get(t);{const e=this._context.createBuffer(1,128,this._context.sampleRate),n=e.getChannelData(0);for(let e=0;e<n.length;e++)n[e]=t;const s=this._context.createBufferSource();return s.channelCount=1,s.channelCountMode="explicit",s.buffer=e,s.loop=!0,s.start(0),this._constants.set(t,s),s}}dispose(){return super.dispose(),this._ticker.dispose(),this._timeouts.dispose(),Object.keys(this._constants).map((t=>this._constants[t].disconnect())),this.close(),this}_timeoutLoop(){const t=this.now();let e=this._timeouts.peek();for(;this._timeouts.length&&e&&e.time<=t;)e.callback(),this._timeouts.shift(),e=this._timeouts.peek()}setTimeout(t,e){this._timeoutIds++;const n=this.now();return this._timeouts.add({callback:t,id:this._timeoutIds,time:n+e}),this._timeoutIds}clearTimeout(t){return this._timeouts.forEach((e=>{e.id===t&&this._timeouts.remove(e)})),this}clearInterval(t){return this.clearTimeout(t)}setInterval(t,e){const n=++this._timeoutIds,s=()=>{const i=this.now();this._timeouts.add({callback:()=>{t(),s()},id:n,time:i+e})};return s(),n}}function Ri(t,e){Hs(e)?e.forEach((e=>Ri(t,e))):Object.defineProperty(t,e,{enumerable:!0,writable:!1})}function Ni(t,e){Hs(e)?e.forEach((e=>Ni(t,e))):Object.defineProperty(t,e,{writable:!0})}const Vi=()=>{};class Pi extends yi{constructor(){super(),this.name="ToneAudioBuffer",this.onload=Vi;const t=gi(Pi.getDefaults(),arguments,["url","onload","onerror"]);this.reverse=t.reverse,this.onload=t.onload,Qs(t.url)?this.load(t.url).catch(t.onerror):t.url&&this.set(t.url)}static getDefaults(){return{onerror:Vi,onload:Vi,reverse:!1}}get sampleRate(){return this._buffer?this._buffer.sampleRate:Wi().sampleRate}set(t){return t instanceof Pi?t.loaded?this._buffer=t.get():t.onload=()=>{this.set(t),this.onload(this)}:this._buffer=t,this._reversed&&this._reverse(),this}get(){return this._buffer}load(t){return hi(this,void 0,void 0,(function*(){const e=Pi.load(t).then((t=>{this.set(t),this.onload(this)}));Pi.downloads.push(e);try{yield e}finally{const t=Pi.downloads.indexOf(e);Pi.downloads.splice(t,1)}return this}))}dispose(){return super.dispose(),this._buffer=void 0,this}fromArray(t){const e=Hs(t)&&t[0].length>0,n=e?t.length:1,s=e?t[0].length:t.length,i=Wi(),o=i.createBuffer(n,s,i.sampleRate),r=e||1!==n?t:[t];for(let t=0;t<n;t++)o.copyToChannel(r[t],t);return this._buffer=o,this}toMono(t){if(Gs(t))this.fromArray(this.toArray(t));else{let t=new Float32Array(this.length);const e=this.numberOfChannels;for(let n=0;n<e;n++){const e=this.toArray(n);for(let n=0;n<e.length;n++)t[n]+=e[n]}t=t.map((t=>t/e)),this.fromArray(t)}return this}toArray(t){if(Gs(t))return this.getChannelData(t);if(1===this.numberOfChannels)return this.toArray(0);{const t=[];for(let e=0;e<this.numberOfChannels;e++)t[e]=this.getChannelData(e);return t}}getChannelData(t){return this._buffer?this._buffer.getChannelData(t):new Float32Array(0)}slice(t,e=this.duration){Js(this.loaded,"Buffer is not loaded");const n=Math.floor(t*this.sampleRate),s=Math.floor(e*this.sampleRate);Js(n<s,"The start time must be less than the end time");const i=s-n,o=Wi().createBuffer(this.numberOfChannels,i,this.sampleRate);for(let t=0;t<this.numberOfChannels;t++)o.copyToChannel(this.getChannelData(t).subarray(n,s),t);return new Pi(o)}_reverse(){if(this.loaded)for(let t=0;t<this.numberOfChannels;t++)this.getChannelData(t).reverse();return this}get loaded(){return this.length>0}get duration(){return this._buffer?this._buffer.duration:0}get length(){return this._buffer?this._buffer.length:0}get numberOfChannels(){return this._buffer?this._buffer.numberOfChannels:0}get reverse(){return this._reversed}set reverse(t){this._reversed!==t&&(this._reversed=t,this._reverse())}static fromArray(t){return(new Pi).fromArray(t)}static fromUrl(t){return hi(this,void 0,void 0,(function*(){const e=new Pi;return yield e.load(t)}))}static load(t){return hi(this,void 0,void 0,(function*(){const e=t.match(/\[([^\]\[]+\|.+)\]$/);if(e){const n=e[1].split("|");let s=n[0];for(const t of n)if(Pi.supportsType(t)){s=t;break}t=t.replace(e[0],s)}const n=""===Pi.baseUrl||Pi.baseUrl.endsWith("/")?Pi.baseUrl:Pi.baseUrl+"/",s=document.createElement("a");s.href=n+t,s.pathname=(s.pathname+s.hash).split("/").map(encodeURIComponent).join("/");const i=yield fetch(s.href);if(!i.ok)throw new Error(`could not load url: ${t}`);const o=yield i.arrayBuffer();return yield Wi().decodeAudioData(o)}))}static supportsType(t){const e=t.split("."),n=e[e.length-1];return""!==document.createElement("audio").canPlayType("audio/"+n)}static loaded(){return hi(this,void 0,void 0,(function*(){for(yield Promise.resolve();Pi.downloads.length;)yield Pi.downloads[0]}))}}Pi.baseUrl="",Pi.downloads=[];class Fi extends Ei{constructor(){var t,e,n;super({clockSource:"offline",context:pi(arguments[0])?arguments[0]:(t=arguments[0],e=arguments[1]*arguments[2],n=arguments[2],new js(t,e,n)),lookAhead:0,updateInterval:pi(arguments[0])?128/arguments[0].sampleRate:128/arguments[2]}),this.name="OfflineContext",this._currentTime=0,this.isOffline=!0,this._duration=pi(arguments[0])?arguments[0].length/arguments[0].sampleRate:arguments[1]}now(){return this._currentTime}get currentTime(){return this._currentTime}_renderClock(t){return hi(this,void 0,void 0,(function*(){let e=0;for(;this._duration-this._currentTime>=0;){this.emit("tick"),this._currentTime+=128/this.sampleRate,e++;const n=Math.floor(this.sampleRate/128);t&&e%n==0&&(yield new Promise((t=>setTimeout(t,1))))}}))}render(){return hi(this,arguments,void 0,(function*(t=!0){yield this.workletsAreReady(),yield this._renderClock(t);const e=yield this._context.startRendering();return new Pi(e)}))}close(){return Promise.resolve()}}const qi=new class extends Ii{constructor(){super(...arguments),this.lookAhead=0,this.latencyHint=0,this.isOffline=!1}createAnalyser(){return{}}createOscillator(){return{}}createBufferSource(){return{}}createBiquadFilter(){return{}}createBuffer(t,e,n){return{}}createChannelMerger(t){return{}}createChannelSplitter(t){return{}}createConstantSource(){return{}}createConvolver(){return{}}createDelay(t){return{}}createDynamicsCompressor(){return{}}createGain(){return{}}createIIRFilter(t,e){return{}}createPanner(){return{}}createPeriodicWave(t,e,n){return{}}createStereoPanner(){return{}}createWaveShaper(){return{}}createMediaStreamSource(t){return{}}createMediaElementSource(t){return{}}createMediaStreamDestination(){return{}}decodeAudioData(t){return Promise.resolve({})}createAudioWorkletNode(t,e){return{}}get rawContext(){return{}}addAudioWorkletModule(t){return hi(this,void 0,void 0,(function*(){return Promise.resolve()}))}resume(){return Promise.resolve()}setTimeout(t,e){return 0}clearTimeout(t){return this}setInterval(t,e){return 0}clearInterval(t){return this}getConstant(t){return{}}get currentTime(){return 0}get state(){return{}}get sampleRate(){return 0}get listener(){return{}}get transport(){return{}}get draw(){return{}}set draw(t){}get destination(){return{}}set destination(t){}now(){return 0}immediate(){return 0}};let Bi=qi;function Wi(){return Bi===qi&&ai&&ji(new Ei),Bi}function ji(t,e=!1){e&&Bi.dispose(),Bi=fi(t)?new Ei(t):pi(t)?new Fi(t):t}function zi(){return Bi.resume()}if(ri&&!ri.TONE_SILENCE_LOGGING){const e=` * Tone.js ${"v"}${t} * `;console.log(`%c${e}`,"background: #000; color: #fff")}function Li(t,e,n){return Math.min(Math.max(t,e),n)}function Ui(t){return Math.pow(10,t/20)}function Xi(t){return Math.log(t)/Math.LN10*20}function Yi(t){return Math.pow(2,t/12)}let Zi=440;function Gi(t){return Math.round(function(t){return 69+12*Math.log2(t/Zi)}(t))}class $i extends yi{constructor(t,e,n){super(),this.defaultUnits="s",this._val=e,this._units=n,this.context=t,this._expressions=this._getExpressions()}_getExpressions(){return{hz:{method:t=>this._frequencyToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)hz$/i},i:{method:t=>this._ticksToUnits(parseInt(t,10)),regexp:/^(\d+)i$/i},m:{method:t=>this._beatsToUnits(parseInt(t,10)*this._getTimeSignature()),regexp:/^(\d+)m$/i},n:{method:(t,e)=>{const n=parseInt(t,10),s="."===e?1.5:1;return 1===n?this._beatsToUnits(this._getTimeSignature())*s:this._beatsToUnits(4/n)*s},regexp:/^(\d+)n(\.?)$/i},number:{method:t=>this._expressions[this.defaultUnits].method.call(this,t),regexp:/^(\d+(?:\.\d+)?)$/},s:{method:t=>this._secondsToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)s$/},samples:{method:t=>parseInt(t,10)/this.context.sampleRate,regexp:/^(\d+)samples$/},t:{method:t=>{const e=parseInt(t,10);return this._beatsToUnits(8/(3*Math.floor(e)))},regexp:/^(\d+)t$/i},tr:{method:(t,e,n)=>{let s=0;return t&&"0"!==t&&(s+=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(s+=this._beatsToUnits(parseFloat(e))),n&&"0"!==n&&(s+=this._beatsToUnits(parseFloat(n)/4)),s},regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/}}}valueOf(){if(this._val instanceof $i&&this.fromType(this._val),Ys(this._val))return this._noArg();if(Qs(this._val)&&Ys(this._units)){for(const t in this._expressions)if(this._expressions[t].regexp.test(this._val.trim())){this._units=t;break}}else if($s(this._val)){let t=0;for(const e in this._val)if(Zs(this._val[e])){const n=this._val[e];t+=new this.constructor(this.context,e).valueOf()*n}return t}if(Zs(this._units)){const t=this._expressions[this._units],e=this._val.toString().trim().match(t.regexp);return e?t.method.apply(this,e.slice(1)):t.method.call(this,this._val)}return Qs(this._val)?parseFloat(this._val):this._val}_frequencyToUnits(t){return 1/t}_beatsToUnits(t){return 60/this._getBpm()*t}_secondsToUnits(t){return t}_ticksToUnits(t){return t*this._beatsToUnits(1)/this._getPPQ()}_noArg(){return this._now()}_getBpm(){return this.context.transport.bpm.value}_getTimeSignature(){return this.context.transport.timeSignature}_getPPQ(){return this.context.transport.PPQ}fromType(t){switch(this._units=void 0,this.defaultUnits){case"s":this._val=t.toSeconds();break;case"i":this._val=t.toTicks();break;case"hz":this._val=t.toFrequency();break;case"midi":this._val=t.toMidi()}return this}toFrequency(){return 1/this.toSeconds()}toSamples(){return this.toSeconds()*this.context.sampleRate}toMilliseconds(){return 1e3*this.toSeconds()}}class Hi extends $i{constructor(){super(...arguments),this.name="TimeClass"}_getExpressions(){return Object.assign(super._getExpressions(),{now:{method:t=>this._now()+new this.constructor(this.context,t).valueOf(),regexp:/^\+(.+)/},quantize:{method:t=>{const e=new Hi(this.context,t).valueOf();return this._secondsToUnits(this.context.transport.nextSubdivision(e))},regexp:/^@(.+)/}})}quantize(t,e=1){const n=new this.constructor(this.context,t).valueOf(),s=this.valueOf();return s+(Math.round(s/n)*n-s)*e}toNotation(){const t=this.toSeconds(),e=["1m"];for(let t=1;t<9;t++){const n=Math.pow(2,t);e.push(n+"n."),e.push(n+"n"),e.push(n+"t")}e.push("0");let n=e[0],s=new Hi(this.context,e[0]).toSeconds();return e.forEach((e=>{const i=new Hi(this.context,e).toSeconds();Math.abs(i-t)<Math.abs(s-t)&&(n=e,s=i)})),n}toBarsBeatsSixteenths(){const t=this._beatsToUnits(1);let e=this.valueOf()/t;e=parseFloat(e.toFixed(4));const n=Math.floor(e/this._getTimeSignature());let s=e%1*4;e=Math.floor(e)%this._getTimeSignature();const i=s.toString();i.length>3&&(s=parseFloat(parseFloat(i).toFixed(3)));return[n,e,s].join(":")}toTicks(){const t=this._beatsToUnits(1);return this.valueOf()/t*this._getPPQ()}toSeconds(){return this.valueOf()}toMidi(){return Gi(this.toFrequency())}_now(){return this.context.now()}}class Qi extends Hi{constructor(){super(...arguments),this.name="Frequency",this.defaultUnits="hz"}static get A4(){return Zi}static set A4(t){!function(t){Zi=t}(t)}_getExpressions(){return Object.assign({},super._getExpressions(),{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method(t){return"midi"===this.defaultUnits?t:Qi.mtof(t)}},note:{regexp:/^([a-g]{1}(?:b|#|##|x|bb|###|#x|x#|bbb)?)(-?[0-9]+)/i,method(t,e){const n=Ji[t.toLowerCase()]+12*(parseInt(e,10)+1);return"midi"===this.defaultUnits?n:Qi.mtof(n)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method(t,e,n){let s=1;return t&&"0"!==t&&(s*=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(s*=this._beatsToUnits(parseFloat(e))),n&&"0"!==n&&(s*=this._beatsToUnits(parseFloat(n)/4)),s}}})}transpose(t){return new Qi(this.context,this.valueOf()*Yi(t))}harmonize(t){return t.map((t=>this.transpose(t)))}toMidi(){return Gi(this.valueOf())}toNote(){const t=this.toFrequency(),e=Math.log2(t/Qi.A4);let n=Math.round(12*e)+57;const s=Math.floor(n/12);s<0&&(n+=-12*s);return Ki[n%12]+s.toString()}toSeconds(){return 1/super.toSeconds()}toTicks(){const t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.floor(e*this._getPPQ())}_noArg(){return 0}_frequencyToUnits(t){return t}_ticksToUnits(t){return 1/(60*t/(this._getBpm()*this._getPPQ()))}_beatsToUnits(t){return 1/super._beatsToUnits(t)}_secondsToUnits(t){return 1/t}static mtof(t){return function(t){return Zi*Math.pow(2,(t-69)/12)}(t)}static ftom(t){return Gi(t)}}const Ji={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},Ki=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];class to extends Hi{constructor(){super(...arguments),this.name="TransportTime"}_now(){return this.context.transport.seconds}}class eo extends yi{constructor(){super();const t=gi(eo.getDefaults(),arguments,["context"]);this.defaultContext?this.context=this.defaultContext:this.context=t.context}static getDefaults(){return{context:Wi()}}now(){return this.context.currentTime+this.context.lookAhead}immediate(){return this.context.currentTime}get sampleTime(){return 1/this.context.sampleRate}get blockTime(){return 128/this.context.sampleRate}toSeconds(t){return function(t){Ys(t)&&ei&&!ni&&(ni=!0,oi("Events scheduled inside of scheduled callbacks should use the passed in scheduling time. See https://github.com/Tonejs/Tone.js/wiki/Accurate-Timing"))}(t),new Hi(this.context,t).toSeconds()}toFrequency(t){return new Qi(this.context,t).toFrequency()}toTicks(t){return new to(this.context,t).toTicks()}_getPartialProperties(t){const e=this.get();return Object.keys(e).forEach((n=>{Ys(t[n])&&delete e[n]})),e}get(){const t=this.constructor.getDefaults();return Object.keys(t).forEach((e=>{if(Reflect.has(this,e)){const n=this[e];Zs(n)&&Zs(n.value)&&Zs(n.setValueAtTime)?t[e]=n.value:n instanceof eo?t[e]=n._getPartialProperties(t[e]):Hs(n)||Gs(n)||Qs(n)||"boolean"==typeof n?t[e]=n:delete t[e]}})),t}set(t){return Object.keys(t).forEach((e=>{Reflect.has(this,e)&&Zs(this[e])&&(this[e]&&Zs(this[e].value)&&Zs(this[e].setValueAtTime)?this[e].value!==t[e]&&(this[e].value=t[e]):this[e]instanceof eo?this[e].set(t[e]):this[e]=t[e])})),this}}class no extends eo{constructor(){const t=gi(no.getDefaults(),arguments,["param","units","convert"]);for(super(t),this.name="Param",this.overridden=!1,this._minOutput=1e-7,Js(Zs(t.param)&&(li(t.param)||t.param instanceof no),"param must be an AudioParam");!li(t.param);)t.param=t.param._param;this._swappable=!!Zs(t.swappable)&&t.swappable,this._swappable?(this.input=this.context.createGain(),this._param=t.param,this.input.connect(this._param)):this._param=this.input=t.param,this._events=new Ai(1e3),this._initialValue=this._param.defaultValue,this.units=t.units,this.convert=t.convert,this._minValue=t.minValue,this._maxValue=t.maxValue,Zs(t.value)&&t.value!==this._toType(this._initialValue)&&this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(eo.getDefaults(),{convert:!0,units:"number"})}get value(){const t=this.now();return this.getValueAtTime(t)}set value(t){this.cancelScheduledValues(this.now()),this.setValueAtTime(t,this.now())}get minValue(){return Zs(this._minValue)?this._minValue:"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"===this.units?0:"audioRange"===this.units?-1:"decibels"===this.units?-1/0:this._param.minValue}get maxValue(){return Zs(this._maxValue)?this._maxValue:"normalRange"===this.units||"audioRange"===this.units?1:this._param.maxValue}_is(t,e){return this.units===e}_assertRange(t){return Zs(this.maxValue)&&Zs(this.minValue)&&Ks(t,this._fromType(this.minValue),this._fromType(this.maxValue)),t}_fromType(t){return this.convert&&!this.overridden?this._is(t,"time")?this.toSeconds(t):this._is(t,"decibels")?Ui(t):this._is(t,"frequency")?this.toFrequency(t):t:this.overridden?0:t}_toType(t){return this.convert&&"decibels"===this.units?Xi(t):t}setValueAtTime(t,e){const n=this.toSeconds(e),s=this._fromType(t);return Js(isFinite(s)&&isFinite(n),`Invalid argument(s) to setValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(s),this.log(this.units,"setValueAtTime",t,n),this._events.add({time:n,type:"setValueAtTime",value:s}),this._param.setValueAtTime(s,n),this}getValueAtTime(t){const e=Math.max(this.toSeconds(t),0),n=this._events.getAfter(e),s=this._events.get(e);let i=this._initialValue;if(null===s)i=this._initialValue;else if("setTargetAtTime"!==s.type||null!==n&&"setValueAtTime"!==n.type)if(null===n)i=s.value;else if("linearRampToValueAtTime"===n.type||"exponentialRampToValueAtTime"===n.type){let t=s.value;if("setTargetAtTime"===s.type){const e=this._events.getBefore(s.time);t=null===e?this._initialValue:e.value}i="linearRampToValueAtTime"===n.type?this._linearInterpolate(s.time,t,n.time,n.value,e):this._exponentialInterpolate(s.time,t,n.time,n.value,e)}else i=s.value;else{const t=this._events.getBefore(s.time);let n;n=null===t?this._initialValue:t.value,"setTargetAtTime"===s.type&&(i=this._exponentialApproach(s.time,n,s.value,s.constant,e))}return this._toType(i)}setRampPoint(t){t=this.toSeconds(t);let e=this.getValueAtTime(t);return this.cancelAndHoldAtTime(t),0===this._fromType(e)&&(e=this._toType(this._minOutput)),this.setValueAtTime(e,t),this}linearRampToValueAtTime(t,e){const n=this._fromType(t),s=this.toSeconds(e);return Js(isFinite(n)&&isFinite(s),`Invalid argument(s) to linearRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(n),this._events.add({time:s,type:"linearRampToValueAtTime",value:n}),this.log(this.units,"linearRampToValueAtTime",t,s),this._param.linearRampToValueAtTime(n,s),this}exponentialRampToValueAtTime(t,e){let n=this._fromType(t);n=Ci(n,0)?this._minOutput:n,this._assertRange(n);const s=this.toSeconds(e);return Js(isFinite(n)&&isFinite(s),`Invalid argument(s) to exponentialRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({time:s,type:"exponentialRampToValueAtTime",value:n}),this.log(this.units,"exponentialRampToValueAtTime",t,s),this._param.exponentialRampToValueAtTime(n,s),this}exponentialRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialRampToValueAtTime(t,n+this.toSeconds(e)),this}linearRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.linearRampToValueAtTime(t,n+this.toSeconds(e)),this}targetRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialApproachValueAtTime(t,n,e),this}exponentialApproachValueAtTime(t,e,n){e=this.toSeconds(e),n=this.toSeconds(n);const s=Math.log(n+1)/Math.log(200);return this.setTargetAtTime(t,e,s),this.cancelAndHoldAtTime(e+.9*n),this.linearRampToValueAtTime(t,e+n),this}setTargetAtTime(t,e,n){const s=this._fromType(t);Js(isFinite(n)&&n>0,"timeConstant must be a number greater than 0");const i=this.toSeconds(e);return this._assertRange(s),Js(isFinite(s)&&isFinite(i),`Invalid argument(s) to setTargetAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({constant:n,time:i,type:"setTargetAtTime",value:s}),this.log(this.units,"setTargetAtTime",t,i,n),this._param.setTargetAtTime(s,i,n),this}setValueCurveAtTime(t,e,n,s=1){n=this.toSeconds(n),e=this.toSeconds(e);const i=this._fromType(t[0])*s;this.setValueAtTime(this._toType(i),e);const o=n/(t.length-1);for(let n=1;n<t.length;n++){const i=this._fromType(t[n])*s;this.linearRampToValueAtTime(this._toType(i),e+n*o)}return this}cancelScheduledValues(t){const e=this.toSeconds(t);return Js(isFinite(e),`Invalid argument to cancelScheduledValues: ${JSON.stringify(t)}`),this._events.cancel(e),this._param.cancelScheduledValues(e),this.log(this.units,"cancelScheduledValues",e),this}cancelAndHoldAtTime(t){const e=this.toSeconds(t),n=this._fromType(this.getValueAtTime(e));Js(isFinite(e),`Invalid argument to cancelAndHoldAtTime: ${JSON.stringify(t)}`),this.log(this.units,"cancelAndHoldAtTime",e,"value="+n);const s=this._events.get(e),i=this._events.getAfter(e);return s&&Ci(s.time,e)?i?(this._param.cancelScheduledValues(i.time),this._events.cancel(i.time)):(this._param.cancelAndHoldAtTime(e),this._events.cancel(e+this.sampleTime)):i&&(this._param.cancelScheduledValues(i.time),this._events.cancel(i.time),"linearRampToValueAtTime"===i.type?this.linearRampToValueAtTime(this._toType(n),e):"exponentialRampToValueAtTime"===i.type&&this.exponentialRampToValueAtTime(this._toType(n),e)),this._events.add({time:e,type:"setValueAtTime",value:n}),this._param.setValueAtTime(n,e),this}rampTo(t,e=.1,n){return"frequency"===this.units||"bpm"===this.units||"decibels"===this.units?this.exponentialRampTo(t,e,n):this.linearRampTo(t,e,n),this}apply(t){const e=this.context.currentTime;t.setValueAtTime(this.getValueAtTime(e),e);const n=this._events.get(e);if(n&&"setTargetAtTime"===n.type){const s=this._events.getAfter(n.time),i=s?s.time:e+2,o=(i-e)/10;for(let n=e;n<i;n+=o)t.linearRampToValueAtTime(this.getValueAtTime(n),n)}return this._events.forEachAfter(this.context.currentTime,(e=>{"cancelScheduledValues"===e.type?t.cancelScheduledValues(e.time):"setTargetAtTime"===e.type?t.setTargetAtTime(e.value,e.time,e.constant):t[e.type](e.value,e.time)})),this}setParam(t){Js(this._swappable,"The Param must be assigned as 'swappable' in the constructor");const e=this.input;return e.disconnect(this._param),this.apply(t),this._param=t,e.connect(this._param),this}dispose(){return super.dispose(),this._events.dispose(),this}get defaultValue(){return this._toType(this._param.defaultValue)}_exponentialApproach(t,e,n,s,i){return n+(e-n)*Math.exp(-(i-t)/s)}_linearInterpolate(t,e,n,s,i){return e+(i-t)/(n-t)*(s-e)}_exponentialInterpolate(t,e,n,s,i){return e*Math.pow(s/e,(i-t)/(n-t))}}class so extends eo{constructor(){super(...arguments),this._internalChannels=[]}get numberOfInputs(){return Zs(this.input)?li(this.input)||this.input instanceof no?1:this.input.numberOfInputs:0}get numberOfOutputs(){return Zs(this.output)?this.output.numberOfOutputs:0}_isAudioNode(t){return Zs(t)&&(t instanceof so||di(t))}_getInternalNodes(){const t=this._internalChannels.slice(0);return this._isAudioNode(this.input)&&t.push(this.input),this._isAudioNode(this.output)&&this.input!==this.output&&t.push(this.output),t}_setChannelProperties(t){this._getInternalNodes().forEach((e=>{e.channelCount=t.channelCount,e.channelCountMode=t.channelCountMode,e.channelInterpretation=t.channelInterpretation}))}_getChannelProperties(){const t=this._getInternalNodes();Js(t.length>0,"ToneAudioNode does not have any internal nodes");const e=t[0];return{channelCount:e.channelCount,channelCountMode:e.channelCountMode,channelInterpretation:e.channelInterpretation}}get channelCount(){return this._getChannelProperties().channelCount}set channelCount(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCount:t}))}get channelCountMode(){return this._getChannelProperties().channelCountMode}set channelCountMode(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCountMode:t}))}get channelInterpretation(){return this._getChannelProperties().channelInterpretation}set channelInterpretation(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelInterpretation:t}))}connect(t,e=0,n=0){return oo(this,t,e,n),this}toDestination(){return this.connect(this.context.destination),this}toMaster(){return oi("toMaster() has been renamed toDestination()"),this.toDestination()}disconnect(t,e=0,n=0){return ro(this,t,e,n),this}chain(...t){return io(this,...t),this}fan(...t){return t.forEach((t=>this.connect(t))),this}dispose(){return super.dispose(),Zs(this.input)&&(this.input instanceof so?this.input.dispose():di(this.input)&&this.input.disconnect()),Zs(this.output)&&(this.output instanceof so?this.output.dispose():di(this.output)&&this.output.disconnect()),this._internalChannels=[],this}}function io(...t){const e=t.shift();t.reduce(((t,e)=>(t instanceof so?t.connect(e):di(t)&&oo(t,e),e)),e)}function oo(t,e,n=0,s=0){for(Js(Zs(t),"Cannot connect from undefined node"),Js(Zs(e),"Cannot connect to undefined node"),(e instanceof so||di(e))&&Js(e.numberOfInputs>0,"Cannot connect to node with no inputs"),Js(t.numberOfOutputs>0,"Cannot connect from node with no outputs");e instanceof so||e instanceof no;)Zs(e.input)&&(e=e.input);for(;t instanceof so;)Zs(t.output)&&(t=t.output);li(e)?t.connect(e,n):t.connect(e,n,s)}function ro(t,e,n=0,s=0){if(Zs(e))for(;e instanceof so;)e=e.input;for(;!di(t);)Zs(t.output)&&(t=t.output);li(e)?t.disconnect(e,n):di(e)?t.disconnect(e,n,s):t.disconnect()}class ao extends so{constructor(){const t=gi(ao.getDefaults(),arguments,["gain","units"]);super(t),this.name="Gain",this._gainNode=this.context.createGain(),this.input=this._gainNode,this.output=this._gainNode,this.gain=new no({context:this.context,convert:t.convert,param:this._gainNode.gain,units:t.units,value:t.gain,minValue:t.minValue,maxValue:t.maxValue}),Ri(this,"gain")}static getDefaults(){return Object.assign(so.getDefaults(),{convert:!0,gain:1,units:"gain"})}dispose(){return super.dispose(),this._gainNode.disconnect(),this.gain.dispose(),this}}class co extends so{constructor(t){super(t),this.onended=Vi,this._startTime=-1,this._stopTime=-1,this._timeout=-1,this.output=new ao({context:this.context,gain:0}),this._gainNode=this.output,this.getStateAtTime=function(t){const e=this.toSeconds(t);return-1!==this._startTime&&e>=this._startTime&&(-1===this._stopTime||e<=this._stopTime)?"started":"stopped"},this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut,this._curve=t.curve,this.onended=t.onended}static getDefaults(){return Object.assign(so.getDefaults(),{curve:"linear",fadeIn:0,fadeOut:0,onended:Vi})}_startGain(t,e=1){Js(-1===this._startTime,"Source cannot be started more than once");const n=this.toSeconds(this._fadeIn);return this._startTime=t+n,this._startTime=Math.max(this._startTime,this.context.currentTime),n>0?(this._gainNode.gain.setValueAtTime(0,t),"linear"===this._curve?this._gainNode.gain.linearRampToValueAtTime(e,t+n):this._gainNode.gain.exponentialApproachValueAtTime(e,t,n)):this._gainNode.gain.setValueAtTime(e,t),this}stop(t){return this.log("stop",t),this._stopGain(this.toSeconds(t)),this}_stopGain(t){Js(-1!==this._startTime,"'start' must be called before 'stop'"),this.cancelStop();const e=this.toSeconds(this._fadeOut);return this._stopTime=this.toSeconds(t)+e,this._stopTime=Math.max(this._stopTime,this.now()),e>0?"linear"===this._curve?this._gainNode.gain.linearRampTo(0,e,t):this._gainNode.gain.targetRampTo(0,e,t):(this._gainNode.gain.cancelAndHoldAtTime(t),this._gainNode.gain.setValueAtTime(0,t)),this.context.clearTimeout(this._timeout),this._timeout=this.context.setTimeout((()=>{const t="exponential"===this._curve?2*e:0;this._stopSource(this.now()+t),this._onended()}),this._stopTime-this.context.currentTime),this}_onended(){if(this.onended!==Vi&&(this.onended(this),this.onended=Vi,!this.context.isOffline)){const t=()=>this.dispose();void 0!==window.requestIdleCallback?window.requestIdleCallback(t):setTimeout(t,1e3)}}get state(){return this.getStateAtTime(this.now())}cancelStop(){return this.log("cancelStop"),Js(-1!==this._startTime,"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=Vi,this}}class ho extends co{constructor(){const t=gi(ho.getDefaults(),arguments,["offset"]);super(t),this.name="ToneConstantSource",this._source=this.context.createConstantSource(),oo(this._source,this._gainNode),this.offset=new no({context:this.context,convert:t.convert,param:this._source.offset,units:t.units,value:t.offset,minValue:t.minValue,maxValue:t.maxValue})}static getDefaults(){return Object.assign(co.getDefaults(),{convert:!0,offset:1,units:"number"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._source.start(e),this}_stopSource(t){this._source.stop(t)}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._source.disconnect(),this.offset.dispose(),this}}class uo extends so{constructor(){const t=gi(uo.getDefaults(),arguments,["value","units"]);super(t),this.name="Signal",this.override=!0,this.output=this._constantSource=new ho({context:this.context,convert:t.convert,offset:t.value,units:t.units,minValue:t.minValue,maxValue:t.maxValue}),this._constantSource.start(0),this.input=this._param=this._constantSource.offset}static getDefaults(){return Object.assign(so.getDefaults(),{convert:!0,units:"number",value:0})}connect(t,e=0,n=0){return lo(this,t,e,n),this}dispose(){return super.dispose(),this._param.dispose(),this._constantSource.dispose(),this}setValueAtTime(t,e){return this._param.setValueAtTime(t,e),this}getValueAtTime(t){return this._param.getValueAtTime(t)}setRampPoint(t){return this._param.setRampPoint(t),this}linearRampToValueAtTime(t,e){return this._param.linearRampToValueAtTime(t,e),this}exponentialRampToValueAtTime(t,e){return this._param.exponentialRampToValueAtTime(t,e),this}exponentialRampTo(t,e,n){return this._param.exponentialRampTo(t,e,n),this}linearRampTo(t,e,n){return this._param.linearRampTo(t,e,n),this}targetRampTo(t,e,n){return this._param.targetRampTo(t,e,n),this}exponentialApproachValueAtTime(t,e,n){return this._param.exponentialApproachValueAtTime(t,e,n),this}setTargetAtTime(t,e,n){return this._param.setTargetAtTime(t,e,n),this}setValueCurveAtTime(t,e,n,s){return this._param.setValueCurveAtTime(t,e,n,s),this}cancelScheduledValues(t){return this._param.cancelScheduledValues(t),this}cancelAndHoldAtTime(t){return this._param.cancelAndHoldAtTime(t),this}rampTo(t,e,n){return this._param.rampTo(t,e,n),this}get value(){return this._param.value}set value(t){this._param.value=t}get convert(){return this._param.convert}set convert(t){this._param.convert=t}get units(){return this._param.units}get overridden(){return this._param.overridden}set overridden(t){this._param.overridden=t}get maxValue(){return this._param.maxValue}get minValue(){return this._param.minValue}apply(t){return this._param.apply(t),this}}function lo(t,e,n,s){(e instanceof no||li(e)||e instanceof uo&&e.override)&&(e.cancelScheduledValues(0),e.setValueAtTime(0,0),e instanceof uo&&(e.overridden=!0)),oo(t,e,n,s)}class po extends so{constructor(){const t=gi(po.getDefaults(),arguments,["volume"]);super(t),this.name="Volume",this.input=this.output=new ao({context:this.context,gain:t.volume,units:"decibels"}),this.volume=this.output.gain,Ri(this,"volume"),this._unmutedVolume=t.volume,this.mute=t.mute}static getDefaults(){return Object.assign(so.getDefaults(),{mute:!1,volume:0})}get mute(){return this.volume.value===-1/0}set mute(t){!this.mute&&t?(this._unmutedVolume=this.volume.value,this.volume.value=-1/0):this.mute&&!t&&(this.volume.value=this._unmutedVolume)}dispose(){return super.dispose(),this.input.dispose(),this.volume.dispose(),this}}class fo extends so{constructor(){const t=gi(fo.getDefaults(),arguments);super(t),this.name="Destination",this.input=new po({context:this.context}),this.output=new ao({context:this.context}),this.volume=this.input.volume,io(this.input,this.output,this.context.rawContext.destination),this.mute=t.mute,this._internalChannels=[this.input,this.context.rawContext.destination,this.output]}static getDefaults(){return Object.assign(so.getDefaults(),{mute:!1,volume:0})}get mute(){return this.input.mute}set mute(t){this.input.mute=t}chain(...t){return this.input.disconnect(),t.unshift(this.input),t.push(this.output),io(...t),this}get maxChannelCount(){return this.context.rawContext.destination.maxChannelCount}dispose(){return super.dispose(),this.volume.dispose(),this}}ki((t=>{t.destination=new fo({context:t})})),Mi((t=>{t.destination.dispose()}));class mo extends yi{constructor(t){super(),this.name="TimelineValue",this._timeline=new Ai({memory:10}),this._initialValue=t}set(t,e){return this._timeline.add({value:t,time:e}),this}get(t){const e=this._timeline.get(t);return e?e.value:this._initialValue}}class _o extends so{constructor(){super(gi(_o.getDefaults(),arguments,["context"]))}connect(t,e=0,n=0){return lo(this,t,e,n),this}}class go extends _o{constructor(){const t=gi(go.getDefaults(),arguments,["mapping","length"]);super(t),this.name="WaveShaper",this._shaper=this.context.createWaveShaper(),this.input=this._shaper,this.output=this._shaper,Hs(t.mapping)||t.mapping instanceof Float32Array?this.curve=Float32Array.from(t.mapping):"function"==typeof t.mapping&&this.setMap(t.mapping,t.length)}static getDefaults(){return Object.assign(uo.getDefaults(),{length:1024})}setMap(t,e=1024){const n=new Float32Array(e);for(let s=0,i=e;s<i;s++){const e=s/(i-1)*2-1;n[s]=t(e,s)}return this.curve=n,this}get curve(){return this._shaper.curve}set curve(t){this._shaper.curve=t}get oversample(){return this._shaper.oversample}set oversample(t){Js(["none","2x","4x"].some((e=>e.includes(t))),"oversampling must be either 'none', '2x', or '4x'"),this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.disconnect(),this}}class vo extends _o{constructor(){const t=gi(vo.getDefaults(),arguments,["value"]);super(t),this.name="Pow",this._exponentScaler=this.input=this.output=new go({context:this.context,mapping:this._expFunc(t.value),length:8192}),this._exponent=t.value}static getDefaults(){return Object.assign(_o.getDefaults(),{value:1})}_expFunc(t){return e=>Math.pow(Math.abs(e),t)}get value(){return this._exponent}set value(t){this._exponent=t,this._exponentScaler.setMap(this._expFunc(this._exponent))}dispose(){return super.dispose(),this._exponentScaler.dispose(),this}}class yo extends to{constructor(){super(...arguments),this.name="Ticks",this.defaultUnits="i"}_now(){return this.context.transport.ticks}_beatsToUnits(t){return this._getPPQ()*t}_secondsToUnits(t){return Math.floor(t/(60/this._getBpm())*this._getPPQ())}_ticksToUnits(t){return t}toTicks(){return this.valueOf()}toSeconds(){return this.valueOf()/this._getPPQ()*(60/this._getBpm())}}class xo extends yi{constructor(){super(...arguments),this.name="IntervalTimeline",this._root=null,this._length=0}add(t){Js(Zs(t.time),"Events must have a time property"),Js(Zs(t.duration),"Events must have a duration parameter"),t.time=t.time.valueOf();let e=new wo(t.time,t.time+t.duration,t);for(null===this._root?this._root=e:this._root.insert(e),this._length++;null!==e;)e.updateHeight(),e.updateMax(),this._rebalance(e),e=e.parent;return this}remove(t){if(null!==this._root){const e=[];this._root.search(t.time,e);for(const n of e)if(n.event===t){this._removeNode(n),this._length--;break}}return this}get length(){return this._length}cancel(t){return this.forEachFrom(t,(t=>this.remove(t))),this}_setRoot(t){this._root=t,null!==this._root&&(this._root.parent=null)}_replaceNodeInParent(t,e){null!==t.parent?(t.isLeftChild()?t.parent.left=e:t.parent.right=e,this._rebalance(t.parent)):this._setRoot(e)}_removeNode(t){if(null===t.left&&null===t.right)this._replaceNodeInParent(t,null);else if(null===t.right)this._replaceNodeInParent(t,t.left);else if(null===t.left)this._replaceNodeInParent(t,t.right);else{let e,n=null;if(t.getBalance()>0)if(null===t.left.right)e=t.left,e.right=t.right,n=e;else{for(e=t.left.right;null!==e.right;)e=e.right;e.parent&&(e.parent.right=e.left,n=e.parent,e.left=t.left,e.right=t.right)}else if(null===t.right.left)e=t.right,e.left=t.left,n=e;else{for(e=t.right.left;null!==e.left;)e=e.left;e.parent&&(e.parent.left=e.right,n=e.parent,e.left=t.left,e.right=t.right)}null!==t.parent?t.isLeftChild()?t.parent.left=e:t.parent.right=e:this._setRoot(e),n&&this._rebalance(n)}t.dispose()}_rotateLeft(t){const e=t.parent,n=t.isLeftChild(),s=t.right;s&&(t.right=s.left,s.left=t),null!==e?n?e.left=s:e.right=s:this._setRoot(s)}_rotateRight(t){const e=t.parent,n=t.isLeftChild(),s=t.left;s&&(t.left=s.right,s.right=t),null!==e?n?e.left=s:e.right=s:this._setRoot(s)}_rebalance(t){const e=t.getBalance();e>1&&t.left?t.left.getBalance()<0?this._rotateLeft(t.left):this._rotateRight(t):e<-1&&t.right&&(t.right.getBalance()>0?this._rotateRight(t.right):this._rotateLeft(t))}get(t){if(null!==this._root){const e=[];if(this._root.search(t,e),e.length>0){let t=e[0];for(let n=1;n<e.length;n++)e[n].low>t.low&&(t=e[n]);return t.event}}return null}forEach(t){if(null!==this._root){const e=[];this._root.traverse((t=>e.push(t))),e.forEach((e=>{e.event&&t(e.event)}))}return this}forEachAtTime(t,e){if(null!==this._root){const n=[];this._root.search(t,n),n.forEach((t=>{t.event&&e(t.event)}))}return this}forEachFrom(t,e){if(null!==this._root){const n=[];this._root.searchAfter(t,n),n.forEach((t=>{t.event&&e(t.event)}))}return this}dispose(){return super.dispose(),null!==this._root&&this._root.traverse((t=>t.dispose())),this._root=null,this}}class wo{constructor(t,e,n){this._left=null,this._right=null,this.parent=null,this.height=0,this.event=n,this.low=t,this.high=e,this.max=this.high}insert(t){t.low<=this.low?null===this.left?this.left=t:this.left.insert(t):null===this.right?this.right=t:this.right.insert(t)}search(t,e){t>this.max||(null!==this.left&&this.left.search(t,e),this.low<=t&&this.high>t&&e.push(this),this.low>t||null!==this.right&&this.right.search(t,e))}searchAfter(t,e){this.low>=t&&(e.push(this),null!==this.left&&this.left.searchAfter(t,e)),null!==this.right&&this.right.searchAfter(t,e)}traverse(t){t(this),null!==this.left&&this.left.traverse(t),null!==this.right&&this.right.traverse(t)}updateHeight(){null!==this.left&&null!==this.right?this.height=Math.max(this.left.height,this.right.height)+1:null!==this.right?this.height=this.right.height+1:null!==this.left?this.height=this.left.height+1:this.height=0}updateMax(){this.max=this.high,null!==this.left&&(this.max=Math.max(this.max,this.left.max)),null!==this.right&&(this.max=Math.max(this.max,this.right.max))}getBalance(){let t=0;return null!==this.left&&null!==this.right?t=this.left.height-this.right.height:null!==this.left?t=this.left.height+1:null!==this.right&&(t=-(this.right.height+1)),t}isLeftChild(){return null!==this.parent&&this.parent.left===this}get left(){return this._left}set left(t){this._left=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}get right(){return this._right}set right(t){this._right=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}dispose(){this.parent=null,this._left=null,this._right=null,this.event=null}}class To extends Ai{constructor(t="stopped"){super(),this.name="StateTimeline",this._initial=t,this.setStateAtTime(this._initial,0)}getValueAtTime(t){const e=this.get(t);return null!==e?e.state:this._initial}setStateAtTime(t,e,n){return Ks(e,0),this.add(Object.assign({},n,{state:t,time:e})),this}getLastState(t,e){for(let n=this._search(e);n>=0;n--){const e=this._timeline[n];if(e.state===t)return e}}getNextState(t,e){const n=this._search(e);if(-1!==n)for(let e=n;e<this._timeline.length;e++){const n=this._timeline[e];if(n.state===t)return n}}}class bo extends no{constructor(){const t=gi(bo.getDefaults(),arguments,["value"]);super(t),this.name="TickParam",this._events=new Ai(1/0),this._multiplier=1,this._multiplier=t.multiplier,this._events.cancel(0),this._events.add({ticks:0,time:0,type:"setValueAtTime",value:this._fromType(t.value)}),this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(no.getDefaults(),{multiplier:1,units:"hertz",value:1})}setTargetAtTime(t,e,n){e=this.toSeconds(e),this.setRampPoint(e);const s=this._fromType(t),i=this._events.get(e),o=Math.round(Math.max(1/n,1));for(let t=0;t<=o;t++){const o=n*t+e,r=this._exponentialApproach(i.time,i.value,s,n,o);this.linearRampToValueAtTime(this._toType(r),o)}return this}setValueAtTime(t,e){const n=this.toSeconds(e);super.setValueAtTime(t,e);const s=this._events.get(n),i=this._events.previousEvent(s),o=this._getTicksUntilEvent(i,n);return s.ticks=Math.max(o,0),this}linearRampToValueAtTime(t,e){const n=this.toSeconds(e);super.linearRampToValueAtTime(t,e);const s=this._events.get(n),i=this._events.previousEvent(s),o=this._getTicksUntilEvent(i,n);return s.ticks=Math.max(o,0),this}exponentialRampToValueAtTime(t,e){e=this.toSeconds(e);const n=this._fromType(t),s=this._events.get(e),i=Math.round(Math.max(10*(e-s.time),1)),o=(e-s.time)/i;for(let t=0;t<=i;t++){const i=o*t+s.time,r=this._exponentialInterpolate(s.time,s.value,e,n,i);this.linearRampToValueAtTime(this._toType(r),i)}return this}_getTicksUntilEvent(t,e){if(null===t)t={ticks:0,time:0,type:"setValueAtTime",value:0};else if(Ys(t.ticks)){const e=this._events.previousEvent(t);t.ticks=this._getTicksUntilEvent(e,t.time)}const n=this._fromType(this.getValueAtTime(t.time));let s=this._fromType(this.getValueAtTime(e));const i=this._events.get(e);return i&&i.time===e&&"setValueAtTime"===i.type&&(s=this._fromType(this.getValueAtTime(e-this.sampleTime))),.5*(e-t.time)*(n+s)+t.ticks}getTicksAtTime(t){const e=this.toSeconds(t),n=this._events.get(e);return Math.max(this._getTicksUntilEvent(n,e),0)}getDurationOfTicks(t,e){const n=this.toSeconds(e),s=this.getTicksAtTime(e);return this.getTimeOfTick(s+t)-n}getTimeOfTick(t){const e=this._events.get(t,"ticks"),n=this._events.getAfter(t,"ticks");if(e&&e.ticks===t)return e.time;if(e&&n&&"linearRampToValueAtTime"===n.type&&e.value!==n.value){const s=this._fromType(this.getValueAtTime(e.time)),i=(this._fromType(this.getValueAtTime(n.time))-s)/(n.time-e.time),o=Math.sqrt(Math.pow(s,2)-2*i*(e.ticks-t)),r=(-s+o)/i;return(r>0?r:(-s-o)/i)+e.time}return e?0===e.value?1/0:e.time+(t-e.ticks)/e.value:t/this._initialValue}ticksToTime(t,e){return this.getDurationOfTicks(t,e)}timeToTicks(t,e){const n=this.toSeconds(e),s=this.toSeconds(t),i=this.getTicksAtTime(n);return this.getTicksAtTime(n+s)-i}_fromType(t){return"bpm"===this.units&&this.multiplier?1/(60/t/this.multiplier):super._fromType(t)}_toType(t){return"bpm"===this.units&&this.multiplier?t/this.multiplier*60:super._toType(t)}get multiplier(){return this._multiplier}set multiplier(t){const e=this.value;this._multiplier=t,this.cancelScheduledValues(0),this.setValueAtTime(e,0)}}class Co extends uo{constructor(){const t=gi(Co.getDefaults(),arguments,["value"]);super(t),this.name="TickSignal",this.input=this._param=new bo({context:this.context,convert:t.convert,multiplier:t.multiplier,param:this._constantSource.offset,units:t.units,value:t.value})}static getDefaults(){return Object.assign(uo.getDefaults(),{multiplier:1,units:"hertz",value:1})}ticksToTime(t,e){return this._param.ticksToTime(t,e)}timeToTicks(t,e){return this._param.timeToTicks(t,e)}getTimeOfTick(t){return this._param.getTimeOfTick(t)}getDurationOfTicks(t,e){return this._param.getDurationOfTicks(t,e)}getTicksAtTime(t){return this._param.getTicksAtTime(t)}get multiplier(){return this._param.multiplier}set multiplier(t){this._param.multiplier=t}dispose(){return super.dispose(),this._param.dispose(),this}}class Ao extends eo{constructor(){const t=gi(Ao.getDefaults(),arguments,["frequency"]);super(t),this.name="TickSource",this._state=new To,this._tickOffset=new Ai,this._ticksAtTime=new Ai,this._secondsAtTime=new Ai,this.frequency=new Co({context:this.context,units:t.units,value:t.frequency}),Ri(this,"frequency"),this._state.setStateAtTime("stopped",0),this.setTicksAtTime(0,0)}static getDefaults(){return Object.assign({frequency:1,units:"hertz"},eo.getDefaults())}get state(){return this.getStateAtTime(this.now())}start(t,e){const n=this.toSeconds(t);return"started"!==this._state.getValueAtTime(n)&&(this._state.setStateAtTime("started",n),Zs(e)&&this.setTicksAtTime(e,n),this._ticksAtTime.cancel(n),this._secondsAtTime.cancel(n)),this}stop(t){const e=this.toSeconds(t);if("stopped"===this._state.getValueAtTime(e)){const t=this._state.get(e);t&&t.time>0&&(this._tickOffset.cancel(t.time),this._state.cancel(t.time))}return this._state.cancel(e),this._state.setStateAtTime("stopped",e),this.setTicksAtTime(0,e),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e),this}pause(t){const e=this.toSeconds(t);return"started"===this._state.getValueAtTime(e)&&(this._state.setStateAtTime("paused",e),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e)),this}cancel(t){return t=this.toSeconds(t),this._state.cancel(t),this._tickOffset.cancel(t),this._ticksAtTime.cancel(t),this._secondsAtTime.cancel(t),this}getTicksAtTime(t){const e=this.toSeconds(t),n=this._state.getLastState("stopped",e),s=this._ticksAtTime.get(e),i={state:"paused",time:e};this._state.add(i);let o=s||n,r=s?s.ticks:0,a=null;return this._state.forEachBetween(o.time,e+this.sampleTime,(t=>{let e=o.time;const n=this._tickOffset.get(t.time);n&&n.time>=o.time&&(r=n.ticks,e=n.time),"started"===o.state&&"started"!==t.state&&(r+=this.frequency.getTicksAtTime(t.time)-this.frequency.getTicksAtTime(e),t.time!==i.time&&(a={state:t.state,time:t.time,ticks:r})),o=t})),this._state.remove(i),a&&this._ticksAtTime.add(a),r}get ticks(){return this.getTicksAtTime(this.now())}set ticks(t){this.setTicksAtTime(t,this.now())}get seconds(){return this.getSecondsAtTime(this.now())}set seconds(t){const e=this.now(),n=this.frequency.timeToTicks(t,e);this.setTicksAtTime(n,e)}getSecondsAtTime(t){t=this.toSeconds(t);const e=this._state.getLastState("stopped",t),n={state:"paused",time:t};this._state.add(n);const s=this._secondsAtTime.get(t);let i=s||e,o=s?s.seconds:0,r=null;return this._state.forEachBetween(i.time,t+this.sampleTime,(t=>{let e=i.time;const s=this._tickOffset.get(t.time);s&&s.time>=i.time&&(o=s.seconds,e=s.time),"started"===i.state&&"started"!==t.state&&(o+=t.time-e,t.time!==n.time&&(r={state:t.state,time:t.time,seconds:o})),i=t})),this._state.remove(n),r&&this._secondsAtTime.add(r),o}setTicksAtTime(t,e){return e=this.toSeconds(e),this._tickOffset.cancel(e),this._tickOffset.add({seconds:this.frequency.getDurationOfTicks(t,e),ticks:t,time:e}),this._ticksAtTime.cancel(e),this._secondsAtTime.cancel(e),this}getStateAtTime(t){return t=this.toSeconds(t),this._state.getValueAtTime(t)}getTimeOfTick(t,e=this.now()){const n=this._tickOffset.get(e),s=this._state.get(e),i=Math.max(n.time,s.time),o=this.frequency.getTicksAtTime(i)+t-n.ticks;return this.frequency.getTimeOfTick(o)}forEachTickBetween(t,e,n){let s=this._state.get(t);this._state.forEachBetween(t,e,(e=>{s&&"started"===s.state&&"started"!==e.state&&this.forEachTickBetween(Math.max(s.time,t),e.time-this.sampleTime,n),s=e}));let i=null;if(s&&"started"===s.state){const o=Math.max(s.time,t),r=this.frequency.getTicksAtTime(o),a=r-this.frequency.getTicksAtTime(s.time);let c=Math.ceil(a)-a;c=Ci(c,1)?0:c;let h=this.frequency.getTimeOfTick(r+c);for(;h<e;){try{n(h,Math.round(this.getTicksAtTime(h)))}catch(t){i=t;break}h+=this.frequency.getDurationOfTicks(1,h)}}if(i)throw i;return this}dispose(){return super.dispose(),this._state.dispose(),this._tickOffset.dispose(),this._ticksAtTime.dispose(),this._secondsAtTime.dispose(),this.frequency.dispose(),this}}class So extends eo{constructor(){const t=gi(So.getDefaults(),arguments,["callback","frequency"]);super(t),this.name="Clock",this.callback=Vi,this._lastUpdate=0,this._state=new To("stopped"),this._boundLoop=this._loop.bind(this),this.callback=t.callback,this._tickSource=new Ao({context:this.context,frequency:t.frequency,units:t.units}),this._lastUpdate=0,this.frequency=this._tickSource.frequency,Ri(this,"frequency"),this._state.setStateAtTime("stopped",0),this.context.on("tick",this._boundLoop)}static getDefaults(){return Object.assign(eo.getDefaults(),{callback:Vi,frequency:1,units:"hertz"})}get state(){return this._state.getValueAtTime(this.now())}start(t,e){ti(this.context);const n=this.toSeconds(t);return this.log("start",n),"started"!==this._state.getValueAtTime(n)&&(this._state.setStateAtTime("started",n),this._tickSource.start(n,e),n<this._lastUpdate&&this.emit("start",n,e)),this}stop(t){const e=this.toSeconds(t);return this.log("stop",e),this._state.cancel(e),this._state.setStateAtTime("stopped",e),this._tickSource.stop(e),e<this._lastUpdate&&this.emit("stop",e),this}pause(t){const e=this.toSeconds(t);return"started"===this._state.getValueAtTime(e)&&(this._state.setStateAtTime("paused",e),this._tickSource.pause(e),e<this._lastUpdate&&this.emit("pause",e)),this}get ticks(){return Math.ceil(this.getTicksAtTime(this.now()))}set ticks(t){this._tickSource.ticks=t}get seconds(){return this._tickSource.seconds}set seconds(t){this._tickSource.seconds=t}getSecondsAtTime(t){return this._tickSource.getSecondsAtTime(t)}setTicksAtTime(t,e){return this._tickSource.setTicksAtTime(t,e),this}getTimeOfTick(t,e=this.now()){return this._tickSource.getTimeOfTick(t,e)}getTicksAtTime(t){return this._tickSource.getTicksAtTime(t)}nextTickTime(t,e){const n=this.toSeconds(e),s=this.getTicksAtTime(n);return this._tickSource.getTimeOfTick(s+t,n)}_loop(){const t=this._lastUpdate,e=this.now();this._lastUpdate=e,this.log("loop",t,e),t!==e&&(this._state.forEachBetween(t,e,(t=>{switch(t.state){case"started":const e=this._tickSource.getTicksAtTime(t.time);this.emit("start",t.time,e);break;case"stopped":0!==t.time&&this.emit("stop",t.time);break;case"paused":this.emit("pause",t.time)}})),this._tickSource.forEachTickBetween(t,e,((t,e)=>{this.callback(t,e)})))}getStateAtTime(t){const e=this.toSeconds(t);return this._state.getValueAtTime(e)}dispose(){return super.dispose(),this.context.off("tick",this._boundLoop),this._tickSource.dispose(),this._state.dispose(),this}}Di.mixin(So);class ko{constructor(t,e){this.id=ko._eventId++,this._remainderTime=0;const n=Object.assign(ko.getDefaults(),e);this.transport=t,this.callback=n.callback,this._once=n.once,this.time=Math.floor(n.time),this._remainderTime=n.time-this.time}static getDefaults(){return{callback:Vi,once:!1,time:0}}get floatTime(){return this.time+this._remainderTime}invoke(t){if(this.callback){const e=this.transport.bpm.getDurationOfTicks(1,t);this.callback(t+this._remainderTime*e),this._once&&this.transport.clear(this.id)}}dispose(){return this.callback=void 0,this}}ko._eventId=0;class Oo extends ko{constructor(t,e){super(t,e),this._currentId=-1,this._nextId=-1,this._nextTick=this.time,this._boundRestart=this._restart.bind(this);const n=Object.assign(Oo.getDefaults(),e);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({},ko.getDefaults(),{duration:1/0,interval:1,once:!1})}invoke(t){this._createEvents(t),super.invoke(t)}_createEvent(){return bi(this._nextTick,this.floatTime+this.duration)?this.transport.scheduleOnce(this.invoke.bind(this),new yo(this.context,this._nextTick).toSeconds()):-1}_createEvents(t){bi(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 yo(this.context,this._nextTick).toSeconds()))}_restart(t){this.transport.clear(this._currentId),this.transport.clear(this._nextId),this._nextTick=this.floatTime;const e=this.transport.getTicksAtTime(t);wi(e,this.time)&&(this._nextTick=this.floatTime+Math.ceil((e-this.floatTime)/this._interval)*this._interval),this._currentId=this._createEvent(),this._nextTick+=this._interval,this._nextId=this._createEvent()}dispose(){return super.dispose(),this.transport.clear(this._currentId),this.transport.clear(this._nextId),this.transport.off("start",this._boundRestart),this.transport.off("loopStart",this._boundRestart),this.transport.off("ticks",this._boundRestart),this}}class Mo extends eo{constructor(){const t=gi(Mo.getDefaults(),arguments);super(t),this.name="Transport",this._loop=new mo(!1),this._loopStart=0,this._loopEnd=0,this._scheduledEvents={},this._timeline=new Ai,this._repeatedEvents=new xo,this._syncedSignals=[],this._swingAmount=0,this._ppq=t.ppq,this._clock=new So({callback:this._processTick.bind(this),context:this.context,frequency:0,units:"bpm"}),this._bindClockEvents(),this.bpm=this._clock.frequency,this._clock.frequency.multiplier=t.ppq,this.bpm.setValueAtTime(t.bpm,0),Ri(this,"bpm"),this._timeSignature=t.timeSignature,this._swingTicks=t.ppq/2}static getDefaults(){return Object.assign(eo.getDefaults(),{bpm:120,loopEnd:"4m",loopStart:0,ppq:192,swing:0,swingSubdivision:"8n",timeSignature:4})}_processTick(t,e){if(this._loop.get(t)&&e>=this._loopEnd&&(this.emit("loopEnd",t),this._clock.setTicksAtTime(this._loopStart,t),e=this._loopStart,this.emit("loopStart",t,this._clock.getSecondsAtTime(t)),this.emit("loop",t)),this._swingAmount>0&&e%this._ppq!=0&&e%(2*this._swingTicks)!=0){const n=e%(2*this._swingTicks)/(2*this._swingTicks),s=Math.sin(n*Math.PI)*this._swingAmount;t+=new yo(this.context,2*this._swingTicks/3).toSeconds()*s}si(!0),this._timeline.forEachAtTime(e,(e=>e.invoke(t))),si(!1)}schedule(t,e){const n=new ko(this,{callback:t,time:new to(this.context,e).toTicks()});return this._addEvent(n,this._timeline)}scheduleRepeat(t,e,n,s=1/0){const i=new Oo(this,{callback:t,duration:new Hi(this.context,s).toTicks(),interval:new Hi(this.context,e).toTicks(),time:new to(this.context,n).toTicks()});return this._addEvent(i,this._repeatedEvents)}scheduleOnce(t,e){const n=new ko(this,{callback:t,once:!0,time:new to(this.context,e).toTicks()});return this._addEvent(n,this._timeline)}clear(t){if(this._scheduledEvents.hasOwnProperty(t)){const e=this._scheduledEvents[t.toString()];e.timeline.remove(e.event),e.event.dispose(),delete this._scheduledEvents[t.toString()]}return this}_addEvent(t,e){return this._scheduledEvents[t.id.toString()]={event:t,timeline:e},e.add(t),t.id}cancel(t=0){const e=this.toTicks(t);return this._timeline.forEachFrom(e,(t=>this.clear(t.id))),this._repeatedEvents.forEachFrom(e,(t=>this.clear(t.id))),this}_bindClockEvents(){this._clock.on("start",((t,e)=>{e=new yo(this.context,e).toSeconds(),this.emit("start",t,e)})),this._clock.on("stop",(t=>{this.emit("stop",t)})),this._clock.on("pause",(t=>{this.emit("pause",t)}))}get state(){return this._clock.getStateAtTime(this.now())}start(t,e){let n;return this.context.resume(),Zs(e)&&(n=this.toTicks(e)),this._clock.start(t,n),this}stop(t){return this._clock.stop(t),this}pause(t){return this._clock.pause(t),this}toggle(t){return t=this.toSeconds(t),"started"!==this._clock.getStateAtTime(t)?this.start(t):this.stop(t),this}get timeSignature(){return this._timeSignature}set timeSignature(t){Hs(t)&&(t=t[0]/t[1]*4),this._timeSignature=t}get loopStart(){return new Hi(this.context,this._loopStart,"i").toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t)}get loopEnd(){return new Hi(this.context,this._loopEnd,"i").toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t)}get loop(){return this._loop.get(this.now())}set loop(t){this._loop.set(t,this.now())}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get swing(){return this._swingAmount}set swing(t){this._swingAmount=t}get swingSubdivision(){return new yo(this.context,this._swingTicks).toNotation()}set swingSubdivision(t){this._swingTicks=this.toTicks(t)}get position(){const t=this.now(),e=this._clock.getTicksAtTime(t);return new yo(this.context,e).toBarsBeatsSixteenths()}set position(t){const e=this.toTicks(t);this.ticks=e}get seconds(){return this._clock.seconds}set seconds(t){const e=this.now(),n=this._clock.frequency.timeToTicks(t,e);this.ticks=n}get progress(){if(this.loop){const t=this.now();return(this._clock.getTicksAtTime(t)-this._loopStart)/(this._loopEnd-this._loopStart)}return 0}get ticks(){return this._clock.ticks}set ticks(t){if(this._clock.ticks!==t){const e=this.now();if("started"===this.state){const n=this._clock.getTicksAtTime(e),s=e+this._clock.frequency.getDurationOfTicks(Math.ceil(n)-n,e);this.emit("stop",s),this._clock.setTicksAtTime(t,s),this.emit("start",s,this._clock.getSecondsAtTime(s))}else this.emit("ticks",e),this._clock.setTicksAtTime(t,e)}}getTicksAtTime(t){return this._clock.getTicksAtTime(t)}getSecondsAtTime(t){return this._clock.getSecondsAtTime(t)}get PPQ(){return this._clock.frequency.multiplier}set PPQ(t){this._clock.frequency.multiplier=t}nextSubdivision(t){if(t=this.toTicks(t),"started"!==this.state)return 0;{const e=this.now(),n=t-this.getTicksAtTime(e)%t;return this._clock.nextTickTime(n,e)}}syncSignal(t,e){const n=this.now();let s=this.bpm,i=1/(60/s.getValueAtTime(n)/this.PPQ),o=[];if("time"===t.units){const t=1/64/i,e=new ao(t),n=new vo(-1),r=new ao(t);s.chain(e,n,r),s=r,i=1/i,o=[e,n,r]}e||(e=0!==t.getValueAtTime(n)?t.getValueAtTime(n)/i:0);const r=new ao(e);return s.connect(r),r.connect(t._param),o.push(r),this._syncedSignals.push({initial:t.value,nodes:o,signal:t}),t.value=0,this}unsyncSignal(t){for(let e=this._syncedSignals.length-1;e>=0;e--){const n=this._syncedSignals[e];n.signal===t&&(n.nodes.forEach((t=>t.dispose())),n.signal.value=n.initial,this._syncedSignals.splice(e,1))}return this}dispose(){return super.dispose(),this._clock.dispose(),Ni(this,"bpm"),this._timeline.dispose(),this._repeatedEvents.dispose(),this}}Di.mixin(Mo),ki((t=>{t.transport=new Mo({context:t})})),Mi((t=>{t.transport.dispose()}));class Do extends so{constructor(t){super(t),this.input=void 0,this._state=new To("stopped"),this._synced=!1,this._scheduled=[],this._syncedStart=Vi,this._syncedStop=Vi,this._state.memory=100,this._state.increasing=!0,this._volume=this.output=new po({context:this.context,mute:t.mute,volume:t.volume}),this.volume=this._volume.volume,Ri(this,"volume"),this.onstop=t.onstop}static getDefaults(){return Object.assign(so.getDefaults(),{mute:!1,onstop:Vi,volume:0})}get state(){return this._synced?"started"===this.context.transport.state?this._state.getValueAtTime(this.context.transport.seconds):"stopped":this._state.getValueAtTime(this.now())}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}_clampToCurrentTime(t){return this._synced?t:Math.max(t,this.context.currentTime)}start(t,e,n){let s=Ys(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(s=this._clampToCurrentTime(s),this._synced||"started"!==this._state.getValueAtTime(s))if(this.log("start",s),this._state.setStateAtTime("started",s),this._synced){const t=this._state.get(s);t&&(t.offset=this.toSeconds(vi(e,0)),t.duration=n?this.toSeconds(n):void 0);const i=this.context.transport.schedule((t=>{this._start(t,e,n)}),s);this._scheduled.push(i),"started"===this.context.transport.state&&this.context.transport.getSecondsAtTime(this.immediate())>s&&this._syncedStart(this.now(),this.context.transport.seconds)}else ti(this.context),this._start(s,e,n);else Js(wi(s,this._state.get(s).time),"Start time must be strictly greater than previous start time"),this._state.cancel(s),this._state.setStateAtTime("started",s),this.log("restart",s),this.restart(s,e,n);return this}stop(t){let e=Ys(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(e=this._clampToCurrentTime(e),"started"===this._state.getValueAtTime(e)||Zs(this._state.getNextState("started",e))){if(this.log("stop",e),this._synced){const t=this.context.transport.schedule(this._stop.bind(this),e);this._scheduled.push(t)}else this._stop(e);this._state.cancel(e),this._state.setStateAtTime("stopped",e)}return this}restart(t,e,n){return t=this.toSeconds(t),"started"===this._state.getValueAtTime(t)&&(this._state.cancel(t),this._restart(t,e,n)),this}sync(){return this._synced||(this._synced=!0,this._syncedStart=(t,e)=>{if(wi(e,0)){const n=this._state.get(e);if(n&&"started"===n.state&&n.time!==e){const s=e-this.toSeconds(n.time);let i;n.duration&&(i=this.toSeconds(n.duration)-s),this._start(t,this.toSeconds(n.offset)+s,i)}}},this._syncedStop=t=>{const e=this.context.transport.getSecondsAtTime(Math.max(t-this.sampleTime,0));"started"===this._state.getValueAtTime(e)&&this._stop(t)},this.context.transport.on("start",this._syncedStart),this.context.transport.on("loopStart",this._syncedStart),this.context.transport.on("stop",this._syncedStop),this.context.transport.on("pause",this._syncedStop),this.context.transport.on("loopEnd",this._syncedStop)),this}unsync(){return this._synced&&(this.context.transport.off("stop",this._syncedStop),this.context.transport.off("pause",this._syncedStop),this.context.transport.off("loopEnd",this._syncedStop),this.context.transport.off("start",this._syncedStart),this.context.transport.off("loopStart",this._syncedStart)),this._synced=!1,this._scheduled.forEach((t=>this.context.transport.clear(t))),this._scheduled=[],this._state.cancel(0),this._stop(0),this}dispose(){return super.dispose(),this.onstop=Vi,this.unsync(),this._volume.dispose(),this._state.dispose(),this}}class Io extends co{constructor(){const t=gi(Io.getDefaults(),arguments,["frequency","type"]);super(t),this.name="ToneOscillatorNode",this._oscillator=this.context.createOscillator(),this._internalChannels=[this._oscillator],oo(this._oscillator,this._gainNode),this.type=t.type,this.frequency=new no({context:this.context,param:this._oscillator.frequency,units:"frequency",value:t.frequency}),this.detune=new no({context:this.context,param:this._oscillator.detune,units:"cents",value:t.detune}),Ri(this,["frequency","detune"])}static getDefaults(){return Object.assign(co.getDefaults(),{detune:0,frequency:440,type:"sine"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._oscillator.start(e),this}_stopSource(t){this._oscillator.stop(t)}setPeriodicWave(t){return this._oscillator.setPeriodicWave(t),this}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._oscillator.disconnect(),this.frequency.dispose(),this.detune.dispose(),this}}class Eo extends Do{constructor(){const t=gi(Eo.getDefaults(),arguments,["frequency","type"]);super(t),this.name="Oscillator",this._oscillator=null,this.frequency=new uo({context:this.context,units:"frequency",value:t.frequency}),Ri(this,"frequency"),this.detune=new uo({context:this.context,units:"cents",value:t.detune}),Ri(this,"detune"),this._partials=t.partials,this._partialCount=t.partialCount,this._type=t.type,t.partialCount&&"custom"!==t.type&&(this._type=this.baseType+t.partialCount.toString()),this.phase=t.phase}static getDefaults(){return Object.assign(Do.getDefaults(),{detune:0,frequency:440,partialCount:0,partials:[],phase:0,type:"sine"})}_start(t){const e=this.toSeconds(t),n=new Io({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(e)}_stop(t){const e=this.toSeconds(t);this._oscillator&&this._oscillator.stop(e)}_restart(t){const e=this.toSeconds(t);return this.log("restart",e),this._oscillator&&this._oscillator.cancelStop(),this._state.cancel(e),this}syncFrequency(){return this.context.transport.syncSignal(this.frequency),this}unsyncFrequency(){return this.context.transport.unsyncSignal(this.frequency),this}_getCachedPeriodicWave(){if("custom"===this._type){return Eo._periodicWaveCache.find((t=>{return t.phase===this._phase&&(e=t.partials,n=this._partials,e.length===n.length&&e.every(((t,e)=>n[e]===t)));var e,n}))}{const t=Eo._periodicWaveCache.find((t=>t.type===this._type&&t.phase===this._phase));return this._partialCount=t?t.partialCount:this._partialCount,t}}get type(){return this._type}set type(t){this._type=t;const e=-1!==["sine","square","sawtooth","triangle"].indexOf(t);if(0===this._phase&&e)this._wave=void 0,this._partialCount=0,null!==this._oscillator&&(this._oscillator.type=t);else{const e=this._getCachedPeriodicWave();if(Zs(e)){const{partials:t,wave:n}=e;this._wave=n,this._partials=t,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave)}else{const[e,n]=this._getRealImaginary(t,this._phase),s=this.context.createPeriodicWave(e,n);this._wave=s,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),Eo._periodicWaveCache.push({imag:n,partialCount:this._partialCount,partials:this._partials,phase:this._phase,real:e,type:this._type,wave:this._wave}),Eo._periodicWaveCache.length>100&&Eo._periodicWaveCache.shift()}}}get baseType(){return this._type.replace(this.partialCount.toString(),"")}set baseType(t){this.partialCount&&"custom"!==this._type&&"custom"!==t?this.type=t+this.partialCount:this.type=t}get partialCount(){return this._partialCount}set partialCount(t){Ks(t,0);let e=this._type;const n=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);if(n&&(e=n[1]),"custom"!==this._type)this.type=0===t?e:e+t.toString();else{const e=new Float32Array(t);this._partials.forEach(((t,n)=>e[n]=t)),this._partials=Array.from(e),this.type=this._type}}_getRealImaginary(t,e){let n=2048;const s=new Float32Array(n),i=new Float32Array(n);let o=1;if("custom"===t){if(o=this._partials.length+1,this._partialCount=this._partials.length,n=o,0===this._partials.length)return[s,i]}else{const e=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(t);e?(o=parseInt(e[2],10)+1,this._partialCount=parseInt(e[2],10),t=e[1],o=Math.max(o,2),n=o):this._partialCount=0,this._partials=[]}for(let r=1;r<n;++r){const n=2/(r*Math.PI);let a;switch(t){case"sine":a=r<=o?1:0,this._partials[r-1]=a;break;case"square":a=1&r?2*n:0,this._partials[r-1]=a;break;case"sawtooth":a=n*(1&r?1:-1),this._partials[r-1]=a;break;case"triangle":a=1&r?n*n*2*(r-1>>1&1?-1:1):0,this._partials[r-1]=a;break;case"custom":a=this._partials[r-1];break;default:throw new TypeError("Oscillator: invalid type: "+t)}0!==a?(s[r]=-a*Math.sin(e*r),i[r]=a*Math.cos(e*r)):(s[r]=0,i[r]=0)}return[s,i]}_inverseFFT(t,e,n){let s=0;const i=t.length;for(let o=0;o<i;o++)s+=t[o]*Math.cos(o*n)+e[o]*Math.sin(o*n);return s}getInitialValue(){const[t,e]=this._getRealImaginary(this._type,0);let n=0;const s=2*Math.PI;for(let i=0;i<32;i++)n=Math.max(this._inverseFFT(t,e,i/32*s),n);return i=-this._inverseFFT(t,e,this._phase)/n,o=-1,r=1,Math.max(Math.min(i,r),o);var i,o,r}get partials(){return this._partials.slice(0,this.partialCount)}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this.type="custom")}get phase(){return this._phase*(180/Math.PI)}set phase(t){this._phase=t*Math.PI/180,this.type=this._type}asArray(){return hi(this,arguments,void 0,(function*(t=1024){return function(t,e){return hi(this,void 0,void 0,(function*(){const n=e/t.context.sampleRate,s=new Fi(1,n,t.context.sampleRate);return new t.constructor(Object.assign(t.get(),{frequency:2/n,detune:0,context:s})).toDestination().start(0),(yield s.render()).getChannelData(0)}))}(this,t)}))}dispose(){return super.dispose(),null!==this._oscillator&&this._oscillator.dispose(),this._wave=void 0,this.frequency.dispose(),this.detune.dispose(),this}}Eo._periodicWaveCache=[];class Ro{constructor(t=440,e="sine"){if("string"==typeof t&&"string"==typeof e){let n=t;t=440,e=n}if("string"==typeof t&&"number"==typeof e){let n=e;e=t,t=n}this.frequency=t,this.type=e,this.osc=(new Eo).toDestination(),this.osc.frequency.value=this.frequency,this.osc.type=this.type,this.osc.volume.value=-6}freq(t,e=0){this.osc.frequency.rampTo(Li(t,0,24e3),e)}phase(t){this.osc.phase=t}setType(t){this.osc.type=t}amp(t,e=.1){if("object"==typeof t)return void t.getNode().connect(this.osc.volume);let n=Xi(t);this.osc.volume.rampTo(n,e)}start(){this.osc.start()}stop(){this.osc.stop()}connect(t){"function"==typeof t.getNode?this.osc.connect(t.getNode()):this.osc.connect(t)}disconnect(){this.osc.disconnect(Ei.destination)}getNode(){return this.osc}}var No=Ro;function Vo(t,e=1/0){const n=new WeakMap;return function(s,i){Reflect.defineProperty(s,i,{configurable:!0,enumerable:!0,get:function(){return n.get(this)},set:function(s){Ks(this.toSeconds(s),t,e),n.set(this,s)}})}}class Po extends so{constructor(){const t=gi(Po.getDefaults(),arguments,["attack","decay","sustain","release"]);super(t),this.name="Envelope",this._sig=new uo({context:this.context,value:0}),this.output=this._sig,this.input=void 0,this.attack=t.attack,this.decay=t.decay,this.sustain=t.sustain,this.release=t.release,this.attackCurve=t.attackCurve,this.releaseCurve=t.releaseCurve,this.decayCurve=t.decayCurve}static getDefaults(){return Object.assign(so.getDefaults(),{attack:.01,attackCurve:"linear",decay:.1,decayCurve:"exponential",release:1,releaseCurve:"exponential",sustain:.5})}get value(){return this.getValueAtTime(this.now())}_getCurve(t,e){if(Qs(t))return t;{let n;for(n in Fo)if(Fo[n][e]===t)return n;return t}}_setCurve(t,e,n){if(Qs(n)&&Reflect.has(Fo,n)){const s=Fo[n];$s(s)?"_decayCurve"!==t&&(this[t]=s[e]):this[t]=s}else{if(!Hs(n)||"_decayCurve"===t)throw new Error("Envelope: invalid curve: "+n);this[t]=n}}get attackCurve(){return this._getCurve(this._attackCurve,"In")}set attackCurve(t){this._setCurve("_attackCurve","In",t)}get releaseCurve(){return this._getCurve(this._releaseCurve,"Out")}set releaseCurve(t){this._setCurve("_releaseCurve","Out",t)}get decayCurve(){return this._getCurve(this._decayCurve,"Out")}set decayCurve(t){this._setCurve("_decayCurve","Out",t)}triggerAttack(t,e=1){this.log("triggerAttack",t,e),t=this.toSeconds(t);let n=this.toSeconds(this.attack);const s=this.toSeconds(this.decay),i=this.getValueAtTime(t);if(i>0){n=(1-i)/(1/n)}if(n<this.sampleTime)this._sig.cancelScheduledValues(t),this._sig.setValueAtTime(e,t);else if("linear"===this._attackCurve)this._sig.linearRampTo(e,n,t);else if("exponential"===this._attackCurve)this._sig.targetRampTo(e,n,t);else{this._sig.cancelAndHoldAtTime(t);let s=this._attackCurve;for(let t=1;t<s.length;t++)if(s[t-1]<=i&&i<=s[t]){s=this._attackCurve.slice(t),s[0]=i;break}this._sig.setValueCurveAtTime(s,t,n,e)}if(s&&this.sustain<1){const i=e*this.sustain,o=t+n;this.log("decay",o),"linear"===this._decayCurve?this._sig.linearRampToValueAtTime(i,s+o):this._sig.exponentialApproachValueAtTime(i,o,s)}return this}triggerRelease(t){this.log("triggerRelease",t),t=this.toSeconds(t);const e=this.getValueAtTime(t);if(e>0){const n=this.toSeconds(this.release);n<this.sampleTime?this._sig.setValueAtTime(0,t):"linear"===this._releaseCurve?this._sig.linearRampTo(0,n,t):"exponential"===this._releaseCurve?this._sig.targetRampTo(0,n,t):(Js(Hs(this._releaseCurve),"releaseCurve must be either 'linear', 'exponential' or an array"),this._sig.cancelAndHoldAtTime(t),this._sig.setValueCurveAtTime(this._releaseCurve,t,n,e))}return this}getValueAtTime(t){return this._sig.getValueAtTime(t)}triggerAttackRelease(t,e,n=1){return e=this.toSeconds(e),this.triggerAttack(e,n),this.triggerRelease(e+this.toSeconds(t)),this}cancel(t){return this._sig.cancelScheduledValues(this.toSeconds(t)),this}connect(t,e=0,n=0){return lo(this,t,e,n),this}asArray(){return hi(this,arguments,void 0,(function*(t=1024){const e=t/this.context.sampleRate,n=new Fi(1,e,this.context.sampleRate),s=this.toSeconds(this.attack)+this.toSeconds(this.decay),i=s+this.toSeconds(this.release),o=.1*i,r=i+o,a=new this.constructor(Object.assign(this.get(),{attack:e*this.toSeconds(this.attack)/r,decay:e*this.toSeconds(this.decay)/r,release:e*this.toSeconds(this.release)/r,context:n}));a._sig.toDestination(),a.triggerAttackRelease(e*(s+o)/r,0);return(yield n.render()).getChannelData(0)}))}dispose(){return super.dispose(),this._sig.dispose(),this}}ci([Vo(0)],Po.prototype,"attack",void 0),ci([Vo(0)],Po.prototype,"decay",void 0),ci([function(t,e=1/0){const n=new WeakMap;return function(s,i){Reflect.defineProperty(s,i,{configurable:!0,enumerable:!0,get:function(){return n.get(this)},set:function(s){Ks(s,t,e),n.set(this,s)}})}}(0,1)],Po.prototype,"sustain",void 0),ci([Vo(0)],Po.prototype,"release",void 0);const Fo=(()=>{const t=128;let e,n;const s=[];for(e=0;e<t;e++)s[e]=Math.sin(e/127*(Math.PI/2));const i=[];for(e=0;e<127;e++){n=e/127;const t=Math.sin(n*(2*Math.PI)*6.4-Math.PI/2)+1;i[e]=t/10+.83*n}i[127]=1;const o=[];for(e=0;e<t;e++)o[e]=Math.ceil(e/127*5)/5;const r=[];for(e=0;e<t;e++)n=e/127,r[e]=.5*(1-Math.cos(Math.PI*n));const a=[];for(e=0;e<t;e++){n=e/127;const t=4*Math.pow(n,3)+.2,s=Math.cos(t*Math.PI*2*n);a[e]=Math.abs(s*(1-n))}function c(t){const e=new Array(t.length);for(let n=0;n<t.length;n++)e[n]=1-t[n];return e}return{bounce:{In:c(a),Out:a},cosine:{In:s,Out:(h=s,h.slice(0).reverse())},exponential:"exponential",linear:"linear",ripple:{In:i,Out:c(i)},sine:{In:r,Out:c(r)},step:{In:o,Out:c(o)}};var h})();class qo extends Po{constructor(){super(gi(qo.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="AmplitudeEnvelope",this._gainNode=new ao({context:this.context,gain:0}),this.output=this._gainNode,this.input=this._gainNode,this._sig.connect(this._gainNode.gain),this.output=this._gainNode,this.input=this._gainNode}dispose(){return super.dispose(),this._gainNode.dispose(),this}}var Bo=class{constructor(t=.1,e=.12,n=.1,s=.2){this.attack=t,this.attackLevel=1,this.decay=e,this.sustain=n,this.release=s,this.envelope=new qo({attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release}).toDestination()}play(){this.envelope.triggerAttackRelease(this.sustain)}triggerAttack(){this.envelope.triggerAttack()}triggerRelease(){this.envelope.triggerRelease()}setInput(t){t.getNode().connect(this.envelope)}setADSR(t,e,n,s){this.envelope.attack=t,this.envelope.decay=e,this.envelope.sustain=n,this.envelope.release=s}releaseTime(t){this.envelope.release=t}attackTime(t){this.envelope.attack=t}connect(t){this.envelope.connect(t.getNode())}disconnect(){this.envelope.disconnect(Ei.destination)}getNode(){return this.envelope}};class Wo extends so{constructor(){const t=gi(Wo.getDefaults(),arguments,["delayTime","maxDelay"]);super(t),this.name="Delay";const e=this.toSeconds(t.maxDelay);this._maxDelay=Math.max(e,this.toSeconds(t.delayTime)),this._delayNode=this.input=this.output=this.context.createDelay(e),this.delayTime=new no({context:this.context,param:this._delayNode.delayTime,units:"time",value:t.delayTime,minValue:0,maxValue:this.maxDelay}),Ri(this,"delayTime")}static getDefaults(){return Object.assign(so.getDefaults(),{delayTime:0,maxDelay:1})}get maxDelay(){return this._maxDelay}dispose(){return super.dispose(),this._delayNode.disconnect(),this.delayTime.dispose(),this}}class jo extends _o{constructor(){super(...arguments),this.name="GainToAudio",this._norm=new go({context:this.context,mapping:t=>2*Math.abs(t)-1}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class zo extends so{constructor(){const t=gi(zo.getDefaults(),arguments,["fade"]);super(t),this.name="CrossFade",this._panner=this.context.createStereoPanner(),this._split=this.context.createChannelSplitter(2),this._g2a=new jo({context:this.context}),this.a=new ao({context:this.context,gain:0}),this.b=new ao({context:this.context,gain:0}),this.output=new ao({context:this.context}),this._internalChannels=[this.a,this.b],this.fade=new uo({context:this.context,units:"normalRange",value:t.fade}),Ri(this,"fade"),this.context.getConstant(1).connect(this._panner),this._panner.connect(this._split),this._panner.channelCount=1,this._panner.channelCountMode="explicit",oo(this._split,this.a.gain,0),oo(this._split,this.b.gain,1),this.fade.chain(this._g2a,this._panner.pan),this.a.connect(this.output),this.b.connect(this.output)}static getDefaults(){return Object.assign(so.getDefaults(),{fade:.5})}dispose(){return super.dispose(),this.a.dispose(),this.b.dispose(),this.output.dispose(),this.fade.dispose(),this._g2a.dispose(),this._panner.disconnect(),this._split.disconnect(),this}}class Lo extends so{constructor(t){super(t),this.name="Effect",this._dryWet=new zo({context:this.context}),this.wet=this._dryWet.fade,this.effectSend=new ao({context:this.context}),this.effectReturn=new ao({context:this.context}),this.input=new ao({context:this.context}),this.output=this._dryWet,this.input.fan(this._dryWet.a,this.effectSend),this.effectReturn.connect(this._dryWet.b),this.wet.setValueAtTime(t.wet,0),this._internalChannels=[this.effectReturn,this.effectSend],Ri(this,"wet")}static getDefaults(){return Object.assign(so.getDefaults(),{wet:1})}connectEffect(t){return this._internalChannels.push(t),this.effectSend.chain(t,this.effectReturn),this}dispose(){return super.dispose(),this._dryWet.dispose(),this.effectSend.dispose(),this.effectReturn.dispose(),this.wet.dispose(),this}}class Uo extends Lo{constructor(t){super(t),this.name="FeedbackEffect",this._feedbackGain=new ao({context:this.context,gain:t.feedback,units:"normalRange"}),this.feedback=this._feedbackGain.gain,Ri(this,"feedback"),this.effectReturn.chain(this._feedbackGain,this.effectSend)}static getDefaults(){return Object.assign(Lo.getDefaults(),{feedback:.125})}dispose(){return super.dispose(),this._feedbackGain.dispose(),this.feedback.dispose(),this}}class Xo extends Uo{constructor(){const t=gi(Xo.getDefaults(),arguments,["delayTime","feedback"]);super(t),this.name="FeedbackDelay",this._delayNode=new Wo({context:this.context,delayTime:t.delayTime,maxDelay:t.maxDelay}),this.delayTime=this._delayNode.delayTime,this.connectEffect(this._delayNode),Ri(this,"delayTime")}static getDefaults(){return Object.assign(Uo.getDefaults(),{delayTime:.25,maxDelay:1})}dispose(){return super.dispose(),this._delayNode.dispose(),this.delayTime.dispose(),this}}var Yo=class{constructor(t=.25,e=.2){this.d=t,this.f=e,this.delay=new Xo(this.d,this.f).toDestination()}delayTime(t,e=.1){0!=e?this.delay.delayTime.rampTo(Li(t,0,1),e):this.delay.delayTime.value=Li(t,0,1)}feedback(t){this.delay.feedback.rampTo(Li(t,0,.99),.1)}process(t,e,n){this.delay.delayTime.value=e,this.delay.feedback.value=n,t.getNode().connect(this.delay)}amp(t){let e=Xi(t);this.delay.volume.rampTo(e,.1)}getNode(){return this.delay}connect(t){"function"==typeof t.getNode?this.delay.connect(t.getNode()):this.delay.connect(t)}disconnect(){this.delay.disconnect(Ei.destination)}};class Zo extends so{constructor(){const t=gi(Zo.getDefaults(),arguments,["channels"]);super(t),this.name="Merge",this._merger=this.output=this.input=this.context.createChannelMerger(t.channels)}static getDefaults(){return Object.assign(so.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._merger.disconnect(),this}}class Go extends co{constructor(){const t=gi(Go.getDefaults(),arguments,["url","onload"]);super(t),this.name="ToneBufferSource",this._source=this.context.createBufferSource(),this._internalChannels=[this._source],this._sourceStarted=!1,this._sourceStopped=!1,oo(this._source,this._gainNode),this._source.onended=()=>this._stopSource(),this.playbackRate=new no({context:this.context,param:this._source.playbackRate,units:"positive",value:t.playbackRate}),this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this._buffer=new Pi(t.url,t.onload,t.onerror),this._internalChannels.push(this._source)}static getDefaults(){return Object.assign(co.getDefaults(),{url:new Pi,loop:!1,loopEnd:0,loopStart:0,onload:Vi,onerror:Vi,playbackRate:1})}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t}get curve(){return this._curve}set curve(t){this._curve=t}start(t,e,n,s=1){Js(this.buffer.loaded,"buffer is either not set or not loaded");const i=this.toSeconds(t);this._startGain(i,s),e=this.loop?vi(e,this.loopStart):vi(e,0);let o=Math.max(this.toSeconds(e),0);if(this.loop){const t=this.toSeconds(this.loopEnd)||this.buffer.duration,e=this.toSeconds(this.loopStart),n=t-e;Ti(o,t)&&(o=(o-e)%n+e),Ci(o,this.buffer.duration)&&(o=0)}if(this._source.buffer=this.buffer.get(),this._source.loopEnd=this.toSeconds(this.loopEnd)||this.buffer.duration,bi(o,this.buffer.duration)&&(this._sourceStarted=!0,this._source.start(i,o)),Zs(n)){let t=this.toSeconds(n);t=Math.max(t,0),this.stop(i+t)}return this}_stopSource(t){!this._sourceStopped&&this._sourceStarted&&(this._sourceStopped=!0,this._source.stop(this.toSeconds(t)),this._onended())}get loopStart(){return this._source.loopStart}set loopStart(t){this._source.loopStart=this.toSeconds(t)}get loopEnd(){return this._source.loopEnd}set loopEnd(t){this._source.loopEnd=this.toSeconds(t)}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._source.loop}set loop(t){this._source.loop=t,this._sourceStarted&&this.cancelStop()}dispose(){return super.dispose(),this._source.onended=null,this._source.disconnect(),this._buffer.dispose(),this.playbackRate.dispose(),this}}class $o extends Do{constructor(){const t=gi($o.getDefaults(),arguments,["type"]);super(t),this.name="Noise",this._source=null,this._playbackRate=t.playbackRate,this.type=t.type,this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut}static getDefaults(){return Object.assign(Do.getDefaults(),{fadeIn:0,fadeOut:0,playbackRate:1,type:"white"})}get type(){return this._type}set type(t){if(Js(t in Jo,"Noise: invalid type: "+t),this._type!==t&&(this._type=t,"started"===this.state)){const t=this.now();this._stop(t),this._start(t)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._source&&(this._source.playbackRate.value=t)}_start(t){const e=Jo[this._type];this._source=new Go({url:e,context:this.context,fadeIn:this._fadeIn,fadeOut:this._fadeOut,loop:!0,onended:()=>this.onstop(this),playbackRate:this._playbackRate}).connect(this.output),this._source.start(this.toSeconds(t),Math.random()*(e.duration-.001))}_stop(t){this._source&&(this._source.stop(this.toSeconds(t)),this._source=null)}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this._source&&(this._source.fadeIn=this._fadeIn)}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this._source&&(this._source.fadeOut=this._fadeOut)}_restart(t){this._stop(t),this._start(t)}dispose(){return super.dispose(),this._source&&this._source.disconnect(),this}}const Ho=220500,Qo={brown:null,pink:null,white:null},Jo={get brown(){if(!Qo.brown){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(Ho);t[e]=n;let s=0;for(let t=0;t<Ho;t++){const e=2*Math.random()-1;n[t]=(s+.02*e)/1.02,s=n[t],n[t]*=3.5}}Qo.brown=(new Pi).fromArray(t)}return Qo.brown},get pink(){if(!Qo.pink){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(Ho);let s,i,o,r,a,c,h;t[e]=n,s=i=o=r=a=c=h=0;for(let t=0;t<Ho;t++){const e=2*Math.random()-1;s=.99886*s+.0555179*e,i=.99332*i+.0750759*e,o=.969*o+.153852*e,r=.8665*r+.3104856*e,a=.55*a+.5329522*e,c=-.7616*c-.016898*e,n[t]=s+i+o+r+a+c+h+.5362*e,n[t]*=.11,h=.115926*e}}Qo.pink=(new Pi).fromArray(t)}return Qo.pink},get white(){if(!Qo.white){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(Ho);t[e]=n;for(let t=0;t<Ho;t++)n[t]=2*Math.random()-1}Qo.white=(new Pi).fromArray(t)}return Qo.white}};class Ko extends Lo{constructor(){const t=gi(Ko.getDefaults(),arguments,["decay"]);super(t),this.name="Reverb",this._convolver=this.context.createConvolver(),this.ready=Promise.resolve(),this._decay=t.decay,this._preDelay=t.preDelay,this.generate(),this.connectEffect(this._convolver)}static getDefaults(){return Object.assign(Lo.getDefaults(),{decay:1.5,preDelay:.01})}get decay(){return this._decay}set decay(t){Ks(t=this.toSeconds(t),.001),this._decay=t,this.generate()}get preDelay(){return this._preDelay}set preDelay(t){Ks(t=this.toSeconds(t),0),this._preDelay=t,this.generate()}generate(){return hi(this,void 0,void 0,(function*(){const t=this.ready,e=new Fi(2,this._decay+this._preDelay,this.context.sampleRate),n=new $o({context:e}),s=new $o({context:e}),i=new Zo({context:e});n.connect(i,0,0),s.connect(i,0,1);const o=new ao({context:e}).toDestination();i.connect(o),n.start(0),s.start(0),o.gain.setValueAtTime(0,0),o.gain.setValueAtTime(1,this._preDelay),o.gain.exponentialApproachValueAtTime(0,this._preDelay,this.decay);const r=e.render();return this.ready=r.then(Vi),yield t,this._convolver.buffer=(yield r).get(),this}))}dispose(){return super.dispose(),this._convolver.disconnect(),this}}var tr=class{constructor(t){this.decayTime=t||1,this.reverb=new Ko(this.decayTime).toDestination()}set(t){this.reverb.decay=t}drywet(t){this.reverb.wet.value=t}connect(t){"function"==typeof t.getNode?this.reverb.connect(t.getNode()):this.reverb.connect(t)}disconnect(){this.reverb.disconnect(Ei.destination)}getNode(){return this.reverb}};class er extends so{constructor(){const t=gi(er.getDefaults(),arguments,["frequency","type"]);super(t),this.name="BiquadFilter",this._filter=this.context.createBiquadFilter(),this.input=this.output=this._filter,this.Q=new no({context:this.context,units:"number",value:t.Q,param:this._filter.Q}),this.frequency=new no({context:this.context,units:"frequency",value:t.frequency,param:this._filter.frequency}),this.detune=new no({context:this.context,units:"cents",value:t.detune,param:this._filter.detune}),this.gain=new no({context:this.context,units:"decibels",convert:!1,value:t.gain,param:this._filter.gain}),this.type=t.type}static getDefaults(){return Object.assign(so.getDefaults(),{Q:1,type:"lowpass",frequency:350,detune:0,gain:0})}get type(){return this._filter.type}set type(t){Js(-1!==["lowpass","highpass","bandpass","lowshelf","highshelf","notch","allpass","peaking"].indexOf(t),`Invalid filter type: ${t}`),this._filter.type=t}getFrequencyResponse(t=128){const e=new Float32Array(t);for(let n=0;n<t;n++){const s=19980*Math.pow(n/t,2)+20;e[n]=s}const n=new Float32Array(t),s=new Float32Array(t),i=this.context.createBiquadFilter();return i.type=this.type,i.Q.value=this.Q.value,i.frequency.value=this.frequency.value,i.gain.value=this.gain.value,i.getFrequencyResponse(e,n,s),n}dispose(){return super.dispose(),this._filter.disconnect(),this.Q.dispose(),this.frequency.dispose(),this.gain.dispose(),this.detune.dispose(),this}}class nr{constructor(t=800,e="lowpass"){this.type=e,this.cutoff=t,this.biquad=new er(this.cutoff,this.type).toDestination()}res(t){this.biquad.Q.value=t}gain(t){this.biquad.gain.value=t}setType(t){this.biquad.type=t}freq(t){this.biquad.frequency.value=Li(t,0,24e3)}connect(t){"function"==typeof t.getNode?this.biquad.connect(t.getNode()):this.biquad.connect(t)}disconnect(){this.biquad.disconnect(Ei.destination)}getNode(){return this.biquad}}var sr=nr;class ir extends _o{constructor(){super(...arguments),this.name="AudioToGain",this._norm=new go({context:this.context,mapping:t=>(t+1)/2}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class or extends uo{constructor(){super(gi(or.getDefaults(),arguments,["value"])),this.override=!1,this.name="Add",this._sum=new ao({context:this.context}),this.input=this._sum,this.output=this._sum,this.addend=this._param,io(this._constantSource,this._sum)}static getDefaults(){return Object.assign(uo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._sum.dispose(),this}}class rr extends uo{constructor(){const t=gi(rr.getDefaults(),arguments,["value"]);super(t),this.name="Multiply",this.override=!1,this._mult=this.input=this.output=new ao({context:this.context,minValue:t.minValue,maxValue:t.maxValue}),this.factor=this._param=this._mult.gain,this.factor.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(uo.getDefaults(),{value:0})}dispose(){return super.dispose(),this._mult.dispose(),this}}class ar extends _o{constructor(){const t=gi(ar.getDefaults(),arguments,["min","max"]);super(t),this.name="Scale",this._mult=this.input=new rr({context:this.context,value:t.max-t.min}),this._add=this.output=new or({context:this.context,value:t.min}),this._min=t.min,this._max=t.max,this.input.connect(this.output)}static getDefaults(){return Object.assign(_o.getDefaults(),{max:1,min:0})}get min(){return this._min}set min(t){this._min=t,this._setRange()}get max(){return this._max}set max(t){this._max=t,this._setRange()}_setRange(){this._add.value=this._min,this._mult.value=this._max-this._min}dispose(){return super.dispose(),this._add.dispose(),this._mult.dispose(),this}}class cr extends _o{constructor(){super(gi(cr.getDefaults(),arguments)),this.name="Zero",this._gain=new ao({context:this.context}),this.output=this._gain,this.input=void 0,oo(this.context.getConstant(0),this._gain)}dispose(){return super.dispose(),ro(this.context.getConstant(0),this._gain),this}}class hr extends so{constructor(){const t=gi(hr.getDefaults(),arguments,["frequency","min","max"]);super(t),this.name="LFO",this._stoppedValue=0,this._units="number",this.convert=!0,this._fromType=no.prototype._fromType,this._toType=no.prototype._toType,this._is=no.prototype._is,this._clampValue=no.prototype._clampValue,this._oscillator=new Eo(t),this.frequency=this._oscillator.frequency,this._amplitudeGain=new ao({context:this.context,gain:t.amplitude,units:"normalRange"}),this.amplitude=this._amplitudeGain.gain,this._stoppedSignal=new uo({context:this.context,units:"audioRange",value:0}),this._zeros=new cr({context:this.context}),this._a2g=new ir({context:this.context}),this._scaler=this.output=new ar({context:this.context,max:t.max,min:t.min}),this.units=t.units,this.min=t.min,this.max=t.max,this._oscillator.chain(this._amplitudeGain,this._a2g,this._scaler),this._zeros.connect(this._a2g),this._stoppedSignal.connect(this._a2g),Ri(this,["amplitude","frequency"]),this.phase=t.phase}static getDefaults(){return Object.assign(Eo.getDefaults(),{amplitude:1,frequency:"4n",max:1,min:0,type:"sine",units:"number"})}start(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(0,t),this._oscillator.start(t),this}stop(t){return t=this.toSeconds(t),this._stoppedSignal.setValueAtTime(this._stoppedValue,t),this._oscillator.stop(t),this}sync(){return this._oscillator.sync(),this._oscillator.syncFrequency(),this}unsync(){return this._oscillator.unsync(),this._oscillator.unsyncFrequency(),this}_setStoppedValue(){this._stoppedValue=this._oscillator.getInitialValue(),this._stoppedSignal.value=this._stoppedValue}get min(){return this._toType(this._scaler.min)}set min(t){t=this._fromType(t),this._scaler.min=t}get max(){return this._toType(this._scaler.max)}set max(t){t=this._fromType(t),this._scaler.max=t}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t,this._setStoppedValue()}get partials(){return this._oscillator.partials}set partials(t){this._oscillator.partials=t,this._setStoppedValue()}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t,this._setStoppedValue()}get units(){return this._units}set units(t){const e=this.min,n=this.max;this._units=t,this.min=e,this.max=n}get state(){return this._oscillator.state}connect(t,e,n){return(t instanceof no||t instanceof uo)&&(this.convert=t.convert,this.units=t.units),lo(this,t,e,n),this}dispose(){return super.dispose(),this._oscillator.dispose(),this._stoppedSignal.dispose(),this._zeros.dispose(),this._scaler.dispose(),this._a2g.dispose(),this._amplitudeGain.dispose(),this.amplitude.dispose(),this}}class ur extends Uo{constructor(){const t=gi(ur.getDefaults(),arguments,["pitch"]);super(t),this.name="PitchShift",this._frequency=new uo({context:this.context}),this._delayA=new Wo({maxDelay:1,context:this.context}),this._lfoA=new hr({context:this.context,min:0,max:.1,type:"sawtooth"}).connect(this._delayA.delayTime),this._delayB=new Wo({maxDelay:1,context:this.context}),this._lfoB=new hr({context:this.context,min:0,max:.1,type:"sawtooth",phase:180}).connect(this._delayB.delayTime),this._crossFade=new zo({context:this.context}),this._crossFadeLFO=new hr({context:this.context,min:0,max:1,type:"triangle",phase:90}).connect(this._crossFade.fade),this._feedbackDelay=new Wo({delayTime:t.delayTime,context:this.context}),this.delayTime=this._feedbackDelay.delayTime,Ri(this,"delayTime"),this._pitch=t.pitch,this._windowSize=t.windowSize,this._delayA.connect(this._crossFade.a),this._delayB.connect(this._crossFade.b),this._frequency.fan(this._lfoA.frequency,this._lfoB.frequency,this._crossFadeLFO.frequency),this.effectSend.fan(this._delayA,this._delayB),this._crossFade.chain(this._feedbackDelay,this.effectReturn);const e=this.now();this._lfoA.start(e),this._lfoB.start(e),this._crossFadeLFO.start(e),this.windowSize=this._windowSize}static getDefaults(){return Object.assign(Uo.getDefaults(),{pitch:0,windowSize:.1,delayTime:0,feedback:0})}get pitch(){return this._pitch}set pitch(t){this._pitch=t;let e=0;t<0?(this._lfoA.min=0,this._lfoA.max=this._windowSize,this._lfoB.min=0,this._lfoB.max=this._windowSize,e=Yi(t-1)+1):(this._lfoA.min=this._windowSize,this._lfoA.max=0,this._lfoB.min=this._windowSize,this._lfoB.max=0,e=Yi(t)-1),this._frequency.value=e*(1.2/this._windowSize)}get windowSize(){return this._windowSize}set windowSize(t){this._windowSize=this.toSeconds(t),this.pitch=this._pitch}dispose(){return super.dispose(),this._frequency.dispose(),this._delayA.dispose(),this._delayB.dispose(),this._lfoA.dispose(),this._lfoB.dispose(),this._crossFade.dispose(),this._crossFadeLFO.dispose(),this._feedbackDelay.dispose(),this}}var lr=class{constructor(t=1){this.pitchshifter=new ur(t).toDestination()}shift(t){void 0!==t&&(this.pitchshifter.pitch=t)}connect(t){"function"==typeof t.getNode?this.pitchshifter.connect(t.getNode()):this.pitchshifter.connect(t)}disconnect(){this.pitchshifter.disconnect(Ei.destination)}getNode(){return this.pitchshifter}};var dr=class{constructor(t=1){this.gain=new ao(t).toDestination()}amp(t){"object"!=typeof t?this.gain.gain.rampTo(t,.1):t.getNode().connect(this.gain.gain)}connect(t){"function"==typeof t.getNode?this.gain.connect(t.getNode()):this.gain.connect(t)}disconnect(){this.gain.disconnect(Ei.destination)}getNode(){return this.gain}};class pr extends so{constructor(){const t=gi(pr.getDefaults(),arguments,["channels"]);super(t),this.name="Split",this._splitter=this.input=this.output=this.context.createChannelSplitter(t.channels),this._internalChannels=[this._splitter]}static getDefaults(){return Object.assign(so.getDefaults(),{channels:2})}dispose(){return super.dispose(),this._splitter.disconnect(),this}}class fr extends so{constructor(){const t=gi(fr.getDefaults(),arguments,["type","size"]);super(t),this.name="Analyser",this._analysers=[],this._buffers=[],this.input=this.output=this._gain=new ao({context:this.context}),this._split=new pr({context:this.context,channels:t.channels}),this.input.connect(this._split),Ks(t.channels,1);for(let e=0;e<t.channels;e++)this._analysers[e]=this.context.createAnalyser(),this._split.connect(this._analysers[e],e,0);this.size=t.size,this.type=t.type,this.smoothing=t.smoothing}static getDefaults(){return Object.assign(so.getDefaults(),{size:1024,smoothing:.8,type:"fft",channels:1})}getValue(){return this._analysers.forEach(((t,e)=>{const n=this._buffers[e];"fft"===this._type?t.getFloatFrequencyData(n):"waveform"===this._type&&t.getFloatTimeDomainData(n)})),1===this.channels?this._buffers[0]:this._buffers}get size(){return this._analysers[0].frequencyBinCount}set size(t){this._analysers.forEach(((e,n)=>{e.fftSize=2*t,this._buffers[n]=new Float32Array(t)}))}get channels(){return this._analysers.length}get type(){return this._type}set type(t){Js("waveform"===t||"fft"===t,`Analyser: invalid type: ${t}`),this._type=t}get smoothing(){return this._analysers[0].smoothingTimeConstant}set smoothing(t){this._analysers.forEach((e=>e.smoothingTimeConstant=t))}dispose(){return super.dispose(),this._analysers.forEach((t=>t.disconnect())),this._split.dispose(),this._gain.dispose(),this}}class mr extends so{constructor(){super(gi(mr.getDefaults(),arguments)),this.name="MeterBase",this.input=this.output=this._analyser=new fr({context:this.context,size:256,type:"waveform"})}dispose(){return super.dispose(),this._analyser.dispose(),this}}class _r extends mr{constructor(){const t=gi(_r.getDefaults(),arguments,["smoothing"]);super(t),this.name="Meter",this.input=this.output=this._analyser=new fr({context:this.context,size:256,type:"waveform",channels:t.channelCount}),this.smoothing=t.smoothing,this.normalRange=t.normalRange,this._rms=new Array(t.channelCount),this._rms.fill(0)}static getDefaults(){return Object.assign(mr.getDefaults(),{smoothing:.8,normalRange:!1,channelCount:1})}getLevel(){return oi("'getLevel' has been changed to 'getValue'"),this.getValue()}getValue(){const t=this._analyser.getValue(),e=(1===this.channels?[t]:t).map(((t,e)=>{const n=t.reduce(((t,e)=>t+e*e),0),s=Math.sqrt(n/t.length);return this._rms[e]=Math.max(s,this._rms[e]*this.smoothing),this.normalRange?this._rms[e]:Xi(this._rms[e])}));return 1===this.channels?e[0]:e}get channels(){return this._analyser.channels}dispose(){return super.dispose(),this._analyser.dispose(),this}}var gr=class{constructor(t=0){this.amplitude=new _r({normalRange:!0,smoothing:t})}setInput(t){t.getNode().connect(this.amplitude)}getLevel(){return this.amplitude.getValue()}smooth(t){this.amplitude.smoothing=t}connect(t){"function"==typeof t.getNode?this.amplitude.connect(t.getNode()):this.amplitude.connect(t)}disconnect(){this.amplitude.disconnect(Ei.destination)}getNode(){return this.amplitude}};class vr extends mr{constructor(){const t=gi(vr.getDefaults(),arguments,["size"]);super(t),this.name="FFT",this.normalRange=t.normalRange,this._analyser.type="fft",this.size=t.size}static getDefaults(){return Object.assign(so.getDefaults(),{normalRange:!1,size:1024,smoothing:.8})}getValue(){return this._analyser.getValue().map((t=>this.normalRange?Ui(t):t))}get size(){return this._analyser.size}set size(t){this._analyser.size=t}get smoothing(){return this._analyser.smoothing}set smoothing(t){this._analyser.smoothing=t}getFrequencyOfIndex(t){return Js(0<=t&&t<this.size,`index must be greater than or equal to 0 and less than ${this.size}`),t*this.context.sampleRate/(2*this.size)}}class yr extends mr{constructor(){const t=gi(yr.getDefaults(),arguments,["size"]);super(t),this.name="Waveform",this._analyser.type="waveform",this.size=t.size}static getDefaults(){return Object.assign(mr.getDefaults(),{size:1024})}getValue(){return this._analyser.getValue()}get size(){return this._analyser.size}set size(t){this._analyser.size=t}}var xr=class{constructor(t=32){this.fftSize=t,this.analyzer=new vr({size:this.fftSize,normalRange:!0}),this.samples=new yr,this.gain=new ao(1),this.gain.connect(this.analyzer),this.gain.connect(this.samples)}getNode(){return this.gain}analyze(){return this.analyzer.getValue()}waveform(){return this.samples.getValue()}};var wr=class{constructor(t){void 0===t&&(t="white"),this.noise=(new $o).toDestination(),this.noise.type=t}type(t){this.noise.type=t}amp(t,e=.1){if("object"==typeof t)return void t.getNode().connect(this.noise.volume);let n=Xi(t);this.noise.volume.rampTo(n,e)}start(){this.noise.start()}stop(){this.noise.stop()}connect(t){"function"==typeof t.getNode?this.noise.connect(t.getNode()):this.noise.connect(t)}disconnect(){this.noise.disconnect(Ei.destination)}getNode(){return this.noise}};class Tr extends so{constructor(){const t=gi(Tr.getDefaults(),arguments,["pan"]);super(t),this.name="Panner",this._panner=this.context.createStereoPanner(),this.input=this._panner,this.output=this._panner,this.pan=new no({context:this.context,param:this._panner.pan,value:t.pan,minValue:-1,maxValue:1}),this._panner.channelCount=t.channelCount,this._panner.channelCountMode="explicit",Ri(this,"pan")}static getDefaults(){return Object.assign(so.getDefaults(),{pan:0,channelCount:1})}dispose(){return super.dispose(),this._panner.disconnect(),this.pan.dispose(),this}}var br=class{constructor(){this.panner=new Tr(0).toDestination()}pan(t){"object"!=typeof t?this.panner.pan.rampTo(Li(t,-1,1),.01):t.getNode().connect(this.panner.pan)}getNode(){return this.panner}connect(t){"function"==typeof t.getNode?this.panner.connect(t.getNode()):this.panner.connect(t)}disconnect(){this.panner.disconnect(Ei.destination)}};class Cr extends so{constructor(){super(...arguments),this.name="Listener",this.positionX=new no({context:this.context,param:this.context.rawContext.listener.positionX}),this.positionY=new no({context:this.context,param:this.context.rawContext.listener.positionY}),this.positionZ=new no({context:this.context,param:this.context.rawContext.listener.positionZ}),this.forwardX=new no({context:this.context,param:this.context.rawContext.listener.forwardX}),this.forwardY=new no({context:this.context,param:this.context.rawContext.listener.forwardY}),this.forwardZ=new no({context:this.context,param:this.context.rawContext.listener.forwardZ}),this.upX=new no({context:this.context,param:this.context.rawContext.listener.upX}),this.upY=new no({context:this.context,param:this.context.rawContext.listener.upY}),this.upZ=new no({context:this.context,param:this.context.rawContext.listener.upZ})}static getDefaults(){return Object.assign(so.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}}ki((t=>{t.listener=new Cr({context:t})})),Mi((t=>{t.listener.dispose()}));class Ar extends so{constructor(){const t=gi(Ar.getDefaults(),arguments,["positionX","positionY","positionZ"]);super(t),this.name="Panner3D",this._panner=this.input=this.output=this.context.createPanner(),this.panningModel=t.panningModel,this.maxDistance=t.maxDistance,this.distanceModel=t.distanceModel,this.coneOuterGain=t.coneOuterGain,this.coneOuterAngle=t.coneOuterAngle,this.coneInnerAngle=t.coneInnerAngle,this.refDistance=t.refDistance,this.rolloffFactor=t.rolloffFactor,this.positionX=new no({context:this.context,param:this._panner.positionX,value:t.positionX}),this.positionY=new no({context:this.context,param:this._panner.positionY,value:t.positionY}),this.positionZ=new no({context:this.context,param:this._panner.positionZ,value:t.positionZ}),this.orientationX=new no({context:this.context,param:this._panner.orientationX,value:t.orientationX}),this.orientationY=new no({context:this.context,param:this._panner.orientationY,value:t.orientationY}),this.orientationZ=new no({context:this.context,param:this._panner.orientationZ,value:t.orientationZ})}static getDefaults(){return Object.assign(so.getDefaults(),{coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:0,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1})}setPosition(t,e,n){return this.positionX.value=t,this.positionY.value=e,this.positionZ.value=n,this}setOrientation(t,e,n){return this.orientationX.value=t,this.orientationY.value=e,this.orientationZ.value=n,this}get panningModel(){return this._panner.panningModel}set panningModel(t){this._panner.panningModel=t}get refDistance(){return this._panner.refDistance}set refDistance(t){this._panner.refDistance=t}get rolloffFactor(){return this._panner.rolloffFactor}set rolloffFactor(t){this._panner.rolloffFactor=t}get distanceModel(){return this._panner.distanceModel}set distanceModel(t){this._panner.distanceModel=t}get coneInnerAngle(){return this._panner.coneInnerAngle}set coneInnerAngle(t){this._panner.coneInnerAngle=t}get coneOuterAngle(){return this._panner.coneOuterAngle}set coneOuterAngle(t){this._panner.coneOuterAngle=t}get coneOuterGain(){return this._panner.coneOuterGain}set coneOuterGain(t){this._panner.coneOuterGain=t}get maxDistance(){return this._panner.maxDistance}set maxDistance(t){this._panner.maxDistance=t}dispose(){return super.dispose(),this._panner.disconnect(),this.orientationX.dispose(),this.orientationY.dispose(),this.orientationZ.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this}}var Sr=class{constructor(){this.panner3d=new Ar({coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:1,positionX:0,positionY:0,positionZ:0}).toDestination()}process(t){t.getNode().connect(this.panner3d)}set(t,e,n){this.panner3d.positionX.rampTo(t,.01),this.panner3d.positionY.rampTo(e,.01),this.panner3d.positionZ.rampTo(n,.01)}setFalloff(t,e){this.panner3d.rolloffFactor=t,this.panner3d.maxDistance=e}maxDist(t){this.panner3d.maxDistance=t}rolloff(t){this.panner3d.rolloffFactor=t}positionX(t){this.panner3d.positionX.rampTo(t,.01)}positionY(t){this.panner3d.positionY.rampTo(t,.01)}positionZ(t){this.panner3d.positionZ.rampTo(t,.01)}connect(t){"function"==typeof t.getNode?this.panner3d.connect(t.getNode()):this.panner3d.connect(t)}disconnect(){this.panner3d.disconnect(Ei.destination)}getNode(){return this.panner3d}};class kr extends Do{constructor(){const t=gi(kr.getDefaults(),arguments,["url","onload"]);super(t),this.name="Player",this._activeSources=new Set,this._buffer=new Pi({onload:this._onload.bind(this,t.onload),onerror:t.onerror,reverse:t.reverse,url:t.url}),this.autostart=t.autostart,this._loop=t.loop,this._loopStart=t.loopStart,this._loopEnd=t.loopEnd,this._playbackRate=t.playbackRate,this.fadeIn=t.fadeIn,this.fadeOut=t.fadeOut}static getDefaults(){return Object.assign(Do.getDefaults(),{autostart:!1,fadeIn:0,fadeOut:0,loop:!1,loopEnd:0,loopStart:0,onload:Vi,onerror:Vi,playbackRate:1,reverse:!1})}load(t){return hi(this,void 0,void 0,(function*(){return yield this._buffer.load(t),this._onload(),this}))}_onload(t=Vi){t(),this.autostart&&this.start()}_onSourceEnd(t){this.onstop(this),this._activeSources.delete(t),0!==this._activeSources.size||this._synced||"started"!==this._state.getValueAtTime(this.now())||(this._state.cancel(this.now()),this._state.setStateAtTime("stopped",this.now()))}start(t,e,n){return super.start(t,e,n),this}_start(t,e,n){e=this._loop?vi(e,this._loopStart):vi(e,0);const s=this.toSeconds(e),i=n;n=vi(n,Math.max(this._buffer.duration-s,0));let o=this.toSeconds(n);o/=this._playbackRate,t=this.toSeconds(t);const r=new Go({url:this._buffer,context:this.context,fadeIn:this.fadeIn,fadeOut:this.fadeOut,loop:this._loop,loopEnd:this._loopEnd,loopStart:this._loopStart,onended:this._onSourceEnd.bind(this),playbackRate:this._playbackRate}).connect(this.output);this._loop||this._synced||(this._state.cancel(t+o),this._state.setStateAtTime("stopped",t+o,{implicitEnd:!0})),this._activeSources.add(r),this._loop&&Ys(i)?r.start(t,s):r.start(t,s,o-this.toSeconds(this.fadeOut))}_stop(t){const e=this.toSeconds(t);this._activeSources.forEach((t=>t.stop(e)))}restart(t,e,n){return super.restart(t,e,n),this}_restart(t,e,n){var s;null===(s=[...this._activeSources].pop())||void 0===s||s.stop(t),this._start(t,e,n)}seek(t,e){const n=this.toSeconds(e);if("started"===this._state.getValueAtTime(n)){const e=this.toSeconds(t);this._stop(n),this._start(n,e)}return this}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get loopStart(){return this._loopStart}set loopStart(t){this._loopStart=t,this.buffer.loaded&&Ks(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach((e=>{e.loopStart=t}))}get loopEnd(){return this._loopEnd}set loopEnd(t){this._loopEnd=t,this.buffer.loaded&&Ks(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach((e=>{e.loopEnd=t}))}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._loop}set loop(t){if(this._loop!==t&&(this._loop=t,this._activeSources.forEach((e=>{e.loop=t})),t)){const t=this._state.getNextState("stopped",this.now());t&&this._state.cancel(t.time)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t;const e=this.now(),n=this._state.getNextState("stopped",e);n&&n.implicitEnd&&(this._state.cancel(n.time),this._activeSources.forEach((t=>t.cancelStop()))),this._activeSources.forEach((n=>{n.playbackRate.setValueAtTime(t,e)}))}get reverse(){return this._buffer.reverse}set reverse(t){this._buffer.reverse=t}get loaded(){return this._buffer.loaded}dispose(){return super.dispose(),this._activeSources.forEach((t=>t.dispose())),this._activeSources.clear(),this._buffer.dispose(),this}}ci([Vo(0)],kr.prototype,"fadeIn",void 0),ci([Vo(0)],kr.prototype,"fadeOut",void 0);var Or=class{constructor(t,e){this.soundfile=new kr(t,e).toDestination(),this.playing=!1,this.speed=1,this.paused=!1}start(){this.soundfile.playbackRate=this.speed,this.playing=!0,this.paused||this.soundfile.start()}play(){this.soundfile.playbackRate=this.speed,this.playing=!0,this.paused||this.soundfile.start()}stop(){this.soundfile.stop(),this.playing=!1}pause(){this.soundfile.playbackRate=0,this.playing=!1,this.paused=!0}loop(t=!0){this.soundfile.loop=t}loopPoints(t=0,e=this.soundfile.buffer.duration,n=0){this.soundfile.loopStart=t,this.soundfile.loopEnd=t+e}amp(t){let e=Xi(t);this.soundfile.volume.value=e}setPath(t,e){this.soundfile.load(t).then((()=>{e?e():console.log("Audio loaded successfully!")})).catch((t=>{console.error("Error loading audio:",t)}))}rate(t=1){t<0&&(t=0),this.soundfile.playbackRate=t,this.speed=t}duration(){return this.soundfile.buffer.duration}sampleRate(){if(this.soundfile.buffer)return this.soundfile.buffer.sampleRate}jump(t){this.soundfile.seek(t)}isPlaying(){return this.playing}isLooping(){return this.soundfile.loop}onended(t){this.soundfile.onstop=t}frames(){if(this.soundfile.buffer)return this.soundfile.buffer.length}sampleRate(){if(this.soundfile.buffer)return this.soundfile.buffer.sampleRate}channels(){if(this.soundfile.buffer)return this.soundfile.buffer.numberOfChannels}connect(t){this.soundfile.connect(t.getNode())}disconnect(){this.soundfile.disconnect(Ei.destination)}getNode(){return this.soundfile}};class Mr extends so{constructor(){const t=gi(Mr.getDefaults(),arguments,["volume"]);super(t),this.name="UserMedia",this._volume=this.output=new po({context:this.context,volume:t.volume}),this.volume=this._volume.volume,Ri(this,"volume"),this.mute=t.mute}static getDefaults(){return Object.assign(so.getDefaults(),{mute:!1,volume:0})}open(t){return hi(this,void 0,void 0,(function*(){Js(Mr.supported,"UserMedia is not supported"),"started"===this.state&&this.close();const e=yield Mr.enumerateDevices();Gs(t)?this._device=e[t]:(this._device=e.find((e=>e.label===t||e.deviceId===t)),!this._device&&e.length>0&&(this._device=e[0]),Js(Zs(this._device),`No matching device ${t}`));const n={audio:{echoCancellation:!1,sampleRate:this.context.sampleRate,noiseSuppression:!1,mozNoiseSuppression:!1}};this._device&&(n.audio.deviceId=this._device.deviceId);const s=yield navigator.mediaDevices.getUserMedia(n);if(!this._stream){this._stream=s;const t=this.context.createMediaStreamSource(s);oo(t,this.output),this._mediaStream=t}return this}))}close(){return this._stream&&this._mediaStream&&(this._stream.getAudioTracks().forEach((t=>{t.stop()})),this._stream=void 0,this._mediaStream.disconnect(),this._mediaStream=void 0),this._device=void 0,this}static enumerateDevices(){return hi(this,void 0,void 0,(function*(){return(yield navigator.mediaDevices.enumerateDevices()).filter((t=>"audioinput"===t.kind))}))}get state(){return this._stream&&this._stream.active?"started":"stopped"}get deviceId(){return this._device?this._device.deviceId:void 0}get groupId(){return this._device?this._device.groupId:void 0}get label(){return this._device?this._device.label:void 0}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}dispose(){return super.dispose(),this.close(),this._volume.dispose(),this.volume.dispose(),this}static get supported(){return Zs(navigator.mediaDevices)&&Zs(navigator.mediaDevices.getUserMedia)}}var Dr=class{constructor(){this.audioIn=new Mr}start(){zi(),this.audioIn.open().then((()=>{console.log("mic open")})).catch((t=>{console.log("mic not open")}))}stop(){this.audioIn.close()}amp(t){let e=Xi(t);this.delay.volume.rampTo(e,.1)}getNode(){return this.audioIn}connect(t){"function"==typeof t.getNode?this.audioIn.connect(t.getNode()):this.audioIn.connect(t)}disconnect(){this.audioIn.disconnect(Ei.destination)}};p5.prototype.getAudioContext=function(){return ji(new window.AudioContext),Wi()._context},p5.prototype.setAudioContext=function(t){ji(t)},p5.prototype.userStartAudio=function(){zi()},p5.prototype.userStopAudio=function(){context=Wi(),context.suspend()},p5.Oscillator=No,p5.SawOsc=class extends Ro{constructor(t){super(t),this.osc.type="sawtooth"}},p5.SinOsc=class extends Ro{constructor(t){super(t),this.osc.type="sine"}},p5.TriOsc=class extends Ro{constructor(t){super(t),this.osc.type="triangle"}},p5.SqrOsc=class extends Ro{constructor(t){super(t),this.osc.type="square"}},p5.Envelope=Bo,p5.Delay=Yo,p5.Reverb=tr,p5.Biquad=sr,p5.LowPass=class extends nr{constructor(t){super(t),this.biquad.type="lowpass"}},p5.HighPass=class extends nr{constructor(t){super(t),this.biquad.type="highpass"}},p5.BandPass=class extends nr{constructor(t){super(t),this.biquad.type="bandpass"}},p5.PitchShifter=lr,p5.Gain=dr,p5.Amplitude=gr,p5.FFT=xr,p5.Noise=wr,p5.Panner=br,p5.Panner3D=Sr,p5.SoundFile=Or,p5.prototype.loadSound=function(t){if(self._incrementPreload&&self._decrementPreload){return self._incrementPreload(),new p5.SoundFile(t,(function(){self._decrementPreload()}))}return new Promise((e=>{let n=new p5.SoundFile(t,(function(){e(n)}))}))},p5.AudioIn=Dr}();