-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
91 lines (73 loc) · 3.71 KB
/
PluginEditor.cpp
File metadata and controls
91 lines (73 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <juce_gui_basics/juce_gui_basics.h>
//==============================================================================
class CustomLookAndFeel : public juce::LookAndFeel_V4
{
public:
CustomLookAndFeel(juce::Drawable* knobDrawable) : knobDrawable(knobDrawable) {}
void drawRotarySlider(juce::Graphics& g, int x, int y, int width, int height, float sliderPos,
const float rotaryStartAngle, const float rotaryEndAngle, juce::Slider& slider) override
{
auto bounds = juce::Rectangle<int>(x, y, width, height).toFloat().reduced(10);
knobDrawable->drawWithin(g, bounds, juce::RectanglePlacement::centred, 1.0f);
}
private:
juce::Drawable* knobDrawable;
};
BaxterAudioProcessorEditor::BaxterAudioProcessorEditor (BaxterAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
setSize (400, 300);
// Load the images
auto dogImageData = BinaryData::BaxFace_png;
auto dogImageSize = BinaryData::BaxFace_pngSize;
auto dogImage = juce::ImageCache::getFromMemory(dogImageData, dogImageSize);
dogDrawable = std::unique_ptr<juce::Drawable>(new juce::DrawableImage());
reinterpret_cast<juce::DrawableImage*>(dogDrawable.get())->setImage(dogImage);
auto knobImageData = BinaryData::BaxKnob_png;
auto knobImageSize = BinaryData::BaxKnob_pngSize;
auto knobImage = juce::ImageCache::getFromMemory(knobImageData, knobImageSize);
knobDrawable = std::unique_ptr<juce::Drawable>(new juce::DrawableImage());
reinterpret_cast<juce::DrawableImage*>(knobDrawable.get())->setImage(knobImage);
// Configure the fuzz amount slider (knob)
fuzzAmountSlider.setSliderStyle(juce::Slider::Rotary);
fuzzAmountSlider.setTextBoxStyle(juce::Slider::NoTextBox, false, 90, 0);
fuzzAmountSlider.setRange(0.0, 1.0, 0.01);
fuzzAmountSlider.setValue(audioProcessor.parameters.getRawParameterValue("fuzzAmount")->load());
// Set the look and feel
customLookAndFeel = std::make_unique<CustomLookAndFeel>(knobDrawable.get());
fuzzAmountSlider.setLookAndFeel(customLookAndFeel.get());
addAndMakeVisible(fuzzAmountSlider);
// Configure the fuzz amount label
fuzzAmountLabel.setText("Fuzz", juce::dontSendNotification);
fuzzAmountLabel.attachToComponent(&fuzzAmountSlider, false);
addAndMakeVisible(fuzzAmountLabel);
// Attach the slider to the corresponding parameter in the processor
auto& params = audioProcessor.getParameters();
fuzzAmountAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment> (params, "fuzz", fuzzAmountSlider);
}
BaxterAudioProcessorEditor::~BaxterAudioProcessorEditor()
{
fuzzAmountAttachment = nullptr;
fuzzAmountSlider.setLookAndFeel(nullptr);
customLookAndFeel = nullptr;
}
//==============================================================================
void BaxterAudioProcessorEditor::paint (juce::Graphics& g)
{
// Draw the dog image
dogDrawable->drawWithin(g, juce::Rectangle<float>(0, 0, getWidth(), getHeight()),
juce::RectanglePlacement::centred, 1.0f);
}
void BaxterAudioProcessorEditor::resized()
{
// Set the bounds of the fuzzAmountSlider and fuzzAmountLabel
fuzzAmountSlider.setBounds (getWidth() / 2 - 50, getHeight() / 2 - 50, 100, 100);
fuzzAmountLabel.setBounds (0, fuzzAmountSlider.getY() - 20, getWidth(), 20);
}