migrating to the latest JUCE version

This commit is contained in:
2022-11-04 23:11:33 +01:00
committed by Nikolai Rodionov
parent 4257a0f8ba
commit faf8f18333
2796 changed files with 888518 additions and 784244 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,172 +1,172 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/PluginGraph.h"
class MainHostWindow;
//==============================================================================
/**
A panel that displays and edits a PluginGraph.
*/
class GraphEditorPanel : public Component,
public ChangeListener,
private Timer
{
public:
GraphEditorPanel (PluginGraph& graph);
~GraphEditorPanel() override;
void createNewPlugin (const PluginDescription&, Point<int> position);
void paint (Graphics&) override;
void resized() override;
void mouseDown (const MouseEvent&) override;
void mouseUp (const MouseEvent&) override;
void mouseDrag (const MouseEvent&) override;
void changeListenerCallback (ChangeBroadcaster*) override;
//==============================================================================
void updateComponents();
//==============================================================================
void showPopupMenu (Point<int> position);
//==============================================================================
void beginConnectorDrag (AudioProcessorGraph::NodeAndChannel source,
AudioProcessorGraph::NodeAndChannel dest,
const MouseEvent&);
void dragConnector (const MouseEvent&);
void endDraggingConnector (const MouseEvent&);
//==============================================================================
PluginGraph& graph;
private:
struct PluginComponent;
struct ConnectorComponent;
struct PinComponent;
OwnedArray<PluginComponent> nodes;
OwnedArray<ConnectorComponent> connectors;
std::unique_ptr<ConnectorComponent> draggingConnector;
std::unique_ptr<PopupMenu> menu;
PluginComponent* getComponentForPlugin (AudioProcessorGraph::NodeID) const;
ConnectorComponent* getComponentForConnection (const AudioProcessorGraph::Connection&) const;
PinComponent* findPinAt (Point<float>) const;
//==============================================================================
Point<int> originalTouchPos;
void timerCallback() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel)
};
//==============================================================================
/**
A panel that embeds a GraphEditorPanel with a midi keyboard at the bottom.
It also manages the graph itself, and plays it.
*/
class GraphDocumentComponent : public Component,
public DragAndDropTarget,
public DragAndDropContainer,
private ChangeListener
{
public:
GraphDocumentComponent (AudioPluginFormatManager& formatManager,
AudioDeviceManager& deviceManager,
KnownPluginList& pluginList);
~GraphDocumentComponent() override;
//==============================================================================
void createNewPlugin (const PluginDescription&, Point<int> position);
void setDoublePrecision (bool doublePrecision);
bool closeAnyOpenPluginWindows();
//==============================================================================
std::unique_ptr<PluginGraph> graph;
void resized() override;
void unfocusKeyboardComponent();
void releaseGraph();
//==============================================================================
bool isInterestedInDragSource (const SourceDetails&) override;
void itemDropped (const SourceDetails&) override;
//==============================================================================
std::unique_ptr<GraphEditorPanel> graphPanel;
std::unique_ptr<MidiKeyboardComponent> keyboardComp;
//==============================================================================
void showSidePanel (bool isSettingsPanel);
void hideLastSidePanel();
BurgerMenuComponent burgerMenu;
private:
//==============================================================================
AudioDeviceManager& deviceManager;
KnownPluginList& pluginList;
AudioProcessorPlayer graphPlayer;
MidiKeyboardState keyState;
MidiOutput* midiOutput = nullptr;
struct TooltipBar;
std::unique_ptr<TooltipBar> statusBar;
class TitleBarComponent;
std::unique_ptr<TitleBarComponent> titleBarComponent;
//==============================================================================
struct PluginListBoxModel;
std::unique_ptr<PluginListBoxModel> pluginListBoxModel;
ListBox pluginListBox;
SidePanel mobileSettingsSidePanel { "Settings", 300, true };
SidePanel pluginListSidePanel { "Plugins", 250, false };
SidePanel* lastOpenedSidePanel = nullptr;
//==============================================================================
void changeListenerCallback (ChangeBroadcaster*) override;
void init();
void checkAvailableWidth();
void updateMidiOutput();
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
};
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/PluginGraph.h"
class MainHostWindow;
//==============================================================================
/**
A panel that displays and edits a PluginGraph.
*/
class GraphEditorPanel : public Component,
public ChangeListener,
private Timer
{
public:
//==============================================================================
GraphEditorPanel (PluginGraph& graph);
~GraphEditorPanel() override;
void createNewPlugin (const PluginDescriptionAndPreference&, Point<int> position);
void paint (Graphics&) override;
void resized() override;
void mouseDown (const MouseEvent&) override;
void mouseUp (const MouseEvent&) override;
void mouseDrag (const MouseEvent&) override;
void changeListenerCallback (ChangeBroadcaster*) override;
//==============================================================================
void updateComponents();
//==============================================================================
void showPopupMenu (Point<int> position);
//==============================================================================
void beginConnectorDrag (AudioProcessorGraph::NodeAndChannel source,
AudioProcessorGraph::NodeAndChannel dest,
const MouseEvent&);
void dragConnector (const MouseEvent&);
void endDraggingConnector (const MouseEvent&);
//==============================================================================
PluginGraph& graph;
private:
struct PluginComponent;
struct ConnectorComponent;
struct PinComponent;
OwnedArray<PluginComponent> nodes;
OwnedArray<ConnectorComponent> connectors;
std::unique_ptr<ConnectorComponent> draggingConnector;
std::unique_ptr<PopupMenu> menu;
PluginComponent* getComponentForPlugin (AudioProcessorGraph::NodeID) const;
ConnectorComponent* getComponentForConnection (const AudioProcessorGraph::Connection&) const;
PinComponent* findPinAt (Point<float>) const;
//==============================================================================
Point<int> originalTouchPos;
void timerCallback() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel)
};
//==============================================================================
/**
A panel that embeds a GraphEditorPanel with a midi keyboard at the bottom.
It also manages the graph itself, and plays it.
*/
class GraphDocumentComponent : public Component,
public DragAndDropTarget,
public DragAndDropContainer,
private ChangeListener
{
public:
GraphDocumentComponent (AudioPluginFormatManager& formatManager,
AudioDeviceManager& deviceManager,
KnownPluginList& pluginList);
~GraphDocumentComponent() override;
//==============================================================================
void createNewPlugin (const PluginDescriptionAndPreference&, Point<int> position);
void setDoublePrecision (bool doublePrecision);
bool closeAnyOpenPluginWindows();
//==============================================================================
std::unique_ptr<PluginGraph> graph;
void resized() override;
void releaseGraph();
//==============================================================================
bool isInterestedInDragSource (const SourceDetails&) override;
void itemDropped (const SourceDetails&) override;
//==============================================================================
std::unique_ptr<GraphEditorPanel> graphPanel;
std::unique_ptr<MidiKeyboardComponent> keyboardComp;
//==============================================================================
void showSidePanel (bool isSettingsPanel);
void hideLastSidePanel();
BurgerMenuComponent burgerMenu;
private:
//==============================================================================
AudioDeviceManager& deviceManager;
KnownPluginList& pluginList;
AudioProcessorPlayer graphPlayer;
MidiKeyboardState keyState;
MidiOutput* midiOutput = nullptr;
struct TooltipBar;
std::unique_ptr<TooltipBar> statusBar;
class TitleBarComponent;
std::unique_ptr<TitleBarComponent> titleBarComponent;
//==============================================================================
struct PluginListBoxModel;
std::unique_ptr<PluginListBoxModel> pluginListBoxModel;
ListBox pluginListBox;
SidePanel mobileSettingsSidePanel { "Settings", 300, true };
SidePanel pluginListSidePanel { "Plugins", 250, false };
SidePanel* lastOpenedSidePanel = nullptr;
//==============================================================================
void changeListenerCallback (ChangeBroadcaster*) override;
void init();
void checkAvailableWidth();
void updateMidiOutput();
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphDocumentComponent)
};

