Skip to content

Commit

Permalink
feat(eq match): add diff curve drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Jan 1, 2025
1 parent 536efef commit 76a2c16
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions source/dsp/eq_match/eq_match_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace zlEqMatch {
std::fill(targetDBs.begin(), targetDBs.end(), 0.f);
std::fill(diffs.begin(), diffs.end(), 0.f);
updateSmooth();
clearDrawingDiffs();
}

template<typename FloatType>
Expand Down Expand Up @@ -159,6 +160,12 @@ namespace zlEqMatch {
for (auto &diff: diffs) {
diff -= diffC;
}
// read from drawing
for (size_t i = 0; i < pointNum; ++i) {
if (drawingFlag[i].load()) {
diffs[i] = drawingDiffs[i].load();
}
}
// save to target
for (size_t i = 0; i < pointNum; ++i) {
atomicTargetDBs[i].store(targetDBs[i]);
Expand Down
13 changes: 13 additions & 0 deletions source/dsp/eq_match/eq_match_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ namespace zlEqMatch {

std::array<std::atomic<float>, pointNum> &getDiffs() { return atomicDiffs; }

void setDrawingDiffs(const size_t idx, const float x) {
drawingDiffs[idx].store(x);
drawingFlag[idx].store(true);
}

void clearDrawingDiffs() {
for (size_t idx = 0; idx < pointNum; ++idx) {
drawingFlag[idx].store(false);
}
}

private:
zlFFT::AverageFFTAnalyzer<FloatType, 2, pointNum> fftAnalyzer;
std::array<float, pointNum> mainDBs{}, targetDBs{}, diffs{};
std::array<std::atomic<float>, pointNum> atomicTargetDBs{}, atomicDiffs{};
std::array<std::atomic<bool>, pointNum> drawingFlag;
std::array<std::atomic<float>, pointNum> drawingDiffs;
std::atomic<MatchMode> mMode;
std::atomic<bool> isON{false};
std::array<float, pointNum> loadDBs{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace zlPanel {

void loadDiffs();

static constexpr double mseThreshold = 5.;
static constexpr double mseThreshold = .5;
};
} // zlPanel

Expand Down
47 changes: 46 additions & 1 deletion source/panel/curve_panel/match_panel/match_analyzer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace zlPanel {
labelLAF(uiBase) {
parametersNARef.addParameterListener(zlState::maximumDB::ID, this);
parameterChanged(zlState::maximumDB::ID, parametersNARef.getRawParameterValue(zlState::maximumDB::ID)->load());
setInterceptsMouseClicks(false, true);
setInterceptsMouseClicks(true, true);
uiBase.getValueTree().addListener(this);
runningLabel.setText("Running", juce::dontSendNotification);
runningLabel.setJustificationType(juce::Justification::centred);
Expand Down Expand Up @@ -165,4 +165,49 @@ namespace zlPanel {
d->updateButton();
}
}

void MatchAnalyzerPanel::mouseDown(const juce::MouseEvent &event) {
if (event.mods.isCommandDown()) {
getIdxDBromPoint(event.getPosition(), preDrawIdx, preDrawDB);
if (event.mods.isRightButtonDown()) {
preDrawDB = 0.f;
}
}
}

void MatchAnalyzerPanel::mouseDrag(const juce::MouseEvent &event) {
if (event.mods.isCommandDown()) {
size_t currentDrawIdx;
float currentDrawDB;
getIdxDBromPoint(event.getPosition(), currentDrawIdx, currentDrawDB);
if (event.mods.isRightButtonDown()) {
currentDrawDB = 0.f;
}
if (currentDrawIdx == preDrawIdx) {
analyzerRef.setDrawingDiffs(currentDrawIdx, currentDrawDB);
} else if (currentDrawIdx < preDrawIdx) {
float dB = currentDrawDB;
const float deltaDB = (preDrawDB - currentDrawDB) / static_cast<float>(preDrawIdx - currentDrawIdx - 1);
for (size_t idx = currentDrawIdx; idx < preDrawIdx; ++idx) {
analyzerRef.setDrawingDiffs(idx, dB);
dB += deltaDB;
}
} else {
float dB = preDrawDB;
const float deltaDB = (currentDrawDB - preDrawDB) / static_cast<float>(currentDrawIdx - preDrawIdx - 1);
for (size_t idx = preDrawIdx + 1; idx <= currentDrawIdx; ++idx) {
analyzerRef.setDrawingDiffs(idx, dB);
dB += deltaDB;
}
}
preDrawIdx = currentDrawIdx;
preDrawDB = currentDrawDB;
}
}

void MatchAnalyzerPanel::mouseDoubleClick(const juce::MouseEvent &event) {
if (!event.mods.isCommandDown()) {
analyzerRef.clearDrawingDiffs();
}
}
} // zlPanel
16 changes: 16 additions & 0 deletions source/panel/curve_panel/match_panel/match_analyzer_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ namespace zlPanel {

void updateDraggers();

void mouseDown(const juce::MouseEvent &event) override;

void mouseDrag(const juce::MouseEvent &event) override;

void mouseDoubleClick(const juce::MouseEvent &event) override;

private:
zlEqMatch::EqMatchAnalyzer<double> &analyzerRef;
juce::AudioProcessorValueTreeState &parametersNARef;
Expand All @@ -54,6 +60,8 @@ namespace zlPanel {
zlInterface::NameLookAndFeel labelLAF;
juce::Label runningLabel;
static constexpr auto scale = 1.5f;
size_t preDrawIdx{0};
float preDrawDB{0.f};

void valueTreePropertyChanged(juce::ValueTree &treeWhosePropertyHasChanged,
const juce::Identifier &property) override;
Expand All @@ -71,6 +79,14 @@ namespace zlPanel {
}

void draggerValueChanged(zlInterface::Dragger *dragger) override;

void getIdxDBromPoint(const juce::Point<int> &p, size_t &idx, float &dB) {
const auto bound = getLocalBounds().toFloat();
const auto idxInt = juce::roundToInt(250.f * (static_cast<float>(p.getX()) - bound.getX()) / bound.getWidth());
idx = static_cast<size_t>(std::clamp(idxInt, 0, 250));
const auto yP = (p.getY() - bound.getY()) / bound.getHeight() - .5f;
dB = -maximumDB.load() * dBScale.load() * yP;
}
};
} // zlPanel

Expand Down

0 comments on commit 76a2c16

Please sign in to comment.