Refactoring round 10 covers everything since round 9 (808e1ee): 110 commits with about 47 000 new lines, nearly all of them sound, sound FX, instruments, patterns and songs. Behaviour is unchanged. Duplicate code (jscpd over src, 50 tokens, TypeScript only, measured on808e1eeand here alike: 47 clones / 426 lines before, 33 / 245 after; round 9 itself ended at 22 / 160 by this count): - PreviewParams (new, editor/soundfx) is the header's parameter bar of the Sound FX and the Instrument tab: values, defaults, fields and the voices a moved field reaches. Both tabs had it line for line. - fxWorklet: an Effect base runs the bit crusher, phaser, flanger, limiter, LFO and bus shifter, a Source base the pitch player and the Chip. Start is the one wait for a voice's first sample, which four processors wrote out each. - nodes/shared has checkPort, detachedPort, fxParamsPort and letRingPort. The Play and Stop nodes of sounds, notes, patterns and songs spelled each port out, up to five times. - parameterValues builds both Sound FX parameters and Instrument parameters, which differed in name and text only. - SetLoopCommand sets the ruler loop of a pattern or a song. It replaces SetPatternLoopCommand and SetSongLoopCommand. - addLink in music/routing is the one rule for a link that both the song routing and the Master routing keep. - eqCurves works out each band and their sum for the EQ tab, which did that in its drawing code. It replaces eqCurveDb, which only a test called. - Smaller ones: the eight neighbour directions of a tile cell, and drawFloatingBox for the shadowed box of Popup and FloatWindow. - Left on purpose: Play pattern and Play song stay two parallel node definitions, and the smaller clones under ten lines stay. Architecture: - SoundLibrary.ts goes from 2897 to 2188 lines. What a stage of a sound FX becomes as Web Audio nodes, and how the knobs of a playing voice move, is now viewport/fxNodes.ts. None of it keeps state of the library. Dead code (TS language service, references per export and member): - soundRefIds, LFO_SHAPE_INDEX, TREMOLO_ROWS, VIBRATO_ROWS and REVERB_ROWS had no reader. The four routing node defs are registered without an unused exported name. - soundFileOf and portTypeOf were called by tests only. The tests now ask findSound and portOf, which the editor uses. DRY moves from src into the one test that uses it. - 51 values used only in their own file lose their `export`. Types and the node catalogues stay exported. - Kept on purpose: neighboursOf is the cell by cell reading the indexed neighboursIn is checked against, and PitchShifter.latency is the test's one view of how late the shifter is. Comments and docs: - Seven comments told history ("no longer", "any more", "as before", "of before #354"). Nine comment blocks ran far past the line width. Proof that this changed no code: the bundle was md5 identical, and the touched tests and e2e modules were identical after esbuild. - README: sound FX, instrument, pattern, song and bus in the asset list, the pages Instruments, Patterns and Songs, 1919 checks. - Wiki: see its own commit. Tests: Gate (melektaus-atx) 274 files, 4236 tests, CHECK EXIT 0 e2e 34, 64, 65 ALL PASSED, 180 checks Unit, touched areas 16 files, 804 tests No check was added, the e2e sum stays at 1919. Counter-checks, each put back by copy and compared with cmp: - addLink without the loop rule: 2 tests fail, one per routing. - eqCurves with the sum of the last band only: 1 test fails. - Start in the worklet never waiting: e2e 34 fails in exactly the four checks that hang on a voice's first sample (Flanger, Tremolo, Chip, a pitched note planned ahead). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.9 KiB
TypeScript
67 lines
2.9 KiB
TypeScript
import { MIDDLE_C } from '../../../instrument/notes';
|
||
import { heldTempo } from '../../../music/time';
|
||
import type { NodeDef } from '../../NodeRegistry';
|
||
import { asBoolean, asNumber, asString } from '../../values';
|
||
import { detachedPort, exec, fxParamsPort, num, playedBusPort, soundFxPort, withDefault } from '../shared';
|
||
import { fxParamsOf, tempoPort } from './PlaySound';
|
||
|
||
export const PlayNote: NodeDef = {
|
||
type: 'PlayNote',
|
||
label: 'Play note',
|
||
category: 'action',
|
||
description:
|
||
'Plays one note of an instrument asset. "note" is its number as MIDI counts it: 60 is C4, 61 C#4, 72 C5. "velocity" is how hard it is struck, 0 to 1 – it makes the note quieter and is handed to what the instrument does with it. "duration" is how many seconds until the note is released; at 0 it is held until a Stop sound ends it. A note belongs to this object like a sound and stops when the object is destroyed, unless "detached" is on. "params" takes values for the parameters of the instrument from an Instrument parameters node. "fx" sends the note through a sound FX on top of what the instrument does; left empty, the one the instrument names, and None through none. "fx params" takes values for its parameters from a Sound FX parameters node – the two sets stay apart. "voice" is the number of this note, for Set sound FX parameters and Stop sound; 0 where the instrument plays nothing for it. "tempo" is what a Delay in the instrument synced to beats counts by, in quarter notes a minute. "bus" is the bus it is heard on; left empty, the one the instrument names.',
|
||
inputs: [
|
||
exec(),
|
||
{
|
||
key: 'instrument',
|
||
label: 'instrument',
|
||
type: 'string',
|
||
field: {
|
||
key: 'instrument',
|
||
label: 'Instrument',
|
||
kind: 'asset',
|
||
default: '',
|
||
assetTypes: ['instrument'],
|
||
},
|
||
},
|
||
{
|
||
key: 'note',
|
||
label: 'note',
|
||
type: 'number',
|
||
default: MIDDLE_C,
|
||
field: { key: 'note', label: 'Note', kind: 'number', default: MIDDLE_C, min: 0, max: 127, step: 1 },
|
||
},
|
||
withDefault(num('velocity'), 1),
|
||
withDefault(num('volume'), 1),
|
||
withDefault(num('duration'), 0),
|
||
detachedPort(),
|
||
fxParamsPort('fxParams', 'params'),
|
||
tempoPort(),
|
||
{ ...soundFxPort(), key: 'soundFx' },
|
||
fxParamsPort('soundFxParams'),
|
||
playedBusPort(),
|
||
],
|
||
outputs: [exec(), num('voice')],
|
||
params: [],
|
||
run: (ctx, inputs) => {
|
||
const instrument = asString(inputs.instrument);
|
||
const voice = instrument
|
||
? ctx.playNote(
|
||
instrument,
|
||
asNumber(inputs.note),
|
||
asNumber(inputs.velocity),
|
||
asNumber(inputs.volume),
|
||
asNumber(inputs.duration),
|
||
asBoolean(inputs.detached),
|
||
fxParamsOf(inputs.fxParams),
|
||
heldTempo(asNumber(inputs.tempo)),
|
||
asString(inputs.soundFx),
|
||
fxParamsOf(inputs.soundFxParams),
|
||
asString(inputs.bus),
|
||
)
|
||
: 0;
|
||
return { next: 'exec', outputs: { voice } };
|
||
},
|
||
};
|