/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / site / assets / index-D9r0IF3O.js
2 lines · 87.8 KBCodeBlameHistory
75ca48aOverhaul playback: background-computed, buffered, one clockJeremy Magland 1(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=48e3,t=null;async function n(){if(!t){let n;try{n=new AudioContext({latencyHint:`playback`,sampleRate:e})}catch{n=new AudioContext({latencyHint:`playback`})}let r=n.createGain(),i=n.createDynamicsCompressor();i.threshold.value=-6,i.knee.value=6,i.ratio.value=12,i.attack.value=.003,i.release.value=.25,r.connect(i).connect(n.destination),t={ctx:n,input:r}}return t.ctx.state!==`running`&&await t.ctx.resume(),t}function r(e){return 10**(e/20)}function i(e){let t={};for(let n of e)t[n.key]=n.default;return t}function a(e,...t){let n=i(e);for(let r of t)if(r)for(let t of e){let e=r[t.key];e!==void 0&&(t.kind===`number`&&typeof e==`number`&&Number.isFinite(e)||t.kind===`select`&&typeof e==`string`&&t.options.includes(e)||t.kind===`bool`&&typeof e==`boolean`||t.kind===`text`&&typeof e==`string`)&&(n[t.key]=e)}return n}function o(e,t){let n={};for(let r of e)n[r.key]=t[r.key];return JSON.stringify(n,null,2)+`
2`}var s=1e3;function c(e,t){let n=e.log?Math.log(t/e.min)/Math.log(e.max/e.min):(t-e.min)/(e.max-e.min);return Math.round(Math.max(0,Math.min(1,n))*s)}function l(e,t){let n=t/s,r=e.log?e.min*(e.max/e.min)**+n:e.min+n*(e.max-e.min);return e.step&&(r=Math.round(r/e.step)*e.step),Number(r.toPrecision(4))}function u(e){return String(Number(e.toPrecision(4)))}function d(e,t={},...n){let r=Object.assign(document.createElement(e),t);return r.append(...n),r}function f(e){let t=d(`aside`,{className:`author`}),n=[],r=(t,n)=>{e.set({...e.get(),[t]:n})},i=d(`span`,{className:`status`}),f=e=>{i.textContent=e,window.setTimeout(()=>{i.textContent===e&&(i.textContent=``)},2e3)},p=d(`button`,{textContent:`copy config`});p.onclick=async()=>{let t=o(e.schema,e.get());try{await navigator.clipboard.writeText(t),f(`copied`)}catch{window.prompt(`copy:`,t)}};let m=d(`button`,{textContent:`paste config`});m.onclick=async()=>{let t=null;try{t=await navigator.clipboard.readText()}catch{t=window.prompt(`paste config JSON:`)}if(t)try{e.set(a(e.schema,JSON.parse(t))),y(),f(`pasted`)}catch{f(`not valid JSON`)}};let h=d(`button`,{textContent:`reset to defaults`});h.onclick=()=>{window.confirm(`Discard your edits and return to the published defaults?`)&&(e.set(e.defaults()),y())},t.append(d(`div`,{className:`actions`},p,m,h,i));let g=d(`input`,{type:`number`,min:`0`,step:`1`,value:String(e.startAt.value)});g.oninput=()=>{e.startAt.value=Math.max(0,Number(g.value)||0)},t.append(d(`label`,{className:`row`},d(`span`,{textContent:`start at (s)`}),g));let _=d(`dl`,{className:`readouts`});t.append(_);let v=new Map;for(let i of e.schema){let a=v.get(i.group);a||(a=d(`fieldset`,{},d(`legend`,{textContent:i.group})),v.set(i.group,a),t.append(a));let o=d(`label`,{className:`row`},d(`span`,{textContent:i.label,title:i.hint??``}));if(i.kind===`number`){let t=d(`input`,{type:`range`,min:`0`,max:String(s),step:`1`}),a=d(`input`,{type:`number`,step:`any`}),f=d(`span`,{className:`unit`,textContent:i.unit??``});t.oninput=()=>{let e=l(i,Number(t.value));a.value=u(e),r(i.key,e)},a.onchange=()=>{let e=Number(a.value);Number.isFinite(e)&&(t.value=String(c(i,e)),r(i.key,e))},n.push(()=>{let n=e.get()[i.key];t.value=String(c(i,n)),a.value=u(n)}),o.append(t,a,f)}else if(i.kind===`select`){let t=d(`select`);for(let e of i.options)t.append(d(`option`,{value:e,textContent:e}));t.onchange=()=>r(i.key,t.value),n.push(()=>t.value=e.get()[i.key]),o.append(t)}else if(i.kind===`text`){let t=d(`textarea`,{rows:3,spellcheck:!1,placeholder:i.hint??``});t.onchange=()=>r(i.key,t.value),n.push(()=>t.value=e.get()[i.key]),o.classList.add(`text`),o.append(t)}else{let t=d(`input`,{type:`checkbox`});t.onchange=()=>r(i.key,t.checked),n.push(()=>t.checked=e.get()[i.key]),o.append(t)}a.append(o)}function y(){for(let e of n)e()}function b(){let t=e.readouts();_.replaceChildren(...Object.entries(t).flatMap(([e,t])=>[d(`dt`,{textContent:e}),d(`dd`,{textContent:t})]))}return y(),b(),{el:t,sync:y,updateReadouts:b}}function p(){return 1+Math.floor(Math.random()*999999)}var m=(e,t)=>e[t],h=e=>e.geometry===`membrane`||e.geometry===`plate`||e.geometry===`disc`,g=(...e)=>t=>e.includes(t.geometry),_=(...e)=>t=>e.includes(t.exciter),v=[`bow`,`reed`,`selfosc`,`noise`],y=[[`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`]],b=[[`sine`,`Sine`],[`tri`,`Triangle`],[`saw`,`Saw`],[`square`,`Square`],[`sh`,`Sample & hold`],[`smooth`,`Smooth random`]];function x(e){let t=t=>t[`lfo${e}Target`]!==`off`;return[{kind:`enum`,id:`lfo${e}Target`,label:`LFO ${e} →`,group:`Modulation`,options:y,def:`off`},{kind:`enum`,id:`lfo${e}Shape`,label:`Shape`,group:`Modulation`,options:b,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}]}var S=[{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:g(`plate`)},{kind:`num`,id:`powerExp`,label:`Exponent p`,group:`Body`,min:.3,max:3,def:1.5,model:!0,show:g(`free`)},{kind:`num`,id:`discExp`,label:`Chladni exponent`,group:`Body`,min:1,max:2.5,def:2,model:!0,show:g(`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&&h(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:h},{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:_(`strike`)},{kind:`num`,id:`hardness`,label:`Contact time`,group:`Exciter`,min:.05,max:20,def:1,scale:`log`,unit:`ms`,show:_(`strike`,`impulse`)},{kind:`num`,id:`feltExp`,label:`Felt exponent`,group:`Exciter`,min:1,max:4,def:2.5,show:_(`strike`)},{kind:`num`,id:`bowForce`,label:`Bow force`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:_(`bow`)},{kind:`num`,id:`bowSpeed`,label:`Bow speed`,group:`Exciter`,min:0,max:2,def:.4,scale:`pow2`,show:_(`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:_(`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:_(`reed`)},{kind:`num`,id:`reedGain`,label:`Reed opening`,group:`Exciter`,min:0,max:2,def:.5,show:_(`reed`)},{kind:`num`,id:`breath`,label:`Breath noise`,group:`Exciter`,min:0,max:1,def:.05,scale:`pow2`,show:_(`reed`)},{kind:`num`,id:`selfGain`,label:`Negative damping`,group:`Exciter`,min:0,max:4,def:.5,scale:`pow2`,show:_(`selfosc`)},{kind:`num`,id:`selfSat`,label:`Saturation level`,group:`Exciter`,min:.02,max:4,def:.5,scale:`log`,show:_(`selfosc`)},{kind:`num`,id:`noiseLevel`,label:`Noise level`,group:`Exciter`,min:0,max:4,def:1,scale:`pow2`,show:_(`noise`)},{kind:`num`,id:`noiseColor`,label:`Noise cutoff`,group:`Exciter`,min:50,max:16e3,def:3e3,scale:`log`,unit:`Hz`,show:_(`noise`,`reed`,`bow`)},{kind:`num`,id:`attack`,label:`Attack`,group:`Exciter`,min:1,max:3e3,def:40,scale:`log`,unit:`ms`,show:_(...v)},{kind:`num`,id:`release`,label:`Release`,group:`Exciter`,min:5,max:5e3,def:150,scale:`log`,unit:`ms`,show:_(...v)},{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},...x(1),...x(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:h},{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(S.map(e=>[e.id,e]));var C=Object.fromEntries(S.map(e=>[e.id,e.def]));S.filter(e=>e.model).map(e=>e.id);var w=class{ctx;input;analyser;scope;shaper;dry;delaySend;dL;dR;fbL;fbR;revSend;conv;master;lastDrive=-1;lastSize=-1;sizeTimer;constructor(e,t=e.destination){this.ctx=e,this.input=e.createGain(),this.analyser=e.createAnalyser(),this.analyser.fftSize=8192,this.analyser.smoothingTimeConstant=0,this.analyser.minDecibels=-120,this.analyser.maxDecibels=-10,this.scope=e.createAnalyser(),this.scope.fftSize=4096,this.input.connect(this.analyser),this.input.connect(this.scope),this.shaper=e.createWaveShaper(),this.shaper.oversample=`4x`,this.dry=e.createGain(),this.master=e.createGain(),this.input.connect(this.shaper),this.shaper.connect(this.dry),this.dry.connect(this.master),this.delaySend=e.createGain();let n=e.createChannelSplitter(2),r=e.createChannelMerger(2);this.dL=e.createDelay(2),this.dR=e.createDelay(2),this.fbL=e.createGain(),this.fbR=e.createGain(),this.shaper.connect(this.delaySend),this.delaySend.connect(n),n.connect(this.dL,0),n.connect(this.dR,1),this.dL.connect(this.fbL),this.fbL.connect(this.dR),this.dR.connect(this.fbR),this.fbR.connect(this.dL),this.dL.connect(r,0,0),this.dR.connect(r,0,1),r.connect(this.master),this.revSend=e.createGain(),this.conv=e.createConvolver(),this.shaper.connect(this.revSend),this.revSend.connect(this.conv),this.conv.connect(this.master);let i=e.createDynamicsCompressor();i.threshold.value=-3,i.knee.value=3,i.ratio.value=20,i.attack.value=.002,i.release.value=.15,this.master.connect(i),i.connect(t)}set(e){let t=this.ctx.currentTime,n=(e,n)=>e.setTargetAtTime(n,t,.02),r=m(e,`drive`);if(r!==this.lastDrive){if(this.lastDrive=r,r<=0)this.shaper.curve=null;else{let e=1+40*r*r,t=2048,n=new Float32Array(t);for(let r=0;r<t;r++){let t=r/2047*2-1;n[r]=Math.tanh(e*t)/Math.tanh(e)}this.shaper.curve=n}}let i=m(e,`delayMix`);n(this.delaySend.gain,i);let a=m(e,`delayTime`)/1e3;n(this.dL.delayTime,a),n(this.dR.delayTime,a),n(this.fbL.gain,m(e,`delayFb`)),n(this.fbR.gain,m(e,`delayFb`));let o=m(e,`reverbMix`);n(this.revSend.gain,o),n(this.dry.gain,r>0?1/(1+2*r):1),n(this.master.gain,10**(m(e,`volume`)/20));let s=m(e,`reverbSize`);s!==this.lastSize&&(this.lastSize=s,clearTimeout(this.sizeTimer),this.sizeTimer=window.setTimeout(()=>this.conv.buffer=this.makeIR(s),150))}makeIR(e){let t=this.ctx.sampleRate,n=Math.round(t*Math.min(e*1.1,12)),r=this.ctx.createBuffer(2,n,t);for(let i=0;i<2;i++){let a=r.getChannelData(i),o=0;for(let r=0;r<n;r++){let n=r/t,i=9e3*Math.exp(-n/(.6*e))+400,s=1-Math.exp(-2*Math.PI*i/t);o+=s*(Math.random()*2-1-o);let c=Math.exp(-6.9*n/e)*Math.min(1,n/.004);a[r]=o*c*.5}}return r}};function T(e,t,n,r,i){if(!r){t.connect(n);return}if(i===`own`){let i=new w(e,n);t.connect(i.input),i.set(r);return}let a=e.createGain();if(a.gain.value=10**(r.volume/20),t.connect(a).connect(n),i!==`none`){let n=e.createGain();n.gain.value=r.reverbMix*a.gain.value,t.connect(n).connect(i.send)}}var E=class{input;conv;constructor(e,t,n){this.input=e.createGain(),this.conv=e.createConvolver(),this.conv.buffer=D(e,n),this.input.connect(this.conv).connect(t)}dispose(){this.input.disconnect(),this.conv.disconnect()}};function D(e,t){let n=e.sampleRate,r=Math.round(n*Math.min(t*1.1,12)),i=e.createBuffer(2,r,n);for(let e=0;e<2;e++){let a=i.getChannelData(e),o=0;for(let e=0;e<r;e++){let r=e/n,i=9e3*Math.exp(-r/(.6*t))+400,s=1-Math.exp(-2*Math.PI*i/n);o+=s*(Math.random()*2-1-o),a[e]=o*Math.exp(-6.9*r/t)*Math.min(1,r/.004)*.5}}return i}var O=class{tracks=new Map;events=[];infos=[];add(e,t,n){if(!n.length)return;let r=this.tracks.get(e);r||this.tracks.set(e,r=[]),r.push({t0:n[0],t1:n[n.length-t],stride:t,data:n})}addEvents(e){for(let t of e)this.events.push(t)}addInfo(e,t){this.infos.push({t:e,info:t})}info(e){let t={};for(let n of this.infos)n.t<=e&&(t=n.info);return t}trim(e){for(let t of this.tracks.values())for(;t.length>1&&t[1].t0<=e&&t[0].t1<e;)t.shift();let t=0;for(;t<this.events.length&&this.events[t].t<e;)t++;for(t>0&&this.events.splice(0,t);this.infos.length>1&&this.infos[1].t<=e;)this.infos.shift()}last(e){let t=this.tracks.get(e);return t?.length?t[t.length-1].t1:-1/0}at(e,t,n){let r=this.tracks.get(e);if(!r?.length)return null;let i=r.length-1;for(;i>0&&r[i].t0>t;)i--;let a=r[i],o=a.stride,s=a.data.length/o,c=a.data,l=0,u=s-1;if(t<=c[0])u=0;else if(t>=c[(s-1)*o])l=u=s-1;else for(;u-l>1;){let e=l+u>>1;c[e*o]<=t?l=e:u=e}let d=l*o,f=u*o,p=c,m=c;l===u&&l===s-1&&i+1<r.length&&t>c[d]&&(m=r[i+1].data,f=0);let h=p[d],g=m[f],_=g>h?Math.min(1,Math.max(0,(t-h)/(g-h))):0;for(let e=1;e<o;e++)n[e-1]=p[d+e]+_*(m[f+e]-p[d+e]);return n}rows(e,t,n,r){let i=this.tracks.get(e);if(i)for(let e of i){if(e.t1<t)continue;if(e.t0>n)break;let i=e.stride,a=e.data;for(let e=0;e<a.length;e+=i){let i=a[e];if(!(i<t)){if(i>n)break;r(a,e)}}}}},k=new URL(`player-CFiFcj0f.js`,import.meta.url).href,ee=4,te=new WeakMap,ne=class{store=new O;start;seed;state=`loading`;endT=null;error=null;fill=0;rebuffers=0;ahead=0;ready;ctx;layout;workers=[];node=null;master;levels=[];pans=[];reverb=null;status=null;disposed=!1;estimatedEnd;constructor(e,t,n,r,i,a,o,s){this.ctx=e,this.start=a,this.seed=i,this.layout=o,this.estimatedEnd=s,this.master=e.createGain(),this.master.connect(t),this.ready=this.open(n,r)}async open(t,n){let r=this.ctx,i=te.get(r);if(i||te.set(r,i=r.audioWorklet.addModule(k)),await i,this.disposed)return;let{stems:a,outputs:o}=this.layout,s={stems:a.length,outputs:o.length,route:a.map(e=>e.output),startFrame:Math.round(this.start*e),estimatedEnd:Math.round(this.estimatedEnd*e)},c=new AudioWorkletNode(r,`stream-player`,{numberOfInputs:0,numberOfOutputs:o.length,outputChannelCount:o.map(()=>2),processorOptions:s});this.node=c,o.some(e=>e.effects===`shared`)&&(this.reverb=new E(r,this.master,this.layout.reverbTime??3)),o.forEach((e,t)=>{let i=r.createGain();i.gain.value=10**(e.level(n)/20),c.connect(i,t);let a=i,o=null;e.pan&&(o=r.createStereoPanner(),o.pan.value=e.pan(n),i.connect(o),a=o),T(r,a,this.master,e.sound,e.effects===`shared`?{send:this.reverb.input}:e.effects),this.levels.push(i),this.pans.push(o)}),c.port.onmessage=e=>this.onStatus(e.data);let l=Math.max(0,this.start-ee),u=[],d=[];a.forEach((t,n)=>{if(t.kind!==`synth`){d.push(null);return}let r=new Worker(new URL(new URL(`synthWorker-ByLtHWda.js`,import.meta.url).href,``+import.meta.url),{type:`module`});this.workers.push(r);let i=new MessageChannel,a=new MessageChannel;d.push(i.port1),u.push(a.port2);let o={type:`init`,sound:t.sound??{},fromFrame:Math.floor(l*e/128)*128,sendFrame:Math.round(this.start*e),stem:n,scorePort:i.port2,playerPort:a.port1,slow:Number(new URLSearchParams(location.search).get(`slow`))||void 0};r.postMessage(o,[i.port2,a.port1]),r.onerror=e=>this.fail(`instrument: ${e.message}`)});let f=new Worker(new URL(new URL(`scoreWorker-B3-6tjqi.js`,import.meta.url).href,``+import.meta.url),{type:`module`});this.workers.push(f);let p=new MessageChannel;u.push(p.port2),f.onmessage=e=>this.onScore(e.data),f.onerror=e=>this.fail(`score: ${e.message}`);let m={type:`init`,comp:t,P:n,seed:this.seed,start:this.start,from:l,synthPorts:d,playerPort:p.port1};f.postMessage(m,[...d.filter(e=>!!e),p.port1]),c.port.postMessage({type:`ports`,ports:u},u),this.state=`buffering`}onScore(e){e.type===`frames`?this.store.add(e.track,e.stride,e.data):e.type===`events`?this.store.addEvents(e.events):e.type===`info`?this.store.addInfo(e.t,e.info):e.type===`end`?this.endT=e.t:e.type===`error`&&this.fail(e.message)}onStatus(e){this.status=e,this.state!==`error`&&(this.state=e.state,this.fill=e.fill,this.rebuffers=e.rebuffers,this.ahead=e.ahead)}fail(e){this.state=`error`,this.error=e,console.error(e)}time(){let t=this.status;if(!t)return this.start;let n=t.playhead;t.state===`playing`&&(n+=Math.min(4096,Math.max(0,this.ctx.currentTime*e-t.at)));let r=(this.ctx.outputLatency||0)+(this.ctx.baseLatency||0);return Math.max(this.start,n/e-r)}update(e){let t=this.ctx.currentTime;this.layout.outputs.forEach((n,r)=>{this.levels[r]?.gain.setTargetAtTime(10**(n.level(e)/20),t,.05),n.pan&&this.pans[r]?.pan.setTargetAtTime(n.pan(e),t,.05)})}dispose(){if(this.disposed)return;this.disposed=!0;for(let e of this.workers)e.terminate();let e=this.ctx.currentTime,t=this.master,n=this.node,r=this.reverb;t.gain.setTargetAtTime(0,e,.02),window.setTimeout(()=>{n?.disconnect(),n?.port.close(),r?.dispose(),t.disconnect()},200)}},re=400;function A(e,t,n){let r=e.view(t,n),i=e.schema.filter(e=>!e.live).map(e=>e.key),a=e=>JSON.stringify(i.map(t=>e[t])),o=null,s=null,c=``,l=null,u=0,d=null,f=0,m=0,h=null,g=window.setInterval(()=>l?.trim(y.now()-r.keep(n())),1e3);function _(t,r,i){let u=n();s?.dispose(),o=t,i&&f||(f=u.seed>0?Math.round(u.seed):p()),s=new ne(t.ctx,t.input,e.id,u,f,Math.max(0,r),e.layout(u),e.estimateLength(u)),c=a(u),l=s.store,d=null,h=null,m=0}function v(){s&&=(u=s.time(),s.endT!==null&&(d=s.endT),s.dispose(),null)}let y={get playing(){return s!==null},async start(e,t){_(e,t,!1),await s.ready},stop:v,seek(e){o&&_(o,e,!0)},draw(){let e=n();if(s){if(s.state===`error`)h=`something went wrong computing this piece; try play again`,v();else if(s.state===`ended`){let e=s.endT??s.time();v(),u=e,y.onEnded?.()}else if(s.update(e),a(e)!==c){let e=performance.now();m?e>=m&&o&&_(o,s.time(),!0):m=e+re}else m=0}let t=y.now();l?.trim(t-r.keep(e)),r.draw(t,l,s?.state===`playing`)},now:()=>s?s.time():u,length:()=>s?.endT??d??e.estimateLength(n()),status:()=>({buffering:s!==null&&(s.state===`loading`||s.state===`buffering`),fill:s?.fill??0}),notice:()=>h,readouts(){let e=y.now();return{time:`${e.toFixed(1)} / ${y.length().toFixed(1)} s`,buffer:s?`${s.state}, ${s.ahead.toFixed(1)} s ahead, ${s.rebuffers} pause${s.rebuffers===1?``:`s`}`:`–`,"seed used":f?String(f):`–`,...l?.info(e)??{},...r.readouts?.(e,l)??{}}},dispose(){v(),window.clearInterval(g),r.dispose?.(),t.replaceChildren()}};return y}var ie={duration:60,peakTime:25,holdTime:10,energyStart:.005,energyPeak:.4,riseShape:`exponential`,riseCurve:1,fallCurve:1,restEnergy:.001,finalHold:2,finalFade:5,speed:50,massRatio:1,lengthRatio:1,tau:2,seed:0,noteInstrument:`modal: Nylon harp`,modalCustom:``,scale:`dorian`,root:`D`,pitchSource:`signed`,thetaRange:3.1416,pitchLow:50,pitchHigh:86,pitchCurve:1,invertPitch:!1,p2Ref:1,loudCurve:1,loudFloor:.08,notesLevel:-6,noteLength:1.5,humInstrument:`modal: Clarinet-ish`,humCustom:``,humPitch:38,humLevel:-24,humFollow:0,humNormalize:!0,humColorMode:`log`,humColorCurve:1,humTarget1:`pickup`,humFrom1:.15,humTo1:.75,humTarget2:`tilt`,humFrom2:.3333,humTo2:.5833,humFadeIn:3,humFadeOut:6,pendulumAlpha:1,pendulumSize:.32,motionBlur:1,fade:10,plotZoom:`fit energy`,zoomSmooth:1.5,plotP:1.5,pointSize:2,orbits:!0,orbitCount:24,orbitCpu:.4,orbitLife:300,orbitBand:.25,orbitMinHold:3,orbitMaxPoints:8e3,orbitXfade:1.5,orbitAlpha:.3,orbitSize:1},j={geometry:`string`,t60:3,hfDamp:2,damper:.6,exciter:`bow`,bowForce:1,bowSpeed:.4,bowNoise:.06,noiseColor:4e3,exWidth:.1,attack:80,release:150,pickup:.99,width:0,spread:0,tilt:-6,vibDelay:350,boxMix:.9,level:23,voices:4,reverbMix:.25,reverbSize:2.2},M=[{name:`Piano-ish`,category:`Instrument`,note:48,p:{geometry:`string`,modes:80,inharm:4e-4,t60:9,hfDamp:1.2,damper:.15,exciter:`strike`,strength:1,exPos:.12,exWidth:.04,hammerMass:.04,hardness:1.4,feltExp:2.6,tension:.01,crossLink:.15,pickup:.77,spread:.35,width:.4,reverbMix:.18}},{name:`Steel-string pluck`,category:`Instrument`,note:52,p:{geometry:`string`,modes:64,inharm:8e-5,t60:5,hfDamp:3,damper:.4,exciter:`pluck`,strength:1,exPos:.18,exWidth:.03,tension:.02,pickup:.92,spread:.25,reverbMix:.15}},{name:`Nylon harp`,category:`Instrument`,note:60,p:{geometry:`string`,modes:48,t60:3.5,hfDamp:8,damper:20,exciter:`pluck`,exPos:.35,exWidth:.2,pickup:.5,spread:.5,reverbMix:.25}},{name:`Marimba`,category:`Instrument`,note:60,p:{geometry:`bar`,modes:24,stretch:1.368,t60:1.3,hfDamp:6,damper:20,exciter:`strike`,exPos:.42,exWidth:.05,hammerMass:.25,hardness:1,feltExp:2,pickup:.22,spread:.3,reverbMix:.2}},{name:`Vibraphone`,category:`Instrument`,note:65,p:{geometry:`bar`,modes:24,stretch:1.368,t60:7,hfDamp:1.5,damper:.2,exciter:`strike`,exPos:.45,exWidth:.05,hammerMass:.15,hardness:.8,feltExp:2.2,pickup:.22,spread:.3,lfo1Target:`amp`,lfo1Rate:5,lfo1Depth:.45,reverbMix:.25}},{name:`Church bell`,category:`Instrument`,note:55,p:{geometry:`ring`,modes:40,t60:14,hfDamp:.4,damper:20,jitter:4,exciter:`strike`,exPos:.1,exWidth:.02,hammerMass:.6,hardness:.5,feltExp:1.5,tension:.01,pickup:.3,spread:.5,reverbMix:.35,reverbSize:5}},{name:`Tom drum`,category:`Instrument`,note:43,p:{geometry:`membrane`,modes:40,t60:.7,hfDamp:6,damper:20,tension:.25,exciter:`strike`,strength:1.6,exPos:.35,exPosY:.45,exWidth:.05,hammerMass:.3,hardness:2.5,feltExp:2,pickup:.5,pickupY:.5,spread:.5,reverbMix:.15}},{name:`Snare-ish`,category:`Instrument`,note:50,p:{geometry:`membrane`,modes:64,t60:.5,hfDamp:2,damper:20,tension:.1,buzz:.5,buzzGap:.05,buzzPos:.5,buzzPosY:.55,buzzSides:`two`,exciter:`strike`,strength:1.5,exPos:.4,exPosY:.4,exWidth:.02,hammerMass:.05,hardness:.6,feltExp:1.5,pickup:.5,pickupY:.5,spread:.6,reverbMix:.15}},{name:`Sitar / tanpura`,category:`Instrument`,note:50,p:{geometry:`string`,modes:96,t60:8,hfDamp:.3,damper:20,buzz:.6,buzzGap:.15,buzzPos:.015,buzzSides:`one`,exciter:`pluck`,strength:1.2,exPos:.2,exWidth:.02,pickup:.12,spread:.3,reverbMix:.25}},{name:`Cello`,category:`Instrument`,note:48,p:{...j,modes:128,inharm:4e-5,exPos:.09,vibDepth:16,vibRate:5.2,soundbox:`cello`}},{name:`Violin`,category:`Instrument`,note:67,p:{...j,modes:80,inharm:2e-5,exPos:.1,exWidth:.15,vibDepth:14,vibRate:5.8,vibDelay:250,soundbox:`violin`}},{name:`Viola`,category:`Instrument`,note:60,p:{...j,modes:96,inharm:3e-5,exPos:.1,vibDepth:15,vibRate:5.5,soundbox:`viola`}},{name:`Double bass`,category:`Instrument`,note:36,p:{...j,modes:160,inharm:6e-5,exPos:.08,t60:4,attack:120,vibDepth:12,vibRate:4.8,vibDelay:450,soundbox:`bass`,voices:3,level:20}},{name:`Cello pizzicato`,category:`Instrument`,note:48,p:{...j,modes:96,inharm:4e-5,exciter:`pluck`,strength:1.2,exPos:.3,exWidth:.25,t60:2.2,hfDamp:8,damper:.4,vibDepth:0,soundbox:`cello`,voices:8,level:24}},{name:`Clarinet-ish`,category:`Instrument`,note:50,p:{geometry:`tube_co`,modes:24,t60:.25,hfDamp:6,damper:.05,exciter:`reed`,reedPressure:.7,reedGain:.4,breath:.03,noiseColor:3e3,exPos:0,exWidth:0,attack:30,release:60,pickup:.25,spread:.2,reverbMix:.2}},{name:`Singing bowl`,category:`Instrument`,note:62,p:{geometry:`ring`,modes:24,t60:20,hfDamp:.5,damper:20,jitter:2,exciter:`selfosc`,selfGain:.15,selfSat:.3,exPos:0,exWidth:.01,attack:1500,release:3e3,pickup:.15,spread:.4,width:.6,reverbMix:.35,reverbSize:6}},{name:`Rubber band`,category:`Experimental`,note:40,p:{geometry:`string`,modes:40,t60:1.5,hfDamp:4,damper:.3,tension:1.2,exciter:`pluck`,strength:2.5,exPos:.3,exWidth:.05,pickup:.8,reverbMix:.1}},{name:`Chaos gong`,category:`Experimental`,note:40,p:{geometry:`plate`,modes:128,aspect:.8,nlModes:64,terms:8,cascade:12,curvature:2.2,t60:10,hfDamp:.2,damper:20,crossTension:.4,crossLink:.8,exciter:`strike`,strength:3.5,exPos:.3,exPosY:.3,hammerMass:.4,hardness:2,feltExp:2,pickup:.6,pickupY:.7,spread:.5,width:.6,reverbMix:.3,reverbSize:6,voices:4}},{name:`Ring-mod chords`,category:`Experimental`,note:57,p:{geometry:`free`,powerExp:1.7,modes:32,jitter:15,t60:6,hfDamp:1,damper:1,crossTension:.3,crossLink:1.4,curvature:.5,exciter:`strike`,strength:1.8,exPos:.2,hammerMass:.1,hardness:.8,pickup:.7,spread:.6,width:.6,delayMix:.25,delayTime:375,delayFb:.4,reverbMix:.3}},{name:`Feedback drone plate`,category:`Experimental`,note:45,p:{geometry:`plate`,modes:96,aspect:.62,nlModes:64,cascade:.8,curvature:.3,t60:6,hfDamp:.5,damper:3,exciter:`noise`,noiseLevel:.2,noiseColor:800,attack:800,release:3e3,fbGain:2.5,fbDelay:12,fbFreq:600,fbQ:2,fbSat:.4,lfo1Target:`position`,lfo1Rate:.07,lfo1Depth:.5,lfo1Shape:`smooth`,lfo2Target:`pickup`,lfo2Rate:.11,lfo2Depth:.4,lfo2Shape:`smooth`,pickup:.3,pickupY:.7,spread:.3,width:.7,reverbMix:.35,reverbSize:5,voices:4}},{name:`Buzzing bar organ`,category:`Experimental`,note:48,p:{geometry:`bar`,modes:32,t60:3,hfDamp:1,damper:.3,buzz:.4,buzzGap:.3,buzzPos:.5,buzzSides:`two`,exciter:`selfosc`,selfGain:.6,selfSat:.4,exPos:.02,attack:60,release:300,pickup:.3,spread:.3,reverbMix:.25}},{name:`Glass harmonics`,category:`Experimental`,note:72,p:{geometry:`free`,powerExp:1.25,modes:24,harmonize:.3,t60:12,hfDamp:.3,damper:2,exciter:`impulse`,strength:.8,hardness:.3,exPos:.21,pickup:.6,spread:.6,width:.8,tension:.05,lfo1Target:`pickup`,lfo1Rate:.3,lfo1Depth:.6,delayMix:.3,delayTime:450,delayFb:.5,reverbMix:.45,reverbSize:7}}];function ae(e){if(!e||!e.trim())return null;try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}var oe=[`bow`,`reed`,`selfosc`,`noise`],N=[...M.map(e=>`modal: ${e.name}`),`modal: custom`],se=[...M.filter(e=>{let t={...C,...e.p};return oe.includes(t.exciter)||t.fbGain>0}).map(e=>`modal: ${e.name}`),`modal: custom`];function P(e,t,n={}){let r=e===`modal: custom`?ae(t):M.find(t=>`modal: ${t.name}`===e)?.p;return{...C,...r??{},...n}}var F=[`bowForce`,`bowSpeed`,`bowNoise`,`exPos`,`reedPressure`,`reedGain`,`breath`,`selfGain`,`selfSat`,`noiseLevel`,`noiseColor`,`tension`,`cascade`,`curvature`,`fbGain`,`fbFreq`,`fbQ`,`fbSat`,`hfDamp`,`t60`,`pickup`,`tilt`,`vibDepth`];function ce(e){let t=P(e.noteInstrument,e.modalCustom),n=P(e.humInstrument,e.humCustom,{voices:1});return{stems:[{kind:`synth`,sound:t,output:0},{kind:`synth`,sound:n,output:1}],outputs:[{effects:`own`,sound:t,level:e=>e.notesLevel},{effects:`own`,sound:n,level:e=>e.humLevel}]}}function le(e){return e.duration+.5+e.finalHold+e.finalFade+.3}var I=[{group:`form`,key:`duration`,label:`duration`,kind:`number`,default:60,min:10,max:600,step:1,unit:`s`,hint:`energy returns to zero at this time`},{group:`form`,key:`peakTime`,label:`peak at`,kind:`number`,default:25,min:1,max:600,step:.5,unit:`s`},{group:`form`,key:`holdTime`,label:`hold`,kind:`number`,default:10,min:0,max:600,step:.5,unit:`s`},{group:`form`,key:`energyStart`,label:`start energy`,kind:`number`,default:.005,min:1e-4,max:1,log:!0},{group:`form`,key:`energyPeak`,label:`peak energy`,kind:`number`,default:1.2,min:.01,max:5,log:!0},{group:`form`,key:`riseShape`,label:`rise shape`,kind:`select`,default:`exponential`,options:[`exponential`,`linear`]},{group:`form`,key:`riseCurve`,label:`rise curve`,kind:`number`,default:1,min:.2,max:5,log:!0,hint:`exponent on the rise; >1 starts slow`},{group:`form`,key:`fallCurve`,label:`fall curve`,kind:`number`,default:1,min:.2,max:5,log:!0,hint:`exponent on the fall; >1 drops fast then lingers`},{group:`form`,key:`restEnergy`,label:`rest energy`,kind:`number`,default:.001,min:1e-5,max:.05,log:!0,hint:`after duration, the pendulum counts as at rest below this energy: no more crossings; the last note rings out`},{group:`form`,key:`finalHold`,label:`final hold`,kind:`number`,default:2,min:0,max:20,step:.1,unit:`s`,hint:`the last note sustains this long…`},{group:`form`,key:`finalFade`,label:`final fade`,kind:`number`,default:5,min:.1,max:30,step:.1,unit:`s`,hint:`…then fades out over this long; the piece ends with it`},{group:`physics`,key:`speed`,label:`speed`,kind:`number`,default:12,min:.5,max:100,log:!0,unit:`×`,hint:`simulated seconds per real second`},{group:`physics`,key:`massRatio`,label:`m2 / m1`,kind:`number`,default:1,min:.1,max:10,log:!0},{group:`physics`,key:`lengthRatio`,label:`l2 / l1`,kind:`number`,default:1,min:.1,max:10,log:!0},{group:`physics`,key:`tau`,label:`energy follow`,kind:`number`,default:2,min:.1,max:50,log:!0,unit:`sim s`,hint:`how quickly the energy tracks its target`},{group:`physics`,key:`seed`,label:`seed`,kind:`number`,default:0,min:0,max:999999,step:1,hint:`0 = a new variation every play`},{group:`notes`,key:`noteInstrument`,label:`instrument`,kind:`select`,default:`modal: Nylon harp`,options:N,hint:`modal: … instruments come from the modal-synth project`},{group:`notes`,key:`modalCustom`,label:`modal custom`,kind:`text`,default:``,hint:`for “modal: custom”: paste JSON from modal-synth’s Copy button`},{group:`notes`,key:`scale`,label:`scale`,kind:`select`,default:`pentatonic minor`,options:Object.keys({continuous:null,chromatic:[0,1,2,3,4,5,6,7,8,9,10,11],major:[0,2,4,5,7,9,11],"natural minor":[0,2,3,5,7,8,10],dorian:[0,2,3,5,7,9,10],lydian:[0,2,4,6,7,9,11],"pentatonic major":[0,2,4,7,9],"pentatonic minor":[0,3,5,7,10],"whole tone":[0,2,4,6,8,10],"harmonic series":null})},{group:`notes`,key:`root`,label:`root`,kind:`select`,default:`D`,options:[`C`,`C#`,`D`,`D#`,`E`,`F`,`F#`,`G`,`G#`,`A`,`A#`,`B`]},{group:`notes`,key:`pitchSource`,label:`pitch from θ2`,kind:`select`,default:`signed`,options:[`signed`,`absolute`],hint:`signed: −range→low, +range→high. absolute: 0→low, ±range→high`},{group:`notes`,key:`thetaRange`,label:`θ2 range`,kind:`number`,default:3.1416,min:.02,max:3.1416,log:!0,unit:`rad`},{group:`notes`,key:`pitchLow`,label:`low pitch`,kind:`number`,default:50,min:12,max:120,step:.5,unit:`midi`},{group:`notes`,key:`pitchHigh`,label:`high pitch`,kind:`number`,default:86,min:12,max:120,step:.5,unit:`midi`},{group:`notes`,key:`pitchCurve`,label:`pitch curve`,kind:`number`,default:1,min:.2,max:5,log:!0},{group:`notes`,key:`invertPitch`,label:`invert pitch`,kind:`bool`,default:!1},{group:`notes`,key:`p2Ref`,label:`|p2| for full`,kind:`number`,default:1,min:.01,max:4,log:!0,hint:`|p2| that gives full loudness`},{group:`notes`,key:`loudCurve`,label:`loudness curve`,kind:`number`,default:1,min:.2,max:5,log:!0},{group:`notes`,key:`loudFloor`,label:`loudness floor`,kind:`number`,default:.08,min:0,max:1,step:.01,hint:`loudness of a crossing with p2 = 0`},{group:`notes`,key:`notesLevel`,label:`level`,kind:`number`,default:-6,min:-48,max:6,step:.5,unit:`dB`,live:!0},{group:`notes`,key:`noteLength`,label:`length`,kind:`number`,default:1.5,min:.05,max:10,log:!0,unit:`s`},{group:`hum`,key:`humInstrument`,label:`instrument`,kind:`select`,default:`modal: Clarinet-ish`,options:se,hint:`modal: … = one held note of a sustained modal-synth preset`},{group:`hum`,key:`humCustom`,label:`modal custom`,kind:`text`,default:``,hint:`for “modal: custom”: paste JSON from modal-synth’s Copy button`},{group:`hum`,key:`humPitch`,label:`pitch`,kind:`number`,default:38,min:12,max:72,step:.5,unit:`midi`},{group:`hum`,key:`humLevel`,label:`level`,kind:`number`,default:-24,min:-60,max:0,step:.5,unit:`dB`,live:!0},{group:`hum`,key:`humFollow`,label:`loudness follows energy`,kind:`number`,default:0,min:0,max:1,step:.01,hint:`0 = constant loudness`},{group:`hum`,key:`humNormalize`,label:`normalize loudness`,kind:`bool`,default:!0,hint:`modal hum: measure the output and compensate slowly, so timbre changes don't change loudness`},{group:`hum`,key:`humColorMode`,label:`timbre from energy`,kind:`select`,default:`log`,options:[`log`,`power`],hint:`log: even steps per energy doubling, from start energy (0) to peak (1). power: (energy / peak)^curve`},{group:`hum`,key:`humColorCurve`,label:`timbre curve`,kind:`number`,default:1,min:.1,max:5,log:!0,hint:`exponent applied to the timbre value`},{group:`hum`,key:`humTarget1`,label:`timbre → A`,kind:`select`,default:`pickup`,options:[`none`,...F],hint:`modal hum: synth setting driven by timbre (bow position, force, pressure, feedback, …)`},{group:`hum`,key:`humFrom1`,label:`A at low energy`,kind:`number`,default:.15,min:0,max:1,step:.005,hint:`fraction of the setting's range in modal-synth`},{group:`hum`,key:`humTo1`,label:`A at peak`,kind:`number`,default:.75,min:0,max:1,step:.005},{group:`hum`,key:`humTarget2`,label:`timbre → B`,kind:`select`,default:`tilt`,options:[`none`,...F]},{group:`hum`,key:`humFrom2`,label:`B at low energy`,kind:`number`,default:.3333,min:0,max:1,step:.005},{group:`hum`,key:`humTo2`,label:`B at peak`,kind:`number`,default:.5833,min:0,max:1,step:.005},{group:`hum`,key:`humFadeIn`,label:`fade in`,kind:`number`,default:3,min:0,max:60,step:.5,unit:`s`},{group:`hum`,key:`humFadeOut`,label:`fade out`,kind:`number`,default:6,min:0,max:60,step:.5,unit:`s`,hint:`ends together with the last note's fade`},{group:`visual`,key:`pendulumAlpha`,label:`pendulum opacity`,kind:`number`,default:1,min:0,max:1,step:.01,hint:`0 = hide the pendulum`,live:!0},{group:`visual`,key:`pendulumSize`,label:`pendulum size`,kind:`number`,default:.32,min:.1,max:1,step:.01,hint:`inset diameter, as a fraction of the plot (upper-left corner)`,live:!0},{group:`visual`,key:`motionBlur`,label:`motion blur`,kind:`number`,default:1,min:0,max:4,step:.05,hint:`pendulum shutter, in display frames; 0 = off`,live:!0},{group:`visual`,key:`fade`,label:`point fade`,kind:`number`,default:10,min:.2,max:120,log:!0,unit:`s`,live:!0},{group:`visual`,key:`plotZoom`,label:`plot zoom`,kind:`select`,default:`fit energy`,options:[`fit energy`,`fixed`],hint:`fit energy: frame the region the pendulum can reach at its current energy`,live:!0},{group:`visual`,key:`zoomSmooth`,label:`zoom smoothing`,kind:`number`,default:1.5,min:.05,max:20,log:!0,unit:`s`,hint:`time constant of zoom changes`,live:!0},{group:`visual`,key:`plotP`,label:`fixed p2 range`,kind:`number`,default:1.5,min:.05,max:5,log:!0,live:!0},{group:`visual`,key:`pointSize`,label:`point size`,kind:`number`,default:2,min:.5,max:8,step:.1,unit:`px`,live:!0},{group:`orbits`,key:`orbits`,label:`show orbits`,kind:`bool`,default:!0,live:!0},{group:`orbits`,key:`orbitCount`,label:`orbits`,kind:`number`,default:24,min:1,max:64,step:1,hint:`trajectories integrated in parallel, all at the portrait's energy`,live:!0},{group:`orbits`,key:`orbitCpu`,label:`cpu`,kind:`number`,default:.4,min:.02,max:.9,step:.01,hint:`fraction of one core the background computation may use`,live:!0},{group:`orbits`,key:`orbitLife`,label:`life`,kind:`number`,default:300,min:10,max:5e3,log:!0,hint:`crossings before an orbit is reseeded elsewhere on the section`,live:!0},{group:`orbits`,key:`orbitBand`,label:`refresh at`,kind:`number`,default:.25,min:.01,max:2,log:!0,hint:`start a new portrait when the energy has changed by this fraction`,live:!0},{group:`orbits`,key:`orbitMinHold`,label:`min hold`,kind:`number`,default:3,min:0,max:30,step:.1,unit:`s`,hint:`a portrait is kept at least this long`,live:!0},{group:`orbits`,key:`orbitMaxPoints`,label:`max points`,kind:`number`,default:8e3,min:500,max:4e4,log:!0,hint:`a portrait stops computing (and using CPU) once it has this many points`,live:!0},{group:`orbits`,key:`orbitXfade`,label:`crossfade`,kind:`number`,default:1.5,min:.05,max:10,log:!0,unit:`s`,hint:`time for the old portrait to fade out once a new one starts`,live:!0},{group:`orbits`,key:`orbitAlpha`,label:`brightness`,kind:`number`,default:.3,min:.02,max:1,step:.01,live:!0},{group:`orbits`,key:`orbitSize`,label:`point size`,kind:`number`,default:1,min:.5,max:4,step:.1,unit:`px`,live:!0}],ue=100,de=class{worker=null;portraits=[];resetPending=!1;latestGen=0;ignoreBelow=0;rate=0;newPts=0;rateT=0;now;live;constructor(e,t){this.now=e,this.live=t}reset(){this.dirty=!0,this.portraits=[],this.ignoreBelow=this.latestGen+1,this.resetPending=!0}ensureWorker(){return this.worker||(this.worker=new Worker(new URL(new URL(`orbitWorker-CV_Zv_V1.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),this.worker.onmessage=e=>this.receive(e.data)),this.worker}receive({gen:e,energy:t,pts:n,tracks:r}){if(!this.live()||(this.latestGen=Math.max(this.latestGen,e),e<this.ignoreBelow))return;let i=this.portraits[this.portraits.length-1];if(!i||e>i.gen){let n=this.now();for(let e of this.portraits)e.retiredAt??=n;i={gen:e,energy:t,pts:[],tracks:new Map,retiredAt:null},this.portraits.push(i)}else if(e<i.gen)return;for(let e=0;e<n.length;e++)i.pts.push(n[e]);for(let e of r){let t=i.tracks.get(e.id);t||i.tracks.set(e.id,t=[]);for(let n=0;n<e.pts.length;n++)t.push(e.pts[n])}this.newPts+=n.length/2+r.reduce((e,t)=>e+t.pts.length/2,0),this.dirty=!0}post(e,t,n,r,i,a){if(!t.show&&!t.tracks&&!this.worker)return;let o={running:e&&(t.show||t.tracks),reset:this.resetPending,energy:n,m2:r,l2:i,count:t.show?Math.round(t.count):0,life:t.life,band:t.band,minHold:t.minHold,maxPoints:t.show?t.maxPoints:0,cpu:t.cpu,tracks:t.tracks?a:[],trackMax:t.trackMax};this.resetPending=!1,this.ensureWorker().postMessage(o)}layer=null;layerAt=0;layerKey=``;dirty=!0;lm={cx:0,kx:1,cy:0,ky:1};draw(e,t,n,r,i){let{g:a,w:o,h:s,sx:c,sy:l}=e,u=this.portraits.length;this.portraits=this.portraits.filter(e=>e.retiredAt===null||t-e.retiredAt<n.xfade),this.portraits.length!==u&&(this.dirty=!0);let d=this.portraits.some(e=>e.retiredAt!==null),f=window.devicePixelRatio||1,p=[o,s,f,n.show,n.tracks,n.alpha,n.size,n.trackAlpha,n.trackSize,r].join(`|`),m={cx:c(0),kx:c(1)-c(0),cy:l(0),ky:l(1)-l(0)},h=m.kx/this.lm.kx,g=m.ky/this.lm.ky,_=Math.abs(Math.log(h))>.05||Math.abs(Math.log(g))>.05,v=performance.now();this.layer||=document.createElement(`canvas`);let y=this.layer;if((this.dirty||d||_||p!==this.layerKey)&&v-this.layerAt>=ue){let e=Math.round(o*f),a=Math.round(s*f);(y.width!==e||y.height!==a)&&(y.width=e,y.height=a);let u=y.getContext(`2d`);u.setTransform(f,0,0,f,0,0),u.clearRect(0,0,o,s);for(let e of this.portraits){let a=e.retiredAt===null?1:Math.max(0,1-(t-e.retiredAt)/n.xfade);if(n.show&&e.pts.length){let t=n.size;u.fillStyle=r,u.globalAlpha=n.alpha*a,u.beginPath();let i=e.pts;for(let e=0;e<i.length;e+=2)u.rect(c(i[e])-t/2,l(i[e+1])-t/2,t,t);u.fill()}if(n.tracks){let t=n.trackSize;for(let[r,o]of e.tracks){u.fillStyle=i(r),u.globalAlpha=n.trackAlpha*a,u.beginPath();for(let e=0;e<o.length;e+=2)u.rect(c(o[e])-t/2,l(o[e+1])-t/2,t,t);u.fill()}}}u.globalAlpha=1,this.layerAt=v,this.layerKey=p,this.lm=m,this.dirty=!1}if(y.width){let e=m.kx/this.lm.kx,t=m.ky/this.lm.ky;a.save(),a.setTransform(f*e,0,0,f*t,f*(m.cx-e*this.lm.cx),f*(m.cy-t*this.lm.cy)),a.drawImage(y,0,0,o,s),a.restore()}}describe(){let e=performance.now()/1e3;e-this.rateT>1&&(this.rate=this.newPts/(e-this.rateT||1),this.newPts=0,this.rateT=e);let t=this.portraits.find(e=>e.retiredAt===null);if(!t)return`–`;let n=[...t.tracks.values()].reduce((e,t)=>e+t.length/2,0);return`E ${t.energy.toFixed(4)}, ${t.pts.length/2} pts${t.tracks.size?` + ${n} traced`:``}, ${Math.round(this.rate)}/s`}dispose(){this.worker?.terminate(),this.worker=null}};function L(e){let t=window.devicePixelRatio||1,n=Math.round(e.clientWidth*t),r=Math.round(e.clientHeight*t);(e.width!==n||e.height!==r)&&(e.width=n,e.height=r);let i=e.getContext(`2d`);return i.setTransform(t,0,0,t,0,0),i}function R(e,t,n=`#ccc`){return getComputedStyle(e).getPropertyValue(t).trim()||n}var fe=class{thR=Math.PI;pR=1;lastWall=0;canvas;constructor(e){this.canvas=e}begin(e,t,n,r,i){let a=performance.now()/1e3,o=a-this.lastWall;this.lastWall=a;let s=this.canvas,c=L(s),l=s.clientWidth,u=s.clientHeight;c.clearRect(0,0,l,u);let d=Math.PI,f=e.plotP;if(e.plotZoom===`fit energy`&&t!==null&&n){let e=Math.max(1e-6,t),i=e*r,a=i>=2*n.m2*n.g*n.l2?Math.PI:Math.acos(1-i/(n.m2*n.g*n.l2));d=Math.min(Math.PI,1.08*a),f=1.08*Math.sqrt(2*e)}let p=o>0&&o<.5?1-Math.exp(-o/Math.max(.01,e.zoomSmooth)):1;this.thR*=Math.exp(p*Math.log(d/this.thR)),this.pR*=Math.exp(p*Math.log(f/this.pR));let m=(l/2-8)/this.thR,h=(u/2-8)/this.pR;return c.strokeStyle=i,c.lineWidth=1,c.beginPath(),c.moveTo(8,u/2),c.lineTo(l-8,u/2),c.moveTo(l/2,8),c.lineTo(l/2,u-8),c.stroke(),{g:c,w:l,h:u,sx:e=>l/2+m*e,sy:e=>u/2-h*e}}};function z(e,t,n,r,i,a,o){let{g:s,sx:c,sy:l}=e;s.fillStyle=o,s.globalAlpha=Math.exp(-r/i),s.beginPath(),s.arc(c(t),l(n),a/2,0,2*Math.PI),s.fill(),r<.4&&(s.globalAlpha=1-r/.4,s.strokeStyle=o,s.beginPath(),s.arc(c(t),l(n),a/2+3+12*r,0,2*Math.PI),s.stroke()),s.globalAlpha=1}var pe=64,me=2,he=50;function ge(e,t){return 2*(1+e)+2*e*t}function _e(e,t){e.classList.add(`c01`);let n=document.createElement(`canvas`);e.append(n);let r=new fe(n),i=0,a=!1,o=new de(()=>i,()=>a),s=e=>({show:e.orbits,count:e.orbitCount,cpu:e.orbitCpu,life:e.orbitLife,band:e.orbitBand,minHold:e.orbitMinHold,maxPoints:e.orbitMaxPoints,xfade:e.orbitXfade,alpha:e.orbitAlpha,size:e.orbitSize,tracks:!1,trackMax:0,trackAlpha:0,trackSize:1}),c=new Float64Array(3),l=null,u=0,d=0,f=1/60;function p(t,n,r,i,o,s){let l=i.pendulumAlpha;if(l<=0)return;let u=e=>{let t=s?.at(0,e,c);return t?[t[0],t[1]]:[0,0]},d=a?i.motionBlur*f:0,p=i.lengthRatio,m=i.pendulumSize*Math.min(n,r)/2,h=.9*m/(1+p),g=8+m,_=8+m,v=1;if(d>0){let e=0,t=u(o);for(let n=1;n<=8;n++){let r=u(o-d*n/8);e+=h*(+Math.abs(r[0]-t[0])+p*Math.abs(r[1]-t[1])),t=r}v=Math.max(2,Math.min(pe,Math.ceil(e/me)))}let y=l*(v===1?1:1-.03**(1/v)),b=3*Math.cbrt(i.massRatio),x=R(e,`--fg`);t.strokeStyle=x,t.fillStyle=x,t.lineWidth=1.5,t.lineCap=`round`,t.globalAlpha=y;for(let e=0;e<v;e++){let[n,r]=u(o-d*e/Math.max(1,v-1)),i=g+h*1*Math.sin(n),a=_+h*1*Math.cos(n),s=i+h*p*Math.sin(r),c=a+h*p*Math.cos(r);t.beginPath(),t.moveTo(g,_),t.lineTo(i,a),t.lineTo(s,c),t.stroke(),t.beginPath(),t.arc(i,a,3,0,2*Math.PI),t.moveTo(s+b,c),t.arc(s,c,b,0,2*Math.PI),t.fill()}t.globalAlpha=l,t.beginPath(),t.arc(g,_,1.5,0,2*Math.PI),t.fill(),t.globalAlpha=1}return{keep:e=>4.6*e.fade+.5,draw(n,m,h){let g=t();i=n,a=h;let _=performance.now(),v=(_-d)/1e3;d=_,v>0&&v<.1&&(f+=(v-f)*.1),m!==l&&(l=m,o.reset());let y=m?.at(0,n,c),b=y?y[2]:null,x=g.massRatio,S=g.lengthRatio,C=R(e,`--fg`);_-u>he&&(u=_,o.post(h,s(g),b??0,x,S,[]));let w=r.begin(g,b,{m1:1,l1:1,g:1,m2:x,l2:S},ge(x,S),R(e,`--dim`));if(o.draw(w,n,s(g),C,()=>C),m){let e=g.fade,t=g.pointSize;for(let r of m.events){let i=n-r.t;if(i<0)break;z(w,r.th2,r.p2,i,e,t,C)}}p(w.g,w.w,w.h,g,n,m)},readouts:()=>({"orbit portrait":o.describe()}),dispose(){o.dispose(),e.classList.remove(`c01`)}}}var ve={id:`01-poincare`,schema:I,layout:ce,estimateLength:le,view:_e},ye={id:ve.id,title:`poincaré`,schema:I,defaults:ie,create:(e,t)=>A(ve,e,t)},be={duration:60,peakTime:25,holdTime:10,energyStart:.005,energyPeak:.4,riseShape:`exponential`,riseCurve:1,fallCurve:1,restEnergy:.001,finalHold:2,finalFade:5,speed:40,massRatio:1,lengthRatio:1,tau:2,seed:0,orbitCount:8,colors:`#d6b37a, #7fa8cf, #c48bb8, #93bf8a, #d48f7f, #a9a6e0`,slot1Instrument:`modal: Nylon harp`,slot1Octave:0,slot2Instrument:`modal: Marimba`,slot2Octave:-1,slot3Instrument:`modal: Vibraphone`,slot3Octave:0,slot4Instrument:`modal: Church bell`,slot4Octave:-1,slot5Instrument:`modal: Steel-string pluck`,slot5Octave:0,slot6Instrument:`modal: Glass harmonics`,slot6Octave:1,modalCustom:``,reverbTime:3.5,scale:`dorian`,root:`D`,pitchSource:`signed`,thetaRange:3.1416,pitchLow:50,pitchHigh:86,pitchCurve:1,invertPitch:!1,p2Ref:1,loudCurve:1,loudFloor:.08,notesLevel:-6,noteLength:1.5,humInstrument:`modal: Clarinet-ish`,humCustom:``,humPitch:38,humLevel:-24,humFollow:0,humNormalize:!0,humColorMode:`log`,humColorCurve:1,humTarget1:`pickup`,humFrom1:.15,humTo1:.75,humTarget2:`tilt`,humFrom2:.3333,humTo2:.5833,humFadeIn:3,humFadeOut:6,fade:20,plotZoom:`fit energy`,zoomSmooth:1.5,plotP:1.5,pointSize:2.5,portrait:!0,portraitCount:24,portraitCpu:.4,portraitLife:300,portraitBand:.25,portraitMinHold:3,portraitMaxPoints:8e3,portraitXfade:1.5,portraitAlpha:.15,portraitSize:1,traces:!0,traceMax:1500,traceAlpha:.75,traceSize:1.5};function xe(e){return Math.max(1,Math.min(20,Math.round(e.orbitCount)))}function Se(e){let t=[],n=[];for(let r=0;r<xe(e);r++){let i=e[`slot${r%6+1}Instrument`],a=t.indexOf(i);a<0&&(a=t.push(i)-1),n.push(a)}return{names:t,stemOf:n}}function Ce(e){let{names:t}=Se(e),n=t.map(t=>P(t,e.modalCustom)),r=P(e.humInstrument,e.humCustom,{voices:1});return{stems:[...n.map((e,t)=>({kind:`synth`,sound:e,output:t})),{kind:`synth`,sound:r,output:t.length}],outputs:[...n.map(e=>({effects:`shared`,sound:e,level:e=>e.notesLevel})),{effects:`own`,sound:r,level:e=>e.humLevel}],reverbTime:e.reverbTime}}function we(e){return e.duration+.5+e.finalHold+e.finalFade+.3}var B=(e,t={})=>{let n=I.find(t=>t.key===e);if(!n)throw Error(`no setting ${e} in composition 1`);return{...n,...t}},Te=[[`modal: Nylon harp`,0],[`modal: Marimba`,-1],[`modal: Vibraphone`,0],[`modal: Church bell`,-1],[`modal: Steel-string pluck`,0],[`modal: Glass harmonics`,1]],Ee=[...[`duration`,`peakTime`,`holdTime`,`energyStart`].map(e=>B(e)),B(`energyPeak`,{default:.4}),...[`riseShape`,`riseCurve`,`fallCurve`,`restEnergy`,`finalHold`,`finalFade`].map(e=>B(e)),B(`speed`,{default:40}),...[`massRatio`,`lengthRatio`,`tau`,`seed`].map(e=>B(e)),{group:`orbits`,key:`orbitCount`,label:`orbits`,kind:`number`,default:8,min:1,max:20,step:1,hint:`pendulums, all following the same energy; each starts at a random place`},{group:`orbits`,key:`colors`,label:`colors`,kind:`text`,default:`#d6b37a, #7fa8cf, #c48bb8, #93bf8a, #d48f7f, #a9a6e0`,hint:`comma-separated CSS colors; orbit n uses color n (cycling)`,live:!0},...Array.from({length:6},(e,t)=>[{group:`orbits`,key:`slot${t+1}Instrument`,label:`instrument ${t+1}`,kind:`select`,default:Te[t][0],options:N,hint:`orbits ${t+1}, ${t+1+6}, ${t+1+12}, … play this instrument`},{group:`orbits`,key:`slot${t+1}Octave`,label:`octave ${t+1}`,kind:`number`,default:Te[t][1],min:-3,max:3,step:1,hint:`register shift for this instrument`}]).flat(),B(`modalCustom`,{group:`orbits`,hint:`for “modal: custom” in any slot: paste JSON from modal-synth’s Copy button`}),{group:`orbits`,key:`reverbTime`,label:`reverb time`,kind:`number`,default:3.5,min:.3,max:12,log:!0,unit:`s`,hint:`one reverb shared by all the orbit instruments (each sends its preset's reverb amount)`},B(`scale`,{default:`dorian`}),...[`root`,`pitchSource`,`thetaRange`,`pitchLow`,`pitchHigh`,`pitchCurve`,`invertPitch`,`p2Ref`,`loudCurve`,`loudFloor`,`notesLevel`,`noteLength`].map(e=>B(e)),...I.filter(e=>e.group===`hum`),B(`fade`,{default:20,hint:`how long each live crossing dot stays visible`}),...[`plotZoom`,`zoomSmooth`,`plotP`].map(e=>B(e)),B(`pointSize`,{default:2.5}),B(`orbits`,{key:`portrait`,group:`portrait`,label:`show portrait`,hint:`grey background: the section's structure at the current energy`}),B(`orbitCount`,{key:`portraitCount`,group:`portrait`}),B(`orbitCpu`,{key:`portraitCpu`,group:`portrait`}),B(`orbitLife`,{key:`portraitLife`,group:`portrait`}),B(`orbitBand`,{key:`portraitBand`,group:`portrait`}),B(`orbitMinHold`,{key:`portraitMinHold`,group:`portrait`}),B(`orbitMaxPoints`,{key:`portraitMaxPoints`,group:`portrait`}),B(`orbitXfade`,{key:`portraitXfade`,group:`portrait`}),B(`orbitAlpha`,{key:`portraitAlpha`,group:`portrait`,default:.15}),B(`orbitSize`,{key:`portraitSize`,group:`portrait`}),{group:`portrait`,key:`traces`,label:`trace orbits`,kind:`bool`,default:!0,hint:`with each portrait, follow every pendulum from its current state (energy frozen) and draw the orbit it's on, in its color`,live:!0},{group:`portrait`,key:`traceMax`,label:`trace length`,kind:`number`,default:1500,min:50,max:1e4,log:!0,hint:`crossings computed per orbit trace`,live:!0},{group:`portrait`,key:`traceAlpha`,label:`trace brightness`,kind:`number`,default:.75,min:.02,max:1,step:.01,live:!0},{group:`portrait`,key:`traceSize`,label:`trace point size`,kind:`number`,default:1.5,min:.5,max:4,step:.1,unit:`px`,live:!0}],De=50;function Oe(e,t){e.classList.add(`c02`);let n=document.createElement(`canvas`);e.append(n);let r=new fe(n),i=0,a=!1,o=new de(()=>i,()=>a),s=e=>({show:e.portrait,count:e.portraitCount,cpu:e.portraitCpu,life:e.portraitLife,band:e.portraitBand,minHold:e.portraitMinHold,maxPoints:e.portraitMaxPoints,xfade:e.portraitXfade,alpha:e.portraitAlpha,size:e.portraitSize,tracks:e.traces,trackMax:e.traceMax,trackAlpha:e.traceAlpha,trackSize:e.traceSize}),c=t=>{let n=String(t.colors).split(`,`).map(e=>e.trim()).filter(Boolean);return n.length?n:[R(e,`--fg`)]},l=new Float64Array(2),u=null,d=0;return{keep:e=>4.6*e.fade+.5,draw(n,f,p){let m=t();i=n,a=p,f!==u&&(u=f,o.reset());let h=xe(m);l.length!==2+5*h&&(l=new Float64Array(2+5*h));let g=f?.at(0,n,l)??null,_=m.massRatio,v=m.lengthRatio,y=performance.now();if(y-d>De){d=y;let e=[];if(g)for(let t=0;t<h;t++)g[2+5*t+4]>.5&&e.push({id:t,y:[g[2+5*t],g[3+5*t],g[4+5*t],g[5+5*t]]});o.post(p,s(m),g?g[0]:0,_,v,e)}let b=r.begin(m,g?g[1]:null,{m1:1,l1:1,g:1,m2:_,l2:v},ge(_,v),R(e,`--dim`)),x=c(m);if(o.draw(b,n,s(m),R(e,`--fg`),e=>x[e%x.length]),f){let e=m.fade,t=m.pointSize;for(let r of f.events){let i=n-r.t;if(i<0)break;z(b,r.th2,r.p2,i,e,t,x[r.o%x.length])}}},readouts:()=>({portrait:o.describe()}),dispose(){o.dispose(),e.classList.remove(`c02`)}}}var ke={id:`02-orbits`,schema:Ee,layout:Ce,estimateLength:we,view:Oe},Ae={id:ke.id,title:`orbits`,schema:Ee,defaults:be,create:(e,t)=>A(ke,e,t)},je={freeTime:40,dampTime:20,dampCurve:1.5,tau:2,restEnergy:.001,finalHold:2,finalFade:5,count:12,releaseAngle:120,jitter:3,separateAt:8,sepThreshold:.02,speed:2.5,massRatio:1,lengthRatio:1,seed:0,instrument:`modal: Vibraphone`,modalCustom:``,pitchMode:`chord`,directionChords:!0,scale:`dorian`,root:`D`,pitchLow:50,pitchHigh:86,loudRef:.6,loudCurve:1,loudFloor:.08,notesLevel:-8,noteLength:2,directionPan:.35,reverbTime:3.5,trails:!0,trailLength:3,trailWidth:1.2,armAlpha:.75,bobSize:3,saturation:35};function Me(e){let t=P(e.instrument,e.modalCustom);return{stems:[{kind:`synth`,sound:t,output:0},{kind:`synth`,sound:t,output:1}],outputs:[{effects:`shared`,sound:t,level:e=>e.notesLevel,pan:e=>-e.directionPan},{effects:`shared`,sound:t,level:e=>e.notesLevel,pan:e=>e.directionPan}],reverbTime:e.reverbTime}}function Ne(e){return e.freeTime+e.dampTime+1+e.finalHold+e.finalFade+.3}var V=(e,t={})=>{let n=I.find(t=>t.key===e);if(!n)throw Error(`no setting ${e} in composition 1`);return{...n,...t}},Pe=[{group:`form`,key:`freeTime`,label:`swinging`,kind:`number`,default:40,min:5,max:600,step:1,unit:`s`,hint:`free (undamped) swinging before the damping begins`},{group:`form`,key:`dampTime`,label:`damping`,kind:`number`,default:20,min:2,max:300,step:.5,unit:`s`,hint:`time for the damping to bring every pendulum to rest`},{group:`form`,key:`dampCurve`,label:`damping curve`,kind:`number`,default:1.5,min:.3,max:5,log:!0,hint:`energy follows (1 − u)^curve during the damping; >1 settles fast then lingers`},{group:`form`,key:`tau`,label:`damping follow`,kind:`number`,default:2,min:.1,max:50,log:!0,unit:`sim s`,hint:`how closely each pendulum's energy follows the damping curve`},V(`restEnergy`,{hint:`after the damping, a pendulum counts as at rest below this energy: its last note rings out`}),V(`finalHold`),V(`finalFade`),{group:`pendulums`,key:`count`,label:`pendulums`,kind:`number`,default:12,min:1,max:24,step:1},{group:`pendulums`,key:`releaseAngle`,label:`release angle`,kind:`number`,default:120,min:10,max:179,step:1,unit:`°`,hint:`both arms released from rest at this angle from straight down`},{group:`pendulums`,key:`jitter`,label:`angle variation`,kind:`number`,default:3,min:0,max:30,step:.1,unit:`°`,hint:`each play varies the release angles by up to this much (seed fixes it)`},{group:`pendulums`,key:`separateAt`,label:`separate after`,kind:`number`,default:8,min:1,max:60,step:.5,unit:`s`,hint:`the tiny offsets between pendulums are calibrated so the outermost visibly separate at about this time`},{group:`pendulums`,key:`sepThreshold`,label:`“visibly”`,kind:`number`,default:.02,min:.001,max:.5,log:!0,hint:`bob separation (fraction of the pendulum's length) that counts as separated`},{group:`pendulums`,key:`speed`,label:`speed`,kind:`number`,default:2.5,min:.25,max:20,log:!0,unit:`×`,hint:`simulated seconds per real second`},V(`massRatio`,{group:`pendulums`}),V(`lengthRatio`,{group:`pendulums`}),V(`seed`,{group:`pendulums`,hint:`0 = a different release every play`}),{group:`notes`,key:`instrument`,label:`instrument`,kind:`select`,default:`modal: Vibraphone`,options:N},V(`modalCustom`),{group:`notes`,key:`pitchMode`,label:`pitch`,kind:`select`,default:`chord`,options:[`chord`,`motion`],hint:`chord: each pendulum has its own note of a chord spread over the range. motion: pitch from the bob's speed at the crossing`},{group:`notes`,key:`directionChords`,label:`two chords`,kind:`bool`,default:!0,hint:`chord mode: left-to-right and right-to-left crossings play two interleaved chords, so the swings alternate between them`},V(`scale`,{default:`dorian`}),V(`root`),V(`pitchLow`,{default:50}),V(`pitchHigh`,{default:86}),{group:`notes`,key:`loudRef`,label:`speed for full`,kind:`number`,default:.6,min:.05,max:1,step:.01,hint:`bob speed (fraction of the fastest possible at release energy) that gives full loudness (and top pitch in motion mode)`},V(`loudCurve`),V(`loudFloor`),V(`notesLevel`,{default:-8,live:!0}),V(`noteLength`,{default:2}),{group:`notes`,key:`directionPan`,label:`pan with direction`,kind:`number`,default:.35,min:0,max:1,step:.01,hint:`a crossing is panned toward the side the bob is heading`,live:!0},{group:`notes`,key:`reverbTime`,label:`reverb time`,kind:`number`,default:3.5,min:.3,max:12,log:!0,unit:`s`},{group:`visual`,key:`trails`,label:`trails`,kind:`bool`,default:!0,live:!0},{group:`visual`,key:`trailLength`,label:`trail length`,kind:`number`,default:3,min:.2,max:20,log:!0,unit:`s`,live:!0},{group:`visual`,key:`trailWidth`,label:`trail width`,kind:`number`,default:1.2,min:.3,max:5,step:.1,unit:`px`,live:!0},{group:`visual`,key:`armAlpha`,label:`arm opacity`,kind:`number`,default:.75,min:.05,max:1,step:.01,live:!0},{group:`visual`,key:`bobSize`,label:`bob size`,kind:`number`,default:3,min:.5,max:10,step:.1,unit:`px`,live:!0},{group:`visual`,key:`saturation`,label:`color saturation`,kind:`number`,default:35,min:0,max:100,step:1,unit:`%`,live:!0}];function Fe(e,t){let n=Math.PI/180,r=e.releaseAngle*n,i=e.jitter*n;return t?[r+(2*t()-1)*i,r+(2*t()-1)*i]:[r,r]}var Ie=1/120;function Le(e,t){e.classList.add(`c03`);let n=document.createElement(`canvas`);e.append(n);let r=new Float64Array,i=(e,t,n)=>`hsl(${((30+360*t/Math.max(1,n))%360).toFixed(0)} ${e.saturation}% 70%)`;return{keep:e=>e.trailLength+.5,draw(a,o){let s=t(),c=L(n),l=n.clientWidth,u=n.clientHeight;c.clearRect(0,0,l,u);let d=Math.max(1,Math.round(s.count)),f=s.lengthRatio,p=.46*Math.min(l,u)/(1+f),m=l/2,h=u/2,g=(e,t)=>{let n=m+p*1*Math.sin(e),r=h+p*1*Math.cos(e);return[n,r,n+p*f*Math.sin(t),r+p*f*Math.cos(t)]};if(s.trails&&o){let e=s.trailLength;c.lineWidth=s.trailWidth,c.lineJoin=c.lineCap=`round`;for(let t=0;t<d;t++){c.strokeStyle=i(s,t,d);for(let n=0;n<6;n++){let r=a-n*e/6,i=a-(n+1)*e/6;c.globalAlpha=.7*(1-(n+.5)/6),c.beginPath();let s=!1;o.rows(0,i-Ie,Math.min(a,r+Ie),(e,n)=>{let[,,r,i]=g(e[n+1+2*t],e[n+2+2*t]);s?c.lineTo(r,i):(c.moveTo(r,i),s=!0)}),c.stroke()}}c.globalAlpha=1}r.length!==2*d&&(r=new Float64Array(2*d));let _=o?.at(0,a,r)??null,[v,y]=Fe(s,null);c.lineWidth=1.5,c.lineCap=`round`;let b=s.bobSize;for(let e=d-1;e>=0;e--){let[t,n,r,a]=_?g(_[2*e],_[2*e+1]):g(v,y),o=i(s,e,d);c.strokeStyle=o,c.fillStyle=o,c.globalAlpha=s.armAlpha,c.beginPath(),c.moveTo(m,h),c.lineTo(t,n),c.lineTo(r,a),c.stroke(),c.globalAlpha=1,c.beginPath(),c.arc(t,n,b*.8,0,2*Math.PI),c.moveTo(r+b,a),c.arc(r,a,b,0,2*Math.PI),c.fill()}c.fillStyle=R(e,`--fg`),c.beginPath(),c.arc(m,h,1.5,0,2*Math.PI),c.fill()},dispose(){e.classList.remove(`c03`)}}}var H={id:`03-divergence`,schema:Pe,layout:Me,estimateLength:Ne,view:Le},Re={id:H.id,title:`divergence`,schema:Pe,defaults:je,create:(e,t)=>A(H,e,t)},ze={fallAfter:2.5,freeTime:60,dampTime:20,dampBase:.004,dampEnd:.2,restEnergy:.001,finalHold:2,finalFade:5,speed:1.5,tipThreshold:.02,massRatio:1,lengthRatio:1,seed:0,extInstrument:`modal: Violin`,modalCustom:``,extPitch:55,minDepth:.25,extLength:.4,firstVel:1,maxVel:.6,loudRef:.8,loudCurve:1,loudFloor:.15,notesLevel:2,maxOverlap:4,click:!0,clickInstrument:`modal: Viola`,clickPitch:72,clickLength:.5,clickMaxVel:.7,clickLevel:-8,heightNotes:!0,heightInstrument:`modal: Piano-ish`,heightLow:60,heightHigh:96,scale:`dorian`,root:`D`,heightStep:2,heightLength:.3,heightVel:.7,heightLevel:14,heightRamp:6,heightRampFrom:.5,heightFollow:.3,trails:!0,trailLength:2.5,rings:!0,motionBlur:1};function Be(e){let t=e.modalCustom,n=P(e.extInstrument,t,{voices:Math.round(e.maxOverlap)}),r=P(e.clickInstrument,t),i=P(e.heightInstrument,t);return{stems:[{kind:`synth`,sound:n,output:0},{kind:`synth`,sound:r,output:1},{kind:`synth`,sound:i,output:2}],outputs:[{effects:`own`,sound:n,level:e=>e.notesLevel},{effects:`own`,sound:r,level:e=>e.clickLevel},{effects:`own`,sound:i,level:e=>e.heightLevel}]}}function Ve(e){return e.freeTime+e.dampTime+3+e.finalHold+e.finalFade+.3}var U=(e,t={})=>{let n=I.find(t=>t.key===e);if(!n)throw Error(`no setting ${e} in composition 1`);return{...n,...t}},He=[{group:`form`,key:`fallAfter`,label:`tips after`,kind:`number`,default:2.5,min:1,max:30,step:.5,unit:`s`,hint:`the nudge from straight up is calibrated so the pendulum visibly tips at about this time`},{group:`form`,key:`freeTime`,label:`swinging`,kind:`number`,default:60,min:5,max:600,step:1,unit:`s`,hint:`time before the stronger damping begins`},{group:`form`,key:`dampTime`,label:`damping`,kind:`number`,default:20,min:2,max:300,step:.5,unit:`s`,hint:`time over which the damping grows to its final strength`},{group:`form`,key:`dampBase`,label:`slight damping`,kind:`number`,default:.004,min:0,max:.1,step:5e-4,unit:`/sim s`,hint:`friction throughout (energy loses roughly this fraction per simulated second)`},{group:`form`,key:`dampEnd`,label:`final damping`,kind:`number`,default:.2,min:.01,max:2,log:!0,unit:`/sim s`,hint:`friction reached by the end of the damping`},U(`restEnergy`,{hint:`after the damping, the pendulum counts as at rest below this energy: the last extension note rings out`}),U(`finalHold`),U(`finalFade`),{group:`pendulum`,key:`speed`,label:`speed`,kind:`number`,default:1.5,min:.25,max:20,log:!0,unit:`×`,hint:`simulated seconds per real second`},{group:`pendulum`,key:`tipThreshold`,label:`“visibly”`,kind:`number`,default:.02,min:.001,max:.5,log:!0,hint:`sideways bob movement (fraction of the length) that counts as tipping`},U(`massRatio`,{group:`pendulum`}),U(`lengthRatio`,{group:`pendulum`}),U(`seed`,{group:`pendulum`,hint:`0 = a different nudge (side and shape) every play`}),{group:`extension`,key:`extInstrument`,label:`instrument`,kind:`select`,default:`modal: Violin`,options:N},U(`modalCustom`,{group:`extension`}),{group:`extension`,key:`extPitch`,label:`pitch`,kind:`number`,default:55,min:12,max:108,step:.5,unit:`midi`},{group:`extension`,key:`extLength`,label:`length`,kind:`number`,default:.4,min:.05,max:5,log:!0,unit:`s`},{group:`extension`,key:`firstVel`,label:`first note`,kind:`number`,default:1,min:.05,max:1,step:.01,hint:`strength of the first extension note (accent)`},{group:`extension`,key:`maxVel`,label:`strongest`,kind:`number`,default:.6,min:.05,max:1,step:.01,hint:`strength of later extension notes at full speed`},{group:`extension`,key:`loudRef`,label:`speed for full`,kind:`number`,default:.8,min:.05,max:1,step:.01,hint:`bob speed (fraction of the fastest possible) that gives the strongest note`},U(`loudCurve`,{group:`extension`}),U(`loudFloor`,{group:`extension`,default:.15}),U(`notesLevel`,{group:`extension`,default:2,max:18,live:!0}),{group:`extension`,key:`maxOverlap`,label:`overlapping notes`,kind:`number`,default:4,min:1,max:16,step:1,hint:`most extension notes ringing at once (a new one replaces the quietest)`},{group:`click`,key:`minDepth`,label:`near the pivot`,kind:`number`,default:.25,min:0,max:.95,step:.01,hint:`a click when the outer bob crosses the vertical within this distance of the pivot (fraction of the length)`},{group:`click`,key:`click`,label:`click`,kind:`bool`,default:!0,hint:`a click when the outer bob passes the pivot (closer than the minimum depth)`},{group:`click`,key:`clickInstrument`,label:`instrument`,kind:`select`,default:`modal: Viola`,options:N},{group:`click`,key:`clickPitch`,label:`pitch`,kind:`number`,default:72,min:24,max:120,step:.5,unit:`midi`},{group:`click`,key:`clickLength`,label:`length`,kind:`number`,default:.5,min:.01,max:2,log:!0,unit:`s`},{group:`click`,key:`clickMaxVel`,label:`strongest`,kind:`number`,default:.7,min:.05,max:1,step:.01,hint:`strength at full bob speed (follows the speed like the extension notes)`},{group:`click`,key:`clickLevel`,label:`level`,kind:`number`,default:-8,min:-48,max:6,step:.5,unit:`dB`,live:!0},{group:`height`,key:`heightNotes`,label:`height notes`,kind:`bool`,default:!0,hint:"levels are the scale's notes between the low and high pitch (every `step`-th); passing one, up or down, plays it"},{group:`height`,key:`heightInstrument`,label:`instrument`,kind:`select`,default:`modal: Piano-ish`,options:N},{group:`height`,key:`heightLow`,label:`pitch at bottom`,kind:`number`,default:60,min:24,max:108,step:.5,unit:`midi`,hint:`bob straight down`},{group:`height`,key:`heightHigh`,label:`pitch at top`,kind:`number`,default:96,min:24,max:120,step:.5,unit:`midi`,hint:`bob straight up`},U(`scale`,{group:`height`,default:`dorian`}),U(`root`,{group:`height`}),{group:`height`,key:`heightStep`,label:`step`,kind:`number`,default:2,min:1,max:7,step:1,hint:`levels every this many scale notes (2 = arpeggio-like)`},{group:`height`,key:`heightLength`,label:`length`,kind:`number`,default:.3,min:.05,max:3,log:!0,unit:`s`},{group:`height`,key:`heightVel`,label:`strength`,kind:`number`,default:.7,min:.05,max:1,step:.01},{group:`height`,key:`heightLevel`,label:`level`,kind:`number`,default:14,min:-48,max:18,step:.5,unit:`dB`,live:!0},{group:`height`,key:`heightRamp`,label:`ramp in`,kind:`number`,default:6,min:0,max:60,step:.5,unit:`s`,hint:`the notes grow to full strength over the opening`},{group:`height`,key:`heightRampFrom`,label:`ramp from`,kind:`number`,default:.5,min:0,max:1,step:.01,hint:`starting strength, as a fraction of full`},{group:`height`,key:`heightFollow`,label:`fades with energy`,kind:`number`,default:.3,min:0,max:2,step:.05,hint:`strength × (energy / start energy)^this`},{group:`visual`,key:`trails`,label:`trail`,kind:`bool`,default:!0,live:!0},{group:`visual`,key:`trailLength`,label:`trail length`,kind:`number`,default:2.5,min:.2,max:20,log:!0,unit:`s`,live:!0},{group:`visual`,key:`rings`,label:`rings`,kind:`bool`,default:!0,hint:`a brief ring where each extension note (and, smaller, each click) happens`,live:!0},U(`motionBlur`)],Ue=48,We=2,Ge=.9,Ke=.35;function qe(e,t){e.classList.add(`c04`);let n=document.createElement(`canvas`);e.append(n);let r=new Float64Array(2),i=0,a=1/60;return{keep:e=>Math.max(e.trailLength,Ge)+.5,draw(o,s,c){let l=t(),u=performance.now()/1e3,d=u-i;i=u,d>0&&d<.1&&(a+=(d-a)*.1);let f=L(n),p=n.clientWidth,m=n.clientHeight;f.clearRect(0,0,p,m);let h=R(e,`--fg`),g=l.lengthRatio,_=.46*Math.min(p,m)/(1+g),v=p/2,y=m/2,b=(e,t)=>{let n=v+_*1*Math.sin(e),r=y+_*1*Math.cos(e);return[n,r,n+_*g*Math.sin(t),r+_*g*Math.cos(t)]},x=e=>{let t=s?.at(0,e,r);return t?[t[0],t[1]]:[Math.PI,Math.PI]};if(l.trails&&s){let e=l.trailLength;f.strokeStyle=h,f.lineWidth=1,f.lineJoin=f.lineCap=`round`;for(let t=0;t<6;t++){let n=o-t*e/6,r=o-(t+1)*e/6;f.globalAlpha=.45*(1-(t+.5)/6),f.beginPath();let i=!1,a=0;s.rows(0,r-.01,Math.min(o,n+.01),(e,t)=>{if(a++%2)return;let[,,n,r]=b(e[t+1],e[t+2]);i?f.lineTo(n,r):(f.moveTo(n,r),i=!0)}),f.stroke()}f.globalAlpha=1}if(l.rings&&s){for(let e of s.events){if(e.kind!==`ring`)continue;let t=o-e.t,n=e.click===1,r=n?Ke:Ge;if(t<0||t>r)continue;let i=e.strength,a=v+_*e.x,s=y+_*e.y;f.strokeStyle=h,f.globalAlpha=(1-t/r)*(.4+.6*i),f.lineWidth=n?1:1.2,f.beginPath();let c=n?14:60*(.5+i);f.arc(a,s,(n?3:6)+c*Math.sqrt(t/r),0,2*Math.PI),f.stroke()}f.globalAlpha=1}let S=c?l.motionBlur*a:0,C=1;if(S>0){let e=0,t=x(o);for(let n=1;n<=8;n++){let r=x(o-S*n/8);e+=_*(+Math.abs(r[0]-t[0])+g*Math.abs(r[1]-t[1])),t=r}C=Math.max(2,Math.min(Ue,Math.ceil(e/We)))}let w=C===1?1:1-.03**(1/C),T=4*Math.cbrt(l.massRatio);f.strokeStyle=h,f.fillStyle=h,f.lineWidth=1.5,f.lineCap=`round`,f.globalAlpha=w;for(let e=0;e<C;e++){let[t,n]=x(o-S*e/Math.max(1,C-1)),[r,i,a,s]=b(t,n);f.beginPath(),f.moveTo(v,y),f.lineTo(r,i),f.lineTo(a,s),f.stroke(),f.beginPath(),f.arc(r,i,4,0,2*Math.PI),f.moveTo(a+T,s),f.arc(a,s,T,0,2*Math.PI),f.fill()}f.globalAlpha=1,f.beginPath(),f.arc(v,y,1.5,0,2*Math.PI),f.fill()},dispose(){e.classList.remove(`c04`)}}}var W={id:`04-descent`,schema:He,layout:Be,estimateLength:Ve,view:qe},Je={id:W.id,title:`descent`,schema:He,defaults:ze,create:(e,t)=>A(W,e,t)},Ye={basePitch:73.42,sizeExp:.5,trail:.35,score:`36 25 36 25 36 25 1!4`,tempo:120,stepBeats:4,pulseAdds:.08,accent:4,tail:16,seed:0,fade:6,signal:`x2`,gain:0,spread:.7,dcCut:20,level:0,ratio1:`1`,partial1:`2`,shape1:1,ring1:20,level1:0,ratio2:`3/2`,partial2:`2`,shape2:1.3,ring2:18,level2:-6,ratio3:`2`,partial3:`3/2`,shape3:.8,ring3:16,level3:-6,ratio4:`5/2`,partial4:`2`,shape4:1.6,ring4:14,level4:-6,ratio5:`3`,partial5:`2`,shape5:.7,ring5:12,level5:-6,ratio6:`4`,partial6:`3/2`,shape6:1.2,ring6:10,level6:-6};function Xe(){return{stems:[{kind:`score`,output:0}],outputs:[{effects:`none`,level:e=>e.level}]}}var Ze=.4;function Qe(e,t,n){return e.trim().split(/\s+/).filter(Boolean).map(e=>{let r=[];for(let i=0;i<e.length;i++)/[1-6]/.test(e[i])&&r.push({i:Number(e[i])-1,add:t*(e[i+1]===`!`?n:1)});return r})}var $e=e=>e.stepBeats*60/Math.max(1,e.tempo),et=e=>Ze+Qe(e.score,0,1).length*$e(e),tt=e=>et(e)+e.tail,G=[`x2`,`y2`,`vx2`,`vy2`,`x1`,`vx1`,`θ1`,`θ2`,`θ2−θ1`,`ω1`,`ω2`,`p1`,`p2`,`speed2`];function K(e,t){let n=1+e,r=e*t,i=e*t*t,a=1+e,o=e*t,s=n*i-r*r,c=(a*i+o*n)/s,l=a*o/s,u=Math.sqrt(Math.max(0,c*c-4*l));return[Math.sqrt((c-u)/2),Math.sqrt((c+u)/2)]}function nt(e,t){let n=1e-4,r=1e4,i=e=>{let[n,r]=K(e,t);return r/n};if(i(n)>=e)return n;if(i(r)<=e)return r;for(let t=0;t<80;t++){let t=Math.sqrt(n*r);i(t)<e?n=t:r=t}return Math.sqrt(n*r)}function rt(e){let[t,n]=e.split(`/`).map(Number);return n?t/n:t}function it(e,t,n,r,i){let a=nt(n,r),[o,s]=K(a,r),c=2*Math.PI*e*t,l=o*i/c,u=l*l;return{l1:u,l2:r*u,m2:a,lower:e*t,upper:e*t*(s/o)}}function at(e,t,n,r){let[i]=K(nt(n,r),r);return 2*Math.PI*e*t/i}var ot=`1.16/15.9/8.6/5.5/4.4/3.45/32.3/2.8/5.5/3.9/5.15/8.2.9/4.12/5.5/2.8/3.3.16/5.10/3.15/4.4.9/2.5.6.8`.split(`.`),st=[`5/4`,`4/3`,`3/2`,`5/3`,`2`,`5/2`,`3`,`4`,`5`,`6`,`8`],ct=[[`1`,`2`,1,20],[`3/2`,`2`,1.3,18],[`2`,`3/2`,.8,16],[`5/2`,`2`,1.6,14],[`3`,`2`,.7,12],[`4`,`3/2`,1.2,10]],lt=[{group:`harmony`,key:`basePitch`,label:`base pitch`,kind:`number`,default:73.42,min:20,max:1e3,log:!0,unit:`Hz`,hint:`pitch ratio 1 sounds here (D2 by default); all pendulums share one time scale, so each pitch comes from its size`},{group:`visual`,key:`sizeExp`,label:`size drawing`,kind:`number`,default:.5,min:0,max:1,step:.05,hint:`drawn size ∝ length^this (1 = true scale: two octaves = 16× the length)`,live:!0},{group:`visual`,key:`trail`,label:`trail`,kind:`number`,default:.35,min:0,max:1,step:.01,hint:`opacity of the bobs' recent paths`,live:!0},{group:`score`,key:`score`,label:`score`,kind:`text`,default:`36 25 36 25 36 25 1!4`,hint:`one step per word: the pendulums pushed together (1–6); ! after a digit = accented; . = a rest`},{group:`score`,key:`tempo`,label:`tempo`,kind:`number`,default:120,min:10,max:400,log:!0,unit:`bpm`},{group:`score`,key:`stepBeats`,label:`step length`,kind:`number`,default:4,min:.25,max:16,step:.25,unit:`beats`,hint:`4 = a whole note per step`},{group:`score`,key:`pulseAdds`,label:`push adds`,kind:`number`,default:.08,min:5e-4,max:2,log:!0,hint:`energy each push adds, in units of E_top`},{group:`score`,key:`accent`,label:`accent`,kind:`number`,default:4,min:1,max:20,log:!0,unit:`×`,hint:`an accented push (!) adds this many times the energy`},{group:`score`,key:`tail`,label:`ring out`,kind:`number`,default:16,min:1,max:120,log:!0,unit:`s`,hint:`after the last step, before the end`},{group:`score`,key:`seed`,label:`seed`,kind:`number`,default:0,min:0,max:999999,step:1,hint:`pushes from rest go in random directions (the mix of each pendulum's two pitches); 0 = a new variation every play`},{group:`score`,key:`fade`,label:`fade`,kind:`number`,default:6,min:.1,max:60,log:!0,unit:`s`,hint:`the last part of the ring-out fades to silence`},{group:`sound`,key:`signal`,label:`signal`,kind:`select`,default:`x2`,options:[...G],hint:`what each pendulum contributes (bob position, velocity, angles…)`},{group:`sound`,key:`gain`,label:`gain`,kind:`number`,default:0,min:-40,max:30,step:.5,unit:`dB`,hint:`per pendulum, before its soft limiter`},{group:`sound`,key:`spread`,label:`stereo spread`,kind:`number`,default:.7,min:0,max:1,step:.01},{group:`sound`,key:`dcCut`,label:`low cut`,kind:`number`,default:20,min:1,max:500,log:!0,unit:`Hz`},{group:`sound`,key:`level`,label:`level`,kind:`number`,default:0,min:-48,max:12,step:.5,unit:`dB`,live:!0},...ct.flatMap(([e,t,n,r],i)=>{let a=`pendulum ${i+1}`;return[{group:a,key:`ratio${i+1}`,label:`pitch ratio`,kind:`select`,default:e,options:ot,hint:`lower partial = base pitch × this (sets the size)`},{group:a,key:`partial${i+1}`,label:`partials`,kind:`select`,default:t,options:st,hint:`upper/lower partial interval (sets the mass ratio)`},{group:a,key:`shape${i+1}`,label:`l2 / l1`,kind:`number`,default:n,min:.2,max:5,log:!0,hint:`the pendulum's shape`},{group:a,key:`ring${i+1}`,label:`ring time`,kind:`number`,default:r,min:.05,max:60,log:!0,unit:`s`},{group:a,key:`level${i+1}`,label:`level`,kind:`number`,default:-6,min:-48,max:12,step:.5,unit:`dB`}]})];function q(e){let t=e.basePitch,n=Array.from({length:6},(t,n)=>({ratio:rt(e[`ratio${n+1}`]),partial:rt(e[`partial${n+1}`]),shape:e[`shape${n+1}`]})),r=n.reduce((e,t)=>t.ratio<e.ratio?t:e),i=at(t,r.ratio,r.partial,r.shape);return{k:i,built:n.map(e=>it(t,e.ratio,e.partial,e.shape,i))}}var ut=.012;function dt(e,t,n){let r=1.5,i=.2,a=e.reduce((e,t)=>e+r*t,0)+i*(e.length-1),o=Math.min(.92*t/a,.5*n/Math.max(...e)),s=n/2-Math.max(...e)*o/2,c=(t-a*o)/2;return{unit:o,at:e.map(e=>{let t={x:c+r/2*e*o,y:s};return c+=(r*e+i)*o,t})}}function ft(e,t){e.classList.add(`c05`);let n=document.createElement(`canvas`);e.append(n);let r=new Float64Array(24),i=``,a=q(t()).built;return{keep:()=>1.5,draw(o,s){let c=t(),l=JSON.stringify([c.basePitch,...Array.from({length:6},(e,t)=>[c[`ratio${t+1}`],c[`partial${t+1}`],c[`shape${t+1}`]])]);l!==i&&(i=l,a=q(c).built);let u=L(n),d=n.clientWidth,f=n.clientHeight;u.clearRect(0,0,d,f);let p=R(e,`--fg`),m=R(e,`--muted`),h=c.sizeExp,g=a.map(e=>e.l1+e.l2),_=g.map(e=>e**+h),{unit:v,at:y}=dt(_,d,f),b=s?.at(0,o,r)??null,x=c.trail,S=[,,,,,,].fill(-1/0);if(s)for(let e of s.events)e.kind===`push`&&e.t<=o&&(S[e.i]=e.t);u.lineCap=`round`,u.lineJoin=`round`;for(let e=0;e<6;e++){let{x:t,y:n}=y[e],r=v*_[e]/g[e];if(s&&x>0){u.strokeStyle=m,u.globalAlpha=x,u.lineWidth=1,u.beginPath();let i=!1;s.rows(1,o-ut,o,(a,o)=>{let s=t+r*a[o+1+2*e],c=n+r*a[o+2+2*e];i?u.lineTo(s,c):(u.moveTo(s,c),i=!0)}),u.stroke()}let i=a[e],c=b?b.subarray(4*e,4*e+4):[0,i.l1,0,g[e]],l=t+r*c[0],d=n+r*c[1],f=t+r*c[2],h=n+r*c[3];u.globalAlpha=.6+.4*Math.max(0,1-(o-S[e])),u.strokeStyle=p,u.fillStyle=p,u.lineWidth=1.5,u.beginPath(),u.moveTo(t,n),u.lineTo(l,d),u.lineTo(f,h),u.stroke();let C=2.2*Math.cbrt(i.m2)+1;u.beginPath(),u.arc(l,d,2,0,2*Math.PI),u.moveTo(f+C,h),u.arc(f,h,C,0,2*Math.PI),u.moveTo(t+1.5,n),u.arc(t,n,1.5,0,2*Math.PI),u.fill()}u.globalAlpha=1},readouts(){let{k:e}=q(t()),n={"time scale":`${e.toFixed(0)} sim s per s`};return a.forEach((e,t)=>{n[`pendulum ${t+1}`]=`${e.lower.toFixed(1)} + ${e.upper.toFixed(1)} Hz; l1 ${e.l1.toFixed(3)}, l2 ${e.l2.toFixed(3)}, m2/m1 ${e.m2.toFixed(2)}`}),n},dispose(){e.classList.remove(`c05`)}}}var pt={id:`05-ensemble`,schema:lt,layout:Xe,estimateLength:tt,view:ft},mt={id:pt.id,title:`ensemble`,schema:lt,defaults:Ye,create:(e,t)=>A(pt,e,t)},ht={mode:`strike`,strikeEnergy:.3,energy:1,pitch:110,ringTime:4,restrike:5,swellTime:2,follow:3,left:`x2`,right:`x1`,gain:-6,dcCut:15,level:-12,massRatio:1,lengthRatio:1,trailMs:12},gt=new URL(`pendulumWorklet-BpTttuTz.js`,import.meta.url).href,_t=new WeakMap;function vt(e,t){let n=document.createElement(`canvas`);n.title=`click (or press S) to strike`,n.style.cursor=`pointer`,e.append(n);let i=null,a=null,o=null,s=null,c,l=!1,u=0,d=null,f=``,p=0,m=e=>({mode:e.mode,pitch:e.pitch,energy:e.energy,strikeEnergy:e.strikeEnergy,ringTime:e.ringTime,restrike:e.restrike,swellTime:e.swellTime,massRatio:e.massRatio,lengthRatio:e.lengthRatio,left:e.left,right:e.right,gain:r(e.gain),dcCut:e.dcCut,follow:e.follow}),h=e=>a?.port.postMessage(e),g=()=>h({type:`strike`});n.onclick=g;let _=e=>{let t=e.target;e.key!==`s`&&e.key!==`S`||t instanceof Element&&t.closest(`input, select, textarea`)||g()};window.addEventListener(`keydown`,_);function v(){if(!a||!i||!o)return;let e=t(),n=m(e),s=JSON.stringify(n);s!==f&&(f=s,h({type:`settings`,s:n})),o.gain.setTargetAtTime(r(e.level),i.ctx.currentTime,.05)}async function y(e){b();let t=++p;i=e;let n=e.ctx,r=_t.get(n);r||_t.set(n,r=n.audioWorklet.addModule(gt)),await r,t===p&&(o=n.createGain(),o.gain.value=0,s=n.createAnalyser(),s.fftSize=4096,s.smoothingTimeConstant=.6,a=new AudioWorkletNode(n,`pendulum-voice`,{numberOfInputs:0,outputChannelCount:[2]}),a.port.onmessage=e=>d=e.data,a.connect(o),o.connect(e.input),o.connect(s),f=``,v(),l=!0,u=n.currentTime,c=window.setInterval(v,50))}function b(){if(p++,c!==void 0&&window.clearInterval(c),c=void 0,l=!1,!i)return;let e=o,t=a,n=s;e&&e.gain.setTargetAtTime(0,i.ctx.currentTime,.03),window.setTimeout(()=>{t?.disconnect(),e?.disconnect(),n?.disconnect()},300),a=o=s=null}let x=new Float32Array(2048),S=null;function C(){let r=t(),a=L(n),o=n.clientWidth,c=n.clientHeight;a.clearRect(0,0,o,c);let u=R(e,`--fg`),f=R(e,`--dim`),p=R(e,`--muted`),m=c*.62;if(d){let e=d.trail,t=e.length/4,n=Math.min(t,Math.round(r.trailMs/(2/48e3*1e3))),i=1+r.lengthRatio,s=.46*Math.min(o,m)/i,c=o/2,l=m/2;a.lineWidth=1,a.strokeStyle=u,a.beginPath();for(let r=t-n;r<t;r++){let i=c+s*e[4*r+2],o=l+s*e[4*r+3];r===t-n?a.moveTo(i,o):a.lineTo(i,o)}a.globalAlpha=.8,a.stroke();let f=t-1;a.globalAlpha=1,a.strokeStyle=p,a.beginPath(),a.moveTo(c,l),a.lineTo(c+s*e[4*f],l+s*e[4*f+1]),a.lineTo(c+s*e[4*f+2],l+s*e[4*f+3]),a.stroke()}if(s){let e=(c-m)*.45,t=m+8;s.getFloatTimeDomainData(x),a.strokeStyle=u,a.lineWidth=1,a.beginPath();for(let n=0;n<1024;n++){let r=n/1023*o,i=t+e/2-x[n]*e/2;n?a.lineTo(r,i):a.moveTo(r,i)}a.stroke(),S&&S.length===s.frequencyBinCount||(S=new Float32Array(s.frequencyBinCount)),s.getFloatFrequencyData(S);let n=(c-m)*.45,r=c-4,l=i.ctx.sampleRate,d=e=>Math.log(e/20)/Math.log(1e3)*o;a.strokeStyle=f,a.beginPath();for(let e of[100,1e3,1e4])a.moveTo(d(e),r-n),a.lineTo(d(e),r);a.stroke(),a.strokeStyle=u,a.beginPath();let p=!1;for(let e=1;e<S.length;e++){let t=e*l/(2*S.length);if(t<20||t>2e4)continue;let i=Math.max(0,Math.min(1,(S[e]+110)/100)),o=d(t),s=r-i*n;p?a.lineTo(o,s):(a.moveTo(o,s),p=!0)}a.stroke()}l||(a.fillStyle=p,a.font=`12px ui-monospace, monospace`,a.fillText(`play, then click here (or press S) to strike`,8,16))}function w(){return{mode:l&&d?d.phase:`–`,energy:d?d.energy.toFixed(4):`–`,"time scale":d?`${d.k.toFixed(0)} sim s per s`:`–`,strike:`click the plot or press S`}}return{get playing(){return l},start:e=>y(e),stop:b,draw:C,now:()=>l&&i?i.ctx.currentTime-u:0,length:()=>1/0,readouts:w,dispose(){b(),window.removeEventListener(`keydown`,_),e.replaceChildren()}}}var yt={id:`lab`,title:`lab: the pendulum as instrument`,hidden:!0,schema:[{group:`play`,key:`mode`,label:`mode`,kind:`select`,default:`strike`,options:[`strike`,`sustain`,`swell`],hint:`strike: start at the energy and ring down; sustain: energy held (like bowing); swell: energy rises, then rings down`},{group:`play`,key:`strikeEnergy`,label:`strike adds`,kind:`number`,default:.3,min:5e-4,max:5,log:!0,hint:`energy each strike adds to the current motion (units of E_top, both arms up)`},{group:`play`,key:`energy`,label:`energy`,kind:`number`,default:1,min:.001,max:5,log:!0,hint:`sustain level and swell target (units of E_top). Low: nearly periodic, two inharmonic modes. ~0.3–1.5: chaos. High: regular again (rotations)`},{group:`play`,key:`pitch`,label:`pitch`,kind:`number`,default:110,min:5,max:2e3,log:!0,unit:`Hz`,hint:`the lower small-swing mode lands here (time scaling)`},{group:`play`,key:`ringTime`,label:`ring time`,kind:`number`,default:4,min:.05,max:60,log:!0,unit:`s`,hint:`damping: amplitude falls 60 dB in this time (strike and swell)`},{group:`play`,key:`restrike`,label:`restrike every`,kind:`number`,default:5,min:0,max:60,step:.1,unit:`s`,hint:`0 = strike once`},{group:`play`,key:`swellTime`,label:`swell time`,kind:`number`,default:2,min:.05,max:30,log:!0,unit:`s`},{group:`play`,key:`follow`,label:`energy follow`,kind:`number`,default:3,min:.2,max:200,log:!0,unit:`periods`,hint:`sustain/swell: how quickly the energy controller corrects`},{group:`sound`,key:`left`,label:`left signal`,kind:`select`,default:`x2`,options:[...G],hint:`x/y: bob position, v: velocity, θ: angles, ω: angular velocities, p: momenta`},{group:`sound`,key:`right`,label:`right signal`,kind:`select`,default:`x1`,options:[...G]},{group:`sound`,key:`gain`,label:`gain`,kind:`number`,default:-6,min:-40,max:30,step:.5,unit:`dB`,hint:`before a soft limiter (high gain = saturated)`},{group:`sound`,key:`dcCut`,label:`low cut`,kind:`number`,default:15,min:1,max:500,log:!0,unit:`Hz`,hint:`removes constant offsets and very slow drift`},{group:`sound`,key:`level`,label:`level`,kind:`number`,default:-12,min:-48,max:6,step:.5,unit:`dB`},{group:`pendulum`,key:`massRatio`,label:`m2 / m1`,kind:`number`,default:1,min:.05,max:20,log:!0},{group:`pendulum`,key:`lengthRatio`,label:`l2 / l1`,kind:`number`,default:1,min:.05,max:20,log:!0},{group:`visual`,key:`trailMs`,label:`path length`,kind:`number`,default:12,min:1,max:16,step:.5,unit:`ms`,hint:`how much of the bob's recent path to draw`}],defaults:ht,create:vt},J=`double pendulum`,Y=[ye,Ae,Re,Je,mt,yt],X=document.getElementById(`app`),Z=null;function Q(e,t={},...n){let r=Object.assign(document.createElement(e),t);return r.append(...n),r}var $={"04-crash":`04-descent`,ensemble:`05-ensemble`};for(let[e,t]of Object.entries($))try{let n=localStorage.getItem(`double-pendulum:author:${e}`);n!==null&&localStorage.getItem(`double-pendulum:author:${t}`)===null&&localStorage.setItem(`double-pendulum:author:${t}`,n),localStorage.removeItem(`double-pendulum:author:${e}`)}catch{}function bt(){Z?.(),Z=null,X.replaceChildren();let e=location.hash.replace(/^#\/?/,``).split(`/`).filter(Boolean);if(e[0]&&$[e[0]]){location.replace(`#/${[$[e[0]],...e.slice(1)].join(`/`)}`);return}let t=Y.find(t=>t.id===e[0]);if(!t)return xt();Z=Tt(t,e[1]===`edit`)}function xt(){document.title=J;let e=Q(`ol`,{className:`tracks`});for(let t of Y)t.hidden||e.append(Q(`li`,{},Q(`a`,{href:`#/${t.id}`,textContent:t.title})));X.append(Q(`main`,{className:`album`},Q(`h1`,{textContent:J}),e))}var St=e=>`double-pendulum:author:${e.id}`;function Ct(e){try{let t=localStorage.getItem(St(e));return t?JSON.parse(t):null}catch{return null}}function wt(e,t){try{localStorage.setItem(St(e),JSON.stringify(t))}catch{}}function Tt(e,t){let r=Y.filter(e=>!e.hidden).indexOf(e)+1;document.title=`${e.title} · ${J}`;let i=()=>a(e.schema,e.defaults),o=t?a(e.schema,e.defaults,Ct(e)):i(),s=Q(`div`,{className:`view`}),c=Q(`button`,{className:`big-play`,textContent:`▶`,title:`play`});c.setAttribute(`aria-label`,`play`);let l=Q(`button`,{className:`play`,textContent:`play`}),u=Q(`div`,{className:`bar`}),d=Q(`div`,{className:`progress`},u),p=Q(`a`,{className:`edit`,href:t?`#/${e.id}`:`#/${e.id}/edit`,textContent:t?`done`:`edit`}),m=Q(`header`,{},Q(`a`,{href:`#/`,textContent:J}),Q(`span`,{className:`sep`,textContent:` / `}),Q(`span`,{textContent:e.hidden?e.title:`${r}. ${e.title}`})),h=Q(`div`,{className:`notice`}),g=Q(`div`,{className:`buffering`,hidden:!0},Q(`div`,{className:`spinner`}),Q(`div`,{className:`fill`})),_=Q(`main`,{className:`stage`},m,h,s,Q(`div`,{className:`transport`},l,d,p)),v=Q(`div`,{className:t?`page with-author`:`page`},_);X.append(v);let y=e.create(s,()=>o);s.append(c,g);let b=()=>{let e=Math.floor(Math.min(s.clientWidth,s.clientHeight));for(let t of s.querySelectorAll(`canvas`))t.style.width=`${e}px`,t.style.height=`${e}px`},x=new ResizeObserver(b);x.observe(s),b();let S={value:0},C=!1,w=async e=>{C=!0;try{let t=await n();await y.start(t,e)}finally{C=!1}};l.onclick=()=>y.playing?y.stop():w(t?S.value:0),c.onclick=()=>l.click(),t&&(d.classList.add(`seekable`),d.onclick=e=>{let t=d.getBoundingClientRect(),n=Math.max(0,(e.clientX-t.left)/t.width*y.length());y.playing&&y.seek?y.seek(n):w(n)});let T=null;t&&(T=f({schema:e.schema,get:()=>o,set:t=>{o=t,wt(e,t)},defaults:i,readouts:()=>y.readouts(),startAt:S}),v.append(T.el));let E=e=>{let t=e.target.tagName;e.code===`Space`&&t!==`INPUT`&&t!==`SELECT`&&t!==`BUTTON`&&(e.preventDefault(),l.click())};window.addEventListener(`keydown`,E);let D=0,O=0,k=e=>{y.draw(),l.textContent=y.playing?`stop`:`play`,c.hidden=y.playing||C;let t=y.playing?y.status?.():void 0,n=!!t?.buffering||C;g.hidden=!n,n&&(g.lastChild.textContent=`${Math.round(100*(t?.fill??0))}%`);let r=y.notice?.()??``;h.textContent!==r&&(h.textContent=r),u.style.width=`${Math.min(100,100*y.now()/y.length())}%`,T&&e-O>200&&(T.updateReadouts(),O=e),D=requestAnimationFrame(k)};return D=requestAnimationFrame(k),()=>{cancelAnimationFrame(D),window.removeEventListener(`keydown`,E),x.disconnect(),y.dispose()}}window.addEventListener(`hashchange`,bt),bt();
↑↓ move↵openescclose