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.

Extend & remix: a reused run sends the song that is attached, and a song swapped in is never sent as the earlier one

Claude4d3613364c76
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index f1e9e508..f955d9a9 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -14,8 +14,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
import { useToday } from "@/hooks/use-today";
import { estimateCost, imageLimit, layoutCanvas, planGeneration, routesFor, type Plan } from "@/lib/catalog/plan";
import type { Engine, GenerationRequest, InputSlot, MediaKind, ModelDef, Operation, Preset, PresetRoute, VideoFormat } from "@/lib/catalog/types";
-import { LYRICS_PARAM } from "@/lib/lyrics";
-import { SONG_ID_PARAM } from "@/lib/catalog/payload";
+import { LYRICS_PARAM, SONG_ID_PARAM, withSongId } from "@/lib/lyrics";
import { dualEngine } from "@/lib/catalog/engines";
import { locksByDefault } from "@/lib/catalog/palettes";
import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";
@@ -240,8 +239,10 @@ const SUNG_OPS = new Set<Operation>(["music", "song-extend", "song-remix"]);
function songDraft<D extends Pick<Draft, "lyrics" | "params" | "slots" | "song">>(d: D, model: ModelDef | undefined, slots: InputSlot[]): D {
let out = d;
if (d.lyrics?.trim() && model?.options.lyrics) out = { ...out, params: { ...out.params, extra: { ...out.params.extra, [LYRICS_PARAM]: d.lyrics } } };
- // One of Mureka's own songs, still the one attached: its tools take it by id (no upload).
- if (d.song && d.slots.audio?.ref === d.song.url && model?.family === "mureka") out = { ...out, params: { ...out.params, extra: { ...out.params.extra, [SONG_ID_PARAM]: d.song.id } } };
+ // One of Mureka's own songs, still the one attached: its tools take it by id (no upload). Any other song goes as itself.
+ if (d.song || (out.params.extra && SONG_ID_PARAM in out.params.extra)) {
+ out = { ...out, params: { ...out.params, extra: withSongId(out.params.extra, d.song, d.slots.audio?.ref, model?.family === "mureka") } };
+ }
const hidden = slots.filter((s) => s.cover && !model?.options.cover && out.slots[s.key]).map((s) => s.key);
if (hidden.length) out = { ...out, slots: Object.fromEntries(Object.entries(out.slots).filter(([k]) => !hidden.includes(k as InputSlot["key"]))) };
return out;
diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsx
index 1172f65e..9bbaf3ae 100644
--- a/src/components/studio/studio-page.tsx
+++ b/src/components/studio/studio-page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { LYRICS_PARAM } from "@/lib/lyrics";
+import { songFromRun } from "@/lib/lyrics";
import { ArrowRight, ArrowUp, Loader2, Upload, Zap } from "lucide-react";
import Link from "next/link";
import dynamic from "next/dynamic";
@@ -186,13 +186,11 @@ function draftFromGeneration(g: Generation, config: StudioConfig, getModel: (id:
// A spoken language stored as a name (Assist's "Spanish") or a locale comes back as the model's own code.
const languages = getModel(r.modelId)?.options.sourceLanguages;
if (languages?.length && params.sourceLanguage) params.sourceLanguage = matchSpokenLanguage(params.sourceLanguage, languages) ?? params.sourceLanguage;
- // A song's lyrics come back in the lyrics editor.
- const lyrics = typeof params.extra?.[LYRICS_PARAM] === "string" ? (params.extra[LYRICS_PARAM] as string) : undefined;
- if (lyrics !== undefined) {
- const rest = { ...params.extra };
- delete rest[LYRICS_PARAM];
- params.extra = Object.keys(rest).length ? rest : undefined;
- }
+ // A song's lyrics come back in the lyrics editor. One of Mureka's own songs (an extend or remix by its id) comes back as
+ // the attached song's id, so a song swapped in afterwards is sent as itself, never as the old id.
+ const sung = songFromRun(params.extra, r.inputs?.audio);
+ params.extra = sung.extra;
+ const { lyrics, song } = sung;
// A layout run comes back in Layout mode (studios that have it): its boxes in the editor, the prompt as their caption.
const laid = config.layout ? withoutLayout(params) : { params, layout: undefined };
return {
@@ -210,6 +208,7 @@ function draftFromGeneration(g: Generation, config: StudioConfig, getModel: (id:
mix: r.mix,
signature: signed?.signature,
lyrics,
+ song,
};
}
diff --git a/src/lib/catalog/payload.ts b/src/lib/catalog/payload.ts
index 5b6bce18..a709ebd1 100644
--- a/src/lib/catalog/payload.ts
+++ b/src/lib/catalog/payload.ts
@@ -1,5 +1,5 @@
import { readTimeline, timelineTracks } from "@/lib/av/timeline";
-import { LYRICS_PARAM, lyricsOf, promptWithLyrics } from "@/lib/lyrics";
+import { LYRICS_PARAM, lyricsOf, promptWithLyrics, SONG_ID_PARAM } from "@/lib/lyrics";
import { toH3MaxTrajectory, type CameraKey } from "@/lib/camera-path";
import { upscaleFactorFor } from "@/lib/av/upscale";
import { carriesBoxes, carriesLayout, LAYOUT_PARAM } from "@/lib/layout-prompt";
@@ -352,8 +352,7 @@ function elementList(e: NonNullable<FieldMap["elements"]>, images: string[], vid
return { list, usedImages, usedVideos };
}
-/** params.extra key of a song tool's source when it is one of the provider's own songs (a result's meta.songId). */
-export const SONG_ID_PARAM = "songId";
+export { SONG_ID_PARAM };
/** Build a provider payload from canonical input using a route's {@link FieldMap}. Pure + unit-tested. */
export function buildPayload(map: FieldMap, input: GenInput): Record<string, unknown> {
diff --git a/src/lib/lyrics.ts b/src/lib/lyrics.ts
index 69e81b53..a579ef0b 100644
--- a/src/lib/lyrics.ts
+++ b/src/lib/lyrics.ts
@@ -11,6 +11,42 @@
/** The params.extra key the lyrics travel in (the ComfyUI graphs' `lyrics` binding reads it as it is). */
export const LYRICS_PARAM = "lyrics";
+/** params.extra key of a song tool's source when it is one of the provider's own songs (a result's meta.songId). */
+export const SONG_ID_PARAM = "songId";
+
+/**
+ * A past run's song, for Reuse: its lyrics (back in the editor) and its Mureka song id together with the song that id names
+ * (so the id goes again only while that song is the one attached); `extra` comes back without either.
+ */
+export function songFromRun(
+ extra: Record<string, unknown> | undefined,
+ audio: string | undefined,
+): { extra: Record<string, unknown> | undefined; lyrics?: string; song?: { id: string; url: string } } {
+ if (!extra || (!(LYRICS_PARAM in extra) && !(SONG_ID_PARAM in extra))) return { extra };
+ const { [LYRICS_PARAM]: words, [SONG_ID_PARAM]: id, ...rest } = extra;
+ return {
+ extra: Object.keys(rest).length ? rest : undefined,
+ ...(typeof words === "string" && { lyrics: words }),
+ ...(typeof id === "string" && id && audio && { song: { id, url: audio } }),
+ };
+}
+
+/**
+ * A request's song id, for a song tool: one of Mureka's own songs goes by its id only while it is still the song attached;
+ * any other song (one swapped in, or a stale id left in the settings) is sent as the file itself.
+ */
+export function withSongId(
+ extra: Record<string, unknown> | undefined,
+ song: { id: string; url: string } | undefined,
+ attached: string | undefined,
+ byId: boolean,
+): Record<string, unknown> | undefined {
+ const rest = { ...extra };
+ delete rest[SONG_ID_PARAM];
+ if (byId && song && attached && attached === song.url) rest[SONG_ID_PARAM] = song.id;
+ return Object.keys(rest).length ? rest : undefined;
+}
+
/** The section tags the editor offers, in song order. */
export const SECTION_TAGS = ["Intro", "Verse", "Pre-Chorus", "Chorus", "Post-Chorus", "Bridge", "Instrumental", "Solo", "Outro"] as const;
diff --git a/tests/lyrics.test.ts b/tests/lyrics.test.ts
index 659427e2..a01c0677 100644
--- a/tests/lyrics.test.ts
+++ b/tests/lyrics.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { insertTag, isInstrumental, lyricsOf, lyricsProblem, normalizeLyrics, parseLyrics, promptWithLyrics, songLength, structureOf, tagName } from "@/lib/lyrics";
+import { insertTag, isInstrumental, lyricsOf, lyricsProblem, normalizeLyrics, parseLyrics, promptWithLyrics, songFromRun, songLength, structureOf, tagName, withSongId } from "@/lib/lyrics";
import { durationLabel } from "@/lib/composer";
// nm10-music3: the lyrics editor's words and section tags, as every music model reads them.
@@ -72,3 +72,21 @@ describe("lyrics with section tags", () => {
expect(durationLabel(270)).toBe("4:30");
});
});
+
+describe("a song's Mureka id on Reuse", () => {
+ it("comes back as the attached song's id, out of the settings, with the lyrics in the editor", () => {
+ const r = songFromRun({ lyrics: "[Verse]\nmore", songId: "song_1", extend_type: "tail" }, "/api/files/a.mp3");
+ expect(r).toEqual({ extra: { extend_type: "tail" }, lyrics: "[Verse]\nmore", song: { id: "song_1", url: "/api/files/a.mp3" } });
+ expect(songFromRun({ songId: "song_1" }, undefined)).toEqual({ extra: undefined });
+ expect(songFromRun({ seed: 1 }, "/api/files/a.mp3")).toEqual({ extra: { seed: 1 } });
+ });
+
+ it("goes with the song it names only: a song swapped in, or a stale id, is sent as the file", () => {
+ const song = { id: "song_1", url: "/api/files/a.mp3" };
+ expect(withSongId({ lyrics: "x" }, song, "/api/files/a.mp3", true)).toEqual({ lyrics: "x", songId: "song_1" });
+ expect(withSongId({ lyrics: "x", songId: "song_1" }, song, "/api/files/b.mp3", true)).toEqual({ lyrics: "x" });
+ expect(withSongId({ songId: "song_1" }, undefined, "/api/files/b.mp3", true)).toBeUndefined();
+ // A model that isn't Mureka's never gets one.
+ expect(withSongId({ lyrics: "x" }, song, "/api/files/a.mp3", false)).toEqual({ lyrics: "x" });
+ });
+});