Skip to content

Commit 55de0b9

Browse files
authored
Merge pull request #4 from SmEgDm/ui-interaction
UI interaction
2 parents 62124d0 + 7119bae commit 55de0b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1333
-383
lines changed

public/icons/bell.svg

Lines changed: 4 additions & 0 deletions
Loading

public/icons/highpass.svg

Lines changed: 4 additions & 0 deletions
Loading

public/icons/lowpass.svg

Lines changed: 4 additions & 0 deletions
Loading

public/icons/powerswitch.svg

Lines changed: 8 additions & 0 deletions
Loading

src/app/editor.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
PluginEditor::PluginEditor(PluginProcessor &p)
44
: juce::AudioProcessorEditor(&p), homePage(p) {
5-
setSize(defaultWidth, defaultHeight);
6-
setResizable(true, true);
5+
juce::LookAndFeel_V4::setDefaultLookAndFeel(&lookAndFeel);
76

87
const auto desktopArea =
98
juce::Desktop::getInstance().getDisplays().getPrimaryDisplay()->userArea;
10-
9+
setSize(defaultWidth, defaultHeight);
10+
setResizable(true, true);
1111
setResizeLimits(minWidth, minHeight, desktopArea.getWidth(),
1212
desktopArea.getHeight());
1313

14-
juce::LookAndFeel::setDefaultLookAndFeel(&lookAndFeel);
15-
1614
addAndMakeVisible(homePage);
1715

1816
resized();
1917
}
2018

2119
PluginEditor::~PluginEditor() {
22-
juce::LookAndFeel::setDefaultLookAndFeel(nullptr);
20+
juce::LookAndFeel_V4::setDefaultLookAndFeel(nullptr);
2321
}
2422

2523
void PluginEditor::resized() { homePage.setBounds(getLocalBounds()); }

