Skip to content

Commit

Permalink
Cleaned up and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LPF9000 committed Jul 8, 2021
1 parent a886c71 commit fdf793d
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 94 deletions.
206 changes: 118 additions & 88 deletions Distortion_Project/Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/

Expand All @@ -13,191 +14,220 @@
Distortion_ProjectAudioProcessorEditor::Distortion_ProjectAudioProcessorEditor (Distortion_ProjectAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
getLookAndFeel().setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);
getLookAndFeel().setColour(juce::Slider::thumbColourId, juce::Colours::transparentWhite);
driveSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colours::aqua);
driveSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colours::aqua);
driveSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour::Colour(0.5f, 0.4f, 0.3f, 1.0f));
driveSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.5f, 0.4f,0.7f,1.0f));

getLookAndFeel().setColour(juce::Slider::textBoxTextColourId, juce::Colours::antiquewhite);


// General Font and Colour Settings
getLookAndFeel().setDefaultSansSerifTypefaceName("Roboto");
getLookAndFeel().setColour(juce::Slider::textBoxTextColourId, juce::Colours::antiquewhite);
getLookAndFeel().setColour(juce::Slider::thumbColourId, juce::Colours::transparentWhite);

// driveSlider Colours
driveSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour::Colour(0.52f, 0.4f, 0.3f, 1.0f));
driveSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f,0.7f,1.0f));
driveSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);

// driveSlider Style and position
driveSlider.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
driveSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition((((getWidth() / 5) * 1 - 25), (getHeight() / 2) + 5 - (25 / 2))), true, 50, 25);
//Set GUI element parameters
driveSlider.setTextBoxStyle(juce::Slider::TextEntryBoxPosition((((getWidth() / 5) * 1 - 25), (getHeight() / 2) + 5 - (25 / 2))), true, 50, 25);

clipSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colours::aqua);
clipSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.5f, 0.2f, 0.7f, 1.0f));
// clipSlider Colours
clipSlider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour::Colour(0.52f, 0.4f, 0.3f, 1.0f));
clipSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f, 0.7f, 1.0f));
clipSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);

// clipSlider Style and position
clipSlider.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
clipSlider.setTextBoxStyle(juce::Slider::NoTextBox, false, 50, 25);




// Add items to ComboBox
typeBox.addItem("Soft", 1);
typeBox.addItem("Hard", 2);

typeBox.setJustificationType(juce::Justification::centred);
//Add parts to GUI

// Add components to GUI
addAndMakeVisible(driveSlider);
addAndMakeVisible(clipSlider);
addAndMakeVisible(&typeBox);
addAndMakeVisible(titleLabel);
addAndMakeVisible(NameLabel);

// Add Listeners
driveSlider.addListener(this);
clipSlider.addListener(this);
typeBox.addListener(this); //typeBox uses listener
clipSlider.addListener(this);
typeBox.addListener(this); //typeBox requires listener

// Use custom lookandfeel
driveSlider.setLookAndFeel(&otherLookAndFeel);
clipSlider.setLookAndFeel(&otherLookAndFeel);

driveSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);
clipSlider.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::transparentWhite);


//Conect GUI object attachments to plugin processor
driveSliderAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"DRIVE", driveSlider);
typeBoxAttachment = std::make_unique<BoxAttachments>(audioProcessor.apvts,
"TYPE", typeBox);
clipSliderAttachment = std::make_unique<SliderAttachments>(audioProcessor.apvts,
"CLIP", clipSlider);

// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize(600, 400);
}

// Editor Destructor
Distortion_ProjectAudioProcessorEditor::~Distortion_ProjectAudioProcessorEditor()
{
driveSlider.setLookAndFeel(nullptr);
clipSlider.setLookAndFeel(nullptr);
}

//==============================================================================
void Distortion_ProjectAudioProcessorEditor::paint(juce::Graphics& g)
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
juce::Colour c1 = juce::Colour(0.52f, 0.4f, 0.2f, 0.8f);
juce::Colour c2 = juce::Colours::black;
juce::ColourGradient g1 = juce::ColourGradient(c1, 0.0f, 0.0f, c2.brighter(0.2f), static_cast<int>(getRight()), static_cast<int>(getBottom()), true);
// Color Gradient for Background
juce::Colour colorAqua = juce::Colour(0.52f, 0.4f, 0.2f, 0.8f);
juce::Colour colorBlack = juce::Colours::black;
juce::ColourGradient g1 = juce::ColourGradient(colorAqua, 0.0f, 0.0f, colorBlack.brighter(0.2f), static_cast<int>(getRight()), static_cast<int>(getBottom()), true);
g.setGradientFill(g1);
g.fillAll();

// Set font colour and size
g.setColour(juce::Colours::whitesmoke);
g.setFont(20.0f);

