Refactoring round 10: split SoundLibrary, fold sound duplicates (#85)
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>
This commit is contained in:
1 parent
76f5097a38
commit
25084f8576
72 files changed
+1369
-1458
No files matched your search
@@ -117,7 +117,7 @@ describe('the nodes of the master routing (#351)', () => {
|
||||
);
|
||||
expect(f.linksOf(f.create('song', 'Outro'))).toEqual([reverb]);
|
||||
expect(f.linksOf(f.create('pattern', 'Riff')).sort()).toEqual([drums, reverb].sort());
|
||||
// A bus goes to the master as before.
|
||||
// A new bus goes to the master only.
|
||||
expect(f.linksOf(f.create('bus', 'Delay'))).toEqual([MASTER_BUS]);
|
||||
// Undone, a new asset takes its links along.
|
||||
const links = f.project.routing.edges.length;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
type EqBand,
|
||||
eqBandDb,
|
||||
eqBandsOf,
|
||||
eqCurveDb,
|
||||
eqCurves,
|
||||
MAX_EQ_BANDS,
|
||||
withBandSet,
|
||||
} from '../../src/core/soundfx/parametricEq';
|
||||
@@ -91,9 +91,13 @@ describe('the bands of a Parametric EQ', () => {
|
||||
expect(eqBandDb(shelf, 200)).toBeCloseTo(3, 1);
|
||||
expect(eqBandDb(band({ type: 'notch' }), 1000)).toBeLessThan(-60);
|
||||
|
||||
// Together they add up in dB.
|
||||
const both = [peak, shelf];
|
||||
expect(eqCurveDb(both, 300)).toBeCloseTo(eqBandDb(peak, 300) + eqBandDb(shelf, 300), 6);
|
||||
// Together they add up in dB; a band that does nothing is drawn but not counted.
|
||||
const flat = band({ type: 'peaking', frequency: 300, gain: 0 });
|
||||
const curves = eqCurves([peak, flat, shelf], [300, 3000]);
|
||||
expect(curves.bands[1]).toHaveLength(2);
|
||||
expect(curves.bands[2]![0]).toBeCloseTo(eqBandDb(shelf, 300), 6);
|
||||
expect(curves.sum[0]).toBeCloseTo(eqBandDb(peak, 300) + eqBandDb(shelf, 300), 6);
|
||||
expect(curves.sum[1]).toBeCloseTo(eqBandDb(peak, 3000) + eqBandDb(shelf, 3000), 6);
|
||||
});
|
||||
|
||||
it('fills a curve that crosses 0 dB with one shape for each side, meeting on the line', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { CreateAssetCommand, SetAssetPropertyCommand } from '../../src/core/commands/assetCommands';
|
||||
import { SetPatternLoopCommand, SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { SetLoopCommand, SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { namedNotes } from '../../src/core/instrument/compile';
|
||||
import { starterInstrumentGraph } from '../../src/core/instrument/nodes';
|
||||
import type { PatternAsset } from '../../src/core/model/Asset';
|
||||
@@ -137,12 +137,12 @@ describe('pattern asset (#333)', () => {
|
||||
it('loops the whole pattern until a loop is set, and a loop is cut at its end', () => {
|
||||
const f = makePattern();
|
||||
expect(patternLoop(f.pattern())).toEqual({ start: 0, end: 7680 });
|
||||
f.stack.execute(new SetPatternLoopCommand(f.id, { start: 1920, end: 9600 }));
|
||||
f.stack.execute(new SetLoopCommand('pattern', f.id, { start: 1920, end: 9600 }));
|
||||
expect(f.pattern().loop).toEqual({ start: 1920, end: 9600 });
|
||||
expect(patternLoop(f.pattern())).toEqual({ start: 1920, end: 7680 });
|
||||
f.set('bars', 1);
|
||||
expect(patternLoop(f.pattern())).toEqual({ start: 0, end: 1920 });
|
||||
f.stack.execute(new SetPatternLoopCommand(f.id, null));
|
||||
f.stack.execute(new SetLoopCommand('pattern', f.id, null));
|
||||
expect(f.pattern().loop).toBeUndefined();
|
||||
f.stack.undo();
|
||||
expect(f.pattern().loop).toEqual({ start: 1920, end: 9600 });
|
||||
@@ -153,7 +153,7 @@ describe('pattern asset (#333)', () => {
|
||||
f.stack.execute(
|
||||
new SetPatternNotesCommand(f.id, [note('a', 0, 120, 36, 1), note('b', 240, 60, 38, 0.25)]),
|
||||
);
|
||||
f.stack.execute(new SetPatternLoopCommand(f.id, { start: 0, end: 960 }));
|
||||
f.stack.execute(new SetLoopCommand('pattern', f.id, { start: 0, end: 960 }));
|
||||
f.set('grid', '1/8T');
|
||||
const back = roundTrip(f.project).assets.find((a) => a.id === f.id) as PatternAsset;
|
||||
expect(back.notes).toEqual(f.pattern().notes);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
type GraphNode,
|
||||
type PortDef,
|
||||
portsCompatible,
|
||||
portTypeOf,
|
||||
portOf,
|
||||
resolveDef,
|
||||
} from '../../src/core/graph';
|
||||
import { graphLookup } from '../../src/core/model/graphLookup';
|
||||
@@ -112,8 +112,8 @@ describe('First not empty, whose a, b and value carry the same value', () => {
|
||||
|
||||
expect(f.behavior.graph.edges.filter((e) => e.to.node === join.id)).toHaveLength(1);
|
||||
const lookup = graphLookup(f.project);
|
||||
const out = portTypeOf(f.behavior.graph, { nodeId: node.id, port: 'value', isOutput: true }, lookup)!;
|
||||
const inp = portTypeOf(f.behavior.graph, { nodeId: join.id, port: 'text', isOutput: false }, lookup)!;
|
||||
const out = portOf(f.behavior.graph, { nodeId: node.id, port: 'value', isOutput: true }, lookup)!.type;
|
||||
const inp = portOf(f.behavior.graph, { nodeId: join.id, port: 'text', isOutput: false }, lookup)!.type;
|
||||
expect(portsCompatible(out, inp)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -142,12 +142,12 @@ describe('Select, whose false, true and value carry the same value', () => {
|
||||
]);
|
||||
const play = f.edit.addNode('PlayAnimation');
|
||||
const lookup = graphLookup(f.project);
|
||||
const out = portTypeOf(f.behavior.graph, { nodeId: node.id, port: 'value', isOutput: true }, lookup)!;
|
||||
const inp = portTypeOf(
|
||||
const out = portOf(f.behavior.graph, { nodeId: node.id, port: 'value', isOutput: true }, lookup)!.type;
|
||||
const inp = portOf(
|
||||
f.behavior.graph,
|
||||
{ nodeId: play.id, port: 'animation', isOutput: false },
|
||||
lookup,
|
||||
)!;
|
||||
)!.type;
|
||||
expect(portsCompatible(out, inp)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -291,9 +291,9 @@ describe('a type handed on through several nodes with a shared group (#210)', ()
|
||||
]);
|
||||
const lookup = () => graphLookup(f.project);
|
||||
const out = () =>
|
||||
portTypeOf(f.behavior.graph, { nodeId: second.id, port: 'value', isOutput: true }, lookup())!;
|
||||
portOf(f.behavior.graph, { nodeId: second.id, port: 'value', isOutput: true }, lookup())!.type;
|
||||
const inp = () =>
|
||||
portTypeOf(f.behavior.graph, { nodeId: sub.id, port: 'text', isOutput: false }, lookup())!;
|
||||
portOf(f.behavior.graph, { nodeId: sub.id, port: 'text', isOutput: false }, lookup())!.type;
|
||||
expect(portsCompatible(out(), inp())).toBe(true);
|
||||
|
||||
f.edit.wire([
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
CreateSoundCommand,
|
||||
SetAssetPropertyCommand,
|
||||
} from '../../src/core/commands/assetCommands';
|
||||
import { SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { SetSongCommand, SetSongLoopCommand } from '../../src/core/commands/songCommands';
|
||||
import { SetLoopCommand, SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { SetSongCommand } from '../../src/core/commands/songCommands';
|
||||
import type { InstrumentAsset, SongAsset } from '../../src/core/model/Asset';
|
||||
import { goesBy, Playbacks, type SequencePlay } from '../../src/core/music/playbacks';
|
||||
import { INTERVAL, LEAD, type ScheduledClip, type ScheduledNote } from '../../src/core/music/Scheduler';
|
||||
@@ -230,7 +230,7 @@ function playingSong(params: Record<string, string | number | boolean> = {}) {
|
||||
],
|
||||
}),
|
||||
);
|
||||
f.stack.execute(new SetSongLoopCommand(id, { start: BAR, end: 2 * BAR }));
|
||||
f.stack.execute(new SetLoopCommand('song', id, { start: BAR, end: 2 * BAR }));
|
||||
const behavior = makeBehavior(f, 'Logic');
|
||||
const box = place(f, f.spriteId, { x: 0, y: 0 });
|
||||
place(f, behavior.id, { x: 0, y: 0 }, box);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { CreateAssetCommand, SetAssetPropertyCommand } from '../../src/core/commands/assetCommands';
|
||||
import { SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { SetSongCommand, SetSongLoopCommand } from '../../src/core/commands/songCommands';
|
||||
import { SetLoopCommand, SetPatternNotesCommand } from '../../src/core/commands/patternCommands';
|
||||
import { SetSongCommand } from '../../src/core/commands/songCommands';
|
||||
import type { PatternAsset, SongAsset } from '../../src/core/model/Asset';
|
||||
import {
|
||||
heldSongItems,
|
||||
@@ -118,7 +118,7 @@ describe('the song asset (#334)', () => {
|
||||
f.lay(f.item({ tick: 4 * BAR, length: 100 }));
|
||||
expect(songLength(f.song())).toBe(5 * BAR);
|
||||
expect(songLoop(f.song())).toEqual({ start: 0, end: 5 * BAR });
|
||||
f.stack.execute(new SetSongLoopCommand(f.song().id, { start: BAR, end: 2 * BAR }));
|
||||
f.stack.execute(new SetLoopCommand('song', f.song().id, { start: BAR, end: 2 * BAR }));
|
||||
expect(songLoop(f.song())).toEqual({ start: BAR, end: 2 * BAR });
|
||||
f.stack.undo();
|
||||
expect(f.song().loop).toBeUndefined();
|
||||
@@ -160,7 +160,7 @@ describe('the song asset (#334)', () => {
|
||||
|
||||
const f = makeSong();
|
||||
f.lay(f.item({ tick: BAR, length: BAR, transpose: -2, volume: -6 }));
|
||||
f.stack.execute(new SetSongLoopCommand(f.song().id, { start: 0, end: BAR }));
|
||||
f.stack.execute(new SetLoopCommand('song', f.song().id, { start: 0, end: BAR }));
|
||||
const back = roundTrip(f.project).assets.find((a) => a.id === f.song().id) as SongAsset;
|
||||
expect([back.tracks, back.items, back.loop]).toEqual([f.song().tracks, f.song().items, f.song().loop]);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,6 @@ import { assetRefChoices } from '../../src/core/properties/assetRef';
|
||||
import { compileSoundFx, soundFxBuildFor } from '../../src/core/soundfx/compile';
|
||||
import {
|
||||
dampingCutoff,
|
||||
DRY,
|
||||
EMPTY_PLAN,
|
||||
type FxChain,
|
||||
fxChainOf,
|
||||
@@ -50,6 +49,9 @@ import {
|
||||
const FILE = `${'a1'.repeat(32)}.wav`;
|
||||
const OTHER_FILE = `${'b2'.repeat(32)}.wav`;
|
||||
|
||||
/** What a sound with no FX goes through. */
|
||||
const DRY: FxChain = { pitch: 0, shifted: false, stages: [] };
|
||||
|
||||
/** The level of a gain or filter stage. */
|
||||
const gainOf = (stage: FxStage | undefined) => (stage && 'gain' in stage ? stage.gain : undefined);
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
cutRange,
|
||||
FADE_CURVES,
|
||||
fadeGain,
|
||||
findSound,
|
||||
isSoundFile,
|
||||
parseCutName,
|
||||
soundFileOf,
|
||||
} from '../../src/core/model/sound';
|
||||
import { assetRefChoices } from '../../src/core/properties/assetRef';
|
||||
import { schemaFor } from '../../src/core/properties/PropertySchema';
|
||||
@@ -175,13 +175,13 @@ describe('the sound asset', () => {
|
||||
|
||||
it('resolves to a file, and to none when the id is unset, dangling or of another type', () => {
|
||||
const s = makeSound();
|
||||
expect(soundFileOf(s.project, s.sound.id)).toBe(FILE);
|
||||
expect(soundFileOf(s.project, '')).toBe('');
|
||||
expect(soundFileOf(s.project, 'no-such-asset')).toBe('');
|
||||
expect(findSound(s.project, s.sound.id)?.asset.file).toBe(FILE);
|
||||
expect(findSound(s.project, '')).toBeNull();
|
||||
expect(findSound(s.project, 'no-such-asset')).toBeNull();
|
||||
|
||||
const text = new CreateAssetCommand('text', 'Title');
|
||||
s.stack.execute(text);
|
||||
expect(soundFileOf(s.project, text.asset.id)).toBe('');
|
||||
expect(findSound(s.project, text.asset.id)).toBeNull();
|
||||
});
|
||||
|
||||
it('is what a sound picker offers, and nothing else is', () => {
|
||||
|
||||
Reference in new issue
Block a user