Skip to content

Commit

Permalink
cleaner GUI look and code
Browse files Browse the repository at this point in the history
addes comments and methods to clean up the code
  • Loading branch information
sadmemelord committed Feb 8, 2023
1 parent 7f4444d commit 57e38ca
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 116 deletions.
2 changes: 2 additions & 0 deletions Source/DSP/CustomCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ void CustomCompressor::setRatio(float newRatio)

void CustomCompressor::setAttack(float newAttack)
{
//attack is in expressed in milliseconds
_attack = newAttack / 1000.0f;
}

void CustomCompressor::setRelease(float newRelease)
{
//release is in expressed in milliseconds
_release = newRelease / 1000.0f;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/DSP/CustomCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class CustomCompressor
//the process method is defined in the header file
//because it is passed through the translation unit
//and has a better chance of being optimized

//bypassing the dsp

if (_isBypassed == true)
return;

Expand Down
2 changes: 2 additions & 0 deletions Source/GUI/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

void QuasoCompressorAudioProcessorEditor::setButtonProps(juce::ToggleButton& button)
{
//setting up group properties
addAndMakeVisible(button);
button.setLookAndFeel(&buttonLAF);
}


void QuasoCompressorAudioProcessorEditor::attachButtons()
{
//attaching the buttons to the related apvts parameters
using ButtonAttachment = juce::AudioProcessorValueTreeState::ButtonAttachment;
compBypassAttach = std::make_unique<ButtonAttachment>(audioProcessor.apvts, compBypassID, compBypassButton);
}
1 change: 1 addition & 0 deletions Source/GUI/Groups/Groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

void QuasoCompressorAudioProcessorEditor::setGroupProps(juce::GroupComponent& group)
{
//setting group properties
addAndMakeVisible(group);
group.setColour(group.outlineColourId, juce::Colours::darkgrey);
ioGroup.setText("I/O");
Expand Down
13 changes: 13 additions & 0 deletions Source/GUI/Labels/Labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ void QuasoCompressorAudioProcessorEditor::setCommonLabelProps(juce::Label& label
label.setFont(juce::Font("Helvetica", 16.0f, juce::Font::FontStyleFlags::bold));
label.setJustificationType(juce::Justification::centred);
}

void QuasoCompressorAudioProcessorEditor::setLabelText()
{
//setting the text for each label
inputDialLabel.setText("Input", juce::dontSendNotification);
threshDialLabel.setText("Threshold", juce::dontSendNotification);
ratioDialLabel.setText("Ratio", juce::dontSendNotification);
attackDialLabel.setText("Attack", juce::dontSendNotification);
releaseDialLabel.setText("Release", juce::dontSendNotification);
limThreshDialLabel.setText("Threshold", juce::dontSendNotification);
limReleaseDialLabel.setText("Release", juce::dontSendNotification);
outputDialLabel.setText("Output", juce::dontSendNotification);
}
26 changes: 25 additions & 1 deletion Source/GUI/Sliders/SliderProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,39 @@ void QuasoCompressorAudioProcessorEditor::setCommonSliderProps(juce::Slider& sli

slider.setLookAndFeel(&customDialLAF);

}

void QuasoCompressorAudioProcessorEditor::setShadowProps(juce::Slider& slider)
{
//setting shadow properties based on the juce::shadowdrop
shadowProperties.radius = 25;
shadowProperties.offset = juce::Point<int>(0,0);
shadowProperties.offset = juce::Point<int>(0, 0);
shadowProperties.colour = juce::Colours::black.brighter(0.05);
dialShadow.setShadowProperties(shadowProperties);
slider.setComponentEffect(&dialShadow);

}


void QuasoCompressorAudioProcessorEditor::setUniqueSliderProps()
{
//some properties are different between dials like the textbox suffix
inputDial.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::indianred.darker(0.3));
inputDial.setTextValueSuffix(" dB");
threshDial.setTextValueSuffix(" dB");
attackDial.setTextValueSuffix(" ms");
releaseDial.setTextValueSuffix(" ms");
limThreshDial.setColour(juce::Slider::ColourIds::thumbColourId,
limThreshDial.findColour(juce::Slider::ColourIds::thumbColourId).withSaturation(0.85));
limThreshDial.setTextValueSuffix(" dB");
limReleaseDial.setColour(juce::Slider::ColourIds::thumbColourId,
limReleaseDial.findColour(juce::Slider::ColourIds::thumbColourId).withSaturation(0.85));
limReleaseDial.setTextValueSuffix(" ms");
outputDial.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::indianred.darker(0.3));
outputDial.setTextValueSuffix(" dB");

}

