Skip to content

Commit

Permalink
General cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Nov 22, 2024
1 parent a60ccf5 commit 736cad5
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 157 deletions.
167 changes: 107 additions & 60 deletions examples/ExampleCompressor/PluginEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,76 +1,123 @@
#include "PluginEditor.h"

void PluginEditor::LevelDetectorEditor::resized()
struct LevelDetectorEditor : juce::Component
{
auto bounds = getLocalBounds();
paramsView->setBounds (bounds.removeFromTop (proportionOfHeight (0.5f)));
viz->setBounds (bounds);
}
LevelDetectorEditor (chowdsp::PluginState& state,
Params& pluginParams,
chow_comp::LevelDetectorVisualizer& levelViz,
chowdsp::ComponentArena<>& arena)
: params { arena.allocator, "Level Detector Params", false },
viz { &levelViz }
{
params.add (pluginParams.attack, pluginParams.release, pluginParams.levelDetectorMode);

void PluginEditor::GainComputerEditor::resized()
{
auto bounds = getLocalBounds();
paramsView->setBounds (bounds.removeFromTop (proportionOfHeight (0.5f)));
plot.setBounds (bounds);
updatePlot();
}
paramsView = arena.allocate<chowdsp::ParametersView> (state, params);
addAndMakeVisible (paramsView);

void PluginEditor::GainComputerEditor::setupPlot (chowdsp::PluginState& state, Params& plugParams)
{
pluginParams = &plugParams;
gainComputer.prepare (48000.0, inputBuffer.getNumSamples());
callbacks += {
state.addParameterListener (pluginParams->threshold, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->ratio, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->knee, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->architecture, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
};
for (auto [n, sample] : chowdsp::enumerate (inputBuffer.getWriteSpan (0)))
sample = juce::Decibels::decibelsToGain (juce::jmap ((float) n,
0.0f,
(float) inputBuffer.getNumSamples(),
plot.params.xMin,
plot.params.xMax));
updatePlot();
}
addAndMakeVisible (viz);
}

void resized() override
{
auto bounds = getLocalBounds();
paramsView->setBounds (bounds.removeFromTop (proportionOfHeight (0.5f)));
viz->setBounds (bounds);
}

chowdsp::ParamHolder params;
chowdsp::ParametersView* paramsView {};
juce::Component* viz {};
};

void PluginEditor::GainComputerEditor::updatePlot()
struct GainComputerEditor : juce::Component
{
gainComputer.setMode (*magic_enum::enum_index (pluginParams->architecture->get()));
gainComputer.setThreshold (pluginParams->threshold->get());
gainComputer.setRatio (pluginParams->ratio->get());
gainComputer.setKnee (pluginParams->knee->get());
gainComputer.reset();
GainComputerEditor (chowdsp::PluginState& state,
Params& plugParams,
chowdsp::ComponentArena<>& arena)
: params { arena.allocator, "Gain Computer Params", false }
{
params.add (plugParams.threshold, plugParams.ratio, plugParams.knee, plugParams.architecture, plugParams.autoMakeup);

gainComputer.processBlock (inputBuffer, outputBuffer);
paramsView = arena.allocate<chowdsp::ParametersView> (state, params);
addAndMakeVisible (paramsView);

plot.setThreshold (pluginParams->threshold->get());
plot.updatePlotPath (inputBuffer.getReadSpan (0), outputBuffer.getReadSpan (0));
}
addAndMakeVisible (plot);
setupPlot (state, plugParams);
}

void resized() override
{
auto bounds = getLocalBounds();
paramsView->setBounds (bounds.removeFromTop (proportionOfHeight (0.5f)));
plot.setBounds (bounds);
updatePlot();
}