//g.setFont(juce::Font(40.0f).withHorizontalScale(0.5f));
// Text for Sliders (Should change these to labels!!)
g.drawText("DRIVE", ((getWidth() / 5) * 1) - driveSlider.getWidth()/2, (getHeight() / 2) + driveSlider.getHeight()/20, 100, 100, juce::Justification::centred, false);
g.drawText("CLIP", ((getWidth() / 5) * 3) - (100 / 2), (getHeight() / 2) + 5, 100, 100, juce::Justification::centred, false);
//g.drawText("U F A E S", 500, 0, 100, 100, juce::Justification::centred, false);
//g.drawEllipse(getWidth() / 5 - (25), getHeight() / 2 - 25, driveSlider.getWidth()/2, driveSlider.getHeight()/2, 0.5f);

// Label for Name of our Organization
titleLabel.setText("U F A E S", juce::dontSendNotification);
titleLabel.setJustificationType(juce::Justification::right);

// Label for Name of Plugin
NameLabel.setFont(juce::Font(25.0f, juce::Font::bold));
NameLabel.setText("T A K E 1", juce::dontSendNotification);
NameLabel.setJustificationType(juce::Justification::left);

}


// Layout of subcomponents in editor
void Distortion_ProjectAudioProcessorEditor::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
driveSlider.setBounds(((getWidth() / 5) * 1) - (100 / 2), (getHeight() / 2) - (100 / 2), 100, 100);
clipSlider.setBounds(((getWidth() / 5) * 3) - (100 / 2), (getHeight() / 2) - (100 / 2), 100, 100);
{
// Slider Bounds
driveSlider.setBounds(((getWidth() / 5) * 1) - (100 / 2),
(getHeight() / 2) - (100 / 2), 100, 100);
clipSlider.setBounds(((getWidth() / 5) * 3) - (100 / 2),
(getHeight() / 2) - (100 / 2), 100, 100);

// ComboBox Bounds
juce::Rectangle<int> area = getLocalBounds().reduced(60);
typeBox.setBounds(area.removeFromTop(20));

// Label Bounds
titleLabel.setBounds(10, 10, getWidth() - 20, 30);
NameLabel.setBounds(10, 10, getWidth() - 20, 30);

}

// Listener Function for ComboBox (Code is purposefully empty...)
void Distortion_ProjectAudioProcessorEditor::comboBoxChanged(juce::ComboBox* box)
{
}

// Listener function for Slider
void Distortion_ProjectAudioProcessorEditor::sliderValueChanged(juce::Slider* slide)
{
// Get Values of sliders
float driveValue = driveSlider.getValue()/10.0;
float clipValue = clipSlider.getValue();

// Limit Brightness between specific range
float driveBrightness = juce::jlimit(0.5f, 0.7f, driveValue);
float clipBrightness = juce::jlimit(0.5f, 0.7f, clipValue);
driveSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f, driveBrightness, 1.0f));
clipSlider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour::Colour(0.52f, 0.4f,clipBrightness, 1.0f));


// Set Brightness Parameter of the Colour
// Colour(float Hue, float Saturation, float Brightness, float Alpha)
driveSlider.setColour(juce::Slider::rotarySliderFillColourId,
juce::Colour::Colour(0.52f, 0.4f, driveBrightness, 1.0f));
clipSlider.setColour(juce::Slider::rotarySliderFillColourId,
juce::Colour::Colour(0.52f, 0.4f,clipBrightness, 1.0f));

}


// Default Constructor
OtherLookAndFeel::OtherLookAndFeel()
{
}

// Destructor
OtherLookAndFeel::~OtherLookAndFeel()
{
}

