xsound 3.11.1 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/xsound.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see xsound.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xsound=e():t.xsound=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{X:()=>Nt,XSound:()=>Nt});class AudioWorkletProcessor{port=new MessagePort}function s(t,e,s){return t.audioWorklet.addModule(function(t){return`data:text/javascript,${encodeURIComponent(t.toString())}; registerProcessor('${t.name}', ${t.name})`}(e),s)}class SoundModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class i{static XMLNS="http://www.w3.org/2000/svg";static XLINK="http://www.w3.org/1999/xlink";static SVG_LINEAR_GRADIENT_ID_TIME_OVERVIEW="svg-linear-gradient-time-overview";static SVG_LINEAR_GRADIENT_ID_TIME="svg-linear-gradient-time";static SVG_LINEAR_GRADIENT_ID_FFT="svg-linear-gradient-fft";sampleRate;channel;isActive=!1;graphics="";canvas=null;context=null;svg=null;interval=1e3;styles={shape:"line",gradients:[{offset:0,color:"rgba(0, 128, 255, 1.0)"},{offset:1,color:"rgba(0, 0, 255, 1.0)"}],wave:"rgba(0, 0, 255, 1.0)",grid:"rgba(255, 0, 0, 1.0)",text:"rgba(255, 255, 255, 1.0)",font:{family:"Arial",size:"13px",style:"normal",weight:"normal"},width:1.5,cap:"round",join:"miter",top:15,right:30,bottom:15,left:30};constructor(t,e){this.sampleRate=t,this.channel=e}setup(t){return t instanceof HTMLCanvasElement?(this.graphics="canvas",this.canvas=t,this.context=this.canvas.getContext("2d")):t instanceof SVGSVGElement&&(this.graphics="svg",this.svg=t),this}start(t,e,s){switch(this.graphics){case"canvas":this.visualizeOnCanvas(t,e,s);break;case"svg":this.visualizeBySVG(t,e,s)}return this}param(t){if("string"==typeof t)switch(t){case"interval":return this.interval;case"styles":return this.styles}for(const[e,s]of Object.entries(t))switch(e){case"interval":"number"==typeof s&&(this.interval=s);break;case"styles":"object"==typeof s&&(this.styles={...this.styles,...s})}}get(){switch(this.graphics){case"canvas":return this.canvas;case"svg":return this.svg;default:return null}}clear(){switch(this.graphics){case"canvas":this.canvas&&this.context&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height);break;case"svg":this.svg&&(this.svg.innerHTML="")}return this}create(){switch(this.graphics){case"canvas":return null===this.canvas?"":this.canvas.toDataURL("image/png").replace("image/png","image/octet-stream");case"svg":return null===this.svg?"":this.svg.outerHTML;default:return""}}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}visualizeTimeDomainFloat32ArrayOnCanvas(t,e,s,i,r,n){const a=this.styles.top??15,o=this.styles.left??30,h=this.styles.width??1.5,c=this.styles.cap??"round",u=this.styles.join??"miter",l=this.styles.wave??"rgba(0, 0, 255, 1.0)";switch(this.styles.shape){case"line":t.strokeStyle=l,t.lineWidth=h,t.lineCap=c,t.lineJoin=u,t.beginPath();for(let r=0,h=e.length;r<h;r++)if(!n||r%n==0){const n=r/h*s+o,c=(1-e[r])*(i/2)+a;0===r?t.moveTo(n+t.lineWidth/2,c):t.lineTo(n,c)}t.stroke();break;case"rect":for(let c=0,u=e.length;c<u;c++)if(!n||c%n==0){const n=c/u*s+o,p=e[c]*(i/2)*-1;if(this.styles.gradients){const e=i/2+a,s=t.createLinearGradient(0,e,0,e+p);for(const t of this.styles.gradients)s.addColorStop(t.offset,t.color);t.fillStyle=s}else t.fillStyle=l;t.fillRect(n,r,h,p)}}}visualizeTimeDomainFloat32ArrayBySVG(t,e,s,r,n,a){const o=this.styles.top??15,h=this.styles.left??30,c=this.styles.width??1.5,u=this.styles.cap??"round",l=this.styles.join??"miter",p=this.styles.wave??"rgba(0, 0, 255, 1.0)";switch(this.styles.shape){case"line":{const r=document.createElementNS(i.XMLNS,"path");let a="";for(let i=0,r=t.length;i<r;i++)if(i%n==0){const n=i/r*e+h,c=(1-t[i])*(s/2)+o;a+=0===i?`M${n+(this.styles.width??1.5)/2} ${c}`:` L${n} ${c}`}return r.setAttribute("d",a),r.setAttribute("stroke",p),r.setAttribute("fill","none"),r.setAttribute("stroke-width",c.toString(10)),r.setAttribute("stroke-linecap",u),r.setAttribute("stroke-linejoin",l),r}case"rect":{let o=null;this.styles.gradients&&(o=this.createSVGLinearGradient(a));const u=document.createElementNS(i.XMLNS,"g");null!==o&&u.appendChild(o);for(let l=0,d=t.length;l<d;l++)if(l%n==0){const n=document.createElementNS(i.XMLNS,"rect"),f=l/d*e+h,m=t[l]*(s/2);n.setAttribute("x",f.toString(10)),n.setAttribute("y",r.toString(10)),n.setAttribute("width",c.toString(10)),n.setAttribute("height",Math.abs(m).toString(10)),m>=0&&n.setAttribute("transform",`rotate(180 ${f+c/2} ${r})`),n.setAttribute("stroke","none"),n.setAttribute("fill",null===o?p:`url(#${a})`),u.appendChild(n)}return u}default:return null}}createSVGLinearGradient(t){if(!this.styles.gradients)return null;const e=document.createElementNS(i.XMLNS,"defs"),s=document.createElementNS(i.XMLNS,"linearGradient");s.setAttribute("id",t),s.setAttribute("x1","0%"),s.setAttribute("y1","0%"),s.setAttribute("x2","0%"),s.setAttribute("y2","100%");for(const t of this.styles.gradients){const e=document.createElementNS(i.XMLNS,"stop");e.setAttribute("offset",t.offset.toString(10)),e.setAttribute("stop-color",t.color),s.appendChild(e)}return e.appendChild(s),e}createFontString(){const{style:t,weight:e,size:s,family:i}=this.styles.font??{};return`${t??"normal"} ${e??"normal"} ${s??"13px"} "${i??"Arial"}"`}}const r="xsound-svg-current-time",n="xsound-svg-sprite";class a extends i{callback=()=>{};currentImageData=null;currentSVGElement=null;currentDataSize=0;currentTime={width:1,color:"rgba(0, 0, 0, 0.5)"};sprite="rgba(255, 255, 255, 0.25)";plotInterval=.0625;textInterval=60;isDown=!1;mode="update";offsetX=0;startTime=0;endTime=0;constructor(t,e){super(t,e),this.onMouseStart=this.onMouseStart.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"currentTime":return this.currentTime;case"sprite":return this.sprite;case"plotInterval":return this.plotInterval;case"textInterval":return this.textInterval;case"mode":return this.mode;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"currentTime":"object"==typeof s&&(this.currentTime={...this.currentTime,...s});break;case"sprite":"string"==typeof s&&(this.sprite=s);break;case"plotInterval":"number"==typeof s&&(this.plotInterval=s);break;case"textInterval":"number"==typeof s&&(this.textInterval=s);break;case"mode":"string"==typeof s&&("update"!==s&&"sprite"!==s||(this.mode=s))}return super.param(t),this}update(t){switch(this.graphics){case"canvas":{if(null===this.currentImageData)return this;if(null===this.canvas||null===this.context)return this;const e=this.context,s=this.canvas.width,i=this.canvas.height,r=s-((this.styles.left??30)+(this.styles.right??30)),n=i-((this.styles.top??15)+(this.styles.bottom??15)),a=t*this.sampleRate/this.currentDataSize*r,o=this.styles.left??30,h=this.styles.top??15,c=this.currentTime.color??"rgba(0, 0, 0, 0.5)";switch(e.clearRect(0,0,s,i),e.putImageData(this.currentImageData,0,0),this.mode){case"update":e.fillStyle=c,e.fillRect(o,h+1,a,n-1);break;case"sprite":if(0!==this.endTime){const t=Math.trunc(Math.abs(this.endTime-this.startTime)*this.sampleRate/this.currentDataSize*r);e.fillStyle=this.sprite,a>=this.offsetX?e.fillRect(o+this.offsetX,h+1,t,n-1):e.fillRect(o+this.offsetX-t,h+1,t,n-1)}e.fillStyle=c,a>=this.offsetX?e.fillRect(o+this.offsetX,h+1,Math.abs(a-this.offsetX),n-1):e.fillRect(o+a,h+1,Math.abs(a-this.offsetX),n-1)}break}case"svg":if(null===this.currentSVGElement)return this;if(this.svg){const e=this.svg.querySelector(`.${r}`);if(null===e)return this;const s=Number(this.svg.getAttribute("width")??"0"),i=this.styles.top??15,o=this.styles.left??30,h=s-(o+(this.styles.right??30)),c=t*this.sampleRate/this.currentDataSize*h;if("update"===this.mode){const t=this.svg.querySelector(`.${n}`);t&&t.parentNode?.removeChild(t),e.setAttribute("x",o.toString(10)),e.setAttribute("width",c.toString(10)),e.setAttribute("aria-label","current time")}else if("sprite"===this.mode){if(0!==this.endTime){const t=this.svg.querySelector(`.${n}`);t&&t.parentNode?.removeChild(t);const s=document.createElementNS(a.XMLNS,"rect");s.classList.add(n);const r=Math.trunc(Math.abs(this.endTime-this.startTime)*this.sampleRate/this.currentDataSize*h);s.setAttribute("y",(i+1).toString(10)),s.setAttribute("height",e.getAttribute("height")??"0"),s.setAttribute("stroke","none"),s.setAttribute("fill",this.sprite),s.setAttribute("aria-label","current time"),c>=this.offsetX?s.setAttribute("x",(o+this.offsetX).toString(10)):s.setAttribute("x",(o+this.offsetX-r).toString(10)),s.setAttribute("width",r.toString(10)),this.svg.appendChild(s),this.svg.appendChild(e)}c>=this.offsetX?e.setAttribute("x",(o+this.offsetX).toString(10)):e.setAttribute("x",(o+c).toString(10)),e.setAttribute("width",Math.abs(c-this.offsetX).toString(10)),e.setAttribute("aria-label","sprite time")}}}return this}drag(t){let e=null;switch(this.graphics){case"canvas":if(null===this.canvas)return this;e=this.canvas;break;case"svg":if(null===this.svg)return this;e=this.svg}return null===e||(t&&(this.callback=t),e.removeEventListener("mousedown",{handleEvent:this.onMouseStart},!1),e.removeEventListener("mousemove",{handleEvent:this.onMouseMove},!1),window.removeEventListener("mouseup",{handleEvent:this.onMouseUp},!1),e.removeEventListener("touchstart",{handleEvent:this.onTouchStart},!1),e.removeEventListener("touchmove",{handleEvent:this.onTouchMove},!1),window.removeEventListener("touchend",{handleEvent:this.onTouchEnd},!1),e.addEventListener("mousedown",{handleEvent:this.onMouseStart},!1),e.addEventListener("mousemove",{handleEvent:this.onMouseMove},!1),window.addEventListener("mouseup",{handleEvent:this.onMouseUp},!1),e.addEventListener("touchstart",{handleEvent:this.onTouchStart},!1),e.addEventListener("touchmove",{handleEvent:this.onTouchMove},!1),window.addEventListener("touchend",{handleEvent:this.onTouchEnd},!1)),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive||t instanceof Uint8Array)return;const i=this.context,r=this.canvas.width,n=this.canvas.height,a=this.styles.top??15,o=this.styles.bottom??15,h=this.styles.left??30,c=r-(h+(this.styles.right??30)),u=n-(a+o),l=Math.trunc(u/2)+a,p=this.styles.grid??"none",d=this.styles.text??"none",f=parseInt(this.styles.font?.size??"13px",10),m=Math.trunc(this.plotInterval*this.sampleRate),v=Math.trunc(this.textInterval*this.sampleRate);if(i.clearRect(0,0,r,n),this.visualizeTimeDomainFloat32ArrayOnCanvas(i,t,c,u,l,m),"none"!==p||"none"!==d){for(let e=0,s=t.length;e<s;e++)if(e%v==0){const t=Math.trunc(e/s*c)+h,r=`${Math.trunc(e/this.sampleRate/60)} min`;"none"!==p&&(i.fillStyle=p,i.fillRect(t,a,1,u)),"none"!==d&&(i.fillStyle=d,i.font=this.createFontString(),i.fillText(r,t-i.measureText(r).width/2,a+u+f))}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=Math.trunc(h-i.measureText(t).width),s=Math.trunc((1-Number(t.trim()))*(u/2))+a;"none"!==p&&(i.fillStyle=p,i.fillRect(h,s,c,1)),"none"!==d&&(i.fillStyle=d,i.font=this.createFontString(),i.fillText(t,e,s-Math.trunc(f/4)))}}this.currentImageData=i.getImageData(0,0,r,n),this.currentDataSize=t.length,i.fillStyle=this.currentTime.color??"rgba(0, 0, 0, 0.5)",i.fillRect(h,a,1,u)}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive||t instanceof Uint8Array)return;const i=this.svg,n=Number(i.getAttribute("width")??"0"),o=Number(i.getAttribute("height")??"0"),h=this.styles.top??15,c=this.styles.bottom??15,u=this.styles.left??30,l=n-(u+(this.styles.right??30)),p=o-(h+c),d=Math.trunc(p/2)+h,f=this.styles.grid??"none",m=this.styles.text??"none",v=parseInt(this.styles.font?.size??"13px",10),g=Math.trunc(this.plotInterval*this.sampleRate),b=Math.trunc(this.textInterval*this.sampleRate);i.innerHTML="";const y=this.visualizeTimeDomainFloat32ArrayBySVG(t,l,p,d,g,`${a.SVG_LINEAR_GRADIENT_ID_TIME_OVERVIEW}-${this.channel}`);if(y&&i.appendChild(y),"none"!==f||"none"!==m){for(let e=0,s=t.length;e<s;e++)if(e%b==0){const t=Math.trunc(e/s*l)+u,r=`${Math.trunc(e/this.sampleRate/60)} min`;if("none"!==f){const e=document.createElementNS(a.XMLNS,"rect");e.setAttribute("x",t.toString(10)),e.setAttribute("y",h.toString(10)),e.setAttribute("width","1"),e.setAttribute("height",p.toString(10)),e.setAttribute("stroke","none"),e.setAttribute("fill",f),i.appendChild(e)}if("none"!==m){const e=document.createElementNS(a.XMLNS,"text");e.textContent=r,e.setAttribute("x",t.toString(10)),e.setAttribute("y",(h+p+v).toString(10)),e.setAttribute("text-anchor","middle"),e.setAttribute("stroke","none"),e.setAttribute("fill",m),e.setAttribute("font-family",this.styles.font?.family??"Arial"),e.setAttribute("font-size",v.toString(10)),e.setAttribute("font-style",this.styles.font?.style??"normal"),e.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(e)}}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=u,s=Math.trunc((1-Number(t.trim()))*(p/2))+h;if("none"!==f){const t=document.createElementNS(a.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",l.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",f),i.appendChild(t)}if("none"!==m){const r=document.createElementNS(a.XMLNS,"text");r.textContent=t,r.setAttribute("x",e.toString(10)),r.setAttribute("y",(s-Math.trunc(v/4)).toString(10)),r.setAttribute("text-anchor","end"),r.setAttribute("stroke","none"),r.setAttribute("fill",m),r.setAttribute("font-family",this.styles.font?.family??"Arial"),r.setAttribute("font-size",v.toString(10)),r.setAttribute("font-style",this.styles.font?.style??"normal"),r.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(r)}}}const k=document.createElementNS(a.XMLNS,"rect");k.classList.add(r),k.setAttribute("y",(h+1).toString(10)),k.setAttribute("height",(p-1).toString(10)),k.setAttribute("stroke","none"),k.setAttribute("fill",this.currentTime.color??"rgba(0, 0, 0, 0.5)"),i.appendChild(k),this.currentSVGElement=i,this.currentDataSize=t.length}visualize(t,e,s){let i=0,r=0;switch(this.graphics){case"canvas":if(null===this.canvas)return;i=this.canvas.offsetLeft,r=this.canvas.width;break;case"svg":if(null===this.svg)return;i=this.svg.parentElement?.offsetLeft??0,r=Number(this.svg.getAttribute("width")??"0")}let n=s-(i+(this.styles.left??30));"canvas"===this.graphics&&this.canvas?.parentElement&&(n+=this.canvas.parentElement.scrollLeft),"svg"===this.graphics&&this.svg?.parentElement&&(n+=this.svg.parentElement.scrollLeft),r-=(this.styles.left??30)+(this.styles.right??30),n<0&&(n=0),n>r&&(n=r);const a=n/r*this.currentDataSize/this.sampleRate;"mousedown"!==e&&"touchstart"!==e||(this.offsetX=n,this.startTime=a,this.endTime=0),"mouseup"!==e&&"touchend"!==e||(this.endTime=a),this.update(a),this.startTime<=a?this.callback(t,this.startTime,a,this.mode,!0):this.startTime>a&&this.callback(t,a,this.startTime,this.mode,!1)}onMouseStart(t){"mousedown"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!0}onMouseMove(t){this.isDown&&(t.stopPropagation(),"mousemove"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)))}onMouseUp(t){this.isDown&&("mouseup"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!1)}onTouchStart(t){"touchstart"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!0}onTouchMove(t){this.isDown&&(t.stopPropagation(),t.preventDefault(),"touchmove"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)))}onTouchEnd(t){this.isDown&&("touchend"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!1)}getOffsetX(t){return t instanceof MouseEvent?t.pageX:t instanceof TouchEvent?t.touches[0].pageX:0}}class o extends i{type="uint";textInterval=.005;constructor(t,e){super(t,e)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"type":return this.type;case"textInterval":return this.textInterval;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"type":"string"==typeof s&&("uint"!==s&&"float"!==s||(this.type=s));break;case"textInterval":"number"==typeof s&&(this.textInterval=s)}return super.param(t),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive)return;const i=this.context,r=this.canvas.width,n=this.canvas.height,a=this.styles.top??15,o=this.styles.bottom??15,h=this.styles.left??30,c=r-(h+(this.styles.right??30)),u=n-(a+o),l=Math.trunc(u/2)+a,p=this.styles.width??1.5,d=this.styles.cap??"round",f=this.styles.join??"miter",m=this.styles.wave??"rgba(0, 0, 255, 1.0)",v=this.styles.grid??"none",g=this.styles.text??"none",b=parseInt(this.styles.font?.size??"13px",10),y=Math.trunc(this.textInterval*this.sampleRate);switch(i.clearRect(0,0,r,n),this.type){case"float":t instanceof Float32Array&&this.visualizeTimeDomainFloat32ArrayOnCanvas(i,t,c,u,l);break;case"uint":switch(this.styles.shape){case"line":i.strokeStyle=m,i.lineWidth=p,i.lineCap=d,i.lineJoin=f,i.beginPath();for(let e=0,s=t.length;e<s;e++){const r=e/s*c+h,n=(1-t[e]/255)*u+a;0===e?i.moveTo(r+p/2,n):i.lineTo(r,n)}i.stroke();break;case"rect":for(let e=0,s=t.length;e<s;e++){const r=e/s*c+h,n=(.5-t[e]/255)*u;if(this.styles.gradients){const t=u/2+a,e=i.createLinearGradient(0,t,0,t+n);for(const t of this.styles.gradients)e.addColorStop(t.offset,t.color);i.fillStyle=e}else i.fillStyle=m;i.fillRect(r,l,1,n)}}}if("none"!==v||"none"!==g){for(let e=0,s=t.length;e<s;e++)if(e%y==0){const t=Math.trunc(e/s*c)+h,r=`${Math.ceil(e/this.sampleRate*1e3)} ms`;"none"!==v&&(i.fillStyle=v,i.fillRect(t,a,1,u)),"none"!==g&&(i.fillStyle=g,i.font=this.createFontString(),i.fillText(r,t-i.measureText(r).width/2,a+u+b))}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=Math.trunc(h-i.measureText(t).width),s=Math.trunc((1-Number(t.trim()))*(u/2))+a;"none"!==v&&(i.fillStyle=v,i.fillRect(h,s,c,1)),"none"!==g&&(i.fillStyle=g,i.font=this.createFontString(),i.fillText(t,e,s-Math.trunc(b/4)))}}}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive)return;const i=this.svg,r=Number(i.getAttribute("width")??"0"),n=Number(i.getAttribute("height")??"0"),a=this.styles.top??15,h=this.styles.bottom??15,c=this.styles.left??30,u=r-(c+(this.styles.right??30)),l=n-(a+h),p=Math.trunc(l/2)+a,d=this.styles.width??1.5,f=this.styles.cap??"round",m=this.styles.join??"miter",v=this.styles.wave??"rgba(0, 0, 255, 1.0)",g=this.styles.grid??"none",b=this.styles.text??"none",y=parseInt(this.styles.font?.size??"13px",10),k=Math.trunc(this.textInterval*this.sampleRate);switch(i.innerHTML="",this.type){case"float":if(t instanceof Float32Array){const e=this.visualizeTimeDomainFloat32ArrayBySVG(t,u,l,p,0,o.SVG_LINEAR_GRADIENT_ID_TIME);null!==e&&i.appendChild(e)}break;case"uint":switch(this.styles.shape){case"line":{const e=document.createElementNS(o.XMLNS,"path");let s="";for(let e=0,i=t.length;e<i;e++){const r=e/i*u+c,n=(1-t[e]/255)*l+a;s+=0===e?`M${r+d/2} ${n}`:` L${r} ${n}`}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",d.toString(10)),e.setAttribute("stroke-linecap",f),e.setAttribute("stroke-linejoin",m),i.appendChild(e);break}case"rect":{let e=null;this.styles.gradients&&(e=this.createSVGLinearGradient(`${o.SVG_LINEAR_GRADIENT_ID_TIME}-${this.channel}`));const s=document.createElementNS(o.XMLNS,"g");null!==e&&s.appendChild(e);for(let i=0,r=t.length;i<r;i++){const n=document.createElementNS(o.XMLNS,"rect"),a=i/r*u+c,h=(t[i]/255-.5)*l;n.setAttribute("x",a.toString(10)),n.setAttribute("y",p.toString(10)),n.setAttribute("width",d.toString(10)),n.setAttribute("height",Math.abs(h).toString(10)),h>=0&&n.setAttribute("transform",`rotate(180 ${a+d/2} ${p})`),n.setAttribute("stroke","none"),n.setAttribute("fill",null===e?v:`url(#${o.SVG_LINEAR_GRADIENT_ID_TIME}-${this.channel})`),s.appendChild(n)}i.appendChild(s);break}}}if("none"!==g||"none"!==b){for(let e=0,s=t.length;e<s;e++)if(e%k==0){const t=Math.trunc(e/s*u)+c,r=`${Math.ceil(e/this.sampleRate*1e3)} ms`;if("none"!==g){const e=document.createElementNS(o.XMLNS,"rect");e.setAttribute("x",t.toString(10)),e.setAttribute("y",a.toString(10)),e.setAttribute("width","1"),e.setAttribute("height",l.toString(10)),e.setAttribute("stroke","none"),e.setAttribute("fill",g),i.appendChild(e)}if("none"!==b){const e=document.createElementNS(o.XMLNS,"text");e.textContent=r,e.setAttribute("x",t.toString(10)),e.setAttribute("y",(a+l+y).toString(10)),e.setAttribute("text-anchor","middle"),e.setAttribute("stroke","none"),e.setAttribute("fill",b),e.setAttribute("font-family",this.styles.font?.family??"Arial"),e.setAttribute("font-size",y.toString(10)),e.setAttribute("font-style",this.styles.font?.style??"normal"),e.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(e)}}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=c,s=Math.trunc((1-Number(t.trim()))*(l/2))+a;if("none"!==g){const t=document.createElementNS(o.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",u.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",g),i.appendChild(t)}if("none"!==b){const r=document.createElementNS(o.XMLNS,"text");r.textContent=t,r.setAttribute("x",e.toString(10)),r.setAttribute("y",(s-Math.trunc(y/4)).toString(10)),r.setAttribute("text-anchor","end"),r.setAttribute("stroke","none"),r.setAttribute("fill",b),r.setAttribute("font-family",this.styles.font?.family??"Arial"),r.setAttribute("font-size",y.toString(10)),r.setAttribute("font-style",this.styles.font?.style??"normal"),r.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(r)}}}}}class h extends i{static MIN_FREQUENCY=62.5;static MAX_FREQUENCY=8e3;static LOGARITHMIC_FREQUENCIES=[62.5,125,250,500,1e3,2e3,4e3,8e3];type="uint";size=256;textInterval=1e3;scale="linear";constructor(t,e){super(t,e)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"type":return this.type;case"size":return this.size;case"textInterval":return this.textInterval;case"scale":return this.scale;case"minFrequency":return h.MIN_FREQUENCY;case"maxFrequency":return h.MAX_FREQUENCY;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"type":"string"==typeof s&&("uint"!==s&&"float"!==s||(this.type=s));break;case"size":"number"==typeof s&&(this.size=s);break;case"textInterval":"number"==typeof s&&(this.textInterval=s);break;case"scale":"string"==typeof s&&("linear"!==s&&"logarithmic"!==s||(this.scale=s))}return super.param(t),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive)return;const i=e??-100,r=s??-30,n=r-i,a=this.context,o=this.canvas.width,c=this.canvas.height,u=this.styles.top??0,l=this.styles.bottom??0,p=this.styles.left??30,d=this.styles.right??30,f=o-(p+d),m=c-(u+l),v=this.styles.width??1.5,g=this.styles.cap??"round",b=this.styles.join??"miter",y=this.styles.wave??"rgba(0, 0, 255, 1.0)",k=this.styles.grid??"none",w=this.styles.text??"none",A=parseInt(this.styles.font?.size??"13px",10),x=this.size>t.length?t.length:this.size,T=this.sampleRate/(2*t.length),S=Math.trunc(this.textInterval/T);switch(a.clearRect(0,0,o,c),this.type){case"float":switch(a.strokeStyle=y,a.lineWidth=v,a.lineCap=g,a.lineJoin=b,a.beginPath(),this.scale){case"linear":for(let e=0;e<x;e++){const s=e/x*f+p,i=Math.trunc(-1*(t[e]-r)*(m/n))+u;0===e?a.moveTo(s+v/2,i):a.lineTo(s,i)}break;case"logarithmic":for(let e=0;e<t.length;e++){if(0===e)continue;const s=e*T,i=Math.trunc(Math.log10(s/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,o=Math.trunc(-1*(t[e]-r)*(m/n))+u;i<p||i>p+f||(1===e?a.moveTo(p+v/2,o):a.lineTo(i,o))}}a.stroke();break;case"uint":switch(this.styles.shape){case"line":a.strokeStyle=y,a.lineWidth=v,a.lineCap=g,a.lineJoin=b,a.beginPath();for(let e=0;e<x;e++){const s=e/x*f+p,i=(1-t[e]/255)*m+u;0===e?a.moveTo(s+v/2,i):a.lineTo(s,i)}a.stroke();break;case"rect":for(let e=0;e<x;e++){const s=e/x*f+p,i=t[e]/255*m*-1;if(this.styles.gradients){const t=m+u,e=a.createLinearGradient(0,t,0,t+i);for(const t of this.styles.gradients)e.addColorStop(t.offset,t.color);a.fillStyle=e}else a.fillStyle=y;a.fillRect(s,m+u,v,i)}}}if("none"!==k||"none"!==w){if("uint"===this.type||"float"===this.type&&"linear"===this.scale){for(let t=0;t<x;t++)if(t%S==0){const e=Math.trunc(t/x*f)+p,s=Math.trunc(this.textInterval*(t/S)),i=s<1e3?`${s} Hz`:`${(s/1e3).toString(10).slice(0,3)} kHz`;"none"!==k&&(a.fillStyle=k,a.fillRect(e,u,1,m)),"none"!==w&&(a.fillStyle=w,a.font=this.createFontString(),a.fillText(i,e-a.measureText(i).width/2,u+m+A))}}else h.LOGARITHMIC_FREQUENCIES.forEach((t=>{const e=Math.trunc(Math.log10(t/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,s=t<1e3?`${t} Hz`:`${(t/1e3).toString(10).slice(0,3)} kHz`;"none"!==k&&(a.fillStyle=k,a.fillRect(e,u,1,m)),"none"!==w&&(a.fillStyle=w,a.font=this.createFontString(),a.fillText(s,e-a.measureText(s).width/2,u+m+A))}));switch(this.type){case"float":for(let t=i;t<=r;t+=10){const e=`${t} dB`,s=Math.trunc(p-a.measureText(e).width),i=Math.trunc(-1*(t-r)/n*m)+u;"none"!==k&&(a.fillStyle=k,a.fillRect(p,i,f,1)),"none"!==w&&(a.fillStyle=w,a.font=this.createFontString(),a.fillText(e,s,i))}break;case"uint":for(const t of["0.00","0.25","0.50","0.75","1.00"]){const e=Math.trunc(p-a.measureText(t).width),s=(1-Number(t))*m+u;"none"!==k&&(a.fillStyle=k,a.fillRect(p,s,f,1)),"none"!==w&&(a.fillStyle=w,a.font=this.createFontString(),a.fillText(t,e,s))}}}}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive)return;const i=e??-100,r=s??-30,n=r-i,a=this.svg,o=Number(a.getAttribute("width")??"0"),c=Number(a.getAttribute("height")??"0"),u=this.styles.top??0,l=this.styles.bottom??0,p=this.styles.left??30,d=this.styles.right??30,f=o-(p+d),m=c-(u+l),v=this.styles.wave??"rgba(0, 0, 255, 1.0)",g=this.styles.width??1.5,b=this.styles.cap??"round",y=this.styles.join??"miter",k=this.styles.grid??"none",w=this.styles.text??"none",A=parseInt(this.styles.font?.size??"13px",10),x=this.size>t.length?t.length:this.size,T=this.sampleRate/(2*t.length),S=Math.trunc(this.textInterval/T);switch(a.innerHTML="",this.type){case"float":{const e=document.createElementNS(h.XMLNS,"path");let s="";switch(this.scale){case"linear":for(let e=0;e<x;e++){const i=Math.trunc(e/x*f)+p,a=Math.trunc(-1*(t[e]-r)*(m/n))+u;Number.isFinite(i)&&Number.isFinite(a)&&(s+=""===s?`M${i+g/2} ${a}`:` L${i} ${a}`)}break;case"logarithmic":for(let e=0;e<t.length;e++){if(0==e)continue;const i=e*T,a=Math.trunc(Math.log10(i/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,o=Math.trunc(-1*(t[e]-r)*(m/n))+u;Number.isFinite(a)&&Number.isFinite(o)&&(a<p||a>p+f||(s+=""===s?`M${a} ${o}`:` L${a} ${o}`))}}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",g.toString(10)),e.setAttribute("stroke-linecap",b),e.setAttribute("stroke-linejoin",y),a.appendChild(e);break}case"uint":switch(this.styles.shape){case"line":{const e=document.createElementNS(h.XMLNS,"path");let s="";for(let e=0;e<x;e++){const i=Math.trunc(e/x*f)+p,r=Math.trunc((1-t[e]/255)*m)+u;s+=0===e?`M${i+g/2} ${r}`:` L${i} ${r}`}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",g.toString(10)),e.setAttribute("stroke-linecap",b),e.setAttribute("stroke-linejoin",y),a.appendChild(e);break}case"rect":{let e=null;this.styles.gradients&&(e=this.createSVGLinearGradient(`${h.SVG_LINEAR_GRADIENT_ID_FFT}-${this.channel}`));const s=document.createElementNS(h.XMLNS,"g");null!==e&&s.appendChild(e);for(let i=0;i<x;i++){const r=document.createElementNS(h.XMLNS,"rect"),n=Math.trunc(i/x*f)+p,a=Math.trunc(t[i]/255*m);r.setAttribute("x",n.toString(10)),r.setAttribute("y",(u+m).toString(10)),r.setAttribute("width",g.toString(10)),r.setAttribute("height",Math.abs(a).toString(10)),a>=0&&r.setAttribute("transform",`rotate(180 ${n+g/2} ${u+m})`),r.setAttribute("stroke","none"),r.setAttribute("fill",null===e?v:`url(#${h.SVG_LINEAR_GRADIENT_ID_FFT}-${this.channel})`),s.appendChild(r)}a.appendChild(s);break}}}if("none"!==k||"none"!==w){if("uint"===this.type||"float"===this.type&&"linear"===this.scale){for(let t=0;t<x;t++)if(t%S==0){const e=Math.trunc(t/x*f)+p,s=Math.trunc(this.textInterval*(t/S)),i=s<1e3?`${s} Hz`:`${(s/1e3).toString(10).slice(0,3)} kHz`;if("none"!==k){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",u.toString(10)),t.setAttribute("width","1"),t.setAttribute("height",m.toString(10)),t.setAttribute("stroke","none"),t.setAttribute("fill",k),a.appendChild(t)}if("none"!==w){const t=document.createElementNS(h.XMLNS,"text");t.textContent=i,t.setAttribute("x",e.toString(10)),t.setAttribute("y",(u+m+l).toString(10)),t.setAttribute("text-anchor","middle"),t.setAttribute("stroke","none"),t.setAttribute("fill",w),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}}else h.LOGARITHMIC_FREQUENCIES.forEach((t=>{const e=Math.trunc(Math.log10(t/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,s=t<1e3?`${t} Hz`:`${(t/1e3).toString(10).slice(0,3)} kHz`;if("none"!==k){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",u.toString(10)),t.setAttribute("width","1"),t.setAttribute("height",m.toString(10)),t.setAttribute("stroke","none"),t.setAttribute("fill",k),a.appendChild(t)}if("none"!==w){const t=document.createElementNS(h.XMLNS,"text");t.textContent=s,t.setAttribute("x",e.toString(10)),t.setAttribute("y",(u+m+l).toString(10)),t.setAttribute("text-anchor","middle"),t.setAttribute("stroke","none"),t.setAttribute("fill",w),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}));switch(this.type){case"float":for(let t=i;t<=r;t+=10){const e=`${t}dB`,s=p,i=Math.trunc(-1*(t-r)/n*m)+u;if("none"!==k){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",s.toString(10)),t.setAttribute("y",i.toString(10)),t.setAttribute("width",f.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",k),a.appendChild(t)}if("none"!==k){const t=document.createElementNS(h.XMLNS,"text");t.textContent=e,t.setAttribute("x",s.toString(10)),t.setAttribute("y",(i-Math.trunc(A/4)).toString(10)),t.setAttribute("text-anchor","end"),t.setAttribute("stroke","none"),t.setAttribute("fill",w),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}break;case"uint":for(const t of["0.00","0.25","0.50","0.75","1.00"]){const e=p,s=(1-Number(t))*m+u;if("none"!==k){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",f.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",k),a.appendChild(t)}if("none"!==w){const i=document.createElementNS(h.XMLNS,"text");i.textContent=t,i.setAttribute("x",e.toString(10)),i.setAttribute("y",(s-Math.trunc(A/4)).toString(10)),i.setAttribute("text-anchor","end"),i.setAttribute("stroke","none"),i.setAttribute("fill",w),i.setAttribute("font-family",this.styles.font?.family??"Arial"),i.setAttribute("font-size",A.toString(10)),i.setAttribute("font-style",this.styles.font?.style??"normal"),i.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(i)}}}}}}class c{analyser;input;timeOverviewL;timeOverviewR;time;fft;timeDomainAnimationId=null;timeDomainTimerId=null;frequencyDomainAnimationId=null;frequencyDomainTimerId=null;constructor(t){this.analyser=t.createAnalyser(),this.input=t.createGain(),this.input.connect(this.analyser),this.timeOverviewL=new a(t.sampleRate,0),this.timeOverviewR=new a(t.sampleRate,1),this.time=new o(t.sampleRate,0),this.fft=new h(t.sampleRate,0),this.analyser.fftSize=2048,this.analyser.minDecibels=-100,this.analyser.maxDecibels=-30,this.analyser.smoothingTimeConstant=.8}start(t,e,s){switch(t){case"timeoverview":if((0===e||1===e)&&s)switch(e){case 0:if(s.numberOfChannels>e){const t=new Float32Array(s.length);t.set(s.getChannelData(e)),this.timeOverviewL.start(t)}break;case 1:if(s.numberOfChannels>e){const t=new Float32Array(s.length);t.set(s.getChannelData(e)),this.timeOverviewR.start(t)}}break;case"time":{const e=this.time.param("interval");switch(this.time.param("type")){case"uint":{const t=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(t),this.time.start(t);break}case"float":{const t=new Float32Array(this.analyser.fftSize);this.analyser.getFloatTimeDomainData(t),this.time.start(t);break}}"number"==typeof e&&(this.stop(t),e<0?this.timeDomainAnimationId=window.requestAnimationFrame((()=>{this.start(t)})):this.timeDomainTimerId=window.setTimeout((()=>{this.start(t)}),e));break}case"fft":{const e=this.fft.param("interval");switch(this.fft.param("type")){case"uint":{const t=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(t),this.fft.start(t);break}case"float":{const t=new Float32Array(this.analyser.frequencyBinCount);this.analyser.getFloatFrequencyData(t),this.fft.start(t,this.analyser.minDecibels,this.analyser.maxDecibels);break}}"number"==typeof e&&(this.stop(t),e<0?this.frequencyDomainAnimationId=window.requestAnimationFrame((()=>{this.start(t)})):this.frequencyDomainTimerId=window.setTimeout((()=>{this.start(t)}),e));break}}return this}stop(t){switch(t){case"time":{const t=this.time.param("interval");"number"==typeof t&&(t<0&&this.timeDomainAnimationId?(window.cancelAnimationFrame(this.timeDomainAnimationId),this.timeDomainAnimationId=null):this.timeDomainTimerId&&(window.clearTimeout(this.timeDomainTimerId),this.timeDomainTimerId=null));break}case"fft":{const t=this.fft.param("interval");"number"==typeof t&&(t<0&&this.frequencyDomainAnimationId?(window.cancelAnimationFrame(this.frequencyDomainAnimationId),this.frequencyDomainAnimationId=null):this.frequencyDomainTimerId&&(window.clearTimeout(this.frequencyDomainTimerId),this.frequencyDomainTimerId=null));break}}return this}param(t){if("string"==typeof t)switch(t){case"fftSize":return this.analyser.fftSize;case"frequencyBinCount":return this.analyser.frequencyBinCount;case"minDecibels":return this.analyser.minDecibels;case"maxDecibels":return this.analyser.maxDecibels;case"smoothingTimeConstant":return this.analyser.smoothingTimeConstant}for(const[e,s]of Object.entries(t))switch(e){case"fftSize":this.analyser.fftSize=s;break;case"minDecibels":this.analyser.minDecibels=s;break;case"maxDecibels":this.analyser.maxDecibels=s;break;case"smoothingTimeConstant":this.analyser.smoothingTimeConstant=s}return this}domain(t,e){switch(t){case"timeoverview":switch(e){case 0:return this.timeOverviewL;case 1:return this.timeOverviewR}return this;case"time":return this.time;case"fft":return this.fft}return this}get(){return this.analyser}get INPUT(){return this.input}get OUTPUT(){return this.input}}class u{id;dataBlocks=[];constructor(t){this.id=t}get(){return this.dataBlocks}append(t){return this.dataBlocks.push(t),this}clear(){this.dataBlocks.length=0}has(){return this.dataBlocks.length>0}toString(){return this.id}}class l{id;frames=[];channelGain=1;constructor(t){this.id=t}append(t){return this.frames.push(t),this}get(t){return"number"==typeof t&&t>=0&&t<this.frames.length?this.frames[t]:this.frames}gain(t){if(!("number"==typeof t&&t>=0&&t<=1))return this.channelGain;this.channelGain=t}length(){return this.frames.length}toString(){return this.id}}class RecorderProcessor extends AudioWorkletProcessor{static BUFFER_SIZE=128;constructor(){super()}process(t){if(0===t.length||0===t[0].length)return!0;const e={inputs:t};return this.port.postMessage(e),!0}}class p{processor;sampleRate;channels=[];activeTrack=-1;paused=!0;constructor(t){this.processor=new AudioWorkletNode(t,RecorderProcessor.name),this.sampleRate=t.sampleRate,this.processor.port.onmessage=t=>{if(-1===this.activeTrack)return;if(0===t.data.inputs.length)return;const e=t.data.inputs[0];if(0===e.length)return;const s=RecorderProcessor.BUFFER_SIZE;if(1===e.length){const t=e[0],i=this.channels[0].gain(),r=this.channels[0].get(this.activeTrack),n=new Float32Array(s);for(let e=0;e<s;e++)n[e]=i*t[e];return void r?.append(n)}const i=e[0],r=e[1],n=this.channels[0].gain(),a=this.channels[1].gain(),o=this.channels[0].get(this.activeTrack),h=this.channels[1].get(this.activeTrack),c=new Float32Array(s),u=new Float32Array(s);for(let t=0;t<s;t++)c[t]=n*i[t],u[t]=a*r[t];o?.append(c),h?.append(u)}}setup(t,e){this.channels.push(new l("0")),this.channels.push(new l("1"));for(const t of this.channels)for(let s=0;s<e;s++)t.append(new u(s.toString(10)));return this}ready(t){return this.hasTrack(t)?this.activeTrack=t:this.activeTrack=-1,this}start(){return-1!==this.activeTrack&&this.paused?(this.paused=!1,this):this}stop(){return this.activeTrack=-1,this.paused=!0,this.processor.disconnect(0),this}param(t){if("string"==typeof t)switch(t){case"0":if(this.channels[0])return this.channels[0].gain();break;case"1":if(this.channels[1])return this.channels[1].gain()}for(const[e,s]of Object.entries(t))switch(e){case"0":this.channels[0]&&"number"==typeof s&&this.channels[0].gain(s);break;case"1":this.channels[1]&&"number"==typeof s&&this.channels[1].gain(s)}return this}get(){return this.activeTrack}clear(t){if(-1!==this.activeTrack&&this.stop(),-1===t)for(const t of this.channels){const e=t.get();for(const t of e)t.clear()}else if(this.hasTrack(t))for(const e of this.channels){const s=e.get(t);s?.clear()}return this}create(t,e,s,i){-1!==this.activeTrack&&this.stop();let r=null,n=null;if(-1===t&&this.has(-1,-1))r=this.mixTrack(0),n=this.mixTrack(1);else{if(!this.has(0,t)||!this.has(1,t))return"";r=this.flatTrack(0,t),n=this.flatTrack(1,t)}if(null===r||null===n)return"";const a=this.sampleRate,o=s,h=e,c=h*Math.min(r.length,n.length),u=36+(8+c*(o/8)),l=u-8,p=a*h*(o/8),d=c*(o/8);let f=null;switch(o){case 8:f=new Uint8Array(c);for(let t=0;t<c;t++){let e=0;e=t%h==0?Math.round((r[Math.trunc(t/h)]+1)/2*255):Math.round((n[Math.trunc(t/h)]+1)/2*255),e>255&&(e=255),e<0&&(e=0),f[t]=e}break;case 16:f=new Int16Array(c);for(let t=0;t<c;t++){let e=0;e=t%h==0?Math.round(32768*r[Math.trunc(t/h)]):Math.round(32768*n[Math.trunc(t/h)]),e>32767&&(e=32767),e<-32768&&(e=-32768),f[t]=e}}if(null===f)return"";const m=new Uint8Array(u);m[0]=82,m[1]=73,m[2]=70,m[3]=70,m[4]=255&l,m[5]=l>>8&255,m[6]=l>>16&255,m[7]=l>>24&255,m[8]=87,m[9]=65,m[10]=86,m[11]=69,m[12]=102,m[13]=109,m[14]=116,m[15]=32,m[16]=16,m[17]=0,m[18]=0,m[19]=0,m[20]=1,m[21]=0,m[22]=h,m[23]=0,m[24]=255&a,m[25]=a>>8&255,m[26]=a>>16&255,m[27]=a>>24&255,m[28]=255&p,m[29]=p>>8&255,m[30]=p>>16&255,m[31]=p>>24&255,m[32]=h*(o/8),m[33]=0,m[34]=o,m[35]=0,m[36]=100,m[37]=97,m[38]=116,m[39]=97,m[40]=255&d,m[41]=d>>8&255,m[42]=d>>16&255,m[43]=d>>24&255;for(let t=0;t<c;t++){const e=u-d;switch(o){case 8:m[e+t]=f[t];break;case 16:m[e+2*t+0]=255&f[t],m[e+2*t+1]=f[t]>>8&255}}switch(i){case"base64":case"dataURL":{const t=window.btoa(Array.from(m).map((t=>String.fromCodePoint(t))).join(""));return"base64"===i?t:`data:audio/wav;base64,${t}`}case"blob":case"objectURL":{const t=new Blob([m],{type:"audio/wav"});return"blob"===i?t:window.URL.createObjectURL(t)}}}has(t,e){if(!this.hasChannel(t))return this.channels.some((t=>t.get().some((t=>t.has()))));const s=this.channels[t].get();if(!this.hasTrack(e))return s.some((t=>t.has()));const i=this.channels[t].get(e);return i?.has()??!1}hasChannel(t){return t>=0&&t<this.channels.length}hasTrack(t){return t>=0&&this.channels.every((e=>t<e.length()))}get INPUT(){return this.processor}get OUTPUT(){return this.processor}flatTrack(t,e){if(!this.hasChannel(t)||!this.hasTrack(e))return null;const s=this.channels[t].get(e);if(null===s)return null;const i=s.get(),r=RecorderProcessor.BUFFER_SIZE,n=new Float32Array(i.length*r);for(let t=0,e=i.length;t<e;t++){const e=i[t];for(let s=0;s<r;s++)n[t*r+s]=e[s]}return n}mixTrack(t){if(!this.hasChannel(t))return null;const e=this.channels[t].get(),s=RecorderProcessor.BUFFER_SIZE;let i=0,r=0,n=0,a=0,o=0;for(const t of e){const e=t.get();o<e.length&&(o=e.length)}const h=new Float32Array(o*s);for(;;){for(let t=0,s=e.length;t<s;t++){const s=e[t].get()[n];s&&a>=0&&a<=s.length&&(i+=s[a],r++)}if(r<=0)return h;h[n*s+a]=i/r,i=0,r=0,a<s-1?a++:(n++,a=0)}}}class d{context;input;output;lfo;depth;rate;isActive=!0;paused=!0;constructor(t){this.context=t,this.input=t.createGain(),this.output=t.createGain(),this.lfo=t.createOscillator(),this.depth=t.createGain(),this.rate=this.lfo.frequency}start(t){this.isActive&&this.paused&&(this.lfo.start(t??this.context.currentTime),this.paused=!1)}stop(t,e){if(!this.isActive||this.paused)return;const s=this.lfo.type,i=this.lfo.frequency.value;this.lfo.stop((t??this.context.currentTime)+(e??0)),this.lfo=this.context.createOscillator(),this.lfo.type=s,this.lfo.frequency.value=i,this.rate=this.lfo.frequency,this.paused=!0}toJSON(){return JSON.stringify(this.params())}state(){return this.isActive}activate(){return this.isActive=!0,this.connect(),this.start(0),this}deactivate(){return this.stop(0),this.isActive=!1,this.connect(),this}get INPUT(){return this.input}get OUTPUT(){return this.output}}class f extends d{panner;constructor(t){super(t),this.panner=this.context.createStereoPanner(),this.panner.pan.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.panner.pan)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.panner.pan))}connect(){return this.input.disconnect(0),this.panner.disconnect(0),this.isActive?(this.input.connect(this.panner),this.panner.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class m extends d{shaper;inputShaper;outputShaper;inputLevel;outputLevel;bitsInput;bitsGain;bits=0;constructor(t){super(t),this.shaper=this.context.createWaveShaper(),this.inputShaper=this.context.createWaveShaper(),this.outputShaper=this.context.createWaveShaper(),this.inputLevel=this.context.createGain(),this.outputLevel=this.context.createGain(),this.bitsInput=this.context.createConstantSource(),this.bitsGain=this.context.createGain();const e=new Float32Array(1023);for(let t=0;t<512;t++){const s=(t/512*128|0)/128;e[511+t]=s,e[511-t]=-s}const s=new Float32Array(10),i=new Float32Array(10);for(let t=0,e=64;t<6;t++,e*=.5)s[0+t]=1/64,s[4+t]=1/e,i[0+t]=64,i[4+t]=e;this.shaper.curve=e,this.shaper.oversample="4x",this.inputShaper.curve=s,this.outputShaper.curve=i,this.inputLevel.gain.value=0,this.outputLevel.gain.value=0,this.bitsInput.offset.value=this.bits,this.bitsGain.gain.value=1/8,this.deactivate()}start(t){this.isActive&&this.paused&&(this.bitsInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.bitsInput.stop(this.context.currentTime),this.bitsInput=this.context.createConstantSource(),this.bitsInput.offset.value=this.bits,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.shaper.disconnect(0),this.inputShaper.disconnect(0),this.outputShaper.disconnect(0),this.inputLevel.disconnect(0),this.outputLevel.disconnect(0),this.bitsInput.disconnect(0),this.bitsGain.disconnect(0),this.isActive?(this.input.connect(this.inputLevel),this.inputLevel.connect(this.shaper),this.shaper.connect(this.outputLevel),this.outputLevel.connect(this.output),this.bitsInput.connect(this.bitsGain),this.bitsGain.connect(this.inputShaper),this.inputShaper.connect(this.inputLevel.gain),this.bitsGain.connect(this.outputShaper),this.outputShaper.connect(this.outputLevel.gain)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"bits":return this.bits;case"oversample":return this.shaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"bits":"number"==typeof s&&(this.bits=s,this.bitsInput.offset.value=this.bits);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s))}return this}params(){return{state:this.isActive,bits:this.bits,oversample:this.shaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class v extends d{delay;tone;mix;feedback;depthRate=0;constructor(t){super(t),this.delay=t.createDelay(),this.mix=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.depth.gain.value=0,this.rate.value=0,this.mix.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.depthRate=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime))}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.mix.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.input.connect(this.output),this.isActive&&(this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.mix),this.mix.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":return this.mix.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s,this.depth.gain.value=this.delay.delayTime.value*this.depthRate);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.delay.delayTime.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.mix.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,depth:this.depthRate,rate:this.rate.value,mix:this.mix.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class g extends d{compressor;constructor(t){super(t),this.compressor=t.createDynamicsCompressor(),this.compressor.threshold.value=-24,this.compressor.knee.value=30,this.compressor.ratio.value=12,this.compressor.attack.value=.003,this.compressor.release.value=.25,this.activate()}connect(){return this.input.disconnect(0),this.compressor.disconnect(0),this.isActive?(this.input.connect(this.compressor),this.compressor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"threshold":return this.compressor.threshold.value;case"knee":return this.compressor.knee.value;case"ratio":return this.compressor.ratio.value;case"attack":return this.compressor.attack.value;case"release":return this.compressor.release.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"threshold":"number"==typeof s&&(this.compressor.threshold.value=s);break;case"knee":"number"==typeof s&&(this.compressor.knee.value=s);break;case"ratio":"number"==typeof s&&(this.compressor.ratio.value=s);break;case"attack":"number"==typeof s&&(this.compressor.attack.value=s);break;case"release":"number"==typeof s&&(this.compressor.release.value=s)}return this}params(){return{state:this.isActive,threshold:this.compressor.threshold.value,knee:this.compressor.knee.value,ratio:this.compressor.ratio.value,attack:this.compressor.attack.value,release:this.compressor.release.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class b extends d{static MAX_DELAY_TIME=5;delay;dry;wet;tone;feedback;constructor(t){super(t),this.delay=t.createDelay(b.MAX_DELAY_TIME),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.isActive?(this.input.connect(this.dry),this.dry.connect(this.output),this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.wet),this.wet.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"dry":return this.dry.gain.value;case"wet":return this.wet.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s);break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class y{static MIN_GAIN=.001;context;generators=[];activeIndexes=[];activeCounter=0;attack=.01;decay=.3;sustain=.5;release=1;isActive=!0;constructor(t){this.context=t}ready(t,e,s){e&&s&&this.generators[t]?(e.connect(this.generators[t]),this.generators[t].connect(s)):e&&null===s&&this.generators[t]?e.connect(this.generators[t]):null===e&&s&&this.generators[t]&&this.generators[t].connect(s),this.activeIndexes[t]=t,this.activeCounter++}start(t){const e=t,s=e+this.attack,i=this.decay,r=this.sustain;for(const t of this.activeIndexes)void 0!==t&&(this.isActive?(this.generators[t].gain.cancelScheduledValues(e),this.generators[t].gain.setValueAtTime(0,e),this.generators[t].gain.linearRampToValueAtTime(1,s),this.generators[t].gain.setTargetAtTime(r,s,i)):this.generators[t].gain.value=1)}stop(t,e){const s=t-this.release,i=s>=this.context.currentTime?s:this.context.currentTime,r=this.release;for(const t of this.activeIndexes)if(void 0!==t)if(this.isActive){if("function"==typeof this.generators[t].gain.cancelAndHoldAtTime)this.generators[t].gain.cancelAndHoldAtTime(i);else{const e=this.generators[t].gain.value;this.generators[t].gain.cancelScheduledValues(i),this.generators[t].gain.setValueAtTime(e,i)}e?this.generators[t].gain.setValueCurveAtTime(new Float32Array([1,.5,.25,0]),i,r):this.generators[t].gain.setTargetAtTime(0,i,r)}else this.generators[t].gain.value=0}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"attack":return this.attack;case"decay":return this.decay;case"sustain":return this.sustain;case"release":return this.release}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"attack":"number"==typeof s&&(this.attack=s);break;case"decay":"number"==typeof s&&(this.decay=s);break;case"sustain":"number"==typeof s&&(this.sustain=s);break;case"release":"number"==typeof s&&(this.release=s)}return this}getGenerator(t){return t>=0&&t<this.generators.length?this.generators[t]:null}setGenerator(t){this.generators[t]=this.context.createGain()}paused(){let t=0;for(const e of this.activeIndexes)if(void 0!==e){if(this.generators[e].gain.value>y.MIN_GAIN)return!1;if(t++,t===this.activeCounter)return!0}return!1}clear(t){this.activeIndexes.length=0,this.activeCounter=0;for(const e of this.generators)e.gain.cancelScheduledValues(this.context.currentTime),e.gain.value=1,t&&e.disconnect(0)}params(){return{state:this.isActive,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release}}toJSON(){return JSON.stringify(this.params())}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}}class k extends d{bass;middle;treble;presence;constructor(t){super(t),this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.presence=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.presence.type="highshelf",this.bass.frequency.value=500,this.middle.frequency.value=1e3,this.treble.frequency.value=2e3,this.presence.frequency.value=4e3,this.bass.Q.value=Math.SQRT1_2,this.middle.Q.value=Math.SQRT1_2,this.treble.Q.value=Math.SQRT1_2,this.presence.Q.value=Math.SQRT1_2,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.presence.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.bass.disconnect(0),this.middle.disconnect(0),this.treble.disconnect(0),this.presence.disconnect(0),this.isActive?(this.input.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.presence),this.presence.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"presence":return this.presence.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"presence":"number"==typeof s&&(this.presence.gain.value=s)}return this}params(){return{state:this.isActive,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,presence:this.presence.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class w extends d{filter;maxFrequency;range=.1;attack=.01;decay=.3;sustain=1;release=1;constructor(t){super(t),this.filter=t.createBiquadFilter(),this.filter.type="lowpass",this.filter.frequency.value=350,this.filter.Q.value=1,this.filter.gain.value=0,this.maxFrequency=this.filter.frequency.value,this.deactivate()}start(t){if(!this.isActive)return;const e=t??this.context.currentTime,s=e+this.attack,i=this.decay,r=this.sustain*this.maxFrequency,n=this.maxFrequency*this.range;this.filter.frequency.cancelScheduledValues(e),this.filter.frequency.setValueAtTime(n,e),this.filter.frequency.linearRampToValueAtTime(this.maxFrequency,s),this.filter.frequency.setTargetAtTime(r,s,i)}stop(t){if(!this.isActive)return;const e=t??this.context.currentTime,s=this.release,i=this.maxFrequency*this.range;if("function"==typeof this.filter.frequency.cancelAndHoldAtTime)this.filter.frequency.cancelAndHoldAtTime(e);else{const t=this.filter.frequency.value;this.filter.frequency.cancelScheduledValues(e),this.filter.frequency.setValueAtTime(t,e)}this.filter.frequency.setTargetAtTime(i,e,s)}connect(){return this.input.disconnect(0),this.filter.disconnect(0),this.isActive?(this.input.connect(this.filter),this.filter.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.filter.type;case"frequency":return this.filter.frequency.value;case"Q":return this.filter.Q.value;case"gain":return this.filter.gain.value;case"range":return this.range;case"attack":return this.attack;case"decay":return this.decay;case"sustain":return this.sustain;case"release":return this.release}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.filter.type=s);break;case"frequency":"number"==typeof s&&(this.filter.frequency.value=s,this.maxFrequency=s);break;case"Q":"number"==typeof s&&(this.filter.Q.value=s);break;case"gain":"number"==typeof s&&(this.filter.gain.value=s);break;case"range":"number"==typeof s&&(this.range=s);break;case"attack":"number"==typeof s&&(this.attack=s);break;case"decay":"number"==typeof s&&(this.decay=s);break;case"sustain":"number"==typeof s&&(this.sustain=s);break;case"release":"number"==typeof s&&(this.release=s)}return this}params(){return{state:this.isActive,type:this.filter.type,frequency:this.filter.frequency.value,Q:this.filter.Q.value,gain:this.filter.gain.value,range:this.range,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release}}activate(){return this.isActive=!0,this.connect(),this}deactivate(){return this.isActive=!1,this.connect(),this}}class A extends d{delay;tone;mix;feedback;depthRate=0;constructor(t){super(t),this.delay=t.createDelay(),this.mix=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.depth.gain.value=0,this.rate.value=0,this.mix.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.depthRate=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime))}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.mix.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.input.connect(this.output),this.isActive&&(this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.mix),this.mix.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":return this.mix.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s,this.depth.gain.value=this.delay.delayTime.value*this.depthRate);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.delay.delayTime.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.mix.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,depth:this.depthRate,rate:this.rate.value,mix:this.mix.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class x extends d{positiveShaper;negativeShaper;positiveInputGain;negativeInputGain;positiveOutputGain;negativeOutputGain;outFilter;driveInput;level;drive=0;constructor(t){super(t),this.positiveShaper=this.context.createWaveShaper(),this.negativeShaper=this.context.createWaveShaper(),this.positiveInputGain=this.context.createGain(),this.negativeInputGain=this.context.createGain(),this.positiveOutputGain=this.context.createGain(),this.negativeOutputGain=this.context.createGain(),this.driveInput=this.context.createConstantSource(),this.outFilter=this.context.createBiquadFilter(),this.level=this.context.createGain();const e=new Float32Array(1024);for(let t=0;t<512;t++){const s=.5*Math.tanh(4*t/512),i=1-t/512;e[512+t]=s,e[511-t]=s*i**4}this.positiveShaper.curve=e,this.negativeShaper.curve=e,this.positiveShaper.oversample="4x",this.negativeShaper.oversample="4x",this.positiveInputGain.gain.value=1,this.negativeInputGain.gain.value=-1,this.positiveOutputGain.gain.value=1,this.negativeOutputGain.gain.value=-1,this.driveInput.offset.value=this.drive,this.outFilter.type="highpass",this.outFilter.frequency.value=80,this.outFilter.Q.value=1,this.outFilter.gain.value=0,this.level.gain.value=1,this.deactivate()}start(t){this.isActive&&this.paused&&(this.driveInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.driveInput.stop(this.context.currentTime),this.driveInput=this.context.createConstantSource(),this.driveInput.offset.value=this.drive,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.positiveShaper.disconnect(0),this.negativeShaper.disconnect(0),this.positiveInputGain.disconnect(0),this.negativeInputGain.disconnect(0),this.positiveOutputGain.disconnect(0),this.negativeOutputGain.disconnect(0),this.driveInput.disconnect(0),this.outFilter.disconnect(0),this.level.disconnect(0),this.isActive?(this.input.connect(this.positiveInputGain),this.positiveInputGain.connect(this.positiveShaper),this.positiveShaper.connect(this.positiveOutputGain),this.positiveOutputGain.connect(this.outFilter),this.input.connect(this.negativeInputGain),this.negativeInputGain.connect(this.negativeShaper),this.negativeShaper.connect(this.negativeOutputGain),this.negativeOutputGain.connect(this.outFilter),this.driveInput.connect(this.negativeOutputGain.gain),this.outFilter.connect(this.level),this.level.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"drive":return this.drive;case"level":return this.level.gain.value;case"oversample":return this.positiveShaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"drive":"number"==typeof s&&(this.drive=s,this.driveInput.offset.value=this.drive);break;case"level":"number"==typeof s&&(this.level.gain.value=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.positiveShaper.oversample=s,this.negativeShaper.oversample=s))}return this}params(){return{state:this.isActive,drive:this.drive,level:this.level.gain.value,oversample:this.positiveShaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class T extends d{listener;positions;forwards;ups;constructor(t){super(t),this.listener=t.listener,this.positions={x:0,y:0,z:0},this.forwards={x:0,y:0,z:-1},this.ups={x:0,y:1,z:0},this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z),this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z)}connect(){return this.output}param(t){if("string"==typeof t)switch(t){case"x":return this.positions.x;case"y":return this.positions.y;case"z":return this.positions.z;case"fx":return this.forwards.x;case"fy":return this.forwards.y;case"fz":return this.forwards.z;case"ux":return this.ups.x;case"uy":return this.ups.y;case"uz":return this.ups.z}for(const[e,s]of Object.entries(t))switch(e){case"x":"number"==typeof s&&(this.positions.x=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"y":"number"==typeof s&&(this.positions.y=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"z":"number"==typeof s&&(this.positions.z=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"fx":"number"==typeof s&&(this.forwards.x=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"fy":"number"==typeof s&&(this.forwards.y=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"fz":"number"==typeof s&&(this.forwards.z=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"ux":"number"==typeof s&&(this.ups.x=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"uy":"number"==typeof s&&(this.ups.y=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"uz":"number"==typeof s&&(this.ups.z=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z))}return this}params(){return{x:this.positions.x,y:this.positions.y,z:this.positions.z,fx:this.forwards.x,fy:this.forwards.y,fz:this.forwards.z,ux:this.ups.x,uy:this.ups.y,uz:this.ups.z}}}class NoiseGateProcessor extends AudioWorkletProcessor{level=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"level":"number"==typeof s&&(this.level=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;const r=s[0].length;for(let t=0,e=s.length;t<e;t++)for(let e=0;e<r;e++)i[t][e]=this.gate(s[t][e]);return!0}gate(t){return this.isActive?Math.abs(t)>this.level?t:0:t}}class S extends d{processor;level=0;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,NoiseGateProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"level":return this.level}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"level":if("number"==typeof s){this.level=s;const t={level:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,level:this.level}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class NoiseSuppressorProcessor extends AudioWorkletProcessor{static FFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}}static IFFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s}threshold=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"threshold":"number"==typeof s&&(this.threshold=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;const r=s[0].length;for(let t=0,e=s.length;t<e;t++)this.suppress(s[t],i[t],r);return!0}suppress(t,e,s){if(!this.isActive||0===this.threshold)return void e.set(t);const i=new Float32Array(t),r=new Float32Array(s),n=new Float32Array(s),a=new Float32Array(s),o=new Float32Array(s),h=new Float32Array(s);NoiseSuppressorProcessor.FFT(i,r,s);for(let t=0;t<s;t++)o[t]=Math.sqrt(i[t]**2+r[t]**2),0!==i[t]&&0!==r[t]&&(h[t]=Math.atan2(r[t],i[t]));for(let t=0;t<s;t++)o[t]-=this.threshold,o[t]<0&&(o[t]=0);for(let t=0;t<s;t++)n[t]=o[t]*Math.cos(h[t]),a[t]=o[t]*Math.sin(h[t]);NoiseSuppressorProcessor.IFFT(n,a,s),e.set(n)}}class E extends d{processor;threshold=0;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,NoiseSuppressorProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"threshold":return this.threshold}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"threshold":if("number"==typeof s&&s>=0){this.threshold=s;const t={threshold:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,threshold:this.threshold}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class M extends d{shaper;inputShaper;outputShaper;inputGain;outputGain;driveInput;level;drive=0;constructor(t){super(t),this.shaper=this.context.createWaveShaper(),this.inputShaper=this.context.createWaveShaper(),this.outputShaper=this.context.createWaveShaper(),this.inputGain=this.context.createGain(),this.outputGain=this.context.createGain(),this.driveInput=this.context.createConstantSource(),this.level=this.context.createGain();const e=new Float32Array(1024);for(let t=0;t<512;t++){const s=.5*Math.tanh(4*t/512);e[512+t]=s,e[511-t]=-s}const s=new Float32Array(101);for(let t=0;t<101;t++)s[t]=.25;for(let t=52,e=.25;t<101;t++,e*=1.1)s[t]=e;const i=new Float32Array([2,2,2,2,2,.9,.5,.35,.3]);this.shaper.curve=e,this.shaper.oversample="4x",this.inputShaper.curve=s,this.outputShaper.curve=i,this.inputGain.gain.value=0,this.outputGain.gain.value=0,this.driveInput.offset.value=this.drive,this.level.gain.value=1,this.deactivate()}start(t){this.isActive&&this.paused&&(this.driveInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.driveInput.stop(this.context.currentTime),this.driveInput=this.context.createConstantSource(),this.driveInput.offset.value=this.drive,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.shaper.disconnect(0),this.inputShaper.disconnect(0),this.outputShaper.disconnect(0),this.inputGain.disconnect(0),this.outputGain.disconnect(0),this.driveInput.disconnect(0),this.level.disconnect(0),this.isActive?(this.input.connect(this.inputGain),this.inputGain.connect(this.shaper),this.shaper.connect(this.outputGain),this.outputGain.connect(this.level),this.level.connect(this.output),this.driveInput.connect(this.inputShaper),this.inputShaper.connect(this.inputGain.gain),this.driveInput.connect(this.outputShaper),this.outputShaper.connect(this.outputGain.gain)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"drive":return this.drive;case"level":return this.level.gain.value;case"oversample":return this.shaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"drive":"number"==typeof s&&(this.drive=s,this.driveInput.offset.value=this.drive);break;case"level":"number"==typeof s&&(this.level.gain.value=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s))}return this}params(){return{state:this.isActive,drive:this.drive,level:this.level.gain.value,oversample:this.shaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class F extends d{panner;positions;orientations;constructor(t){super(t),this.panner=t.createPanner(),this.positions={x:0,y:0,z:0},this.orientations={x:1,y:0,z:0},this.panner.refDistance=1,this.panner.maxDistance=1e4,this.panner.rolloffFactor=1,this.panner.coneInnerAngle=360,this.panner.coneOuterAngle=360,this.panner.coneOuterGain=0,this.panner.panningModel="HRTF",this.panner.distanceModel="inverse",this.panner.positionX.value=this.positions.x,this.panner.positionY.value=this.positions.y,this.panner.positionZ.value=this.positions.z,this.panner.orientationX.value=this.orientations.x,this.panner.orientationY.value=this.orientations.y,this.panner.orientationZ.value=this.orientations.z,this.deactivate()}connect(){return this.input.disconnect(0),this.panner.disconnect(0),this.isActive?(this.input.connect(this.panner),this.panner.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"x":return this.panner.positionX.value;case"y":return this.panner.positionY.value;case"z":return this.panner.positionZ.value;case"ox":return this.panner.orientationX.value;case"oy":return this.panner.orientationY.value;case"oz":return this.panner.orientationZ.value;case"refDistance":return this.panner.refDistance;case"maxDistance":return this.panner.maxDistance;case"rolloffFactor":return this.panner.rolloffFactor;case"coneInnerAngle":return this.panner.coneInnerAngle;case"coneOuterAngle":return this.panner.coneOuterAngle;case"coneOuterGain":return this.panner.coneOuterGain;case"panningModel":return this.panner.panningModel;case"distanceModel":return this.panner.distanceModel}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"x":"number"==typeof s&&(this.panner.positionX.value=s);break;case"y":"number"==typeof s&&(this.panner.positionY.value=s);break;case"z":"number"==typeof s&&(this.panner.positionZ.value=s);break;case"ox":"number"==typeof s&&(this.panner.orientationX.value=s);break;case"oy":"number"==typeof s&&(this.panner.orientationY.value=s);break;case"oz":"number"==typeof s&&(this.panner.orientationZ.value=s);break;case"refDistance":"number"==typeof s&&(this.panner.refDistance=s);break;case"maxDistance":"number"==typeof s&&(this.panner.maxDistance=s);break;case"rolloffFactor":"number"==typeof s&&(this.panner.rolloffFactor=s);break;case"coneInnerAngle":"number"==typeof s&&(this.panner.coneInnerAngle=s);break;case"coneOuterAngle":"number"==typeof s&&(this.panner.coneOuterAngle=s);break;case"coneOuterGain":"number"==typeof s&&(this.panner.coneOuterGain=s);break;case"panningModel":"HRTF"!==s&&"equalpower"!==s||(this.panner.panningModel=s);break;case"distanceModel":"linear"!==s&&"inverse"!==s&&"exponential"!==s||(this.panner.distanceModel=s)}return this}params(){return{state:this.isActive,x:this.positions.x,y:this.positions.y,z:this.positions.z,ox:this.orientations.x,oy:this.orientations.y,oz:this.orientations.z,refDistance:this.panner.refDistance,maxDistance:this.panner.maxDistance,rolloffFactor:this.panner.rolloffFactor,coneInnerAngle:this.panner.coneInnerAngle,coneOuterAngle:this.panner.coneOuterAngle,coneOuterGain:this.panner.coneOuterGain,panningModel:this.panner.panningModel,distanceModel:this.panner.distanceModel}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class N extends d{static MAX_STAGES=24;numberOfStages=12;filters=[];mix;depthRate=0;constructor(t){super(t);for(let e=0;e<N.MAX_STAGES;e++){const e=t.createBiquadFilter();e.type="allpass",e.frequency.value=350,e.Q.value=1,e.gain.value=0,this.filters.push(e)}this.mix=t.createGain(),this.depth.gain.value=0,this.rate.value=0,this.mix.gain.value=0,this.deactivate(),this.lfo.connect(this.depth);for(let t=0;t<N.MAX_STAGES;t++)this.depth.connect(this.filters[t].frequency)}stop(t,e){if(super.stop(t,e),this.isActive){this.lfo.connect(this.depth);for(let t=0;t<N.MAX_STAGES;t++)this.depth.connect(this.filters[t].frequency)}}connect(){this.input.disconnect(0);for(let t=0;t<N.MAX_STAGES;t++)this.filters[t].disconnect(0);if(this.mix.disconnect(0),this.input.connect(this.output),this.isActive&&this.numberOfStages>0){this.input.connect(this.filters[0]);for(let t=0;t<this.numberOfStages;t++)t<this.numberOfStages-1?this.filters[t].connect(this.filters[t+1]):(this.filters[t].connect(this.mix),this.mix.connect(this.output))}return this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"stage":return this.numberOfStages;case"frequency":return this.filters[0].frequency.value;case"resonance":return this.filters[0].Q.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":return this.mix.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"stage":switch(s){case 0:case 2:case 4:case 8:case 12:case 24:this.numberOfStages=s,this.connect()}break;case"frequency":if("number"==typeof s){for(const t of this.filters)t.frequency.value=s;this.depth.gain.value=s*this.depthRate}break;case"resonance":if("number"==typeof s)for(const t of this.filters)t.Q.value=s;break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.filters[0].frequency.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.mix.gain.value=s)}return this}params(){return{state:this.isActive,stage:this.numberOfStages,frequency:this.filters[0].frequency.value,resonance:this.filters[0].Q.value,depth:this.depthRate,rate:this.rate.value,mix:this.mix.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class PitchShifterProcessor extends AudioWorkletProcessor{static GAIN_CORRECTION=2;static FFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}}static IFFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s}isActive=!0;pitch=1;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"pitch":"number"==typeof s&&(this.pitch=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(this.isActive){const t=s[0].length;for(let e=0,r=s.length;e<r;e++)this.shift(s[e],i[e],t)}else i[0].set(s[0]),i[1].set(s[1]);return!0}shift(t,e,s){if(1===this.pitch)return void e.set(t);const i=new Float32Array(t),r=new Float32Array(s);PitchShifterProcessor.FFT(i,r,s);const n=new Float32Array(s),a=new Float32Array(s);for(let t=0;t<s;t++){const e=Math.trunc(this.pitch*t);let o=1;t>s/2&&(o=0),e>=0&&e<s&&(n[e]+=PitchShifterProcessor.GAIN_CORRECTION*o*i[t],a[e]+=PitchShifterProcessor.GAIN_CORRECTION*o*r[t])}PitchShifterProcessor.IFFT(n,a,s),e.set(n)}}class O extends d{processor;pitch=1;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,PitchShifterProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pitch":return this.pitch}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"pitch":if("number"==typeof s&&s>0){this.pitch=s;const t={pitch:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,pitch:this.pitch}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class R extends d{lowpass;notch;constructor(t){super(t),this.lowpass=t.createBiquadFilter(),this.notch=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=3200,this.lowpass.Q.value=6,this.lowpass.gain.value=0,this.notch.type="notch",this.notch.frequency.value=8e3,this.notch.Q.value=1,this.notch.gain.value=0,this.activate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.notch),this.notch.connect(this.lowpass),this.lowpass.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t&&"state"===t)return this.isActive;for(const[e,s]of Object.entries(t))if("state"===e)"boolean"==typeof s&&(s?this.activate():this.deactivate())}params(){return{state:this.isActive}}}class I extends d{shaper;preGain;leadGain;lowpass;highpass1;highpass2;highpass3;constructor(t){super(t),this.shaper=t.createWaveShaper(),this.preGain=t.createGain(),this.leadGain=t.createGain(),this.lowpass=t.createBiquadFilter(),this.highpass1=t.createBiquadFilter(),this.highpass2=t.createBiquadFilter(),this.highpass3=t.createBiquadFilter(),this.shaper.oversample="4x",this.preGain.gain.value=.5,this.leadGain.gain.value=.5,this.lowpass.type="lowpass",this.lowpass.frequency.value=3200,this.lowpass.Q.value=-3,this.lowpass.gain.value=0,this.highpass1.type="highpass",this.highpass1.frequency.value=80,this.highpass1.Q.value=-3,this.highpass1.gain.value=0,this.highpass2.type="highpass",this.highpass2.frequency.value=640,this.highpass2.Q.value=-3,this.highpass2.gain.value=0,this.highpass3.type="highpass",this.highpass3.frequency.value=80,this.highpass3.Q.value=-3,this.highpass3.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.highpass1),this.highpass1.connect(this.preGain),this.preGain.connect(this.highpass3),this.input.connect(this.highpass2),this.highpass2.connect(this.leadGain),this.leadGain.connect(this.highpass3),this.highpass3.connect(this.shaper),this.shaper.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"curve":case"oversample":return this.shaper.curve;case"gain":return this.preGain.gain.value;case"lead":return this.leadGain.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"curve":"number"!=typeof s&&"boolean"!=typeof s&&(s instanceof Float32Array||null===s)&&(this.shaper.curve=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s));break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"lead":"number"==typeof s&&(this.leadGain.gain.value=s)}}params(){return{state:this.isActive,curve:this.shaper.curve,gain:this.preGain.gain.value,lead:this.leadGain.gain.value,oversample:this.shaper.oversample}}}class C extends d{shaper;bass;middle;treble;lowpass;highpass;constructor(t){super(t),this.shaper=t.createWaveShaper(),this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.shaper.oversample="4x",this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=240,this.middle.frequency.value=500,this.treble.frequency.value=1600,this.bass.Q.value=Math.SQRT1_2,this.middle.Q.value=Math.SQRT1_2,this.treble.Q.value=Math.SQRT1_2,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.lowpass=t.createBiquadFilter(),this.highpass=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=2e4,this.lowpass.Q.value=-3,this.lowpass.gain.value=0,this.highpass.type="highpass",this.highpass.frequency.value=40,this.highpass.Q.value=-3,this.highpass.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.lowpass),this.lowpass.connect(this.highpass),this.highpass.connect(this.shaper),this.shaper.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"curve":return this.shaper.curve;case"oversample":return this.shaper.oversample;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"frequency":return this.middle.frequency.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"curve":"number"!=typeof s&&"boolean"!=typeof s&&(s instanceof Float32Array||null===s)&&(this.shaper.curve=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s));break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"frequency":"number"==typeof s&&(this.middle.frequency.value=s)}}params(){return{state:this.isActive,curve:this.shaper.curve,oversample:this.shaper.oversample,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,frequency:this.middle.frequency.value}}}class q extends d{preEQ;postEQ;cabinet;level=0;numberOfSamples=1024;constructor(t){super(t),this.preEQ=new I(t),this.postEQ=new C(t),this.cabinet=new R(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.postEQ.INPUT),this.postEQ.OUTPUT.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"level":return this.level;case"samples":return this.numberOfSamples;case"pre":return this.preEQ.params();case"post":return this.postEQ.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postEQ.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postEQ.deactivate()));break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);this.preEQ.param({curve:t}),this.postEQ.param({curve:t})}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);this.preEQ.param({curve:t}),this.postEQ.param({curve:t})}break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postEQ.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,level:this.level,samples:this.numberOfSamples,pre:this.preEQ.params(),post:this.postEQ.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class P extends d{preGain;preHighpass;postHighpass;bass;middle;treble;shapers=[];level=0;numberOfSamples=1024;usePostFilters=!0;lowpass;highpass;constructor(t){super(t),this.preGain=t.createGain(),this.preGain.gain.value=.5,this.preHighpass=t.createBiquadFilter(),this.postHighpass=t.createBiquadFilter(),this.preHighpass.type="highpass",this.postHighpass.type="highpass",this.preHighpass.frequency.value=40,this.postHighpass.frequency.value=80,this.preHighpass.Q.value=-3,this.postHighpass.Q.value=-3,this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=160,this.middle.frequency.value=284,this.treble.frequency.value=1200,this.middle.Q.value=1.5,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0;const e=D(this.level,this.numberOfSamples);for(let s=0;s<2;s++)this.shapers[s]=t.createWaveShaper(),this.shapers[s].curve=e,this.shapers[s].oversample="4x";this.lowpass=t.createBiquadFilter(),this.highpass=t.createBiquadFilter(),this.lowpass.type="lowpass",this.highpass.type="highpass",this.lowpass.frequency.value=4e3,this.highpass.frequency.value=40,this.lowpass.Q.value=-3,this.highpass.Q.value=-3,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preGain),this.preGain.connect(this.preHighpass),this.preHighpass.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.postHighpass),this.postHighpass.connect(this.shapers[0]),this.usePostFilters?(this.shapers[0].connect(this.lowpass),this.lowpass.connect(this.highpass),this.highpass.connect(this.shapers[1])):this.shapers[0].connect(this.shapers[1]),this.shapers[1].connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"gain":return this.preGain.gain.value;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"level":return this.level;case"samples":return this.numberOfSamples;case"oversample":return this.shapers[0].oversample;case"postFilters":return this.usePostFilters}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<2;e++)this.shapers[e].curve=t}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<2;e++)this.shapers[e].curve=t}break;case"oversample":if("string"==typeof s&&("none"===s||"2x"===s||"4x"===s))for(let t=0;t<2;t++)this.shapers[t].oversample=s;break;case"postFilters":"boolean"==typeof s&&(this.usePostFilters=s,this.connect())}}params(){return{state:this.isActive,gain:this.preGain.gain.value,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,level:this.level,samples:this.numberOfSamples,oversample:this.shapers[0].oversample,postFilters:this.usePostFilters}}}class U extends d{peakingFilters=[];constructor(t){super(t);for(let e=0;e<5;e++)this.peakingFilters[e]=t.createBiquadFilter(),this.peakingFilters[e].type="peaking",this.peakingFilters[e].gain.value=0;this.peakingFilters[0].frequency.value=100,this.peakingFilters[1].frequency.value=360,this.peakingFilters[2].frequency.value=720,this.peakingFilters[3].frequency.value=1600,this.peakingFilters[4].frequency.value=4800,this.peakingFilters[0].Q.value=1.5,this.peakingFilters[1].Q.value=2,this.peakingFilters[2].Q.value=2,this.peakingFilters[3].Q.value=1.1,this.peakingFilters[4].Q.value=1.2,this.deactivate()}connect(){if(this.input.disconnect(0),this.isActive){this.input.connect(this.peakingFilters[0]);for(let t=0,e=this.peakingFilters.length-1;t<e;t++)this.peakingFilters[t].connect(this.peakingFilters[t+1]);this.peakingFilters[4].connect(this.output)}else this.input.connect(this.output);return this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"fc100":return this.peakingFilters[0].gain.value;case"fc360":return this.peakingFilters[1].gain.value;case"fc720":return this.peakingFilters[2].gain.value;case"fc1600":return this.peakingFilters[3].gain.value;case"fc4800":return this.peakingFilters[4].gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"fc100":"number"==typeof s&&(this.peakingFilters[0].gain.value=s);break;case"fc360":"number"==typeof s&&(this.peakingFilters[1].gain.value=s);break;case"fc720":"number"==typeof s&&(this.peakingFilters[2].gain.value=s);break;case"fc1600":"number"==typeof s&&(this.peakingFilters[3].gain.value=s);break;case"fc4800":"number"==typeof s&&(this.peakingFilters[4].gain.value=s)}}params(){return{state:this.isActive,fc100:this.peakingFilters[0].gain.value,fc360:this.peakingFilters[1].gain.value,fc720:this.peakingFilters[2].gain.value,fc1600:this.peakingFilters[3].gain.value,fc4800:this.peakingFilters[4].gain.value}}}class G extends d{preEQ;postEQ;cabinet;constructor(t){super(t),this.preEQ=new P(t),this.postEQ=new U(t),this.cabinet=new R(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.postEQ.INPUT),this.postEQ.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pre":return this.preEQ.params();case"post":return this.postEQ.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postEQ.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postEQ.deactivate()));break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postEQ.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,pre:this.preEQ.params(),post:this.postEQ.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class z extends d{preGain;highpass;bass;middle;treble;gainEdge;gainBody;gainBottom;shapers=[];iirLowpassFilters=[];iirHighpassFilters=[];mixer;level=0;numberOfSamples=1024;constructor(t){super(t),this.preGain=t.createGain(),this.preGain.gain.value=.5,this.highpass=t.createBiquadFilter(),this.highpass.type="highpass",this.highpass.frequency.value=40,this.highpass.Q.value=1,this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=160,this.middle.frequency.value=284,this.treble.frequency.value=1200,this.middle.Q.value=1.5,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.gainEdge=t.createGain(),this.gainBody=t.createGain(),this.gainBottom=t.createGain(),this.gainEdge.gain.value=1,this.gainBody.gain.value=1,this.gainBottom.gain.value=1;const e=D(this.level,this.numberOfSamples);for(let s=0;s<3;s++)this.shapers[s]=t.createWaveShaper(),this.shapers[s].curve=e,this.shapers[s].oversample="4x";const s=220/t.sampleRate*Math.PI,i=220/t.sampleRate*Math.PI,r=new Float32Array([s,s]),n=new Float32Array([i,i]),a=new Float32Array([1+s,-1+s]),o=new Float32Array([1+i,-1+i]),h=new Float32Array([1,-1]),c=new Float32Array([1,-1]),u=new Float32Array([1+s,-1+s]),l=new Float32Array([1+i,-1+i]);this.iirLowpassFilters[0]=t.createIIRFilter(r,a),this.iirLowpassFilters[1]=t.createIIRFilter(n,o),this.iirHighpassFilters[0]=t.createIIRFilter(h,u),this.iirHighpassFilters[1]=t.createIIRFilter(c,l),this.mixer=t.createGain(),this.mixer.gain.value=1,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preGain),this.preGain.connect(this.highpass),this.highpass.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.iirHighpassFilters[1]),this.iirHighpassFilters[1].connect(this.shapers[0]),this.shapers[0].connect(this.gainEdge),this.gainEdge.connect(this.mixer),this.treble.connect(this.iirHighpassFilters[0]),this.iirHighpassFilters[0].connect(this.shapers[1]),this.shapers[1].connect(this.iirLowpassFilters[1]),this.iirLowpassFilters[1].connect(this.gainBody),this.gainBody.connect(this.mixer),this.treble.connect(this.iirLowpassFilters[0]),this.iirLowpassFilters[0].connect(this.shapers[2]),this.shapers[2].connect(this.gainBottom),this.gainBottom.connect(this.mixer),this.mixer.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"gain":return this.preGain.gain.value;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"level":return this.level;case"samples":return this.numberOfSamples;case"oversample":return this.shapers[0].oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<3;e++)this.shapers[e].curve=t}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<3;e++)this.shapers[e].curve=t}break;case"oversample":if("string"==typeof s&&("none"===s||"2x"===s||"4x"===s))for(let t=0;t<3;t++)this.shapers[t].oversample=s}}params(){return{state:this.isActive,gain:this.preGain.gain.value,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,level:this.level,samples:this.numberOfSamples,oversample:this.shapers[0].oversample}}}class _ extends d{cabinet;inch=-1;tilt=!1;speakerFilter;tiltFilter;constructor(t,e){super(t),this.cabinet=e,this.speakerFilter=t.createBiquadFilter(),this.speakerFilter.type="peaking",this.speakerFilter.frequency.value=40,this.speakerFilter.Q.value=-3,this.speakerFilter.gain.value=0,this.tiltFilter=t.createBiquadFilter(),this.tiltFilter.type="highshelf",this.tiltFilter.frequency.value=3200,this.tiltFilter.Q.value=Math.SQRT1_2,this.tiltFilter.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.speakerFilter),this.speakerFilter.connect(this.tiltFilter),this.tiltFilter.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"inch":return this.inch;case"tilt":return this.tilt}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"inch":if("number"==typeof s)switch(s){case-1:this.inch=-1,this.speakerFilter.frequency.value=40,this.speakerFilter.Q.value=Math.SQRT1_2,this.speakerFilter.gain.value=0;break;case 10:this.inch=10,this.speakerFilter.frequency.value=120,this.speakerFilter.Q.value=3,this.speakerFilter.gain.value=9;break;case 12:this.inch=12,this.speakerFilter.frequency.value=80,this.speakerFilter.Q.value=6,this.speakerFilter.gain.value=10;break;case 15:this.inch=15,this.speakerFilter.frequency.value=60,this.speakerFilter.Q.value=9,this.speakerFilter.gain.value=12}break;case"tilt":"boolean"==typeof s&&(this.tilt=s,this.tilt?this.tiltFilter.gain.value=6:this.tiltFilter.gain.value=0)}}params(){return{state:this.isActive,inch:this.inch,tilt:this.tilt}}}class L extends d{preEQ;postFilter;cabinet;constructor(t){super(t),this.cabinet=new R(t),this.preEQ=new z(t),this.postFilter=new _(t,this.cabinet),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.postFilter.INPUT),this.postFilter.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pre":return this.preEQ.params();case"post":return this.postFilter.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postFilter.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postFilter.deactivate()));break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postFilter.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,pre:this.preEQ.params(),post:this.postFilter.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}function D(t,e){const s=Math.trunc((e-1)/2),i=new Float32Array(e),r=(10**(t/5-1)-.1)/5+1;let n=.4;1===r?n=1:r>1&&r<1.04&&(n=-15.5*r+16.52);for(let t=0;t<s;t++)i[s+t]=n*(1-r**-t+t*r**-s/s),i[s-t]=n*(-1+r**-t-t*r**-s/s);return i[s]=0,i}class B extends d{type="marshall";preamp;constructor(t){super(t),this.preamp=new q(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.preamp.connect(),this.input.connect(this.preamp.INPUT),this.preamp.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.type;case"preamp":return this.preamp.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preamp.activate()):(this.deactivate(),this.preamp.deactivate()));break;case"type":if("string"==typeof s){switch(s){case"marshall":this.type="marshall",this.preamp=new q(this.context);break;case"mesa":this.type="mesa",this.preamp=new G(this.context);break;case"fender":this.type="fender",this.preamp=new L(this.context)}this.connect()}break;case"preamp":if("object"==typeof s){if(this.preamp instanceof q){const t=s;this.preamp.param(t)}if(this.preamp instanceof G){const t=s;this.preamp.param(t)}if(this.preamp instanceof L){const t=s;this.preamp.param(t)}}}return this}params(){return{state:this.isActive,type:this.type,preamp:this.preamp.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class Q extends d{convolver;dry;wet;tone;rirs=[];loadError=!1;constructor(t){super(t),this.convolver=t.createConvolver(),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.convolver.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.isActive?(this.input.connect(this.dry),this.dry.connect(this.output),this.input.connect(this.tone),this.tone.connect(this.convolver),this.convolver.connect(this.wet),this.wet.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"buffer":return this.convolver.buffer;case"dry":return this.dry.gain.value;case"wet":return this.wet.gain.value;case"tone":return this.tone.frequency.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"buffer":"number"==typeof s?s>=0&&s<this.rirs.length&&(this.convolver.buffer=this.rirs[s],this.connect()):s instanceof AudioBuffer?(this.convolver.buffer=s,this.connect()):null===s&&(this.convolver.buffer=null,this.input.disconnect(0),this.input.connect(this.output));break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s)}return this}add(t,e){if(t instanceof AudioBuffer)this.convolver.buffer=t,this.rirs.push(t);else if(t instanceof ArrayBuffer){const s=t=>{this.convolver.buffer=t,this.rirs.push(t)};this.context.decodeAudioData(t,s,e??(()=>{}))}return this}preset(t){const{rirs:e,timeout:s,successCallback:i,errorCallback:r,progressCallback:n}=t;for(let t=0,a=e.length;t<a;t++){const a=e[t];"string"==typeof a?this.load({rir:a,index:t,timeout:s,successCallback:i,errorCallback:r,progressCallback:n}):this.rirs[t]=a}}params(){return{state:this.isActive,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value}}activate(){return this.isActive=!0,this.connect(),this}deactivate(){return this.isActive=!1,this.connect(),this}load(t){const{rir:e,index:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{!this.loadError&&n&&n(t,"timeout"),this.loadError=!0},o.onprogress=t=>{this.loadError?o.abort():a&&a(t)},o.onerror=t=>{!this.loadError&&n&&n(t,"error"),this.loadError=!0},o.onload=t=>{if(200===o.status){const e=o.response,i=e=>{this.rirs[s]=e;for(const t of this.rirs)if(void 0===t)return;r&&r(t)},a=t=>{n&&n(t,"decode")};this.context.decodeAudioData(e,i,a)}},o.open("GET",e,!0),o.responseType="arraybuffer",o.send(null)}}class $ extends d{amplitude;constructor(t){super(t),this.amplitude=t.createGain(),this.amplitude.gain.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain))}connect(){return this.input.disconnect(0),this.amplitude.disconnect(0),this.isActive?(this.input.connect(this.amplitude),this.amplitude.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class StereoProcessor extends AudioWorkletProcessor{isActive=!1;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))if("state"===e)"boolean"==typeof s&&(this.isActive=s)}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(2!==s.length||2!==i.length)return i[0].set(s[0]),!0;if(this.isActive){const t=s[0].length;for(let e=0;e<t;e++)i[0][e]=s[0][e],i[1][e]=-s[1][e]}else i[0].set(s[0]),i[1].set(s[1]);return!0}}class j extends d{static MAX_DELAY_TIME=1;processor;splitter;merger;delayL;delayR;constructor(t){super(t),this.splitter=t.createChannelSplitter(2),this.merger=t.createChannelMerger(2),this.delayL=t.createDelay(j.MAX_DELAY_TIME),this.delayR=t.createDelay(j.MAX_DELAY_TIME),this.delayL.delayTime.value=0,this.delayR.delayTime.value=0,this.processor=new AudioWorkletNode(this.context,StereoProcessor.name),this.deactivate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.splitter.disconnect(0),this.delayL.disconnect(0),this.delayR.disconnect(0),this.merger.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.splitter),this.splitter.connect(this.delayL,0,0),this.splitter.connect(this.delayR,1,0),this.delayL.connect(this.processor),this.delayR.connect(this.processor),this.processor.connect(this.merger),this.merger.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delayL.delayTime.value}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"time":"number"==typeof s&&(this.delayL.delayTime.value=s,this.delayR.delayTime.value=s)}return this}params(){return{state:this.isActive,time:this.delayL.delayTime.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class X extends d{amplitude;constructor(t){super(t),this.amplitude=t.createGain(),this.amplitude.gain.value=1,this.lfo.type="sine",this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain))}connect(){return this.input.disconnect(0),this.amplitude.disconnect(0),this.isActive?(this.input.connect(this.amplitude),this.amplitude.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.lfo.type;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.lfo.type=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,type:this.lfo.type,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class VocalCancelerProcessor extends AudioWorkletProcessor{depth=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(2!==s.length||2!==i.length)return i[0].set(s[0]),!0;const r=s[0].length;for(let t=0;t<r;t++)i[0][t]=this.cancel(s[0][t],s[1][t]),i[1][t]=this.cancel(s[1][t],s[0][t]);return!0}cancel(t,e){return this.isActive?t-this.depth*e:t}}class W extends d{processor;constructor(t){super(t),this.depth.gain.value=0,this.processor=new AudioWorkletNode(this.context,VocalCancelerProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"depth":if("number"==typeof s){this.depth.gain.value=s;const t={depth:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,depth:this.depth.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class V extends d{auto=!1;lowpass;envelopeFollower;sensitivity;depthRate=0;constructor(t){super(t),this.lowpass=t.createBiquadFilter(),this.envelopeFollower=t.createWaveShaper(),this.sensitivity=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=this.auto?20:350,this.lowpass.Q.value=1,this.lowpass.gain.value=0,this.envelopeFollower.curve=new Float32Array([1,0,1]),this.sensitivity.type="lowpass",this.sensitivity.frequency.value=350,this.sensitivity.Q.value=1,this.sensitivity.gain.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.connect()}stop(t,e){super.stop(t,e),!this.auto&&this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.lowpass.frequency))}connect(){return this.input.disconnect(0),this.sensitivity.disconnect(0),this.envelopeFollower.disconnect(0),this.lowpass.disconnect(0),this.depth.disconnect(0),this.isActive?this.auto?(this.input.connect(this.sensitivity),this.sensitivity.connect(this.output),this.input.connect(this.envelopeFollower),this.envelopeFollower.connect(this.lowpass),this.lowpass.connect(this.depth),this.depth.connect(this.sensitivity.frequency)):(this.input.connect(this.lowpass),this.lowpass.connect(this.output),this.lfo.connect(this.depth),this.depth.connect(this.lowpass.frequency)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"auto":return this.auto;case"cutoff":return this.auto?this.sensitivity.frequency.value:this.lowpass.frequency.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"resonance":return this.auto?this.sensitivity.Q.value:this.lowpass.Q.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"auto":"boolean"==typeof s&&(this.auto=s,this.connect());break;case"cutoff":"number"==typeof s&&(this.auto?(this.sensitivity.frequency.value=s,this.lowpass.frequency.value=20):this.lowpass.frequency.value=s);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.auto?1e4*s:this.lowpass.frequency.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"resonance":"number"==typeof s&&(this.auto?(this.sensitivity.Q.value=s,this.lowpass.Q.value=1):this.lowpass.Q.value=s)}return this}params(){return{state:this.isActive,auto:this.auto,cutoff:this.auto?this.sensitivity.frequency.value:this.lowpass.frequency.value,depth:this.auto?this.depth.gain.value:this.depthRate,rate:this.rate.value,resonance:this.auto?this.sensitivity.Q.value:this.lowpass.Q.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class H{static NUMBER_OF_INPUTS=2;static NUMBER_OF_OUTPUTS=2;context;modules=[];mastervolume;processor;analyser;recorder;autopanner;bitcrusher;chorus;compressor;delay;envelopegenerator;equalizer;filter;flanger;fuzz;listener;noisegate;noisesuppressor;overdrive;panner;phaser;pitchshifter;preamp;reverb;ringmodulator;stereo;tremolo;vocalcanceler;wah;runningAnalyser=!1;mixed=!1;constructor(t){this.context=t,this.mastervolume=t.createGain(),this.processor=new AudioWorkletNode(t,SoundModuleProcessor.name),this.analyser=new c(t),this.recorder=new p(t),this.autopanner=new f(t),this.bitcrusher=new m(t),this.chorus=new v(t),this.compressor=new g(t),this.delay=new b(t),this.envelopegenerator=new y(t),this.equalizer=new k(t),this.filter=new w(t),this.flanger=new A(t),this.fuzz=new x(t),this.listener=new T(t),this.noisegate=new S(t),this.noisesuppressor=new E(t),this.overdrive=new M(t),this.panner=new F(t),this.phaser=new N(t),this.pitchshifter=new O(t),this.preamp=new B(t),this.reverb=new Q(t),this.ringmodulator=new $(t),this.stereo=new j(t),this.tremolo=new X(t),this.vocalcanceler=new W(t),this.wah=new V(t),this.modules=[this.compressor,this.wah,this.bitcrusher,this.overdrive,this.fuzz,this.preamp,this.equalizer,this.filter,this.pitchshifter,this.tremolo,this.ringmodulator,this.phaser,this.flanger,this.chorus,this.delay,this.reverb,this.panner,this.autopanner]}connect(t){if(t.disconnect(0),this.modules.length>0){const e=this.modules[0].INPUT;if(null===e)return;t.connect(e)}else t.connect(this.mastervolume);for(let t=0,e=this.modules.length;t<e;t++){const e=this.modules[t].OUTPUT;if(null!==e)if(e.disconnect(0),t<this.modules.length-1){const s=this.modules[t+1].INPUT;if(null===s)continue;e.connect(s)}else e.connect(this.mastervolume)}this.mastervolume.connect(this.context.destination),this.mastervolume.connect(this.analyser.INPUT),this.mastervolume.connect(this.recorder.INPUT),this.recorder.OUTPUT.connect(this.context.destination)}disconnect(){this.processor.disconnect(0)}install(t){const e=new t(this.context);return this.modules.push(e),e}on(t){const e=t??this.context.currentTime;return this.autopanner.start(e),this.bitcrusher.start(e),this.chorus.start(e),this.filter.start(e),this.flanger.start(e),this.fuzz.start(e),this.overdrive.start(e),this.phaser.start(e),this.ringmodulator.start(e),this.tremolo.start(e),this.wah.start(e),this}off(t){const e=t??this.context.currentTime;return this.autopanner.stop(e),this.bitcrusher.stop(e),this.chorus.stop(e),this.filter.stop(e),this.flanger.stop(e),this.fuzz.stop(e),this.overdrive.stop(e),this.phaser.stop(e),this.ringmodulator.stop(e),this.tremolo.stop(e),this.wah.stop(e),this}suspend(){return this.analyser.stop("time"),this.analyser.stop("fft"),this.runningAnalyser=!1,this.recorder.stop(),this}mix(){return this.mixed=!0,this}demix(){return this.mixed=!1,this}params(){return{mastervolume:this.mastervolume.gain.value,stereo:this.stereo.params(),compressor:this.compressor.params(),bitcrusher:this.bitcrusher.params(),overdrive:this.overdrive.params(),fuzz:this.fuzz.params(),preamp:this.preamp.params(),wah:this.wah.params(),pitchshifter:this.pitchshifter.params(),equalizer:this.equalizer.params(),filter:this.filter.params(),autopanner:this.autopanner.params(),tremolo:this.tremolo.params(),ringmodulator:this.ringmodulator.params(),phaser:this.phaser.params(),flanger:this.flanger.params(),chorus:this.chorus.params(),delay:this.delay.params(),reverb:this.reverb.params(),panner:this.panner.params(),listener:this.listener.params(),envelopegenerator:this.envelopegenerator.params(),noisegate:this.noisegate.params(),noisesuppressor:this.noisesuppressor.params(),vocalcanceler:this.vocalcanceler.params()}}edit(t){const e=this.modules;return this.modules=t,e}toJSON(){return JSON.stringify(this.params())}init(t){this.mastervolume.disconnect(0),this.processor.disconnect(0),this.analyser.INPUT.disconnect(0),this.recorder.INPUT.disconnect(0);for(const t of this.modules)t.INPUT&&t.INPUT.disconnect(0),t.OUTPUT&&t.OUTPUT.disconnect(0);this.modules.length=0,this.analyser=new c(t),this.recorder=new p(t),this.autopanner=new f(t),this.bitcrusher=new m(t),this.chorus=new v(t),this.compressor=new g(t),this.delay=new b(t),this.envelopegenerator=new y(t),this.equalizer=new k(t),this.filter=new w(t),this.flanger=new A(t),this.fuzz=new x(t),this.listener=new T(t),this.noisegate=new S(t),this.noisesuppressor=new E(t),this.overdrive=new M(t),this.panner=new F(t),this.phaser=new N(t),this.pitchshifter=new O(t),this.preamp=new B(t),this.reverb=new Q(t),this.ringmodulator=new $(t),this.stereo=new j(t),this.tremolo=new X(t),this.vocalcanceler=new W(t),this.wah=new V(t),this.modules=[this.compressor,this.wah,this.bitcrusher,this.overdrive,this.fuzz,this.preamp,this.equalizer,this.filter,this.pitchshifter,this.tremolo,this.ringmodulator,this.phaser,this.flanger,this.chorus,this.delay,this.reverb,this.panner,this.autopanner]}}class OscillatorModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class Y{context;type="linear";time=0;prevFrequency=-1;nextFrequency=0;isActive=!0;constructor(t){this.context=t}ready(t){this.nextFrequency=t;const e=-1===this.prevFrequency?0:this.nextFrequency-this.prevFrequency;this.isActive&&0!==this.time&&0!==e||(this.prevFrequency=this.nextFrequency)}start(t,e){const s=e??this.context.currentTime,i=s+this.time;t.frequency.cancelScheduledValues(s),t.frequency.setValueAtTime(this.prevFrequency,s),"exponential"===this.type?t.frequency.exponentialRampToValueAtTime(this.nextFrequency,i):t.frequency.linearRampToValueAtTime(this.nextFrequency,i)}stop(){this.prevFrequency=this.nextFrequency}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.type;case"time":return this.time}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.type=s);break;case"time":"number"==typeof s&&(this.time=s)}return this}params(){return{state:this.isActive,type:this.type,time:this.time}}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}}class J{static OCTAVE=1200;context;source;volume;octave=0;fine=0;custom={real:new Float32Array([0,1]),imag:new Float32Array([0,1])};isActive;paused=!0;constructor(t,e){this.context=t,this.source=t.createOscillator(),this.volume=t.createGain(),this.isActive=e}ready(t){if(!this.isActive)return;const e=this.source.type,s=this.source.frequency.value,i=this.source.detune.value;if(this.paused||(this.source.stop(this.context.currentTime),this.source.disconnect(0)),this.source=this.context.createOscillator(),"custom"===e){const t=this.custom.real,e=this.custom.imag,s=this.context.createPeriodicWave(t,e);this.source.setPeriodicWave(s)}else this.source.type=e;this.source.frequency.value=s,this.source.detune.value=i,this.volume.connect(t)}start(t){this.isActive?(this.source.start(t??this.context.currentTime),this.paused=!1):(this.paused||(this.source.stop(this.context.currentTime),this.paused=!0),this.source.disconnect(0))}stop(t){this.paused||(this.source.stop(t??this.context.currentTime),this.source.disconnect(0),this.paused=!0)}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.source.type;case"octave":return this.octave;case"fine":return this.fine;case"volume":return this.volume.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":if("string"==typeof s)this.source.type=s;else if("object"==typeof s){let{real:t,imag:e}=s;const i=4096;t.length>i&&(t=t.subarray(0,i)),e.length>i&&(e=e.subarray(0,i)),0!==t[0]&&(t[0]=0),0!==e[0]&&(e[0]=0);const r=this.context.createPeriodicWave(t,e);this.source.setPeriodicWave(r),this.custom.real=t,this.custom.imag=e}break;case"octave":"number"==typeof s&&(this.octave=s,this.source.detune.value=this.fine+s*J.OCTAVE);break;case"fine":"number"==typeof s&&(this.fine=s,this.source.detune.value=s+this.octave*J.OCTAVE);break;case"volume":"number"==typeof s&&(this.volume.gain.value=s)}return this}get(){return this.source}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}params(){return{state:this.isActive,type:this.source.type,octave:this.octave,fine:this.fine,volume:this.volume.gain.value}}get INPUT(){return this.source}get OUTPUT(){return this.volume}}class K extends H{sources=[];glide;startTime=0;duration=0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,OscillatorModuleProcessor.name),this.glide=new Y(t)}setup(t){this.sources.length=0;for(let e=0,s=t.length;e<s;e++)this.sources[e]=new J(this.context,t[e]),this.envelopegenerator.setGenerator(e);return this}ready(t,e){return this.startTime=t??this.context.currentTime,this.duration=e??0,this.envelopegenerator.clear(!0),this}start(t){const e=this.context.currentTime+this.startTime;this.mixed||(this.envelopegenerator.clear(!0),this.connect(this.processor));for(let s=0,i=t.length;s<i&&!(s>=this.sources.length);s++){const i=this.sources[s],r=t[s];i.ready(this.processor),this.envelopegenerator.ready(s,i.INPUT,i.OUTPUT),this.glide.ready(r),this.glide.start(i.INPUT,e),i.start(e)}return this.envelopegenerator.start(e),this.on(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(){const t=this.context.currentTime+this.startTime+this.duration;return this.envelopegenerator.stop(t,!1),this.glide.stop(),this.filter.stop(t),this}param(t){if("string"==typeof t&&"mastervolume"===t)return this.mastervolume.gain.value;for(const[e,s]of Object.entries(t))if("mastervolume"===e)"number"==typeof s&&(this.mastervolume.gain.value=s);return this}get(t){return"number"==typeof t&&t>=0&&t<this.sources.length?this.sources[t]:this.sources}length(){return this.sources.length}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah;case"glide":return this.glide}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),oscillator:{glide:this.glide.params(),params:this.sources.map((t=>t.params()))}}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class OneshotModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class Z extends H{sources=[];resources=[];buffers=[];volumes=[];states=[];settings=[];startTime=0;duration=0;transpose=0;loadError=!1;constructor(t){super(t),this.processor=new AudioWorkletNode(t,OneshotModuleProcessor.name)}setup(t){const{resources:e,settings:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t;for(let t=0,e=s.length;t<e;t++)this.states[t]=!1,this.volumes[t]=this.context.createGain(),this.settings[t]=s[t],this.envelopegenerator.setGenerator(t);for(let t=0,s=e.length;t<s;t++){this.resources[t]=e[t];const s=this.resources[t];"string"==typeof s?this.load({url:s,index:t,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}):this.buffers[t]=s}return this}ready(t,e){return this.startTime=t??0,this.duration=e??0,this.envelopegenerator.clear(!1),this}start(t){const e=this.context.currentTime+this.startTime;this.mixed||(this.envelopegenerator.clear(!1),this.connect(this.processor));for(const s of t){if(s<0||s>=this.settings.length)continue;const{bufferIndex:t,playbackRate:i,loop:r,loopStart:n,loopEnd:a,volume:o}=this.settings[s],h=this.context.createBufferSource();h.buffer=this.buffers[t],h.playbackRate.value=i??1,h.detune.value=100*this.transpose,h.loop=r??!1,h.loopStart=n??0,h.loopEnd=a??h.buffer.duration,this.volumes[s].gain.value=o??1,this.envelopegenerator.ready(s,h,this.volumes[s]),this.volumes[s].connect(this.processor),h.loop?h.start(e,e+h.loopStart,h.loopEnd-e):h.start(e),this.sources[s]=h,this.states[s]=!0}return this.envelopegenerator.start(e),this.on(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(t){const e=this.context.currentTime+this.startTime+this.duration;return t.forEach((t=>{this.states[t]&&(this.sources[t].stop(e),this.states[t]=!1)})),this.envelopegenerator.stop(e),this.envelopegenerator.clear(!1),this.off(e),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"transpose":return this.transpose}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"transpose":"number"==typeof s&&(this.transpose=s)}return this}get(t){return"number"==typeof t&&t>=0&&t<this.buffers.length?this.buffers[t]:this.buffers}reset(t,e,s){if(t>=0&&t<this.settings.length)switch(e){case"bufferIndex":case"playbackRate":case"loopStart":case"loopEnd":case"volume":"number"==typeof s&&(this.settings[t][e]=s);break;case"loop":"boolean"==typeof s&&(this.settings[t][e]=s)}return this}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),transpose:this.transpose}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}load(t){const{url:e,index:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{!this.loadError&&n&&n(t,"timeout"),this.loadError=!0},o.onprogress=t=>{this.loadError?o.abort():a&&a(t)},o.onerror=t=>{!this.loadError&&n&&n(t,"error"),this.loadError=!0},o.onload=t=>{if(200===o.status){const e=o.response;if(!(e instanceof ArrayBuffer))return;const i=e=>{this.buffers[s]=e;for(const t of this.buffers)if(void 0===t)return;r&&r(t,this.buffers)},a=t=>{n&&n(t,"decode")};this.context.decodeAudioData(e,i,a)}},o.open("GET",e,!0),o.responseType="arraybuffer",o.send(null)}}class NoiseModuleProcessor extends AudioWorkletProcessor{processing=!1;type="whitenoise";b0=0;b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;lastOut=0;constructor(){super(),this.port.onmessage=t=>{"boolean"==typeof t.data.processing&&(this.processing=t.data.processing),t.data.type&&(this.type=t.data.type)}}process(t,e){if(!this.processing)return!0;const s=e[0];for(let t=0,e=s.length;t<e;t++){const e=s[t].length;switch(this.type){case"whitenoise":this.generateWhiteNoise(s[t],e);break;case"pinknoise":this.generatePinkNoise(s[t],e);break;case"browniannoise":this.generateBrownianNoise(s[t],e)}}return!0}generateWhiteNoise(t,e){for(let s=0;s<e;s++)t[s]=2*Math.random()-1}generatePinkNoise(t,e){for(let s=0;s<e;s++){const e=2*Math.random()-1;this.b0=.99886*this.b0+.0555179*e,this.b1=.99332*this.b1+.0750759*e,this.b2=.969*this.b2+.153852*e,this.b3=.8665*this.b3+.3104856*e,this.b4=.55*this.b4+.5329522*e,this.b5=-.7616*this.b5-.016898*e,t[s]=this.b0+this.b1+this.b2+this.b3+this.b4+this.b5+this.b6+.5362*e,t[s]*=.11,this.b6=.115926*e}}generateBrownianNoise(t,e){for(let s=0;s<e;s++){const e=2*Math.random()-1;t[s]=(this.lastOut+.02*e)/1.02,this.lastOut=(this.lastOut+.02*e)/1.02,t[s]*=3.5}}}class tt extends H{type="whitenoise";constructor(t){super(t),this.processor=new AudioWorkletNode(t,NoiseModuleProcessor.name),this.envelopegenerator.setGenerator(0)}setup(){return this}ready(){return this}start(){const t=this.context.currentTime;if(!this.mixed){const t=this.envelopegenerator.getGenerator(0);t&&this.connect(t)}this.envelopegenerator.ready(0,this.processor,null),this.envelopegenerator.start(t),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this.on(t);return this.processor.port.postMessage({processing:!0}),this}stop(){const t=this.context.currentTime;this.envelopegenerator.stop(t),this.off(t);return this.processor.port.postMessage({processing:!1}),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"type":return this.type}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"type":if("string"==typeof s&&("whitenoise"===s||"pinknoise"===s||"browniannoise"===s)){this.type=s;const t={type:s};this.processor.port.postMessage(t)}}return this}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}disconnect(){const t=this.envelopegenerator.getGenerator(0);t&&t.disconnect(0)}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),type:this.type}}get INPUT(){const t=this.envelopegenerator.getGenerator(0);return t||null}get OUTPUT(){return this.mastervolume}}class AudioModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];s.length>0&&s[0].length>0&&currentFrame%16384==0&&this.port.postMessage({});for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class et extends H{source;buffer=null;currentTime=0;stopped=!0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,AudioModuleProcessor.name),this.source=t.createBufferSource()}setup(t){const{decodeCallback:e,updateCallback:s,endedCallback:i,errorCallback:r}=t??{};return e&&(this.decodeCallback=e),s&&(this.updateCallback=s),i&&(this.endedCallback=i),r&&(this.errorCallback=r),this.envelopegenerator.setGenerator(0),this.envelopegenerator.param({attack:0,decay:.01,sustain:1,release:.01}),this}ready(t){if(t instanceof ArrayBuffer){this.buffer=null;const e=t=>{this.buffer=t,this.analyser.start("timeoverview",0,this.buffer),this.analyser.start("timeoverview",1,this.buffer),this.decodeCallback&&this.decodeCallback(this.buffer)};this.context.decodeAudioData(t,e,this.errorCallback)}else t instanceof AudioBuffer&&(this.buffer=t);return this}start(t,e){if(null===this.buffer||!this.stopped)return this;const s=this.context.currentTime,i=t??0,r=e??this.buffer.duration;this.currentTime=r>=0?i>=0&&i<=r?i:0:i>=0&&i<=this.buffer.duration?i:0;const n=this.source.playbackRate.value,a=this.source.detune.value,o=this.source.loop;this.source=this.context.createBufferSource(),this.source.buffer=this.buffer,this.source.playbackRate.value=n,this.source.detune.value=a,this.source.loop=o,this.source.loopStart=this.currentTime,this.source.loopEnd=r>=0?r:this.buffer.duration,this.envelopegenerator.ready(0,this.source,this.processor),this.connect(this.processor);const h=this.computePlaybackRate();r>=0?this.source.start(s,this.currentTime,r-i):this.source.start(s,this.currentTime,this.buffer.duration-this.currentTime),this.analyser.start("time"),this.analyser.start("fft"),this.stopped=!1,this.envelopegenerator.start(s),r>=0?this.envelopegenerator.stop(s+(r-i)/h,!0):this.envelopegenerator.stop(s+(this.buffer.duration-i)/h,!0),this.on(s);const c=this.analyser.domain("timeoverview",0),u=this.analyser.domain("timeoverview",1);return this.processor.port.onmessage=()=>{if(null!==this.buffer)if(Math.abs(this.source.loopEnd-this.currentTime)>.5){const t=this.computePlaybackRate();this.currentTime+=16384/this.buffer.sampleRate*t,this.updateCallback&&this.updateCallback(this.source,this.currentTime),c.update(this.currentTime),u.update(this.currentTime)}else this.source.loop?(this.stop(),"sprite"===c.param("mode")?this.start(this.source.loopStart,this.source.loopEnd):this.start(0,this.buffer.duration)):this.end();else this.end()},this}stop(){if(null===this.buffer||this.stopped)return this;const t=this.context.currentTime;return this.source.stop(t),this.off(t),this.analyser.stop("time"),this.analyser.stop("fft"),this.stopped=!0,this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"playbackRate":return this.source.playbackRate.value;case"detune":return this.source.detune.value;case"loop":return this.source.loop;case"currentTime":return this.currentTime;case"duration":return this.source.buffer?.duration??0;case"sampleRate":return this.source.buffer?.sampleRate??this.context.sampleRate;case"numberOfChannels":return this.source.buffer?.numberOfChannels??0}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"playbackRate":if("number"==typeof s&&s>0){this.source.playbackRate.value=s;const t=this.computePlaybackRate(),e=this.context.currentTime,i=this.currentTime,r=this.source.buffer?.duration??0;this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(r-i)/t,!0)}break;case"detune":if("number"==typeof s){this.source.detune.value=s;const t=this.computePlaybackRate(),e=this.context.currentTime,i=this.currentTime,r=this.source.buffer?.duration??0;this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(r-i)/t,!0)}break;case"loop":"boolean"==typeof s&&(this.source.loop=s);break;case"currentTime":"number"==typeof s&&(this.currentTime=s,this.stopped||(this.stop(),this.start(s)))}return this}get(){return this.source}end(){return this.stop(),this.currentTime=0,this.endedCallback&&this.endedCallback(this.source,0),this}has(){return null!==this.buffer}paused(){return this.stopped}fadeIn(t){if("number"!=typeof t)return this.envelopegenerator.param("attack");this.envelopegenerator.param({attack:t});const e=this.context.currentTime,s=this.currentTime,i=this.source.buffer?.duration??0,r=this.computePlaybackRate();return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}fadeOut(t){if("number"!=typeof t)return this.envelopegenerator.param("release");this.envelopegenerator.param({release:t});const e=this.context.currentTime,s=this.currentTime,i=this.source.buffer?.duration??0,r=this.computePlaybackRate();return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}slice(t,e){if(null===this.buffer)return null;const s=this.buffer.duration,i=this.buffer.sampleRate,r=this.buffer.numberOfChannels,n=Math.trunc((t??0)*i),a=Math.trunc((e??s)*i),o=r>0?this.buffer.getChannelData(0):null,h=r>1?this.buffer.getChannelData(1):null,c=a-n;switch(r){case 1:{if(null===o)return null;const t=new Float32Array(c);for(let e=n;e<a;e++)t[e-n]=o[e];const e=this.context.createBuffer(1,c,i);return e.copyToChannel(t,0),e}case 2:{if(null===o||null===h)return null;const t=new Float32Array(c),e=new Float32Array(c);for(let s=n;s<a;s++)t[s-n]=o[s],e[s-n]=h[s];const s=this.context.createBuffer(2,c,i);return s.copyToChannel(t,0),s.copyToChannel(e,1),s}}return null}sprite(t){return null===this.buffer?null:Object.keys(t).reduce(((e,s)=>{const i=t[s],r=this.slice(...i);return null!==r&&(e[s]=r),e}),{})}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),playbackRate:this.source.playbackRate.value,detune:this.source.detune.value,loop:this.source.loop,currentTime:this.currentTime,duration:this.buffer?.duration??0,sampleRate:this.buffer?.sampleRate??this.context.sampleRate,numberOfChannels:this.buffer?.numberOfChannels??0,vocalcanceler:this.vocalcanceler.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}computePlaybackRate(){return this.source.playbackRate.value*2**(this.source.detune.value/1200)}}class MediaModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class st extends H{source=null;media=null;ext="";autoplay=!1;mediaSource=null;sourceBuffer=null;file="";mimeType="";listeners={};constructor(t){super(t),this.processor=new AudioWorkletNode(t,MediaModuleProcessor.name),this.onSourceOpen=this.onSourceOpen.bind(this),this.onSourceEnded=this.onSourceEnded.bind(this),this.onSourceClose=this.onSourceClose.bind(this),this.onSourceBufferUpdateEnd=this.onSourceBufferUpdateEnd.bind(this),this.onSourceBufferError=this.onSourceBufferError.bind(this)}setup(t){this.envelopegenerator.setGenerator(0),this.envelopegenerator.param({attack:0,decay:.01,sustain:1,release:.01});const{media:e,formats:s,listeners:i,autoplay:r}=t;if(!e)return this;this.media=e;for(const t of s??[]){const e=`audio/${t}`,s=`video/${t}`,i=this.media.canPlayType(e),r=this.media.canPlayType(s);if(/^(?:maybe|probably)/.test(i)||/^(?:maybe|probably)/.test(r)){this.ext=t;break}}return i&&(this.listeners=i,Object.keys(i).forEach((t=>{const e=i[t];"function"==typeof e&&(i[t]=e),this.media&&this.media.addEventListener(t,e,!1)}))),this.media.addEventListener("loadstart",(()=>{null!==this.media&&(null!==this.source&&this.media===e||(this.source=this.context.createMediaElementSource(this.media)))}),!1),this.media.addEventListener("ended",(()=>{null!==this.media&&(this.media.pause(),this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"))}),!1),this.autoplay=r??!1,this.autoplay&&null===this.source&&(this.source=this.context.createMediaElementSource(this.media)),this.autoplay&&this.media.src&&this.context.resume().then((()=>{this.start(this.media?.currentTime??0)})).catch((t=>{this.listeners.error&&this.listeners.error(t)})),this}ready(t,e){if(null===this.media)return this;if(this.mediaSource&&"open"===this.mediaSource.readyState&&(this.mediaSource.endOfStream(),window.URL.revokeObjectURL(this.media.src),this.mediaSource.removeEventListener("sourceopen",this.onSourceOpen,!1),this.mediaSource.removeEventListener("sourceended",this.onSourceEnded,!1),this.mediaSource.removeEventListener("sourceclose",this.onSourceClose,!1),this.sourceBuffer&&(this.sourceBuffer.removeEventListener("updateend",this.onSourceBufferUpdateEnd,!1),this.sourceBuffer.removeEventListener("error",this.onSourceBufferError,!1))),e){if(!MediaSource||!MediaSource.isTypeSupported(e))return this;this.media.removeAttribute("src"),this.media.load(),this.mediaSource=new MediaSource,this.media.src=window.URL.createObjectURL(this.mediaSource),this.mimeType=e,this.file=t,this.mediaSource.addEventListener("sourceopen",this.onSourceOpen,!1),this.mediaSource.addEventListener("sourceended",this.onSourceEnded,!1),this.mediaSource.addEventListener("sourceclose",this.onSourceClose,!1)}else t.startsWith("blob:")||""===this.ext?this.media.src=t:this.media.src=`${t}.${this.ext}`;return this}start(t,e){return null===this.source||null===this.media||(this.envelopegenerator.ready(0,this.source,this.processor),this.connect(this.processor),this.media.play().then((()=>{if(null===this.media)return;const e=this.context.currentTime;this.media.currentTime=t??0,this.envelopegenerator.start(e),Number.isFinite(this.media.duration)&&this.envelopegenerator.stop(e+(this.media.duration-this.media.currentTime)/this.media.playbackRate,!0),this.on(e),this.analyser.start("time"),this.analyser.start("fft")})).catch((()=>{this.stop((()=>{null!==this.media&&(this.autoplay&&(this.media.muted=!0,this.media.volume=0),this.start(t))}),e)}))),this}stop(t,e){return null===this.source||null===this.media||this.media.play().then((()=>{null!==this.media&&(this.media.pause(),this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"),t&&t())})).catch((t=>{e&&e(t)})),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"autoplay":return this.autoplay;case"playbackRate":return this.media?.playbackRate??1;case"currentTime":return this.media?.currentTime??0;case"controls":return this.media?.controls??!1;case"loop":return this.media?.loop??!1;case"muted":return this.media?.muted??!1;case"duration":return Number.isNaN(this.media?.duration)?0:this.media?.duration??0}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"playbackRate":if(this.media&&"number"==typeof s&&s>0){this.media.playbackRate=s;const t=this.context.currentTime,e=this.media.currentTime,i=this.media.duration;this.envelopegenerator.start(t),Number.isFinite(i)&&this.envelopegenerator.stop(t+(i-e)/s,!0)}break;case"currentTime":if(this.media&&"number"==typeof s){this.media.currentTime=s;const t=this.context.currentTime,e=this.media.duration,i=this.media.playbackRate;this.envelopegenerator.start(t),Number.isFinite(e)&&this.envelopegenerator.stop(t+(e-s)/i,!0)}break;case"controls":this.media&&"boolean"==typeof s&&(this.media.controls=s);break;case"loop":this.media&&"boolean"==typeof s&&(this.media.loop=s);break;case"muted":this.media&&"boolean"==typeof s&&(this.media.muted=s)}return this}get(){return this.source}hasMedia(){return null!==this.media}hasSource(){return null!==this.source}paused(){return null===this.media||this.media.paused}fadeIn(t){if("number"!=typeof t)return this.envelopegenerator.param("attack");this.envelopegenerator.param({attack:t});const e=this.context.currentTime,s=this.media?.currentTime??0,i=this.media?.duration??0,r=this.media?.playbackRate??1;return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}fadeOut(t){if("number"!=typeof t)return this.envelopegenerator.param("release");this.envelopegenerator.param({release:t});const e=this.context.currentTime,s=this.media?.currentTime??0,i=this.media?.duration??0,r=this.media?.playbackRate??1;return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}requestPictureInPicture(){return this.media instanceof HTMLVideoElement&&"pictureInPictureEnabled"in document&&document.pictureInPictureEnabled?this.media.disablePictureInPicture||0===this.media.readyState||this.media===document.pictureInPictureElement?Promise.reject():this.media.requestPictureInPicture():Promise.reject()}exitPictureInPicture(){return this.media instanceof HTMLVideoElement&&"pictureInPictureEnabled"in document&&document.pictureInPictureEnabled?this.media.disablePictureInPicture||0===this.media.readyState||this.media!==document.pictureInPictureElement?Promise.reject():document.exitPictureInPicture():Promise.reject()}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),autoplay:this.autoplay,playbackRate:this.media?.playbackRate??1,controls:this.media?.controls??!1,loop:this.media?.loop??!1,muted:this.media?.muted??!1,currentTime:this.media?.currentTime??0,duration:Number.isNaN(this.media?.duration??0)?0:this.media?.duration??0,vocalcanceler:this.vocalcanceler.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}onSourceOpen(t){if(null===this.mediaSource)return;this.sourceBuffer=this.mediaSource.addSourceBuffer(this.mimeType),this.sourceBuffer.mode="sequence",this.sourceBuffer.addEventListener("updateend",this.onSourceBufferUpdateEnd,!1),this.sourceBuffer.addEventListener("error",this.onSourceBufferError,!1);const e=new Request(this.file);fetch(e).then((t=>t.arrayBuffer())).then((t=>{this.sourceBuffer&&this.sourceBuffer.appendBuffer(t)})).catch((t=>{this.listeners.error&&this.listeners.error(t)})).finally((()=>{this.listeners.sourceopen&&this.listeners.sourceopen(t)}))}onSourceEnded(t){this.listeners.sourceended&&this.listeners.sourceended(t)}onSourceClose(t){this.listeners.sourceclose&&this.listeners.sourceclose(t)}onSourceBufferUpdateEnd(t){this.listeners.updateend&&this.listeners.updateend(t)}onSourceBufferError(t){this.listeners.error&&this.listeners.error(t)}}class StreamModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class it extends H{sources=[];stream=null;constraints={audio:!0,video:!1};output=!0;track=!1;paused=!0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,StreamModuleProcessor.name)}setup(t){return t&&(this.constraints={...this.constraints,...t}),this}ready(t){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&window.MediaStream?(this.paused=!1,t?.stream?(this.stream=t.stream,Promise.resolve(this.stream)):navigator.mediaDevices.getUserMedia(this.constraints).then((e=>(this.paused||(this.stream=e,t?.successCallback&&t.successCallback(e)),e))).catch((e=>(t?.errorCallback&&t.errorCallback(e),e)))):Promise.reject()}start(){if(null===this.stream)return this;if(this.track){const t=this.stream.getAudioTracks();for(let e=0,s=t.length;e<s;e++)this.sources[e]=this.context.createMediaStreamTrackSource(t[e]),this.sources[e].connect(this.processor),this.connect(this.processor)}else this.sources[0]=this.context.createMediaStreamSource(this.stream),this.sources[0].connect(this.processor),this.connect(this.processor);return this.output||(this.mastervolume.disconnect(0),this.mastervolume.connect(this.analyser.INPUT),this.mastervolume.connect(this.recorder.INPUT),this.recorder.OUTPUT.connect(this.context.destination)),this.on(this.context.currentTime),this.analyser.start("time"),this.analyser.start("fft"),this}stop(){return this.sources.length=0,this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"),this.paused=!0,this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"output":return this.output;case"track":return this.track}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"output":"boolean"==typeof s&&(this.output=s);break;case"track":"boolean"==typeof s&&(this.track=s)}return this}get(t){return"number"==typeof t&&t>=0&&t<this.sources.length?this.sources[t]:this.sources}getStream(){return this.stream}clear(){return this.stop(),this.clearAudioDevices(),this.clearVideoDevices(),this.stream=null,this}clearAudioDevices(){if(null===this.stream)return this;this.stop();const t=this.stream.getAudioTracks();for(const e of t)e.stop();return this}clearVideoDevices(){if(null===this.stream)return this;this.stop();const t=this.stream.getVideoTracks();for(const e of t)e.stop();return this.stream=null,this}devices(){return navigator.mediaDevices&&navigator.mediaDevices.enumerateDevices?navigator.mediaDevices.enumerateDevices():Promise.reject()}streaming(){return!this.paused}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),output:this.output,track:this.track,noisegate:this.noisegate.params(),noisesuppressor:this.noisesuppressor.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class rt extends H{processorName="";options={};moduleURL="";constructor(t){super(t),this.envelopegenerator.setGenerator(0)}setup(t,e){return this.processorName=t,this.options=e??{},this}ready(t,e){return this.moduleURL=t,this.context.audioWorklet.addModule(this.moduleURL,e??{credentials:"same-origin"}).then((()=>{this.processor=new AudioWorkletNode(this.context,this.processorName,this.options)}))}start(){const t=this.envelopegenerator.getGenerator(0);if(null===t)return this;const e=this.context.currentTime;return this.mixed||(this.envelopegenerator.clear(!0),this.processor.disconnect(0),this.connect(t)),this.envelopegenerator.ready(0,this.processor,null),this.envelopegenerator.start(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this.on(e),this}stop(){const t=this.context.currentTime;return this.envelopegenerator.stop(t),this.off(t),this}postMessage(t){return this.processor.port.postMessage(t),this}onMessage(t){return this.processor.port.onmessage=t,this}onMessageError(t){return this.processor.port.onmessageerror=t,this}map(){return this.processor.parameters}get(){return this.processor}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){super.suspend();const t=this.envelopegenerator.getGenerator(0);return this.processor&&t&&(t.disconnect(0),this.processor.connect(t)),this}mix(){return super.mix(),this}demix(){return super.demix(),this}get INPUT(){const t=this.envelopegenerator.getGenerator(0);return t||null}get OUTPUT(){return this.mastervolume}}class MixerModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class nt extends H{sources=[];gainNodes=[];constructor(t){super(t),this.processor=new AudioWorkletNode(t,MixerModuleProcessor.name)}setup(){return this}ready(){return this}start(t,e){this.sources=t;for(let t=0,s=this.sources.length;t<s;t++){const s=this.sources[t],i=this.context.currentTime;s.off(i),s.suspend(),s.mix(),s.INPUT&&(this.gainNodes[t]=this.context.createGain(),this.gainNodes[t].gain.value=e?e[t]:1,s.disconnect(),s.INPUT.connect(this.gainNodes[t]),this.gainNodes[t].connect(this.processor))}this.connect(this.processor);const s=this.context.currentTime;return this.on(s),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(){const t=this.context.currentTime;this.off(t),this.suspend();for(const t of this.sources)t.demix(),t.INPUT&&(t.disconnect(),t.connect(t.INPUT));for(const t of this.gainNodes)t.disconnect(0);return this}param(t){if("string"==typeof t&&"mastervolume"===t)return this.mastervolume.gain.value;for(const[e,s]of Object.entries(t))if("mastervolume"===e)"number"==typeof s&&(this.mastervolume.gain.value=s);return this}get(){return this.sources}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class at{midiAccess=null;inputs=[];outputs=[];constructor(){}setup(t){if(!navigator.requestMIDIAccess)return Promise.reject();const{options:e,successCallback:s,errorCallback:i}=t;return navigator.requestMIDIAccess(e).then((t=>{this.midiAccess=t,t.inputs.forEach((t=>{this.inputs.push(t)})),t.outputs.forEach((t=>{this.outputs.push(t)})),s&&s(this.midiAccess,this.inputs,this.outputs)})).catch((t=>{i&&i(t)}))}get(){return this.midiAccess}}function ot(t){return t.replace(/^.+?\{/s,"").replace(/\};?$/s,"")}function ht(t){return window.URL.createObjectURL(function(t){return new Blob([ot(t)],{type:"text/javascript"})}(t))}const ct=new Map([["T","TEMPO"],["O","OCTAVE"],["C","NOTE"],["D","NOTE"],["E","NOTE"],["F","NOTE"],["G","NOTE"],["A","NOTE"],["B","NOTE"],["+","NOTE"],["-","NOTE"],["#","NOTE"],["R","REST"],["0","NUMBER"],["1","NUMBER"],["2","NUMBER"],["3","NUMBER"],["4","NUMBER"],["5","NUMBER"],["6","NUMBER"],["7","NUMBER"],["8","NUMBER"],["9","NUMBER"],[".","NUMBER"],["&","TIE"],[" ","SPACE"],[void 0,"EOS"]]);class ut{_id;_type;_token;_value;constructor(t,e,s){this._id=t,this._type=e,this._token=s,this._value=s?Number(s):-1}get type(){return this._type}get token(){return this._token}get value(){return Number.isNaN(this._value)?-1:this._value}toString(){return JSON.stringify({id:this._id,type:this._type,token:this._token,value:this._value})}}class lt{static id=0;tokens=[];notes=[];numbers=[];constructor(t){this.tokens=t.trim().toUpperCase().split("").reverse()}get(){let t=this.tokens.pop(),e=ct.get(t);if(lt.id++,!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"SPACE"===e;)if(t=this.tokens.pop(),e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);if("EOS"===e)return new ut(lt.id.toString(10),"EOS",t);switch(this.notes.length=0,this.numbers.length=0,e){case"TEMPO":if(t)return new ut(lt.id.toString(10),"TEMPO",t);break;case"OCTAVE":if(t)return new ut(lt.id.toString(10),"OCTAVE",t);break;case"NOTE":if(t){if(this.notes.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NOTE",this.notes.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"NOTE"===e;){if(this.notes.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NOTE",this.notes.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t)}return this.tokens.push(t),new ut(lt.id.toString(10),"NOTE",this.notes.join(""))}break;case"REST":if(t)return new ut(lt.id.toString(10),"REST",t);break;case"NUMBER":if(t){if(this.numbers.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"NUMBER"===e;){if(this.numbers.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t)}return this.tokens.push(t),new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""))}break;case"TIE":if(t)return new ut(lt.id.toString(10),"TIE",t)}return null}}class pt{static indent=0;_id;_operator;_left;_right;constructor(t,e,s,i){this._id=t,this._operator=e,this._left=s,this._right=i}concat(t){this._right=t}get operator(){return this._operator}get left(){return this._left}get right(){return this._right}clear(){pt.indent=0}toString(){let t="";for(let e=0;e<pt.indent;e++)t+=" ";return pt.indent++,`\n${t} ${this._operator.token} (id = ${this._id})\n${t} /\\\n${t}${this._left?.operator.token??""}${null!==this._right&&void 0!==this._right._operator.token?this.toString.call(this._right):"EOS"}\n`}}class dt{_token;constructor(t){this._token=t}get token(){return this._token}}class ft{static id=0;tokenizer;syntaxTree=[];constructor(t){this.tokenizer=t}parse(){lt.id=0;let t=this.tokenizer.get(),e=this.tokenizer.get();for(;;){if(!t||!e)return this.syntaxTree;switch(ft.id+=2,t.type){case"TEMPO":if("NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree.push(i);break}return new dt(t);case"OCTAVE":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"NOTE":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"REST":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"NUMBER":ft.id-=2;break;case"TIE":if(this.syntaxTree.length>0){ft.id--;const e=new pt((ft.id-0).toString(10),t,null,null);this.syntaxTree[this.syntaxTree.length-1].concat(e),this.syntaxTree.push(e);break}return new dt(t);case"EOS":if(this.syntaxTree.length>0){const e=new pt((ft.id-1).toString(10),t,null,null);this.syntaxTree[this.syntaxTree.length-1].concat(e),this.syntaxTree.push(e)}else{const e=new pt((ft.id-1).toString(10),t,null,null);this.syntaxTree.push(e)}return this.syntaxTree}t=e,e=this.tokenizer.get()}}free(){this.syntaxTree.length=0}}const mt=1.0594630943592953,vt=27.5;function gt(t){switch(t.toUpperCase()){case"C":case"D":case"E":case"F":case"G":case"A":case"B":case"R":return!0;default:return!1}}function bt(t,e){let s=0;switch(e){case"C":s=3;break;case"D":s=5;break;case"E":s=7;break;case"F":s=8;break;case"G":s=10;break;case"A":s=12;break;case"B":s=14;break;case"R":return-1}const i=12*(t-1)+s;return i>=0?i:-1}function yt(t){return t>=0?vt*mt**t:0}function kt(t){const{file:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t,a=new FileReader;switch(a.onprogress=t=>{n&&n(t)},a.onerror=t=>{if(!r)return;let e;switch(a.error?.code){case a.error?.NOT_FOUND_ERR:e="NOT_FOUND_ERR";break;case a.error?.SECURITY_ERR:e="SECURITY_ERR";break;case a.error?.ABORT_ERR:e="ABORT_ERR";break;case a.error?.NOT_SUPPORTED_ERR:e="NOT_READABLE_ERR";break;default:e="ERR"}r(t,e)},a.onload=t=>{if(!i)return;let e=a.result;switch(s){case"text":"string"==typeof e&&(e=e.replace(/<(\/?script.*?)>/gi,"&lt;$1&gt;"));break;case"json":"string"==typeof e&&(e=JSON.parse(e.replace(/<(\/?script.*?)>/gi,"&lt;$1&gt;")))}i(t,e)},s){case"arraybuffer":a.readAsArrayBuffer(e);break;case"dataURL":a.readAsDataURL(e);break;case"text":case"json":a.readAsText(e,"UTF-8")}}class wt{_id;_note;_indexes;_frequencies;_start;_stop;_duration;constructor(t){const{id:e,note:s,indexes:i,frequencies:r,start:n,stop:a,duration:o}=t;this._id=e,this._note=s,this._indexes=i,this._frequencies=r,this._start=n,this._stop=a,this._duration=o}concat(t){return new wt({id:this._id,note:`${this._note}&${t.note}`,indexes:this._indexes,frequencies:this._frequencies,start:this._start,duration:this._duration+t.duration,stop:this._start+(this._duration+t.duration)})}get note(){return this._note}get indexes(){return this._indexes}get frequencies(){return this._frequencies}get start(){return this._start}get stop(){return this._stop}get duration(){return this._duration}toString(){return JSON.stringify({id:this._id,note:this._note,indexes:this._indexes,frequencies:this._frequencies,start:this._start,stop:this._stop,duration:this._duration})}}class At{sequences=[];treeConstructor;syntaxTree="";timeOf4note=0;octave=-1;currentTime=0;errorCallback;constructor(t,e){this.treeConstructor=t,this.errorCallback=e||(t=>{throw t})}get(){ft.id=0;const t=this.treeConstructor.parse();if(!t)return void this.errorCallback(new dt(new ut("1","UNKNOWN","")));if(t instanceof dt)return void this.errorCallback(t);this.timeOf4note=0,this.octave=-1,this.currentTime=0;let e=t[0];for(;null!==e;){if(!e)return void this.errorCallback(new dt(new ut((this.sequences.length+1).toString(10),"UNKNOWN","")));if(e instanceof dt)return void this.errorCallback(e);const t=e.operator,s=t.type,i=e.left,r=null!==i?i.operator.value:-1;switch(s){case"TEMPO":if(r<=0)return void this.errorCallback(new dt(t));this.timeOf4note=60/r,e=e.right;break;case"OCTAVE":if(r<0)return void this.errorCallback(new dt(t));this.octave=r,e=e.right;break;case"NOTE":case"REST":case"TIE":{const t=this.push("TIE"===s?e.right:e);if(t instanceof dt)return void this.errorCallback(t);"TIE"===s?(this.concat(),e=e.right?.right??null):e=e.right;break}case"EOS":e=e.right}}return this.syntaxTree=t[0].toString(),this.treeConstructor.free(),this.sequences}getSyntaxTree(){return this.syntaxTree}push(t){if(null===t)return;const e=t.left,s=t.right;if(null===e||null===s)return;const i=e.operator,r=s.operator;if(null===i&&null===r)return this.push(e),void this.push(s);const n=t.operator.token,a=i.value,o=i.token,h=[],c=[];if(!n)return;for(let t=0,e=n.length;t<e;t++){const e=n.charAt(t);if(!gt(e))continue;let s=bt(this.octave,e);switch(n.charAt(t+1)){case"+":case"#":s++,t++;break;case"-":s--,t++}if(s>=h[0]&&(s-=12),-1!==s&&s<0)return;h.push(s)}for(const t of h){const e=yt(t);if(e<0)return;c.push(e)}let u=0;switch(a){case 1:case 2:case 4:case 8:case 16:case 32:case 64:case 128:case 256:if(o){const t=4/a;o.includes(".")?u+=t*this.timeOf4note*1.5:u+=t*this.timeOf4note}break;case 6:u+=2*this.timeOf4note/3;break;case 12:u+=this.timeOf4note/3;break;case 18:u+=2*this.timeOf4note/9;break;case 24:u+=.5*this.timeOf4note/3;break;case 36:u+=this.timeOf4note/9;break;case 48:u+=.25*this.timeOf4note/3;break;case 72:u+=.5*this.timeOf4note/9;break;case 96:u+=.125*this.timeOf4note/3;break;case 144:u+=.25*this.timeOf4note/9;break;case 192:u+=.0625*this.timeOf4note/3;break;default:return void this.errorCallback(new dt(i))}const l=(this.sequences.length+1).toString(10),p=`${n}${o}`,d=this.currentTime,f=d+u;this.sequences.push(new wt({id:l,note:p,indexes:h,frequencies:c,start:d,stop:f,duration:u})),this.currentTime+=u}concat(){const t=this.sequences.pop(),e=this.sequences.pop();e&&t&&this.sequences.push(e.concat(t))}}const xt=()=>{let t=null;self.onmessage=e=>{switch(e.data.type){case"schedule":"number"==typeof e.data.duration&&(t=self.setTimeout((()=>{self.postMessage({type:"next"})}),1e3*e.data.duration));break;case"next":break;case"stop":null!==t&&(self.clearTimeout(t),self.close(),t=null)}}};class Tt{sequences=[];source;mml;syntaxTree;previous=null;scheduleWorker=null;currentIndex=0;currentPosition=0;offset=0;constructor(t){const{source:e,mml:s,offset:i,startCallback:r,stopCallback:n,endedCallback:a,errorCallback:o}=t;this.source=e,this.mml=s,this.offset=i??0,r&&(this.startCallback=r),n&&(this.stopCallback=n),a&&(this.endedCallback=a),o&&(this.errorCallback=o);const h=new lt(s),c=new ft(h),u=new At(c,this.errorCallback),l=u.get();l&&(this.sequences=l),this.syntaxTree=u.getSyntaxTree();const p=ht(xt.toString());this.scheduleWorker=new Worker(p),window.URL.revokeObjectURL(p)}start(t){if(null===this.scheduleWorker)return;if(!this.sequences[this.currentIndex])return this.stop(),void(this.endedCallback&&this.endedCallback());const e=this.sequences[this.currentIndex++];if(t){const t=this.mml.slice(0,this.currentPosition),s=this.mml.slice(this.currentPosition).replace(e.note,`<span class="x-highlight">${e.note}</span>`);this.mml=`${t}${s}`,this.currentPosition+=this.mml.slice(this.currentPosition).indexOf("</span>")+7}else{const t=this.mml.slice(0,this.currentPosition),s=e.note;this.mml=`${t}${s}`,this.currentPosition+=s.length}if(this.source instanceof K)this.source.ready(0,e.duration).start(e.frequencies),this.startCallback&&this.startCallback(e);else if(this.source instanceof Z){const t=e.indexes.filter((t=>-1!==t)).map((t=>t+this.offset));this.source.ready(0,e.duration).start(t),this.startCallback&&this.startCallback(e,this.offset)}else this.source instanceof tt&&(this.source.start(),this.startCallback&&this.startCallback(e));const s={type:"schedule",duration:e.duration};this.scheduleWorker.postMessage(s),this.scheduleWorker.onmessage=s=>{"next"===s.data.type&&(this.source instanceof K?this.stopCallback&&this.stopCallback(e):this.source instanceof Z?this.stopCallback&&this.stopCallback(e,this.offset):this.source instanceof tt&&(this.source.stop(),this.stopCallback&&this.stopCallback(e)),this.previous=e,this.start(t))}}stop(){if(null===this.scheduleWorker)return;if(null===this.previous)return;if(this.source instanceof K)this.source.stop(),this.stopCallback&&this.stopCallback(this.previous);else if(this.source instanceof Z){const t=this.previous.indexes.filter((t=>-1!==t)).map((t=>t+this.offset));this.source.stop(t),this.stopCallback&&this.stopCallback(this.previous,this.offset)}else this.source instanceof tt&&(this.source.stop(),this.stopCallback&&this.stopCallback(this.previous));this.scheduleWorker.postMessage({type:"stop"}),this.scheduleWorker.terminate(),this.scheduleWorker=null}getMML(){return this.mml}getSequences(){return this.sequences}getSyntaxTree(){return this.syntaxTree}has(){return this.sequences.length>0}paused(){return null===this.scheduleWorker}getCurrentIndex(){return this.currentIndex}setCurrentIndex(t){t>=0&&t<this.sequences.length&&(this.currentIndex=t)}}class St{parts=[];constructor(){}setup(t){return t?.startCallback&&(this.startCallback=t.startCallback),t?.stopCallback&&(this.stopCallback=t.stopCallback),t?.endedCallback&&(this.endedCallback=t.endedCallback),t?.errorCallback&&(this.errorCallback=t.errorCallback),this}ready(t){const{source:e,mmls:s,offset:i}=t;this.stop(),this.clear();const r=this.startCallback,n=this.stopCallback,a=this.endedCallback,o=this.errorCallback;for(const t of s)this.parts.push(new Tt({source:e,mml:t,offset:i,startCallback:r,stopCallback:n,endedCallback:a,errorCallback:o}));return this}start(t,e){if(t>=0&&t<this.parts.length){this.parts[t].start(e??!1)}return this}stop(){for(const t of this.parts)t.stop();return this}getMML(t){return t>=0&&t<this.parts.length?this.parts[t].getMML():""}getMMLs(){return this.parts.map((t=>t.getMML()))}has(){return this.parts.length>0&&this.parts.every((t=>t.has()))}getSequences(t){return t>=0&&t<this.parts.length?this.parts[t].getSequences():[]}getAllSequences(){return this.parts.map((t=>t.getSequences()))}getSyntaxTree(t){return t>=0&&t<this.parts.length?this.parts[t].getSyntaxTree():""}paused(){return 0===this.parts.length||this.parts.every((t=>t.paused()))}currentIndex(t,e){return t<0||t>=this.parts.length?this:e?(this.parts[t].setCurrentIndex(e),this):this.parts[t].getCurrentIndex()}clear(){for(const t of this.parts)t.stop();return this.parts.length=0,this}toABC(t,e,s,i,r,n){let a="";a+=`X:${e||1}\n`,a+=`T:${s||""}\n`,a+=`M:${i||"4/4"}\n`,a+=`L:${r||"1/256"}\n`,a+=`K:${n||""}\n`;const o=t.match(/\s*(?:T\d+)\s*|\s*(?:O\d+)\s*|\s*(?:(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)(?:&(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)*\s*/gi);if(null===o)return a;let h=null,c=0;for(;o.length>0;){const t=o.shift()?.trim();if(!t)return a;if(/T\d+/i.test(t)){const e=Number(t.slice(1));if(e<=0)return a;a+=`Q:1/4=${e}\n`}else if(/O\d+/i.test(t)){if(h=Number(t.slice(1)),h<0)return a}else if(/(?:(?:[CDEFGABR][#+-]?)+)(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)(?:&(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)*/i.test(t)){if(null===h)return a;let e=null;e=t.includes("&")?t.split("&"):[t];let s="";for(;e.length>0;){const t=e.shift();if(!t)return a;let i="",r=0;switch(Number(t.replace(/^.+?(\d+)\.*$/,"$1"))){case 1:i=t.replace("1","256");break;case 2:i=t.replace("2","128");break;case 4:i=t.replace("4","64");break;case 8:i=t.replace("8","32");break;case 16:i=t.replace("16","16");break;case 32:i=t.replace("32","8");break;case 64:i=t.replace("64","4");break;case 128:i=t.replace("128","2");break;case 256:i=t.replace("256","1");break;case 6:i=`(3${t.replace("6","128")}`,r=128/3;break;case 12:i=`(3${t.replace("12","64")}`,r=64/3;break;case 18:i=`(9${t.replace("18","128")}`,r=128/9;break;case 24:i=`(3${t.replace("24","32")}`,r=32/3;break;case 36:i=`(9${t.replace("36","64")}`,r=64/9;break;case 48:i=`(3${t.replace("48","16")}`,r=16/3;break;case 72:i=`(9${t.replace("72","32")}`,r=32/9;break;case 96:i=`(3${t.replace("96","8")}`,r=8/3;break;case 144:i=`(9${t.replace("144","16")}`,r=16/9;break;case 192:i=`(3${t.replace("192","4")}`,r=4/3;break;default:return a}if(i.includes(".")&&(i=i.replace(/^(.+?)\d+\.+$/,"$1"+1.5*Number(i.replace(/^.+?(\d+)\.+$/,"$1")))),i.includes("(")?c+=Number(i.replace(/^.+?(\d+)\.*$/i,"$1")):c+=r,c>=256&&(i+=" | ",c=0),/R/i.test(i)){a+=`${i} `;continue}let n="";switch(h){case 0:n=",,,,";break;case 1:n=",,,";break;case 2:n=",,";break;case 3:n=",";break;case 5:n="'";break;case 6:n="''";break;case 7:n="'''"}const o=i.match(/^(\(\d+)?((?:[CDEFGAB][#+-]?)+)(.*)$/i);if(null===o)return a;const u=o[1]?o[1]:"",l=o[2].length,p=o[3]?o[3]:"";let d=0;if(u.length>0&&(i=i.replace(/^(?:\(\d+)?((?:[CDEFGAB][#+-]?)+)(.*)$/i,"$1$2")),1===l)s+=`${u}${i.slice(0,1)}${n}${p}`;else if(2===l&&/[#+-]/.test(i.charAt(1)))s+=`${u}${i.slice(1,2)}${i.slice(0,1)}${n}${p}`;else for(;d<l;)0===d&&(s+=`${u}[`),/[#+-]/.test(i.charAt(d+1))?(s+=`${i.slice(d+1,d+2)}${i.slice(d,d+1)}${n}`,d+=2):(s+=`${i.slice(d,d+1)}${n}`,d++),d===l&&(s+=`]${p}`);e.length>0?s+="&":a+=`${s} `}}}return a.replace(/R/gi,"z").replace(/[#+]/g,"^").replace(/-/g,"_").replace(/&/g,"-").replace(/\s{2}/g," ").trim()}}window.AudioContext=window.AudioContext||window.webkitAudioContext,window.URL=window.URL||window.webkitURL;const Et=new AudioContext,Mt={oscillator:null,oneshot:null,noise:null,audio:null,media:null,stream:null,processor:null,mixer:null,midi:null,mml:null},Ft=Promise.all([s(Et,SoundModuleProcessor),s(Et,RecorderProcessor),s(Et,OscillatorModuleProcessor),s(Et,OneshotModuleProcessor),s(Et,NoiseModuleProcessor),s(Et,AudioModuleProcessor),s(Et,MediaModuleProcessor),s(Et,StreamModuleProcessor),s(Et,MixerModuleProcessor),s(Et,NoiseGateProcessor),s(Et,NoiseSuppressorProcessor),s(Et,PitchShifterProcessor),s(Et,StereoProcessor),s(Et,VocalCancelerProcessor)]).then((()=>(Mt.oscillator=new K(Et),Mt.oneshot=new Z(Et),Mt.noise=new tt(Et),Mt.audio=new et(Et),Mt.media=new st(Et),Mt.stream=new it(Et),Mt.processor=new rt(Et),Mt.mixer=new nt(Et),Mt.midi=new at,Mt.mml=new St,Mt))).catch((t=>t));function Nt(t){switch(t){case"oscillator":return Mt.oscillator;case"oneshot":return Mt.oneshot;case"noise":return Mt.noise;case"audio":return Mt.audio;case"media":return Mt.media;case"stream":return Mt.stream;case"processor":return Mt.processor;case"mixer":return Mt.mixer;case"midi":return Mt.midi;case"mml":return Mt.mml;default:return null}}Nt.SAMPLE_RATE=Et.sampleRate,Nt.EQUAL_TEMPERAMENT=12,Nt.FREQUENCY_RATIO=mt,Nt.MIN_A=vt,Nt.QUARTER_NOT=4,Nt.HALF_UP="+",Nt.HALF_DOWN="-",Nt.DOT=".",Nt.isPitchChar=gt,Nt.computeIndex=bt,Nt.computeHz=function(t,e){return t<=0?0:t*2**(e/1200)},Nt.computeFrequency=yt,Nt.computePlaybackRate=function(t,e){return t<=0?1:t*2**(e/1200)},Nt.fft=function(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}},Nt.ifft=function(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s},Nt.ajax=function(t){const{url:e,type:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{n&&n(t,"timeout")},o.onprogress=t=>{a&&a(t)},o.onerror=t=>{n&&n(t,"error")},o.onload=t=>{r&&200===o.status&&r(t,o.response)},o.open("GET",e,!0),o.responseType=s??"arraybuffer",o.send(null)},Nt.convertTime=function(t){return t<0?{minutes:-1,seconds:-1,milliseconds:-1}:{minutes:Math.trunc(t/60),seconds:Math.trunc(t%60),milliseconds:t-Math.trunc(t)}},Nt.decode=function(t,e,s,i){return s||(s=()=>{}),i||(i=()=>{}),t.decodeAudioData(e,s,i)},Nt.requestFullscreen=function(t){return t.requestFullscreen()},Nt.exitFullscreen=function(){return document.exitFullscreen()},Nt.read=kt,Nt.drop=function(t){const{event:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t;e.preventDefault();const a=e.dataTransfer?.items[0].getAsFile()??null;return null===a?null:"objectURL"===s?window.URL.createObjectURL(a):(kt({file:a,type:s,successCallback:i,errorCallback:r,progressCallback:n}),a)},Nt.file=function(t){const{event:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t,a=e.target.files?.item(0)??null;return null===a?null:"objectURL"===s?window.URL.createObjectURL(a):(kt({file:a,type:s,successCallback:i,errorCallback:r,progressCallback:n}),a)},Nt.toFrequencies=function(t){return t.map((t=>yt(t)))},Nt.toTextFile=function(t,e){if(e){const e=new Blob([t],{type:"text/plain"});return window.URL.createObjectURL(e)}return`data:,${encodeURIComponent(t)}`},Nt.Analyser=c,Nt.Recorder=p,Nt.Effector=d,Nt.Autopanner=f,Nt.BitCrusher=m,Nt.Chorus=v,Nt.Compressor=g,Nt.Delay=b,Nt.Equalizer=k,Nt.Filter=w,Nt.Flanger=A,Nt.Fuzz=x,Nt.Listener=T,Nt.NoiseGate=S,Nt.NoiseSuppressor=E,Nt.OverDrive=M,Nt.Panner=F,Nt.Phaser=N,Nt.PitchShifter=O,Nt.Preamp=B,Nt.Reverb=Q,Nt.Ringmodulator=$,Nt.Stereo=j,Nt.Tremolo=X,Nt.VocalCanceler=W,Nt.Wah=V,Nt.setup=()=>"running"!==Et.state?Et.resume():Promise.resolve(),Nt.promise=()=>Ft,Nt.clone=()=>{const t={oscillator:null,oneshot:null,noise:null,audio:null,media:null,stream:null,processor:null,mixer:null,midi:null,mml:null};function e(e){switch(e){case"oscillator":return t.oscillator;case"oneshot":return t.oneshot;case"noise":return t.noise;case"audio":return t.audio;case"media":return t.media;case"stream":return t.stream;case"processor":return t.processor;case"mixer":return t.mixer;case"midi":return t.midi;case"mml":return t.mml;default:return null}}return e.free=e=>{for(const s of e)null!==s&&Object.entries(t).forEach((([e,i])=>{s===i&&(t[e]=null)}))},t.oscillator=new K(Et),t.oneshot=new Z(Et),t.noise=new tt(Et),t.audio=new et(Et),t.media=new st(Et),t.stream=new it(Et),t.processor=new rt(Et),t.mixer=new nt(Et),t.midi=new at,t.mml=new St,e},Nt.free=t=>{for(const e of t)null!==e&&Object.entries(Mt).forEach((([t,s])=>{e===s&&(Mt[t]=null)}))},Nt.noConflict=t=>(window.X===Nt&&(window.X=void 0),t&&window.XSound===Nt&&(window.XSound=void 0),Nt),Nt.get=()=>Et,Nt.getCurrentTime=()=>Et.currentTime;const Ot=t=>{t.stopImmediatePropagation(),Nt.setup().finally((()=>{document.removeEventListener("mousedown",Ot,!1),document.removeEventListener("touchstart",Ot,!1)}))};return document.addEventListener("mousedown",Ot,!1),document.addEventListener("touchstart",Ot,!1),e})()));
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xsound=e():t.xsound=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{X:()=>Nt,XSound:()=>Nt});class AudioWorkletProcessor{port=new MessagePort}function s(t,e,s){return t.audioWorklet.addModule(function(t){return`data:text/javascript,${encodeURIComponent(t.toString())}; registerProcessor('${t.name}', ${t.name})`}(e),s)}class SoundModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class i{static XMLNS="http://www.w3.org/2000/svg";static XLINK="http://www.w3.org/1999/xlink";static SVG_LINEAR_GRADIENT_ID_TIME_OVERVIEW="svg-linear-gradient-time-overview";static SVG_LINEAR_GRADIENT_ID_TIME="svg-linear-gradient-time";static SVG_LINEAR_GRADIENT_ID_FFT="svg-linear-gradient-fft";sampleRate;channel;isActive=!1;graphics="";canvas=null;context=null;svg=null;interval=1e3;styles={shape:"line",gradients:[{offset:0,color:"rgba(0, 128, 255, 1.0)"},{offset:1,color:"rgba(0, 0, 255, 1.0)"}],wave:"rgba(0, 0, 255, 1.0)",grid:"rgba(255, 0, 0, 1.0)",text:"rgba(255, 255, 255, 1.0)",font:{family:"Arial",size:"13px",style:"normal",weight:"normal"},width:1.5,cap:"round",join:"miter",top:15,right:30,bottom:15,left:30};constructor(t,e){this.sampleRate=t,this.channel=e}setup(t){return t instanceof HTMLCanvasElement?(this.graphics="canvas",this.canvas=t,this.context=this.canvas.getContext("2d")):t instanceof SVGSVGElement&&(this.graphics="svg",this.svg=t),this}start(t,e,s){switch(this.graphics){case"canvas":this.visualizeOnCanvas(t,e,s);break;case"svg":this.visualizeBySVG(t,e,s)}return this}param(t){if("string"==typeof t)switch(t){case"interval":return this.interval;case"styles":return this.styles}for(const[e,s]of Object.entries(t))switch(e){case"interval":"number"==typeof s&&(this.interval=s);break;case"styles":"object"==typeof s&&(this.styles={...this.styles,...s})}}get(){switch(this.graphics){case"canvas":return this.canvas;case"svg":return this.svg;default:return null}}clear(){switch(this.graphics){case"canvas":this.canvas&&this.context&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height);break;case"svg":this.svg&&(this.svg.innerHTML="")}return this}create(){switch(this.graphics){case"canvas":return null===this.canvas?"":this.canvas.toDataURL("image/png").replace("image/png","image/octet-stream");case"svg":return null===this.svg?"":this.svg.outerHTML;default:return""}}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}visualizeTimeDomainFloat32ArrayOnCanvas(t,e,s,i,r,n){const a=this.styles.top??15,o=this.styles.left??30,h=this.styles.width??1.5,c=this.styles.cap??"round",u=this.styles.join??"miter",l=this.styles.wave??"rgba(0, 0, 255, 1.0)";switch(this.styles.shape){case"line":t.strokeStyle=l,t.lineWidth=h,t.lineCap=c,t.lineJoin=u,t.beginPath();for(let r=0,h=e.length;r<h;r++)if(!n||r%n==0){const n=r/h*s+o,c=(1-e[r])*(i/2)+a;0===r?t.moveTo(n+t.lineWidth/2,c):t.lineTo(n,c)}t.stroke();break;case"rect":for(let c=0,u=e.length;c<u;c++)if(!n||c%n==0){const n=c/u*s+o,p=e[c]*(i/2)*-1;if(this.styles.gradients){const e=i/2+a,s=t.createLinearGradient(0,e,0,e+p);for(const t of this.styles.gradients)s.addColorStop(t.offset,t.color);t.fillStyle=s}else t.fillStyle=l;t.fillRect(n,r,h,p)}}}visualizeTimeDomainFloat32ArrayBySVG(t,e,s,r,n,a){const o=this.styles.top??15,h=this.styles.left??30,c=this.styles.width??1.5,u=this.styles.cap??"round",l=this.styles.join??"miter",p=this.styles.wave??"rgba(0, 0, 255, 1.0)";switch(this.styles.shape){case"line":{const r=document.createElementNS(i.XMLNS,"path");let a="";for(let i=0,r=t.length;i<r;i++)if(i%n==0){const n=i/r*e+h,c=(1-t[i])*(s/2)+o;a+=0===i?`M${n+(this.styles.width??1.5)/2} ${c}`:` L${n} ${c}`}return r.setAttribute("d",a),r.setAttribute("stroke",p),r.setAttribute("fill","none"),r.setAttribute("stroke-width",c.toString(10)),r.setAttribute("stroke-linecap",u),r.setAttribute("stroke-linejoin",l),r}case"rect":{let o=null;this.styles.gradients&&(o=this.createSVGLinearGradient(a));const u=document.createElementNS(i.XMLNS,"g");null!==o&&u.appendChild(o);for(let l=0,d=t.length;l<d;l++)if(l%n==0){const n=document.createElementNS(i.XMLNS,"rect"),f=l/d*e+h,m=t[l]*(s/2);n.setAttribute("x",f.toString(10)),n.setAttribute("y",r.toString(10)),n.setAttribute("width",c.toString(10)),n.setAttribute("height",Math.abs(m).toString(10)),m>=0&&n.setAttribute("transform",`rotate(180 ${f+c/2} ${r})`),n.setAttribute("stroke","none"),n.setAttribute("fill",null===o?p:`url(#${a})`),u.appendChild(n)}return u}default:return null}}createSVGLinearGradient(t){if(!this.styles.gradients)return null;const e=document.createElementNS(i.XMLNS,"defs"),s=document.createElementNS(i.XMLNS,"linearGradient");s.setAttribute("id",t),s.setAttribute("x1","0%"),s.setAttribute("y1","0%"),s.setAttribute("x2","0%"),s.setAttribute("y2","100%");for(const t of this.styles.gradients){const e=document.createElementNS(i.XMLNS,"stop");e.setAttribute("offset",t.offset.toString(10)),e.setAttribute("stop-color",t.color),s.appendChild(e)}return e.appendChild(s),e}createFontString(){const{style:t,weight:e,size:s,family:i}=this.styles.font??{};return`${t??"normal"} ${e??"normal"} ${s??"13px"} "${i??"Arial"}"`}}const r="xsound-svg-current-time",n="xsound-svg-sprite";class a extends i{callback=()=>{};currentImageData=null;currentSVGElement=null;currentDataSize=0;currentTime={width:1,color:"rgba(0, 0, 0, 0.5)"};sprite="rgba(255, 255, 255, 0.25)";plotInterval=.0625;textInterval=60;isDown=!1;mode="update";offsetX=0;startTime=0;endTime=0;constructor(t,e){super(t,e),this.onMouseStart=this.onMouseStart.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"currentTime":return this.currentTime;case"sprite":return this.sprite;case"plotInterval":return this.plotInterval;case"textInterval":return this.textInterval;case"mode":return this.mode;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"currentTime":"object"==typeof s&&(this.currentTime={...this.currentTime,...s});break;case"sprite":"string"==typeof s&&(this.sprite=s);break;case"plotInterval":"number"==typeof s&&(this.plotInterval=s);break;case"textInterval":"number"==typeof s&&(this.textInterval=s);break;case"mode":"string"==typeof s&&("update"!==s&&"sprite"!==s||(this.mode=s))}return super.param(t),this}update(t){switch(this.graphics){case"canvas":{if(null===this.currentImageData)return this;if(null===this.canvas||null===this.context)return this;const e=this.context,s=this.canvas.width,i=this.canvas.height,r=s-((this.styles.left??30)+(this.styles.right??30)),n=i-((this.styles.top??15)+(this.styles.bottom??15)),a=t*this.sampleRate/this.currentDataSize*r,o=this.styles.left??30,h=this.styles.top??15,c=this.currentTime.color??"rgba(0, 0, 0, 0.5)";switch(e.clearRect(0,0,s,i),e.putImageData(this.currentImageData,0,0),this.mode){case"update":e.fillStyle=c,e.fillRect(o,h+1,a,n-1);break;case"sprite":if(0!==this.endTime){const t=Math.trunc(Math.abs(this.endTime-this.startTime)*this.sampleRate/this.currentDataSize*r);e.fillStyle=this.sprite,a>=this.offsetX?e.fillRect(o+this.offsetX,h+1,t,n-1):e.fillRect(o+this.offsetX-t,h+1,t,n-1)}e.fillStyle=c,a>=this.offsetX?e.fillRect(o+this.offsetX,h+1,Math.abs(a-this.offsetX),n-1):e.fillRect(o+a,h+1,Math.abs(a-this.offsetX),n-1)}break}case"svg":if(null===this.currentSVGElement)return this;if(this.svg){const e=this.svg.querySelector(`.${r}`);if(null===e)return this;const s=Number(this.svg.getAttribute("width")??"0"),i=this.styles.top??15,o=this.styles.left??30,h=s-(o+(this.styles.right??30)),c=t*this.sampleRate/this.currentDataSize*h;if("update"===this.mode){const t=this.svg.querySelector(`.${n}`);t&&t.parentNode?.removeChild(t),e.setAttribute("x",o.toString(10)),e.setAttribute("width",c.toString(10)),e.setAttribute("aria-label","current time")}else if("sprite"===this.mode){if(0!==this.endTime){const t=this.svg.querySelector(`.${n}`);t&&t.parentNode?.removeChild(t);const s=document.createElementNS(a.XMLNS,"rect");s.classList.add(n);const r=Math.trunc(Math.abs(this.endTime-this.startTime)*this.sampleRate/this.currentDataSize*h);s.setAttribute("y",(i+1).toString(10)),s.setAttribute("height",e.getAttribute("height")??"0"),s.setAttribute("stroke","none"),s.setAttribute("fill",this.sprite),s.setAttribute("aria-label","current time"),c>=this.offsetX?s.setAttribute("x",(o+this.offsetX).toString(10)):s.setAttribute("x",(o+this.offsetX-r).toString(10)),s.setAttribute("width",r.toString(10)),this.svg.appendChild(s),this.svg.appendChild(e)}c>=this.offsetX?e.setAttribute("x",(o+this.offsetX).toString(10)):e.setAttribute("x",(o+c).toString(10)),e.setAttribute("width",Math.abs(c-this.offsetX).toString(10)),e.setAttribute("aria-label","sprite time")}}}return this}drag(t){let e=null;switch(this.graphics){case"canvas":if(null===this.canvas)return this;e=this.canvas;break;case"svg":if(null===this.svg)return this;e=this.svg}return null===e||(t&&(this.callback=t),e.removeEventListener("mousedown",{handleEvent:this.onMouseStart},!1),e.removeEventListener("mousemove",{handleEvent:this.onMouseMove},!1),window.removeEventListener("mouseup",{handleEvent:this.onMouseUp},!1),e.removeEventListener("touchstart",{handleEvent:this.onTouchStart},!1),e.removeEventListener("touchmove",{handleEvent:this.onTouchMove},!1),window.removeEventListener("touchend",{handleEvent:this.onTouchEnd},!1),e.addEventListener("mousedown",{handleEvent:this.onMouseStart},!1),e.addEventListener("mousemove",{handleEvent:this.onMouseMove},!1),window.addEventListener("mouseup",{handleEvent:this.onMouseUp},!1),e.addEventListener("touchstart",{handleEvent:this.onTouchStart},!1),e.addEventListener("touchmove",{handleEvent:this.onTouchMove},!1),window.addEventListener("touchend",{handleEvent:this.onTouchEnd},!1)),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive||t instanceof Uint8Array)return;const i=this.context,r=this.canvas.width,n=this.canvas.height,a=this.styles.top??15,o=this.styles.bottom??15,h=this.styles.left??30,c=r-(h+(this.styles.right??30)),u=n-(a+o),l=Math.trunc(u/2)+a,p=this.styles.grid??"none",d=this.styles.text??"none",f=parseInt(this.styles.font?.size??"13px",10),m=Math.trunc(this.plotInterval*this.sampleRate),v=Math.trunc(this.textInterval*this.sampleRate);if(i.clearRect(0,0,r,n),this.visualizeTimeDomainFloat32ArrayOnCanvas(i,t,c,u,l,m),"none"!==p||"none"!==d){for(let e=0,s=t.length;e<s;e++)if(e%v==0){const t=Math.trunc(e/s*c)+h,r=`${Math.trunc(e/this.sampleRate/60)} min`;"none"!==p&&(i.fillStyle=p,i.fillRect(t,a,1,u)),"none"!==d&&(i.fillStyle=d,i.font=this.createFontString(),i.fillText(r,t-i.measureText(r).width/2,a+u+f))}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=Math.trunc(h-i.measureText(t).width),s=Math.trunc((1-Number(t.trim()))*(u/2))+a;"none"!==p&&(i.fillStyle=p,i.fillRect(h,s,c,1)),"none"!==d&&(i.fillStyle=d,i.font=this.createFontString(),i.fillText(t,e,s-Math.trunc(f/4)))}}this.currentImageData=i.getImageData(0,0,r,n),this.currentDataSize=t.length,i.fillStyle=this.currentTime.color??"rgba(0, 0, 0, 0.5)",i.fillRect(h,a,1,u)}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive||t instanceof Uint8Array)return;const i=this.svg,n=Number(i.getAttribute("width")??"0"),o=Number(i.getAttribute("height")??"0"),h=this.styles.top??15,c=this.styles.bottom??15,u=this.styles.left??30,l=n-(u+(this.styles.right??30)),p=o-(h+c),d=Math.trunc(p/2)+h,f=this.styles.grid??"none",m=this.styles.text??"none",v=parseInt(this.styles.font?.size??"13px",10),g=Math.trunc(this.plotInterval*this.sampleRate),b=Math.trunc(this.textInterval*this.sampleRate);i.innerHTML="";const y=this.visualizeTimeDomainFloat32ArrayBySVG(t,l,p,d,g,`${a.SVG_LINEAR_GRADIENT_ID_TIME_OVERVIEW}-${this.channel}`);if(y&&i.appendChild(y),"none"!==f||"none"!==m){for(let e=0,s=t.length;e<s;e++)if(e%b==0){const t=Math.trunc(e/s*l)+u,r=`${Math.trunc(e/this.sampleRate/60)} min`;if("none"!==f){const e=document.createElementNS(a.XMLNS,"rect");e.setAttribute("x",t.toString(10)),e.setAttribute("y",h.toString(10)),e.setAttribute("width","1"),e.setAttribute("height",p.toString(10)),e.setAttribute("stroke","none"),e.setAttribute("fill",f),i.appendChild(e)}if("none"!==m){const e=document.createElementNS(a.XMLNS,"text");e.textContent=r,e.setAttribute("x",t.toString(10)),e.setAttribute("y",(h+p+v).toString(10)),e.setAttribute("text-anchor","middle"),e.setAttribute("stroke","none"),e.setAttribute("fill",m),e.setAttribute("font-family",this.styles.font?.family??"Arial"),e.setAttribute("font-size",v.toString(10)),e.setAttribute("font-style",this.styles.font?.style??"normal"),e.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(e)}}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=u,s=Math.trunc((1-Number(t.trim()))*(p/2))+h;if("none"!==f){const t=document.createElementNS(a.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",l.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",f),i.appendChild(t)}if("none"!==m){const r=document.createElementNS(a.XMLNS,"text");r.textContent=t,r.setAttribute("x",e.toString(10)),r.setAttribute("y",(s-Math.trunc(v/4)).toString(10)),r.setAttribute("text-anchor","end"),r.setAttribute("stroke","none"),r.setAttribute("fill",m),r.setAttribute("font-family",this.styles.font?.family??"Arial"),r.setAttribute("font-size",v.toString(10)),r.setAttribute("font-style",this.styles.font?.style??"normal"),r.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(r)}}}const w=document.createElementNS(a.XMLNS,"rect");w.classList.add(r),w.setAttribute("y",(h+1).toString(10)),w.setAttribute("height",(p-1).toString(10)),w.setAttribute("stroke","none"),w.setAttribute("fill",this.currentTime.color??"rgba(0, 0, 0, 0.5)"),i.appendChild(w),this.currentSVGElement=i,this.currentDataSize=t.length}visualize(t,e,s){let i=0,r=0;switch(this.graphics){case"canvas":if(null===this.canvas)return;i=this.canvas.offsetLeft,r=this.canvas.width;break;case"svg":if(null===this.svg)return;i=this.svg.parentElement?.offsetLeft??0,r=Number(this.svg.getAttribute("width")??"0")}let n=s-(i+(this.styles.left??30));"canvas"===this.graphics&&this.canvas?.parentElement&&(n+=this.canvas.parentElement.scrollLeft),"svg"===this.graphics&&this.svg?.parentElement&&(n+=this.svg.parentElement.scrollLeft),r-=(this.styles.left??30)+(this.styles.right??30),n<0&&(n=0),n>r&&(n=r);const a=n/r*this.currentDataSize/this.sampleRate;"mousedown"!==e&&"touchstart"!==e||(this.offsetX=n,this.startTime=a,this.endTime=0),"mouseup"!==e&&"touchend"!==e||(this.endTime=a),this.update(a),this.startTime<=a?this.callback(t,this.startTime,a,this.mode,!0):this.startTime>a&&this.callback(t,a,this.startTime,this.mode,!1)}onMouseStart(t){"mousedown"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!0}onMouseMove(t){this.isDown&&(t.stopPropagation(),"mousemove"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)))}onMouseUp(t){this.isDown&&("mouseup"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!1)}onTouchStart(t){"touchstart"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!0}onTouchMove(t){this.isDown&&(t.stopPropagation(),t.preventDefault(),"touchmove"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)))}onTouchEnd(t){this.isDown&&("touchend"===t.type&&this.visualize(t,t.type,this.getOffsetX(t)),this.isDown=!1)}getOffsetX(t){return t instanceof MouseEvent?t.pageX:t instanceof TouchEvent?t.touches[0].pageX:0}}class o extends i{type="uint";textInterval=.005;constructor(t,e){super(t,e)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"type":return this.type;case"textInterval":return this.textInterval;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"type":"string"==typeof s&&("uint"!==s&&"float"!==s||(this.type=s));break;case"textInterval":"number"==typeof s&&(this.textInterval=s)}return super.param(t),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive)return;const i=this.context,r=this.canvas.width,n=this.canvas.height,a=this.styles.top??15,o=this.styles.bottom??15,h=this.styles.left??30,c=r-(h+(this.styles.right??30)),u=n-(a+o),l=Math.trunc(u/2)+a,p=this.styles.width??1.5,d=this.styles.cap??"round",f=this.styles.join??"miter",m=this.styles.wave??"rgba(0, 0, 255, 1.0)",v=this.styles.grid??"none",g=this.styles.text??"none",b=parseInt(this.styles.font?.size??"13px",10),y=Math.trunc(this.textInterval*this.sampleRate);switch(i.clearRect(0,0,r,n),this.type){case"float":t instanceof Float32Array&&this.visualizeTimeDomainFloat32ArrayOnCanvas(i,t,c,u,l);break;case"uint":switch(this.styles.shape){case"line":i.strokeStyle=m,i.lineWidth=p,i.lineCap=d,i.lineJoin=f,i.beginPath();for(let e=0,s=t.length;e<s;e++){const r=e/s*c+h,n=(1-t[e]/255)*u+a;0===e?i.moveTo(r+p/2,n):i.lineTo(r,n)}i.stroke();break;case"rect":for(let e=0,s=t.length;e<s;e++){const r=e/s*c+h,n=(.5-t[e]/255)*u;if(this.styles.gradients){const t=u/2+a,e=i.createLinearGradient(0,t,0,t+n);for(const t of this.styles.gradients)e.addColorStop(t.offset,t.color);i.fillStyle=e}else i.fillStyle=m;i.fillRect(r,l,1,n)}}}if("none"!==v||"none"!==g){for(let e=0,s=t.length;e<s;e++)if(e%y==0){const t=Math.trunc(e/s*c)+h,r=`${Math.ceil(e/this.sampleRate*1e3)} ms`;"none"!==v&&(i.fillStyle=v,i.fillRect(t,a,1,u)),"none"!==g&&(i.fillStyle=g,i.font=this.createFontString(),i.fillText(r,t-i.measureText(r).width/2,a+u+b))}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=Math.trunc(h-i.measureText(t).width),s=Math.trunc((1-Number(t.trim()))*(u/2))+a;"none"!==v&&(i.fillStyle=v,i.fillRect(h,s,c,1)),"none"!==g&&(i.fillStyle=g,i.font=this.createFontString(),i.fillText(t,e,s-Math.trunc(b/4)))}}}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive)return;const i=this.svg,r=Number(i.getAttribute("width")??"0"),n=Number(i.getAttribute("height")??"0"),a=this.styles.top??15,h=this.styles.bottom??15,c=this.styles.left??30,u=r-(c+(this.styles.right??30)),l=n-(a+h),p=Math.trunc(l/2)+a,d=this.styles.width??1.5,f=this.styles.cap??"round",m=this.styles.join??"miter",v=this.styles.wave??"rgba(0, 0, 255, 1.0)",g=this.styles.grid??"none",b=this.styles.text??"none",y=parseInt(this.styles.font?.size??"13px",10),w=Math.trunc(this.textInterval*this.sampleRate);switch(i.innerHTML="",this.type){case"float":if(t instanceof Float32Array){const e=this.visualizeTimeDomainFloat32ArrayBySVG(t,u,l,p,0,o.SVG_LINEAR_GRADIENT_ID_TIME);null!==e&&i.appendChild(e)}break;case"uint":switch(this.styles.shape){case"line":{const e=document.createElementNS(o.XMLNS,"path");let s="";for(let e=0,i=t.length;e<i;e++){const r=e/i*u+c,n=(1-t[e]/255)*l+a;s+=0===e?`M${r+d/2} ${n}`:` L${r} ${n}`}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",d.toString(10)),e.setAttribute("stroke-linecap",f),e.setAttribute("stroke-linejoin",m),i.appendChild(e);break}case"rect":{let e=null;this.styles.gradients&&(e=this.createSVGLinearGradient(`${o.SVG_LINEAR_GRADIENT_ID_TIME}-${this.channel}`));const s=document.createElementNS(o.XMLNS,"g");null!==e&&s.appendChild(e);for(let i=0,r=t.length;i<r;i++){const n=document.createElementNS(o.XMLNS,"rect"),a=i/r*u+c,h=(t[i]/255-.5)*l;n.setAttribute("x",a.toString(10)),n.setAttribute("y",p.toString(10)),n.setAttribute("width",d.toString(10)),n.setAttribute("height",Math.abs(h).toString(10)),h>=0&&n.setAttribute("transform",`rotate(180 ${a+d/2} ${p})`),n.setAttribute("stroke","none"),n.setAttribute("fill",null===e?v:`url(#${o.SVG_LINEAR_GRADIENT_ID_TIME}-${this.channel})`),s.appendChild(n)}i.appendChild(s);break}}}if("none"!==g||"none"!==b){for(let e=0,s=t.length;e<s;e++)if(e%w==0){const t=Math.trunc(e/s*u)+c,r=`${Math.ceil(e/this.sampleRate*1e3)} ms`;if("none"!==g){const e=document.createElementNS(o.XMLNS,"rect");e.setAttribute("x",t.toString(10)),e.setAttribute("y",a.toString(10)),e.setAttribute("width","1"),e.setAttribute("height",l.toString(10)),e.setAttribute("stroke","none"),e.setAttribute("fill",g),i.appendChild(e)}if("none"!==b){const e=document.createElementNS(o.XMLNS,"text");e.textContent=r,e.setAttribute("x",t.toString(10)),e.setAttribute("y",(a+l+y).toString(10)),e.setAttribute("text-anchor","middle"),e.setAttribute("stroke","none"),e.setAttribute("fill",b),e.setAttribute("font-family",this.styles.font?.family??"Arial"),e.setAttribute("font-size",y.toString(10)),e.setAttribute("font-style",this.styles.font?.style??"normal"),e.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(e)}}for(const t of["-1.00","-0.50"," 0.00"," 0.50"," 1.00"]){const e=c,s=Math.trunc((1-Number(t.trim()))*(l/2))+a;if("none"!==g){const t=document.createElementNS(o.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",u.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",g),i.appendChild(t)}if("none"!==b){const r=document.createElementNS(o.XMLNS,"text");r.textContent=t,r.setAttribute("x",e.toString(10)),r.setAttribute("y",(s-Math.trunc(y/4)).toString(10)),r.setAttribute("text-anchor","end"),r.setAttribute("stroke","none"),r.setAttribute("fill",b),r.setAttribute("font-family",this.styles.font?.family??"Arial"),r.setAttribute("font-size",y.toString(10)),r.setAttribute("font-style",this.styles.font?.style??"normal"),r.setAttribute("font-weight",this.styles.font?.weight??"normal"),i.appendChild(r)}}}}}class h extends i{static MIN_FREQUENCY=62.5;static MAX_FREQUENCY=8e3;static LOGARITHMIC_FREQUENCIES=[62.5,125,250,500,1e3,2e3,4e3,8e3];type="uint";size=256;textInterval=1e3;scale="linear";constructor(t,e){super(t,e)}setup(t){return super.setup(t),this}param(t){if("string"==typeof t)switch(t){case"type":return this.type;case"size":return this.size;case"textInterval":return this.textInterval;case"scale":return this.scale;case"minFrequency":return h.MIN_FREQUENCY;case"maxFrequency":return h.MAX_FREQUENCY;case"interval":case"styles":return super.param(t)}for(const[e,s]of Object.entries(t))switch(e){case"type":"string"==typeof s&&("uint"!==s&&"float"!==s||(this.type=s));break;case"size":"number"==typeof s&&(this.size=s);break;case"textInterval":"number"==typeof s&&(this.textInterval=s);break;case"scale":"string"==typeof s&&("linear"!==s&&"logarithmic"!==s||(this.scale=s))}return super.param(t),this}clear(){return super.clear(),this}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}visualizeOnCanvas(t,e,s){if(null===this.canvas||null===this.context||!this.isActive)return;const i=e??-100,r=s??-30,n=r-i,a=this.context,o=this.canvas.width,c=this.canvas.height,u=this.styles.top??0,l=this.styles.bottom??0,p=this.styles.left??30,d=this.styles.right??30,f=o-(p+d),m=c-(u+l),v=this.styles.width??1.5,g=this.styles.cap??"round",b=this.styles.join??"miter",y=this.styles.wave??"rgba(0, 0, 255, 1.0)",w=this.styles.grid??"none",k=this.styles.text??"none",A=parseInt(this.styles.font?.size??"13px",10),x=this.size>t.length?t.length:this.size,T=this.sampleRate/(2*t.length),S=Math.trunc(this.textInterval/T);switch(a.clearRect(0,0,o,c),this.type){case"float":switch(a.strokeStyle=y,a.lineWidth=v,a.lineCap=g,a.lineJoin=b,a.beginPath(),this.scale){case"linear":for(let e=0;e<x;e++){const s=e/x*f+p,i=Math.trunc(-1*(t[e]-r)*(m/n))+u;0===e?a.moveTo(s+v/2,i):a.lineTo(s,i)}break;case"logarithmic":for(let e=0;e<t.length;e++){if(0===e)continue;const s=e*T,i=Math.trunc(Math.log10(s/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,o=Math.trunc(-1*(t[e]-r)*(m/n))+u;i<p||i>p+f||(1===e?a.moveTo(p+v/2,o):a.lineTo(i,o))}}a.stroke();break;case"uint":switch(this.styles.shape){case"line":a.strokeStyle=y,a.lineWidth=v,a.lineCap=g,a.lineJoin=b,a.beginPath();for(let e=0;e<x;e++){const s=e/x*f+p,i=(1-t[e]/255)*m+u;0===e?a.moveTo(s+v/2,i):a.lineTo(s,i)}a.stroke();break;case"rect":for(let e=0;e<x;e++){const s=e/x*f+p,i=t[e]/255*m*-1;if(this.styles.gradients){const t=m+u,e=a.createLinearGradient(0,t,0,t+i);for(const t of this.styles.gradients)e.addColorStop(t.offset,t.color);a.fillStyle=e}else a.fillStyle=y;a.fillRect(s,m+u,v,i)}}}if("none"!==w||"none"!==k){if("uint"===this.type||"float"===this.type&&"linear"===this.scale){for(let t=0;t<x;t++)if(t%S==0){const e=Math.trunc(t/x*f)+p,s=Math.trunc(this.textInterval*(t/S)),i=s<1e3?`${s} Hz`:`${(s/1e3).toString(10).slice(0,3)} kHz`;"none"!==w&&(a.fillStyle=w,a.fillRect(e,u,1,m)),"none"!==k&&(a.fillStyle=k,a.font=this.createFontString(),a.fillText(i,e-a.measureText(i).width/2,u+m+A))}}else h.LOGARITHMIC_FREQUENCIES.forEach((t=>{const e=Math.trunc(Math.log10(t/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,s=t<1e3?`${t} Hz`:`${(t/1e3).toString(10).slice(0,3)} kHz`;"none"!==w&&(a.fillStyle=w,a.fillRect(e,u,1,m)),"none"!==k&&(a.fillStyle=k,a.font=this.createFontString(),a.fillText(s,e-a.measureText(s).width/2,u+m+A))}));switch(this.type){case"float":for(let t=i;t<=r;t+=10){const e=`${t} dB`,s=Math.trunc(p-a.measureText(e).width),i=Math.trunc(-1*(t-r)/n*m)+u;"none"!==w&&(a.fillStyle=w,a.fillRect(p,i,f,1)),"none"!==k&&(a.fillStyle=k,a.font=this.createFontString(),a.fillText(e,s,i))}break;case"uint":for(const t of["0.00","0.25","0.50","0.75","1.00"]){const e=Math.trunc(p-a.measureText(t).width),s=(1-Number(t))*m+u;"none"!==w&&(a.fillStyle=w,a.fillRect(p,s,f,1)),"none"!==k&&(a.fillStyle=k,a.font=this.createFontString(),a.fillText(t,e,s))}}}}visualizeBySVG(t,e,s){if(null===this.svg||!this.isActive)return;const i=e??-100,r=s??-30,n=r-i,a=this.svg,o=Number(a.getAttribute("width")??"0"),c=Number(a.getAttribute("height")??"0"),u=this.styles.top??0,l=this.styles.bottom??0,p=this.styles.left??30,d=this.styles.right??30,f=o-(p+d),m=c-(u+l),v=this.styles.wave??"rgba(0, 0, 255, 1.0)",g=this.styles.width??1.5,b=this.styles.cap??"round",y=this.styles.join??"miter",w=this.styles.grid??"none",k=this.styles.text??"none",A=parseInt(this.styles.font?.size??"13px",10),x=this.size>t.length?t.length:this.size,T=this.sampleRate/(2*t.length),S=Math.trunc(this.textInterval/T);switch(a.innerHTML="",this.type){case"float":{const e=document.createElementNS(h.XMLNS,"path");let s="";switch(this.scale){case"linear":for(let e=0;e<x;e++){const i=Math.trunc(e/x*f)+p,a=Math.trunc(-1*(t[e]-r)*(m/n))+u;Number.isFinite(i)&&Number.isFinite(a)&&(s+=""===s?`M${i+g/2} ${a}`:` L${i} ${a}`)}break;case"logarithmic":for(let e=0;e<t.length;e++){if(0==e)continue;const i=e*T,a=Math.trunc(Math.log10(i/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,o=Math.trunc(-1*(t[e]-r)*(m/n))+u;Number.isFinite(a)&&Number.isFinite(o)&&(a<p||a>p+f||(s+=""===s?`M${a} ${o}`:` L${a} ${o}`))}}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",g.toString(10)),e.setAttribute("stroke-linecap",b),e.setAttribute("stroke-linejoin",y),a.appendChild(e);break}case"uint":switch(this.styles.shape){case"line":{const e=document.createElementNS(h.XMLNS,"path");let s="";for(let e=0;e<x;e++){const i=Math.trunc(e/x*f)+p,r=Math.trunc((1-t[e]/255)*m)+u;s+=0===e?`M${i+g/2} ${r}`:` L${i} ${r}`}e.setAttribute("d",s),e.setAttribute("stroke",v),e.setAttribute("fill","none"),e.setAttribute("stroke-width",g.toString(10)),e.setAttribute("stroke-linecap",b),e.setAttribute("stroke-linejoin",y),a.appendChild(e);break}case"rect":{let e=null;this.styles.gradients&&(e=this.createSVGLinearGradient(`${h.SVG_LINEAR_GRADIENT_ID_FFT}-${this.channel}`));const s=document.createElementNS(h.XMLNS,"g");null!==e&&s.appendChild(e);for(let i=0;i<x;i++){const r=document.createElementNS(h.XMLNS,"rect"),n=Math.trunc(i/x*f)+p,a=Math.trunc(t[i]/255*m);r.setAttribute("x",n.toString(10)),r.setAttribute("y",(u+m).toString(10)),r.setAttribute("width",g.toString(10)),r.setAttribute("height",Math.abs(a).toString(10)),a>=0&&r.setAttribute("transform",`rotate(180 ${n+g/2} ${u+m})`),r.setAttribute("stroke","none"),r.setAttribute("fill",null===e?v:`url(#${h.SVG_LINEAR_GRADIENT_ID_FFT}-${this.channel})`),s.appendChild(r)}a.appendChild(s);break}}}if("none"!==w||"none"!==k){if("uint"===this.type||"float"===this.type&&"linear"===this.scale){for(let t=0;t<x;t++)if(t%S==0){const e=Math.trunc(t/x*f)+p,s=Math.trunc(this.textInterval*(t/S)),i=s<1e3?`${s} Hz`:`${(s/1e3).toString(10).slice(0,3)} kHz`;if("none"!==w){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",u.toString(10)),t.setAttribute("width","1"),t.setAttribute("height",m.toString(10)),t.setAttribute("stroke","none"),t.setAttribute("fill",w),a.appendChild(t)}if("none"!==k){const t=document.createElementNS(h.XMLNS,"text");t.textContent=i,t.setAttribute("x",e.toString(10)),t.setAttribute("y",(u+m+l).toString(10)),t.setAttribute("text-anchor","middle"),t.setAttribute("stroke","none"),t.setAttribute("fill",k),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}}else h.LOGARITHMIC_FREQUENCIES.forEach((t=>{const e=Math.trunc(Math.log10(t/h.MIN_FREQUENCY)/Math.log10(h.MAX_FREQUENCY/h.MIN_FREQUENCY)*f)+p,s=t<1e3?`${t} Hz`:`${(t/1e3).toString(10).slice(0,3)} kHz`;if("none"!==w){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",u.toString(10)),t.setAttribute("width","1"),t.setAttribute("height",m.toString(10)),t.setAttribute("stroke","none"),t.setAttribute("fill",w),a.appendChild(t)}if("none"!==k){const t=document.createElementNS(h.XMLNS,"text");t.textContent=s,t.setAttribute("x",e.toString(10)),t.setAttribute("y",(u+m+l).toString(10)),t.setAttribute("text-anchor","middle"),t.setAttribute("stroke","none"),t.setAttribute("fill",k),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}));switch(this.type){case"float":for(let t=i;t<=r;t+=10){const e=`${t}dB`,s=p,i=Math.trunc(-1*(t-r)/n*m)+u;if("none"!==w){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",s.toString(10)),t.setAttribute("y",i.toString(10)),t.setAttribute("width",f.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",w),a.appendChild(t)}if("none"!==w){const t=document.createElementNS(h.XMLNS,"text");t.textContent=e,t.setAttribute("x",s.toString(10)),t.setAttribute("y",(i-Math.trunc(A/4)).toString(10)),t.setAttribute("text-anchor","end"),t.setAttribute("stroke","none"),t.setAttribute("fill",k),t.setAttribute("font-family",this.styles.font?.family??"Arial"),t.setAttribute("font-size",A.toString(10)),t.setAttribute("font-style",this.styles.font?.style??"normal"),t.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(t)}}break;case"uint":for(const t of["0.00","0.25","0.50","0.75","1.00"]){const e=p,s=(1-Number(t))*m+u;if("none"!==w){const t=document.createElementNS(h.XMLNS,"rect");t.setAttribute("x",e.toString(10)),t.setAttribute("y",s.toString(10)),t.setAttribute("width",f.toString(10)),t.setAttribute("height","1"),t.setAttribute("stroke","none"),t.setAttribute("fill",w),a.appendChild(t)}if("none"!==k){const i=document.createElementNS(h.XMLNS,"text");i.textContent=t,i.setAttribute("x",e.toString(10)),i.setAttribute("y",(s-Math.trunc(A/4)).toString(10)),i.setAttribute("text-anchor","end"),i.setAttribute("stroke","none"),i.setAttribute("fill",k),i.setAttribute("font-family",this.styles.font?.family??"Arial"),i.setAttribute("font-size",A.toString(10)),i.setAttribute("font-style",this.styles.font?.style??"normal"),i.setAttribute("font-weight",this.styles.font?.weight??"normal"),a.appendChild(i)}}}}}}class c{analyser;input;timeOverviewL;timeOverviewR;time;fft;timeDomainAnimationId=null;timeDomainTimerId=null;frequencyDomainAnimationId=null;frequencyDomainTimerId=null;constructor(t){this.analyser=t.createAnalyser(),this.input=t.createGain(),this.input.connect(this.analyser),this.timeOverviewL=new a(t.sampleRate,0),this.timeOverviewR=new a(t.sampleRate,1),this.time=new o(t.sampleRate,0),this.fft=new h(t.sampleRate,0),this.analyser.fftSize=2048,this.analyser.minDecibels=-100,this.analyser.maxDecibels=-30,this.analyser.smoothingTimeConstant=.8}start(t,e,s){switch(t){case"timeoverview":if((0===e||1===e)&&s)switch(e){case 0:if(s.numberOfChannels>e){const t=new Float32Array(s.length);t.set(s.getChannelData(e)),this.timeOverviewL.start(t)}break;case 1:if(s.numberOfChannels>e){const t=new Float32Array(s.length);t.set(s.getChannelData(e)),this.timeOverviewR.start(t)}}break;case"time":{const e=this.time.param("interval");switch(this.time.param("type")){case"uint":{const t=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(t),this.time.start(t);break}case"float":{const t=new Float32Array(this.analyser.fftSize);this.analyser.getFloatTimeDomainData(t),this.time.start(t);break}}"number"==typeof e&&(this.stop(t),e<0?this.timeDomainAnimationId=window.requestAnimationFrame((()=>{this.start(t)})):this.timeDomainTimerId=window.setTimeout((()=>{this.start(t)}),e));break}case"fft":{const e=this.fft.param("interval");switch(this.fft.param("type")){case"uint":{const t=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(t),this.fft.start(t);break}case"float":{const t=new Float32Array(this.analyser.frequencyBinCount);this.analyser.getFloatFrequencyData(t),this.fft.start(t,this.analyser.minDecibels,this.analyser.maxDecibels);break}}"number"==typeof e&&(this.stop(t),e<0?this.frequencyDomainAnimationId=window.requestAnimationFrame((()=>{this.start(t)})):this.frequencyDomainTimerId=window.setTimeout((()=>{this.start(t)}),e));break}}return this}stop(t){switch(t){case"time":{const t=this.time.param("interval");"number"==typeof t&&(t<0&&this.timeDomainAnimationId?(window.cancelAnimationFrame(this.timeDomainAnimationId),this.timeDomainAnimationId=null):this.timeDomainTimerId&&(window.clearTimeout(this.timeDomainTimerId),this.timeDomainTimerId=null));break}case"fft":{const t=this.fft.param("interval");"number"==typeof t&&(t<0&&this.frequencyDomainAnimationId?(window.cancelAnimationFrame(this.frequencyDomainAnimationId),this.frequencyDomainAnimationId=null):this.frequencyDomainTimerId&&(window.clearTimeout(this.frequencyDomainTimerId),this.frequencyDomainTimerId=null));break}}return this}param(t){if("string"==typeof t)switch(t){case"fftSize":return this.analyser.fftSize;case"frequencyBinCount":return this.analyser.frequencyBinCount;case"minDecibels":return this.analyser.minDecibels;case"maxDecibels":return this.analyser.maxDecibels;case"smoothingTimeConstant":return this.analyser.smoothingTimeConstant}for(const[e,s]of Object.entries(t))switch(e){case"fftSize":this.analyser.fftSize=s;break;case"minDecibels":this.analyser.minDecibels=s;break;case"maxDecibels":this.analyser.maxDecibels=s;break;case"smoothingTimeConstant":this.analyser.smoothingTimeConstant=s}return this}domain(t,e){switch(t){case"timeoverview":switch(e){case 0:return this.timeOverviewL;case 1:return this.timeOverviewR}return this;case"time":return this.time;case"fft":return this.fft}return this}get(){return this.analyser}get INPUT(){return this.input}get OUTPUT(){return this.input}}class u{id;dataBlocks=[];constructor(t){this.id=t}get(){return this.dataBlocks}append(t){return this.dataBlocks.push(t),this}clear(){this.dataBlocks.length=0}has(){return this.dataBlocks.length>0}toString(){return this.id}}class l{id;frames=[];channelGain=1;constructor(t){this.id=t}append(t){return this.frames.push(t),this}get(t){return"number"==typeof t&&t>=0&&t<this.frames.length?this.frames[t]:this.frames}gain(t){if(!("number"==typeof t&&t>=0&&t<=1))return this.channelGain;this.channelGain=t}length(){return this.frames.length}toString(){return this.id}}class RecorderProcessor extends AudioWorkletProcessor{static BUFFER_SIZE=128;constructor(){super()}process(t){if(0===t.length||0===t[0].length)return!0;const e={inputs:t};return this.port.postMessage(e),!0}}class p{processor;sampleRate;channels=[];activeTrack=-1;paused=!0;constructor(t){this.processor=new AudioWorkletNode(t,RecorderProcessor.name),this.sampleRate=t.sampleRate,this.processor.port.onmessage=t=>{if(-1===this.activeTrack)return;if(0===t.data.inputs.length)return;const e=t.data.inputs[0];if(0===e.length)return;const s=RecorderProcessor.BUFFER_SIZE;if(1===e.length){const t=e[0],i=this.channels[0].gain(),r=this.channels[0].get(this.activeTrack),n=new Float32Array(s);for(let e=0;e<s;e++)n[e]=i*t[e];return void r?.append(n)}const i=e[0],r=e[1],n=this.channels[0].gain(),a=this.channels[1].gain(),o=this.channels[0].get(this.activeTrack),h=this.channels[1].get(this.activeTrack),c=new Float32Array(s),u=new Float32Array(s);for(let t=0;t<s;t++)c[t]=n*i[t],u[t]=a*r[t];o?.append(c),h?.append(u)}}setup(t,e){this.channels.push(new l("0")),this.channels.push(new l("1"));for(const t of this.channels)for(let s=0;s<e;s++)t.append(new u(s.toString(10)));return this}ready(t){return this.hasTrack(t)?this.activeTrack=t:this.activeTrack=-1,this}start(){return-1!==this.activeTrack&&this.paused?(this.paused=!1,this):this}stop(){return this.activeTrack=-1,this.paused=!0,this.processor.disconnect(0),this}param(t){if("string"==typeof t)switch(t){case"0":if(this.channels[0])return this.channels[0].gain();break;case"1":if(this.channels[1])return this.channels[1].gain()}for(const[e,s]of Object.entries(t))switch(e){case"0":this.channels[0]&&"number"==typeof s&&this.channels[0].gain(s);break;case"1":this.channels[1]&&"number"==typeof s&&this.channels[1].gain(s)}return this}get(){return this.activeTrack}clear(t){if(-1!==this.activeTrack&&this.stop(),-1===t)for(const t of this.channels){const e=t.get();for(const t of e)t.clear()}else if(this.hasTrack(t))for(const e of this.channels){const s=e.get(t);s?.clear()}return this}create(t,e,s,i){-1!==this.activeTrack&&this.stop();let r=null,n=null;if(-1===t&&this.has(-1,-1))r=this.mixTrack(0),n=this.mixTrack(1);else{if(!this.has(0,t)||!this.has(1,t))return"";r=this.flatTrack(0,t),n=this.flatTrack(1,t)}if(null===r||null===n)return"";const a=this.sampleRate,o=s,h=e,c=h*Math.min(r.length,n.length),u=36+(8+c*(o/8)),l=u-8,p=a*h*(o/8),d=c*(o/8);let f=null;switch(o){case 8:f=new Uint8Array(c);for(let t=0;t<c;t++){let e=0;e=t%h==0?Math.round((r[Math.trunc(t/h)]+1)/2*255):Math.round((n[Math.trunc(t/h)]+1)/2*255),e>255&&(e=255),e<0&&(e=0),f[t]=e}break;case 16:f=new Int16Array(c);for(let t=0;t<c;t++){let e=0;e=t%h==0?Math.round(32768*r[Math.trunc(t/h)]):Math.round(32768*n[Math.trunc(t/h)]),e>32767&&(e=32767),e<-32768&&(e=-32768),f[t]=e}}if(null===f)return"";const m=new Uint8Array(u);m[0]=82,m[1]=73,m[2]=70,m[3]=70,m[4]=255&l,m[5]=l>>8&255,m[6]=l>>16&255,m[7]=l>>24&255,m[8]=87,m[9]=65,m[10]=86,m[11]=69,m[12]=102,m[13]=109,m[14]=116,m[15]=32,m[16]=16,m[17]=0,m[18]=0,m[19]=0,m[20]=1,m[21]=0,m[22]=h,m[23]=0,m[24]=255&a,m[25]=a>>8&255,m[26]=a>>16&255,m[27]=a>>24&255,m[28]=255&p,m[29]=p>>8&255,m[30]=p>>16&255,m[31]=p>>24&255,m[32]=h*(o/8),m[33]=0,m[34]=o,m[35]=0,m[36]=100,m[37]=97,m[38]=116,m[39]=97,m[40]=255&d,m[41]=d>>8&255,m[42]=d>>16&255,m[43]=d>>24&255;for(let t=0;t<c;t++){const e=u-d;switch(o){case 8:m[e+t]=f[t];break;case 16:m[e+2*t+0]=255&f[t],m[e+2*t+1]=f[t]>>8&255}}switch(i){case"base64":case"dataURL":{const t=window.btoa(Array.from(m).map((t=>String.fromCodePoint(t))).join(""));return"base64"===i?t:`data:audio/wav;base64,${t}`}case"blob":case"objectURL":{const t=new Blob([m],{type:"audio/wav"});return"blob"===i?t:window.URL.createObjectURL(t)}}}has(t,e){if(!this.hasChannel(t))return this.channels.some((t=>t.get().some((t=>t.has()))));const s=this.channels[t].get();if(!this.hasTrack(e))return s.some((t=>t.has()));const i=this.channels[t].get(e);return i?.has()??!1}hasChannel(t){return t>=0&&t<this.channels.length}hasTrack(t){return t>=0&&this.channels.every((e=>t<e.length()))}get INPUT(){return this.processor}get OUTPUT(){return this.processor}flatTrack(t,e){if(!this.hasChannel(t)||!this.hasTrack(e))return null;const s=this.channels[t].get(e);if(null===s)return null;const i=s.get(),r=RecorderProcessor.BUFFER_SIZE,n=new Float32Array(i.length*r);for(let t=0,e=i.length;t<e;t++){const e=i[t];for(let s=0;s<r;s++)n[t*r+s]=e[s]}return n}mixTrack(t){if(!this.hasChannel(t))return null;const e=this.channels[t].get(),s=RecorderProcessor.BUFFER_SIZE;let i=0,r=0,n=0,a=0,o=0;for(const t of e){const e=t.get();o<e.length&&(o=e.length)}const h=new Float32Array(o*s);for(;;){for(let t=0,s=e.length;t<s;t++){const s=e[t].get()[n];s&&a>=0&&a<=s.length&&(i+=s[a],r++)}if(r<=0)return h;h[n*s+a]=i/r,i=0,r=0,a<s-1?a++:(n++,a=0)}}}class d{context;input;output;lfo;depth;rate;isActive=!0;paused=!0;constructor(t){this.context=t,this.input=t.createGain(),this.output=t.createGain(),this.lfo=t.createOscillator(),this.depth=t.createGain(),this.rate=this.lfo.frequency}start(t){this.isActive&&this.paused&&(this.lfo.start(t??this.context.currentTime),this.paused=!1)}stop(t,e){if(!this.isActive||this.paused)return;const s=this.lfo.type,i=this.lfo.frequency.value;this.lfo.stop((t??this.context.currentTime)+(e??0)),this.lfo=this.context.createOscillator(),this.lfo.type=s,this.lfo.frequency.value=i,this.rate=this.lfo.frequency,this.paused=!0}toJSON(){return JSON.stringify(this.params())}state(){return this.isActive}activate(){return this.isActive=!0,this.connect(),this.start(0),this}deactivate(){return this.stop(0),this.isActive=!1,this.connect(),this}get INPUT(){return this.input}get OUTPUT(){return this.output}}class f extends d{panner;constructor(t){super(t),this.panner=this.context.createStereoPanner(),this.panner.pan.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.panner.pan)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.panner.pan))}connect(){return this.input.disconnect(0),this.panner.disconnect(0),this.isActive?(this.input.connect(this.panner),this.panner.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class m extends d{shaper;inputShaper;outputShaper;inputLevel;outputLevel;bitsInput;bitsGain;bits=0;constructor(t){super(t),this.shaper=this.context.createWaveShaper(),this.inputShaper=this.context.createWaveShaper(),this.outputShaper=this.context.createWaveShaper(),this.inputLevel=this.context.createGain(),this.outputLevel=this.context.createGain(),this.bitsInput=this.context.createConstantSource(),this.bitsGain=this.context.createGain();const e=new Float32Array(1023);for(let t=0;t<512;t++){const s=(t/512*128|0)/128;e[511+t]=s,e[511-t]=-s}const s=new Float32Array(10),i=new Float32Array(10);for(let t=0,e=64;t<6;t++,e*=.5)s[0+t]=1/64,s[4+t]=1/e,i[0+t]=64,i[4+t]=e;this.shaper.curve=e,this.shaper.oversample="4x",this.inputShaper.curve=s,this.outputShaper.curve=i,this.inputLevel.gain.value=0,this.outputLevel.gain.value=0,this.bitsInput.offset.value=this.bits,this.bitsGain.gain.value=1/8,this.deactivate()}start(t){this.isActive&&this.paused&&(this.bitsInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.bitsInput.stop(this.context.currentTime),this.bitsInput=this.context.createConstantSource(),this.bitsInput.offset.value=this.bits,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.shaper.disconnect(0),this.inputShaper.disconnect(0),this.outputShaper.disconnect(0),this.inputLevel.disconnect(0),this.outputLevel.disconnect(0),this.bitsInput.disconnect(0),this.bitsGain.disconnect(0),this.isActive?(this.input.connect(this.inputLevel),this.inputLevel.connect(this.shaper),this.shaper.connect(this.outputLevel),this.outputLevel.connect(this.output),this.bitsInput.connect(this.bitsGain),this.bitsGain.connect(this.inputShaper),this.inputShaper.connect(this.inputLevel.gain),this.bitsGain.connect(this.outputShaper),this.outputShaper.connect(this.outputLevel.gain)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"bits":return this.bits;case"oversample":return this.shaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"bits":"number"==typeof s&&(this.bits=s,this.bitsInput.offset.value=this.bits);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s))}return this}params(){return{state:this.isActive,bits:this.bits,oversample:this.shaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class v extends d{delay;tone;dry;wet;feedback;depthRate=0;constructor(t){super(t),this.delay=t.createDelay(),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.depth.gain.value=0,this.rate.value=0,this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.depthRate=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime))}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.input.connect(this.dry),this.dry.connect(this.output),this.isActive&&(this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.wet),this.wet.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":case"wet":return this.wet.gain.value;case"dry":return this.dry.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s,this.depth.gain.value=this.delay.delayTime.value*this.depthRate);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.delay.delayTime.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.wet.gain.value=s,this.dry.gain.value=1-this.wet.gain.value);break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,depth:this.depthRate,rate:this.rate.value,mix:this.wet.gain.value,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class g extends d{compressor;constructor(t){super(t),this.compressor=t.createDynamicsCompressor(),this.compressor.threshold.value=-24,this.compressor.knee.value=30,this.compressor.ratio.value=12,this.compressor.attack.value=.003,this.compressor.release.value=.25,this.activate()}connect(){return this.input.disconnect(0),this.compressor.disconnect(0),this.isActive?(this.input.connect(this.compressor),this.compressor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"threshold":return this.compressor.threshold.value;case"knee":return this.compressor.knee.value;case"ratio":return this.compressor.ratio.value;case"attack":return this.compressor.attack.value;case"release":return this.compressor.release.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"threshold":"number"==typeof s&&(this.compressor.threshold.value=s);break;case"knee":"number"==typeof s&&(this.compressor.knee.value=s);break;case"ratio":"number"==typeof s&&(this.compressor.ratio.value=s);break;case"attack":"number"==typeof s&&(this.compressor.attack.value=s);break;case"release":"number"==typeof s&&(this.compressor.release.value=s)}return this}params(){return{state:this.isActive,threshold:this.compressor.threshold.value,knee:this.compressor.knee.value,ratio:this.compressor.ratio.value,attack:this.compressor.attack.value,release:this.compressor.release.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class b extends d{static MAX_DELAY_TIME=5;delay;dry;wet;tone;feedback;constructor(t){super(t),this.delay=t.createDelay(b.MAX_DELAY_TIME),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.isActive?(this.input.connect(this.dry),this.dry.connect(this.output),this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.wet),this.wet.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"dry":return this.dry.gain.value;case"wet":return this.wet.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s);break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class y{static MIN_GAIN=.001;context;generators=[];activeIndexes=[];activeCounter=0;attack=.01;decay=.3;sustain=.5;release=1;isActive=!0;constructor(t){this.context=t}ready(t,e,s){e&&s&&this.generators[t]?(e.connect(this.generators[t]),this.generators[t].connect(s)):e&&null===s&&this.generators[t]?e.connect(this.generators[t]):null===e&&s&&this.generators[t]&&this.generators[t].connect(s),this.activeIndexes[t]=t,this.activeCounter++}start(t){const e=t,s=e+this.attack,i=this.decay,r=this.sustain;for(const t of this.activeIndexes)void 0!==t&&(this.isActive?(this.generators[t].gain.cancelScheduledValues(e),this.generators[t].gain.setValueAtTime(0,e),this.generators[t].gain.linearRampToValueAtTime(1,s),this.generators[t].gain.setTargetAtTime(r,s,i)):this.generators[t].gain.value=1)}stop(t,e){const s=t-this.release,i=s>=this.context.currentTime?s:this.context.currentTime,r=this.release;for(const t of this.activeIndexes)if(void 0!==t)if(this.isActive){if("function"==typeof this.generators[t].gain.cancelAndHoldAtTime)this.generators[t].gain.cancelAndHoldAtTime(i);else{const e=this.generators[t].gain.value;this.generators[t].gain.cancelScheduledValues(i),this.generators[t].gain.setValueAtTime(e,i)}e?this.generators[t].gain.setValueCurveAtTime(new Float32Array([1,.5,.25,0]),i,r):this.generators[t].gain.setTargetAtTime(0,i,r)}else this.generators[t].gain.value=0}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"attack":return this.attack;case"decay":return this.decay;case"sustain":return this.sustain;case"release":return this.release}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"attack":"number"==typeof s&&(this.attack=s);break;case"decay":"number"==typeof s&&(this.decay=s);break;case"sustain":"number"==typeof s&&(this.sustain=s);break;case"release":"number"==typeof s&&(this.release=s)}return this}getGenerator(t){return t>=0&&t<this.generators.length?this.generators[t]:null}setGenerator(t){this.generators[t]=this.context.createGain()}paused(){let t=0;for(const e of this.activeIndexes)if(void 0!==e){if(this.generators[e].gain.value>y.MIN_GAIN)return!1;if(t++,t===this.activeCounter)return!0}return!1}clear(t){this.activeIndexes.length=0,this.activeCounter=0;for(const e of this.generators)e.gain.cancelScheduledValues(this.context.currentTime),e.gain.value=1,t&&e.disconnect(0)}params(){return{state:this.isActive,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release}}toJSON(){return JSON.stringify(this.params())}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}}class w extends d{bass;middle;treble;presence;constructor(t){super(t),this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.presence=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.presence.type="highshelf",this.bass.frequency.value=500,this.middle.frequency.value=1e3,this.treble.frequency.value=2e3,this.presence.frequency.value=4e3,this.bass.Q.value=Math.SQRT1_2,this.middle.Q.value=Math.SQRT1_2,this.treble.Q.value=Math.SQRT1_2,this.presence.Q.value=Math.SQRT1_2,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.presence.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.bass.disconnect(0),this.middle.disconnect(0),this.treble.disconnect(0),this.presence.disconnect(0),this.isActive?(this.input.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.presence),this.presence.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"presence":return this.presence.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"presence":"number"==typeof s&&(this.presence.gain.value=s)}return this}params(){return{state:this.isActive,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,presence:this.presence.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class k extends d{filter;maxFrequency;range=.1;attack=.01;decay=.3;sustain=1;release=1;constructor(t){super(t),this.filter=t.createBiquadFilter(),this.filter.type="lowpass",this.filter.frequency.value=350,this.filter.Q.value=1,this.filter.gain.value=0,this.maxFrequency=this.filter.frequency.value,this.deactivate()}start(t){if(!this.isActive)return;const e=t??this.context.currentTime,s=e+this.attack,i=this.decay,r=this.sustain*this.maxFrequency,n=this.maxFrequency*this.range;this.filter.frequency.cancelScheduledValues(e),this.filter.frequency.setValueAtTime(n,e),this.filter.frequency.linearRampToValueAtTime(this.maxFrequency,s),this.filter.frequency.setTargetAtTime(r,s,i)}stop(t){if(!this.isActive)return;const e=t??this.context.currentTime,s=this.release,i=this.maxFrequency*this.range;if("function"==typeof this.filter.frequency.cancelAndHoldAtTime)this.filter.frequency.cancelAndHoldAtTime(e);else{const t=this.filter.frequency.value;this.filter.frequency.cancelScheduledValues(e),this.filter.frequency.setValueAtTime(t,e)}this.filter.frequency.setTargetAtTime(i,e,s)}connect(){return this.input.disconnect(0),this.filter.disconnect(0),this.isActive?(this.input.connect(this.filter),this.filter.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.filter.type;case"frequency":return this.filter.frequency.value;case"Q":return this.filter.Q.value;case"gain":return this.filter.gain.value;case"range":return this.range;case"attack":return this.attack;case"decay":return this.decay;case"sustain":return this.sustain;case"release":return this.release}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.filter.type=s);break;case"frequency":"number"==typeof s&&(this.filter.frequency.value=s,this.maxFrequency=s);break;case"Q":"number"==typeof s&&(this.filter.Q.value=s);break;case"gain":"number"==typeof s&&(this.filter.gain.value=s);break;case"range":"number"==typeof s&&(this.range=s);break;case"attack":"number"==typeof s&&(this.attack=s);break;case"decay":"number"==typeof s&&(this.decay=s);break;case"sustain":"number"==typeof s&&(this.sustain=s);break;case"release":"number"==typeof s&&(this.release=s)}return this}params(){return{state:this.isActive,type:this.filter.type,frequency:this.filter.frequency.value,Q:this.filter.Q.value,gain:this.filter.gain.value,range:this.range,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release}}activate(){return this.isActive=!0,this.connect(),this}deactivate(){return this.isActive=!1,this.connect(),this}}class A extends d{delay;tone;dry;wet;feedback;depthRate=0;constructor(t){super(t),this.delay=t.createDelay(),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.feedback=t.createGain(),this.delay.delayTime.value=0,this.depth.gain.value=0,this.rate.value=0,this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.feedback.gain.value=0,this.depthRate=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.delay.delayTime))}connect(){return this.input.disconnect(0),this.delay.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.feedback.disconnect(0),this.input.connect(this.dry),this.dry.connect(this.output),this.isActive&&(this.input.connect(this.tone),this.tone.connect(this.delay),this.delay.connect(this.wet),this.wet.connect(this.output),this.delay.connect(this.feedback),this.feedback.connect(this.delay)),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delay.delayTime.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":case"wet":return this.wet.gain.value;case"dry":return this.dry.gain.value;case"tone":return this.tone.frequency.value;case"feedback":return this.feedback.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"time":"number"==typeof s&&(this.delay.delayTime.value=s,this.depth.gain.value=this.delay.delayTime.value*this.depthRate);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.delay.delayTime.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.wet.gain.value=s,this.dry.gain.value=1-this.wet.gain.value);break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s);break;case"feedback":"number"==typeof s&&(this.feedback.gain.value=s)}return this}params(){return{state:this.isActive,time:this.delay.delayTime.value,depth:this.depthRate,rate:this.rate.value,mix:this.wet.gain.value,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value,feedback:this.feedback.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class x extends d{positiveShaper;negativeShaper;positiveInputGain;negativeInputGain;positiveOutputGain;negativeOutputGain;outFilter;driveInput;level;drive=0;constructor(t){super(t),this.positiveShaper=this.context.createWaveShaper(),this.negativeShaper=this.context.createWaveShaper(),this.positiveInputGain=this.context.createGain(),this.negativeInputGain=this.context.createGain(),this.positiveOutputGain=this.context.createGain(),this.negativeOutputGain=this.context.createGain(),this.driveInput=this.context.createConstantSource(),this.outFilter=this.context.createBiquadFilter(),this.level=this.context.createGain();const e=new Float32Array(1024);for(let t=0;t<512;t++){const s=.5*Math.tanh(4*t/512),i=1-t/512;e[512+t]=s,e[511-t]=s*i**4}this.positiveShaper.curve=e,this.negativeShaper.curve=e,this.positiveShaper.oversample="4x",this.negativeShaper.oversample="4x",this.positiveInputGain.gain.value=1,this.negativeInputGain.gain.value=-1,this.positiveOutputGain.gain.value=1,this.negativeOutputGain.gain.value=-1,this.driveInput.offset.value=this.drive,this.outFilter.type="highpass",this.outFilter.frequency.value=80,this.outFilter.Q.value=1,this.outFilter.gain.value=0,this.level.gain.value=1,this.deactivate()}start(t){this.isActive&&this.paused&&(this.driveInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.driveInput.stop(this.context.currentTime),this.driveInput=this.context.createConstantSource(),this.driveInput.offset.value=this.drive,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.positiveShaper.disconnect(0),this.negativeShaper.disconnect(0),this.positiveInputGain.disconnect(0),this.negativeInputGain.disconnect(0),this.positiveOutputGain.disconnect(0),this.negativeOutputGain.disconnect(0),this.driveInput.disconnect(0),this.outFilter.disconnect(0),this.level.disconnect(0),this.isActive?(this.input.connect(this.positiveInputGain),this.positiveInputGain.connect(this.positiveShaper),this.positiveShaper.connect(this.positiveOutputGain),this.positiveOutputGain.connect(this.outFilter),this.input.connect(this.negativeInputGain),this.negativeInputGain.connect(this.negativeShaper),this.negativeShaper.connect(this.negativeOutputGain),this.negativeOutputGain.connect(this.outFilter),this.driveInput.connect(this.negativeOutputGain.gain),this.outFilter.connect(this.level),this.level.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"drive":return this.drive;case"level":return this.level.gain.value;case"oversample":return this.positiveShaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"drive":"number"==typeof s&&(this.drive=s,this.driveInput.offset.value=this.drive);break;case"level":"number"==typeof s&&(this.level.gain.value=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.positiveShaper.oversample=s,this.negativeShaper.oversample=s))}return this}params(){return{state:this.isActive,drive:this.drive,level:this.level.gain.value,oversample:this.positiveShaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class T extends d{listener;positions;forwards;ups;constructor(t){super(t),this.listener=t.listener,this.positions={x:0,y:0,z:0},this.forwards={x:0,y:0,z:-1},this.ups={x:0,y:1,z:0},this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z),this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z)}connect(){return this.output}param(t){if("string"==typeof t)switch(t){case"x":return this.positions.x;case"y":return this.positions.y;case"z":return this.positions.z;case"fx":return this.forwards.x;case"fy":return this.forwards.y;case"fz":return this.forwards.z;case"ux":return this.ups.x;case"uy":return this.ups.y;case"uz":return this.ups.z}for(const[e,s]of Object.entries(t))switch(e){case"x":"number"==typeof s&&(this.positions.x=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"y":"number"==typeof s&&(this.positions.y=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"z":"number"==typeof s&&(this.positions.z=s,this.listener.setPosition(this.positions.x,this.positions.y,this.positions.z));break;case"fx":"number"==typeof s&&(this.forwards.x=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"fy":"number"==typeof s&&(this.forwards.y=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"fz":"number"==typeof s&&(this.forwards.z=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"ux":"number"==typeof s&&(this.ups.x=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"uy":"number"==typeof s&&(this.ups.y=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z));break;case"uz":"number"==typeof s&&(this.ups.z=s,this.listener.setOrientation(this.forwards.x,this.forwards.y,this.forwards.z,this.ups.x,this.ups.y,this.ups.z))}return this}params(){return{x:this.positions.x,y:this.positions.y,z:this.positions.z,fx:this.forwards.x,fy:this.forwards.y,fz:this.forwards.z,ux:this.ups.x,uy:this.ups.y,uz:this.ups.z}}}class NoiseGateProcessor extends AudioWorkletProcessor{level=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"level":"number"==typeof s&&(this.level=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;const r=s[0].length;for(let t=0,e=s.length;t<e;t++)for(let e=0;e<r;e++)i[t][e]=this.gate(s[t][e]);return!0}gate(t){return this.isActive?Math.abs(t)>this.level?t:0:t}}class S extends d{processor;level=0;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,NoiseGateProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"level":return this.level}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"level":if("number"==typeof s){this.level=s;const t={level:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,level:this.level}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class NoiseSuppressorProcessor extends AudioWorkletProcessor{static FFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}}static IFFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s}threshold=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"threshold":"number"==typeof s&&(this.threshold=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;const r=s[0].length;for(let t=0,e=s.length;t<e;t++)this.suppress(s[t],i[t],r);return!0}suppress(t,e,s){if(!this.isActive||0===this.threshold)return void e.set(t);const i=new Float32Array(t),r=new Float32Array(s),n=new Float32Array(s),a=new Float32Array(s),o=new Float32Array(s),h=new Float32Array(s);NoiseSuppressorProcessor.FFT(i,r,s);for(let t=0;t<s;t++)o[t]=Math.sqrt(i[t]**2+r[t]**2),0!==i[t]&&0!==r[t]&&(h[t]=Math.atan2(r[t],i[t]));for(let t=0;t<s;t++)o[t]-=this.threshold,o[t]<0&&(o[t]=0);for(let t=0;t<s;t++)n[t]=o[t]*Math.cos(h[t]),a[t]=o[t]*Math.sin(h[t]);NoiseSuppressorProcessor.IFFT(n,a,s),e.set(n)}}class E extends d{processor;threshold=0;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,NoiseSuppressorProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"threshold":return this.threshold}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"threshold":if("number"==typeof s&&s>=0){this.threshold=s;const t={threshold:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,threshold:this.threshold}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class M extends d{shaper;inputShaper;outputShaper;inputGain;outputGain;driveInput;level;drive=0;constructor(t){super(t),this.shaper=this.context.createWaveShaper(),this.inputShaper=this.context.createWaveShaper(),this.outputShaper=this.context.createWaveShaper(),this.inputGain=this.context.createGain(),this.outputGain=this.context.createGain(),this.driveInput=this.context.createConstantSource(),this.level=this.context.createGain();const e=new Float32Array(1024);for(let t=0;t<512;t++){const s=.5*Math.tanh(4*t/512);e[512+t]=s,e[511-t]=-s}const s=new Float32Array(101);for(let t=0;t<101;t++)s[t]=.25;for(let t=52,e=.25;t<101;t++,e*=1.1)s[t]=e;const i=new Float32Array([2,2,2,2,2,.9,.5,.35,.3]);this.shaper.curve=e,this.shaper.oversample="4x",this.inputShaper.curve=s,this.outputShaper.curve=i,this.inputGain.gain.value=0,this.outputGain.gain.value=0,this.driveInput.offset.value=this.drive,this.level.gain.value=1,this.deactivate()}start(t){this.isActive&&this.paused&&(this.driveInput.start(this.context.currentTime),this.paused=!1)}stop(t,e){this.isActive&&!this.paused&&(this.driveInput.stop(this.context.currentTime),this.driveInput=this.context.createConstantSource(),this.driveInput.offset.value=this.drive,this.paused=!0,this.connect())}connect(){return this.input.disconnect(0),this.shaper.disconnect(0),this.inputShaper.disconnect(0),this.outputShaper.disconnect(0),this.inputGain.disconnect(0),this.outputGain.disconnect(0),this.driveInput.disconnect(0),this.level.disconnect(0),this.isActive?(this.input.connect(this.inputGain),this.inputGain.connect(this.shaper),this.shaper.connect(this.outputGain),this.outputGain.connect(this.level),this.level.connect(this.output),this.driveInput.connect(this.inputShaper),this.inputShaper.connect(this.inputGain.gain),this.driveInput.connect(this.outputShaper),this.outputShaper.connect(this.outputGain.gain)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"drive":return this.drive;case"level":return this.level.gain.value;case"oversample":return this.shaper.oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"drive":"number"==typeof s&&(this.drive=s,this.driveInput.offset.value=this.drive);break;case"level":"number"==typeof s&&(this.level.gain.value=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s))}return this}params(){return{state:this.isActive,drive:this.drive,level:this.level.gain.value,oversample:this.shaper.oversample}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class F extends d{panner;positions;orientations;constructor(t){super(t),this.panner=t.createPanner(),this.positions={x:0,y:0,z:0},this.orientations={x:1,y:0,z:0},this.panner.refDistance=1,this.panner.maxDistance=1e4,this.panner.rolloffFactor=1,this.panner.coneInnerAngle=360,this.panner.coneOuterAngle=360,this.panner.coneOuterGain=0,this.panner.panningModel="HRTF",this.panner.distanceModel="inverse",this.panner.positionX.value=this.positions.x,this.panner.positionY.value=this.positions.y,this.panner.positionZ.value=this.positions.z,this.panner.orientationX.value=this.orientations.x,this.panner.orientationY.value=this.orientations.y,this.panner.orientationZ.value=this.orientations.z,this.deactivate()}connect(){return this.input.disconnect(0),this.panner.disconnect(0),this.isActive?(this.input.connect(this.panner),this.panner.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"x":return this.panner.positionX.value;case"y":return this.panner.positionY.value;case"z":return this.panner.positionZ.value;case"ox":return this.panner.orientationX.value;case"oy":return this.panner.orientationY.value;case"oz":return this.panner.orientationZ.value;case"refDistance":return this.panner.refDistance;case"maxDistance":return this.panner.maxDistance;case"rolloffFactor":return this.panner.rolloffFactor;case"coneInnerAngle":return this.panner.coneInnerAngle;case"coneOuterAngle":return this.panner.coneOuterAngle;case"coneOuterGain":return this.panner.coneOuterGain;case"panningModel":return this.panner.panningModel;case"distanceModel":return this.panner.distanceModel}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"x":"number"==typeof s&&(this.panner.positionX.value=s);break;case"y":"number"==typeof s&&(this.panner.positionY.value=s);break;case"z":"number"==typeof s&&(this.panner.positionZ.value=s);break;case"ox":"number"==typeof s&&(this.panner.orientationX.value=s);break;case"oy":"number"==typeof s&&(this.panner.orientationY.value=s);break;case"oz":"number"==typeof s&&(this.panner.orientationZ.value=s);break;case"refDistance":"number"==typeof s&&(this.panner.refDistance=s);break;case"maxDistance":"number"==typeof s&&(this.panner.maxDistance=s);break;case"rolloffFactor":"number"==typeof s&&(this.panner.rolloffFactor=s);break;case"coneInnerAngle":"number"==typeof s&&(this.panner.coneInnerAngle=s);break;case"coneOuterAngle":"number"==typeof s&&(this.panner.coneOuterAngle=s);break;case"coneOuterGain":"number"==typeof s&&(this.panner.coneOuterGain=s);break;case"panningModel":"HRTF"!==s&&"equalpower"!==s||(this.panner.panningModel=s);break;case"distanceModel":"linear"!==s&&"inverse"!==s&&"exponential"!==s||(this.panner.distanceModel=s)}return this}params(){return{state:this.isActive,x:this.positions.x,y:this.positions.y,z:this.positions.z,ox:this.orientations.x,oy:this.orientations.y,oz:this.orientations.z,refDistance:this.panner.refDistance,maxDistance:this.panner.maxDistance,rolloffFactor:this.panner.rolloffFactor,coneInnerAngle:this.panner.coneInnerAngle,coneOuterAngle:this.panner.coneOuterAngle,coneOuterGain:this.panner.coneOuterGain,panningModel:this.panner.panningModel,distanceModel:this.panner.distanceModel}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class N extends d{static MAX_STAGES=24;numberOfStages=12;filters=[];dry;wet;depthRate=0;constructor(t){super(t);for(let e=0;e<N.MAX_STAGES;e++){const e=t.createBiquadFilter();e.type="allpass",e.frequency.value=350,e.Q.value=1,e.gain.value=0,this.filters.push(e)}this.dry=t.createGain(),this.wet=t.createGain(),this.depth.gain.value=0,this.rate.value=0,this.dry.gain.value=1,this.wet.gain.value=0,this.deactivate(),this.lfo.connect(this.depth);for(let t=0;t<N.MAX_STAGES;t++)this.depth.connect(this.filters[t].frequency)}stop(t,e){if(super.stop(t,e),this.isActive){this.lfo.connect(this.depth);for(let t=0;t<N.MAX_STAGES;t++)this.depth.connect(this.filters[t].frequency)}}connect(){this.input.disconnect(0);for(let t=0;t<N.MAX_STAGES;t++)this.filters[t].disconnect(0);if(this.dry.disconnect(0),this.wet.disconnect(0),this.input.connect(this.dry),this.dry.connect(this.output),this.isActive&&this.numberOfStages>0){this.input.connect(this.filters[0]);for(let t=0;t<this.numberOfStages;t++)t<this.numberOfStages-1?this.filters[t].connect(this.filters[t+1]):(this.filters[t].connect(this.wet),this.wet.connect(this.output))}return this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"stage":return this.numberOfStages;case"frequency":return this.filters[0].frequency.value;case"resonance":return this.filters[0].Q.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"mix":case"wet":return this.wet.gain.value;case"dry":return this.dry.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"stage":switch(s){case 0:case 2:case 4:case 8:case 12:case 24:this.numberOfStages=s,this.connect()}break;case"frequency":if("number"==typeof s){for(const t of this.filters)t.frequency.value=s;this.depth.gain.value=s*this.depthRate}break;case"resonance":if("number"==typeof s)for(const t of this.filters)t.Q.value=s;break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.filters[0].frequency.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"mix":"number"==typeof s&&(this.wet.gain.value=s,this.dry.gain.value=1-this.wet.gain.value);break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s)}return this}params(){return{state:this.isActive,stage:this.numberOfStages,frequency:this.filters[0].frequency.value,resonance:this.filters[0].Q.value,depth:this.depthRate,rate:this.rate.value,mix:this.wet.gain.value,dry:this.dry.gain.value,wet:this.wet.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class PitchShifterProcessor extends AudioWorkletProcessor{static GAIN_CORRECTION=2;static FFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}}static IFFT(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s}isActive=!0;pitch=1;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"pitch":"number"==typeof s&&(this.pitch=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(this.isActive){const t=s[0].length;for(let e=0,r=s.length;e<r;e++)this.shift(s[e],i[e],t)}else i[0].set(s[0]),i[1].set(s[1]);return!0}shift(t,e,s){if(1===this.pitch)return void e.set(t);const i=new Float32Array(t),r=new Float32Array(s);PitchShifterProcessor.FFT(i,r,s);const n=new Float32Array(s),a=new Float32Array(s);for(let t=0;t<s;t++){const e=Math.trunc(this.pitch*t);let o=1;t>s/2&&(o=0),e>=0&&e<s&&(n[e]+=PitchShifterProcessor.GAIN_CORRECTION*o*i[t],a[e]+=PitchShifterProcessor.GAIN_CORRECTION*o*r[t])}PitchShifterProcessor.IFFT(n,a,s),e.set(n)}}class O extends d{processor;pitch=1;constructor(t){super(t),this.processor=new AudioWorkletNode(this.context,PitchShifterProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pitch":return this.pitch}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"pitch":if("number"==typeof s&&s>0){this.pitch=s;const t={pitch:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,pitch:this.pitch}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class R extends d{lowpass;notch;constructor(t){super(t),this.lowpass=t.createBiquadFilter(),this.notch=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=3200,this.lowpass.Q.value=6,this.lowpass.gain.value=0,this.notch.type="notch",this.notch.frequency.value=8e3,this.notch.Q.value=1,this.notch.gain.value=0,this.activate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.notch),this.notch.connect(this.lowpass),this.lowpass.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t&&"state"===t)return this.isActive;for(const[e,s]of Object.entries(t))if("state"===e)"boolean"==typeof s&&(s?this.activate():this.deactivate())}params(){return{state:this.isActive}}}class I extends d{shaper;preGain;leadGain;lowpass;highpass1;highpass2;highpass3;constructor(t){super(t),this.shaper=t.createWaveShaper(),this.preGain=t.createGain(),this.leadGain=t.createGain(),this.lowpass=t.createBiquadFilter(),this.highpass1=t.createBiquadFilter(),this.highpass2=t.createBiquadFilter(),this.highpass3=t.createBiquadFilter(),this.shaper.oversample="4x",this.preGain.gain.value=.5,this.leadGain.gain.value=.5,this.lowpass.type="lowpass",this.lowpass.frequency.value=3200,this.lowpass.Q.value=-3,this.lowpass.gain.value=0,this.highpass1.type="highpass",this.highpass1.frequency.value=80,this.highpass1.Q.value=-3,this.highpass1.gain.value=0,this.highpass2.type="highpass",this.highpass2.frequency.value=640,this.highpass2.Q.value=-3,this.highpass2.gain.value=0,this.highpass3.type="highpass",this.highpass3.frequency.value=80,this.highpass3.Q.value=-3,this.highpass3.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.highpass1),this.highpass1.connect(this.preGain),this.preGain.connect(this.highpass3),this.input.connect(this.highpass2),this.highpass2.connect(this.leadGain),this.leadGain.connect(this.highpass3),this.highpass3.connect(this.shaper),this.shaper.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"curve":case"oversample":return this.shaper.curve;case"gain":return this.preGain.gain.value;case"lead":return this.leadGain.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"curve":"number"!=typeof s&&"boolean"!=typeof s&&(s instanceof Float32Array||null===s)&&(this.shaper.curve=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s));break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"lead":"number"==typeof s&&(this.leadGain.gain.value=s)}}params(){return{state:this.isActive,curve:this.shaper.curve,gain:this.preGain.gain.value,lead:this.leadGain.gain.value,oversample:this.shaper.oversample}}}class C extends d{shaper;bass;middle;treble;lowpass;highpass;constructor(t){super(t),this.shaper=t.createWaveShaper(),this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.shaper.oversample="4x",this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=240,this.middle.frequency.value=500,this.treble.frequency.value=1600,this.bass.Q.value=Math.SQRT1_2,this.middle.Q.value=Math.SQRT1_2,this.treble.Q.value=Math.SQRT1_2,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.lowpass=t.createBiquadFilter(),this.highpass=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=2e4,this.lowpass.Q.value=-3,this.lowpass.gain.value=0,this.highpass.type="highpass",this.highpass.frequency.value=40,this.highpass.Q.value=-3,this.highpass.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.lowpass),this.lowpass.connect(this.highpass),this.highpass.connect(this.shaper),this.shaper.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"curve":return this.shaper.curve;case"oversample":return this.shaper.oversample;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"frequency":return this.middle.frequency.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"curve":"number"!=typeof s&&"boolean"!=typeof s&&(s instanceof Float32Array||null===s)&&(this.shaper.curve=s);break;case"oversample":"string"==typeof s&&("none"!==s&&"2x"!==s&&"4x"!==s||(this.shaper.oversample=s));break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"frequency":"number"==typeof s&&(this.middle.frequency.value=s)}}params(){return{state:this.isActive,curve:this.shaper.curve,oversample:this.shaper.oversample,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,frequency:this.middle.frequency.value}}}class q extends d{preEQ;postEQ;cabinet;level=0;numberOfSamples=1024;constructor(t){super(t),this.preEQ=new I(t),this.postEQ=new C(t),this.cabinet=new R(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.postEQ.INPUT),this.postEQ.OUTPUT.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"level":return this.level;case"samples":return this.numberOfSamples;case"pre":return this.preEQ.params();case"post":return this.postEQ.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postEQ.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postEQ.deactivate()));break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);this.preEQ.param({curve:t}),this.postEQ.param({curve:t})}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);this.preEQ.param({curve:t}),this.postEQ.param({curve:t})}break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postEQ.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,level:this.level,samples:this.numberOfSamples,pre:this.preEQ.params(),post:this.postEQ.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class P extends d{preGain;preHighpass;postHighpass;bass;middle;treble;shapers=[];level=0;numberOfSamples=1024;usePostFilters=!0;lowpass;highpass;constructor(t){super(t),this.preGain=t.createGain(),this.preGain.gain.value=.5,this.preHighpass=t.createBiquadFilter(),this.postHighpass=t.createBiquadFilter(),this.preHighpass.type="highpass",this.postHighpass.type="highpass",this.preHighpass.frequency.value=40,this.postHighpass.frequency.value=80,this.preHighpass.Q.value=-3,this.postHighpass.Q.value=-3,this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=160,this.middle.frequency.value=284,this.treble.frequency.value=1200,this.middle.Q.value=1.5,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0;const e=D(this.level,this.numberOfSamples);for(let s=0;s<2;s++)this.shapers[s]=t.createWaveShaper(),this.shapers[s].curve=e,this.shapers[s].oversample="4x";this.lowpass=t.createBiquadFilter(),this.highpass=t.createBiquadFilter(),this.lowpass.type="lowpass",this.highpass.type="highpass",this.lowpass.frequency.value=4e3,this.highpass.frequency.value=40,this.lowpass.Q.value=-3,this.highpass.Q.value=-3,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preGain),this.preGain.connect(this.preHighpass),this.preHighpass.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.postHighpass),this.postHighpass.connect(this.shapers[0]),this.usePostFilters?(this.shapers[0].connect(this.lowpass),this.lowpass.connect(this.highpass),this.highpass.connect(this.shapers[1])):this.shapers[0].connect(this.shapers[1]),this.shapers[1].connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"gain":return this.preGain.gain.value;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"level":return this.level;case"samples":return this.numberOfSamples;case"oversample":return this.shapers[0].oversample;case"postFilters":return this.usePostFilters}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<2;e++)this.shapers[e].curve=t}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<2;e++)this.shapers[e].curve=t}break;case"oversample":if("string"==typeof s&&("none"===s||"2x"===s||"4x"===s))for(let t=0;t<2;t++)this.shapers[t].oversample=s;break;case"postFilters":"boolean"==typeof s&&(this.usePostFilters=s,this.connect())}}params(){return{state:this.isActive,gain:this.preGain.gain.value,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,level:this.level,samples:this.numberOfSamples,oversample:this.shapers[0].oversample,postFilters:this.usePostFilters}}}class U extends d{peakingFilters=[];constructor(t){super(t);for(let e=0;e<5;e++)this.peakingFilters[e]=t.createBiquadFilter(),this.peakingFilters[e].type="peaking",this.peakingFilters[e].gain.value=0;this.peakingFilters[0].frequency.value=100,this.peakingFilters[1].frequency.value=360,this.peakingFilters[2].frequency.value=720,this.peakingFilters[3].frequency.value=1600,this.peakingFilters[4].frequency.value=4800,this.peakingFilters[0].Q.value=1.5,this.peakingFilters[1].Q.value=2,this.peakingFilters[2].Q.value=2,this.peakingFilters[3].Q.value=1.1,this.peakingFilters[4].Q.value=1.2,this.deactivate()}connect(){if(this.input.disconnect(0),this.isActive){this.input.connect(this.peakingFilters[0]);for(let t=0,e=this.peakingFilters.length-1;t<e;t++)this.peakingFilters[t].connect(this.peakingFilters[t+1]);this.peakingFilters[4].connect(this.output)}else this.input.connect(this.output);return this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"fc100":return this.peakingFilters[0].gain.value;case"fc360":return this.peakingFilters[1].gain.value;case"fc720":return this.peakingFilters[2].gain.value;case"fc1600":return this.peakingFilters[3].gain.value;case"fc4800":return this.peakingFilters[4].gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"fc100":"number"==typeof s&&(this.peakingFilters[0].gain.value=s);break;case"fc360":"number"==typeof s&&(this.peakingFilters[1].gain.value=s);break;case"fc720":"number"==typeof s&&(this.peakingFilters[2].gain.value=s);break;case"fc1600":"number"==typeof s&&(this.peakingFilters[3].gain.value=s);break;case"fc4800":"number"==typeof s&&(this.peakingFilters[4].gain.value=s)}}params(){return{state:this.isActive,fc100:this.peakingFilters[0].gain.value,fc360:this.peakingFilters[1].gain.value,fc720:this.peakingFilters[2].gain.value,fc1600:this.peakingFilters[3].gain.value,fc4800:this.peakingFilters[4].gain.value}}}class G extends d{preEQ;postEQ;cabinet;constructor(t){super(t),this.preEQ=new P(t),this.postEQ=new U(t),this.cabinet=new R(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.postEQ.INPUT),this.postEQ.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pre":return this.preEQ.params();case"post":return this.postEQ.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postEQ.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postEQ.deactivate()));break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postEQ.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,pre:this.preEQ.params(),post:this.postEQ.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class z extends d{preGain;highpass;bass;middle;treble;gainEdge;gainBody;gainBottom;shapers=[];iirLowpassFilters=[];iirHighpassFilters=[];mixer;level=0;numberOfSamples=1024;constructor(t){super(t),this.preGain=t.createGain(),this.preGain.gain.value=.5,this.highpass=t.createBiquadFilter(),this.highpass.type="highpass",this.highpass.frequency.value=40,this.highpass.Q.value=1,this.bass=t.createBiquadFilter(),this.middle=t.createBiquadFilter(),this.treble=t.createBiquadFilter(),this.bass.type="lowshelf",this.middle.type="peaking",this.treble.type="highshelf",this.bass.frequency.value=160,this.middle.frequency.value=284,this.treble.frequency.value=1200,this.middle.Q.value=1.5,this.bass.gain.value=0,this.middle.gain.value=0,this.treble.gain.value=0,this.gainEdge=t.createGain(),this.gainBody=t.createGain(),this.gainBottom=t.createGain(),this.gainEdge.gain.value=1,this.gainBody.gain.value=1,this.gainBottom.gain.value=1;const e=D(this.level,this.numberOfSamples);for(let s=0;s<3;s++)this.shapers[s]=t.createWaveShaper(),this.shapers[s].curve=e,this.shapers[s].oversample="4x";const s=220/t.sampleRate*Math.PI,i=220/t.sampleRate*Math.PI,r=new Float32Array([s,s]),n=new Float32Array([i,i]),a=new Float32Array([1+s,-1+s]),o=new Float32Array([1+i,-1+i]),h=new Float32Array([1,-1]),c=new Float32Array([1,-1]),u=new Float32Array([1+s,-1+s]),l=new Float32Array([1+i,-1+i]);this.iirLowpassFilters[0]=t.createIIRFilter(r,a),this.iirLowpassFilters[1]=t.createIIRFilter(n,o),this.iirHighpassFilters[0]=t.createIIRFilter(h,u),this.iirHighpassFilters[1]=t.createIIRFilter(c,l),this.mixer=t.createGain(),this.mixer.gain.value=1,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preGain),this.preGain.connect(this.highpass),this.highpass.connect(this.bass),this.bass.connect(this.middle),this.middle.connect(this.treble),this.treble.connect(this.iirHighpassFilters[1]),this.iirHighpassFilters[1].connect(this.shapers[0]),this.shapers[0].connect(this.gainEdge),this.gainEdge.connect(this.mixer),this.treble.connect(this.iirHighpassFilters[0]),this.iirHighpassFilters[0].connect(this.shapers[1]),this.shapers[1].connect(this.iirLowpassFilters[1]),this.iirLowpassFilters[1].connect(this.gainBody),this.gainBody.connect(this.mixer),this.treble.connect(this.iirLowpassFilters[0]),this.iirLowpassFilters[0].connect(this.shapers[2]),this.shapers[2].connect(this.gainBottom),this.gainBottom.connect(this.mixer),this.mixer.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"gain":return this.preGain.gain.value;case"bass":return this.bass.gain.value;case"middle":return this.middle.gain.value;case"treble":return this.treble.gain.value;case"level":return this.level;case"samples":return this.numberOfSamples;case"oversample":return this.shapers[0].oversample}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"gain":"number"==typeof s&&(this.preGain.gain.value=s);break;case"bass":"number"==typeof s&&(this.bass.gain.value=s);break;case"middle":"number"==typeof s&&(this.middle.gain.value=s);break;case"treble":"number"==typeof s&&(this.treble.gain.value=s);break;case"level":if("number"==typeof s){this.level=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<3;e++)this.shapers[e].curve=t}break;case"samples":if("number"==typeof s){this.numberOfSamples=s;const t=D(this.level,this.numberOfSamples);for(let e=0;e<3;e++)this.shapers[e].curve=t}break;case"oversample":if("string"==typeof s&&("none"===s||"2x"===s||"4x"===s))for(let t=0;t<3;t++)this.shapers[t].oversample=s}}params(){return{state:this.isActive,gain:this.preGain.gain.value,bass:this.bass.gain.value,middle:this.middle.gain.value,treble:this.treble.gain.value,level:this.level,samples:this.numberOfSamples,oversample:this.shapers[0].oversample}}}class _ extends d{cabinet;inch=-1;tilt=!1;speakerFilter;tiltFilter;constructor(t,e){super(t),this.cabinet=e,this.speakerFilter=t.createBiquadFilter(),this.speakerFilter.type="peaking",this.speakerFilter.frequency.value=40,this.speakerFilter.Q.value=-3,this.speakerFilter.gain.value=0,this.tiltFilter=t.createBiquadFilter(),this.tiltFilter.type="highshelf",this.tiltFilter.frequency.value=3200,this.tiltFilter.Q.value=Math.SQRT1_2,this.tiltFilter.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.cabinet.INPUT),this.cabinet.OUTPUT.connect(this.speakerFilter),this.speakerFilter.connect(this.tiltFilter),this.tiltFilter.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"inch":return this.inch;case"tilt":return this.tilt}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?this.activate():this.deactivate());break;case"inch":if("number"==typeof s)switch(s){case-1:this.inch=-1,this.speakerFilter.frequency.value=40,this.speakerFilter.Q.value=Math.SQRT1_2,this.speakerFilter.gain.value=0;break;case 10:this.inch=10,this.speakerFilter.frequency.value=120,this.speakerFilter.Q.value=3,this.speakerFilter.gain.value=9;break;case 12:this.inch=12,this.speakerFilter.frequency.value=80,this.speakerFilter.Q.value=6,this.speakerFilter.gain.value=10;break;case 15:this.inch=15,this.speakerFilter.frequency.value=60,this.speakerFilter.Q.value=9,this.speakerFilter.gain.value=12}break;case"tilt":"boolean"==typeof s&&(this.tilt=s,this.tilt?this.tiltFilter.gain.value=6:this.tiltFilter.gain.value=0)}}params(){return{state:this.isActive,inch:this.inch,tilt:this.tilt}}}class L extends d{preEQ;postFilter;cabinet;constructor(t){super(t),this.cabinet=new R(t),this.preEQ=new z(t),this.postFilter=new _(t,this.cabinet),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.input.connect(this.preEQ.INPUT),this.preEQ.OUTPUT.connect(this.postFilter.INPUT),this.postFilter.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"pre":return this.preEQ.params();case"post":return this.postFilter.params();case"cabinet":return this.cabinet.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preEQ.activate(),this.postFilter.activate()):(this.deactivate(),this.preEQ.deactivate(),this.postFilter.deactivate()));break;case"pre":"object"==typeof s&&this.preEQ.param(s);break;case"post":"object"==typeof s&&this.postFilter.param(s);break;case"cabinet":"object"==typeof s&&this.cabinet.param(s)}return this}params(){return{state:this.isActive,pre:this.preEQ.params(),post:this.postFilter.params(),cabinet:this.cabinet.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}function D(t,e){const s=Math.trunc((e-1)/2),i=new Float32Array(e),r=(10**(t/5-1)-.1)/5+1;let n=.4;1===r?n=1:r>1&&r<1.04&&(n=-15.5*r+16.52);for(let t=0;t<s;t++)i[s+t]=n*(1-r**-t+t*r**-s/s),i[s-t]=n*(-1+r**-t-t*r**-s/s);return i[s]=0,i}class B extends d{type="marshall";preamp;constructor(t){super(t),this.preamp=new q(t),this.deactivate()}connect(){return this.input.disconnect(0),this.isActive?(this.preamp.connect(),this.input.connect(this.preamp.INPUT),this.preamp.OUTPUT.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.type;case"preamp":return this.preamp.params()}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(s?(this.activate(),this.preamp.activate()):(this.deactivate(),this.preamp.deactivate()));break;case"type":if("string"==typeof s){switch(s){case"marshall":this.type="marshall",this.preamp=new q(this.context);break;case"mesa":this.type="mesa",this.preamp=new G(this.context);break;case"fender":this.type="fender",this.preamp=new L(this.context)}this.connect()}break;case"preamp":if("object"==typeof s){if(this.preamp instanceof q){const t=s;this.preamp.param(t)}if(this.preamp instanceof G){const t=s;this.preamp.param(t)}if(this.preamp instanceof L){const t=s;this.preamp.param(t)}}}return this}params(){return{state:this.isActive,type:this.type,preamp:this.preamp.params()}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class Q extends d{convolver;dry;wet;tone;rirs=[];loadError=!1;constructor(t){super(t),this.convolver=t.createConvolver(),this.dry=t.createGain(),this.wet=t.createGain(),this.tone=t.createBiquadFilter(),this.dry.gain.value=1,this.wet.gain.value=0,this.tone.type="lowpass",this.tone.frequency.value=350,this.tone.Q.value=Math.SQRT1_2,this.tone.gain.value=0,this.deactivate()}connect(){return this.input.disconnect(0),this.convolver.disconnect(0),this.dry.disconnect(0),this.wet.disconnect(0),this.tone.disconnect(0),this.isActive?(this.input.connect(this.dry),this.dry.connect(this.output),this.input.connect(this.tone),this.tone.connect(this.convolver),this.convolver.connect(this.wet),this.wet.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"buffer":return this.convolver.buffer;case"dry":return this.dry.gain.value;case"wet":return this.wet.gain.value;case"tone":return this.tone.frequency.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"buffer":"number"==typeof s?s>=0&&s<this.rirs.length&&(this.convolver.buffer=this.rirs[s],this.connect()):s instanceof AudioBuffer?(this.convolver.buffer=s,this.connect()):null===s&&(this.convolver.buffer=null,this.input.disconnect(0),this.input.connect(this.output));break;case"dry":"number"==typeof s&&(this.dry.gain.value=s);break;case"wet":"number"==typeof s&&(this.wet.gain.value=s);break;case"tone":"number"==typeof s&&(this.tone.frequency.value=s)}return this}add(t,e){if(t instanceof AudioBuffer)this.convolver.buffer=t,this.rirs.push(t);else if(t instanceof ArrayBuffer){const s=t=>{this.convolver.buffer=t,this.rirs.push(t)};this.context.decodeAudioData(t,s,e??(()=>{}))}return this}preset(t){const{rirs:e,timeout:s,successCallback:i,errorCallback:r,progressCallback:n}=t;for(let t=0,a=e.length;t<a;t++){const a=e[t];"string"==typeof a?this.load({rir:a,index:t,timeout:s,successCallback:i,errorCallback:r,progressCallback:n}):this.rirs[t]=a}}params(){return{state:this.isActive,dry:this.dry.gain.value,wet:this.wet.gain.value,tone:this.tone.frequency.value}}activate(){return this.isActive=!0,this.connect(),this}deactivate(){return this.isActive=!1,this.connect(),this}load(t){const{rir:e,index:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{!this.loadError&&n&&n(t,"timeout"),this.loadError=!0},o.onprogress=t=>{this.loadError?o.abort():a&&a(t)},o.onerror=t=>{!this.loadError&&n&&n(t,"error"),this.loadError=!0},o.onload=t=>{if(200===o.status){const e=o.response,i=e=>{this.rirs[s]=e;for(const t of this.rirs)if(void 0===t)return;r&&r(t)},a=t=>{n&&n(t,"decode")};this.context.decodeAudioData(e,i,a)}},o.open("GET",e,!0),o.responseType="arraybuffer",o.send(null)}}class $ extends d{amplitude;constructor(t){super(t),this.amplitude=t.createGain(),this.amplitude.gain.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain))}connect(){return this.input.disconnect(0),this.amplitude.disconnect(0),this.isActive?(this.input.connect(this.amplitude),this.amplitude.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class StereoProcessor extends AudioWorkletProcessor{isActive=!1;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))if("state"===e)"boolean"==typeof s&&(this.isActive=s)}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(2!==s.length||2!==i.length)return i[0].set(s[0]),!0;if(this.isActive){const t=s[0].length;for(let e=0;e<t;e++)i[0][e]=s[0][e],i[1][e]=-s[1][e]}else i[0].set(s[0]),i[1].set(s[1]);return!0}}class j extends d{static MAX_DELAY_TIME=1;processor;splitter;merger;delayL;delayR;constructor(t){super(t),this.splitter=t.createChannelSplitter(2),this.merger=t.createChannelMerger(2),this.delayL=t.createDelay(j.MAX_DELAY_TIME),this.delayR=t.createDelay(j.MAX_DELAY_TIME),this.delayL.delayTime.value=0,this.delayR.delayTime.value=0,this.processor=new AudioWorkletNode(this.context,StereoProcessor.name),this.deactivate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.splitter.disconnect(0),this.delayL.disconnect(0),this.delayR.disconnect(0),this.merger.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.splitter),this.splitter.connect(this.delayL,0,0),this.splitter.connect(this.delayR,1,0),this.delayL.connect(this.processor),this.delayR.connect(this.processor),this.processor.connect(this.merger),this.merger.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"time":return this.delayL.delayTime.value}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"time":"number"==typeof s&&(this.delayL.delayTime.value=s,this.delayR.delayTime.value=s)}return this}params(){return{state:this.isActive,time:this.delayL.delayTime.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class X extends d{amplitude;constructor(t){super(t),this.amplitude=t.createGain(),this.amplitude.gain.value=1,this.lfo.type="sine",this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain)}stop(t,e){super.stop(t,e),this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.amplitude.gain))}connect(){return this.input.disconnect(0),this.amplitude.disconnect(0),this.isActive?(this.input.connect(this.amplitude),this.amplitude.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.lfo.type;case"depth":return this.depth.gain.value;case"rate":return this.rate.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.lfo.type=s);break;case"depth":"number"==typeof s&&(this.depth.gain.value=s);break;case"rate":"number"==typeof s&&(this.rate.value=s)}return this}params(){return{state:this.isActive,type:this.lfo.type,depth:this.depth.gain.value,rate:this.rate.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class VocalCancelerProcessor extends AudioWorkletProcessor{depth=0;isActive=!0;constructor(){super(),this.port.onmessage=t=>{for(const[e,s]of Object.entries(t.data))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"depth":"number"==typeof s&&(this.depth=s)}}}process(t,e){const s=t[0],i=e[0];if(0===s.length||0===i.length)return!0;if(2!==s.length||2!==i.length)return i[0].set(s[0]),!0;const r=s[0].length;for(let t=0;t<r;t++)i[0][t]=this.cancel(s[0][t],s[1][t]),i[1][t]=this.cancel(s[1][t],s[0][t]);return!0}cancel(t,e){return this.isActive?t-this.depth*e:t}}class W extends d{processor;constructor(t){super(t),this.depth.gain.value=0,this.processor=new AudioWorkletNode(this.context,VocalCancelerProcessor.name),this.activate()}start(){}stop(){}connect(){return this.input.disconnect(0),this.processor.disconnect(0),this.isActive?(this.input.connect(this.processor),this.processor.connect(this.output)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"depth":return this.depth.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":if("boolean"==typeof s){this.isActive=s;const t={state:s};this.processor.port.postMessage(t)}break;case"depth":if("number"==typeof s){this.depth.gain.value=s;const t={depth:s};this.processor.port.postMessage(t)}}return this}params(){return{state:this.isActive,depth:this.depth.gain.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class V extends d{auto=!1;lowpass;envelopeFollower;sensitivity;depthRate=0;constructor(t){super(t),this.lowpass=t.createBiquadFilter(),this.envelopeFollower=t.createWaveShaper(),this.sensitivity=t.createBiquadFilter(),this.lowpass.type="lowpass",this.lowpass.frequency.value=this.auto?20:350,this.lowpass.Q.value=1,this.lowpass.gain.value=0,this.envelopeFollower.curve=new Float32Array([1,0,1]),this.sensitivity.type="lowpass",this.sensitivity.frequency.value=350,this.sensitivity.Q.value=1,this.sensitivity.gain.value=0,this.depth.gain.value=0,this.rate.value=0,this.deactivate(),this.connect()}stop(t,e){super.stop(t,e),!this.auto&&this.isActive&&(this.lfo.connect(this.depth),this.depth.connect(this.lowpass.frequency))}connect(){return this.input.disconnect(0),this.sensitivity.disconnect(0),this.envelopeFollower.disconnect(0),this.lowpass.disconnect(0),this.depth.disconnect(0),this.isActive?this.auto?(this.input.connect(this.sensitivity),this.sensitivity.connect(this.output),this.input.connect(this.envelopeFollower),this.envelopeFollower.connect(this.lowpass),this.lowpass.connect(this.depth),this.depth.connect(this.sensitivity.frequency)):(this.input.connect(this.lowpass),this.lowpass.connect(this.output),this.lfo.connect(this.depth),this.depth.connect(this.lowpass.frequency)):this.input.connect(this.output),this.output}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"auto":return this.auto;case"cutoff":return this.auto?this.sensitivity.frequency.value:this.lowpass.frequency.value;case"depth":return this.depthRate;case"rate":return this.rate.value;case"resonance":return this.auto?this.sensitivity.Q.value:this.lowpass.Q.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"auto":"boolean"==typeof s&&(this.auto=s,this.connect());break;case"cutoff":"number"==typeof s&&(this.auto?(this.sensitivity.frequency.value=s,this.lowpass.frequency.value=20):this.lowpass.frequency.value=s);break;case"depth":"number"==typeof s&&(this.depthRate=s,this.depth.gain.value=this.auto?1e4*s:this.lowpass.frequency.value*s);break;case"rate":"number"==typeof s&&(this.rate.value=s);break;case"resonance":"number"==typeof s&&(this.auto?(this.sensitivity.Q.value=s,this.lowpass.Q.value=1):this.lowpass.Q.value=s)}return this}params(){return{state:this.isActive,auto:this.auto,cutoff:this.auto?this.sensitivity.frequency.value:this.lowpass.frequency.value,depth:this.auto?this.depth.gain.value:this.depthRate,rate:this.rate.value,resonance:this.auto?this.sensitivity.Q.value:this.lowpass.Q.value}}activate(){return super.activate(),this}deactivate(){return super.deactivate(),this}}class H{static NUMBER_OF_INPUTS=2;static NUMBER_OF_OUTPUTS=2;context;modules=[];mastervolume;processor;analyser;recorder;autopanner;bitcrusher;chorus;compressor;delay;envelopegenerator;equalizer;filter;flanger;fuzz;listener;noisegate;noisesuppressor;overdrive;panner;phaser;pitchshifter;preamp;reverb;ringmodulator;stereo;tremolo;vocalcanceler;wah;runningAnalyser=!1;mixed=!1;constructor(t){this.context=t,this.mastervolume=t.createGain(),this.processor=new AudioWorkletNode(t,SoundModuleProcessor.name),this.analyser=new c(t),this.recorder=new p(t),this.autopanner=new f(t),this.bitcrusher=new m(t),this.chorus=new v(t),this.compressor=new g(t),this.delay=new b(t),this.envelopegenerator=new y(t),this.equalizer=new w(t),this.filter=new k(t),this.flanger=new A(t),this.fuzz=new x(t),this.listener=new T(t),this.noisegate=new S(t),this.noisesuppressor=new E(t),this.overdrive=new M(t),this.panner=new F(t),this.phaser=new N(t),this.pitchshifter=new O(t),this.preamp=new B(t),this.reverb=new Q(t),this.ringmodulator=new $(t),this.stereo=new j(t),this.tremolo=new X(t),this.vocalcanceler=new W(t),this.wah=new V(t),this.modules=[this.compressor,this.wah,this.bitcrusher,this.overdrive,this.fuzz,this.preamp,this.equalizer,this.filter,this.pitchshifter,this.tremolo,this.ringmodulator,this.phaser,this.flanger,this.chorus,this.delay,this.reverb,this.panner,this.autopanner]}connect(t){if(t.disconnect(0),this.modules.length>0){const e=this.modules[0].INPUT;if(null===e)return;t.connect(e)}else t.connect(this.mastervolume);for(let t=0,e=this.modules.length;t<e;t++){const e=this.modules[t].OUTPUT;if(null!==e)if(e.disconnect(0),t<this.modules.length-1){const s=this.modules[t+1].INPUT;if(null===s)continue;e.connect(s)}else e.connect(this.mastervolume)}this.mastervolume.connect(this.context.destination),this.mastervolume.connect(this.analyser.INPUT),this.mastervolume.connect(this.recorder.INPUT),this.recorder.OUTPUT.connect(this.context.destination)}disconnect(){this.processor.disconnect(0)}install(t){const e=new t(this.context);return this.modules.push(e),e}on(t){const e=t??this.context.currentTime;return this.autopanner.start(e),this.bitcrusher.start(e),this.chorus.start(e),this.filter.start(e),this.flanger.start(e),this.fuzz.start(e),this.overdrive.start(e),this.phaser.start(e),this.ringmodulator.start(e),this.tremolo.start(e),this.wah.start(e),this}off(t){const e=t??this.context.currentTime;return this.autopanner.stop(e),this.bitcrusher.stop(e),this.chorus.stop(e),this.filter.stop(e),this.flanger.stop(e),this.fuzz.stop(e),this.overdrive.stop(e),this.phaser.stop(e),this.ringmodulator.stop(e),this.tremolo.stop(e),this.wah.stop(e),this}suspend(){return this.analyser.stop("time"),this.analyser.stop("fft"),this.runningAnalyser=!1,this.recorder.stop(),this}mix(){return this.mixed=!0,this}demix(){return this.mixed=!1,this}params(){return{mastervolume:this.mastervolume.gain.value,stereo:this.stereo.params(),compressor:this.compressor.params(),bitcrusher:this.bitcrusher.params(),overdrive:this.overdrive.params(),fuzz:this.fuzz.params(),preamp:this.preamp.params(),wah:this.wah.params(),pitchshifter:this.pitchshifter.params(),equalizer:this.equalizer.params(),filter:this.filter.params(),autopanner:this.autopanner.params(),tremolo:this.tremolo.params(),ringmodulator:this.ringmodulator.params(),phaser:this.phaser.params(),flanger:this.flanger.params(),chorus:this.chorus.params(),delay:this.delay.params(),reverb:this.reverb.params(),panner:this.panner.params(),listener:this.listener.params(),envelopegenerator:this.envelopegenerator.params(),noisegate:this.noisegate.params(),noisesuppressor:this.noisesuppressor.params(),vocalcanceler:this.vocalcanceler.params()}}edit(t){const e=this.modules;return this.modules=t,e}toJSON(){return JSON.stringify(this.params())}init(t){this.mastervolume.disconnect(0),this.processor.disconnect(0),this.analyser.INPUT.disconnect(0),this.recorder.INPUT.disconnect(0);for(const t of this.modules)t.INPUT&&t.INPUT.disconnect(0),t.OUTPUT&&t.OUTPUT.disconnect(0);this.modules.length=0,this.analyser=new c(t),this.recorder=new p(t),this.autopanner=new f(t),this.bitcrusher=new m(t),this.chorus=new v(t),this.compressor=new g(t),this.delay=new b(t),this.envelopegenerator=new y(t),this.equalizer=new w(t),this.filter=new k(t),this.flanger=new A(t),this.fuzz=new x(t),this.listener=new T(t),this.noisegate=new S(t),this.noisesuppressor=new E(t),this.overdrive=new M(t),this.panner=new F(t),this.phaser=new N(t),this.pitchshifter=new O(t),this.preamp=new B(t),this.reverb=new Q(t),this.ringmodulator=new $(t),this.stereo=new j(t),this.tremolo=new X(t),this.vocalcanceler=new W(t),this.wah=new V(t),this.modules=[this.compressor,this.wah,this.bitcrusher,this.overdrive,this.fuzz,this.preamp,this.equalizer,this.filter,this.pitchshifter,this.tremolo,this.ringmodulator,this.phaser,this.flanger,this.chorus,this.delay,this.reverb,this.panner,this.autopanner]}}class OscillatorModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class Y{context;type="linear";time=0;prevFrequency=-1;nextFrequency=0;isActive=!0;constructor(t){this.context=t}ready(t){this.nextFrequency=t;const e=-1===this.prevFrequency?0:this.nextFrequency-this.prevFrequency;this.isActive&&0!==this.time&&0!==e||(this.prevFrequency=this.nextFrequency)}start(t,e){const s=e??this.context.currentTime,i=s+this.time;t.frequency.cancelScheduledValues(s),t.frequency.setValueAtTime(this.prevFrequency,s),"exponential"===this.type?t.frequency.exponentialRampToValueAtTime(this.nextFrequency,i):t.frequency.linearRampToValueAtTime(this.nextFrequency,i)}stop(){this.prevFrequency=this.nextFrequency}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.type;case"time":return this.time}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":"string"==typeof s&&(this.type=s);break;case"time":"number"==typeof s&&(this.time=s)}return this}params(){return{state:this.isActive,type:this.type,time:this.time}}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}}class J{static OCTAVE=1200;context;source;volume;octave=0;fine=0;custom={real:new Float32Array([0,1]),imag:new Float32Array([0,1])};isActive;paused=!0;constructor(t,e){this.context=t,this.source=t.createOscillator(),this.volume=t.createGain(),this.isActive=e}ready(t){if(!this.isActive)return;const e=this.source.type,s=this.source.frequency.value,i=this.source.detune.value;if(this.paused||(this.source.stop(this.context.currentTime),this.source.disconnect(0)),this.source=this.context.createOscillator(),"custom"===e){const t=this.custom.real,e=this.custom.imag,s=this.context.createPeriodicWave(t,e);this.source.setPeriodicWave(s)}else this.source.type=e;this.source.frequency.value=s,this.source.detune.value=i,this.volume.connect(t)}start(t){this.isActive?(this.source.start(t??this.context.currentTime),this.paused=!1):(this.paused||(this.source.stop(this.context.currentTime),this.paused=!0),this.source.disconnect(0))}stop(t){this.paused||(this.source.stop(t??this.context.currentTime),this.source.disconnect(0),this.paused=!0)}param(t){if("string"==typeof t)switch(t){case"state":return this.isActive;case"type":return this.source.type;case"octave":return this.octave;case"fine":return this.fine;case"volume":return this.volume.gain.value}for(const[e,s]of Object.entries(t))switch(e){case"state":"boolean"==typeof s&&(this.isActive=s);break;case"type":if("string"==typeof s)this.source.type=s;else if("object"==typeof s){let{real:t,imag:e}=s;const i=4096;t.length>i&&(t=t.subarray(0,i)),e.length>i&&(e=e.subarray(0,i)),0!==t[0]&&(t[0]=0),0!==e[0]&&(e[0]=0);const r=this.context.createPeriodicWave(t,e);this.source.setPeriodicWave(r),this.custom.real=t,this.custom.imag=e}break;case"octave":"number"==typeof s&&(this.octave=s,this.source.detune.value=this.fine+s*J.OCTAVE);break;case"fine":"number"==typeof s&&(this.fine=s,this.source.detune.value=s+this.octave*J.OCTAVE);break;case"volume":"number"==typeof s&&(this.volume.gain.value=s)}return this}get(){return this.source}state(){return this.isActive}activate(){return this.isActive=!0,this}deactivate(){return this.isActive=!1,this}params(){return{state:this.isActive,type:this.source.type,octave:this.octave,fine:this.fine,volume:this.volume.gain.value}}get INPUT(){return this.source}get OUTPUT(){return this.volume}}class K extends H{sources=[];glide;startTime=0;duration=0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,OscillatorModuleProcessor.name),this.glide=new Y(t)}setup(t){this.sources.length=0;for(let e=0,s=t.length;e<s;e++)this.sources[e]=new J(this.context,t[e]),this.envelopegenerator.setGenerator(e);return this}ready(t,e){return this.startTime=t??this.context.currentTime,this.duration=e??0,this.envelopegenerator.clear(!0),this}start(t){const e=this.context.currentTime+this.startTime;this.mixed||(this.envelopegenerator.clear(!0),this.connect(this.processor));for(let s=0,i=t.length;s<i&&!(s>=this.sources.length);s++){const i=this.sources[s],r=t[s];i.ready(this.processor),this.envelopegenerator.ready(s,i.INPUT,i.OUTPUT),this.glide.ready(r),this.glide.start(i.INPUT,e),i.start(e)}return this.envelopegenerator.start(e),this.on(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(){const t=this.context.currentTime+this.startTime+this.duration;return this.envelopegenerator.stop(t,!1),this.glide.stop(),this.filter.stop(t),this}param(t){if("string"==typeof t&&"mastervolume"===t)return this.mastervolume.gain.value;for(const[e,s]of Object.entries(t))if("mastervolume"===e)"number"==typeof s&&(this.mastervolume.gain.value=s);return this}get(t){return"number"==typeof t&&t>=0&&t<this.sources.length?this.sources[t]:this.sources}length(){return this.sources.length}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah;case"glide":return this.glide}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),oscillator:{glide:this.glide.params(),params:this.sources.map((t=>t.params()))}}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class OneshotModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class Z extends H{sources=[];resources=[];buffers=[];volumes=[];states=[];settings=[];startTime=0;duration=0;transpose=0;loadError=!1;constructor(t){super(t),this.processor=new AudioWorkletNode(t,OneshotModuleProcessor.name)}setup(t){const{resources:e,settings:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t;for(let t=0,e=s.length;t<e;t++)this.states[t]=!1,this.volumes[t]=this.context.createGain(),this.settings[t]=s[t],this.envelopegenerator.setGenerator(t);for(let t=0,s=e.length;t<s;t++){this.resources[t]=e[t];const s=this.resources[t];"string"==typeof s?this.load({url:s,index:t,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}):this.buffers[t]=s}return this}ready(t,e){return this.startTime=t??0,this.duration=e??0,this.envelopegenerator.clear(!1),this}start(t){const e=this.context.currentTime+this.startTime;this.mixed||(this.envelopegenerator.clear(!1),this.connect(this.processor));for(const s of t){if(s<0||s>=this.settings.length)continue;const{bufferIndex:t,playbackRate:i,loop:r,loopStart:n,loopEnd:a,volume:o}=this.settings[s],h=this.context.createBufferSource();h.buffer=this.buffers[t],h.playbackRate.value=i??1,h.detune.value=100*this.transpose,h.loop=r??!1,h.loopStart=n??0,h.loopEnd=a??h.buffer.duration,this.volumes[s].gain.value=o??1,this.envelopegenerator.ready(s,h,this.volumes[s]),this.volumes[s].connect(this.processor),h.loop?h.start(e,e+h.loopStart,h.loopEnd-e):h.start(e),this.sources[s]=h,this.states[s]=!0}return this.envelopegenerator.start(e),this.on(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(t){const e=this.context.currentTime+this.startTime+this.duration;return t.forEach((t=>{this.states[t]&&(this.sources[t].stop(e),this.states[t]=!1)})),this.envelopegenerator.stop(e),this.envelopegenerator.clear(!1),this.off(e),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"transpose":return this.transpose}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"transpose":"number"==typeof s&&(this.transpose=s)}return this}get(t){return"number"==typeof t&&t>=0&&t<this.buffers.length?this.buffers[t]:this.buffers}reset(t,e,s){if(t>=0&&t<this.settings.length)switch(e){case"bufferIndex":case"playbackRate":case"loopStart":case"loopEnd":case"volume":"number"==typeof s&&(this.settings[t][e]=s);break;case"loop":"boolean"==typeof s&&(this.settings[t][e]=s)}return this}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),transpose:this.transpose}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}load(t){const{url:e,index:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{!this.loadError&&n&&n(t,"timeout"),this.loadError=!0},o.onprogress=t=>{this.loadError?o.abort():a&&a(t)},o.onerror=t=>{!this.loadError&&n&&n(t,"error"),this.loadError=!0},o.onload=t=>{if(200===o.status){const e=o.response;if(!(e instanceof ArrayBuffer))return;const i=e=>{this.buffers[s]=e;for(const t of this.buffers)if(void 0===t)return;r&&r(t,this.buffers)},a=t=>{n&&n(t,"decode")};this.context.decodeAudioData(e,i,a)}},o.open("GET",e,!0),o.responseType="arraybuffer",o.send(null)}}class NoiseModuleProcessor extends AudioWorkletProcessor{processing=!1;type="whitenoise";b0=0;b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;lastOut=0;constructor(){super(),this.port.onmessage=t=>{"boolean"==typeof t.data.processing&&(this.processing=t.data.processing),t.data.type&&(this.type=t.data.type)}}process(t,e){if(!this.processing)return!0;const s=e[0];for(let t=0,e=s.length;t<e;t++){const e=s[t].length;switch(this.type){case"whitenoise":this.generateWhiteNoise(s[t],e);break;case"pinknoise":this.generatePinkNoise(s[t],e);break;case"browniannoise":this.generateBrownianNoise(s[t],e)}}return!0}generateWhiteNoise(t,e){for(let s=0;s<e;s++)t[s]=2*Math.random()-1}generatePinkNoise(t,e){for(let s=0;s<e;s++){const e=2*Math.random()-1;this.b0=.99886*this.b0+.0555179*e,this.b1=.99332*this.b1+.0750759*e,this.b2=.969*this.b2+.153852*e,this.b3=.8665*this.b3+.3104856*e,this.b4=.55*this.b4+.5329522*e,this.b5=-.7616*this.b5-.016898*e,t[s]=this.b0+this.b1+this.b2+this.b3+this.b4+this.b5+this.b6+.5362*e,t[s]*=.11,this.b6=.115926*e}}generateBrownianNoise(t,e){for(let s=0;s<e;s++){const e=2*Math.random()-1;t[s]=(this.lastOut+.02*e)/1.02,this.lastOut=(this.lastOut+.02*e)/1.02,t[s]*=3.5}}}class tt extends H{type="whitenoise";constructor(t){super(t),this.processor=new AudioWorkletNode(t,NoiseModuleProcessor.name),this.envelopegenerator.setGenerator(0)}setup(){return this}ready(){return this}start(){const t=this.context.currentTime;if(!this.mixed){const t=this.envelopegenerator.getGenerator(0);t&&this.connect(t)}this.envelopegenerator.ready(0,this.processor,null),this.envelopegenerator.start(t),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this.on(t);return this.processor.port.postMessage({processing:!0}),this}stop(){const t=this.context.currentTime;this.envelopegenerator.stop(t),this.off(t);return this.processor.port.postMessage({processing:!1}),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"type":return this.type}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"type":if("string"==typeof s&&("whitenoise"===s||"pinknoise"===s||"browniannoise"===s)){this.type=s;const t={type:s};this.processor.port.postMessage(t)}}return this}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}disconnect(){const t=this.envelopegenerator.getGenerator(0);t&&t.disconnect(0)}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),type:this.type}}get INPUT(){const t=this.envelopegenerator.getGenerator(0);return t||null}get OUTPUT(){return this.mastervolume}}class AudioModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];s.length>0&&s[0].length>0&&currentFrame%16384==0&&this.port.postMessage({});for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class et extends H{source;buffer=null;currentTime=0;stopped=!0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,AudioModuleProcessor.name),this.source=t.createBufferSource()}setup(t){const{decodeCallback:e,updateCallback:s,endedCallback:i,errorCallback:r}=t??{};return e&&(this.decodeCallback=e),s&&(this.updateCallback=s),i&&(this.endedCallback=i),r&&(this.errorCallback=r),this.envelopegenerator.setGenerator(0),this.envelopegenerator.param({attack:0,decay:.01,sustain:1,release:.01}),this}ready(t){if(t instanceof ArrayBuffer){this.buffer=null;const e=t=>{this.buffer=t,this.analyser.start("timeoverview",0,this.buffer),this.analyser.start("timeoverview",1,this.buffer),this.decodeCallback&&this.decodeCallback(this.buffer)};this.context.decodeAudioData(t,e,this.errorCallback)}else t instanceof AudioBuffer&&(this.buffer=t);return this}start(t,e){if(null===this.buffer||!this.stopped)return this;const s=this.context.currentTime,i=t??0,r=e??this.buffer.duration;this.currentTime=r>=0?i>=0&&i<=r?i:0:i>=0&&i<=this.buffer.duration?i:0;const n=this.source.playbackRate.value,a=this.source.detune.value,o=this.source.loop;this.source=this.context.createBufferSource(),this.source.buffer=this.buffer,this.source.playbackRate.value=n,this.source.detune.value=a,this.source.loop=o,this.source.loopStart=this.currentTime,this.source.loopEnd=r>=0?r:this.buffer.duration,this.envelopegenerator.ready(0,this.source,this.processor),this.connect(this.processor);const h=this.computePlaybackRate();r>=0?this.source.start(s,this.currentTime,r-i):this.source.start(s,this.currentTime,this.buffer.duration-this.currentTime),this.analyser.start("time"),this.analyser.start("fft"),this.stopped=!1,this.envelopegenerator.start(s),r>=0?this.envelopegenerator.stop(s+(r-i)/h,!0):this.envelopegenerator.stop(s+(this.buffer.duration-i)/h,!0),this.on(s);const c=this.analyser.domain("timeoverview",0),u=this.analyser.domain("timeoverview",1);return this.processor.port.onmessage=()=>{if(null!==this.buffer)if(Math.abs(this.source.loopEnd-this.currentTime)>.5){const t=this.computePlaybackRate();this.currentTime+=16384/this.buffer.sampleRate*t,this.updateCallback&&this.updateCallback(this.source,this.currentTime),c.update(this.currentTime),u.update(this.currentTime)}else this.source.loop?(this.stop(),"sprite"===c.param("mode")?this.start(this.source.loopStart,this.source.loopEnd):this.start(0,this.buffer.duration)):this.end();else this.end()},this}stop(){if(null===this.buffer||this.stopped)return this;const t=this.context.currentTime;return this.source.stop(t),this.off(t),this.analyser.stop("time"),this.analyser.stop("fft"),this.stopped=!0,this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"playbackRate":return this.source.playbackRate.value;case"detune":return this.source.detune.value;case"loop":return this.source.loop;case"currentTime":return this.currentTime;case"duration":return this.source.buffer?.duration??0;case"sampleRate":return this.source.buffer?.sampleRate??this.context.sampleRate;case"numberOfChannels":return this.source.buffer?.numberOfChannels??0}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"playbackRate":if("number"==typeof s&&s>0){this.source.playbackRate.value=s;const t=this.computePlaybackRate(),e=this.context.currentTime,i=this.currentTime,r=this.source.buffer?.duration??0;this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(r-i)/t,!0)}break;case"detune":if("number"==typeof s){this.source.detune.value=s;const t=this.computePlaybackRate(),e=this.context.currentTime,i=this.currentTime,r=this.source.buffer?.duration??0;this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(r-i)/t,!0)}break;case"loop":"boolean"==typeof s&&(this.source.loop=s);break;case"currentTime":"number"==typeof s&&(this.currentTime=s,this.stopped||(this.stop(),this.start(s)))}return this}get(){return this.source}end(){return this.stop(),this.currentTime=0,this.endedCallback&&this.endedCallback(this.source,0),this}has(){return null!==this.buffer}paused(){return this.stopped}fadeIn(t){if("number"!=typeof t)return this.envelopegenerator.param("attack");this.envelopegenerator.param({attack:t});const e=this.context.currentTime,s=this.currentTime,i=this.source.buffer?.duration??0,r=this.computePlaybackRate();return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}fadeOut(t){if("number"!=typeof t)return this.envelopegenerator.param("release");this.envelopegenerator.param({release:t});const e=this.context.currentTime,s=this.currentTime,i=this.source.buffer?.duration??0,r=this.computePlaybackRate();return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}slice(t,e){if(null===this.buffer)return null;const s=this.buffer.duration,i=this.buffer.sampleRate,r=this.buffer.numberOfChannels,n=Math.trunc((t??0)*i),a=Math.trunc((e??s)*i),o=r>0?this.buffer.getChannelData(0):null,h=r>1?this.buffer.getChannelData(1):null,c=a-n;switch(r){case 1:{if(null===o)return null;const t=new Float32Array(c);for(let e=n;e<a;e++)t[e-n]=o[e];const e=this.context.createBuffer(1,c,i);return e.copyToChannel(t,0),e}case 2:{if(null===o||null===h)return null;const t=new Float32Array(c),e=new Float32Array(c);for(let s=n;s<a;s++)t[s-n]=o[s],e[s-n]=h[s];const s=this.context.createBuffer(2,c,i);return s.copyToChannel(t,0),s.copyToChannel(e,1),s}}return null}sprite(t){return null===this.buffer?null:Object.keys(t).reduce(((e,s)=>{const i=t[s],r=this.slice(...i);return null!==r&&(e[s]=r),e}),{})}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),playbackRate:this.source.playbackRate.value,detune:this.source.detune.value,loop:this.source.loop,currentTime:this.currentTime,duration:this.buffer?.duration??0,sampleRate:this.buffer?.sampleRate??this.context.sampleRate,numberOfChannels:this.buffer?.numberOfChannels??0,vocalcanceler:this.vocalcanceler.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}computePlaybackRate(){return this.source.playbackRate.value*2**(this.source.detune.value/1200)}}class MediaModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class st extends H{source=null;media=null;ext="";autoplay=!1;mediaSource=null;sourceBuffer=null;file="";mimeType="";listeners={};constructor(t){super(t),this.processor=new AudioWorkletNode(t,MediaModuleProcessor.name),this.onSourceOpen=this.onSourceOpen.bind(this),this.onSourceEnded=this.onSourceEnded.bind(this),this.onSourceClose=this.onSourceClose.bind(this),this.onSourceBufferUpdateEnd=this.onSourceBufferUpdateEnd.bind(this),this.onSourceBufferError=this.onSourceBufferError.bind(this)}setup(t){this.envelopegenerator.setGenerator(0),this.envelopegenerator.param({attack:0,decay:.01,sustain:1,release:.01});const{media:e,formats:s,listeners:i,autoplay:r}=t;if(!e)return this;this.media=e;for(const t of s??[]){const e=`audio/${t}`,s=`video/${t}`,i=this.media.canPlayType(e),r=this.media.canPlayType(s);if(/^(?:maybe|probably)/.test(i)||/^(?:maybe|probably)/.test(r)){this.ext=t;break}}return i&&(this.listeners=i,Object.keys(i).forEach((t=>{const e=i[t];"function"==typeof e&&(i[t]=e),this.media&&this.media.addEventListener(t,e,!1)}))),this.media.addEventListener("loadstart",(()=>{null!==this.media&&(null!==this.source&&this.media===e||(this.source=this.context.createMediaElementSource(this.media)))}),!1),this.media.addEventListener("ended",(()=>{null!==this.media&&(this.media.pause(),this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"))}),!1),this.autoplay=r??!1,this.autoplay&&null===this.source&&(this.source=this.context.createMediaElementSource(this.media)),this.autoplay&&this.media.src&&this.context.resume().then((()=>{this.start(this.media?.currentTime??0)})).catch((t=>{this.listeners.error&&this.listeners.error(t)})),this}ready(t,e){if(null===this.media)return this;if(this.mediaSource&&"open"===this.mediaSource.readyState&&(this.mediaSource.endOfStream(),window.URL.revokeObjectURL(this.media.src),this.mediaSource.removeEventListener("sourceopen",this.onSourceOpen,!1),this.mediaSource.removeEventListener("sourceended",this.onSourceEnded,!1),this.mediaSource.removeEventListener("sourceclose",this.onSourceClose,!1),this.sourceBuffer&&(this.sourceBuffer.removeEventListener("updateend",this.onSourceBufferUpdateEnd,!1),this.sourceBuffer.removeEventListener("error",this.onSourceBufferError,!1))),e){if(!MediaSource||!MediaSource.isTypeSupported(e))return this;this.media.removeAttribute("src"),this.media.load(),this.mediaSource=new MediaSource,this.media.src=window.URL.createObjectURL(this.mediaSource),this.mimeType=e,this.file=t,this.mediaSource.addEventListener("sourceopen",this.onSourceOpen,!1),this.mediaSource.addEventListener("sourceended",this.onSourceEnded,!1),this.mediaSource.addEventListener("sourceclose",this.onSourceClose,!1)}else t.startsWith("blob:")||""===this.ext?this.media.src=t:this.media.src=`${t}.${this.ext}`;return this}start(t,e){return null===this.source||null===this.media||(this.envelopegenerator.ready(0,this.source,this.processor),this.connect(this.processor),this.media.play().then((()=>{if(null===this.media)return;const e=this.context.currentTime;this.media.currentTime=t??0,this.envelopegenerator.start(e),Number.isFinite(this.media.duration)&&this.envelopegenerator.stop(e+(this.media.duration-this.media.currentTime)/this.media.playbackRate,!0),this.on(e),this.analyser.start("time"),this.analyser.start("fft")})).catch((()=>{this.stop((()=>{null!==this.media&&(this.autoplay&&(this.media.muted=!0,this.media.volume=0),this.start(t))}),e)}))),this}stop(t,e){return null===this.source||null===this.media||this.media.play().then((()=>{null!==this.media&&(this.media.pause(),this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"),t&&t())})).catch((t=>{e&&e(t)})),this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"autoplay":return this.autoplay;case"playbackRate":return this.media?.playbackRate??1;case"currentTime":return this.media?.currentTime??0;case"controls":return this.media?.controls??!1;case"loop":return this.media?.loop??!1;case"muted":return this.media?.muted??!1;case"duration":return Number.isNaN(this.media?.duration)?0:this.media?.duration??0}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"playbackRate":if(this.media&&"number"==typeof s&&s>0){this.media.playbackRate=s;const t=this.context.currentTime,e=this.media.currentTime,i=this.media.duration;this.envelopegenerator.start(t),Number.isFinite(i)&&this.envelopegenerator.stop(t+(i-e)/s,!0)}break;case"currentTime":if(this.media&&"number"==typeof s){this.media.currentTime=s;const t=this.context.currentTime,e=this.media.duration,i=this.media.playbackRate;this.envelopegenerator.start(t),Number.isFinite(e)&&this.envelopegenerator.stop(t+(e-s)/i,!0)}break;case"controls":this.media&&"boolean"==typeof s&&(this.media.controls=s);break;case"loop":this.media&&"boolean"==typeof s&&(this.media.loop=s);break;case"muted":this.media&&"boolean"==typeof s&&(this.media.muted=s)}return this}get(){return this.source}hasMedia(){return null!==this.media}hasSource(){return null!==this.source}paused(){return null===this.media||this.media.paused}fadeIn(t){if("number"!=typeof t)return this.envelopegenerator.param("attack");this.envelopegenerator.param({attack:t});const e=this.context.currentTime,s=this.media?.currentTime??0,i=this.media?.duration??0,r=this.media?.playbackRate??1;return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}fadeOut(t){if("number"!=typeof t)return this.envelopegenerator.param("release");this.envelopegenerator.param({release:t});const e=this.context.currentTime,s=this.media?.currentTime??0,i=this.media?.duration??0,r=this.media?.playbackRate??1;return this.envelopegenerator.start(e),this.envelopegenerator.stop(e+(i-s)/r,!0),this}requestPictureInPicture(){return this.media instanceof HTMLVideoElement&&"pictureInPictureEnabled"in document&&document.pictureInPictureEnabled?this.media.disablePictureInPicture||0===this.media.readyState||this.media===document.pictureInPictureElement?Promise.reject():this.media.requestPictureInPicture():Promise.reject()}exitPictureInPicture(){return this.media instanceof HTMLVideoElement&&"pictureInPictureEnabled"in document&&document.pictureInPictureEnabled?this.media.disablePictureInPicture||0===this.media.readyState||this.media!==document.pictureInPictureElement?Promise.reject():document.exitPictureInPicture():Promise.reject()}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),autoplay:this.autoplay,playbackRate:this.media?.playbackRate??1,controls:this.media?.controls??!1,loop:this.media?.loop??!1,muted:this.media?.muted??!1,currentTime:this.media?.currentTime??0,duration:Number.isNaN(this.media?.duration??0)?0:this.media?.duration??0,vocalcanceler:this.vocalcanceler.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}onSourceOpen(t){if(null===this.mediaSource)return;this.sourceBuffer=this.mediaSource.addSourceBuffer(this.mimeType),this.sourceBuffer.mode="sequence",this.sourceBuffer.addEventListener("updateend",this.onSourceBufferUpdateEnd,!1),this.sourceBuffer.addEventListener("error",this.onSourceBufferError,!1);const e=new Request(this.file);fetch(e).then((t=>t.arrayBuffer())).then((t=>{this.sourceBuffer&&this.sourceBuffer.appendBuffer(t)})).catch((t=>{this.listeners.error&&this.listeners.error(t)})).finally((()=>{this.listeners.sourceopen&&this.listeners.sourceopen(t)}))}onSourceEnded(t){this.listeners.sourceended&&this.listeners.sourceended(t)}onSourceClose(t){this.listeners.sourceclose&&this.listeners.sourceclose(t)}onSourceBufferUpdateEnd(t){this.listeners.updateend&&this.listeners.updateend(t)}onSourceBufferError(t){this.listeners.error&&this.listeners.error(t)}}class StreamModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class it extends H{sources=[];stream=null;constraints={audio:!0,video:!1};output=!0;track=!1;paused=!0;constructor(t){super(t),this.processor=new AudioWorkletNode(t,StreamModuleProcessor.name)}setup(t){return t&&(this.constraints={...this.constraints,...t}),this}ready(t){return navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&window.MediaStream?(this.paused=!1,t?.stream?(this.stream=t.stream,Promise.resolve(this.stream)):navigator.mediaDevices.getUserMedia(this.constraints).then((e=>(this.paused||(this.stream=e,t?.successCallback&&t.successCallback(e)),e))).catch((e=>(t?.errorCallback&&t.errorCallback(e),e)))):Promise.reject()}start(){if(null===this.stream)return this;if(this.track){const t=this.stream.getAudioTracks();for(let e=0,s=t.length;e<s;e++)this.sources[e]=this.context.createMediaStreamTrackSource(t[e]),this.sources[e].connect(this.processor),this.connect(this.processor)}else this.sources[0]=this.context.createMediaStreamSource(this.stream),this.sources[0].connect(this.processor),this.connect(this.processor);return this.output||(this.mastervolume.disconnect(0),this.mastervolume.connect(this.analyser.INPUT),this.mastervolume.connect(this.recorder.INPUT),this.recorder.OUTPUT.connect(this.context.destination)),this.on(this.context.currentTime),this.analyser.start("time"),this.analyser.start("fft"),this}stop(){return this.sources.length=0,this.off(this.context.currentTime),this.analyser.stop("time"),this.analyser.stop("fft"),this.paused=!0,this}param(t){if("string"==typeof t)switch(t){case"mastervolume":return this.mastervolume.gain.value;case"output":return this.output;case"track":return this.track}for(const[e,s]of Object.entries(t))switch(e){case"mastervolume":"number"==typeof s&&(this.mastervolume.gain.value=s);break;case"output":"boolean"==typeof s&&(this.output=s);break;case"track":"boolean"==typeof s&&(this.track=s)}return this}get(t){return"number"==typeof t&&t>=0&&t<this.sources.length?this.sources[t]:this.sources}getStream(){return this.stream}clear(){return this.stop(),this.clearAudioDevices(),this.clearVideoDevices(),this.stream=null,this}clearAudioDevices(){if(null===this.stream)return this;this.stop();const t=this.stream.getAudioTracks();for(const e of t)e.stop();return this}clearVideoDevices(){if(null===this.stream)return this;this.stop();const t=this.stream.getVideoTracks();for(const e of t)e.stop();return this.stream=null,this}devices(){return navigator.mediaDevices&&navigator.mediaDevices.enumerateDevices?navigator.mediaDevices.enumerateDevices():Promise.reject()}streaming(){return!this.paused}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}params(){return{...super.params(),output:this.output,track:this.track,noisegate:this.noisegate.params(),noisesuppressor:this.noisesuppressor.params()}}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class rt extends H{processorName="";options={};moduleURL="";constructor(t){super(t),this.envelopegenerator.setGenerator(0)}setup(t,e){return this.processorName=t,this.options=e??{},this}ready(t,e){return this.moduleURL=t,this.context.audioWorklet.addModule(this.moduleURL,e??{credentials:"same-origin"}).then((()=>{this.processor=new AudioWorkletNode(this.context,this.processorName,this.options)}))}start(){const t=this.envelopegenerator.getGenerator(0);if(null===t)return this;const e=this.context.currentTime;return this.mixed||(this.envelopegenerator.clear(!0),this.processor.disconnect(0),this.connect(t)),this.envelopegenerator.ready(0,this.processor,null),this.envelopegenerator.start(e),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this.on(e),this}stop(){const t=this.context.currentTime;return this.envelopegenerator.stop(t),this.off(t),this}postMessage(t){return this.processor.port.postMessage(t),this}onMessage(t){return this.processor.port.onmessage=t,this}onMessageError(t){return this.processor.port.onmessageerror=t,this}map(){return this.processor.parameters}get(){return this.processor}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){super.suspend();const t=this.envelopegenerator.getGenerator(0);return this.processor&&t&&(t.disconnect(0),this.processor.connect(t)),this}mix(){return super.mix(),this}demix(){return super.demix(),this}get INPUT(){const t=this.envelopegenerator.getGenerator(0);return t||null}get OUTPUT(){return this.mastervolume}}class MixerModuleProcessor extends AudioWorkletProcessor{constructor(){super()}process(t,e){const s=t[0],i=e[0];for(let t=0,e=s.length;t<e;t++)i[t].set(s[t]);return!0}}class nt extends H{sources=[];gainNodes=[];constructor(t){super(t),this.processor=new AudioWorkletNode(t,MixerModuleProcessor.name)}setup(){return this}ready(){return this}start(t,e){this.sources=t;for(let t=0,s=this.sources.length;t<s;t++){const s=this.sources[t],i=this.context.currentTime;s.off(i),s.suspend(),s.mix(),s.INPUT&&(this.gainNodes[t]=this.context.createGain(),this.gainNodes[t].gain.value=e?e[t]:1,s.disconnect(),s.INPUT.connect(this.gainNodes[t]),this.gainNodes[t].connect(this.processor))}this.connect(this.processor);const s=this.context.currentTime;return this.on(s),this.runningAnalyser||(this.analyser.start("time"),this.analyser.start("fft"),this.runningAnalyser=!0),this}stop(){const t=this.context.currentTime;this.off(t),this.suspend();for(const t of this.sources)t.demix(),t.INPUT&&(t.disconnect(),t.connect(t.INPUT));for(const t of this.gainNodes)t.disconnect(0);return this}param(t){if("string"==typeof t&&"mastervolume"===t)return this.mastervolume.gain.value;for(const[e,s]of Object.entries(t))if("mastervolume"===e)"number"==typeof s&&(this.mastervolume.gain.value=s);return this}get(){return this.sources}module(t){switch(t){case"analyser":return this.analyser;case"recorder":return this.recorder;case"autopanner":return this.autopanner;case"bitcrusher":return this.bitcrusher;case"chorus":return this.chorus;case"compressor":return this.compressor;case"delay":return this.delay;case"envelopegenerator":return this.envelopegenerator;case"equalizer":return this.equalizer;case"filter":return this.filter;case"flanger":return this.flanger;case"fuzz":return this.fuzz;case"listener":return this.listener;case"noisegate":return this.noisegate;case"noisesuppressor":return this.noisesuppressor;case"overdrive":return this.overdrive;case"panner":return this.panner;case"phaser":return this.phaser;case"pitchshifter":return this.pitchshifter;case"preamp":return this.preamp;case"reverb":return this.reverb;case"ringmodulator":return this.ringmodulator;case"stereo":return this.stereo;case"tremolo":return this.tremolo;case"vocalcanceler":return this.vocalcanceler;case"wah":return this.wah}}on(t){return super.on(t),this}off(t){return super.off(t),this}suspend(){return super.suspend(),this}mix(){return super.mix(),this}demix(){return super.demix(),this}get INPUT(){return this.processor}get OUTPUT(){return this.mastervolume}}class at{midiAccess=null;inputs=[];outputs=[];constructor(){}setup(t){if(!navigator.requestMIDIAccess)return Promise.reject();const{options:e,successCallback:s,errorCallback:i}=t;return navigator.requestMIDIAccess(e).then((t=>{this.midiAccess=t,t.inputs.forEach((t=>{this.inputs.push(t)})),t.outputs.forEach((t=>{this.outputs.push(t)})),s&&s(this.midiAccess,this.inputs,this.outputs)})).catch((t=>{i&&i(t)}))}get(){return this.midiAccess}}function ot(t){return t.replace(/^.+?\{/s,"").replace(/\};?$/s,"")}function ht(t){return window.URL.createObjectURL(function(t){return new Blob([ot(t)],{type:"text/javascript"})}(t))}const ct=new Map([["T","TEMPO"],["O","OCTAVE"],["C","NOTE"],["D","NOTE"],["E","NOTE"],["F","NOTE"],["G","NOTE"],["A","NOTE"],["B","NOTE"],["+","NOTE"],["-","NOTE"],["#","NOTE"],["R","REST"],["0","NUMBER"],["1","NUMBER"],["2","NUMBER"],["3","NUMBER"],["4","NUMBER"],["5","NUMBER"],["6","NUMBER"],["7","NUMBER"],["8","NUMBER"],["9","NUMBER"],[".","NUMBER"],["&","TIE"],[" ","SPACE"],[void 0,"EOS"]]);class ut{_id;_type;_token;_value;constructor(t,e,s){this._id=t,this._type=e,this._token=s,this._value=s?Number(s):-1}get type(){return this._type}get token(){return this._token}get value(){return Number.isNaN(this._value)?-1:this._value}toString(){return JSON.stringify({id:this._id,type:this._type,token:this._token,value:this._value})}}class lt{static id=0;tokens=[];notes=[];numbers=[];constructor(t){this.tokens=t.trim().toUpperCase().split("").reverse()}get(){let t=this.tokens.pop(),e=ct.get(t);if(lt.id++,!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"SPACE"===e;)if(t=this.tokens.pop(),e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);if("EOS"===e)return new ut(lt.id.toString(10),"EOS",t);switch(this.notes.length=0,this.numbers.length=0,e){case"TEMPO":if(t)return new ut(lt.id.toString(10),"TEMPO",t);break;case"OCTAVE":if(t)return new ut(lt.id.toString(10),"OCTAVE",t);break;case"NOTE":if(t){if(this.notes.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NOTE",this.notes.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"NOTE"===e;){if(this.notes.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NOTE",this.notes.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t)}return this.tokens.push(t),new ut(lt.id.toString(10),"NOTE",this.notes.join(""))}break;case"REST":if(t)return new ut(lt.id.toString(10),"REST",t);break;case"NUMBER":if(t){if(this.numbers.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t);for(;"NUMBER"===e;){if(this.numbers.push(t),t=this.tokens.pop(),!t)return new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""));if(e=ct.get(t),!e)return new ut(lt.id.toString(10),"UNKNOWN",t)}return this.tokens.push(t),new ut(lt.id.toString(10),"NUMBER",this.numbers.join(""))}break;case"TIE":if(t)return new ut(lt.id.toString(10),"TIE",t)}return null}}class pt{static indent=0;_id;_operator;_left;_right;constructor(t,e,s,i){this._id=t,this._operator=e,this._left=s,this._right=i}concat(t){this._right=t}get operator(){return this._operator}get left(){return this._left}get right(){return this._right}clear(){pt.indent=0}toString(){let t="";for(let e=0;e<pt.indent;e++)t+=" ";return pt.indent++,`\n${t} ${this._operator.token} (id = ${this._id})\n${t} /\\\n${t}${this._left?.operator.token??""}${null!==this._right&&void 0!==this._right._operator.token?this.toString.call(this._right):"EOS"}\n`}}class dt{_token;constructor(t){this._token=t}get token(){return this._token}}class ft{static id=0;tokenizer;syntaxTree=[];constructor(t){this.tokenizer=t}parse(){lt.id=0;let t=this.tokenizer.get(),e=this.tokenizer.get();for(;;){if(!t||!e)return this.syntaxTree;switch(ft.id+=2,t.type){case"TEMPO":if("NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree.push(i);break}return new dt(t);case"OCTAVE":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"NOTE":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"REST":if(this.syntaxTree.length>0&&"NUMBER"===e.type){const s=new pt((ft.id-0).toString(10),e,null,null),i=new pt((ft.id-1).toString(10),t,s,null);this.syntaxTree[this.syntaxTree.length-1].concat(i),this.syntaxTree.push(i);break}return new dt(t);case"NUMBER":ft.id-=2;break;case"TIE":if(this.syntaxTree.length>0){ft.id--;const e=new pt((ft.id-0).toString(10),t,null,null);this.syntaxTree[this.syntaxTree.length-1].concat(e),this.syntaxTree.push(e);break}return new dt(t);case"EOS":if(this.syntaxTree.length>0){const e=new pt((ft.id-1).toString(10),t,null,null);this.syntaxTree[this.syntaxTree.length-1].concat(e),this.syntaxTree.push(e)}else{const e=new pt((ft.id-1).toString(10),t,null,null);this.syntaxTree.push(e)}return this.syntaxTree}t=e,e=this.tokenizer.get()}}free(){this.syntaxTree.length=0}}const mt=1.0594630943592953,vt=27.5;function gt(t){switch(t.toUpperCase()){case"C":case"D":case"E":case"F":case"G":case"A":case"B":case"R":return!0;default:return!1}}function bt(t,e){let s=0;switch(e){case"C":s=3;break;case"D":s=5;break;case"E":s=7;break;case"F":s=8;break;case"G":s=10;break;case"A":s=12;break;case"B":s=14;break;case"R":return-1}const i=12*(t-1)+s;return i>=0?i:-1}function yt(t){return t>=0?vt*mt**t:0}function wt(t){const{file:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t,a=new FileReader;switch(a.onprogress=t=>{n&&n(t)},a.onerror=t=>{if(!r)return;let e;switch(a.error?.code){case a.error?.NOT_FOUND_ERR:e="NOT_FOUND_ERR";break;case a.error?.SECURITY_ERR:e="SECURITY_ERR";break;case a.error?.ABORT_ERR:e="ABORT_ERR";break;case a.error?.NOT_SUPPORTED_ERR:e="NOT_READABLE_ERR";break;default:e="ERR"}r(t,e)},a.onload=t=>{if(!i)return;let e=a.result;switch(s){case"text":"string"==typeof e&&(e=e.replace(/<(\/?script.*?)>/gi,"&lt;$1&gt;"));break;case"json":"string"==typeof e&&(e=JSON.parse(e.replace(/<(\/?script.*?)>/gi,"&lt;$1&gt;")))}i(t,e)},s){case"arraybuffer":a.readAsArrayBuffer(e);break;case"dataURL":a.readAsDataURL(e);break;case"text":case"json":a.readAsText(e,"UTF-8")}}class kt{_id;_note;_indexes;_frequencies;_start;_stop;_duration;constructor(t){const{id:e,note:s,indexes:i,frequencies:r,start:n,stop:a,duration:o}=t;this._id=e,this._note=s,this._indexes=i,this._frequencies=r,this._start=n,this._stop=a,this._duration=o}concat(t){return new kt({id:this._id,note:`${this._note}&${t.note}`,indexes:this._indexes,frequencies:this._frequencies,start:this._start,duration:this._duration+t.duration,stop:this._start+(this._duration+t.duration)})}get note(){return this._note}get indexes(){return this._indexes}get frequencies(){return this._frequencies}get start(){return this._start}get stop(){return this._stop}get duration(){return this._duration}toString(){return JSON.stringify({id:this._id,note:this._note,indexes:this._indexes,frequencies:this._frequencies,start:this._start,stop:this._stop,duration:this._duration})}}class At{sequences=[];treeConstructor;syntaxTree="";timeOf4note=0;octave=-1;currentTime=0;errorCallback;constructor(t,e){this.treeConstructor=t,this.errorCallback=e||(t=>{throw t})}get(){ft.id=0;const t=this.treeConstructor.parse();if(!t)return void this.errorCallback(new dt(new ut("1","UNKNOWN","")));if(t instanceof dt)return void this.errorCallback(t);this.timeOf4note=0,this.octave=-1,this.currentTime=0;let e=t[0];for(;null!==e;){if(!e)return void this.errorCallback(new dt(new ut((this.sequences.length+1).toString(10),"UNKNOWN","")));if(e instanceof dt)return void this.errorCallback(e);const t=e.operator,s=t.type,i=e.left,r=null!==i?i.operator.value:-1;switch(s){case"TEMPO":if(r<=0)return void this.errorCallback(new dt(t));this.timeOf4note=60/r,e=e.right;break;case"OCTAVE":if(r<0)return void this.errorCallback(new dt(t));this.octave=r,e=e.right;break;case"NOTE":case"REST":case"TIE":{const t=this.push("TIE"===s?e.right:e);if(t instanceof dt)return void this.errorCallback(t);"TIE"===s?(this.concat(),e=e.right?.right??null):e=e.right;break}case"EOS":e=e.right}}return this.syntaxTree=t[0].toString(),this.treeConstructor.free(),this.sequences}getSyntaxTree(){return this.syntaxTree}push(t){if(null===t)return;const e=t.left,s=t.right;if(null===e||null===s)return;const i=e.operator,r=s.operator;if(null===i&&null===r)return this.push(e),void this.push(s);const n=t.operator.token,a=i.value,o=i.token,h=[],c=[];if(!n)return;for(let t=0,e=n.length;t<e;t++){const e=n.charAt(t);if(!gt(e))continue;let s=bt(this.octave,e);switch(n.charAt(t+1)){case"+":case"#":s++,t++;break;case"-":s--,t++}if(s>=h[0]&&(s-=12),-1!==s&&s<0)return;h.push(s)}for(const t of h){const e=yt(t);if(e<0)return;c.push(e)}let u=0;switch(a){case 1:case 2:case 4:case 8:case 16:case 32:case 64:case 128:case 256:if(o){const t=4/a;o.includes(".")?u+=t*this.timeOf4note*1.5:u+=t*this.timeOf4note}break;case 6:u+=2*this.timeOf4note/3;break;case 12:u+=this.timeOf4note/3;break;case 18:u+=2*this.timeOf4note/9;break;case 24:u+=.5*this.timeOf4note/3;break;case 36:u+=this.timeOf4note/9;break;case 48:u+=.25*this.timeOf4note/3;break;case 72:u+=.5*this.timeOf4note/9;break;case 96:u+=.125*this.timeOf4note/3;break;case 144:u+=.25*this.timeOf4note/9;break;case 192:u+=.0625*this.timeOf4note/3;break;default:return void this.errorCallback(new dt(i))}const l=(this.sequences.length+1).toString(10),p=`${n}${o}`,d=this.currentTime,f=d+u;this.sequences.push(new kt({id:l,note:p,indexes:h,frequencies:c,start:d,stop:f,duration:u})),this.currentTime+=u}concat(){const t=this.sequences.pop(),e=this.sequences.pop();e&&t&&this.sequences.push(e.concat(t))}}const xt=()=>{let t=null;self.onmessage=e=>{switch(e.data.type){case"schedule":"number"==typeof e.data.duration&&(t=self.setTimeout((()=>{self.postMessage({type:"next"})}),1e3*e.data.duration));break;case"next":break;case"stop":null!==t&&(self.clearTimeout(t),self.close(),t=null)}}};class Tt{sequences=[];source;mml;syntaxTree;previous=null;scheduleWorker=null;currentIndex=0;currentPosition=0;offset=0;constructor(t){const{source:e,mml:s,offset:i,startCallback:r,stopCallback:n,endedCallback:a,errorCallback:o}=t;this.source=e,this.mml=s,this.offset=i??0,r&&(this.startCallback=r),n&&(this.stopCallback=n),a&&(this.endedCallback=a),o&&(this.errorCallback=o);const h=new lt(s),c=new ft(h),u=new At(c,this.errorCallback),l=u.get();l&&(this.sequences=l),this.syntaxTree=u.getSyntaxTree();const p=ht(xt.toString());this.scheduleWorker=new Worker(p),window.URL.revokeObjectURL(p)}start(t){if(null===this.scheduleWorker)return;if(!this.sequences[this.currentIndex])return this.stop(),void(this.endedCallback&&this.endedCallback());const e=this.sequences[this.currentIndex++];if(t){const t=this.mml.slice(0,this.currentPosition),s=this.mml.slice(this.currentPosition).replace(e.note,`<span class="x-highlight">${e.note}</span>`);this.mml=`${t}${s}`,this.currentPosition+=this.mml.slice(this.currentPosition).indexOf("</span>")+7}else{const t=this.mml.slice(0,this.currentPosition),s=e.note;this.mml=`${t}${s}`,this.currentPosition+=s.length}if(this.source instanceof K)this.source.ready(0,e.duration).start(e.frequencies),this.startCallback&&this.startCallback(e);else if(this.source instanceof Z){const t=e.indexes.filter((t=>-1!==t)).map((t=>t+this.offset));this.source.ready(0,e.duration).start(t),this.startCallback&&this.startCallback(e,this.offset)}else this.source instanceof tt&&(this.source.start(),this.startCallback&&this.startCallback(e));const s={type:"schedule",duration:e.duration};this.scheduleWorker.postMessage(s),this.scheduleWorker.onmessage=s=>{"next"===s.data.type&&(this.source instanceof K?this.stopCallback&&this.stopCallback(e):this.source instanceof Z?this.stopCallback&&this.stopCallback(e,this.offset):this.source instanceof tt&&(this.source.stop(),this.stopCallback&&this.stopCallback(e)),this.previous=e,this.start(t))}}stop(){if(null===this.scheduleWorker)return;if(null===this.previous)return;if(this.source instanceof K)this.source.stop(),this.stopCallback&&this.stopCallback(this.previous);else if(this.source instanceof Z){const t=this.previous.indexes.filter((t=>-1!==t)).map((t=>t+this.offset));this.source.stop(t),this.stopCallback&&this.stopCallback(this.previous,this.offset)}else this.source instanceof tt&&(this.source.stop(),this.stopCallback&&this.stopCallback(this.previous));this.scheduleWorker.postMessage({type:"stop"}),this.scheduleWorker.terminate(),this.scheduleWorker=null}getMML(){return this.mml}getSequences(){return this.sequences}getSyntaxTree(){return this.syntaxTree}has(){return this.sequences.length>0}paused(){return null===this.scheduleWorker}getCurrentIndex(){return this.currentIndex}setCurrentIndex(t){t>=0&&t<this.sequences.length&&(this.currentIndex=t)}}class St{parts=[];constructor(){}setup(t){return t?.startCallback&&(this.startCallback=t.startCallback),t?.stopCallback&&(this.stopCallback=t.stopCallback),t?.endedCallback&&(this.endedCallback=t.endedCallback),t?.errorCallback&&(this.errorCallback=t.errorCallback),this}ready(t){const{source:e,mmls:s,offset:i}=t;this.stop(),this.clear();const r=this.startCallback,n=this.stopCallback,a=this.endedCallback,o=this.errorCallback;for(const t of s)this.parts.push(new Tt({source:e,mml:t,offset:i,startCallback:r,stopCallback:n,endedCallback:a,errorCallback:o}));return this}start(t,e){if(t>=0&&t<this.parts.length){this.parts[t].start(e??!1)}return this}stop(){for(const t of this.parts)t.stop();return this}getMML(t){return t>=0&&t<this.parts.length?this.parts[t].getMML():""}getMMLs(){return this.parts.map((t=>t.getMML()))}has(){return this.parts.length>0&&this.parts.every((t=>t.has()))}getSequences(t){return t>=0&&t<this.parts.length?this.parts[t].getSequences():[]}getAllSequences(){return this.parts.map((t=>t.getSequences()))}getSyntaxTree(t){return t>=0&&t<this.parts.length?this.parts[t].getSyntaxTree():""}paused(){return 0===this.parts.length||this.parts.every((t=>t.paused()))}currentIndex(t,e){return t<0||t>=this.parts.length?this:e?(this.parts[t].setCurrentIndex(e),this):this.parts[t].getCurrentIndex()}clear(){for(const t of this.parts)t.stop();return this.parts.length=0,this}toABC(t,e,s,i,r,n){let a="";a+=`X:${e||1}\n`,a+=`T:${s||""}\n`,a+=`M:${i||"4/4"}\n`,a+=`L:${r||"1/256"}\n`,a+=`K:${n||""}\n`;const o=t.match(/\s*(?:T\d+)\s*|\s*(?:O\d+)\s*|\s*(?:(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)(?:&(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)*\s*/gi);if(null===o)return a;let h=null,c=0;for(;o.length>0;){const t=o.shift()?.trim();if(!t)return a;if(/T\d+/i.test(t)){const e=Number(t.slice(1));if(e<=0)return a;a+=`Q:1/4=${e}\n`}else if(/O\d+/i.test(t)){if(h=Number(t.slice(1)),h<0)return a}else if(/(?:(?:[CDEFGABR][#+-]?)+)(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)(?:&(?:[CDEFGABR][#+-]?)+(?:256|192|144|128|96|72|64|48|36|32|24|18|16|12|8|6|4|2|1)\.?)*/i.test(t)){if(null===h)return a;let e=null;e=t.includes("&")?t.split("&"):[t];let s="";for(;e.length>0;){const t=e.shift();if(!t)return a;let i="",r=0;switch(Number(t.replace(/^.+?(\d+)\.*$/,"$1"))){case 1:i=t.replace("1","256");break;case 2:i=t.replace("2","128");break;case 4:i=t.replace("4","64");break;case 8:i=t.replace("8","32");break;case 16:i=t.replace("16","16");break;case 32:i=t.replace("32","8");break;case 64:i=t.replace("64","4");break;case 128:i=t.replace("128","2");break;case 256:i=t.replace("256","1");break;case 6:i=`(3${t.replace("6","128")}`,r=128/3;break;case 12:i=`(3${t.replace("12","64")}`,r=64/3;break;case 18:i=`(9${t.replace("18","128")}`,r=128/9;break;case 24:i=`(3${t.replace("24","32")}`,r=32/3;break;case 36:i=`(9${t.replace("36","64")}`,r=64/9;break;case 48:i=`(3${t.replace("48","16")}`,r=16/3;break;case 72:i=`(9${t.replace("72","32")}`,r=32/9;break;case 96:i=`(3${t.replace("96","8")}`,r=8/3;break;case 144:i=`(9${t.replace("144","16")}`,r=16/9;break;case 192:i=`(3${t.replace("192","4")}`,r=4/3;break;default:return a}if(i.includes(".")&&(i=i.replace(/^(.+?)\d+\.+$/,"$1"+1.5*Number(i.replace(/^.+?(\d+)\.+$/,"$1")))),i.includes("(")?c+=Number(i.replace(/^.+?(\d+)\.*$/i,"$1")):c+=r,c>=256&&(i+=" | ",c=0),/R/i.test(i)){a+=`${i} `;continue}let n="";switch(h){case 0:n=",,,,";break;case 1:n=",,,";break;case 2:n=",,";break;case 3:n=",";break;case 5:n="'";break;case 6:n="''";break;case 7:n="'''"}const o=i.match(/^(\(\d+)?((?:[CDEFGAB][#+-]?)+)(.*)$/i);if(null===o)return a;const u=o[1]?o[1]:"",l=o[2].length,p=o[3]?o[3]:"";let d=0;if(u.length>0&&(i=i.replace(/^(?:\(\d+)?((?:[CDEFGAB][#+-]?)+)(.*)$/i,"$1$2")),1===l)s+=`${u}${i.slice(0,1)}${n}${p}`;else if(2===l&&/[#+-]/.test(i.charAt(1)))s+=`${u}${i.slice(1,2)}${i.slice(0,1)}${n}${p}`;else for(;d<l;)0===d&&(s+=`${u}[`),/[#+-]/.test(i.charAt(d+1))?(s+=`${i.slice(d+1,d+2)}${i.slice(d,d+1)}${n}`,d+=2):(s+=`${i.slice(d,d+1)}${n}`,d++),d===l&&(s+=`]${p}`);e.length>0?s+="&":a+=`${s} `}}}return a.replace(/R/gi,"z").replace(/[#+]/g,"^").replace(/-/g,"_").replace(/&/g,"-").replace(/\s{2}/g," ").trim()}}window.AudioContext=window.AudioContext||window.webkitAudioContext,window.URL=window.URL||window.webkitURL;const Et=new AudioContext,Mt={oscillator:null,oneshot:null,noise:null,audio:null,media:null,stream:null,processor:null,mixer:null,midi:null,mml:null},Ft=Promise.all([s(Et,SoundModuleProcessor),s(Et,RecorderProcessor),s(Et,OscillatorModuleProcessor),s(Et,OneshotModuleProcessor),s(Et,NoiseModuleProcessor),s(Et,AudioModuleProcessor),s(Et,MediaModuleProcessor),s(Et,StreamModuleProcessor),s(Et,MixerModuleProcessor),s(Et,NoiseGateProcessor),s(Et,NoiseSuppressorProcessor),s(Et,PitchShifterProcessor),s(Et,StereoProcessor),s(Et,VocalCancelerProcessor)]).then((()=>(Mt.oscillator=new K(Et),Mt.oneshot=new Z(Et),Mt.noise=new tt(Et),Mt.audio=new et(Et),Mt.media=new st(Et),Mt.stream=new it(Et),Mt.processor=new rt(Et),Mt.mixer=new nt(Et),Mt.midi=new at,Mt.mml=new St,Mt))).catch((t=>t));function Nt(t){switch(t){case"oscillator":return Mt.oscillator;case"oneshot":return Mt.oneshot;case"noise":return Mt.noise;case"audio":return Mt.audio;case"media":return Mt.media;case"stream":return Mt.stream;case"processor":return Mt.processor;case"mixer":return Mt.mixer;case"midi":return Mt.midi;case"mml":return Mt.mml;default:return null}}Nt.SAMPLE_RATE=Et.sampleRate,Nt.EQUAL_TEMPERAMENT=12,Nt.FREQUENCY_RATIO=mt,Nt.MIN_A=vt,Nt.QUARTER_NOT=4,Nt.HALF_UP="+",Nt.HALF_DOWN="-",Nt.DOT=".",Nt.isPitchChar=gt,Nt.computeIndex=bt,Nt.computeHz=function(t,e){return t<=0?0:t*2**(e/1200)},Nt.computeFrequency=yt,Nt.computePlaybackRate=function(t,e){return t<=0?1:t*2**(e/1200)},Nt.fft=function(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=-1*Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}},Nt.ifft=function(t,e,s){const i=t=>2**t,r=new Uint16Array(s),n=Math.log2(s);for(let r=1;r<=n;r++)for(let a=0;a<i(r-1);a++){const o=n-r;for(let h=0;h<i(o);h++){const c=a*i(o+1)+h,u=i(o)+c,l=h*i(r-1),p=t[c],d=e[c],f=t[u],m=e[u],v=Math.cos(2*Math.PI*l/s),g=Math.sin(2*Math.PI*l/s);r<n?(t[c]=p+f,e[c]=d+m,t[u]=v*(p-f)-g*(d-m),e[u]=v*(d-m)+g*(p-f)):(t[c]=p+f,e[c]=d+m,t[u]=p-f,e[u]=d-m)}}for(let t=1;t<=n;t++){const e=n-t;for(let s=0;s<i(t-1);s++)r[i(t-1)+s]=r[s]+i(e)}for(let i=0;i<s;i++){if(r[i]<=i)continue;const s=t[r[i]],n=e[r[i]];t[r[i]]=t[i],e[r[i]]=e[i],t[i]=s,e[i]=n}for(let i=0;i<s;i++)t[i]/=s,e[i]/=s},Nt.ajax=function(t){const{url:e,type:s,timeout:i,successCallback:r,errorCallback:n,progressCallback:a}=t,o=new XMLHttpRequest;o.timeout=i??6e4,o.ontimeout=t=>{n&&n(t,"timeout")},o.onprogress=t=>{a&&a(t)},o.onerror=t=>{n&&n(t,"error")},o.onload=t=>{r&&200===o.status&&r(t,o.response)},o.open("GET",e,!0),o.responseType=s??"arraybuffer",o.send(null)},Nt.convertTime=function(t){return t<0?{minutes:-1,seconds:-1,milliseconds:-1}:{minutes:Math.trunc(t/60),seconds:Math.trunc(t%60),milliseconds:t-Math.trunc(t)}},Nt.decode=function(t,e,s,i){return s||(s=()=>{}),i||(i=()=>{}),t.decodeAudioData(e,s,i)},Nt.requestFullscreen=function(t){return t.requestFullscreen()},Nt.exitFullscreen=function(){return document.exitFullscreen()},Nt.read=wt,Nt.drop=function(t){const{event:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t;e.preventDefault();const a=e.dataTransfer?.items[0].getAsFile()??null;return null===a?null:"objectURL"===s?window.URL.createObjectURL(a):(wt({file:a,type:s,successCallback:i,errorCallback:r,progressCallback:n}),a)},Nt.file=function(t){const{event:e,type:s,successCallback:i,errorCallback:r,progressCallback:n}=t,a=e.target.files?.item(0)??null;return null===a?null:"objectURL"===s?window.URL.createObjectURL(a):(wt({file:a,type:s,successCallback:i,errorCallback:r,progressCallback:n}),a)},Nt.toFrequencies=function(t){return t.map((t=>yt(t)))},Nt.toTextFile=function(t,e){if(e){const e=new Blob([t],{type:"text/plain"});return window.URL.createObjectURL(e)}return`data:,${encodeURIComponent(t)}`},Nt.Analyser=c,Nt.Recorder=p,Nt.Effector=d,Nt.Autopanner=f,Nt.BitCrusher=m,Nt.Chorus=v,Nt.Compressor=g,Nt.Delay=b,Nt.Equalizer=w,Nt.Filter=k,Nt.Flanger=A,Nt.Fuzz=x,Nt.Listener=T,Nt.NoiseGate=S,Nt.NoiseSuppressor=E,Nt.OverDrive=M,Nt.Panner=F,Nt.Phaser=N,Nt.PitchShifter=O,Nt.Preamp=B,Nt.Reverb=Q,Nt.Ringmodulator=$,Nt.Stereo=j,Nt.Tremolo=X,Nt.VocalCanceler=W,Nt.Wah=V,Nt.setup=()=>"running"!==Et.state?Et.resume():Promise.resolve(),Nt.promise=()=>Ft,Nt.clone=()=>{const t={oscillator:null,oneshot:null,noise:null,audio:null,media:null,stream:null,processor:null,mixer:null,midi:null,mml:null};function e(e){switch(e){case"oscillator":return t.oscillator;case"oneshot":return t.oneshot;case"noise":return t.noise;case"audio":return t.audio;case"media":return t.media;case"stream":return t.stream;case"processor":return t.processor;case"mixer":return t.mixer;case"midi":return t.midi;case"mml":return t.mml;default:return null}}return e.free=e=>{for(const s of e)null!==s&&Object.entries(t).forEach((([e,i])=>{s===i&&(t[e]=null)}))},t.oscillator=new K(Et),t.oneshot=new Z(Et),t.noise=new tt(Et),t.audio=new et(Et),t.media=new st(Et),t.stream=new it(Et),t.processor=new rt(Et),t.mixer=new nt(Et),t.midi=new at,t.mml=new St,e},Nt.free=t=>{for(const e of t)null!==e&&Object.entries(Mt).forEach((([t,s])=>{e===s&&(Mt[t]=null)}))},Nt.noConflict=t=>(window.X===Nt&&(window.X=void 0),t&&window.XSound===Nt&&(window.XSound=void 0),Nt),Nt.get=()=>Et,Nt.getCurrentTime=()=>Et.currentTime;const Ot=t=>{t.stopImmediatePropagation(),Nt.setup().finally((()=>{document.removeEventListener("mousedown",Ot,!1),document.removeEventListener("touchstart",Ot,!1)}))};return document.addEventListener("mousedown",Ot,!1),document.addEventListener("touchstart",Ot,!1),e})()));
3
3
  //# sourceMappingURL=xsound.js.map