Files
feuerwerk/tools/e2e/65-song.mjs
T
adminandClaude Opus 5.5 aa097bd076 Zoom with the wheel and set the loop on its own strip in music tabs
The ruler of the Pattern and Song tabs did two things with one drag,
and the wheel did three things with Alt and Shift. Both now do one
thing each, and the Song tab gets a few edits it was missing.

- The ruler has a loop strip along its top. A drag there sets the
  loop, a press or drag below it moves only where playing starts.
- The wheel only zooms: the time over the grid, lanes and ruler, the
  rows over the keys, the tracks over their heads. Alt and Shift no
  longer change it. A middle-drag still pans.
- Tracks can be zoomed from 28 to 160 px. Below 46 px a head shows
  only its name, M and S. An old saved view gets the old height.
- A click on nothing in the lanes picks the song itself.
- A right-click on an item opens a menu with Delete instead of
  deleting it. The inspector has no delete buttons any more.
- A sound item goes up to +12 dB, a track up to +12 dB. A pattern
  item stays at 0 dB, since a note is held to unity.
- An end of an item under the pointer lights up and shows a resize
  cursor. A long item marks every point where it starts over.
- The Pattern tab has an Audition switch in its header, off at first.
  Only with it on does a note sound when drawn, grabbed or moved.
  The keys down the left sound either way.
- A looped sound item draws every round alike. Each round is drawn
  from its own start, and each column shows the loudest part of the
  sound it covers instead of one sampled bucket.
- A song is at least one bar long instead of four. An empty song
  fits that bar across, and Play song ends after the last item.
- The ghost notes held back in #334 got their own issue, #339.

Finding: suite 542 for f97961c failed 5 game checks in e2e 64 and 65
while my runs on the same Windows machine overlapped it. Modules
60-65 alone without load passed, so this push's suite has to show it.

Tests:
- Unit: song-edit 11, piano-roll 17, song 14, sound-library 67.
  Four of them are new, one in song changed.
- e2e 64+65 on melektaus-atx: ALL PASSED - 46 checks (+3).
- e2e 60-65 on melektaus-atx: ALL PASSED - 86 checks.
- Gate on melektaus-atx: 251 files, 3907 tests, CHECK EXIT 0.
- Audition, after the gate: e2e 64 alone ALL PASSED - 25 checks
  (+1), transitions and piano-roll 30 tests, typecheck and ESLint
  clean.
- Waveform and one bar, after the gate: song, song-edit, song-play
  and the node catalog 438 tests. e2e 65 alone ALL PASSED - 25
  checks (+1). A probe shot of a looped pop sound: all six rounds
  pixel for pixel alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:25:49 +02:00

561 lines
23 KiB
JavaScript

