Skip to content

Commit

Permalink
Clean Gain: change colours when inverted and add option to extend gai…
Browse files Browse the repository at this point in the history
…n range (#215)
  • Loading branch information
jatinchowdhury18 committed Oct 14, 2022
1 parent 807a40b commit d6fc65c
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 74 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ target_sources(BYOD PRIVATE
processors/other/spring_reverb/SpringReverb.cpp
processors/other/spring_reverb/SpringReverbProcessor.cpp

processors/utility/CleanGain.cpp
processors/utility/FreqBandSplitter.cpp
processors/utility/InputProcessor.cpp
processors/utility/Mixer.cpp
Expand Down
79 changes: 50 additions & 29 deletions src/gui/pedalboard/editors/KnobsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ KnobsComponent::KnobsComponent (BaseProcessor& baseProc,
const Colour& cc,
const Colour& ac,
const HostContextProvider& hostContextProvider)
: contrastColour (cc), accentColour (ac)
{
const auto addSlider = [this,
&vts,
Expand All @@ -27,12 +26,6 @@ KnobsComponent::KnobsComponent (BaseProcessor& baseProc,
newSlide->setSliderStyle (Slider::RotaryHorizontalVerticalDrag);
newSlide->setName (param->name);
newSlide->setTextBoxStyle (Slider::TextBoxBelow, false, 80, 20);
newSlide->setColour (Slider::textBoxOutlineColourId, contrastColour);
newSlide->setColour (Slider::textBoxTextColourId, contrastColour);
newSlide->setColour (Slider::textBoxBackgroundColourId, Colours::transparentWhite);
newSlide->setColour (Slider::textBoxHighlightColourId, accentColour.withAlpha (0.55f));
newSlide->setColour (Slider::thumbColourId, accentColour);

sliders.add (std::move (newSlide));
};

Expand All @@ -44,12 +37,7 @@ KnobsComponent::KnobsComponent (BaseProcessor& baseProc,
newBox->setName (param->name);
newBox->addItemList (param->choices, 1);
newBox->setSelectedItemIndex (0);
newBox->setColour (ComboBox::outlineColourId, contrastColour);
newBox->setColour (ComboBox::textColourId, contrastColour);
newBox->setColour (ComboBox::arrowColourId, contrastColour);

newBox->attachment = std::make_unique<ComboBoxAttachment> (vts, param->paramID, *newBox);

boxes.add (std::move (newBox));
};

Expand All @@ -63,12 +51,7 @@ KnobsComponent::KnobsComponent (BaseProcessor& baseProc,
newButton->setComponentID (param->paramID);
newButton->setButtonText (param->name);
newButton->setClickingTogglesState (true);
newButton->setColour (TextButton::buttonColourId, contrastColour.withAlpha (0.4f));
newButton->setColour (TextButton::buttonOnColourId, accentColour);
newButton->setColour (TextButton::textColourOnId, contrastColour);

newButton->attachment = std::make_unique<ButtonAttachment> (vts, param->paramID, *newButton);

buttons.add (std::move (newButton));
};

Expand Down Expand Up @@ -113,37 +96,75 @@ KnobsComponent::KnobsComponent (BaseProcessor& baseProc,
if (auto* sliderComp = dynamic_cast<Slider*> (comp))
{
sliderComp->setSliderStyle (Slider::RotaryHorizontalVerticalDrag);
sliderComp->setColour (Slider::textBoxOutlineColourId, contrastColour);
sliderComp->setColour (Slider::textBoxTextColourId, contrastColour);
sliderComp->setColour (Slider::textBoxBackgroundColourId, Colours::transparentWhite);
sliderComp->setColour (Slider::textBoxHighlightColourId, accentColour.withAlpha (0.55f));
sliderComp->setColour (Slider::thumbColourId, accentColour);

customComponents.removeObject (comp, false);

if (customComponentsFirst)
sliders.insert (0, sliderComp);
else
sliders.add (sliderComp);
}
else if (auto* boxComp = dynamic_cast<ComboBox*> (comp))
{
boxComp->setColour (ComboBox::outlineColourId, contrastColour);
boxComp->setColour (ComboBox::textColourId, contrastColour);
boxComp->setColour (ComboBox::arrowColourId, contrastColour);

customComponents.removeObject (comp, false);

if (customComponentsFirst)
boxes.insert (0, boxComp);
else
boxes.add (boxComp);
}
}

setColours (cc, ac);
setSize (getWidth(), 100);
}

void KnobsComponent::setColours (const Colour& cc, const Colour& ac)
{
contrastColour = cc;
accentColour = ac;

for (auto* slider : sliders)
{
slider->setColour (Slider::textBoxOutlineColourId, contrastColour);
slider->setColour (Slider::textBoxTextColourId, contrastColour);
slider->setColour (Slider::textBoxBackgroundColourId, Colours::transparentWhite);
slider->setColour (Slider::textBoxHighlightColourId, accentColour.withAlpha (0.55f));
slider->setColour (Slider::thumbColourId, accentColour);
}

for (auto* box : boxes)
{
box->setColour (ComboBox::outlineColourId, contrastColour);
box->setColour (ComboBox::textColourId, contrastColour);
box->setColour (ComboBox::arrowColourId, contrastColour);
}

for (auto* button : buttons)
{
button->setColour (TextButton::buttonColourId, contrastColour.withAlpha (0.4f));
button->setColour (TextButton::buttonOnColourId, accentColour);
button->setColour (TextButton::textColourOnId, contrastColour);
}

for (auto* comp : customComponents)
{
if (auto* sliderComp = dynamic_cast<Slider*> (comp))
{
sliderComp->setColour (Slider::textBoxOutlineColourId, contrastColour);
sliderComp->setColour (Slider::textBoxTextColourId, contrastColour);
sliderComp->setColour (Slider::textBoxBackgroundColourId, Colours::transparentWhite);
sliderComp->setColour (Slider::textBoxHighlightColourId, accentColour.withAlpha (0.55f));
sliderComp->setColour (Slider::thumbColourId, accentColour);
}
else if (auto* boxComp = dynamic_cast<ComboBox*> (comp))
{
boxComp->setColour (ComboBox::outlineColourId, contrastColour);
boxComp->setColour (ComboBox::textColourId, contrastColour);
boxComp->setColour (ComboBox::arrowColourId, contrastColour);
}
}

repaint();
}

void KnobsComponent::toggleParamsEnabled (const std::vector<String>& paramIDs, bool shouldEnable)
{
for (auto* comp : getChildren())
Expand Down
6 changes: 4 additions & 2 deletions src/gui/pedalboard/editors/KnobsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class KnobsComponent : public Component

void toggleParamsEnabled (const std::vector<String>& paramIDs, bool shouldEnable);

void setColours (const Colour& contrastColour, const Colour& accentColour);

private:
using SliderAttachment = AudioProcessorValueTreeState::SliderAttachment;
using ComboBoxAttachment = AudioProcessorValueTreeState::ComboBoxAttachment;
Expand All @@ -43,8 +45,8 @@ class KnobsComponent : public Component
OwnedArray<TextButton> buttons;
OwnedArray<Component> customComponents;

const Colour& contrastColour;
const Colour& accentColour;
Colour contrastColour;
Colour accentColour;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KnobsComponent)
};
11 changes: 8 additions & 3 deletions src/gui/pedalboard/editors/PowerButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ class PowerButton : public Component
addAndMakeVisible (button);
button.setClickingTogglesState (true);

button.onStateChange = [this]
{ enableDisable(); };

setupPowerButton (powerColour);
}

void setupPowerButton (const Colour& powerColour)
{
auto onImage = Drawable::createFromImageData (BinaryData::PowerButton_svg, BinaryData::PowerButton_svgSize);
auto offImage = onImage->createCopy();

onImage->replaceColour (Colours::black, powerColour);
offImage->replaceColour (Colours::black, Colours::darkgrey);
button.setImages (offImage.get(), offImage.get(), onImage.get(), offImage.get(), onImage.get(), onImage.get(), offImage.get());

button.onStateChange = [=]
{ enableDisable(); };
}

void resized() override
Expand Down
8 changes: 8 additions & 0 deletions src/gui/pedalboard/editors/ProcessorEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ ProcessorEditor::ProcessorEditor (BaseProcessor& baseProc,

for (int i = 0; i < proc.getNumInputs(); ++i)
toggleParamsEnabledOnInputConnectionChange (i, false);

uiOptionsChangedCallback = proc.uiOptionsChanged.connect (
[this]
{
contrastColour = procUI.backgroundColour.contrasting();
knobs.setColours (contrastColour, procUI.powerColour);
powerButton.setupPowerButton (procUI.powerColour);
});
}

ProcessorEditor::~ProcessorEditor() = default;
Expand Down
4 changes: 3 additions & 1 deletion src/gui/pedalboard/editors/ProcessorEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProcessorEditor : public Component
BaseProcessor& proc;
ProcessorChain& procChain;

ProcessorUIOptions& procUI;
const ProcessorUIOptions& procUI;
Colour contrastColour;

KnobsComponent knobs;
Expand All @@ -56,6 +56,8 @@ class ProcessorEditor : public Component

DrawableButton settingsButton { "Settings", DrawableButton::ImageFitted };

chowdsp::ScopedCallback uiOptionsChangedCallback;

chowdsp::SharedLNFAllocator lnfAllocator;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorEditor)
Expand Down
3 changes: 3 additions & 0 deletions src/processors/BaseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class BaseProcessor : private JuceProcWrapper
ProcessorUIOptions& getUIOptions() { return uiOptions; }
const ProcessorUIOptions& getUIOptions() const { return uiOptions; }

/** If a processor changes its UI options after construction it should call this to alert the editor. */
chowdsp::Broadcaster<void()> uiOptionsChanged;

/**
* If your processor has custom UI components, create them here!
*
Expand Down
Loading

0 comments on commit d6fc65c

Please sign in to comment.