Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(timeline): the one funnel reads parts, so an extension is a segment like any other

EtienneLescotc9b261ff8fea
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 2d24ed32e..e69fe96de 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -1513,6 +1513,7 @@ export function NewEditorShell() {
speedRegions={tl.speedRegions}
cameraFullscreenRegions={tl.cameraFullscreenRegions}
trimRanges={tl.trimRanges}
+ transcripts={document?.transcripts ?? []}
selectedZoomRegionId={tl.selection?.kind === "zoom" ? tl.selection.id : null}
onZoomFocusChange={tl.updateZoomFocusLive}
onZoomFocusCommit={() => void tl.commitZoomFocus()}
diff --git a/src/components/ai-edition/Preview.tsx b/src/components/ai-edition/Preview.tsx
index cd6868e75..3a1db9756 100644
--- a/src/components/ai-edition/Preview.tsx
+++ b/src/components/ai-edition/Preview.tsx
@@ -5,6 +5,7 @@ import type {
AxcutAnnotationRegion,
AxcutAudioTrack,
AxcutClip,
+ AxcutTranscript,
AxcutTrimRange,
AxcutZoomRegion,
} from "@/lib/ai-edition/schema";
@@ -33,6 +34,7 @@ interface PreviewProps {
speedRegions?: SpeedRegion[];
cameraFullscreenRegions?: CameraFullscreenRegion[];
trimRanges?: AxcutTrimRange[];
+ transcripts?: AxcutTranscript[];
selectedZoomRegionId?: string | null;
onZoomFocusChange?: (id: string, focus: ZoomFocus) => void;
onZoomFocusCommit?: () => void;
@@ -66,6 +68,7 @@ export function Preview({
speedRegions,
cameraFullscreenRegions,
trimRanges,
+ transcripts,
selectedZoomRegionId,
onZoomFocusChange,
onZoomFocusCommit,
@@ -194,6 +197,7 @@ export function Preview({
speedRegions={speedRegions}
cameraFullscreenRegions={cameraFullscreenRegions}
trimRanges={trimRanges}
+ transcripts={transcripts}
selectedZoomRegionId={selectedZoomRegionId}
onZoomFocusChange={onZoomFocusChange}
onZoomFocusCommit={onZoomFocusCommit}
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsx
index 150012b95..55e9ada15 100644
--- a/src/components/ai-edition/PreviewCanvas.tsx
+++ b/src/components/ai-edition/PreviewCanvas.tsx
@@ -36,6 +36,7 @@ import type {
AxcutAnnotationRegion,
AxcutAudioTrack,
AxcutClip,
+ AxcutTranscript,
AxcutTrimRange,
AxcutZoomRegion,
} from "@/lib/ai-edition/schema";
@@ -75,6 +76,8 @@ interface PreviewCanvasProps {
speedRegions?: SpeedRegion[];
cameraFullscreenRegions?: CameraFullscreenRegion[];
trimRanges?: AxcutTrimRange[];
+ /** Relayed to `VirtualPreview` so a clip carrying added words plays their extensions. */
+ transcripts?: AxcutTranscript[];
selectedZoomRegionId?: string | null;
onZoomFocusChange?: (id: string, focus: ZoomFocus) => void;
onZoomFocusCommit?: () => void;
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index feb174ff8..cf388eb2e 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -16,6 +16,7 @@ import {
import type {
AxcutAudioTrack,
AxcutClip,
+ AxcutTranscript,
AxcutTrimRange,
AxcutZoomRegion,
} from "@/lib/ai-edition/schema";
@@ -212,6 +213,8 @@ interface VirtualPreviewProps {
zoomRegions?: AxcutZoomRegion[];
speedRegions?: SpeedRegion[];
trimRanges?: AxcutTrimRange[];
+ /** So a clip carrying added words plays their extensions — see `clipParts`. */
+ transcripts?: AxcutTranscript[];
seekTarget?: { timeSec: number; isSource?: boolean; requestId: number } | null;
onTimeChange?: (timeSec: number) => void;
onLoadedMetadata?: (
@@ -258,6 +261,7 @@ export function VirtualPreview({
zoomRegions = [],
speedRegions = [],
trimRanges = [],
+ transcripts = [],
seekTarget,
onTimeChange,
onLoadedMetadata,
@@ -589,8 +593,8 @@ export function VirtualPreview({
// source time to a RAW virtual time that jumps discontinuously by exactly the trim's
// width the moment the video itself jumps — matching the marker's own pixel span.
const playbackClips = useMemo(
- () => resolvePlaybackSegments(clips, trimRanges),
- [clips, trimRanges],
+ () => resolvePlaybackSegments(clips, trimRanges, transcripts),
+ [clips, trimRanges, transcripts],
);
const playbackClipsRef = useRef(playbackClips);
playbackClipsRef.current = playbackClips;
diff --git a/src/lib/ai-edition/document/timeline.test.ts b/src/lib/ai-edition/document/timeline.test.ts
index 9cbdbc5ec..9abbbb2c8 100644
--- a/src/lib/ai-edition/document/timeline.test.ts
+++ b/src/lib/ai-edition/document/timeline.test.ts
@@ -1740,3 +1740,80 @@ describe("projectRawTimelineSecToPlayback with speed regions", () => {
// ─── The pause an added word bought ──────────────────────────────
// Created time only exists once playback honours it. These pin the one thing the record
// is for: the stream really does stay on the held frame, and the film really is longer.
+
+// ─── Segments across an extension ───────────────────────────────────────────
+// The whole point of the layer, seen from the one funnel every consumer goes through: an
+// added word becomes a SEGMENT of its own, naming media rather than a behaviour, and the
+// recording on either side keeps the source window it always had.
+
+describe("resolvePlaybackSegments across an added word", () => {
+ const clip = makeClip({
+ id: "c1",
+ assetId: "a1",
+ sourceStartSec: 0,
+ sourceEndSec: 10,
+ timelineStartSec: 0,
+ timelineEndSec: 10,
+ });
+ const transcripts = [
+ {
+ assetId: "a1",
+ language: "en",
+ segments: [],
+ words: [
+ { id: "w1", segmentId: "s", startSec: 1, endSec: 2, text: "said" },
+ {
+ id: "synth_1",
+ segmentId: "s",
+ startSec: 4,
+ endSec: 4,
+ text: "really",
+ source: "synth" as const,
+ },
+ ],
+ },
+ ];
+
+ it("puts the extension between the halves, as its own segment", () => {
+ const segs = resolvePlaybackSegments([clip], [], transcripts);
+ expect(segs.map((s) => s.extensionWordId ?? null)).toEqual([null, "synth_1", null]);
+ // The recording resumes at the source second it stopped on — nothing moved.
+ expect(segs[0]).toMatchObject({ sourceStartSec: 0, sourceEndSec: 4 });
+ expect(segs[2]).toMatchObject({ sourceStartSec: 4, sourceEndSec: 10 });
+ });
+
+ it("gives the extension its own media window, starting at zero", () => {
+ const [, ext] = resolvePlaybackSegments([clip], [], transcripts);
+ expect(ext.sourceStartSec).toBe(0);
+ expect(ext.sourceEndSec).toBeCloseTo(6 / 15, 6);
+ expect(ext.timelineEndSec - ext.timelineStartSec).toBeCloseTo(6 / 15, 6);
+ });
+
+ it("lays the programme out end to end, with no gap and no overlap", () => {
+ const segs = resolvePlaybackSegments([clip], [], transcripts);
+ expect(segs[0].timelineStartSec).toBe(0);
+ for (const [i, seg] of segs.slice(0, -1).entries()) {
+ expect(seg.timelineEndSec).toBeCloseTo(segs[i + 1].timelineStartSec, 9);
+ }
+ });
+
+ it("still cuts the recording, and never the extension", () => {
+ // A trim is anchored in the RECORDING's seconds; an extension has none, so no trim
+ // can name it. Cutting source 5..6 shortens the half after the added word only.
+ const trims = [makeTrim({ id: "t1", clipId: "c1", startSec: 5, endSec: 6 })];
+ const segs = resolvePlaybackSegments([clip], trims, transcripts);
+ expect(segs.filter((s) => s.extensionWordId).length).toBe(1);
+ const recorded = segs.filter((s) => !s.extensionWordId);
+ expect(recorded.map((s) => [s.sourceStartSec, s.sourceEndSec])).toEqual([
+ [0, 4],
+ [4, 5],
+ [6, 10],
+ ]);
+ });
+
+ it("behaves exactly as before when no word was added", () => {
+ const plain = resolvePlaybackSegments([clip], []);
+ expect(plain).toHaveLength(1);
+ expect(plain[0]).toMatchObject({ id: "c1", sourceStartSec: 0, sourceEndSec: 10 });
+ });
+});
diff --git a/src/lib/ai-edition/document/timeline.ts b/src/lib/ai-edition/document/timeline.ts
index ae26d7fb7..a1598db4b 100644
--- a/src/lib/ai-edition/document/timeline.ts
+++ b/src/lib/ai-edition/document/timeline.ts
@@ -6,15 +6,19 @@
import type { AxcutClip, AxcutDocument, AxcutTranscript, AxcutTrimRange } from "../schema";
/**
- * What `resolvePlaybackSegments` returns: a clip-shaped slice of playable film, plus the
- * one thing a stored clip can never carry — `heldSec`, the pause an added word created.
+ * What `resolvePlaybackSegments` returns: a clip-shaped slice of playable film.
*
- * A held segment's source window is the single frame it shows; its LENGTH is `heldSec`.
- * The field lives only on this derived shape, never on `clipSchema`, so nothing can write
- * one to disk — which is the whole difference from the attempt that made clips for it.
+ * `extensionWordId` names the ONE case where the media is not the clip's own asset — the
+ * extension an added word is spoken over, whose file is derived from the word. It says which
+ * MEDIA to play, not what behaviour to perform, and that is the whole difference from the
+ * `heldSec` this replaces: a reader resolves it to a file like any other, rather than
+ * carrying a special case for a stretch with nothing to decode.
+ *
+ * Derived-only, never on `clipSchema`, so nothing can write one to disk.
*/
-export type PlaybackSegment = AxcutClip;
+export type PlaybackSegment = AxcutClip & { extensionWordId?: string };
+import { clipParts } from "../timeline/clip-parts";
import { type Interval, subtractInterval } from "../timeline/intervals";
import { keptRawSpans } from "../timeline/programme-time";
import {
@@ -160,8 +164,12 @@ export function resequenceClips(clips: AxcutClip[]): AxcutClip[] {
export function resolvePlaybackSegments(
clips: AxcutClip[],
trimRanges: AxcutTrimRange[],
+ /** The transcripts, so a clip carrying added words splits into its parts. Omitted, a
+ * clip is one recording part and this behaves exactly as it did before extensions. */
+ transcripts: readonly AxcutTranscript[] = [],
): PlaybackSegment[] {
const ordered = [...clips].sort((a, b) => a.timelineStartSec - b.timelineStartSec);
+ const wordsByAsset = new Map(transcripts.map((t) => [t.assetId, t.words]));
const result: PlaybackSegment[] = [];
let timelineCursor = 0;
for (const clip of ordered) {
@@ -177,18 +185,39 @@ export function resolvePlaybackSegments(
timelineCursor += dur;
continue;
}
- let kept: Interval[] = [{ startSec: clip.sourceStartSec, endSec: sourceEnd }];
- for (const trim of trimRanges) {
- if (!trimAppliesToClip(trim, clip)) continue;
- kept = subtractInterval(kept, { startSec: trim.startSec, endSec: trim.endSec });
- }
- const pieces = kept.map((iv) => ({ startSec: iv.startSec, endSec: iv.endSec }));
- pieces.forEach((piece, i) => {
- const dur = piece.endSec - piece.startSec;
- if (dur > 0) {
- result.push({
+ // The insertion layer, and the only place this function meets it. Below here a part
+ // is media with a source window, and the trim arithmetic is the same it always was.
+ const parts = clipParts(clip, wordsByAsset.get(clip.assetId) ?? []);
+ // Named once the clip's own pieces are known: a clip keeps its id only when it yields
+ // exactly ONE piece of recording and nothing else. Naming from the PART count instead
+ // missed the split a trim makes inside a single part.
+ const clipSegments: PlaybackSegment[] = [];
+ for (const part of parts) {
+ if (part.kind === "extension") {
+ // No trim can name it: a trim is anchored in the RECORDING's seconds, and an
+ // extension has none. Its own media starts at zero and runs its full length.
+ clipSegments.push({
+ ...clip,
+ id: `${clip.id}__ext_${part.wordId}`,
+ extensionWordId: part.wordId,
+ sourceStartSec: 0,
+ sourceEndSec: part.timelineEndSec - part.timelineStartSec,
+ timelineStartSec: timelineCursor,
+ timelineEndSec: timelineCursor + (part.timelineEndSec - part.timelineStartSec),
+ });
+ timelineCursor += part.timelineEndSec - part.timelineStartSec;
+ continue;
+ }
+ let kept: Interval[] = [{ startSec: part.sourceStartSec, endSec: part.sourceEndSec }];
+ for (const trim of trimRanges) {
+ if (!trimAppliesToClip(trim, clip)) continue;
+ kept = subtractInterval(kept, { startSec: trim.startSec, endSec: trim.endSec });
+ }
+ for (const piece of kept) {
+ const dur = piece.endSec - piece.startSec;
+ if (dur <= 0) continue;
+ clipSegments.push({
...clip,
- id: pieces.length === 1 ? clip.id : `${clip.id}_seg${i + 1}`,
sourceStartSec: piece.startSec,
sourceEndSec: piece.endSec,
timelineStartSec: timelineCursor,
@@ -196,7 +225,14 @@ export function resolvePlaybackSegments(
});
timelineCursor += dur;
}
- });
+ }
+ const recorded = clipSegments.filter((seg) => seg.extensionWordId === undefined);
+ let n = 0;
+ for (const seg of clipSegments) {
+ if (seg.extensionWordId !== undefined) continue;
+ seg.id = recorded.length === 1 ? clip.id : `${clip.id}_seg${++n}`;
+ }
+ result.push(...clipSegments);
}
return result;
}
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index ce22db0ed..6c7981d0f 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -522,7 +522,11 @@ function clipAssetIsResolvable(
*/
export function resolveVisibleClips(document: AxcutDocument): PlaybackSegment[] {
const assetById = new Map(document.assets.map((a) => [a.id, a]));
- return resolvePlaybackSegments(document.timeline.clips, document.timeline.trimRanges)
+ return resolvePlaybackSegments(
+ document.timeline.clips,
+ document.timeline.trimRanges,
+ document.transcripts,
+ )
.sort((a, b) => a.timelineStartSec - b.timelineStartSec)
.filter((clip) => clipAssetIsResolvable(clip, assetById));
}