Skip to content

Write HTML. Render video. Built for agents.

feat(studio): edit a clip's speed ramp with a rate lane and presets (#4153)

Miguel Ángel0c158be16506
diff --git a/docs/docs.json b/docs/docs.json
index a0edc083f2..bedd182a00 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -916,7 +916,8 @@
"pages": [
"reference/html-schema",
"reference/color-grading",
- "reference/audio-effects"
+ "reference/audio-effects",
+ "reference/speed-ramps"
]
},
{
diff --git a/docs/reference/html-schema.mdx b/docs/reference/html-schema.mdx
index e11aa8d93f..db42909ec6 100644
--- a/docs/reference/html-schema.mdx
+++ b/docs/reference/html-schema.mdx
@@ -124,7 +124,7 @@ Audio has no visual lifecycle.
| Attribute | Applies to | Meaning |
| --- | --- | --- |
| `data-media-start` / `data-playback-start` | Video, audio, nested composition | Offset into the source file, used by trim and split. Two groups of readers disagree, so the right name depends on the element. **Read only `data-media-start`:** the timing compiler, the HTML parser, `hyperframes validate` (which only inspects `<audio>`), and the engine's audio mixer (which feeds ffmpeg `-ss`). **Read `data-playback-start` first, falling back to `data-media-start`:** the runtime player, Studio (which also writes it), and `hyperframes snapshot`. Because the audio mixer reads only `data-media-start`, a `<video>` authored with just `data-playback-start` renders a trimmed picture over untrimmed audio. Set the name by kind: **`<video>` / `<audio>` → `data-media-start`**; **nested composition → `data-playback-start`** — composition hosts are inspected only by the playback-start-first readers (the media-start-only ones are all `<video>`/`<audio>`-scoped). `data-media-start` still works there as a fallback, but `data-playback-start` is the canonical name Studio writes and normalises to for new composition hosts, so the other name works until an edit rewrites it (it is the [child-timeline offset](/concepts/compositions)). |
-| `data-playback-rate` | Video, audio, nested composition | Playback multiplier from `0.1` to `5` |
+| `data-playback-rate` | Video, audio, nested composition | Playback multiplier from `0.1` to `10`. A `rate` lane in `data-automation` overrides it; see [Speed ramps](/reference/speed-ramps) |
| `data-volume` | Video and audio | Static gain. `1` is 0 dB, `0` is silence, and values above `1` boost up to `3.98` (+12 dB) |
| `data-has-audio="true"` | Video | Declares that the video contributes audio |
diff --git a/docs/reference/speed-ramps.mdx b/docs/reference/speed-ramps.mdx
new file mode 100644
index 0000000000..13d4cd4902
--- /dev/null
+++ b/docs/reference/speed-ramps.mdx
@@ -0,0 +1,66 @@
+---
+title: "Speed ramps"
+sidebarTitle: "Speed ramps"
+description: "Change a clip's playback speed over time with a rate lane in data-automation. One curve drives the preview, the render and Studio."
+---
+
+A speed ramp changes how fast a `<video>` or `<audio>` clip plays while it
+plays: slow into a beat, fast out of it. It is a `rate` lane in
+[`data-automation`](/reference/audio-effects#the-four-attributes), the same
+attribute that carries volume envelopes.
+
+```html
+<video
+ src="clip.mp4"
+ data-start="0"
+ data-duration="4"
+ data-track-index="0"
+ data-automation='{"version":1,"lanes":[{"target":"rate","points":[{"t":0,"v":1},{"t":2,"v":4},{"t":4,"v":0.5}]}]}'
+></video>
+```
+
+## The lane
+
+| Field | Meaning |
+| --- | --- |
+| `target` | `"rate"` |
+| `points[].t` | Seconds from the start of the clip, not from the start of the composition |
+| `points[].v` | Speed multiplier. `1` is normal, `2` is twice as fast. Clamped to `0.1` to `10` |
+| `points[].curve` | Optional, `-1` to `1`. Bends the segment leaving this point |
+
+Speed moves between points on a logarithmic scale, so going from `0.5` to `2`
+passes through `1` at the midpoint. A lane wins over the constant
+`data-playback-rate` on the same element. Without a lane, the constant applies.
+
+## What stays the same everywhere
+
+The source frame shown at each moment comes from one function, `sourceTimeAt`,
+which the preview and the renderer both use, so the render shows the frames the
+preview showed. Set `data-duration` on the clip to fix how long it holds the
+timeline; without it the length follows from the source and the speed.
+
+Pitch is kept. The preview leaves the browser's default pitch correction on.
+The render time-stretches audio in short constant-speed slices (a quarter
+second, coarser on clips longer than a minute), which approximates the curve
+while keeping pitch, so the sound follows the ramp closely rather than exactly.
+
+## Presets
+
+Studio's **Speed preset** menu draws a ready curve over the clip: Montage,
+Hero, Bullet, Jump cut, Flash in and Flash out. An agent can write the same
+points by hand.
+
+## Editing in Studio
+
+Select a clip and open its Media section. The **Speed** slider sets the
+constant rate. The **A** toggle next to it automates speed, which shows a rate
+lane on the clip in the timeline that you edit like the volume lane.
+
+## Limits
+
+- Only `<video>` and `<audio>` clips carry a rate lane.
+- Speeds outside `0.1` to `10` are clamped.
+- The viewer's own transport speed is a separate control that multiplies with
+ the clip's speed, and it is narrower: the Studio speed menu offers `0.25` to
+ `2`, the player's menu offers up to `4`, and the runtime clamps a transport
+ request to `0.1` to `5`.
diff --git a/packages/cli/src/commands/snapshot.test.ts b/packages/cli/src/commands/snapshot.test.ts
index 42022c4945..7a1f56561c 100644
--- a/packages/cli/src/commands/snapshot.test.ts
+++ b/packages/cli/src/commands/snapshot.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from "vitest";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { tmpdir } from "node:os";
+import { sourceTimeAt } from "@hyperframes/core";
const snapshotState = vi.hoisted(() => ({
openSettledPage: vi.fn(async () => {
@@ -29,7 +30,7 @@ import snapshotCommand, {
requireSnapshotFfmpeg,
resolveSnapshotVideoClipStart,
resolveSnapshotVideoFrameTime,
- resolveSnapshotVideoPlaybackRate,
+ resolveSnapshotVideoRateSpec,
tailFrameTime,
} from "./snapshot.js";
@@ -274,9 +275,40 @@ describe("resolveSnapshotVideoClipStart", () => {
});
});
-describe("resolveSnapshotVideoPlaybackRate", () => {
+describe("resolveSnapshotVideoRateSpec", () => {
it("prefers the authored data-playback-rate over the browser default", () => {
- expect(resolveSnapshotVideoPlaybackRate({ authoredRate: "1.8", defaultRate: 1 })).toBe(1.8);
+ expect(resolveSnapshotVideoRateSpec({ authoredRate: "1.8", defaultRate: 1 })).toBe(1.8);
+ });
+
+ it("falls back to the browser default when the authored rate is invalid", () => {
+ expect(resolveSnapshotVideoRateSpec({ authoredRate: "abc", defaultRate: 2 })).toBe(2);
+ expect(resolveSnapshotVideoRateSpec({ authoredRate: "0", defaultRate: 2 })).toBe(2);
+ });
+
+ it("allows rates up to the shared 10x bound", () => {
+ expect(resolveSnapshotVideoRateSpec({ authoredRate: "8", defaultRate: 1 })).toBe(8);
+ });
+
+ it("maps a frame through a rate lane instead of the constant", () => {
+ const lane = JSON.stringify({
+ version: 1,
+ lanes: [
+ {
+ target: "rate",
+ points: [
+ { t: 0, v: 1 },
+ { t: 2, v: 3 },
+ ],
+ },
+ ],
+ });
+ const spec = resolveSnapshotVideoRateSpec({
+ authoredRate: "1",
+ authoredAutomation: lane,
+ defaultRate: 1,
+ });
+ expect(typeof spec).toBe("object");
+ expect(sourceTimeAt(spec, 2)).toBeCloseTo(3.641, 2);
});
});
diff --git a/packages/cli/src/commands/snapshot.ts b/packages/cli/src/commands/snapshot.ts
index 24561425c9..4a8fb8f7be 100644
--- a/packages/cli/src/commands/snapshot.ts
+++ b/packages/cli/src/commands/snapshot.ts
@@ -14,6 +14,12 @@ import {
seekCompositionTimeline,
type ZoomTarget,
} from "../capture/captureCompositionFrame.js";
+import {
+ readElementRateSpec,
+ sourceTimeAt,
+ timeAtSourceTime,
+ type RateSpec,
+} from "@hyperframes/core";
import { resolveProject } from "../utils/project.js";
import {
definitiveEntryMismatchComposition,
@@ -110,16 +116,22 @@ export function resolveSnapshotVideoClipStart(input: {
return input.runtimeResolvedStart ?? input.authoredStart;
}
-/** Match runtime/render timing: authored data-playback-rate wins over the
- * browser default, then the effective rate is clamped to the supported range. */
-export function resolveSnapshotVideoPlaybackRate(input: {
+/** Match runtime/render timing: a `rate` lane in data-automation wins, then the authored
+ * data-playback-rate, then the browser default, all through the runtime's own reader. */
+export function resolveSnapshotVideoRateSpec(input: {
authoredRate: string | undefined;
+ authoredAutomation?: string | undefined;
defaultRate: number;
-}): number {
+}): RateSpec {
const authoredRate = Number.parseFloat(input.authoredRate ?? "");
- const rawRate =
- Number.isFinite(authoredRate) && authoredRate > 0 ? authoredRate : input.defaultRate;
- return Number.isFinite(rawRate) && rawRate > 0 ? Math.max(0.1, Math.min(5, rawRate)) : 1;
+ const attrs: Record<string, string | undefined> = {
+ "data-playback-rate":
+ Number.isFinite(authoredRate) && authoredRate > 0
+ ? input.authoredRate
+ : String(input.defaultRate),
+ "data-automation": input.authoredAutomation,
+ };
+ return readElementRateSpec({ getAttribute: (name) => attrs[name] ?? null });
}
export function requireSnapshotFfmpeg(ffmpegPath: string | undefined): string {
@@ -454,6 +466,7 @@ async function captureSnapshots(
src: v.currentSrc || v.src,
authoredStart,
authoredRate: v.dataset.playbackRate,
+ authoredAutomation: v.dataset.automation,
defaultRate: v.defaultPlaybackRate,
runtimeResolvedStart:
runtimeResolvedStart !== undefined && Number.isFinite(runtimeResolvedStart)
@@ -469,13 +482,16 @@ async function captureSnapshots(
});
const active = candidates.flatMap((candidate) => {
const start = resolveSnapshotVideoClipStart(candidate);
- const playbackRate = resolveSnapshotVideoPlaybackRate(candidate);
+ const playbackRate = resolveSnapshotVideoRateSpec(candidate);
const duration =
candidate.authoredDuration ??
(candidate.srcDuration > 0
- ? Math.max(0, (candidate.srcDuration - candidate.mediaStart) / playbackRate)
+ ? Math.max(
+ 0,
+ timeAtSourceTime(playbackRate, candidate.srcDuration - candidate.mediaStart),
+ )
: Number.POSITIVE_INFINITY);
- let relTime = (time - start) * playbackRate + candidate.mediaStart;
+ let relTime = sourceTimeAt(playbackRate, time - start) + candidate.mediaStart;
if (
candidate.loop &&
candidate.srcDuration > candidate.mediaStart &&
diff --git a/packages/core/package-subpaths.json b/packages/core/package-subpaths.json
index d3153d5762..6a390f486a 100644
--- a/packages/core/package-subpaths.json
+++ b/packages/core/package-subpaths.json
@@ -188,6 +188,12 @@
"types": "./dist/audioGain.d.ts",
"environments": ["browser", "bun", "node"]
},
+ "./speed-ramp": {
+ "source": "./src/speedRamp.ts",
+ "runtime": "./dist/speedRamp.js",
+ "types": "./dist/speedRamp.d.ts",
+ "environments": ["browser", "bun", "node"]
+ },
"./color-grading": {
"source": "./src/colorGrading.ts",
"runtime": "./dist/colorGrading.js",
diff --git a/packages/core/package.json b/packages/core/package.json
index def644a583..69288f6abf 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -202,6 +202,12 @@
"import": "./src/audioGain.ts",
"types": "./src/audioGain.ts"
},
+ "./speed-ramp": {
+ "bun": "./src/speedRamp.ts",
+ "node": "./dist/speedRamp.js",
+ "import": "./src/speedRamp.ts",
+ "types": "./src/speedRamp.ts"
+ },
"./color-grading": {
"bun": "./src/colorGrading.ts",
"node": "./dist/colorGrading.js",
@@ -540,6 +546,10 @@
"import": "./dist/audioGain.js",
"types": "./dist/audioGain.d.ts"
},
+ "./speed-ramp": {
+ "import": "./dist/speedRamp.js",
+ "types": "./dist/speedRamp.d.ts"
+ },
"./color-grading": {
"import": "./dist/colorGrading.js",
"types": "./dist/colorGrading.d.ts"
diff --git a/packages/studio/src/components/editor/propertyPanelFlatMediaSection.test.tsx b/packages/studio/src/components/editor/propertyPanelFlatMediaSection.test.tsx
index c15a46b03f..4aa0bcdd9d 100644
--- a/packages/studio/src/components/editor/propertyPanelFlatMediaSection.test.tsx
+++ b/packages/studio/src/components/editor/propertyPanelFlatMediaSection.test.tsx
@@ -250,8 +250,8 @@ describe("FlatMediaSection — volume/rate/media-start", () => {
rateTrack.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true, clientX: 100 }));
rateTrack.dispatchEvent(new MouseEvent("pointerup", { bubbles: true, clientX: 100 }));
});
- // min=25, max=300, ratio=1.0 -> raw=300 -> commit(300) -> 300/100=3 -> "3"
- expect(onSetAttribute).toHaveBeenCalledWith("playback-rate", "3");
+ // the speed slider is log-scaled 0.1x..10x, so the far end of the track is 10x
+ expect(onSetAttribute).toHaveBeenCalledWith("playback-rate", "10");
act(() => root.unmount());
});
diff --git a/packages/studio/src/components/editor/propertyPanelFlatMediaSection.tsx b/packages/studio/src/components/editor/propertyPanelFlatMediaSection.tsx
index 52aacdf70b..7fbdb2836f 100644
--- a/packages/studio/src/components/editor/propertyPanelFlatMediaSection.tsx
+++ b/packages/studio/src/components/editor/propertyPanelFlatMediaSection.tsx
@@ -13,6 +13,10 @@ import {
import { FlatSelectRow, FlatSlider } from "./propertyPanelFlatPrimitives";
import { FlatToggle } from "./propertyPanelFlatToggle";
import { AutomationToggle } from "./propertyPanelFxControls";
+import { RATE_RANGE } from "@hyperframes/core/audio-automation";
+import { type SpeedPresetId } from "@hyperframes/core/speed-ramp";
+import { SPEED_PRESET_OPTIONS, type RateBinding } from "./useVolumeAutomation";
+import { fromUnit, toUnit } from "../../player/components/automationLaneGeometry";
import {
AUDIO_GAIN_FADER_MAX,
AUDIO_GAIN_FADER_MIN,
@@ -36,6 +40,7 @@ export function FlatMediaSection({
onRemoveVolumeAutomation,
onCommitVolumeAt,
automatedVolumeValue,
+ rate,
}: {
projectDir: string | null;
element: DomEditSelection;
@@ -49,6 +54,8 @@ export function FlatMediaSection({
onRemoveVolumeAutomation?: () => void;
onCommitVolumeAt?: (v: number) => void;
automatedVolumeValue?: number;
+ /** Speed lane binding and presets; absent outside the Studio panel. */
+ rate?: RateBinding;
onRemoveBackground?: (
inputPath: string,
options: {
@@ -77,7 +84,9 @@ export function FlatMediaSection({
Number.parseFloat(
element.dataAttributes["media-start"] ?? element.dataAttributes["playback-start"] ?? "0",
) || 0;
- const playbackRate = Number.parseFloat(element.dataAttributes["playback-rate"] ?? "1") || 1;
+ const constantRate = Number.parseFloat(element.dataAttributes["playback-rate"] ?? "1") || 1;
+ const playbackRate =
+ rate?.automated && rate.automatedValue !== undefined ? rate.automatedValue : constantRate;
const sourceDuration =
Number.parseFloat(element.dataAttributes["source-duration"] ?? "") ||
(el as HTMLMediaElement).duration ||
@@ -259,17 +268,42 @@ export function FlatMediaSection({
}
/>
</div>
- <FlatSlider
- label="Rate"
- value={playbackRate * 100}
- min={25}
- max={300}
- tier={playbackRate === 1 ? "default" : "explicitCustom"}
- displayValue={`${formatNumericValue(playbackRate)}x`}
- onCommit={(next) =>
- void onSetAttribute("playback-rate", formatNumericValue(next / 100))
- }
- />
+ <div className="flex items-center gap-1">
+ <div className="min-w-0 flex-1">
+ <FlatSlider
+ label="Speed"
+ value={Math.round(toUnit(RATE_RANGE, playbackRate) * 1000)}
+ min={0}
+ max={1000}
+ tier={playbackRate === 1 ? "default" : "explicitCustom"}
+ displayValue={`${formatNumericValue(playbackRate)}x`}
+ onCommit={(next) => {
+ const speed = fromUnit(RATE_RANGE, next / 1000);
+ if (rate?.automated) {
+ rate.onCommitAt(speed);
+ } else {
+ void onSetAttribute("playback-rate", formatNumericValue(speed));
+ }
+ }}
+ />
+ </div>
+ <AutomationToggle
+ paramKey="rate"
+ label="Speed"
+ automated={Boolean(rate?.automated)}
+ onAutomate={rate ? () => rate.onAutomate() : undefined}
+ onRemoveAutomation={rate ? () => rate.onRemoveAutomation() : undefined}
+ />
+ </div>
+ {rate?.canApplyPreset && (
+ <FlatSelectRow
+ label="Speed preset"
+ value=""
+ options={[{ value: "", label: "Choose…" }, ...SPEED_PRESET_OPTIONS]}
+ tier="default"
+ onChange={(id) => id && rate.onApplyPreset(id as SpeedPresetId)}
+ />
+ )}
<FlatSlider
label="Media start"
value={Math.round(mediaStart * 100)}
diff --git a/packages/studio/src/components/editor/useVolumeAutomation.test.tsx b/packages/studio/src/components/editor/useVolumeAutomation.test.tsx
index c0b6451fef..7ca1b8b693 100644
--- a/packages/studio/src/components/editor/useVolumeAutomation.test.tsx
+++ b/packages/studio/src/components/editor/useVolumeAutomation.test.tsx
@@ -191,3 +191,71 @@ describe("useVolumeAutomation", () => {
expect(writtenAutomation(onSetAttributeQuiet).lanes[0].points[0].v).toBe(1);
});
});
+
+describe("useVolumeAutomation speed lane", () => {
+ const rateLane = JSON.stringify({
+ version: 1,
+ lanes: [
+ {
+ target: "rate",
+ points: [
+ { t: 0, v: 1 },
+ { t: 4, v: 4 },
+ ],
+ },
+ ],
+ });
+
+ it("seeds a rate lane at the clip's constant rate so automating does not change the speed", () => {
+ const { binding, onSetAttributeQuiet } = bind({ "playback-rate": "2" });
+ binding.rate.onAutomate();
+ expect(writtenAutomation(onSetAttributeQuiet).lanes).toEqual([
+ { target: "rate", points: [{ t: 0, v: 2 }] },
+ ]);
+ });
+
+ it("reports the lane's geometric value at the playhead", () => {
+ // 1x to 4x over 4s: halfway is 2x, not the linear 2.5x
+ const { binding } = bind({ automation: rateLane, start: "0", duration: "4" }, 2);
+ expect(binding.rate.automated).toBe(true);
+ expect(binding.rate.automatedValue).toBeCloseTo(2, 5);
+ });
+
+ it("writes a keyframe on the rate lane and leaves the volume lane alone", () => {
+ const both = JSON.stringify({
+ version: 1,
+ lanes: [
+ { target: "volume", points: [{ t: 0, v: 0.5 }] },
+ { target: "rate", points: [{ t: 0, v: 1 }] },
+ ],
+ });
+ const { binding, onSetAttributeQuiet } = bind(
+ { automation: both, start: "0", duration: "4" },
+ 2,
+ );
+ binding.rate.onCommitAt(3);
+ const lanes = writtenAutomation(onSetAttributeQuiet).lanes;
+ expect(lanes.find((l: { target: string }) => l.target === "volume").points).toEqual([
+ { t: 0, v: 0.5 },
+ ]);
+ expect(lanes.find((l: { target: string }) => l.target === "rate").points).toContainEqual({
+ t: 2,
+ v: 3,
+ });
+ });
+
+ it("stretches a preset over the clip's duration", () => {
+ const { binding, onSetAttributeQuiet } = bind({ start: "0", duration: "8" });
+ binding.rate.onApplyPreset("flash-out");
+ const lane = writtenAutomation(onSetAttributeQuiet).lanes[0];
+ expect(lane.target).toBe("rate");
+ expect(lane.points.at(-1).t).toBe(8);
+ });
+
+ it("offers no preset while the clip has no known duration, and writes nothing", () => {
+ const { binding, onSetAttributeQuiet } = bind({ start: "0" });
+ expect(binding.rate.canApplyPreset).toBe(false);
+ binding.rate.onApplyPreset("flash-out");
+ expect(onSetAttributeQuiet).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/studio/src/components/editor/useVolumeAutomation.ts b/packages/studio/src/components/editor/useVolumeAutomation.ts
index b7a7c24156..f0fe065dc4 100644
--- a/packages/studio/src/components/editor/useVolumeAutomation.ts
+++ b/packages/studio/src/components/editor/useVolumeAutomation.ts
@@ -1,13 +1,15 @@
/**
- * The volume lane's state and edits for the media section.
+ * The media section's lane state and edits: volume and speed.
*
- * Volume lives in a different panel section from the FX chain, but is automated
- * the same way, so it reads and writes through the same helper the FX group uses
+ * Both live in a different panel section from the FX chain but are automated
+ * the same way, so they read and write through the same helper the FX group uses
* rather than a second interpretation of the attribute.
*/
import {
HF_AUDIO_AUTOMATION_DATA_KEY,
+ RATE_TARGET,
+ resolveAutomationRange,
sampleAutomationLane,
VOLUME_TARGET,
} from "@hyperframes/core/audio-automation";
@@ -16,30 +18,50 @@ import {
automationAttrValue,
HF_AUDIO_AUTOMATION_ATTR,
readPanelAutomation,
+ withLane,
withoutLane,
withPointAt,
withSeededLane,
} from "./propertyPanelAutomation";
import { deriveElementTiming } from "./propertyPanelFlatTimingDerivation";
+import { SPEED_PRESETS, speedPresetLane, type SpeedPresetId } from "@hyperframes/core/speed-ramp";
import { clampNumber } from "../../utils/studioHelpers";
+export interface LaneBinding {
+ automated: boolean;
+ onAutomate: () => void;
+ onRemoveAutomation: () => void;
+ /** Write `v` as a keyframe at the playhead instead of the disabled fallback. */
+ onCommitAt: (v: number) => void;
+ /** The envelope's own value at the playhead, so the slider tracks it live. */
+ automatedValue: number | undefined;
+}
+
+export type RateBinding = LaneBinding & {
+ /** False while the clip has no known duration to stretch a preset over. */
+ canApplyPreset: boolean;
+ onApplyPreset: (id: SpeedPresetId) => void;
+};
+
export interface VolumeAutomationBinding {
volumeAutomated: boolean;
onAutomateVolume: () => void;
onRemoveVolumeAutomation: () => void;
- /** Write `v` as a keyframe at the playhead instead of the disabled fallback. */
onCommitVolumeAt: (v: number) => void;
- /** The envelope's own value at the playhead, so the slider tracks it live. */
automatedVolumeValue: number | undefined;
+ /** Speed: the `rate` lane, plus the CapCut-style presets that seed it. */
+ rate: RateBinding;
}
+export const SPEED_PRESET_OPTIONS = SPEED_PRESETS.map(({ id, label }) => ({ value: id, label }));
+
export function useVolumeAutomation(
element: DomEditSelection,
currentTime: number,
onSetAttributeQuiet: (attr: string, value: string | null) => void | Promise<void>,
): VolumeAutomationBinding {
- // The chain is not needed to resolve a volume lane — volume is always a valid
- // target — so this deliberately does not parse it.
+ // The chain is not needed to resolve a volume or rate lane: both are always valid
+ // targets, so this deliberately does not parse it.
const automation = readPanelAutomation(
element.dataAttributes?.[HF_AUDIO_AUTOMATION_DATA_KEY],
undefined,
@@ -55,21 +77,40 @@ export function useVolumeAutomation(
// playing track, while the same click on an effect parameter did not.
void onSetAttributeQuiet(HF_AUDIO_AUTOMATION_ATTR, automationAttrValue(next) || null);
};
+ const laneBinding = (target: string, seed: number): LaneBinding => {
+ const lane = automation.lanes.find((l) => l.target === target);
+ return {
+ automated: lane !== undefined,
+ automatedValue: lane
+ ? sampleAutomationLane(lane, clipTimeSec, resolveAutomationRange(target, undefined)?.scale)
+ : undefined,
+ // Seeded at the level the control already shows, so automating does not change it.
+ onAutomate: () => write(withSeededLane(automation, target, seed)),
+ onRemoveAutomation: () => write(withoutLane(automation, target)),
+ onCommitAt: (v: number) => write(withPointAt(automation, target, clipTimeSec, v)),
+ };
+ };
// `??` alone would let an empty `data-volume` through as Number("") === 0, so
// automating the track would seed its lane at silence. The engine reads the same
// empty value as unity.
const raw = element.dataAttributes?.["volume"];
const parsed = raw ? Number(raw) : 1;
const current = Number.isFinite(parsed) ? parsed : 1;
- const volumeLane = automation.lanes.find((lane) => lane.target === VOLUME_TARGET);
+ const volume = laneBinding(VOLUME_TARGET, current);
+ const rateAttr = Number.parseFloat(element.dataAttributes?.["playback-rate"] ?? "");
+ const rate = laneBinding(RATE_TARGET, Number.isFinite(rateAttr) && rateAttr > 0 ? rateAttr : 1);
return {
- volumeAutomated: volumeLane !== undefined,
- automatedVolumeValue: volumeLane ? sampleAutomationLane(volumeLane, clipTimeSec) : undefined,
- // Seeded at the level the slider already shows, so automating the track does
- // not change how loud it is.
- onAutomateVolume: () =>
- write(withSeededLane(automation, VOLUME_TARGET, Number.isFinite(current) ? current : 1)),
- onRemoveVolumeAutomation: () => write(withoutLane(automation, VOLUME_TARGET)),
- onCommitVolumeAt: (v: number) => write(withPointAt(automation, VOLUME_TARGET, clipTimeSec, v)),
+ volumeAutomated: volume.automated,
+ automatedVolumeValue: volume.automatedValue,
+ onAutomateVolume: volume.onAutomate,
+ onRemoveVolumeAutomation: volume.onRemoveAutomation,
+ onCommitVolumeAt: volume.onCommitAt,
+ rate: {
+ ...rate,
+ canApplyPreset: elDuration > 0,
+ onApplyPreset: (id) => {
+ if (elDuration > 0) write(withLane(automation, speedPresetLane(id, elDuration)));
+ },
+ },
};
}
diff --git a/packages/studio/src/hooks/useDomEditAttributeCommits.test.ts b/packages/studio/src/hooks/useDomEditAttributeCommits.test.ts
new file mode 100644
index 0000000000..6382a35161
--- /dev/null
+++ b/packages/studio/src/hooks/useDomEditAttributeCommits.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from "vitest";
+import { resolveOptimisticAttributeValue } from "./useDomEditAttributeCommits";
+
+describe("resolveOptimisticAttributeValue", () => {
+ it("removes an HTML boolean attribute when the value is the literal string false", () => {
+ expect(resolveOptimisticAttributeValue("loop", "false")).toBeNull();
+ expect(resolveOptimisticAttributeValue("muted", "false")).toBeNull();
+ });
+
+ it("keeps the literal string false for a non-boolean attribute, matching what persist() writes", () => {
+ expect(resolveOptimisticAttributeValue("data-example", "false")).toBe("false");
+ });
+
+ it("always removes on null regardless of attribute", () => {
+ expect(resolveOptimisticAttributeValue("loop", null)).toBeNull();
+ expect(resolveOptimisticAttributeValue("data-example", null)).toBeNull();
+ });
+
+ it("passes any other value through unchanged", () => {
+ expect(resolveOptimisticAttributeValue("data-example", "true")).toBe("true");
+ expect(resolveOptimisticAttributeValue("loop", "true")).toBe("true");
+ });
+});
diff --git a/packages/studio/src/hooks/useDomEditAttributeCommits.ts b/packages/studio/src/hooks/useDomEditAttributeCommits.ts
index 1ab929dd39..d420185bd5 100644
--- a/packages/studio/src/hooks/useDomEditAttributeCommits.ts
+++ b/packages/studio/src/hooks/useDomEditAttributeCommits.ts
@@ -1,5 +1,5 @@
import { useCallback, useRef } from "react";
-import type { PatchOperation } from "../utils/sourcePatcher";
+import { HTML_BOOLEAN_ATTRIBUTES, type PatchOperation } from "../utils/sourcePatcher";
import {
findElementForSelection,
getDomEditTargetKey,
@@ -55,6 +55,14 @@ function resolveFullAttrName(attr: string, prefixData: boolean | undefined): str
return prefixData && !attr.startsWith("data-") ? `data-${attr}` : attr;
}
+// Matches sourcePatcher's own boolean handling: "false" means "remove" only
+// for HTML_BOOLEAN_ATTRIBUTES (loop, muted, ...), so the live preview node
+// ends up holding what persist() actually writes to disk.
+export function resolveOptimisticAttributeValue(attr: string, value: string | null): string | null {
+ if (value === null) return null;
+ return value === "false" && HTML_BOOLEAN_ATTRIBUTES.has(attr) ? null : value;
+}
+
function setOrRemovePreviewAttribute(
el: HTMLElement,
fullAttr: string,
@@ -393,8 +401,11 @@ export function useDomEditAttributeCommits({
},
apply: () => {
if (!editedElement) return;
- const nextValue = value === null || value === "false" ? null : value;
- setOrRemovePreviewAttribute(editedElement, attr, nextValue);
+ setOrRemovePreviewAttribute(
+ editedElement,
+ attr,
+ resolveOptimisticAttributeValue(attr, value),
+ );
},
persist: () =>
persistDomEditOperations(domEditSelection, [op], {
diff --git a/packages/studio/src/utils/sourcePatcher.ts b/packages/studio/src/utils/sourcePatcher.ts
index fd799632ff..44c9843a69 100644
--- a/packages/studio/src/utils/sourcePatcher.ts
+++ b/packages/studio/src/utils/sourcePatcher.ts
@@ -420,7 +420,7 @@ function findMatchingClosingTagIndex(html: string, tagName: string, contentStart
return -1;
}
-const HTML_BOOLEAN_ATTRIBUTES = new Set([
+export const HTML_BOOLEAN_ATTRIBUTES = new Set([
"loop",
"muted",
"autoplay",
diff --git a/skills-manifest.json b/skills-manifest.json
index c305a0fdbb..99060c3e75 100644
--- a/skills-manifest.json
+++ b/skills-manifest.json
@@ -18,7 +18,7 @@
"files": 4
},
"hyperframes": {
- "hash": "05525e9c53582e4b",
+ "hash": "ca51ed2be534305c",
"files": 26
},
"hyperframes-animation": {
@@ -26,7 +26,7 @@
"files": 122
},
"hyperframes-audio": {
- "hash": "b39bac771e873eae",
+ "hash": "7e9a13aba7143c08",
"files": 7
},
"hyperframes-cli": {
@@ -34,7 +34,7 @@
"files": 11
},
"hyperframes-core": {
- "hash": "77ce4deba31148a2",
+ "hash": "b4d9c7b3d0e5ae75",
"files": 11
},
"hyperframes-creative": {
@@ -42,7 +42,7 @@
"files": 79
},
"hyperframes-keyframes": {
- "hash": "6bc62531ecea9a52",
+ "hash": "16a7da9819e7e4ab",
"files": 3
},
"hyperframes-registry": {
diff --git a/skills/hyperframes-audio/SKILL.md b/skills/hyperframes-audio/SKILL.md
index 2ec0902df7..2fbedd407d 100644
--- a/skills/hyperframes-audio/SKILL.md
+++ b/skills/hyperframes-audio/SKILL.md
@@ -32,10 +32,11 @@ crossfade envelopes, track gain/track volume, volume and effect automation,
ducking/voiceover carve, and the effect chain. `/media-use` owns sourcing,
generation, and preprocessing.
-Constant `data-playback-rate` (`0.1..5`) is render-safe for picture and
+Constant `data-playback-rate` (`0.1..10`) is render-safe for picture and
pitch-preserved sound when matching audio/video elements use the same timing,
-source offset, and rate. Source speed ramps are not supported because there is
-no rate envelope; preprocess a derived synchronized asset. HyperFrames does not
+source offset, and rate. A speed ramp is a `rate` lane in `data-automation`
+(see `docs/reference/speed-ramps`); it wins over the constant and keeps pitch
+in preview and render. HyperFrames does not
provide automatic waveform sync or drift correction.
For copyable cut/crossfade/retime recipes, use `/hyperframes-core` → `references/creator-editing-recipes.md`.
diff --git a/skills/hyperframes-core/references/creator-editing-recipes.md b/skills/hyperframes-core/references/creator-editing-recipes.md
index 6977324653..b0c150980f 100644
--- a/skills/hyperframes-core/references/creator-editing-recipes.md
+++ b/skills/hyperframes-core/references/creator-editing-recipes.md
@@ -229,7 +229,7 @@ Timeline math: the still owns its hold duration. Source math: final-source frame
></video>
```
-Timeline math: duration is authored timeline time. Source math: consumed source = timeline duration × rate; natural timeline duration = remaining source / rate. Audio follows: matching separate audio track uses the same constant rate. Owner: `/hyperframes-core`. Limit: normalized 0.1..5 constant only; no speed ramp envelope.
+Timeline math: duration is authored timeline time. Source math: consumed source = timeline duration × rate; natural timeline duration = remaining source / rate. Audio follows: matching separate audio track uses the same constant rate. Owner: `/hyperframes-core`. Limit: normalized 0.1..10. For a speed ramp put a `rate` lane in `data-automation`, e.g. `{"version":1,"lanes":[{"target":"rate","points":[{"t":0,"v":1},{"t":2,"v":4}]}]}`; it wins over the constant.
## Zoom / punch
@@ -488,4 +488,4 @@ Timeline math: change only `src`. Source math: reset `data-media-start` to the o
## Split a section and change its speed
-Timeline math: a section that is a sub-composition or a group of clips has no `data-playback-rate` of its own to set; split it by giving each half its own host or clips and shift everything after the cut by the length change. New length of a part = old length / rate. Every later `data-start` (clips, audio, root-timeline tweens) moves by the same delta. Source math: `<video>` and `<audio>` parts use `data-playback-rate` (0.1 to 5, constant) per the constant-speed recipe above, with matching audio. Limit: a speed ramp (a rate that changes within one clip) is not in the format; approximate with several constant-rate parts or preprocess a derived asset through `/media-use`. Say which you did, and do not invent a rate attribute.
+Timeline math: a section that is a sub-composition or a group of clips has no `data-playback-rate` of its own to set; split it by giving each half its own host or clips and shift everything after the cut by the length change. New length of a part = old length / rate. Every later `data-start` (clips, audio, root-timeline tweens) moves by the same delta. Source math: `<video>` and `<audio>` parts use `data-playback-rate` (0.1 to 10, constant) per the constant-speed recipe above, with matching audio. A speed ramp (a rate that changes within one clip) is a `rate` lane in `data-automation` on the `<video>`/`<audio>`; see `docs/reference/speed-ramps`. Say which you did.
diff --git a/skills/hyperframes-keyframes/SKILL.md b/skills/hyperframes-keyframes/SKILL.md
index ce7697e8bf..0640bd6c9c 100644
--- a/skills/hyperframes-keyframes/SKILL.md
+++ b/skills/hyperframes-keyframes/SKILL.md
@@ -34,8 +34,8 @@ fades use `/hyperframes-audio`.
| Crop and mask reframe | Interpolate `clip-path` or a mask on an inner visual wrapper to crop/reframe without changing source time. Polygon keyframes can form a polygon/mask transition. |
| Directional wipe cut or iris/reveal cut | Animate a mask/clip boundary across overlapping visual clips; `/hyperframes-animation` owns the handoff choreography. |
| Split-screen handoff | Keep both visual clips placed by core, then keyframe their inner crop/mask wrappers and divider geometry. |
-| Constant source retime | `/hyperframes-core` owns normalized `data-playback-rate` (`0.1..5`) for render-safe picture and pitch-preserved sound. It is constant for the whole media element. |
-| Source speed ramps | Not supported: there is no time-varying playback-rate envelope. Preprocess a derived media asset, then place it through core. |
+| Constant source retime | `/hyperframes-core` owns normalized `data-playback-rate` (`0.1..10`) for render-safe picture and pitch-preserved sound. It is constant for the whole media element. |
+| Source speed ramps | A `rate` lane in `data-automation` on the `<video>`/`<audio>` (`t` in clip seconds, `v` 0.1..10, log interpolation); it wins over the constant rate. |
| Freeze / hold | A visual pose, final source frame, or finished sub-composition can hold. Arbitrary mid-source freeze is not supported; preprocess a still/derived segment, place it as its own clip, then resume with another source range. |
When editing picture and sound together, load `/hyperframes-core`, this skill for
diff --git a/skills/hyperframes/SKILL.md b/skills/hyperframes/SKILL.md
index 067dde5c21..884cbd65a0 100644
--- a/skills/hyperframes/SKILL.md
+++ b/skills/hyperframes/SKILL.md
@@ -108,10 +108,10 @@ Creator edit phrases are cross-domain requests. Load every skill named in the ma
| fade, crossfade, track gain/volume, automation, duck/carve, audio effects, or one effect across several tracks | `/general-video` + `/hyperframes-core` + `/hyperframes-audio`; core places clips, audio mixes placed tracks — including a submix bus over a group of them. |
| picture and sound edits that combine cuts with camera motion or mixing | `/general-video` + `/hyperframes-core` + `/hyperframes-keyframes` when there is visual motion + `/hyperframes-audio` when sound is faded, mixed, ducked, automated, or processed. |
| lay out a project so it reads well in Studio: caption track, tracks per element kind, sub-compositions, safe zones | `/hyperframes-studio` + `/hyperframes-core`; studio owns the layout conventions, core owns each edit. |
-| source or generate media, or preprocess an unsupported speed ramp/mid-source freeze | `/media-use`; sourcing/generation/preprocessing only, never placed-track mixing. |
+| source or generate media, or preprocess an unsupported mid-source freeze | `/media-use`; sourcing/generation/preprocessing only, never placed-track mixing. |
Constant `data-playback-rate` is render-safe for picture and pitch-preserved
-sound. It does not make source speed ramps keyframeable; preprocess ramps.
+sound. Speed ramps are a `rate` lane in `data-automation`.
For copyable edit contracts, load `/hyperframes-core` → `references/creator-editing-recipes.md`.
Broad feedback about how photographic media looks or behaves also routes to