import { edge, node } from '../lib/builders.mjs';
import { LANES, pickAssetType, scaffoldBehavior } from './lib/scaffold.mjs';
/**
* Songs and their tracks (#334). "+ → Song" opens the tab on four empty tracks. A pattern and a
* sound dragged in from the Assets panel land as items where the preview showed them; an item's
* right end lengthens it, its body moves it across tracks, its left end cuts it back, Ctrl+D puts a
* copy behind it, Ctrl+E splits it where playing starts, Delete or its menu takes it away. A click
* on nothing picks the song, an end under the pointer lights up, a long item marks its rounds, the
* wheel zooms tracks or time, the strip above the ruler sets the loop. A head mutes, solos and sets
* the volume of its track, "+ Track" adds one. Space plays the song through the scheduler:
* the pattern round and round at the song's tempo, the sound as a clip, each track on its own bus.
* A pattern started meanwhile takes over, and a double-click opens a pattern item in its tab.
* Nothing is heard in CI (muted browser): the witnesses are the model, the planned notes and clips
* and what the buses were set to, as in e2e 64.
*
* Everything it adds carries a `sg65` id or is the song it made, and goes again at the end.
*/
const BLIP_BYTES = 4044;
const BAR = 1920;
const PATTERN = 'sg65-pat';
const SOUND = 'sg65-snd';
export async function song(t) {
const {
check,
sleep,
json,
evaluate,
mutate,
mouse,
click,
clickText,
doubleClick,
press,
drag,
shot,
showTab,
play,
stop,
clickToolbar,
} = t;
const waitFor = async (read, done, tries = 25) => {
let value = await read();
for (let i = 0; i < tries && !done(value); i++) {
await sleep(150);
value = await read();
}
return value;
};
/** Drags a row of the Assets panel to a point step by step: the drop only exists while the button is down. */
const dragAsset = async (assetId, to) => {
const from = await json(`__gm.assetRow(${JSON.stringify(assetId)})`);
await mouse('mouseMoved', from.x, from.y);
await mouse('mousePressed', from.x, from.y);
for (let i = 1; i <= 8; i++) {
await mouse(
'mouseMoved',
from.x + ((to.x - from.x) * i) / 8,
from.y + ((to.y - from.y) * i) / 8,
'left',
{
buttons: 1,
},
);
await sleep(16);
}
const drop = (await json('__gm.song.view()')).drop;
await mouse('mouseReleased', to.x, to.y);
await sleep(200);
return drop;
};
await press('Escape');
await evaluate('__gm.state.select(null)');
await showTab('scene');
const stored = await evaluate(`fetch('/game-maker/api/index.php?r=sounds').then((r) => r.json())`);
const blip = stored.find((item) => item.bytes === BLIP_BYTES);
await mutate(`
__gm.state.project.assets.push(
{ id: ${JSON.stringify(SOUND)}, type: 'sound', name: 'Blip 65', props: {}, file: ${JSON.stringify(blip?.file ?? '')} },
{
id: 'sg65-ins',
type: 'instrument',
name: 'Lead 65',
props: {},
graph: {
nodes: ${JSON.stringify([
node('sg65-notes', 'InstrumentNotes', 0, 0, { from: 48, to: 84 }),
node('sg65-sample', 'InstrumentSample', 200, 0, { sound: SOUND }),
node('sg65-out', 'InstrumentOutput', 420, 0),
])},
edges: ${JSON.stringify([
edge('sg65-e1', 'sg65-notes', 'any', 'sg65-sample', 'trigger'),
edge('sg65-e2', 'sg65-sample', 'out', 'sg65-out', 'in'),
])},
},
},
{
id: ${JSON.stringify(PATTERN)},
type: 'pattern',
name: 'Riff 65',
props: { instrument: 'sg65-ins', bars: 1 },
notes: [
{ id: 'sg65-n1', tick: 0, length: 480, note: 60, velocity: 1 },
{ id: 'sg65-n2', tick: 960, length: 480, note: 64, velocity: 0.5 },
],
},
);`);
const seconds = await evaluate(`__gm.sound.load(${JSON.stringify(blip?.file ?? '')})`);
// 65a. "+ → Song" makes a song of four empty tracks and opens its tab.
await clickText('+');
await pickAssetType(t, 'Song');
const created = await json(`{
tab: __gm.tab(),
current: __gm.song.current(),
info: __gm.song.info(),
songs: __gm.state.project.assets.filter((a) => a.type === 'song').map((a) => ({ id: a.id, tracks: a.tracks.length })),
}`);
check(
'the + menu creates a song of four empty tracks and opens its tab',
created.tab === 'song' &&
created.songs.length === 1 &&
created.current === created.songs[0].id &&
created.songs[0].tracks === 4 &&
created.info === '4 tracks · 0 items',
JSON.stringify(created),
);
const id = created.songs[0]?.id;
const model = () => json(`__gm.song.model(${JSON.stringify(id)})`);
const tracks = (await model()).tracks.map((track) => track.id);
// 65b. An empty song is a bar long and fits it across; the wheel takes the view out to eight bars.
// A pattern dragged onto the second track lands on the bar before the pointer, a bar long.
const fitted = await json('__gm.song.view()');
const area = await json('__gm.song.rect()');
for (let i = 0; i < 30; i++) {
const far = await json(`__gm.song.laneAt(${8 * BAR}, 0)`);
if (far.x < area.x + area.w) break;
const near = await json(`__gm.song.laneAt(0, 0)`);
await t.wheel(near.x + 2, near.y, 200);
}
const zoomedOut = await json('__gm.song.view()');
check(
'an empty song fits a single bar across, and the wheel over the lanes takes the view out',
fitted.pxPerTick > zoomedOut.pxPerTick * 4,
JSON.stringify({ fitted, zoomedOut }),
);
const preview = await dragAsset(PATTERN, await json(`__gm.song.laneAt(${BAR + 400}, 1)`));
let items = (await model()).items;
const riff = items[0];
check(
'a pattern dragged in from the Assets panel shows where it lands and lands there, picked',
preview?.kind === 'pattern' &&
preview.track === tracks[1] &&
preview.tick === BAR &&
items.length === 1 &&
riff.kind === 'pattern' &&
riff.asset === PATTERN &&
riff.track === tracks[1] &&
riff.tick === BAR &&
riff.length === BAR &&
(await json('__gm.song.picked()')).join() === riff.id &&
(await json('__gm.state.selection?.kind')) === 'song',
JSON.stringify({ preview, items }),
);
// 65c. A sound dragged onto the first track is as long as it plays at 120 BPM.
await dragAsset(SOUND, await json('__gm.song.laneAt(300, 0)'));
items = (await model()).items;
const clip = items.find((item) => item.kind === 'sound');
const drawn = await waitFor(
() => json('__gm.song.items()'),
(list) => list.find((item) => item.id === clip?.id)?.content === 'wave',
);
check(
'a sound dropped on a track lasts as long as the sound at the tempo, and shows its waveform',
clip?.track === tracks[0] &&
clip.tick === 0 &&
clip.length === Math.max(1, Math.round(seconds * 960)) &&
drawn.find((item) => item.id === riff.id)?.content === 'notes' &&
drawn.find((item) => item.id === clip.id)?.label === 'Blip 65',
JSON.stringify({ seconds, clip, drawn }),
);
await shot('01-dropped');
// 65d. The pattern's right end takes it to three bars, its body to the third track a bar later.
let p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'end')`);
let to = await json(`__gm.song.laneAt(${4 * BAR}, 1)`);
await drag(p.x, p.y, to.x, to.y);
await sleep(200);
const lengthened = (await model()).items.find((item) => item.id === riff.id);
p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'body')`);
const { pxPerTick } = await json('__gm.song.view()');
to = await json(`__gm.song.laneAt(0, 2)`);
await drag(p.x, p.y, p.x + BAR * pxPerTick, to.y);
await sleep(200);
const movedRiff = (await model()).items.find((item) => item.id === riff.id);
check(
'its right end lengthens the pattern to three bars, its body takes it a bar on and a track down',
lengthened?.length === 3 * BAR && movedRiff?.tick === 2 * BAR && movedRiff.track === tracks[2],
JSON.stringify({ lengthened, movedRiff }),
);
// 65e. Its left end cuts a bar off the front: it then starts a bar into what it repeats.
p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'start')`);
to = await json(`__gm.song.laneAt(${3 * BAR}, 2)`);
await drag(p.x, p.y, to.x, to.y);
await sleep(200);
const trimmedRiff = (await model()).items.find((item) => item.id === riff.id);
check(
'its left end cuts the front off, and what it plays starts that far in',
trimmedRiff?.tick === 3 * BAR && trimmedRiff.length === 2 * BAR && trimmedRiff.offset === BAR,
JSON.stringify(trimmedRiff),
);
await press('z', { ctrl: true });
check(
'one undo takes the cut back',
JSON.stringify((await model()).items.find((item) => item.id === riff.id)) === JSON.stringify(movedRiff),
);
// 65f. Ctrl+D puts a copy right behind it; a click on the ruler and Ctrl+E split the copy there.
p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'body')`);
await click(p.x, p.y);
await press('d', { ctrl: true });
items = (await model()).items;
const copy = items.find((item) => item.id !== riff.id && item.kind === 'pattern');
check(
'Ctrl+D puts a copy right behind the item on its track, picked',
items.length === 3 &&
copy?.tick === 5 * BAR &&
copy.length === 3 * BAR &&
copy.track === tracks[2] &&
(await json('__gm.song.picked()')).join() === copy.id,
JSON.stringify(items),
);
p = await json('__gm.song.fitAt()');
await click(p.x, p.y);
p = await json(`__gm.song.rulerAt(${6 * BAR + 300})`);
await click(p.x, p.y);
await press('e', { ctrl: true });
items = (await model()).items;
const parts = items.filter((item) => item.tick >= 5 * BAR).sort((a, b) => a.tick - b.tick);
check(
'a click on the ruler sets where playing starts, and Ctrl+E splits the picked item there',
(await json('__gm.song.view()')).start === 6 * BAR &&
parts.length === 2 &&
parts[0].length === BAR &&
parts[1].tick === 6 * BAR &&
parts[1].length === 2 * BAR &&
parts[1].offset === BAR &&
(await json('__gm.song.picked()')).join() === parts[1].id,
JSON.stringify(parts),
);
await press('Delete');
p = await json(`__gm.song.itemAt(${JSON.stringify(parts[0].id)}, 'body')`);
await click(p.x, p.y, 'right');
await sleep(150);
const menuDelete = await json("__gm.locate('Delete', true)");
const beforeMenu = (await model()).items.length;
if (menuDelete) await click(menuDelete.x, menuDelete.y);
await sleep(150);
items = (await model()).items;
check(
'Delete takes an item away, and a right-click opens a menu whose "Delete" does',
beforeMenu === 3 &&
Boolean(menuDelete) &&
items.length === 2 &&
items.every((item) => item.id === riff.id || item.id === clip.id),
JSON.stringify({ beforeMenu, menuDelete, items }),
);
// 65f-ii. A click on nothing picks the song; a sound item turns up to +12 dB in the inspector, which
// has no delete button any more. An end of an item under the pointer shows it can be dragged,
// and an item longer than what it plays marks where it starts over.
p = await json('__gm.song.laneAt(300, 3)');
await click(p.x, p.y);
const emptyPick = await json('__gm.state.selection');
p = await json(`__gm.song.itemAt(${JSON.stringify(clip.id)}, 'body')`);
await click(p.x, p.y);
await sleep(150);
const volumeField = await json("__gm.inspectorField('Volume (dB)')");
await click(volumeField.x, volumeField.y);
await t.typeText('30');
await press('Enter');
await sleep(150);
const loud = (await model()).items.find((item) => item.id === clip.id);
const deleteButtons = await json("[__gm.locate('Delete item'), __gm.locate('Delete items')]");
p = await json(`__gm.song.itemAt(${JSON.stringify(clip.id)}, 'end')`);
await mouse('mouseMoved', p.x - 1, p.y);
await mouse('mouseMoved', p.x, p.y);
const onEnd = await json('__gm.song.view()');
p = await json(`__gm.song.itemAt(${JSON.stringify(clip.id)}, 'body')`);
await mouse('mouseMoved', p.x, p.y);
const onBody = await json('__gm.song.view()');
const seams = (await json('__gm.song.items()')).find((item) => item.id === riff.id)?.seams;
check(
'a click on nothing picks the song, a sound item goes to +12 dB, an end lights up under the pointer, and a long item marks its rounds',
emptyPick?.kind === 'asset' &&
emptyPick.assetId === id &&
loud?.volume === 12 &&
deleteButtons.every((b) => b === null) &&
onEnd.hover?.id === clip.id &&
onEnd.hover.part === 'end' &&
onEnd.cursor === 'ew-resize' &&
onBody.hover?.part === 'body' &&
onBody.cursor === 'default' &&
seams?.join() === [3 * BAR, 4 * BAR].join(),
JSON.stringify({ emptyPick, loud, deleteButtons, onEnd, onBody, seams }),
);
await shot('01b-hover');
// 65f-iii. The wheel zooms the tracks over their heads and the time over the lanes; a drag on the
// strip above the ruler sets the loop, Ctrl+Z takes it back.
const unzoomed = await json('__gm.song.view()');
p = await json("__gm.song.headAt(0, 'name')");
await t.wheel(p.x, p.y, -200);
const taller = await json('__gm.song.view()');
p = await json(`__gm.song.laneAt(${2 * BAR}, 0)`);
await t.wheel(p.x, p.y, -200);
const wider = await json('__gm.song.view()');
p = await json("__gm.song.headAt(0, 'name')");
await t.wheel(p.x, p.y, 200);
p = await json('__gm.song.fitAt()');
await click(p.x, p.y);
p = await json(`__gm.song.loopAt(${BAR})`);
to = await json(`__gm.song.loopAt(${3 * BAR})`);
await drag(p.x, p.y, to.x, to.y);
const songLoop = (await model()).loop;
await press('z', { ctrl: true });
check(
'the wheel zooms the tracks on their heads and the time on the lanes, and the strip above the ruler sets the loop',
taller.trackHeight > unzoomed.trackHeight &&
taller.pxPerTick === unzoomed.pxPerTick &&
wider.pxPerTick > taller.pxPerTick &&
wider.trackHeight === taller.trackHeight &&
songLoop?.start === BAR &&
songLoop.end === 3 * BAR &&
(await model()).loop === null,
JSON.stringify({ unzoomed, taller, wider, songLoop }),
);
// 65g. The heads: mute and solo toggle, the volume slider sets decibels, "+ Track" adds a track.
await click(...Object.values(await json("__gm.song.headAt(0, 'mute')")));
await click(...Object.values(await json("__gm.song.headAt(2, 'solo')")));
p = await json("__gm.song.headAt(2, 'volume', 0.5)");
to = await json("__gm.song.headAt(2, 'volume', 0)");
await drag(p.x, p.y, to.x + 1, to.y);
await sleep(150);
p = await json('__gm.song.addTrackAt()');
await click(p.x, p.y);
const heads = await model();
check(
'a head mutes, solos and turns down its track, "+ Track" adds a fifth and picks it',
heads.tracks.length === 5 &&
heads.tracks[0].mute &&
heads.tracks[2].solo &&
heads.tracks[2].volume < -55 &&
(await json('__gm.song.pickedTrack()')) === heads.tracks[4].id &&
(await json('__gm.song.info()')) === '5 tracks · 2 items',
JSON.stringify(heads.tracks),
);
await mutate(`
const song = __gm.state.project.assets.find((a) => a.id === ${JSON.stringify(id)});
song.tracks[2].volume = -6;
song.tracks[2].solo = false;
song.tracks[0].mute = false;`);
// 65h. Space plays from the start: the pattern a bar into itself at 2 s a bar, the sound as a
// clip round and round, each on the bus of its track.
p = await json('__gm.song.rulerAt(0)');
await click(p.x, p.y);
await mutate(`
const song = __gm.state.project.assets.find((a) => a.id === ${JSON.stringify(id)});
song.items.find((i) => i.kind === 'sound').length = ${BAR};`);
await press('Space');
const played = await waitFor(
() => json('{ planned: __gm.song.planned(), clips: __gm.song.clips(), playing: __gm.song.playing() }'),
(s) => s.planned.length >= 2 && s.clips.length >= 1,
60,
);
const busOf = (track) => `song:${id}:${track}`;
const firstClip = played.clips[0];
const notes = played.planned.slice(0, 2);
check(
'Space plays the song: the clip at once, the pattern from bar 3 with its notes a second apart, each on its track',
played.playing &&
Boolean(firstClip) &&
firstClip.sound === SOUND &&
firstClip.bus === busOf(tracks[0]) &&
Math.abs(firstClip.duration - 2) < 1e-9 &&
notes.length === 2 &&
notes.every((n) => n.instrument === 'sg65-ins' && n.bus === busOf(tracks[2]) && n.tempo === 120) &&
Math.abs(notes[0].at - firstClip.at - 4) < 1e-6 &&
Math.abs(notes[1].at - notes[0].at - 1) < 1e-6 &&
notes[0].note === 60,
JSON.stringify(played),
);
const buses = await json('__gm.song.buses()');
const bus = (track) => buses.find((b) => b.name === busOf(track));
check(
'each track is set on its bus: the turned-down one at -6 dB, the others at unity',
Math.abs(bus(tracks[2])?.gain - 10 ** (-6 / 20)) < 1e-6 &&
bus(tracks[0])?.gain === 1 &&
bus(tracks[1])?.gain === 1,
JSON.stringify(buses),
);
await click(...Object.values(await json("__gm.song.headAt(0, 'mute')")));
const muted = await waitFor(
() => json('__gm.song.buses()'),
(list) => list.find((b) => b.name === busOf(tracks[0]))?.gain === 0,
);
check(
'muting a track while it plays silences its bus at once',
muted.find((b) => b.name === busOf(tracks[0]))?.gain === 0 && (await json('__gm.song.playing()')),
JSON.stringify(muted),
);
await shot('02-playing');
// 65i. A pattern played in its tab takes over; a double-click on a pattern item opens it there.
await evaluate(`__gm.state.openAsset(${JSON.stringify(PATTERN)})`);
await sleep(200);
p = await json('__gm.pattern.playAt()');
await click(p.x, p.y);
await sleep(200);
const swapped = await json('{ song: __gm.song.playing(), pattern: __gm.pattern.playing() }');
await click(p.x, p.y);
check(
'a pattern started in its tab stops the song',
swapped.pattern && !swapped.song,
JSON.stringify(swapped),
);
await evaluate(`__gm.state.openAsset(${JSON.stringify(id)})`);
await sleep(200);
p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'body')`);
await doubleClick(p.x, p.y);
await sleep(200);
const opened = await json('{ tab: __gm.tab(), pattern: __gm.pattern.current() }');
check(
'a double-click on a pattern item opens the pattern in its tab',
opened.tab === 'pattern' && opened.pattern === PATTERN,
JSON.stringify(opened),
);
// 65k. A game plays the song through Play song (#336): the clip once as the intro, then round the
// loop of its ruler, each track on a bus inside a master of the playing. The pause of the
// toolbar holds the clock; S fires Stop song, which fades it out, then it is gone.
await evaluate('__gm.sound.stopAll()');
await mutate(`
const song = __gm.state.project.assets.find((a) => a.id === ${JSON.stringify(id)});
song.tracks.forEach((track, i) => Object.assign(track, { mute: false, solo: false, volume: i === 1 ? -6 : 0, pan: i === 1 ? -0.5 : 0 }));
const base = song.items[0];
song.items = [
{ ...base, id: 'sg65-i1', track: song.tracks[0].id, kind: 'sound', asset: ${JSON.stringify(SOUND)}, tick: 0, length: ${BAR}, offset: 0 },
{ ...base, id: 'sg65-i2', track: song.tracks[1].id, kind: 'pattern', asset: ${JSON.stringify(PATTERN)}, tick: ${BAR}, length: ${BAR}, offset: 0 },
];
song.loop = { start: ${BAR}, end: ${2 * BAR} };`);
await showTab('scene');
const rig = await scaffoldBehavior(t, {
assetId: 'sg65-logic',
name: 'Music 65',
boxId: 'sg65-box',
logicId: 'sg65-brain',
y: LANES.sound,
graph: {
nodes: [
node('sg65-start', 'OnStart', 0, 0),
node('sg65-play', 'PlaySong', 260, 0, { song: id, volume: 0.8, fadeIn: 1, loop: true }),
node('sg65-s', 'OnKeyDown', 0, 200, { key: 's' }),
node('sg65-stop', 'StopSong', 260, 200, { song: id, fadeOut: 1 }),
],
edges: [
edge('sg65-e3', 'sg65-start', 'exec', 'sg65-play', 'exec'),
edge('sg65-e4', 'sg65-s', 'exec', 'sg65-stop', 'exec'),
],
},
});
const playbacks = () => json('__gm.sound.playbacks()');
await play();
const game = await waitFor(playbacks, (list) => list[0]?.planned.length >= 4, 60);
const [run] = game;
const master = `play:${run?.id}`;
const gameNotes = run?.planned ?? [];
const gameClip = run?.clips[0];
check(
'Play song plays the clip once as the intro, then the pattern round the loop, 2 s a round, on their tracks',
game.length === 1 &&
run.name === `song:${id}` &&
run.owner !== '' &&
run.clips.length === 1 &&
gameClip?.sound === SOUND &&
gameClip.bus === busOf(tracks[0]) &&
gameNotes.every((n) => n.bus === busOf(tracks[1]) && n.tempo === 120) &&
Math.abs(gameNotes[0].at - gameClip.at - 2) < 1e-6 &&
Math.abs(gameNotes[1].at - gameNotes[0].at - 1) < 1e-6 &&
Math.abs(gameNotes[2].at - gameNotes[0].at - 2) < 1e-6,
JSON.stringify({ game: game.map((g) => ({ ...g, planned: g.planned.length })), gameNotes }),
);
const gameBuses = await json('__gm.song.buses()');
const gameBus = (name) => gameBuses.find((b) => b.name === name);
check(
'the playing has a master at its volume, the tracks inside it as they are set',
gameBus(master)?.gain === 0.8 &&
gameBus(`${master}:${busOf(tracks[0])}`)?.gain === 1 &&
Math.abs(gameBus(`${master}:${busOf(tracks[1])}`)?.gain - 10 ** (-6 / 20)) < 1e-6 &&
gameBus(`${master}:${busOf(tracks[1])}`)?.pan === -0.5,
JSON.stringify(gameBuses),
);
await clickToolbar('pause');
await sleep(400);
const heldClock = await json('{ state: __gm.sound.clockState(), at: __gm.sound.clock() }');
await sleep(300);
const heldLater = await json('{ state: __gm.sound.clockState(), at: __gm.sound.clock() }');
await clickToolbar('pause');
await sleep(200);
const resumed = await json('__gm.sound.clockState()');
check(
'the pause of the toolbar holds the clock while the song plays, and resuming lets it run',
heldClock.state === 'suspended' &&
heldLater.state === 'suspended' &&
heldLater.at === heldClock.at &&
resumed === 'running',
JSON.stringify({ heldClock, heldLater, resumed }),
);
await press('s');
const fading = await waitFor(playbacks, (list) => list[0]?.fading !== null);
const fadedOut = await waitFor(playbacks, (list) => list.length === 0, 40);
await sleep(100);
const leftBuses = (await json('__gm.song.buses()')).filter((b) => b.name.startsWith(master));
await stop();
check(
'Stop song fades it out over its second, playing on meanwhile, then it and its buses are gone',
fading.length === 1 &&
fading[0].fading !== null &&
fading[0].playing &&
fadedOut.length === 0 &&
leftBuses.length === 0,
JSON.stringify({ fading: fading.map((g) => g.fading), fadedOut, leftBuses }),
);
const left = await rig.remove();
// 65j. The step takes back everything it made.
await evaluate('__gm.sound.stopAll()');
await mutate(`
const gone = new Set([${JSON.stringify(SOUND)}, 'sg65-ins', ${JSON.stringify(PATTERN)}, ${JSON.stringify(id)}]);
const project = __gm.state.project;
project.assets = project.assets.filter((a) => !gone.has(a.id));
__gm.state.select(null);`);
await showTab('scene');
check(
'the step leaves nothing of its own behind',
(await json(
`__gm.state.project.assets.filter((a) => a.id.startsWith('sg65') || a.type === 'song').length`,
)) === 0 &&
left.objects === 0 &&
left.assets === 0,
JSON.stringify(left),
);
}