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

+34 -1
View File
@@ -5,6 +5,7 @@ import {
namedNotes,
playedNotes,
} from '../../core/instrument/compile';
import { ghostNotes, placeOf } from '../../core/music/ghosts';
import {
GRID_OPTIONS,
PATTERN_GRID_KEY,
@@ -18,7 +19,7 @@ import type { Asset, PatternAsset } from '../../core/model/Asset';
import { textOf } from '../../core/model/Properties';
import { findAssetOf } from '../../core/model/Project';
import { playNote } from '../../runtime/systems/behaviorContext';
import { Button, Dropdown, Label, Menu } from '../../ui';
import { Button, Dropdown, Label, Menu, type Widget } from '../../ui';
import { Music } from '../../viewport/music';
import { soundLibrary } from '../../viewport/SoundLibrary';
import { AssetTabEditor } from '../AssetTabEditor';
@@ -45,6 +46,10 @@ export class PatternEditor extends AssetTabEditor<PatternAsset, PianoRoll> {
readonly gridButton = new Dropdown('1/16', { width: GRID_WIDTH });
/** Whether a note drawn, grabbed or moved sounds; off by default. A key down the left always does. */
readonly auditionButton: Button;
/** Whether the notes the song plays around the pattern are shown (#339); on by default. */
readonly ghostsButton: Button;
/** Where the ghost notes come from: song, track and bar. */
readonly ghostSource = new Label('', { style: 'muted' });
readonly music = new Music(() => this.state.project);
/** The pattern playing, `''` while none is. */
private playingId = '';
@@ -66,6 +71,18 @@ export class PatternEditor extends AssetTabEditor<PatternAsset, PianoRoll> {
tooltip: 'Let a note sound when it is drawn, grabbed or moved',
onClick: () => this.auditionButton.setToggled(!this.auditionButton.toggled),
});
this.ghostsButton = new Button('Ghosts', {
toggle: true,
tooltip: () =>
this.ghostsButton.enabled
? 'Show what the song plays around this pattern, faint'
: 'Double-click an item of this pattern in a song to see what plays around it',
onClick: () => {
this.ghostsButton.setToggled(!this.ghostsButton.toggled);
this.refresh();
},
});
this.ghostsButton.setToggled(true);
const roll = new PianoRoll(state);
roll.onPreview = (note, held) => this.preview(note, held);
roll.onRelease = (voice) => soundLibrary.release(voice);
@@ -78,6 +95,8 @@ export class PatternEditor extends AssetTabEditor<PatternAsset, PianoRoll> {
new Label('Grid', { style: 'muted' }),
this.gridButton,
this.auditionButton,
this.ghostsButton,
this.ghostSource,
]);
state.on('load', () => this.stop());
}
@@ -214,6 +233,20 @@ export class PatternEditor extends AssetTabEditor<PatternAsset, PianoRoll> {
);
this.canvas.setInstrument(new Set(sounding), namedNotes(instrument.graph));
} else this.canvas.setInstrument(new Set(), new Map());
this.syncGhosts(asset);
this.follow(asset);
}
/** The song item the pattern was opened from – or the only one it lies in – and what plays around it. */
private syncGhosts(asset: PatternAsset | null): void {
const project = this.state.project;
const place = asset && placeOf(project, asset.id, this.state.patternPlaces.get(asset.id));
const ghosts = asset && place ? ghostNotes(project, asset.id, place) : null;
this.ghostsButton.setEnabled(ghosts !== null);
this.canvas.setGhosts(this.ghostsButton.toggled ? ghosts : null);
const source = ghosts ? `${ghosts.song} · ${ghosts.track} · bar ${ghosts.bar}` : '';
if (source === this.ghostSource.text) return;
this.ghostSource.setText(source);
(this.ghostSource.parent as Widget | null)?.layout();
}
}