Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(editor): push every native param on load, not just the open panel's
Etienne Lescot66c1c709649d
diff --git a/src/components/ai-edition/NativeCompositorOverlay.tsx b/src/components/ai-edition/NativeCompositorOverlay.tsxindex 4ad76f062..198cf89b5 100644--- a/src/components/ai-edition/NativeCompositorOverlay.tsx+++ b/src/components/ai-edition/NativeCompositorOverlay.tsx@@ -1,13 +1,16 @@import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";import { useScopedT } from "@/contexts/I18nContext";import { noteUiProbeClipSwitch } from "@/lib/ai-edition/perf/uiFrameProbe";+import { getEditorSettings } from "@/lib/ai-edition/store/editorSettings";import { useProjectStore } from "@/lib/ai-edition/store/projectStore";import { resolveNativePosition } from "@/lib/ai-edition/timeline/timelineMap";import {+ pushAllNativeParams,setActiveClip,setCurrentNativeViewId,setNativePlaying,setNativeScene,+ subscribeNativeCompositor,useIsCpuCompositor,useNativeCompositorView,} from "@/native";@@ -142,6 +145,31 @@ export function NativeCompositorOverlay() {// arriving after mount never gets pushed to native).}, [viewId, document, sources, _webcamSizeRevision]);+ // SYNCHRO COMPLETE DES PARAMS, en un seul endroit.+ //+ // Avant, chaque groupe de params n'etait pousse que par l'effet de montage du+ // panneau qui le possede (VideoEffectsPane, LayoutPane, CursorPane). Or+ // l'inspecteur n'affiche qu'UN panneau a la fois, donc au chargement les+ // params curseur et layout n'avaient jamais ete pousses et l'addon restait+ // sur ses defauts compiles : un projet en taille de curseur 3.0 s'affichait a+ // 1.0 jusqu'a ce qu'on ouvre le panneau curseur, ou tout se remettait en+ // place -- ce qui donnait l'illusion que le panneau « activait » le curseur.+ //+ // Ici, l'overlay possede deja la vue et pousse deja la scene ; c'est le seul+ // point qui existe quel que soit le panneau affiche.+ //+ // Pas de garde sur `viewId` : `setNativeParam` memoise dans `lastParams` et+ // `setCurrentNativeViewId` le rejoue a l'activation, donc l'ordre de montage+ // n'a pas d'importance. Et ca ne peut pas lutter contre un drag de slider :+ // `setLive` passe par `setDocument`, donc `document` a deja la NOUVELLE+ // valeur a chaque tick -- la meme que celle que le handler vient de pousser.+ const settings = useMemo(() => getEditorSettings(document), [document]);+ useEffect(() => {+ const push = () => pushAllNativeParams(settings);+ push();+ return subscribeNativeCompositor(push);+ }, [settings]);+const activeClipId = activeClip?.id ?? null;const activeClipIndex = activePosition?.clipIndex ?? null;const activeSourceTimeSec = activePosition?.sourceTimeSec ?? null;diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 8a5ccae27..8470b723b 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -59,7 +59,7 @@ import { supportsCursorClickEffects } from "@/lib/cursor/cursorCapabilities";import { CURSOR_THEMES, DEFAULT_CURSOR_THEME_ID } from "@/lib/cursor/cursorThemes";import { buildGradientFromEditor } from "@/lib/gradientBuilder";import { resolveImageWallpaperUrl, WALLPAPER_PATHS, WALLPAPER_THUMB_PATHS } from "@/lib/wallpaper";-import { isNativeCompositorActive, setNativeParam, subscribeNativeCompositor } from "@/native";+import { isNativeCompositorActive, setNativeParam } from "@/native";import styles from "./NewEditorShell.module.css";interface PaneProps {@@ -1269,31 +1269,10 @@ export function VideoEffectsPane() {// valeur px de l'UI par ce même rayon de base fait que le coin natif ≈ les px affichés// (au lieu de plafonner à ~24px comme avec /64).const NATIVE_SCREEN_BASE_RADIUS_PX = 24;- useEffect(() => {- const syncToNative = () => {- // pas de garde `isNativeCompositorActive` : setNativeParam mémorise les valeurs- // même sans vue active, et le store les rejoue quand une vue s'active (fix du- // démarrage sur les défauts, indépendant de l'ordre de montage).- setNativeParam("backgroundBlur", settings.showBlur);- setNativeParam("motionBlur", settings.motionBlurAmount);- setNativeParam("shadow", settings.shadowIntensity);- setNativeParam("roundness", settings.borderRadius / NATIVE_SCREEN_BASE_RADIUS_PX);- setNativeParam("padding", settings.padding / 100);- const bg = settings.wallpaper;- if (bg.startsWith("#")) {- setNativeParam("backgroundColor", bg);- }- };- syncToNative();- return subscribeNativeCompositor(syncToNative);- }, [- settings.showBlur,- settings.motionBlurAmount,- settings.shadowIntensity,- settings.borderRadius,- settings.padding,- settings.wallpaper,- ]);+ // La synchro initiale de ces params vit desormais dans NativeCompositorOverlay+ // (`pushAllNativeParams`) : l'inspecteur n'affiche qu'un panneau a la fois, donc+ // un effet de montage ici ne poussait rien tant que ce panneau precis n'avait pas+ // ete ouvert. Les handlers par controle ci-dessous poussent toujours leurs diffs.return (<Pane title={ts("effects.title")} icon={<Sliders size={14} />} helpText={ts("effects.help")}>@@ -1419,17 +1398,7 @@ export function LayoutPane() {const { settings, set, setLive, commit, hasDocument } = useEditorSettings();const document = useProjectStore((s) => s.document);- // Push webcam-layout settings into the native compositor (initial values + on view- // activation); the per-control handlers below also push their diffs live.- useEffect(() => {- const syncToNative = () => {- setNativeParam("webcamSize", settings.webcamSizePreset / NATIVE_WEBCAM_BASE_PCT);- setNativeParam("webcamMirror", settings.webcamMirrored);- setNativeParam("webcamShape", settings.webcamMaskShape);- };- syncToNative();- return subscribeNativeCompositor(syncToNative);- }, [settings.webcamSizePreset, settings.webcamMirrored, settings.webcamMaskShape]);+ // Synchro initiale : cf. NativeCompositorOverlay (`pushAllNativeParams`).// the mask shape picker only makes sense for Picture-in-Picture.// Dual-frame (side-by-side) and vertical-stack (top/bottom) weld the camera// to the screen as one block — the mask is rectangular and sized off the@@ -1496,7 +1465,15 @@ export function LayoutPane() {<divstyle={{display: "grid",- gridTemplateColumns: "repeat(4, 1fr)",+ // `minmax(0, 1fr)` et non `1fr`. `1fr` vaut `minmax(auto, 1fr)`,+ // donc la taille MINIMALE de la piste est `auto`, ce qui resout+ // pour chaque bouton a son minimum de contenu -- et « Rounded »+ // est un mot insecable. Quatre boutons a 64,83 px plus trois+ // gouttieres de 8 px reclamaient 283,3 px la ou le panneau n'en+ // offre que 234 : les pistes refusaient de retrecir et la grille+ // debordait, en coupant le dernier bouton. `minmax(0, ...)`+ // autorise la piste a passer sous son contenu.+ gridTemplateColumns: "repeat(4, minmax(0, 1fr))",gap: 8,padding: "0 var(--sp-4) 12px",}}@@ -1514,6 +1491,10 @@ export function LayoutPane() {padding: 8,display: "flex",alignItems: "center",+ // Sans `minWidth: 0` le bouton garde son minimum de+ // contenu et rouvre le debordement que `minmax(0, 1fr)`+ // vient de fermer sur la piste.+ minWidth: 0,}}disabled={layoutControlsDisabled}onClick={() => {@@ -1588,23 +1569,7 @@ export function CursorPane() {// Push cursor settings into the native compositor (initial + on view activation); the// handlers below push diffs live. Sizes are sent as direct scales (1 = fixture default).- useEffect(() => {- const syncToNative = () => {- setNativeParam("cursorShow", settings.cursorShow);- setNativeParam("cursorSize", settings.cursor.size);- setNativeParam("cursorClickBounce", settings.cursor.clickBounce);- setNativeParam("cursorSmoothing", settings.cursor.smoothing);- setNativeParam("cursorMotionBlur", settings.cursor.motionBlur);- };- syncToNative();- return subscribeNativeCompositor(syncToNative);- }, [- settings.cursorShow,- settings.cursor.size,- settings.cursor.clickBounce,- settings.cursor.smoothing,- settings.cursor.motionBlur,- ]);+ // Synchro initiale : cf. NativeCompositorOverlay (`pushAllNativeParams`).// Built-in "Default" plus each bundled theme. Thumbnails use the theme's// arrow asset; the persisted value is the theme id. Same shape as thediff --git a/src/native/nativeCompositorStore.test.ts b/src/native/nativeCompositorStore.test.tsnew file mode 100644index 000000000..ae19569cd--- /dev/null+++ b/src/native/nativeCompositorStore.test.ts@@ -0,0 +1,118 @@+import { beforeEach, describe, expect, it, vi } from "vitest";+import { DEFAULT_EDITOR_SETTINGS } from "@/lib/ai-edition/store/editorSettings";+import type { CompositorParamValue } from "./contracts";++const setCompositorParam = vi.fn(() => Promise.resolve());++vi.mock("./compositorViewClient", () => ({+ setCompositorParam: (id: number, key: string, value: CompositorParamValue) =>+ setCompositorParam(id, key, value),+ setCompositorPlaying: vi.fn(() => Promise.resolve()),+ setCompositorScene: vi.fn(() => Promise.resolve()),+ setCompositorTime: vi.fn(() => Promise.resolve()),+}));++/**+ * The full key set the addon understands, transcribed from+ * `crates/compositor/src/live.rs` — `set_param_bool` (3), `set_param_num` (9)+ * and `set_param_str` (2). Anything the addon accepts and the app never pushes+ * silently keeps its compiled-in default, which is exactly the bug this file+ * guards: `cursorSize` was only ever pushed by the cursor panel's mount effect,+ * and the inspector shows one panel at a time, so a project's cursor settings+ * did not reach the preview until the user opened that panel.+ */+const ADDON_KEYS = [+ "backgroundBlur",+ "webcamMirror",+ "cursorShow",+ "shadow",+ "roundness",+ "motionBlur",+ "padding",+ "webcamSize",+ "cursorSize",+ "cursorClickBounce",+ "cursorSmoothing",+ "cursorMotionBlur",+ "backgroundColor",+ "webcamShape",+] as const;++describe("pushAllNativeParams", () => {+ beforeEach(() => {+ vi.resetModules();+ setCompositorParam.mockClear();+ });++ async function pushWith(overrides: Record<string, unknown> = {}) {+ const store = await import("./nativeCompositorStore");+ store.setCurrentNativeViewId(1);+ setCompositorParam.mockClear();+ store.pushAllNativeParams({+ ...DEFAULT_EDITOR_SETTINGS,+ ...overrides,+ } as Parameters<typeof store.pushAllNativeParams>[0]);+ return new Map(+ setCompositorParam.mock.calls.map((c) => [c[1] as string, c[2] as CompositorParamValue]),+ );+ }++ it("pushes every key the addon understands", async () => {+ // A hex wallpaper so backgroundColor is included; a gradient or image+ // wallpaper legitimately travels in the scene instead.+ const pushed = await pushWith({ wallpaper: "#101820" });+ const missing = ADDON_KEYS.filter((k) => !pushed.has(k));+ expect(missing, `params the addon accepts but nothing pushes: ${missing.join(", ")}`).toEqual(+ [],+ );+ });++ it("sends cursor values RAW, not in slider space", async () => {+ // SliderCell displays cursor.size * 10 and divides by 10 on the way out;+ // smoothing and motionBlur use * 100. Pushing a slider-space value from+ // here would scale the preview by 10 or 100 on load — a regression that+ // would look like "the cursor is enormous when I open a project".+ const pushed = await pushWith({+ cursor: { size: 3, clickBounce: 2.5, smoothing: 0.67, motionBlur: 0.35 },+ });+ expect(pushed.get("cursorSize")).toBe(3);+ expect(pushed.get("cursorClickBounce")).toBe(2.5);+ expect(pushed.get("cursorSmoothing")).toBeCloseTo(0.67, 5);+ expect(pushed.get("cursorMotionBlur")).toBeCloseTo(0.35, 5);+ });++ it("converts padding and the two base-unit scales", async () => {+ const pushed = await pushWith({+ padding: 50,+ borderRadius: 48,+ webcamSizePreset: 33.4,+ });+ expect(pushed.get("padding")).toBeCloseTo(0.5, 5);+ // NATIVE_SCREEN_BASE_RADIUS_PX = 24, NATIVE_WEBCAM_BASE_PCT = 16.7.+ expect(pushed.get("roundness")).toBeCloseTo(2, 5);+ expect(pushed.get("webcamSize")).toBeCloseTo(2, 5);+ });++ it("omits backgroundColor when the wallpaper is not a literal colour", async () => {+ const pushed = await pushWith({ wallpaper: "wallpapers/ridges.jpg" });+ expect(pushed.has("backgroundColor")).toBe(false);+ });++ it("memoises so a view activating later still gets everything", async () => {+ // The ordering guarantee the fix leans on: params pushed before a view+ // exists are replayed on activation, so the overlay needs no viewId guard.+ const store = await import("./nativeCompositorStore");+ store.setCurrentNativeViewId(null);+ setCompositorParam.mockClear();+ store.pushAllNativeParams({+ ...DEFAULT_EDITOR_SETTINGS,+ wallpaper: "#101820",+ } as Parameters<typeof store.pushAllNativeParams>[0]);+ expect(setCompositorParam).not.toHaveBeenCalled();++ store.setCurrentNativeViewId(7);+ const replayed = new Set(setCompositorParam.mock.calls.map((c) => c[1] as string));+ const missing = ADDON_KEYS.filter((k) => !replayed.has(k));+ expect(missing, `not replayed on activation: ${missing.join(", ")}`).toEqual([]);+ });+});diff --git a/src/native/nativeCompositorStore.ts b/src/native/nativeCompositorStore.tsindex 87954939b..65a1e2cc3 100644--- a/src/native/nativeCompositorStore.ts+++ b/src/native/nativeCompositorStore.ts@@ -4,6 +4,8 @@* pousser un paramètre via `setNativeParam` sans connaître l'overlay. No-op tant qu'aucune* vue n'est active (pas encore de document/asset chargé, ou addon absent).*/++import type { EditorSettingsSnapshot } from "@/lib/ai-edition/store/editorSettings";import {setCompositorParam,setCompositorPlaying,@@ -11,6 +13,7 @@ import {setCompositorTime,} from "./compositorViewClient";import type { CompositorParamValue } from "./contracts";+import { NATIVE_SCREEN_BASE_RADIUS_PX, NATIVE_WEBCAM_BASE_PCT } from "./paramUnits";let currentViewId: number | null = null;const listeners = new Set<() => void>();@@ -99,3 +102,49 @@ export function subscribeNativeCompositor(listener: () => void): () => void {listeners.delete(listener);};}++/**+ * Pushes EVERY param the addon understands, from a settings snapshot.+ *+ * WHY THIS EXISTS. Until this function, each group of params was pushed only by+ * the mount effect of the panel that owns it — VideoEffectsPane, LayoutPane,+ * CursorPane. The inspector renders exactly ONE panel at a time+ * (FloatingInspector's if/else on `facet`, defaulting to "effects"), so on load+ * the cursor and layout panels have never mounted and their params sit at the+ * addon's compiled-in defaults. That is the whole bug: a project with cursor+ * size 3.0 previewed at 1.0 until the user opened the cursor panel, at which+ * point it snapped to the right value and looked like the panel had "enabled"+ * something.+ *+ * The `lastParams` replay above is not a substitute: it can only replay keys+ * that were pushed at least once, and a key owned by a panel that never mounted+ * was never pushed at all.+ *+ * UNITS. The values here are RAW, matching what the old mount effects sent and+ * NOT what the sliders send. `SliderCell` displays `cursor.size * 10` and its+ * handler divides by 10 again on the way out; the same asymmetry applies to+ * clickBounce (x10) and to smoothing/motionBlur (x100). Sending a slider-space+ * value from here would scale the whole preview by 10 or 100 on load.+ */+export function pushAllNativeParams(settings: EditorSettingsSnapshot): void {+ setNativeParam("backgroundBlur", settings.showBlur);+ setNativeParam("motionBlur", settings.motionBlurAmount);+ setNativeParam("shadow", settings.shadowIntensity);+ setNativeParam("roundness", settings.borderRadius / NATIVE_SCREEN_BASE_RADIUS_PX);+ setNativeParam("padding", settings.padding / 100);+ // Only a literal colour is a param; a gradient or an image wallpaper travels+ // in the scene instead, and pushing its name here would be meaningless.+ if (settings.wallpaper.startsWith("#")) {+ setNativeParam("backgroundColor", settings.wallpaper);+ }++ setNativeParam("webcamSize", settings.webcamSizePreset / NATIVE_WEBCAM_BASE_PCT);+ setNativeParam("webcamMirror", settings.webcamMirrored);+ setNativeParam("webcamShape", settings.webcamMaskShape);++ setNativeParam("cursorShow", settings.cursorShow);+ setNativeParam("cursorSize", settings.cursor.size);+ setNativeParam("cursorClickBounce", settings.cursor.clickBounce);+ setNativeParam("cursorSmoothing", settings.cursor.smoothing);+ setNativeParam("cursorMotionBlur", settings.cursor.motionBlur);+}diff --git a/src/native/paramUnits.ts b/src/native/paramUnits.tsnew file mode 100644index 000000000..204802cb9--- /dev/null+++ b/src/native/paramUnits.ts@@ -0,0 +1,26 @@+/**+ * Unit conversions between the editor's settings and the native compositor's+ * params.+ *+ * These two constants used to live inside the panels that pushed them — one+ * declared inside `VideoEffectsPane`'s body, the other at RightPanes module+ * scope. They are here because `pushAllNativeParams` needs the same numbers,+ * and a second copy of a conversion factor is a silent divergence waiting to+ * happen: the preview would drift from the panel by exactly the ratio between+ * the two values, which is the kind of bug nobody attributes to a constant.+ */++/**+ * The fixture's screen corner radius at 1920 wide. The native `roundness` param+ * is a SCALE on it, so dividing the UI's pixel value by the same base makes the+ * rendered corner match the pixels shown (dividing by 64, as an earlier version+ * did, capped it at ~24px).+ */+export const NATIVE_SCREEN_BASE_RADIUS_PX = 24;++/**+ * The fixture's webcam width as a percentage of the frame (a_side = 320px @1920+ * ≈ 16.7%). `webcamSizePreset / this` is the native size scale, 1 meaning the+ * shipped default, so the slider reads as a direct multiplier.+ */+export const NATIVE_WEBCAM_BASE_PCT = 16.7;