Skip to content

ui: Palace tab for projector rigs; tabs follow the layout - #154

Merged
pyramation merged 2 commits into
mainfrom
devin/1794562184-palace-tab
Nov 13, 2026
Merged

pyramation merged 2 commits into
mainfrom
devin/1794562184-palace-tab

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

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: one evalPattern (palacePattern(fixtures)) with geometry baked in from layout.fixtures (X position along the line, RANK zigzag order, PROJ kind). Because of that, it renders the same in the brain preview, the receiver sandbox and MiniGridPreview. Params: stops, flow, span, spin, anim, who, level, cannon, projector, paint.
    • 12 scenes (Monument, Golden Hour, Lagoon, …), 8 colour flows, 17 brightness motions, all existing 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 a setPatternParam. Touching a fixture in Palace sets paint[i] and the motion keeps running.
  • Tab visibility now follows the layout instead of a static list:
    tabsFor(layout): paint, pool, gradient
      + palace         if layout.fixtures.some(kind === 'projector')
      + grace, gracepaint if layout.topology === 'rings'
    A saved tab that this rig doesn't show falls back to Paint.
  • MiniGridPreview: an optional height gives a wide tile that fits the fixtures' bounding box, with projectors drawn square.
  • Server: a plain cannon paint now stops the brain's pattern engine. The receiver already dropped its pattern on paint, so before this the preview kept animating while the lasers didn't. A client that connects mid-pattern is now sent evalPattern with the current code and params, so a reconnecting receiver picks the pattern back up.
  • Receiver: an evalPattern with 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) and server/__tests__/pattern-handoff.test.ts (reconnect gets the running pattern; cannon paint stops it). pnpm build, lint and all package tests pass locally.

Palace scenes
Palace motion
Palace colour

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

…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
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

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 · unchanged line

// 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));

handleEvalPattern defers loadPattern and the writes to _patternCode/_patternTime/_patternFrame into a .then after an awaited ensureSandbox (packages/receiver/src/receiver.ts:321-338), so a clear/stopPattern (which calls disposeSandbox, receiver.ts:367-373) or a newer evalPattern can run in between. The stale callback then loads into the disposed/replaced engine and still sets _patternCode = A after pattern B is loaded, corrupting the dedup key: a later evalPattern of A hits the sameCode branch (receiver.ts:217) and applies A's params to B's sandbox, so the wrong pattern keeps rendering with no clock reset. If the disposed engine throws instead, the catch sets patternActive = false and silently kills the newer pattern. Impact: receivers run the wrong pattern (or lose the current one) after a rapid stop/switch during sandbox startup.


This PR introduces the Palace system: a new UI tab with a paint editor (backed by use-palace/use-grace-paint), a look-to-JavaScript pattern compiler in palace.ts, and receiver/server changes so evalPattern code can be deduplicated and re-applied with live params across reconnects.

Files Change
packages/ui/src/lib/palace.ts, use-palace.ts, use-grace-paint.ts New look/paint state model, param coercion, and the compiler that generates the JS pattern sent to receivers
packages/ui/src/components/palace-tab.tsx, mini-grid-preview.tsx, grid-display.tsx, app.tsx Palace tab UI with live per-look preview tiles and palace routing in the main tab/cannon handlers
packages/receiver/src/receiver.ts evalPattern same-code dedup path that applies params without resetting the pattern clock, plus async sandbox-load handling
packages/server/src/server.ts Reconnect re-send of pattern code and currentParams, and cannon handler stopping an active pattern engine
packages/server/__tests__/pattern-handoff.test.ts, packages/ui/__tests__/palace.test.ts Tests for the handoff dedup path and the look compiler/preview logic

Reviewed commit: e38c896

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +311 to +317
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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Comment on lines +219 to +227
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);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread packages/ui/src/lib/palace.ts Outdated
const who: Who = p.who === 'cannon' || p.who === 'projector' ? p.who : 'both';
return {
kind: 'palace',
stops: p.stops as [number, number][],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@pyramation
pyramation merged commit 6946dc7 into main Nov 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant