Skip to content

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

fix(cursor): find the click samples in installers and mute them with the cursor

EtienneLescotb9ed587796c0
diff --git a/src/hooks/useClickSound.ts b/src/hooks/useClickSound.ts
index 91ad6e3b8..a271a48dc 100644
--- a/src/hooks/useClickSound.ts
+++ b/src/hooks/useClickSound.ts
@@ -6,17 +6,11 @@
import { useEffect, useState } from "react";
import type { ClickCue } from "@/lib/ai-edition/clickSound";
-import {
- clickTakeOf,
- ensureClickHitPaths,
- LEGACY_CLICK_BED_LABEL,
- loadClickCues,
-} from "@/lib/ai-edition/clickSound";
+import { clickTakeOf, ensureClickHitPaths, loadClickCues } from "@/lib/ai-edition/clickSound";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
export function useClickSound() {
const document = useProjectStore((s) => s.document);
- const removeAsset = useProjectStore((s) => s.removeAsset);
const takePath = clickTakeOf(document)?.originalPath ?? null;
// The row is offered only once the take is known to hold clicks, and reading its cues is what
// says so — the same one-shot read the hits come from, so switching on waits on nothing more.
@@ -39,20 +33,9 @@ export function useClickSound() {
* a background read. Nothing here can fail the pane: a sample that will not stage just
* means the export has no clicks in it. */
prepare: async () => {
- // A project saved by the earlier cut of this feature holds one rendered WAV as a music
- // track. The hits are laid from the clicks themselves now, so leaving that bed on the
- // timeline would sound every click twice.
- for (const asset of document?.assets ?? []) {
- if (asset.kind !== "audio" || asset.label !== LEGACY_CLICK_BED_LABEL) continue;
- try {
- await removeAsset(asset.id);
- } catch (error) {
- console.error("Failed to drop the old click bed", error);
- }
- }
const take = clickTakeOf(document)?.originalPath;
if (!take) return;
- await Promise.all([loadClickCues(take), ensureClickHitPaths()]);
+ await Promise.all([loadClickCues(take), ensureClickHitPaths().catch(() => null)]);
},
};
}
diff --git a/src/lib/ai-edition/clickSound.ts b/src/lib/ai-edition/clickSound.ts
index 1eb6cad52..3e0518dca 100644
--- a/src/lib/ai-edition/clickSound.ts
+++ b/src/lib/ai-edition/clickSound.ts
@@ -8,7 +8,6 @@
// edit falls behind every click after it; these hits are computed from the edit instead.
import type { CursorTelemetryPoint } from "@/components/video-editor/types";
-import { getAssetPath } from "@/lib/assetPath";
import { nativeBridgeClient } from "@/native/client";
import { projectRawTimelineSecToPlayback, readSpeedRegions } from "./document/timeline";
import type { AxcutAsset, AxcutDocument } from "./schema";
@@ -21,13 +20,6 @@ export const CLICK_SOUND_UP_URL = "sounds/click-up.wav";
/** The names the two samples are staged under, and the only names the main process accepts. */
const HIT_FILES = { down: "click-down.wav", up: "click-up.wav" } as const;
-/**
- * The asset label an earlier cut of this feature stamped onto projects: it rendered the whole
- * take into one WAV and added that as a music track. Nothing writes one any more, and switching
- * the sound on clears it — a document holding both would hear every click twice.
- */
-export const LEGACY_CLICK_BED_LABEL = "Mouse clicks";
-
/** A press with no matching release inside this window gets a synthetic one this far later. */
const MAX_RELEASE_GAP_MS = 600;
const FALLBACK_RELEASE_MS = 110;
@@ -108,13 +100,10 @@ export function buildClickCues(points: CursorTelemetryPoint[]): ClickCue[] {
/** Resolved URLs of the two bundled hits, for the renderer and for staging. */
export function clickHitUrls(): { down: string; up: string } {
- const one = (relative: string) => {
- try {
- return getAssetPath(relative);
- } catch {
- return `/${relative}`;
- }
- };
+ // Page-relative, like the web-demuxer wasm: Vite copies public/sounds into dist/, which an
+ // installer ships inside the asar. `getAssetPath` resolves against resources/, which only holds
+ // what electron-builder's extraResources copies there.
+ const one = (relative: string) => new URL(relative, window.location.href).href;
return { down: one(CLICK_SOUND_DOWN_URL), up: one(CLICK_SOUND_UP_URL) };
}
@@ -312,8 +301,9 @@ export function placeClickHits(
* always asks cannot hand the preview clicks the user never asked to hear.
*/
export async function prepareClickSound(document: AxcutDocument): Promise<void> {
- const cursor = getEditorSettings(document).cursor;
- if (!cursor.clickSound) return;
+ const settings = getEditorSettings(document);
+ const cursor = settings.cursor;
+ if (!cursor.clickSound || !settings.cursorShow) return;
const take = clickTakeOf(document);
if (!take?.originalPath) return;
previewGainDb = cursor.clickSoundGainDb;
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index 1433edc02..0d84461b5 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -5,12 +5,14 @@
// and verify every derivation branch listed in the spec (background / clips / zoomRegions /
// crop / settings mapping / output dims).
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
import {
+ type CursorTelemetryPoint,
DEFAULT_CROP_REGION,
getZoomScale,
ZOOM_DEPTH_SCALES,
} from "@/components/video-editor/types";
+import { prepareClickSound } from "@/lib/ai-edition/clickSound";
import type {
AxcutAsset,
AxcutClip,
@@ -21,6 +23,7 @@ import { axcutSchemaVersion } from "@/lib/ai-edition/schema";
import { CURSOR_KIND_IDS, DEFAULT_CURSOR_THEME_ID } from "@/lib/cursor/cursorThemes";
import { DEVICE_FRAMES } from "@/lib/projectDefaults";
import { getFocusBoundsForScale } from "@/lib/zoomMath/focusUtils";
+import { nativeBridgeClient } from "./client";
import {
annotationFootageRect,
buildSceneDescription,
@@ -1319,6 +1322,48 @@ describe("buildSceneDescription.settings mapping", () => {
expect("clickImpact" in off).toBe(false);
});
+ it("sounds the recorded clicks only while the cursor is shown", async () => {
+ const take = makeAsset({ id: "a1", originalPath: "/rec.mp4", durationSec: 10 });
+ const clips = [
+ makeClip({
+ id: "c1",
+ assetId: "a1",
+ sourceStartSec: 0,
+ timelineStartSec: 0,
+ timelineEndSec: 10,
+ }),
+ ];
+ const doc = (cursorShow: boolean) =>
+ makeDoc({ assets: [take], clips, legacyEditor: { cursorShow, cursorClickSound: true } });
+ const click: CursorTelemetryPoint = {
+ timeMs: 2000,
+ cx: 0.5,
+ cy: 0.5,
+ interactionType: "click",
+ };
+ const telemetry = vi
+ .spyOn(nativeBridgeClient.cursor, "getTelemetry")
+ .mockResolvedValue([click]);
+ // The main process stages the two samples; any path stands in for it here.
+ vi.stubGlobal("window", {
+ location: { href: "http://localhost/" },
+ electronAPI: {
+ stageClickSoundHit: async (name: string) => ({ success: true, path: `/sfx/${name}` }),
+ },
+ });
+ vi.stubGlobal("fetch", async () => new Response(new Uint8Array([1])));
+ try {
+ await prepareClickSound(doc(true));
+ // A press and its release.
+ expect(buildSceneDescription(doc(true)).clickSound?.hits).toHaveLength(2);
+ // Its row is hidden with the cursor, like the click impact, so it must not keep sounding.
+ expect(buildSceneDescription(doc(false)).clickSound).toBeUndefined();
+ } finally {
+ telemetry.mockRestore();
+ vi.unstubAllGlobals();
+ }
+ });
+
it("carries depth of field: on by default, off when the project turns it off", () => {
expect(buildSceneDescription(makeDoc({})).effects.depthOfField).toBe(true);
const off = makeDoc({ legacyEditor: { depthOfField: false } });
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 2ca7dd861..5cf2a8e5d 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -836,7 +836,11 @@ export function buildSceneDescription(
);
// Click hits for the "mouse clicks" toggle, placed on the programme this export assembles.
// Synchronous: the cues were read from the take's sidecar when the sound was switched on.
- const clickSound = clickSoundForDocument(document, settings.cursor);
+ // Its row lives under "Show cursor", like the click impact: a hidden cursor makes no sound.
+ const clickSound = clickSoundForDocument(document, {
+ clickSound: settings.cursorShow && settings.cursor.clickSound,
+ clickSoundGainDb: settings.cursor.clickSoundGainDb,
+ });
const audioTracks = document.audioTracks.flatMap((track) => {
if (track.muted) return [];
const asset = assetById.get(track.assetId);