mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 00:07:09 +00:00
fix(studio): clamp selection-start paste, sharpen clipboard test, cleanup
- useAutomationSelectionKeyboard: clamp the selection-start paste branch to [0, element.duration - clip.span], same as the playhead branch already does. An unclamped paste near a clip's end could write points past element.duration and leave the resulting selection's edge ungrabbable off the visible lane. - automationClipboard.test.ts: swap the cross-parameter mapping test's target from fx.r.wet (numerically identical to VOLUME_RANGE) to the log-scaled fx.n1.frequency, so the test actually discriminates real unit-space mapping from a linear guess or a verbatim value copy. - automationLaneSelection.ts: drop the lone `!` non-null assertion in decimateEvenly's budget-of-1 branch for a guarded pattern, matching the loop right below it and the repo's no-`!` convention. - .fallowrc.jsonc: remove the two ignoreExports entries for AUTOMATION_SHAPES and simplifyPoints — both are now genuinely consumed (AutomationSelectionMenu.tsx, TimelineAutomationLane.tsx). - AutomationSelectionMenu.tsx: port TrackGapContextMenu's viewport-edge clamping so a right-click near the bottom/right of the timeline doesn't render the shape/simplify menu partially off-screen.
This commit is contained in:
@@ -176,22 +176,6 @@
|
||||
"withLane",
|
||||
],
|
||||
},
|
||||
// automationShapes is part of the audio-automation stack: its consumer is
|
||||
// the UI layer that uses shape generators 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/automationShapes.ts",
|
||||
"exports": ["AUTOMATION_SHAPES"],
|
||||
},
|
||||
// automationSimplify is part of the audio-automation stack: its consumer is
|
||||
// the UI layer 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/automationSimplify.ts",
|
||||
"exports": ["simplifyPoints"],
|
||||
},
|
||||
// propertyPanelAutomation is the shared reader for both panel sections; the
|
||||
// FX group that consumes these two lands one PR upstack, so a per-PR audit
|
||||
// against the merge base sees them as unused.
|
||||
|
||||
@@ -221,6 +221,40 @@ describe("useAutomationSelectionKeyboard", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("Cmd+V at a selection near the clip's end clamps the paste inside its duration", () => {
|
||||
// The playhead branch already clamps to duration - span; the
|
||||
// selection-start branch didn't, so pasting a 2s clip at a selection
|
||||
// sitting at t0=5.5 on a 6s clip used to write points out to t=7.5 —
|
||||
// past element.duration — and leave the selection itself out of bounds.
|
||||
clearAutomationClipboard();
|
||||
usePlayerStore.setState({ elements: [bgmElement], selectedElementId: "bgm" });
|
||||
usePlayerStore
|
||||
.getState()
|
||||
.setAutomationSelection({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 });
|
||||
const { onCommit } = setup({});
|
||||
combo("c");
|
||||
expect(readClipboard(null)?.span).toBe(2);
|
||||
|
||||
// A 0.1s-wide selection right near the clip's 6s end.
|
||||
usePlayerStore
|
||||
.getState()
|
||||
.setAutomationSelection({ elementKey: "bgm", target: "volume", t0: 5.5, t1: 5.6 });
|
||||
combo("v");
|
||||
const written = onCommit.mock.calls.at(-1)?.[0];
|
||||
const times = (written?.lanes?.[0]?.points ?? []).map((p: { t: number }) => p.t);
|
||||
for (const t of times) {
|
||||
expect(t).toBeGreaterThanOrEqual(0);
|
||||
expect(t).toBeLessThanOrEqual(bgmElement.duration);
|
||||
}
|
||||
// Clamped to duration (6) - span (2) = 4, not the unclamped 5.5.
|
||||
expect(usePlayerStore.getState().automationSelection).toEqual({
|
||||
elementKey: "bgm",
|
||||
target: "volume",
|
||||
t0: 4,
|
||||
t1: 6,
|
||||
});
|
||||
});
|
||||
|
||||
it("refuses to paste when the dom-edit layer would write to a different clip", () => {
|
||||
// selectedElementId says "bgm" but the commit channel is still on the
|
||||
// previously selected clip — writing here would serialize bgm's automation
|
||||
|
||||
@@ -30,11 +30,19 @@ export const AutomationSelectionMenu = memo(function AutomationSelectionMenu({
|
||||
const menuRef = useContextMenuDismiss(onClose);
|
||||
const row =
|
||||
"block w-full px-2 py-1 text-left text-[11px] text-panel-text-1 hover:bg-panel-bg-3 disabled:opacity-40";
|
||||
// Same edge-clamping precedent as TrackGapContextMenu: without it a
|
||||
// right-click near the bottom/right of the timeline renders this menu
|
||||
// partially off-screen.
|
||||
const menuWidth = 140;
|
||||
const menuHeight = AUTOMATION_SHAPES.length * 24 + 32;
|
||||
const overflowY = y + menuHeight - window.innerHeight;
|
||||
const adjustedX = x + menuWidth > window.innerWidth ? x - menuWidth : x;
|
||||
const adjustedY = overflowY > 0 ? y - overflowY - 8 : y;
|
||||
return createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="hf-automation-menu fixed z-50 min-w-[140px] rounded border border-panel-border-input bg-panel-bg-2 py-1 shadow-lg"
|
||||
style={{ left: x, top: y }}
|
||||
style={{ left: adjustedX, top: adjustedY }}
|
||||
>
|
||||
{AUTOMATION_SHAPES.map((shape) => (
|
||||
<button
|
||||
|
||||
@@ -39,19 +39,34 @@ describe("automation clipboard", () => {
|
||||
});
|
||||
|
||||
it("maps values through unit space onto a different parameter", () => {
|
||||
const wet = resolveAutomationRange("fx.r.wet", {
|
||||
// fx.n1.frequency (lowpass cutoff) is log-scaled (min:20, max:20000):
|
||||
// linear unit math and a literal copy of the source value would both
|
||||
// read as a passing test on a range that happens to be numerically
|
||||
// identical to VOLUME_RANGE (e.g. fx.r.wet), so this target has to be
|
||||
// genuinely log for the test to discriminate real unit-space mapping.
|
||||
const frequency = resolveAutomationRange("fx.n1.frequency", {
|
||||
version: 1,
|
||||
nodes: [{ type: "reverb", id: "r", params: {} }],
|
||||
nodes: [{ type: "lowpass", id: "n1", params: {} }],
|
||||
});
|
||||
expect(wet).toBeTruthy();
|
||||
if (!wet) return;
|
||||
expect(frequency).toBeTruthy();
|
||||
if (!frequency) return;
|
||||
expect(frequency.scale).toBe("log");
|
||||
copyRange("project-a", duck, VOLUME_RANGE, 2, 4);
|
||||
const entry = readClipboard("project-a");
|
||||
if (!entry) return;
|
||||
const pts = pastePoints(entry, wet, 0);
|
||||
// volume 1 (unit 1) → wet max; volume 0.25 (unit 0.25) → a quarter up wet's axis
|
||||
expect(pts[0]?.v).toBeCloseTo(wet.max, 5);
|
||||
expect(pts[1]?.v).toBeCloseTo(wet.min + 0.25 * (wet.max - wet.min), 5);
|
||||
const pts = pastePoints(entry, frequency, 0);
|
||||
// volume 1 (unit 1) → frequency max; volume 0.25 (unit 0.25) → a quarter
|
||||
// up frequency's LOG axis, i.e. exp(ln(min) + 0.25*(ln(max)-ln(min))) —
|
||||
// NOT the naive linear guess (min + 0.25*(max-min)) and nowhere near a
|
||||
// literal copy of 0.25.
|
||||
expect(pts[0]?.v).toBeCloseTo(frequency.max, 5);
|
||||
const expectedLog = Math.exp(
|
||||
Math.log(frequency.min) + 0.25 * (Math.log(frequency.max) - Math.log(frequency.min)),
|
||||
);
|
||||
const naiveLinear = frequency.min + 0.25 * (frequency.max - frequency.min);
|
||||
expect(pts[1]?.v).toBeCloseTo(expectedLog, 5);
|
||||
expect(pts[1]?.v).not.toBeCloseTo(naiveLinear, 0);
|
||||
expect(pts[1]?.v).not.toBeCloseTo(0.25, 0);
|
||||
});
|
||||
|
||||
it("reads null when nothing was copied", () => {
|
||||
|
||||
@@ -42,7 +42,10 @@ function anchor(
|
||||
function decimateEvenly<T>(items: readonly T[], budget: number): T[] {
|
||||
if (budget <= 0) return [];
|
||||
if (items.length <= budget) return [...items];
|
||||
if (budget === 1) return [items[0]!];
|
||||
if (budget === 1) {
|
||||
const item = items[0];
|
||||
return item ? [item] : [];
|
||||
}
|
||||
const out: T[] = [];
|
||||
const step = (items.length - 1) / (budget - 1);
|
||||
for (let i = 0; i < budget; i += 1) {
|
||||
|
||||
Reference in New Issue
Block a user