Show what the song plays around a pattern as ghost notes (#339)

A bass line is written against the chords it goes with. Until now the
piano roll showed only the pattern itself, so writing a part to fit the
rest of a song meant switching between the Pattern and the Song tab.

- A double-click on a pattern item remembers song, item and the round
  clicked into for that pattern. The place lives in the session, not in
  the project, and goes by the item's id, so moving the item moves the
  ghost notes along.
- Opened from the Assets panel, the pattern shows the item of the last
  double-click. Without one, a pattern that lies in exactly one item of
  all the songs shows that item's first round.
- Ghost notes are the pattern items of the other tracks all along the
  song, and on the own track the items before and after and the other
  rounds of the item. The round edited itself does not count. Sound
  items have no notes.
- A ghost note sits on the row it sounds with: its own transpose, less
  the transpose of the item the pattern was opened from.
- The roll draws them grey, without an edge, under the notes. Resting
  on one names its track and its pattern.
- The header has a Ghosts switch, on by default, and names where they
  come from, e.g. "Tune · Bass · bar 5".
- The time axis pans back to the start of the song, with bar and grid
  lines before the pattern. Fit still frames only the pattern.
- A click or a paste outside the pattern no longer lands. Before, only
  the time left of bar 1 was closed, notes could still be drawn past
  the end, where they are kept but never played.
- The rounds of a pattern item are now worked out in one place,
  itemNotes() in song.ts, which songSequence() and the ghost notes
  share.

Tests:
- Unit ghosts (new): 5 green. Counter-check with the round edited
  not left out and the own transpose not taken off: 2 red.
- Unit piano-roll: 1 new (pan back to the song, lines before bar 1).
  Counter-check without the song's start: red.
- e2e 65 (melektaus-atx): ALL PASSED - 38 checks (3 new). The first
  run was red on the tooltip check: the ghost note it rested on lay a
  fifth up, outside the rows Fit frames. The test now uses a tone.
- e2e 64 (melektaus-atx): ALL PASSED - 30 checks.
- Gate (melektaus-atx): CHECK EXIT 0, 260 files, 4027 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-07 15:06:32 +02:00
1 parent c33d6d98e5
commit d505f6ed27
13 files changed
+521 -33

No files matched your search

+51
View File
@@ -493,6 +493,10 @@ export async function song(t) {
swapped.pattern && !swapped.song,
JSON.stringify(swapped),
);
// The riff a tone up for four bars on the second track: what its ghost notes (#339) show.
await mutate(`
const song = __gm.state.project.assets.find((a) => a.id === ${JSON.stringify(id)});
song.items.push({ ...song.items.find((i) => i.kind === 'pattern'), id: 'sg65-tone', track: song.tracks[1].id, tick: 0, length: ${4 * BAR}, offset: 0, transpose: 2 });`);
await evaluate(`__gm.state.openAsset(${JSON.stringify(id)})`);
await sleep(200);
p = await json(`__gm.song.itemAt(${JSON.stringify(riff.id)}, 'body')`);
@@ -504,6 +508,53 @@ export async function song(t) {
opened.tab === 'pattern' && opened.pattern === PATTERN,
JSON.stringify(opened),
);
const songNow = {
...(await model()),
name: await json(`__gm.state.project.assets.find((a) => a.id === ${JSON.stringify(id)}).name`),
};
const riffNow = songNow.items.find((i) => i.id === riff.id);
const trackName = (trackId) => songNow.tracks.find((tr) => tr.id === trackId).name;
const ghosts = await json('__gm.pattern.ghosts()');
const tone = ghosts.notes.filter((n) => n.track === trackName(songNow.tracks[1].id));
const toneTicks = tone.map((n) => n.tick + ghosts.origin);
check(
'the pattern opened from the song shows the other track faint: each note where it sounds, a tone up, on by default',
ghosts.toggled &&
ghosts.enabled &&
tone.length === 8 &&
toneTicks.every((tick, i) => tick === Math.floor(i / 2) * BAR + (i % 2) * 960) &&
tone.every((n, i) => n.note === (i % 2 ? 64 : 60) + 2 - riffNow.transpose && n.pattern === 'Riff 65') &&
(ghosts.origin - riffNow.tick + (riffNow.offset % BAR)) % BAR === 0 &&
ghosts.source ===
`${songNow.name} · ${trackName(riffNow.track)} · bar ${Math.floor(Math.max(ghosts.origin, riffNow.tick) / BAR) + 1}`,
JSON.stringify({ ghosts, riff: riffNow }),
);
const inside = tone.find((n) => n.tick >= 0 && n.tick < BAR);
p = await json(`__gm.pattern.gridAt(${inside.tick + 100}, ${inside.note})`);
await mouse('mouseMoved', p.x - 2, p.y);
await mouse('mouseMoved', p.x, p.y);
const sign = await waitFor(
() => json('__gm.tooltip()'),
(s) => s !== null,
);
check(
'resting on a ghost note tells its track and its pattern',
sign?.text === `${trackName(songNow.tracks[1].id)} · Riff 65`,
JSON.stringify(sign),
);
await shot('03-ghosts');
await click(ghosts.x, ghosts.y);
await sleep(150);
const hidden = await json('__gm.pattern.ghosts()');
await click(ghosts.x, ghosts.y);
await sleep(150);
check(
'Ghosts hides them and shows them again',
!hidden.toggled &&
hidden.notes.length === 0 &&
(await json('__gm.pattern.ghosts()')).notes.length === ghosts.notes.length,
JSON.stringify({ hidden: hidden.notes.length, toggled: hidden.toggled }),
);
// 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