Route the tracks of a song through a graph (#350)
Every track of a song went straight into its output. Now the Song tab has a second view, Routing: a graph with a node per track and one Output, the links between them sends. A track can go into other tracks, into several at once, and a link has its own volume and the point of the track it taps. - The song asset has a graph like an instrument (SongTrack, SongOutput). heldSongGraph keeps it in step with the tracks on load and in SetSongCommand: a node per track named after it, one output, a new track and every track of an old song linked to the output. Links of gone tracks, doubled links and links closing a loop are dropped. - A link carries an optional send (volume in dB, tap). The inspector shows Volume and Mode for a picked link of a song: Post volume (Post pan), Pre volume (Post FX), Pre volume (Pre FX). SetSendCommand. - NodeDef has two new flags. `fixed` nodes are never added or deleted by hand. Links between `acyclic` nodes may not close a loop, checked in canConnect, dropTargetPort and ConnectCommand. - songBuses gives each track its sends instead of one `into`, and a bus `song:<song>:<track>:#items` for its own items. That bus is what solo closes on a track that only passes a soloed one on. - Mute and solo now act on the sends (trackGates). A muted track passes nothing on, on any tap. A soloed track is heard with what goes into it, through the tracks it goes through, their own items silent. Only sends on a way through a soloed track stay open, so a track going into it and into the output is heard through it only. - SoundLibrary: a bus has either `into` or sends. Each send is tap, delay, level, target. busLatency takes the latest way (arrivalOf), and each send is held back so all ways of a track arrive together (sendDelays). Taps are wired again whenever a chain comes or goes. - The Song tab has Timeline and Routing in its header. The routing uses GraphCanvas with an empty palette. A track linked nowhere shows "Goes nowhere". Delete takes links, never a track node. - Game playings route the same way, the output being the master of the playing. Decided without asking: a send ranges -60 to +12 dB like a track, default 0 dB Post. Mute closes the sends, the track's own level stays. Found on the way: the inspector built the Mode row with the send as it was when the rows were made. Setting Volume and then Mode wrote the old volume back. Both rows now read the current send when they change. Tests: - Unit song-routing (new): 13 green. Sound library: 4 new, 94 green. 11 counter-probes (loop on load, canConnect, solo, solo past the soloed track, mute, preFx latency, graph sync, delete guard, delays, taps, glide), each red. - Existing tests adjusted to the new bus names and send shape: song, bus-fx, song-play, graph registry, edge description. - e2e 65 on melektaus-atx: ALL PASSED, 43 checks (5 new). The first run caught the inspector bug. Counter-probe with the old closure: 2 FAILED. - Gate on melektaus-atx: typecheck, lint, format clean, 2 tests red (registry rule, edge shape), fixed and rerun locally: 56 green. - Not rerun after the per-send solo fix: e2e 65 and the gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a52f2290f
commit
daeffe0f9d
30 files changed
+1323
-104
No files matched your search
@@ -12,6 +12,7 @@ import type {
|
||||
} from '../model/Asset';
|
||||
import type { AssetType } from '../model/AssetTypes';
|
||||
import { defaultTracks } from '../music/song';
|
||||
import { heldSongGraph } from '../music/routing';
|
||||
import { linearCurve } from '../model/curve';
|
||||
import { isFontFile } from '../model/font';
|
||||
import { DEFAULT_PALETTE, PIXEL_CANVAS_DEFAULT } from '../model/pixelart';
|
||||
@@ -109,8 +110,10 @@ export function buildAsset(type: AssetType, name: string, id = newId()): Asset {
|
||||
return { ...base, type: 'instrument', graph: starterInstrumentGraph() };
|
||||
case 'pattern':
|
||||
return { ...base, type: 'pattern', notes: [] };
|
||||
case 'song':
|
||||
return { ...base, type: 'song', tracks: defaultTracks(), items: [] };
|
||||
case 'song': {
|
||||
const tracks = defaultTracks();
|
||||
return { ...base, type: 'song', tracks, items: [], graph: heldSongGraph(undefined, tracks) };
|
||||
}
|
||||
case 'bus':
|
||||
return { ...base, type: 'bus' };
|
||||
case 'particles':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { edgesInto, edgesOfNode, findNode, type Graph, type GraphEdge, type GraphNode } from '../graph/Graph';
|
||||
import { closesLoop } from '../graph/dropTarget';
|
||||
import type { GraphLookup } from '../graph/lookup';
|
||||
import { isTerminalType, resolveDef, terminalNode } from '../graph/nested';
|
||||
import { nextTransitionName, parallelTransitions } from '../graph/stateMachine';
|
||||
@@ -50,7 +51,8 @@ export class AddNodeCommand implements Command {
|
||||
}
|
||||
|
||||
execute(project: Project): void {
|
||||
requireNodeDef(this.node.type);
|
||||
const def = requireNodeDef(this.node.type);
|
||||
if (def.fixed) throw new CommandError(`A ${def.label} node comes and goes on its own`);
|
||||
const graph = requireGraph(project, this.assetId);
|
||||
// The two terminals give the behavior its signature; a second one of either would make
|
||||
// "which ports does this behavior have" ambiguous.
|
||||
@@ -79,6 +81,8 @@ export class RemoveNodeCommand implements Command {
|
||||
|
||||
execute(project: Project): void {
|
||||
const graph = requireGraph(project, this.assetId);
|
||||
const def = nodeDef(findNode(graph, this.nodeId)?.type ?? '');
|
||||
if (def?.fixed) throw new CommandError(`A ${def.label} node comes and goes on its own`);
|
||||
const node = removeFirst(graph.nodes, (n) => n.id === this.nodeId);
|
||||
if (!node) throw new CommandError(`Node ${this.nodeId} not found`);
|
||||
// `edgesOfNode` reads the edge list only, so it still finds them after the node is gone.
|
||||
@@ -214,6 +218,8 @@ export class ConnectCommand implements Command {
|
||||
const inp = toDef?.inputs.find((p) => p.key === this.edge.to.port);
|
||||
if (!out || !inp) throw new CommandError('Port not found');
|
||||
if (!portsMeet(out, inp)) throw new CommandError(`Cannot connect ${out.type} to ${inp.type}`);
|
||||
if (closesLoop(graph, this.edge.from.node, this.edge.to.node, lookup))
|
||||
throw new CommandError('That link would lead round in a loop');
|
||||
if (graph.edges.some((e) => sameEnds(e, this.edge))) {
|
||||
// Transitions are told apart by name, so a further one between the same states gets its own.
|
||||
if (fromDef?.transitionEdges !== true || toDef?.transitionEdges !== true)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/**
|
||||
* Editing a song (#334). As with the notes of a pattern, one gesture is one command: the tracks or
|
||||
* items are written whole once the pointer lets go, so an undo takes the drag back. What is written
|
||||
* is held to the rules of a track and an item first; an item whose track goes goes with it.
|
||||
* is held to the rules of a track and an item first; an item whose track goes goes with it, and the
|
||||
* routing follows the tracks (#350).
|
||||
*/
|
||||
import type { EdgeSend, Graph } from '../graph/Graph';
|
||||
import type { SongAsset } from '../model/Asset';
|
||||
import type { Project } from '../model/Project';
|
||||
import { heldSend, heldSongGraph } from '../music/routing';
|
||||
import { heldSongItems, heldSongTracks, type SongItem, type SongTrack } from '../music/song';
|
||||
import { heldLoop, type LoopRange } from '../music/sequence';
|
||||
import type { Command } from './Command';
|
||||
import { requireSong } from './require';
|
||||
import { requireEdge, requireSong } from './require';
|
||||
|
||||
export interface SongParts {
|
||||
tracks?: readonly SongTrack[];
|
||||
@@ -16,7 +19,7 @@ export interface SongParts {
|
||||
}
|
||||
|
||||
export class SetSongCommand implements Command {
|
||||
private previous: { tracks: SongTrack[]; items: SongItem[] } | null = null;
|
||||
private previous: { tracks: SongTrack[]; items: SongItem[]; graph: Graph } | null = null;
|
||||
|
||||
constructor(
|
||||
private readonly assetId: string,
|
||||
@@ -33,9 +36,10 @@ export class SetSongCommand implements Command {
|
||||
|
||||
execute(project: Project): void {
|
||||
const asset = requireSong(project, this.assetId);
|
||||
this.previous = { tracks: asset.tracks, items: asset.items };
|
||||
this.previous = { tracks: asset.tracks, items: asset.items, graph: asset.graph };
|
||||
asset.tracks = heldSongTracks(this.parts.tracks ?? asset.tracks);
|
||||
asset.items = heldSongItems(this.parts.items ?? asset.items, asset.tracks);
|
||||
asset.graph = heldSongGraph(asset.graph, asset.tracks);
|
||||
}
|
||||
|
||||
undo(project: Project): void {
|
||||
@@ -43,6 +47,34 @@ export class SetSongCommand implements Command {
|
||||
const asset = requireSong(project, this.assetId);
|
||||
asset.tracks = this.previous.tracks;
|
||||
asset.items = this.previous.items;
|
||||
asset.graph = this.previous.graph;
|
||||
}
|
||||
}
|
||||
|
||||
/** How loud a link of a song's routing sends, and where it taps its track (#350). */
|
||||
export class SetSendCommand implements Command {
|
||||
readonly label = 'Set send';
|
||||
private previous: EdgeSend | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly assetId: string,
|
||||
private readonly edgeId: string,
|
||||
private readonly send: EdgeSend,
|
||||
) {}
|
||||
|
||||
execute(project: Project): void {
|
||||
requireSong(project, this.assetId);
|
||||
const edge = requireEdge(project, this.assetId, this.edgeId);
|
||||
this.previous = edge.send;
|
||||
const held = heldSend(this.send);
|
||||
if (held) edge.send = held;
|
||||
else delete edge.send;
|
||||
}
|
||||
|
||||
undo(project: Project): void {
|
||||
const edge = requireEdge(project, this.assetId, this.edgeId);
|
||||
if (this.previous) edge.send = this.previous;
|
||||
else delete edge.send;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user