Skip to content

Commit

Permalink
Move top row components to a new class
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseDiazRohena committed Jan 3, 2024
1 parent 5963661 commit 7094bff
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 86 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 3 additions & 79 deletions src/gui/panels/ValentineCenterPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions src/gui/panels/ValentineCenterPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<juce::Drawable> valentineTblLogo;
TopRowPanel topRow;

LabelSlider ratioSlider;
LabelSlider attackSlider;
Expand Down
115 changes: 115 additions & 0 deletions src/gui/panels/ValentineTopRowPanel.cpp
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions src/gui/panels/ValentineTopRowPanel.h
Original file line number Diff line number Diff line change
@@ -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 <juce_gui_basics/juce_gui_basics.h>

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<juce::Drawable> valentineTblLogo;
};
} // namespace valentine
} // namespace tote_bag

0 comments on commit 7094bff

Please sign in to comment.