/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / site / assets / worklet-PIV7En5i.js
1 line · 38.7 KBCodeBlameHistory
73fe08adouble pendulum: album app with composition 1 (poincaré)Jeremy Magland 1const e=Math.SQRT2,t=Math.PI;function n(e,n){let r=Math.ceil(Math.abs(n)+e)+24,i=0;for(let a=0;a<=r;a++){let o=t*a/r;i+=(a===0||a===r?.5:1)*Math.cos(e*o-n*Math.sin(o))}return i/r}function r(e,t){let r=[],i=e===0?.5:e,a=n(e,i);for(let o=i+.05;o<=t;o+=.05){let t=n(e,o);if(a*t<0){let t=i,s=o,c=a;for(let r=0;r<50;r++){let r=.5*(t+s),i=n(e,r);c*i<=0?s=r:(t=r,c=i)}r.push(.5*(t+s))}i=o,a=t}return r}const i=[4.730040745,7.853204624,10.99560784,14.13716549,17.27875966],a=e=>e<i.length?i[e]:(2*e+3)*t/2;function o(e,t,n){if(t<12){let e=(Math.cosh(t)-Math.cos(t))/(Math.sinh(t)-Math.sin(t));return Math.cosh(t*n)+Math.cos(t*n)-e*(Math.sinh(t*n)+Math.sin(t*n))}let r=e%2==0?1:-1;return Math.cos(t*n)-Math.sin(t*n)+Math.exp(-t*n)+r*Math.exp(-t*(1-n))}const s=[[.5,2],[1,2],[1.2,3],[1.5,3],[2,4],[2.5,4],[2.67,3],[3,5],[4,6],[4.24,5],[5.33,7],[5.7,6],[6.67,8],[7.2,7],[8,9],[9,8],[10,10],[11.1,9],[12.1,11],[13.5,10]];function c(i,c,d,f,p=2){let m=new Float64Array(c),h=new Float64Array(c),g={kind:i,N:c,ratios:m,wavenum:h,aspect:d};switch(i){case`string`:case`free`:for(let e=0;e<c;e++){let t=e+1;m[e]=i===`string`?t:t**+f,h[e]=t}return{...g,view:`line`,dim:1,shape:(n,r)=>e*Math.sin((n+1)*t*r)};case`tube_co`:for(let e=0;e<c;e++)m[e]=2*e+1,h[e]=(2*e+1)/2;return{...g,view:`line`,dim:1,shape:(n,r)=>e*Math.cos((2*n+1)*t*r/2)};case`tube_oo`:for(let e=0;e<c;e++)m[e]=e+1,h[e]=e+1;return{...g,view:`line`,dim:1,shape:(n,r)=>e*Math.cos((n+1)*t*r)};case`bar`:{let e=a(0),n=new Float64Array(c),r=2048;for(let i=0;i<c;i++){let s=a(i);m[i]=(s/e)**2,h[i]=s/t;let c=0;for(let e=0;e<r;e++)c+=o(i,s,(e+.5)/r)**2;n[i]=1/Math.sqrt(c/r)}return{...g,view:`line`,dim:1,shape:(e,t)=>n[e]*o(e,a(e),t)}}case`ring`:{let n=[],r=[],i=0,a=0,o=2;for(;n.length<c;){i<s.length?[a,o]=s[i]:(a*=1.09,o+=+(i%2==0));for(let e=0;e<2&&n.length<c;e++)m[n.length]=a*(e===0?1:1+6e-4*(1+i%3)),h[n.length]=2*o,n.push(o),r.push(e);i++}return{...g,view:`ring`,dim:1,shape:(i,a)=>{let o=2*t*a*n[i];return e*(r[i]===0?Math.cos(o):Math.sin(o))}}}case`plate`:{let e=Math.ceil(3*Math.sqrt(c))+3,n=[];for(let t=1;t<=e;t++)for(let r=1;r<=e;r++)n.push([t*t+(r/d)**2,t,r]);n.sort((e,t)=>e[0]-t[0]);let r=new Int32Array(c),i=new Int32Array(c),a=n[0][0];for(let e=0;e<c;e++){let[t,o,s]=n[e];m[e]=t/a,h[e]=Math.sqrt(o*o+(s/d)**2),r[e]=o,i[e]=s}return{...g,view:`rect`,dim:2,shape:(e,n,a)=>2*Math.sin(r[e]*t*n)*Math.sin(i[e]*t*a)}}case`membrane`:{let i=2*Math.sqrt(c)+6,a=[];for(;;){a=[];for(let e=0;e<=Math.ceil(i);e++)for(let t of r(e,i))a.push([t,e,0]),e>0&&a.push([t,e,1]);if(a.length>=c)break;i*=1.3}a.sort((e,t)=>e[0]-t[0]||e[2]-t[2]);let o=a[0][0],s=new Int32Array(c),l=new Int32Array(c),d=new Float64Array(c),f=new Float64Array(c);for(let r=0;r<c;r++){let[i,c,u]=a[r];m[r]=i/o,h[r]=i/t,s[r]=c,l[r]=u,d[r]=i,f[r]=c===0?1/Math.abs(n(1,i)):e/Math.abs(n(c+1,i))}return u(g,s,l,d,f)}case`disc`:{let e=p,n=Math.ceil(Math.sqrt(2*c))+4,r=[];for(let t=0;t<=n;t++)for(let i=0;t+2*i<=n;i++){if(i===0&&t<2)continue;let n=(t+2.1*i)**+e;r.push([n,t,i,0]),t>0&&r.push([n*1.0004,t,i,1])}r.sort((e,t)=>e[0]-t[0]);let i=r.slice(0,c),a=i.reduce((e,t)=>Math.max(e,t[1]),0),o=i.reduce((e,t)=>Math.max(e,t[2]),0),s=[];for(let e=0;e<=a;e++)s.push(l(e,o+1));let d=new Int32Array(c),f=new Int32Array(c),_=new Float64Array(c),v=i[0][0];for(let e=0;e<c;e++){let[n,r,a,o]=i[e];m[e]=n/v,d[e]=r,f[e]=o,_[e]=s[r][r===0?a-1:a],h[e]=_[e]/t}return u(g,d,f,_,null)}}}function l(e,t){let r=t=>e===0?-n(1,t):.5*(n(e-1,t)-n(e+1,t)),i=[],a=e===0?.5:Math.max(.3,e*.8),o=r(a);for(let e=a+.05;i.length<t;e+=.05){let t=r(e);if(o*t<0){let t=a,n=e,s=o;for(let e=0;e<50;e++){let e=.5*(t+n),i=r(e);s*i<=0?n=e:(t=e,s=i)}i.push(.5*(t+n))}a=e,o=t}return i}function u(e,t,r,i,a){let o=e.N,s=Array(o).fill(null),c=a??new Float64Array(o),l=(e,r)=>{let o=s[e];if(!o){o=/* @__PURE__ */ new Float64Array(258);for(let r=0;r<=256;r++)o[r]=n(t[e],i[e]*r/256);if(o[257]=o[256],s[e]=o,!a){let n=0;for(let e=0;e<=256;e++)n+=(e===0||e===256?.5:1)*o[e]*o[e]*e/256/256;c[e]=1/Math.sqrt(Math.max(1e-12,(t[e]===0?2:1)*n))}}let l=r*256,u=Math.floor(l),d=l-u;return o[u]*(1-d)+o[u+1]*d};return{...e,view:`disk`,dim:2,shape:(e,n,i)=>{let a=2*n-1,o=2*i-1,s=Math.hypot(a,o);if(s>=1)return 0;let u=l(e,s),d=t[e],f=d===0?1:r[e]===0?Math.cos(d*Math.atan2(o,a)):Math.sin(d*Math.atan2(o,a));return c[e]*u*f}}}const d=(e,t)=>e[t],f=(e,t)=>e[t],p=e=>e.geometry===`membrane`||e.geometry===`plate`||e.geometry===`disc`,m=(...e)=>t=>e.includes(t.geometry),h=(...e)=>t=>e.includes(t.exciter),g=[`bow`,`reed`,`selfosc`,`noise`],_=[[`off`,`Off`],[`pitch`,`Pitch`],[`amp`,`Amplitude`],[`position`,`Excite position`],[`pickup`,`Pickup position`],[`tension`,`Tension coupling`],[`cascade`,`Cascade coupling`],[`damping`,`Damping`],[`feedback`,`Feedback gain`],[`exciter`,`Exciter intensity`]],v=[[`sine`,`Sine`],[`tri`,`Triangle`],[`saw`,`Saw`],[`square`,`Square`],[`sh`,`Sample & hold`],[`smooth`,`Smooth random`]];function y(e){let t=t=>t[`lfo${e}Target`]!==`off`;return[{kind:`enum`,id:`lfo${e}Target`,label:`LFO ${e} →`,group:`Modulation`,options:_,def:`off`},{kind:`enum`,id:`lfo${e}Shape`,label:`Shape`,group:`Modulation`,options:v,def:`sine`,show:t},{kind:`num`,id:`lfo${e}Rate`,label:`Rate`,group:`Modulation`,min:.01,max:40,def:1,scale:`log`,unit:`Hz`,show:t},{kind:`num`,id:`lfo${e}Depth`,label:`Depth`,group:`Modulation`,min:0,max:1,def:.3,scale:`pow2`,show:t}]}const b=[{kind:`enum`,id:`geometry`,label:`Geometry`,group:`Body`,model:!0,def:`string`,options:[[`string`,`String`],[`bar`,`Bar (free–free)`],[`tube_co`,`Tube (closed–open)`],[`tube_oo`,`Tube (open–open)`],[`membrane`,`Membrane (circular)`],[`plate`,`Plate (rectangular)`],[`disc`,`Disc (cymbal / gong)`],[`ring`,`Bell / ring`],[`free`,`Free spectrum (kᵖ)`]],hint:`Sets the mode frequency ratios and mode shapes`},{kind:`num`,id:`modes`,label:`Modes`,group:`Body`,min:4,max:256,def:64,int:!0,model:!0,scale:`log`},{kind:`num`,id:`aspect`,label:`Aspect ratio`,group:`Body`,min:.2,max:1,def:.71,model:!0,show:m(`plate`)},{kind:`num`,id:`powerExp`,label:`Exponent p`,group:`Body`,min:.3,max:3,def:1.5,model:!0,show:m(`free`)},{kind:`num`,id:`discExp`,label:`Chladni exponent`,group:`Body`,min:1,max:2.5,def:2,model:!0,show:m(`disc`),hint:`f ∝ (m + 2n)^p: 2 = flat plate; lower for domed cymbals and gongs`},{kind:`num`,id:`stretch`,label:`Stretch`,group:`Body`,min:.5,max:2,def:1,model:!0,digits:3,hint:`ratio → ratio^s (bar with s≈1.368 gives the 1:4:10 marimba tuning)`},{kind:`num`,id:`inharm`,label:`Stiffness B`,group:`Body`,min:0,max:.05,def:0,scale:`pow2`,model:!0,digits:5,hint:`ratio·√(1+B·ratio²): piano-like stretched partials`},{kind:`num`,id:`harmonize`,label:`Harmonize`,group:`Body`,min:0,max:1,def:0,model:!0,hint:`pull partials toward integer multiples`},{kind:`num`,id:`jitter`,label:`Detune jitter`,group:`Body`,min:0,max:200,def:0,scale:`pow2`,unit:`¢`,model:!0},{kind:`num`,id:`seed`,label:`Seed`,group:`Body`,min:1,max:999,def:1,int:!0,model:!0,hint:`random detune, coupling topology and radiation`},{kind:`num`,id:`t60`,label:`Decay T60`,group:`Damping`,min:.05,max:60,def:4,scale:`log`,unit:`s`},{kind:`num`,id:`hfDamp`,label:`HF damping`,group:`Damping`,min:0,max:100,def:2,scale:`pow2`,unit:`/s@1k`,hint:`extra decay rate σ = c·(f/1kHz)²`},{kind:`num`,id:`damper`,label:`Damper T60`,group:`Damping`,min:.02,max:20,def:.3,scale:`log`,unit:`s`,hint:`applied on key release; max = no damper`},{kind:`num`,id:`tension`,label:`Tension modulation`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`amplitude-dependent pitch (glides)`},{kind:`num`,id:`cascade`,label:`Cascade coupling`,group:`Nonlinear`,min:0,max:20,def:0,scale:`pow2`,digits:3,hint:`random quartic coupling: energy spreads across modes (gong/cymbal shimmer)`},{kind:`num`,id:`curvature`,label:`Curvature (3-wave)`,group:`Nonlinear`,min:0,max:3,def:0,scale:`pow2`,digits:3,hint:`quadratic forces: sum/difference tones, crashes`},{kind:`num`,id:`terms`,label:`Coupling terms`,group:`Nonlinear`,min:1,max:16,def:6,int:!0,model:!0},{kind:`num`,id:`nlModes`,label:`Coupled modes`,group:`Nonlinear`,min:4,max:128,def:48,int:!0,model:!0,scale:`log`},{kind:`num`,id:`glide`,label:`Pitch glide`,group:`Nonlinear`,min:-12,max:12,def:0,unit:`st`,hint:`pitch offset while loud, relaxing as the note decays: + falls (like tension), − rises (Chinese opera gong)`},{kind:`num`,id:`crossTension`,label:`Cross-note tension`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`notes share one tension: they bend each other`},{kind:`num`,id:`crossLink`,label:`Cross-note link`,group:`Nonlinear`,min:0,max:2,def:0,scale:`pow2`,digits:3,hint:`sympathetic coupling + intermodulation between notes`},{kind:`num`,id:`buzz`,label:`Barrier stiffness`,group:`Collision`,min:0,max:1,def:0,scale:`pow2`,digits:3,hint:`sitar bridge, snare wires, rattles`},{kind:`num`,id:`buzzGap`,label:`Gap`,group:`Collision`,min:0,max:2,def:.2,digits:3,show:e=>e.buzz>0},{kind:`num`,id:`buzzPos`,label:`Position`,group:`Collision`,min:0,max:1,def:.02,digits:3,show:e=>e.buzz>0},{kind:`num`,id:`buzzPosY`,label:`Position Y`,group:`Collision`,min:0,max:1,def:.5,show:e=>e.buzz>0&&p(e)},{kind:`enum`,id:`buzzSides`,label:`Barrier`,group:`Collision`,options:[[`one`,`One-sided (bridge)`],[`two`,`Two-sided (rattle)`]],def:`one`,show:e=>e.buzz>0},{kind:`enum`,id:`exciter`,label:`Key exciter`,group:`Exciter`,def:`strike`,options:[[`strike`,`Strike (hammer / mallet)`],[`pluck`,`Pluck`],[`impulse`,`Impulse`],[`bow`,`Bow`],[`reed`,`Reed / blow`],[`selfosc`,`Self-oscillator`],[`noise`,`Noise`]]},{kind:`num`,id:`strength`,label:`Strength`,group:`Exciter`,min:0,max:6,def:1,scale:`pow2`,hint:`>1 pushes the body into its nonlinear regime`},{kind:`num`,id:`exPos`,label:`Position`,group:`Exciter`,min:0,max:1,def:.13,digits:3},{kind:`num`,id:`exPosY`,label:`Position Y`,group:`Exciter`,min:0,max:1,def:.37,show:p},{kind:`num`,id:`exWidth`,label:`Contact width`,group:`Exciter`,min:0,max:1,def:.05,scale:`pow2`},{kind:`num`,id:`hammerMass`,label:`Hammer mass`,group:`Exciter`,min:.005,max:5,def:.1,scale:`log`,digits:3,show:h(`strike`)},{kind:`num`,id:`hardness`,label:`Contact time`,group:`Exciter`,min:.05,max:20,def:1,scale:`log`,unit:`ms`,show:h(`strike`,`impulse`)},{kind:`num`,id:`feltExp`,label:`Felt exponent`,group:`Exciter`,min:1,max:4,def:2.5,show:h(`strike`)},{kind:`num`,id:`bowForce`,label:`Bow force`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:h(`bow`)},{kind:`num`,id:`bowSpeed`,label:`Bow speed`,group:`Exciter`,min:0,max:2,def:.4,scale:`pow2`,show:h(`bow`),hint:`scaled by key velocity: sets the loudness`},{kind:`num`,id:`bowNoise`,label:`Bow noise`,group:`Exciter`,min:0,max:1,def:0,scale:`pow2`,show:h(`bow`),hint:`random bow-force fluctuation: rosin and hair noise`},{kind:`num`,id:`reedPressure`,label:`Mouth pressure`,group:`Exciter`,min:0,max:1.5,def:.6,show:h(`reed`)},{kind:`num`,id:`reedGain`,label:`Reed opening`,group:`Exciter`,min:0,max:2,def:.5,show:h(`reed`)},{kind:`num`,id:`breath`,label:`Breath noise`,group:`Exciter`,min:0,max:1,def:.05,scale:`pow2`,show:h(`reed`)},{kind:`num`,id:`selfGain`,label:`Negative damping`,group:`Exciter`,min:0,max:4,def:.5,scale:`pow2`,show:h(`selfosc`)},{kind:`num`,id:`selfSat`,label:`Saturation level`,group:`Exciter`,min:.02,max:4,def:.5,scale:`log`,show:h(`selfosc`)},{kind:`num`,id:`noiseLevel`,label:`Noise level`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:h(`noise`)},{kind:`num`,id:`noiseColor`,label:`Noise cutoff`,group:`Exciter`,min:50,max:16e3,def:3e3,scale:`log`,unit:`Hz`,show:h(`noise`,`reed`,`bow`)},{kind:`num`,id:`attack`,label:`Attack`,group:`Exciter`,min:1,max:3e3,def:40,scale:`log`,unit:`ms`,show:h(...g)},{kind:`num`,id:`release`,label:`Release`,group:`Exciter`,min:5,max:5e3,def:150,scale:`log`,unit:`ms`,show:h(...g)},{kind:`num`,id:`fbGain`,label:`Feedback gain`,group:`Feedback`,min:0,max:8,def:0,scale:`pow2`,hint:`output → delay → band-pass → saturate → back into the body (while a key is held)`},{kind:`num`,id:`fbDelay`,label:`Delay`,group:`Feedback`,min:.05,max:600,def:5,scale:`log`,unit:`ms`,show:e=>e.fbGain>0},{kind:`num`,id:`fbFreq`,label:`Band centre`,group:`Feedback`,min:30,max:12e3,def:800,scale:`log`,unit:`Hz`,show:e=>e.fbGain>0},{kind:`num`,id:`fbQ`,label:`Band Q`,group:`Feedback`,min:.3,max:30,def:1.5,scale:`log`,show:e=>e.fbGain>0},{kind:`num`,id:`fbSat`,label:`Saturation`,group:`Feedback`,min:.01,max:4,def:.4,scale:`log`,show:e=>e.fbGain>0},...y(1),...y(2),{kind:`num`,id:`vibDepth`,label:`Vibrato depth`,group:`Modulation`,min:0,max:100,def:0,scale:`pow2`,unit:`¢`,hint:`per-note vibrato, each note with its own phase and rate`},{kind:`num`,id:`vibRate`,label:`Vibrato rate`,group:`Modulation`,min:1,max:12,def:5.5,unit:`Hz`,show:e=>e.vibDepth>0},{kind:`num`,id:`vibDelay`,label:`Vibrato onset`,group:`Modulation`,min:0,max:2e3,def:300,unit:`ms`,show:e=>e.vibDepth>0,hint:`vibrato fades in after the note starts`},{kind:`num`,id:`bendRange`,label:`Pitch-bend range`,group:`Modulation`,min:0,max:24,def:2,int:!0,unit:`st`},{kind:`enum`,id:`soundbox`,label:`Soundbox`,group:`Soundbox`,def:`off`,options:[[`off`,`Off`],[`violin`,`Violin`],[`viola`,`Viola`],[`cello`,`Cello`],[`bass`,`Double bass`],[`guitar`,`Guitar`]],hint:`fixed resonances that every note passes through (they don't transpose)`},{kind:`num`,id:`boxSize`,label:`Size`,group:`Soundbox`,min:.4,max:3,def:1,scale:`log`,digits:3,show:e=>e.soundbox!==`off`,hint:`>1 lowers every resonance`},{kind:`num`,id:`boxDamp`,label:`Damping`,group:`Soundbox`,min:.3,max:4,def:1,scale:`log`,show:e=>e.soundbox!==`off`,hint:`scales every resonance's bandwidth`},{kind:`num`,id:`boxMix`,label:`Mix`,group:`Soundbox`,min:0,max:1,def:1,show:e=>e.soundbox!==`off`},{kind:`num`,id:`pickup`,label:`Pickup position`,group:`Output`,min:0,max:1,def:.77,digits:3},{kind:`num`,id:`pickupY`,label:`Pickup Y`,group:`Output`,min:0,max:1,def:.61,show:p},{kind:`num`,id:`width`,label:`Stereo width`,group:`Output`,min:0,max:1,def:.3,hint:`right pickup is offset from the left one`},{kind:`num`,id:`spread`,label:`Whole-body radiation`,group:`Output`,min:0,max:1,def:.2,hint:`0 = point pickup, 1 = every mode radiates equally`},{kind:`num`,id:`tilt`,label:`Spectral tilt`,group:`Output`,min:-12,max:12,def:0,unit:`dB/oct`},{kind:`num`,id:`level`,label:`Level`,group:`Output`,min:-24,max:36,def:0,unit:`dB`,hint:`instrument level (saved with presets; Volume is not)`},{kind:`num`,id:`voices`,label:`Max notes`,group:`Output`,min:1,max:16,def:8,int:!0},{kind:`num`,id:`drive`,label:`Saturation`,group:`Output`,min:0,max:1,def:0},{kind:`num`,id:`delayMix`,label:`Delay mix`,group:`Output`,min:0,max:1,def:0},{kind:`num`,id:`delayTime`,label:`Delay time`,group:`Output`,min:10,max:1500,def:350,scale:`log`,unit:`ms`,show:e=>e.delayMix>0},{kind:`num`,id:`delayFb`,label:`Delay feedback`,group:`Output`,min:0,max:.95,def:.35,show:e=>e.delayMix>0},{kind:`num`,id:`reverbMix`,label:`Reverb mix`,group:`Output`,min:0,max:1,def:.15},{kind:`num`,id:`reverbSize`,label:`Reverb time`,group:`Output`,min:.2,max:12,def:2.5,scale:`log`,unit:`s`,show:e=>e.reverbMix>0},{kind:`num`,id:`volume`,label:`Volume`,group:`Output`,min:-40,max:12,def:-6,unit:`dB`},{kind:`bool`,id:`seqOn`,label:`Auto-play`,group:`Auto`,def:!1},{kind:`enum`,id:`seqMode`,label:`Pattern`,group:`Auto`,def:`mixed`,options:[[`mixed`,`Mixed (changes every 4 bars)`],[`melody`,`Melody`],[`arpeggio`,`Arpeggio`],[`chords`,`Chords`],[`rhythm`,`Rhythm (one pitch)`],[`drone`,`Drone + sparse melody`]]},{kind:`num`,id:`seqTempo`,label:`Tempo`,group:`Auto`,min:20,max:400,def:110,int:!0,unit:`bpm`},{kind:`num`,id:`seqDensity`,label:`Density`,group:`Auto`,min:0,max:1,def:.5},{kind:`enum`,id:`seqScale`,label:`Scale`,group:`Auto`,def:`pentatonic`,options:[[`chromatic`,`Chromatic`],[`major`,`Major`],[`minor`,`Natural minor`],[`dorian`,`Dorian`],[`pentatonic`,`Pentatonic`],[`wholetone`,`Whole tone`],[`harmonic`,`Harmonic series`]]},{kind:`num`,id:`seqRoot`,label:`Root`,group:`Auto`,min:24,max:84,def:48,int:!0},{kind:`num`,id:`seqRange`,label:`Range`,group:`Auto`,min:1,max:4,def:2,int:!0,unit:`oct`},{kind:`num`,id:`seqGate`,label:`Note length`,group:`Auto`,min:.05,max:8,def:.5,scale:`log`,unit:`beats`},{kind:`num`,id:`seqPoly`,label:`Notes per step`,group:`Auto`,min:1,max:4,def:1,int:!0,show:e=>e.seqMode===`melody`||e.seqMode===`mixed`},{kind:`num`,id:`seqVelRand`,label:`Velocity spread`,group:`Auto`,min:0,max:1,def:.3},{kind:`num`,id:`seqPosRand`,label:`Position spread`,group:`Auto`,min:0,max:1,def:0,hint:`randomize where each note is excited`}];Object.fromEntries(b.map(e=>[e.id,e]));const x=Object.fromEntries(b.map(e=>[e.id,e.def])),S=b.filter(e=>e.model).map(e=>e.id);function C(e){let t=e>>>0;return()=>{t=t+0x6d2b79f5>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function w(e){let t=Math.max(e(),1e-12);return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}const T=e=>S.map(t=>String(e[t])).join(`|`);function E(e){let t=Math.round(d(e,`modes`)),n=c(f(e,`geometry`),t,d(e,`aspect`),d(e,`powerExp`),d(e,`discExp`)),r=Math.round(d(e,`seed`)),i=C(r*7919+13),a=d(e,`stretch`),o=d(e,`inharm`),s=d(e,`harmonize`),l=d(e,`jitter`),u=0;for(let e=0;e<t;e++)if(Math.abs(n.ratios[e]-1)<1e-9){u=e;break}let p=new Float64Array(t);for(let e=0;e<t;e++){let t=n.ratios[e]**+a;if(t*=Math.sqrt(1+o*t*t)/Math.sqrt(1+o),s>0){let e=t<.75?.5:Math.max(1,Math.round(t));t=t**(1-s)*e**+s}let r=w(i);e!==u&&l>0&&(t*=2**(l*r/1200)),p[e]=t}let m=Int32Array.from({length:t},(e,t)=>t).sort((e,t)=>p[e]-p[t]),h=new Float64Array(t),g=new Float64Array(t),_=0;for(let e=0;e<t;e++)h[e]=p[m[e]],g[e]=n.wavenum[m[e]],m[e]===u&&(_=e);let v=Math.min(t,Math.round(d(e,`nlModes`))),y=Math.round(d(e,`terms`)),b=C(r*104729+7),x=[],S=new Float64Array(y*v);for(let e=0;e<y;e++){let t=[],n=Math.max(2,Math.round(v*.75)),r=0;for(let e=0;e<n;e++){let e=Math.floor(b()*v),n=b()<.25?e:Math.floor(b()*v),i=w(b);t.push([e,n,i]),r+=(e===n?1:2)*i*i}let i=1/Math.sqrt(r),a=[];for(let[e,n,r]of t)a.push([e,n,r*i]),e!==n&&a.push([n,e,r*i]);x.push(a);let o=0;for(let t=0;t<v;t++){let n=w(b);S[e*v+t]=n,o+=n*n}o=1/Math.sqrt(o);for(let t=0;t<v;t++)S[e*v+t]*=o}let E=x.reduce((e,t)=>e+t.length,0),D=new Int32Array(y+1),O=new Int32Array(E),k=new Int32Array(E),A=new Float64Array(E),j=0;for(let e=0;e<y;e++){D[e]=j;for(let[t,n,r]of x[e])O[j]=t,k[j]=n,A[j]=r,j++}D[y]=j;let M=C(r*31337+1),N=new Float64Array(v),P=0;for(let e=0;e<v;e++)N[e]=w(M),P+=N[e]**2;for(let e=0;e<v;e++)N[e]/=Math.sqrt(P);let F=new Float64Array(t);for(let e=0;e<t;e++)F[e]=(M()<.5?-1:1)*(.5+.5*M());return{key:T(e),geom:n,N:t,ratios:h,wavenum:g,pitchK:_,perm:m,Nnl:v,M:y,tStart:D,ti:O,tj:k,tv:A,tb:S,bx:N,rad:F,shape:(e,t,r)=>n.shape(m[e],t,r)}}const D={violin:{name:`Violin`,low:[[275,22,0],[405,30,-12],[470,40,-8],[460,32,0],[540,32,2]],hill:2600,hillDb:6,top:5500},viola:{name:`Viola`,low:[[230,22,0],[340,30,-12],[390,40,-8],[380,32,0],[445,32,2]],hill:2100,hillDb:5,top:4800},cello:{name:`Cello`,low:[[102,20,0],[145,30,-10],[170,40,-8],[178,30,1],[210,30,2]],hill:1500,hillDb:4,top:3500},bass:{name:`Double bass`,low:[[62,18,0],[92,28,-10],[104,38,-8],[112,30,1],[138,30,2]],hill:900,hillDb:3,top:2400},guitar:{name:`Guitar`,low:[[98,18,0],[204,28,3],[230,35,-6],[390,30,-3],[440,35,-2]],hill:2500,hillDb:2,top:5e3}};function O(e,t,n,r=1){let i=D[e];if(!i)return[];let a=C(r*6151+17),o=[];for(let[e,r,s]of i.low){let i=10**(s/20);o.push({f:e/t,q:r/n,gL:i,gR:i*(.8+.4*a())})}let s=1.2*Math.max(...i.low.map(e=>e[0]));for(;s<4.5*i.top;){let e=Math.log2(s/i.hill),r=-6+i.hillDb*Math.exp(-(e*e)/.72);r-=12*Math.max(0,Math.log2(s/i.top));let c=10**((r+3*w(a))/20),l=10**((r+3*w(a))/20);o.push({f:s/t,q:(20+25*a())/n,gL:c*(a()<.5?-1:1),gR:l*(a()<.5?-1:1)}),s*=1+.07*(.5+a())}return o}function k(e,t){let n=0,r=0,i=0,a=0;for(let o of e){let e=t/o.f,s=1-e*e,c=e/o.q,l=s*s+c*c,u=c*c/l,d=c*s/l;n+=o.gL*u,r+=o.gL*d,i+=o.gR*u,a+=o.gR*d}return .5*(n*n+r*r+i*i+a*a)}var A=class{n=0;b0=/* @__PURE__ */ new Float64Array;a1=/* @__PURE__ */ new Float64Array;a2=/* @__PURE__ */ new Float64Array;gL=/* @__PURE__ */ new Float64Array;gR=/* @__PURE__ */ new Float64Array;x1=0;x2=0;y1=/* @__PURE__ */ new Float64Array;y2=/* @__PURE__ */ new Float64Array;key=``;configure(e,t,n,r){let i=`${e}|${t}|${n}|${r}`;if(i===this.key)return;this.key=i;let a=O(e,t,n).filter(e=>e.f<.45*r),o=0,s=0;if(a.length){let e=.8*a[0].f,t=Math.min(1e4,.45*r);for(let n=0;n<=200;n++)o+=k(a,e*(t/e)**(n/200)),s++}let c=s?1/Math.sqrt(o/s):0,l=a.length,u=this.n!==l;if(this.n=l,u)for(let e of[`b0`,`a1`,`a2`,`gL`,`gR`,`y1`,`y2`])this[e]=new Float64Array(l);a.forEach((e,t)=>{let n=2*Math.PI*e.f/r,i=Math.sin(n)/(2*e.q),a=1+i;this.b0[t]=i/a,this.a1[t]=-2*Math.cos(n)/a,this.a2[t]=(1-i)/a,this.gL[t]=e.gL*c,this.gR[t]=e.gR*c})}reset(){this.x1=this.x2=0,this.y1.fill(0),this.y2.fill(0)}tick(e,t){let n=this.n,r=this.b0,i=this.a1,a=this.a2,o=this.y1,s=this.y2,c=this.gL,l=this.gR,u=e-this.x2;this.x2=this.x1,this.x1=e;let d=0,f=0;for(let e=0;e<n;e++){let t=r[e]*u-i[e]*o[e]-a[e]*s[e];s[e]=o[e],o[e]=t,d+=c[e]*t,f+=l[e]*t}t[0]=d,t[1]=f}};const j=.5,M=1e-14,N=.002,P=.05,F=e=>{let t=Math.abs(e);return t+Math.log1p(Math.exp(-2*t))-Math.LN2},I=6.907755;var L=class{idx;active=!1;note=60;baseHz=261.6;vel=1;gate=!1;held=!1;sustained=!1;touching=!1;damped=!0;order=0;N=0;nAct=0;nNL=0;q=/* @__PURE__ */ new Float64Array;qp=/* @__PURE__ */ new Float64Array;qn=/* @__PURE__ */ new Float64Array;A=/* @__PURE__ */ new Float64Array;B=/* @__PURE__ */ new Float64Array;C=/* @__PURE__ */ new Float64Array;om=/* @__PURE__ */ new Float64Array;sw=/* @__PURE__ */ new Float64Array;grad=/* @__PURE__ */ new Float64Array;pv=/* @__PURE__ */ new Float64Array;gp=/* @__PURE__ */ new Float64Array;phiE=/* @__PURE__ */ new Float64Array;phiB=/* @__PURE__ */ new Float64Array;wL=/* @__PURE__ */ new Float64Array;wR=/* @__PURE__ */ new Float64Array;wsum=0;omega1=1;Z0=1;tunedPitch=-1;tunedDamp=-1;tunedGate=!1;glideMul=1;tunedGlide=1;vibMul=1;tunedVib=1;vibPh=0;vibAge=0;vibRateJ=1;dirtyTune=!0;dirtyVec=!0;posX=-1;posY=-1;ham=!1;hz=0;hzp=0;hzn=0;hamISM=1;hamK=0;hamA=2.5;hamTimer=0;gz=0;buzzK=0;buzzGap=0;buzzPhi1=1;beta=.11;env=0;fLaw=0;nz=0;f=0;fb=/* @__PURE__ */ new Float32Array(32768);fbW=0;bx1=0;bx2=0;by1=0;by2=0;S=0;X=0;Vv=0;useG=!1;pred=!1;energy=0;outMono=0;constructor(e){this.idx=e}alloc(e){let t=t=>{let n=new Float64Array(e);return n.set(t.subarray(0,Math.min(e,t.length))),n};this.q=t(this.q),this.qp=t(this.qp),this.qn=new Float64Array(e);for(let t of[`A`,`B`,`C`,`om`,`sw`,`grad`,`pv`,`gp`,`phiE`,`phiB`,`wL`,`wR`])this[t]=new Float64Array(e);this.N=e,this.dirtyTune=this.dirtyVec=!0}reset(){this.q.fill(0),this.qp.fill(0),this.qn.fill(0),this.ham=!1,this.env=0,this.fLaw=0,this.fb.fill(0),this.bx1=this.bx2=this.by1=this.by2=0,this.energy=0}};const R=e=>440*2**((e-69)/12),z=e=>e<0?0:e>1?1:e,B=e=>e-Math.floor(e);var V=class{sr;h;p={...x};model;voices=[];act=[];eps=M;vMax=0;vHold=0;psi=Math.sqrt(M);psiReset=!1;order=0;bend=0;sustain=!1;lastNote=60;focus=null;touchVoice=null;pending=[];post=()=>{};paramVersion=0;rngS=0x9e3779b9;lfoPh=[0,0];lfoA=[0,0];lfoB=[0,0];kt=0;kc=0;cc=0;ct=0;cl=0;crossOn=!1;buzzA=1.5;buzzTwo=!1;ampMul=1;fbMul=1;excMul=1;pitchMul=1;dampMul=1;posOff=0;pickOff=0;vecVersion=-1;lastPosOff=0;lastPickOff=0;law=0;lwF=0;lwVb=0;lwGam=0;lwD=0;lawK=/* @__PURE__ */ new Float64Array(3);envAtt=0;envRel=0;noiseC=0;noiseNorm=1;fbD=1;fb0=0;fb2=0;fa1=0;fa2=0;snapCount=0;cpuMs=0;cpuWall=0;cpu=0;lastTouch=null;box=new A;boxOut=/* @__PURE__ */ new Float64Array(2);constructor(e){this.sr=e,this.h=1/e,this.model=E(this.p);for(let e=0;e<16;e++){let t=new L(e);t.alloc(this.model.N),this.voices.push(t)}}message(e){e.type===`params`?this.setParams(e.params):this.pending.push(e)}setParams(e){if(this.p={...x,...e},this.paramVersion++,T(this.p)!==this.model.key){this.model=E(this.p);for(let e of this.voices)e.alloc(this.model.N);this.psiReset=!0}for(let e of this.voices)e.dirtyTune=e.dirtyVec=!0;let t=f(this.p,`soundbox`);t===`off`?(this.box.configure(``,1,1,this.sr),this.box.reset()):this.box.configure(t,d(this.p,`boxSize`),d(this.p,`boxDamp`),this.sr)}handle(e){switch(e.type){case`noteOn`:this.noteOn(e.note,e.vel,e.x,e.y);break;case`noteOff`:this.noteOff(e.note);break;case`sustain`:if(this.sustain=e.on,!e.on)for(let e of this.voices)e.sustained&&(e.sustained=!1,this.updateGate(e));break;case`bend`:this.bend=e.value;break;case`touchStart`:this.touchStart(e.x,e.y,e.vel);break;case`touchMove`:this.lastTouch={x:e.x,y:e.y},this.touchVoice&&(this.touchVoice.posX=e.x,this.touchVoice.posY=e.y,this.touchVoice.dirtyVec=!0);break;case`touchEnd`:this.lastTouch=null,this.touchVoice&&=(this.touchVoice.touching=!1,this.updateGate(this.touchVoice),null);break;case`panic`:for(let e of this.voices)e.reset(),e.active=!1;this.box.reset(),this.psi=Math.sqrt(this.eps)}}allocVoice(e){let t=this.voices.find(t=>t.active&&t.note===e);if(t)return t;let n=Math.round(d(this.p,`voices`)),r=this.voices.filter(e=>e.active);return r.length>=n?(r.sort((e,t)=>Number(e.gate)-Number(t.gate)||e.energy-t.energy||e.order-t.order),t=r[0]):t=this.voices.find(e=>!e.active),t.reset(),t.active=!0,t.glideMul=1,t.vibMul=1,t.vibPh=this.rand(),t.vibRateJ=1+.1*(this.rand()*2-1),t.note=e,t.baseHz=R(e),t.held=t.sustained=t.touching=!1,t.gate=!1,t.dirtyTune=t.dirtyVec=!0,t.tunedPitch=-1,this.psiReset=!0,t}updateGate(e){let t=e.held||e.sustained||e.touching;t!==e.gate&&(e.gate=t,e.dirtyTune=!0)}noteOn(e,t,n,r){let i=this.allocVoice(e);i.order=++this.order,i.vel=Math.max(.01,Math.min(1,t)),i.held=!0,i.damped=!0,i.vibAge=0,i.posX=n??-1,i.posY=r??-1,i.dirtyVec=!0,this.updateGate(i),this.lastNote=e,this.focus=i,this.prepare(i),this.excite(i,i.vel)}noteOff(e){for(let t of this.voices)t.active&&t.note===e&&t.held&&(t.held=!1,this.sustain&&(t.sustained=!0),this.updateGate(t))}touchStart(e,t,n){this.lastTouch={x:e,y:t};let r=this.focus&&this.focus.active?this.focus:null;r||(r=this.allocVoice(this.lastNote),r.order=++this.order,r.damped=!1,this.focus=r),r.posX=e,r.posY=t,r.vel=n,r.dirtyVec=!0;let i=this.law!==0;i&&(r.touching=!0,this.touchVoice=r,this.updateGate(r)),this.prepare(r),i||this.excite(r,n)}prepare(e){e.dirtyVec&&this.vecVoice(e),(e.dirtyTune||e.tunedPitch!==this.pitchMul||e.tunedDamp!==this.dampMul||e.tunedGate!==e.gate||e.tunedGlide!==e.glideMul||e.tunedVib!==e.vibMul)&&this.tuneVoice(e)}excite(e,t){let n=f(this.p,`exciter`),r=j*(d(this.p,`strength`)*t)**2;if(r<=0)return;let i=e.nAct,a=e.phiE,o=e.om,s=this.h;if(n===`strike`){let t=d(this.p,`hammerMass`),n=d(this.p,`hardness`)/1e3,o=d(this.p,`feltExp`),c=Math.sqrt(2*r/t),l=Math.sqrt(2*j/t)*n/Math.PI,u=0,f=0;for(let t=0;t<i;t++)u+=a[t]*e.q[t],f+=a[t]*(e.q[t]-e.qp[t])/s;let p=Math.sqrt(t);e.ham=!0,e.hamTimer=0,e.hamISM=1/p,e.hamK=t*(Math.PI/n)**2/l**(o-1),e.hamA=o,e.hz=u*p,e.hzp=(u-(f+c)*s)*p}else if(n===`pluck`){let t=0;for(let e=0;e<i;e++)t+=a[e]*a[e]/(o[e]*o[e]);if(t<=0)return;let n=Math.sqrt(2*r/t);for(let t=0;t<i;t++){let r=n*a[t]/(o[t]*o[t]);e.q[t]+=r,e.qp[t]+=r}this.psiReset=!0}else if(n===`impulse`){let t=d(this.p,`hardness`)/1e3,n=0,c=e.qn;for(let e=0;e<i;e++){let r=o[e]*t/2,i=1-(r/Math.PI)**2,s=r<1e-9?1:Math.abs(i)<1e-6?.5:Math.abs(Math.sin(r)/r/i);c[e]=a[e]*s,n+=c[e]*c[e]}if(n<=0)return;let l=Math.sqrt(2*r/n);for(let t=0;t<i;t++)e.qp[t]-=s*l*c[t];c.fill(0)}}tuneVoice(e){let t=this.model,n=t.N,r=this.h,i=this.p,a=e.baseHz*this.pitchMul*e.glideMul*e.vibMul,o=I/d(i,`t60`),s=d(i,`hfDamp`),c=d(i,`damper`),l=!e.gate&&e.damped&&c<19.9?I/c:0,u=.45*this.sr,f=0,p=0;for(let i=0;i<n;i++){let n=a*t.ratios[i],c=2*Math.PI*n;if(e.om[i]=c,n>=u){e.A[i]=e.B[i]=e.C[i]=e.sw[i]=0;continue}f=i+1;let d=(o+s*(n/1e3)**2)*this.dampMul+l,m=Math.exp(-d*r);if(d<c)e.A[i]=2*m*Math.cos(Math.sqrt(c*c-d*d)*r);else{let t=Math.sqrt(d*d-c*c)*r;e.A[i]=m*(Math.exp(t)+Math.exp(-t))}e.B[i]=m*m,e.C[i]=r*r/(1+Math.tanh(d*r));let h=2-2*Math.cos(c*r),g=Math.max(0,Math.min(1,(3.6/h-1)/12));e.sw[i]=c*Math.sqrt(g),g>0&&(p=i+1)}for(let t=f;t<n;t++)e.q[t]=e.qp[t]=0;e.nAct=f,e.nNL=Math.min(p,f),e.omega1=2*Math.PI*a,e.Z0=2*a;let m=0;for(let t=0;t<f;t++)m+=e.phiE[t]*e.phiE[t]*e.C[t];e.wsum=m;let h=+Math.max(e.buzzPhi1,.05)/e.omega1,g=d(i,`buzz`);e.buzzGap=d(i,`buzzGap`)*h,e.buzzK=g>0?g*(2*Math.PI*4e3)**2*.1*h**(1-this.buzzA):0,e.tunedPitch=this.pitchMul,e.tunedDamp=this.dampMul,e.tunedGate=e.gate,e.tunedGlide=e.glideMul,e.tunedVib=e.vibMul,e.dirtyTune=!1}vecVoice(e){let t=this.model,n=t.N,r=this.p,i=e.posX>=0?e.posX:z(d(r,`exPos`)+this.posOff),a=e.posY>=0?e.posY:z(d(r,`exPosY`)+this.posOff),o=d(r,`exWidth`)*.15,s=d(r,`buzzPos`),c=d(r,`buzzPosY`),l=B(d(r,`pickup`)+this.pickOff),u=d(r,`pickupY`),f=d(r,`width`),p=B(l+.5*f),m=B(u+.37*f),h=d(r,`spread`),g=d(r,`tilt`)/6.0206;for(let r=0;r<n;r++){let d=Math.exp(-.5*(Math.PI*t.wavenum[r]*o)**2);e.phiE[r]=t.shape(r,i,a)*d,e.phiB[r]=t.shape(r,s,c);let f=t.ratios[r]**+g;e.wL[r]=((1-h)*t.shape(r,l,u)+h*t.rad[r])*f,e.wR[r]=((1-h)*t.shape(r,p,m)+h*t.rad[(r+1)%n]*(r%2?1:-1))*f}e.buzzPhi1=Math.abs(t.shape(t.pitchK,s,c)),e.beta=Math.max(.02,Math.min(i,1-i)),e.dirtyVec=!1,e.dirtyTune=!0}rand(){let e=this.rngS;return e^=e<<13,e^=e>>>17,e^=e<<5,this.rngS=e>>>0,this.rngS/4294967296}lfo(e,t){let n=this.p,r=d(n,`lfo${e+1}Rate`),i=this.lfoPh[e]+r*t;switch(i>=1&&(i-=Math.floor(i),this.lfoA[e]=this.lfoB[e],this.lfoB[e]=this.rand()*2-1),this.lfoPh[e]=i,f(n,`lfo${e+1}Shape`)){case`tri`:return 1-4*Math.abs(i-.5);case`saw`:return 2*i-1;case`square`:return i<.5?1:-1;case`sh`:return this.lfoB[e];case`smooth`:return this.lfoA[e]+(this.lfoB[e]-this.lfoA[e])*(.5-.5*Math.cos(Math.PI*i));default:return Math.sin(2*Math.PI*i)}}blockUpdate(e){let t=this.p,n=this.sr,r=e/n,i=this.bend*d(t,`bendRange`),a=1,o=0,s=0,c=d(t,`tension`),l=d(t,`cascade`),u=1,p=1,m=1;for(let e=0;e<2;e++){let n=f(t,`lfo${e+1}Target`);if(n===`off`)continue;let h=d(t,`lfo${e+1}Depth`),g=this.lfo(e,r)*h;switch(n){case`pitch`:i+=4*g;break;case`amp`:a*=Math.max(0,1+g);break;case`position`:o+=.5*g;break;case`pickup`:s+=.5*g;break;case`tension`:c*=Math.max(0,1+g);break;case`cascade`:l*=Math.max(0,1+g);break;case`damping`:u*=2**(3*g);break;case`feedback`:p*=Math.max(0,1+g);break;case`exciter`:m*=Math.max(0,1+g)}}this.pitchMul=2**(i/12),this.dampMul=u,this.ampMul=a,this.fbMul=p,this.excMul=m,this.kt=c,this.kc=this.model.M>0?l:0,this.cc=+d(t,`curvature`),this.ct=d(t,`crossTension`),this.cl=d(t,`crossLink`),this.crossOn=this.ct>0||this.cl>0,this.buzzTwo=f(t,`buzzSides`)===`two`;let h=f(t,`exciter`);this.law=h===`bow`?1:h===`reed`?2:h===`selfosc`?3:h===`noise`?4:0;let g=this.lawK;this.law===1?(g[0]=d(t,`bowSpeed`)*.5,g[1]=+d(t,`bowForce`),g[2]=d(t,`bowNoise`)):this.law===2?(g[0]=d(t,`reedGain`)*2,g[1]=d(t,`reedPressure`),g[2]=d(t,`breath`)):this.law===3&&(g[0]=+d(t,`selfGain`),g[1]=d(t,`selfSat`)),this.envAtt=1-Math.exp(-1/(d(t,`attack`)/1e3*n)),this.envRel=1-Math.exp(-1/(d(t,`release`)/1e3*n));let _=Math.min(d(t,`noiseColor`),.45*n);this.noiseC=1-Math.exp(-2*Math.PI*_/n),this.noiseNorm=Math.sqrt(3*(2-this.noiseC)/this.noiseC),this.fbD=Math.max(1,Math.min(32767,Math.round(d(t,`fbDelay`)/1e3*n)));let v=2*Math.PI*Math.min(d(t,`fbFreq`),.45*n)/n,y=Math.sin(v)/(2*d(t,`fbQ`)),b=1+y;this.fb0=y/b,this.fb2=-y/b,this.fa1=-2*Math.cos(v)/b,this.fa2=(1-y)/b;let x=o!==this.lastPosOff||s!==this.lastPickOff||this.vecVersion!==this.paramVersion;this.posOff=o,this.pickOff=s,this.lastPosOff=o,this.lastPickOff=s,this.vecVersion=this.paramVersion;let S=d(t,`vibDepth`),C=d(t,`vibRate`),w=d(t,`vibDelay`)/1e3;this.act.length=0;for(let e of this.voices)if(e.active){if(S>0){e.vibAge+=r;let t=e.vibAge,n=w>0?(t-.3*w)/(.7*w):1;n=n<0?0:n>1?1:n*n*(3-2*n),e.vibPh+=C*e.vibRateJ*(1+.06*Math.sin(2.3*t+7*e.vibRateJ))*r,e.vibPh-=Math.floor(e.vibPh);let i=2**(S*n*Math.sin(2*Math.PI*e.vibPh)/1200);(Math.abs(i/e.vibMul-1)>1e-5||n===0&&e.vibMul!==1)&&(e.vibMul=i)}else e.vibMul=1;x&&(e.dirtyVec=!0),this.prepare(e),this.act.push(e)}}nl(e){if(this.kt<=0&&this.ct<=0&&this.kc<=0&&!this.crossOn&&!e.ham&&e.buzzK<=0){e.S=e.X=e.Vv=e.gz=0,e.useG=!1;return}let t=e.nAct,n=e.q,r=e.sw,i=e.grad,a=this.model,o=0,s=!1,c=e.nNL,l=0;if(this.kt>0||this.ct>0||this.kc>0)for(let e=0;e<c;e++){let t=r[e]*n[e];l+=t*t}if(e.S=l,i.fill(0,0,t),e.gz=0,this.kt>0&&l>0){let e=3/this.kt,t=l/j;o+=this.kt*j*.5*e*e*F(t/e);let a=this.kt*e*Math.tanh(t/e);for(let e=0;e<c;e++)i[e]+=a*r[e]*r[e]*n[e];s=!0}let u=this.kc;if(u>0){let t=a.Nnl,l=Math.min(c,t),d=e.pv,f=e.gp,p=this.cc,m=3/(u*a.M);for(let e=0;e<t;e++)d[e]=e<l?r[e]*n[e]:0,f[e]=0;let h=a.ti,g=a.tj,_=a.tv,v=a.tb;for(let e=0;e<a.M;e++){let n=a.tStart[e],r=a.tStart[e+1],i=0;for(let e=n;e<r;e++)i+=_[e]*d[h[e]]*d[g[e]];let s=0,c=e*t;if(p!==0)for(let e=0;e<l;e++)s+=v[c+e]*d[e];let y=(i+p*s)/j;o+=u*j*m*m*F(y/m);let b=u*m*Math.tanh(y/m),x=2*b;for(let e=n;e<r;e++)f[h[e]]+=x*_[e]*d[g[e]];let S=b*p;if(S!==0)for(let e=0;e<l;e++)f[e]+=S*v[c+e]}for(let e=0;e<l;e++)i[e]+=r[e]*f[e];s=!0}if(e.ham){let r=e.phiE,a=0;for(let e=0;e<t;e++)a+=r[e]*n[e];let c=e.hz*e.hamISM-a;if(c>0){let n=e.hamA,a=e.hamK*c**+n;o+=a*c/(n+1);for(let e=0;e<t;e++)i[e]-=a*r[e];e.gz=a*e.hamISM,e.hamTimer=0,s=!0}else++e.hamTimer>.05*this.sr&&(e.ham=!1)}if(e.buzzK>0){let r=e.phiB,a=0;for(let e=0;e<t;e++)a+=r[e]*n[e];let c=this.buzzA,l=0,u=a-e.buzzGap;if(u>0){let t=e.buzzK*u**+c;o+=t*u/(c+1),l+=t}if(this.buzzTwo){let t=-a-e.buzzGap;if(t>0){let n=e.buzzK*t**+c;o+=n*t/(c+1),l-=n}}if(l!==0){for(let e=0;e<t;e++)i[e]+=l*r[e];s=!0}}if(this.crossOn){let t=0,r=Math.min(c,a.Nnl),i=a.bx;if(this.cl>0)for(let a=0;a<r;a++)t+=i[a]*e.sw[a]*n[a];e.X=.5*this.ct*l+this.cl*1*t}else e.X=0;e.Vv=o,e.useG=s||this.crossOn}lawEval(e){let t=0,n=0;if(this.law===1){let r=e-this.lwVb,i=Math.tanh(r/N),a=1+Math.abs(r)/P,o=.35+.65/a,s=-.65/(P*a*a)*(r>=0?1:-1);t=-this.lwF*i*o,n=-this.lwF*((1-i*i)/N*o+i*s)}else if(this.law===2){let r=this.lwGam-e;if(r<1){let e=Math.sqrt(Math.abs(r)+1e-9),i=this.lwF;r>=0?(t=i*(1-r)*e,n=-i*(-e+(1-r)/(2*e))):(t=-i*(1-r)*e,n=-i*(e+(1-r)/(2*e)))}}else{let r=this.lwF,i=this.lwVb;t=r*(e-e*e*e/(3*i*i)),n=r*(1-e*e/(i*i))}return this.lwD=n,t}solveLaw(e,t,n){let r=e.nAct,i=e.phiE,a=e.A,o=e.B,s=e.q,c=e.qp,l=e.qn,u=0;for(let e=0;e<r;e++){let t=a[e]*s[e]-o[e]*c[e];l[e]=t,u+=i[e]*(t-c[e])}e.pred=!0;let d=.5/this.h,f=(u+t*e.wsum)*d,p=e.wsum*d,m=e.env*this.excMul,h=e.Z0,g=this.lawK;if(this.law===1){this.lwVb=g[0]*m;let t=g[2];this.lwF=g[1]*h*(this.lwVb/.05)*(.11/e.beta)*(t>0?Math.max(0,1+t*n):1)}else this.law===2?(this.lwF=g[0]*h,this.lwGam=g[1]*m*(1+g[2]*n)):(this.lwF=g[0]*h*m,this.lwVb=g[1]);let _=this.lwF+1e-9,v=1e-9*_,y=e.fLaw,b=!1;for(let e=0;e<8;e++){let e=y-this.lawEval(f+p*y);if(Math.abs(e)<v){b=!0;break}let t=1-p*this.lwD;if(t<.05)break;y-=e/t}if(!b||!Number.isFinite(y)){let t=Number.isFinite(e.fLaw)?e.fLaw:0,n=.01*_,r=t,i=t,a=0,o=0;for(let e=0;e<60&&(r=t-n,i=t+n,a=r-this.lawEval(f+p*r),o=i-this.lawEval(f+p*i),!(a<=0&&o>=0));e++)n*=2;for(let e=0;e<50;e++){let e=.5*(r+i);e-this.lawEval(f+p*e)<0?r=e:i=e}y=.5*(r+i),Number.isFinite(y)||(y=0)}return e.fLaw=y,y}process(e,t,n,r=0){let i=Date.now(),a=n/this.sr;if(this.pending.length){let e=[];for(let t of this.pending)(`time`in t&&t.time!==void 0?t.time:0)<=r+a?this.handle(t):e.push(t);this.pending=e}this.blockUpdate(n);let o=this.act,s=this.h,c=s*s,l=1/s,u=this.p,f=d(u,`fbGain`)*this.fbMul,p=d(u,`fbSat`),m=d(u,`noiseLevel`),h=this.law,g=h===4||h===3||h===2&&d(u,`breath`)>0||h===1&&d(u,`bowNoise`)>0,_=this.box,v=_.n>0,y=v?d(u,`boxMix`):0,b=1-y,x=this.boxOut,S=.25*this.ampMul*l*10**(d(u,`level`)/20),C=32767;for(let r=0;r<n;r++){let n=0,i=0,a=!1;for(let e=0;e<o.length;e++){let t=o[e];t.env+=((t.gate?t.vel:0)-t.env)*(t.gate?this.envAtt:this.envRel);let r=0;if(t.env>1e-6){let e=0;if(g&&(t.nz+=this.noiseC*(this.rand()*2-1-t.nz),e=t.nz*this.noiseNorm),f>0){let e=t.fb[t.fbW-this.fbD&C],n=this.fb0*e+this.fb2*t.bx2-this.fa1*t.by1-this.fa2*t.by2;t.bx2=t.bx1,t.bx1=e,t.by2=t.by1,t.by1=n,r+=p*t.Z0*Math.tanh(f*n/p)*t.env}h===3&&(r+=.001*t.Z0*t.env*e),h===4?r+=m*t.Z0*t.env*this.excMul*e*.5:h!==0&&(r+=this.solveLaw(t,r,e))}else t.fLaw=0;t.f=r,this.nl(t),n+=t.Vv,i+=t.X,t.useG&&(a=!0)}if(this.crossOn&&o.length){let e=i/j;n+=j*3*3*F(e/3);let t=3*Math.tanh(e/3),r=this.ct,a=+this.cl,s=this.model.bx,c=this.model.Nnl;for(let e of o){let n=e.nNL,i=e.grad,o=e.q,l=e.sw;for(let e=0;e<n;e++)i[e]+=t*(r*l[e]*l[e]*o[e]+(e<c?a*s[e]*l[e]:0))}}if(a){n>this.vMax&&(this.vMax=n),this.psiReset&&(this.eps=.01);let e=Math.sqrt(2*n+this.eps),t=1/e;if(this.psiReset)this.psi=e,this.psiReset=!1;else{let t=this.psi+.01*(e-this.psi);Math.abs(t)<Math.abs(this.psi)&&(this.psi=t)}let r=0;for(let e of o){if(!e.useG)continue;let t=e.nAct,n=e.grad,i=e.qp;for(let e=0;e<t;e++)r+=n[e]*i[e];e.ham&&(r+=e.gz*e.hzp)}r*=t;let i=this.psi,a=r/4,s=0,l=0;for(let e of o){if(!e.useG){this.linearStep(e);continue}e.pred=!1;let n=e.nAct,r=e.grad,o=e.q,u=e.qp,d=e.qn,f=e.A,p=e.B,m=e.C,h=e.phiE,g=e.f;for(let e=0;e<n;e++){let n=r[e]*t,c=f[e]*o[e]-p[e]*u[e]+m[e]*(h[e]*g+n*(a-i));d[e]=c,s+=n*c,l+=m[e]*n*n}if(e.ham){let n=e.gz*t,r=2*e.hz-e.hzp+c*n*(a-i);e.hzn=r,s+=n*r,l+=c*n*n}}let u=s/(1+l/4),d=u*t/4;for(let e of o){if(!e.useG)continue;let t=e.nAct,n=e.grad,r=e.qn,i=e.C;for(let e=0;e<t;e++)r[e]-=i[e]*n[e]*d;e.ham&&(e.hzn-=c*e.gz*d)}this.psi=i+(u-r)/2}else{for(let e of o)this.linearStep(e);this.psi=Math.sqrt(this.eps)}let s=0,u=0;for(let e of o){let t=e.nAct,n=e.q,r=e.qn,i=e.wL,a=e.wR,o=0,c=0;for(let e=0;e<t;e++){let t=r[e]-n[e];o+=i[e]*t,c+=a[e]*t}s+=o,u+=c,e.fb[e.fbW]=.5*(o+c)*l,e.fbW=e.fbW+1&C;let d=e.qp;e.qp=e.q,e.q=e.qn,e.qn=d,e.ham&&(e.hzp=e.hz,e.hz=e.hzn)}v?(_.tick(.5*(s+u)*S,x),e[r]=b*s*S+y*x[0],t[r]=b*u*S+y*x[1]):(e[r]=s*S,t[r]=u*S)}this.blockEnd(n),this.cpuMs+=Date.now()-i,this.cpuWall+=a*1e3}linearStep(e){let t=e.nAct,n=e.q,r=e.qp,i=e.qn,a=e.A,o=e.B,s=e.C,c=e.phiE,l=e.f;if(e.pred){if(e.pred=!1,l!==0)for(let e=0;e<t;e++)i[e]+=s[e]*c[e]*l}else if(l!==0)for(let e=0;e<t;e++)i[e]=a[e]*n[e]-o[e]*r[e]+s[e]*c[e]*l;else for(let e=0;e<t;e++)i[e]=a[e]*n[e]-o[e]*r[e];e.ham&&(e.hzn=2*e.hz-e.hzp)}blockEnd(e){let t=1/this.h;for(let e of this.act){let n=e.nAct,r=e.q,i=e.qp,a=e.om,o=0;for(let e=0;e<n;e++){let n=(r[e]-i[e])*t;o+=.5*(n*n+a[e]*a[e]*r[e]*r[e])}if(!Number.isFinite(o)||o>1e8){e.reset(),e.active=!1,this.psiReset=!0;continue}e.energy=o;let s=d(this.p,`glide`),c=1;if(s!==0){let e=4*o/j;c=2**(s*e/(1+e)/12)}(Math.abs(c/e.glideMul-1)>2e-5||c===1&&e.glideMul!==1)&&(e.glideMul=c),!e.gate&&!e.ham&&o<1e-10&&e.env<1e-4&&(e.active=!1)}let n=0;for(let e of this.act)e.active&&(n+=e.energy);this.vHold=Math.max(this.vMax,this.vHold*.95),this.vMax=0;let r=Math.max(M,.02*n+2*this.vHold);if(r<this.eps){let e=Math.max(r,this.eps*.95),t=this.psi*this.psi-(this.eps-e);this.psi=(this.psi<0?-1:1)*Math.sqrt(Math.max(0,t)),this.eps=e}this.snapCount+=e,this.snapCount>=this.sr/30&&(this.snapCount=0,this.cpuWall>0&&(this.cpu=this.cpuMs/this.cpuWall),this.cpuMs=this.cpuWall=0,this.snapshot())}snapshot(){let e=this.focus&&this.focus.active?this.focus:null;if(!e)for(let t of this.voices)t.active&&(!e||t.order>e.order)&&(e=t);let t=this.model.N,n=new Float32Array(t),r=new Float32Array(t),i=new Float32Array(t),a=new Float32Array(t);if(e){let o=1/this.h;for(let s=0;s<t;s++){n[s]=e.q[s];let t=(e.q[s]-e.qp[s])*o;r[s]=t,i[s]=.5*(t*t+e.om[s]*e.om[s]*e.q[s]*e.q[s]),a[s]=e.om[s]/(2*Math.PI)}}let o=[];for(let e of this.voices)e.active&&o.push(e.note);let s={type:`snap`,cpu:this.cpu,nVoices:o.length,notes:o,focusNote:e?e.note:-1,focusHz:e?e.baseHz*this.pitchMul:0,nAct:e?e.nAct:0,q:n,qd:r,energy:i,freqs:a,touch:this.lastTouch};this.post(s,[n.buffer,r.buffer,i.buffer,a.buffer])}},H=class extends AudioWorkletProcessor{synth=new V(sampleRate);constructor(){super(),this.port.onmessage=e=>this.synth.message(e.data),this.synth.post=(e,t)=>this.port.postMessage(e,t)}process(e,t){let n=t[0],r=n[0],i=n[1]??n[0];return this.synth.process(r,i,r.length,currentTime),!0}};registerProcessor(`modal-synth`,H);
↑↓ move↵openescclose