Skip to content

Commit

Permalink
Tri-state button logic adjusted to account for automation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Jan 17, 2024
1 parent 41eceb8 commit b0cce36
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/dsp/BandSplitter/BandSplitterProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>
}
else if (params.threeBandOnOff->get())
{
bufferLowMid.clear();
bufferHighMid.clear();
processCrossover (threeBandFilters, processThreeBandFilter);
if (extraState.isEditorOpen.load() && extraState.showSpectrum.get())
{
Expand All @@ -120,6 +122,8 @@ void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>
else
{
bufferMid.clear();
bufferLowMid.clear();
bufferHighMid.clear();
processCrossover (twoBandFilters, processTwoBandFilter);
if (extraState.isEditorOpen.load() && extraState.showSpectrum.get())
{
Expand Down
2 changes: 1 addition & 1 deletion src/dsp/BandSplitter/BandSplitterProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Params : chowdsp::ParamHolder
juce::ParameterID { "band_split_cutoff3", ParameterVersionHints::version1_1_0 },
"Band Splitter Cutoff 3",
chowdsp::ParamUtils::createNormalisableRange (20.0f, 20000.0f, 2000.0f),
10000.0f
15000.0f
};

chowdsp::BoolParameter::Ptr threeBandOnOff {
Expand Down
6 changes: 3 additions & 3 deletions src/gui/BandSplitter/BandSplitterEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BandSplitterEditor::BandSplitterEditor (State& pluginState,
spectrumTasks),
slopePicker (pluginState, *params.slope),
extraState (bandSplitterExtraState),
triStateButton (*params.threeBandOnOff, *params.fourBandOnOff)
triStateButton (*params.threeBandOnOff, *params.fourBandOnOff, pluginState)
{
addAndMakeVisible (bandSplitterPlot);
addAndMakeVisible (slopePicker);
Expand Down Expand Up @@ -47,10 +47,10 @@ void BandSplitterEditor::resized()
triStateButton.setBounds (getWidth() - pad - dim, pad, dim, dim);
}

BandSplitterEditor::TriStateButton::TriStateButton (chowdsp::BoolParameter& threeBandOnOff, chowdsp::BoolParameter& fourBandOnOff) : juce::Button ("TriState"),
BandSplitterEditor::TriStateButton::TriStateButton (chowdsp::BoolParameter& threeBandOnOff, chowdsp::BoolParameter& fourBandOnOff, State& pluginState) : juce::Button ("TriState"),
threeBandOnOffParam (threeBandOnOff),
fourBandOnOffParam (fourBandOnOff),
triStateButtonAttachment (threeBandOnOff, fourBandOnOff, *this, currentState)
triStateButtonAttachment (threeBandOnOff, fourBandOnOff, pluginState, *this, currentState)
{
currentState = (threeBandOnOffParam.get() && fourBandOnOffParam.get()) ? std::make_pair (BandState::FourBands, 4) : threeBandOnOffParam.get() ? std::make_pair (BandState::ThreeBands, 3)
: std::make_pair (BandState::TwoBands, 2);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/BandSplitter/BandSplitterEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BandSplitterEditor : public juce::Component

struct TriStateButton : public juce::Button
{
TriStateButton (chowdsp::BoolParameter& threeBandOnOff, chowdsp::BoolParameter& fourBandOnOff);
TriStateButton (chowdsp::BoolParameter& threeBandOnOff, chowdsp::BoolParameter& fourBandOnOff, State& pluginState);
void paintButton (juce::Graphics& g, bool, bool) override;
chowdsp::BoolParameter& threeBandOnOffParam;
chowdsp::BoolParameter& fourBandOnOffParam;
Expand Down
20 changes: 11 additions & 9 deletions src/gui/BandSplitter/BandSplitterPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ BandSplitterPlot::BandSplitterPlot (State& pluginState,
for (int bandIndex = 0; bandIndex < numBands; ++bandIndex)
setFilterActive (bandIndex, true);

getCutoffParam = [this](int bandIndex) -> const chowdsp::FreqHzParameter::Ptr& {
if (bandIndex < (numBands / 3))
return bandSplitterParams.cutoff;
else if (bandIndex <= numBands / 2)
return bandSplitterParams.cutoff2;
else
return bandSplitterParams.cutoff3;
};

callbacks +=
{
pluginState.addParameterListener (*bandSplitterParams.cutoff,
Expand Down Expand Up @@ -179,10 +188,7 @@ void BandSplitterPlot::updateCutoffFrequency()
{
for (int bandIndex = 0; bandIndex < numBands; ++bandIndex) //bands 0, 1, 2, 3, 4, 5
{
//bands 1 & 2 assigned cutoff 1, bands 2 & 3 assigned cutoff 2, bands 5 & 6 assigned cutoff 3 - this will be the current cutoff frequency in Hz
const auto& cutoffParam = bandIndex < (numBands / 3) ? bandSplitterParams.cutoff : bandIndex <= numBands / 2 ? bandSplitterParams.cutoff2
: bandSplitterParams.cutoff3;
setCutoffParameter (bandIndex, cutoffParam->get());
setCutoffParameter (bandIndex, getCutoffParam(bandIndex)->get());
updateFilterPlotPath (bandIndex);
}
}
Expand Down Expand Up @@ -217,10 +223,7 @@ void BandSplitterPlot::updateFilterSlope()

for (int bandIndex = 0; bandIndex < numBands; ++bandIndex)
{
const auto& cutoffParam = bandIndex < (numBands / 3) ? bandSplitterParams.cutoff : bandIndex <= numBands / 2 ? bandSplitterParams.cutoff2
: bandSplitterParams.cutoff3;

setCutoffParameter (bandIndex, cutoffParam->get());
setCutoffParameter (bandIndex, getCutoffParam(bandIndex)->get());
setQParameter (bandIndex, 0.5f);
updateFilterPlotPath (bandIndex);
}
Expand Down Expand Up @@ -251,7 +254,6 @@ void BandSplitterPlot::paintOverChildren (juce::Graphics& g)
g.strokePath (getPath (2), juce::PathStrokeType { 2.0f });
g.strokePath (getPath (3), juce::PathStrokeType { 2.0f });
}

if (bandSplitterParams.fourBandOnOff->get())
{
g.strokePath (getPath (4), juce::PathStrokeType { 2.0f });
Expand Down
1 change: 1 addition & 0 deletions src/gui/BandSplitter/BandSplitterPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BandSplitterPlot : public chowdsp::EQ::EqualizerPlot
void updateCutoffFrequency();
void updateFilterSlope();
void updateSpectrumPlots();
std::function<const chowdsp::FreqHzParameter::Ptr&(int)> getCutoffParam;

const dsp::band_splitter::Params& bandSplitterParams;
dsp::band_splitter::ExtraState& extraState;
Expand Down
16 changes: 12 additions & 4 deletions src/gui/BandSplitter/TriStateButtonAttachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ namespace gui::band_splitter
{
TriStateButtonAttachment::TriStateButtonAttachment (chowdsp::BoolParameter& threeBandParam,
chowdsp::BoolParameter& fourBandParam,
chowdsp::PluginState& pluginState,
juce::Button& triStateButton,
std::pair<BandState, int>& currentState)
: bandStateButton (&triStateButton), currentState (currentState), threeBandParam (threeBandParam), fourBandParam (fourBandParam)
: threeBandAttachment(threeBandParam, pluginState, [this](bool threeBandOn) { updateButtonState(); }),
fourBandAttachment(fourBandParam, pluginState, [this](bool fourBandOn) { updateButtonState(); }),
bandStateButton (&triStateButton),
um(pluginState.undoManager),
currentState (currentState),
threeBandParam (threeBandParam),
fourBandParam (fourBandParam)
{
updateButtonState();
bandStateButton->addListener (this);
Expand All @@ -29,6 +36,7 @@ void TriStateButtonAttachment::updateButtonState()
currentState = std::make_pair (BandState::ThreeBands, 3);
else
currentState = std::make_pair (BandState::FourBands, 4);
bandStateButton->repaint();
}

void TriStateButtonAttachment::buttonClicked (juce::Button* button)
Expand All @@ -38,21 +46,21 @@ void TriStateButtonAttachment::buttonClicked (juce::Button* button)

if (currentState.first == BandState::TwoBands)
{
currentState = std::make_pair (BandState::ThreeBands, 3);
threeBandParam.setValueNotifyingHost (true);
fourBandParam.setValueNotifyingHost (false);
}
else if (currentState.first == BandState::ThreeBands)
{
currentState = std::make_pair (BandState::FourBands, 4);
threeBandParam.setValueNotifyingHost (true);
fourBandParam.setValueNotifyingHost (true);
}
else if (currentState.first == BandState::FourBands)
{
currentState = std::make_pair (BandState::TwoBands, 2);
threeBandParam.setValueNotifyingHost (false);
fourBandParam.setValueNotifyingHost (false);
}

threeBandAttachment.setValueAsCompleteGesture(threeBandParam.get(), um);
fourBandAttachment.setValueAsCompleteGesture(fourBandParam.get(), um);
}
} // namespace gui::band_splitter
5 changes: 5 additions & 0 deletions src/gui/BandSplitter/TriStateButtonAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TriStateButtonAttachment : public juce::Button::Listener
public:
TriStateButtonAttachment (chowdsp::BoolParameter& threeBandParam,
chowdsp::BoolParameter& fourBandParam,
chowdsp::PluginState& pluginState,
juce::Button& triStateButton,
std::pair<BandState, int>& currentState);

Expand All @@ -18,7 +19,11 @@ class TriStateButtonAttachment : public juce::Button::Listener
private:
void buttonClicked (juce::Button* button) override;

chowdsp::ParameterAttachment<chowdsp::BoolParameter> threeBandAttachment;
chowdsp::ParameterAttachment<chowdsp::BoolParameter> fourBandAttachment;

juce::Button* bandStateButton = nullptr;
juce::UndoManager* um = nullptr;
std::pair<BandState, int>& currentState;
chowdsp::BoolParameter& threeBandParam;
chowdsp::BoolParameter& fourBandParam;
Expand Down

0 comments on commit b0cce36

Please sign in to comment.