Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Audio: Loop and Join results say what each call did, and the crossfade sent is the one shown

Claudebc004f8872cb
diff --git a/src/components/audio-tools/audio-tools.tsx b/src/components/audio-tools/audio-tools.tsx
index 72b46955..efcafd96 100644
--- a/src/components/audio-tools/audio-tools.tsx
+++ b/src/components/audio-tools/audio-tools.tsx
@@ -176,9 +176,12 @@ function LengthField({ value, onCommit, max }: { value: number; onCommit: (s: nu
);
}
+/** The longest crossfade offered when the clips allow up to `max` seconds (half-second steps). */
+const crossfadeTop = (max: number) => Math.max(0.5, Math.min(CROSSFADE_MAX, Math.floor(max * 2) / 2));
+
/** Crossfade length and fade shape (open engine; the cloud has no crossfade, the run bar says so). */
function CrossfadeControls({ value, onChange, curve, onCurve, max }: { value: number; onChange: (v: number) => void; curve: Curve; onCurve: (c: Curve) => void; max: number }) {
- const top = Math.max(0.5, Math.min(CROSSFADE_MAX, Math.floor(max * 2) / 2));
+ const top = crossfadeTop(max);
return (
<div className="space-y-3">
<div className="flex items-center gap-3">
@@ -312,9 +315,12 @@ export function AudioLoopTool({ tabs }: { tabs?: React.ReactNode }) {
const [curve, setCurve] = useState<Curve>("equal-power");
useHandoff(setClip);
const ready = clip && !clip.uploading && clip.ref ? clip : null;
+ // The crossfade the slider shows: what the clip allows (a shorter clip lowers it).
+ const fadeMax = clip?.duration ? clip.duration / 2 - 0.1 : CROSSFADE_MAX;
+ const fade = Math.min(crossfade, crossfadeTop(fadeMax));
const body: AudioToolBody | null = useMemo(
- () => (ready ? { tool: "loop", engine, audio: ready.ref, name: nameOf(ready), duration: target, ...(ready.duration && { sourceDuration: ready.duration }), ...(engine === "open" && { crossfade, curve }) } : null),
- [ready, engine, target, crossfade, curve],
+ () => (ready ? { tool: "loop", engine, audio: ready.ref, name: nameOf(ready), duration: target, ...(ready.duration && { sourceDuration: ready.duration }), ...(engine === "open" && { crossfade: fade, curve }) } : null),
+ [ready, engine, target, fade, curve],
);
const preview = useAudioToolPreview(useSettled(body));
const blocker = !clip ? "Add a clip to loop" : clip.uploading ? "Uploading…" : clip.duration && target <= clip.duration ? `The clip is already ${clock(clip.duration)} — pick a longer length` : null;
@@ -360,12 +366,12 @@ export function AudioLoopTool({ tabs }: { tabs?: React.ReactNode }) {
/>
<LengthField value={target} onCommit={setTarget} max={LOOP_MAX_SECONDS} />
</div>
- {clip.duration ? <LoopBar clip={clip.duration} target={target} crossfade={crossfade} engine={engine} /> : null}
+ {clip.duration ? <LoopBar clip={clip.duration} target={target} crossfade={fade} engine={engine} /> : null}
</Panel>
)}
{clip && engine === "open" && (
<Panel title="Seams">
- <CrossfadeControls value={crossfade} onChange={setCrossfade} curve={curve} onCurve={setCurve} max={clip.duration ? clip.duration / 2 - 0.1 : CROSSFADE_MAX} />
+ <CrossfadeControls value={fade} onChange={setCrossfade} curve={curve} onCurve={setCurve} max={fadeMax} />
</Panel>
)}
{clip && <RunBar label="Loop it" icon={Repeat} blocker={blocker} preview={preview} engine={engine} onRun={go} pending={run.isPending} onOpenEngine={mode === "both" ? () => setEngine("open") : undefined} />}
@@ -398,13 +404,16 @@ export function AudioJoinTool({ tabs }: { tabs?: React.ReactNode }) {
return next;
});
const ready = clips.length >= 2 && clips.every((c) => !c.uploading && c.ref);
+ // End clips allow a crossfade up to their length, middle ones up to half of it (they have two seams).
+ const shortest = clips.reduce((m, c, i) => Math.min(m, (c.duration ?? Infinity) / (i === 0 || i === clips.length - 1 ? 1 : 2)), Infinity);
+ const fadeMax = Number.isFinite(shortest) ? shortest - 0.1 : CROSSFADE_MAX;
+ const fade = Math.min(crossfade, crossfadeTop(fadeMax));
const body: AudioToolBody | null = useMemo(
- () => (ready ? { tool: "join", engine, clips: clips.map((c) => ({ url: c.ref, name: nameOf(c), ...(c.duration && { duration: c.duration }) })), ...(engine === "open" && { crossfade, curve }) } : null),
- [ready, clips, engine, crossfade, curve],
+ () => (ready ? { tool: "join", engine, clips: clips.map((c) => ({ url: c.ref, name: nameOf(c), ...(c.duration && { duration: c.duration }) })), ...(engine === "open" && { crossfade: fade, curve }) } : null),
+ [ready, clips, engine, fade, curve],
);
const preview = useAudioToolPreview(useSettled(body));
const blocker = clips.length < 2 ? "Add at least two clips" : clips.some((c) => c.uploading) ? "Uploading…" : null;
- const shortest = clips.reduce((m, c, i) => Math.min(m, (c.duration ?? Infinity) / (i === 0 || i === clips.length - 1 ? 1 : 2)), Infinity);
const go = () => {
if (blocker) return void toast(blocker);
if (preview.error) return void toast.error((preview.error as Error).message);
@@ -453,7 +462,7 @@ export function AudioJoinTool({ tabs }: { tabs?: React.ReactNode }) {
)}
{clips.length > 0 && engine === "open" && (
<Panel title="Seams">
- <CrossfadeControls value={crossfade} onChange={setCrossfade} curve={curve} onCurve={setCurve} max={Number.isFinite(shortest) ? shortest - 0.1 : CROSSFADE_MAX} />
+ <CrossfadeControls value={fade} onChange={setCrossfade} curve={curve} onCurve={setCurve} max={fadeMax} />
</Panel>
)}
{clips.length > 0 && <RunBar label="Join them" icon={Merge} blocker={blocker} preview={preview} engine={engine} onRun={go} pending={run.isPending} onOpenEngine={mode === "both" ? () => setEngine("open") : undefined} />}
diff --git a/src/lib/av/audio-tools.ts b/src/lib/av/audio-tools.ts
index 15e81674..c99ab69d 100644
--- a/src/lib/av/audio-tools.ts
+++ b/src/lib/av/audio-tools.ts
@@ -116,6 +116,7 @@ export function planLoop(i: LoopInput): ToolPlan {
inputs: { audio: i.audio },
params: { duration, crossfade: x, sourceDuration: L, ...(i.curve === "linear" && { extra: { curve: "linear" } }) },
title,
+ step: { label: `${plural(seams, "seam")} · ${x} s crossfades`, index: 0, of: 1 },
},
},
],
@@ -144,6 +145,7 @@ export function planLoop(i: LoopInput): ToolPlan {
...(k === 0 && { inputs: { audio: i.audio } }),
params: { duration: made, sourceDuration: clip },
...(k === passes.length - 1 && { title }),
+ step: { label: `${p} plays${passes.length > 1 ? ` · call ${k + 1} of ${passes.length}` : ""}`, index: k, of: passes.length },
},
...(k > 0 && { after: [`loop-${k}`], chain: [{ slot: "audio" as const }] }),
};
@@ -186,6 +188,7 @@ export function planJoin(i: JoinInput): ToolPlan {
inputs: { audios: clips.map((c) => c.url) },
params: { crossfade: x, ...(i.curve === "linear" && { extra: { curve: "linear" } }) },
title,
+ step: { label: `${plural(clips.length - 1, "seam")} · ${x} s crossfades`, index: 0, of: 1 },
},
},
],
@@ -208,6 +211,7 @@ export function planJoin(i: JoinInput): ToolPlan {
...(k > 1 && { after: [`join-${k - 1}`], chain: [{ slot: "audios" as const, position: "first" as const }] }),
});
}
+ steps.forEach((s, k) => (s.request.step = { label: `Hard cuts${steps.length > 1 ? ` · call ${k + 1} of ${steps.length}` : ""}`, index: k, of: steps.length }));
return {
steps,
length: known ? joinedLength(lengths as number[], 0) : null,
diff --git a/src/lib/catalog/models.ts b/src/lib/catalog/models.ts
index 9dc62868..c20a8820 100644
--- a/src/lib/catalog/models.ts
+++ b/src/lib/catalog/models.ts
@@ -1039,7 +1039,7 @@ const open: ModelDef[] = [
}),
o({
id: "oss-audio-loop",
- name: "Loop audio",
+ name: "Crossfade loop",
vendor: "ComfyUI",
family: "utility",
kind: "audio",
@@ -1050,7 +1050,7 @@ const open: ModelDef[] = [
}),
o({
id: "oss-audio-join",
- name: "Join audio",
+ name: "Crossfade join",
vendor: "ComfyUI",
family: "utility",
kind: "audio",
diff --git a/tests/audio-tools.test.ts b/tests/audio-tools.test.ts
index 4c7e9dcb..01a9beeb 100644
--- a/tests/audio-tools.test.ts
+++ b/tests/audio-tools.test.ts
@@ -50,6 +50,7 @@ describe("Loop / extend and Join plans", () => {
it("loops on the open engine in one job, crossfaded, to the exact length", () => {
const p = planLoop({ engine: "open", audio: "/api/files/a.wav", name: "Bed", sourceDuration: 45, duration: 300, crossfade: 2 });
expect(p.steps).toHaveLength(1);
+ expect(p.steps[0].request.step?.label).toMatch(/^\d+ seams · 2 s crossfades$/);
expect(p.steps[0].request).toMatchObject({ feature: "audio-loop", modelId: "oss-audio-loop", op: "audio-loop", inputs: { audio: "/api/files/a.wav" }, params: { duration: 300, crossfade: 2, sourceDuration: 45 }, title: "Loop · Bed to 5:00" });
expect(p.length).toBe(300);
expect(p.summary).toBe("Loops it to 5:00 with 6 crossfaded seams (2 s each), then fades out over the last 2 s.");
@@ -71,6 +72,8 @@ describe("Loop / extend and Join plans", () => {
expect(chain.steps[2].request.inputs).toBeUndefined();
expect(chain.steps.map((s) => !!s.request.title)).toEqual([false, false, true]);
expect(chain.summary).toBe("Plays it 60 times back to back (3 calls of up to 5): 10:00.");
+ // Each tile says what its call does (not the pipeline's "Step 1 of 3").
+ expect(chain.steps.map((s) => s.request.step?.label)).toEqual(["5 plays · call 1 of 3", "4 plays · call 2 of 3", "3 plays · call 3 of 3"]);
expect(chain.notes).toEqual(["No crossfade on the cloud: switch to the open engine for smooth seams and an exact length."]);
});
@@ -98,11 +101,13 @@ describe("Loop / extend and Join plans", () => {
expect(open.steps).toHaveLength(1);
expect(open.steps[0].request).toMatchObject({ feature: "audio-join", modelId: "oss-audio-join", op: "audio-join", inputs: { audios: clips.map((c) => c.url) }, params: { crossfade: 1.5 }, title: "Join · 7 clips" });
expect(open.length).toBe(61);
+ expect(open.steps[0].request.step?.label).toBe("6 seams · 1.5 s crossfades");
expect(open.summary).toBe("Joins 7 clips in this order with a 1.5 s crossfade at 6 seams.");
const cloud = planJoin({ engine: "cloud", clips });
expect(cloud.steps.map((s) => s.request.inputs?.audios?.length)).toEqual([5, 2]);
expect(cloud.steps[1]).toMatchObject({ after: ["join-1"], chain: [{ slot: "audios", position: "first" }] });
expect(cloud.length).toBe(70);
+ expect(cloud.steps.map((s) => s.request.step?.label)).toEqual(["Hard cuts · call 1 of 2", "Hard cuts · call 2 of 2"]);
expect(cloud.notes[0]).toMatch(/hard cut/);
expect(() => planJoin({ engine: "open", clips: clips.slice(0, 1) })).toThrow("Add at least two clips to join");
expect(() => planJoin({ engine: "open", clips: Array.from({ length: 11 }, () => clips[0]) })).toThrow("Join up to 10 clips at a time");