/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / src / compositions / c02-orbits / schema.ts
76 lines · 4.3 KBCodeBlameHistory
5c043e1Add composition 2: orbitsJeremy Magland 1import type { ParamSpec } from "../../core/params.ts";
2import { NOTE_INSTRUMENTS } from "../../instruments/index.ts";
3import { schema as c01 } from "../c01-poincare/schema.ts";
5// Composition 2 shares most settings with composition 1 (same meanings and ranges).
6const pick = (key: string, o: Partial<ParamSpec> = {}): ParamSpec => {
7 const s = c01.find((x) => x.key === key);
8 if (!s) throw new Error(`no setting ${key} in composition 1`);
9 return { ...s, ...o } as ParamSpec;
10};
12export const SLOTS = 6;
13const SLOT_DEFAULTS: [string, number][] = [
14 ["modal: Nylon harp", 0],
15 ["modal: Marimba", -1],
16 ["modal: Vibraphone", 0],
17 ["modal: Church bell", -1],
18 ["modal: Steel-string pluck", 0],
19 ["modal: Glass harmonics", 1],
20];
22export const schema: ParamSpec[] = [
23 // ── form ──
24 ...["duration", "peakTime", "holdTime", "energyStart"].map((k) => pick(k)),
25 pick("energyPeak", { default: 0.4 }),
26 ...["riseShape", "riseCurve", "fallCurve", "restEnergy", "finalHold", "finalFade"].map((k) => pick(k)),
28 // ── physics ──
2b58483orbits: default 15 orbits at speed 40Jeremy Magland 29 pick("speed", { default: 40 }),
5c043e1Add composition 2: orbitsJeremy Magland 30 ...["massRatio", "lengthRatio", "tau", "seed"].map((k) => pick(k)),
32 // ── orbits ──
2b58483orbits: default 15 orbits at speed 40Jeremy Magland 33 { group: "orbits", key: "orbitCount", label: "orbits", kind: "number", default: 15, min: 1, max: 20, step: 1, hint: "pendulums, all following the same energy; each starts at a random place" },
5c043e1Add composition 2: orbitsJeremy Magland 34 {
35 group: "orbits", key: "colors", label: "colors", kind: "text",
36 default: "#d6b37a, #7fa8cf, #c48bb8, #93bf8a, #d48f7f, #a9a6e0",
37 hint: "comma-separated CSS colors; orbit n uses color n (cycling)",
38 },
39 ...Array.from({ length: SLOTS }, (_, i): ParamSpec[] => [
40 {
41 group: "orbits", key: `slot${i + 1}Instrument`, label: `instrument ${i + 1}`, kind: "select",
42 default: SLOT_DEFAULTS[i][0], options: Object.keys(NOTE_INSTRUMENTS),
43 hint: `orbits ${i + 1}, ${i + 1 + SLOTS}, ${i + 1 + 2 * SLOTS}, … play this instrument`,
44 },
45 { group: "orbits", key: `slot${i + 1}Octave`, label: `octave ${i + 1}`, kind: "number", default: SLOT_DEFAULTS[i][1], min: -3, max: 3, step: 1, hint: "register shift for this instrument" },
46 ]).flat(),
47 pick("modalCustom", { group: "orbits", hint: "for “modal: custom” in any slot: paste JSON from modal-synth’s Copy button" }),
49 // ── notes (one per crossing, per orbit) ──
50 pick("scale", { default: "dorian" }),
51 ...["root", "pitchSource", "thetaRange", "pitchLow", "pitchHigh", "pitchCurve", "invertPitch", "p2Ref", "loudCurve", "loudFloor", "notesLevel", "noteLength", "panAmount"].map((k) => pick(k)),
53 // ── hum ──
54 ...c01.filter((s) => s.group === "hum"),
56 // ── visual ──
01b86bforbits: show the section portrait and each pendulum's traced orbitJeremy Magland 57 pick("fade", { default: 20, hint: "how long each live crossing dot stays visible" }),
5c043e1Add composition 2: orbitsJeremy Magland 58 ...["plotZoom", "zoomSmooth", "plotP"].map((k) => pick(k)),
59 pick("pointSize", { default: 2.5 }),
61 // ── portrait: computed at frozen energy, refreshed (crossfading) as the energy moves ──
62 pick("orbits", { key: "portrait", group: "portrait", label: "show portrait", hint: "grey background: the section's structure at the current energy" }),
63 pick("orbitCount", { key: "portraitCount", group: "portrait" }),
64 pick("orbitCpu", { key: "portraitCpu", group: "portrait" }),
65 pick("orbitLife", { key: "portraitLife", group: "portrait" }),
66 pick("orbitBand", { key: "portraitBand", group: "portrait" }),
67 pick("orbitMinHold", { key: "portraitMinHold", group: "portrait" }),
68 pick("orbitMaxPoints", { key: "portraitMaxPoints", group: "portrait" }),
69 pick("orbitXfade", { key: "portraitXfade", group: "portrait" }),
70 pick("orbitAlpha", { key: "portraitAlpha", group: "portrait", default: 0.15 }),
71 pick("orbitSize", { key: "portraitSize", group: "portrait" }),
72 { group: "portrait", key: "traces", label: "trace orbits", kind: "bool", default: true, hint: "with each portrait, follow every pendulum from its current state (energy frozen) and draw the orbit it's on, in its color" },
73 { group: "portrait", key: "traceMax", label: "trace length", kind: "number", default: 1500, min: 50, max: 10000, log: true, hint: "crossings computed per orbit trace" },
74 { group: "portrait", key: "traceAlpha", label: "trace brightness", kind: "number", default: 0.75, min: 0.02, max: 1, step: 0.01 },
75 { group: "portrait", key: "traceSize", label: "trace point size", kind: "number", default: 1.5, min: 0.5, max: 4, step: 0.1, unit: "px" },
5c043e1Add composition 2: orbitsJeremy Magland 76];
↑↓ move↵openescclose