|
| 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_dynamic_attach.hpp" |
| 11 | + |
| 12 | +namespace zlp { |
| 13 | + FilterDynamicAttach::FilterDynamicAttach(juce::AudioProcessor& processor, |
| 14 | + juce::AudioProcessorValueTreeState& parameters, |
| 15 | + Controller& controller, size_t idx) : |
| 16 | + parameters_(parameters), |
| 17 | + controller_(controller), |
| 18 | + idx_(idx) { |
| 19 | + for (size_t i = 0; i < kIDs.size(); ++i) { |
| 20 | + const auto ID = kIDs[i] + std::to_string(idx_); |
| 21 | + parameters_.addParameterListener(ID, this); |
| 22 | + parameterChanged(ID, parameters.getRawParameterValue(ID)->load(std::memory_order::relaxed)); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + FilterDynamicAttach::~FilterDynamicAttach() { |
| 27 | + for (size_t i = 0; i < kIDs.size(); ++i) { |
| 28 | + parameters_.removeParameterListener(kIDs[i] + std::to_string(idx_), this); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + void FilterDynamicAttach::parameterChanged(const juce::String& parameter_ID, const float value) { |
| 33 | + if (parameter_ID.startsWith(PDynamicON::kID)) { |
| 34 | + controller_.setDynamicON(idx_, value > .5f); |
| 35 | + } else if (parameter_ID.startsWith(PDynamicBypass::kID)) { |
| 36 | + controller_.setDynamicBypass(idx_, value > .5f); |
| 37 | + } else if (parameter_ID.startsWith(PDynamicMode::kID)) { |
| 38 | + controller_.setDynamicMode(idx_, static_cast<DynamicMode>(std::round(value))); |
| 39 | + } else if (parameter_ID.startsWith(PThresholdAbs::kID)) { |
| 40 | + controller_.setSpecThresholdAbs(idx_, value); |
| 41 | + } else if (parameter_ID.startsWith(PThresholdBand::kID)) { |
| 42 | + controller_.setSpecThresholdBand(idx_, value); |
| 43 | + } else if (parameter_ID.startsWith(PThresholdRel::kID)) { |
| 44 | + controller_.setSpecThresholdRel(idx_, value); |
| 45 | + } else if (parameter_ID.startsWith(PKneeW::kID)) { |
| 46 | + controller_.setSpecKnee(idx_, value); |
| 47 | + } else if (parameter_ID.startsWith(PAttack::kID)) { |
| 48 | + controller_.setSpecAttack(idx_, value); |
| 49 | + } else if (parameter_ID.startsWith(PRelease::kID)) { |
| 50 | + controller_.setSpecRelease(idx_, value); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments