Files
feuerwerk/src/editor/soundfx/deviceFace.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

95 lines
3.2 KiB
TypeScript

import { SetNodeParamCommand } from '../../core/commands/graphCommands';
import type { GraphNode } from '../../core/graph';
import type { PropertyValue } from '../../core/model/Properties';
import { findGraphAsset, type Project } from '../../core/model/Project';
import { tapId } from '../../core/soundfx/nodes';
import { soundLibrary } from '../../viewport/SoundLibrary';
import type { EditorState } from '../state';
import { NodeParamDrag } from './nodeParamDrag';
/** Whether a link feeds a node's setting: its knob cannot be turned then. */
export function paramWired(project: Project, assetId: string, nodeId: string, key: string): boolean {
const graph = findGraphAsset(project, assetId)?.graph;
return Boolean(graph?.edges.some((e) => e.to.node === nodeId && e.to.port === key));
}
/**
* What a node drawn as its device (#380 ff.) does with that node: looks it up anew each time, as
* an undo may have taken it away; tells which settings a link feeds; writes a turned knob as it
* goes and as one undo step when it lands; and sets anything else in one step.
*/
export abstract class DeviceFace {
protected readonly drag: NodeParamDrag;
/** Sounds whose peaks are on their way, so they are asked for once. */
private readonly loading = new Set<string>();
private listening = false;
constructor(
protected readonly state: EditorState,
protected readonly assetId: string,
protected readonly nodeId: string,
private readonly nodeType: string,
dragName: string,
) {
this.drag = new NodeParamDrag(state, dragName);
}
protected node(): GraphNode | null {
const node = findGraphAsset(this.state.project, this.assetId)?.graph.nodes.find(
(n) => n.id === this.nodeId,
);
return node?.type === this.nodeType ? node : null;
}
protected wired = (key: string): boolean => paramWired(this.state.project, this.assetId, this.nodeId, key);
abstract sync(): void;
/** A frame on; most devices have nothing that moves by itself. */
tick(): boolean {
return false;
}
hide(): void {}
preview(key: string, value: number): void {
const node = this.node();
if (node) this.drag.preview(node, key, value);
}
commit(key: string, value: number): void {
const node = this.node();
if (node) this.drag.commit(this.assetId, node, key, value);
}
/** Loads what the screen draws a sound from, and draws it once it is there. */
protected load(file: string): void {
if (this.loading.has(file)) return;
this.loading.add(file);
void soundLibrary.loadPicture(file).then(() => {
this.loading.delete(file);
this.sync();
});
}
/** Hears the node's tap from now on; its id. */
protected listen(): string {
const id = tapId(this.assetId, this.nodeId);
soundLibrary.listen(id);
this.listening = true;
return id;
}
/** Stops hearing the node's tap; whether it was heard. */
protected unlisten(): boolean {
if (!this.listening) return false;
this.listening = false;
soundLibrary.unlisten(tapId(this.assetId, this.nodeId));
return true;
}
protected set(key: string, value: PropertyValue): void {
if (this.node()) this.state.execute(new SetNodeParamCommand(this.assetId, this.nodeId, key, value));
}
}