void setupPlot (chowdsp::PluginState& state, Params& plugParams)
{
pluginParams = &plugParams;
gainComputer.prepare (48000.0, inputBuffer.getNumSamples());
callbacks += {
state.addParameterListener (pluginParams->threshold, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->ratio, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->knee, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
state.addParameterListener (pluginParams->architecture, chowdsp::ParameterListenerThread::MessageThread, [this]
{ updatePlot(); }),
};
for (auto [n, sample] : chowdsp::enumerate (inputBuffer.getWriteSpan (0)))
sample = juce::Decibels::decibelsToGain (juce::jmap ((float) n,
0.0f,
(float) inputBuffer.getNumSamples(),
plot.params.xMin,
plot.params.xMax));
updatePlot();
}

void updatePlot()
{
gainComputer.setMode (*magic_enum::enum_index (pluginParams->architecture->get()));
gainComputer.setThreshold (pluginParams->threshold->get());
gainComputer.setRatio (pluginParams->ratio->get());
gainComputer.setKnee (pluginParams->knee->get());
gainComputer.reset();

gainComputer.processBlock (inputBuffer, outputBuffer);

plot.setThreshold (pluginParams->threshold->get());
plot.updatePlotPath (inputBuffer.getReadSpan (0), outputBuffer.getReadSpan (0));
}

chowdsp::ParamHolder params;
chowdsp::ParametersView* paramsView {};

Params* pluginParams = nullptr;
GainComputer gainComputer;
chow_comp::GainComputerPlot plot;

chowdsp::ScopedCallbackList callbacks;
static constexpr int plotNumSamples = 128;
chowdsp::StaticBuffer<float, 1, plotNumSamples> inputBuffer { 1, plotNumSamples };
chowdsp::StaticBuffer<float, 1, plotNumSamples> outputBuffer { 1, plotNumSamples };
};

PluginEditor::PluginEditor (ExampleCompressorPlugin& plugin)
: juce::AudioProcessorEditor (plugin),
meter (plugin.compressor.gainReductionMeterTask)
: juce::AudioProcessorEditor (plugin)
{
auto& params = plugin.getState().params;
levelDetectorEditor.params.add (params.attack, params.release, params.levelDetectorMode);
levelDetectorEditor.paramsView.emplace (plugin.getState(), levelDetectorEditor.params);
levelDetectorEditor.addAndMakeVisible (*levelDetectorEditor.paramsView);
levelDetectorEditor.viz = &plugin.compressor.levelDetector.levelDetectorViz;
levelDetectorEditor.addAndMakeVisible (levelDetectorEditor.viz);
levelDetectorEditor = arena.allocate<LevelDetectorEditor> (plugin.getState(),
plugin.getState().params,
plugin.compressor.levelDetector.levelDetectorViz,
arena);
addAndMakeVisible (levelDetectorEditor);

gainComputerEditor.params.add (params.threshold, params.ratio, params.knee, params.architecture, params.autoMakeup);
gainComputerEditor.paramsView.emplace (plugin.getState(), gainComputerEditor.params);
gainComputerEditor.addAndMakeVisible (*gainComputerEditor.paramsView);
gainComputerEditor.addAndMakeVisible (gainComputerEditor.plot);
gainComputerEditor.setupPlot (plugin.getState(), params);
gainComputerEditor = arena.allocate<GainComputerEditor> (plugin.getState(),
plugin.getState().params,
arena);
addAndMakeVisible (gainComputerEditor);

meter = arena.allocate<chow_comp::GainReductionMeter> (plugin.compressor.gainReductionMeterTask);
addAndMakeVisible (meter);

setSize (900, 400);
Expand All @@ -84,7 +131,7 @@ void PluginEditor::paint (juce::Graphics& g)
void PluginEditor::resized()
{
auto bounds = getLocalBounds();
levelDetectorEditor.setBounds (bounds.removeFromLeft (proportionOfWidth (0.46f)));
gainComputerEditor.setBounds (bounds.removeFromLeft (proportionOfWidth (0.46f)));
meter.setBounds (bounds);
levelDetectorEditor->setBounds (bounds.removeFromLeft (proportionOfWidth (0.46f)));
gainComputerEditor->setBounds (bounds.removeFromLeft (proportionOfWidth (0.46f)));
meter->setBounds (bounds);
}
33 changes: 4 additions & 29 deletions examples/ExampleCompressor/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,10 @@ class PluginEditor : public juce::AudioProcessorEditor
void resized() override;

private:
struct LevelDetectorEditor : juce::Component
{
void resized() override;

chowdsp::ParamHolder params { "Level Detector Params", false };
std::optional<chowdsp::ParametersView> paramsView;
juce::Component* viz;
} levelDetectorEditor;

struct GainComputerEditor : juce::Component
{
void resized() override;
void setupPlot (chowdsp::PluginState& state, Params& pluginParams);
void updatePlot();

chowdsp::ParamHolder params { "Gain Computer Params", false };
std::optional<chowdsp::ParametersView> paramsView;

Params* pluginParams = nullptr;
GainComputer gainComputer;
chow_comp::GainComputerPlot plot;

chowdsp::ScopedCallbackList callbacks;
static constexpr int plotNumSamples = 128;
chowdsp::StaticBuffer<float, 1, plotNumSamples> inputBuffer { 1, plotNumSamples };
chowdsp::StaticBuffer<float, 1, plotNumSamples> outputBuffer { 1, plotNumSamples };
} gainComputerEditor;

chow_comp::GainReductionMeter meter;
chowdsp::ComponentArena<> arena {};
juce::Component* levelDetectorEditor {};
juce::Component* gainComputerEditor {};
juce::Component* meter;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginEditor)
};
2 changes: 1 addition & 1 deletion examples/SimpleEQ/SimpleEQPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Params : chowdsp::ParamHolder
add (eqParams, linPhaseMode);
}

