Files
feuerwerk/src/editor/panels/assetGroups.ts
T
adminandClaude Opus 5.5 8a4e4a6762
game-maker / suite (push) Failing after 2m40s
game-maker / gate (push) Successful in 3m14s
Play sounds as notes of an instrument asset #331
A sound could only be played as it was, one at a time. An instrument
is a node graph that makes a note a sound: Notes nodes bring the note
in, Samples play sound assets for it, the effects of a sound FX shape
it and the Output sums the layers. Its tab plays it from a keyboard,
a behavior with Play note. It is what patterns and songs (#330) will
play.

- New asset type instrument, under the heading Music, not placeable.
  A new one starts as Notes into a Sample into the Output.
- Notes are counted as MIDI does: 60 is C4, names like C#4, sharps
  only, the lowest C-1. Notes has From and To, outputs any, note,
  frequency and velocity, and with Single notes a trigger per note,
  each with an optional name for a drum kit.
- New port type trigger, only into the trigger of a source. Inputs
  can take any number of edges now (PortDef.many): a trigger, and
  the Output, which plays everything into it side by side.
- Sample plays a sound asset. Follow note shifts it by note - root
  through the pitch worklet of #317, so it keeps its length. Gate
  fades it out at the end of the note, One-shot plays through. Loop
  runs between Loop start and Loop end, also in the worklet.
- Parameters declares the instrument's own parameters with a
  default. Sound FX sends the sound through a sound FX asset, its
  parameters as inputs, the sound set in where its Input was.
- compileInstrument walks the graph once per note. A trigger is on
  only for the notes it stands for, a silent source silences what it
  alone feeds, a Mix with a silent side is the other side. velocity
  and the parameters stay open for the voice. Builds are cached per
  note until the graph or a sound or FX it names changes.
- The player takes a note as one voice of several layers, each way
  with its own file and volume. release fades the gated ways out,
  one-shots play on. playNote can release after a duration.
- Play note plays one note with velocity, volume, duration and
  detached, and hands out voice for Set sound FX parameters and
  Stop sound. Velocity is always loudness. Instrument parameters
  picks values for the instrument's parameters like Sound FX
  parameters does for an FX, renames follow.
- The tab has the graph, a header field per parameter, Stop, and
  128 keys below. Keys without sound are grey. A key plays while it
  is held. Focused, the computer keyboard plays as in a tracker by
  KeyboardEvent.code, the arrows move the octave.

Findings:
- A label of the keys set fill on the shared small text style and
  darkened every small label of the editor. Caught in a screenshot
  before the commit, the keys have a style of their own now.
- Suite task 523 on cf6799a failed two checks of e2e 34 that timed
  audio by the page's clock: a 2.95 s echo tail was gone after 1 s,
  and Quad in was further along than 0.7 s allow. Both time on the
  audio clock now through a new hook __gm.sound.clock().

Tests:
- instrument.test.ts (new, 22): notes, asset, palette, round trip,
  compile per note, drum kit, zones, Mix, velocity and parameters,
  Sound FX node with rename, problems, cache, Play note, the keys
- sound-library +7 (layers, release, duration, early release, loop
  region in buffer and worklet), pitch-player +2 (loop region),
  node-catalog +4, graph adjusted. 582 tests in the touched files.
- e2e 4 and 34 on melektaus-atx: ALL PASSED, 34 with 44 checks (+7)
- Gate on melektaus-atx: CHECK EXIT 0, 243 test files, 3750 tests
- Counter-checks: any always on, release ending one-shots, Sound FX
  inputs ignored, loop region ignored. 3, 2, 1 and 1 tests failed.
- Browser probe on stein2: keys, held key, Single notes names and
  the header looked at in screenshots.

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

67 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Asset } from '../../core/model/Asset';
import type { AssetType } from '../../core/model/AssetTypes';
/**
* Group headings of the asset panel. Plural, because a heading names what is under it – and so no
* heading reads like the `+` menu entry that creates one of its kind.
*/
export const ASSET_GROUP_LABELS: Record<AssetType, string> = {
scene: 'Scenes',
camera: 'Cameras',
sprite: 'Sprites',
text: 'Texts',
behavior: 'Behaviors',
variables: 'Variables',
struct: 'Structs',
collider: 'Colliders',
rigidbody: 'Rigidbodies',
joint: 'Joints',
container: 'Containers',
clip: 'Clip areas',
texture: 'Textures',
// Not "Vector art": that is the `+` menu entry, and a heading of the same words would take the
// click meant for the menu (see the test below the labels).
vectorart: 'Vector drawings',
// Not "Pixel art" either, for the same reason.
pixelart: 'Pixel drawings',
palette: 'Palettes',
animation: 'Animations',
curve: 'Curves',
tile: 'Tiles',
tilemap: 'Tilemaps',
statemachine: 'State machines',
shader: 'Shaders',
shaderfunction: 'Shader functions',
font: 'Fonts',
sound: 'Sounds',
// Not "Sound FX": that is the `+` menu entry (see Vector art).
soundfx: 'Sound effects',
// Where patterns and songs join it (#330).
instrument: 'Music',
particles: 'Particles',
};
export interface AssetGroup {
type: AssetType;
assets: Asset[];
}
/** Case aside and digits as numbers, so `Level 2` comes before `Level 10`. */
const collator = new Intl.Collator('en', { numeric: true, sensitivity: 'base' });
/**
* The asset panel's rows (#176): one group per type that has assets, groups and the assets in
* each alphabetical. Equal names keep the project's order, so a row does not jump on a rebuild.
*/
export function groupAssets(assets: readonly Asset[]): AssetGroup[] {
const byType = new Map<AssetType, Asset[]>();
for (const asset of assets) {
const list = byType.get(asset.type);
if (list) list.push(asset);
else byType.set(asset.type, [asset]);
}
return [...byType]
.map(([type, list]) => ({ type, assets: list.sort((a, b) => collator.compare(a.name, b.name)) }))
.sort((a, b) => collator.compare(ASSET_GROUP_LABELS[a.type], ASSET_GROUP_LABELS[b.type]));
}