Skip to content

Commit 6f012a4

Browse files
committed
feat(zlp): add filter attach
1 parent fe738b5 commit 6f012a4

5 files changed

Lines changed: 122 additions & 0 deletions

File tree

source/PluginProcessor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ PluginProcessor::PluginProcessor() :
2929
zlstate::getNAParameterLayout()),
3030
controller_(*this),
3131
a_bypass_(*parameters_.getRawParameterValue(zlp::PBypass::kID)) {
32+
for (size_t i = 0; i < zlp::kBandNum; ++i) {
33+
filter_attachments_[i] = std::make_unique<zlp::FilterAttach>(*this, parameters_, controller_, i);
34+
}
3235
}
3336

3437
PluginProcessor::~PluginProcessor() = default;

source/PluginProcessor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class PluginProcessor final : public juce::AudioProcessor {
7474

7575
private:
7676
zlp::Controller controller_;
77+
std::array<std::unique_ptr<zlp::FilterAttach>, zlp::kBandNum> filter_attachments_;
78+
7779
std::atomic<double> sample_rate_{48000.0};
7880
std::atomic<float>& a_bypass_;
7981

source/zlp/filter_attach.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) 2026 - zsliu98
2+
// This file is part of ZLSpectrumEqualizer
3+
//
4+
// ZLSpectrumEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 as published by the Free Software Foundation.
5+
//
6+
// ZLSpectrumEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
7+
//
8+
// You should have received a copy of the GNU Affero General Public License along with ZLSpectrumEqualizer. If not, see <https://www.gnu.org/licenses/>.
9+
10+
#include "filter_attach.hpp"
11+
12+
namespace zlp {
13+
FilterAttach::FilterAttach(juce::AudioProcessor&,
14+
juce::AudioProcessorValueTreeState& parameters,
15+
Controller& controller, const size_t idx) :
16+
parameters_(parameters),
17+
controller_(controller),
18+
idx_(idx),
19+
empty_(controller.getEmptyFilters()[idx]),
20+
scale_(*parameters.getRawParameterValue(PGainScale::kID)),
21+
gain_(*parameters.getRawParameterValue(PGain::kID + std::to_string(idx))),
22+
empty_update_flag_(controller.getEmptyUpdateFlags()[idx]),
23+
spec_update_flag_(controller.getSpecResponseUpdateFlag()),
24+
whole_update_flag_(controller.getUpdateFlag()) {
25+
for (size_t i = 0; i < kIDs.size(); ++i) {
26+
const auto ID = kIDs[i] + std::to_string(idx_);
27+
parameters_.addParameterListener(ID, this);
28+
parameterChanged(ID, parameters.getRawParameterValue(ID)->load(std::memory_order::relaxed));
29+
}
30+
parameters_.addParameterListener(PGainScale::kID, this);
31+
}
32+
33+
FilterAttach::~FilterAttach() {
34+
for (size_t i = 0; i < kIDs.size(); ++i) {
35+
parameters_.removeParameterListener(kIDs[i] + std::to_string(idx_), this);
36+
}
37+
parameters_.removeParameterListener(PGainScale::kID, this);
38+
}
39+
40+
void FilterAttach::parameterChanged(const juce::String& parameter_ID, const float value) {
41+
if (parameter_ID.startsWith(PFilterStatus::kID)) {
42+
controller_.setFilterStatus(idx_, static_cast<FilterStatus>(std::round(value)));
43+
} else if (parameter_ID.startsWith(PFilterType::kID)) {
44+
empty_.setFilterType(static_cast<zldsp::filter::FilterType>(std::round(value)));
45+
signal();
46+
} else if (parameter_ID.startsWith(POrder::kID)) {
47+
empty_.setOrder(POrder::kOrderArray[static_cast<size_t>(std::round(value))]);
48+
signal();
49+
} else if (parameter_ID.startsWith(PLRMode::kID)) {
50+
controller_.setLRMS(idx_, static_cast<FilterStereo>(std::round(value)));
51+
} else if (parameter_ID.startsWith(PFreq::kID)) {
52+
empty_.setFreq(value);
53+
signal();
54+
} else if (parameter_ID.startsWith(PGain::kID)) {
55+
empty_.setGain(std::clamp(value * (scale_.load(std::memory_order::relaxed) / 100.f), -30.f, 30.f));
56+
signal();
57+
} else if (parameter_ID.startsWith(PQ::kID)) {
58+
empty_.setQ(value);
59+
signal();
60+
} else if (parameter_ID.startsWith(PGainScale::kID)) {
61+
empty_.setGain(std::clamp(gain_.load(std::memory_order::relaxed) * (value / 100.f), -30.f, 30.f));
62+
signal();
63+
}
64+
}
65+
66+
void FilterAttach::signal() {
67+
empty_update_flag_.signal();
68+
spec_update_flag_.signal();
69+
whole_update_flag_.signal();
70+
}
71+
}

source/zlp/filter_attach.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2026 - zsliu98
2+
// This file is part of ZLSpectrumEqualizer
3+
//
4+
// ZLSpectrumEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 as published by the Free Software Foundation.
5+
//
6+
// ZLSpectrumEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
7+
//
8+
// You should have received a copy of the GNU Affero General Public License along with ZLSpectrumEqualizer. If not, see <https://www.gnu.org/licenses/>.
9+
10+
#pragma once
11+
12+
#include "controller.hpp"
13+
#include "juce_helper/para_updater.hpp"
14+
15+
namespace zlp {
16+
class FilterAttach final : private juce::AudioProcessorValueTreeState::Listener {
17+
public:
18+
explicit FilterAttach(juce::AudioProcessor& processor,
19+
juce::AudioProcessorValueTreeState& parameters,
20+
Controller& controller,
21+
size_t idx);
22+
23+
~FilterAttach() override;
24+
25+
private:
26+
juce::AudioProcessorValueTreeState& parameters_;
27+
Controller& controller_;
28+
size_t idx_;
29+
zldsp::filter::Empty& empty_;
30+
std::atomic<float>& scale_;
31+
std::atomic<float>& gain_;
32+
zlchore::thread::Notifier& empty_update_flag_;
33+
zlchore::thread::Notifier& spec_update_flag_;
34+
zlchore::thread::Notifier& whole_update_flag_;
35+
36+
static constexpr std::array kIDs{
37+
PFilterStatus::kID, PFilterType::kID, POrder::kID, PLRMode::kID,
38+
PFreq::kID, PGain::kID, PQ::kID,
39+
};
40+
41+
void parameterChanged(const juce::String& parameter_ID, float value) override;
42+
43+
void signal();
44+
};
45+
}

source/zlp/zlp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111

1212
#include "zlp_definitions.hpp"
1313
#include "controller.hpp"
14+
#include "filter_attach.hpp"

0 commit comments

Comments
 (0)