Skip to content

Commit

Permalink
Spectrum Analyser Background Tasks Made Optional and Post EQ for Bric…
Browse files Browse the repository at this point in the history
…kwall
  • Loading branch information
RachelMaryamLocke committed Nov 30, 2023
1 parent 168b876 commit fd6a6e9
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/dsp/Brickwall/BrickwallProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ void BrickwallProcessor::prepare (const juce::dsp::ProcessSpec& spec)
{
filter.prepare (spec);
filter.setQValue (chowdsp::CoefficientCalculators::butterworthQ<float>);
postSpectrumAnalyserTask.prepareToPlay (spec.sampleRate, (int) spec.maximumBlockSize, (int) spec.numChannels);
}

void BrickwallProcessor::reset()
Expand All @@ -20,6 +21,9 @@ void BrickwallProcessor::processBlock (const chowdsp::BufferView<float>& buffer)
filter.setFilterType (getFilterTypeIndex());
filter.setCutoffFrequency (*params.cutoff);
filter.processBlock (buffer);

if (extraState.isEditorOpen.load() && extraState.showPostSpectrum.get())
postSpectrumAnalyserTask.processBlockInput (buffer.toAudioBuffer());
}

int BrickwallProcessor::getFilterTypeIndex() const
Expand Down
22 changes: 21 additions & 1 deletion src/dsp/Brickwall/BrickwallProcessor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "gui/Shared/SpectrumAnalyserTask.h"
#include <pch.h>

namespace dsp::brickwall
Expand Down Expand Up @@ -28,6 +29,13 @@ enum class FilterType
ChebyshevII = 2,
Elliptic = 4,
};

struct ExtraState
{
std::atomic<bool> isEditorOpen { false };
chowdsp::StateValue<std::atomic_bool, bool> showPostSpectrum { "brickwall_show_post_spectrum", true };
};

} // namespace dsp::brickwall

template <>
Expand Down Expand Up @@ -98,16 +106,26 @@ struct Params : chowdsp::ParamHolder
class BrickwallProcessor
{
public:
explicit BrickwallProcessor (const Params& brickwallParams) : params (brickwallParams) {}
explicit BrickwallProcessor (const Params& brickwallParams, const dsp::brickwall::ExtraState& es) : params (brickwallParams), extraState(es){}

void prepare (const juce::dsp::ProcessSpec& spec);
void reset();
void processBlock (const chowdsp::BufferView<float>& buffer) noexcept;

using optionalSpectrumBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;

std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> getSpectrumAnalyserTasks()
{
return {std::nullopt, std::ref(postSpectrumAnalyserTask.SpectrumAnalyserUITask)};
}
// gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask& getSpectrumAnalyserTasks() { return postSpectrumAnalyserTask.SpectrumAnalyserUITask; }


private:
int getFilterTypeIndex() const;

const Params& params;
const dsp::brickwall::ExtraState& extraState;

using EQBand = chowdsp::EQ::EQBand<
float,
Expand Down Expand Up @@ -161,6 +179,8 @@ class BrickwallProcessor
chowdsp::EllipticFilter<16, chowdsp::EllipticFilterType::Highpass>>;
EQBand filter;

gui::SpectrumAnalyserTask postSpectrumAnalyserTask;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BrickwallProcessor)
};
} // namespace dsp::brickwall
9 changes: 8 additions & 1 deletion src/dsp/EQ/EQProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,20 @@ struct ExtraState
class EQProcessor
{
public:

EQProcessor (const EQToolParams& eqParams, const ExtraState& extraState);

void prepare (const juce::dsp::ProcessSpec& spec);
void processBlock (const chowdsp::BufferView<float>& buffer);

int getLatencySamples() const;
std::pair<gui::SpectrumAnalyserTask&, gui::SpectrumAnalyserTask&> getSpectrumAnalyserTasks() { return { preSpectrumAnalyserTask, postSpectrumAnalyserTask }; }

using optionalSpectrumBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;

std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> getSpectrumAnalyserTasks()
{
return {std::ref(preSpectrumAnalyserTask.SpectrumAnalyserUITask), std::ref(postSpectrumAnalyserTask.SpectrumAnalyserUITask)};
}

private:
const EQToolParams& params;
Expand Down
4 changes: 2 additions & 2 deletions src/dsp/MultiToolProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace detail
{ return analog_eq::AnalogEQProcessor { *params.analogEQParams }; }),
tool_maker<band_splitter::BandSplitterProcessor> ([&params]
{ return band_splitter::BandSplitterProcessor { *params.bandSplitParams }; }),
tool_maker<brickwall::BrickwallProcessor> ([&params]
{ return brickwall::BrickwallProcessor { *params.brickwallParams }; }),
tool_maker<brickwall::BrickwallProcessor> ([&params, &pluginState]
{ return brickwall::BrickwallProcessor { *params.brickwallParams, *pluginState.nonParams.brickwallExtraState }; }),
tool_maker<svf::SVFProcessor> ([&params]
{ return svf::SVFProcessor { *params.svfParams }; })
};
Expand Down
55 changes: 53 additions & 2 deletions src/gui/Brickwall/BrickwallEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
#include "BrickwallEditor.h"
#include "BottomBar.h"
#include "gui/Shared/Colours.h"
#include "gui/Shared/LookAndFeels.h"



