Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add music folders and continuous playback

Bitti37f15c341c19
diff --git a/README.md b/README.md
index c506a1c..3de615f 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ Slopus combines an AI assistant, local image, video and music generation, reusab
- **Agent.** Plan scenes, generate media, inspect frames and edit projects with Claude Code, Codex, OpenRouter or a local OpenAI-compatible model. Toggle the pane with Ctrl+Shift+A.
- **Video.** Generate Prompt, First & last frame and other [scene types](docs/scene-types.md), with shot timing, dialogue, camera and sound controls. Keep up to four takes and an editable Draft; use **Make Primary** to choose the timeline video.
- **Images.** Generate with MiniMax H3, MOSS Image or Fibo 2.0. Use whole-image, box, lasso and Zoom edits where supported, with drafts and versions in the image bar.
-- **Music.** Generate songs with YuE2 or MiniMax Music3, edit lyrics and style, browse grid or list views, and play, reference or add songs to the timeline.
+- **Music.** Generate with YuE2 or MiniMax Music3, edit lyrics and style, organize songs in folders, browse grid/list views, and play songs in sequence or reuse them as references and timeline audio.
- **References.** Reuse descriptions, images, trimmed video clips and [H3 RefMods](docs/refmods.md) across scenes.
- **Generators.** Manage model weights, supported LoRAs, attention and generation effects. Share [generator templates](docs/generator-weights.md#sharing-generator-templates) as `.slop` bundles or run jobs on LAN workers.
- **Timeline.** Arrange video and audio with trimming, splitting, snapping, waveforms, transitions, chroma key and GPU effects.
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 7e2e551..d212ae7 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -4,7 +4,7 @@ Changes since 0.3.2.
## What's new
-- **Music.** Generate with YuE2 or MiniMax Music3, browse grid/list views, play songs, and create references or timeline audio. YuE2 selects BF16 above 8 GiB VRAM, otherwise INT8.
+- **Music.** YuE2 and MiniMax Music3 generation with folders, drag-and-drop organization, grid/list views, continuous playback, references and timeline audio. YuE2 selects BF16 above 8 GiB VRAM, otherwise INT8.
- **Motions.** Create JavaScript animations with the agent, edit elements and parameters, and export them on the timeline or as reference videos.
- **Scene history.** Keep up to four takes and an editable Draft, restore take settings, choose the primary timeline video, and duplicate scenes.
- **Agent frame inspection.** Agents can view timeline frames, scenes, takes, references, generated images and Motions at a requested time.
diff --git a/src-tauri/src/project/model.rs b/src-tauri/src/project/model.rs
index c610c36..a3c1e64 100644
--- a/src-tauri/src/project/model.rs
+++ b/src-tauri/src/project/model.rs
@@ -20,6 +20,8 @@ pub(crate) enum GenerationType {
pub(crate) struct ProjectConfig {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) music_songs: Vec<super::music::MusicSong>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub(crate) music_folders: Vec<super::music::MusicFolder>,
pub(crate) schema_version: u32,
#[serde(default)]
pub(crate) generation_type: GenerationType,
diff --git a/src-tauri/src/project/music.rs b/src-tauri/src/project/music.rs
index 2d0e459..4b7e7f3 100644
--- a/src-tauri/src/project/music.rs
+++ b/src-tauri/src/project/music.rs
@@ -6,6 +6,8 @@ use slopus_core::slopfab::music::MusicSettings;
pub(crate) struct MusicSong {
pub id: String,
pub title: String,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub folder_id: Option<String>,
#[serde(default)] pub style: String,
pub generator_id: String,
pub settings: MusicSettings,
@@ -17,9 +19,32 @@ pub(crate) struct MusicSong {
pub created_at: String,
}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct MusicFolder {
+ pub id: String,
+ pub name: String,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub parent_id: Option<String>,
+}
+
pub(crate) fn validate(config: &super::ProjectConfig) -> Result<(), String> {
+ let mut folders = std::collections::HashMap::new();
+ for folder in &config.music_folders {
+ if folder.id.is_empty() || folder.name.trim().is_empty() || folder.name.chars().count() > 200
+ || folders.insert(folder.id.as_str(), folder).is_some() { return Err("Invalid music folder.".into()); }
+ }
+ for folder in &config.music_folders {
+ let mut visited = std::collections::HashSet::from([folder.id.as_str()]);
+ let mut parent = folder.parent_id.as_deref();
+ while let Some(id) = parent {
+ if !visited.insert(id) { return Err("Music folders cannot contain a cycle.".into()); }
+ parent = folders.get(id).ok_or("Music folder parent does not exist.")?.parent_id.as_deref();
+ }
+ }
let mut ids = std::collections::HashSet::new();
for song in &config.music_songs {
+ if song.folder_id.as_deref().is_some_and(|id| !folders.contains_key(id)) { return Err("Song folder does not exist.".into()); }
if song.id.is_empty() || !ids.insert(&song.id) || song.title.trim().is_empty() || song.title.chars().count() > 200
|| song.style.chars().count() > 10000 || !(2..=100).contains(&song.steps) || song.seed < -1
|| !matches!(song.status.as_str(), "draft" | "queued" | "generating" | "completed" | "failed" | "cancelled") {
diff --git a/src-tauri/src/tests/schema.rs b/src-tauri/src/tests/schema.rs
index 48dc651..ef2e95e 100644
--- a/src-tauri/src/tests/schema.rs
+++ b/src-tauri/src/tests/schema.rs
@@ -3,18 +3,28 @@ use super::*;
#[test]
fn music_settings_survive_project_validation_and_reopen() {
let mut config = created_fixture();
+ config.music_folders = serde_json::from_value(serde_json::json!([
+ { "id": "jazz", "name": "Jazz" }, { "id": "piano", "name": "Piano", "parentId": "jazz" }
+ ])).unwrap();
config.music_songs.push(serde_json::from_value(serde_json::json!({
"id": "song-1", "title": "Evening", "style": "Quiet jazz", "generatorId": "yue2",
"settings": { "lyrics": "[Verse]\nHome again", "duration": 30 }, "steps": 32, "seed": -1,
- "status": "draft", "createdAt": "2026-10-25T00:00:00Z"
+ "status": "draft", "folderId": "piano", "createdAt": "2026-10-25T00:00:00Z"
})).unwrap());
let saved = validate_and_normalize_config(config).unwrap();
let reopened: ProjectConfig = serde_json::from_slice(&serde_json::to_vec(&saved).unwrap()).unwrap();
assert_eq!(reopened.music_songs, saved.music_songs);
+ assert_eq!(reopened.music_folders, saved.music_folders);
assert_eq!(reopened.music_songs[0].settings.lyrics, "[Verse]\nHome again");
let mut invalid = reopened;
invalid.music_songs[0].steps = 1000;
assert!(validate_and_normalize_config(invalid).is_err());
+ let mut cycle = saved.clone();
+ cycle.music_folders[0].parent_id = Some("piano".into());
+ assert!(validate_and_normalize_config(cycle).is_err());
+ let mut missing = saved;
+ missing.music_songs[0].folder_id = Some("missing".into());
+ assert!(validate_and_normalize_config(missing).is_err());
}
#[test]
diff --git a/src/components/workspace/MusicView.test.tsx b/src/components/workspace/MusicView.test.tsx
index 37b9631..ca94e53 100644
--- a/src/components/workspace/MusicView.test.tsx
+++ b/src/components/workspace/MusicView.test.tsx
@@ -5,7 +5,7 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-li
import { useState } from "react";
import { MusicView } from "./MusicView";
import { createProjectConfig, type ProjectConfig } from "../../lib/project";
-import { newSong } from "../../lib/music";
+import { newMusicFolder, newSong } from "../../lib/music";
import { readMediaFileUrl } from "../../lib/persistence";
import { loadGeneratorTemplateSettings, musicTemplates, saveGeneratorTemplateSettings } from "../../lib/settings";
@@ -19,12 +19,74 @@ function Harness({ initial = createConfig() }: { initial?: ProjectConfig }) {
}
beforeEach(() => {
vi.clearAllMocks(); localStorage.clear();
+ vi.mocked(readMediaFileUrl).mockResolvedValue("blob:song");
const settings = loadGeneratorTemplateSettings();
saveGeneratorTemplateSettings({ ...settings, templates: settings.templates.map((template) => template.id === "yue2" ? { ...template, paths: { ...template.paths, transformer: "C:/weights/yue2.safetensors" }, sources: {} } : template) });
vi.spyOn(HTMLMediaElement.prototype, "pause").mockImplementation(() => {});
vi.spyOn(HTMLMediaElement.prototype, "play").mockResolvedValue();
vi.stubGlobal("URL", Object.assign(URL, { revokeObjectURL: vi.fn() }));
});
+
+it("creates songs in the browsed folder and moves them between folders by drag and drop", () => {
+ render(<Harness />);
+ const createFolder = (name: string) => {
+ fireEvent.click(screen.getByRole("button", { name: "New folder" }));
+ fireEvent.change(screen.getByLabelText("Folder name"), { target: { value: name } });
+ fireEvent.click(screen.getByRole("button", { name: "Create folder" }));
+ };
+ createFolder("Jazz");
+ fireEvent.click(screen.getAllByRole("button", { name: "New song" })[0]);
+ const jazz = latest.musicFolders![0];
+ expect(latest.musicSongs![0].folderId).toBe(jazz.id);
+ createFolder("Piano");
+ fireEvent.click(screen.getAllByRole("button", { name: "New song" })[0]);
+ const piano = latest.musicFolders![1], song = latest.musicSongs![1];
+ expect(piano.parentId).toBe(jazz.id);
+ expect(song.folderId).toBe(piano.id);
+ const data = new Map<string, string>();
+ const dataTransfer = { effectAllowed: "", dropEffect: "", types: ["application/x-slopus-music-song"],
+ setData: (type: string, value: string) => data.set(type, value), getData: (type: string) => data.get(type) ?? "" };
+ fireEvent.dragStart(screen.getByRole("listitem"), { dataTransfer });
+ const destination = within(screen.getByRole("navigation", { name: "Music folders" })).getByRole("button", { name: "Jazz" });
+ fireEvent.dragOver(destination, { dataTransfer });
+ expect(destination).toHaveAttribute("data-drop-target", "true");
+ fireEvent.drop(destination, { dataTransfer });
+ expect(latest.musicSongs![1].folderId).toBe(jazz.id);
+ expect(screen.getByText("This folder is empty")).toBeInTheDocument();
+ fireEvent.click(destination);
+ expect(screen.getAllByRole("listitem")).toHaveLength(2);
+ fireEvent.dragStart(screen.getAllByRole("listitem")[1], { dataTransfer });
+ fireEvent.drop(within(screen.getByRole("navigation", { name: "Music folders" })).getByRole("button", { name: "Your music" }), { dataTransfer });
+ expect(latest.musicSongs![1].folderId).toBeNull();
+});
+
+it("automatically plays the next generated song in the starting folder even after browsing elsewhere", async () => {
+ const jazz = newMusicFolder("Jazz", null), other = newMusicFolder("Other", null);
+ const songs = [
+ { ...newSong("yue2", 32, jazz.id), title: "First", assetId: "first" },
+ { ...newSong("yue2", 32, jazz.id), title: "Draft" },
+ { ...newSong("yue2", 32, jazz.id), title: "Second", assetId: "second" },
+ { ...newSong("yue2", 32, other.id), title: "Elsewhere", assetId: "other" },
+ ];
+ const assets = songs.flatMap((song) => song.assetId ? [{ id: song.assetId, kind: "audio" as const, name: song.title,
+ relativePath: `media/${song.assetId}.wav`, durationMs: 30000, mimeType: "audio/wav", createdAt: song.createdAt }] : []);
+ vi.mocked(readMediaFileUrl).mockImplementation(async (_, asset) => `blob:${asset.relativePath}`);
+ const { container } = render(<Harness initial={{ ...createConfig(), musicFolders: [jazz, other], musicSongs: songs, assets }} />);
+ const folders = within(screen.getByRole("navigation", { name: "Music folders" }));
+ fireEvent.click(folders.getByRole("button", { name: "Jazz" }));
+ fireEvent.click(screen.getByRole("button", { name: "Play First" }));
+ const audio = container.querySelector("audio")!;
+ await waitFor(() => expect(audio).toHaveAttribute("src", "blob:media/first.wav"));
+ fireEvent.canPlay(audio);
+ fireEvent.click(folders.getByRole("button", { name: "Other" }));
+ fireEvent.ended(audio);
+ await waitFor(() => expect(audio).toHaveAttribute("src", "blob:media/second.wav"));
+ fireEvent.canPlay(audio);
+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(2);
+ fireEvent.ended(audio);
+ expect(readMediaFileUrl).toHaveBeenCalledTimes(2);
+ expect(screen.getByRole("button", { name: "Select Elsewhere" })).toBeInTheDocument();
+});
afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
it("adds songs, edits lyrics and style, switches layout and queues the selected song", () => {
diff --git a/src/components/workspace/MusicView.tsx b/src/components/workspace/MusicView.tsx
index 41fed43..8e10a38 100644
--- a/src/components/workspace/MusicView.tsx
+++ b/src/components/workspace/MusicView.tsx
@@ -2,10 +2,10 @@ import { useEffect, useRef, useState } from "react";
import type { ProjectAsset, ProjectConfig } from "../../lib/project";
import { isTauri, readMediaFileUrl } from "../../lib/persistence";
import { loadGeneratorTemplateSettings, subscribeGeneratorTemplates, templateSupportsMusic, templateUsable, generatorPathFields, type GeneratorTemplate } from "../../lib/settings";
-import { musicSettingsForModel, newSong, songReference, updateSong, type MusicSettings, type MusicSong } from "../../lib/music";
+import { musicFolderLabel, musicSettingsForModel, moveSong, newMusicFolder, newSong, songReference, updateSong, type MusicSettings, type MusicSong } from "../../lib/music";
import { isWorkActive, type WorkItem } from "../../lib/workQueue";
import { ComboBox, PropRow, PropSection, Slider, Splitter, useContextMenu, usePaneSize } from "../ui";
-import { Add16, Audio16, GoToEnd16, GoToStart16, GridView16, ListView16, Pause16, Play16, References16, Speaker14, Sparkle16, Stop14 } from "../ui/icons";
+import { Add16, Audio16, FolderAdd16, FolderOpen16, GoToEnd16, GoToStart16, GridView16, ListView16, Pause16, Play16, References16, Speaker14, Sparkle16, Stop14 } from "../ui/icons";
import { generatorOptions } from "../generatorOptions";
import { SliderNumberInput, GENERATION_STEPS_RANGE } from "./SliderNumberInput";
import type { ConfigUpdate } from "./TimelineView";
@@ -13,6 +13,7 @@ import { GeneratorSelector } from "./GeneratorSelector";
import { ProjectStatus } from "./ProjectStatus";
const time = (seconds: number) => `${Math.floor(seconds / 60)}:${Math.floor(seconds % 60).toString().padStart(2, "0")}`;
+const SONG_DRAG_TYPE = "application/x-slopus-music-song";
export function MusicView({ config, folderPath, onChange, onGenerate, onCancel, workItems, openSong, onSongOpened }: {
openSong?: { id: string }; onSongOpened?: () => void;
@@ -22,9 +23,17 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
}) {
const [templates, setTemplates] = useState(() => loadGeneratorTemplateSettings().templates.filter(templateSupportsMusic));
useEffect(() => subscribeGeneratorTemplates(() => setTemplates(loadGeneratorTemplateSettings().templates.filter(templateSupportsMusic))), []);
+ const folders = config.musicFolders ?? [];
+ const [folderId, setFolderId] = useState<string | null>(null);
+ const currentFolder = folders.find((folder) => folder.id === folderId);
+ const currentFolderId = currentFolder?.id ?? null;
+ const visibleSongs = (config.musicSongs ?? []).filter((song) => (song.folderId ?? null) === currentFolderId);
+ const [creatingFolder, setCreatingFolder] = useState(false);
+ const [folderName, setFolderName] = useState("");
+ const [dropFolder, setDropFolder] = useState<string>();
const [selectedId, setSelectedId] = useState(config.musicSongs?.[0]?.id);
- useEffect(() => { if (openSong) { setSelectedId(openSong.id); onSongOpened?.(); } }, [openSong]);
- const selected = (config.musicSongs ?? []).find((song) => song.id === selectedId) ?? config.musicSongs?.[0];
+ useEffect(() => { if (openSong) { setFolderId(config.musicSongs?.find((song) => song.id === openSong.id)?.folderId ?? null); setSelectedId(openSong.id); onSongOpened?.(); } }, [openSong]);
+ const selected = visibleSongs.find((song) => song.id === selectedId) ?? visibleSongs[0];
const [newGeneratorId, setNewGeneratorId] = useState(templates[0]?.id ?? "");
const template = templates.find((item) => item.id === (selected?.generatorId ?? newGeneratorId)) ?? templates[0];
const [view, setView] = useState<"grid" | "list">(() => localStorage.getItem("slopus.music.view") === "list" ? "list" : "grid");
@@ -45,10 +54,26 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
};
const setting = (patch: Partial<MusicSettings>) => { if (selected) edit({ settings: { ...selected.settings, ...patch } }); };
const add = () => {
- const song = newSong(template?.id, Math.min(100, template?.defaultSteps ?? 32));
+ const song = newSong(template?.id, Math.min(100, template?.defaultSteps ?? 32), currentFolderId);
onChange((current) => ({ ...current, musicSongs: [...(current.musicSongs ?? []), song] }));
setSelectedId(song.id); setError(null);
};
+ const createFolder = (event: React.FormEvent) => {
+ event.preventDefault();
+ try {
+ const folder = newMusicFolder(folderName, currentFolderId);
+ onChange((current) => ({ ...current, musicFolders: [...(current.musicFolders ?? []), folder] }));
+ setFolderName(""); setCreatingFolder(false); setFolderId(folder.id); setError(null);
+ } catch { setError("Enter a folder name of 1 to 200 characters."); }
+ };
+ const dropSong = (event: React.DragEvent, destination: string | null) => {
+ event.preventDefault(); setDropFolder(undefined);
+ try {
+ const data = JSON.parse(event.dataTransfer.getData(SONG_DRAG_TYPE));
+ if (data.projectId !== config.id || !config.musicSongs?.some((song) => song.id === data.songId)) return;
+ onChange((current) => moveSong(current, data.songId, destination));
+ } catch { /* Ignore unrelated or malformed drag data. */ }
+ };
const chooseGenerator = (id: string) => {
const next = templates.find((item) => item.id === id);
setNewGeneratorId(id);
@@ -62,6 +87,7 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
const audio = useRef<HTMLAudioElement>(null);
const [playerId, setPlayerId] = useState<string | null>(null);
+ const [playlist, setPlaylist] = useState<string[]>([]);
const playerAsset = config.assets.find((asset) => asset.id === playerId);
const [url, setUrl] = useState<string | null>(null);
const [playing, setPlaying] = useState(false);
@@ -70,10 +96,16 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
const [volume, setVolume] = useState(0.8);
const playWhenReady = useRef(false);
const [playbackError, setPlaybackError] = useState<string | null>(null);
- const playable = (config.musicSongs ?? []).flatMap((song) => {
+ const visiblePlayable = visibleSongs.flatMap((song) => {
const asset = config.assets.find((item) => item.id === song.assetId && item.kind === "audio" && item.relativePath);
return asset ? [{ song, asset }] : [];
});
+ // Capture the folder's order when playback starts. Browsing other folders
+ // does not change what plays next; drafts and unavailable assets are skipped.
+ const playable = playlist.length ? playlist.flatMap((id) => {
+ const asset = config.assets.find((item) => item.id === id && item.kind === "audio" && item.relativePath);
+ return asset ? [{ asset }] : [];
+ }) : visiblePlayable;
useEffect(() => {
let disposed = false, owned: string | null = null;
audio.current?.pause(); setPlaying(false); setPosition(0); setLength(0); setUrl(null); setPlaybackError(null);
@@ -93,15 +125,20 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
if (asset.id === playerId && url) void play();
else { playWhenReady.current = true; setPlayerId(asset.id); }
};
+ const startSong = (asset: ProjectAsset) => {
+ setPlaylist(visiblePlayable.map((item) => item.asset.id));
+ playAsset(asset);
+ };
const move = (direction: number) => {
if (!playable.length) return;
+ if (!playlist.length) setPlaylist(visiblePlayable.map((item) => item.asset.id));
const index = playable.findIndex(({ asset }) => asset.id === playerId);
playAsset(playable[(Math.max(0, index) + direction + playable.length) % playable.length].asset);
};
const toggle = () => {
if (playing) { audio.current?.pause(); return; }
- const asset = playerAsset ?? playable.find(({ song }) => song.id === selected?.id)?.asset ?? playable[0]?.asset;
- if (asset) playAsset(asset);
+ const asset = playerAsset ?? visiblePlayable.find(({ song }) => song.id === selected?.id)?.asset ?? visiblePlayable[0]?.asset;
+ if (asset) { if (playerAsset) playAsset(asset); else startSong(asset); }
};
const context = (event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>, song: MusicSong) => {
const asset = config.assets.find((item) => item.id === song.assetId);
@@ -122,6 +159,7 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
options={generatorOptions(templates, (item) => ({ disabled: !templateReady(item), description: !templateReady(item) ? "Download in Settings" : undefined }))}
onChange={chooseGenerator} />
<button type="button" className="secondary-button" onClick={add}><Add16 />New song</button>
+ <button type="button" className="secondary-button" onClick={() => { setCreatingFolder(true); setFolderName(""); }}><FolderAdd16 />New folder</button>
<div className="music-toolbar__views" role="group" aria-label="Song view">
{(["grid", "list"] as const).map((mode) => <button type="button" className="icon-button" key={mode} aria-label={`${mode === "grid" ? "Grid" : "List"} view`} aria-pressed={view === mode}
onClick={() => { setView(mode); localStorage.setItem("slopus.music.view", mode); }}>{mode === "grid" ? <GridView16 /> : <ListView16 />}</button>)}
@@ -129,24 +167,37 @@ export function MusicView({ config, folderPath, onChange, onGenerate, onCancel,
</div>
<div className="music-body">
<div className="music-library">
- <div className="music-library__heading"><h2>Your music</h2><span>{(config.musicSongs?.length ?? 0)} songs</span></div>
+ <div className="music-library__heading"><h2>{currentFolder?.name ?? "Your music"}</h2><span>{visibleSongs.length} songs</span></div>
+ <nav className="music-folders" aria-label="Music folders">
+ {[{ id: null, name: "Your music" }, ...folders.map((folder) => ({ id: folder.id, name: musicFolderLabel(folders, folder.id) }))].map((folder) =>
+ <button key={folder.id ?? "root"} type="button" className="secondary-button" aria-current={currentFolderId === folder.id ? "page" : undefined}
+ data-drop-target={dropFolder === (folder.id ?? "") ? "true" : undefined} onClick={() => { setFolderId(folder.id); setSelectedId(undefined); setNotice(null); }}
+ onDragOver={(event) => { if (event.dataTransfer.types.includes(SONG_DRAG_TYPE)) { event.preventDefault(); event.dataTransfer.dropEffect = "move"; setDropFolder(folder.id ?? ""); } }}
+ onDragLeave={() => setDropFolder(undefined)} onDrop={(event) => dropSong(event, folder.id)} data-tooltip={folder.name}><FolderOpen16 /><span>{folder.name}</span></button>)}
+ </nav>
+ {creatingFolder && <form className="music-new-folder" onSubmit={createFolder}>
+ <input className="text-field" aria-label="Folder name" placeholder="Folder name" autoFocus maxLength={200} value={folderName} onChange={(event) => setFolderName(event.target.value)} />
+ <button type="submit" className="primary-button" disabled={!folderName.trim()}>Create folder</button>
+ <button type="button" className="secondary-button" onClick={() => setCreatingFolder(false)}>Cancel</button>
+ </form>}
{notice && <p role="status">{notice}</p>}
{error && <p role="alert">{error}</p>}
- {!(config.musicSongs?.length ?? 0) ? <div className="music-empty"><Audio16 /><h3>Create your first song</h3><p>Add a song, describe its style and write lyrics, or leave lyrics empty for an instrumental.</p><button type="button" className="primary-button" onClick={add}><Add16 />New song</button></div> :
+ {!visibleSongs.length ? <div className="music-empty"><Audio16 /><h3>{currentFolder ? "This folder is empty" : "Create your first song"}</h3><p>Add a song, describe its style and write lyrics, or leave lyrics empty for an instrumental.</p><button type="button" className="primary-button" onClick={add}><Add16 />New song</button></div> :
<div className={`music-songs music-songs--${view}`} role="list" aria-label="Songs">
- {(config.musicSongs ?? []).map((song, index) => {
+ {visibleSongs.map((song, index) => {
const asset = config.assets.find((item) => item.id === song.assetId);
const work = workItems.find((item) => item.sceneId === song.id && isWorkActive(item));
return <div className={`music-song${selected?.id === song.id ? " music-song--selected" : ""}`} role="listitem" key={song.id}
+ draggable onDragStart={(event) => { event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData(SONG_DRAG_TYPE, JSON.stringify({ projectId: config.id, songId: song.id })); }} onDragEnd={() => setDropFolder(undefined)}
onContextMenu={(event) => context(event, song)}>
<button type="button" className="music-song__select" aria-label={`Select ${song.title}`} aria-pressed={selected?.id === song.id}
- onClick={() => setSelectedId(song.id)} onDoubleClick={() => { if (asset) playAsset(asset); }}
+ onClick={() => setSelectedId(song.id)} onDoubleClick={() => { if (asset) startSong(asset); }}
onKeyDown={(event) => { if (event.key === "ContextMenu" || event.shiftKey && event.key === "F10") context(event, song); }}>
<span className="music-song__art" aria-hidden="true"><Audio16 /><span>{String(index + 1).padStart(2, "0")}</span></span>
<span className="music-song__info"><strong>{song.title}</strong><span>{song.style || "Add a style to get started"}</span></span>
<span className="music-song__status">{work ? `${work.detail} · ${Math.round(work.progress * 100)}%` : song.status === "completed" && asset ? time((asset.durationMs ?? 0) / 1000) : song.status}</span>
</button>
- <button type="button" className="icon-button music-song__play" aria-label={`Play ${song.title}`} disabled={!asset?.relativePath} onClick={() => asset && playAsset(asset)}><Play16 /></button>
+ <button type="button" className="icon-button music-song__play" aria-label={`Play ${song.title}`} disabled={!asset?.relativePath} onClick={() => asset && startSong(asset)}><Play16 /></button>
</div>;
})}
</div>}
diff --git a/src/lib/music.test.ts b/src/lib/music.test.ts
index db7c79d..ae8d309 100644
--- a/src/lib/music.test.ts
+++ b/src/lib/music.test.ts
@@ -1,8 +1,20 @@
import { describe, expect, it } from "vitest";
import { createProjectConfig, parseProjectConfig, type ProjectAsset } from "./project";
-import { musicSettingsForModel, musicSettingsSchema, newSong, songReference } from "./music";
+import { moveSong, musicFolderLabel, musicSettingsForModel, musicSettingsSchema, newMusicFolder, newSong, songReference } from "./music";
describe("music projects", () => {
+ it("persists folders and song moves without moving or rewriting generated audio", () => {
+ const parent = newMusicFolder("Jazz", null), child = newMusicFolder("Piano", parent.id);
+ const song = { ...newSong("yue2", 32, parent.id), assetId: "audio-1" };
+ const config = { ...createProjectConfig({ name: "Music", prompt: "", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 }), musicFolders: [parent, child], musicSongs: [song] };
+ const moved = moveSong(config, song.id, child.id);
+ const saved = parseProjectConfig(JSON.parse(JSON.stringify(moved)));
+ expect(saved.musicFolders).toEqual([parent, child]);
+ expect(saved.musicSongs![0]).toMatchObject({ folderId: child.id, assetId: "audio-1" });
+ expect(musicFolderLabel(saved.musicFolders!, child.id)).toBe("Jazz / Piano");
+ expect(moveSong(saved, song.id, "missing")).toBe(saved);
+ expect(moveSong(saved, song.id, null).musicSongs![0].folderId).toBeNull();
+ });
it("round-trips songs and preserves older projects without songs", () => {
const config = createProjectConfig({ name: "Music", prompt: "", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 });
expect(parseProjectConfig(JSON.parse(JSON.stringify(config))).musicSongs).toBeUndefined();
diff --git a/src/lib/music.ts b/src/lib/music.ts
index 3a8ee2f..3f97f15 100644
--- a/src/lib/music.ts
+++ b/src/lib/music.ts
@@ -17,6 +17,7 @@ export const musicSettingsSchema = z.object({
.refine((value) => value.planning !== "off" || !value.abc, "ABC requires full or melody planning.");
export const musicSongSchema = z.object({
id: z.string().min(1), title: z.string().min(1).max(200),
+ folderId: z.string().min(1).nullish(),
style: z.string().max(10000).default(""),
generatorId: z.string().default("yue2"),
settings: musicSettingsSchema.default({}),
@@ -28,9 +29,30 @@ export const musicSongSchema = z.object({
});
export type MusicSong = z.infer<typeof musicSongSchema>;
export type MusicSettings = z.infer<typeof musicSettingsSchema>;
+export const musicFolderSchema = z.object({ id: z.string().min(1), name: z.string().trim().min(1).max(200), parentId: z.string().min(1).nullish() });
+export type MusicFolder = z.infer<typeof musicFolderSchema>;
-export function newSong(generatorId = "yue2", steps = 32): MusicSong {
- return musicSongSchema.parse({ id: `song-${crypto.randomUUID()}`, title: "New song", generatorId, steps, createdAt: new Date().toISOString() });
+export function newSong(generatorId = "yue2", steps = 32, folderId?: string | null): MusicSong {
+ return musicSongSchema.parse({ id: `song-${crypto.randomUUID()}`, title: "New song", generatorId, steps, ...(folderId ? { folderId } : {}), createdAt: new Date().toISOString() });
+}
+
+export function newMusicFolder(name: string, parentId: string | null): MusicFolder {
+ return musicFolderSchema.parse({ id: `music-folder-${crypto.randomUUID()}`, name, parentId });
+}
+
+export function moveSong(config: ProjectConfig, songId: string, folderId: string | null): ProjectConfig {
+ if (folderId && !config.musicFolders?.some((folder) => folder.id === folderId)) return config;
+ return updateSong(config, songId, { folderId });
+}
+
+export function musicFolderLabel(folders: readonly MusicFolder[], id: string): string {
+ const names: string[] = [], visited = new Set<string>();
+ let folder = folders.find((item) => item.id === id);
+ while (folder && !visited.has(folder.id)) {
+ visited.add(folder.id); names.unshift(folder.name);
+ folder = folders.find((item) => item.id === folder!.parentId);
+ }
+ return names.join(" / ");
}
export function musicSettingsForModel(settings: MusicSettings, modelType: string): MusicSettings {
diff --git a/src/lib/project.ts b/src/lib/project.ts
index 2fc25b8..01b8c20 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -3,7 +3,7 @@ import { generationEffectsSchema, activeGenerationEffects, type GenerationEffect
import { MIN_SIGMA_SHIFT, MAX_SIGMA_SHIFT } from "./sampling";
import { z } from "zod";
import { backdropDirection, backdropShotDirection, backdropSummary, type BackdropColor } from "./backdrop";
-import { musicSongSchema } from "./music";
+import { musicFolderSchema, musicSongSchema } from "./music";
import { createImageScene, imageSceneReferenceIds, imageSceneSchema } from "./imageScene";
import { effectEnabledSchema, effectSchemas, isEffectOn } from "./effectSettings";
import { normalizeShotTagSelection, shotTagClauses, SHOT_TAG_ID_PATTERN, type ShotTagClauses, type ShotTagSelection } from "./shot-tags";
@@ -695,6 +695,7 @@ export const projectConfigSchema = z.object({
generationType: generationTypeSchema.default("video"),
imageScene: imageSceneSchema.nullish(),
musicSongs: z.array(musicSongSchema).optional(),
+ musicFolders: z.array(musicFolderSchema).optional(),
imageSettings: z.object({
resolution: resolutionSchema,
aspectRatio: aspectRatioSchema,
diff --git a/src/styles/music.css b/src/styles/music.css
index da0f8b5..e259a97 100644
--- a/src/styles/music.css
+++ b/src/styles/music.css
@@ -1,12 +1,19 @@
.music-view { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; min-height: 0; min-width: 0; }
-.music-toolbar { display: flex; align-items: center; gap: var(--space-2); height: var(--command-row); padding: 0 var(--space-2); border-bottom: 1px solid var(--line); }
+.music-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-height: var(--command-row); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--line); }
.music-toolbar > .generator-runtime { flex: 0 1 auto; }
.music-toolbar__views { display: flex; gap: var(--space-1); margin-left: auto; }
.music-toolbar__views [aria-pressed="true"] { background: var(--fill-subtle-hover); color: var(--accent); }
.music-body { display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(280px, var(--pane-music-inspector)); min-height: 0; }
.music-library { min-width: 0; overflow: auto; padding: var(--space-4); }
.music-library__heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-4); }
-.music-library__heading h2 { margin: 0; font-size: var(--text-lg); }
+.music-library__heading h2 { margin: 0; font-size: var(--text-lg); min-width: 0; overflow-wrap: anywhere; }
+.music-folders { display: flex; flex-wrap: wrap; gap: var(--space-1); max-height: 128px; overflow-y: auto; margin-bottom: var(--space-3); }
+.music-folders > button { min-width: 0; max-width: 100%; }
+.music-folders > button > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.music-folders [aria-current="page"] { color: var(--accent); border-color: var(--accent); }
+.music-folders [data-drop-target="true"] { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--fill-subtle-hover); }
+.music-new-folder { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
+.music-new-folder input { flex: 1; min-width: 120px; }
.music-library__heading > span, .music-song__info > span, .music-song__status, .music-player__now span { color: var(--text-secondary); font-size: var(--text-xs); }
.music-songs { display: grid; gap: var(--space-3); }
.music-songs--grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }