Skip to content

Commit

Permalink
fix(match analyzer panel): use draggers to control low/high cut
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 31, 2024
1 parent 6a0b428 commit 3f8af3d
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 38 deletions.
19 changes: 8 additions & 11 deletions source/gui/dragger2d/dragger_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace zlInterface {
void Dragger::updateButton() {
if (dummyButtonChanged.exchange(false)) {
button.setBounds(dummyButton.getBounds());
auto bound = button.getLocalBounds().toFloat();
const auto radius = std::min(bound.getHeight(), bound.getWidth());
bound = bound.withSizeKeepingCentre(radius, radius);
draggerLAF.updatePaths(bound);
}
}

Expand All @@ -43,7 +47,6 @@ namespace zlInterface {
dummyBound = dummyButton.getBounds();
isShiftDown = event.mods.isShiftDown();
dragger.startDraggingComponent(&preButton, event);

const BailOutChecker checker(this);
listeners.callChecked(checker, [&](Dragger::Listener &l) { l.dragStarted(this); });
}
Expand All @@ -60,26 +63,20 @@ namespace zlInterface {
if (event.mods.isCommandDown()) {
if (event.mods.isLeftButtonDown()) {
constrainer.setXON(false);
constrainer.setYON(true);
constrainer.setYON(yEnabled);
} else {
constrainer.setXON(true);
constrainer.setXON(xEnabled);
constrainer.setYON(false);
}
} else {
constrainer.setXON(true);
constrainer.setYON(true);
constrainer.setXON(xEnabled);
constrainer.setYON(yEnabled);
}
if (!isShiftDown && event.mods.isShiftDown()) {
preBound = preButton.getBounds();
dummyBound = dummyButton.getBounds();
isShiftDown = true;
}
// if (currentShiftDown && !isShiftDown) {
// dragger.startDraggingComponent(&preButton, event);
// preBound = preButton.getBounds();
// dummyBound = dummyButton.getBounds();
// isShiftDown = currentShiftDown;
// }

dragger.dragComponent(&preButton, event, nullptr);
const auto shift = (preButton.getBounds().getPosition() - preBound.getPosition()).toFloat();
Expand Down
10 changes: 8 additions & 2 deletions source/gui/dragger2d/dragger_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ namespace zlInterface {
void removeListener(Listener *listener);

void setPadding(const float left, const float right,
const float uppper, const float bottom) {
const float upper, const float bottom) {
lPadding = left;
rPadding = right;
uPadding = uppper;
uPadding = upper;
bPadding = bottom;
}

void setActive(const bool f) { draggerLAF.setActive(f); }

DraggerLookAndFeel &getLAF() {return draggerLAF;}

void setXYEnabled(const bool x, const bool y) {
xEnabled = x;
yEnabled = y;
}

private:
UIBase &uiBase;

Expand All @@ -89,6 +94,7 @@ namespace zlInterface {
DraggerLookAndFeel draggerLAF;
juce::ComponentDragger dragger;
DraggerConstrainer constrainer;
bool xEnabled{true}, yEnabled{true};
std::atomic<bool> isSelected;
std::atomic<float> xPortion, yPortion;

Expand Down
47 changes: 40 additions & 7 deletions source/gui/dragger2d/dragger_look_and_feel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace zlInterface {
enum DraggerShape {
round,
rectangle,
upDownArrow
upDownArrow,
rightArrow,
leftArrow
};

explicit DraggerLookAndFeel(UIBase &base) : uiBase(base) {
Expand All @@ -30,11 +32,6 @@ namespace zlInterface {
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown) override {
if (!active.load()) { return; }
auto bound = button.getLocalBounds().toFloat();
const auto radius = std::min(bound.getHeight(), bound.getWidth());
bound = bound.withSizeKeepingCentre(radius, radius);

updatePaths(bound);

if (shouldDrawButtonAsDown || button.getToggleState()) {
g.setColour(uiBase.getTextColor());
Expand All @@ -54,8 +51,10 @@ namespace zlInterface {
} else {
g.setColour(juce::Colours::black);
}
// g.setColour(colour.withMultipliedBrightness(2.f));
g.setFont(uiBase.getFontSize() * labelScale);
auto bound = button.getLocalBounds().toFloat();
const auto radius = std::min(bound.getHeight(), bound.getWidth());
bound = bound.withSizeKeepingCentre(radius, radius);
g.drawText(l, bound, juce::Justification::centred);
}
}
Expand Down Expand Up @@ -88,6 +87,14 @@ namespace zlInterface {
updateUpDownArrowPaths(bound);
break;
}
case rightArrow: {
updateRightArrowPaths(bound);
break;
}
case leftArrow: {
updateLeftArrowPaths(bound);
break;
}
}
}

Expand Down Expand Up @@ -119,6 +126,32 @@ namespace zlInterface {
updateOnePath(innerPath, bound);
}

void updateRightArrowPaths(juce::Rectangle<float> &bound) {
auto updateOnePath = [](juce::Path &path, const juce::Rectangle<float> &temp) {
const auto center = temp.getCentre();
path.startNewSubPath(center.getX() + temp.getWidth() * .5f, center.getY());
path.lineTo(center.getX() - temp.getWidth() * .25f, center.getY() + temp.getHeight() * std::sqrt(3.f) * .25f);
path.lineTo(center.getX() - temp.getWidth() * .25f, center.getY() - temp.getHeight() * std::sqrt(3.f) * .25f);
path.closeSubPath();
};
updateOnePath(outlinePath, bound);
bound = bound.withSizeKeepingCentre(bound.getWidth() * .75f, bound.getHeight() * .75f);
updateOnePath(innerPath, bound);
}

void updateLeftArrowPaths(juce::Rectangle<float> &bound) {
auto updateOnePath = [](juce::Path &path, const juce::Rectangle<float> &temp) {
const auto center = temp.getCentre();
path.startNewSubPath(center.getX() - temp.getWidth() * .5f, center.getY());
path.lineTo(center.getX() + temp.getWidth() * .25f, center.getY() + temp.getHeight() * std::sqrt(3.f) * .25f);
path.lineTo(center.getX() + temp.getWidth() * .25f, center.getY() - temp.getHeight() * std::sqrt(3.f) * .25f);
path.closeSubPath();
};
updateOnePath(outlinePath, bound);
bound = bound.withSizeKeepingCentre(bound.getWidth() * .75f, bound.getHeight() * .75f);
updateOnePath(innerPath, bound);
}

void setLabel(const char l) { label.store(l); }

void setLabelScale(const float x) { labelScale = x; }
Expand Down
4 changes: 4 additions & 0 deletions source/gui/interface_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ namespace zlInterface {
valueTree.setProperty(identifiers[idx], v, nullptr);
}

static bool isProperty(const settingIdx idx, const juce::Identifier &property) {
return property == identifiers[static_cast<size_t>(idx)];
}

private:
juce::AudioProcessorValueTreeState &state;
juce::ValueTree valueTree{"ui_setting"};
Expand Down
61 changes: 49 additions & 12 deletions source/panel/curve_panel/match_panel/match_analyzer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,31 @@ namespace zlPanel {
juce::AudioProcessorValueTreeState &parametersNA,
zlInterface::UIBase &base)
: analyzerRef(analyzer), parametersNARef(parametersNA), uiBase(base),
lowDragger(base), highDragger(base),
labelLAF(uiBase) {
parametersNARef.addParameterListener(zlState::maximumDB::ID, this);
parameterChanged(zlState::maximumDB::ID, parametersNARef.getRawParameterValue(zlState::maximumDB::ID)->load());
setInterceptsMouseClicks(false, false);
setInterceptsMouseClicks(false, true);
uiBase.getValueTree().addListener(this);
runningLabel.setText("Running", juce::dontSendNotification);
runningLabel.setJustificationType(juce::Justification::centred);
labelLAF.setFontScale(5.f);
runningLabel.setLookAndFeel(&labelLAF);
addChildComponent(runningLabel);
lowDragger.getLAF().setDraggerShape(zlInterface::DraggerLookAndFeel::DraggerShape::rightArrow);
highDragger.getLAF().setDraggerShape(zlInterface::DraggerLookAndFeel::DraggerShape::leftArrow);
for (auto &d : {&lowDragger, &highDragger}) {
d->setYPortion(.5f);
d->setXYEnabled(true, false);
d->setScale(scale);
d->setActive(true);
d->getButton().setToggleState(true, juce::dontSendNotification);
d->getLAF().setIsSelected(true);
d->setInterceptsMouseClicks(false, true);
d->addListener(this);
addAndMakeVisible(d);
}
lookAndFeelChanged();
}

MatchAnalyzerPanel::~MatchAnalyzerPanel() {
Expand All @@ -32,6 +47,9 @@ namespace zlPanel {
}

void MatchAnalyzerPanel::paint(juce::Graphics &g) {
for (auto &d : {&lowDragger, &highDragger}) {
d->updateButton();
}
g.fillAll(uiBase.getColourByIdx(zlInterface::backgroundColour).withAlpha(backgroundAlpha));
const auto thickness = uiBase.getFontSize() * 0.2f * uiBase.getSumCurveThickness();
juce::GenericScopedTryLock lock{pathLock};
Expand All @@ -50,16 +68,16 @@ namespace zlPanel {
g.strokePath(recentPath3,
juce::PathStrokeType(thickness * 1.5f,
juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
if (lowCutP > 0.001f) {
if (const auto xP = lowDragger.getXPortion(); xP > 0.001f) {
auto bound = getLocalBounds().toFloat();
bound = bound.removeFromLeft(bound.getWidth() * lowCutP);
g.setColour(uiBase.getBackgroundColor().withAlpha(.5f));
bound = bound.removeFromLeft(bound.getWidth() * xP);
g.setColour(uiBase.getBackgroundColor().withAlpha(.75f));
g.fillRect(bound);
}
if (highCutP < .999f) {
if (const auto yP = highDragger.getXPortion(); yP < .999f) {
auto bound = getLocalBounds().toFloat();
bound = bound.removeFromRight(bound.getWidth() * (1.f - highCutP));
g.setColour(uiBase.getBackgroundColor().withAlpha(.5f));
bound = bound.removeFromRight(bound.getWidth() * (1.f - yP));
g.setColour(uiBase.getBackgroundColor().withAlpha(.75f));
g.fillRect(bound);
}
}
Expand All @@ -72,6 +90,8 @@ namespace zlPanel {
dBScale.store((1.f + uiBase.getFontSize() * 2.f / bound.getHeight()) * 2.f);
runningLabel.setBounds(bound.withSizeKeepingCentre(
bound.getWidth() * .5f, uiBase.getFontSize() * 5.f).toNearestInt());
lowDragger.setBounds(getLocalBounds());
highDragger.setBounds(getLocalBounds());
}

void MatchAnalyzerPanel::updatePaths() {
Expand All @@ -89,16 +109,19 @@ namespace zlPanel {
analyzerRef.checkRun();
}

void MatchAnalyzerPanel::visibilityChanged() {
lowDragger.setXPortion(0.f);
highDragger.setXPortion(1.f);
draggerValueChanged(&lowDragger);
draggerValueChanged(&highDragger);
}

void MatchAnalyzerPanel::valueTreePropertyChanged(juce::ValueTree &, const juce::Identifier &property) {
if (property == zlInterface::identifiers[static_cast<size_t>(zlInterface::settingIdx::matchPanelFit)]) {
const auto f = static_cast<bool>(uiBase.getProperty(zlInterface::settingIdx::matchPanelFit));
backgroundAlpha = f ? .2f : .5f;
showAverage = !f;
} else if (property == zlInterface::identifiers[static_cast<size_t>(zlInterface::settingIdx::matchLowCut)]) {
lowCutP = static_cast<float>(uiBase.getProperty(zlInterface::settingIdx::matchLowCut));
} else if (property == zlInterface::identifiers[static_cast<size_t>(zlInterface::settingIdx::matchHighCut)]) {
highCutP = static_cast<float>(uiBase.getProperty(zlInterface::settingIdx::matchHighCut));
} else if (property == zlInterface::identifiers[static_cast<size_t>(zlInterface::settingIdx::matchFitRunning)]) {
} else if (uiBase.isProperty(zlInterface::settingIdx::matchFitRunning, property)) {
runningLabel.setVisible(static_cast<bool>(uiBase.getProperty(zlInterface::settingIdx::matchFitRunning)));
}
}
Expand All @@ -107,4 +130,18 @@ namespace zlPanel {
juce::ignoreUnused(parameterID);
maximumDB.store(zlState::maximumDB::dBs[static_cast<size_t>(newValue)]);
}

void MatchAnalyzerPanel::lookAndFeelChanged() {
for (auto &d : {&lowDragger, &highDragger}) {
d->getLAF().setColour(uiBase.getTextColor());
}
}

void MatchAnalyzerPanel::draggerValueChanged(zlInterface::Dragger *dragger) {
if (dragger == &lowDragger) {
uiBase.setProperty(zlInterface::settingIdx::matchLowCut, lowDragger.getXPortion());
} else if (dragger == &highDragger) {
uiBase.setProperty(zlInterface::settingIdx::matchHighCut, highDragger.getXPortion());
}
}
} // zlPanel
22 changes: 19 additions & 3 deletions source/panel/curve_panel/match_panel/match_analyzer_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

namespace zlPanel {
class MatchAnalyzerPanel final : public juce::Component,
private juce::AudioProcessorValueTreeState::Listener,
private juce::ValueTree::Listener {
private juce::AudioProcessorValueTreeState::Listener,
private juce::ValueTree::Listener,
private zlInterface::Dragger::Listener {
public:
explicit MatchAnalyzerPanel(zlEqMatch::EqMatchAnalyzer<double> &analyzer,
juce::AudioProcessorValueTreeState &parametersNA,
Expand All @@ -29,6 +30,8 @@ namespace zlPanel {

void resized() override;

void visibilityChanged() override;

void updatePaths();

private:
Expand All @@ -44,14 +47,27 @@ namespace zlPanel {
bool showAverage{true};
std::atomic<float> dBScale{1.f};
std::atomic<float> maximumDB{zlState::maximumDB::dBs[static_cast<size_t>(zlState::maximumDB::defaultI)]};
float lowCutP{0.f}, highCutP{1.f};
zlInterface::Dragger lowDragger, highDragger;
zlInterface::NameLookAndFeel labelLAF;
juce::Label runningLabel;
static constexpr auto scale = 1.5f;

void valueTreePropertyChanged(juce::ValueTree &treeWhosePropertyHasChanged,
const juce::Identifier &property) override;

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

void lookAndFeelChanged() override;

void dragStarted(zlInterface::Dragger *dragger) override {
juce::ignoreUnused(dragger);
}

void dragEnded(zlInterface::Dragger *dragger) override {
juce::ignoreUnused(dragger);
}

void draggerValueChanged(zlInterface::Dragger *dragger) override;
};
} // zlPanel

Expand Down
4 changes: 4 additions & 0 deletions source/panel/curve_panel/match_panel/match_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace zlPanel {
matchAnalyzerPanel.updatePaths();
}

void visibilityChanged() override {
matchAnalyzerPanel.visibilityChanged();
}

private:
zlInterface::UIBase &uiBase;
MatchAnalyzerPanel matchAnalyzerPanel;
Expand Down
3 changes: 0 additions & 3 deletions source/panel/state_panel/match_setting_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ namespace zlPanel {
uiBase.setProperty(zlInterface::settingIdx::matchPanelShow, !f);
if (!f) {
uiBase.setProperty(zlInterface::settingIdx::matchPanelFit, false);
} else {
uiBase.setProperty(zlInterface::settingIdx::matchLowCut, 0.f);
uiBase.setProperty(zlInterface::settingIdx::matchHighCut, 1.f);
}
}
} // zlPanel

0 comments on commit 3f8af3d

Please sign in to comment.