void QuasoCompressorAudioProcessorEditor::attachSliders()
{
//method to attach dials to apvts
Expand Down
114 changes: 38 additions & 76 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,33 @@
QuasoCompressorAudioProcessorEditor::QuasoCompressorAudioProcessorEditor (QuasoCompressorAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{

//setting the label text
inputDialLabel.setText("Input", juce::dontSendNotification);
threshDialLabel.setText("Threshold", juce::dontSendNotification);
ratioDialLabel.setText("Ratio", juce::dontSendNotification);
attackDialLabel.setText("Attack", juce::dontSendNotification);
releaseDialLabel.setText("Release", juce::dontSendNotification);
limThreshDialLabel.setText("Threshold", juce::dontSendNotification);
limReleaseDialLabel.setText("Release", juce::dontSendNotification);
outputDialLabel.setText("Output", juce::dontSendNotification);

//setting the slider properties is called for every slider in the vector
//setting up common slider and labels props
for (int i = 0; i < dials.size(); i++)
{
setCommonSliderProps(*dials[i]);
setCommonLabelProps(*dialLabels[i]);
dialLabels[i]->attachToComponent(dials[i], false);
}

for (int i = 0; i < groups.size(); i++)
//unique slider properties like suffixes and colors
setUniqueSliderProps();
//text for each label
setLabelText();
//toggle button properties
setButtonProps(compBypassButton);

//shadow properties are the same for each slider
for (int i = 0; i < dials.size(); i++)
{
setGroupProps(*groups[i]);
setShadowProps(*dials[i]);
}

for (int i = 0; i < buttons.size(); i++)
//group properties
for (int i = 0; i < groups.size(); i++)
{
setButtonProps(*buttons[i]);
setGroupProps(*groups[i]);
}

//some properties are different between dials like the textbox suffix
//inputDial.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::indianred.darker(0.3));
inputDial.setTextValueSuffix(" dB");
threshDial.setTextValueSuffix(" dB");
attackDial.setTextValueSuffix(" ms");
releaseDial.setTextValueSuffix(" ms");
//limThreshDial.setColour(juce::Slider::ColourIds::thumbColourId,
//limThreshDial.findColour(juce::Slider::ColourIds::thumbColourId).withSaturation(0.85));
limThreshDial.setTextValueSuffix(" dB");
//limReleaseDial.setColour(juce::Slider::ColourIds::thumbColourId,
//limReleaseDial.findColour(juce::Slider::ColourIds::thumbColourId).withSaturation(0.85));
limReleaseDial.setTextValueSuffix(" ms");
//outputDial.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::indianred.darker(0.3));
outputDial.setTextValueSuffix(" dB");


//methods to attach sliders and buttons the apvts parameters
attachSliders();
attachButtons();

Expand All @@ -75,6 +57,7 @@ QuasoCompressorAudioProcessorEditor::~QuasoCompressorAudioProcessorEditor()
{
dial->setLookAndFeel(nullptr);
}

//the vector is cleared and then shrinked to size zero inside the destructor
dials.clear();
dials.shrink_to_fit();
Expand All @@ -92,61 +75,40 @@ void QuasoCompressorAudioProcessorEditor::paint (juce::Graphics& g)

void QuasoCompressorAudioProcessorEditor::resized()
{
//useful variables for placing the components in the gui
auto dialSize = getWidth() * 0.18;
auto mainLeftMargin = getWidth() * 0.3;
auto leftMargin = getWidth() * 0.03;
auto mainLeftMargin = getWidth() * 0.32;
auto leftMargin = getWidth() * 0.05;
auto secondRowHeight = 1.3;
auto limiterMargin = 1.45;

////first row of GUI with input, thresh and ratio
//juce::FlexBox flexboxRowOne;
//flexboxRowOne.flexDirection = juce::FlexBox::Direction::row;
//flexboxRowOne.flexWrap = juce::FlexBox::Wrap::noWrap;
//flexboxRowOne.alignContent = juce::FlexBox::AlignContent::center;
//
//juce::Array<juce::FlexItem> itemArrayRowOne;
//itemArrayRowOne.add(juce::FlexItem(dialSize, dialSize, inputDial).withMargin(juce::FlexItem::Margin(0, 0, 0, leftMargin)));
//itemArrayRowOne.add(juce::FlexItem(dialSize, dialSize, threshDial).withMargin(juce::FlexItem::Margin(0, 0, 0, mainLeftMargin)));
//itemArrayRowOne.add(juce::FlexItem(dialSize, dialSize, ratioDial).withMargin(juce::FlexItem::Margin(0, 0, 0, leftMargin)));
//
//flexboxRowOne.items = itemArrayRowOne;
//flexboxRowOne.performLayout(getLocalBounds().withY(0).withHeight(getHeight() * 0.5));
//
////second row of GUI with output, attack and release
//juce::FlexBox flexboxRowTwo;
//flexboxRowTwo.flexDirection = juce::FlexBox::Direction::row;
//flexboxRowTwo.flexWrap = juce::FlexBox::Wrap::noWrap;
//flexboxRowTwo.alignContent = juce::FlexBox::AlignContent::center;
//
//juce::Array<juce::FlexItem> itemArrayRowTwo;
//itemArrayRowTwo.add(juce::FlexItem(dialSize, dialSize, outputDial).withMargin(juce::FlexItem::Margin(0, 0, 0, leftMargin)));
//itemArrayRowTwo.add(juce::FlexItem(dialSize, dialSize, attackDial).withMargin(juce::FlexItem::Margin(0, 0, 0, mainLeftMargin)));
//itemArrayRowTwo.add(juce::FlexItem(dialSize, dialSize, releaseDial).withMargin(juce::FlexItem::Margin(0, 0, 0, leftMargin)));
//
//flexboxRowTwo.items = itemArrayRowTwo;
//flexboxRowTwo.performLayout(getLocalBounds().withY(getHeight() * 0.5).withHeight(getHeight()*0.5));
auto limiterMargin = 1.5;
auto buttonSize = 50;

//I/O section GUI
inputDial.setBounds(leftMargin, 65, dialSize, dialSize);
threshDial.setBounds(mainLeftMargin, 65, dialSize, dialSize);
ratioDial.setBounds(threshDial.getX() + threshDial.getWidth(), 65, dialSize, dialSize);
outputDial.setBounds(leftMargin, inputDial.getY() + inputDial.getHeight() * secondRowHeight, dialSize, dialSize);

ioGroup.setBounds(inputDial.getX(), inputDial.getY() * 0.1, inputDial.getWidth(),
inputDial.getY() + inputDial.getHeight() * 2.4);
ioGroup.setBounds(inputDial.getX(), inputDial.getY() * 0.1, inputDial.getWidth(),
inputDial.getY() + inputDial.getHeight() * 2.35);

outputDial.setBounds(leftMargin, inputDial.getY() + inputDial.getHeight() *secondRowHeight, dialSize, dialSize);

//Compressor section GUI
threshDial.setBounds(mainLeftMargin, 65, dialSize, dialSize);
ratioDial.setBounds(threshDial.getX() + threshDial.getWidth(), 65, dialSize, dialSize);
attackDial.setBounds(threshDial.getX(), outputDial.getY(), dialSize, dialSize);
releaseDial.setBounds(ratioDial.getX(), outputDial.getY(), dialSize, dialSize);

compressorGroup.setBounds(threshDial.getX(), threshDial.getY() * 0.1, threshDial.getWidth() * 2.0,
threshDial.getY() + threshDial.getHeight() * 2.4);
compressorGroup.setBounds(threshDial.getX(), threshDial.getY() * 0.1, threshDial.getWidth() * 2.0,
threshDial.getY() + threshDial.getHeight() * 2.35);

compBypassButton.setBounds(releaseDial.getX() - 26, compressorGroup.getBottom() - 55, buttonSize, buttonSize);


//Limiter Section GUI
limThreshDial.setBounds(ratioDial.getX() + ratioDial.getWidth() * limiterMargin, inputDial.getY(), dialSize, dialSize);
limReleaseDial.setBounds(limThreshDial.getX(), inputDial.getY() +limThreshDial.getHeight()*secondRowHeight, dialSize, dialSize);

limiterGroup.setBounds(limThreshDial.getX(), limThreshDial.getY() * 0.1,
limThreshDial.getWidth(), limThreshDial.getY() + limThreshDial.getHeight() * 2.4);

compBypassButton.setBounds(compressorGroup.getRight() - 46, compressorGroup.getBottom() - 46, 50, 50);

limiterGroup.setBounds(limThreshDial.getX(), limThreshDial.getY() * 0.1,
limThreshDial.getWidth(), limThreshDial.getY() + limThreshDial.getHeight() * 2.35);


}
40 changes: 16 additions & 24 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
void resized() override;

private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
//This reference is provided as a quick way for your editor to
//access the processor object that created it.
QuasoCompressorAudioProcessor& audioProcessor;

//six dials attached to the six apvts parameters
//dials to attach to the apvts parameters
juce::Slider inputDial;
juce::Slider threshDial;
juce::Slider ratioDial;
Expand All @@ -41,11 +41,11 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
juce::Slider limReleaseDial;
juce::Slider outputDial;

//using custom look and feel
//using custom look and feel for dials and button from ViatorDSP style sheet
DialStyle customDialLAF;
PowerToggleLAF buttonLAF;

//shadows
//shadows properties
juce::DropShadow shadowProperties;
juce::DropShadowEffect dialShadow;

Expand All @@ -62,7 +62,7 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
&outputDial
};

//labels
//labels for each dial
juce::Label inputDialLabel;
juce::Label threshDialLabel;
juce::Label ratioDialLabel;
Expand All @@ -85,7 +85,8 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
&outputDialLabel
};

//groups
//three groups for a cleaner GUI look with
// I/O, Compressor and Limiter section
juce::GroupComponent ioGroup;
juce::GroupComponent compressorGroup;
juce::GroupComponent limiterGroup;
Expand All @@ -98,25 +99,21 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
&limiterGroup
};

//buttons
//toggle button to bypass the compressor
juce::ToggleButton compBypassButton;
juce::ToggleButton limBypassButton;

//buttons vector
std::vector<juce::ToggleButton*> buttons =
{
&compBypassButton,
&limBypassButton
};


//method to set some properties common to every silders, labels, groups and buttons
//method to set some properties common to every silders, labels, groups and button
void setCommonSliderProps(juce::Slider& slider);
void setCommonLabelProps(juce::Label& label);
void setShadowProps(juce::Slider& slider);
void setGroupProps(juce::GroupComponent& group);
void setButtonProps(juce::ToggleButton& button);

//method to set unique properties
void setUniqueSliderProps();
void setLabelText();

//setting up attachment
//setting up attachments
using ButtonAttachment = std::unique_ptr<juce::AudioProcessorValueTreeState::ButtonAttachment>;
ButtonAttachment compBypassAttach;

Expand All @@ -134,10 +131,5 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
void attachSliders();
void attachButtons();






JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (QuasoCompressorAudioProcessorEditor)
};
Loading

0 comments on commit 57e38ca

Please sign in to comment.