diff --git a/CMakeLists.txt b/CMakeLists.txt index d78a819a..1cd35f6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,8 +72,10 @@ set(SourceFiles src/gui/panels/ValentineCenterPanel.h src/gui/panels/ValentineMainPanel.h + src/gui/panels/ValentineTopRowPanel.h src/gui/panels/ValentineCenterPanel.cpp src/gui/panels/ValentineMainPanel.cpp + src/gui/panels/ValentineTopRowPanel.cpp libs/tote_bag/dsp/AudioHelpers.h libs/tote_bag/dsp/CircularBuffer.h diff --git a/src/gui/panels/ValentineCenterPanel.cpp b/src/gui/panels/ValentineCenterPanel.cpp index 4dbe4163..f1281f8f 100644 --- a/src/gui/panels/ValentineCenterPanel.cpp +++ b/src/gui/panels/ValentineCenterPanel.cpp @@ -27,20 +27,7 @@ inline const juce::String kMixSliderText = "MIX"; CenterPanel::CenterPanel (ValentineAudioProcessor& processor) : borderLineThickness (0.0f) , borderCornerSize (0.0f) - , crushEnableButton (parameterID (VParameter::crushEnable), processor.treeState) - , crushSlider (detail::kCrushSliderText, - parameterID (VParameter::bitCrush), - processor.treeState) - , compressSlider (detail::kCompressSliderText, - parameterID (VParameter::inputGain), - processor.treeState) - , saturateEnableButton (parameterID (VParameter::saturateEnable), processor.treeState) - , saturateSlider (detail::kSaturateSliderText, - parameterID (VParameter::saturation), - processor.treeState) - , valentineTblLogo ( - juce::Drawable::createFromImageData (BinaryData::val_totebag_logo_svg, - BinaryData::val_totebag_logo_svgSize)) + , topRow (processor) , ratioSlider (detail::kRatioSliderText, parameterID (VParameter::ratio), processor.treeState) @@ -58,12 +45,7 @@ CenterPanel::CenterPanel (ValentineAudioProcessor& processor) parameterID (VParameter::dryWet), processor.treeState) { - addAndMakeVisible (crushEnableButton); - addAndMakeVisible (crushSlider); - addAndMakeVisible (compressSlider); - addAndMakeVisible (saturateEnableButton); - addAndMakeVisible (saturateSlider); - addAndMakeVisible (valentineTblLogo.get()); + addAndMakeVisible (topRow); addAndMakeVisible (ratioSlider); addAndMakeVisible (attackSlider); addAndMakeVisible (releaseSlider); @@ -108,65 +90,7 @@ void CenterPanel::resized() auto topRowComponents = topRowBorder.reduced (juce::roundToInt (margin)); - auto topRowSliders = topRowComponents.removeFromLeft ( - juce::roundToInt (topRowComponents.getWidth() * .65f)); - const auto topRowButtonWidth = juce::roundToInt (topRowSliders.getWidth() * .033f); - const auto adjustedTopRowComponentsWidth = - topRowSliders.getWidth() - (topRowButtonWidth * 2.0f); - const auto topRowSliderWidth = - juce::roundToInt (adjustedTopRowComponentsWidth / 3.0f); - - const auto topRowButtonSpacer = - juce::roundToInt ((topRowSliders.getHeight() - topRowButtonWidth) * .5f); - - // See below note about horizontal LabelSlider dimensions and button placement. - const auto topRowButtonNudge = juce::roundToInt (topRowButtonWidth / 1.5f); - - const auto initialCrushButtonX = topRowSliders.getX(); - const auto crushEnableButtonBounds = - topRowSliders.removeFromLeft (topRowButtonWidth) - .reduced (0, topRowButtonSpacer) - .withX (initialCrushButtonX + topRowButtonNudge); - - crushEnableButton.setBounds (crushEnableButtonBounds); - crushSlider.setBounds ( - topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); - compressSlider.setBounds (topRowSliders.removeFromLeft (topRowSliderWidth)); - - const auto initialSaturateButtonX = topRowSliders.getX(); - const auto saturateEnableButtonBounds = - topRowSliders.removeFromLeft (topRowButtonWidth) - .reduced (0, topRowButtonSpacer) - .withX (initialSaturateButtonX + topRowButtonNudge); - - saturateEnableButton.setBounds (saturateEnableButtonBounds); - saturateSlider.setBounds ( - topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); - - const auto logoHeight = topRowComponents.getHeight() * .25f; - const auto logoWidth = topRowComponents.getWidth() * .75f; - - const auto logoVerticalSpacer = (topRowComponents.getHeight() - logoHeight) / 2.0f; - topRowComponents.removeFromTop (juce::roundToInt (logoVerticalSpacer)); - - const auto logoHorizontalSpacer = (topRowComponents.getWidth() - logoWidth) / 2.0f; - - // logoHorizontalSpacer is the amount we hypothetically should remove from left - // in order to have the log centred. However, the spacing is fudged here to account - // for the fact that our sliders don't take up all of the horizontal space given - // to them. - const auto horizontalKludgeQuotient = .8f; - topRowComponents.removeFromLeft ( - juce::roundToInt (logoHorizontalSpacer * horizontalKludgeQuotient)); - - const auto valentineLogoBounds = - topRowComponents.removeFromLeft (juce::roundToInt (logoWidth)) - .removeFromTop (juce::roundToInt (logoHeight)); - - valentineTblLogo->setTransformToFit ( - valentineLogoBounds.toFloat(), - juce::RectanglePlacement (juce::RectanglePlacement::centred - | juce::RectanglePlacement::fillDestination)); + topRow.setBounds (topRowComponents); localBounds.removeFromTop (juce::roundToInt (margin * 2)); bottomRowBorder = localBounds; diff --git a/src/gui/panels/ValentineCenterPanel.h b/src/gui/panels/ValentineCenterPanel.h index d0502836..a0e31b77 100644 --- a/src/gui/panels/ValentineCenterPanel.h +++ b/src/gui/panels/ValentineCenterPanel.h @@ -2,6 +2,7 @@ #pragma once +#include "ValentineTopRowPanel.h" #include "tote_bag/juce_gui/components/widgets/LabelSlider.h" #include "tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h" @@ -29,13 +30,7 @@ class CenterPanel : public juce::Component float borderLineThickness; float borderCornerSize; - ToggleButton crushEnableButton; - LabelSlider crushSlider; - LabelSlider compressSlider; - ToggleButton saturateEnableButton; - LabelSlider saturateSlider; - - std::unique_ptr valentineTblLogo; + TopRowPanel topRow; LabelSlider ratioSlider; LabelSlider attackSlider; diff --git a/src/gui/panels/ValentineTopRowPanel.cpp b/src/gui/panels/ValentineTopRowPanel.cpp new file mode 100644 index 00000000..c4b495ed --- /dev/null +++ b/src/gui/panels/ValentineTopRowPanel.cpp @@ -0,0 +1,115 @@ +// 2023 Tote Bag Labs + +#include "ValentineTopRowPanel.h" +#include "BinaryData.h" +#include "PluginProcessor.h" + +#include "ValentineParameters.h" +#include "tote_bag/juce_gui/lookandfeel/LookAndFeelConstants.h" +#include "tote_bag/juce_gui/utilities/GraphicsUtilities.h" + +namespace tote_bag +{ +namespace valentine +{ +namespace detail +{ +inline const juce::String kCrushSliderText = "CRUSH"; +inline const juce::String kCompressSliderText = "COMPRESS"; +inline const juce::String kSaturateSliderText = "SATURATE"; +} // namespace detail + +TopRowPanel::TopRowPanel (ValentineAudioProcessor& processor) + : crushEnableButton (parameterID (VParameter::crushEnable), processor.treeState) + , crushSlider (detail::kCrushSliderText, + parameterID (VParameter::bitCrush), + processor.treeState) + , compressSlider (detail::kCompressSliderText, + parameterID (VParameter::inputGain), + processor.treeState) + , saturateEnableButton (parameterID (VParameter::saturateEnable), processor.treeState) + , saturateSlider (detail::kSaturateSliderText, + parameterID (VParameter::saturation), + processor.treeState) + , valentineTblLogo ( + juce::Drawable::createFromImageData (BinaryData::val_totebag_logo_svg, + BinaryData::val_totebag_logo_svgSize)) +{ + addAndMakeVisible (crushEnableButton); + addAndMakeVisible (crushSlider); + addAndMakeVisible (compressSlider); + addAndMakeVisible (saturateEnableButton); + addAndMakeVisible (saturateSlider); + addAndMakeVisible (valentineTblLogo.get()); +} + +TopRowPanel::~TopRowPanel() +{ +} + +void TopRowPanel::resized() +{ + auto bounds = getLocalBounds(); + + auto topRowSliders = + bounds.removeFromLeft (juce::roundToInt (bounds.getWidth() * .65f)); + const auto topRowButtonWidth = juce::roundToInt (topRowSliders.getWidth() * .033f); + const auto adjustedTopRowComponentsWidth = + topRowSliders.getWidth() - (topRowButtonWidth * 2.0f); + const auto topRowSliderWidth = + juce::roundToInt (adjustedTopRowComponentsWidth / 3.0f); + + const auto topRowButtonSpacer = + juce::roundToInt ((topRowSliders.getHeight() - topRowButtonWidth) * .5f); + + // See below note about horizontal LabelSlider dimensions and button placement. + const auto topRowButtonNudge = juce::roundToInt (topRowButtonWidth / 1.5f); + + const auto initialCrushButtonX = topRowSliders.getX(); + const auto crushEnableButtonBounds = + topRowSliders.removeFromLeft (topRowButtonWidth) + .reduced (0, topRowButtonSpacer) + .withX (initialCrushButtonX + topRowButtonNudge); + + crushEnableButton.setBounds (crushEnableButtonBounds); + crushSlider.setBounds ( + topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); + compressSlider.setBounds (topRowSliders.removeFromLeft (topRowSliderWidth)); + + const auto initialSaturateButtonX = topRowSliders.getX(); + const auto saturateEnableButtonBounds = + topRowSliders.removeFromLeft (topRowButtonWidth) + .reduced (0, topRowButtonSpacer) + .withX (initialSaturateButtonX + topRowButtonNudge); + + saturateEnableButton.setBounds (saturateEnableButtonBounds); + saturateSlider.setBounds ( + topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); + + const auto logoHeight = bounds.getHeight() * .25f; + const auto logoWidth = bounds.getWidth() * .75f; + + const auto logoVerticalSpacer = (bounds.getHeight() - logoHeight) / 2.0f; + bounds.removeFromTop (juce::roundToInt (logoVerticalSpacer)); + + const auto logoHorizontalSpacer = (bounds.getWidth() - logoWidth) / 2.0f; + + // logoHorizontalSpacer is the amount we hypothetically should remove from left + // in order to have the log centred. However, the spacing is fudged here to account + // for the fact that our sliders don't take up all of the horizontal space given + // to them. + const auto horizontalKludgeQuotient = .8f; + bounds.removeFromLeft ( + juce::roundToInt (logoHorizontalSpacer * horizontalKludgeQuotient)); + + const auto valentineLogoBounds = bounds.removeFromLeft (juce::roundToInt (logoWidth)) + .removeFromTop (juce::roundToInt (logoHeight)); + + valentineTblLogo->setTransformToFit ( + valentineLogoBounds.toFloat(), + juce::RectanglePlacement (juce::RectanglePlacement::centred + | juce::RectanglePlacement::fillDestination)); +} + +} // namespace valentine +} // namespace tote_bag \ No newline at end of file diff --git a/src/gui/panels/ValentineTopRowPanel.h b/src/gui/panels/ValentineTopRowPanel.h new file mode 100644 index 00000000..47d252d4 --- /dev/null +++ b/src/gui/panels/ValentineTopRowPanel.h @@ -0,0 +1,32 @@ +#pragma once + +#include "tote_bag/juce_gui/components/widgets/LabelSlider.h" +#include "tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h" + +#include + +class ValentineAudioProcessor; + +namespace tote_bag +{ +namespace valentine +{ +class TopRowPanel : public juce::Component +{ +public: + TopRowPanel (ValentineAudioProcessor& processor); + ~TopRowPanel() override; + + void resized() override; + +private: + ToggleButton crushEnableButton; + LabelSlider crushSlider; + LabelSlider compressSlider; + ToggleButton saturateEnableButton; + LabelSlider saturateSlider; + + std::unique_ptr valentineTblLogo; +}; +} // namespace valentine +} // namespace tote_bag \ No newline at end of file