File diff suppressed because it is too large Load Diff

View File

@ -1,138 +1,142 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/PluginGraph.h"
#include "GraphEditorPanel.h"
//==============================================================================
namespace CommandIDs
{
#if ! (JUCE_IOS || JUCE_ANDROID)
static const int open = 0x30000;
static const int save = 0x30001;
static const int saveAs = 0x30002;
static const int newFile = 0x30003;
#endif
static const int showPluginListEditor = 0x30100;
static const int showAudioSettings = 0x30200;
static const int aboutBox = 0x30300;
static const int allWindowsForward = 0x30400;
static const int toggleDoublePrecision = 0x30500;
static const int autoScalePluginWindows = 0x30600;
}
//==============================================================================
ApplicationCommandManager& getCommandManager();
ApplicationProperties& getAppProperties();
bool isOnTouchDevice();
//==============================================================================
enum class AutoScale
{
scaled,
unscaled,
useDefault
};
constexpr bool autoScaleOptionAvailable =
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
true;
#else
false;
#endif
AutoScale getAutoScaleValueForPlugin (const String&);
void setAutoScaleValueForPlugin (const String&, AutoScale);
bool shouldAutoScalePlugin (const PluginDescription&);
void addPluginAutoScaleOptionsSubMenu (AudioPluginInstance*, PopupMenu&);
//==============================================================================
class MainHostWindow : public DocumentWindow,
public MenuBarModel,
public ApplicationCommandTarget,
public ChangeListener,
public FileDragAndDropTarget
{
public:
//==============================================================================
MainHostWindow();
~MainHostWindow() override;
//==============================================================================
void closeButtonPressed() override;
void changeListenerCallback (ChangeBroadcaster*) override;
bool isInterestedInFileDrag (const StringArray& files) override;
void fileDragEnter (const StringArray& files, int, int) override;
void fileDragMove (const StringArray& files, int, int) override;
void fileDragExit (const StringArray& files) override;
void filesDropped (const StringArray& files, int, int) override;
void menuBarActivated (bool isActive) override;
StringArray getMenuBarNames() override;
PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName) override;
void menuItemSelected (int menuItemID, int topLevelMenuIndex) override;
ApplicationCommandTarget* getNextCommandTarget() override;
void getAllCommands (Array<CommandID>&) override;
void getCommandInfo (CommandID, ApplicationCommandInfo&) override;
bool perform (const InvocationInfo&) override;
void tryToQuitApplication();
void createPlugin (const PluginDescription&, Point<int> pos);
void addPluginsToMenu (PopupMenu&);
PluginDescription getChosenType (int menuID) const;
std::unique_ptr<GraphDocumentComponent> graphHolder;
private:
//==============================================================================
static bool isDoublePrecisionProcessingEnabled();
static bool isAutoScalePluginWindowsEnabled();
static void updatePrecisionMenuItem (ApplicationCommandInfo& info);
static void updateAutoScaleMenuItem (ApplicationCommandInfo& info);
void showAudioSettings();
//==============================================================================
AudioDeviceManager deviceManager;
AudioPluginFormatManager formatManager;
std::vector<PluginDescription> internalTypes;
KnownPluginList knownPluginList;
KnownPluginList::SortMethod pluginSortMethod;
Array<PluginDescription> pluginDescriptions;
class PluginListWindow;
std::unique_ptr<PluginListWindow> pluginListWindow;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainHostWindow)
};
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/PluginGraph.h"
#include "GraphEditorPanel.h"
//==============================================================================
namespace CommandIDs
{
#if ! (JUCE_IOS || JUCE_ANDROID)
static const int open = 0x30000;
static const int save = 0x30001;
static const int saveAs = 0x30002;
static const int newFile = 0x30003;
#endif
static const int showPluginListEditor = 0x30100;
static const int showAudioSettings = 0x30200;
static const int aboutBox = 0x30300;
static const int allWindowsForward = 0x30400;
static const int toggleDoublePrecision = 0x30500;
static const int autoScalePluginWindows = 0x30600;
}
//==============================================================================
ApplicationCommandManager& getCommandManager();
ApplicationProperties& getAppProperties();
bool isOnTouchDevice();
//==============================================================================
enum class AutoScale
{
scaled,
unscaled,
useDefault
};
constexpr bool autoScaleOptionAvailable =
#if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE
true;
#else
false;
#endif
AutoScale getAutoScaleValueForPlugin (const String&);
void setAutoScaleValueForPlugin (const String&, AutoScale);
bool shouldAutoScalePlugin (const PluginDescription&);
void addPluginAutoScaleOptionsSubMenu (AudioPluginInstance*, PopupMenu&);
constexpr const char* processUID = "juceaudiopluginhost";
//==============================================================================
class MainHostWindow : public DocumentWindow,
public MenuBarModel,
public ApplicationCommandTarget,
public ChangeListener,
public FileDragAndDropTarget
{
public:
//==============================================================================
MainHostWindow();
~MainHostWindow() override;
//==============================================================================
void closeButtonPressed() override;
void changeListenerCallback (ChangeBroadcaster*) override;
bool isInterestedInFileDrag (const StringArray& files) override;
void fileDragEnter (const StringArray& files, int, int) override;
void fileDragMove (const StringArray& files, int, int) override;
void fileDragExit (const StringArray& files) override;
void filesDropped (const StringArray& files, int, int) override;
void menuBarActivated (bool isActive) override;
StringArray getMenuBarNames() override;
PopupMenu getMenuForIndex (int topLevelMenuIndex, const String& menuName) override;
void menuItemSelected (int menuItemID, int topLevelMenuIndex) override;
ApplicationCommandTarget* getNextCommandTarget() override;
void getAllCommands (Array<CommandID>&) override;
void getCommandInfo (CommandID, ApplicationCommandInfo&) override;
bool perform (const InvocationInfo&) override;
void tryToQuitApplication();
void createPlugin (const PluginDescriptionAndPreference&, Point<int> pos);
void addPluginsToMenu (PopupMenu&);
PluginDescriptionAndPreference getChosenType (int menuID) const;
std::unique_ptr<GraphDocumentComponent> graphHolder;
private:
//==============================================================================
static bool isDoublePrecisionProcessingEnabled();
static bool isAutoScalePluginWindowsEnabled();
static void updatePrecisionMenuItem (ApplicationCommandInfo& info);
static void updateAutoScaleMenuItem (ApplicationCommandInfo& info);
void showAudioSettings();
int getIndexChosenByMenu (int menuID) const;
//==============================================================================
AudioDeviceManager deviceManager;
AudioPluginFormatManager formatManager;
std::vector<PluginDescription> internalTypes;
KnownPluginList knownPluginList;
KnownPluginList::SortMethod pluginSortMethod;
Array<PluginDescriptionAndPreference> pluginDescriptionsAndPreference;
class PluginListWindow;
std::unique_ptr<PluginListWindow> pluginListWindow;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainHostWindow)
};

