From 423ddb16752fb8e2be8f8181d97e23bd24f5a993 Mon Sep 17 00:00:00 2001 From: ascpixi <44982772+ascpixi@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:05:11 +0100 Subject: [PATCH] chore: replace more ctors with initializers --- src/graph.ts | 6 +----- src/nodes/ChorusNode.tsx | 2 +- src/nodes/FilterNode.tsx | 16 ++++++---------- src/nodes/LfoNode.tsx | 15 ++++----------- src/nodes/MixNode.tsx | 13 ++----------- src/nodes/PentatonicChordsNode.tsx | 2 +- src/nodes/PentatonicMelodyNode.tsx | 2 +- src/nodes/ReverbNode.tsx | 14 +++++--------- src/nodes/SamplerNode.tsx | 2 +- src/nodes/SynthNode.tsx | 8 ++------ 10 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/graph.ts b/src/graph.ts index 4ac9d3b..6165466 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -325,11 +325,7 @@ export class GraphForwarder { * For each note generator-to-instrument connection, stores the previous * notes (in MIDI pitches) that were active in the previous pulse. */ - private prevNoteMap: Map; - - constructor() { - this.prevNoteMap = new Map(); - } + private prevNoteMap: Map = new Map(); /** * Traces the given graph, forwarding Vestige-generated data to out-of-graph diff --git a/src/nodes/ChorusNode.tsx b/src/nodes/ChorusNode.tsx index 5902fbe..372c563 100644 --- a/src/nodes/ChorusNode.tsx +++ b/src/nodes/ChorusNode.tsx @@ -57,7 +57,7 @@ export class ChorusAudioEffect implements AudioEffect { wet: 0.4 }); - constructor () { + constructor() { this.chorus.start(); } diff --git a/src/nodes/FilterNode.tsx b/src/nodes/FilterNode.tsx index fd8451a..8a3a2fa 100644 --- a/src/nodes/FilterNode.tsx +++ b/src/nodes/FilterNode.tsx @@ -40,7 +40,12 @@ export class FilterNodeData extends EffectNodeData { }; export class FilterAudioEffect implements AudioEffect { - filter: tone.Filter; + filter: tone.Filter = new tone.Filter({ + frequency: cutoffScalarToHz(0.5), + Q: scalarToResonance(0.5), + rolloff: -24, + type: "lowpass" + }); connectTo(dst: AudioDestination): void { dst.accept(this.filter); @@ -59,15 +64,6 @@ export class FilterAudioEffect implements AudioEffect { assert(handleId == SIGNAL_INPUT_HID_MAIN, `Unknown signal input handle ID ${handleId}`); return unaryAudioDestination(this.filter); } - - constructor() { - this.filter = new tone.Filter({ - frequency: cutoffScalarToHz(0.5), - Q: scalarToResonance(0.5), - rolloff: -24, - type: "lowpass" - }); - } } export class FilterNodeSerializer implements NodeDataSerializer { diff --git a/src/nodes/LfoNode.tsx b/src/nodes/LfoNode.tsx index 4919b38..18159a3 100644 --- a/src/nodes/LfoNode.tsx +++ b/src/nodes/LfoNode.tsx @@ -39,10 +39,10 @@ export class LfoNodeData extends ValueNodeData { }; export class LfoValueGenerator implements ValueGenerator { - shape: LfoShape; - frequency: number; - min: number; - max: number; + shape: LfoShape = "sine"; + frequency: number = 1; + min: number = 0; + max: number = 1; generate(time: number): number { switch (this.shape) { @@ -54,13 +54,6 @@ export class LfoValueGenerator implements ValueGenerator { return scale(biToUni(lfoSaw(time, this.frequency)), this.min, this.max); } } - - constructor() { - this.shape = "sine"; - this.frequency = 1; - this.min = 0; - this.max = 1; - } } export class LfoNodeSerializer implements NodeDataSerializer { diff --git a/src/nodes/MixNode.tsx b/src/nodes/MixNode.tsx index dddae3d..f13e2f4 100644 --- a/src/nodes/MixNode.tsx +++ b/src/nodes/MixNode.tsx @@ -17,16 +17,11 @@ const INPUT_A = signalInHandleId("a"); const INPUT_B = signalInHandleId("b"); export class MixNodeData extends EffectNodeData { - effect: MixAudioEffect; - - constructor() { - super(); - this.effect = new MixAudioEffect(); - } + effect = new MixAudioEffect(); }; export class MixAudioEffect implements AudioEffect { - gain: tone.Gain; + gain = new tone.Gain(); inputA?: tone.ToneAudioNode; inputB?: tone.ToneAudioNode; @@ -47,10 +42,6 @@ export class MixAudioEffect implements AudioEffect { assert(handleId == INPUT_A || handleId == INPUT_B, `Unknown signal input handle ID ${handleId}`); return unaryAudioDestination(this.gain); } - - constructor() { - this.gain = new tone.Gain(); - } } export class MixNodeSerializer extends NullNodeDataSerializer { diff --git a/src/nodes/PentatonicChordsNode.tsx b/src/nodes/PentatonicChordsNode.tsx index 444232a..9a0f102 100644 --- a/src/nodes/PentatonicChordsNode.tsx +++ b/src/nodes/PentatonicChordsNode.tsx @@ -22,7 +22,7 @@ export class PentatonicChordsGenerator implements PlainNoteGenerator { seedOffset: number; lastNotes: number[] = []; - constructor( + constructor ( public chordLength: number = 6, public minNotes: number = 4, public maxNotes: number = 6, diff --git a/src/nodes/PentatonicMelodyNode.tsx b/src/nodes/PentatonicMelodyNode.tsx index 6195ac5..24e0688 100644 --- a/src/nodes/PentatonicMelodyNode.tsx +++ b/src/nodes/PentatonicMelodyNode.tsx @@ -21,7 +21,7 @@ export class PentatonicMelodyGenerator implements PlainNoteGenerator { offset: number; lastNotes: number[] = []; - constructor( + constructor ( public density: number = 50, public octave: number = 4, public pitchRange: number = 6, diff --git a/src/nodes/ReverbNode.tsx b/src/nodes/ReverbNode.tsx index 907c519..e9526a0 100644 --- a/src/nodes/ReverbNode.tsx +++ b/src/nodes/ReverbNode.tsx @@ -47,7 +47,11 @@ export class ReverbNodeData extends EffectNodeData { }; export class ReverbAudioEffect implements AudioEffect { - reverb: tone.Reverb; + reverb: tone.Reverb = new tone.Reverb({ + decay: 4.00, + preDelay: 20 / 1000, + wet: 0.5 + }); connectTo(dst: AudioDestination): void { dst.accept(this.reverb); @@ -66,14 +70,6 @@ export class ReverbAudioEffect implements AudioEffect { assert(handleId == SIGNAL_INPUT_HID_MAIN, `Unknown signal input handle ID ${handleId}`); return unaryAudioDestination(this.reverb); } - - constructor() { - this.reverb = new tone.Reverb({ - decay: 4.00, - preDelay: 20 / 1000, - wet: 0.5 - }); - } } export class ReverbNodeSerializer implements NodeDataSerializer { diff --git a/src/nodes/SamplerNode.tsx b/src/nodes/SamplerNode.tsx index 1831209..7ea8801 100644 --- a/src/nodes/SamplerNode.tsx +++ b/src/nodes/SamplerNode.tsx @@ -70,7 +70,7 @@ export class SamplerAudioGenerator implements AudioGenerator { this.sampler.connect(this.out); } - constructor () { + constructor() { this.sampler.connect(this.out); } diff --git a/src/nodes/SynthNode.tsx b/src/nodes/SynthNode.tsx index 7a90f63..f76d75a 100644 --- a/src/nodes/SynthNode.tsx +++ b/src/nodes/SynthNode.tsx @@ -70,7 +70,7 @@ export class SynthNodeData extends InstrumentNodeData { this.generator.synth.set({ envelope: env }); } - constructor () { + constructor() { super(); this.generator = new SynthAudioGenerator(); @@ -84,15 +84,11 @@ export class SynthNodeData extends InstrumentNodeData { }; export class SynthAudioGenerator implements AudioGenerator { - synth: tone.PolySynth; + synth = new tone.PolySynth(tone.Synth, { oscillator: { type: this.waveform} }); private _waveform: Waveform = "sine"; private _unisonSpread: number = 20; private _unisonCount: number = 1; - constructor() { - this.synth = new tone.PolySynth(tone.Synth, { oscillator: { type: this.waveform} }); - } - /** Fully applies oscillator settings, changing its type. May produce audible clicks. */ private fullyApplyOsc() { if (this._unisonCount > 1) {