EQParams eqParams {
EQParams eqParams { this,
{
BandParams { 0, "eq_band_0", "Band ", 100, bandTypeChoices, 10, 250.0f },
BandParams { 1, "eq_band_1", "Band ", 100, bandTypeChoices, 10, 1000.0f },
Expand Down
4 changes: 2 additions & 2 deletions examples/StatefulPlugin/StatefulPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

struct LevelParams : chowdsp::ParamHolder
{
LevelParams() : chowdsp::ParamHolder ("Level")
explicit LevelParams (ParamHolder* parent) : ParamHolder { parent, "Level" }
{
add (percent, gain);
}
Expand All @@ -22,7 +22,7 @@ struct PluginParameterState : chowdsp::ParamHolder
add (levelParams, mode, onOff);
}

LevelParams levelParams;
LevelParams levelParams { this };
chowdsp::ChoiceParameter::Ptr mode { juce::ParameterID { "mode", 100 }, "Mode", juce::StringArray { "Percent", "Gain", "Percent / Gain", "Gain / Percent" }, 2 };
chowdsp::BoolParameter::Ptr onOff { juce::ParameterID { "on_off", 100 }, "On/Off", true };
};
Expand Down
17 changes: 11 additions & 6 deletions modules/dsp/chowdsp_eq/EQ/chowdsp_StandardEQParameters.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#if JUCE_MODULE_AVAILABLE_chowdsp_plugin_state
#include <chowdsp_logging/chowdsp_logging.h>

namespace chowdsp::EQ
{
template <size_t NumBands>
StandardEQParameters<NumBands>::StandardEQParameters (EQParameterHandles&& paramHandles,
const juce::String& paramHolderName)
: ParamHolder (paramHolderName),
eqParams (std::move (paramHandles))
StandardEQParameters<NumBands>::StandardEQParameters (ParamHolder* parent,
EQParameterHandles&& paramHandles,
std::string_view paramHolderName)
: ParamHolder { parent, paramHolderName },
eqParams { std::move (paramHandles) }
{
for (auto& bandParams : eqParams)
{
bandParams.paramHolder.add (bandParams.onOffParam,
bandParams.paramHolder.emplace (this,
format (*arena, "{} {}", bandParams.bandNamePrefix, bandParams.bandIndex + 1));
bandParams.paramHolder->add (bandParams.onOffParam,
bandParams.typeParam,
bandParams.freqParam,
bandParams.qParam,
bandParams.gainParam);
add (bandParams.paramHolder);
add (*bandParams.paramHolder);
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/dsp/chowdsp_eq/EQ/chowdsp_StandardEQParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ struct StandardEQParameters : ParamHolder
};

/** Internal use only! */
chowdsp::ParamHolder paramHolder { bandNamePrefix + juce::String (bandIndex + 1) };
std::optional<ParamHolder> paramHolder { std::nullopt };
};

/** Set of parameter handles for the entire EQ. */
using EQParameterHandles = std::array<EQBandParams, NumBands>;

/** Constructor */
explicit StandardEQParameters (EQParameterHandles&& paramHandles, const juce::String& name = {});
explicit StandardEQParameters (ParamHolder* parent, EQParameterHandles&& paramHandles, std::string_view name = {});

/** Parameter handles */
EQParameterHandles eqParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ namespace parameters_view_detail

std::unique_ptr<juce::Component> createItemComponent() override
{
return std::make_unique<juce::Label> (name, name);
return std::make_unique<juce::Label> (toString (name), toString (name));
}

juce::String name;
std::string_view name;
};
} // namespace parameters_view_detail
#endif
Expand Down
Loading

0 comments on commit 736cad5

Please sign in to comment.