Pick a song's sign in one row, and let its patterns keep theirs (#363)
game-maker / gate (push) Successful in 3m46s
game-maker / suite (push) Successful in 15m52s

A song had two rows for its meter, Beats per bar and Beat, and the
patterns it kept to itself took both from it on every change. Their
length is counted in bars, so a new sign cut or stretched them and
their items.

- The song has one row Sign with 1/2, 2/2, 3/2, 1/4 to 6/4 and 5/8
  to 9/8, 4/4 by default. It is stored as `sign`. A value not in the
  list reads as 4/4.
- An embedded pattern keeps its own tempo and meter, as a project
  pattern does. Its inspector shows Tempo, Beats per bar and Beat
  again and hides only Bus.
- A pattern made in a song still starts with the song's tempo and
  sign, so its first bar fits the item it gets.
- A copy (Embed a copy, a paste from another song) keeps its clock.
  `clockFollowers` and the follow step in `AssetPropertyCommand` are
  gone.
- No load migration. The two songs of the user's project were moved
  from `beats`/`beat` to `sign` by hand. No other project had a song
  with a meter of its own.

Tests:
- Unit song + embedded + pattern: 44 green, 1 new, 4 rewritten.
  Counter-probes: a copy taking the song's clock and a sign outside
  the list both turn a test red.
- e2e 65 (melektaus-atx): ALL PASSED, 57 checks (1 new: Sign picked
  from its list in the inspector).
- Gate (melektaus-atx): CHECK EXIT 0, 272 files, 4214 tests.
  After it, `SIGNS` lost its `as const` and the cast went with it.
  Typecheck, lint and the 44 unit tests ran again, all green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-09 07:33:49 +02:00
1 parent d0b76ec355
commit 0d57a2f3c4
7 files changed
+109 -92

No files matched your search

