Skip to content

Commit

Permalink
fix(solo panel): improve solo focus
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 27, 2024
1 parent 8c86fc8 commit da8bd55
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 31 deletions.
6 changes: 6 additions & 0 deletions source/dsp/chore/para_updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace zlChore {
triggerAsyncUpdate();
}

void updateSync(const float paraValue) {
para->beginChangeGesture();
para->setValueNotifyingHost(paraValue);
para->endChangeGesture();
}

private:
juce::RangedAudioParameter *para;
std::atomic<float> value;
Expand Down
4 changes: 3 additions & 1 deletion source/dsp/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ namespace zlDSP {

void setSolo(size_t idx, bool isSide);

inline bool getSolo() const { return useSolo.load(); }
bool getSolo() const { return useSolo.load(); }

bool getSoloIsSide() const { return soloSide.load(); }

void clearSolo(size_t idx, bool isSide);

Expand Down
8 changes: 8 additions & 0 deletions source/panel/curve_panel/button_panel/button_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ namespace zlPanel {

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

zlInterface::Dragger &getDragger(const size_t idx) const {
return panels[idx]->getDragger();
}

zlInterface::Dragger &getSideDragger(const size_t idx) const {
return panels[idx]->getSideDragger();
}

void updateDraggers() const {
for (const auto &p: panels) {
p->getDragger().updateButton();
Expand Down
2 changes: 1 addition & 1 deletion source/panel/curve_panel/curve_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace zlPanel {
fftPanel(controllerRef.getAnalyzer(), base),
conflictPanel(controllerRef.getConflictAnalyzer(), base),
sumPanel(parametersRef, base, controllerRef, baseFilters, mainFilters),
soloPanel(parametersRef, parametersNARef, base, controllerRef),
buttonPanel(processorRef, base),
soloPanel(parametersRef, parametersNARef, base, controllerRef, buttonPanel),
matchPanel(processor.getController().getMatchAnalyzer(), parametersNARef, base),
currentT(juce::Time::getCurrentTime()),
vblank(this, [this]() { repaintCallBack(); }) {
Expand Down
2 changes: 1 addition & 1 deletion source/panel/curve_panel/curve_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace zlPanel {
FFTPanel fftPanel;
ConflictPanel conflictPanel;
SumPanel sumPanel;
SoloPanel soloPanel;
ButtonPanel buttonPanel;
SoloPanel soloPanel;
std::array<std::unique_ptr<SinglePanel>, zlState::bandNUM> singlePanels;
MatchPanel matchPanel;
juce::Time currentT;
Expand Down
92 changes: 69 additions & 23 deletions source/panel/curve_panel/sum_panel/solo_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,92 @@

namespace zlPanel {
SoloPanel::SoloPanel(juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA, zlInterface::UIBase &base,
zlDSP::Controller<double> &controller)
: parametersRef(parameters), uiBase(base),
juce::AudioProcessorValueTreeState &parametersNA,
zlInterface::UIBase &base,
zlDSP::Controller<double> &controller,
ButtonPanel &buttonPanel)
: parametersRef(parameters), parametersNARef(parametersNA),
uiBase(base),
soloF(controller.getSoloFilter()),
controllerRef(controller) {
controllerRef(controller), buttonPanelRef(buttonPanel) {
juce::ignoreUnused(parametersRef, parametersNA);
parametersNARef.addParameterListener(zlState::selectedBandIdx::ID, this);
for (size_t i = 0; i < zlDSP::bandNUM; ++i) {
soloUpdaters.emplace_back(std::make_unique<zlChore::ParaUpdater>(
parametersRef, zlDSP::appendSuffix(zlDSP::solo::ID, i)));
sideSoloUpdaters.emplace_back(std::make_unique<zlChore::ParaUpdater>(
parametersRef, zlDSP::appendSuffix(zlDSP::sideSolo::ID, i)));
}
selectBandIdx.store(static_cast<size_t>(
parametersNARef.getRawParameterValue(zlState::selectedBandIdx::ID)->load()));
handleAsyncUpdate();
}

SoloPanel::~SoloPanel() = default;
SoloPanel::~SoloPanel() {
parametersNARef.removeParameterListener(zlState::selectedBandIdx::ID, this);
}

void SoloPanel::paint(juce::Graphics &g) {
if (!controllerRef.getSolo()) {
return;
}
if (std::abs(soloF.getFreq() - soloFreq) >= 0.001 || std::abs(soloF.getQ() - soloQ) >= 0.001) {
const size_t bandIdx = selectBandIdx.load();
const auto x = buttonPanelRef.getDragger(selectBandIdx.load()).getButton().getBounds().getCentreX();
if (std::abs(x - currentX) >= 0.001 || std::abs(soloF.getQ() - soloQ) >= 0.001) {
currentX = x;
handleAsyncUpdate();
}
auto bound = getLocalBounds().toFloat();
bound = bound.withSizeKeepingCentre(bound.getWidth(), bound.getHeight());
const auto x1 = scale1 * bound.getWidth();
const auto x2 = scale2 * bound.getWidth();

const auto width = bound.getWidth();
const auto leftArea = bound.removeFromLeft(x1);
const auto rightArea = bound.removeFromRight(width - x2);

g.setColour(uiBase.getTextColor().withAlpha(.1f));
g.fillRect(leftArea);
g.fillRect(rightArea);
auto bound = getLocalBounds().toFloat();
if (controllerRef.getSoloIsSide()) {
} else {
const auto &f = controllerRef.getMainIdealFilter(bandIdx);
switch (f.getFilterType()) {
case zlFilter::highPass:
case zlFilter::lowShelf: {
bound = bound.removeFromLeft(currentX);
g.fillRect(bound);
break;
}
case zlFilter::lowPass:
case zlFilter::highShelf: {
bound.removeFromLeft(currentX);
g.fillRect(bound);
break;
}
case zlFilter::tiltShelf: {
break;
}
case zlFilter::peak:
case zlFilter::bandShelf:
case zlFilter::bandPass:
case zlFilter::notch: {
const auto boundWidth = bound.getWidth();
const auto leftWidth = currentX - currentBW * boundWidth;
const auto rightWidth = boundWidth - currentX - currentBW * boundWidth;
const auto leftArea = bound.removeFromLeft(leftWidth);
const auto rightArea = bound.removeFromRight(rightWidth);
g.fillRect(leftArea);
g.fillRect(rightArea);
}
}
}
}

void SoloPanel::handleAsyncUpdate() {
soloFreq = soloF.getFreq();
soloQ = soloF.getQ();
const auto bw = 2 * std::asinh(0.5f / soloQ) / std::log(2.f);
const auto scale = std::pow(2.f, bw / 2.f);
const auto freq1 = soloFreq / scale, freq2 = soloFreq * scale;
const auto bw = std::asinh(0.5f / soloQ);
currentBW = static_cast<float>(bw) / std::log(2200.f);
}

scale1 = std::log(static_cast<float>(freq1) / 10.f) / std::log(2200.f);
scale2 = std::log(static_cast<float>(freq2) / 10.f) / std::log(2200.f);
void SoloPanel::parameterChanged(const juce::String &parameterID, const float newValue) {
juce::ignoreUnused(parameterID);
const auto previousBandIdx = selectBandIdx.load();
const auto currentBandIdx = static_cast<size_t>(newValue);
if (previousBandIdx != currentBandIdx) {
soloUpdaters[previousBandIdx]->update(0.f);
sideSoloUpdaters[previousBandIdx]->update(0.f);
}
selectBandIdx.store(currentBandIdx);
}
} // zlPanel
18 changes: 13 additions & 5 deletions source/panel/curve_panel/sum_panel/solo_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,36 @@

#include "../../../dsp/dsp.hpp"
#include "../../../gui/gui.hpp"
#include "../button_panel/button_panel.hpp"

namespace zlPanel {
class SoloPanel final : public juce::Component {
class SoloPanel final : public juce::Component,
private juce::AudioProcessorValueTreeState::Listener {
public:
SoloPanel(juce::AudioProcessorValueTreeState &parameters,
juce::AudioProcessorValueTreeState &parametersNA,
zlInterface::UIBase &base,
zlDSP::Controller<double> &controller);
zlDSP::Controller<double> &controller,
ButtonPanel &buttonPanel);

~SoloPanel() override;

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

private:
juce::AudioProcessorValueTreeState &parametersRef;
juce::AudioProcessorValueTreeState &parametersRef, &parametersNARef;
zlInterface::UIBase &uiBase;
zlFilter::IIR<double, zlDSP::Controller<double>::FilterSize> &soloF;
zlDSP::Controller<double> &controllerRef;
double soloFreq{0.}, soloQ{0.};
float scale1{.5f}, scale2{.5f};
ButtonPanel &buttonPanelRef;
float currentX{0.}, currentBW{0.};
double soloQ{0.};
std::atomic<size_t> selectBandIdx{0};
std::vector<std::unique_ptr<zlChore::ParaUpdater>> soloUpdaters, sideSoloUpdaters;

void handleAsyncUpdate();

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

Expand Down

0 comments on commit da8bd55

Please sign in to comment.