Skip to content

Commit

Permalink
fix: move reset attach to each single panel
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Nov 21, 2024
1 parent 4299288 commit 9de6cc2
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 136 deletions.
3 changes: 1 addition & 2 deletions source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ PluginProcessor::PluginProcessor()
static_cast<size_t>(state.getRawParameterValue(zlState::ffTOrder::ID)->load())]),
filtersAttach(*this, parameters, parametersNA, controller),
soloAttach(*this, parameters, controller),
choreAttach(*this, parameters, parametersNA, controller),
resetAttach(*this, parameters, parametersNA, controller) {
choreAttach(*this, parameters, parametersNA, controller) {
}

PluginProcessor::~PluginProcessor() = default;
Expand Down
1 change: 0 additions & 1 deletion source/PluginProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class PluginProcessor : public juce::AudioProcessor {
zlDSP::FiltersAttach<double> filtersAttach;
zlDSP::SoloAttach<double> soloAttach;
zlDSP::ChoreAttach<double> choreAttach;
zlDSP::ResetAttach<double> resetAttach;
juce::AudioBuffer<double> doubleBuffer;
std::atomic<bool> isMono{false};
std::atomic<int> mainInChannelNum{2}, auxInChannelNum{2};
Expand Down
1 change: 0 additions & 1 deletion source/dsp/dsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
#include "filters_attach.hpp"
#include "solo_attach.hpp"
#include "chore_attach.hpp"
#include "reset_attach.hpp"

#endif //ZLEqualizer_DSP_H
5 changes: 4 additions & 1 deletion source/dsp/filters_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace zlDSP {
for (auto &ID: IDs) {
parameterRef.addParameterListener(ID + suffix, this);
}
parameterNARef.addParameterListener(zlState::active::ID + suffix, this);
}
parameterNARef.addParameterListener(zlState::maximumDB::ID, this);
}
Expand Down Expand Up @@ -146,7 +147,9 @@ namespace zlDSP {
}
const auto idx = static_cast<size_t>(parameterID.getTrailingIntValue());
auto value = static_cast<FloatType>(newValue);
if (parameterID.startsWith(bypass::ID)) {
if (parameterID.startsWith(zlState::active::ID)) {
controllerRef.setIsActive(idx, newValue > .5f);
} else if (parameterID.startsWith(bypass::ID)) {
controllerRef.setBypass(idx, newValue > .5f);
} else if (parameterID.startsWith(fType::ID)) {
const auto fType = static_cast<zlFilter::FilterType>(value);
Expand Down
65 changes: 0 additions & 65 deletions source/dsp/reset_attach.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions source/dsp/reset_attach.hpp

This file was deleted.

92 changes: 92 additions & 0 deletions source/panel/curve_panel/single_panel/reset_attach.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (C) 2024 - zsliu98
// This file is part of ZLEqualizer
//
// ZLEqualizer 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.
//
// ZLEqualizer 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.
//
// You should have received a copy of the GNU Affero General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef ZLPANEL_RESET_ATTACH_HPP
#define ZLPANEL_RESET_ATTACH_HPP

#include "../../../dsp/dsp.hpp"

namespace zlPanel {
class ResetAttach final : private juce::AudioProcessorValueTreeState::Listener,
private juce::AsyncUpdater {
public:
explicit ResetAttach(const size_t bandIdx,
juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA,
zlDSP::Controller<double> &controller)
: idx(bandIdx), parametersRef(parameters), parametersNARef(parametersNA), controllerRef(controller) {
parametersRef.addParameterListener(zlDSP::appendSuffix(zlDSP::bypass::ID, idx), this);
parametersNARef.addParameterListener(zlState::appendSuffix(zlState::active::ID, idx), this);
}

~ResetAttach() override {
parametersRef.removeParameterListener(zlDSP::appendSuffix(zlDSP::bypass::ID, idx), this);
parametersNARef.removeParameterListener(zlState::appendSuffix(zlState::active::ID, idx), this);
}

private:
size_t idx;
juce::AudioProcessorValueTreeState &parametersRef;
juce::AudioProcessorValueTreeState &parametersNARef;
zlDSP::Controller<double> &controllerRef;
std::atomic<bool> toActive;

constexpr static std::array resetIDs{
zlDSP::solo::ID, zlDSP::sideSolo::ID,
zlDSP::dynamicON::ID, zlDSP::dynamicLearn::ID,
zlDSP::threshold::ID, zlDSP::kneeW::ID, zlDSP::attack::ID, zlDSP::release::ID,
zlDSP::bypass::ID, zlDSP::fType::ID, zlDSP::slope::ID, zlDSP::lrType::ID
};

inline const static std::array resetDefaultVs{
zlDSP::solo::convertTo01(zlDSP::solo::defaultV),
zlDSP::sideSolo::convertTo01(zlDSP::sideSolo::defaultV),
zlDSP::dynamicON::convertTo01(zlDSP::dynamicON::defaultV),
zlDSP::dynamicLearn::convertTo01(zlDSP::dynamicLearn::defaultV),
zlDSP::threshold::convertTo01(zlDSP::threshold::defaultV),
zlDSP::kneeW::convertTo01(zlDSP::kneeW::defaultV),
zlDSP::attack::convertTo01(zlDSP::attack::defaultV),
zlDSP::release::convertTo01(zlDSP::release::defaultV),
zlDSP::bypass::convertTo01(zlDSP::bypass::defaultV),
zlDSP::fType::convertTo01(zlDSP::fType::defaultI),
zlDSP::slope::convertTo01(zlDSP::slope::defaultI),
zlDSP::lrType::convertTo01(zlDSP::lrType::defaultI),
};

void parameterChanged(const juce::String &parameterID, float newValue) override {
if (parameterID.startsWith(zlDSP::bypass::ID) && newValue < .5f) {
toActive.store(true);
triggerAsyncUpdate();
} else if (parameterID.startsWith(zlState::active::ID) && newValue < .5f) {
toActive.store(false);
triggerAsyncUpdate();
}
}

void handleAsyncUpdate() override {
if (toActive.load()) {
auto *para = parametersNARef.getParameter(zlState::appendSuffix(zlState::active::ID, idx));
para->beginChangeGesture();
para->setValueNotifyingHost(zlState::active::convertTo01(true));
para->endChangeGesture();
} else {
const auto suffix = zlState::appendSuffix("", idx);
for (size_t j = 0; j < resetDefaultVs.size(); ++j) {
const auto resetID = resetIDs[j] + suffix;
auto *para = parametersRef.getParameter(resetID);
para->beginChangeGesture();
para->setValueNotifyingHost(resetDefaultVs[j]);
para->endChangeGesture();
}
}
}
};
}

#endif //ZLPANEL_RESET_ATTACH_HPP
13 changes: 13 additions & 0 deletions source/panel/curve_panel/single_panel/sidefq_attach.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2024 - zsliu98
// This file is part of ZLEqualizer
//
// ZLEqualizer 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.
//
// ZLEqualizer 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.
//
// You should have received a copy of the GNU Affero General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef SIDEFQ_ATTACH_HPP
#define SIDEFQ_ATTACH_HPP

#endif //SIDEFQ_ATTACH_HPP
13 changes: 7 additions & 6 deletions source/panel/curve_panel/single_panel/single_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace zlPanel {
zlFilter::Ideal<double, 16> &mainFilter)
: idx(bandIdx), parametersRef(parameters), parametersNARef(parametersNA),
uiBase(base), controllerRef(controller),
resetAttach(bandIdx, parameters, parametersNA, controller),
baseF(baseFilter), targetF(targetFilter), mainF(mainFilter),
sidePanel(bandIdx, parameters, parametersNA, base, controller) {
curvePath.preallocateSpace(static_cast<int>(zlFilter::frequencies.size() * 3 + 12));
Expand Down Expand Up @@ -67,7 +68,7 @@ namespace zlPanel {
}

void SinglePanel::paint(juce::Graphics &g) {
if (!actived.load()) {
if (!active.load()) {
return;
}
auto thickness = selected.load() ? uiBase.getFontSize() * 0.15f : uiBase.getFontSize() * 0.075f;
Expand Down Expand Up @@ -164,7 +165,7 @@ namespace zlPanel {
selected.store(static_cast<size_t>(newValue) == idx);
} else {
if (parameterID.startsWith(zlState::active::ID)) {
actived.store(newValue > .5f);
active.store(newValue > .5f);
baseFreq.store(10.0);
baseGain.store(0.0);
} else if (parameterID.startsWith(zlDSP::dynamicON::ID)) {
Expand Down Expand Up @@ -217,7 +218,7 @@ namespace zlPanel {
baseGain.store(static_cast<double>(baseF.getGain())); {
baseF.updateMagnitude(ws);
curvePath.clear();
if (actived.load()) {
if (active.load()) {
drawCurve(curvePath, baseF.getDBs(), maxDB, bound);
centeredDB.store(static_cast<float>(baseF.getDB(0.0001308996938995747 * baseFreq.load())));
} else {
Expand All @@ -229,10 +230,10 @@ namespace zlPanel {
// draw shadow
{
shadowPath.clear();
if (actived.load()) {
if (active.load()) {
drawCurve(shadowPath, baseF.getDBs(), maxDB, bound);
}
if (actived.load() && selected.load()) {
if (active.load() && selected.load()) {
switch (baseF.getFilterType()) {
case zlFilter::FilterType::peak:
case zlFilter::FilterType::lowShelf:
Expand Down Expand Up @@ -261,7 +262,7 @@ namespace zlPanel {
// draw dynamic shadow
{
dynPath.clear();
if (dynON.load() && actived.load()) {
if (dynON.load() && active.load()) {
drawCurve(dynPath, baseF.getDBs(), maxDB, bound);
targetF.updateMagnitude(ws);
drawCurve(dynPath, targetF.getDBs(), maxDB, bound, true, false);
Expand Down
7 changes: 5 additions & 2 deletions source/panel/curve_panel/single_panel/single_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "../helpers.hpp"
#include "../../../state/state_definitions.hpp"
#include "side_panel.hpp"
#include "reset_attach.hpp"
#include "sidefq_attach.hpp"

namespace zlPanel {
class SinglePanel final : public juce::Component,
Expand Down Expand Up @@ -63,11 +65,12 @@ namespace zlPanel {

size_t idx;
juce::AudioProcessorValueTreeState &parametersRef, &parametersNARef;

zlInterface::UIBase &uiBase;
std::atomic<bool> dynON, selected, actived;
zlDSP::Controller<double> &controllerRef;
zlPanel::ResetAttach resetAttach;
zlFilter::Ideal<double, 16> &baseF, &targetF, &mainF;

std::atomic<bool> dynON, selected, active;
std::atomic<float> maximumDB;
AtomicBound atomicBound;

Expand Down

0 comments on commit 9de6cc2

Please sign in to comment.