Files
feuerwerk/src/editor/soundfx/SampleFace.ts
T
adminandClaude Opus 5.5 0701fe3856
feuerwerk / gate (push) Successful in 5m5s
feuerwerk / suite (push) Failing after 18m39s
Share the parts the sound devices and timelines repeated (#85)
Round 12 of the clean-up. Duplicate code had grown from 33 clones
(249 lines) after round 11 to 140 clones (1263 lines), almost all of
it in the panels and faces of the sound FX devices (#379 to #401).
It is down to 57 clones (416 lines) now, and src is 816 lines
shorter.

- deviceParts.ts holds what the device panels built by hand: the
  head, rows of knobs, the screen style and the row layout for
  groups of knobs. Twelve panels use it. panel.knobs stays because
  the debug hooks read it.
- DeviceFace is the base of the twelve faces. It finds the node and
  does wired, preview, commit, set, hide, reload and audition.
  compressorWired lives there as paramWired.
- TextPool replaces ten copies of "make texts as needed, hide the
  rest" in the wave and video tabs, the rulers, the piano roll and
  the song and composition timelines. clipStrip.ts is the clip label
  strip the wave and video tabs share.
- core/util/bytes.ts has the concat that ogg, matroska and avcColour
  each wrote out.
- Dead code is gone: clear on the video players (never called since
  #402), posterFileOf and videoTimeAt (only tests called them) and
  easeOut (the same as glide(t, 3)). Values only used in their own
  file lose their export.
- Comments over 125 columns are wrapped, and comments that told the
  history ("as before", "used to") say what is, in src and in the
  e2e modules.
- Left alone on purpose: AnimationEditor and CompositionEditor share
  only the play button, and the curve panels are built differently.
- Chip now places its boxes through put, which rounds. They were
  whole numbers already. The three row layouts are byte-identical
  before and after.
- README lists the video and composition assets and the Videos and
  Compositions pages.

Tests:
- Gate (melektaus-atx): CHECK EXIT 0, 313 files, 4835 tests.
- e2e 25, 34, 64, 65, 66, 69 (melektaus-atx): ALL PASSED, 330 checks.
- TextPool without keeping its texts and framesToRoom without making
  room both go red.

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

101 lines
3.7 KiB
TypeScript

import { SetNodeParamCommand } from '../../core/commands/graphCommands';
import { InstrumentSample, type SamplePlay } from '../../core/instrument/nodes';
import { findSound } from '../../core/model/sound';
import { assetRefLabel, soundChoices } from '../../core/properties/assetRef';
import { playedSoundOf } from '../../core/properties/playedSound';
import { resolveAssetProps } from '../../core/properties/resolve';
import { volumeOf } from '../../core/properties/sounds';
import { Menu, type Widget } from '../../ui';
import { soundLibrary } from '../../viewport/SoundLibrary';
import type { NodeFace } from '../graph/nodeFace';
import type { EditorState } from '../state';
import { DeviceFace } from './deviceFace';
import { type SampleHost, SamplePanel, type SamplePicture } from './SamplePanel';
import { idleSampleKeys, sampleValues } from './sampleView';
const SOUND = 'sound';
const ROOT = 'root';
const PLAY = 'play';
const FOLLOW = 'followNote';
/**
* A Sample node drawn as its device (#400): the waveform of the sound or clip it plays, drawn from
* its peaks once they are loaded, and every setting worked right in the graph. Nothing on it moves
* by itself, and it listens to nothing.
*/
export class SampleFace extends DeviceFace implements NodeFace, SampleHost {
readonly widget: SamplePanel;
constructor(state: EditorState, assetId: string, nodeId: string) {
super(state, assetId, nodeId, InstrumentSample.type, 'sample-face');
this.widget = new SamplePanel(this);
}
sync(): void {
const node = this.node();
if (!node) return;
const values = sampleValues(node.params);
const ref = values.sound ? findSound(this.state.project, values.sound) : null;
const file = ref ? playedSoundOf(ref) : '';
let picture: SamplePicture | null = null;
let missing = '';
// What the screen says without a sound to draw: what the instrument says of it, then the loading.
if (!values.sound) missing = 'NO SOUND PICKED';
else if (!ref) missing = 'THAT SOUND IS GONE';
else if (!file) missing = 'THE SOUND HAS NO FILE';
else {
const peaks = soundLibrary.peaks(file);
const seconds = soundLibrary.duration(file);
if (peaks && seconds !== null)
picture = { peaks, seconds, volume: volumeOf(resolveAssetProps(this.state.project, ref.asset)) };
else if (soundLibrary.failedToLoad(file)) missing = 'CANNOT LOAD';
else {
missing = 'LOADING';
this.load(file);
}
}
this.widget.sync({
values,
idle: idleSampleKeys(node.params),
picture,
sound: values.sound ? assetRefLabel(this.state.project, values.sound) : '',
missing,
});
}
previewRoot(note: number): void {
const node = this.node();
if (node) this.drag.previewAll(node, { [ROOT]: String(note) });
}
commitRoot(note: number): void {
const node = this.node();
if (node) this.drag.commit(this.assetId, node, ROOT, String(note));
}
pickPlay(play: SamplePlay): void {
const node = this.node();
if (node && sampleValues(node.params).play !== play) this.set(PLAY, play);
}
switchFollow(on: boolean): void {
this.set(FOLLOW, on);
}
/** The sounds of the project and their clips; picking one makes it what the Sample plays. */
pickSound(button: Widget): void {
const node = this.node();
if (!node) return;
const current = sampleValues(node.params).sound;
const items = soundChoices(this.state.project).map((sound) => ({
label: sound.label,
current: sound.id === current,
onSelect: () => {
if (sound.id !== current)
this.state.execute(new SetNodeParamCommand(this.assetId, this.nodeId, SOUND, sound.id));
},
}));
if (items.length > 0) new Menu(items, { searchable: true }).openBelow(button);
}
}