Skip to content

the ultimate vocal synthesizer - sing, speak, beatbox, and more

Rust

Vector display, phase 3: Bestiary

Jameson Hodge525698472248
diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index 27b0ef8..a2385aa 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -11,11 +11,8 @@ import { Keys } from "./components/Keys.tsx";
import { Segmented, Toggle } from "./components/Controls.tsx";
import { Screen } from "./components/Screen.tsx";
import { SpeakRight, speechInfo, speechSlots } from "./components/SpeakPanel.tsx";
-import { BestiaryPanel } from "./components/BestiaryPanel.tsx";
+import { BestiaryRight } from "./components/BestiaryPanel.tsx";
import { CreatureView } from "./components/CreatureView.tsx";
-import { Spectrogram } from "./components/Spectrogram.tsx";
-import { Scope } from "./components/Scope.tsx";
-import { CreatureTubes } from "./components/CreatureTubes.tsx";
import { creatureById } from "../wasm/engine.ts";
import { BeatboxRight, BeatOverlay, beatInfo, beatSlots } from "./components/BeatboxPanel.tsx";
import { SingRight, singInfo } from "./components/SingPanel.tsx";
@@ -190,32 +187,6 @@ function PlayRight() {
);
}
-/** Modes not yet redrawn in the vector style: their three instruments, as screens. */
-function LegacyRight() {
- const mode = useStore((s) => s.mode);
- const screens: [string, React.ReactNode][] =
- mode === "beatbox"
- ? [["Tube, glottis to lips", <TubeView key="t" />], ["Spectrogram", <Spectrogram key="s" />], ["Vocal folds, slowed down", <Stroboscope key="f" />]]
- : mode === "bestiary"
- ? [["Spectrogram", <Spectrogram key="s" />], ["Waveform, three cycles", <Scope key="w" />], ["Airway, each tube unrolled", <CreatureTubes key="a" />]]
- : [["Tube, glottis to lips", <TubeView key="t" />], ["Vocal folds, slowed down", <Stroboscope key="f" />], ["Spectrum and resonances", <SpectrumView key="p" ring={mode === "sing"} />]];
- return (
- <div className="right right-legacy">
- {screens.map(([title, node]) => (
- <Screen key={title} title={title}>
- {node}
- </Screen>
- ))}
- </div>
- );
-}
-
-function Deck() {
- const mode = useStore((s) => s.mode);
- if (mode === "bestiary") return <BestiaryPanel />;
- return null;
-}
-
export function App() {
const mode = useStore((s) => s.mode);
return (
@@ -223,9 +194,8 @@ export function App() {
<TopBar />
<main className={`wall wall-${mode}`}>
<LeftScreen />
- {mode === "play" ? <PlayRight /> : mode === "speak" ? <SpeakRight /> : mode === "sing" ? <SingRight /> : mode === "beatbox" ? <BeatboxRight /> : <LegacyRight />}
+ {mode === "play" ? <PlayRight /> : mode === "speak" ? <SpeakRight /> : mode === "sing" ? <SingRight /> : mode === "beatbox" ? <BeatboxRight /> : <BestiaryRight />}
</main>
- <Deck />
</div>
);
}
diff --git a/src/ui/components/BestiaryPanel.tsx b/src/ui/components/BestiaryPanel.tsx
index b577643..cfbe547 100644
--- a/src/ui/components/BestiaryPanel.tsx
+++ b/src/ui/components/BestiaryPanel.tsx
@@ -3,20 +3,24 @@ import { useStore } from "../store.ts";
import { CREATURES, creatureById } from "../../wasm/engine.ts";
import type { CreatureDef } from "../../wasm/types.ts";
import { useLiveCreature } from "../creatureLive.ts";
-import { Slider } from "./Controls.tsx";
import { Keys } from "./Keys.tsx";
+import { Chip, Screen } from "./Screen.tsx";
+import { EncoderPages, type EncoderPage } from "./Encoder.tsx";
+import { Spectrogram } from "./Spectrogram.tsx";
+import { CreatureTubes } from "./CreatureTubes.tsx";
-/** Scout-image thumbnail: the creature's outline with its airway traced in black. */
+/** Thumbnail: the creature's outline in blue with its airway traced in amber. */
const Thumb = memo(function Thumb({ def }: { def: CreatureDef }) {
const v = def.visual;
const vw = v.view.x1 - v.view.x0, vh = v.view.y1 - v.view.y0;
const pad = Math.max(vw, vh) * 0.06;
+ const stroke = Math.max(vw, vh) * 0.012;
const pts = (p: [number, number][]) => p.map(([x, y]) => `${x},${-y}`).join(" ");
return (
<svg className="thumb" viewBox={`${v.view.x0 - pad} ${-v.view.y1 - pad} ${vw + 2 * pad} ${vh + 2 * pad}`} preserveAspectRatio="xMidYMid meet" aria-hidden="true">
- <polygon points={pts(v.silhouette)} fill="#8a8a8a" stroke="#bdbdbd" strokeWidth={Math.max(vw, vh) * 0.012} strokeLinejoin="round" />
+ <polygon points={pts(v.silhouette)} fill="none" stroke="var(--blue)" strokeWidth={stroke} strokeLinejoin="round" />
{v.tubes.map((t) => (
- <polyline key={t.tube} points={pts(t.path)} fill="none" stroke="#000" strokeWidth={Math.max(vw, vh) * 0.022} strokeLinecap="round" strokeLinejoin="round" />
+ <polyline key={t.tube} points={pts(t.path)} fill="none" stroke="var(--amber)" strokeWidth={stroke * 0.9} strokeLinecap="round" strokeLinejoin="round" />
))}
</svg>
);
@@ -26,17 +30,14 @@ function Gallery() {
const creature = useStore((s) => s.creature);
const setCreature = useStore((s) => s.setCreature);
return (
- <div className="panel gallery">
- <h2>Creatures</h2>
- <div className="specimens">
- {CREATURES.map((c) => (
- <button key={c.id} className={`specimen${c.id === creature ? " on" : ""}`} onClick={() => setCreature(c.id)} aria-pressed={c.id === creature}>
- <Thumb def={c} />
- <span className="specimen-name">{c.name}</span>
- <span className="specimen-latin">{c.latin}</span>
- </button>
- ))}
- </div>
+ <div className="specimens">
+ {CREATURES.map((c) => (
+ <button key={c.id} className={`specimen${c.id === creature ? " on" : ""}`} onClick={() => setCreature(c.id)} aria-pressed={c.id === creature}>
+ <Thumb def={c} />
+ <span className="specimen-name">{c.name}</span>
+ <span className="specimen-latin">{c.latin}</span>
+ </button>
+ ))}
</div>
);
}
@@ -49,75 +50,81 @@ function Calls({ def }: { def: CreatureDef }) {
const setKeyCall = useStore((s) => s.setKeyCall);
const live = useLiveCreature(def.id);
return (
- <div className="panel calls-panel">
- <h2>Calls</h2>
+ <div className="calls-body">
<div className="calls">
{def.calls.map((c) => (
- <button key={c.id} className={`call${live?.call === c.id ? " playing" : ""}`} onClick={() => playCall(c.id)}>
+ <button key={c.id} className={`call${live?.call === c.id ? " playing" : ""}`} onClick={() => playCall(c.id)} title={c.hint}>
<span className="call-name">{c.name}</span>
- <span className="call-hint">{c.hint}</span>
</button>
))}
- <button className={`call sustain${hold ? " on" : ""}`} onClick={() => setHold(!hold)} aria-pressed={hold}>
+ <button className={`call sustain${hold ? " on" : ""}`} onClick={() => setHold(!hold)} aria-pressed={hold} title="Keep the breath on and shape the sound with the controls">
<span className="call-name">{hold ? "Stop sustaining" : "Sustain"}</span>
- <span className="call-hint">Keep the breath on and shape the sound with the sliders</span>
</button>
</div>
<div className="keys-mode" role="radiogroup" aria-label="What the keys play">
<span className="dim">Keys play</span>
- <button role="radio" aria-checked={keyCall === null} className={`chip${keyCall === null ? " on" : ""}`} onClick={() => setKeyCall(null)}>
+ <Chip toggle={false} role="radio" aria-checked={keyCall === null} on={keyCall === null} onClick={() => setKeyCall(null)}>
Held voice
- </button>
+ </Chip>
{def.calls.map((c) => (
- <button key={c.id} role="radio" aria-checked={keyCall === c.id} className={`chip${keyCall === c.id ? " on" : ""}`} onClick={() => setKeyCall(c.id)}>
+ <Chip key={c.id} toggle={false} role="radio" aria-checked={keyCall === c.id} on={keyCall === c.id} onClick={() => setKeyCall(c.id)}>
{c.name}
- </button>
+ </Chip>
))}
</div>
+ <p className="creature-blurb">{def.blurb}</p>
</div>
);
}
-function fmt(v: number, p: CreatureDef["params"][number]): string {
+function fmt(v: number, p: CreatureDef["params"][number]): { value: string; unit: string } {
const digits = p.digits ?? (p.max - p.min <= 2 ? 2 : v < 100 && p.log ? 1 : 0);
- return `${v.toFixed(digits)}${p.unit ? " " + p.unit : ""}`;
+ return { value: v.toFixed(digits), unit: p.unit ?? "" };
}
function Params({ def }: { def: CreatureDef }) {
const cparams = useStore((s) => s.cparams[def.id]);
const setCParam = useStore((s) => s.setCParam);
const live = useLiveCreature(def.id);
- // while a call plays, the sliders follow its automation; afterwards they return to yours
+ // while a call plays, the encoders follow its automation; afterwards they return to yours
const calling = !!live?.call;
- return (
- <div className="panel creature-params">
- <h2>{def.name}</h2>
- <p className="creature-role">{def.role}</p>
- <p className="creature-blurb">{def.blurb}</p>
- <div className="creature-sliders">
- {def.params.map((p) => {
- const mine = cparams?.[p.key] ?? p.default;
- const value = calling ? (live!.params[p.key] ?? mine) : mine;
- return <Slider key={p.key} label={p.label} value={value} min={p.min} max={p.max} log={p.log} onChange={(v) => setCParam(p.key, v)} format={(v) => fmt(v, p)} />;
- })}
- </div>
- </div>
- );
+ const pages: EncoderPage[] = [];
+ for (let i = 0; i < def.params.length; i += 4) {
+ pages.push({
+ name: String(pages.length + 1),
+ encoders: def.params.slice(i, i + 4).map((p) => {
+ const mine = cparams?.[p.key] ?? p.default;
+ return { label: p.label, value: calling ? (live!.params[p.key] ?? mine) : mine, min: p.min, max: p.max, log: p.log, onChange: (v: number) => setCParam(p.key, v), format: (v: number) => fmt(v, p) };
+ }),
+ });
+ }
+ return <EncoderPages key={def.id} label={`${def.name} controls`} pages={pages} />;
}
-export function BestiaryPanel() {
+/** Bestiary's right column: the creatures, the waterfall, the calls, the controls, the airway, the keys. */
+export function BestiaryRight() {
const creature = useStore((s) => s.creature);
const def = creatureById(creature);
return (
- <>
- <section className="bestiary">
+ <div className="right right-bestiary">
+ <Screen className="s-gallery" title="Creatures" sub={`${CREATURES.length} specimens`}>
<Gallery />
+ </Screen>
+ <Screen className="s-wf" title="Spectrogram" sub="Waterfall of the call">
+ <Spectrogram />
+ </Screen>
+ <Screen className="s-calls" title="Calls">
{def && <Calls def={def} />}
+ </Screen>
+ <Screen className="s-cparams" title="Controls" sub={def?.role}>
{def && <Params def={def} />}
- </section>
- <footer className="keys-bar">
+ </Screen>
+ <Screen className="s-airway" title="Airway" sub="Each tube unrolled">
+ <CreatureTubes />
+ </Screen>
+ <Screen className="s-keys s-keys-compact" title="Keys" sub="The held voice or a call, at the key's pitch">
<Keys />
- </footer>
- </>
+ </Screen>
+ </div>
);
}
diff --git a/src/ui/components/CreatureTubes.tsx b/src/ui/components/CreatureTubes.tsx
index ba90a0d..99c5816 100644
--- a/src/ui/components/CreatureTubes.tsx
+++ b/src/ui/components/CreatureTubes.tsx
@@ -1,17 +1,17 @@
-import { useCanvasLoop, font } from "../useCanvas.ts";
+import { usePhosphor } from "../usePhosphor.ts";
import { useStore } from "../store.ts";
import { creatureById } from "../../wasm/engine.ts";
import { liveTelemetry, previewTelemetry } from "../creatureLive.ts";
-import { C, hot, pressureLevel } from "../colors.ts";
+import { V, heat, pressureLevel } from "../colors.ts";
+import { beam, beamPts, label, type Pt } from "../render/vector.ts";
const a2d = (A: number) => 2 * Math.sqrt(Math.max(0, A) / Math.PI);
-/** Each airway tube unrolled into a lane: diameter profile (shared scale) lit by acoustic pressure. */
+/** Each airway tube unrolled into a lane: one ring per section (shared diameter scale), lit by sound pressure. */
export function CreatureTubes() {
- const ref = useCanvasLoop(({ ctx, w, h }) => {
+ const ref = usePhosphor(({ ctx, w, h }) => {
const st = useStore.getState();
const def = creatureById(st.creature);
- ctx.clearRect(0, 0, w, h);
if (!def) return;
const live = liveTelemetry(def.id);
const tele = live ?? previewTelemetry(def, st.cparams[def.id]);
@@ -19,25 +19,28 @@ export function CreatureTubes() {
if (!lanes.length) return;
let dMax = 0.01;
for (const l of lanes) for (const a of tele.tubes[l.tube].areas) dMax = Math.max(dMax, a2d(a));
- const labelW = 92;
- const laneH = (h - 2) / lanes.length;
- ctx.font = font(11);
+ const labelW = 120;
+ const laneH = (h - 6) / lanes.length;
lanes.forEach((l, li) => {
const data = tele.tubes[l.tube];
- const y = 1 + laneH * (li + 0.5);
- ctx.fillStyle = C.textDim;
- ctx.fillText(l.label ?? l.tube, 0, y + 4);
+ const y = 3 + laneH * (li + 0.5);
+ label(ctx, (l.label ?? l.tube).toUpperCase(), 14, y + 3, { size: 9, color: V.blueMid, ls: 0.16 });
const n = data.areas.length;
- const x0 = labelW, x1 = w - 2;
+ const x0 = labelW, x1 = w - 14;
const dx = (x1 - x0) / n;
+ const r = (k: number) => Math.max(0.8, (a2d(data.areas[k]) / dMax) * (laneH - 6) * 0.5);
+ const topL: Pt[] = [], botL: Pt[] = [];
for (let k = 0; k < n; k++) {
- const d = Math.max(1, (a2d(data.areas[k]) / dMax) * (laneH - 4));
- if (live) {
- const [r, g, b] = hot(0.08 + 0.92 * pressureLevel(data.rms[k] * 0.6));
- ctx.fillStyle = `rgb(${r | 0},${g | 0},${b | 0})`;
- } else ctx.fillStyle = "#5b6368";
- ctx.fillRect(x0 + k * dx, y - d / 2, Math.max(1, dx - 0.6), d);
+ const x = x0 + (k + 0.5) * dx;
+ topL.push([x, y - r(k)]);
+ botL.push([x, y + r(k)]);
+ const lv = live ? Math.pow(pressureLevel(data.rms[k] * 0.6), 0.85) : 0;
+ const p = new Path2D();
+ p.ellipse(x, y, Math.max(1, r(k) * 0.28), r(k), 0, 0, Math.PI * 2);
+ beam(ctx, p, live ? heat(lv) : V.blueDim, 1, { alpha: live ? 0.35 + 0.65 * lv : 0.6 });
}
+ beamPts(ctx, topL, V.blue, 1.1);
+ beamPts(ctx, botL, V.blue, 1.1);
});
});
return <canvas ref={ref} className="instrument-canvas" aria-label="Airway tubes unrolled, lit by sound pressure" role="img" />;
diff --git a/src/ui/components/CreatureView.tsx b/src/ui/components/CreatureView.tsx
index 3d1182f..a0fa1ca 100644
--- a/src/ui/components/CreatureView.tsx
+++ b/src/ui/components/CreatureView.tsx
@@ -1,10 +1,11 @@
import { useRef } from "react";
-import { useCanvasLoop, font } from "../useCanvas.ts";
+import { usePhosphor } from "../usePhosphor.ts";
import { useStore } from "../store.ts";
import { creatureById } from "../../wasm/engine.ts";
import type { CreatureDef } from "../../wasm/types.ts";
import { liveTelemetry, previewTelemetry } from "../creatureLive.ts";
-import { C, hot, pressureLevel } from "../colors.ts";
+import { V, SLOTS, heat, pressureLevel } from "../colors.ts";
+import { beamPts, dot, hfont, label, ring, seg, type Pt } from "../render/vector.ts";
type P = [number, number];
@@ -68,155 +69,102 @@ function pointAt(t: TubeGeom, s: number): P {
return [t.pts[i - 1][0] + (t.pts[i][0] - t.pts[i - 1][0]) * u, t.pts[i - 1][1] + (t.pts[i][1] - t.pts[i - 1][1]) * u];
}
+/** a creature parameter's value for display */
+function fmtParam(v: number, p: CreatureDef["params"][number]): { value: string; unit: string } {
+ const digits = p.digits ?? (p.max - p.min <= 2 ? 2 : v < 100 && p.log ? 1 : 0);
+ return { value: v.toFixed(digits), unit: p.unit ?? "" };
+}
+
/**
- * Creature cross-section in the same visual language as the human MRI view: tissue silhouette,
- * black airway channels whose width follows the simulated cross-section, acoustic pressure in
- * the hot scale, and source glyphs whose ripples follow the vibration.
+ * The creature as a vector drawing, in the language of the human face: the outline in bright blue,
+ * tissue dimmer, airway walls at the simulated width with cross-section rungs lit by sound
+ * pressure, sound sources as rings in slot colours with ripples paced by the pitch, and the first
+ * four parameters as readouts across the bottom.
*/
export function CreatureView() {
- const grainRef = useRef<CanvasPattern | null>(null);
const glyph = useRef<{ peak: Record<string, number>; phase: Record<string, number> }>({ peak: {}, phase: {} });
- const ref = useCanvasLoop(({ ctx, w, h, dt }) => {
+ const ref = usePhosphor(({ ctx, w, h, dt }) => {
const st = useStore.getState();
const def = creatureById(st.creature);
- ctx.fillStyle = "#000";
- ctx.fillRect(0, 0, w, h);
if (!def) return;
const vis = def.visual;
const geo = geometry(def);
const live = liveTelemetry(def.id);
const tele = live ?? previewTelemetry(def, st.cparams[def.id]);
+ const top = 64, slotH = Math.min(118, h * 0.2);
const vw = vis.view.x1 - vis.view.x0, vh = vis.view.y1 - vis.view.y0;
- const sc = Math.min((w * 0.84) / vw, (h * 0.7) / vh);
+ const sc = Math.min((w * 0.86) / vw, ((h - top - slotH) * 0.9) / vh);
const ox = w / 2 - ((vis.view.x0 + vis.view.x1) / 2) * sc;
- const oy = h * 0.53 + ((vis.view.y0 + vis.view.y1) / 2) * sc;
- const X = (x: number) => ox + x * sc;
- const Y = (y: number) => oy - y * sc;
- if (!grainRef.current) {
- const g = document.createElement("canvas");
- g.width = g.height = 160;
- const gc = g.getContext("2d")!;
- const img = gc.createImageData(160, 160);
- for (let i = 0; i < img.data.length; i += 4) {
- const v = 128 + (Math.random() + Math.random() + Math.random() - 1.5) * 90;
- img.data[i] = img.data[i + 1] = img.data[i + 2] = v;
- img.data[i + 3] = 255;
- }
- gc.putImageData(img, 0, 0);
- grainRef.current = ctx.createPattern(g, "repeat");
- }
- const path = (pts: P[]) => {
- ctx.beginPath();
- pts.forEach(([x, y], i) => (i ? ctx.lineTo(X(x), Y(y)) : ctx.moveTo(X(x), Y(y))));
- ctx.closePath();
- };
- // tissue: bright subcutaneous fat rim around darker muscle, T1-like
- const span = Math.min(vw * sc, vh * sc * 2.5);
- ctx.save();
- path(geo.silhouette);
- ctx.clip();
- ctx.fillStyle = C.muscle;
- ctx.fill();
- ctx.lineJoin = "round";
- ctx.strokeStyle = C.fat;
- ctx.lineWidth = Math.max(5, span * 0.018);
- ctx.stroke();
- ctx.strokeStyle = C.skin;
- ctx.lineWidth = Math.max(2, span * 0.006);
- ctx.stroke();
- for (const part of geo.parts) {
- path(part.pts);
- const v = Math.round(part.shade * 255);
- ctx.fillStyle = `rgb(${v},${v},${v})`;
- ctx.fill();
- }
- if (grainRef.current) {
- ctx.globalCompositeOperation = "overlay";
- ctx.globalAlpha = 0.2;
- ctx.fillStyle = grainRef.current;
- ctx.fillRect(0, 0, w, h);
- ctx.globalAlpha = 1;
- ctx.globalCompositeOperation = "source-over";
- }
- ctx.restore();
- // airway channels: drawn wider than life so narrow tubes stay legible
+ const oy = top + (h - top - slotH) / 2 + ((vis.view.y0 + vis.view.y1) / 2) * sc;
+ const S = ([x, y]: P): Pt => [ox + x * sc, oy - y * sc];
+
+ beamPts(ctx, geo.silhouette.map(S), V.blue, 1.7, { hot: true, close: true });
+ for (const part of geo.parts) beamPts(ctx, part.pts.map(S), part.shade > 0.5 ? V.blueMid : V.blueDim, 1, { close: true, alpha: 0.9 });
+
+ // airways: walls at the simulated width (drawn wider than life so narrow tubes stay legible)
const exaggerate = vis.tubeScale ?? 1.6;
- ctx.lineCap = "round";
- const labels: { text: string; x: number; y: number }[] = [];
+ const labels: { text: string; x: number; y: number; color: string }[] = [];
for (const tg of geo.tubes) {
const data = tele.tubes[tg.tube];
if (!data) continue;
const n = data.areas.length;
- const width = (k: number) => 2 * Math.sqrt(Math.max(0, data.areas[k]) / Math.PI) * exaggerate * sc;
- // walls first (mucosa), then lumen, then pressure
- for (let pass = 0; pass < 3; pass++) {
- for (let k = 0; k < n; k++) {
- const a = pointAt(tg, (k / n) * tg.length), b = pointAt(tg, ((k + 1) / n) * tg.length);
- const d = width(k);
- ctx.beginPath();
- ctx.moveTo(X(a[0]), Y(a[1]));
- ctx.lineTo(X(b[0]), Y(b[1]));
- if (pass === 0) {
- ctx.strokeStyle = C.mucosa;
- ctx.lineWidth = d + 3;
- } else if (pass === 1) {
- ctx.strokeStyle = "#000";
- ctx.lineWidth = Math.max(1.5, d);
- } else {
- if (!live || !st.view.pressure) break;
- const lvl = pressureLevel(data.rms[k] * 0.6);
- if (lvl < 0.02) continue;
- const [r, g, bb] = hot(lvl);
- ctx.strokeStyle = `rgba(${r | 0},${g | 0},${bb | 0},${0.5 + 0.5 * lvl})`;
- ctx.lineWidth = Math.max(1.2, d - 1);
- }
- ctx.stroke();
- }
+ const half = (k: number) => Math.sqrt(Math.max(0, data.areas[Math.min(n - 1, k)]) / Math.PI) * exaggerate;
+ const frame = (s: number) => {
+ const a = pointAt(tg, Math.max(0, s - 0.02 * tg.length)), b = pointAt(tg, Math.min(tg.length, s + 0.02 * tg.length));
+ const dx = b[0] - a[0], dy = b[1] - a[1], l = Math.hypot(dx, dy) || 1;
+ return { p: pointAt(tg, s), nx: -dy / l, ny: dx / l };
+ };
+ const wallA: Pt[] = [], wallB: Pt[] = [];
+ for (let k = 0; k <= n; k++) {
+ const { p, nx, ny } = frame((k / n) * tg.length);
+ const r = half(k);
+ wallA.push(S([p[0] + nx * r, p[1] + ny * r]));
+ wallB.push(S([p[0] - nx * r, p[1] - ny * r]));
+ }
+ beamPts(ctx, wallA, V.blue, 1.2, { hot: true });
+ beamPts(ctx, wallB, V.blue, 1.2, { hot: true });
+ for (let k = 0; k < n; k++) {
+ const { p, nx, ny } = frame(((k + 0.5) / n) * tg.length);
+ const r = half(k);
+ const lvl = live && st.view.pressure ? Math.pow(pressureLevel(data.rms[k] * 0.6), 0.85) : 0;
+ const [x0, y0] = S([p[0] + nx * r, p[1] + ny * r]), [x1, y1] = S([p[0] - nx * r, p[1] - ny * r]);
+ seg(ctx, x0, y0, x1, y1, live ? heat(lvl) : V.blueDim, 1, { alpha: live ? 0.35 + 0.65 * lvl : 0.6 });
}
if (tg.label && tg.inView) {
- const m = pointAt(tg, tg.length * 0.5);
- labels.push({ text: tg.label, x: X(m[0]) + 10, y: Y(m[1]) - 10 });
+ const m = S(pointAt(tg, tg.length * 0.5));
+ labels.push({ text: tg.label.toUpperCase(), x: m[0] + 12, y: m[1] - 12, color: V.blueMid });
}
}
- // source glyphs: a ring sized by the vibration envelope, ripples paced by the pitch
+
+ // sound sources: a ring sized by the vibration envelope, ripples paced by the pitch
const pp = def.params.find((p) => p.role === "pitch");
- const pitch = pp ? (live ? live.params[pp.key] : (st.cparams[def.id]?.[pp.key] ?? pp.default)) : 200;
+ const paramValue = (key: string, dflt: number) => (live ? (live.params[key] ?? dflt) : (st.cparams[def.id]?.[key] ?? dflt));
+ const pitch = pp ? paramValue(pp.key, pp.default) : 200;
const rate = 1.2 + 4.8 * Math.max(0, Math.min(1, Math.log(pitch / 10) / Math.log(900)));
- for (const s of vis.sources ?? []) {
+ (vis.sources ?? []).forEach((s, i) => {
+ const color = SLOTS[i % 4];
const raw = Math.max(0, Math.min(1, live?.source[s.key] ?? 0));
const pk = Math.max(raw, (glyph.current.peak[s.key] ?? 0) * Math.exp(-dt / 0.18));
glyph.current.peak[s.key] = pk;
const ph = ((glyph.current.phase[s.key] ?? 0) + dt * rate) % 1;
glyph.current.phase[s.key] = ph;
- const x = X(s.at[0]), y = Y(s.at[1]);
+ const [x, y] = S(s.at);
const r0 = 3.5 + 6 * pk;
- if (pk > 0.04) {
- for (let j = 0; j < 3; j++) {
- const u = (ph + j / 3) % 1;
- ctx.beginPath();
- ctx.arc(x, y, r0 + u * 24, 0, Math.PI * 2);
- ctx.strokeStyle = `rgba(242,207,91,${(1 - u) * Math.min(1, pk * 1.3) * 0.7})`;
- ctx.lineWidth = 1;
- ctx.stroke();
- }
+ if (pk > 0.04) for (let j = 0; j < 3; j++) {
+ const u = (ph + j / 3) % 1;
+ ring(ctx, x, y, r0 + u * 24, color, 1, { alpha: (1 - u) * Math.min(1, pk * 1.3) * 0.8 });
}
- ctx.beginPath();
- ctx.arc(x, y, r0, 0, Math.PI * 2);
- ctx.strokeStyle = C.caliper;
- ctx.lineWidth = 1.5;
- ctx.stroke();
- ctx.beginPath();
- ctx.arc(x, y, 1.8, 0, Math.PI * 2);
- ctx.fillStyle = C.caliper;
- ctx.fill();
- labels.push({ text: s.label, x: x + 14, y: y + 18 });
- }
+ ring(ctx, x, y, r0, color, 1.5, { hot: true });
+ dot(ctx, x, y, 1.8, color);
+ labels.push({ text: s.label.toUpperCase(), x: x + 14, y: y + 18, color });
+ });
+
if (st.view.calipers) {
// place labels, nudging down past any earlier label they would overlap
- ctx.font = font(11.5);
+ ctx.font = hfont(10);
const placed: { x0: number; x1: number; y0: number; y1: number }[] = [];
for (const l of labels) {
- const tw = ctx.measureText(l.text).width;
+ const tw = ctx.measureText(l.text).width + l.text.length * 1.5;
const x = Math.min(w - tw - 6, l.x);
let y = l.y;
for (let guard = 0; guard < 8; guard++) {
@@ -225,30 +173,40 @@ export function CreatureView() {
y = hit.y1 + 12;
}
placed.push({ x0: x, x1: x + tw, y0: y - 11, y1: y + 2 });
- const isSource = (vis.sources ?? []).some((s) => s.label === l.text);
- ctx.lineJoin = "round";
- ctx.lineWidth = 3.5;
- ctx.strokeStyle = "rgba(0,0,0,0.85)";
- ctx.strokeText(l.text, x, y);
- ctx.fillStyle = isSource ? C.caliper : "rgba(232,234,235,0.82)";
- ctx.fillText(l.text, x, y);
+ label(ctx, l.text, x, y, { size: 10, color: l.color, ls: 0.15 });
}
}
- // corner overlays
- ctx.font = font(14, 600, 112);
- ctx.fillStyle = "rgba(232,234,235,0.9)";
- ctx.fillText(def.name, 14, 26);
- ctx.font = `italic ${font(12.5)}`;
- ctx.fillStyle = C.textDim;
- ctx.fillText(def.latin, 14, 44);
- ctx.textAlign = "right";
- ctx.font = font(12.5);
- ctx.fillStyle = "rgba(232,234,235,0.85)";
- if (pp) ctx.fillText(`${pitch.toFixed(pp.digits ?? (pitch < 100 ? 1 : 0))} ${pp.unit ?? ""}`.trim(), w - 14, 26);
+
+ // like a map's title: the name, the latin name, and what it is doing
+ label(ctx, def.name.toUpperCase(), 16, 34, { size: 24, color: V.blue, ls: 0.18 });
+ label(ctx, def.latin.toUpperCase(), 18, 54, { size: 10, color: V.blueMid, ls: 0.16 });
const state = live ? (live.call ? (def.calls.find((c) => c.id === live.call)?.name ?? live.call) : live.gate > 0.05 ? "Sustaining" : "At rest") : "Not started";
- ctx.fillStyle = C.textDim;
- ctx.fillText(state, w - 14, 44);
- ctx.textAlign = "left";
+ label(ctx, state.toUpperCase(), w - 16, 30, { size: 13, color: V.amber, align: "right", ls: 0.16 });
+ if (pp) {
+ const f = fmtParam(pitch, pp);
+ label(ctx, `${f.value} ${f.unit}`.trim().toUpperCase(), w - 16, 50, { size: 11, color: V.amber, align: "right", ls: 0.12, alpha: 0.8 });
+ }
+ // a scale bar: 1 drawing unit (about a centimetre)
+ const unit = vw > 60 ? 10 : 1;
+ const by = h - slotH - 10;
+ seg(ctx, 18, by, 18 + unit * sc, by, V.blueMid, 1.2);
+ seg(ctx, 18, by - 4, 18, by + 4, V.blueMid, 1.2);
+ seg(ctx, 18 + unit * sc, by - 4, 18 + unit * sc, by + 4, V.blueMid, 1.2);
+ label(ctx, `${unit} CM`, 26 + unit * sc, by + 3, { size: 9, color: V.blueMid, ls: 0.14 });
+
+ // the first four parameters, OP-1 style, across the bottom (the encoders on the right share the colours)
+ const params = def.params.slice(0, 4);
+ const cw = (w - 28) / Math.max(1, params.length);
+ const big = Math.max(18, Math.min(40, slotH * 0.36, cw * 0.2));
+ params.forEach((p, i) => {
+ const color = SLOTS[i];
+ const cx = 16 + i * cw, cy = h - slotH + 12;
+ dot(ctx, cx + 5, cy, 4, color);
+ label(ctx, p.label.toUpperCase(), cx + 15, cy + 4, { size: 10, color, ls: 0.16, alpha: 0.85 });
+ const f = fmtParam(paramValue(p.key, p.default), p);
+ label(ctx, f.value, cx, cy + 14 + big, { size: big, color, weight: "m", ls: 0.02 });
+ if (f.unit) label(ctx, f.unit.toUpperCase(), cx, cy + 32 + big, { size: 10, color, ls: 0.14, alpha: 0.7 });
+ });
});
- return <canvas ref={ref} className="creature-canvas" aria-label="Creature airway cross-section" role="img" />;
+ return <canvas ref={ref} className="creature-canvas" aria-label="Creature airway: its outline, its airways lit by sound pressure, and its sound sources" role="img" />;
}
diff --git a/src/ui/components/Scope.tsx b/src/ui/components/Scope.tsx
deleted file mode 100644
index 02ebc93..0000000
--- a/src/ui/components/Scope.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { useRef } from "react";
-import { useCanvasLoop, font } from "../useCanvas.ts";
-import { engine } from "../../audio/AudioEngine.ts";
-import { useStore } from "../store.ts";
-import { creatureById } from "../../wasm/engine.ts";
-import { liveTelemetry } from "../creatureLive.ts";
-import { C } from "../colors.ts";
-
-/** Output waveform, triggered on a rising zero crossing and spanning three cycles of the pitch. */
-export function Scope() {
- const buf = useRef<Float32Array | null>(null);
- const gainRef = useRef(1);
- const ref = useCanvasLoop(({ ctx, w, h, dt }) => {
- const st = useStore.getState();
- ctx.clearRect(0, 0, w, h);
- const mid = h / 2;
- ctx.strokeStyle = "rgba(255,255,255,0.08)";
- ctx.beginPath();
- ctx.moveTo(0, mid);
- ctx.lineTo(w, mid);
- ctx.stroke();
- const an = engine.analyserScope;
- if (!an || !st.started) return;
- if (!buf.current || buf.current.length !== an.fftSize) buf.current = new Float32Array(an.fftSize);
- const b = buf.current;
- an.getFloatTimeDomainData(b as Float32Array<ArrayBuffer>);
- const sr = engine.sampleRate;
- const def = creatureById(st.creature);
- const pp = def?.params.find((p) => p.role === "pitch");
- const tele = def ? liveTelemetry(def.id) : null;
- const f0 = pp && tele ? tele.params[pp.key] : 200;
- const win = Math.round(Math.min(b.length / 2, Math.max(0.004 * sr, Math.min(0.3 * sr, (3 * sr) / f0))));
- // latest rising zero crossing that leaves a full window after it
- let start = b.length - win;
- for (let i = b.length - win; i > b.length - win - Math.min(b.length / 2, (2 * sr) / f0); i--) {
- if (b[i - 1] < 0 && b[i] >= 0) {
- start = i;
- break;
- }
- }
- let peak = 1e-4;
- for (let i = start; i < start + win; i++) peak = Math.max(peak, Math.abs(b[i]));
- // slow auto-gain so quiet calls stay visible without the trace jumping
- const want = 0.42 / Math.max(peak, 0.01);
- gainRef.current += (want - gainRef.current) * (1 - Math.exp(-dt / (want < gainRef.current ? 0.05 : 0.6)));
- const g = gainRef.current * h;
- ctx.beginPath();
- for (let x = 0; x < w; x++) {
- const i0 = start + Math.floor((x / w) * win), i1 = Math.max(i0 + 1, start + Math.floor(((x + 1) / w) * win));
- let lo = Infinity, hi = -Infinity;
- for (let i = i0; i < i1; i++) {
- if (b[i] < lo) lo = b[i];
- if (b[i] > hi) hi = b[i];
- }
- ctx.lineTo(x, mid - hi * g);
- if (lo < hi) ctx.lineTo(x, mid - lo * g);
- }
- ctx.strokeStyle = "rgba(232,234,235,0.85)";
- ctx.lineWidth = 1.25;
- ctx.stroke();
- ctx.font = font(10.5);
- ctx.fillStyle = C.textDim;
- const ms = (win / sr) * 1000;
- const label = ms >= 10 ? `${ms.toFixed(0)} ms` : `${ms.toFixed(1)} ms`;
- ctx.fillText(label, w - ctx.measureText(label).width - 2, h - 4);
- });
- return <canvas ref={ref} className="instrument-canvas" aria-label="Output waveform" role="img" />;
-}
diff --git a/src/ui/styles.css b/src/ui/styles.css
index 7f78da0..9637acc 100644
--- a/src/ui/styles.css
+++ b/src/ui/styles.css
@@ -1559,10 +1559,19 @@ button.ghost:hover,
}
.screen-sub {
+ flex: 0 1 auto;
+ min-width: 0;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--blue-mid);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.screen-title {
+ flex: none;
}
.screen-tools {
@@ -1718,11 +1727,18 @@ button.ghost:hover,
}
.enc-label {
+ max-width: 100%;
font-size: 10px;
+ line-height: 1.25;
letter-spacing: 0.2em;
+ text-align: center;
text-transform: uppercase;
opacity: 0.85;
- white-space: nowrap;
+ /* long names (a creature's "Drive (pure → raspy)") wrap to two lines rather than run into the next */
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
}
.enc-dial {
@@ -2684,3 +2700,194 @@ input[type="range"]::-moz-range-thumb {
top: 10px;
}
}
+
+/* ---------- Bestiary */
+.right-bestiary {
+ grid-template-columns: minmax(0, 342fr) minmax(0, 342fr);
+ grid-template-rows: minmax(0, 196fr) minmax(0, 196fr) minmax(0, 232fr) minmax(0, 120fr) minmax(0, 88fr);
+ grid-template-areas: "gallery gallery" "wf wf" "calls cparams" "airway airway" "keys keys";
+}
+
+.s-gallery { grid-area: gallery; }
+.s-calls { grid-area: calls; }
+.s-cparams { grid-area: cparams; }
+.s-airway { grid-area: airway; }
+
+.s-gallery .specimens {
+ position: absolute;
+ inset: 0;
+ padding: 4px 14px 12px;
+ display: grid;
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ gap: 8px;
+}
+
+.s-gallery .specimen {
+ display: grid;
+ grid-template-rows: minmax(0, 1fr) auto auto;
+ gap: 2px;
+ justify-items: center;
+ min-height: 0;
+ padding: 6px;
+ background: transparent;
+ border: 1px solid transparent;
+ border-radius: 0;
+ color: var(--blue-mid);
+ cursor: pointer;
+}
+
+.s-gallery .specimen:hover {
+ border-color: var(--frame);
+}
+
+.s-gallery .specimen.on {
+ border-color: var(--blue);
+ box-shadow: 0 0 6px rgba(79, 182, 242, 0.3), inset 0 0 5px rgba(79, 182, 242, 0.15);
+}
+
+.s-gallery .thumb {
+ width: 100%;
+ height: 100%;
+ min-height: 0;
+ filter: drop-shadow(0 0 2px rgba(79, 182, 242, 0.6));
+}
+
+.s-gallery .specimen-name {
+ font-size: 10px;
+ letter-spacing: 0.16em;
+ text-transform: uppercase;
+ color: var(--blue);
+}
+
+.s-gallery .specimen.on .specimen-name {
+ text-shadow: var(--glow-blue);
+}
+
+.s-gallery .specimen-latin {
+ font-size: 8px;
+ font-style: normal;
+ letter-spacing: 0.1em;
+ text-transform: uppercase;
+ color: var(--blue-dim);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ max-width: 100%;
+}
+
+.calls-body {
+ position: absolute;
+ inset: 0;
+ padding: 4px 14px 10px;
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ overflow-y: auto;
+}
+
+.calls-body .calls {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 5px;
+}
+
+.calls-body .call {
+ background: transparent;
+ border: 1px solid var(--frame);
+ border-radius: 0;
+ padding: 4px 10px;
+ color: var(--blue-mid);
+ text-align: left;
+ cursor: pointer;
+}
+
+.calls-body .call:hover {
+ border-color: var(--blue-dim);
+ color: var(--blue);
+}
+
+.calls-body .call-name {
+ font-size: 10px;
+ font-weight: 300;
+ letter-spacing: 0.14em;
+ text-transform: uppercase;
+}
+
+.calls-body .call.playing {
+ border-color: var(--amber);
+ color: var(--amber);
+ box-shadow: 0 0 6px rgba(255, 179, 64, 0.45);
+ text-shadow: 0 0 3px rgba(255, 179, 64, 0.6);
+}
+
+.calls-body .call.playing .call-name {
+ color: var(--amber);
+}
+
+.calls-body .call.sustain.on {
+ border-color: var(--blue);
+ color: var(--blue);
+ background: transparent;
+}
+
+.calls-body .keys-mode {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ align-items: center;
+}
+
+.calls-body .keys-mode .dim {
+ font-size: 8px;
+ letter-spacing: 0.14em;
+ text-transform: uppercase;
+ color: var(--blue-dim);
+ margin-right: 4px;
+}
+
+.calls-body .keys-mode .chip {
+ padding: 2px 7px;
+ font-size: 9px;
+}
+
+.calls-body .creature-blurb {
+ margin: 0;
+ font-size: 10px;
+ line-height: 1.5;
+ letter-spacing: 0.04em;
+ color: var(--blue-dim);
+}
+
+.s-cparams .enc-label {
+ font-size: 9px;
+ letter-spacing: 0.12em;
+}
+
+@media (max-width: 1100px) {
+ .right-bestiary {
+ grid-template-rows: none;
+ grid-template-areas: "gallery gallery" "wf wf" "calls cparams" "airway airway" "keys keys";
+ }
+ .right-bestiary .screen-body {
+ min-height: 190px;
+ }
+ .s-airway .screen-body {
+ min-height: 120px;
+ }
+ .right-bestiary .s-keys-compact .screen-body {
+ min-height: 90px;
+ }
+}
+
+@media (max-width: 640px) {
+ .right-bestiary {
+ grid-template-columns: minmax(0, 1fr);
+ grid-template-areas: "gallery" "wf" "calls" "cparams" "airway" "keys";
+ }
+ .s-gallery .specimens {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+ .s-gallery .screen-body {
+ min-height: 300px;
+ }
+}