Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing undo/redo issue
Browse files Browse the repository at this point in the history
jatinchowdhury18 committed Jan 19, 2024
1 parent 273f578 commit 8a18438
Showing 6 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/dsp/BandSplitter/BandSplitterProcessor.cpp
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ void BandSplitterProcessor::processBlock (const chowdsp::BufferView<const float>
processFilter (bandFilters.filter12);
};

const auto currentBandState = getCurrentBandState();
if (params.fourBandOnOff->get())
{
bufferMid.clear();
18 changes: 18 additions & 0 deletions src/dsp/BandSplitter/BandSplitterProcessor.h
Original file line number Diff line number Diff line change
@@ -14,6 +14,13 @@ enum class Slope
m72_dBpOct = 16,
};

enum class BandState
{
TwoBands,
ThreeBands,
FourBands,
};

struct Params : chowdsp::ParamHolder
{
Params()
@@ -60,6 +67,17 @@ struct Params : chowdsp::ParamHolder
"Band Splitter 4-Band",
false
};

BandState getCurrentBandState() const
{
if (fourBandOnOff->get())
return BandState::FourBands;

if (threeBandOnOff->get())
return BandState::ThreeBands;

return BandState::TwoBands;
}
};

struct ExtraState
6 changes: 3 additions & 3 deletions src/gui/BandSplitter/BandSplitterEditor.cpp
Original file line number Diff line number Diff line change
@@ -50,9 +50,9 @@ void BandSplitterEditor::resized()
BandSplitterEditor::TriStateButton::TriStateButton (State& pluginState) : juce::Button ("TriState"),
triStateButtonAttachment (pluginState, *this, currentState)
{
currentState = (pluginState.params.bandSplitParams->threeBandOnOff.get() && pluginState.params.bandSplitParams->fourBandOnOff.get()) ? std::make_pair (BandState::FourBands, 4)
: pluginState.params.bandSplitParams->threeBandOnOff.get() ? std::make_pair (BandState::ThreeBands, 3)
: std::make_pair (BandState::TwoBands, 2);
currentState = (pluginState.params.bandSplitParams->threeBandOnOff->get() && pluginState.params.bandSplitParams->fourBandOnOff->get()) ? std::make_pair (BandState::FourBands, 4)
: pluginState.params.bandSplitParams->threeBandOnOff->get() ? std::make_pair (BandState::ThreeBands, 3)
: std::make_pair (BandState::TwoBands, 2);
}

void BandSplitterEditor::TriStateButton::paintButton (juce::Graphics& g, bool, bool)
6 changes: 0 additions & 6 deletions src/gui/BandSplitter/BandSplitterEditor.h
Original file line number Diff line number Diff line change
@@ -8,12 +8,6 @@

namespace gui::band_splitter
{
enum class BandState
{
TwoBands,
ThreeBands,
FourBands,
};
class BandSplitterEditor : public juce::Component
{
public:
45 changes: 39 additions & 6 deletions src/gui/BandSplitter/TriStateButtonAttachment.cpp
Original file line number Diff line number Diff line change
@@ -39,25 +39,58 @@ void TriStateButtonAttachment::updateButtonState()
bandStateButton->repaint();
}

void TriStateButtonAttachment::setParametersFromUI (BandState newBandState)
{
auto setParameter = [this] (chowdsp::BoolParameter& param, bool newValue)
{
if (param.get() == newValue)
return;

um->perform (
new chowdsp::ParameterAttachmentHelpers::ParameterChangeAction (
param,
chowdsp::ParameterTypeHelpers::getValue (param),
newValue));

param.beginChangeGesture();
chowdsp::ParameterTypeHelpers::setValue (newValue, param);
param.endChangeGesture();
};

um->beginNewTransaction();
if (newBandState == BandState::TwoBands)
{
setParameter (*threeBandAttachment.param, false);
setParameter (*fourBandAttachment.param, false);
}
else if (newBandState == BandState::ThreeBands)
{
setParameter (*threeBandAttachment.param, true);
setParameter (*fourBandAttachment.param, false);
}
else if (newBandState == BandState::FourBands)
{
setParameter (*threeBandAttachment.param, true);
setParameter (*fourBandAttachment.param, true);
}
}

void TriStateButtonAttachment::buttonClicked (juce::Button* button)
{
if (button != bandStateButton)
return;

if (currentState.first == BandState::TwoBands)
{
threeBandAttachment.setValueAsCompleteGesture (true, um);
fourBandAttachment.setValueAsCompleteGesture (false, um);
setParametersFromUI (BandState::ThreeBands);
}
else if (currentState.first == BandState::ThreeBands)
{
threeBandAttachment.setValueAsCompleteGesture (true, um);
fourBandAttachment.setValueAsCompleteGesture (true, um);
setParametersFromUI (BandState::FourBands);
}
else if (currentState.first == BandState::FourBands)
{
threeBandAttachment.setValueAsCompleteGesture (false, um);
fourBandAttachment.setValueAsCompleteGesture (false, um);
setParametersFromUI (BandState::TwoBands);
}
}
} // namespace gui::band_splitter
10 changes: 9 additions & 1 deletion src/gui/BandSplitter/TriStateButtonAttachment.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#pragma once

#include "state/PluginState.h"
namespace gui::band_splitter

namespace dsp::band_splitter
{
enum class BandState;
}

namespace gui::band_splitter
{
using BandState = dsp::band_splitter::BandState;
class TriStateButtonAttachment : public juce::Button::Listener
{
public:
@@ -18,6 +24,8 @@ class TriStateButtonAttachment : public juce::Button::Listener
private:
void buttonClicked (juce::Button* button) override;

void setParametersFromUI (BandState newBandState);

chowdsp::BoolParameter& threeBandParam;
chowdsp::BoolParameter& fourBandParam;
chowdsp::ParameterAttachment<chowdsp::BoolParameter> threeBandAttachment;

0 comments on commit 8a18438

Please sign in to comment.