JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AudioProcessorEditor.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31 initialise();
32}
33
35{
36 // the filter must be valid..
37 jassert (p != nullptr);
38 initialise();
39}
40
42{
43 splashScreen.deleteAndZero();
44
45 // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
46 // filter for some reason..
48 removeComponentListener (resizeListener.get());
49}
50
53
56
57void AudioProcessorEditor::initialise()
58{
59 /*
60 ==========================================================================
61 In accordance with the terms of the JUCE 7 End-Use License Agreement, the
62 JUCE Code in SECTION A cannot be removed, changed or otherwise rendered
63 ineffective unless you have a JUCE Indie or Pro license, or are using
64 JUCE under the GPL v3 license.
65
66 End User License Agreement: www.juce.com/juce-7-licence
67 ==========================================================================
68 */
69
70 // BEGIN SECTION A
71
72 splashScreen = new JUCESplashScreen (*this);
73
74 // END SECTION A
75
76 attachConstrainer (&defaultConstrainer);
77 resizeListener.reset (new AudioProcessorEditorListener (*this));
78 addComponentListener (resizeListener.get());
79}
80
81//==============================================================================
82void AudioProcessorEditor::setResizable (bool allowHostToResize, bool useBottomRightCornerResizer)
83{
84 resizableByHost = allowHostToResize;
85
86 const auto hasResizableCorner = (resizableCorner.get() != nullptr);
87
88 if (useBottomRightCornerResizer != hasResizableCorner)
89 {
90 if (useBottomRightCornerResizer)
91 attachResizableCornerComponent();
92 else
93 resizableCorner = nullptr;
94 }
95}
96
100 int newMaximumHeight) noexcept
101{
102 if (constrainer != nullptr && constrainer != &defaultConstrainer)
103 {
104 // if you've set up a custom constrainer then these settings won't have any effect..
106 return;
107 }
108
110
111 defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
113
114 if (constrainer == nullptr)
115 setConstrainer (&defaultConstrainer);
116
117 if (resizableCorner != nullptr)
118 attachResizableCornerComponent();
119
120 setBoundsConstrained (getBounds());
121}
122
124{
125 if (constrainer != newConstrainer)
126 {
127 attachConstrainer (newConstrainer);
128
129 if (constrainer != nullptr)
130 resizableByHost = (newConstrainer->getMinimumWidth() != newConstrainer->getMaximumWidth()
131 || newConstrainer->getMinimumHeight() != newConstrainer->getMaximumHeight());
132
133 if (resizableCorner != nullptr)
134 attachResizableCornerComponent();
135 }
136}
137
138void AudioProcessorEditor::attachConstrainer (ComponentBoundsConstrainer* newConstrainer)
139{
140 if (constrainer != newConstrainer)
141 {
142 constrainer = newConstrainer;
143 updatePeer();
144 }
145}
146
147void AudioProcessorEditor::attachResizableCornerComponent()
148{
149 resizableCorner = std::make_unique<ResizableCornerComponent> (this, constrainer);
151 resizableCorner->setAlwaysOnTop (true);
152 editorResized (true);
153}
154
156{
157 if (constrainer == nullptr)
158 {
160 return;
161 }
162
163 auto currentBounds = getBounds();
164
165 constrainer->setBoundsForComponent (this,
166 newBounds,
167 newBounds.getY() != currentBounds.getY() && newBounds.getBottom() == currentBounds.getBottom(),
168 newBounds.getX() != currentBounds.getX() && newBounds.getRight() == currentBounds.getRight(),
169 newBounds.getY() == currentBounds.getY() && newBounds.getBottom() != currentBounds.getBottom(),
170 newBounds.getX() == currentBounds.getX() && newBounds.getRight() != currentBounds.getRight());
171}
172
173void AudioProcessorEditor::editorResized (bool wasResized)
174{
175 // The host needs to be able to rescale the plug-in editor and applying your own transform will
176 // obliterate it! If you want to scale the whole of your UI use Desktop::setGlobalScaleFactor(),
177 // or, for applying other transforms, consider putting the component you want to transform
178 // in a child of the editor and transform that instead.
179 jassert (getTransform() == hostScaleTransform);
180
181 if (wasResized)
182 {
183 bool resizerHidden = false;
184
185 if (auto* peer = getPeer())
186 resizerHidden = peer->isFullScreen() || peer->isKioskMode();
187
188 if (resizableCorner != nullptr)
189 {
190 resizableCorner->setVisible (! resizerHidden);
191
192 const int resizerSize = 18;
193 resizableCorner->setBounds (getWidth() - resizerSize,
196 }
197 }
198}
199
200void AudioProcessorEditor::updatePeer()
201{
202 if (isOnDesktop())
203 if (auto* peer = getPeer())
204 peer->setConstrainer (constrainer);
205}
206
208{
209 hostScaleTransform = AffineTransform::scale (newScale);
210 setTransform (hostScaleTransform);
211
212 editorResized (true);
213}
214
215//==============================================================================
216typedef ComponentPeer* (*createUnityPeerFunctionType) (Component&);
217createUnityPeerFunctionType juce_createUnityPeerFn = nullptr;
218
219ComponentPeer* AudioProcessorEditor::createNewPeer ([[maybe_unused]] int styleFlags,
220 [[maybe_unused]] void* nativeWindow)
221{
222 if (juce_createUnityPeerFn != nullptr)
223 return juce_createUnityPeerFn (*this);
224
225 return Component::createNewPeer (styleFlags, nativeWindow);
226}
227
229{
230 #if JUCE_MODULE_AVAILABLE_juce_opengl && JUCE_MAC
231 if (@available (macOS 10.14, *))
232 return true;
233
234 return false;
235 #else
236 return true;
237 #endif
238}
239
240} // namespace juce
static AffineTransform scale(float factorX, float factorY) noexcept
Returns a new transform which is a re-scale about the origin.
void setBoundsConstrained(Rectangle< int > newBounds)
Calls the window's setBounds method, after first checking these bounds with the current constrainer.
AudioProcessorEditor(AudioProcessor &) noexcept
Creates an editor for the specified processor.
virtual bool supportsHostMIDIControllerPresence(bool hostMIDIControllerIsAvailable)
Override this method to indicate if your editor supports the presence or absence of a host-provided M...
void setResizable(bool allowHostToResize, bool useBottomRightCornerResizer)
Sets whether the editor is resizable by the host and/or user.
virtual int getControlParameterIndex(Component &)
Called by certain plug-in wrappers to find out whether a component is used to control a parameter.
~AudioProcessorEditor() override
Destructor.
virtual void setControlHighlight(ParameterControlHighlightInfo)
Some types of plugin can call this to suggest that the control for a particular parameter should be h...
virtual void setScaleFactor(float newScale)
Can be called by a host to tell the editor that it should use a non-unity GUI scale.
void setResizeLimits(int newMinimumWidth, int newMinimumHeight, int newMaximumWidth, int newMaximumHeight) noexcept
This sets the maximum and minimum sizes for the window.
virtual bool wantsLayerBackedView() const
The plugin wrapper will call this function to decide whether to use a layer-backed view to host the e...
std::unique_ptr< ResizableCornerComponent > resizableCorner
The ResizableCornerComponent which is currently being used by this editor, or nullptr if it does not ...
AudioProcessor & processor
The AudioProcessor that this editor represents.
virtual void hostMIDIControllerIsAvailable(bool controllerIsAvailable)
Called to indicate if a host is providing a MIDI controller when the host reconfigures its layout.
void setConstrainer(ComponentBoundsConstrainer *newConstrainer)
Sets the bounds-constrainer object to use for resizing and dragging this window.
Base class for audio processing classes or plugins.
AudioProcessorEditor * getActiveEditor() const noexcept
Returns the active editor, if there is one.
A class that imposes restrictions on a Component's size or position.
void setBoundsForComponent(Component *component, Rectangle< int > bounds, bool isStretchingTop, bool isStretchingLeft, bool isStretchingBottom, bool isStretchingRight)
Checks the given bounds, and then sets the component to the corrected size.
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
The base class for all JUCE user-interface objects.
AffineTransform getTransform() const
Returns the transform that is currently being applied to this component.
void setTransform(const AffineTransform &transform)
Sets a transform matrix to be applied to this component.
void removeComponentListener(ComponentListener *listenerToRemove)
Removes a component listener.
int getHeight() const noexcept
Returns the component's height in pixels.
void addComponentListener(ComponentListener *newListener)
Adds a listener to be told about changes to the component hierarchy or position.
Rectangle< int > getBounds() const noexcept
Returns this component's bounding box.
bool isOnDesktop() const noexcept
Returns true if this component is currently showing on the desktop.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
int getWidth() const noexcept
Returns the component's width in pixels.
ComponentPeer * getPeer() const
Returns the heavyweight window that contains this component.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
The standard JUCE splash screen component.
Manages a rectangle and allows geometric operations to be performed on it.
T get(T... args)
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T reset(T... args)