the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Review fixes for phase 3
Jameson Hodge76756094ed16
diff --git a/src/ui/components/BeatboxPanel.tsx b/src/ui/components/BeatboxPanel.tsxindex 847a8a8..0fa802b 100644--- a/src/ui/components/BeatboxPanel.tsx+++ b/src/ui/components/BeatboxPanel.tsx@@ -75,7 +75,19 @@ function Pads() {return (<div className="pads">{BEAT_SOUNDS.map((s, i) => (- <button key={s.id} className={`pad pad-${s.role}${lit === s.id ? " lit" : ""}`} onPointerDown={() => hit(s.id)} title={s.hint} aria-label={`${s.name}: ${s.hint}. Key ${(i + 1) % 10}`}>+ <button+ key={s.id}+ className={`pad pad-${s.role}${lit === s.id ? " lit" : ""}`}+ onPointerDown={() => hit(s.id)}+ onKeyDown={(e) => {+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ hit(s.id);+ }+ }}+ title={s.hint}+ aria-label={`${s.name}: ${s.hint}. Key ${(i + 1) % 10}`}+ ><span className="pad-sym">{s.id}</span><span className="pad-name">{s.name}</span><span className="pad-air">{AIR[s.airstream]}</span>diff --git a/src/ui/components/CreatureView.tsx b/src/ui/components/CreatureView.tsxindex a0fa1ca..257a1c6 100644--- a/src/ui/components/CreatureView.tsx+++ b/src/ui/components/CreatureView.tsx@@ -69,6 +69,17 @@ 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];}+/** text cut to fit a width (in the Hershey font at this size and spacing), ending in an ellipsis */+function fit(ctx: CanvasRenderingContext2D, text: string, maxW: number, size: number, ls: number): string {+ ctx.save();+ ctx.font = hfont(size);+ const width = (s: string) => ctx.measureText(s).width + s.length * size * ls;+ let t = text;+ while (t.length > 2 && width(t) > maxW) t = t.slice(0, -2) + "…";+ ctx.restore();+ return t;+}+/** 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);@@ -91,7 +102,9 @@ export function CreatureView() {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);+ // a narrow screen (a phone) stacks the title and status, and puts the readouts two by two+ const compact = w < 560;+ const top = compact ? 96 : 64, slotH = compact ? 132 : 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.86) / vw, ((h - top - slotH) * 0.9) / vh);const ox = w / 2 - ((vis.view.x0 + vis.view.x1) / 2) * sc;@@ -178,13 +191,15 @@ export function CreatureView() {}// 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 });+ label(ctx, fit(ctx, def.name.toUpperCase(), w - 32, compact ? 18 : 24, 0.18), 16, compact ? 30 : 34, { size: compact ? 18 : 24, color: V.blue, ls: 0.18 });+ label(ctx, fit(ctx, def.latin.toUpperCase(), w - 34, 10, 0.16), 18, compact ? 48 : 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";- 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 });+ const pitchText = pp ? (() => { const f = fmtParam(pitch, pp); return `${f.value} ${f.unit}`.trim().toUpperCase(); })() : "";+ if (compact) {+ label(ctx, `${state.toUpperCase()}${pitchText ? " " + pitchText : ""}`, 18, 70, { size: 11, color: V.amber, ls: 0.14 });+ } else {+ label(ctx, state.toUpperCase(), w - 16, 30, { size: 13, color: V.amber, align: "right", ls: 0.16 });+ if (pitchText) label(ctx, pitchText, 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;@@ -196,13 +211,14 @@ export function CreatureView() {// 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));+ const perRow = compact ? 2 : Math.max(1, params.length);+ const cw = (w - 28) / perRow, rowH = compact ? slotH / 2 : slotH;+ const big = Math.max(18, Math.min(40, rowH * (compact ? 0.42 : 0.36), cw * 0.2));params.forEach((p, i) => {const color = SLOTS[i];- const cx = 16 + i * cw, cy = h - slotH + 12;+ const cx = 16 + (i % perRow) * cw, cy = h - slotH + 12 + Math.floor(i / perRow) * rowH;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 });+ label(ctx, fit(ctx, p.label.toUpperCase(), cw - 22, 10, 0.16), 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 });diff --git a/src/ui/components/SingPanel.tsx b/src/ui/components/SingPanel.tsxindex 0bda411..5dc01e2 100644--- a/src/ui/components/SingPanel.tsx+++ b/src/ui/components/SingPanel.tsx@@ -1,5 +1,5 @@import { useStore } from "../store.ts";-import { useSing, playDemo, stopSinging, DEMO_SONGS } from "../singing.ts";+import { useSing, playDemo, stopSinging, soundingSyllable, DEMO_SONGS } from "../singing.ts";import { Keys } from "./Keys.tsx";import { PianoRoll } from "./PianoRoll.tsx";import { SpectrumView } from "./SpectrumView.tsx";@@ -11,11 +11,11 @@ import type { InfoFn } from "./AnatomyView.tsx";/** epilarynx narrowing for the singer's ring (measured: +3 to +12 dB at 2.4–3.6 kHz, adult male) */const RING = 0.85;-/** the syllable being sung now: the demo's, or the one the held key sang */+/** the syllable being sung now: the demo's, or the one the held key is singing */function syllableNow(): string | null {const s = useSing.getState();if (s.demo) return s.syllables[s.demoAt]?.text ?? null;- return useStore.getState().heldNotes.length ? (s.syllables[s.cursor - 1]?.text ?? null) : null;+ return soundingSyllable();}/** Sing mode's lines over the face: the note, the syllable, the ring */diff --git a/src/ui/components/Spectrogram.tsx b/src/ui/components/Spectrogram.tsxindex f3d63b2..7e09e92 100644--- a/src/ui/components/Spectrogram.tsx+++ b/src/ui/components/Spectrogram.tsx@@ -19,14 +19,19 @@ const POINTS = 96;* hiding what is behind it.*/export function Spectrogram() {- const st = useRef<{ slices: Float32Array[]; bins: Float32Array | null; acc: number }>({ slices: [], bins: null, acc: EVERY });- const ref = usePhosphor(({ ctx, w, h, dt }) => {+ const st = useRef<{ slices: { t: number; v: Float32Array }[]; bins: Float32Array | null; last: number }>({ slices: [], bins: null, last: -Infinity });+ const ref = usePhosphor(({ ctx, w, h, now }) => {const s = st.current;const an = engine.analyserFast;const started = useStore.getState().started;- s.acc += dt;- if (s.acc >= EVERY) {- s.acc %= EVERY;+ // slices are timestamped, so a slow or hidden tab doesn't stretch "the last two seconds"+ const t = now / 1000, span = SLICES * EVERY;+ if (t - s.last > span) {+ s.slices = [];+ s.last = t - EVERY;+ }+ if (t - s.last >= EVERY) {+ s.last = t;const slice = new Float32Array(POINTS);if (an && started) {const n = an.frequencyBinCount;@@ -40,9 +45,9 @@ export function Spectrogram() {slice[i] = Math.max(0, Math.min(1, (db - DB_LO) / (DB_HI - DB_LO)));}}- s.slices.push(slice);- if (s.slices.length > SLICES) s.slices.shift();+ s.slices.push({ t, v: slice });}+ while (s.slices.length && t - s.slices[0].t > span) s.slices.shift();const left = 26, right = w - 70, base = h - 22;const depthX = Math.min(90, (right - left) * 0.18), depthY = Math.min(h * 0.42, 70);const frontW = right - left - depthX;@@ -50,9 +55,10 @@ export function Spectrogram() {const n = s.slices.length;// back to front: fill black under each slice, then stroke it, so nearer slices hide farther onesfor (let k = 0; k < n; k++) {- const age = n - 1 - k; // 0 = newest- const ox = left + (age / SLICES) * depthX, oy = base - (age / SLICES) * depthY;- const sl = s.slices[k];+ const u = Math.min(1, (t - s.slices[k].t) / span); // 0 = now+ const age = k === n - 1 ? 0 : u * SLICES;+ const ox = left + u * depthX, oy = base - u * depthY;+ const sl = s.slices[k].v;const p = new Path2D();p.moveTo(ox, oy);for (let i = 0; i < POINTS; i++) p.lineTo(ox + (i / (POINTS - 1)) * frontW, oy - Math.pow(sl[i], 1.4) * amp);diff --git a/src/ui/singing.ts b/src/ui/singing.tsindex d577a4c..4ee3e43 100644--- a/src/ui/singing.ts+++ b/src/ui/singing.ts@@ -90,6 +90,11 @@ interface Sounding {}let sounding: Sounding | null = null;++/** The syllable whose vowel is sounding from the keys now (null when no key sings). */+export function soundingSyllable(): string | null {+ return sounding?.syl.text ?? null;+}/** keys down, oldest first */let keys: number[] = [];/** gesture tags: a note uses tag (articulation, breath) and tag + 1 (pitch, vibrato) */diff --git a/src/ui/styles.css b/src/ui/styles.cssindex c77089a..67c7c3e 100644--- a/src/ui/styles.css+++ b/src/ui/styles.css@@ -196,14 +196,6 @@ button.primary.large {box-shadow: inset 0 0 0 1px var(--line);}-/* ---------- stage */-.stage {- display: grid;- grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);- gap: 10px;- min-height: 520px;-}-.viewport {position: relative;background: var(--black);@@ -274,23 +266,6 @@ button.primary.large {font-size: 14px;}-.instruments {- display: grid;- grid-template-rows: 1fr 1fr 1fr;- gap: 10px;-}--.instrument {- margin: 0;- display: grid;- grid-template-rows: auto minmax(0, 1fr);- background: var(--inset);- border-radius: var(--radius-m);- padding: 8px 10px 6px;- min-height: 150px;-}--.instrument figcaption,.panel h2 {font-size: 13px;font-weight: 550;@@ -305,24 +280,12 @@ button.primary.large {display: block;}-/* ---------- deck */-.deck {- display: grid;- grid-template-columns: minmax(240px, 1fr) minmax(260px, 1fr) minmax(260px, 1fr);- gap: 10px;-}-.panel {background: var(--inset);border-radius: var(--radius-m);padding: 10px 14px 12px;}-.vowel-panel {- display: grid;- grid-template-rows: auto minmax(0, 1fr);-}-.vowel-map {width: 100%;height: 100%;@@ -334,21 +297,6 @@ button.primary.large {touch-action: none;}-.voice-panel,-.artic-panel {- display: grid;- grid-template-columns: 1fr 1fr;- column-gap: 18px;- row-gap: 4px;- align-content: start;-}--.voice-panel h2,-.artic-panel h2,-.voice-panel .row {- grid-column: 1 / -1;-}-.row {display: flex;gap: 18px;@@ -439,26 +387,6 @@ input[type="range"]::-moz-range-thumb {gap: 10px;}-.speak-input {- display: flex;- flex-direction: column;- gap: 8px;-}--.speak-input textarea {- width: 100%;- resize: vertical;- min-height: 72px;- background: var(--black);- color: var(--text);- border: 1px solid var(--line);- border-radius: var(--radius-s);- padding: 8px 10px;- font: inherit;- font-size: 16px;- line-height: 1.4;-}-.examples {display: flex;flex-wrap: wrap;@@ -504,13 +432,6 @@ button.ghost {font-stretch: 87%;}-.chart-panel {- display: flex;- flex-direction: column;- gap: 8px;- min-width: 0;-}-.chart-scroll {overflow-x: auto;}@@ -564,12 +485,6 @@ button.ghost {color: #1d1a10;}-.score-panel {- grid-column: 1 / -1;- display: grid;- grid-template-rows: auto minmax(0, 1fr);-}-.score-canvas {width: 100%;height: 210px;@@ -652,12 +567,6 @@ button.ghost {line-height: 1.3;}-.calls-panel {- display: flex;- flex-direction: column;- gap: 10px;-}-.calls {display: grid;grid-template-columns: 1fr 1fr;@@ -704,18 +613,6 @@ button.ghost {font-size: 14px;}-.call-hint {- font-size: 12.5px;- font-stretch: 87%;- color: var(--text-dim);- line-height: 1.3;-}--.call:active .call-hint,-.call.sustain.on .call-hint {- color: #3d3620;-}-.keys-mode {display: flex;flex-wrap: wrap;@@ -727,17 +624,6 @@ button.ghost {margin-right: 2px;}-.creature-params {- display: flex;- flex-direction: column;-}--.creature-role {- margin: 0;- font-size: 15px;- font-weight: 550;-}-.creature-blurb {margin: 4px 0 10px;font-size: 13px;@@ -745,13 +631,6 @@ button.ghost {max-width: 62ch;}-.creature-sliders {- display: grid;- grid-template-columns: 1fr 1fr;- column-gap: 18px;- row-gap: 4px;-}-/* ---------- sing */.sing {display: grid;@@ -759,31 +638,6 @@ button.ghost {gap: 10px;}-.lyrics-panel,-.song-panel {- display: flex;- flex-direction: column;- gap: 8px;-}--.lyrics-panel textarea {- width: 100%;- resize: vertical;- min-height: 52px;- background: var(--black);- color: var(--text);- border: 1px solid var(--line);- border-radius: var(--radius-s);- padding: 8px 10px;- font: inherit;- font-size: 16px;- line-height: 1.4;-}--.song-panel h2 + .examples {- margin-bottom: 6px;-}-.syllables {display: flex;flex-wrap: wrap;@@ -835,11 +689,6 @@ button.ghost {line-height: 1;}-.roll-panel {- grid-column: 1 / -1;- min-height: 0;-}-.roll-canvas {height: 168px;border-radius: var(--radius-s);@@ -900,12 +749,6 @@ button.midi.on .midi-status {gap: 10px;}-.pads-panel {- display: flex;- flex-direction: column;- gap: 8px;-}-.pads {display: grid;grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));@@ -966,17 +809,6 @@ button.midi.on .midi-status {opacity: 0.7;}-.pads-panel .dim {- margin: 2px 0 0;-}--.seq-panel {- display: flex;- flex-direction: column;- gap: 10px;- min-width: 0;-}-.transport {display: flex;align-items: center;@@ -992,14 +824,6 @@ button.midi.on .midi-status {background: #ffd15c;}-.transport-sliders {- display: grid;- grid-template-columns: 1fr 1fr;- gap: 4px 18px;- flex: 1;- min-width: 240px;-}-.seq-grid {display: flex;flex-direction: column;@@ -1128,13 +952,6 @@ button.midi.on .midi-status {}}-/* ---------- keys */-.keys-bar {- background: var(--inset);- border-radius: var(--radius-m);- padding: 8px;-}-.keys {position: relative;height: 74px;@@ -1187,25 +1004,9 @@ button.midi.on .midi-status {/* ---------- responsive */@media (max-width: 1100px) {- .stage {- grid-template-columns: 1fr;- }- .instruments {- grid-template-columns: 1fr 1fr 1fr;- grid-template-rows: auto;- }- .deck {- grid-template-columns: 1fr 1fr;- }- .vowel-panel {- grid-column: 1 / -1;- }.bestiary {grid-template-columns: 1fr 1fr;}- .creature-params {- grid-column: 1 / -1;- }.beatbox {grid-template-columns: 1fr;}@@ -1213,7 +1014,7 @@ button.midi.on .midi-status {@media (max-width: 900px) {.speak,- .sing {+.sing {grid-template-columns: 1fr;}}@@ -1226,17 +1027,13 @@ button.midi.on .midi-status {padding: 8px;gap: 8px;}- .stage {- display: contents;- }.viewport {order: 1;}- .deck,.speak,- .sing,- .bestiary,- .beatbox {+.sing,+.bestiary,+.beatbox {order: 2;}.sing {@@ -1265,26 +1062,9 @@ button.midi.on .midi-status {.pad {min-height: 64px;}- .keys-bar {- order: 3;- }- .instruments {- order: 4;- }.tagline {display: none;}- .instruments {- grid-template-columns: 1fr;- }- .deck {- grid-template-columns: 1fr;- }- .voice-panel,- .artic-panel,- .creature-sliders {- grid-template-columns: 1fr;- }.bestiary {grid-template-columns: 1fr;}@@ -1298,7 +1078,7 @@ button.midi.on .midi-status {min-height: 0;}.anatomy,- .creature-canvas {+.creature-canvas {position: relative;inset: auto;width: 100%;@@ -1520,11 +1300,6 @@ button.ghost:hover,.s-voice { grid-area: voice; }.s-keys { grid-area: keys; }-/* modes not yet redrawn: their three instruments on the right, their deck below the wall */-.right-legacy {- grid-template-rows: repeat(3, minmax(0, 1fr));-}-/* ---------- a screen */.screen {position: relative;@@ -1804,6 +1579,20 @@ button.ghost:hover,justify-content: center;}+/* a screen holding encoders is as tall as they need (tabs, two-line labels, dial, value, unit) */+.screen .screen-body:has(> .enc-pages) {+ min-height: 176px;+}++.s-cparams .enc-dial {+ width: 62px;+ height: 62px;+}++.s-cparams .enc-value {+ font-size: 24px;+}+/* ---------- keys */.s-keys .screen-body {padding: 8px 14px 12px;@@ -1874,16 +1663,13 @@ button.midi.on .midi-status {}/* ---------- panels of modes not yet redrawn: framed, black, capital headings */-.panel,-.instrument,-.keys-bar {+.panel {background: #000;border: 1px solid var(--frame);border-radius: 0;}-.panel h2,-.instrument figcaption {+.panel h2 {font-weight: 300;font-size: 12px;letter-spacing: 0.2em;@@ -1969,20 +1755,11 @@ input[type="range"]::-moz-range-thumb {.s-voice .screen-body {min-height: 230px;}- .right-legacy {- grid-template-rows: none;- }- .right-legacy .screen-body {- min-height: 170px;- }}/* phones: the keys strip stacks under its MIDI button; flex: 1 from a zero basis collapsed itto its border (also true on main before the redesign), so it takes its fixed height instead */@media (max-width: 720px) {- .keys-bar .keys-row .keys {- flex: none;- }.beat-overlay {top: 10px;bottom: auto;@@ -1993,6 +1770,10 @@ input[type="range"]::-moz-range-thumb {.app {padding: 6px 8px 12px;}+ /* encoders go two by two here: two rows of them */+ .screen .screen-body:has(> .enc-pages) {+ min-height: 350px;+ }.right-play {grid-template-columns: minmax(0, 1fr);grid-template-areas: "tube" "folds" "spec" "vowels" "voice" "keys";@@ -2687,7 +2468,7 @@ input[type="range"]::-moz-range-thumb {min-height: 240px;}.s-pads .screen-body,- .s-transport .screen-body {+.s-transport .screen-body {min-height: 300px;}.s-keys-compact .screen-body {