src/app/editor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PluginEditor : public juce::AudioProcessorEditor {
1919
void resized() override;
2020

2121
private:
22-
SairaFontLookAndFeel lookAndFeel;
22+
PluginLookAndFeel lookAndFeel;
2323

2424
HomePage homePage;
2525

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
#include "equalizer.hpp"
22

3-
Equalizer::Equalizer(PluginProcessor &pluginProcessor)
4-
: analyzer(pluginProcessor), freqResponse(pluginProcessor) {
3+
#include <algorithm>
4+
5+
Equalizer::Equalizer(PluginProcessor &p)
6+
: pluginProcessor(p), uiState(p.getUiState()), analyzer(p), freqResponse(p),
7+
filterPanel(p, [&]() { update(); }) {
8+
addMouseListener(this, true);
9+
510
addAndMakeVisible(grid);
611
addAndMakeVisible(analyzer);
12+
13+
for (int id = constants::FILTER_MIN_ID; id <= constants::FILTER_MAX_ID;
14+
++id) {
15+
filterFreqResponses.push_back(
16+
std::make_unique<FilterFrequencyResponse>(pluginProcessor, id));
17+
addChildComponent(filterFreqResponses.back().get());
18+
}
19+
720
addAndMakeVisible(freqResponse);
821

22+
for (int id = constants::FILTER_MIN_ID; id <= constants::FILTER_MAX_ID;
23+
++id) {
24+
filterButtons.push_back(std::make_unique<FilterButton>(
25+
id, pluginProcessor, [&]() { update(); }));
26+
addChildComponent(filterButtons.back().get());
27+
}
28+
29+
addChildComponent(filterPanel);
30+
31+
update();
32+
933
resized();
1034
}
1135

@@ -16,6 +40,77 @@ void Equalizer::resized() {
1640

1741
LayoutComponent::resized();
1842

19-
analyzer.setBounds(getLocalBounds());
20-
freqResponse.setBounds(getLocalBounds());
43+
const auto bounds = getLocalBounds();
44+
45+
analyzer.setBounds(bounds);
46+
for (auto &filterFreqResponse : filterFreqResponses) {
47+
filterFreqResponse->setBounds(bounds);
48+
}
49+
freqResponse.setBounds(bounds);
50+
filterPanel.setBounds(bounds.withSizeKeepingCentre(300, 170).translated(
51+
0.0f, static_cast<float>(getHeight()) * 0.5f - 85.0f - 30.0f));
52+
for (auto &filterButton : filterButtons) {
53+
filterButton->timerCallback();
54+
}
55+
}
56+
57+
void Equalizer::mouseDown(const juce::MouseEvent &event) {
58+
LayoutComponent::mouseDown(event);
59+
60+
if (event.eventComponent == &freqResponse) {
61+
uiState.selectedFilterID = -1;
62+
update();
63+
}
64+
}
65+
66+
void Equalizer::mouseDoubleClick(const juce::MouseEvent &event) {
67+
LayoutComponent::mouseDoubleClick(event);
68+
69+
if (event.eventComponent != &freqResponse || !uiState.addFilter()) {
70+
return;
71+
}
72+
73+
const float xMin = 0.0f;
74+
const float xMax = static_cast<float>(event.eventComponent->getWidth());
75+
const float yMax = static_cast<float>(event.eventComponent->getHeight());
76+
77+
const auto xToFreq = math::invLogMapping(xMin, xMax, constants::GRID_MIN_FREQ,
78+
constants::GRID_MAX_FREQ);
79+
const auto yToDb = math::segmentMapping(yMax, 0.0f, constants::GRID_MIN_DB,
80+
constants::GRID_MAX_DB);
81+
const auto dBToNorm = math::segmentMapping(-12, 12, 0, 1);
82+
83+
const float x = static_cast<float>(event.getMouseDownX());
84+
const float y = static_cast<float>(event.getMouseDownY());
85+
86+
FilterParameters filterParameters(uiState.selectedFilterID,
87+
pluginProcessor.getAPVTS());
88+
const auto freqToNorm = filterParameters.frequency->getNormalisableRange();
89+
90+
filterParameters.isActive->beginChangeGesture();
91+
filterParameters.isActive->setValueNotifyingHost(1.0f);
92+
filterParameters.isActive->endChangeGesture();
93+
94+
filterParameters.frequency->beginChangeGesture();
95+
filterParameters.frequency->setValueNotifyingHost(
96+
freqToNorm.convertTo0to1(xToFreq(x)));
97+
filterParameters.frequency->endChangeGesture();
98+
99+
filterParameters.gain->beginChangeGesture();
100+
filterParameters.gain->setValueNotifyingHost(dBToNorm(yToDb(y)));
101+
filterParameters.gain->endChangeGesture();
102+
103+
filterButtons[uiState.selectedFilterID - 1]->setCentrePosition(
104+
event.getMouseDownPosition());
105+
filterButtons[uiState.selectedFilterID - 1]->setVisible(true);
106+
107+
update();
108+
}
109+
110+
void Equalizer::update() {
111+
filterPanel.update();
112+
for (const auto &[filterID, isUsed] : uiState.usedFilterIDs) {
113+
filterFreqResponses[filterID - 1]->setVisible(isUsed);
114+
filterButtons[filterID - 1]->setVisible(isUsed);
115+
}
21116
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
#pragma once
22

33
#include "shared.hpp"
4-
54
#include "ui/ui.hpp"
65

6+
#include <memory>
7+
#include <vector>
8+
79
class Equalizer : public LayoutComponent {
810
public:
911
Equalizer(PluginProcessor &);
1012

1113
void resized() override;
1214

15+
void mouseDown(const juce::MouseEvent &event) override;
16+
void mouseDoubleClick(const juce::MouseEvent &event) override;
17+
18+
void update();
19+
1320
private:
21+
PluginProcessor &pluginProcessor;
22+
PluginProcessor::UiState &uiState;
23+
1424
GridComponent grid;
1525
AnalyzerComponent analyzer;
16-
FrequencyResponseComponent freqResponse;
26+
std::vector<std::unique_ptr<FilterFrequencyResponse>> filterFreqResponses;
27+
EqualizerFrequencyResponse freqResponse;
28+
FilterPanel filterPanel;
29+
std::vector<std::unique_ptr<FilterButton>> filterButtons;
1730
};

src/pages/home/equalizer/ui/analyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <vector>
88

99
AnalyzerComponent::AnalyzerComponent(PluginProcessor &p) : pluginProcessor(p) {
10-
startTimerHz(30);
10+
startTimerHz(24);
1111
}
1212

1313
void AnalyzerComponent::paint(juce::Graphics &g) {

src/pages/home/equalizer/ui/frequency_response.cpp renamed to src/pages/home/equalizer/ui/equalizer_response.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include "frequency_response.hpp"
1+
#include "equalizer_response.hpp"
22

33
#include "constants.hpp"
44

5-
FrequencyResponseComponent::FrequencyResponseComponent(PluginProcessor &p)
5+
EqualizerFrequencyResponse::EqualizerFrequencyResponse(PluginProcessor &p)
66
: pluginProcessor(p), frequencyResponse([](float) { return 0.0f; }) {
7-
startTimerHz(30);
7+
startTimerHz(24);
88
}
99

10-
void FrequencyResponseComponent::paint(juce::Graphics &g) {
10+
void EqualizerFrequencyResponse::paint(juce::Graphics &g) {
1111
const auto equalizerProcessor = pluginProcessor.getEqualizerProcessor();
1212

1313
if (!equalizerProcessor) {
@@ -44,7 +44,7 @@ void FrequencyResponseComponent::paint(juce::Graphics &g) {
4444
juce::PathStrokeType::EndCapStyle::rounded));
4545
}
4646

47-
void FrequencyResponseComponent::timerCallback() {
47+
void EqualizerFrequencyResponse::timerCallback() {
4848
const auto equalizerProcessor = pluginProcessor.getEqualizerProcessor();
4949

5050
if (equalizerProcessor) {

0 commit comments

Comments
 (0)