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(effects): CodeRabbit's second pass on the integration PR
EtienneLescota6cd941f3d7e
diff --git a/crates/compositor/src/shader_fx.rs b/crates/compositor/src/shader_fx.rsindex d62f7cd17..08299edc8 100644--- a/crates/compositor/src/shader_fx.rs+++ b/crates/compositor/src/shader_fx.rs@@ -763,8 +763,9 @@ pub fn eviction_victim(entries: impl Iterator<Item = (u64, u64)>, scene: &[Scene/// Les régions actives au temps source `t`. Le document n'en tient qu'une à la fois ; une scène/// écrite à la main qui en superpose les applique dans son ordre.pub fn active_effects(effects: &[SceneShaderEffect], t: f32) -> Vec<&SceneShaderEffect> {- let t = t as f64;- effects.iter().filter(|e| t >= e.start_sec && t < e.end_sec).collect()+ // En f32 comme `t` et comme les annotations : `0.7_f32 as f64` tombe sous `0.7_f64`, et la+ // frame posée sur le début de la région la manquerait.+ effects.iter().filter(|e| t >= e.start_sec as f32 && t < e.end_sec as f32).collect()}/// La boîte englobante (x, y, w, h) d'un quad, en uv de sortie : `ctx.footage` sous un tilt 3D.@@ -1210,6 +1211,11 @@ mod tests {assert!(during.len() == 1 && std::ptr::eq(during[0], &effects[1]));let after = active_effects(&effects, 3.0);assert!(after.len() == 1 && std::ptr::eq(after[0], &effects[0]), "fin exclusive");+ let mut c = test_effect(VIGNETTE, vec![], &[]);+ (c.start_sec, c.end_sec) = (0.7, 1.3);+ let fractional = [c];+ assert_eq!(active_effects(&fractional, 0.7).len(), 1, "début fractionnaire inclus");+ assert!(active_effects(&fractional, 1.3).is_empty(), "fin fractionnaire exclue");let ctx = context(&effects[1], 2.0, 10.0, [1920.0, 1080.0], &FxFrameInputs::default());assert_eq!(ctx.region, [0.5, 2.0, 1.0, 0.0], "fragment, temps source");diff --git a/electron/ai-edition/agent-tools.test.ts b/electron/ai-edition/agent-tools.test.tsindex 3c72687b0..c105d2e4b 100644--- a/electron/ai-edition/agent-tools.test.ts+++ b/electron/ai-edition/agent-tools.test.ts@@ -3862,6 +3862,28 @@ describe("shader effects", () => {});});+ it("moves only its own pill when a re-tune makes it match the neighbour it touches", () => {+ const first = add(fixtureDocument(), { values: { level: 0.5 } }).document as AxcutDocument;+ const effectId = first.shaderEffects?.[0].id;+ const doc = run(first, "addEffect", { startSec: 6, endSec: 8, effectId })+ .document as AxcutDocument;+ const regionId = doc.shaderEffectRanges?.find((r) => r.startMs === 2000)?.id;+ const moved = run(doc, "setEffect", {+ effectRegionId: regionId,+ values: { level: 1 },+ endSec: 5,+ });+ expect(moved.ok).toBe(true);+ expect(+ [...(moved.document?.shaderEffectRanges ?? [])]+ .sort((a, b) => a.startMs - b.startMs)+ .map((r) => [r.startMs, r.endMs, r.values]),+ ).toEqual([+ [2000, 5000, {}],+ [6000, 8000, {}],+ ]);+ });+it("refuses to move an effect onto another one", () => {const first = add(fixtureDocument()).document as AxcutDocument;const doc = add(first, { startSec: 8, endSec: 9 }).document as AxcutDocument;diff --git a/electron/ai-edition/agent-tools.ts b/electron/ai-edition/agent-tools.tsindex 8b26e8419..50bb5de41 100644--- a/electron/ai-edition/agent-tools.ts+++ b/electron/ai-edition/agent-tools.ts@@ -3439,18 +3439,6 @@ export function executeAgentTool(const pillIds = new Set(resolvePillIds(prev, existing.id));const pill = coalesceRegionsForRuler(prev).find((p) => p.ids.includes(existing.id));const { values, target } = parsed.data;- const patched = prev.map((r) =>- pillIds.has(r.id)- ? {- ...r,- values:- values === undefined- ? r.values- : storedShaderEffectValues(definition, { ...r.values, ...values }),- target: target ?? r.target,- }- : r,- );const { startMs, endMs } = resolveSpanMs(pill? { startMs: Math.round(pill.start * 1000), endMs: Math.round(pill.end * 1000) }@@ -3458,14 +3446,29 @@ export function executeAgentTool(parsed.data.startSec,parsed.data.endSec,);- const blocked = effectBlocked(patched, startMs, endMs, pillIds);+ const blocked = effectBlocked(prev, startMs, endMs, pillIds);if (blocked) return failure(`The effect was NOT changed: ${blocked}`);const moved = parsed.data.startSec !== undefined || parsed.data.endSec !== undefined;- const rebuilt = moved- ? replacePillSpan(patched, existing.id, startMs, endMs, document.timeline.clips, () =>+ // The span is replaced before the patch: patched first, the pill could take the same+ // values as a touching neighbour, coalesce with it, and move it along.+ const spanned = moved+ ? replacePillSpan(prev, existing.id, startMs, endMs, document.timeline.clips, () =>createId("fxr"),)- : patched;+ : prev;+ const others = new Set(prev.filter((r) => !pillIds.has(r.id)).map((r) => r.id));+ const rebuilt = spanned.map((r) =>+ others.has(r.id)+ ? r+ : {+ ...r,+ values:+ values === undefined+ ? r.values+ : storedShaderEffectValues(definition, { ...r.values, ...values }),+ target: target ?? r.target,+ },+ );const landing = landingAfterPillEdit(prev, rebuilt, pillIds, document);if (!landing.anchored) return coversNoClip("effect", startMs / 1000, endMs / 1000, document);const next: AxcutDocument = { ...document, shaderEffectRanges: rebuilt };diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsxindex 4375d0c88..60a209b6f 100644--- a/src/components/ai-edition/NewEditorShell.tsx+++ b/src/components/ai-edition/NewEditorShell.tsx@@ -1135,6 +1135,7 @@ export function NewEditorShell() {doc,snapshot.definition,anchored as AxcutShaderEffectRange[],+ () => createId("fx"),);if (!next) {toast.error(te("regionClipboard.pasteEffectOverlap"));@@ -1202,14 +1203,22 @@ export function NewEditorShell() {return;}- // An effect region goes with its definition (`RegionSnapshot`).+ // An effect region goes with its definition (`RegionSnapshot`), and with the span of the+ // whole pill: one cut by a clip boundary is several fragments.if (sel.kind === "shaderEffect") {- const region = tl.shaderEffectRanges.find((r) => r.id === sel.id);- const definition = region && tl.shaderEffects.find((e) => e.id === region.effectId);- if (!region || !definition) return;+ const { coalesceRegionsForRuler } = await import("@/lib/ai-edition/timeline/timelineMap");+ const pill = coalesceRegionsForRuler(tl.shaderEffectRanges).find((p) =>+ p.ids.includes(sel.id),+ );+ const definition = pill && tl.shaderEffects.find((e) => e.id === pill.member.effectId);+ if (!pill || !definition) return;copyRegion({kind: "shaderEffect",- region: region as unknown as Record<string, unknown>,+ region: {+ ...pill.member,+ startMs: Math.round(pill.start * 1000),+ endMs: Math.round(pill.end * 1000),+ } as unknown as Record<string, unknown>,definition,});setCopiedClipId(null);diff --git a/src/lib/ai-edition/shaderEffects.test.ts b/src/lib/ai-edition/shaderEffects.test.tsindex 41d082a0e..3c61961af 100644--- a/src/lib/ai-edition/shaderEffects.test.ts+++ b/src/lib/ai-edition/shaderEffects.test.ts@@ -20,23 +20,46 @@ const fragment = (id: string, startMs: number, endMs: number): AxcutShaderEffectvalues: {},target: "image",});+const newId = () => "fx_new";describe("withPastedShaderEffect", () => {const empty: AxcutDocument = createEmptyDocument({ projectId: "p", title: "t" });it("recreates the definition in a project that does not have it", () => {- const next = withPastedShaderEffect(empty, definition, [fragment("fxr_1", 0, 1000)]);+ const next = withPastedShaderEffect(empty, definition, [fragment("fxr_1", 0, 1000)], newId);expect(next?.shaderEffects).toEqual([definition]);expect(next?.shaderEffectRanges).toHaveLength(1);});it("reuses the definition the project already has, and refuses a paste onto an effect", () => {- const doc = withPastedShaderEffect(empty, definition, [- fragment("fxr_1", 0, 1000),- ]) as AxcutDocument;- const again = withPastedShaderEffect(doc, definition, [fragment("fxr_2", 2000, 3000)]);+ const doc = withPastedShaderEffect(+ empty,+ definition,+ [fragment("fxr_1", 0, 1000)],+ newId,+ ) as AxcutDocument;+ const again = withPastedShaderEffect(doc, definition, [fragment("fxr_2", 2000, 3000)], newId);expect(again?.shaderEffects).toHaveLength(1);expect(again?.shaderEffectRanges).toHaveLength(2);- expect(withPastedShaderEffect(doc, definition, [fragment("fxr_3", 500, 1500)])).toBeNull();+ expect(+ withPastedShaderEffect(doc, definition, [fragment("fxr_3", 500, 1500)], newId),+ ).toBeNull();+ });++ it("gives the paste its own id when the project holds another effect under that one", () => {+ const doc = withPastedShaderEffect(+ empty,+ definition,+ [fragment("fxr_1", 0, 1000)],+ newId,+ ) as AxcutDocument;+ // Copied, then edited on the other side: same id, other code.+ const edited = { ...definition, code: definition.code.replace("frame(uv)", "frame(uv) * 0.5") };+ const next = withPastedShaderEffect(doc, edited, [fragment("fxr_2", 2000, 3000)], newId);+ expect(next?.shaderEffects?.map((e) => [e.id, e.code])).toEqual([+ ["fx_1", definition.code],+ ["fx_new", edited.code],+ ]);+ expect(next?.shaderEffectRanges?.map((r) => r.effectId)).toEqual(["fx_1", "fx_new"]);});});diff --git a/src/lib/ai-edition/shaderEffects.ts b/src/lib/ai-edition/shaderEffects.tsindex 53293df59..a1a3fbef4 100644--- a/src/lib/ai-edition/shaderEffects.ts+++ b/src/lib/ai-edition/shaderEffects.ts@@ -153,25 +153,44 @@ export function shaderEffectCostAdvice(tier: ShaderEffectTier, spanSec: number):return `${tier} over ${spanSec.toFixed(1)} s: this tier is meant for at most ${TIER_SPAN_SEC[tier]} s; for a region this long, aim ${lighter}. It is a recommendation, not a limit.`;}+/** Two definitions that draw and read the same: everything but the cached cost. */+function sameShaderEffect(a: AxcutShaderEffect, b: AxcutShaderEffect): boolean {+ return (+ a.name === b.name &&+ a.description === b.description &&+ a.contract === b.contract &&+ a.code === b.code &&+ JSON.stringify(a.params) === JSON.stringify(b.params)+ );+}+/*** `document` with a pasted effect region (its fragments, already anchored) and its definition,- * recreated when the project does not have it: a region copied from another project. `null`- * when the region would overlap an effect already there, since one effect runs at a time.+ * recreated when the project does not have it: a region copied from another project. A project+ * holding a different definition under that id (the effect was copied, then edited on one side)+ * keeps it, and the paste gets its own (`newId`). `null` when the region would overlap an effect+ * already there, since one effect runs at a time.*/export function withPastedShaderEffect(document: AxcutDocument,definition: AxcutShaderEffect,fragments: AxcutShaderEffectRange[],+ newId: () => string,): AxcutDocument | null {const ranges = document.shaderEffectRanges ?? [];const overlaps = fragments.some((f) =>ranges.some((r) => r.startMs < f.endMs && r.endMs > f.startMs),);if (overlaps) return null;- const known = (document.shaderEffects ?? []).some((e) => e.id === definition.id);+ const effects = document.shaderEffects ?? [];+ const held = effects.find((e) => e.id === definition.id);+ if (held && sameShaderEffect(held, definition)) {+ return { ...document, shaderEffectRanges: [...ranges, ...fragments] };+ }+ const pasted = held ? { ...definition, id: newId() } : definition;return {...document,- shaderEffects: known ? document.shaderEffects : [...(document.shaderEffects ?? []), definition],- shaderEffectRanges: [...ranges, ...fragments],+ shaderEffects: [...effects, pasted],+ shaderEffectRanges: [...ranges, ...fragments.map((f) => ({ ...f, effectId: pasted.id }))],};}