the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Review fixes for phases 1 and 2
Jameson Hodgeb5e0906bf527
diff --git a/docs/ui-redesign.md b/docs/ui-redesign.mdindex 42f836c..872d20d 100644--- a/docs/ui-redesign.md+++ b/docs/ui-redesign.md@@ -53,7 +53,7 @@ A hook, `usePhosphor(draw)`, replaces `useCanvasLoop` for the vector screens: DP| Beatbox | face with the hit's big symbol | step sequencer, waterfall spectrogram, pads, transport encoders + presets, compact keys || Bestiary | creature (`CreatureView`) | creature gallery, waterfall spectrogram, calls, creature encoders, unrolled airway, compact keys |-`Keys` also owns the computer-keyboard listeners and the MIDI connect button, so every mode keeps at least a compact keys strip.+`Keys` also owns the computer-keyboard listeners and the MIDI connect button, so every mode that has keys today keeps at least a compact keys strip. (Speak never had them: it plays text, not notes.)The mockup generator (`docs/mockups/gen/`) is the reference implementation for each drawing: the same geometry, colours and layout rules, written against the live data the app already has (`HumanFrame`, telemetry, transfer functions, plans, creature visuals).diff --git a/src/ui/components/AnatomyView.tsx b/src/ui/components/AnatomyView.tsxindex 24c4465..655e8fb 100644--- a/src/ui/components/AnatomyView.tsx+++ b/src/ui/components/AnatomyView.tsx@@ -53,7 +53,7 @@ export function AnatomyView(props: { slots?: SlotsFn }) {const glow = new Glow();rendererRef.current = r;let w = 0, h = 0, dpr = 1;- const ro = new ResizeObserver(() => {+ const fit = () => {const b = wrap.getBoundingClientRect();dpr = Math.min(2, window.devicePixelRatio || 1);w = b.width;@@ -61,7 +61,8 @@ export function AnatomyView(props: { slots?: SlotsFn }) {canvas.width = Math.max(1, Math.round(w * dpr));canvas.height = Math.max(1, Math.round(h * dpr));r.resize(w, h);- });+ };+ const ro = new ResizeObserver(fit);ro.observe(wrap);let raf = 0;let last = performance.now();@@ -70,6 +71,7 @@ export function AnatomyView(props: { slots?: SlotsFn }) {const loop = (now: number) => {const dt = Math.min(0.05, (now - last) / 1000);last = now;+ if (Math.min(2, window.devicePixelRatio || 1) !== dpr) fit();const st = useStore.getState();const tele = engine.latest && engine.latest.body === st.body ? engine.latest : null;const a = tele ? VoiceModel.articFromArray(tele.t.artic) : st.artic;diff --git a/src/ui/components/Encoder.tsx b/src/ui/components/Encoder.tsxindex 80aae44..77bc500 100644--- a/src/ui/components/Encoder.tsx+++ b/src/ui/components/Encoder.tsx@@ -20,8 +20,8 @@ const SPAN = (270 * Math.PI) / 180;/*** OP-1 style encoder: a dial and a big numeral in its slot colour, over a native range input* that does the work (label, keyboard incl. Home/End and Page keys, aria-valuetext). Dragging the- * dial is relative: up or right raises the value. touch-action: pan-y keeps vertical swipes- * scrolling the page on touch screens, so only horizontal drags edit there.+ * dial is relative: up or right raises the value. On touch, vertical swipes scroll the page+ * (touch-action: pan-y) and only horizontal drags edit.*/export function Encoder(props: EncoderSpec & { slot: number }) {const { label, value, min, max, log, onChange, format, slot } = props;@@ -34,7 +34,7 @@ export function Encoder(props: EncoderSpec & { slot: number }) {};const pos = Math.min(1, Math.max(0, toPos(value)));const shown = format(value);- const drag = useRef<{ x: number; y: number; pos: number; id: number } | null>(null);+ const drag = useRef<{ x: number; y: number; pos: number; id: number; touch: boolean } | null>(null);const at = (u: number, r: number) => [Math.cos(A0 - u * SPAN) * r, -Math.sin(A0 - u * SPAN) * r];const [x0, y0] = at(0, 30), [x1, y1] = at(pos, 30), [px, py] = at(pos, 23);const arc = pos > 0.002 ? `M${x0.toFixed(2)} ${y0.toFixed(2)}A30 30 0 ${pos * 270 > 180 ? 1 : 0} 1 ${x1.toFixed(2)} ${y1.toFixed(2)}` : "";@@ -48,13 +48,17 @@ export function Encoder(props: EncoderSpec & { slot: number }) {onPointerDown={(e) => {if (e.button !== 0) return;(e.currentTarget as Element).setPointerCapture(e.pointerId);- drag.current = { x: e.clientX, y: e.clientY, pos, id: e.pointerId };+ drag.current = { x: e.clientX, y: e.clientY, pos, id: e.pointerId, touch: e.pointerType === "touch" };document.getElementById(id)?.focus({ preventScroll: true });}}onPointerMove={(e) => {const d = drag.current;if (!d || d.id !== e.pointerId) return;- const delta = (e.clientX - d.x - (e.clientY - d.y)) / (e.shiftKey ? 600 : 160);+ const dx = e.clientX - d.x, dy = e.clientY - d.y;+ // a vertical touch swipe is the page scrolling (pan-y), not an edit: touch uses dx only,+ // past a small dead zone; mouse and pen also take vertical movement+ if (d.touch && Math.abs(dx) < 6) return;+ const delta = (d.touch ? dx : dx - dy) / (e.shiftKey ? 600 : 160);onChange(fromPos(d.pos + delta));}}onPointerUp={() => (drag.current = null)}diff --git a/src/ui/components/VowelMap.tsx b/src/ui/components/VowelMap.tsxindex 0a99c0f..1b3247d 100644--- a/src/ui/components/VowelMap.tsx+++ b/src/ui/components/VowelMap.tsx@@ -36,7 +36,8 @@ export function VowelMap() {const F1 = Math.exp(Math.log(r.f1[0]) + v * (Math.log(r.f1[1]) - Math.log(r.f1[0])));return { F1, F2 };};- const trail = useRef<{ x: number; y: number }[]>([]);+ /** recent (F1, F2) of the live tract, so the trail survives resizes and fades out */+ const trail = useRef<{ F1: number; F2: number; t: number; body: string }[]>([]);const ref = usePhosphor(({ ctx, w, h }) => {const m = model.current;if (!m) return;@@ -55,12 +56,15 @@ export function VowelMap() {ipaGlyph(ctx, p.x, p.y + 5, v.ipa, 15, V.blueMid);}if (live) {- // where the tongue has been: a fading trail of the last second or so- const tr = trail.current;+ // where the tongue has been: a trail of the last 1.5 s, fading with age+ const now = performance.now();+ const tr = (trail.current = trail.current.filter((p) => p.body === st.body && now - p.t < 1500));const last = tr[tr.length - 1];- if (!last || Math.hypot(last.x - live.x, last.y - live.y) > 0.5) tr.push(live);- if (tr.length > 40) tr.shift();- for (let i = 1; i < tr.length; i++) seg(ctx, tr[i - 1].x, tr[i - 1].y, tr[i].x, tr[i].y, V.green, 1.2, { alpha: 0.08 + (0.6 * i) / tr.length });+ if (!last || Math.abs(Math.log(last.F1 / fm[0])) + Math.abs(Math.log(last.F2 / fm[1])) > 0.004) tr.push({ F1: fm[0], F2: fm[1], t: now, body: st.body });+ for (let i = 1; i < tr.length; i++) {+ const p0 = toXY(tr[i - 1].F1, tr[i - 1].F2, w, h), p1 = toXY(tr[i].F1, tr[i].F2, w, h);+ seg(ctx, p0.x, p0.y, p1.x, p1.y, V.green, 1.2, { alpha: 0.7 * (1 - (now - tr[i].t) / 1500) });+ }handle(ctx, live.x, live.y, V.green, 8);ipaGlyph(ctx, live.x + 20, live.y - 8, near, 17, V.green);}diff --git a/src/ui/styles.css b/src/ui/styles.cssindex 619f087..8f51f13 100644--- a/src/ui/styles.css+++ b/src/ui/styles.css@@ -1373,6 +1373,7 @@ body {.app {display: grid;+ grid-template-columns: minmax(0, 1fr);grid-template-rows: auto auto;align-content: start;min-height: 100vh;@@ -1411,7 +1412,9 @@ body {background: transparent;border: 0;padding: 0;- gap: 8px;+ gap: 4px 8px;+ flex-wrap: wrap;+ min-width: 0;}.segmented button {@@ -1582,6 +1585,8 @@ button.ghost:hover,inset: 0;width: 100%;height: 100%;+ /* the body sets the minimum; a canvas minimum (e.g. the old .vowel-map 220 px) would overflow it */+ min-height: 0;}.left .screen-body {@@ -1791,7 +1796,8 @@ button.ghost:hover,min-width: 0;}-.keys {+/* only Play's keys screen sizes the keyboard to fill it; legacy strips keep their fixed height */+.s-keys .keys {height: auto;flex: 1;}@@ -1951,6 +1957,14 @@ input[type="range"]::-moz-range-thumb {}}+/* phones: the keys strip stacks under its MIDI button; flex: 1 from a zero basis collapsed it+ to 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;+ }+}+@media (max-width: 640px) {.app {padding: 6px 8px 12px;diff --git a/src/ui/usePhosphor.ts b/src/ui/usePhosphor.tsindex 67487b7..a44efee 100644--- a/src/ui/usePhosphor.ts+++ b/src/ui/usePhosphor.ts@@ -17,20 +17,23 @@ export function usePhosphor(draw: (f: CanvasFrame) => void, opts: { sigma?: numbconst ctx = canvas.getContext("2d")!;const glow = new Glow(sigma, alpha);let w = 0, h = 0, dpr = 1;- const ro = new ResizeObserver(() => {+ const fit = () => {const r = canvas.getBoundingClientRect();dpr = Math.min(2, window.devicePixelRatio || 1);w = r.width;h = r.height;canvas.width = Math.max(1, Math.round(w * dpr));canvas.height = Math.max(1, Math.round(h * dpr));- });+ };+ const ro = new ResizeObserver(fit);ro.observe(canvas);let raf = 0;let last = performance.now();const loop = (now: number) => {const dt = Math.min(0.05, (now - last) / 1000);last = now;+ // a window moved to a display with another scale changes DPR without a resize+ if (Math.min(2, window.devicePixelRatio || 1) !== dpr) fit();if (w > 0 && h > 0) {ctx.setTransform(1, 0, 0, 1, 0, 0);ctx.globalCompositeOperation = "source-over";