Skip to content

Commit f3f8d3e

Browse files
committed
Swapped where the filters are applied, renamed them to eq filter and note filter.
1 parent c9943b7 commit f3f8d3e

File tree

5 files changed

+506
-421
lines changed

5 files changed

+506
-421
lines changed

editor/FilterEditor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class FilterEditor {
3333
);
3434
private readonly _pointRadius: number = 2;
3535

36-
private _useDistortionFilter: boolean = false;
36+
private _useNoteFilter: boolean = false;
3737
private _touchMode: boolean = false;
3838
private _mouseX: number = 0;
3939
private _mouseY: number = 0;
@@ -56,8 +56,8 @@ export class FilterEditor {
5656
private _renderedPointGains: number = -1;
5757
//private _renderedKey: number = -1;
5858

59-
constructor(private _doc: SongDocument, useDistortionFilter: boolean = false) {
60-
this._useDistortionFilter = useDistortionFilter;
59+
constructor(private _doc: SongDocument, useNoteFilter: boolean = false) {
60+
this._useNoteFilter = useNoteFilter;
6161
/*
6262
for (let i: number = 0; i < Config.filterFreqRange * Config.filterFreqStep; i++) {
6363
this._octaves.appendChild(SVG.rect({fill: ColorConfig.tonic, x: i * this._editorWidth / (Config.filterFreqRange * Config.filterFreqStep) - 0.5, y: 0, width: 1, height: this._editorHeight}));
@@ -351,7 +351,7 @@ export class FilterEditor {
351351

352352
public render(): void {
353353
const instrument: Instrument = this._doc.song.channels[this._doc.channel].instruments[this._doc.getCurrentInstrument()];
354-
const filterSettings: FilterSettings = this._useDistortionFilter ? instrument.distortionFilter : instrument.filter;
354+
const filterSettings: FilterSettings = this._useNoteFilter ? instrument.noteFilter : instrument.eqFilter;
355355
if (this._filterSettings != filterSettings) {
356356
this._dragChange = null;
357357
this._mouseDown = false;

editor/SongEditor.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C) 2020 John Nesky, distributed under the MIT license.
22

3-
import {InstrumentType, EffectType, Config, getPulseWidthRatio, effectsIncludeDistortion, effectsIncludeBitcrusher, effectsIncludePanning, effectsIncludeReverb} from "../synth/SynthConfig";
3+
import {InstrumentType, EffectType, Config, getPulseWidthRatio, effectsIncludeNoteFilter, effectsIncludeDistortion, effectsIncludeBitcrusher, effectsIncludePanning, effectsIncludeReverb} from "../synth/SynthConfig";
44
import {Preset, PresetCategory, EditorConfig, isMobile, prettyNumber} from "./EditorConfig";
55
import {ColorConfig} from "./ColorConfig";
66
import {Layout} from "./Layout";
@@ -200,10 +200,10 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
200200
private readonly _transitionRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("transition")}, "Transition:"), div({class: "selectContainer"}, this._transitionSelect));
201201
private readonly _effectsDisplayOption: HTMLOptionElement = option({selected: true, disabled: true, hidden: false}, "Preferences"); // todo: "hidden" should be true but looks wrong on mac chrome, adds checkmark next to first visible option even though it's not selected. :(
202202
private readonly _effectsSelect: HTMLSelectElement = select(this._effectsDisplayOption);
203-
private readonly _filterEditor: FilterEditor = new FilterEditor(this._doc);
204-
private readonly _filterRow: HTMLElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("filter")}, "Filter:"), this._filterEditor.container);
205-
private readonly _distortionFilterEditor: FilterEditor = new FilterEditor(this._doc, true);
206-
private readonly _distortionFilterRow: HTMLElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("distortionFilter")}, "Post-Filter:"), this._distortionFilterEditor.container);
203+
private readonly _eqFilterEditor: FilterEditor = new FilterEditor(this._doc);
204+
private readonly _eqFilterRow: HTMLElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("eqFilter")}, "EQ Filter:"), this._eqFilterEditor.container);
205+
private readonly _noteFilterEditor: FilterEditor = new FilterEditor(this._doc, true);
206+
private readonly _noteFilterRow: HTMLElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("noteFilter")}, "Note Filter:"), this._noteFilterEditor.container);
207207
private readonly _filterEnvelopeSelect: HTMLSelectElement = buildOptions(select(), Config.envelopes.map(envelope=>envelope.name));
208208
private _filterEnvelopeRow: HTMLDivElement = div({class: "selectRow", title: "Low-pass Filter Envelope"}, span({class: "tip", onclick: ()=>this._openPrompt("filterEnvelope")}, "Filter Env:"), div({class: "selectContainer"}, this._filterEnvelopeSelect));
209209
private readonly _pulseEnvelopeSelect: HTMLSelectElement = buildOptions(select(), Config.envelopes.map(envelope=>envelope.name));
@@ -213,9 +213,9 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
213213
private readonly _distortionSlider: Slider = new Slider(input({style: "margin: 0;", type: "range", min: "0", max: Config.distortionRange - 1, value: "0", step: "1"}), this._doc, (oldValue: number, newValue: number) => new ChangeDistortion(this._doc, oldValue, newValue));
214214
private _distortionRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("distortion")}, "Distortion:"), this._distortionSlider.input);
215215
private readonly _bitcrusherQuantizationSlider: Slider = new Slider(input({style: "margin: 0;", type: "range", min: "0", max: Config.bitcrusherQuantizationRange - 1, value: "0", step: "1"}), this._doc, (oldValue: number, newValue: number) => new ChangeBitcrusherQuantization(this._doc, oldValue, newValue));
216-
private _bitcrusherQuantizationRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("bitcrusherQuantization")}, "Bitcrusher:"), this._bitcrusherQuantizationSlider.input);
216+
private _bitcrusherQuantizationRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("bitcrusherQuantization")}, "Bit Crush:"), this._bitcrusherQuantizationSlider.input);
217217
private readonly _bitcrusherFreqSlider: Slider = new Slider(input({style: "margin: 0;", type: "range", min: "0", max: Config.bitcrusherFreqRange - 1, value: "0", step: "1"}), this._doc, (oldValue: number, newValue: number) => new ChangeBitcrusherFreq(this._doc, oldValue, newValue));
218-
private _bitcrusherFreqRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("bitcrusherFreq")}, "Bitcrush Freq:"), this._bitcrusherFreqSlider.input);
218+
private _bitcrusherFreqRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("bitcrusherFreq")}, "Freq Crush:"), this._bitcrusherFreqSlider.input);
219219
private readonly _sustainSlider: Slider = new Slider(input({style: "margin: 0;", type: "range", min: "0", max: Config.sustainRange - 1, value: "0", step: "1"}), this._doc, (oldValue: number, newValue: number) => new ChangeSustain(this._doc, oldValue, newValue));
220220
private _sustainRow: HTMLDivElement = div({class: "selectRow"}, span({class: "tip", onclick: ()=>this._openPrompt("sustain")}, "Sustain:"), this._sustainSlider.input);
221221
private readonly _intervalSelect: HTMLSelectElement = buildOptions(select(), Config.intervals.map(interval=>interval.name));
@@ -245,8 +245,7 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
245245
"Customize Instrument",
246246
);
247247
private readonly _customInstrumentSettingsGroup: HTMLDivElement = div({class: "editor-controls"},
248-
this._filterRow,
249-
this._filterEnvelopeRow,
248+
this._eqFilterRow,
250249
this._transitionRow,
251250
this._chordSelectRow,
252251
this._vibratoSelectRow,
@@ -267,8 +266,9 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
267266
span({class: "tip", onclick: ()=>this._openPrompt("effects")}, "Effects:"),
268267
div({class: "selectContainer"}, this._effectsSelect),
269268
),
269+
this._noteFilterRow,
270+
this._filterEnvelopeRow,
270271
this._distortionRow,
271-
this._distortionFilterRow,
272272
this._bitcrusherQuantizationRow,
273273
this._bitcrusherFreqRow,
274274
this._panSliderRow,
@@ -491,8 +491,8 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
491491
this._patternArea.addEventListener("mousedown", this._refocusStage);
492492
this._trackArea.addEventListener("mousedown", this._refocusStage);
493493
this._spectrumEditor.container.addEventListener("mousedown", this._refocusStage);
494-
this._filterEditor.container.addEventListener("mousedown", this._refocusStage);
495-
this._distortionFilterEditor.container.addEventListener("mousedown", this._refocusStage);
494+
this._eqFilterEditor.container.addEventListener("mousedown", this._refocusStage);
495+
this._noteFilterEditor.container.addEventListener("mousedown", this._refocusStage);
496496
this._harmonicsEditor.container.addEventListener("mousedown", this._refocusStage);
497497
this._tempoStepper.addEventListener("keydown", this._tempoStepperCaptureNumberKeys, false);
498498
this.mainLayer.addEventListener("keydown", this._whenKeyPressed);
@@ -709,7 +709,6 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
709709
this._drumsetGroup.style.display = "";
710710
this._transitionRow.style.display = "none";
711711
this._chordSelectRow.style.display = "none";
712-
this._filterEnvelopeRow.style.display = "none";
713712
for (let i: number = 0; i < Config.drumCount; i++) {
714713
setSelectedValue(this._drumsetEnvelopeSelects[i], instrument.drumsetEnvelopes[i]);
715714
this._drumsetSpectrumEditors[i].render();
@@ -718,7 +717,6 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
718717
this._drumsetGroup.style.display = "none";
719718
this._transitionRow.style.display = "";
720719
this._chordSelectRow.style.display = "";
721-
this._filterEnvelopeRow.style.display = "";
722720
}
723721
if (instrument.type == InstrumentType.chip) {
724722
this._chipWaveSelectRow.style.display = "";
@@ -774,14 +772,21 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
774772
this._pulseWidthRow.style.display = "none";
775773
}
776774

775+
if (effectsIncludeNoteFilter(instrument.effects)) {
776+
this._noteFilterRow.style.display = "";
777+
this._noteFilterEditor.render();
778+
this._filterEnvelopeRow.style.display = "";
779+
setSelectedValue(this._filterEnvelopeSelect, instrument.filterEnvelope);
780+
} else {
781+
this._noteFilterRow.style.display = "none";
782+
this._filterEnvelopeRow.style.display = "none";
783+
}
784+
777785
if (effectsIncludeDistortion(instrument.effects)) {
778786
this._distortionRow.style.display = "";
779787
this._distortionSlider.updateValue(instrument.distortion);
780-
this._distortionFilterRow.style.display = "";
781-
this._distortionFilterEditor.render();
782788
} else {
783789
this._distortionRow.style.display = "none";
784-
this._distortionFilterRow.style.display = "none";
785790
}
786791

787792
if (effectsIncludeBitcrusher(instrument.effects)) {
@@ -862,8 +867,7 @@ import {ChangeTempo, ChangeReverb, ChangeVolume, ChangePan, ChangePatternSelecti
862867

863868
this._instrumentSettingsGroup.style.color = ColorConfig.getChannelColor(this._doc.song, this._doc.channel).primaryNote;
864869

865-
this._filterEditor.render();
866-
setSelectedValue(this._filterEnvelopeSelect, instrument.filterEnvelope);
870+
this._eqFilterEditor.render();
867871
setSelectedValue(this._transitionSelect, instrument.transition);
868872
setSelectedValue(this._vibratoSelect, instrument.vibrato);
869873
setSelectedValue(this._intervalSelect, instrument.interval);

editor/changes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ import {SongDocument} from "./SongDocument";
407407
peakPoint.freq = selectCurvedDistribution(0, Config.filterFreqRange - 1, FilterControlPoint.getRoundedSettingValueFromHz(500.0), 1.0 / Config.filterFreqStep);
408408
peakPoint.gain = selectCurvedDistribution(0, Config.filterGainRange - 1, Config.filterGainCenter, 2.0 / Config.filterGainStep);
409409
}
410-
instrument.filter.controlPointCount = 0;
410+
instrument.eqFilter.controlPointCount = 0;
411411
for (let i: number = 0; i < addingPoints.length; i++) {
412412
const point: FilterControlPoint = addingPoints[i];
413413
let alreadyUsed: boolean = false;
@@ -419,8 +419,8 @@ import {SongDocument} from "./SongDocument";
419419
}
420420
if (alreadyUsed) break;
421421
if (point.type == FilterType.peak && point.gain == Config.filterGainCenter) break;
422-
instrument.filter.controlPoints[instrument.filter.controlPointCount] = point;
423-
instrument.filter.controlPointCount++;
422+
instrument.eqFilter.controlPoints[instrument.eqFilter.controlPointCount] = point;
423+
instrument.eqFilter.controlPointCount++;
424424
}
425425

426426
if (isNoise) {

synth/SynthConfig.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ SOFTWARE.
6666
panning = 2,
6767
distortion = 3,
6868
bitcrusher = 4,
69+
noteFilter = 5,
6970
length,
7071
}
7172

@@ -277,8 +278,8 @@ SOFTWARE.
277278
{name: "bowed", spread: 0.02, offset: 0.0, expression: 1.0, sign:-1.0},
278279
{name: "piano", spread: 0.01, offset: 0.0, expression: 1.0, sign: 0.7},
279280
]);
280-
public static readonly effectsNames: ReadonlyArray<string> = ["reverb", "chorus", "panning", "distortion", "bitcrusher"];
281-
public static readonly effectOrder: ReadonlyArray<EffectType> = [EffectType.distortion, EffectType.bitcrusher, EffectType.panning, EffectType.chorus, EffectType.reverb];
281+
public static readonly effectsNames: ReadonlyArray<string> = ["reverb", "chorus", "panning", "distortion", "bitcrusher", "note filter"];
282+
public static readonly effectOrder: ReadonlyArray<EffectType> = [EffectType.noteFilter, EffectType.distortion, EffectType.bitcrusher, EffectType.panning, EffectType.chorus, EffectType.reverb];
282283
public static readonly volumeRange: number = 8;
283284
public static readonly volumeLogScale: number = -0.5;
284285
public static readonly panCenter: number = 4;
@@ -571,6 +572,10 @@ SOFTWARE.
571572
return result;
572573
}
573574

575+
export function effectsIncludeNoteFilter(effects: number): boolean {
576+
return (effects & (1 << EffectType.noteFilter)) != 0;
577+
}
578+
574579
export function effectsIncludeDistortion(effects: number): boolean {
575580
return (effects & (1 << EffectType.distortion)) != 0;
576581
}

0 commit comments

Comments
 (0)