diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index a54c751de6..104067d479 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -160,6 +160,22 @@ "file": "packages/core/src/audio/audioFxGraph.ts", "exports": ["ensureAudioFxWorklets"], }, + // automationLaneGeometry is the bottom of the audio-automation stack: its + // consumer is the lane component one PR upstack, so a per-PR audit diffing + // against the merge base sees these as unused. Consumed for real once the + // stack merges; safe to drop this entry then. + { + "file": "packages/studio/src/player/components/automationLaneGeometry.ts", + "exports": [ + "POINT_MERGE_SEC", + "GRAB_PX", + "DRAW_SAMPLES", + "PAD_X", + "formatValue", + "laneFor", + "withLane", + ], + }, // drawElementService is the bottom of the fast-capture Graphite stack // (#1917): its consumers (frameCapture in #1919) land two PRs upstack, so // a per-PR audit diffing against the merge base sees these exports as diff --git a/packages/studio/src/player/components/automationLaneData.test.ts b/packages/studio/src/player/components/automationLaneData.test.ts new file mode 100644 index 0000000000..948c926167 --- /dev/null +++ b/packages/studio/src/player/components/automationLaneData.test.ts @@ -0,0 +1,66 @@ +// @vitest-environment happy-dom +import { describe, expect, it } from "vitest"; +import { elementAutomation, elementFxChain } from "./automationLaneData"; +import type { TimelineElement } from "../store/timelineElement"; + +const el = (over: Partial = {}): TimelineElement => ({ + id: "bgm", + key: "bgm", + tag: "audio", + start: 0, + duration: 10, + track: 10, + ...over, +}); + +const CHAIN = JSON.stringify({ + version: 1, + nodes: [{ type: "lowpass", id: "n1", params: { frequency: 400, q: 0.9, poles: "2" } }], +}); +const LANE = JSON.stringify({ + version: 1, + lanes: [{ target: "fx.n1.frequency", points: [{ t: 0, v: 400 }] }], +}); + +describe("automationLaneData", () => { + it("returns the same object for the same attributes", () => { + // The lane compares its drag draft against this identity; a fresh object per + // playhead tick would drop the drag. + const a = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + const b = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + expect(a).toBe(b); + expect(elementFxChain(el({ fxChain: CHAIN }))).toBe(elementFxChain(el({ fxChain: CHAIN }))); + }); + + it("re-parses when the chain changes even though the automation text did not", () => { + const withChain = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + const withoutChain = elementAutomation(el({ automation: LANE })); + expect(withChain.lanes.map((l) => l.target)).toEqual(["fx.n1.frequency"]); + // No chain to resolve against, so the fx lane is dropped rather than drawn. + expect(withoutChain.lanes).toEqual([]); + }); + + it("keeps a hot entry alive when other elements push the cache past its limit", () => { + // Eviction used to clear the whole map, which changed every lane's identity + // at once and released any drag in progress. + const hot = el({ automation: LANE, fxChain: CHAIN }); + const first = elementAutomation(hot); + for (let i = 0; i < 40; i += 1) { + elementAutomation( + el({ + automation: JSON.stringify({ + version: 1, + lanes: [{ target: "volume", points: [{ t: i, v: 0.5 }] }], + }), + }), + ); + elementAutomation(hot); + } + expect(elementAutomation(hot)).toBe(first); + }); + + it("reads an unreadable attribute as nothing rather than throwing", () => { + expect(elementAutomation(el({ automation: "{nope" })).lanes).toEqual([]); + expect(elementFxChain(el({ fxChain: "{nope" }))).toBeNull(); + }); +}); diff --git a/packages/studio/src/player/components/automationLaneData.ts b/packages/studio/src/player/components/automationLaneData.ts index c87b895eae..375f891dcd 100644 Binary files a/packages/studio/src/player/components/automationLaneData.ts and b/packages/studio/src/player/components/automationLaneData.ts differ