Repository navigation
ui: Palace tab for projector rigs; tabs follow the layout - #154
Conversation
…igs; tabs follow the layout - palace.ts: one evalPattern with geometry baked from the layout; 12 scenes, 8 flows, 17 motions, gradients, duos, trims, paint - use-palace / palace-tab: GracePaint-style hook and tab; touching a fixture paints without stopping the motion - tabs: Palace when the layout has projectors, Grace/GracePaint on rings - MiniGridPreview: wide tiles fit the layout, projectors drawn square - server: a plain cannon paint stops the brain pattern (as the receiver does); a client connecting mid-pattern gets the running pattern + params - receiver: the same pattern code again updates params instead of restarting
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟠 2 high · 🟡 3 medium 💬 Inline comments (4)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Pending pattern load can resurrect cleared sandbox state · receiver.ts:321–338 · // packages/receiver/src/receiver.ts
321 private handleEvalPattern(cmd: EvalPatternCommand): void {
322 this.ensureSandbox()
323 .then((sb) => {
324 try {
325 const meta = sb.loadPattern(cmd.code, cmd.params);
326 this._patternCode = cmd.code;
327 this._patternTime = 0;
328 this._patternFrame = 0;
329 console.log(' ◈ Pattern loaded:', meta.name || '(anonymous)');
330 } catch (e: unknown) {
331 this._animState.patternActive = false;
332 console.error(' ◈ Pattern load error:', e instanceof Error ? e.message : String(e));
This PR introduces the Palace system: a new UI tab with a paint editor (backed by
Reviewed commit: e38c896 |
There was a problem hiding this comment.
Adds the Palace paint-pattern feature spanning UI tab, look-to-JS pattern compilation, and receiver/server pattern handoff, with five confirmed defects around stale params, async load races, unvalidated pattern inputs, and preview render cost.
Key findings
- 🟠 Per-fixture shadowBlur fill in every frame — mini-grid-preview.tsx:311
- 🟠 Dedup path keeps stale params on pattern restart — receiver.ts:219
- 🟡 Pending pattern load can resurrect cleared sandbox state — receiver.ts:321
- 🟡 Speed slider restarts every preview rAF loop — mini-grid-preview.tsx:358
- 🟡
coercePalaceParamsforwards unvalidatedstops/paintto receiver — palace.ts:203
| ctx2d!.beginPath(); | ||
| if (f.kind === 'projector') ctx2d!.rect(px - dotR, py - dotR, dotR * 2, dotR * 2); | ||
| else ctx2d!.arc(px, py, dotR, 0, Math.PI * 2); | ||
| ctx2d!.fillStyle = `rgb(${r},${g},${b})`; | ||
| ctx2d!.shadowColor = `rgb(${r},${g},${b})`; | ||
| ctx2d!.shadowBlur = dotR * 1.2; | ||
| ctx2d!.fill(); |
There was a problem hiding this comment.
🟠 performance · high
Per-fixture shadowBlur fill in every frame
The new wide-tile branch sets shadowColor/shadowBlur and issues a beginPath+fill per fixture on every rAF tick (packages/ui/src/components/mini-grid-preview.tsx:311-317). Each shadowed fill forces the canvas backend to run a separate blur composite, so a 24-fixture rig at 60fps performs ~1,500 blurred composites per second per tile — and PalaceTab mounts many such tiles at once. This will dominate frame time on the tablets/phones this UI targets.
📋 Prompt for AI Agents
In packages/ui/src/components/mini-grid-preview.tsx lines 306-319 (wide-tile branch of the tick loop), remove the per-fixture shadowColor/shadowBlur state and fills. Instead, pre-render once per effect run a small offscreen canvas containing a white radial glow, then per fixture draw that sprite tinted via the dot color with globalCompositeOperation = 'lighter' (or draw plain arc fills plus one cached gradient overlay). Keep the per-fixture loop free of shadow state entirely. The same per-fixture shadow pattern exists in the ring branch at lines 329-341.
| if (sameCode) { | ||
| // The same pattern again (a UI restarting it, a reconnect): take its | ||
| // params without resetting the pattern clock. | ||
| for (const [name, value] of Object.entries(cmd.params ?? {})) { | ||
| this.handleSetPatternParam({ type: 'command', action: 'setPatternParam', name, value }); | ||
| } | ||
| } else { | ||
| this.handleEvalPattern(cmd); | ||
| } |
There was a problem hiding this comment.
🟠 bug · high
Dedup path keeps stale params on pattern restart
When an evalPattern re-sends the same code, the receiver takes the dedup branch and applies only the keys present in cmd.params (packages/receiver/src/receiver.ts:222-224), never resetting the others. The server instead performs a full patternEngine.load(msg.code, params), which resets params to the pattern's declared defaults before applying initialParams (packages/server/src/pattern-engine.ts:74-77) but broadcasts the raw msg.params (packages/server/src/server.ts:1101-1107). Restarting a pattern with a partial params object therefore leaves receivers running previously-tuned values (e.g. an earlier setPatternParam speed) while the server preview uses the declared defaults — rig and preview visibly diverge. Impact: receivers render the restarted pattern with stale parameters until every param is individually re-sent.
📋 Prompt for AI Agents
In packages/receiver/src/receiver.ts lines 219-224, the evalPattern dedup branch reapplies only Object.entries(cmd.params) via handleSetPatternParam, skipping the parameter reset that a full loadPattern performs. Fix so a same-code restart matches ServerPatternEngine.load semantics (packages/server/src/pattern-engine.ts lines 74-77: params reset to meta.params defaults, then initialParams applied). Preferred: add a method to the receiver's SandboxEngine that resets params to the pattern's declared defaults, call it at the start of the dedup branch before applying cmd.params. Alternatively change packages/server/src/server.ts case 'evalPattern' (lines 1101-1107) to broadcast params: patternEngine.currentParams after patternEngine.load so receivers always receive the complete effective param set.
| rafRef.current = requestAnimationFrame(tick); | ||
| return () => cancelAnimationFrame(rafRef.current); | ||
| }, [speed, size, ring, fixtures]); | ||
| }, [speed, size, height, ring, fixtures]); |
There was a problem hiding this comment.
🟡 performance · medium
Speed slider restarts every preview rAF loop
The render effect depends on speed and re-runs its whole setup on each change: it rebuilds geometry and buffers and resets startRef/frameRef to 0 (packages/ui/src/components/mini-grid-preview.tsx:189-198, 358). Dragging the Speed slider fires this on every input event, so all mounted preview tiles tear down and restart their animation from t=0 dozens of times per drag — visible hitching plus allocation churn. speed is only read as a time multiplier, which needs no restart.
📋 Prompt for AI Agents
In packages/ui/src/components/mini-grid-preview.tsx, add a speedRef updated on every render (mirroring easingRef/paramsRef at lines 166-169), read speedRef.current inside tick() where t/frame/dt are computed (lines 219-221), and remove speed from the effect dependency array at line 358 so slider drags no longer tear down and restart every preview loop. Leave size in the dependencies — the effect reads canvas.width/canvas.height.
| const who: Who = p.who === 'cannon' || p.who === 'projector' ? p.who : 'both'; | ||
| return { | ||
| kind: 'palace', | ||
| stops: p.stops as [number, number][], |
There was a problem hiding this comment.
🟡 bug · medium
coercePalaceParams forwards unvalidated stops/paint to receiver
coercePalaceParams validates scalars via num() but blind-casts p.stops as [number, number][] (packages/ui/src/lib/palace.ts:203) and accepts any finite p.paint values (line 199) from loosely-typed look JSON before it is sent to the receiver's pattern. A look with stop entries like null, strings, or 1-element arrays reaches the generated pattern's grad(stops, u), where a missing component makes hue/sat NaN; the pattern's hue wrap ((c[0] + hueShift) % 360 + 360) % 360 and brightness clamp do not filter NaN, so NaN or out-of-range values are written via ctx.set toward hardware commands, and a null entry throws inside the sandbox render loop every tick, freezing the pattern's output. Impact: corrupt saved-look data silences or garbles the rig with only per-tick console errors.
📋 Prompt for AI Agents
In packages/ui/src/lib/palace.ts in coercePalaceParams (lines 196-213), replace the blind cast p.stops as [number, number][] with a validation pass: keep only entries that are arrays of two finite numbers, coerced via num() and clamped to hue [0, 360) and sat [0, 100] (fall back to a default like [[220, 90]] if none survive). Also clamp accepted paint values: hue indices into [0, 360) unless negative-sentinel, sat indices into [0, 100]. This prevents NaN or out-of-range values from a malformed saved Look reaching ctx.set, since the pattern's hue wrap and brightness clamp do not filter NaN.
…only dedups a full param re-send
Summary
Adds Palace, a one-tap show tab for the Palace of Fine Arts rig (
interleaved-12x2: cannon row zippered with a projector row). It changes colour and brightness only. It never sends projector size, position, FX or cue commands.lib/palace.ts: oneevalPattern(palacePattern(fixtures)) with geometry baked in fromlayout.fixtures(Xposition along the line,RANKzigzag order,PROJkind). Because of that, it renders the same in the brain preview, the receiver sandbox andMiniGridPreview. Params:stops, flow, span, spin, anim, who, level, cannon, projector, paint.GRADIENTS, duos (PAIRS+ Gold/White), plus per-kind trims.use-palace.ts/palace-tab.tsx(Scenes · Colour · Motion · Paint sub-tabs, saved looks) follow the GracePaint model: while the pattern runs, every change is asetPatternParam. Touching a fixture in Palace setspaint[i]and the motion keeps running.MiniGridPreview: an optionalheightgives a wide tile that fits the fixtures' bounding box, with projectors drawn square.cannonpaint now stops the brain's pattern engine. The receiver already dropped its pattern onpaint, so before this the preview kept animating while the lasers didn't. A client that connects mid-pattern is now sentevalPatternwith the current code and params, so a reconnecting receiver picks the pattern back up.evalPatternwith the same code as the loaded pattern applies its params instead of reloading, so the pattern clock doesn't reset.Tests:
ui/__tests__/palace.test.ts(every motion × who stays finite and within 0–100, trims, duos, paint override, scene validity) andserver/__tests__/pattern-handoff.test.ts(reconnect gets the running pattern; cannon paint stops it).pnpm build, lint and all package tests pass locally.Link to Devin session: https://app.devin.ai/sessions/e6939c79261649988b8277ba34725160
Open in Devin Desktop: https://app.devin.ai/desktop/session/e6939c79261649988b8277ba34725160?variant=devin
Requested by: @pyramation