namespace gui::brickwall
{
BrickwallEditor::BrickwallEditor (State& pluginState, dsp::brickwall::Params& params, const chowdsp::HostContextProvider& hcp)
: plot (pluginState, params, hcp)
BrickwallEditor::BrickwallEditor (State& pluginState,
dsp::brickwall::Params& params,
dsp::brickwall::ExtraState& brickwallExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> spectrumAnalyserTasks)
: extraState(brickwallExtraState),
plot (pluginState, params, hcp),
spectrumAnalyser(plot, spectrumAnalyserTasks)
{
addMouseListener (this, true);
extraState.isEditorOpen.store (true);
spectrumAnalyser.setShowPostEQ (extraState.showPostSpectrum.get());
callbacks += {
extraState.showPostSpectrum.changeBroadcaster.connect ([this]
{
spectrumAnalyser.setShowPostEQ(extraState.showPostSpectrum.get());
spectrumAnalyser.repaint(); }),
};

bottomBar = std::make_unique<BottomBar> (pluginState, params);

addAndMakeVisible (plot);
addAndMakeVisible (bottomBar.get());
addAndMakeVisible (spectrumAnalyser);
spectrumAnalyser.toBehind(bottomBar.get());
// spectrumAnalyser.toBehind(&plot.getCutoffSlider());
}

BrickwallEditor::~BrickwallEditor()
{
removeMouseListener (this);
extraState.isEditorOpen.store (false);
}

void BrickwallEditor::mouseDown (const juce::MouseEvent& event)
{
if (event.mods.isPopupMenu())
{
chowdsp::SharedLNFAllocator lnfAllocator;
juce::PopupMenu menu;

juce::PopupMenu::Item postSpectrumItem;
postSpectrumItem.itemID = 100;
postSpectrumItem.text = extraState.showPostSpectrum.get() ? "Disable Post-EQ Visualizer" : "Enable Post-EQ Visualizer";
postSpectrumItem.action = [this]
{
extraState.showPostSpectrum.set (! extraState.showPostSpectrum.get());
};
menu.addItem (postSpectrumItem);

menu.setLookAndFeel (lnfAllocator->getLookAndFeel<lnf::MenuLNF>());
menu.showMenuAsync (juce::PopupMenu::Options {}
.withParentComponent (getParentComponent()));
}
}

void BrickwallEditor::paint (juce::Graphics& g)
Expand All @@ -28,5 +78,6 @@ void BrickwallEditor::resized()
auto bounds = getLocalBounds();
plot.setBounds (bounds);
bottomBar->setBounds (bounds.removeFromBottom (proportionOfHeight (0.075f)));
spectrumAnalyser.setBounds (getLocalBounds());
}
} // namespace gui::brickwall
18 changes: 17 additions & 1 deletion src/gui/Brickwall/BrickwallEditor.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
#pragma once

#include "BrickwallPlot.h"
#include "gui/Shared/SpectrumAnalyser.h"

using optionalSpectrumBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;

