# double pendulum An album of electroacoustic compositions. Each composition's sound and image are computed live in the browser from a double pendulum simulation. ```bash npm install npm run dev # http://127.0.0.1:8031 npm run build # static site in dist/ (relative paths, so it works under any subpath) ``` ## Routes - `#/`: the track list - `#/`: a composition with its published defaults (what visitors hear) - `#//edit`: author mode. Adds a panel of every parameter, readouts, "start at", and click-to-seek on the progress line. ## Author workflow 1. Open a composition, click **edit**, and tweak while it plays. Most changes are heard immediately. Instrument choice and the seed apply on the next play. 2. Your edits persist in this browser (localStorage), and only in author mode. 3. **copy config** copies the full parameter set as JSON. Paste it over `src/compositions//defaults.json` and rebuild to publish it. 4. **seed** = 0 gives a new variation each play. The readouts show the seed that was used, so you can pin a variation you liked. ## Layout - `src/physics/doublePendulum.ts`: Hamiltonian double pendulum, RK4. Energy is steered to a target by a force `λ·p` (`dE/dt = 2λT`), so it rises and falls smoothly. - `src/instruments/`: instrument interfaces (`NoteInstrument`, `DroneInstrument`), placeholders, and the registry. Add real instruments here and they appear in the composition's instrument menus. - `src/instruments/modal.ts`: instruments from the sibling **modal-synth** project (`../modal-synth`), imported live through the `@modal-synth` alias (see `vite.config.ts` and `tsconfig.json`). Every built-in modal-synth preset appears as `modal: `. For your own sounds, press **Copy** in modal-synth, choose `modal: custom`, and paste the JSON into **modal custom**. The JSON then becomes part of the composition's config. Building requires `../modal-synth` to be present. - `src/music/scales.ts`: scales and quantization (including continuous and harmonic series). - `src/core/`: params schema, author panel, audio context, and the composition interface. - `src/compositions/`: one folder per track (`schema.ts`, `defaults.json`, `piece.ts`), listed in `index.ts`. - `src/compositions/c01-poincare/orbitWorker.ts`: background orbit portrait, run in short work slices that use about `orbitCpu` of one core. ## 1. poincaré The section is θ1 = 0, crossed with dθ1/dt > 0, and plotted at (θ2, p2). Each crossing plays a note: - θ2 sets the pitch (signed or absolute, range, curve, scale, root) - |p2| sets the loudness - θ2 sets the pan Notes stop at `duration − finalAt`. The last note is then held for `finalHold` and faded over `finalFade`, all within `tail`. Behind the live crossings, a pool of energy-conserving orbits at the current energy keeps drawing the section's structure (islands and chaotic sea). They're reseeded as the energy moves. The hum is one held note of a sustained modal-synth preset (bowed, blown, self-oscillating or fed back). The energy sets a timbre value, which drives up to two synth settings (A and B), e.g. bow position and bow force. **normalize loudness** measures the hum's output and compensates slowly, so it holds a fixed pitch and loudness while only its timbre follows the energy. The energy follows an envelope: start → peak (exponential or linear rise) → hold → fall to zero at `duration`. Units: energy is in units of the potential energy with both arms up, and p2 is in units of √(m2·l2²·E_top). ## 2. orbits Several pendulums at once (6 by default, up to 20). All follow the same energy envelope from random starts. Only the section is shown: each orbit traces its crossings in its own color (**colors**, cycling). Each orbit plays instrument slot n (cycling through 6 slots), with a register shift per slot. Orbits on the same instrument share one polyphonic instance. The note mapping, hum, and rest-based ending match composition 1. The piece ends when every orbit has come to rest and its last note has faded. Behind the live dots: the grey portrait of the section at the current energy, and each pendulum's *traced orbit* in its color. Each time the portrait refreshes, every pendulum's current state is followed forward with its energy frozen. That draws the orbit it is on right now: a closed loop on an island, a cloud in the chaotic sea. Traces refresh and crossfade with the portrait as the energy moves. Shared machinery lives in `src/compositions/shared/`: the energy envelope, crossing → note mapping, hum control, section plot with its "fit energy" zoom, and the portrait/trace layer with its throttled worker. ## Deploying The site is published from the `site/` directory of `music/double-pendulum` on vault1.magland.org, served at https://double-pendulum--music.vault1-sites.magland.org/. The build needs `../modal-synth`, so it runs locally, not in CI: ```bash npm run site # build, then copy dist/ to site/ git add -A && git commit -m "Update site" && git push ``` Every push to `main` republishes the site.