Skip to content

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

click sound: answer the two review findings

一个成熟的剪辑猿100d07295354
diff --git a/src/cli/CliExportRunner.tsx b/src/cli/CliExportRunner.tsx
index de080359e..85b066851 100644
--- a/src/cli/CliExportRunner.tsx
+++ b/src/cli/CliExportRunner.tsx
@@ -13,6 +13,7 @@ import {
toFileUrl,
validateProjectData,
} from "@/components/video-editor/projectPersistence";
+import { prepareClickSound } from "@/lib/ai-edition/clickSound";
import { migrateProjectDataToAxcutDocument } from "@/lib/ai-edition/document/migrate";
import {
collectEffectiveClipDims,
@@ -281,6 +282,10 @@ async function runExport(request: CliExportRequest): Promise<CliDoneResult> {
if (builtClips.length === 0) {
throw new Error("The project's timeline has no visible clips to export");
}
+ // The scene carries the click hits, whose cues and staged samples are read out of caches a
+ // scene build cannot await — without this a cold CLI export builds its scene from empty
+ // caches and comes out silent. Clicks that will not load must not cost the export.
+ await prepareClickSound(axcutDocument).catch(() => undefined);
const sceneDesc = buildSceneDescription(axcutDocument);
// The webcam background effect is applied by the compositor from the scene, so the clip
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index c02b421d6..54d5cd1ce 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -1228,12 +1228,14 @@ export function VirtualPreview({
// click lands on the click being drawn. A clip swap or a cut moves it by more than a
// frame can, which reads as a seek and fires nothing; and while stopped the anchor is
// dropped, so the next run does not repay a stack of old clicks.
- // ponytail: the cues are the primary take's, so a project that interleaves several
- // takes would need the mounted asset's id here to pick the right list.
+ // The cues are the primary take's, so they only belong over that take's picture.
if (v.paused) {
resetClickPlayhead();
} else {
- const crossed = takeCrossedClickHits(sourceTime);
+ const crossed = takeCrossedClickHits(
+ sourceTime,
+ videoSourcesRef.current[sourceIndexRef.current]?.filePath,
+ );
const clickGraph = audioGraphRef.current;
if (crossed.length && clickGraph) {
playClickHits(
diff --git a/src/lib/ai-edition/clickSound.test.ts b/src/lib/ai-edition/clickSound.test.ts
index e00ed1ba1..9157c3d1a 100644
--- a/src/lib/ai-edition/clickSound.test.ts
+++ b/src/lib/ai-edition/clickSound.test.ts
@@ -1,7 +1,13 @@
import { describe, expect, it } from "vitest";
import type { CursorTelemetryPoint } from "@/components/video-editor/types";
import type { ClickCue } from "./clickSound";
-import { buildClickCues, crossedClickHits, levelClickCues, placeClickHits } from "./clickSound";
+import {
+ buildClickCues,
+ clickCuesFitTake,
+ crossedClickHits,
+ levelClickCues,
+ placeClickHits,
+} from "./clickSound";
const point = (
timeMs: number,
@@ -127,6 +133,17 @@ describe("levelClickCues", () => {
});
});
+describe("clickCuesFitTake", () => {
+ it("goes silent only on a known mismatch of takes", () => {
+ expect(clickCuesFitTake("/t/a.mp4", "/t/a.mp4")).toBe(true);
+ expect(clickCuesFitTake("/t/a.mp4", "/t/b.mp4")).toBe(false);
+ // A source whose path is not resolved yet, and a document with no cues stashed, are not
+ // mismatches: neither is a reason to stop hearing the sound.
+ expect(clickCuesFitTake("/t/a.mp4", undefined)).toBe(true);
+ expect(clickCuesFitTake(undefined, "/t/b.mp4")).toBe(true);
+ });
+});
+
describe("crossedClickHits", () => {
const cues = [cue(1), cue(2.02), cue(3)];
diff --git a/src/lib/ai-edition/clickSound.ts b/src/lib/ai-edition/clickSound.ts
index 13d7feb36..58477e0c4 100644
--- a/src/lib/ai-edition/clickSound.ts
+++ b/src/lib/ai-edition/clickSound.ts
@@ -285,13 +285,33 @@ let lastSourceSec = Number.NaN;
/** The hits the playhead passed since the last call, measured in the take's own source seconds —
* where a click was recorded, and where the preview's picture is: under a 2x region that clock
- * races with the picture, so a hit fired on a crossing lands on the click being shown. */
-export function takeCrossedClickHits(sourceSec: number): ClickCue[] {
- const crossed = crossedClickHits(previewCues, lastSourceSec, sourceSec);
+ * races with the picture, so a hit fired on a crossing lands on the click being shown.
+ *
+ * `mountedTakePath` is the take on screen now. The cues belong to one take, so playing them over
+ * another take's picture would put a click where no click happened. */
+export function takeCrossedClickHits(
+ sourceSec: number,
+ mountedTakePath?: string | null,
+): ClickCue[] {
+ const fit = clickCuesFitTake(previewTake, mountedTakePath);
+ const crossed = fit ? crossedClickHits(previewCues, lastSourceSec, sourceSec) : [];
+ // The anchor moves either way: coming back to the right take must not repay a stack of clicks.
lastSourceSec = sourceSec;
return crossed;
}
+/**
+ * Whether cues recorded against `cueTake` may sound while `mountedTake` is on screen. Only a known
+ * mismatch suppresses them — a preview that has no path resolved yet (a source still being built,
+ * or one loaded from a URL rather than a file) must not fall silent because of this check.
+ */
+export function clickCuesFitTake(
+ cueTake: string | undefined,
+ mountedTake?: string | null,
+): boolean {
+ return !cueTake || !mountedTake || mountedTake === cueTake;
+}
+
/**
* The clicks whose recorded time lies between two readings of the playhead, both in the take's own
* source seconds. A move too big for one frame is a seek (or a clip swap) and nothing is owed