namespace gui::brickwall
{
class BrickwallEditor : public juce::Component
{
public:
BrickwallEditor (State& pluginState, dsp::brickwall::Params& params, const chowdsp::HostContextProvider& hcp);
BrickwallEditor (State& pluginState,
dsp::brickwall::Params& params,
dsp::brickwall::ExtraState& brickwallExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> spectrumAnalyserTasks);

~BrickwallEditor();

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

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

private:

dsp::brickwall::ExtraState& extraState;
chowdsp::ScopedCallbackList callbacks;

BrickwallPlot plot;
std::unique_ptr<juce::Component> bottomBar;
SpectrumAnalyser spectrumAnalyser;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BrickwallEditor)
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Brickwall/BrickwallPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ BrickwallPlot::BrickwallPlot (State& pluginState, dsp::brickwall::Params& brickw
.sampleRate = sampleRate,
.fftOrder = fftOrder,
}),
brickwall (brickwallParams),
brickwall (brickwallParams, *pluginState.nonParams.brickwallExtraState),
cutoffSlider (*brickwallParams.cutoff, *this, pluginState, hcp),
chyron (pluginState, brickwallParams, hcp)
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/Brickwall/BrickwallPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BrickwallPlot : public chowdsp::SpectrumPlotBase
void paint (juce::Graphics& g) override;
void paintOverChildren (juce::Graphics& g) override;
void resized() override;
// juce::Slider& getCutoffSlider(){ return cutoffSlider ;}

private:
void updatePlot();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/EQ/EQEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EQEditor::EQEditor (State& pluginState,
dsp::eq::EQToolParams& eqParams,
dsp::eq::ExtraState& eqExtraState,
const chowdsp::HostContextProvider& hcp,
std::pair<SpectrumAnalyserTask&, SpectrumAnalyserTask&> spectrumAnalyserTasks)
std::pair<optionalSpectrumBackgroundTask , optionalSpectrumBackgroundTask> spectrumAnalyserTasks)
: params (eqParams),
extraState (eqExtraState),
plot (pluginState, eqParams.eqParams, hcp),
Expand Down
4 changes: 3 additions & 1 deletion src/gui/EQ/EQEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// - Figure out type-in values for chyron
// - Better controls for Q values

using optionalSpectrumBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;

namespace gui::eq
{
class EQEditor : public juce::Component
Expand All @@ -17,7 +19,7 @@ class EQEditor : public juce::Component
dsp::eq::EQToolParams& eqParams,
dsp::eq::ExtraState& extraState,
const chowdsp::HostContextProvider& hcp,
std::pair<SpectrumAnalyserTask&, SpectrumAnalyserTask&> spectrumAnalyserTasks);
std::pair<optionalSpectrumBackgroundTask , optionalSpectrumBackgroundTask> spectrumAnalyserTasks);
~EQEditor() override;

void paint (juce::Graphics& g) override;
Expand Down
6 changes: 5 additions & 1 deletion src/gui/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ void PluginEditor::refreshEditor()
else if constexpr (std::is_same_v<ToolType, dsp::band_splitter::BandSplitterProcessor>)
editorComponent = std::make_unique<band_splitter::BandSplitterEditor> (pluginState, *pluginState.params.bandSplitParams, hostContextProvider);
else if constexpr (std::is_same_v<ToolType, dsp::brickwall::BrickwallProcessor>)
editorComponent = std::make_unique<brickwall::BrickwallEditor> (pluginState, *pluginState.params.brickwallParams, hostContextProvider);
editorComponent = std::make_unique<brickwall::BrickwallEditor> (pluginState,
*pluginState.params.brickwallParams,
*pluginState.nonParams.brickwallExtraState,
hostContextProvider,
std::get<dsp::brickwall::BrickwallProcessor> (plugin.getProcessor().getTools()).getSpectrumAnalyserTasks());
else if constexpr (std::is_same_v<ToolType, dsp::svf::SVFProcessor>)
editorComponent = std::make_unique<svf::SVFEditor> (pluginState, *pluginState.params.svfParams, hostContextProvider);
});
Expand Down
36 changes: 20 additions & 16 deletions src/gui/Shared/SpectrumAnalyser.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include "SpectrumAnalyser.h"
#include "gui/Shared/Colours.h"

SpectrumAnalyser::SpectrumAnalyser (const chowdsp::SpectrumPlotBase& eqPlot, std::pair<gui::SpectrumAnalyserTask&, gui::SpectrumAnalyserTask&> spectrumAnalyserTasks)
SpectrumAnalyser::SpectrumAnalyser (const chowdsp::SpectrumPlotBase& eqPlot, std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> spectrumAnalyserTasks)
: eqPlot (eqPlot),
preTask (spectrumAnalyserTasks.first.SpectrumAnalyserUITask),
postTask (spectrumAnalyserTasks.second.SpectrumAnalyserUITask)
preTask (spectrumAnalyserTasks.first.has_value() ? std::ref(spectrumAnalyserTasks.first).get() : std::nullopt),
postTask (spectrumAnalyserTasks.second.has_value() ? std::ref(spectrumAnalyserTasks.second).get() : std::nullopt)

