@jadujoel/web-audio-clip-node 0.1.6 → 0.1.7

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.
@@ -1,6 +1,6 @@
1
- function ve(e){return Math.max(20*Math.log10(e),-1e3)}function Ue(e){return 10**(e/20)}var Ne=["beat","bar","8th","16th"];function q(e,t,a){return Math.min(Math.max(e,t),a)}function ge(e){return Ne.includes(e)}function G(e,t){if(!Number.isFinite(t)||t<=0)return null;let a=60/t;switch(e){case"beat":return a;case"bar":return a*4;case"8th":return a/2;case"16th":return a/4;default:return null}}function $e(e,t,a,o,r,n){if(!ge(t)||e<0)return q(e,r,n);let s=G(t,a),l=G(t,o);if(s==null||l==null)return q(e,r,n);let i=Math.round(e/s);return q(i*l,r,n)}function Je(e,t,a){let o=G(t,a);return o!=null?Math.round(e/o)*o:t==="int"?Math.round(e):e}var Qe={hertz:{snaps:[32,64,128,256,512,1024,2048,4096,8192,16384],ticks:[64,128,256,512,1024,2048,4096,8192,16384],min:32,max:16384,logarithmic:!0},decibel:{ticks:[-48,-24,-12,-6,-3,0],min:-60,max:0,skew:1},cents:{snaps:Array.from({length:49},(e,t)=>(t-24)*100),ticks:[-2400,-1200,0,1200,2400],min:-2400,max:2400,skew:1,step:1},playbackRate:{snaps:[-2,-1,-.5,0,.5,1,1.5,2],ticks:[-2,-1,0,1,2],min:-2,max:2,skew:1},gain:{snaps:[-60,-48,-36,-24,-18,-12,-9,-6,-3,-1,0],ticks:[-48,-24,-12,-6,-3,0],min:-100,max:0,skew:6},pan:{snaps:[-1,-.75,-.5,-.25,0,.25,.5,.75,1],ticks:[-1,-.5,0,.5,1],min:-1,max:1,skew:1}};function Ge(e){return e.numberOfChannels===1?[e.getChannelData(0)]:[e.getChannelData(0),e.getChannelData(1)]}function ae(e,t){if(!t||t.length===0)return;let a=e.createBuffer(t.length,t[0].length,e.sampleRate);for(let o=0;o<t.length;o++)a.copyToChannel(new Float32Array(t[o]),o);return a}function Xe(e,t,a,o){let r=G(e,t)??(e==="int"?1:null);if(r==null)return[];if(r<=0)return[];let n=[],s=Math.ceil(a/r)*r;for(let l=s;l<=o;l+=r)n.push(Math.round(l*1e10)/1e10);return n}var oe=class extends AudioWorkletNode{onscheduled;onstarted;onpaused;onresumed;onended;onlooped;onstopped;onframe;ondisposed;onstatechange;_buffer;_loopStart=0;_loopEnd=0;_loop=!1;_offset=0;_playhead=0;_fadeIn=0;_fadeOut=0;_loopCrossfade=0;_duration=-1;_previousState="initial";_bufferWriteCursor=0;timesLooped=0;state="initial";cpu=0;constructor(t,a={}){super(t,"ClipProcessor",{numberOfInputs:a.numberOfInputs??0,outputChannelCount:a.outputChannelCount??[2],processorOptions:a.processorOptions,channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfOutputs:a.numberOfOutputs,parameterData:a.parameterData}),this._buffer=ae(this.context,a.processorOptions?.buffer),this.port.onmessage=this.handleMessage}handleMessage=t=>{let{type:a,data:o}=t.data;switch(a){case"frame":{let[r,n,s,l]=o;this._playhead=s,this.cpu=l,this.onframe?.(o);break}case"scheduled":this.setState("scheduled"),this.onscheduled?.();break;case"started":this.setState("started"),this.onstarted?.();break;case"stopped":this.setState("stopped"),this.onstopped?.();break;case"paused":this.setState("paused"),this.onpaused?.();break;case"resume":this.setState("resumed"),this.onresumed?.();break;case"ended":this.setState("ended"),this.onended?.();break;case"looped":this.timesLooped++,this.onlooped?.();break;case"disposed":this.setState("disposed");break}};setState(t){this._previousState=this.state,this.state=t,this.state!==this._previousState&&this.onstatechange?.(this.state)}toggleGain(t=!0){this.port.postMessage({type:"toggleGain",data:t})}togglePlaybackRate(t=!0){this.port.postMessage({type:"togglePlaybackRate",data:t})}toggleDetune(t=!0){this.port.postMessage({type:"toggleDetune",data:t})}togglePan(t=!0){this.port.postMessage({type:"togglePan",data:t})}toggleHighpass(t=!0){this.port.postMessage({type:"toggleHighpass",data:t})}toggleLowpass(t=!0){this.port.postMessage({type:"toggleLowpass",data:t})}toggleFadeIn(t=!0){this.port.postMessage({type:"toggleFadeIn",data:t})}toggleFadeOut(t=!0){this.port.postMessage({type:"toggleFadeOut",data:t})}toggleLoopCrossfade(t=!0){this.port.postMessage({type:"toggleLoopCrossfade",data:t})}toggleLoopStart(t=!0){this.port.postMessage({type:"toggleLoopStart",data:t})}toggleLoopEnd(t=!0){this.port.postMessage({type:"toggleLoopEnd",data:t})}logState(){this.port.postMessage({type:"logState"})}get buffer(){return this._buffer}set buffer(t){this._buffer=t,this._bufferWriteCursor=t.length,this._loopStart>=t.duration&&(this._loopStart=0),(this._loopEnd<=this._loopStart||this._loopEnd>t.duration)&&(this._loopEnd=t.duration);let a=t.numberOfChannels===1?[t.getChannelData(0)]:[t.getChannelData(0),t.getChannelData(1)];this.port.postMessage({type:"buffer",data:a}),this.port.postMessage({type:"loopStart",data:this._loopStart}),this.port.postMessage({type:"loopEnd",data:this._loopEnd})}initializeBuffer(t,a,o={}){this._buffer=this.context.createBuffer(a,t,this.context.sampleRate),this._bufferWriteCursor=0;let r=t/this.context.sampleRate;this._loopStart>=r&&(this._loopStart=0),(this._loopEnd<=this._loopStart||this._loopEnd>r)&&(this._loopEnd=r),this.port.postMessage({type:"bufferInit",data:{channels:a,totalLength:t,streaming:o.streaming??!0}}),this.port.postMessage({type:"loopStart",data:this._loopStart}),this.port.postMessage({type:"loopEnd",data:this._loopEnd})}replaceBufferRange(t,a,o={}){this.port.postMessage({type:"bufferRange",data:{startSample:t,channelData:a,totalLength:o.totalLength,streamEnded:o.streamEnded}}),this._bufferWriteCursor=Math.max(this._bufferWriteCursor,t+(a[0]?.length??0))}appendBufferRange(t,a={}){this.replaceBufferRange(this._bufferWriteCursor,t,a)}finalizeBuffer(t){this.port.postMessage({type:"bufferEnd",data:{totalLength:t}})}start(t,a,o){if(!this._buffer){console.error("Buffer not set.");return}this.port.postMessage({type:"start",data:{when:t,offset:a,duration:o}})}stop(t=this.context.currentTime,a=0){this.port.postMessage({type:"stop",data:t+a+this._fadeOut+.2})}pause(t=this.context.currentTime){this.port.postMessage({type:"pause",data:t})}resume(t=this.context.currentTime){this.port.postMessage({type:"resume",data:t})}get loop(){return this._loop}set loop(t){this._loop!==t&&(this._loop=t,this.port.postMessage({type:"loop",data:t}))}get loopStart(){return this._loopStart}set loopStart(t){t!==this._loopStart&&(this._loopStart=t,this.port.postMessage({type:"loopStart",data:t}))}get loopEnd(){return this._loopEnd}set loopEnd(t){t!==this._loopEnd&&(this._loopEnd=t,this.port.postMessage({type:"loopEnd",data:t}))}get duration(){return this._duration??this._buffer?.duration??-1}set duration(t){this._duration=t}get offset(){return this._offset}set offset(t){this._offset=t}get playhead(){return this._playhead}set playhead(t){this.port.postMessage({type:"playhead",data:t})}get playbackRate(){return this.parameters.get("playbackRate")}get detune(){return this.parameters.get("detune")}get highpass(){return this.parameters.get("highpass")}get lowpass(){return this.parameters.get("lowpass")}get gain(){return this.parameters.get("gain")}get pan(){return this.parameters.get("pan")}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this.port.postMessage({type:"fadeIn",data:t})}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this.port.postMessage({type:"fadeOut",data:t})}get loopCrossfade(){return this._loopCrossfade}set loopCrossfade(t){this._loopCrossfade=t,this.port.postMessage({type:"loopCrossfade",data:t})}dispose(){this.port.postMessage({type:"dispose"}),this.port.close(),this.ondisposed?.(),this._buffer=void 0,this.onended=void 0,this.onframe=void 0,this.onlooped=void 0,this.onpaused=void 0,this.onresumed=void 0,this.onstarted=void 0,this.onstopped=void 0,this.onscheduled=void 0,this.onstatechange=void 0,this.ondisposed=void 0,this.state="disposed"}};var ne=`var P={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var _=128;function i(V=[]){let A=V[0]?.length??0,F=A>0;return{totalLength:F?A:null,committedLength:F?A:0,streamEnded:F,streaming:!1,writtenSpans:F?[{startSample:0,endSample:A}]:[],pendingWrites:[],lowWaterThreshold:_*4,lowWaterNotified:!1,lastUnderrunSample:null}}function G0(V){return V[0]?.length??0}function o(V){return V.streamBuffer.totalLength??G0(V.buffer)}function H0(V,A){return Array.from({length:V},()=>new Float32Array(A))}function E0(V,A){let F=[...V,A].sort((J,k)=>J.startSample-k.startSample),T=[];for(let J of F){let k=T[T.length-1];if(!k||J.startSample>k.endSample){T.push({...J});continue}k.endSample=Math.max(k.endSample,J.endSample)}return T}function I0(V){let A=0;for(let F of V){if(F.startSample>A)break;A=Math.max(A,F.endSample)}return A}function w0(V,A){if(V.committedLength-Math.floor(A)>=V.lowWaterThreshold)V.lowWaterNotified=!1}function R0(V,A,F){let T=G0(V.buffer),J=V.buffer.length;if(T>=F&&J>=A)return;let k=Math.max(T,F),Q=Math.max(J,A),X=H0(Q,k);for(let U=0;U<J;U++)X[U].set(V.buffer[U].subarray(0,T));if(V.buffer=X,V.streamBuffer.totalLength==null||V.streamBuffer.totalLength<k)V.streamBuffer.totalLength=k}function B0(V,A){let F=Math.max(Math.floor(A.startSample),0),T=A.channelData[0]?.length??0,J=A.totalLength??null,k=Math.max(F+T,J??0);R0(V,Math.max(A.channelData.length,V.buffer.length,1),k);for(let Q=0;Q<A.channelData.length;Q++)V.buffer[Q].set(A.channelData[Q],F);if(J!=null)V.streamBuffer.totalLength=J;if(T>0)V.streamBuffer.writtenSpans=E0(V.streamBuffer.writtenSpans,{startSample:F,endSample:F+T}),V.streamBuffer.committedLength=I0(V.streamBuffer.writtenSpans);if(A.streamEnded===!0)V.streamBuffer.streamEnded=!0;w0(V.streamBuffer,V.playhead)}function y0(V){if(V.streamBuffer.pendingWrites.length===0)return;for(let A of V.streamBuffer.pendingWrites)B0(V,A);V.streamBuffer.pendingWrites=[]}function _0(V,A){V.buffer=A,V.streamBuffer=i(A)}function v0(V={},A){let{buffer:F=[],streamBuffer:T=i(F),duration:J=-1,loop:k=!1,loopStart:Q=0,loopEnd:X=(F[0]?.length??0)/A,loopCrossfade:U=0,playhead:$=0,offset:M=0,startWhen:Y=0,stopWhen:j=0,pauseWhen:z=0,resumeWhen:C=0,playedSamples:N=0,state:K=P.Initial,timesLooped:w=0,fadeInDuration:v=0,fadeOutDuration:Z=0,enableFadeIn:E=v>0,enableFadeOut:O=Z>0,enableLoopStart:R=!0,enableLoopEnd:d=!0,enableLoopCrossfade:b=U>0,enableHighpass:c=!0,enableLowpass:g=!0,enableGain:s=!0,enablePan:t=!0,enableDetune:r=!0,enablePlaybackRate:p=!0}=V;return{buffer:F,streamBuffer:T,loop:k,loopStart:Q,loopEnd:X,loopCrossfade:U,duration:J,playhead:$,offset:M,startWhen:Y,stopWhen:j,pauseWhen:z,resumeWhen:C,playedSamples:N,state:K,timesLooped:w,fadeInDuration:v,fadeOutDuration:Z,enableFadeIn:E,enableFadeOut:O,enableLoopStart:R,enableLoopEnd:d,enableHighpass:c,enableLowpass:g,enableGain:s,enablePan:t,enableDetune:r,enablePlaybackRate:p,enableLoopCrossfade:b}}function b0(V,A){return o(V)/A}function n(V,A){let F=b0(V,A);if(F<=0){V.loopStart=0,V.loopEnd=0;return}if(!Number.isFinite(V.loopStart)||V.loopStart<0)V.loopStart=0;if(V.loopStart>=F)V.loopStart=0;if(!Number.isFinite(V.loopEnd)||V.loopEnd<=V.loopStart||V.loopEnd>F)V.loopEnd=F}function e(V,A,F){if(A===void 0)return V.offset=0,0;if(A<0)return e(V,o(V)+A,F);if(A>(o(V)||1)-1)return e(V,o(V)%A,F);let T=Math.floor(A*F);return V.offset=T,T}function L0(V){let{playhead:A,bufferLength:F,loop:T,loopStartSamples:J,loopEndSamples:k}=V,Q=128;if(!T&&A+128>F)Q=Math.max(F-A,0);let X=Array(Q);if(!T){for(let Y=0,j=A;Y<Q;Y++,j++)X[Y]=j;let M=A+Q;return{playhead:M,indexes:X,looped:!1,ended:M>=F}}let U=A,$=!1;for(let M=0;M<Q;M++,U++){if(U>=k)U=J+(U-k),$=!0;X[M]=U}return{indexes:X,looped:$,ended:!1,playhead:U}}function x0(V){let{playhead:A,bufferLength:F,loop:T,loopStartSamples:J,loopEndSamples:k,playbackRates:Q}=V,X=128;if(!T&&A+128>F)X=Math.max(F-A,0);let U=Array(X),$=A,M=!1;if(T){for(let Y=0;Y<X;Y++){U[Y]=Math.min(Math.max(Math.floor($),0),F-1);let j=Q[Y]??Q[0]??1;if($+=j,j>=0&&($>k||$>F))$=J,M=!0;else if(j<0&&($<J||$<0))$=k,M=!0}return{playhead:$,indexes:U,looped:M,ended:!1}}for(let Y=0;Y<X;Y++)U[Y]=Math.min(Math.max(Math.floor($),0),F-1),$+=Q[Y]??Q[0]??1;return{playhead:$,indexes:U,looped:!1,ended:$>=F||$<0}}function m0(V,A,F){let T=Math.min(V.length,A.length);for(let J=0;J<F.length;J++)for(let k=0;k<T;k++)V[k][J]=A[k][F[J]];for(let J=T;J<V.length;J++)for(let k=0;k<V[J].length;k++)V[J][k]=0;for(let J=F.length;J<V[0].length;J++)for(let k=0;k<T;k++)V[k][J]=0}function h(V){for(let A=0;A<V.length;A++)for(let F=0;F<V[A].length;F++)V[A][F]=0}function S0(V){if(V.length>=2)for(let A=0;A<V[0].length;A++)V[1][A]=V[0][A];else{let A=new Float32Array(V[0].length);for(let F=0;F<V[0].length;F++)A[F]=V[0][F];V.push(A)}}function M0(V,A){for(let F=A.length;F<V.length;F++)A[F]=new Float32Array(V[F].length);for(let F=0;F<V.length;F++)for(let T=0;T<V[F].length;T++)A[F][T]=V[F][T]}function c0(V){let A=0;for(let F=0;F<V.length;F++)for(let T=0;T<V[F].length;T++)if(Number.isNaN(V[F][T]))A++,V[F][T]=0;return A}function V0(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function g0(V,A){if(A.length===1){let T=A[0];if(T===1)return;for(let J of V)for(let k=0;k<J.length;k++)J[k]*=T;return}let F=A[0];for(let T of V)for(let J=0;J<T.length;J++)F=A[J]??F,T[J]*=F}function h0(V,A){let F=A[0];for(let T=0;T<V[0].length;T++){F=A[T]??F;let J=F<=0?1:1-F,k=F>=0?1:1+F;V[0][T]*=J,V[1][T]*=k}}function d0(V,A,F,T){for(let J=0;J<V.length;J++){let k=V[J],{x_1:Q,x_2:X,y_1:U,y_2:$}=T[J]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let M=A[0];if(M>=20000)return;let Y=2*Math.PI*M/F,j=Math.sin(Y)/2,z=(1-Math.cos(Y))/2,C=1-Math.cos(Y),N=(1-Math.cos(Y))/2,K=1+j,w=-2*Math.cos(Y),v=1-j,Z=z/K,E=C/K,O=N/K,R=w/K,d=v/K;for(let b=0;b<k.length;b++){let c=k[b],g=Z*c+E*Q+O*X-R*U-d*$;X=Q,Q=c,$=U,U=g,k[b]=g}}else{let M=A[0];for(let Y=0;Y<k.length;Y++){let j=A[Y]??M,z=2*Math.PI*j/F,C=Math.sin(z)/2,N=(1-Math.cos(z))/2,K=1-Math.cos(z),w=(1-Math.cos(z))/2,v=1+C,Z=-2*Math.cos(z),E=1-C,O=k[Y],R=N/v*O+K/v*Q+w/v*X-Z/v*U-E/v*$;X=Q,Q=O,$=U,U=R,k[Y]=R}}T[J]={x_1:Q,x_2:X,y_1:U,y_2:$}}}function u0(V,A,F,T){for(let J=0;J<V.length;J++){let k=V[J],{x_1:Q,x_2:X,y_1:U,y_2:$}=T[J]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let M=A[0];if(M<=20)return;let Y=2*Math.PI*M/F,j=Math.sin(Y)/2,z=(1+Math.cos(Y))/2,C=-(1+Math.cos(Y)),N=(1+Math.cos(Y))/2,K=1+j,w=-2*Math.cos(Y),v=1-j;for(let Z=0;Z<k.length;Z++){let E=k[Z],O=z/K*E+C/K*Q+N/K*X-w/K*U-v/K*$;X=Q,Q=E,$=U,U=O,k[Z]=O}}else{let M=A[0];for(let Y=0;Y<k.length;Y++){let j=A[Y]??M,z=2*Math.PI*j/F,C=Math.sin(z)/2,N=(1+Math.cos(z))/2,K=-(1+Math.cos(z)),w=(1+Math.cos(z))/2,v=1+C,Z=-2*Math.cos(z),E=1-C,O=k[Y],R=N/v*O+K/v*Q+w/v*X-Z/v*U-E/v*$;X=Q,Q=O,$=U,U=R,k[Y]=R}}T[J]={x_1:Q,x_2:X,y_1:U,y_2:$}}}function P0(V,A,F,T){let{type:J,data:k}=A;switch(J){case"buffer":return _0(V,k),n(V,T),[];case"bufferInit":{let Q=k;return V.buffer=H0(Q.channels,Q.totalLength),V.streamBuffer={...i(),totalLength:Q.totalLength,streamEnded:!1,streaming:Q.streaming??!0},n(V,T),[]}case"bufferRange":return V.streamBuffer.pendingWrites.push(k),[];case"bufferEnd":{let Q=k;if(Q?.totalLength!=null)V.streamBuffer.totalLength=Q.totalLength;return V.streamBuffer.streamEnded=!0,[]}case"bufferReset":return V.buffer=[],V.streamBuffer=i(),n(V,T),[];case"start":V.timesLooped=0;{let Q=k;if(V.duration=Q?.duration??-1,V.duration===-1)V.duration=V.loop?Number.MAX_SAFE_INTEGER:(V.buffer[0]?.length??0)/T;e(V,Q?.offset,T),n(V,T),V.playhead=V.offset,V.startWhen=Q?.when??F,V.stopWhen=V.startWhen+V.duration,V.playedSamples=0,V.state=P.Scheduled}return[{type:"scheduled"}];case"stop":if(V.state===P.Ended||V.state===P.Initial)return[];return V.stopWhen=k??V.stopWhen,V.state=P.Stopped,[{type:"stopped"}];case"pause":return V.state=P.Paused,V.pauseWhen=k??F,[{type:"paused"}];case"resume":return V.state=P.Started,V.startWhen=k??F,[{type:"resume"}];case"dispose":return V.state=P.Disposed,V.buffer=[],V.streamBuffer=i(),[{type:"disposed"}];case"loop":{let Q=k,X=V.state;if(Q&&(X===P.Scheduled||X===P.Started))V.stopWhen=Number.MAX_SAFE_INTEGER,V.duration=Number.MAX_SAFE_INTEGER;if(V.loop=Q,Q)n(V,T);return[]}case"loopStart":return V.loopStart=k,[];case"loopEnd":return V.loopEnd=k,[];case"loopCrossfade":return V.loopCrossfade=k,[];case"playhead":return V.playhead=Math.floor(k),[];case"fadeIn":return V.fadeInDuration=k,[];case"fadeOut":return V.fadeOutDuration=k,[];case"toggleGain":return V.enableGain=k??!V.enableGain,[];case"togglePan":return V.enablePan=k??!V.enablePan,[];case"toggleLowpass":return V.enableLowpass=k??!V.enableLowpass,[];case"toggleHighpass":return V.enableHighpass=k??!V.enableHighpass,[];case"toggleDetune":return V.enableDetune=k??!V.enableDetune,[];case"togglePlaybackRate":return V.enablePlaybackRate=k??!V.enablePlaybackRate,[];case"toggleFadeIn":return V.enableFadeIn=k??!V.enableFadeIn,[];case"toggleFadeOut":return V.enableFadeOut=k??!V.enableFadeOut,[];case"toggleLoopStart":return V.enableLoopStart=k??!V.enableLoopStart,[];case"toggleLoopEnd":return V.enableLoopEnd=k??!V.enableLoopEnd,[];case"toggleLoopCrossfade":return V.enableLoopCrossfade=k??!V.enableLoopCrossfade,[];case"logState":return[]}return[]}function j0(V,A,F,T,J){let k=[],Q=V.state;if(Q===P.Disposed)return{keepAlive:!1,messages:k};if(y0(V),Q===P.Initial)return{keepAlive:!0,messages:k};if(Q===P.Ended)return h(A[0]),{keepAlive:!0,messages:k};if(Q===P.Scheduled)if(T.currentTime>=V.startWhen)Q=V.state=P.Started,k.push({type:"started"});else return h(A[0]),{keepAlive:!0,messages:k};else if(Q===P.Paused){if(T.currentTime>V.pauseWhen)return h(A[0]),{keepAlive:!0,messages:k}}if(T.currentTime>V.stopWhen)return h(A[0]),V.state=P.Ended,k.push({type:"ended"}),V.playedSamples=0,{keepAlive:!0,messages:k};let X=A[0],U=o(V);if(U===0)return h(X),{keepAlive:!0,messages:k};let{playbackRate:$,detune:M,lowpass:Y,highpass:j,gain:z,pan:C}=F,{buffer:N,loopStart:K,loopEnd:w,loopCrossfade:v,stopWhen:Z,playedSamples:E,enableLowpass:O,enableHighpass:R,enableGain:d,enablePan:b,enableDetune:c,enableFadeOut:g,enableFadeIn:s,enableLoopStart:t,enableLoopEnd:r,enableLoopCrossfade:p,playhead:D,fadeInDuration:A0,fadeOutDuration:F0}=V,K0=V.streamBuffer.streaming&&V.streamBuffer.committedLength<U,k0=V.loop&&!K0,u=Math.min(N.length,X.length),W0=V.duration*T.sampleRate,Z0=Math.floor(T.sampleRate*v),q0=Math.max(U-_,0),L=t?Math.min(Math.floor(K*T.sampleRate),q0):0,x=r?Math.min(Math.floor(w*T.sampleRate),U):U,N0=x-L,T0=c&&M.length>0&&M[0]!==0,l=$;if(T0){let G=Math.max($.length,M.length,_);l=new Float32Array(G);for(let W=0;W<G;W++){let I=$[W]??$[$.length-1],H=M[W]??M[M.length-1];l[W]=I*2**(H/1200)}}let J0=V.enablePlaybackRate||T0,O0=J0&&l.length>0&&l.every((G)=>G===0);if(V.streamBuffer.streaming&&!V.streamBuffer.streamEnded&&!V.streamBuffer.lowWaterNotified&&V.streamBuffer.committedLength-Math.floor(D)<V.streamBuffer.lowWaterThreshold)k.push({type:"bufferLowWater",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength}}),V.streamBuffer.lowWaterNotified=!0;if(O0){h(X);for(let G=1;G<A.length;G++)M0(X,A[G]);return{keepAlive:!0,messages:k}}let Q0={bufferLength:U,loop:k0,playhead:D,loopStartSamples:L,loopEndSamples:x,durationSamples:W0,playbackRates:l},{indexes:a,ended:U0,looped:X0,playhead:Y0}=J0?x0(Q0):L0(Q0),f=a.find((G)=>G>=V.streamBuffer.committedLength&&G<U);if(f!==void 0&&!V.streamBuffer.streamEnded&&V.streamBuffer.lastUnderrunSample!==f)k.push({type:"bufferUnderrun",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength,requestedSample:f}}),V.streamBuffer.lastUnderrunSample=f;else if(f===void 0)V.streamBuffer.lastUnderrunSample=null;m0(X,N,a);let m=Math.min(Math.floor(v*T.sampleRate),N0),D0=k0&&D>L&&D<x,C0=p&&Z0>0&&U>_;if(D0&&C0){{let G=L+m;if(m>0&&D>L&&D<G){let W=D-L,I=Math.min(Math.floor(G-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.cos(Math.PI*B/2),q=Math.floor(x-m+W+H);if(q>=0&&q<U)for(let y=0;y<u;y++)X[y][H]+=N[y][q]*S}}}{let G=x-m;if(m>0&&D>G&&D<x){let W=D-G,I=Math.min(Math.floor(x-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.sin(Math.PI*B/2),q=Math.floor(L+W+H);if(q>=0&&q<U)for(let y=0;y<u;y++)X[y][H]+=N[y][q]*S}}}}if(s&&A0>0){let G=Math.floor(A0*T.sampleRate),W=G-E;if(W>0){let I=Math.min(W,_);for(let H=0;H<I;H++){let B=(E+H)/G,S=B*B*B;for(let q=0;q<u;q++)X[q][H]*=S}}}if(g&&F0>0){let G=Math.floor(F0*T.sampleRate),W=Math.floor(T.sampleRate*(Z-T.currentTime));if(W<G+_)for(let I=0;I<_;I++){let H=W-I;if(H>=G)continue;let B=H<=0?0:H/G,S=B*B*B;for(let q=0;q<u;q++)X[q][I]*=S}}if(O)d0(X,Y,T.sampleRate,J.lowpass);if(R)u0(X,j,T.sampleRate,J.highpass);if(d)g0(X,z);if(u===1)S0(X);if(b)h0(X,C);if(X0)V.timesLooped++,k.push({type:"looped",data:V.timesLooped});if(U0)V.state=P.Ended,k.push({type:"ended"});V.playedSamples+=a.length,V.playhead=Y0;let $0=c0(X);if($0>0)return console.log({numNans:$0,indexes:a,playhead:Y0,ended:U0,looped:X0,sourceLength:U}),{keepAlive:!0,messages:k};for(let G=1;G<A.length;G++)M0(X,A[G]);return{keepAlive:!0,messages:k}}class z0 extends AudioWorkletProcessor{static get parameterDescriptors(){return[{name:"playbackRate",automationRate:"a-rate",defaultValue:1},{name:"detune",automationRate:"a-rate",defaultValue:0},{name:"gain",automationRate:"a-rate",defaultValue:1,minValue:0},{name:"pan",automationRate:"a-rate",defaultValue:0},{name:"highpass",automationRate:"a-rate",defaultValue:20,minValue:20,maxValue:20000},{name:"lowpass",automationRate:"a-rate",defaultValue:20000,minValue:20,maxValue:20000}]}properties;filterState={lowpass:V0(),highpass:V0()};lastFrameTime=0;constructor(V){super(V);this.properties=v0(V?.processorOptions,sampleRate),this.port.onmessage=(A)=>{let F=P0(this.properties,A.data,currentTime,sampleRate);for(let T of F)this.port.postMessage(T);if(this.properties.state===P.Disposed)this.port.close()}}process(V,A,F){try{let T=j0(this.properties,A,F,{currentTime,currentFrame,sampleRate},this.filterState);for(let k of T.messages)this.port.postMessage(k);let J=currentTime-this.lastFrameTime;return this.lastFrameTime=currentTime,this.port.postMessage({type:"frame",data:[currentTime,currentFrame,Math.floor(this.properties.playhead),J*1000]}),T.keepAlive}catch(T){return this.port.postMessage({type:"processorError",data:{error:String(T),state:this.properties.state,bufferChannels:this.properties.buffer?.length,bufferLength:this.properties.buffer?.[0]?.length,paramKeys:Object.keys(F),hasPlaybackRate:!!F.playbackRate,hasDetune:!!F.detune,hasGain:!!F.gain,hasPan:!!F.pan,outputChannels:A[0]?.length}}),!0}}}registerProcessor("ClipProcessor",z0);
1
+ function ve(e){return Math.max(20*Math.log10(e),-1e3)}function Ue(e){return 10**(e/20)}var Ne=["beat","bar","8th","16th"];function Y(e,t,a){return Math.min(Math.max(e,t),a)}function ge(e){return Ne.includes(e)}function K(e,t){if(!Number.isFinite(t)||t<=0)return null;let a=60/t;switch(e){case"beat":return a;case"bar":return a*4;case"8th":return a/2;case"16th":return a/4;default:return null}}function Je(e,t,a,o,r,n){if(!ge(t)||e<0)return Y(e,r,n);let s=K(t,a),l=K(t,o);if(s==null||l==null)return Y(e,r,n);let i=Math.round(e/s);return Y(i*l,r,n)}function $e(e,t,a){let o=K(t,a);return o!=null?Math.round(e/o)*o:t==="int"?Math.round(e):e}var Ge={hertz:{snaps:[32,64,128,256,512,1024,2048,4096,8192,16384],ticks:[64,128,256,512,1024,2048,4096,8192,16384],min:32,max:16384,logarithmic:!0},decibel:{ticks:[-48,-24,-12,-6,-3,0],min:-60,max:0,skew:1},cents:{snaps:Array.from({length:49},(e,t)=>(t-24)*100),ticks:[-2400,-1200,0,1200,2400],min:-2400,max:2400,skew:1,step:1},playbackRate:{snaps:[-2,-1,-.5,0,.5,1,1.5,2],ticks:[-2,-1,0,1,2],min:-2,max:2,skew:1},gain:{snaps:[-60,-48,-36,-24,-18,-12,-9,-6,-3,-1,0],ticks:[-48,-24,-12,-6,-3,0],min:-100,max:0,skew:6},pan:{snaps:[-1,-.75,-.5,-.25,0,.25,.5,.75,1],ticks:[-1,-.5,0,.5,1],min:-1,max:1,skew:1}};function Ke(e){return e.numberOfChannels===1?[e.getChannelData(0)]:[e.getChannelData(0),e.getChannelData(1)]}function ae(e,t){if(!t||t.length===0)return;let a=e.createBuffer(t.length,t[0].length,e.sampleRate);for(let o=0;o<t.length;o++)a.copyToChannel(new Float32Array(t[o]),o);return a}function Qe(e,t,a,o){let r=K(e,t)??(e==="int"?1:null);if(r==null)return[];if(r<=0)return[];let n=[],s=Math.ceil(a/r)*r;for(let l=s;l<=o;l+=r)n.push(Math.round(l*1e10)/1e10);return n}var oe=class extends AudioWorkletNode{onscheduled;onstarted;onpaused;onresumed;onended;onlooped;onstopped;onframe;ondisposed;onstatechange;_buffer;_loopStart=0;_loopEnd=0;_loop=!1;_offset=0;_playhead=0;_fadeIn=0;_fadeOut=0;_loopCrossfade=0;_duration=-1;_previousState="initial";_bufferWriteCursor=0;_hasStreamingPort=!1;timesLooped=0;state="initial";cpu=0;constructor(t,a={}){super(t,"ClipProcessor",{numberOfInputs:a.numberOfInputs??0,outputChannelCount:a.outputChannelCount??[2],processorOptions:a.processorOptions,channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfOutputs:a.numberOfOutputs,parameterData:a.parameterData}),this._buffer=ae(this.context,a.processorOptions?.buffer),this.port.onmessage=this.handleMessage}handleMessage=t=>{let{type:a,data:o}=t.data;switch(a){case"frame":{let[r,n,s,l]=o;this._playhead=s,this.cpu=l,this.onframe?.(o);break}case"scheduled":this.setState("scheduled"),this.onscheduled?.();break;case"started":this.setState("started"),this.onstarted?.();break;case"stopped":this.setState("stopped"),this.onstopped?.();break;case"paused":this.setState("paused"),this.onpaused?.();break;case"resume":this.setState("resumed"),this.onresumed?.();break;case"ended":this.setState("ended"),this.onended?.();break;case"looped":this.timesLooped++,this.onlooped?.();break;case"disposed":this.setState("disposed");break}};setState(t){this._previousState=this.state,this.state=t,this.state!==this._previousState&&this.onstatechange?.(this.state)}toggleGain(t=!0){this.port.postMessage({type:"toggleGain",data:t})}togglePlaybackRate(t=!0){this.port.postMessage({type:"togglePlaybackRate",data:t})}toggleDetune(t=!0){this.port.postMessage({type:"toggleDetune",data:t})}togglePan(t=!0){this.port.postMessage({type:"togglePan",data:t})}toggleHighpass(t=!0){this.port.postMessage({type:"toggleHighpass",data:t})}toggleLowpass(t=!0){this.port.postMessage({type:"toggleLowpass",data:t})}toggleFadeIn(t=!0){this.port.postMessage({type:"toggleFadeIn",data:t})}toggleFadeOut(t=!0){this.port.postMessage({type:"toggleFadeOut",data:t})}toggleLoopCrossfade(t=!0){this.port.postMessage({type:"toggleLoopCrossfade",data:t})}toggleLoopStart(t=!0){this.port.postMessage({type:"toggleLoopStart",data:t})}toggleLoopEnd(t=!0){this.port.postMessage({type:"toggleLoopEnd",data:t})}logState(){this.port.postMessage({type:"logState"})}get buffer(){return this._buffer}set buffer(t){this._buffer=t,this._bufferWriteCursor=t.length,this._loopStart>=t.duration&&(this._loopStart=0),(this._loopEnd<=this._loopStart||this._loopEnd>t.duration)&&(this._loopEnd=t.duration);let a=t.numberOfChannels===1?[t.getChannelData(0)]:[t.getChannelData(0),t.getChannelData(1)];this.port.postMessage({type:"buffer",data:a}),this.port.postMessage({type:"loopStart",data:this._loopStart}),this.port.postMessage({type:"loopEnd",data:this._loopEnd})}transferPort(t){this._hasStreamingPort=!0,this.port.postMessage({type:"transferPort",data:t},[t])}initializeBuffer(t,a,o={}){this._buffer=this.context.createBuffer(a,t,this.context.sampleRate),this._bufferWriteCursor=0;let r=t/this.context.sampleRate;this._loopStart>=r&&(this._loopStart=0),(this._loopEnd<=this._loopStart||this._loopEnd>r)&&(this._loopEnd=r),this.port.postMessage({type:"bufferInit",data:{channels:a,totalLength:t,streaming:o.streaming??!0}}),this.port.postMessage({type:"loopStart",data:this._loopStart}),this.port.postMessage({type:"loopEnd",data:this._loopEnd})}replaceBufferRange(t,a,o={}){this.port.postMessage({type:"bufferRange",data:{startSample:t,channelData:a,totalLength:o.totalLength,streamEnded:o.streamEnded}}),this._bufferWriteCursor=Math.max(this._bufferWriteCursor,t+(a[0]?.length??0))}appendBufferRange(t,a={}){this.replaceBufferRange(this._bufferWriteCursor,t,a)}finalizeBuffer(t){this.port.postMessage({type:"bufferEnd",data:{totalLength:t}})}start(t,a,o){if(!this._buffer&&!this._hasStreamingPort){console.error("Buffer not set.");return}this.port.postMessage({type:"start",data:{when:t,offset:a,duration:o}})}stop(t=this.context.currentTime,a=0){this.port.postMessage({type:"stop",data:t+a+this._fadeOut+.2})}pause(t=this.context.currentTime){this.port.postMessage({type:"pause",data:t})}resume(t=this.context.currentTime){this.port.postMessage({type:"resume",data:t})}get loop(){return this._loop}set loop(t){this._loop!==t&&(this._loop=t,this.port.postMessage({type:"loop",data:t}))}get loopStart(){return this._loopStart}set loopStart(t){t!==this._loopStart&&(this._loopStart=t,this.port.postMessage({type:"loopStart",data:t}))}get loopEnd(){return this._loopEnd}set loopEnd(t){t!==this._loopEnd&&(this._loopEnd=t,this.port.postMessage({type:"loopEnd",data:t}))}get duration(){return this._duration??this._buffer?.duration??-1}set duration(t){this._duration=t}get offset(){return this._offset}set offset(t){this._offset=t}get playhead(){return this._playhead}set playhead(t){this.port.postMessage({type:"playhead",data:t})}get playbackRate(){return this.parameters.get("playbackRate")}get detune(){return this.parameters.get("detune")}get highpass(){return this.parameters.get("highpass")}get lowpass(){return this.parameters.get("lowpass")}get gain(){return this.parameters.get("gain")}get pan(){return this.parameters.get("pan")}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this.port.postMessage({type:"fadeIn",data:t})}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this.port.postMessage({type:"fadeOut",data:t})}get loopCrossfade(){return this._loopCrossfade}set loopCrossfade(t){this._loopCrossfade=t,this.port.postMessage({type:"loopCrossfade",data:t})}dispose(){this.port.postMessage({type:"dispose"}),this.port.close(),this.ondisposed?.(),this._buffer=void 0,this.onended=void 0,this.onframe=void 0,this.onlooped=void 0,this.onpaused=void 0,this.onresumed=void 0,this.onstarted=void 0,this.onstopped=void 0,this.onscheduled=void 0,this.onstatechange=void 0,this.ondisposed=void 0,this.state="disposed"}};var ne=`var j={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var _=128;function i(V=[]){let A=V[0]?.length??0,F=A>0;return{totalLength:F?A:null,committedLength:F?A:0,streamEnded:F,streaming:!1,writtenSpans:F?[{startSample:0,endSample:A}]:[],pendingWrites:[],lowWaterThreshold:_*4,lowWaterNotified:!1,lastUnderrunSample:null}}function H0(V){return V[0]?.length??0}function o(V){return V.streamBuffer.totalLength??H0(V.buffer)}function P0(V,A){return Array.from({length:V},()=>new Float32Array(A))}function E0(V,A){let F=[...V,A].sort((T,k)=>T.startSample-k.startSample),M=[];for(let T of F){let k=M[M.length-1];if(!k||T.startSample>k.endSample){M.push({...T});continue}k.endSample=Math.max(k.endSample,T.endSample)}return M}function I0(V){let A=0;for(let F of V){if(F.startSample>A)break;A=Math.max(A,F.endSample)}return A}function w0(V,A){if(V.committedLength-Math.floor(A)>=V.lowWaterThreshold)V.lowWaterNotified=!1}function R0(V,A,F){let M=H0(V.buffer),T=V.buffer.length;if(M>=F&&T>=A)return;let k=Math.max(M,F),J=Math.max(T,A),U=P0(J,k);for(let Q=0;Q<T;Q++)U[Q].set(V.buffer[Q].subarray(0,M));if(V.buffer=U,V.streamBuffer.totalLength==null||V.streamBuffer.totalLength<k)V.streamBuffer.totalLength=k}function B0(V,A){let F=Math.max(Math.floor(A.startSample),0),M=A.channelData[0]?.length??0,T=A.totalLength??null,k=Math.max(F+M,T??0);R0(V,Math.max(A.channelData.length,V.buffer.length,1),k);for(let J=0;J<A.channelData.length;J++)V.buffer[J].set(A.channelData[J],F);if(T!=null)V.streamBuffer.totalLength=T;if(M>0)V.streamBuffer.writtenSpans=E0(V.streamBuffer.writtenSpans,{startSample:F,endSample:F+M}),V.streamBuffer.committedLength=I0(V.streamBuffer.writtenSpans);if(A.streamEnded===!0)V.streamBuffer.streamEnded=!0;w0(V.streamBuffer,V.playhead)}function y0(V){if(V.streamBuffer.pendingWrites.length===0)return;for(let A of V.streamBuffer.pendingWrites)B0(V,A);V.streamBuffer.pendingWrites=[]}function _0(V,A){V.buffer=A,V.streamBuffer=i(A)}function j0(V={},A){let{buffer:F=[],streamBuffer:M=i(F),duration:T=-1,loop:k=!1,loopStart:J=0,loopEnd:U=(F[0]?.length??0)/A,loopCrossfade:Q=0,playhead:Y=0,offset:$=0,startWhen:X=0,stopWhen:v=0,pauseWhen:z=0,resumeWhen:C=0,playedSamples:N=0,state:K=j.Initial,timesLooped:w=0,fadeInDuration:P=0,fadeOutDuration:Z=0,enableFadeIn:E=P>0,enableFadeOut:O=Z>0,enableLoopStart:R=!0,enableLoopEnd:d=!0,enableLoopCrossfade:b=Q>0,enableHighpass:c=!0,enableLowpass:g=!0,enableGain:s=!0,enablePan:t=!0,enableDetune:r=!0,enablePlaybackRate:p=!0}=V;return{buffer:F,streamBuffer:M,loop:k,loopStart:J,loopEnd:U,loopCrossfade:Q,duration:T,playhead:Y,offset:$,startWhen:X,stopWhen:v,pauseWhen:z,resumeWhen:C,playedSamples:N,state:K,timesLooped:w,fadeInDuration:P,fadeOutDuration:Z,enableFadeIn:E,enableFadeOut:O,enableLoopStart:R,enableLoopEnd:d,enableHighpass:c,enableLowpass:g,enableGain:s,enablePan:t,enableDetune:r,enablePlaybackRate:p,enableLoopCrossfade:b}}function b0(V,A){return o(V)/A}function n(V,A){let F=b0(V,A);if(F<=0){V.loopStart=0,V.loopEnd=0;return}if(!Number.isFinite(V.loopStart)||V.loopStart<0)V.loopStart=0;if(V.loopStart>=F)V.loopStart=0;if(!Number.isFinite(V.loopEnd)||V.loopEnd<=V.loopStart||V.loopEnd>F)V.loopEnd=F}function e(V,A,F){if(A===void 0)return V.offset=0,0;if(A<0)return e(V,o(V)+A,F);if(A>(o(V)||1)-1)return e(V,o(V)%A,F);let M=Math.floor(A*F);return V.offset=M,M}function L0(V){let{playhead:A,bufferLength:F,loop:M,loopStartSamples:T,loopEndSamples:k}=V,J=128;if(!M&&A+128>F)J=Math.max(F-A,0);let U=Array(J);if(!M){for(let X=0,v=A;X<J;X++,v++)U[X]=v;let $=A+J;return{playhead:$,indexes:U,looped:!1,ended:$>=F}}let Q=A,Y=!1;for(let $=0;$<J;$++,Q++){if(Q>=k)Q=T+(Q-k),Y=!0;U[$]=Q}return{indexes:U,looped:Y,ended:!1,playhead:Q}}function x0(V){let{playhead:A,bufferLength:F,loop:M,loopStartSamples:T,loopEndSamples:k,playbackRates:J}=V,U=128;if(!M&&A+128>F)U=Math.max(F-A,0);let Q=Array(U),Y=A,$=!1;if(M){for(let X=0;X<U;X++){Q[X]=Math.min(Math.max(Math.floor(Y),0),F-1);let v=J[X]??J[0]??1;if(Y+=v,v>=0&&(Y>k||Y>F))Y=T,$=!0;else if(v<0&&(Y<T||Y<0))Y=k,$=!0}return{playhead:Y,indexes:Q,looped:$,ended:!1}}for(let X=0;X<U;X++)Q[X]=Math.min(Math.max(Math.floor(Y),0),F-1),Y+=J[X]??J[0]??1;return{playhead:Y,indexes:Q,looped:!1,ended:Y>=F||Y<0}}function m0(V,A,F){let M=Math.min(V.length,A.length);for(let T=0;T<F.length;T++)for(let k=0;k<M;k++)V[k][T]=A[k][F[T]];for(let T=M;T<V.length;T++)for(let k=0;k<V[T].length;k++)V[T][k]=0;for(let T=F.length;T<V[0].length;T++)for(let k=0;k<M;k++)V[k][T]=0}function h(V){for(let A=0;A<V.length;A++)for(let F=0;F<V[A].length;F++)V[A][F]=0}function S0(V){if(V.length>=2)for(let A=0;A<V[0].length;A++)V[1][A]=V[0][A];else{let A=new Float32Array(V[0].length);for(let F=0;F<V[0].length;F++)A[F]=V[0][F];V.push(A)}}function G0(V,A){for(let F=A.length;F<V.length;F++)A[F]=new Float32Array(V[F].length);for(let F=0;F<V.length;F++)for(let M=0;M<V[F].length;M++)A[F][M]=V[F][M]}function c0(V){let A=0;for(let F=0;F<V.length;F++)for(let M=0;M<V[F].length;M++)if(Number.isNaN(V[F][M]))A++,V[F][M]=0;return A}function V0(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function g0(V,A){if(A.length===1){let M=A[0];if(M===1)return;for(let T of V)for(let k=0;k<T.length;k++)T[k]*=M;return}let F=A[0];for(let M of V)for(let T=0;T<M.length;T++)F=A[T]??F,M[T]*=F}function h0(V,A){let F=A[0];for(let M=0;M<V[0].length;M++){F=A[M]??F;let T=F<=0?1:1-F,k=F>=0?1:1+F;V[0][M]*=T,V[1][M]*=k}}function d0(V,A,F,M){for(let T=0;T<V.length;T++){let k=V[T],{x_1:J,x_2:U,y_1:Q,y_2:Y}=M[T]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let $=A[0];if($>=20000)return;let X=2*Math.PI*$/F,v=Math.sin(X)/2,z=(1-Math.cos(X))/2,C=1-Math.cos(X),N=(1-Math.cos(X))/2,K=1+v,w=-2*Math.cos(X),P=1-v,Z=z/K,E=C/K,O=N/K,R=w/K,d=P/K;for(let b=0;b<k.length;b++){let c=k[b],g=Z*c+E*J+O*U-R*Q-d*Y;U=J,J=c,Y=Q,Q=g,k[b]=g}}else{let $=A[0];for(let X=0;X<k.length;X++){let v=A[X]??$,z=2*Math.PI*v/F,C=Math.sin(z)/2,N=(1-Math.cos(z))/2,K=1-Math.cos(z),w=(1-Math.cos(z))/2,P=1+C,Z=-2*Math.cos(z),E=1-C,O=k[X],R=N/P*O+K/P*J+w/P*U-Z/P*Q-E/P*Y;U=J,J=O,Y=Q,Q=R,k[X]=R}}M[T]={x_1:J,x_2:U,y_1:Q,y_2:Y}}}function u0(V,A,F,M){for(let T=0;T<V.length;T++){let k=V[T],{x_1:J,x_2:U,y_1:Q,y_2:Y}=M[T]??{x_1:0,x_2:0,y_1:0,y_2:0};if(A.length===1){let $=A[0];if($<=20)return;let X=2*Math.PI*$/F,v=Math.sin(X)/2,z=(1+Math.cos(X))/2,C=-(1+Math.cos(X)),N=(1+Math.cos(X))/2,K=1+v,w=-2*Math.cos(X),P=1-v;for(let Z=0;Z<k.length;Z++){let E=k[Z],O=z/K*E+C/K*J+N/K*U-w/K*Q-P/K*Y;U=J,J=E,Y=Q,Q=O,k[Z]=O}}else{let $=A[0];for(let X=0;X<k.length;X++){let v=A[X]??$,z=2*Math.PI*v/F,C=Math.sin(z)/2,N=(1+Math.cos(z))/2,K=-(1+Math.cos(z)),w=(1+Math.cos(z))/2,P=1+C,Z=-2*Math.cos(z),E=1-C,O=k[X],R=N/P*O+K/P*J+w/P*U-Z/P*Q-E/P*Y;U=J,J=O,Y=Q,Q=R,k[X]=R}}M[T]={x_1:J,x_2:U,y_1:Q,y_2:Y}}}function A0(V,A,F,M){let{type:T,data:k}=A;switch(T){case"buffer":return _0(V,k),n(V,M),[];case"bufferInit":{let J=k;return V.buffer=P0(J.channels,J.totalLength),V.streamBuffer={...i(),totalLength:J.totalLength,streamEnded:!1,streaming:J.streaming??!0},n(V,M),[]}case"bufferRange":return V.streamBuffer.pendingWrites.push(k),[];case"bufferEnd":{let J=k;if(J?.totalLength!=null)V.streamBuffer.totalLength=J.totalLength;return V.streamBuffer.streamEnded=!0,[]}case"bufferReset":return V.buffer=[],V.streamBuffer=i(),n(V,M),[];case"start":V.timesLooped=0;{let J=k;if(V.duration=J?.duration??-1,V.duration===-1)V.duration=V.loop?Number.MAX_SAFE_INTEGER:(V.buffer[0]?.length??0)/M;e(V,J?.offset,M),n(V,M),V.playhead=V.offset,V.startWhen=J?.when??F,V.stopWhen=V.startWhen+V.duration,V.playedSamples=0,V.state=j.Scheduled}return[{type:"scheduled"}];case"stop":if(V.state===j.Ended||V.state===j.Initial)return[];return V.stopWhen=k??V.stopWhen,V.state=j.Stopped,[{type:"stopped"}];case"pause":return V.state=j.Paused,V.pauseWhen=k??F,[{type:"paused"}];case"resume":return V.state=j.Started,V.startWhen=k??F,[{type:"resume"}];case"dispose":return V.state=j.Disposed,V.buffer=[],V.streamBuffer=i(),[{type:"disposed"}];case"loop":{let J=k,U=V.state;if(J&&(U===j.Scheduled||U===j.Started))V.stopWhen=Number.MAX_SAFE_INTEGER,V.duration=Number.MAX_SAFE_INTEGER;if(V.loop=J,J)n(V,M);return[]}case"loopStart":return V.loopStart=k,[];case"loopEnd":return V.loopEnd=k,[];case"loopCrossfade":return V.loopCrossfade=k,V.enableLoopCrossfade=V.loopCrossfade>0,[];case"playhead":return V.playhead=Math.floor(k),[];case"fadeIn":return V.fadeInDuration=k,V.enableFadeIn=V.fadeInDuration>0,[];case"fadeOut":return V.fadeOutDuration=k,V.enableFadeOut=V.fadeOutDuration>0,[];case"toggleGain":return V.enableGain=k??!V.enableGain,[];case"togglePan":return V.enablePan=k??!V.enablePan,[];case"toggleLowpass":return V.enableLowpass=k??!V.enableLowpass,[];case"toggleHighpass":return V.enableHighpass=k??!V.enableHighpass,[];case"toggleDetune":return V.enableDetune=k??!V.enableDetune,[];case"togglePlaybackRate":return V.enablePlaybackRate=k??!V.enablePlaybackRate,[];case"toggleFadeIn":return V.enableFadeIn=k??!V.enableFadeIn,[];case"toggleFadeOut":return V.enableFadeOut=k??!V.enableFadeOut,[];case"toggleLoopStart":return V.enableLoopStart=k??!V.enableLoopStart,[];case"toggleLoopEnd":return V.enableLoopEnd=k??!V.enableLoopEnd,[];case"toggleLoopCrossfade":return V.enableLoopCrossfade=k??!V.enableLoopCrossfade,[];case"logState":return[]}return[]}function v0(V,A,F,M,T){let k=[],J=V.state;if(J===j.Disposed)return{keepAlive:!1,messages:k};if(y0(V),J===j.Initial)return{keepAlive:!0,messages:k};if(J===j.Ended)return h(A[0]),{keepAlive:!0,messages:k};if(J===j.Scheduled)if(M.currentTime>=V.startWhen)J=V.state=j.Started,k.push({type:"started"});else return h(A[0]),{keepAlive:!0,messages:k};else if(J===j.Paused){if(M.currentTime>V.pauseWhen)return h(A[0]),{keepAlive:!0,messages:k}}if(M.currentTime>V.stopWhen)return h(A[0]),V.state=j.Ended,k.push({type:"ended"}),V.playedSamples=0,{keepAlive:!0,messages:k};let U=A[0],Q=o(V);if(Q===0)return h(U),{keepAlive:!0,messages:k};let{playbackRate:Y,detune:$,lowpass:X,highpass:v,gain:z,pan:C}=F,{buffer:N,loopStart:K,loopEnd:w,loopCrossfade:P,stopWhen:Z,playedSamples:E,enableLowpass:O,enableHighpass:R,enableGain:d,enablePan:b,enableDetune:c,enableFadeOut:g,enableFadeIn:s,enableLoopStart:t,enableLoopEnd:r,enableLoopCrossfade:p,playhead:D,fadeInDuration:F0,fadeOutDuration:k0}=V,K0=V.streamBuffer.streaming&&V.streamBuffer.committedLength<Q,M0=V.loop&&!K0,u=Math.min(N.length,U.length),W0=V.duration*M.sampleRate,Z0=Math.floor(M.sampleRate*P),q0=Math.max(Q-_,0),L=t?Math.min(Math.floor(K*M.sampleRate),q0):0,x=r?Math.min(Math.floor(w*M.sampleRate),Q):Q,N0=x-L,T0=c&&$.length>0&&$[0]!==0,l=Y;if(T0){let G=Math.max(Y.length,$.length,_);l=new Float32Array(G);for(let W=0;W<G;W++){let I=Y[W]??Y[Y.length-1],H=$[W]??$[$.length-1];l[W]=I*2**(H/1200)}}let J0=V.enablePlaybackRate||T0,O0=J0&&l.length>0&&l.every((G)=>G===0);if(V.streamBuffer.streaming&&!V.streamBuffer.streamEnded&&!V.streamBuffer.lowWaterNotified&&V.streamBuffer.committedLength-Math.floor(D)<V.streamBuffer.lowWaterThreshold)k.push({type:"bufferLowWater",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength}}),V.streamBuffer.lowWaterNotified=!0;if(O0){h(U);for(let G=1;G<A.length;G++)G0(U,A[G]);return{keepAlive:!0,messages:k}}let Q0={bufferLength:Q,loop:M0,playhead:D,loopStartSamples:L,loopEndSamples:x,durationSamples:W0,playbackRates:l},{indexes:a,ended:U0,looped:X0,playhead:Y0}=J0?x0(Q0):L0(Q0),f=a.find((G)=>G>=V.streamBuffer.committedLength&&G<Q);if(f!==void 0&&!V.streamBuffer.streamEnded&&V.streamBuffer.lastUnderrunSample!==f)k.push({type:"bufferUnderrun",data:{playhead:Math.floor(D),committedLength:V.streamBuffer.committedLength,requestedSample:f}}),V.streamBuffer.lastUnderrunSample=f;else if(f===void 0)V.streamBuffer.lastUnderrunSample=null;m0(U,N,a);let m=Math.min(Math.floor(P*M.sampleRate),N0),D0=M0&&D>L&&D<x,C0=p&&Z0>0&&Q>_;if(D0&&C0){{let G=L+m;if(m>0&&D>L&&D<G){let W=D-L,I=Math.min(Math.floor(G-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.cos(Math.PI*B/2),q=Math.floor(x-m+W+H);if(q>=0&&q<Q)for(let y=0;y<u;y++)U[y][H]+=N[y][q]*S}}}{let G=x-m;if(m>0&&D>G&&D<x){let W=D-G,I=Math.min(Math.floor(x-D),_);for(let H=0;H<I;H++){let B=(W+H)/m,S=Math.sin(Math.PI*B/2),q=Math.floor(L+W+H);if(q>=0&&q<Q)for(let y=0;y<u;y++)U[y][H]+=N[y][q]*S}}}}if(s&&F0>0){let G=Math.floor(F0*M.sampleRate),W=G-E;if(W>0){let I=Math.min(W,_);for(let H=0;H<I;H++){let B=(E+H)/G,S=B*B*B;for(let q=0;q<u;q++)U[q][H]*=S}}}if(g&&k0>0){let G=Math.floor(k0*M.sampleRate),W=Math.floor(M.sampleRate*(Z-M.currentTime));if(W<G+_)for(let I=0;I<_;I++){let H=W-I;if(H>=G)continue;let B=H<=0?0:H/G,S=B*B*B;for(let q=0;q<u;q++)U[q][I]*=S}}if(O)d0(U,X,M.sampleRate,T.lowpass);if(R)u0(U,v,M.sampleRate,T.highpass);if(d)g0(U,z);if(u===1)S0(U);if(b)h0(U,C);if(X0)V.timesLooped++,k.push({type:"looped",data:V.timesLooped});if(U0)V.state=j.Ended,k.push({type:"ended"});V.playedSamples+=a.length,V.playhead=Y0;let $0=c0(U);if($0>0)return console.log({numNans:$0,indexes:a,playhead:Y0,ended:U0,looped:X0,sourceLength:Q}),{keepAlive:!0,messages:k};for(let G=1;G<A.length;G++)G0(U,A[G]);return{keepAlive:!0,messages:k}}class z0 extends AudioWorkletProcessor{static get parameterDescriptors(){return[{name:"playbackRate",automationRate:"a-rate",defaultValue:1},{name:"detune",automationRate:"a-rate",defaultValue:0},{name:"gain",automationRate:"a-rate",defaultValue:1,minValue:0},{name:"pan",automationRate:"a-rate",defaultValue:0},{name:"highpass",automationRate:"a-rate",defaultValue:20,minValue:20,maxValue:20000},{name:"lowpass",automationRate:"a-rate",defaultValue:20000,minValue:20,maxValue:20000}]}properties;filterState={lowpass:V0(),highpass:V0()};lastFrameTime=0;constructor(V){super(V);this.properties=j0(V?.processorOptions,sampleRate),this.port.onmessage=(A)=>{if(A.data.type==="transferPort"){let M=A.data.data;M.onmessage=(T)=>{let k=A0(this.properties,T.data,currentTime,sampleRate);for(let J of k)this.port.postMessage(J)};return}let F=A0(this.properties,A.data,currentTime,sampleRate);for(let M of F)this.port.postMessage(M);if(this.properties.state===j.Disposed)this.port.close()}}process(V,A,F){try{let M=v0(this.properties,A,F,{currentTime,currentFrame,sampleRate},this.filterState);for(let k of M.messages)this.port.postMessage(k);let T=currentTime-this.lastFrameTime;return this.lastFrameTime=currentTime,this.port.postMessage({type:"frame",data:[currentTime,currentFrame,Math.floor(this.properties.playhead),T*1000]}),M.keepAlive}catch(M){return this.port.postMessage({type:"processorError",data:{error:String(M),state:this.properties.state,bufferChannels:this.properties.buffer?.length,bufferLength:this.properties.buffer?.[0]?.length,paramKeys:Object.keys(F),hasPlaybackRate:!!F.playbackRate,hasDetune:!!F.detune,hasGain:!!F.gain,hasPan:!!F.pan,outputChannels:A[0]?.length}}),!0}}}registerProcessor("ClipProcessor",z0);
2
2
 
3
- //# debugId=12FC7555EABD465B64756E2164756E21
3
+ //# debugId=78F68534B0A72CAE64756E2164756E21
4
4
  //# sourceMappingURL=processor.js.map
5
- `;var b={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var E=128;function K(e=[]){let t=e[0]?.length??0,a=t>0;return{totalLength:a?t:null,committedLength:a?t:0,streamEnded:a,streaming:!1,writtenSpans:a?[{startSample:0,endSample:t}]:[],pendingWrites:[],lowWaterThreshold:E*4,lowWaterNotified:!1,lastUnderrunSample:null}}function ye(e){return e[0]?.length??0}function Y(e){return e.streamBuffer.totalLength??ye(e.buffer)}function Se(e,t){return Array.from({length:e},()=>new Float32Array(t))}function Ke(e,t){let a=[...e,t].sort((r,n)=>r.startSample-n.startSample),o=[];for(let r of a){let n=o[o.length-1];if(!n||r.startSample>n.endSample){o.push({...r});continue}n.endSample=Math.max(n.endSample,r.endSample)}return o}function Ye(e){let t=0;for(let a of e){if(a.startSample>t)break;t=Math.max(t,a.endSample)}return t}function He(e,t){e.committedLength-Math.floor(t)>=e.lowWaterThreshold&&(e.lowWaterNotified=!1)}function qe(e,t,a){let o=ye(e.buffer),r=e.buffer.length;if(o>=a&&r>=t)return;let n=Math.max(o,a),s=Math.max(r,t),l=Se(s,n);for(let i=0;i<r;i++)l[i].set(e.buffer[i].subarray(0,o));e.buffer=l,(e.streamBuffer.totalLength==null||e.streamBuffer.totalLength<n)&&(e.streamBuffer.totalLength=n)}function je(e,t){let a=Math.max(Math.floor(t.startSample),0),o=t.channelData[0]?.length??0,r=t.totalLength??null,n=Math.max(a+o,r??0);qe(e,Math.max(t.channelData.length,e.buffer.length,1),n);for(let s=0;s<t.channelData.length;s++)e.buffer[s].set(t.channelData[s],a);r!=null&&(e.streamBuffer.totalLength=r),o>0&&(e.streamBuffer.writtenSpans=Ke(e.streamBuffer.writtenSpans,{startSample:a,endSample:a+o}),e.streamBuffer.committedLength=Ye(e.streamBuffer.writtenSpans)),t.streamEnded===!0&&(e.streamBuffer.streamEnded=!0),He(e.streamBuffer,e.playhead)}function ze(e){if(e.streamBuffer.pendingWrites.length!==0){for(let t of e.streamBuffer.pendingWrites)je(e,t);e.streamBuffer.pendingWrites=[]}}function Ze(e,t){e.buffer=t,e.streamBuffer=K(t)}function et(e={},t){let{buffer:a=[],streamBuffer:o=K(a),duration:r=-1,loop:n=!1,loopStart:s=0,loopEnd:l=(a[0]?.length??0)/t,loopCrossfade:i=0,playhead:f=0,offset:d=0,startWhen:u=0,stopWhen:h=0,pauseWhen:m=0,resumeWhen:M=0,playedSamples:V=0,state:y=b.Initial,timesLooped:P=0,fadeInDuration:g=0,fadeOutDuration:x=0,enableFadeIn:A=g>0,enableFadeOut:F=x>0,enableLoopStart:R=!0,enableLoopEnd:N=!0,enableLoopCrossfade:_=i>0,enableHighpass:W=!0,enableLowpass:v=!0,enableGain:z=!0,enablePan:Z=!0,enableDetune:ee=!0,enablePlaybackRate:te=!0}=e;return{buffer:a,streamBuffer:o,loop:n,loopStart:s,loopEnd:l,loopCrossfade:i,duration:r,playhead:f,offset:d,startWhen:u,stopWhen:h,pauseWhen:m,resumeWhen:M,playedSamples:V,state:y,timesLooped:P,fadeInDuration:g,fadeOutDuration:x,enableFadeIn:A,enableFadeOut:F,enableLoopStart:R,enableLoopEnd:N,enableHighpass:W,enableLowpass:v,enableGain:z,enablePan:Z,enableDetune:ee,enablePlaybackRate:te,enableLoopCrossfade:_}}function tt(e,t){return Y(e)/t}function X(e,t){let a=tt(e,t);if(a<=0){e.loopStart=0,e.loopEnd=0;return}(!Number.isFinite(e.loopStart)||e.loopStart<0)&&(e.loopStart=0),e.loopStart>=a&&(e.loopStart=0),(!Number.isFinite(e.loopEnd)||e.loopEnd<=e.loopStart||e.loopEnd>a)&&(e.loopEnd=a)}function re(e,t,a){if(t===void 0)return e.offset=0,0;if(t<0)return re(e,Y(e)+t,a);if(t>(Y(e)||1)-1)return re(e,Y(e)%t,a);let o=Math.floor(t*a);return e.offset=o,o}function at(e){let{playhead:t,bufferLength:a,loop:o,loopStartSamples:r,loopEndSamples:n}=e,s=128;!o&&t+128>a&&(s=Math.max(a-t,0));let l=new Array(s);if(!o){for(let u=0,h=t;u<s;u++,h++)l[u]=h;let d=t+s;return{playhead:d,indexes:l,looped:!1,ended:d>=a}}let i=t,f=!1;for(let d=0;d<s;d++,i++)i>=n&&(i=r+(i-n),f=!0),l[d]=i;return{indexes:l,looped:f,ended:!1,playhead:i}}function ot(e){let{playhead:t,bufferLength:a,loop:o,loopStartSamples:r,loopEndSamples:n,playbackRates:s}=e,l=128;!o&&t+128>a&&(l=Math.max(a-t,0));let i=new Array(l),f=t,d=!1;if(o){for(let u=0;u<l;u++){i[u]=Math.min(Math.max(Math.floor(f),0),a-1);let h=s[u]??s[0]??1;f+=h,h>=0&&(f>n||f>a)?(f=r,d=!0):h<0&&(f<r||f<0)&&(f=n,d=!0)}return{playhead:f,indexes:i,looped:d,ended:!1}}for(let u=0;u<l;u++)i[u]=Math.min(Math.max(Math.floor(f),0),a-1),f+=s[u]??s[0]??1;return{playhead:f,indexes:i,looped:!1,ended:f>=a||f<0}}function nt(e,t,a){let o=Math.min(e.length,t.length);for(let r=0;r<a.length;r++)for(let n=0;n<o;n++)e[n][r]=t[n][a[r]];for(let r=o;r<e.length;r++)for(let n=0;n<e[r].length;n++)e[r][n]=0;for(let r=a.length;r<e[0].length;r++)for(let n=0;n<o;n++)e[n][r]=0}function U(e){for(let t=0;t<e.length;t++)for(let a=0;a<e[t].length;a++)e[t][a]=0}function rt(e){if(e.length>=2)for(let t=0;t<e[0].length;t++)e[1][t]=e[0][t];else{let t=new Float32Array(e[0].length);for(let a=0;a<e[0].length;a++)t[a]=e[0][a];e.push(t)}}function be(e,t){for(let a=t.length;a<e.length;a++)t[a]=new Float32Array(e[a].length);for(let a=0;a<e.length;a++)for(let o=0;o<e[a].length;o++)t[a][o]=e[a][o]}function st(e){let t=0;for(let a=0;a<e.length;a++)for(let o=0;o<e[a].length;o++)Number.isNaN(e[a][o])&&(t++,e[a][o]=0);return t}function lt(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function it(e,t){if(t.length===1){let o=t[0];if(o===1)return;for(let r of e)for(let n=0;n<r.length;n++)r[n]*=o;return}let a=t[0];for(let o of e)for(let r=0;r<o.length;r++)a=t[r]??a,o[r]*=a}function ut(e,t){let a=t[0];for(let o=0;o<e[0].length;o++){a=t[o]??a;let r=a<=0?1:1-a,n=a>=0?1:1+a;e[0][o]*=r,e[1][o]*=n}}function ft(e,t,a,o){for(let r=0;r<e.length;r++){let n=e[r],{x_1:s,x_2:l,y_1:i,y_2:f}=o[r]??{x_1:0,x_2:0,y_1:0,y_2:0};if(t.length===1){let d=t[0];if(d>=2e4)return;let u=2*Math.PI*d/a,h=Math.sin(u)/2,m=(1-Math.cos(u))/2,M=1-Math.cos(u),V=(1-Math.cos(u))/2,y=1+h,P=-2*Math.cos(u),g=1-h,x=m/y,A=M/y,F=V/y,R=P/y,N=g/y;for(let _=0;_<n.length;_++){let W=n[_],v=x*W+A*s+F*l-R*i-N*f;l=s,s=W,f=i,i=v,n[_]=v}}else{let d=t[0];for(let u=0;u<n.length;u++){let h=t[u]??d,m=2*Math.PI*h/a,M=Math.sin(m)/2,V=(1-Math.cos(m))/2,y=1-Math.cos(m),P=(1-Math.cos(m))/2,g=1+M,x=-2*Math.cos(m),A=1-M,F=n[u],R=V/g*F+y/g*s+P/g*l-x/g*i-A/g*f;l=s,s=F,f=i,i=R,n[u]=R}}o[r]={x_1:s,x_2:l,y_1:i,y_2:f}}}function dt(e,t,a,o){for(let r=0;r<e.length;r++){let n=e[r],{x_1:s,x_2:l,y_1:i,y_2:f}=o[r]??{x_1:0,x_2:0,y_1:0,y_2:0};if(t.length===1){let d=t[0];if(d<=20)return;let u=2*Math.PI*d/a,h=Math.sin(u)/2,m=(1+Math.cos(u))/2,M=-(1+Math.cos(u)),V=(1+Math.cos(u))/2,y=1+h,P=-2*Math.cos(u),g=1-h;for(let x=0;x<n.length;x++){let A=n[x],F=m/y*A+M/y*s+V/y*l-P/y*i-g/y*f;l=s,s=A,f=i,i=F,n[x]=F}}else{let d=t[0];for(let u=0;u<n.length;u++){let h=t[u]??d,m=2*Math.PI*h/a,M=Math.sin(m)/2,V=(1+Math.cos(m))/2,y=-(1+Math.cos(m)),P=(1+Math.cos(m))/2,g=1+M,x=-2*Math.cos(m),A=1-M,F=n[u],R=V/g*F+y/g*s+P/g*l-x/g*i-A/g*f;l=s,s=F,f=i,i=R,n[u]=R}}o[r]={x_1:s,x_2:l,y_1:i,y_2:f}}}function pt(e,t,a,o){let{type:r,data:n}=t;switch(r){case"buffer":return Ze(e,n),X(e,o),[];case"bufferInit":{let s=n;return e.buffer=Se(s.channels,s.totalLength),e.streamBuffer={...K(),totalLength:s.totalLength,streamEnded:!1,streaming:s.streaming??!0},X(e,o),[]}case"bufferRange":return e.streamBuffer.pendingWrites.push(n),[];case"bufferEnd":{let s=n;return s?.totalLength!=null&&(e.streamBuffer.totalLength=s.totalLength),e.streamBuffer.streamEnded=!0,[]}case"bufferReset":return e.buffer=[],e.streamBuffer=K(),X(e,o),[];case"start":e.timesLooped=0;{let s=n;e.duration=s?.duration??-1,e.duration===-1&&(e.duration=e.loop?Number.MAX_SAFE_INTEGER:(e.buffer[0]?.length??0)/o),re(e,s?.offset,o),X(e,o),e.playhead=e.offset,e.startWhen=s?.when??a,e.stopWhen=e.startWhen+e.duration,e.playedSamples=0,e.state=b.Scheduled}return[{type:"scheduled"}];case"stop":return e.state===b.Ended||e.state===b.Initial?[]:(e.stopWhen=n??e.stopWhen,e.state=b.Stopped,[{type:"stopped"}]);case"pause":return e.state=b.Paused,e.pauseWhen=n??a,[{type:"paused"}];case"resume":return e.state=b.Started,e.startWhen=n??a,[{type:"resume"}];case"dispose":return e.state=b.Disposed,e.buffer=[],e.streamBuffer=K(),[{type:"disposed"}];case"loop":{let s=n,l=e.state;return s&&(l===b.Scheduled||l===b.Started)&&(e.stopWhen=Number.MAX_SAFE_INTEGER,e.duration=Number.MAX_SAFE_INTEGER),e.loop=s,s&&X(e,o),[]}case"loopStart":return e.loopStart=n,[];case"loopEnd":return e.loopEnd=n,[];case"loopCrossfade":return e.loopCrossfade=n,[];case"playhead":return e.playhead=Math.floor(n),[];case"fadeIn":return e.fadeInDuration=n,[];case"fadeOut":return e.fadeOutDuration=n,[];case"toggleGain":return e.enableGain=n??!e.enableGain,[];case"togglePan":return e.enablePan=n??!e.enablePan,[];case"toggleLowpass":return e.enableLowpass=n??!e.enableLowpass,[];case"toggleHighpass":return e.enableHighpass=n??!e.enableHighpass,[];case"toggleDetune":return e.enableDetune=n??!e.enableDetune,[];case"togglePlaybackRate":return e.enablePlaybackRate=n??!e.enablePlaybackRate,[];case"toggleFadeIn":return e.enableFadeIn=n??!e.enableFadeIn,[];case"toggleFadeOut":return e.enableFadeOut=n??!e.enableFadeOut,[];case"toggleLoopStart":return e.enableLoopStart=n??!e.enableLoopStart,[];case"toggleLoopEnd":return e.enableLoopEnd=n??!e.enableLoopEnd,[];case"toggleLoopCrossfade":return e.enableLoopCrossfade=n??!e.enableLoopCrossfade,[];case"logState":return[]}return[]}function ht(e,t,a,o,r){let n=[],s=e.state;if(s===b.Disposed)return{keepAlive:!1,messages:n};if(ze(e),s===b.Initial)return{keepAlive:!0,messages:n};if(s===b.Ended)return U(t[0]),{keepAlive:!0,messages:n};if(s===b.Scheduled)if(o.currentTime>=e.startWhen)s=e.state=b.Started,n.push({type:"started"});else return U(t[0]),{keepAlive:!0,messages:n};else if(s===b.Paused&&o.currentTime>e.pauseWhen)return U(t[0]),{keepAlive:!0,messages:n};if(o.currentTime>e.stopWhen)return U(t[0]),e.state=b.Ended,n.push({type:"ended"}),e.playedSamples=0,{keepAlive:!0,messages:n};let l=t[0],i=Y(e);if(i===0)return U(l),{keepAlive:!0,messages:n};let{playbackRate:f,detune:d,lowpass:u,highpass:h,gain:m,pan:M}=a,{buffer:V,loopStart:y,loopEnd:P,loopCrossfade:g,stopWhen:x,playedSamples:A,enableLowpass:F,enableHighpass:R,enableGain:N,enablePan:_,enableDetune:W,enableFadeOut:v,enableFadeIn:z,enableLoopStart:Z,enableLoopEnd:ee,enableLoopCrossfade:te,playhead:C,fadeInDuration:se,fadeOutDuration:le}=e,Ee=e.streamBuffer.streaming&&e.streamBuffer.committedLength<i,ie=e.loop&&!Ee,$=Math.min(V.length,l.length),Te=e.duration*o.sampleRate,_e=Math.floor(o.sampleRate*g),De=Math.max(i-E,0),D=Z?Math.min(Math.floor(y*o.sampleRate),De):0,O=ee?Math.min(Math.floor(P*o.sampleRate),i):i,Oe=O-D,ue=W&&d.length>0&&d[0]!==0,J=f;if(ue){let p=Math.max(f.length,d.length,E);J=new Float32Array(p);for(let S=0;S<p;S++){let L=f[S]??f[f.length-1],c=d[S]??d[d.length-1];J[S]=L*2**(c/1200)}}let fe=e.enablePlaybackRate||ue,we=fe&&J.length>0&&J.every(p=>p===0);if(e.streamBuffer.streaming&&!e.streamBuffer.streamEnded&&!e.streamBuffer.lowWaterNotified&&e.streamBuffer.committedLength-Math.floor(C)<e.streamBuffer.lowWaterThreshold&&(n.push({type:"bufferLowWater",data:{playhead:Math.floor(C),committedLength:e.streamBuffer.committedLength}}),e.streamBuffer.lowWaterNotified=!0),we){U(l);for(let p=1;p<t.length;p++)be(l,t[p]);return{keepAlive:!0,messages:n}}let de={bufferLength:i,loop:ie,playhead:C,loopStartSamples:D,loopEndSamples:O,durationSamples:Te,playbackRates:J},{indexes:H,ended:pe,looped:he,playhead:ce}=fe?ot(de):at(de),Q=H.find(p=>p>=e.streamBuffer.committedLength&&p<i);Q!==void 0&&!e.streamBuffer.streamEnded&&e.streamBuffer.lastUnderrunSample!==Q?(n.push({type:"bufferUnderrun",data:{playhead:Math.floor(C),committedLength:e.streamBuffer.committedLength,requestedSample:Q}}),e.streamBuffer.lastUnderrunSample=Q):Q===void 0&&(e.streamBuffer.lastUnderrunSample=null),nt(l,V,H);let w=Math.min(Math.floor(g*o.sampleRate),Oe),Ie=ie&&C>D&&C<O,We=te&&_e>0&&i>E;if(Ie&&We){{let p=D+w;if(w>0&&C>D&&C<p){let S=C-D,L=Math.min(Math.floor(p-C),E);for(let c=0;c<L;c++){let B=(S+c)/w,I=Math.cos(Math.PI*B/2),k=Math.floor(O-w+S+c);if(k>=0&&k<i)for(let T=0;T<$;T++)l[T][c]+=V[T][k]*I}}}{let p=O-w;if(w>0&&C>p&&C<O){let S=C-p,L=Math.min(Math.floor(O-C),E);for(let c=0;c<L;c++){let B=(S+c)/w,I=Math.sin(Math.PI*B/2),k=Math.floor(D+S+c);if(k>=0&&k<i)for(let T=0;T<$;T++)l[T][c]+=V[T][k]*I}}}}if(z&&se>0){let p=Math.floor(se*o.sampleRate),S=p-A;if(S>0){let L=Math.min(S,E);for(let c=0;c<L;c++){let B=(A+c)/p,I=B*B*B;for(let k=0;k<$;k++)l[k][c]*=I}}}if(v&&le>0){let p=Math.floor(le*o.sampleRate),S=Math.floor(o.sampleRate*(x-o.currentTime));if(S<p+E)for(let L=0;L<E;L++){let c=S-L;if(c>=p)continue;let B=c<=0?0:c/p,I=B*B*B;for(let k=0;k<$;k++)l[k][L]*=I}}F&&ft(l,u,o.sampleRate,r.lowpass),R&&dt(l,h,o.sampleRate,r.highpass),N&&it(l,m),$===1&&rt(l),_&&ut(l,M),he&&(e.timesLooped++,n.push({type:"looped",data:e.timesLooped})),pe&&(e.state=b.Ended,n.push({type:"ended"})),e.playedSamples+=H.length,e.playhead=ce;let me=st(l);if(me>0)return console.log({numNans:me,indexes:H,playhead:ce,ended:pe,looped:he,sourceLength:i}),{keepAlive:!0,messages:n};for(let p=1;p<t.length;p++)be(l,t[p]);return{keepAlive:!0,messages:n}}var Me="0.1.6";var ct="@jadujoel/web-audio-clip-node",mt=Me;function gt(){let e=new Blob([ne],{type:"text/javascript"});return URL.createObjectURL(e)}function bt(e=mt){return`https://cdn.jsdelivr.net/npm/${ct}@${e}/dist/processor.js`}function yt(e=document.baseURI){return new URL("./processor.js",e).toString()}var St=120,Mt=48e3,xe=[{key:"offset",label:"Offset",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0,title:"Start position in the buffer (seconds)."},{key:"duration",label:"Duration",min:-1,max:60,defaultValue:-1,hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0,title:"How long to play before auto-stopping (seconds). -1 for full length."},{key:"startDelay",label:"StartDelay",min:0,max:4,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,title:"Delay before starting (seconds)."},{key:"stopDelay",label:"StopDelay",min:0,max:4,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Delay before stopping (seconds)."},{key:"fadeIn",label:"FadeIn",min:0,max:60,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Fade-in duration (seconds)."},{key:"fadeOut",label:"FadeOut",min:0,max:60,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Fade-out duration (seconds)."}],ke=[{key:"loopStart",label:"Start",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0},{key:"loopEnd",label:"End",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0},{key:"loopCrossfade",label:"Crossfade",min:0,max:1,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0}],Ve=[{key:"playbackRate",label:"PlaybackRate",min:-2,max:2,defaultValue:1,precision:2,preset:"playbackRate",hasToggle:!0,title:"Playback speed. Negative for reverse."},{key:"detune",label:"Detune",min:-2400,max:2400,defaultValue:0,precision:4,preset:"cents",hasToggle:!0,title:"Pitch shift in cents."},{key:"gain",label:"Gain",min:-100,max:0,defaultValue:0,precision:3,preset:"gain",hasToggle:!0,title:"Amplitude in dB."},{key:"pan",label:"Pan",min:-1,max:1,defaultValue:0,preset:"pan",hasToggle:!0,title:"-1 full left, 1 full right."},{key:"lowpass",label:"Lowpass",min:32,max:16384,defaultValue:16384,preset:"hertz",hasToggle:!0,title:"Lowpass cutoff frequency."},{key:"highpass",label:"Highpass",min:32,max:16384,defaultValue:32,preset:"hertz",hasToggle:!0,title:"Highpass cutoff frequency."}],xt={key:"playhead",label:"Playhead",min:0,max:48e4,defaultValue:0,precision:1,snap:"int",title:"Current sample position of buffer playback."},Fe=[xt,...xe,...ke,...Ve];function kt(){let e={},t={},a={},o={},r={},n={};for(let s of Fe)e[s.key]=s.defaultValue,t[s.key]=s.snap??"none",a[s.key]=!0,o[s.key]=s.min,r[s.key]=s.max,n[s.key]=s.maxLockedByDefault??!1;return{values:e,snaps:t,enabled:a,mins:o,maxs:r,maxLocked:n}}function Vt(e,t,a,o){switch(t){case"gain":return`${e.toFixed(1)} dB`;case"lowpass":case"highpass":return`${Math.round(e)} Hz`;case"detune":return`${Math.round(e)} cents`;case"pan":return e===0?"center":e<0?`${Math.abs(e).toFixed(2)} left`:`${e.toFixed(2)} right`;case"playbackRate":return`${e.toFixed(2)}x`;case"playhead":return`sample ${Math.round(e)}`;default:break}if(a==="beat"||a==="bar"||a==="8th"||a==="16th"){let r=60/o;if(a==="bar"){let s=e/(r*4);return`${Math.round(s)} bars`}if(a==="8th"){let s=e/(r/2);return`${Math.round(s)} 8ths`}if(a==="16th"){let s=e/(r/4);return`${Math.round(s)} 16ths`}let n=e/r;return`${Math.round(n)} beats`}return a==="integer"?`${Math.round(e)} s`:`${e.toPrecision(4)} s`}function Ft(e,t,a,o){switch(t){case"gain":return e.toFixed(1);case"lowpass":case"highpass":return`${Math.round(e)}`;case"detune":return`${Math.round(e)}`;case"pan":return e===0?"C":e<0?`${Math.abs(e).toFixed(2)}L`:`${e.toFixed(2)}R`;case"playbackRate":return`${e.toFixed(2)}x`;case"playhead":return`${Math.round(e)}`;default:break}if(a==="beat"||a==="bar"||a==="8th"||a==="16th"){let r=60/o;return a==="bar"?`${Math.round(e/(r*4))}`:a==="8th"?`${Math.round(e/(r/2))}`:a==="16th"?`${Math.round(e/(r/4))}`:`${Math.round(e/r)}`}return a==="integer"?`${Math.round(e)}`:e.toPrecision(4)}var Ce=[{key:"fadeOutStopDelay",label:"Link StopDelay and FadeOut",controls:["stopDelay","fadeOut"]}],Ae=[{key:"loopStartEnd",label:"Link Start and End",controls:["loopStart","loopEnd"]}],Ct=[...Ce,...Ae];function At(){return{fadeOutStopDelay:!1,loopStartEnd:!1}}function Le(e){return Ct.find(t=>t.controls[0]===e||t.controls[1]===e)}function Lt(e,t){let a=Le(e);return a&&t[a.key]?a.controls:[e]}function Pt({pair:e,changedKey:t,nextValue:a,values:o,mins:r,maxs:n}){let[s,l]=e.controls;if(t!==s&&t!==l)return{[t]:a};let i=t===s?l:s,f=o[t],d=o[i],u=a-f,h=Math.max(r[t]-f,r[i]-d),m=Math.min(n[t]-f,n[i]-d),M=Math.min(Math.max(u,h),m);return{[t]:f+M,[i]:d+M}}var Rt=caches.open("sound-files");async function Bt(e){let t=performance.now(),a=await Rt,o=await a.match(e);if(o)return console.log(`[cache] Loaded ${e} from CacheStorage in ${(performance.now()-t).toFixed(0)}ms`),o.arrayBuffer();let r=await fetch(e);if(r.ok)return a.put(e,r.clone()).catch(()=>{}),console.log(`[cache] Loaded ${e} from network in ${(performance.now()-t).toFixed(0)}ms`),r.arrayBuffer()}var Et="clip-audio-store";var j="files",Pe="last-uploaded";function Re(){return new Promise((e,t)=>{let a=indexedDB.open(Et,1);a.onupgradeneeded=()=>{let o=a.result;o.objectStoreNames.contains(j)||o.createObjectStore(j)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}function Be(e,t){return e.transaction(j,t).objectStore(j)}async function Tt(e,t){let a=await Re(),o=Be(a,"readwrite"),r={name:e,arrayBuffer:t};await new Promise((n,s)=>{let l=o.put(r,Pe);l.onsuccess=()=>n(),l.onerror=()=>s(l.error)})}async function _t(){let e=await Re(),t=Be(e,"readonly");return new Promise((a,o)=>{let r=t.get(Pe);r.onsuccess=()=>a(r.result??null),r.onerror=()=>o(r.error)})}export{oe as ClipNode,St as DEFAULT_TEMPO,E as SAMPLE_BLOCK_SIZE,Mt as SAMPLE_RATE,b as State,Fe as allDefs,ae as audioBufferFromFloat32Array,kt as buildDefaults,At as buildLinkedControlPairDefaults,xe as controlDefs,lt as createFilterState,ve as dbFromLin,Ge as float32ArrayFromAudioBuffer,Ft as formatTickLabel,Vt as formatValueText,Xe as generateSnapPoints,Lt as getActiveLinkedControls,Le as getLinkedControlPairForControl,Pt as getLinkedControlUpdates,gt as getProcessorBlobUrl,bt as getProcessorCdnUrl,yt as getProcessorModuleUrl,et as getProperties,Je as getSnappedValue,G as getTempoSnapInterval,pt as handleProcessorMessage,ge as isTempoRelativeSnap,Ue as linFromDb,Bt as loadFromCache,_t as loadUploadedFile,ke as loopControlDefs,Ae as loopLinkedControlPairs,Ve as paramDefs,Qe as presets,ht as processBlock,ne as processorCode,$e as remapTempoRelativeValue,Tt as saveUploadedFile,Ce as transportLinkedControlPairs};
5
+ `;var b={Initial:0,Started:1,Stopped:2,Paused:3,Scheduled:4,Ended:5,Disposed:6};var E=128;function X(e=[]){let t=e[0]?.length??0,a=t>0;return{totalLength:a?t:null,committedLength:a?t:0,streamEnded:a,streaming:!1,writtenSpans:a?[{startSample:0,endSample:t}]:[],pendingWrites:[],lowWaterThreshold:E*4,lowWaterNotified:!1,lastUnderrunSample:null}}function ye(e){return e[0]?.length??0}function H(e){return e.streamBuffer.totalLength??ye(e.buffer)}function Me(e,t){return Array.from({length:e},()=>new Float32Array(t))}function Xe(e,t){let a=[...e,t].sort((r,n)=>r.startSample-n.startSample),o=[];for(let r of a){let n=o[o.length-1];if(!n||r.startSample>n.endSample){o.push({...r});continue}n.endSample=Math.max(n.endSample,r.endSample)}return o}function He(e){let t=0;for(let a of e){if(a.startSample>t)break;t=Math.max(t,a.endSample)}return t}function qe(e,t){e.committedLength-Math.floor(t)>=e.lowWaterThreshold&&(e.lowWaterNotified=!1)}function Ye(e,t,a){let o=ye(e.buffer),r=e.buffer.length;if(o>=a&&r>=t)return;let n=Math.max(o,a),s=Math.max(r,t),l=Me(s,n);for(let i=0;i<r;i++)l[i].set(e.buffer[i].subarray(0,o));e.buffer=l,(e.streamBuffer.totalLength==null||e.streamBuffer.totalLength<n)&&(e.streamBuffer.totalLength=n)}function je(e,t){let a=Math.max(Math.floor(t.startSample),0),o=t.channelData[0]?.length??0,r=t.totalLength??null,n=Math.max(a+o,r??0);Ye(e,Math.max(t.channelData.length,e.buffer.length,1),n);for(let s=0;s<t.channelData.length;s++)e.buffer[s].set(t.channelData[s],a);r!=null&&(e.streamBuffer.totalLength=r),o>0&&(e.streamBuffer.writtenSpans=Xe(e.streamBuffer.writtenSpans,{startSample:a,endSample:a+o}),e.streamBuffer.committedLength=He(e.streamBuffer.writtenSpans)),t.streamEnded===!0&&(e.streamBuffer.streamEnded=!0),qe(e.streamBuffer,e.playhead)}function ze(e){if(e.streamBuffer.pendingWrites.length!==0){for(let t of e.streamBuffer.pendingWrites)je(e,t);e.streamBuffer.pendingWrites=[]}}function Ze(e,t){e.buffer=t,e.streamBuffer=X(t)}function et(e={},t){let{buffer:a=[],streamBuffer:o=X(a),duration:r=-1,loop:n=!1,loopStart:s=0,loopEnd:l=(a[0]?.length??0)/t,loopCrossfade:i=0,playhead:f=0,offset:d=0,startWhen:u=0,stopWhen:h=0,pauseWhen:m=0,resumeWhen:S=0,playedSamples:V=0,state:y=b.Initial,timesLooped:L=0,fadeInDuration:g=0,fadeOutDuration:x=0,enableFadeIn:A=g>0,enableFadeOut:F=x>0,enableLoopStart:R=!0,enableLoopEnd:N=!0,enableLoopCrossfade:T=i>0,enableHighpass:W=!0,enableLowpass:v=!0,enableGain:z=!0,enablePan:Z=!0,enableDetune:ee=!0,enablePlaybackRate:te=!0}=e;return{buffer:a,streamBuffer:o,loop:n,loopStart:s,loopEnd:l,loopCrossfade:i,duration:r,playhead:f,offset:d,startWhen:u,stopWhen:h,pauseWhen:m,resumeWhen:S,playedSamples:V,state:y,timesLooped:L,fadeInDuration:g,fadeOutDuration:x,enableFadeIn:A,enableFadeOut:F,enableLoopStart:R,enableLoopEnd:N,enableHighpass:W,enableLowpass:v,enableGain:z,enablePan:Z,enableDetune:ee,enablePlaybackRate:te,enableLoopCrossfade:T}}function tt(e,t){return H(e)/t}function Q(e,t){let a=tt(e,t);if(a<=0){e.loopStart=0,e.loopEnd=0;return}(!Number.isFinite(e.loopStart)||e.loopStart<0)&&(e.loopStart=0),e.loopStart>=a&&(e.loopStart=0),(!Number.isFinite(e.loopEnd)||e.loopEnd<=e.loopStart||e.loopEnd>a)&&(e.loopEnd=a)}function re(e,t,a){if(t===void 0)return e.offset=0,0;if(t<0)return re(e,H(e)+t,a);if(t>(H(e)||1)-1)return re(e,H(e)%t,a);let o=Math.floor(t*a);return e.offset=o,o}function at(e){let{playhead:t,bufferLength:a,loop:o,loopStartSamples:r,loopEndSamples:n}=e,s=128;!o&&t+128>a&&(s=Math.max(a-t,0));let l=new Array(s);if(!o){for(let u=0,h=t;u<s;u++,h++)l[u]=h;let d=t+s;return{playhead:d,indexes:l,looped:!1,ended:d>=a}}let i=t,f=!1;for(let d=0;d<s;d++,i++)i>=n&&(i=r+(i-n),f=!0),l[d]=i;return{indexes:l,looped:f,ended:!1,playhead:i}}function ot(e){let{playhead:t,bufferLength:a,loop:o,loopStartSamples:r,loopEndSamples:n,playbackRates:s}=e,l=128;!o&&t+128>a&&(l=Math.max(a-t,0));let i=new Array(l),f=t,d=!1;if(o){for(let u=0;u<l;u++){i[u]=Math.min(Math.max(Math.floor(f),0),a-1);let h=s[u]??s[0]??1;f+=h,h>=0&&(f>n||f>a)?(f=r,d=!0):h<0&&(f<r||f<0)&&(f=n,d=!0)}return{playhead:f,indexes:i,looped:d,ended:!1}}for(let u=0;u<l;u++)i[u]=Math.min(Math.max(Math.floor(f),0),a-1),f+=s[u]??s[0]??1;return{playhead:f,indexes:i,looped:!1,ended:f>=a||f<0}}function nt(e,t,a){let o=Math.min(e.length,t.length);for(let r=0;r<a.length;r++)for(let n=0;n<o;n++)e[n][r]=t[n][a[r]];for(let r=o;r<e.length;r++)for(let n=0;n<e[r].length;n++)e[r][n]=0;for(let r=a.length;r<e[0].length;r++)for(let n=0;n<o;n++)e[n][r]=0}function U(e){for(let t=0;t<e.length;t++)for(let a=0;a<e[t].length;a++)e[t][a]=0}function rt(e){if(e.length>=2)for(let t=0;t<e[0].length;t++)e[1][t]=e[0][t];else{let t=new Float32Array(e[0].length);for(let a=0;a<e[0].length;a++)t[a]=e[0][a];e.push(t)}}function be(e,t){for(let a=t.length;a<e.length;a++)t[a]=new Float32Array(e[a].length);for(let a=0;a<e.length;a++)for(let o=0;o<e[a].length;o++)t[a][o]=e[a][o]}function st(e){let t=0;for(let a=0;a<e.length;a++)for(let o=0;o<e[a].length;o++)Number.isNaN(e[a][o])&&(t++,e[a][o]=0);return t}function lt(){return[{x_1:0,x_2:0,y_1:0,y_2:0},{x_1:0,x_2:0,y_1:0,y_2:0}]}function it(e,t){if(t.length===1){let o=t[0];if(o===1)return;for(let r of e)for(let n=0;n<r.length;n++)r[n]*=o;return}let a=t[0];for(let o of e)for(let r=0;r<o.length;r++)a=t[r]??a,o[r]*=a}function ut(e,t){let a=t[0];for(let o=0;o<e[0].length;o++){a=t[o]??a;let r=a<=0?1:1-a,n=a>=0?1:1+a;e[0][o]*=r,e[1][o]*=n}}function ft(e,t,a,o){for(let r=0;r<e.length;r++){let n=e[r],{x_1:s,x_2:l,y_1:i,y_2:f}=o[r]??{x_1:0,x_2:0,y_1:0,y_2:0};if(t.length===1){let d=t[0];if(d>=2e4)return;let u=2*Math.PI*d/a,h=Math.sin(u)/2,m=(1-Math.cos(u))/2,S=1-Math.cos(u),V=(1-Math.cos(u))/2,y=1+h,L=-2*Math.cos(u),g=1-h,x=m/y,A=S/y,F=V/y,R=L/y,N=g/y;for(let T=0;T<n.length;T++){let W=n[T],v=x*W+A*s+F*l-R*i-N*f;l=s,s=W,f=i,i=v,n[T]=v}}else{let d=t[0];for(let u=0;u<n.length;u++){let h=t[u]??d,m=2*Math.PI*h/a,S=Math.sin(m)/2,V=(1-Math.cos(m))/2,y=1-Math.cos(m),L=(1-Math.cos(m))/2,g=1+S,x=-2*Math.cos(m),A=1-S,F=n[u],R=V/g*F+y/g*s+L/g*l-x/g*i-A/g*f;l=s,s=F,f=i,i=R,n[u]=R}}o[r]={x_1:s,x_2:l,y_1:i,y_2:f}}}function dt(e,t,a,o){for(let r=0;r<e.length;r++){let n=e[r],{x_1:s,x_2:l,y_1:i,y_2:f}=o[r]??{x_1:0,x_2:0,y_1:0,y_2:0};if(t.length===1){let d=t[0];if(d<=20)return;let u=2*Math.PI*d/a,h=Math.sin(u)/2,m=(1+Math.cos(u))/2,S=-(1+Math.cos(u)),V=(1+Math.cos(u))/2,y=1+h,L=-2*Math.cos(u),g=1-h;for(let x=0;x<n.length;x++){let A=n[x],F=m/y*A+S/y*s+V/y*l-L/y*i-g/y*f;l=s,s=A,f=i,i=F,n[x]=F}}else{let d=t[0];for(let u=0;u<n.length;u++){let h=t[u]??d,m=2*Math.PI*h/a,S=Math.sin(m)/2,V=(1+Math.cos(m))/2,y=-(1+Math.cos(m)),L=(1+Math.cos(m))/2,g=1+S,x=-2*Math.cos(m),A=1-S,F=n[u],R=V/g*F+y/g*s+L/g*l-x/g*i-A/g*f;l=s,s=F,f=i,i=R,n[u]=R}}o[r]={x_1:s,x_2:l,y_1:i,y_2:f}}}function pt(e,t,a,o){let{type:r,data:n}=t;switch(r){case"buffer":return Ze(e,n),Q(e,o),[];case"bufferInit":{let s=n;return e.buffer=Me(s.channels,s.totalLength),e.streamBuffer={...X(),totalLength:s.totalLength,streamEnded:!1,streaming:s.streaming??!0},Q(e,o),[]}case"bufferRange":return e.streamBuffer.pendingWrites.push(n),[];case"bufferEnd":{let s=n;return s?.totalLength!=null&&(e.streamBuffer.totalLength=s.totalLength),e.streamBuffer.streamEnded=!0,[]}case"bufferReset":return e.buffer=[],e.streamBuffer=X(),Q(e,o),[];case"start":e.timesLooped=0;{let s=n;e.duration=s?.duration??-1,e.duration===-1&&(e.duration=e.loop?Number.MAX_SAFE_INTEGER:(e.buffer[0]?.length??0)/o),re(e,s?.offset,o),Q(e,o),e.playhead=e.offset,e.startWhen=s?.when??a,e.stopWhen=e.startWhen+e.duration,e.playedSamples=0,e.state=b.Scheduled}return[{type:"scheduled"}];case"stop":return e.state===b.Ended||e.state===b.Initial?[]:(e.stopWhen=n??e.stopWhen,e.state=b.Stopped,[{type:"stopped"}]);case"pause":return e.state=b.Paused,e.pauseWhen=n??a,[{type:"paused"}];case"resume":return e.state=b.Started,e.startWhen=n??a,[{type:"resume"}];case"dispose":return e.state=b.Disposed,e.buffer=[],e.streamBuffer=X(),[{type:"disposed"}];case"loop":{let s=n,l=e.state;return s&&(l===b.Scheduled||l===b.Started)&&(e.stopWhen=Number.MAX_SAFE_INTEGER,e.duration=Number.MAX_SAFE_INTEGER),e.loop=s,s&&Q(e,o),[]}case"loopStart":return e.loopStart=n,[];case"loopEnd":return e.loopEnd=n,[];case"loopCrossfade":return e.loopCrossfade=n,e.enableLoopCrossfade=e.loopCrossfade>0,[];case"playhead":return e.playhead=Math.floor(n),[];case"fadeIn":return e.fadeInDuration=n,e.enableFadeIn=e.fadeInDuration>0,[];case"fadeOut":return e.fadeOutDuration=n,e.enableFadeOut=e.fadeOutDuration>0,[];case"toggleGain":return e.enableGain=n??!e.enableGain,[];case"togglePan":return e.enablePan=n??!e.enablePan,[];case"toggleLowpass":return e.enableLowpass=n??!e.enableLowpass,[];case"toggleHighpass":return e.enableHighpass=n??!e.enableHighpass,[];case"toggleDetune":return e.enableDetune=n??!e.enableDetune,[];case"togglePlaybackRate":return e.enablePlaybackRate=n??!e.enablePlaybackRate,[];case"toggleFadeIn":return e.enableFadeIn=n??!e.enableFadeIn,[];case"toggleFadeOut":return e.enableFadeOut=n??!e.enableFadeOut,[];case"toggleLoopStart":return e.enableLoopStart=n??!e.enableLoopStart,[];case"toggleLoopEnd":return e.enableLoopEnd=n??!e.enableLoopEnd,[];case"toggleLoopCrossfade":return e.enableLoopCrossfade=n??!e.enableLoopCrossfade,[];case"logState":return[]}return[]}function ht(e,t,a,o,r){let n=[],s=e.state;if(s===b.Disposed)return{keepAlive:!1,messages:n};if(ze(e),s===b.Initial)return{keepAlive:!0,messages:n};if(s===b.Ended)return U(t[0]),{keepAlive:!0,messages:n};if(s===b.Scheduled)if(o.currentTime>=e.startWhen)s=e.state=b.Started,n.push({type:"started"});else return U(t[0]),{keepAlive:!0,messages:n};else if(s===b.Paused&&o.currentTime>e.pauseWhen)return U(t[0]),{keepAlive:!0,messages:n};if(o.currentTime>e.stopWhen)return U(t[0]),e.state=b.Ended,n.push({type:"ended"}),e.playedSamples=0,{keepAlive:!0,messages:n};let l=t[0],i=H(e);if(i===0)return U(l),{keepAlive:!0,messages:n};let{playbackRate:f,detune:d,lowpass:u,highpass:h,gain:m,pan:S}=a,{buffer:V,loopStart:y,loopEnd:L,loopCrossfade:g,stopWhen:x,playedSamples:A,enableLowpass:F,enableHighpass:R,enableGain:N,enablePan:T,enableDetune:W,enableFadeOut:v,enableFadeIn:z,enableLoopStart:Z,enableLoopEnd:ee,enableLoopCrossfade:te,playhead:C,fadeInDuration:se,fadeOutDuration:le}=e,Ee=e.streamBuffer.streaming&&e.streamBuffer.committedLength<i,ie=e.loop&&!Ee,J=Math.min(V.length,l.length),_e=e.duration*o.sampleRate,Te=Math.floor(o.sampleRate*g),De=Math.max(i-E,0),D=Z?Math.min(Math.floor(y*o.sampleRate),De):0,O=ee?Math.min(Math.floor(L*o.sampleRate),i):i,Oe=O-D,ue=W&&d.length>0&&d[0]!==0,$=f;if(ue){let p=Math.max(f.length,d.length,E);$=new Float32Array(p);for(let M=0;M<p;M++){let P=f[M]??f[f.length-1],c=d[M]??d[d.length-1];$[M]=P*2**(c/1200)}}let fe=e.enablePlaybackRate||ue,Ie=fe&&$.length>0&&$.every(p=>p===0);if(e.streamBuffer.streaming&&!e.streamBuffer.streamEnded&&!e.streamBuffer.lowWaterNotified&&e.streamBuffer.committedLength-Math.floor(C)<e.streamBuffer.lowWaterThreshold&&(n.push({type:"bufferLowWater",data:{playhead:Math.floor(C),committedLength:e.streamBuffer.committedLength}}),e.streamBuffer.lowWaterNotified=!0),Ie){U(l);for(let p=1;p<t.length;p++)be(l,t[p]);return{keepAlive:!0,messages:n}}let de={bufferLength:i,loop:ie,playhead:C,loopStartSamples:D,loopEndSamples:O,durationSamples:_e,playbackRates:$},{indexes:q,ended:pe,looped:he,playhead:ce}=fe?ot(de):at(de),G=q.find(p=>p>=e.streamBuffer.committedLength&&p<i);G!==void 0&&!e.streamBuffer.streamEnded&&e.streamBuffer.lastUnderrunSample!==G?(n.push({type:"bufferUnderrun",data:{playhead:Math.floor(C),committedLength:e.streamBuffer.committedLength,requestedSample:G}}),e.streamBuffer.lastUnderrunSample=G):G===void 0&&(e.streamBuffer.lastUnderrunSample=null),nt(l,V,q);let I=Math.min(Math.floor(g*o.sampleRate),Oe),we=ie&&C>D&&C<O,We=te&&Te>0&&i>E;if(we&&We){{let p=D+I;if(I>0&&C>D&&C<p){let M=C-D,P=Math.min(Math.floor(p-C),E);for(let c=0;c<P;c++){let B=(M+c)/I,w=Math.cos(Math.PI*B/2),k=Math.floor(O-I+M+c);if(k>=0&&k<i)for(let _=0;_<J;_++)l[_][c]+=V[_][k]*w}}}{let p=O-I;if(I>0&&C>p&&C<O){let M=C-p,P=Math.min(Math.floor(O-C),E);for(let c=0;c<P;c++){let B=(M+c)/I,w=Math.sin(Math.PI*B/2),k=Math.floor(D+M+c);if(k>=0&&k<i)for(let _=0;_<J;_++)l[_][c]+=V[_][k]*w}}}}if(z&&se>0){let p=Math.floor(se*o.sampleRate),M=p-A;if(M>0){let P=Math.min(M,E);for(let c=0;c<P;c++){let B=(A+c)/p,w=B*B*B;for(let k=0;k<J;k++)l[k][c]*=w}}}if(v&&le>0){let p=Math.floor(le*o.sampleRate),M=Math.floor(o.sampleRate*(x-o.currentTime));if(M<p+E)for(let P=0;P<E;P++){let c=M-P;if(c>=p)continue;let B=c<=0?0:c/p,w=B*B*B;for(let k=0;k<J;k++)l[k][P]*=w}}F&&ft(l,u,o.sampleRate,r.lowpass),R&&dt(l,h,o.sampleRate,r.highpass),N&&it(l,m),J===1&&rt(l),T&&ut(l,S),he&&(e.timesLooped++,n.push({type:"looped",data:e.timesLooped})),pe&&(e.state=b.Ended,n.push({type:"ended"})),e.playedSamples+=q.length,e.playhead=ce;let me=st(l);if(me>0)return console.log({numNans:me,indexes:q,playhead:ce,ended:pe,looped:he,sourceLength:i}),{keepAlive:!0,messages:n};for(let p=1;p<t.length;p++)be(l,t[p]);return{keepAlive:!0,messages:n}}var Se="0.1.7";var ct="@jadujoel/web-audio-clip-node",mt=Se;function gt(){let e=new Blob([ne],{type:"text/javascript"});return URL.createObjectURL(e)}function bt(e=mt){return`https://cdn.jsdelivr.net/npm/${ct}@${e}/dist/processor.js`}function yt(e=document.baseURI){return new URL("./processor.js",e).toString()}var Mt=120,St=48e3,xe=[{key:"offset",label:"Offset",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0,title:"Start position in the buffer (seconds)."},{key:"duration",label:"Duration",min:-1,max:60,defaultValue:-1,hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0,title:"How long to play before auto-stopping (seconds). -1 for full length."},{key:"startDelay",label:"StartDelay",min:0,max:4,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,title:"Delay before starting (seconds)."},{key:"stopDelay",label:"StopDelay",min:0,max:4,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Delay before stopping (seconds)."},{key:"fadeIn",label:"FadeIn",min:0,max:60,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Fade-in duration (seconds)."},{key:"fadeOut",label:"FadeOut",min:0,max:60,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,title:"Fade-out duration (seconds)."}],ke=[{key:"loopStart",label:"Start",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0},{key:"loopEnd",label:"End",min:0,max:60,defaultValue:0,snap:"bar",hasSnap:!0,hasToggle:!0,hasMaxLock:!0,maxLockedByDefault:!0},{key:"loopCrossfade",label:"Crossfade",min:0,max:1,defaultValue:0,snap:"beat",hasSnap:!0,hasToggle:!0}],Ve=[{key:"playbackRate",label:"PlaybackRate",min:-2,max:2,defaultValue:1,precision:2,preset:"playbackRate",hasToggle:!0,title:"Playback speed. Negative for reverse."},{key:"detune",label:"Detune",min:-2400,max:2400,defaultValue:0,precision:4,preset:"cents",hasToggle:!0,title:"Pitch shift in cents."},{key:"gain",label:"Gain",min:-100,max:0,defaultValue:0,precision:3,preset:"gain",hasToggle:!0,title:"Amplitude in dB."},{key:"pan",label:"Pan",min:-1,max:1,defaultValue:0,preset:"pan",hasToggle:!0,title:"-1 full left, 1 full right."},{key:"lowpass",label:"Lowpass",min:32,max:16384,defaultValue:16384,preset:"hertz",hasToggle:!0,title:"Lowpass cutoff frequency."},{key:"highpass",label:"Highpass",min:32,max:16384,defaultValue:32,preset:"hertz",hasToggle:!0,title:"Highpass cutoff frequency."}],xt={key:"playhead",label:"Playhead",min:0,max:48e4,defaultValue:0,precision:1,snap:"int",title:"Current sample position of buffer playback."},Fe=[xt,...xe,...ke,...Ve];function kt(){let e={},t={},a={},o={},r={},n={};for(let s of Fe)e[s.key]=s.defaultValue,t[s.key]=s.snap??"none",a[s.key]=!0,o[s.key]=s.min,r[s.key]=s.max,n[s.key]=s.maxLockedByDefault??!1;return{values:e,snaps:t,enabled:a,mins:o,maxs:r,maxLocked:n}}function Vt(e,t,a,o){switch(t){case"gain":return`${e.toFixed(1)} dB`;case"lowpass":case"highpass":return`${Math.round(e)} Hz`;case"detune":return`${Math.round(e)} cents`;case"pan":return e===0?"center":e<0?`${Math.abs(e).toFixed(2)} left`:`${e.toFixed(2)} right`;case"playbackRate":return`${e.toFixed(2)}x`;case"playhead":return`sample ${Math.round(e)}`;default:break}if(a==="beat"||a==="bar"||a==="8th"||a==="16th"){let r=60/o;if(a==="bar"){let s=e/(r*4);return`${Math.round(s)} bars`}if(a==="8th"){let s=e/(r/2);return`${Math.round(s)} 8ths`}if(a==="16th"){let s=e/(r/4);return`${Math.round(s)} 16ths`}let n=e/r;return`${Math.round(n)} beats`}return a==="integer"?`${Math.round(e)} s`:`${e.toPrecision(4)} s`}function Ft(e,t,a,o){switch(t){case"gain":return e.toFixed(1);case"lowpass":case"highpass":return`${Math.round(e)}`;case"detune":return`${Math.round(e)}`;case"pan":return e===0?"C":e<0?`${Math.abs(e).toFixed(2)}L`:`${e.toFixed(2)}R`;case"playbackRate":return`${e.toFixed(2)}x`;case"playhead":return`${Math.round(e)}`;default:break}if(a==="beat"||a==="bar"||a==="8th"||a==="16th"){let r=60/o;return a==="bar"?`${Math.round(e/(r*4))}`:a==="8th"?`${Math.round(e/(r/2))}`:a==="16th"?`${Math.round(e/(r/4))}`:`${Math.round(e/r)}`}return a==="integer"?`${Math.round(e)}`:e.toPrecision(4)}var Ce=[{key:"fadeOutStopDelay",label:"Link StopDelay and FadeOut",controls:["stopDelay","fadeOut"]}],Ae=[{key:"loopStartEnd",label:"Link Start and End",controls:["loopStart","loopEnd"]}],Ct=[...Ce,...Ae];function At(){return{fadeOutStopDelay:!1,loopStartEnd:!1}}function Pe(e){return Ct.find(t=>t.controls[0]===e||t.controls[1]===e)}function Pt(e,t){let a=Pe(e);return a&&t[a.key]?a.controls:[e]}function Lt({pair:e,changedKey:t,nextValue:a,values:o,mins:r,maxs:n}){let[s,l]=e.controls;if(t!==s&&t!==l)return{[t]:a};let i=t===s?l:s,f=o[t],d=o[i],u=a-f,h=Math.max(r[t]-f,r[i]-d),m=Math.min(n[t]-f,n[i]-d),S=Math.min(Math.max(u,h),m);return{[t]:f+S,[i]:d+S}}var Rt=caches.open("sound-files");async function Bt(e){let t=performance.now(),a=await Rt,o=await a.match(e);if(o)return console.log(`[cache] Loaded ${e} from CacheStorage in ${(performance.now()-t).toFixed(0)}ms`),o.arrayBuffer();let r=await fetch(e);if(r.ok)return a.put(e,r.clone()).catch(()=>{}),console.log(`[cache] Loaded ${e} from network in ${(performance.now()-t).toFixed(0)}ms`),r.arrayBuffer()}var Et="clip-audio-store";var j="files",Le="last-uploaded";function Re(){return new Promise((e,t)=>{let a=indexedDB.open(Et,1);a.onupgradeneeded=()=>{let o=a.result;o.objectStoreNames.contains(j)||o.createObjectStore(j)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}function Be(e,t){return e.transaction(j,t).objectStore(j)}async function _t(e,t){let a=await Re(),o=Be(a,"readwrite"),r={name:e,arrayBuffer:t};await new Promise((n,s)=>{let l=o.put(r,Le);l.onsuccess=()=>n(),l.onerror=()=>s(l.error)})}async function Tt(){let e=await Re(),t=Be(e,"readonly");return new Promise((a,o)=>{let r=t.get(Le);r.onsuccess=()=>a(r.result??null),r.onerror=()=>o(r.error)})}export{oe as ClipNode,Mt as DEFAULT_TEMPO,E as SAMPLE_BLOCK_SIZE,St as SAMPLE_RATE,b as State,Fe as allDefs,ae as audioBufferFromFloat32Array,kt as buildDefaults,At as buildLinkedControlPairDefaults,xe as controlDefs,lt as createFilterState,ve as dbFromLin,Ke as float32ArrayFromAudioBuffer,Ft as formatTickLabel,Vt as formatValueText,Qe as generateSnapPoints,Pt as getActiveLinkedControls,Pe as getLinkedControlPairForControl,Lt as getLinkedControlUpdates,gt as getProcessorBlobUrl,bt as getProcessorCdnUrl,yt as getProcessorModuleUrl,et as getProperties,$e as getSnappedValue,K as getTempoSnapInterval,pt as handleProcessorMessage,ge as isTempoRelativeSnap,Ue as linFromDb,Bt as loadFromCache,Tt as loadUploadedFile,ke as loopControlDefs,Ae as loopLinkedControlPairs,Ve as paramDefs,Ge as presets,ht as processBlock,ne as processorCode,Je as remapTempoRelativeValue,_t as saveUploadedFile,Ce as transportLinkedControlPairs};
6
6
  //# sourceMappingURL=lib.bundle.js.map