Oscilloscope 0.5.0
A simple oscilloscope VST
Loading...
Searching...
No Matches
PluginEditor.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file contains the basic framework code for a JUCE plugin editor.
5
6 ==============================================================================
7*/
8
9#include "PluginProcessor.h"
10#include "PluginEditor.h"
11
12//==============================================================================
14 : AudioProcessorEditor(&p), audioProcessor(p)
15{
16
17 // set correct oscilloscopeComponent height
18 if (audioProcessor.getTreeState()->getParameterAsValue("isProfessional").getValue())
19 {
20 margin_multiplier = GUI_EXPANDED_MARGIN_MULTIPLIER();
21 }
22 else
23 {
24 margin_multiplier = GUI_CONTRACTED_MARGIN_MULTIPLIER();
25 }
26
27 // reset oscilloscopeComponent and guiTransformer pointers
28 if (audioProcessor.getTreeState()->getParameterAsValue("isProfessional").getValue())
29 {
30 oscilloscopeComponent.reset(new TriggeredOscilloscope(audioProcessor, audioProcessor.getSampleRate()));
31 }
32 else
33 {
34 oscilloscopeComponent.reset(new UntriggeredOscilloscope(audioProcessor, audioProcessor.getSampleRate()));
35 }
36
37 guiTransformer.reset(new GuiTransformer(
38 audioProcessor,
39 GUI_EXPAND_ANIMATION_DURATION(),
40 [this]()
41 { this->expandCallback(); },
42 [this]()
43 { this->contractCallback(); },
44 [this]()
45 { this->expansionStartedCallback(); },
46 [this]()
47 { this->contractionStartedCallback(); },
48 [this]()
49 { this->expansionEndedCallback(); },
50 [this]()
51 { this->contractionEndedCallback(); }));
52
53 // reset triggerListener
54 triggerListener.reset(
56 // callback to reset to triggered state
57 [this]()
58 {
59 removeChildComponent(oscilloscopeComponent.get());
60 oscilloscopeComponent.reset(
61 new TriggeredOscilloscope(audioProcessor, audioProcessor.getSampleRate()));
62 addAndMakeVisible(oscilloscopeComponent.get());
63 resized();
64 },
65 // callback to reset to untriggered state
66 [this]()
67 {
68 removeChildComponent(oscilloscopeComponent.get());
69 oscilloscopeComponent.reset(
70 new UntriggeredOscilloscope(audioProcessor, audioProcessor.getSampleRate()));
71 addAndMakeVisible(oscilloscopeComponent.get());
72 resized();
73 }));
74 audioProcessor.getTreeState()->addParameterListener("isTriggered", triggerListener.get());
75
76 // add and make visible components
77 addAndMakeVisible(oscilloscopeComponent.get());
78 addAndMakeVisible(controlSection);
79
80 // set editor size
81 setSize(audioProcessor.getEditorWidth(), audioProcessor.getEditorHeight());
82
83 // set control section attachments
84 std::vector<juce::String> attachmentNames;
85 attachmentNames.push_back("drawGrid");
86 attachmentNames.push_back("bufferLength");
87 attachmentNames.push_back("isProfessional");
88 attachmentNames.push_back("isTriggered");
89 attachmentNames.push_back("slopeButtonTriggered");
90 attachmentNames.push_back("triggerLevel");
91 attachmentNames.push_back("autoTriggered");
92 attachmentNames.push_back("refreshTime");
93 attachmentNames.push_back("muteOutput");
94 attachmentNames.push_back("decayTime");
95 controlSection.setMultipleAttachments(attachmentNames, *audioProcessor.getTreeState());
96
97 // set resize options
98 setResizable(true, true);
99 setResizeLimits(256, 256, 1920, 1080);
100}
101
103{
104}
105
106//==============================================================================
108{
109}
110
112{
113
114 // get bounds
115 auto area = getLocalBounds();
116 int height = area.getHeight();
117 int width = area.getWidth();
118 int margin = int(float(area.getHeight()) * margin_multiplier);
119
120 // resize components
121 oscilloscopeComponent->setTopLeftPosition(0, 0);
122 oscilloscopeComponent->setSize(area.getWidth(), margin);
123 controlSection.setTopLeftPosition(0, margin);
124 controlSection.setSize(width, height - margin);
125
126 // store new size
127 audioProcessor.storeEditorSize(getWidth(), getHeight());
128}
129
130void OscilloscopeAudioProcessorEditor::expandCallback()
131{
132
133 if (this->margin_multiplier > GUI_EXPANDED_MARGIN_MULTIPLIER())
134 {
135 // increase by a fraction of the difference in pixels such that it takes the correct amount of frames
136 float difference = GUI_CONTRACTED_MARGIN_MULTIPLIER() - GUI_EXPANDED_MARGIN_MULTIPLIER();
137 float totalFrames = float(EDITOR_INITIAL_RATE()) * GUI_EXPAND_ANIMATION_DURATION();
138 float increment = difference / totalFrames;
139 this->margin_multiplier = this->margin_multiplier - increment;
140 }
141 else
142 {
143 // set it to correct value
144 this->margin_multiplier = GUI_EXPANDED_MARGIN_MULTIPLIER();
145 }
146
147 // reset component bounds
148 this->resized();
149}
150
151void OscilloscopeAudioProcessorEditor::expansionEndedCallback()
152{
153 // reset component bounds
154 this->resized();
155}
156
157void OscilloscopeAudioProcessorEditor::contractCallback()
158{
159
160 if (this->margin_multiplier < GUI_CONTRACTED_MARGIN_MULTIPLIER())
161 {
162 // increase by a fraction of the difference in pixels such that it takes the correct amount of frames
163 float difference = GUI_CONTRACTED_MARGIN_MULTIPLIER() - GUI_EXPANDED_MARGIN_MULTIPLIER();
164 ;
165 float totalFrames = float(EDITOR_INITIAL_RATE()) * GUI_EXPAND_ANIMATION_DURATION();
166 float increment = difference / totalFrames;
167 this->margin_multiplier = this->margin_multiplier + increment;
168 }
169 else
170 {
171 // set it to correct value
172 this->margin_multiplier = GUI_CONTRACTED_MARGIN_MULTIPLIER();
173 }
174
175 // reset component bounds
176 this->resized();
177}
178
179void OscilloscopeAudioProcessorEditor::contractionEndedCallback()
180{
181
182 // reset horizontal control sections counter and text
183 controlSection.resetNumHorizontalSections();
184
185 // reset component bounds
186 this->resized();
187 controlSection.resized();
188}
189
190void OscilloscopeAudioProcessorEditor::expansionStartedCallback()
191{
192
193 // reset horizontal control sections counter and text
194 controlSection.resetNumHorizontalSections();
195 controlSection.resetButtonText();
196}
197
198void OscilloscopeAudioProcessorEditor::contractionStartedCallback()
199{
200 controlSection.resetButtonText();
201}
void resized() override
void resetNumHorizontalSections()
void setMultipleAttachments(std::vector< juce::String > attachmentNames, juce::AudioProcessorValueTreeState &processorTreeState)
void paint(juce::Graphics &) override
OscilloscopeAudioProcessorEditor(OscilloscopeAudioProcessor &)
Oscilloscope audio processor.
void storeEditorSize(int width, int height)
juce::AudioProcessorValueTreeState * getTreeState()