+3 -14
View File
@@ -12,7 +12,7 @@ import type {
VariablesAsset,
} from '../model/Asset';
import type { AssetType } from '../model/AssetTypes';
import { clockFollowers, embeddedIn } from '../music/embedded';
import { embeddedIn } from '../music/embedded';
import { defaultTracks } from '../music/song';
import { heldSongGraph } from '../music/routing';
import { linearCurve } from '../model/curve';
@@ -21,7 +21,7 @@ import { DEFAULT_PALETTE, PIXEL_CANVAS_DEFAULT } from '../model/pixelart';
import { isSoundFile, renewClipIds } from '../model/sound';
import { removeSubtrees } from '../model/hierarchy';
import { dropReferencesToGone, renamedReference, shownObjectIds, swapReferences } from '../model/objectRefs';
import { type PropertyBag, type PropertyValue, setBagValue } from '../model/Properties';
import type { PropertyBag, PropertyValue } from '../model/Properties';
import { objectHolders, type Project } from '../model/Project';
import {
type Scope,
@@ -547,12 +547,8 @@ export class SetMachineStartCommand implements Command {
}
}
/**
* An embedded pattern follows the tempo and the meter of its song (#355), in the same undo step. A
* song that picks another sound FX lets go of the one it kept to itself, in that step too.
*/
/** A song that picks another sound FX lets go of the one it kept to itself, in the same undo step. */
abstract class AssetPropertyCommand extends SetBagValueCommand<Asset> {
private followed: { id: string; previous: PropertyValue | undefined }[] = [];
private settled: SetSongCommand | null = null;
protected constructor(
@@ -566,11 +562,6 @@ abstract class AssetPropertyCommand extends SetBagValueCommand<Asset> {
override execute(project: Project): void {
super.execute(project);
const asset = requireAsset(project, this.assetId);
this.followed = clockFollowers(project, asset, this.key).map((pattern) => {
const previous = pattern.props[this.key];
setBagValue(pattern.props, this.key, asset.props[this.key]);
return { id: pattern.id, previous };
});
this.settled =
asset.type === 'song' && this.key === ASSET_FX_KEY ? new SetSongCommand(asset.id, {}) : null;
this.settled?.execute(project);
@@ -578,8 +569,6 @@ abstract class AssetPropertyCommand extends SetBagValueCommand<Asset> {
override undo(project: Project): void {
this.settled?.undo(project);
for (const { id, previous } of this.followed)
setBagValue(requireAsset(project, id).props, this.key, previous);
super.undo(project);
}
+6 -25
View File
@@ -8,7 +8,7 @@
import type { Graph } from '../graph/Graph';
import { SOUND_FX_INPUT, SOUND_FX_OUTPUT } from '../graph/nested';
import { newId } from '../ids';
import type { Asset, PatternAsset, SongAsset } from '../model/Asset';
import type { Asset, SongAsset } from '../model/Asset';
import type { AssetType } from '../model/AssetTypes';
import type { PropertyBag } from '../model/Properties';
import { findAsset, findAssetOf, type Project } from '../model/Project';
@@ -20,19 +20,13 @@ import { type SongItem, songMeter, songTempo, type SongTrack } from './song';
export const EMBEDDABLE_TYPES: readonly AssetType[] = ['sound', 'pattern', 'soundfx'];
/**
* What an embedded pattern takes from its song: it is drawn and heard on the song's clock. A pattern
* names these the way a song does, so one key serves both.
*/
export const SONG_CLOCK_KEYS: readonly string[] = [PATTERN_TEMPO_KEY, PATTERN_BEATS_KEY, PATTERN_BEAT_KEY];
/**
* The rows of an embedded asset that do nothing in a song: where it goes and how it repeats is the
* song's, and a pattern's clock is the song's too.
* song's. A pattern keeps its tempo and meter (#363), as one of the project does.
*/
const HIDDEN_ROWS: Partial<Record<AssetType, readonly string[]>> = {
sound: ['loop', 'bus'],
pattern: [...SONG_CLOCK_KEYS, 'bus'],
pattern: ['bus'],
};
export function isEmbeddable(type: AssetType): boolean {
@@ -75,7 +69,7 @@ export function assetTitle(project: Project, asset: Asset): string {
return song ? `${song.name} › ${asset.name}` : asset.name;
}
/** The tempo and the meter of a song, as a pattern's props. */
/** The tempo and the meter of a song, as the props a pattern made in it starts with. */
export function songClockProps(props: PropertyBag): PropertyBag {
const meter = songMeter(props);
return {
@@ -85,30 +79,17 @@ export function songClockProps(props: PropertyBag): PropertyBag {
};
}
/** Gives an asset that comes to live in `song` its owner, and a pattern the song's clock. */
function ownedBy<T extends Asset>(asset: T, song: SongAsset): T {
asset.owner = song.id;
if (asset.type === 'pattern') Object.assign(asset.props, songClockProps(song.props));
return asset;
}
/**
* A copy of a project asset for the song to keep to itself (#355), to bend without touching the rest.
* `ids` says what the asset and its clips (#357) are called in the copy.
*/
export function embeddedCopy(asset: Asset, song: SongAsset): { copy: Asset; ids: Map<string, string> } {
const copy = ownedBy({ ...structuredClone(asset), id: newId() }, song);
const copy: Asset = { ...structuredClone(asset), id: newId(), owner: song.id };
const ids = new Map([[asset.id, copy.id]]);
renewClipIds(copy, ids);
return { copy, ids };
}
/** The patterns that follow `key` of an asset: those a song keeps, when the key is part of its clock. */
export function clockFollowers(project: Project, asset: Asset, key: string): PatternAsset[] {
if (asset.type !== 'song' || !SONG_CLOCK_KEYS.includes(key)) return [];
return embeddedIn(project, asset.id).filter((a): a is PatternAsset => a.type === 'pattern');
}
/** "Pattern 1", 2, 3 … ("Sound FX 1" …): the first number none of what the song keeps to itself has. */
export function embeddedName(project: Project, songId: string, base: string): string {
return nextNumberedName(
@@ -218,7 +199,7 @@ export function settleEmbedded(
if (!ids) {
const fresh = found !== undefined || taken.has(source.id);
const id = fresh ? newId() : source.id;
const copy = ownedBy({ ...structuredClone(source), id }, song);
const copy: Asset = { ...structuredClone(source), id, owner: song.id };
ids = new Map([[source.id, id]]);
if (fresh) renewClipIds(copy, ids);
copies.set(source.id, ids);
+25 -7
View File
@@ -56,10 +56,29 @@ export interface SongItem {
}
export const SONG_TEMPO_KEY = 'tempo';
export const SONG_BEATS_KEY = 'beats';
export const SONG_BEAT_KEY = 'beat';
export const SONG_SIGN_KEY = 'sign';
export const SONG_GRID_KEY = 'grid';
/** The time signatures a song is written in (#363), one row for both numbers. */
export const SIGNS: readonly string[] = [
'1/2',
'2/2',
'3/2',
'1/4',
'2/4',
'3/4',
'4/4',
'5/4',
'6/4',
'5/8',
'6/8',
'7/8',
'8/8',
'9/8',
];
export const DEFAULT_SIGN = '4/4';
export const SIGN_OPTIONS = SIGNS.map((sign) => ({ value: sign, label: sign }));
export const DEFAULT_SONG_GRID = 'bar';
export const SONG_GRID_OPTIONS = [{ value: 'bar', label: 'Bar' }, ...GRID_OPTIONS];
/** A new song has this many tracks. */
@@ -78,12 +97,11 @@ export function itemMaxDb(kind: SongItemKind): number {
return kind === 'sound' ? SOUND_ITEM_MAX_DB : 0;
}
/** The meter of a song's sign; 4/4 where it is not one of `SIGNS`. */
export function songMeter(props: PropertyBag): Meter {
const beats = props[SONG_BEATS_KEY];
return heldMeter({
beats: typeof beats === 'number' ? Math.round(beats) : 4,
unit: Number(textOf(props[SONG_BEAT_KEY] ?? '4')),
});
const sign = textOf(props[SONG_SIGN_KEY] ?? DEFAULT_SIGN);
const [beats, unit] = (SIGNS.includes(sign) ? sign : DEFAULT_SIGN).split('/');
return heldMeter({ beats: Number(beats), unit: Number(unit) });
}
export function songTempo(props: PropertyBag): number {
+4 -13
View File
@@ -118,11 +118,12 @@ import {
PATTERN_TEMPO_KEY,
} from '../music/pattern';
import {
DEFAULT_SIGN,
DEFAULT_SONG_GRID,
SONG_BEAT_KEY,
SONG_BEATS_KEY,
SIGN_OPTIONS,
SONG_GRID_KEY,
SONG_GRID_OPTIONS,
SONG_SIGN_KEY,
SONG_TEMPO_KEY,
} from '../music/song';
import { DEFAULT_TEMPO, MAX_TEMPO, MIN_TEMPO } from '../music/time';
@@ -770,17 +771,7 @@ const ASSET_SCHEMAS: Record<AssetType, PropertySchema> = {
max: MAX_TEMPO,
step: 1,
},
{
key: SONG_BEATS_KEY,
label: 'Beats per bar',
kind: 'number',
default: 4,
min: 1,
max: 32,
step: 1,
decimals: 0,
},
{ key: SONG_BEAT_KEY, label: 'Beat', kind: 'enum', default: '4', options: BEAT_OPTIONS },
{ key: SONG_SIGN_KEY, label: 'Sign', kind: 'enum', default: DEFAULT_SIGN, options: SIGN_OPTIONS },
{
key: SONG_GRID_KEY,
label: 'Grid',