Skip to content

Commit

Permalink
fix(side panel): sync line position with side dragger
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 28, 2024
1 parent 5bc8233 commit 9bced50
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 66 deletions.
6 changes: 5 additions & 1 deletion source/panel/curve_panel/curve_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace zlPanel {
const auto idx = zlState::bandNUM - i - 1;
singlePanels[i] =
std::make_unique<SinglePanel>(idx, parametersRef, parametersNARef, base, controllerRef,
baseFilters[idx], targetFilters[idx], mainFilters[idx]);
baseFilters[idx], targetFilters[idx], mainFilters[idx],
buttonPanel.getSideDragger(idx));
addAndMakeVisible(*singlePanels[i]);
}
addAndMakeVisible(sumPanel);
Expand Down Expand Up @@ -126,6 +127,9 @@ namespace zlPanel {
if ((nowT - currentT).inMilliseconds() > uiBase.getRefreshRateMS() * refreshRateMul) {
buttonPanel.updateDraggers();
conflictPanel.updateGradient();
for (const auto &panel : singlePanels) {
panel->updateDragger();
}
repaint();
currentT = nowT;
}
Expand Down
59 changes: 22 additions & 37 deletions source/panel/curve_panel/single_panel/side_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@
#include "side_panel.hpp"

namespace zlPanel {
SidePanel::SidePanel(size_t bandIdx, juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA, zlInterface::UIBase &base,
zlDSP::Controller<double> &controller)
SidePanel::SidePanel(const size_t bandIdx,
juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA,
zlInterface::UIBase &base,
zlDSP::Controller<double> &controller,
zlInterface::Dragger &sideDragger)
: idx(bandIdx),
parametersRef(parameters), parametersNARef(parametersNA),
uiBase(base),
sideF(controller.getFilter(bandIdx).getSideFilter()) {
sideF(controller.getFilter(bandIdx).getSideFilter()),
sideDraggerRef(sideDragger) {
setInterceptsMouseClicks(false, false);
const std::string suffix = zlDSP::appendSuffix("", idx);
skipRepaint.store(true);
parameterChanged(zlDSP::dynamicON::ID + suffix,
parametersRef.getRawParameterValue(zlDSP::dynamicON::ID + suffix)->load());
parameterChanged(zlDSP::sideFreq::ID + suffix,
parametersRef.getRawParameterValue(zlDSP::sideFreq::ID + suffix)->load());
parameterChanged(zlDSP::sideQ::ID + suffix,
parametersRef.getRawParameterValue(zlDSP::sideQ::ID + suffix)->load());
parameterChanged(zlState::selectedBandIdx::ID,
parametersNARef.getRawParameterValue(zlState::selectedBandIdx::ID)->load());
parameterChanged(zlState::active::ID + suffix,
parametersNARef.getRawParameterValue(zlState::active::ID + suffix)->load());
skipRepaint.store(false);

for (auto &id: changeIDs) {
parametersRef.addParameterListener(id + suffix, this);
}
parametersNARef.addParameterListener(zlState::selectedBandIdx::ID, this);
parametersNARef.addParameterListener(zlState::active::ID + suffix, this);
update();
lookAndFeelChanged();
}

Expand All @@ -51,27 +50,16 @@ namespace zlPanel {
}

void SidePanel::paint(juce::Graphics &g) {
if (!selected.load() || !actived.load() || !dynON.load()) {
if (!isVisible()) {
return;
}
if (toUpdate.exchange(false)) {
update();
}
auto bound = getLocalBounds().toFloat();
bound = bound.withSizeKeepingCentre(bound.getWidth(), bound.getHeight() - 4 * uiBase.getFontSize());
const auto x1 = scale1.load() * bound.getWidth();
const auto x2 = scale2.load() * bound.getWidth();

const auto x = static_cast<float>(sideDraggerRef.getButton().getBounds().getCentreX());
const auto thickness = uiBase.getFontSize() * 0.15f;
g.setColour(colour);
g.drawLine(x1, bound.getBottom(), x2, bound.getBottom(), thickness);
}

bool SidePanel::checkRepaint() {
if (toRepaint.exchange(false)) {
return true;
}
return false;
g.drawLine(x - currentBW, bound.getBottom(), x + currentBW, bound.getBottom(), thickness);
}

void SidePanel::parameterChanged(const juce::String &parameterID, float newValue) {
Expand All @@ -82,27 +70,24 @@ namespace zlPanel {
actived.store(newValue > .5f);
} else if (parameterID.startsWith(zlDSP::dynamicON::ID)) {
dynON.store(newValue > .5f);
} else if (parameterID.startsWith(zlDSP::sideFreq::ID)) {
sideFreq.store(newValue);
toUpdate.store(true);
} else if (parameterID.startsWith(zlDSP::sideQ::ID)) {
sideQ.store(newValue);
toUpdate.store(true);
}
}
if (!skipRepaint.load()) {
toRepaint.store(true);
}
}

void SidePanel::update() {
const auto q = sideQ.load(), freq = sideFreq.load();
const auto bw = 2 * std::asinh(0.5f / q) / std::log(2.f);
const auto scale = std::pow(2.f, bw / 2.f);
const auto freq1 = freq / scale, freq2 = freq * scale;

scale1.store(std::log(static_cast<float>(freq1) / 10.f) / std::log(2200.f));
scale2.store(std::log(static_cast<float>(freq2) / 10.f) / std::log(2200.f));
void SidePanel::updateDragger() {
if (!selected.load() || !actived.load() || !dynON.load()) {
setVisible(false);
return;
} else {
setVisible(true);
}
if (toUpdate.exchange(false)) {
const auto bw = std::asinh(0.5f / sideQ.load());
currentBW = static_cast<float>(bw) / std::log(2200.f) * getLocalBounds().toFloat().getWidth();
}
}

void SidePanel::lookAndFeelChanged() {
Expand Down
18 changes: 8 additions & 10 deletions source/panel/curve_panel/single_panel/side_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,36 @@ namespace zlPanel {
juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA,
zlInterface::UIBase &base,
zlDSP::Controller<double> &controller);
zlDSP::Controller<double> &controller,
zlInterface::Dragger &sideDragger);

~SidePanel() override;

void paint(juce::Graphics &g) override;

bool checkRepaint();

void lookAndFeelChanged() override;

void updateDragger();

private:
size_t idx;
juce::AudioProcessorValueTreeState &parametersRef, &parametersNARef;
zlInterface::UIBase &uiBase;
zlFilter::IIR<double, zlDSP::Controller<double>::FilterSize> &sideF;
zlInterface::Dragger &sideDraggerRef;
std::atomic<bool> dynON, selected, actived;
std::atomic<bool> toRepaint{false};

static constexpr std::array changeIDs{
zlDSP::dynamicON::ID, zlDSP::sideFreq::ID, zlDSP::sideQ::ID
zlDSP::dynamicON::ID, zlDSP::sideQ::ID
};

juce::Colour colour;

std::atomic<double> sideFreq{1000.0}, sideQ{0.707};
std::atomic<float> scale1{.5f}, scale2{.5f};
std::atomic<bool> skipRepaint{false};
std::atomic<double> sideQ{0.707};
std::atomic<bool> toUpdate{false};
float currentBW;

void parameterChanged(const juce::String &parameterID, float newValue) override;

void update();
};
} // zlPanel

Expand Down
13 changes: 0 additions & 13 deletions source/panel/curve_panel/single_panel/sidefq_attach.hpp

This file was deleted.

7 changes: 4 additions & 3 deletions source/panel/curve_panel/single_panel/single_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ namespace zlPanel {
zlDSP::Controller<double> &controller,
zlFilter::Ideal<double, 16> &baseFilter,
zlFilter::Ideal<double, 16> &targetFilter,
zlFilter::Ideal<double, 16> &mainFilter)
zlFilter::Ideal<double, 16> &mainFilter,
zlInterface::Dragger &sideDragger)
: idx(bandIdx), parametersRef(parameters), parametersNARef(parametersNA),
uiBase(base), controllerRef(controller),
resetAttach(bandIdx, parameters, parametersNA),
baseF(baseFilter), targetF(targetFilter), mainF(mainFilter),
sidePanel(bandIdx, parameters, parametersNA, base, controller) {
sidePanel(bandIdx, parameters, parametersNA, base, controller, sideDragger) {
curvePath.preallocateSpace(static_cast<int>(zlFilter::frequencies.size() * 3 + 12));
shadowPath.preallocateSpace(static_cast<int>(zlFilter::frequencies.size() * 3 + 12));
dynPath.preallocateSpace(static_cast<int>(zlFilter::frequencies.size() * 6 + 12));
Expand Down Expand Up @@ -157,7 +158,7 @@ namespace zlPanel {
} else if (toRepaint.exchange(false)) {
return true;
}
return sidePanel.checkRepaint();
return false;
}

void SinglePanel::parameterChanged(const juce::String &parameterID, float newValue) {
Expand Down
8 changes: 6 additions & 2 deletions source/panel/curve_panel/single_panel/single_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#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 All @@ -29,7 +28,8 @@ namespace zlPanel {
zlDSP::Controller<double> &controller,
zlFilter::Ideal<double, 16> &baseFilter,
zlFilter::Ideal<double, 16> &targetFilter,
zlFilter::Ideal<double, 16> &mainFilter);
zlFilter::Ideal<double, 16> &mainFilter,
zlInterface::Dragger &sideDragger);

~SinglePanel() override;

Expand Down Expand Up @@ -58,6 +58,10 @@ namespace zlPanel {

void lookAndFeelChanged() override;

void updateDragger() {
sidePanel.updateDragger();
}

private:
juce::Path curvePath, shadowPath, dynPath;
juce::Path recentCurvePath, recentShadowPath, recentDynPath;
Expand Down

0 comments on commit 9bced50

Please sign in to comment.