View File

@ -1,331 +1,350 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/IOConfigurationWindow.h"
inline String getFormatSuffix (const AudioProcessor* plugin)
{
const auto format = [plugin]()
{
if (auto* instance = dynamic_cast<const AudioPluginInstance*> (plugin))
return instance->getPluginDescription().pluginFormatName;
return String();
}();
return format.isNotEmpty() ? (" (" + format + ")") : format;
}
class PluginGraph;
/**
A window that shows a log of parameter change messages sent by the plugin.
*/
class PluginDebugWindow : public AudioProcessorEditor,
public AudioProcessorParameter::Listener,
public ListBoxModel,
public AsyncUpdater
{
public:
PluginDebugWindow (AudioProcessor& proc)
: AudioProcessorEditor (proc), audioProc (proc)
{
setSize (500, 200);
addAndMakeVisible (list);
for (auto* p : audioProc.getParameters())
p->addListener (this);
log.add ("Parameter debug log started");
}
void parameterValueChanged (int parameterIndex, float newValue) override
{
auto* param = audioProc.getParameters()[parameterIndex];
auto value = param->getCurrentValueAsText().quoted() + " (" + String (newValue, 4) + ")";
appendToLog ("parameter change", *param, value);
}
void parameterGestureChanged (int parameterIndex, bool gestureIsStarting) override
{
auto* param = audioProc.getParameters()[parameterIndex];
appendToLog ("gesture", *param, gestureIsStarting ? "start" : "end");
}
private:
void appendToLog (StringRef action, AudioProcessorParameter& param, StringRef value)
{
String entry (action + " " + param.getName (30).quoted() + " [" + String (param.getParameterIndex()) + "]: " + value);
{
ScopedLock lock (pendingLogLock);
pendingLogEntries.add (entry);
}
triggerAsyncUpdate();
}
void resized() override
{
list.setBounds(getLocalBounds());
}
int getNumRows() override
{
return log.size();
}
void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool) override
{
g.setColour (getLookAndFeel().findColour (TextEditor::textColourId));
if (isPositiveAndBelow (rowNumber, log.size()))
g.drawText (log[rowNumber], Rectangle<int> { 0, 0, width, height }, Justification::left, true);
}
void handleAsyncUpdate() override
{
if (log.size() > logSizeTrimThreshold)
log.removeRange (0, log.size() - maxLogSize);
{
ScopedLock lock (pendingLogLock);
log.addArray (pendingLogEntries);
pendingLogEntries.clear();
}
list.updateContent();
list.scrollToEnsureRowIsOnscreen (log.size() - 1);
}
constexpr static const int maxLogSize = 300;
constexpr static const int logSizeTrimThreshold = 400;
ListBox list { "Log", this };
StringArray log;
StringArray pendingLogEntries;
CriticalSection pendingLogLock;
AudioProcessor& audioProc;
};
//==============================================================================
/**
A desktop window containing a plugin's GUI.
*/
class PluginWindow : public DocumentWindow
{
public:
enum class Type
{
normal = 0,
generic,
programs,
audioIO,
debug,
numTypes
};
PluginWindow (AudioProcessorGraph::Node* n, Type t, OwnedArray<PluginWindow>& windowList)
: DocumentWindow (n->getProcessor()->getName() + getFormatSuffix (n->getProcessor()),
LookAndFeel::getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId),
DocumentWindow::minimiseButton | DocumentWindow::closeButton),
activeWindowList (windowList),
node (n), type (t)
{
setSize (400, 300);
if (auto* ui = createProcessorEditor (*node->getProcessor(), type))
{
setContentOwned (ui, true);
setResizable (ui->isResizable(), false);
}
#if JUCE_IOS || JUCE_ANDROID
auto screenBounds = Desktop::getInstance().getDisplays().getTotalBounds (true).toFloat();
auto scaleFactor = jmin ((screenBounds.getWidth() - 50) / getWidth(), (screenBounds.getHeight() - 50) / getHeight());
if (scaleFactor < 1.0f)
setSize ((int) (getWidth() * scaleFactor), (int) (getHeight() * scaleFactor));
setTopLeftPosition (20, 20);
#else
setTopLeftPosition (node->properties.getWithDefault (getLastXProp (type), Random::getSystemRandom().nextInt (500)),
node->properties.getWithDefault (getLastYProp (type), Random::getSystemRandom().nextInt (500)));
#endif
node->properties.set (getOpenProp (type), true);
setVisible (true);
}
~PluginWindow() override
{
clearContentComponent();
}
void moved() override
{
node->properties.set (getLastXProp (type), getX());
node->properties.set (getLastYProp (type), getY());
}
void closeButtonPressed() override
{
node->properties.set (getOpenProp (type), false);
activeWindowList.removeObject (this);
}
static String getLastXProp (Type type) { return "uiLastX_" + getTypeName (type); }
static String getLastYProp (Type type) { return "uiLastY_" + getTypeName (type); }
static String getOpenProp (Type type) { return "uiopen_" + getTypeName (type); }
OwnedArray<PluginWindow>& activeWindowList;
const AudioProcessorGraph::Node::Ptr node;
const Type type;
BorderSize<int> getBorderThickness() override
{
#if JUCE_IOS || JUCE_ANDROID
const int border = 10;
return { border, border, border, border };
#else
return DocumentWindow::getBorderThickness();
#endif
}
private:
float getDesktopScaleFactor() const override { return 1.0f; }
static AudioProcessorEditor* createProcessorEditor (AudioProcessor& processor,
PluginWindow::Type type)
{
if (type == PluginWindow::Type::normal)
{
if (processor.hasEditor())
if (auto* ui = processor.createEditorIfNeeded())
return ui;
type = PluginWindow::Type::generic;
}
if (type == PluginWindow::Type::generic) return new GenericAudioProcessorEditor (processor);
if (type == PluginWindow::Type::programs) return new ProgramAudioProcessorEditor (processor);
if (type == PluginWindow::Type::audioIO) return new IOConfigurationWindow (processor);
if (type == PluginWindow::Type::debug) return new PluginDebugWindow (processor);
jassertfalse;
return {};
}
static String getTypeName (Type type)
{
switch (type)
{
case Type::normal: return "Normal";
case Type::generic: return "Generic";
case Type::programs: return "Programs";
case Type::audioIO: return "IO";
case Type::debug: return "Debug";
case Type::numTypes:
default: return {};
}
}
//==============================================================================
struct ProgramAudioProcessorEditor : public AudioProcessorEditor
{
ProgramAudioProcessorEditor (AudioProcessor& p) : AudioProcessorEditor (p)
{
setOpaque (true);
addAndMakeVisible (panel);
Array<PropertyComponent*> programs;
auto numPrograms = p.getNumPrograms();
int totalHeight = 0;
for (int i = 0; i < numPrograms; ++i)
{
auto name = p.getProgramName (i).trim();
if (name.isEmpty())
name = "Unnamed";
auto pc = new PropertyComp (name, p);
programs.add (pc);
totalHeight += pc->getPreferredHeight();
}
panel.addProperties (programs);
setSize (400, jlimit (25, 400, totalHeight));
}
void paint (Graphics& g) override
{
g.fillAll (Colours::grey);
}
void resized() override
{
panel.setBounds (getLocalBounds());
}
private:
struct PropertyComp : public PropertyComponent,
private AudioProcessorListener
{
PropertyComp (const String& name, AudioProcessor& p) : PropertyComponent (name), owner (p)
{
owner.addListener (this);
}
~PropertyComp() override
{
owner.removeListener (this);
}
void refresh() override {}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override {}
void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
AudioProcessor& owner;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyComp)
};
PropertyPanel panel;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgramAudioProcessorEditor)
};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWindow)
};
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../Plugins/IOConfigurationWindow.h"
#include "../Plugins/ARAPlugin.h"
inline String getFormatSuffix (const AudioProcessor* plugin)
{
const auto format = [plugin]()
{
if (auto* instance = dynamic_cast<const AudioPluginInstance*> (plugin))
return instance->getPluginDescription().pluginFormatName;
return String();
}();
return format.isNotEmpty() ? (" (" + format + ")") : format;
}
class PluginGraph;
/**
A window that shows a log of parameter change messages sent by the plugin.
*/
class PluginDebugWindow : public AudioProcessorEditor,
public AudioProcessorParameter::Listener,
public ListBoxModel,
public AsyncUpdater
{
public:
PluginDebugWindow (AudioProcessor& proc)
: AudioProcessorEditor (proc), audioProc (proc)
{
setSize (500, 200);
addAndMakeVisible (list);
for (auto* p : audioProc.getParameters())
p->addListener (this);
log.add ("Parameter debug log started");
}
~PluginDebugWindow() override
{
for (auto* p : audioProc.getParameters())
p->removeListener (this);
}
void parameterValueChanged (int parameterIndex, float newValue) override
{
auto* param = audioProc.getParameters()[parameterIndex];
auto value = param->getCurrentValueAsText().quoted() + " (" + String (newValue, 4) + ")";
appendToLog ("parameter change", *param, value);
}
void parameterGestureChanged (int parameterIndex, bool gestureIsStarting) override
{
auto* param = audioProc.getParameters()[parameterIndex];
appendToLog ("gesture", *param, gestureIsStarting ? "start" : "end");
}
private:
void appendToLog (StringRef action, AudioProcessorParameter& param, StringRef value)
{
String entry (action + " " + param.getName (30).quoted() + " [" + String (param.getParameterIndex()) + "]: " + value);
{
ScopedLock lock (pendingLogLock);
pendingLogEntries.add (entry);
}
triggerAsyncUpdate();
}
void resized() override
{
list.setBounds(getLocalBounds());
}
int getNumRows() override
{
return log.size();
}
void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool) override
{
g.setColour (getLookAndFeel().findColour (TextEditor::textColourId));
if (isPositiveAndBelow (rowNumber, log.size()))
g.drawText (log[rowNumber], Rectangle<int> { 0, 0, width, height }, Justification::left, true);
}
void handleAsyncUpdate() override
{
if (log.size() > logSizeTrimThreshold)
log.removeRange (0, log.size() - maxLogSize);
{
ScopedLock lock (pendingLogLock);
log.addArray (pendingLogEntries);
pendingLogEntries.clear();
}
list.updateContent();
list.scrollToEnsureRowIsOnscreen (log.size() - 1);
}
constexpr static const int maxLogSize = 300;
constexpr static const int logSizeTrimThreshold = 400;
ListBox list { "Log", this };
StringArray log;
StringArray pendingLogEntries;
CriticalSection pendingLogLock;
AudioProcessor& audioProc;
};
//==============================================================================
/**
A desktop window containing a plugin's GUI.
*/
class PluginWindow : public DocumentWindow
{
public:
enum class Type
{
normal = 0,
generic,
programs,
audioIO,
debug,
araHost,
numTypes
};
PluginWindow (AudioProcessorGraph::Node* n, Type t, OwnedArray<PluginWindow>& windowList)
: DocumentWindow (n->getProcessor()->getName() + getFormatSuffix (n->getProcessor()),
LookAndFeel::getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId),
DocumentWindow::minimiseButton | DocumentWindow::closeButton),
activeWindowList (windowList),
node (n), type (t)
{
setSize (400, 300);
if (auto* ui = createProcessorEditor (*node->getProcessor(), type))
{
setContentOwned (ui, true);
setResizable (ui->isResizable(), false);
}
#if JUCE_IOS || JUCE_ANDROID
auto screenBounds = Desktop::getInstance().getDisplays().getTotalBounds (true).toFloat();
auto scaleFactor = jmin ((screenBounds.getWidth() - 50) / getWidth(), (screenBounds.getHeight() - 50) / getHeight());
if (scaleFactor < 1.0f)
setSize ((int) (getWidth() * scaleFactor), (int) (getHeight() * scaleFactor));
setTopLeftPosition (20, 20);
#else
setTopLeftPosition (node->properties.getWithDefault (getLastXProp (type), Random::getSystemRandom().nextInt (500)),
node->properties.getWithDefault (getLastYProp (type), Random::getSystemRandom().nextInt (500)));
#endif
node->properties.set (getOpenProp (type), true);
setVisible (true);
}
~PluginWindow() override
{
clearContentComponent();
}
void moved() override
{
node->properties.set (getLastXProp (type), getX());
node->properties.set (getLastYProp (type), getY());
}
void closeButtonPressed() override
{
node->properties.set (getOpenProp (type), false);
activeWindowList.removeObject (this);
}
static String getLastXProp (Type type) { return "uiLastX_" + getTypeName (type); }
static String getLastYProp (Type type) { return "uiLastY_" + getTypeName (type); }
static String getOpenProp (Type type) { return "uiopen_" + getTypeName (type); }
OwnedArray<PluginWindow>& activeWindowList;
const AudioProcessorGraph::Node::Ptr node;
const Type type;
BorderSize<int> getBorderThickness() override
{
#if JUCE_IOS || JUCE_ANDROID
const int border = 10;
return { border, border, border, border };
#else
return DocumentWindow::getBorderThickness();
#endif
}
private:
float getDesktopScaleFactor() const override { return 1.0f; }
static AudioProcessorEditor* createProcessorEditor (AudioProcessor& processor,
PluginWindow::Type type)
{
if (type == PluginWindow::Type::normal)
{
if (processor.hasEditor())
if (auto* ui = processor.createEditorIfNeeded())
return ui;
type = PluginWindow::Type::generic;
}
if (type == PluginWindow::Type::araHost)
{
#if JUCE_PLUGINHOST_ARA && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)
if (auto* araPluginInstanceWrapper = dynamic_cast<ARAPluginInstanceWrapper*> (&processor))
if (auto* ui = araPluginInstanceWrapper->createARAHostEditor())
return ui;
#endif
return {};
}
if (type == PluginWindow::Type::generic) return new GenericAudioProcessorEditor (processor);
if (type == PluginWindow::Type::programs) return new ProgramAudioProcessorEditor (processor);
if (type == PluginWindow::Type::audioIO) return new IOConfigurationWindow (processor);
if (type == PluginWindow::Type::debug) return new PluginDebugWindow (processor);
jassertfalse;
return {};
}
static String getTypeName (Type type)
{
switch (type)
{
case Type::normal: return "Normal";
case Type::generic: return "Generic";
case Type::programs: return "Programs";
case Type::audioIO: return "IO";
case Type::debug: return "Debug";
case Type::araHost: return "ARAHost";
case Type::numTypes:
default: return {};
}
}
//==============================================================================
struct ProgramAudioProcessorEditor : public AudioProcessorEditor
{
ProgramAudioProcessorEditor (AudioProcessor& p) : AudioProcessorEditor (p)
{
setOpaque (true);
addAndMakeVisible (panel);
Array<PropertyComponent*> programs;
auto numPrograms = p.getNumPrograms();
int totalHeight = 0;
for (int i = 0; i < numPrograms; ++i)
{
auto name = p.getProgramName (i).trim();
if (name.isEmpty())
name = "Unnamed";
auto pc = new PropertyComp (name, p);
programs.add (pc);
totalHeight += pc->getPreferredHeight();
}
panel.addProperties (programs);
setSize (400, jlimit (25, 400, totalHeight));
}
void paint (Graphics& g) override
{
g.fillAll (Colours::grey);
}
void resized() override
{
panel.setBounds (getLocalBounds());
}
private:
struct PropertyComp : public PropertyComponent,
private AudioProcessorListener
{
PropertyComp (const String& name, AudioProcessor& p) : PropertyComponent (name), owner (p)
{
owner.addListener (this);
}
~PropertyComp() override
{
owner.removeListener (this);
}
void refresh() override {}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override {}
void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
AudioProcessor& owner;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyComp)
};
PropertyPanel panel;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgramAudioProcessorEditor)
};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginWindow)
};