{
}

SpectrumAnalyser::~SpectrumAnalyser()
{
if (preTask.isTaskRunning())
preTask.setShouldBeRunning (false);
if (postTask.isTaskRunning())
postTask.setShouldBeRunning (false);
if (preTask && preTask->get().isTaskRunning())
preTask->get().setShouldBeRunning (false);
if (postTask && postTask->get().isTaskRunning())
postTask->get().setShouldBeRunning (false);
}

void SpectrumAnalyser::paint (juce::Graphics& g)
{
// g.fillAll(juce::Colours::whitesmoke.withAlpha(0.4f));
// g.fillAll(juce::Colours::whitesmoke.withAlpha(0.4f));

if (showPreEQ)
{
Expand All @@ -41,24 +41,28 @@ void SpectrumAnalyser::visibilityChanged()
{
if (isVisible())
{
preTask.setShouldBeRunning (showPreEQ);
postTask.setShouldBeRunning (showPostEQ);
if (preTask)
preTask->get().setShouldBeRunning (showPreEQ);
if (postTask)
postTask->get().setShouldBeRunning (showPostEQ);
startTimerHz (32);
}
else
{
preTask.setShouldBeRunning (false);
postTask.setShouldBeRunning (false);
if (preTask)
preTask->get().setShouldBeRunning (false);
if (postTask)
postTask->get().setShouldBeRunning (false);
stopTimer();
}
}

void SpectrumAnalyser::timerCallback()
{
if (showPreEQ)
updatePlotPath (prePath, preTask);
if (showPostEQ)
updatePlotPath (postPath, postTask);
if (preTask && showPreEQ)
updatePlotPath (prePath, preTask->get());
if (postTask && showPostEQ)
updatePlotPath (postPath, postTask->get());
}

void SpectrumAnalyser::updatePlotPath (juce::Path& pathToUpdate, gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask& taskToUpdate)
Expand Down
9 changes: 6 additions & 3 deletions src/gui/Shared/SpectrumAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include "SpectrumAnalyserTask.h"
#include "dsp/MultiToolProcessor.h"

using optionalSpectrumBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;

class SpectrumAnalyser : public juce::Component,
public juce::Timer
{
public:
SpectrumAnalyser (const chowdsp::SpectrumPlotBase& eqPlot, std::pair<gui::SpectrumAnalyserTask&, gui::SpectrumAnalyserTask&> spectrumAnalyserTasks);
SpectrumAnalyser (const chowdsp::SpectrumPlotBase& eqPlot, std::pair<optionalSpectrumBackgroundTask, optionalSpectrumBackgroundTask> spectrumAnalyserTasks);
~SpectrumAnalyser() override;
void paint (juce::Graphics& g) override;
void visibilityChanged() override;
Expand All @@ -18,11 +20,12 @@ class SpectrumAnalyser : public juce::Component,
void setShowPostEQ (bool showPostSpectrum) { showPostEQ = showPostSpectrum; }

private:
using optionalBackgroundTask = std::optional<std::reference_wrapper<gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask>>;
juce::Path prePath;
juce::Path postPath;
const chowdsp::SpectrumPlotBase& eqPlot;
gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask& preTask;
gui::SpectrumAnalyserTask::SpectrumAnalyserBackgroundTask& postTask;
optionalBackgroundTask preTask;
optionalBackgroundTask postTask;
bool showPreEQ = true;
bool showPostEQ = true;

Expand Down
2 changes: 2 additions & 0 deletions src/state/PluginState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ PluginExtraState::PluginExtraState()
{
waveshaperExtraState = std::make_unique<dsp::waveshaper::ExtraState>();
eqExtraState.emplace();
brickwallExtraState.emplace();

addStateValues ({ &waveshaperExtraState->freeDrawState,
&waveshaperExtraState->mathState,
&waveshaperExtraState->pointsState,
&eqExtraState->showPreSpectrum,
&eqExtraState->showPostSpectrum,
&brickwallExtraState->showPostSpectrum,
&editorBounds });
}

Expand Down
Loading

0 comments on commit fd6a6e9

Please sign in to comment.