// DrawRotarySlider function from the OtherLookAndFeel class
void OtherLookAndFeel::drawRotarySlider(juce::Graphics& g, int x, int y, int width, int height, float sliderPos,
const float rotaryStartAngle, const float rotaryEndAngle, juce::Slider& slider)
{

//namespace juce
//{
void OtherLookAndFeel::drawRotarySlider(juce::Graphics& g, int x, int y, int width, int height, float sliderPos,
const float rotaryStartAngle, const float rotaryEndAngle, juce::Slider& slider)
{
auto outline = slider.findColour(juce::Slider::rotarySliderOutlineColourId);
auto fill = slider.findColour(juce::Slider::rotarySliderFillColourId);
// When copying code from pre-made juce functions, you need to add
// the juce namespace to the front of the objects!!
auto outline = slider.findColour(juce::Slider::rotarySliderOutlineColourId);
auto fill = slider.findColour(juce::Slider::rotarySliderFillColourId);

auto bounds = juce::Rectangle<int>(x, y, width, height).toFloat().reduced(10);
// This is the bounds of the slider - very useful!!
auto bounds = juce::Rectangle<int>(x, y, width, height).toFloat().reduced(10);

auto radius = juce::jmin(bounds.getWidth(), bounds.getHeight()) / 2.0f;
auto toAngle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
auto lineW = juce::jmin(4.0f, radius * 0.2f);
auto arcRadius = radius - lineW * 0.5f;
auto radius = juce::jmin(bounds.getWidth(), bounds.getHeight()) / 2.0f;
auto toAngle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);

juce::Path backgroundArc;
backgroundArc.addCentredArc(bounds.getCentreX(),
// This is the line width of the slider - very useful!!!
auto lineW = juce::jmin(4.0f, radius * 0.2f);
auto arcRadius = radius - lineW * 0.5f;

juce::Path backgroundArc;
backgroundArc.addCentredArc(bounds.getCentreX(),
bounds.getCentreY(),
arcRadius,
arcRadius,
0.0f,
rotaryStartAngle,
rotaryEndAngle,
true);

g.setColour(outline);
g.strokePath(backgroundArc, juce::PathStrokeType(lineW, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));

if (slider.isEnabled())
{
juce::Path valueArc;
valueArc.addCentredArc(bounds.getCentreX(),
bounds.getCentreY(),
arcRadius,
arcRadius,
0.0f,
rotaryStartAngle,
rotaryEndAngle,
toAngle,
true);

g.setColour(outline);
g.strokePath(backgroundArc, juce::PathStrokeType(lineW, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));

if (slider.isEnabled())
{
juce::Path valueArc;
valueArc.addCentredArc(bounds.getCentreX(),
bounds.getCentreY(),
arcRadius,
arcRadius,
0.0f,
rotaryStartAngle,
toAngle,
true);

g.setColour(fill);
g.strokePath(valueArc, juce::PathStrokeType(lineW, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));

g.setColour(juce::Colour::Colour(0.52f, 0.4f, 0.5f, 0.2f));
auto bounds1 = juce::Rectangle<int>(x, y, width, height).toFloat().reduced(10+lineW);
g.fillEllipse(bounds1.getX(), bounds1.getY(), bounds1.getWidth(), bounds1.getHeight());
}

auto thumbWidth = lineW * 0.5f;
juce::Point<float> thumbPoint(bounds.getCentreX() + arcRadius * std::cos(toAngle - juce::MathConstants<float>::halfPi),
bounds.getCentreY() + arcRadius * std::sin(toAngle - juce::MathConstants<float>::halfPi));

g.setColour(slider.findColour(juce::Slider::thumbColourId));
g.fillEllipse(juce::Rectangle<float>(thumbWidth, thumbWidth).withCentre(thumbPoint));
g.setColour(fill);
g.strokePath(valueArc, juce::PathStrokeType(lineW, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));

// Set the colour of the Ellipse to be drawn
// Colour(float Hue, float Saturation, float Brightness, float Alpha)
g.setColour(juce::Colour::Colour(0.52f, 0.4f, 0.2f, 0.4f));

// Set the bounds of the ellipse to be just inside the arc line of the slider
// This is the bounds of the slider reduced by the linewidth (see the beginning of this function)
auto ellipseBounds = juce::Rectangle<int>(x, y, width, height).toFloat().reduced(10+lineW);

// Create a filled ellipse with the new bounds
// fillEllipse(float x, float y, float width, float height)
g.fillEllipse(ellipseBounds.getX(), ellipseBounds.getY(), ellipseBounds.getWidth(), ellipseBounds.getHeight());
}
//}

// This is the thumb of the slider, the circle at the end, or indicator point
auto thumbWidth = lineW * 0.5f;
juce::Point<float> thumbPoint(bounds.getCentreX() + arcRadius * std::cos(toAngle - juce::MathConstants<float>::halfPi),
bounds.getCentreY() + arcRadius * std::sin(toAngle - juce::MathConstants<float>::halfPi));

// Sets the color of the slider thumb
g.setColour(slider.findColour(juce::Slider::thumbColourId));
g.fillEllipse(juce::Rectangle<float>(thumbWidth, thumbWidth).withCentre(thumbPoint));
}

14 changes: 8 additions & 6 deletions Distortion_Project/Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
//==============================================================================
/**
*/

// Derived class from LookAndFeel_V4
class OtherLookAndFeel : public juce::LookAndFeel_V4
{
public:

/** Creates a LookAndFeel_V4 object with a default colour scheme. */
// Default Constructor
OtherLookAndFeel();

/** Creates a LookAndFeel_V4 object with a given colour scheme. */
// Custom Constructor
OtherLookAndFeel(ColourScheme);

/** Destructor. */
Expand All @@ -47,26 +51,24 @@ class Distortion_ProjectAudioProcessorEditor : public juce::AudioProcessorEdito
void paint (juce::Graphics&) override;
void resized() override;



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

// LookandFeel classes need to be implemented before the component
OtherLookAndFeel otherLookAndFeel;

//Create GUI objects
juce::Slider driveSlider;
juce::ComboBox typeBox;
juce::Slider clipSlider;

// Create Label Objects
juce::Label titleLabel;
juce::Label NameLabel;


juce::Label NameLabel;

// Use namespaces to cleanup code
// Use namespaces to cleanup code for TreeState Attachments
using SliderAttachments = juce::AudioProcessorValueTreeState::SliderAttachment;
using BoxAttachments = juce::AudioProcessorValueTreeState::ComboBoxAttachment;

Expand Down

0 comments on commit fdf793d

Please sign in to comment.