адаптация s13bby/osc под vst и gui. (вайбкод)

вайбкод потому что мне в моменте стало понятно. что проще было сразу писать на фреймворке JUCE, чем адаптировать консольное приложение на MiniAudio.
обновляться данный репозиторий не будет. СmakeLists адаптирован онли под linux.
This commit is contained in:
2026-11-20 14:52:33 +06:00
parent 8384123f87
commit b0a75e98db
10387 changed files with 4025195 additions and 0 deletions
@@ -0,0 +1,264 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
AudioProcessorEditor::AudioProcessorEditor (AudioProcessor& p) noexcept : processor (p)
{
initialise();
}
AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* p) noexcept : processor (*p)
{
// the filter must be valid
jassert (p != nullptr);
initialise();
}
AudioProcessorEditor::~AudioProcessorEditor()
{
// if this fails, then the wrapper hasn't called editorBeingDeleted() on the
// filter for some reason
jassert (processor.getActiveEditor() != this);
removeComponentListener (resizeListener.get());
}
void AudioProcessorEditor::setControlHighlight (ParameterControlHighlightInfo) {}
int AudioProcessorEditor::getControlParameterIndex (Component&) { return -1; }
bool AudioProcessorEditor::supportsHostMIDIControllerPresence (bool) { return true; }
void AudioProcessorEditor::hostMIDIControllerIsAvailable (bool) {}
void AudioProcessorEditor::initialise()
{
attachConstrainer (&defaultConstrainer);
resizeListener.reset (new AudioProcessorEditorListener (*this));
addComponentListener (resizeListener.get());
}
//==============================================================================
void AudioProcessorEditor::setResizable (bool allowHostToResize, bool useBottomRightCornerResizer)
{
resizableByHost = allowHostToResize;
const auto hasResizableCorner = (resizableCorner.get() != nullptr);
if (useBottomRightCornerResizer != hasResizableCorner)
{
if (useBottomRightCornerResizer)
attachResizableCornerComponent();
else
resizableCorner = nullptr;
}
}
void AudioProcessorEditor::setResizeLimits (int newMinimumWidth,
int newMinimumHeight,
int newMaximumWidth,
int newMaximumHeight) noexcept
{
if (constrainer != nullptr && constrainer != &defaultConstrainer)
{
// if you've set up a custom constrainer then these settings won't have any effect
jassertfalse;
return;
}
resizableByHost = (newMinimumWidth != newMaximumWidth || newMinimumHeight != newMaximumHeight);
defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
newMaximumWidth, newMaximumHeight);
if (constrainer == nullptr)
setConstrainer (&defaultConstrainer);
if (resizableCorner != nullptr)
attachResizableCornerComponent();
setBoundsConstrained (getBounds());
}
void AudioProcessorEditor::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
{
if (constrainer != newConstrainer)
{
attachConstrainer (newConstrainer);
if (constrainer != nullptr)
resizableByHost = (newConstrainer->getMinimumWidth() != newConstrainer->getMaximumWidth()
|| newConstrainer->getMinimumHeight() != newConstrainer->getMaximumHeight());
if (resizableCorner != nullptr)
attachResizableCornerComponent();
}
}
void AudioProcessorEditor::attachConstrainer (ComponentBoundsConstrainer* newConstrainer)
{
if (constrainer != newConstrainer)
{
constrainer = newConstrainer;
updatePeer();
}
}
void AudioProcessorEditor::attachResizableCornerComponent()
{
resizableCorner = std::make_unique<ResizableCornerComponent> (this, constrainer);
Component::addChildComponent (resizableCorner.get());
resizableCorner->setAlwaysOnTop (true);
editorResized (true);
}
void AudioProcessorEditor::setBoundsConstrained (Rectangle<int> newBounds)
{
if (constrainer == nullptr)
{
setBounds (newBounds);
return;
}
auto currentBounds = getBounds();
constrainer->setBoundsForComponent (this,
newBounds,
newBounds.getY() != currentBounds.getY() && newBounds.getBottom() == currentBounds.getBottom(),
newBounds.getX() != currentBounds.getX() && newBounds.getRight() == currentBounds.getRight(),
newBounds.getY() == currentBounds.getY() && newBounds.getBottom() != currentBounds.getBottom(),
newBounds.getX() == currentBounds.getX() && newBounds.getRight() != currentBounds.getRight());
}
AudioProcessorEditorARAExtension* AudioProcessorEditor::getARAClientExtensions()
{
#if JucePlugin_Enable_ARA
if (auto* extensions = dynamic_cast<AudioProcessorEditorARAExtension*> (this))
{
// To silence this jassert there are two options:
//
// 1. - Override AudioProcessorEditor::getARAClientExtensions() and
// return the "this" pointer.
//
// - This option has the advantage of being quick and easy,
// and avoids the above dynamic_cast.
//
// 2. - Create a new object that inherits from AudioProcessorEditorARAClientExtension.
//
// - Port your existing functionality from the AudioProcessorEditor
// to the new object.
//
// - Return a pointer to the object in AudioProcessorEditor::getARAClientExtensions().
//
// - This option has the advantage of allowing you to break
// up your AudioProcessorEditor into smaller composable objects.
jassertfalse;
return extensions;
}
#endif
return nullptr;
}
void AudioProcessorEditor::editorResized (bool wasResized)
{
// The host needs to be able to rescale the plug-in editor and applying your own transform will
// obliterate it! If you want to scale the whole of your UI use Desktop::setGlobalScaleFactor(),
// or, for applying other transforms, consider putting the component you want to transform
// in a child of the editor and transform that instead.
jassert (getTransform() == hostScaleTransform);
if (wasResized)
{
bool resizerHidden = false;
if (auto* peer = getPeer())
resizerHidden = peer->isFullScreen() || peer->isKioskMode();
if (resizableCorner != nullptr)
{
resizableCorner->setVisible (! resizerHidden);
const int resizerSize = 18;
resizableCorner->setBounds (getWidth() - resizerSize,
getHeight() - resizerSize,
resizerSize, resizerSize);
}
}
}
void AudioProcessorEditor::updatePeer()
{
if (isOnDesktop())
if (auto* peer = getPeer())
peer->setConstrainer (constrainer);
}
void AudioProcessorEditor::setScaleFactor (float newScale)
{
hostScaleTransform = AffineTransform::scale (newScale);
setTransform (hostScaleTransform);
editorResized (true);
}
//==============================================================================
typedef ComponentPeer* (*createUnityPeerFunctionType) (Component&);
createUnityPeerFunctionType juce_createUnityPeerFn = nullptr;
ComponentPeer* AudioProcessorEditor::createNewPeer (const DesktopWindowOptions& options)
{
if (juce_createUnityPeerFn != nullptr)
return juce_createUnityPeerFn (*this);
return Component::createNewPeer (options);
}
bool AudioProcessorEditor::wantsLayerBackedView() const
{
#if JUCE_MODULE_AVAILABLE_juce_opengl && JUCE_MAC
if (@available (macOS 10.14, *))
return true;
return false;
#else
return true;
#endif
}
bool AudioProcessorEditor::usesWindowsMultiTouch() const
{
return false;
}
} // namespace juce
@@ -0,0 +1,293 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
class AudioProcessorEditorListener;
class AudioProcessor;
class AudioProcessorEditorARAExtension;
//==============================================================================
/**
Base class for the component that acts as the GUI for an AudioProcessor.
Derive your editor component from this class, and create an instance of it
by overriding the AudioProcessor::createEditor() method.
@see AudioProcessor, GenericAudioProcessorEditor
@tags{Audio}
*/
class JUCE_API AudioProcessorEditor : public Component
{
protected:
//==============================================================================
/** Creates an editor for the specified processor. */
AudioProcessorEditor (AudioProcessor&) noexcept;
/** Creates an editor for the specified processor. */
AudioProcessorEditor (AudioProcessor*) noexcept;
public:
/** Destructor. */
~AudioProcessorEditor() override;
//==============================================================================
/** The AudioProcessor that this editor represents. */
AudioProcessor& processor;
/** Returns a pointer to the processor that this editor represents.
This method is here to support legacy code, but it's easier to just use the
AudioProcessorEditor::processor member variable directly to get this object.
*/
AudioProcessor* getAudioProcessor() const noexcept { return &processor; }
//==============================================================================
/** Used by the setParameterHighlighting() method. */
struct ParameterControlHighlightInfo
{
int parameterIndex;
bool isHighlighted;
Colour suggestedColour;
};
/** Some types of plugin can call this to suggest that the control for a particular
parameter should be highlighted.
Currently only AAX plugins will call this, and implementing it is optional.
*/
virtual void setControlHighlight (ParameterControlHighlightInfo);
/** Called by certain plug-in wrappers to find out whether a component is used
to control a parameter.
If the given component represents a particular plugin parameter, then this
method should return the index of that parameter. If not, it should return -1.
If not overridden, this will return -1 for all components.
This function will be called by the host in AAX and VST3 plug-ins in order to map
screen locations to parameters. For example, in Steinberg hosts, this enables the
"AI Knob" functionality, which enables hardware to control the parameter currently
under the mouse.
*/
virtual int getControlParameterIndex (Component&);
/** Override this method to indicate if your editor supports the presence or
absence of a host-provided MIDI controller.
Currently only AUv3 plug-ins support this functionality, and even then the
host may choose to ignore this information.
The default behaviour is to report support for both cases.
*/
virtual bool supportsHostMIDIControllerPresence (bool hostMIDIControllerIsAvailable);
/** Called to indicate if a host is providing a MIDI controller when the host
reconfigures its layout.
Use this as an opportunity to hide or display your own onscreen keyboard or
other input component.
Currently only AUv3 plug-ins support this functionality.
*/
virtual void hostMIDIControllerIsAvailable (bool controllerIsAvailable);
/** Can be called by a host to tell the editor that it should use a non-unity
GUI scale.
*/
virtual void setScaleFactor (float newScale);
//==============================================================================
/** Sets whether the editor is resizable by the host and/or user.
@param allowHostToResize whether the editor's parent window can be resized
by the host. Even if this is false, you can still
resize your window yourself by calling setBounds
(for example, when a user clicks on a button in
your editor to drop out a panel) which will bypass
any resizable/constraints checks.
@param useBottomRightCornerResizer if this is true, a ResizableCornerComponent will be
added to the editor's bottom-right to allow the user
to resize the editor regardless of the value of
`allowHostToResize`.
@see setResizeLimits, isResizable
*/
void setResizable (bool allowHostToResize, bool useBottomRightCornerResizer);
/** Returns true if the host is allowed to resize the editor's parent window.
@see setResizable
*/
bool isResizable() const noexcept { return resizableByHost; }
/** This sets the maximum and minimum sizes for the window.
If the window's current size is outside these limits, it will be resized to
make sure it's within them.
If you pass in a different minimum and maximum size, this will mark the editor
as resizable by the host.
A direct call to setBounds() will bypass any constraint checks, but when the
window is dragged by the user or resized by other indirect means, the constrainer
will limit the numbers involved.
Note that if you have set a custom constrainer for this editor then this will have
no effect, and if you have removed the constrainer with `setConstrainer (nullptr);`
then this will re-add the default constrainer with the new limits.
@see setResizable
*/
void setResizeLimits (int newMinimumWidth,
int newMinimumHeight,
int newMaximumWidth,
int newMaximumHeight) noexcept;
/** Returns the bounds constrainer object that this window is using.
You can access this to change its properties.
*/
ComponentBoundsConstrainer* getConstrainer() noexcept { return constrainer; }
/** Sets the bounds-constrainer object to use for resizing and dragging this window.
A pointer to the object you pass in will be kept, but it won't be deleted
by this object, so it's the caller's responsibility to manage it.
If you pass a nullptr, then no constraints will be placed on the positioning of the window.
*/
void setConstrainer (ComponentBoundsConstrainer* newConstrainer);
/** Calls the window's setBounds method, after first checking these bounds
with the current constrainer.
@see setConstrainer
*/
void setBoundsConstrained (Rectangle<int> newBounds);
/** Gets a context object, if one is available.
Returns nullptr if the host does not provide any information that the editor
can query.
The returned pointer is non-owning, so do not attempt to free it.
*/
AudioProcessorEditorHostContext* getHostContext() const noexcept { return hostContext; }
/** Sets a context object that can be queried to find information that the host
makes available to the plugin.
You will only need to call this function if you are implementing a plugin host.
*/
void setHostContext (AudioProcessorEditorHostContext* context) noexcept { hostContext = context; }
/** Returns a non-owning pointer to an object that implements ARA specific information
regarding this AudioProcessorEditor.
By default, for backwards compatibility, this will attempt to dynamic-cast this
AudioProcessor to AudioProcessorEditorARAExtension.
It is recommended to override this function to return a pointer directly to an object
of the correct type in order to avoid this dynamic cast.
*/
virtual AudioProcessorEditorARAExtension* getARAClientExtensions();
/** The ResizableCornerComponent which is currently being used by this editor,
or nullptr if it does not have one.
*/
std::unique_ptr<ResizableCornerComponent> resizableCorner;
/** The plugin wrapper will call this function to decide whether to use a layer-backed view to
host the editor on macOS and iOS.
Layer-backed views generally provide better performance, and are recommended in most
situations. However, on older macOS versions (confirmed on 10.12 and 10.13), displaying an
OpenGL context inside a layer-backed view can lead to deadlocks, so it is recommended to
avoid layer-backed views when using OpenGL on these OS versions.
The default behaviour of this function is to return false if and only if the juce_opengl
module is present and the current platform is macOS 10.13 or earlier.
You may want to override this behaviour if your plugin has an option to enable and disable
OpenGL rendering. If you know your plugin editor will never use OpenGL rendering, you can
set this function to return true in all situations.
*/
virtual bool wantsLayerBackedView() const;
/** The plugin wrapper will call this function to decide whether the editor is capable of
handling multi-touch events on Windows. This is disabled by default.
Editors and Windows that opt in to handling multi-touch events will have the built-in
Windows gesture recognition features disabled, and will not receive callbacks to
Component::mouseMagnify().
*/
virtual bool usesWindowsMultiTouch() const;
private:
//==============================================================================
struct AudioProcessorEditorListener : public ComponentListener
{
AudioProcessorEditorListener (AudioProcessorEditor& e) : ed (e) {}
void componentMovedOrResized (Component&, bool, bool wasResized) override { ed.editorResized (wasResized); }
void componentParentHierarchyChanged (Component&) override { ed.updatePeer(); }
AudioProcessorEditor& ed;
JUCE_DECLARE_NON_COPYABLE (AudioProcessorEditorListener)
};
ComponentPeer* createNewPeer (const DesktopWindowOptions&) override;
//==============================================================================
void initialise();
void editorResized (bool wasResized);
void updatePeer();
void attachConstrainer (ComponentBoundsConstrainer*);
void attachResizableCornerComponent();
//==============================================================================
std::unique_ptr<AudioProcessorEditorListener> resizeListener;
bool resizableByHost = false;
ComponentBoundsConstrainer defaultConstrainer;
ComponentBoundsConstrainer* constrainer = nullptr;
AudioProcessorEditorHostContext* hostContext = nullptr;
AffineTransform hostScaleTransform;
JUCE_DECLARE_NON_COPYABLE (AudioProcessorEditor)
};
} // namespace juce
@@ -0,0 +1,98 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** This wraps a context menu for a specific parameter, as provided by the host.
You can choose to create a standard PopupMenu to display the host-provided
options. Alternatively, you can ask the host to display a native menu at
a specific location.
@tags{Audio}
*/
struct HostProvidedContextMenu
{
virtual ~HostProvidedContextMenu() = default;
/** Get a PopupMenu holding entries specified by the host.
Most hosts will populate this menu with options that relate to the
parameter, such as displaying its automation lane. You are free
to modify this menu before displaying it, if you wish to add additional
options.
*/
virtual PopupMenu getEquivalentPopupMenu() const = 0;
/** Asks the host to display its native menu at a location relative
to the top left corner of the editor.
The position you provide should be in logical pixels. To display
the menu next to the mouse cursor, call Component::getMouseXYRelative()
on your editor and pass the result to this function.
*/
virtual void showNativeMenu (Point<int> pos) const = 0;
};
/** Calling AudioProcessorEditor::getHostContext() may return a pointer to an
instance of this class.
At the moment, this can be used to retrieve context menus for parameters in
compatible VST3 hosts. Additional extensions may be added here in the future.
@tags{Audio}
*/
struct AudioProcessorEditorHostContext
{
virtual ~AudioProcessorEditorHostContext() = default;
/** Returns an object which can be used to display a context menu for the
parameter with the given index.
*/
virtual std::unique_ptr<HostProvidedContextMenu> getContextMenuForParameter (const AudioProcessorParameter *) const = 0;
/** The naming of this function is misleading. Use getContextMenuForParameter() instead.
Returns an object which can be used to display a context menu for the
parameter with the given index.
*/
[[deprecated ("The naming of this function has been fixed, use getContextMenuForParameter instead")]]
virtual std::unique_ptr<HostProvidedContextMenu> getContextMenuForParameterIndex (const AudioProcessorParameter * p) const
{
return getContextMenuForParameter (p);
}
};
} // namespace juce
@@ -0,0 +1,644 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
#include <juce_audio_processors_headless/format_types/juce_LegacyAudioParameter.h>
namespace juce
{
class ParameterListener : private AudioProcessorParameter::Listener,
private AudioProcessorListener,
private Timer
{
public:
ParameterListener (AudioProcessor& proc, AudioProcessorParameter& param)
: processor (proc), parameter (param), isLegacyParam (LegacyAudioParameter::isLegacy (&param))
{
if (isLegacyParam)
processor.addListener (this);
else
parameter.addListener (this);
startTimer (100);
}
~ParameterListener() override
{
if (isLegacyParam)
processor.removeListener (this);
else
parameter.removeListener (this);
}
AudioProcessorParameter& getParameter() const noexcept
{
return parameter;
}
virtual void handleNewParameterValue() = 0;
private:
//==============================================================================
void parameterValueChanged (int, float) override
{
parameterValueHasChanged = 1;
}
void parameterGestureChanged (int, bool) override {}
//==============================================================================
void audioProcessorParameterChanged (AudioProcessor*, int index, float) override
{
if (index == parameter.getParameterIndex())
parameterValueHasChanged = 1;
}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override {}
//==============================================================================
void timerCallback() override
{
if (parameterValueHasChanged.compareAndSetBool (0, 1))
{
handleNewParameterValue();
startTimerHz (50);
}
else
{
startTimer (jmin (250, getTimerInterval() + 10));
}
}
AudioProcessor& processor;
AudioProcessorParameter& parameter;
Atomic<int> parameterValueHasChanged { 0 };
const bool isLegacyParam;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterListener)
};
class ParameterComponent : public Component,
public ParameterListener
{
public:
using ParameterListener::ParameterListener;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterComponent)
};
//==============================================================================
class BooleanParameterComponent final : public ParameterComponent
{
public:
BooleanParameterComponent (AudioProcessor& proc, AudioProcessorParameter& param)
: ParameterComponent (proc, param)
{
// Set the initial value.
handleNewParameterValue();
button.onClick = [this] { buttonClicked(); };
addAndMakeVisible (button);
}
void paint (Graphics&) override {}
void resized() override
{
auto area = getLocalBounds();
area.removeFromLeft (8);
button.setBounds (area.reduced (0, 10));
}
void handleNewParameterValue() override
{
button.setToggleState (isParameterOn(), dontSendNotification);
}
private:
void buttonClicked()
{
if (isParameterOn() != button.getToggleState())
{
getParameter().beginChangeGesture();
getParameter().setValueNotifyingHost (button.getToggleState() ? 1.0f : 0.0f);
getParameter().endChangeGesture();
}
}
bool isParameterOn() const { return getParameter().getValue() >= 0.5f; }
ToggleButton button;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BooleanParameterComponent)
};
//==============================================================================
class SwitchParameterComponent final : public ParameterComponent
{
public:
SwitchParameterComponent (AudioProcessor& proc, AudioProcessorParameter& param)
: ParameterComponent (proc, param)
{
for (auto& button : buttons)
{
button.setRadioGroupId (293847);
button.setClickingTogglesState (true);
}
buttons[0].setButtonText (getParameter().getText (0.0f, 16));
buttons[1].setButtonText (getParameter().getText (1.0f, 16));
buttons[0].setConnectedEdges (Button::ConnectedOnRight);
buttons[1].setConnectedEdges (Button::ConnectedOnLeft);
// Set the initial value.
buttons[0].setToggleState (true, dontSendNotification);
handleNewParameterValue();
buttons[1].onStateChange = [this] { rightButtonChanged(); };
for (auto& button : buttons)
addAndMakeVisible (button);
}
void paint (Graphics&) override {}
void resized() override
{
auto area = getLocalBounds().reduced (0, 8);
area.removeFromLeft (8);
for (auto& button : buttons)
button.setBounds (area.removeFromLeft (80));
}
void handleNewParameterValue() override
{
bool newState = isParameterOn();
if (buttons[1].getToggleState() != newState)
{
buttons[1].setToggleState (newState, dontSendNotification);
buttons[0].setToggleState (! newState, dontSendNotification);
}
}
private:
void rightButtonChanged()
{
auto buttonState = buttons[1].getToggleState();
if (isParameterOn() != buttonState)
{
getParameter().beginChangeGesture();
if (getParameter().getAllValueStrings().isEmpty())
{
getParameter().setValueNotifyingHost (buttonState ? 1.0f : 0.0f);
}
else
{
// When a parameter provides a list of strings we must set its
// value using those strings, rather than a float, because VSTs can
// have uneven spacing between the different allowed values and we
// want the snapping behaviour to be consistent with what we do with
// a combo box.
auto selectedText = buttons[buttonState ? 1 : 0].getButtonText();
getParameter().setValueNotifyingHost (getParameter().getValueForText (selectedText));
}
getParameter().endChangeGesture();
}
}
bool isParameterOn() const
{
if (getParameter().getAllValueStrings().isEmpty())
return getParameter().getValue() > 0.5f;
auto index = getParameter().getAllValueStrings()
.indexOf (getParameter().getCurrentValueAsText());
if (index < 0)
{
// The parameter is producing some unexpected text, so we'll do
// some linear interpolation.
index = roundToInt (getParameter().getValue());
}
return index == 1;
}
TextButton buttons[2];
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SwitchParameterComponent)
};
//==============================================================================
class ChoiceParameterComponent final : public ParameterComponent
{
public:
ChoiceParameterComponent (AudioProcessor& proc, AudioProcessorParameter& param)
: ParameterComponent (proc, param),
parameterValues (getParameter().getAllValueStrings())
{
box.addItemList (parameterValues, 1);
// Set the initial value.
handleNewParameterValue();
box.onChange = [this] { boxChanged(); };
addAndMakeVisible (box);
}
void paint (Graphics&) override {}
void resized() override
{
auto area = getLocalBounds();
area.removeFromLeft (8);
box.setBounds (area.reduced (0, 10));
}
private:
void handleNewParameterValue() override
{
auto index = parameterValues.indexOf (getParameter().getCurrentValueAsText());
if (index < 0)
{
// The parameter is producing some unexpected text, so we'll do
// some linear interpolation.
index = roundToInt (getParameter().getValue() * (float) (parameterValues.size() - 1));
}
box.setSelectedItemIndex (index, dontSendNotification);
}
void boxChanged()
{
if (getParameter().getCurrentValueAsText() != box.getText())
{
getParameter().beginChangeGesture();
// When a parameter provides a list of strings we must set its
// value using those strings, rather than a float, because VSTs can
// have uneven spacing between the different allowed values.
getParameter().setValueNotifyingHost (getParameter().getValueForText (box.getText()));
getParameter().endChangeGesture();
}
}
ComboBox box;
const StringArray parameterValues;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChoiceParameterComponent)
};
//==============================================================================
class SliderParameterComponent final : public ParameterComponent
{
public:
SliderParameterComponent (AudioProcessor& proc, AudioProcessorParameter& param)
: ParameterComponent (proc, param)
{
if (getParameter().getNumSteps() != AudioProcessor::getDefaultNumParameterSteps())
slider.setRange (0.0, 1.0, 1.0 / (getParameter().getNumSteps() - 1.0));
else
slider.setRange (0.0, 1.0);
slider.setDoubleClickReturnValue (true, param.getDefaultValue());
slider.setScrollWheelEnabled (false);
addAndMakeVisible (slider);
valueLabel.setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
valueLabel.setBorderSize ({ 1, 1, 1, 1 });
valueLabel.setJustificationType (Justification::centred);
addAndMakeVisible (valueLabel);
// Set the initial value.
handleNewParameterValue();
slider.onValueChange = [this] { sliderValueChanged(); };
slider.onDragStart = [this] { sliderStartedDragging(); };
slider.onDragEnd = [this] { sliderStoppedDragging(); };
}
void paint (Graphics&) override {}
void resized() override
{
auto area = getLocalBounds().reduced (0, 10);
valueLabel.setBounds (area.removeFromRight (80));
area.removeFromLeft (6);
slider.setBounds (area);
}
void handleNewParameterValue() override
{
if (! isDragging)
{
slider.setValue (getParameter().getValue(), dontSendNotification);
updateTextDisplay();
}
}
private:
void updateTextDisplay()
{
valueLabel.setText (getParameter().getCurrentValueAsText(), dontSendNotification);
}
void sliderValueChanged()
{
auto newVal = (float) slider.getValue();
if (! approximatelyEqual (getParameter().getValue(), newVal))
{
if (! isDragging)
getParameter().beginChangeGesture();
getParameter().setValueNotifyingHost ((float) slider.getValue());
updateTextDisplay();
if (! isDragging)
getParameter().endChangeGesture();
}
}
void sliderStartedDragging()
{
isDragging = true;
getParameter().beginChangeGesture();
}
void sliderStoppedDragging()
{
isDragging = false;
getParameter().endChangeGesture();
}
Slider slider { Slider::LinearHorizontal, Slider::TextEntryBoxPosition::NoTextBox };
Label valueLabel;
bool isDragging = false;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SliderParameterComponent)
};
//==============================================================================
class ParameterDisplayComponent final : public Component,
private AudioProcessorListener,
private AsyncUpdater
{
public:
ParameterDisplayComponent (AudioProcessorEditor& editorIn, AudioProcessorParameter& param)
: editor (editorIn), parameter (param)
{
editor.processor.addListener (this);
parameterName.setText (parameter.getName (128), dontSendNotification);
parameterName.setJustificationType (Justification::centredRight);
parameterName.setInterceptsMouseClicks (false, false);
addAndMakeVisible (parameterName);
parameterLabel.setText (parameter.getLabel(), dontSendNotification);
parameterLabel.setInterceptsMouseClicks (false, false);
addAndMakeVisible (parameterLabel);
addAndMakeVisible (*(parameterComp = createParameterComp (editor.processor)));
setSize (400, 40);
}
~ParameterDisplayComponent() override
{
cancelPendingUpdate();
editor.processor.removeListener (this);
}
void resized() override
{
auto area = getLocalBounds();
parameterName.setBounds (area.removeFromLeft (100));
parameterLabel.setBounds (area.removeFromRight (50));
parameterComp->setBounds (area);
}
void mouseDown (const MouseEvent& e) override
{
if (e.mods.isRightButtonDown())
if (auto* context = editor.getHostContext())
if (auto menu = context->getContextMenuForParameter (&parameter))
menu->getEquivalentPopupMenu().showMenuAsync (PopupMenu::Options().withTargetComponent (this)
.withMousePosition());
}
private:
AudioProcessorEditor& editor;
AudioProcessorParameter& parameter;
Label parameterName, parameterLabel;
std::unique_ptr<ParameterComponent> parameterComp;
std::unique_ptr<ParameterComponent> createParameterComp (AudioProcessor& processor) const
{
// The AU, AUv3 and VST (only via a .vstxml file) SDKs support
// marking a parameter as boolean. If you want consistency across
// all formats then it might be best to use a
// SwitchParameterComponent instead.
if (parameter.isBoolean())
return std::make_unique<BooleanParameterComponent> (processor, parameter);
// Most hosts display any parameter with just two steps as a switch.
if (parameter.getNumSteps() == 2)
return std::make_unique<SwitchParameterComponent> (processor, parameter);
// If we have a list of strings to represent the different states a
// parameter can be in then we should present a dropdown allowing a
// user to pick one of them.
// We limit the number of items in the dropdown to avoid having to
// build and display an overly-large menu.
constexpr auto arbitraryDiscreteChoiceThreshold = 1000;
if (const auto numSteps = parameter.getNumSteps();
numSteps < arbitraryDiscreteChoiceThreshold)
{
const auto valueStrings = parameter.getAllValueStrings();
if (! valueStrings.isEmpty() && std::abs (numSteps - valueStrings.size()) <= 1)
return std::make_unique<ChoiceParameterComponent> (processor, parameter);
}
// Everything else can be represented as a slider.
return std::make_unique<SliderParameterComponent> (processor, parameter);
}
void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails& details) override
{
if (! details.parameterInfoChanged)
return;
if (MessageManager::getInstance()->isThisTheMessageThread())
handleAsyncUpdate();
else
triggerAsyncUpdate();
}
void handleAsyncUpdate() override
{
parameterName .setText (parameter.getName (128), dontSendNotification);
parameterLabel.setText (parameter.getLabel(), dontSendNotification);
if (auto* p = parameterComp.get())
p->handleNewParameterValue();
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterDisplayComponent)
};
//==============================================================================
struct ParamControlItem final : public TreeViewItem
{
ParamControlItem (AudioProcessorEditor& editorIn, AudioProcessorParameter& paramIn)
: editor (editorIn), param (paramIn) {}
bool mightContainSubItems() override { return false; }
std::unique_ptr<Component> createItemComponent() override
{
return std::make_unique<ParameterDisplayComponent> (editor, param);
}
int getItemHeight() const override { return 40; }
AudioProcessorEditor& editor;
AudioProcessorParameter& param;
};
struct ParameterGroupItem final : public TreeViewItem
{
ParameterGroupItem (AudioProcessorEditor& editor, const AudioProcessorParameterGroup& group)
: name (group.getName())
{
for (auto* node : group)
{
if (auto* param = node->getParameter())
if (param->isAutomatable())
addSubItem (new ParamControlItem (editor, *param));
if (auto* inner = node->getGroup())
{
auto groupItem = std::make_unique<ParameterGroupItem> (editor, *inner);
if (groupItem->getNumSubItems() != 0)
addSubItem (groupItem.release());
}
}
}
bool mightContainSubItems() override { return getNumSubItems() > 0; }
std::unique_ptr<Component> createItemComponent() override
{
return std::make_unique<Label> (name, name);
}
String name;
};
//==============================================================================
struct GenericAudioProcessorEditor::Pimpl
{
Pimpl (AudioProcessorEditor& editor)
: legacyParameters (editor.processor, false),
groupItem (editor, legacyParameters.getGroup())
{
const auto numIndents = getNumIndents (groupItem);
const auto width = 400 + view.getIndentSize() * numIndents;
view.setSize (width, 400);
view.setDefaultOpenness (true);
view.setRootItemVisible (false);
view.setRootItem (&groupItem);
}
static int getNumIndents (const TreeViewItem& item)
{
int maxInner = 0;
for (auto i = 0; i < item.getNumSubItems(); ++i)
maxInner = jmax (maxInner, 1 + getNumIndents (*item.getSubItem (i)));
return maxInner;
}
LegacyAudioParametersWrapper legacyParameters;
ParameterGroupItem groupItem;
TreeView view;
};
//==============================================================================
GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor& p)
: AudioProcessorEditor (p), pimpl (std::make_unique<Pimpl> (*this))
{
auto* viewport = pimpl->view.getViewport();
setOpaque (true);
addAndMakeVisible (pimpl->view);
setResizable (true, false);
setSize (viewport->getViewedComponent()->getWidth() + viewport->getVerticalScrollBar().getWidth(),
jlimit (125, 400, viewport->getViewedComponent()->getHeight()));
}
GenericAudioProcessorEditor::~GenericAudioProcessorEditor() = default;
void GenericAudioProcessorEditor::paint (Graphics& g)
{
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
}
void GenericAudioProcessorEditor::resized()
{
pimpl->view.setBounds (getLocalBounds());
}
} // namespace juce
@@ -0,0 +1,74 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-9-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A type of UI component that displays the parameters of an AudioProcessor as
a simple list of sliders, combo boxes and switches.
This can be used for showing an editor for a processor that doesn't supply
its own custom editor.
@see AudioProcessor
@tags{Audio}
*/
class JUCE_API GenericAudioProcessorEditor : public AudioProcessorEditor
{
public:
//==============================================================================
GenericAudioProcessorEditor (AudioProcessor&);
~GenericAudioProcessorEditor() override;
//==============================================================================
void paint (Graphics&) override;
void resized() override;
/** @cond */
[[deprecated ("This constructor has been changed to take a reference instead of a pointer.")]]
GenericAudioProcessorEditor (AudioProcessor* p) : GenericAudioProcessorEditor (*p) {}
/** @endcond */
private:
//==============================================================================
struct Pimpl;
std::unique_ptr<Pimpl> pimpl;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GenericAudioProcessorEditor)
};
} // namespace juce