@blibliki/engine 0.1.24 → 0.1.25
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/dist/main.esm.js
CHANGED
|
@@ -21,5 +21,5 @@ return t.mode.CTRGladman=function(){var e=t.lib.BlockCipherMode.extend();functio
|
|
|
21
21
|
|
|
22
22
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
23
|
*/
|
|
24
|
-
return function(e){var s=t,n=s.lib,i=n.WordArray,r=n.Hasher,o=s.algo,a=i.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),c=i.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),u=i.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),h=i.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),l=i.create([0,1518500249,1859775393,2400959708,2840853838]),p=i.create([1352829926,1548603684,1836072691,2053994217,0]),d=o.RIPEMD160=r.extend({_doReset:function(){this._hash=i.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var s=0;s<16;s++){var n=e+s,i=t[n];t[n]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8)}var r,o,d,w,x,b,T,C,k,A,S,M=this._hash.words,O=l.words,E=p.words,D=a.words,I=c.words,N=u.words,R=h.words;for(b=r=M[0],T=o=M[1],C=d=M[2],k=w=M[3],A=x=M[4],s=0;s<80;s+=1)S=r+t[e+D[s]]|0,S+=s<16?f(o,d,w)+O[0]:s<32?m(o,d,w)+O[1]:s<48?_(o,d,w)+O[2]:s<64?g(o,d,w)+O[3]:v(o,d,w)+O[4],S=(S=y(S|=0,N[s]))+x|0,r=x,x=w,w=y(d,10),d=o,o=S,S=b+t[e+I[s]]|0,S+=s<16?v(T,C,k)+E[0]:s<32?g(T,C,k)+E[1]:s<48?_(T,C,k)+E[2]:s<64?m(T,C,k)+E[3]:f(T,C,k)+E[4],S=(S=y(S|=0,R[s]))+A|0,b=A,A=k,k=y(C,10),C=T,T=S;S=M[1]+d+k|0,M[1]=M[2]+w+A|0,M[2]=M[3]+x+b|0,M[3]=M[4]+r+T|0,M[4]=M[0]+o+C|0,M[0]=S},_doFinalize:function(){var t=this._data,e=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(e.length+1),this._process();for(var i=this._hash,r=i.words,o=0;o<5;o++){var a=r[o];r[o]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}return i},clone:function(){var t=r.clone.call(this);return t._hash=this._hash.clone(),t}});function f(t,e,s){return t^e^s}function m(t,e,s){return t&e|~t&s}function _(t,e,s){return(t|~e)^s}function g(t,e,s){return t&s|e&~s}function v(t,e,s){return t^(e|~s)}function y(t,e){return t<<e|t>>>32-e}s.RIPEMD160=r._createHelper(d),s.HmacRIPEMD160=r._createHmacHelper(d)}(),t.RIPEMD160}(oa())),Ua(),Ga||(Ga=1,$a.exports=function(t){return n=(s=(e=t).lib).Base,i=s.WordArray,o=(r=e.algo).SHA256,a=r.HMAC,c=r.PBKDF2=n.extend({cfg:n.extend({keySize:4,hasher:o,iterations:25e4}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var s=this.cfg,n=a.create(s.hasher,t),r=i.create(),o=i.create([1]),c=r.words,u=o.words,h=s.keySize,l=s.iterations;c.length<h;){var p=n.update(e).finalize(o);n.reset();for(var d=p.words,f=d.length,m=p,_=1;_<l;_++){m=n.finalize(m),n.reset();for(var g=m.words,v=0;v<f;v++)d[v]^=g[v]}r.concat(p),u[0]++}return r.sigBytes=4*h,r}}),e.PBKDF2=function(t,e,s){return c.create(s).compute(t,e)},t.PBKDF2;var e,s,n,i,r,o,a,c}(oa(),Ea(),Ua())),Ya(),Ja(),sc(),rc(),cc(),lc(),pc||(pc=1,dc.exports=function(t){return t.mode.ECB=((e=t.lib.BlockCipherMode.extend()).Encryptor=e.extend({processBlock:function(t,e){this._cipher.encryptBlock(t,e)}}),e.Decryptor=e.extend({processBlock:function(t,e){this._cipher.decryptBlock(t,e)}}),e),t.mode.ECB;var e}(oa(),Ja())),fc||(fc=1,mc.exports=function(t){return t.pad.AnsiX923={pad:function(t,e){var s=t.sigBytes,n=4*e,i=n-s%n,r=s+i-1;t.clamp(),t.words[r>>>2]|=i<<24-r%4*8,t.sigBytes+=i},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Ansix923}(oa(),Ja())),_c||(_c=1,gc.exports=function(t){return t.pad.Iso10126={pad:function(e,s){var n=4*s,i=n-e.sigBytes%n;e.concat(t.lib.WordArray.random(i-1)).concat(t.lib.WordArray.create([i<<24],1))},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Iso10126}(oa(),Ja())),vc||(vc=1,yc.exports=function(t){return t.pad.Iso97971={pad:function(e,s){e.concat(t.lib.WordArray.create([2147483648],1)),t.pad.ZeroPadding.pad(e,s)},unpad:function(e){t.pad.ZeroPadding.unpad(e),e.sigBytes--}},t.pad.Iso97971}(oa(),Ja())),wc||(wc=1,xc.exports=function(t){return t.pad.ZeroPadding={pad:function(t,e){var s=4*e;t.clamp(),t.sigBytes+=s-(t.sigBytes%s||s)},unpad:function(t){var e=t.words,s=t.sigBytes-1;for(s=t.sigBytes-1;s>=0;s--)if(e[s>>>2]>>>24-s%4*8&255){t.sigBytes=s+1;break}}},t.pad.ZeroPadding}(oa(),Ja())),bc||(bc=1,Tc.exports=function(t){return t.pad.NoPadding={pad:function(){},unpad:function(){}},t.pad.NoPadding}(oa(),Ja())),Cc||(Cc=1,kc.exports=function(t){return s=(e=t).lib.CipherParams,n=e.enc.Hex,e.format.Hex={stringify:function(t){return t.ciphertext.toString(n)},parse:function(t){var e=n.parse(t);return s.create({ciphertext:e})}},t.format.Hex;var e,s,n}(oa(),Ja())),Ac||(Ac=1,Sc.exports=function(t){return function(){var e=t,s=e.lib.BlockCipher,n=e.algo,i=[],r=[],o=[],a=[],c=[],u=[],h=[],l=[],p=[],d=[];!function(){for(var t=[],e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;var s=0,n=0;for(e=0;e<256;e++){var f=n^n<<1^n<<2^n<<3^n<<4;f=f>>>8^255&f^99,i[s]=f,r[f]=s;var m=t[s],_=t[m],g=t[_],v=257*t[f]^16843008*f;o[s]=v<<24|v>>>8,a[s]=v<<16|v>>>16,c[s]=v<<8|v>>>24,u[s]=v,v=16843009*g^65537*_^257*m^16843008*s,h[f]=v<<24|v>>>8,l[f]=v<<16|v>>>16,p[f]=v<<8|v>>>24,d[f]=v,s?(s=m^t[t[t[g^m]]],n^=t[t[n]]):s=n=1}}();var f=[0,1,2,4,8,16,32,64,128,27,54],m=n.AES=s.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var t=this._keyPriorReset=this._key,e=t.words,s=t.sigBytes/4,n=4*((this._nRounds=s+6)+1),r=this._keySchedule=[],o=0;o<n;o++)o<s?r[o]=e[o]:(u=r[o-1],o%s?s>6&&o%s==4&&(u=i[u>>>24]<<24|i[u>>>16&255]<<16|i[u>>>8&255]<<8|i[255&u]):(u=i[(u=u<<8|u>>>24)>>>24]<<24|i[u>>>16&255]<<16|i[u>>>8&255]<<8|i[255&u],u^=f[o/s|0]<<24),r[o]=r[o-s]^u);for(var a=this._invKeySchedule=[],c=0;c<n;c++){if(o=n-c,c%4)var u=r[o];else u=r[o-4];a[c]=c<4||o<=4?u:h[i[u>>>24]]^l[i[u>>>16&255]]^p[i[u>>>8&255]]^d[i[255&u]]}}},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,o,a,c,u,i)},decryptBlock:function(t,e){var s=t[e+1];t[e+1]=t[e+3],t[e+3]=s,this._doCryptBlock(t,e,this._invKeySchedule,h,l,p,d,r),s=t[e+1],t[e+1]=t[e+3],t[e+3]=s},_doCryptBlock:function(t,e,s,n,i,r,o,a){for(var c=this._nRounds,u=t[e]^s[0],h=t[e+1]^s[1],l=t[e+2]^s[2],p=t[e+3]^s[3],d=4,f=1;f<c;f++){var m=n[u>>>24]^i[h>>>16&255]^r[l>>>8&255]^o[255&p]^s[d++],_=n[h>>>24]^i[l>>>16&255]^r[p>>>8&255]^o[255&u]^s[d++],g=n[l>>>24]^i[p>>>16&255]^r[u>>>8&255]^o[255&h]^s[d++],v=n[p>>>24]^i[u>>>16&255]^r[h>>>8&255]^o[255&l]^s[d++];u=m,h=_,l=g,p=v}m=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^s[d++],_=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&u])^s[d++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^s[d++],v=(a[p>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^s[d++],t[e]=m,t[e+1]=_,t[e+2]=g,t[e+3]=v},keySize:8});e.AES=s._createHelper(m)}(),t.AES}(oa(),va(),Ca(),Ya(),Ja())),Ec(),Dc||(Dc=1,Ic.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=n.RC4=s.extend({_doReset:function(){for(var t=this._key,e=t.words,s=t.sigBytes,n=this._S=[],i=0;i<256;i++)n[i]=i;i=0;for(var r=0;i<256;i++){var o=i%s,a=e[o>>>2]>>>24-o%4*8&255;r=(r+n[i]+a)%256;var c=n[i];n[i]=n[r],n[r]=c}this._i=this._j=0},_doProcessBlock:function(t,e){t[e]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var t=this._S,e=this._i,s=this._j,n=0,i=0;i<4;i++){s=(s+t[e=(e+1)%256])%256;var r=t[e];t[e]=t[s],t[s]=r,n|=t[(t[e]+t[s])%256]<<24-8*i}return this._i=e,this._j=s,n}e.RC4=s._createHelper(i);var o=n.RC4Drop=i.extend({cfg:i.cfg.extend({drop:192}),_doReset:function(){i._doReset.call(this);for(var t=this.cfg.drop;t>0;t--)r.call(this)}});e.RC4Drop=s._createHelper(o)}(),t.RC4}(oa(),va(),Ca(),Ya(),Ja())),Nc||(Nc=1,Rc.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=[],r=[],o=[],a=n.Rabbit=s.extend({_doReset:function(){for(var t=this._key.words,e=this.cfg.iv,s=0;s<4;s++)t[s]=16711935&(t[s]<<8|t[s]>>>24)|4278255360&(t[s]<<24|t[s]>>>8);var n=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],i=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];for(this._b=0,s=0;s<4;s++)c.call(this);for(s=0;s<8;s++)i[s]^=n[s+4&7];if(e){var r=e.words,o=r[0],a=r[1],u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=u>>>16|4294901760&h,p=h<<16|65535&u;for(i[0]^=u,i[1]^=l,i[2]^=h,i[3]^=p,i[4]^=u,i[5]^=l,i[6]^=h,i[7]^=p,s=0;s<4;s++)c.call(this)}},_doProcessBlock:function(t,e){var s=this._X;c.call(this),i[0]=s[0]^s[5]>>>16^s[3]<<16,i[1]=s[2]^s[7]>>>16^s[5]<<16,i[2]=s[4]^s[1]>>>16^s[7]<<16,i[3]=s[6]^s[3]>>>16^s[1]<<16;for(var n=0;n<4;n++)i[n]=16711935&(i[n]<<8|i[n]>>>24)|4278255360&(i[n]<<24|i[n]>>>8),t[e+n]^=i[n]},blockSize:4,ivSize:2});function c(){for(var t=this._X,e=this._C,s=0;s<8;s++)r[s]=e[s];for(e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0<r[0]>>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0<r[1]>>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0<r[2]>>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0<r[3]>>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0<r[4]>>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0<r[5]>>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0<r[6]>>>0?1:0)|0,this._b=e[7]>>>0<r[7]>>>0?1:0,s=0;s<8;s++){var n=t[s]+e[s],i=65535&n,a=n>>>16,c=((i*i>>>17)+i*a>>>15)+a*a,u=((4294901760&n)*n|0)+((65535&n)*n|0);o[s]=c^u}t[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,t[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,t[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,t[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,t[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,t[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,t[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,t[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.Rabbit=s._createHelper(a)}(),t.Rabbit}(oa(),va(),Ca(),Ya(),Ja())),Bc||(Bc=1,Pc.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=[],r=[],o=[],a=n.RabbitLegacy=s.extend({_doReset:function(){var t=this._key.words,e=this.cfg.iv,s=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],n=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var i=0;i<4;i++)c.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(e){var r=e.words,o=r[0],a=r[1],u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=u>>>16|4294901760&h,p=h<<16|65535&u;for(n[0]^=u,n[1]^=l,n[2]^=h,n[3]^=p,n[4]^=u,n[5]^=l,n[6]^=h,n[7]^=p,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(t,e){var s=this._X;c.call(this),i[0]=s[0]^s[5]>>>16^s[3]<<16,i[1]=s[2]^s[7]>>>16^s[5]<<16,i[2]=s[4]^s[1]>>>16^s[7]<<16,i[3]=s[6]^s[3]>>>16^s[1]<<16;for(var n=0;n<4;n++)i[n]=16711935&(i[n]<<8|i[n]>>>24)|4278255360&(i[n]<<24|i[n]>>>8),t[e+n]^=i[n]},blockSize:4,ivSize:2});function c(){for(var t=this._X,e=this._C,s=0;s<8;s++)r[s]=e[s];for(e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0<r[0]>>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0<r[1]>>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0<r[2]>>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0<r[3]>>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0<r[4]>>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0<r[5]>>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0<r[6]>>>0?1:0)|0,this._b=e[7]>>>0<r[7]>>>0?1:0,s=0;s<8;s++){var n=t[s]+e[s],i=65535&n,a=n>>>16,c=((i*i>>>17)+i*a>>>15)+a*a,u=((4294901760&n)*n|0)+((65535&n)*n|0);o[s]=c^u}t[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,t[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,t[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,t[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,t[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,t[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,t[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,t[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.RabbitLegacy=s._createHelper(a)}(),t.RabbitLegacy}(oa(),va(),Ca(),Ya(),Ja())),Fc());var zc,jc=sa(na.exports);function Wc(t,e){const s=`${t}:${e}`,n=jc.SHA256(s).toString(jc.enc.Hex);return`${n.substring(0,8)}-${n.substring(8,12)}-4${n.substring(13,16)}-${"89AB"[parseInt(n.substring(17,18),16)%4]}${n.substring(18,21)}-${n.substring(21,33)}`}function Lc(t,e){if(t instanceof Xc&&e instanceof Zc)t.plug(e);else if(t instanceof Yc&&e instanceof Qc)t.plug(e);else if(t instanceof Gc&&e instanceof $c)t.plug(e);else if(t instanceof Gc&&e instanceof Qc)t.plug(e);else if(t instanceof Gc&&e instanceof Zc)t.plug(e);else if(t instanceof Xc&&e instanceof $c)t.plug(e);else{if(!(t instanceof Yc&&e instanceof $c))throw Error("Input and output type is not compatible");t.plug(e)}}function Hc(t,e){if(t instanceof Xc&&e instanceof Zc)t.unPlug(e);else if(t instanceof Yc&&e instanceof Qc)t.unPlug(e);else if(t instanceof Gc&&e instanceof $c)t.unPlug(e);else if(t instanceof Gc&&e instanceof Qc)t.unPlug(e);else if(t instanceof Gc&&e instanceof Zc)t.unPlug(e);else if(t instanceof Xc&&e instanceof $c)t.unPlug(e);else{if(!(t instanceof Yc&&e instanceof $c))throw Error("Input and output type is not compatible");t.unPlug(e)}}!function(t){t.AudioInput="audioInput",t.AudioOutput="audioOutput",t.MidiInput="midiInput",t.MidiOutput="midiOutput",t.ForwardInput="forwardInput",t.ForwardOutput="forwardOutput"}(zc||(zc={}));class Uc{id;ioType;name;plugableModule;connections=[];static unPlugAll(t){t.connections.forEach((e=>t.unPlug(e)))}constructor(t,e){this.plugableModule=t,this.id=Wc(t.id,e.name),Object.assign(this,e)}plug(t,e=!0){this.connections.push(t),e&&t.plug(this,!1)}unPlug(t,e=!0){this.connections=this.connections.filter((e=>e.id!==t.id)),e&&t.unPlug(this,!1)}serialize(){return{id:this.id,name:this.name,moduleId:this.plugableModule.id,moduleName:this.plugableModule.name,ioType:this.ioType}}}class Gc extends Uc{constructor(t,e){super(t,e),this.checkNameValidity()}get subInputs(){return this.plugableModule.audioModules.map((t=>{const e=t.inputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}))}get subModules(){return this.plugableModule.audioModules}subModule(t){const e=this.subModules.find((e=>e.voiceNo===t));if(!e)throw Error(`Submodule with voiceNo ${t} not found`);return e}subInput(t){const e=this.subModule(t).inputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}plug(t,e=!0){super.plug(t,e),!e&&t instanceof $c||(t instanceof $c?this.subModules.forEach((e=>{const s=e.inputs.findByName(this.name);if(!s)throw Error(`Could not forward input ${this.name}`);Lc(s,t.subOutput(e.voiceNo))})):this.subInputs.forEach((e=>Lc(e,t))))}unPlug(t,e=!0){super.unPlug(t,e),!e&&t instanceof $c||(t instanceof $c?this.subModules.forEach((e=>{const s=e.inputs.findByName(this.name);if(!s)throw Error(`Could not forward input ${this.name}`);Hc(s,t.subOutput(e.voiceNo))})):this.subInputs.forEach((e=>Hc(e,t))))}unPlugAll(){Uc.unPlugAll(this)}checkNameValidity(){if(!this.plugableModule.audioModules[0].inputs.findByName(this.name))throw Error("You should forward to existing input")}}class $c extends Uc{constructor(t,e){super(t,e),this.checkNameValidity()}get subOutputs(){return this.subModules.map((t=>{const e=t.outputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}))}get subModules(){return this.plugableModule.audioModules}subModule(t){const e=this.subModules.find((e=>e.voiceNo===t));if(!e)throw Error(`Submodule with voiceNo ${t} not found`);return e}subOutput(t){const e=this.subModule(t).outputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}plug(t,e=!0){super.plug(t,e),!e&&t instanceof Gc||(t instanceof Gc?this.subModules.forEach((e=>{const s=e.outputs.findByName(this.name);if(!s)throw Error(`Could not forward output ${this.name}`);Lc(t.subInput(e.voiceNo),s)})):this.subOutputs.forEach((e=>Lc(t,e))))}unPlug(t,e=!0){super.unPlug(t,e),!e&&t instanceof Gc||(t instanceof Gc?this.subModules.forEach((e=>{const s=e.outputs.findByName(this.name);if(!s)throw Error(`Could not forward output ${this.name}`);Hc(t.subInput(e.voiceNo),s)})):this.subOutputs.forEach((e=>Hc(t,e))))}unPlugAll(){Uc.unPlugAll(this)}checkNameValidity(){if(!this.plugableModule.audioModules[0].outputs.findByName(this.name))throw Error("You should forward to existing output")}}class Xc extends Uc{internalModule;constructor(t,e){super(t,e),this.internalModule=e.internalModule}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}}class Zc extends Uc{internalModule;constructor(t,e){super(t,e),this.internalModule=e.internalModule}plug(t,e=!0){super.plug(t,e),t instanceof Gc||this.internalModule.connect(t.internalModule)}unPlug(t,e=!0){if(super.unPlug(t,e),!(t instanceof Gc))try{this.internalModule.disconnect(t.internalModule)}catch(t){console.error(t)}}unPlugAll(){Uc.unPlugAll(this)}}class Yc extends Uc{onMidiEvent;constructor(t,e){super(t,e),this.onMidiEvent=e.onMidiEvent}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}}class Qc extends Uc{constructor(t,e){super(t,e)}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}onMidiEvent=t=>{this.midiConnections.forEach((e=>{e.onMidiEvent(t)}))};get midiConnections(){return this.connections.filter((t=>t instanceof Yc))}}class Kc{plugableModule;collection=[];constructor(t){this.plugableModule=t}add(t){let e;switch(t.ioType){case zc.AudioInput:if(this.plugableModule instanceof su)throw Error("PolyModule is not supported");e=new Xc(this.plugableModule,t);break;case zc.AudioOutput:if(this.plugableModule instanceof su)throw Error("PolyModule is not supported");e=new Zc(this.plugableModule,t);break;case zc.ForwardInput:if(this.plugableModule instanceof eu)throw Error("MonoModule is not supported");e=new Gc(this.plugableModule,t);break;case zc.ForwardOutput:if(this.plugableModule instanceof eu)throw Error("MonoModule is not supported");e=new $c(this.plugableModule,t);break;case zc.MidiInput:e=new Yc(this.plugableModule,t);break;case zc.MidiOutput:e=new Qc(this.plugableModule,t);break;default:throw Error("Unknown IOType")}return this.collection.push(e),e}unPlugAll(){this.collection.forEach((t=>t.unPlugAll()))}find(t){return this.collection.find((e=>e.id===t))}findByName(t){return this.collection.find((e=>e.name===t))}serialize(){return this.collection.map((t=>t.serialize()))}}class Jc{connect(){throw Error("This module is not connectable")}disconnect(){throw Error("This module is not connectable")}dispose(){}}var tu,eu=class{static moduleName;id;name;internalModule;inputs;outputs;voiceNo;updatedAt;_props={};constructor(t,e){this.internalModule=t,this.id=e.id||ta(),delete e.id,this.inputs=new Kc(this),this.outputs=new Kc(this),Object.assign(this,e)}set props(t){t&&(this.updatedAt=new Date,Object.assign(this,t))}get props(){return this._props}plug(t,e,s){const n=this.outputs.findByName(e);if(!n)throw Error(`Output ${e} not exist`);const i=t.inputs.findByName(s);if(!i)throw Error(`Input ${s} not exist`);Lc(i,n)}unPlugAll(){this.outputs.unPlugAll()}dispose(){this.inputs.unPlugAll(),this.outputs.unPlugAll(),this.internalModule.dispose()}triggerAttack=(t,e)=>{throw Error("triggerAttack not implemented")};triggerRelease=(t,e)=>{throw Error("triggerRelease not implemented")};onMidiEvent=t=>{if(void 0!==t.voiceNo&&t.voiceNo!==this.voiceNo)return;const{note:e,triggeredAt:s}=t;switch(t.type){case"noteOn":{const{duration:t}=e;if(this.triggerer(this.triggerAttack,e,s),t){const r=s+(n=t,new Xi(ji(),n,i)).toSeconds();this.triggerer(this.triggerRelease,e,r)}break}case"noteOff":this.triggerer(this.triggerRelease,e,s);break;default:throw Error("This type is not a note")}var n,i};triggerer(t,e,s){t(e,s)}serialize(){const t=this.constructor;return{id:this.id,name:this.name,type:t.moduleName,props:this.props,inputs:this.inputs.serialize(),outputs:this.outputs.serialize()}}registerMidiInput(t){return this.inputs.add({...t,ioType:zc.MidiInput})}registerAudioInput(t){return this.inputs.add({...t,ioType:zc.AudioInput})}registerMidiOutput(t){return this.outputs.add({...t,ioType:zc.MidiOutput})}registerAudioOutput(t){return this.outputs.add({...t,ioType:zc.AudioOutput})}registerBasicOutputs(){this.registerAudioOutput({name:"output",internalModule:this.internalModule})}registerBasicInputs(){this.registerAudioInput({name:"input",internalModule:this.internalModule}),this.registerDefaultMidiInput()}registerDefaultMidiInput(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}};class su{static moduleName;id;child;_name;audioModules;inputs;outputs;_numberOfVoices;constructor(t){this.id=t.id||ta(),delete t.id,this.audioModules=[];const{child:e,props:s,...n}=t;this.child=e,Object.assign(this,n),this.numberOfVoices=t.numberOfVoices||1,this.inputs=new Kc(this),this.outputs=new Kc(this),Object.assign(this,{props:s})}get name(){return this._name}set name(t){this._name=t,this.audioModules.forEach((e=>e.name=t))}get props(){if(0===this.audioModules.length)throw Error("There isn't any initialized module");return this.audioModules[0].props}set props(t){Object.assign(this,t),this.audioModules.forEach((e=>e.props=t))}get numberOfVoices(){return this._numberOfVoices}set numberOfVoices(t){this._numberOfVoices=t,this.adjustNumberOfModules()}plug(t,e,s){const n=this.outputs.findByName(e);if(!n)throw Error(`Output ${e} not exist`);const i=t.inputs.findByName(s);if(!i)throw Error(`Input ${s} not exist`);Lc(i,n)}unPlugAll(){this.outputs.unPlugAll()}dispose(){this.unPlugAll(),this.audioModules.forEach((t=>t.dispose()))}onMidiEvent=t=>{const e=t.voiceNo||0,s=this.findVoice(e);s?.onMidiEvent(t)};serialize(){if(0===this.audioModules.length)throw Error("There isn't any initialized module");const t=this.constructor;return{...this.audioModules[0].serialize(),id:this.id,type:t.moduleName,numberOfVoices:this.numberOfVoices,inputs:this.inputs.serialize(),outputs:this.outputs.serialize()}}find(t){const e=this.audioModules.find(t);if(!e)throw Error("Audio module not found");return e}findVoice(t){return this.audioModules.find((e=>e.voiceNo===t))}registerInput(t){return this.inputs.add({...t,ioType:zc.ForwardInput})}registerOutput(t){return this.outputs.add({...t,ioType:zc.ForwardOutput})}registerMidiInput(t){return this.inputs.add({...t,ioType:zc.MidiInput})}registerMidiOutput(t){return this.outputs.add({...t,ioType:zc.MidiOutput})}registerBasicOutputs(){this.registerOutput({name:"output"})}registerBasicInputs(){this.registerInput({name:"input"}),this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}adjustNumberOfModules(){if(this.audioModules.length!==this.numberOfVoices){if(this.audioModules.length>this.numberOfVoices){const t=this.audioModules.pop();t?.dispose()}else{const t=this.audioModules.length,e=Wc(this.id,t.toString()),s=0===t?{}:this.props,n=new this.child({id:e,name:this.name,props:{...s,voiceNo:t}});if(n instanceof su)throw Error("Polymodule not supported");this.audioModules.push(n)}this.adjustNumberOfModules()}}}!function(t){t.Attack="attack",t.Decay="decay",t.Sustain="sustain",t.Release="release"}(tu||(tu={}));const nu=.01,iu={attack:nu,decay:nu,sustain:1,release:nu};class ru extends eu{activeNote;triggeredAt;constructor(t){const{id:e,name:s,props:n,internalModule:i}=t;super(i,{id:e,name:s,props:{...iu,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}get attack(){return this._props.attack}set attack(t){this.setStage(tu.Attack,t)}get decay(){return this._props.decay}set decay(t){this.setStage(tu.Decay,t)}get sustain(){return this._props.sustain}set sustain(t){this.setStage(tu.Sustain,t)}get release(){return this._props.release}set release(t){this.setStage(tu.Release,t)}setStage(t,e){const s=0===e?this.minTime(t):this.maxTime(t)*e;this._props={...this.props,[t]:e},this.internalModule[t]=s}triggerAttack=(t,e)=>{this.activeNote=t.fullName,this.triggeredAt=e,this.internalModule.triggerAttack(e,t.velocity)};triggerRelease=(t,e)=>{this.activeNote&&this.activeNote!==t.fullName||(this.internalModule.triggerRelease(e),this.activeNote=void 0)};maxTime(t){return t===tu.Sustain?1:2}minTime(t){return t===tu.Sustain?0:nu}}class ou extends su{constructor(t){const{id:e,name:s,child:n,props:i}=t;super({id:e,name:s,child:n,props:{...iu,...i}}),this.registerBasicInputs(),this.registerBasicOutputs()}}class au extends ru{constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new so,props:n})}}class cu extends ou{static moduleName="Envelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:au,props:{...iu,...n}})}}class uu extends ru{constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new oo,props:n})}}class hu extends ou{static moduleName="AmpEnvelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:uu,props:n})}}const lu={amount:0};class pu extends ru{_frequency;_amount;filter;constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new ho,props:{...lu,...n}})}get frequency(){return this._frequency}set frequency(t){this._frequency=t,this.internalModule.baseFrequency=t}get amount(){return this._amount}set amount(t){this._amount=t,this.internalModule.octaves=t}}class du extends ou{static moduleName="FreqEnvelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:pu,props:n})}}const fu={noteName:"C3",fine:0,coarse:0,wave:"sine",range:0,volume:0};class mu extends eu{_note;_fineSignal;constructor(t){const{id:e,name:s,props:n}=t;super(new Br,{id:e,name:s,props:{...fu,...n}}),this.registerInputs(),this.registerBasicOutputs(),this.start(Bo())}get note(){return this._note}setNoteAt(t,e){this._note=this.getNote(t),this.updateFrequency(e)}set note(t){this._note=this.getNote(t),this.updateFrequency()}get noteName(){return this._props.noteName}set noteName(t){this._props={...this.props,noteName:t},this.note=new Fo(this.noteName)}get fineSingal(){return this._fineSignal||(this._fineSignal=new Fr(100),this._fineSignal.connect(this.internalModule.detune)),this._fineSignal}get fine(){return this._props.fine}set fine(t){this._props={...this.props,fine:t},this.fineSingal.value=this.fine}get coarse(){return this._props.coarse}set coarse(t){this._props={...this.props,coarse:Math.floor(t)},this.updateFrequency()}get wave(){return this._props.wave}set wave(t){this._props={...this.props,wave:t},this.internalModule.type=this.wave}get volume(){return this._props.volume}set volume(t){this._props={...this.props,volume:t},this.internalModule.volume.value=this.volume}get range(){return this._props.range}set range(t){this._props={...this.props,range:t},this.updateFrequency()}start(t){if(!Gu.isStarted)return;"started"===this.internalModule.state?this.internalModule.restart(t):this.internalModule.start(t)}stop(t){this.internalModule.stop(t)}triggerAttack=(t,e)=>{this.setNoteAt(t,e),this.start(e)};triggerRelease=()=>{};updateFrequency(t){if(!this.note)return;const e=this.note.adjustFrequency(this.range,this.coarse);t?this.internalModule.frequency.linearRampToValueAtTime(e,t):this.internalModule.frequency.value=e}getNote(t){return t instanceof Fo?t:new Fo(t)}registerInputs(){this.registerDefaultMidiInput(),this.registerAudioInput({name:"fine",internalModule:this.fineSingal})}}class _u extends su{static moduleName="Oscillator";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:mu,props:{...fu,...n}}),this.registerBasicOutputs(),this.registerInput({name:"midi in"}),this.registerInput({name:"fine"})}start(t){this.audioModules.forEach((e=>e.start(t)))}stop(t){this.audioModules.forEach((e=>e.stop(t)))}}const gu={cutoff:2e4,resonance:0,envelopeAmount:0,slope:-24,filterType:"lowpass"};class vu extends eu{_cutoff;_amount;constructor(t){const{id:e,name:s,props:n}=t;super(new uo({type:"lowpass"}),{id:e,name:s,props:{...gu,...n}}),this._cutoff=new $r(this.cutoff),this._cutoff.connect(this.internalModule.frequency),this._amount=new Fr,this._amount.connect(this._cutoff),this.updateAmountFactor(),this.registerBasicInputs(),this.registerOutputs()}get cutoff(){return this._props.cutoff}set cutoff(t){this._cutoff&&(this._cutoff.addend.value=t),this._props={...this.props,cutoff:t},this.updateAmountFactor()}get filterType(){return this._props.filterType}set filterType(t){this._props={...this.props,filterType:t},this.internalModule.type=t}get slope(){return this._props.slope}set slope(t){this._props={...this.props,slope:t},this.internalModule.rolloff=t}get frequency(){return this.internalModule.frequency}get resonance(){return this._props.resonance}set resonance(t){this._props={...this.props,resonance:t},this.internalModule.Q.value=t}get envelopeAmount(){return this._props.envelopeAmount}set envelopeAmount(t){this._props={...this.props,envelopeAmount:t},this.updateAmountFactor()}registerOutputs(){this.registerBasicOutputs(),this.registerAudioInput({name:"cutoff",internalModule:this._amount})}updateAmountFactor(){if(!this._amount)return;const t=this.envelopeAmount>0?this.envelopeAmount*Math.abs(2e4-this.cutoff):this.envelopeAmount*Math.abs(1-this.cutoff);this._amount.factor.value=t}}class yu extends su{static moduleName="Filter";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:vu,props:{...gu,...n}}),this.registerBasicInputs(),this.registerOutputs()}registerOutputs(){this.registerBasicOutputs(),this.registerInput({name:"cutoff"})}}class wu extends eu{static moduleName="Master";constructor({id:t}){super(ji().destination,{id:t,name:"Master"}),this.registerAudioInput({name:"input",internalModule:this.internalModule})}dispose(){this.inputs.unPlugAll(),this.outputs.unPlugAll()}}class xu extends su{static moduleName="VoiceScheduler";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:bu,props:n}),this.registerInputs(),this.registerOutputs(),this.polyNumber=this.numberOfVoices}set polyNumber(t){super.numberOfVoices=t}get polyNumber(){return this.numberOfVoices}onMidiEvent=t=>{let e;switch(t.type){case"noteOn":e=this.findFreeVoice();break;case"noteOff":e=this.audioModules.find((e=>e.activeNote===t.note.fullName));break;default:throw Error("This type is not a note")}e&&(e.midiTriggered(t),t.voiceNo=e.voiceNo,this.midiOutput.onMidiEvent(t))};serialize(){const t=super.serialize();return{...t,props:{...t.props,polyNumber:this.polyNumber}}}findFreeVoice(){let t=this.audioModules.find((t=>!t.activeNote));return t||(t=this.audioModules.sort(((t,e)=>t&&e?t.triggeredAt-e.triggeredAt:0))[0]),t}registerInputs(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}}class bu extends eu{midiEvent;activeNote;triggeredAt;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:n})}midiTriggered=t=>{if(void 0===this.voiceNo)throw Error("Voice without voiceNo");const{triggeredAt:e,note:s,type:n}=t;if(!s)return;const i=s.fullName;switch(n){case"noteOn":this.activeNote=i,this.triggeredAt=e,this.midiEvent=t;break;case"noteOff":this.activeNote=null,this.midiEvent=null;break;default:throw Error("This type is not a note")}}}const Tu={selectedId:null};class Cu extends eu{static moduleName="MidiSelector";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{...Tu,...n}}),this.registerOutputs(),this.addEventListener(this.selectedId)}get selectedId(){return this._props.selectedId}set selectedId(t){this.removeEventListener(),this._props={...this.props,selectedId:t},this.addEventListener(t)}dispose(){this.removeEventListener(),super.dispose()}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}addEventListener(t){if(!this.onMidiEvent||!t)return;const e=Gu.midiDeviceManager.find(t);e?.addEventListener(this.forwardMidiEvent)}forwardMidiEvent=t=>{this.midiOutput.onMidiEvent(t)};removeEventListener(){if(!this.selectedId)return;const t=Gu.midiDeviceManager.find(this.selectedId);t?.removeEventListener(this.forwardMidiEvent)}}const ku={volume:-1/0};class Au extends eu{constructor(t){const{id:e,name:s,props:n}=t;super(new xr,{id:e,name:s,props:{...ku,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}get volume(){return this._props.volume}set volume(t){this._props={...this.props,volume:t},this.internalModule.volume.value=this.volume}triggerAttack=(t,e)=>{const s=20*Math.log10(t.velocity);this.internalModule.volume.exponentialRampToValueAtTime(s,e)};triggerRelease=()=>{}}class Su extends su{static moduleName="Volume";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:Au,props:{...ku,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}}const Mu={activeNotes:[]};class Ou extends eu{static moduleName="VirtualMidi";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{...Mu,...n}}),this.registerInputs(),this.registerOutputs()}get activeNotes(){return this._props.activeNotes}set activeNotes(t){this._props={...this.props,activeNotes:t}}sendMidi(t){this.midiOutput.onMidiEvent(t)}triggerAttack=(t,e)=>{this.activeNotes=[...this.activeNotes,t.fullName],Gu._triggerPropsUpdate(this.id,this.props),this.sendMidi(jo.fromNote(t,!0,e))};triggerRelease=(t,e)=>{this.activeNotes=this.activeNotes.filter((e=>e!==t.fullName)),Gu._triggerPropsUpdate(this.id,this.props),this.sendMidi(jo.fromNote(t,!1,e))};serialize(){return{...super.serialize(),activeNotes:this.activeNotes}}registerInputs(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}}const Eu={wet:1};class Du extends eu{constructor(t){const{id:e,name:s,internalModule:n,props:i}=t;super(n,{id:e,name:s,props:{...Eu,...i}}),this.registerBasicInputs(),this.registerBasicOutputs()}get wet(){return this._props.wet}set wet(t){this._props={...this.props,wet:t},this.internalModule.wet.value=this.wet}}const Iu={decay:1.5,preDelay:.025};class Nu extends Du{static moduleName="Reverb";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Eo,props:{...Iu,...n}})}get decay(){return this._props.decay}set decay(t){this._props={...this.props,decay:t},this.internalModule.decay=this.decay}get preDelay(){return this._props.preDelay}set preDelay(t){this._props={...this.props,preDelay:t},this.internalModule.preDelay=this.preDelay}}const Ru={delayTime:1,feedback:.3};class Bu extends Du{static moduleName="Delay";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Oo,props:{...Ru,...n}})}get delayTime(){return this._props.delayTime}set delayTime(t){this._props={...this.props,delayTime:t},this.internalModule.delayTime.value=this.delayTime}get feedback(){return this._props.feedback}set feedback(t){this._props={...this.props,feedback:t},this.internalModule.feedback.value=this.feedback}}const Pu={drive:.3};class Vu extends Du{static moduleName="Distortion";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new So,props:{...Pu,...n}})}get drive(){return this._props.drive}set drive(t){this._props={...this.props,drive:t},this.internalModule.distortion=this.drive}}const qu={bits:16};class Fu extends Du{static moduleName="BitCrusher";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Co,props:{...qu,...n}})}get bits(){return this._props.bits}set bits(t){this._props={...this.props,bits:t},this.internalModule.bits.value=this.bits}}class zu extends eu{static moduleName="Sequencer";midiOutput;part;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{sequences:[],steps:16,bars:1,...n}}),this.initializePart(),this.start(Bo()),this.registerOutputs()}get props(){return super.props}set props(t){this.sequences||(this._props.sequences=[]),super.props={...this.props,...t},this.adjust()}get steps(){return this._props.steps}set steps(t){this._props={...this.props,steps:t}}get bars(){return this.props.bars}set bars(t){this._props={...this.props,bars:t}}get sequences(){return this._props.sequences}set sequences(t){const e=t;this._props={...this.props,sequences:e}}start(t){Gu.isStarted&&this.part.start(t)}stop(){this.part.stop()}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}initializePart(){this.part=new yo(this.onPartEvent,[]),this.part.loop=!0,this.part.loopEnd=this.loopEnd}adjust(){this.part&&(this.adjustNumberOfBars(),this.adjustNumberOfSteps(),this.updateBarParts())}adjustNumberOfBars(){const t=this.sequences.length-this.bars,e=[...this.sequences];0!==t&&(t>0?e.pop():e.push([]),this.sequences=e,this.adjustNumberOfBars())}adjustNumberOfSteps(t=0){if(!this.bars)return;const e=[...this.sequences],s=[...e[t]],n=s.length-this.steps;if(0!==n){if(n>0)s.pop();else{const e=s.length;s.push({active:!1,time:`${t}:0:${e}`,notes:[]})}e[t]=s,this.sequences=e,this.adjustNumberOfSteps(t)}else{if(t===this.bars-1)return;this.adjustNumberOfSteps(t+1)}}updateBarParts(){this.part.clear(),this.sequences.forEach((t=>{t.forEach((t=>this.part.add(t.time,t)))})),this.part.loopEnd=this.loopEnd}get loopEnd(){return`${this.bars}:0:0`}onPartEvent=(t,e)=>{e.active&&jo.fromSequence(e,t).forEach((t=>{this.midiOutput.onMidiEvent(t)}))}}const ju={wave:"sine",frequency:.1,min:0,max:1,amount:1};class Wu extends eu{constructor(t){const{id:e,name:s,props:n}=t;super(new Yr,{id:e,name:s,props:{...ju,...n}}),this.registerBasicOutputs(),this.registerInputs(),this.start(Bo())}get wave(){return this._props.wave}set wave(t){this._props={...this.props,wave:t},this.internalModule.type=this.wave}get min(){return this._props.min}set min(t){this._props={...this.props,min:t},this.internalModule.min=this.min}get max(){return this._props.max}set max(t){this._props={...this.props,max:t},this.internalModule.max=this.max}get frequency(){return this._props.frequency}set frequency(t){this._props={...this.props,frequency:t},this.internalModule.frequency.value=this.frequency}get amount(){return this._props.amount}set amount(t){this._props={...this.props,amount:t},this.internalModule.amplitude.value=this.amount}start(t){if(!Gu.isStarted)return;"started"===this.internalModule.state?(this.internalModule.stop(t-2),this.internalModule.start(t)):this.internalModule.start(t)}stop(t){this.internalModule.stop(t)}triggerAttack=(t,e)=>{this.start(e)};triggerRelease=()=>{};registerInputs(){this.registerDefaultMidiInput(),this.registerAudioInput({name:"amount",internalModule:this.internalModule.amplitude})}}class Lu extends su{static moduleName="LFO";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:Wu,props:{...ju,...n}}),this.registerBasicOutputs(),this.registerInput({name:"midi in"}),this.registerInput({name:"amount"})}start(t){this.audioModules.forEach((e=>e.start(t)))}stop(t){this.audioModules.forEach((e=>e.stop(t)))}}function Hu(t){const{id:e,type:s,name:n,props:i}=t,r=function(t){switch(t){case _u.moduleName:return _u;case cu.moduleName:return cu;case hu.moduleName:return hu;case du.moduleName:return du;case yu.moduleName:return yu;case Su.moduleName:return Su;case wu.moduleName:return wu;case xu.moduleName:return xu;case Cu.moduleName:return Cu;case Ou.moduleName:return Ou;case Nu.moduleName:return Nu;case Bu.moduleName:return Bu;case Vu.moduleName:return Vu;case Fu.moduleName:return Fu;case zu.moduleName:return zu;case Lu.moduleName:return Lu;default:throw Error(`Unknown module type ${t}`)}}(s);return new r({id:e,name:n,props:i})}class Uu{midiDeviceManager;static instance;context;propsUpdateCallbacks;_isStarted=!1;modules;routes;constructor(){this.modules={},this.routes={},this.propsUpdateCallbacks=[]}static getInstance(){return Uu.instance||(Uu.instance=new Uu),Uu.instance}initialize(t){return new Promise((e=>{if(this.context)return e({});this.context=new Ni(t.context),Wi(this.context),this.context.transport.start(),this.midiDeviceManager=new Go,setTimeout((()=>{e({})}),0)}))}addModule(t){const{id:e,name:s,numberOfVoices:n,type:i,props:r={}}=t,o=Hu({id:e,name:s,type:i,props:{}});return o instanceof su&&n&&(o.numberOfVoices=n),o.props=r,this.modules[o.id]=o,this.updateRoutes(),o.serialize()}removeModule(t){this.modules[t].dispose();const e=this.moduleRouteIds(t);return e.forEach((t=>delete this.routes[t])),this.updateRoutes(),delete this.modules[t],e}updateModule(t){const{id:e,changes:{name:s,numberOfVoices:n,props:i={}}}=t,r=this.findById(e);return r.props=i,s&&(r.name=s),r instanceof su&&n&&(r.numberOfVoices=n),r.serialize()}onPropsUpdate(t){this.propsUpdateCallbacks.push(t)}_triggerPropsUpdate(t,e){this.propsUpdateCallbacks.forEach((s=>s(t,e)))}addRoute(t){const e=function(t){const e=t.id||ta();return{...t,id:e}}(t),s={...this.routes,[e.id]:e};return this.routes=s,this.updateRoutes(),e}removeRoute(t){delete this.routes[t],this.updateRoutes()}triggerVirtualMidi(t,e,s){this.findById(t).sendMidi(jo.fromNote(e,"noteOn"===s))}dispose(){Object.values(this.modules).forEach((t=>{t.dispose()})),this.modules={},this.routes={}}findById(t){const e=this.modules[t];if(!e)throw Error(`Audio module with id ${t} not exists`);return e}get isStarted(){return void 0!==this.context&&"started"===this.context.transport.state&&this._isStarted}start(){const t=Bo();this._isStarted=!0,this.updateRoutes(),Object.values(this.modules).forEach((e=>{const s=e;s.start&&s.start(t)}))}stop(){const t=Bo();Object.values(this.modules).forEach((e=>{const s=e;s.stop&&s.stop(t)})),this._isStarted=!1}get bpm(){return this.context.transport.bpm.value}set bpm(t){this.context.transport.bpm.value=t}updateRoutes(){var t;t=Object.values(this.routes),Object.values(Gu.modules).forEach((t=>{t.unPlugAll()})),t.map((t=>{const{sourceId:e,sourceIOId:s,destinationId:n,destinationIOId:i}=t,r=Gu.findById(e),o=Gu.findById(n),a=r.outputs.find(s),c=o.inputs.find(i);if(!c||!a)throw Error("IO not found");return Lc(c,a),!0})).every((t=>t))?console.log("######## Routes succesfully applied"):console.log("######## Routes partialy applied")}moduleRouteIds(t){const e={...this.routes};return Object.keys(e).filter((s=>{const{sourceId:n,destinationId:i}=e[s];return n===t||i===t}))}}var Gu=Uu.getInstance();export{Wo as MidiDevice,Go as MidiDeviceManager,Fo as Note,Gu as default};
|
|
24
|
+
return function(e){var s=t,n=s.lib,i=n.WordArray,r=n.Hasher,o=s.algo,a=i.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),c=i.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),u=i.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),h=i.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),l=i.create([0,1518500249,1859775393,2400959708,2840853838]),p=i.create([1352829926,1548603684,1836072691,2053994217,0]),d=o.RIPEMD160=r.extend({_doReset:function(){this._hash=i.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var s=0;s<16;s++){var n=e+s,i=t[n];t[n]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8)}var r,o,d,w,x,b,T,C,k,A,S,M=this._hash.words,O=l.words,E=p.words,D=a.words,I=c.words,N=u.words,R=h.words;for(b=r=M[0],T=o=M[1],C=d=M[2],k=w=M[3],A=x=M[4],s=0;s<80;s+=1)S=r+t[e+D[s]]|0,S+=s<16?f(o,d,w)+O[0]:s<32?m(o,d,w)+O[1]:s<48?_(o,d,w)+O[2]:s<64?g(o,d,w)+O[3]:v(o,d,w)+O[4],S=(S=y(S|=0,N[s]))+x|0,r=x,x=w,w=y(d,10),d=o,o=S,S=b+t[e+I[s]]|0,S+=s<16?v(T,C,k)+E[0]:s<32?g(T,C,k)+E[1]:s<48?_(T,C,k)+E[2]:s<64?m(T,C,k)+E[3]:f(T,C,k)+E[4],S=(S=y(S|=0,R[s]))+A|0,b=A,A=k,k=y(C,10),C=T,T=S;S=M[1]+d+k|0,M[1]=M[2]+w+A|0,M[2]=M[3]+x+b|0,M[3]=M[4]+r+T|0,M[4]=M[0]+o+C|0,M[0]=S},_doFinalize:function(){var t=this._data,e=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(e.length+1),this._process();for(var i=this._hash,r=i.words,o=0;o<5;o++){var a=r[o];r[o]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}return i},clone:function(){var t=r.clone.call(this);return t._hash=this._hash.clone(),t}});function f(t,e,s){return t^e^s}function m(t,e,s){return t&e|~t&s}function _(t,e,s){return(t|~e)^s}function g(t,e,s){return t&s|e&~s}function v(t,e,s){return t^(e|~s)}function y(t,e){return t<<e|t>>>32-e}s.RIPEMD160=r._createHelper(d),s.HmacRIPEMD160=r._createHmacHelper(d)}(),t.RIPEMD160}(oa())),Ua(),Ga||(Ga=1,$a.exports=function(t){return n=(s=(e=t).lib).Base,i=s.WordArray,o=(r=e.algo).SHA256,a=r.HMAC,c=r.PBKDF2=n.extend({cfg:n.extend({keySize:4,hasher:o,iterations:25e4}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var s=this.cfg,n=a.create(s.hasher,t),r=i.create(),o=i.create([1]),c=r.words,u=o.words,h=s.keySize,l=s.iterations;c.length<h;){var p=n.update(e).finalize(o);n.reset();for(var d=p.words,f=d.length,m=p,_=1;_<l;_++){m=n.finalize(m),n.reset();for(var g=m.words,v=0;v<f;v++)d[v]^=g[v]}r.concat(p),u[0]++}return r.sigBytes=4*h,r}}),e.PBKDF2=function(t,e,s){return c.create(s).compute(t,e)},t.PBKDF2;var e,s,n,i,r,o,a,c}(oa(),Ea(),Ua())),Ya(),Ja(),sc(),rc(),cc(),lc(),pc||(pc=1,dc.exports=function(t){return t.mode.ECB=((e=t.lib.BlockCipherMode.extend()).Encryptor=e.extend({processBlock:function(t,e){this._cipher.encryptBlock(t,e)}}),e.Decryptor=e.extend({processBlock:function(t,e){this._cipher.decryptBlock(t,e)}}),e),t.mode.ECB;var e}(oa(),Ja())),fc||(fc=1,mc.exports=function(t){return t.pad.AnsiX923={pad:function(t,e){var s=t.sigBytes,n=4*e,i=n-s%n,r=s+i-1;t.clamp(),t.words[r>>>2]|=i<<24-r%4*8,t.sigBytes+=i},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Ansix923}(oa(),Ja())),_c||(_c=1,gc.exports=function(t){return t.pad.Iso10126={pad:function(e,s){var n=4*s,i=n-e.sigBytes%n;e.concat(t.lib.WordArray.random(i-1)).concat(t.lib.WordArray.create([i<<24],1))},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Iso10126}(oa(),Ja())),vc||(vc=1,yc.exports=function(t){return t.pad.Iso97971={pad:function(e,s){e.concat(t.lib.WordArray.create([2147483648],1)),t.pad.ZeroPadding.pad(e,s)},unpad:function(e){t.pad.ZeroPadding.unpad(e),e.sigBytes--}},t.pad.Iso97971}(oa(),Ja())),wc||(wc=1,xc.exports=function(t){return t.pad.ZeroPadding={pad:function(t,e){var s=4*e;t.clamp(),t.sigBytes+=s-(t.sigBytes%s||s)},unpad:function(t){var e=t.words,s=t.sigBytes-1;for(s=t.sigBytes-1;s>=0;s--)if(e[s>>>2]>>>24-s%4*8&255){t.sigBytes=s+1;break}}},t.pad.ZeroPadding}(oa(),Ja())),bc||(bc=1,Tc.exports=function(t){return t.pad.NoPadding={pad:function(){},unpad:function(){}},t.pad.NoPadding}(oa(),Ja())),Cc||(Cc=1,kc.exports=function(t){return s=(e=t).lib.CipherParams,n=e.enc.Hex,e.format.Hex={stringify:function(t){return t.ciphertext.toString(n)},parse:function(t){var e=n.parse(t);return s.create({ciphertext:e})}},t.format.Hex;var e,s,n}(oa(),Ja())),Ac||(Ac=1,Sc.exports=function(t){return function(){var e=t,s=e.lib.BlockCipher,n=e.algo,i=[],r=[],o=[],a=[],c=[],u=[],h=[],l=[],p=[],d=[];!function(){for(var t=[],e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;var s=0,n=0;for(e=0;e<256;e++){var f=n^n<<1^n<<2^n<<3^n<<4;f=f>>>8^255&f^99,i[s]=f,r[f]=s;var m=t[s],_=t[m],g=t[_],v=257*t[f]^16843008*f;o[s]=v<<24|v>>>8,a[s]=v<<16|v>>>16,c[s]=v<<8|v>>>24,u[s]=v,v=16843009*g^65537*_^257*m^16843008*s,h[f]=v<<24|v>>>8,l[f]=v<<16|v>>>16,p[f]=v<<8|v>>>24,d[f]=v,s?(s=m^t[t[t[g^m]]],n^=t[t[n]]):s=n=1}}();var f=[0,1,2,4,8,16,32,64,128,27,54],m=n.AES=s.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var t=this._keyPriorReset=this._key,e=t.words,s=t.sigBytes/4,n=4*((this._nRounds=s+6)+1),r=this._keySchedule=[],o=0;o<n;o++)o<s?r[o]=e[o]:(u=r[o-1],o%s?s>6&&o%s==4&&(u=i[u>>>24]<<24|i[u>>>16&255]<<16|i[u>>>8&255]<<8|i[255&u]):(u=i[(u=u<<8|u>>>24)>>>24]<<24|i[u>>>16&255]<<16|i[u>>>8&255]<<8|i[255&u],u^=f[o/s|0]<<24),r[o]=r[o-s]^u);for(var a=this._invKeySchedule=[],c=0;c<n;c++){if(o=n-c,c%4)var u=r[o];else u=r[o-4];a[c]=c<4||o<=4?u:h[i[u>>>24]]^l[i[u>>>16&255]]^p[i[u>>>8&255]]^d[i[255&u]]}}},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,o,a,c,u,i)},decryptBlock:function(t,e){var s=t[e+1];t[e+1]=t[e+3],t[e+3]=s,this._doCryptBlock(t,e,this._invKeySchedule,h,l,p,d,r),s=t[e+1],t[e+1]=t[e+3],t[e+3]=s},_doCryptBlock:function(t,e,s,n,i,r,o,a){for(var c=this._nRounds,u=t[e]^s[0],h=t[e+1]^s[1],l=t[e+2]^s[2],p=t[e+3]^s[3],d=4,f=1;f<c;f++){var m=n[u>>>24]^i[h>>>16&255]^r[l>>>8&255]^o[255&p]^s[d++],_=n[h>>>24]^i[l>>>16&255]^r[p>>>8&255]^o[255&u]^s[d++],g=n[l>>>24]^i[p>>>16&255]^r[u>>>8&255]^o[255&h]^s[d++],v=n[p>>>24]^i[u>>>16&255]^r[h>>>8&255]^o[255&l]^s[d++];u=m,h=_,l=g,p=v}m=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^s[d++],_=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&u])^s[d++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^s[d++],v=(a[p>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^s[d++],t[e]=m,t[e+1]=_,t[e+2]=g,t[e+3]=v},keySize:8});e.AES=s._createHelper(m)}(),t.AES}(oa(),va(),Ca(),Ya(),Ja())),Ec(),Dc||(Dc=1,Ic.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=n.RC4=s.extend({_doReset:function(){for(var t=this._key,e=t.words,s=t.sigBytes,n=this._S=[],i=0;i<256;i++)n[i]=i;i=0;for(var r=0;i<256;i++){var o=i%s,a=e[o>>>2]>>>24-o%4*8&255;r=(r+n[i]+a)%256;var c=n[i];n[i]=n[r],n[r]=c}this._i=this._j=0},_doProcessBlock:function(t,e){t[e]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var t=this._S,e=this._i,s=this._j,n=0,i=0;i<4;i++){s=(s+t[e=(e+1)%256])%256;var r=t[e];t[e]=t[s],t[s]=r,n|=t[(t[e]+t[s])%256]<<24-8*i}return this._i=e,this._j=s,n}e.RC4=s._createHelper(i);var o=n.RC4Drop=i.extend({cfg:i.cfg.extend({drop:192}),_doReset:function(){i._doReset.call(this);for(var t=this.cfg.drop;t>0;t--)r.call(this)}});e.RC4Drop=s._createHelper(o)}(),t.RC4}(oa(),va(),Ca(),Ya(),Ja())),Nc||(Nc=1,Rc.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=[],r=[],o=[],a=n.Rabbit=s.extend({_doReset:function(){for(var t=this._key.words,e=this.cfg.iv,s=0;s<4;s++)t[s]=16711935&(t[s]<<8|t[s]>>>24)|4278255360&(t[s]<<24|t[s]>>>8);var n=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],i=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];for(this._b=0,s=0;s<4;s++)c.call(this);for(s=0;s<8;s++)i[s]^=n[s+4&7];if(e){var r=e.words,o=r[0],a=r[1],u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=u>>>16|4294901760&h,p=h<<16|65535&u;for(i[0]^=u,i[1]^=l,i[2]^=h,i[3]^=p,i[4]^=u,i[5]^=l,i[6]^=h,i[7]^=p,s=0;s<4;s++)c.call(this)}},_doProcessBlock:function(t,e){var s=this._X;c.call(this),i[0]=s[0]^s[5]>>>16^s[3]<<16,i[1]=s[2]^s[7]>>>16^s[5]<<16,i[2]=s[4]^s[1]>>>16^s[7]<<16,i[3]=s[6]^s[3]>>>16^s[1]<<16;for(var n=0;n<4;n++)i[n]=16711935&(i[n]<<8|i[n]>>>24)|4278255360&(i[n]<<24|i[n]>>>8),t[e+n]^=i[n]},blockSize:4,ivSize:2});function c(){for(var t=this._X,e=this._C,s=0;s<8;s++)r[s]=e[s];for(e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0<r[0]>>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0<r[1]>>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0<r[2]>>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0<r[3]>>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0<r[4]>>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0<r[5]>>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0<r[6]>>>0?1:0)|0,this._b=e[7]>>>0<r[7]>>>0?1:0,s=0;s<8;s++){var n=t[s]+e[s],i=65535&n,a=n>>>16,c=((i*i>>>17)+i*a>>>15)+a*a,u=((4294901760&n)*n|0)+((65535&n)*n|0);o[s]=c^u}t[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,t[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,t[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,t[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,t[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,t[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,t[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,t[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.Rabbit=s._createHelper(a)}(),t.Rabbit}(oa(),va(),Ca(),Ya(),Ja())),Bc||(Bc=1,Pc.exports=function(t){return function(){var e=t,s=e.lib.StreamCipher,n=e.algo,i=[],r=[],o=[],a=n.RabbitLegacy=s.extend({_doReset:function(){var t=this._key.words,e=this.cfg.iv,s=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],n=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var i=0;i<4;i++)c.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(e){var r=e.words,o=r[0],a=r[1],u=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=u>>>16|4294901760&h,p=h<<16|65535&u;for(n[0]^=u,n[1]^=l,n[2]^=h,n[3]^=p,n[4]^=u,n[5]^=l,n[6]^=h,n[7]^=p,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(t,e){var s=this._X;c.call(this),i[0]=s[0]^s[5]>>>16^s[3]<<16,i[1]=s[2]^s[7]>>>16^s[5]<<16,i[2]=s[4]^s[1]>>>16^s[7]<<16,i[3]=s[6]^s[3]>>>16^s[1]<<16;for(var n=0;n<4;n++)i[n]=16711935&(i[n]<<8|i[n]>>>24)|4278255360&(i[n]<<24|i[n]>>>8),t[e+n]^=i[n]},blockSize:4,ivSize:2});function c(){for(var t=this._X,e=this._C,s=0;s<8;s++)r[s]=e[s];for(e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0<r[0]>>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0<r[1]>>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0<r[2]>>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0<r[3]>>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0<r[4]>>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0<r[5]>>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0<r[6]>>>0?1:0)|0,this._b=e[7]>>>0<r[7]>>>0?1:0,s=0;s<8;s++){var n=t[s]+e[s],i=65535&n,a=n>>>16,c=((i*i>>>17)+i*a>>>15)+a*a,u=((4294901760&n)*n|0)+((65535&n)*n|0);o[s]=c^u}t[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,t[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,t[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,t[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,t[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,t[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,t[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,t[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.RabbitLegacy=s._createHelper(a)}(),t.RabbitLegacy}(oa(),va(),Ca(),Ya(),Ja())),Fc());var zc,jc=sa(na.exports);function Wc(t,e){const s=`${t}:${e}`,n=jc.SHA256(s).toString(jc.enc.Hex);return`${n.substring(0,8)}-${n.substring(8,12)}-4${n.substring(13,16)}-${"89AB"[parseInt(n.substring(17,18),16)%4]}${n.substring(18,21)}-${n.substring(21,33)}`}function Lc(t,e){if(t instanceof Xc&&e instanceof Zc)t.plug(e);else if(t instanceof Yc&&e instanceof Qc)t.plug(e);else if(t instanceof Gc&&e instanceof $c)t.plug(e);else if(t instanceof Gc&&e instanceof Qc)t.plug(e);else if(t instanceof Gc&&e instanceof Zc)t.plug(e);else if(t instanceof Xc&&e instanceof $c)t.plug(e);else{if(!(t instanceof Yc&&e instanceof $c))throw Error("Input and output type is not compatible");t.plug(e)}}function Hc(t,e){if(t instanceof Xc&&e instanceof Zc)t.unPlug(e);else if(t instanceof Yc&&e instanceof Qc)t.unPlug(e);else if(t instanceof Gc&&e instanceof $c)t.unPlug(e);else if(t instanceof Gc&&e instanceof Qc)t.unPlug(e);else if(t instanceof Gc&&e instanceof Zc)t.unPlug(e);else if(t instanceof Xc&&e instanceof $c)t.unPlug(e);else{if(!(t instanceof Yc&&e instanceof $c))throw Error("Input and output type is not compatible");t.unPlug(e)}}!function(t){t.AudioInput="audioInput",t.AudioOutput="audioOutput",t.MidiInput="midiInput",t.MidiOutput="midiOutput",t.ForwardInput="forwardInput",t.ForwardOutput="forwardOutput"}(zc||(zc={}));class Uc{id;ioType;name;plugableModule;connections=[];static unPlugAll(t){t.connections.forEach((e=>t.unPlug(e)))}constructor(t,e){this.plugableModule=t,this.id=Wc(t.id,e.name),Object.assign(this,e)}plug(t,e=!0){this.connections.push(t),e&&t.plug(this,!1)}unPlug(t,e=!0){this.connections=this.connections.filter((e=>e.id!==t.id)),e&&t.unPlug(this,!1)}serialize(){return{id:this.id,name:this.name,moduleId:this.plugableModule.id,moduleName:this.plugableModule.name,ioType:this.ioType}}}class Gc extends Uc{constructor(t,e){super(t,e),this.checkNameValidity()}get subInputs(){return this.plugableModule.audioModules.map((t=>{const e=t.inputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}))}get subModules(){return this.plugableModule.audioModules}subModule(t){const e=t%this.subModules.length,s=this.subModules.find((t=>t.voiceNo===e));if(!s)throw Error(`Submodule with voiceNo ${t} not found`);return s}subInput(t){const e=this.subModule(t).inputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}plug(t,e=!0){super.plug(t,e),!e&&t instanceof $c||(t instanceof $c?this.subModules.forEach((e=>{const s=e.inputs.findByName(this.name);if(!s)throw Error(`Could not forward input ${this.name}`);Lc(s,t.subOutput(e.voiceNo))})):this.subInputs.forEach((e=>Lc(e,t))))}unPlug(t,e=!0){super.unPlug(t,e),!e&&t instanceof $c||(t instanceof $c?this.subModules.forEach((e=>{const s=e.inputs.findByName(this.name);if(!s)throw Error(`Could not forward input ${this.name}`);Hc(s,t.subOutput(e.voiceNo))})):this.subInputs.forEach((e=>Hc(e,t))))}unPlugAll(){Uc.unPlugAll(this)}checkNameValidity(){if(!this.plugableModule.audioModules[0].inputs.findByName(this.name))throw Error("You should forward to existing input")}}class $c extends Uc{constructor(t,e){super(t,e),this.checkNameValidity()}get subOutputs(){return this.subModules.map((t=>{const e=t.outputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}))}get subModules(){return this.plugableModule.audioModules}subModule(t){const e=t%this.subModules.length,s=this.subModules.find((t=>t.voiceNo===e));if(!s)throw Error(`Submodule with voiceNo ${t} not found`);return s}subOutput(t){const e=this.subModule(t).outputs.findByName(this.name);if(!e)throw Error(`Could not forward input ${this.name}`);return e}plug(t,e=!0){super.plug(t,e),!e&&t instanceof Gc||(t instanceof Gc?this.subModules.forEach((e=>{const s=e.outputs.findByName(this.name);if(!s)throw Error(`Could not forward output ${this.name}`);Lc(t.subInput(e.voiceNo),s)})):this.subOutputs.forEach((e=>Lc(t,e))))}unPlug(t,e=!0){super.unPlug(t,e),!e&&t instanceof Gc||(t instanceof Gc?this.subModules.forEach((e=>{const s=e.outputs.findByName(this.name);if(!s)throw Error(`Could not forward output ${this.name}`);Hc(t.subInput(e.voiceNo),s)})):this.subOutputs.forEach((e=>Hc(t,e))))}unPlugAll(){Uc.unPlugAll(this)}checkNameValidity(){if(!this.plugableModule.audioModules[0].outputs.findByName(this.name))throw Error("You should forward to existing output")}}class Xc extends Uc{internalModule;constructor(t,e){super(t,e),this.internalModule=e.internalModule}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}}class Zc extends Uc{internalModule;constructor(t,e){super(t,e),this.internalModule=e.internalModule}plug(t,e=!0){super.plug(t,e),t instanceof Gc||this.internalModule.connect(t.internalModule)}unPlug(t,e=!0){if(super.unPlug(t,e),!(t instanceof Gc))try{this.internalModule.disconnect(t.internalModule)}catch(t){console.error(t)}}unPlugAll(){Uc.unPlugAll(this)}}class Yc extends Uc{onMidiEvent;constructor(t,e){super(t,e),this.onMidiEvent=e.onMidiEvent}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}}class Qc extends Uc{constructor(t,e){super(t,e)}plug(t,e=!0){super.plug(t,e)}unPlug(t,e=!0){super.unPlug(t,e)}unPlugAll(){Uc.unPlugAll(this)}onMidiEvent=t=>{this.midiConnections.forEach((e=>{e.onMidiEvent(t)}))};get midiConnections(){return this.connections.filter((t=>t instanceof Yc))}}class Kc{plugableModule;collection=[];constructor(t){this.plugableModule=t}add(t){let e;switch(t.ioType){case zc.AudioInput:if(this.plugableModule instanceof su)throw Error("PolyModule is not supported");e=new Xc(this.plugableModule,t);break;case zc.AudioOutput:if(this.plugableModule instanceof su)throw Error("PolyModule is not supported");e=new Zc(this.plugableModule,t);break;case zc.ForwardInput:if(this.plugableModule instanceof eu)throw Error("MonoModule is not supported");e=new Gc(this.plugableModule,t);break;case zc.ForwardOutput:if(this.plugableModule instanceof eu)throw Error("MonoModule is not supported");e=new $c(this.plugableModule,t);break;case zc.MidiInput:e=new Yc(this.plugableModule,t);break;case zc.MidiOutput:e=new Qc(this.plugableModule,t);break;default:throw Error("Unknown IOType")}return this.collection.push(e),e}unPlugAll(){this.collection.forEach((t=>t.unPlugAll()))}find(t){return this.collection.find((e=>e.id===t))}findByName(t){return this.collection.find((e=>e.name===t))}serialize(){return this.collection.map((t=>t.serialize()))}}class Jc{connect(){throw Error("This module is not connectable")}disconnect(){throw Error("This module is not connectable")}dispose(){}}var tu,eu=class{static moduleName;id;name;internalModule;inputs;outputs;voiceNo;updatedAt;_props={};constructor(t,e){this.internalModule=t,this.id=e.id||ta(),delete e.id,this.inputs=new Kc(this),this.outputs=new Kc(this),Object.assign(this,e)}set props(t){t&&(this.updatedAt=new Date,Object.assign(this,t))}get props(){return this._props}plug(t,e,s){const n=this.outputs.findByName(e);if(!n)throw Error(`Output ${e} not exist`);const i=t.inputs.findByName(s);if(!i)throw Error(`Input ${s} not exist`);Lc(i,n)}unPlugAll(){this.outputs.unPlugAll()}dispose(){this.inputs.unPlugAll(),this.outputs.unPlugAll(),this.internalModule.dispose()}triggerAttack=(t,e)=>{throw Error("triggerAttack not implemented")};triggerRelease=(t,e)=>{throw Error("triggerRelease not implemented")};onMidiEvent=t=>{if(void 0!==t.voiceNo&&t.voiceNo!==this.voiceNo)return;const{note:e,triggeredAt:s}=t;switch(t.type){case"noteOn":{const{duration:t}=e;if(this.triggerer(this.triggerAttack,e,s),t){const r=s+(n=t,new Xi(ji(),n,i)).toSeconds();this.triggerer(this.triggerRelease,e,r)}break}case"noteOff":this.triggerer(this.triggerRelease,e,s);break;default:throw Error("This type is not a note")}var n,i};triggerer(t,e,s){t(e,s)}serialize(){const t=this.constructor;return{id:this.id,name:this.name,type:t.moduleName,props:this.props,inputs:this.inputs.serialize(),outputs:this.outputs.serialize()}}registerMidiInput(t){return this.inputs.add({...t,ioType:zc.MidiInput})}registerAudioInput(t){return this.inputs.add({...t,ioType:zc.AudioInput})}registerMidiOutput(t){return this.outputs.add({...t,ioType:zc.MidiOutput})}registerAudioOutput(t){return this.outputs.add({...t,ioType:zc.AudioOutput})}registerBasicOutputs(){this.registerAudioOutput({name:"output",internalModule:this.internalModule})}registerBasicInputs(){this.registerAudioInput({name:"input",internalModule:this.internalModule}),this.registerDefaultMidiInput()}registerDefaultMidiInput(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}};class su{static moduleName;id;child;_name;audioModules;inputs;outputs;_numberOfVoices;constructor(t){this.id=t.id||ta(),delete t.id,this.audioModules=[];const{child:e,props:s,...n}=t;this.child=e,Object.assign(this,n),this.numberOfVoices=t.numberOfVoices||1,this.inputs=new Kc(this),this.outputs=new Kc(this),Object.assign(this,{props:s})}get name(){return this._name}set name(t){this._name=t,this.audioModules.forEach((e=>e.name=t))}get props(){if(0===this.audioModules.length)throw Error("There isn't any initialized module");return this.audioModules[0].props}set props(t){Object.assign(this,t),this.audioModules.forEach((e=>e.props=t))}get numberOfVoices(){return this._numberOfVoices}set numberOfVoices(t){this._numberOfVoices=t,this.adjustNumberOfModules()}plug(t,e,s){const n=this.outputs.findByName(e);if(!n)throw Error(`Output ${e} not exist`);const i=t.inputs.findByName(s);if(!i)throw Error(`Input ${s} not exist`);Lc(i,n)}unPlugAll(){this.outputs.unPlugAll()}dispose(){this.unPlugAll(),this.audioModules.forEach((t=>t.dispose()))}onMidiEvent=t=>{const e=t.voiceNo||0,s=this.findVoice(e);s?.onMidiEvent(t)};serialize(){if(0===this.audioModules.length)throw Error("There isn't any initialized module");const t=this.constructor;return{...this.audioModules[0].serialize(),id:this.id,type:t.moduleName,numberOfVoices:this.numberOfVoices,inputs:this.inputs.serialize(),outputs:this.outputs.serialize()}}find(t){const e=this.audioModules.find(t);if(!e)throw Error("Audio module not found");return e}findVoice(t){return this.audioModules.find((e=>e.voiceNo===t))}registerInput(t){return this.inputs.add({...t,ioType:zc.ForwardInput})}registerOutput(t){return this.outputs.add({...t,ioType:zc.ForwardOutput})}registerMidiInput(t){return this.inputs.add({...t,ioType:zc.MidiInput})}registerMidiOutput(t){return this.outputs.add({...t,ioType:zc.MidiOutput})}registerBasicOutputs(){this.registerOutput({name:"output"})}registerBasicInputs(){this.registerInput({name:"input"}),this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}adjustNumberOfModules(){if(this.audioModules.length!==this.numberOfVoices){if(this.audioModules.length>this.numberOfVoices){const t=this.audioModules.pop();t?.dispose()}else{const t=this.audioModules.length,e=Wc(this.id,t.toString()),s=0===t?{}:this.props,n=new this.child({id:e,name:this.name,props:{...s,voiceNo:t}});if(n instanceof su)throw Error("Polymodule not supported");this.audioModules.push(n)}this.adjustNumberOfModules()}}}!function(t){t.Attack="attack",t.Decay="decay",t.Sustain="sustain",t.Release="release"}(tu||(tu={}));const nu=.01,iu={attack:nu,decay:nu,sustain:1,release:nu};class ru extends eu{activeNote;triggeredAt;constructor(t){const{id:e,name:s,props:n,internalModule:i}=t;super(i,{id:e,name:s,props:{...iu,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}get attack(){return this._props.attack}set attack(t){this.setStage(tu.Attack,t)}get decay(){return this._props.decay}set decay(t){this.setStage(tu.Decay,t)}get sustain(){return this._props.sustain}set sustain(t){this.setStage(tu.Sustain,t)}get release(){return this._props.release}set release(t){this.setStage(tu.Release,t)}setStage(t,e){const s=0===e?this.minTime(t):this.maxTime(t)*e;this._props={...this.props,[t]:e},this.internalModule[t]=s}triggerAttack=(t,e)=>{this.activeNote=t.fullName,this.triggeredAt=e,this.internalModule.triggerAttack(e,t.velocity)};triggerRelease=(t,e)=>{this.activeNote&&this.activeNote!==t.fullName||(this.internalModule.triggerRelease(e),this.activeNote=void 0)};maxTime(t){return t===tu.Sustain?1:2}minTime(t){return t===tu.Sustain?0:nu}}class ou extends su{constructor(t){const{id:e,name:s,child:n,props:i}=t;super({id:e,name:s,child:n,props:{...iu,...i}}),this.registerBasicInputs(),this.registerBasicOutputs()}}class au extends ru{constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new so,props:n})}}class cu extends ou{static moduleName="Envelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:au,props:{...iu,...n}})}}class uu extends ru{constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new oo,props:n})}}class hu extends ou{static moduleName="AmpEnvelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:uu,props:n})}}const lu={amount:0};class pu extends ru{_frequency;_amount;filter;constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new ho,props:{...lu,...n}})}get frequency(){return this._frequency}set frequency(t){this._frequency=t,this.internalModule.baseFrequency=t}get amount(){return this._amount}set amount(t){this._amount=t,this.internalModule.octaves=t}}class du extends ou{static moduleName="FreqEnvelope";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:pu,props:n})}}const fu={noteName:"C3",fine:0,coarse:0,wave:"sine",range:0,volume:0};class mu extends eu{_note;_fineSignal;constructor(t){const{id:e,name:s,props:n}=t;super(new Br,{id:e,name:s,props:{...fu,...n}}),this.registerInputs(),this.registerBasicOutputs(),this.start(Bo())}get note(){return this._note}setNoteAt(t,e){this._note=this.getNote(t),this.updateFrequency(e)}set note(t){this._note=this.getNote(t),this.updateFrequency()}get noteName(){return this._props.noteName}set noteName(t){this._props={...this.props,noteName:t},this.note=new Fo(this.noteName)}get fineSingal(){return this._fineSignal||(this._fineSignal=new Fr(100),this._fineSignal.connect(this.internalModule.detune)),this._fineSignal}get fine(){return this._props.fine}set fine(t){this._props={...this.props,fine:t},this.fineSingal.value=this.fine}get coarse(){return this._props.coarse}set coarse(t){this._props={...this.props,coarse:Math.floor(t)},this.updateFrequency()}get wave(){return this._props.wave}set wave(t){this._props={...this.props,wave:t},this.internalModule.type=this.wave}get volume(){return this._props.volume}set volume(t){this._props={...this.props,volume:t},this.internalModule.volume.value=this.volume}get range(){return this._props.range}set range(t){this._props={...this.props,range:t},this.updateFrequency()}start(t){if(!Gu.isStarted)return;"started"===this.internalModule.state?this.internalModule.restart(t):this.internalModule.start(t)}stop(t){this.internalModule.stop(t)}triggerAttack=(t,e)=>{this.setNoteAt(t,e),this.start(e)};triggerRelease=()=>{};updateFrequency(t){if(!this.note)return;const e=this.note.adjustFrequency(this.range,this.coarse);t?this.internalModule.frequency.linearRampToValueAtTime(e,t):this.internalModule.frequency.value=e}getNote(t){return t instanceof Fo?t:new Fo(t)}registerInputs(){this.registerDefaultMidiInput(),this.registerAudioInput({name:"fine",internalModule:this.fineSingal})}}class _u extends su{static moduleName="Oscillator";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:mu,props:{...fu,...n}}),this.registerBasicOutputs(),this.registerInput({name:"midi in"}),this.registerInput({name:"fine"})}start(t){this.audioModules.forEach((e=>e.start(t)))}stop(t){this.audioModules.forEach((e=>e.stop(t)))}}const gu={cutoff:2e4,resonance:0,envelopeAmount:0,slope:-24,filterType:"lowpass"};class vu extends eu{_cutoff;_amount;constructor(t){const{id:e,name:s,props:n}=t;super(new uo({type:"lowpass"}),{id:e,name:s,props:{...gu,...n}}),this._cutoff=new $r,this._cutoff.connect(this.internalModule.frequency),this._amount=new Fr,this._amount.connect(this._cutoff),this.updateAmountFactor(),this.registerBasicInputs(),this.registerOutputs()}get cutoff(){return this._props.cutoff}set cutoff(t){this._cutoff&&(this._cutoff.addend.value=t),this._props={...this.props,cutoff:t},this.updateAmountFactor()}get filterType(){return this._props.filterType}set filterType(t){this._props={...this.props,filterType:t},this.internalModule.type=t}get slope(){return this._props.slope}set slope(t){this._props={...this.props,slope:t},this.internalModule.rolloff=t}get frequency(){return this.internalModule.frequency}get resonance(){return this._props.resonance}set resonance(t){this._props={...this.props,resonance:t},this.internalModule.Q.value=t}get envelopeAmount(){return this._props.envelopeAmount}set envelopeAmount(t){this._props={...this.props,envelopeAmount:t},this.updateAmountFactor()}registerOutputs(){this.registerBasicOutputs(),this.registerAudioInput({name:"cutoff",internalModule:this._amount})}updateAmountFactor(){if(!this._amount)return;const t=this.envelopeAmount>0?this.envelopeAmount*Math.abs(2e4-this.cutoff):this.envelopeAmount*Math.abs(1-this.cutoff);this._amount.factor.value=t}}class yu extends su{static moduleName="Filter";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:vu,props:{...gu,...n}}),this.registerBasicInputs(),this.registerOutputs()}registerOutputs(){this.registerBasicOutputs(),this.registerInput({name:"cutoff"})}}class wu extends eu{static moduleName="Master";constructor({id:t}){super(ji().destination,{id:t,name:"Master"}),this.registerAudioInput({name:"input",internalModule:this.internalModule})}dispose(){this.inputs.unPlugAll(),this.outputs.unPlugAll()}}class xu extends su{static moduleName="VoiceScheduler";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:bu,props:n}),this.registerInputs(),this.registerOutputs(),this.polyNumber=this.numberOfVoices}set polyNumber(t){super.numberOfVoices=t}get polyNumber(){return this.numberOfVoices}onMidiEvent=t=>{let e;switch(t.type){case"noteOn":e=this.findFreeVoice();break;case"noteOff":e=this.audioModules.find((e=>e.activeNote===t.note.fullName));break;default:throw Error("This type is not a note")}e&&(e.midiTriggered(t),t.voiceNo=e.voiceNo,this.midiOutput.onMidiEvent(t))};serialize(){const t=super.serialize();return{...t,props:{...t.props,polyNumber:this.polyNumber}}}findFreeVoice(){let t=this.audioModules.find((t=>!t.activeNote));return t||(t=this.audioModules.sort(((t,e)=>t&&e?t.triggeredAt-e.triggeredAt:0))[0]),t}registerInputs(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}}class bu extends eu{midiEvent;activeNote;triggeredAt;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:n})}midiTriggered=t=>{if(void 0===this.voiceNo)throw Error("Voice without voiceNo");const{triggeredAt:e,note:s,type:n}=t;if(!s)return;const i=s.fullName;switch(n){case"noteOn":this.activeNote=i,this.triggeredAt=e,this.midiEvent=t;break;case"noteOff":this.activeNote=null,this.midiEvent=null;break;default:throw Error("This type is not a note")}}}const Tu={selectedId:null};class Cu extends eu{static moduleName="MidiSelector";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{...Tu,...n}}),this.registerOutputs(),this.addEventListener(this.selectedId)}get selectedId(){return this._props.selectedId}set selectedId(t){this.removeEventListener(),this._props={...this.props,selectedId:t},this.addEventListener(t)}dispose(){this.removeEventListener(),super.dispose()}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}addEventListener(t){if(!this.onMidiEvent||!t)return;const e=Gu.midiDeviceManager.find(t);e?.addEventListener(this.forwardMidiEvent)}forwardMidiEvent=t=>{this.midiOutput.onMidiEvent(t)};removeEventListener(){if(!this.selectedId)return;const t=Gu.midiDeviceManager.find(this.selectedId);t?.removeEventListener(this.forwardMidiEvent)}}const ku={volume:-1/0};class Au extends eu{constructor(t){const{id:e,name:s,props:n}=t;super(new xr,{id:e,name:s,props:{...ku,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}get volume(){return this._props.volume}set volume(t){this._props={...this.props,volume:t},this.internalModule.volume.value=this.volume}triggerAttack=(t,e)=>{const s=20*Math.log10(t.velocity);this.internalModule.volume.exponentialRampToValueAtTime(s,e)};triggerRelease=()=>{}}class Su extends su{static moduleName="Volume";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:Au,props:{...ku,...n}}),this.registerBasicInputs(),this.registerBasicOutputs()}}const Mu={activeNotes:[]};class Ou extends eu{static moduleName="VirtualMidi";midiOutput;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{...Mu,...n}}),this.registerInputs(),this.registerOutputs()}get activeNotes(){return this._props.activeNotes}set activeNotes(t){this._props={...this.props,activeNotes:t}}sendMidi(t){this.midiOutput.onMidiEvent(t)}triggerAttack=(t,e)=>{this.activeNotes=[...this.activeNotes,t.fullName],Gu._triggerPropsUpdate(this.id,this.props),this.sendMidi(jo.fromNote(t,!0,e))};triggerRelease=(t,e)=>{this.activeNotes=this.activeNotes.filter((e=>e!==t.fullName)),Gu._triggerPropsUpdate(this.id,this.props),this.sendMidi(jo.fromNote(t,!1,e))};serialize(){return{...super.serialize(),activeNotes:this.activeNotes}}registerInputs(){this.registerMidiInput({name:"midi in",onMidiEvent:this.onMidiEvent})}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}}const Eu={wet:1};class Du extends eu{constructor(t){const{id:e,name:s,internalModule:n,props:i}=t;super(n,{id:e,name:s,props:{...Eu,...i}}),this.registerBasicInputs(),this.registerBasicOutputs()}get wet(){return this._props.wet}set wet(t){this._props={...this.props,wet:t},this.internalModule.wet.value=this.wet}}const Iu={decay:1.5,preDelay:.025};class Nu extends Du{static moduleName="Reverb";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Eo,props:{...Iu,...n}})}get decay(){return this._props.decay}set decay(t){this._props={...this.props,decay:t},this.internalModule.decay=this.decay}get preDelay(){return this._props.preDelay}set preDelay(t){this._props={...this.props,preDelay:t},this.internalModule.preDelay=this.preDelay}}const Ru={delayTime:1,feedback:.3};class Bu extends Du{static moduleName="Delay";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Oo,props:{...Ru,...n}})}get delayTime(){return this._props.delayTime}set delayTime(t){this._props={...this.props,delayTime:t},this.internalModule.delayTime.value=this.delayTime}get feedback(){return this._props.feedback}set feedback(t){this._props={...this.props,feedback:t},this.internalModule.feedback.value=this.feedback}}const Pu={drive:.3};class Vu extends Du{static moduleName="Distortion";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new So,props:{...Pu,...n}})}get drive(){return this._props.drive}set drive(t){this._props={...this.props,drive:t},this.internalModule.distortion=this.drive}}const qu={bits:16};class Fu extends Du{static moduleName="BitCrusher";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,internalModule:new Co,props:{...qu,...n}})}get bits(){return this._props.bits}set bits(t){this._props={...this.props,bits:t},this.internalModule.bits.value=this.bits}}class zu extends eu{static moduleName="Sequencer";midiOutput;part;constructor(t){const{id:e,name:s,props:n}=t;super(new Jc,{id:e,name:s,props:{sequences:[],steps:16,bars:1,...n}}),this.initializePart(),this.start(Bo()),this.registerOutputs()}get props(){return super.props}set props(t){this.sequences||(this._props.sequences=[]),super.props={...this.props,...t},this.adjust()}get steps(){return this._props.steps}set steps(t){this._props={...this.props,steps:t}}get bars(){return this.props.bars}set bars(t){this._props={...this.props,bars:t}}get sequences(){return this._props.sequences}set sequences(t){const e=t;this._props={...this.props,sequences:e}}start(t){Gu.isStarted&&this.part.start(t)}stop(){this.part.stop()}registerOutputs(){this.midiOutput=this.registerMidiOutput({name:"midi out"})}initializePart(){this.part=new yo(this.onPartEvent,[]),this.part.loop=!0,this.part.loopEnd=this.loopEnd}adjust(){this.part&&(this.adjustNumberOfBars(),this.adjustNumberOfSteps(),this.updateBarParts())}adjustNumberOfBars(){const t=this.sequences.length-this.bars,e=[...this.sequences];0!==t&&(t>0?e.pop():e.push([]),this.sequences=e,this.adjustNumberOfBars())}adjustNumberOfSteps(t=0){if(!this.bars)return;const e=[...this.sequences],s=[...e[t]],n=s.length-this.steps;if(0!==n){if(n>0)s.pop();else{const e=s.length;s.push({active:!1,time:`${t}:0:${e}`,notes:[]})}e[t]=s,this.sequences=e,this.adjustNumberOfSteps(t)}else{if(t===this.bars-1)return;this.adjustNumberOfSteps(t+1)}}updateBarParts(){this.part.clear(),this.sequences.forEach((t=>{t.forEach((t=>this.part.add(t.time,t)))})),this.part.loopEnd=this.loopEnd}get loopEnd(){return`${this.bars}:0:0`}onPartEvent=(t,e)=>{e.active&&jo.fromSequence(e,t).forEach((t=>{this.midiOutput.onMidiEvent(t)}))}}const ju={wave:"sine",frequency:.1,min:0,max:1,amount:1};class Wu extends eu{constructor(t){const{id:e,name:s,props:n}=t;super(new Yr,{id:e,name:s,props:{...ju,...n}}),this.registerBasicOutputs(),this.registerInputs(),this.start(Bo())}get wave(){return this._props.wave}set wave(t){this._props={...this.props,wave:t},this.internalModule.type=this.wave}get min(){return this._props.min}set min(t){this._props={...this.props,min:t},this.internalModule.min=this.min}get max(){return this._props.max}set max(t){this._props={...this.props,max:t},this.internalModule.max=this.max}get frequency(){return this._props.frequency}set frequency(t){this._props={...this.props,frequency:t},this.internalModule.frequency.value=this.frequency}get amount(){return this._props.amount}set amount(t){this._props={...this.props,amount:t},this.internalModule.amplitude.value=this.amount}start(t){if(!Gu.isStarted)return;"started"===this.internalModule.state?(this.internalModule.stop(t-2),this.internalModule.start(t)):this.internalModule.start(t)}stop(t){this.internalModule.stop(t)}triggerAttack=(t,e)=>{this.start(e)};triggerRelease=()=>{};registerInputs(){this.registerDefaultMidiInput(),this.registerAudioInput({name:"amount",internalModule:this.internalModule.amplitude})}}class Lu extends su{static moduleName="LFO";constructor(t){const{id:e,name:s,props:n}=t;super({id:e,name:s,child:Wu,props:{...ju,...n}}),this.registerBasicOutputs(),this.registerInput({name:"midi in"}),this.registerInput({name:"amount"})}start(t){this.audioModules.forEach((e=>e.start(t)))}stop(t){this.audioModules.forEach((e=>e.stop(t)))}}function Hu(t){const{id:e,type:s,name:n,props:i}=t,r=function(t){switch(t){case _u.moduleName:return _u;case cu.moduleName:return cu;case hu.moduleName:return hu;case du.moduleName:return du;case yu.moduleName:return yu;case Su.moduleName:return Su;case wu.moduleName:return wu;case xu.moduleName:return xu;case Cu.moduleName:return Cu;case Ou.moduleName:return Ou;case Nu.moduleName:return Nu;case Bu.moduleName:return Bu;case Vu.moduleName:return Vu;case Fu.moduleName:return Fu;case zu.moduleName:return zu;case Lu.moduleName:return Lu;default:throw Error(`Unknown module type ${t}`)}}(s);return new r({id:e,name:n,props:i})}class Uu{midiDeviceManager;static instance;context;propsUpdateCallbacks;_isStarted=!1;modules;routes;constructor(){this.modules={},this.routes={},this.propsUpdateCallbacks=[]}static getInstance(){return Uu.instance||(Uu.instance=new Uu),Uu.instance}initialize(t){return new Promise((e=>{if(this.context)return e({});this.context=new Ni(t.context),Wi(this.context),this.context.transport.start(),this.midiDeviceManager=new Go,setTimeout((()=>{e({})}),0)}))}addModule(t){const{id:e,name:s,numberOfVoices:n,type:i,props:r={}}=t,o=Hu({id:e,name:s,type:i,props:{}});return o instanceof su&&n&&(o.numberOfVoices=n),o.props=r,this.modules[o.id]=o,this.updateRoutes(),o.serialize()}removeModule(t){this.modules[t].dispose();const e=this.moduleRouteIds(t);return e.forEach((t=>delete this.routes[t])),this.updateRoutes(),delete this.modules[t],e}updateModule(t){const{id:e,changes:{name:s,numberOfVoices:n,props:i={}}}=t,r=this.findById(e);return r.props=i,s&&(r.name=s),r instanceof su&&n&&(r.numberOfVoices=n),r.serialize()}onPropsUpdate(t){this.propsUpdateCallbacks.push(t)}_triggerPropsUpdate(t,e){this.propsUpdateCallbacks.forEach((s=>s(t,e)))}addRoute(t){const e=function(t){const e=t.id||ta();return{...t,id:e}}(t),s={...this.routes,[e.id]:e};return this.routes=s,this.updateRoutes(),e}removeRoute(t){delete this.routes[t],this.updateRoutes()}triggerVirtualMidi(t,e,s){this.findById(t).sendMidi(jo.fromNote(e,"noteOn"===s))}dispose(){Object.values(this.modules).forEach((t=>{t.dispose()})),this.modules={},this.routes={}}findById(t){const e=this.modules[t];if(!e)throw Error(`Audio module with id ${t} not exists`);return e}get isStarted(){return void 0!==this.context&&"started"===this.context.transport.state&&this._isStarted}start(){const t=Bo();this._isStarted=!0,this.updateRoutes(),Object.values(this.modules).forEach((e=>{const s=e;s.start&&s.start(t)}))}stop(){const t=Bo();Object.values(this.modules).forEach((e=>{const s=e;s.stop&&s.stop(t)})),this._isStarted=!1}get bpm(){return this.context.transport.bpm.value}set bpm(t){this.context.transport.bpm.value=t}updateRoutes(){var t;t=Object.values(this.routes),Object.values(Gu.modules).forEach((t=>{t.unPlugAll()})),t.map((t=>{const{sourceId:e,sourceIOId:s,destinationId:n,destinationIOId:i}=t,r=Gu.findById(e),o=Gu.findById(n),a=r.outputs.find(s),c=o.inputs.find(i);if(!c||!a)throw Error("IO not found");return Lc(c,a),!0})).every((t=>t))?console.log("######## Routes succesfully applied"):console.log("######## Routes partialy applied")}moduleRouteIds(t){const e={...this.routes};return Object.keys(e).filter((s=>{const{sourceId:n,destinationId:i}=e[s];return n===t||i===t}))}}var Gu=Uu.getInstance();export{Wo as MidiDevice,Go as MidiDeviceManager,Fo as Note,Gu as default};
|
|
25
25
|
//# sourceMappingURL=main.esm.js.map
|