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

View File

@ -1,284 +1,393 @@
/*
==============================================================================
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.
==============================================================================
*/
#include <JuceHeader.h>
#include "UI/MainHostWindow.h"
#include "Plugins/InternalPlugins.h"
#include "MacSpecific.h"
#if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
#error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
#endif
//==============================================================================
class PluginHostApp : public JUCEApplication,
private AsyncUpdater
{
public:
PluginHostApp() {}
void initialise (const String&) override
{
// initialise our settings file..
PropertiesFile::Options options;
options.applicationName = "Juce Audio Plugin Host";
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Preferences";
appProperties.reset (new ApplicationProperties());
appProperties->setStorageParameters (options);
mainWindow.reset (new MainHostWindow());
mainWindow->setUsingNativeTitleBar (true);
commandManager.registerAllCommandsForTarget (this);
commandManager.registerAllCommandsForTarget (mainWindow.get());
mainWindow->menuItemsChanged();
#if JUCE_MAC
disableAppNap();
#endif
// Important note! We're going to use an async update here so that if we need
// to re-open a file and instantiate some plugins, it will happen AFTER this
// initialisation method has returned.
// On Windows this probably won't make a difference, but on OSX there's a subtle event loop
// issue that can happen if a plugin runs one of those irritating modal dialogs while it's
// being loaded. If that happens inside this method, the OSX event loop seems to be in some
// kind of special "initialisation" mode and things get confused. But if we load the plugin
// later when the normal event loop is running, everything's fine.
triggerAsyncUpdate();
}
void handleAsyncUpdate() override
{
File fileToOpen;
#if JUCE_ANDROID || JUCE_IOS
fileToOpen = PluginGraph::getDefaultGraphDocumentOnMobile();
#else
for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
{
fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
if (fileToOpen.existsAsFile())
break;
}
#endif
if (! fileToOpen.existsAsFile())
{
RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
if (recentFiles.getNumFiles() > 0)
fileToOpen = recentFiles.getFile (0);
}
if (fileToOpen.existsAsFile())
if (auto* graph = mainWindow->graphHolder.get())
if (auto* ioGraph = graph->graph.get())
ioGraph->loadFrom (fileToOpen, true);
}
void shutdown() override
{
mainWindow = nullptr;
appProperties = nullptr;
LookAndFeel::setDefaultLookAndFeel (nullptr);
}
void suspended() override
{
#if JUCE_ANDROID || JUCE_IOS
if (auto graph = mainWindow->graphHolder.get())
if (auto ioGraph = graph->graph.get())
ioGraph->saveDocument (PluginGraph::getDefaultGraphDocumentOnMobile());
#endif
}
void systemRequestedQuit() override
{
if (mainWindow != nullptr)
mainWindow->tryToQuitApplication();
else
JUCEApplicationBase::quit();
}
bool backButtonPressed() override
{
if (mainWindow->graphHolder != nullptr)
mainWindow->graphHolder->hideLastSidePanel();
return true;
}
const String getApplicationName() override { return "Juce Plug-In Host"; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
ApplicationCommandManager commandManager;
std::unique_ptr<ApplicationProperties> appProperties;
private:
std::unique_ptr<MainHostWindow> mainWindow;
};
static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
bool isOnTouchDevice()
{
static bool isTouch = Desktop::getInstance().getMainMouseSource().isTouch();
return isTouch;
}
//==============================================================================
static AutoScale autoScaleFromString (StringRef str)
{
if (str.isEmpty()) return AutoScale::useDefault;
if (str == CharPointer_ASCII { "0" }) return AutoScale::scaled;
if (str == CharPointer_ASCII { "1" }) return AutoScale::unscaled;
jassertfalse;
return AutoScale::useDefault;
}
static const char* autoScaleToString (AutoScale autoScale)
{
if (autoScale == AutoScale::scaled) return "0";
if (autoScale == AutoScale::unscaled) return "1";
return {};
}
AutoScale getAutoScaleValueForPlugin (const String& identifier)
{
if (identifier.isNotEmpty())
{
auto plugins = StringArray::fromLines (getAppProperties().getUserSettings()->getValue ("autoScalePlugins"));
plugins.removeEmptyStrings();
for (auto& plugin : plugins)
{
auto fromIdentifier = plugin.fromFirstOccurrenceOf (identifier, false, false);
if (fromIdentifier.isNotEmpty())
return autoScaleFromString (fromIdentifier.fromFirstOccurrenceOf (":", false, false));
}
}
return AutoScale::useDefault;
}
void setAutoScaleValueForPlugin (const String& identifier, AutoScale s)
{
auto plugins = StringArray::fromLines (getAppProperties().getUserSettings()->getValue ("autoScalePlugins"));
plugins.removeEmptyStrings();
auto index = [identifier, plugins]
{
auto it = std::find_if (plugins.begin(), plugins.end(),
[&] (const String& str) { return str.startsWith (identifier); });
return (int) std::distance (plugins.begin(), it);
}();
if (s == AutoScale::useDefault && index != plugins.size())
{
plugins.remove (index);
}
else
{
auto str = identifier + ":" + autoScaleToString (s);
if (index != plugins.size())
plugins.getReference (index) = str;
else
plugins.add (str);
}
getAppProperties().getUserSettings()->setValue ("autoScalePlugins", plugins.joinIntoString ("\n"));
}
static bool isAutoScaleAvailableForPlugin (const PluginDescription& description)
{
return autoScaleOptionAvailable
&& description.pluginFormatName.containsIgnoreCase ("VST");
}
bool shouldAutoScalePlugin (const PluginDescription& description)
{
if (! isAutoScaleAvailableForPlugin (description))
return false;
const auto scaleValue = getAutoScaleValueForPlugin (description.fileOrIdentifier);
return (scaleValue == AutoScale::scaled
|| (scaleValue == AutoScale::useDefault
&& getAppProperties().getUserSettings()->getBoolValue ("autoScalePluginWindows")));
}
void addPluginAutoScaleOptionsSubMenu (AudioPluginInstance* pluginInstance,
PopupMenu& menu)
{
if (pluginInstance == nullptr)
return;
auto description = pluginInstance->getPluginDescription();
if (! isAutoScaleAvailableForPlugin (description))
return;
auto identifier = description.fileOrIdentifier;
PopupMenu autoScaleMenu;
autoScaleMenu.addItem ("Default",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::useDefault,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::useDefault); });
autoScaleMenu.addItem ("Enabled",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::scaled,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::scaled); });
autoScaleMenu.addItem ("Disabled",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::unscaled,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::unscaled); });
menu.addSubMenu ("Auto-scale window", autoScaleMenu);
}
// This kicks the whole thing off..
START_JUCE_APPLICATION (PluginHostApp)
/*
==============================================================================
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.
==============================================================================
*/
#include <JuceHeader.h>
#include "UI/MainHostWindow.h"
#include "Plugins/InternalPlugins.h"
#if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
#error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
#endif
class PluginScannerSubprocess : private ChildProcessWorker,
private AsyncUpdater
{
public:
PluginScannerSubprocess()
{
formatManager.addDefaultFormats();
}
using ChildProcessWorker::initialiseFromCommandLine;
private:
void handleMessageFromCoordinator (const MemoryBlock& mb) override
{
if (mb.isEmpty())
return;
if (! doScan (mb))
{
{
const std::lock_guard<std::mutex> lock (mutex);
pendingBlocks.emplace (mb);
}
triggerAsyncUpdate();
}
}
void handleConnectionLost() override
{
JUCEApplicationBase::quit();
}
void handleAsyncUpdate() override
{
for (;;)
{
const auto block = [&]() -> MemoryBlock
{
const std::lock_guard<std::mutex> lock (mutex);
if (pendingBlocks.empty())
return {};
auto out = std::move (pendingBlocks.front());
pendingBlocks.pop();
return out;
}();
if (block.isEmpty())
return;
doScan (block);
}
}
bool doScan (const MemoryBlock& block)
{
MemoryInputStream stream { block, false };
const auto formatName = stream.readString();
const auto identifier = stream.readString();
PluginDescription pd;
pd.fileOrIdentifier = identifier;
pd.uniqueId = pd.deprecatedUid = 0;
const auto matchingFormat = [&]() -> AudioPluginFormat*
{
for (auto* format : formatManager.getFormats())
if (format->getName() == formatName)
return format;
return nullptr;
}();
if (matchingFormat == nullptr
|| (! MessageManager::getInstance()->isThisTheMessageThread()
&& ! matchingFormat->requiresUnblockedMessageThreadDuringCreation (pd)))
{
return false;
}
OwnedArray<PluginDescription> results;
matchingFormat->findAllTypesForFile (results, identifier);
sendPluginDescriptions (results);
return true;
}
void sendPluginDescriptions (const OwnedArray<PluginDescription>& results)
{
XmlElement xml ("LIST");
for (const auto& desc : results)
xml.addChildElement (desc->createXml().release());
const auto str = xml.toString();
sendMessageToCoordinator ({ str.toRawUTF8(), str.getNumBytesAsUTF8() });
}
std::mutex mutex;
std::queue<MemoryBlock> pendingBlocks;
// After construction, this will only be accessed by doScan so there's no need
// to worry about synchronisation.
AudioPluginFormatManager formatManager;
};
//==============================================================================
class PluginHostApp : public JUCEApplication,
private AsyncUpdater
{
public:
PluginHostApp() = default;
void initialise (const String& commandLine) override
{
auto scannerSubprocess = std::make_unique<PluginScannerSubprocess>();
if (scannerSubprocess->initialiseFromCommandLine (commandLine, processUID))
{
storedScannerSubprocess = std::move (scannerSubprocess);
return;
}
// initialise our settings file..
PropertiesFile::Options options;
options.applicationName = "Juce Audio Plugin Host";
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Preferences";
appProperties.reset (new ApplicationProperties());
appProperties->setStorageParameters (options);
mainWindow.reset (new MainHostWindow());
commandManager.registerAllCommandsForTarget (this);
commandManager.registerAllCommandsForTarget (mainWindow.get());
mainWindow->menuItemsChanged();
// Important note! We're going to use an async update here so that if we need
// to re-open a file and instantiate some plugins, it will happen AFTER this
// initialisation method has returned.
// On Windows this probably won't make a difference, but on OSX there's a subtle event loop
// issue that can happen if a plugin runs one of those irritating modal dialogs while it's
// being loaded. If that happens inside this method, the OSX event loop seems to be in some
// kind of special "initialisation" mode and things get confused. But if we load the plugin
// later when the normal event loop is running, everything's fine.
triggerAsyncUpdate();
}
void handleAsyncUpdate() override
{
File fileToOpen;
#if JUCE_ANDROID || JUCE_IOS
fileToOpen = PluginGraph::getDefaultGraphDocumentOnMobile();
#else
for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
{
fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
if (fileToOpen.existsAsFile())
break;
}
#endif
if (! fileToOpen.existsAsFile())
{
RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
if (recentFiles.getNumFiles() > 0)
fileToOpen = recentFiles.getFile (0);
}
if (fileToOpen.existsAsFile())
if (auto* graph = mainWindow->graphHolder.get())
if (auto* ioGraph = graph->graph.get())
ioGraph->loadFrom (fileToOpen, true);
}
void shutdown() override
{
mainWindow = nullptr;
appProperties = nullptr;
LookAndFeel::setDefaultLookAndFeel (nullptr);
}
void suspended() override
{
#if JUCE_ANDROID || JUCE_IOS
if (auto graph = mainWindow->graphHolder.get())
if (auto ioGraph = graph->graph.get())
ioGraph->saveDocument (PluginGraph::getDefaultGraphDocumentOnMobile());
#endif
}
void systemRequestedQuit() override
{
if (mainWindow != nullptr)
mainWindow->tryToQuitApplication();
else
JUCEApplicationBase::quit();
}
bool backButtonPressed() override
{
if (mainWindow->graphHolder != nullptr)
mainWindow->graphHolder->hideLastSidePanel();
return true;
}
const String getApplicationName() override { return "Juce Plug-In Host"; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
ApplicationCommandManager commandManager;
std::unique_ptr<ApplicationProperties> appProperties;
private:
std::unique_ptr<MainHostWindow> mainWindow;
std::unique_ptr<PluginScannerSubprocess> storedScannerSubprocess;
};
static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
bool isOnTouchDevice()
{
static bool isTouch = Desktop::getInstance().getMainMouseSource().isTouch();
return isTouch;
}
//==============================================================================
static AutoScale autoScaleFromString (StringRef str)
{
if (str.isEmpty()) return AutoScale::useDefault;
if (str == CharPointer_ASCII { "0" }) return AutoScale::scaled;
if (str == CharPointer_ASCII { "1" }) return AutoScale::unscaled;
jassertfalse;
return AutoScale::useDefault;
}
static const char* autoScaleToString (AutoScale autoScale)
{
if (autoScale == AutoScale::scaled) return "0";
if (autoScale == AutoScale::unscaled) return "1";
return {};
}
AutoScale getAutoScaleValueForPlugin (const String& identifier)
{
if (identifier.isNotEmpty())
{
auto plugins = StringArray::fromLines (getAppProperties().getUserSettings()->getValue ("autoScalePlugins"));
plugins.removeEmptyStrings();
for (auto& plugin : plugins)
{
auto fromIdentifier = plugin.fromFirstOccurrenceOf (identifier, false, false);
if (fromIdentifier.isNotEmpty())
return autoScaleFromString (fromIdentifier.fromFirstOccurrenceOf (":", false, false));
}
}
return AutoScale::useDefault;
}
void setAutoScaleValueForPlugin (const String& identifier, AutoScale s)
{
auto plugins = StringArray::fromLines (getAppProperties().getUserSettings()->getValue ("autoScalePlugins"));
plugins.removeEmptyStrings();
auto index = [identifier, plugins]
{
auto it = std::find_if (plugins.begin(), plugins.end(),
[&] (const String& str) { return str.startsWith (identifier); });
return (int) std::distance (plugins.begin(), it);
}();
if (s == AutoScale::useDefault && index != plugins.size())
{
plugins.remove (index);
}
else
{
auto str = identifier + ":" + autoScaleToString (s);
if (index != plugins.size())
plugins.getReference (index) = str;
else
plugins.add (str);
}
getAppProperties().getUserSettings()->setValue ("autoScalePlugins", plugins.joinIntoString ("\n"));
}
static bool isAutoScaleAvailableForPlugin (const PluginDescription& description)
{
return autoScaleOptionAvailable
&& (description.pluginFormatName.containsIgnoreCase ("VST")
|| description.pluginFormatName.containsIgnoreCase ("LV2"));
}
bool shouldAutoScalePlugin (const PluginDescription& description)
{
if (! isAutoScaleAvailableForPlugin (description))
return false;
const auto scaleValue = getAutoScaleValueForPlugin (description.fileOrIdentifier);
return (scaleValue == AutoScale::scaled
|| (scaleValue == AutoScale::useDefault
&& getAppProperties().getUserSettings()->getBoolValue ("autoScalePluginWindows")));
}
void addPluginAutoScaleOptionsSubMenu (AudioPluginInstance* pluginInstance,
PopupMenu& menu)
{
if (pluginInstance == nullptr)
return;
auto description = pluginInstance->getPluginDescription();
if (! isAutoScaleAvailableForPlugin (description))
return;
auto identifier = description.fileOrIdentifier;
PopupMenu autoScaleMenu;
autoScaleMenu.addItem ("Default",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::useDefault,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::useDefault); });
autoScaleMenu.addItem ("Enabled",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::scaled,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::scaled); });
autoScaleMenu.addItem ("Disabled",
true,
getAutoScaleValueForPlugin (identifier) == AutoScale::unscaled,
[identifier] { setAutoScaleValueForPlugin (identifier, AutoScale::unscaled); });
menu.addSubMenu ("Auto-scale window", autoScaleMenu);
}
// This kicks the whole thing off..
START_JUCE_APPLICATION (PluginHostApp)

View File

@ -1,7 +0,0 @@
#pragma once
#if JUCE_MAC
void disableAppNap();
#endif

View File

@ -1,33 +0,0 @@
//
// MacSpecific.m
// AudioPluginHost - App
//
// Created by Jesse Chappell on 1/6/22.
// Copyright © 2022 Raw Material Software Limited. All rights reserved.
//
#include <juce_core/system/juce_TargetPlatform.h>
#if JUCE_MAC
#import <Cocoa/Cocoa.h>
void disableAppNap() {
// Does the App Nap API even exist on this Mac?
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)]) {
// If the API exists, then disable App Nap...
// From NSProcessInfo.h:
// NSActivityIdleSystemSleepDisabled = (1ULL << 20),
// NSActivityUserInitiated = (0x00FFFFFFULL | NSActivityIdleSystemSleepDisabled),
// NSActivityLatencyCritical = 0xFF00000000ULL
uint64_t options = (0x00FFFFFFULL | (1ULL << 20)) | 0xFF00000000ULL;
// NSActivityLatencyCritical | NSActivityUserInitiated
[[NSProcessInfo processInfo] beginActivityWithOptions:options
reason:@"avoiding audio hiccups and reducing latency"];
}
}
#endif

View File

@ -0,0 +1,33 @@
/*
==============================================================================
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.
==============================================================================
*/
#include "ARAPlugin.h"
#if JUCE_PLUGINHOST_ARA && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX)
const Identifier ARAPluginInstanceWrapper::ARATestHost::Context::xmlRootTag { "ARATestHostContext" };
const Identifier ARAPluginInstanceWrapper::ARATestHost::Context::xmlAudioFileAttrib { "AudioFile" };
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +1,59 @@
/*
==============================================================================
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
class MainHostWindow;
class GraphDocumentComponent;
//==============================================================================
class IOConfigurationWindow : public AudioProcessorEditor
{
public:
IOConfigurationWindow (AudioProcessor&);
~IOConfigurationWindow() override;
//==============================================================================
void paint (Graphics& g) override;
void resized() override;
private:
class InputOutputConfig;
AudioProcessor::BusesLayout currentLayout;
Label title;
std::unique_ptr<InputOutputConfig> inConfig, outConfig;
InputOutputConfig* getConfig (bool isInput) noexcept { return isInput ? inConfig.get() : outConfig.get(); }
void update();
MainHostWindow* getMainWindow() const;
GraphDocumentComponent* getGraphEditor() const;
AudioProcessorGraph* getGraph() const;
AudioProcessorGraph::NodeID getNodeID() const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IOConfigurationWindow)
};
/*
==============================================================================
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
class MainHostWindow;
class GraphDocumentComponent;
//==============================================================================
class IOConfigurationWindow : public AudioProcessorEditor
{
public:
IOConfigurationWindow (AudioProcessor&);
~IOConfigurationWindow() override;
//==============================================================================
void paint (Graphics& g) override;
void resized() override;
private:
class InputOutputConfig;
AudioProcessor::BusesLayout currentLayout;
Label title;
std::unique_ptr<InputOutputConfig> inConfig, outConfig;
InputOutputConfig* getConfig (bool isInput) noexcept { return isInput ? inConfig.get() : outConfig.get(); }
void update();
MainHostWindow* getMainWindow() const;
GraphDocumentComponent* getGraphEditor() const;
AudioProcessorGraph* getGraph() const;
AudioProcessorGraph::NodeID getNodeID() const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IOConfigurationWindow)
};

View File

@ -1,462 +1,482 @@
/*
==============================================================================
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.
==============================================================================
*/
#include <JuceHeader.h>
#include <juce_audio_plugin_client/juce_audio_plugin_client.h>
#include "InternalPlugins.h"
#include "PluginGraph.h"
#include "../../../../examples/Plugins/AUv3SynthPluginDemo.h"
#include "../../../../examples/Plugins/ArpeggiatorPluginDemo.h"
#include "../../../../examples/Plugins/AudioPluginDemo.h"
#include "../../../../examples/Plugins/DSPModulePluginDemo.h"
#include "../../../../examples/Plugins/GainPluginDemo.h"
#include "../../../../examples/Plugins/MidiLoggerPluginDemo.h"
#include "../../../../examples/Plugins/MultiOutSynthPluginDemo.h"
#include "../../../../examples/Plugins/NoiseGatePluginDemo.h"
#include "../../../../examples/Plugins/SamplerPluginDemo.h"
#include "../../../../examples/Plugins/SurroundPluginDemo.h"
//==============================================================================
class InternalPlugin : public AudioPluginInstance
{
public:
explicit InternalPlugin (std::unique_ptr<AudioProcessor> innerIn)
: inner (std::move (innerIn))
{
jassert (inner != nullptr);
for (auto isInput : { true, false })
matchChannels (isInput);
setBusesLayout (inner->getBusesLayout());
}
//==============================================================================
const String getName() const override { return inner->getName(); }
StringArray getAlternateDisplayNames() const override { return inner->getAlternateDisplayNames(); }
double getTailLengthSeconds() const override { return inner->getTailLengthSeconds(); }
bool acceptsMidi() const override { return inner->acceptsMidi(); }
bool producesMidi() const override { return inner->producesMidi(); }
AudioProcessorEditor* createEditor() override { return inner->createEditor(); }
bool hasEditor() const override { return inner->hasEditor(); }
int getNumPrograms() override { return inner->getNumPrograms(); }
int getCurrentProgram() override { return inner->getCurrentProgram(); }
void setCurrentProgram (int i) override { inner->setCurrentProgram (i); }
const String getProgramName (int i) override { return inner->getProgramName (i); }
void changeProgramName (int i, const String& n) override { inner->changeProgramName (i, n); }
void getStateInformation (juce::MemoryBlock& b) override { inner->getStateInformation (b); }
void setStateInformation (const void* d, int s) override { inner->setStateInformation (d, s); }
void getCurrentProgramStateInformation (juce::MemoryBlock& b) override { inner->getCurrentProgramStateInformation (b); }
void setCurrentProgramStateInformation (const void* d, int s) override { inner->setCurrentProgramStateInformation (d, s); }
void prepareToPlay (double sr, int bs) override { inner->setRateAndBufferSizeDetails (sr, bs); inner->prepareToPlay (sr, bs); }
void releaseResources() override { inner->releaseResources(); }
void memoryWarningReceived() override { inner->memoryWarningReceived(); }
void processBlock (AudioBuffer<float>& a, MidiBuffer& m) override { inner->processBlock (a, m); }
void processBlock (AudioBuffer<double>& a, MidiBuffer& m) override { inner->processBlock (a, m); }
void processBlockBypassed (AudioBuffer<float>& a, MidiBuffer& m) override { inner->processBlockBypassed (a, m); }
void processBlockBypassed (AudioBuffer<double>& a, MidiBuffer& m) override { inner->processBlockBypassed (a, m); }
bool supportsDoublePrecisionProcessing() const override { return inner->supportsDoublePrecisionProcessing(); }
bool supportsMPE() const override { return inner->supportsMPE(); }
bool isMidiEffect() const override { return inner->isMidiEffect(); }
void reset() override { inner->reset(); }
void setNonRealtime (bool b) noexcept override { inner->setNonRealtime (b); }
void refreshParameterList() override { inner->refreshParameterList(); }
void numChannelsChanged() override { inner->numChannelsChanged(); }
void numBusesChanged() override { inner->numBusesChanged(); }
void processorLayoutsChanged() override { inner->processorLayoutsChanged(); }
void setPlayHead (AudioPlayHead* p) override { inner->setPlayHead (p); }
void updateTrackProperties (const TrackProperties& p) override { inner->updateTrackProperties (p); }
bool isBusesLayoutSupported (const BusesLayout& layout) const override { return inner->checkBusesLayoutSupported (layout); }
bool canAddBus (bool) const override { return true; }
bool canRemoveBus (bool) const override { return true; }
//==============================================================================
void fillInPluginDescription (PluginDescription& description) const override
{
description = getPluginDescription (*inner);
}
private:
static PluginDescription getPluginDescription (const AudioProcessor& proc)
{
const auto ins = proc.getTotalNumInputChannels();
const auto outs = proc.getTotalNumOutputChannels();
const auto identifier = proc.getName();
const auto registerAsGenerator = ins == 0;
const auto acceptsMidi = proc.acceptsMidi();
PluginDescription descr;
descr.name = identifier;
descr.descriptiveName = identifier;
descr.pluginFormatName = InternalPluginFormat::getIdentifier();
descr.category = (registerAsGenerator ? (acceptsMidi ? "Synth" : "Generator") : "Effect");
descr.manufacturerName = "JUCE";
descr.version = ProjectInfo::versionString;
descr.fileOrIdentifier = identifier;
descr.isInstrument = (acceptsMidi && registerAsGenerator);
descr.numInputChannels = ins;
descr.numOutputChannels = outs;
descr.uniqueId = descr.deprecatedUid = identifier.hashCode();
return descr;
}
void matchChannels (bool isInput)
{
const auto inBuses = inner->getBusCount (isInput);
while (getBusCount (isInput) < inBuses)
addBus (isInput);
while (inBuses < getBusCount (isInput))
removeBus (isInput);
}
std::unique_ptr<AudioProcessor> inner;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalPlugin)
};
//==============================================================================
class SineWaveSynth : public AudioProcessor
{
public:
SineWaveSynth()
: AudioProcessor (BusesProperties().withOutput ("Output", AudioChannelSet::stereo()))
{
const int numVoices = 8;
// Add some voices...
for (int i = numVoices; --i >= 0;)
synth.addVoice (new SineWaveVoice());
// ..and give the synth a sound to play
synth.addSound (new SineWaveSound());
}
static String getIdentifier()
{
return "Sine Wave Synth";
}
//==============================================================================
void prepareToPlay (double newSampleRate, int) override
{
synth.setCurrentPlaybackSampleRate (newSampleRate);
}
void releaseResources() override {}
//==============================================================================
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override
{
const int numSamples = buffer.getNumSamples();
buffer.clear();
synth.renderNextBlock (buffer, midiMessages, 0, numSamples);
buffer.applyGain (0.8f);
}
using AudioProcessor::processBlock;
const String getName() const override { return getIdentifier(); }
double getTailLengthSeconds() const override { return 0.0; }
bool acceptsMidi() const override { return true; }
bool producesMidi() const override { return true; }
AudioProcessorEditor* createEditor() override { return nullptr; }
bool hasEditor() const override { return false; }
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram (int) override {}
const String getProgramName (int) override { return {}; }
void changeProgramName (int, const String&) override {}
void getStateInformation (juce::MemoryBlock&) override {}
void setStateInformation (const void*, int) override {}
private:
//==============================================================================
struct SineWaveSound : public SynthesiserSound
{
SineWaveSound() = default;
bool appliesToNote (int /*midiNoteNumber*/) override { return true; }
bool appliesToChannel (int /*midiChannel*/) override { return true; }
};
struct SineWaveVoice : public SynthesiserVoice
{
SineWaveVoice() = default;
bool canPlaySound (SynthesiserSound* sound) override
{
return dynamic_cast<SineWaveSound*> (sound) != nullptr;
}
void startNote (int midiNoteNumber, float velocity,
SynthesiserSound* /*sound*/,
int /*currentPitchWheelPosition*/) override
{
currentAngle = 0.0;
level = velocity * 0.15;
tailOff = 0.0;
double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
double cyclesPerSample = cyclesPerSecond / getSampleRate();
angleDelta = cyclesPerSample * 2.0 * MathConstants<double>::pi;
}
void stopNote (float /*velocity*/, bool allowTailOff) override
{
if (allowTailOff)
{
// start a tail-off by setting this flag. The render callback will pick up on
// this and do a fade out, calling clearCurrentNote() when it's finished.
if (tailOff == 0.0) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
tailOff = 1.0;
}
else
{
// we're being told to stop playing immediately, so reset everything..
clearCurrentNote();
angleDelta = 0.0;
}
}
void pitchWheelMoved (int /*newValue*/) override
{
// not implemented for the purposes of this demo!
}
void controllerMoved (int /*controllerNumber*/, int /*newValue*/) override
{
// not implemented for the purposes of this demo!
}
void renderNextBlock (AudioBuffer<float>& outputBuffer, int startSample, int numSamples) override
{
if (angleDelta != 0.0)
{
if (tailOff > 0)
{
while (--numSamples >= 0)
{
const float currentSample = (float) (sin (currentAngle) * level * tailOff);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
currentAngle += angleDelta;
++startSample;
tailOff *= 0.99;
if (tailOff <= 0.005)
{
// tells the synth that this voice has stopped
clearCurrentNote();
angleDelta = 0.0;
break;
}
}
}
else
{
while (--numSamples >= 0)
{
const float currentSample = (float) (sin (currentAngle) * level);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
currentAngle += angleDelta;
++startSample;
}
}
}
}
using SynthesiserVoice::renderNextBlock;
private:
double currentAngle = 0, angleDelta = 0, level = 0, tailOff = 0;
};
//==============================================================================
Synthesiser synth;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SineWaveSynth)
};
//==============================================================================
class ReverbPlugin : public AudioProcessor
{
public:
ReverbPlugin()
: AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo())
.withOutput ("Output", AudioChannelSet::stereo()))
{}
static String getIdentifier()
{
return "Reverb";
}
void prepareToPlay (double newSampleRate, int) override
{
reverb.setSampleRate (newSampleRate);
}
void reset() override
{
reverb.reset();
}
void releaseResources() override {}
void processBlock (AudioBuffer<float>& buffer, MidiBuffer&) override
{
auto numChannels = buffer.getNumChannels();
if (numChannels == 1)
reverb.processMono (buffer.getWritePointer (0), buffer.getNumSamples());
else
reverb.processStereo (buffer.getWritePointer (0),
buffer.getWritePointer (1),
buffer.getNumSamples());
for (int ch = 2; ch < numChannels; ++ch)
buffer.clear (ch, 0, buffer.getNumSamples());
}
using AudioProcessor::processBlock;
const String getName() const override { return getIdentifier(); }
double getTailLengthSeconds() const override { return 0.0; }
bool acceptsMidi() const override { return false; }
bool producesMidi() const override { return false; }
AudioProcessorEditor* createEditor() override { return nullptr; }
bool hasEditor() const override { return false; }
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram (int) override {}
const String getProgramName (int) override { return {}; }
void changeProgramName (int, const String&) override {}
void getStateInformation (juce::MemoryBlock&) override {}
void setStateInformation (const void*, int) override {}
private:
Reverb reverb;
};
//==============================================================================
InternalPluginFormat::InternalPluginFactory::InternalPluginFactory (const std::initializer_list<Constructor>& constructorsIn)
: constructors (constructorsIn),
descriptions ([&]
{
std::vector<PluginDescription> result;
for (const auto& constructor : constructors)
result.push_back (constructor()->getPluginDescription());
return result;
}())
{}
std::unique_ptr<AudioPluginInstance> InternalPluginFormat::InternalPluginFactory::createInstance (const String& name) const
{
const auto begin = descriptions.begin();
const auto it = std::find_if (begin,
descriptions.end(),
[&] (const PluginDescription& desc) { return name.equalsIgnoreCase (desc.name); });
if (it == descriptions.end())
return nullptr;
const auto index = (size_t) std::distance (begin, it);
return constructors[index]();
}
InternalPluginFormat::InternalPluginFormat()
: factory {
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::midiInputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::midiOutputNode); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SineWaveSynth>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<ReverbPlugin>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<AUv3SynthProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<Arpeggiator>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<DspModulePluginDemoAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<GainProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<JuceDemoPluginAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<MidiLoggerPluginDemoProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<MultiOutSynth>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<NoiseGate>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SamplerAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SurroundProcessor>()); }
}
{
}
std::unique_ptr<AudioPluginInstance> InternalPluginFormat::createInstance (const String& name)
{
return factory.createInstance (name);
}
void InternalPluginFormat::createPluginInstance (const PluginDescription& desc,
double /*initialSampleRate*/, int /*initialBufferSize*/,
PluginCreationCallback callback)
{
if (auto p = createInstance (desc.name))
callback (std::move (p), {});
else
callback (nullptr, NEEDS_TRANS ("Invalid internal plugin name"));
}
bool InternalPluginFormat::requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const
{
return false;
}
const std::vector<PluginDescription>& InternalPluginFormat::getAllTypes() const
{
return factory.getDescriptions();
}
/*
==============================================================================
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.
==============================================================================
*/
#include <JuceHeader.h>
#include <juce_audio_plugin_client/juce_audio_plugin_client.h>
#include "InternalPlugins.h"
#include "PluginGraph.h"
#define PIP_DEMO_UTILITIES_INCLUDED 1
// An alternative version of createAssetInputStream from the demo utilities header
// that fetches resources from embedded binary data instead of files
static std::unique_ptr<InputStream> createAssetInputStream (const char* resourcePath)
{
for (int i = 0; i < BinaryData::namedResourceListSize; ++i)
{
if (String (BinaryData::originalFilenames[i]) == String (resourcePath))
{
int dataSizeInBytes;
auto* resource = BinaryData::getNamedResource (BinaryData::namedResourceList[i], dataSizeInBytes);
return std::make_unique<MemoryInputStream> (resource, dataSizeInBytes, false);
}
}
return {};
}
#include "../../../../examples/Plugins/AUv3SynthPluginDemo.h"
#include "../../../../examples/Plugins/ArpeggiatorPluginDemo.h"
#include "../../../../examples/Plugins/AudioPluginDemo.h"
#include "../../../../examples/Plugins/DSPModulePluginDemo.h"
#include "../../../../examples/Plugins/GainPluginDemo.h"
#include "../../../../examples/Plugins/MidiLoggerPluginDemo.h"
#include "../../../../examples/Plugins/MultiOutSynthPluginDemo.h"
#include "../../../../examples/Plugins/NoiseGatePluginDemo.h"
#include "../../../../examples/Plugins/SamplerPluginDemo.h"
#include "../../../../examples/Plugins/SurroundPluginDemo.h"
//==============================================================================
class InternalPlugin : public AudioPluginInstance
{
public:
explicit InternalPlugin (std::unique_ptr<AudioProcessor> innerIn)
: inner (std::move (innerIn))
{
jassert (inner != nullptr);
for (auto isInput : { true, false })
matchChannels (isInput);
setBusesLayout (inner->getBusesLayout());
}
//==============================================================================
const String getName() const override { return inner->getName(); }
StringArray getAlternateDisplayNames() const override { return inner->getAlternateDisplayNames(); }
double getTailLengthSeconds() const override { return inner->getTailLengthSeconds(); }
bool acceptsMidi() const override { return inner->acceptsMidi(); }
bool producesMidi() const override { return inner->producesMidi(); }
AudioProcessorEditor* createEditor() override { return inner->createEditor(); }
bool hasEditor() const override { return inner->hasEditor(); }
int getNumPrograms() override { return inner->getNumPrograms(); }
int getCurrentProgram() override { return inner->getCurrentProgram(); }
void setCurrentProgram (int i) override { inner->setCurrentProgram (i); }
const String getProgramName (int i) override { return inner->getProgramName (i); }
void changeProgramName (int i, const String& n) override { inner->changeProgramName (i, n); }
void getStateInformation (juce::MemoryBlock& b) override { inner->getStateInformation (b); }
void setStateInformation (const void* d, int s) override { inner->setStateInformation (d, s); }
void getCurrentProgramStateInformation (juce::MemoryBlock& b) override { inner->getCurrentProgramStateInformation (b); }
void setCurrentProgramStateInformation (const void* d, int s) override { inner->setCurrentProgramStateInformation (d, s); }
void prepareToPlay (double sr, int bs) override { inner->setRateAndBufferSizeDetails (sr, bs); inner->prepareToPlay (sr, bs); }
void releaseResources() override { inner->releaseResources(); }
void memoryWarningReceived() override { inner->memoryWarningReceived(); }
void processBlock (AudioBuffer<float>& a, MidiBuffer& m) override { inner->processBlock (a, m); }
void processBlock (AudioBuffer<double>& a, MidiBuffer& m) override { inner->processBlock (a, m); }
void processBlockBypassed (AudioBuffer<float>& a, MidiBuffer& m) override { inner->processBlockBypassed (a, m); }
void processBlockBypassed (AudioBuffer<double>& a, MidiBuffer& m) override { inner->processBlockBypassed (a, m); }
bool supportsDoublePrecisionProcessing() const override { return inner->supportsDoublePrecisionProcessing(); }
bool supportsMPE() const override { return inner->supportsMPE(); }
bool isMidiEffect() const override { return inner->isMidiEffect(); }
void reset() override { inner->reset(); }
void setNonRealtime (bool b) noexcept override { inner->setNonRealtime (b); }
void refreshParameterList() override { inner->refreshParameterList(); }
void numChannelsChanged() override { inner->numChannelsChanged(); }
void numBusesChanged() override { inner->numBusesChanged(); }
void processorLayoutsChanged() override { inner->processorLayoutsChanged(); }
void setPlayHead (AudioPlayHead* p) override { inner->setPlayHead (p); }
void updateTrackProperties (const TrackProperties& p) override { inner->updateTrackProperties (p); }
bool isBusesLayoutSupported (const BusesLayout& layout) const override { return inner->checkBusesLayoutSupported (layout); }
bool applyBusLayouts (const BusesLayout& layouts) override { return inner->setBusesLayout (layouts) && AudioPluginInstance::applyBusLayouts (layouts); }
bool canAddBus (bool) const override { return true; }
bool canRemoveBus (bool) const override { return true; }
//==============================================================================
void fillInPluginDescription (PluginDescription& description) const override
{
description = getPluginDescription (*inner);
}
private:
static PluginDescription getPluginDescription (const AudioProcessor& proc)
{
const auto ins = proc.getTotalNumInputChannels();
const auto outs = proc.getTotalNumOutputChannels();
const auto identifier = proc.getName();
const auto registerAsGenerator = ins == 0;
const auto acceptsMidi = proc.acceptsMidi();
PluginDescription descr;
descr.name = identifier;
descr.descriptiveName = identifier;
descr.pluginFormatName = InternalPluginFormat::getIdentifier();
descr.category = (registerAsGenerator ? (acceptsMidi ? "Synth" : "Generator") : "Effect");
descr.manufacturerName = "JUCE";
descr.version = ProjectInfo::versionString;
descr.fileOrIdentifier = identifier;
descr.isInstrument = (acceptsMidi && registerAsGenerator);
descr.numInputChannels = ins;
descr.numOutputChannels = outs;
descr.uniqueId = descr.deprecatedUid = identifier.hashCode();
return descr;
}
void matchChannels (bool isInput)
{
const auto inBuses = inner->getBusCount (isInput);
while (getBusCount (isInput) < inBuses)
addBus (isInput);
while (inBuses < getBusCount (isInput))
removeBus (isInput);
}
std::unique_ptr<AudioProcessor> inner;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalPlugin)
};
//==============================================================================
class SineWaveSynth : public AudioProcessor
{
public:
SineWaveSynth()
: AudioProcessor (BusesProperties().withOutput ("Output", AudioChannelSet::stereo()))
{
const int numVoices = 8;
// Add some voices...
for (int i = numVoices; --i >= 0;)
synth.addVoice (new SineWaveVoice());
// ..and give the synth a sound to play
synth.addSound (new SineWaveSound());
}
static String getIdentifier()
{
return "Sine Wave Synth";
}
//==============================================================================
void prepareToPlay (double newSampleRate, int) override
{
synth.setCurrentPlaybackSampleRate (newSampleRate);
}
void releaseResources() override {}
//==============================================================================
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override
{
const int numSamples = buffer.getNumSamples();
buffer.clear();
synth.renderNextBlock (buffer, midiMessages, 0, numSamples);
buffer.applyGain (0.8f);
}
using AudioProcessor::processBlock;
const String getName() const override { return getIdentifier(); }
double getTailLengthSeconds() const override { return 0.0; }
bool acceptsMidi() const override { return true; }
bool producesMidi() const override { return true; }
AudioProcessorEditor* createEditor() override { return nullptr; }
bool hasEditor() const override { return false; }
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram (int) override {}
const String getProgramName (int) override { return {}; }
void changeProgramName (int, const String&) override {}
void getStateInformation (juce::MemoryBlock&) override {}
void setStateInformation (const void*, int) override {}
private:
//==============================================================================
struct SineWaveSound : public SynthesiserSound
{
SineWaveSound() = default;
bool appliesToNote (int /*midiNoteNumber*/) override { return true; }
bool appliesToChannel (int /*midiChannel*/) override { return true; }
};
struct SineWaveVoice : public SynthesiserVoice
{
SineWaveVoice() = default;
bool canPlaySound (SynthesiserSound* sound) override
{
return dynamic_cast<SineWaveSound*> (sound) != nullptr;
}
void startNote (int midiNoteNumber, float velocity,
SynthesiserSound* /*sound*/,
int /*currentPitchWheelPosition*/) override
{
currentAngle = 0.0;
level = velocity * 0.15;
tailOff = 0.0;
double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
double cyclesPerSample = cyclesPerSecond / getSampleRate();
angleDelta = cyclesPerSample * 2.0 * MathConstants<double>::pi;
}
void stopNote (float /*velocity*/, bool allowTailOff) override
{
if (allowTailOff)
{
// start a tail-off by setting this flag. The render callback will pick up on
// this and do a fade out, calling clearCurrentNote() when it's finished.
if (tailOff == 0.0) // we only need to begin a tail-off if it's not already doing so - the
// stopNote method could be called more than once.
tailOff = 1.0;
}
else
{
// we're being told to stop playing immediately, so reset everything..
clearCurrentNote();
angleDelta = 0.0;
}
}
void pitchWheelMoved (int /*newValue*/) override
{
// not implemented for the purposes of this demo!
}
void controllerMoved (int /*controllerNumber*/, int /*newValue*/) override
{
// not implemented for the purposes of this demo!
}
void renderNextBlock (AudioBuffer<float>& outputBuffer, int startSample, int numSamples) override
{
if (angleDelta != 0.0)
{
if (tailOff > 0)
{
while (--numSamples >= 0)
{
const float currentSample = (float) (sin (currentAngle) * level * tailOff);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
currentAngle += angleDelta;
++startSample;
tailOff *= 0.99;
if (tailOff <= 0.005)
{
// tells the synth that this voice has stopped
clearCurrentNote();
angleDelta = 0.0;
break;
}
}
}
else
{
while (--numSamples >= 0)
{
const float currentSample = (float) (sin (currentAngle) * level);
for (int i = outputBuffer.getNumChannels(); --i >= 0;)
outputBuffer.addSample (i, startSample, currentSample);
currentAngle += angleDelta;
++startSample;
}
}
}
}
using SynthesiserVoice::renderNextBlock;
private:
double currentAngle = 0, angleDelta = 0, level = 0, tailOff = 0;
};
//==============================================================================
Synthesiser synth;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SineWaveSynth)
};
//==============================================================================
class ReverbPlugin : public AudioProcessor
{
public:
ReverbPlugin()
: AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo())
.withOutput ("Output", AudioChannelSet::stereo()))
{}
static String getIdentifier()
{
return "Reverb";
}
void prepareToPlay (double newSampleRate, int) override
{
reverb.setSampleRate (newSampleRate);
}
void reset() override
{
reverb.reset();
}
void releaseResources() override {}
void processBlock (AudioBuffer<float>& buffer, MidiBuffer&) override
{
auto numChannels = buffer.getNumChannels();
if (numChannels == 1)
reverb.processMono (buffer.getWritePointer (0), buffer.getNumSamples());
else
reverb.processStereo (buffer.getWritePointer (0),
buffer.getWritePointer (1),
buffer.getNumSamples());
for (int ch = 2; ch < numChannels; ++ch)
buffer.clear (ch, 0, buffer.getNumSamples());
}
using AudioProcessor::processBlock;
const String getName() const override { return getIdentifier(); }
double getTailLengthSeconds() const override { return 0.0; }
bool acceptsMidi() const override { return false; }
bool producesMidi() const override { return false; }
AudioProcessorEditor* createEditor() override { return nullptr; }
bool hasEditor() const override { return false; }
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram (int) override {}
const String getProgramName (int) override { return {}; }
void changeProgramName (int, const String&) override {}
void getStateInformation (juce::MemoryBlock&) override {}
void setStateInformation (const void*, int) override {}
private:
Reverb reverb;
};
//==============================================================================
InternalPluginFormat::InternalPluginFactory::InternalPluginFactory (const std::initializer_list<Constructor>& constructorsIn)
: constructors (constructorsIn),
descriptions ([&]
{
std::vector<PluginDescription> result;
for (const auto& constructor : constructors)
result.push_back (constructor()->getPluginDescription());
return result;
}())
{}
std::unique_ptr<AudioPluginInstance> InternalPluginFormat::InternalPluginFactory::createInstance (const String& name) const
{
const auto begin = descriptions.begin();
const auto it = std::find_if (begin,
descriptions.end(),
[&] (const PluginDescription& desc) { return name.equalsIgnoreCase (desc.name); });
if (it == descriptions.end())
return nullptr;
const auto index = (size_t) std::distance (begin, it);
return constructors[index]();
}
InternalPluginFormat::InternalPluginFormat()
: factory {
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::audioInputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::midiInputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::audioOutputNode); },
[] { return std::make_unique<AudioProcessorGraph::AudioGraphIOProcessor> (AudioProcessorGraph::AudioGraphIOProcessor::midiOutputNode); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SineWaveSynth>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<ReverbPlugin>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<AUv3SynthProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<Arpeggiator>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<DspModulePluginDemoAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<GainProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<JuceDemoPluginAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<MidiLoggerPluginDemoProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<MultiOutSynth>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<NoiseGate>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SamplerAudioProcessor>()); },
[] { return std::make_unique<InternalPlugin> (std::make_unique<SurroundProcessor>()); }
}
{
}
std::unique_ptr<AudioPluginInstance> InternalPluginFormat::createInstance (const String& name)
{
return factory.createInstance (name);
}
void InternalPluginFormat::createPluginInstance (const PluginDescription& desc,
double /*initialSampleRate*/, int /*initialBufferSize*/,
PluginCreationCallback callback)
{
if (auto p = createInstance (desc.name))
callback (std::move (p), {});
else
callback (nullptr, NEEDS_TRANS ("Invalid internal plugin name"));
}
bool InternalPluginFormat::requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const
{
return false;
}
const std::vector<PluginDescription>& InternalPluginFormat::getAllTypes() const
{
return factory.getDescriptions();
}

View File

@ -1,84 +1,84 @@
/*
==============================================================================
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 "PluginGraph.h"
//==============================================================================
/**
Manages the internal plugin types.
*/
class InternalPluginFormat : public AudioPluginFormat
{
public:
//==============================================================================
InternalPluginFormat();
//==============================================================================
const std::vector<PluginDescription>& getAllTypes() const;
//==============================================================================
static String getIdentifier() { return "Internal"; }
String getName() const override { return getIdentifier(); }
bool fileMightContainThisPluginType (const String&) override { return true; }
FileSearchPath getDefaultLocationsToSearch() override { return {}; }
bool canScanForPlugins() const override { return false; }
bool isTrivialToScan() const override { return true; }
void findAllTypesForFile (OwnedArray<PluginDescription>&, const String&) override {}
bool doesPluginStillExist (const PluginDescription&) override { return true; }
String getNameOfPluginFromIdentifier (const String& fileOrIdentifier) override { return fileOrIdentifier; }
bool pluginNeedsRescanning (const PluginDescription&) override { return false; }
StringArray searchPathsForPlugins (const FileSearchPath&, bool, bool) override { return {}; }
private:
class InternalPluginFactory
{
public:
using Constructor = std::function<std::unique_ptr<AudioPluginInstance>()>;
explicit InternalPluginFactory (const std::initializer_list<Constructor>& constructorsIn);
const std::vector<PluginDescription>& getDescriptions() const { return descriptions; }
std::unique_ptr<AudioPluginInstance> createInstance (const String& name) const;
private:
const std::vector<Constructor> constructors;
const std::vector<PluginDescription> descriptions;
};
//==============================================================================
void createPluginInstance (const PluginDescription&,
double initialSampleRate, int initialBufferSize,
PluginCreationCallback) override;
std::unique_ptr<AudioPluginInstance> createInstance (const String& name);
bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const override;
InternalPluginFactory factory;
};
/*
==============================================================================
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 "PluginGraph.h"
//==============================================================================
/**
Manages the internal plugin types.
*/
class InternalPluginFormat : public AudioPluginFormat
{
public:
//==============================================================================
InternalPluginFormat();
//==============================================================================
const std::vector<PluginDescription>& getAllTypes() const;
//==============================================================================
static String getIdentifier() { return "Internal"; }
String getName() const override { return getIdentifier(); }
bool fileMightContainThisPluginType (const String&) override { return true; }
FileSearchPath getDefaultLocationsToSearch() override { return {}; }
bool canScanForPlugins() const override { return false; }
bool isTrivialToScan() const override { return true; }
void findAllTypesForFile (OwnedArray<PluginDescription>&, const String&) override {}
bool doesPluginStillExist (const PluginDescription&) override { return true; }
String getNameOfPluginFromIdentifier (const String& fileOrIdentifier) override { return fileOrIdentifier; }
bool pluginNeedsRescanning (const PluginDescription&) override { return false; }
StringArray searchPathsForPlugins (const FileSearchPath&, bool, bool) override { return {}; }
private:
class InternalPluginFactory
{
public:
using Constructor = std::function<std::unique_ptr<AudioPluginInstance>()>;
explicit InternalPluginFactory (const std::initializer_list<Constructor>& constructorsIn);
const std::vector<PluginDescription>& getDescriptions() const { return descriptions; }
std::unique_ptr<AudioPluginInstance> createInstance (const String& name) const;
private:
const std::vector<Constructor> constructors;
const std::vector<PluginDescription> descriptions;
};
//==============================================================================
void createPluginInstance (const PluginDescription&,
double initialSampleRate, int initialBufferSize,
PluginCreationCallback) override;
std::unique_ptr<AudioPluginInstance> createInstance (const String& name);
bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const override;
InternalPluginFactory factory;
};

File diff suppressed because it is too large Load Diff

View File

@ -1,99 +1,125 @@
/*
==============================================================================
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 "../UI/PluginWindow.h"
//==============================================================================
/**
A collection of plugins and some connections between them.
*/
class PluginGraph : public FileBasedDocument,
public AudioProcessorListener,
private ChangeListener
{
public:
//==============================================================================
PluginGraph (AudioPluginFormatManager&, KnownPluginList&);
~PluginGraph() override;
//==============================================================================
using NodeID = AudioProcessorGraph::NodeID;
void addPlugin (const PluginDescription&, Point<double>);
AudioProcessorGraph::Node::Ptr getNodeForName (const String& name) const;
void setNodePosition (NodeID, Point<double>);
Point<double> getNodePosition (NodeID) const;
//==============================================================================
void clear();
PluginWindow* getOrCreateWindowFor (AudioProcessorGraph::Node*, PluginWindow::Type);
void closeCurrentlyOpenWindowsFor (AudioProcessorGraph::NodeID);
bool closeAnyOpenPluginWindows();
//==============================================================================
void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override { changed(); }
//==============================================================================
std::unique_ptr<XmlElement> createXml() const;
void restoreFromXml (const XmlElement&);
static const char* getFilenameSuffix() { return ".filtergraph"; }
static const char* getFilenameWildcard() { return "*.filtergraph"; }
//==============================================================================
void newDocument();
String getDocumentTitle() override;
Result loadDocument (const File& file) override;
Result saveDocument (const File& file) override;
File getLastDocumentOpened() override;
void setLastDocumentOpened (const File& file) override;
static File getDefaultGraphDocumentOnMobile();
//==============================================================================
AudioProcessorGraph graph;
private:
//==============================================================================
AudioPluginFormatManager& formatManager;
KnownPluginList& knownPlugins;
OwnedArray<PluginWindow> activePluginWindows;
NodeID lastUID;
NodeID getNextUID() noexcept;
void createNodeFromXml (const XmlElement&);
void addPluginCallback (std::unique_ptr<AudioPluginInstance>, const String& error, Point<double>);
void changeListenerCallback (ChangeBroadcaster*) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginGraph)
};
/*
==============================================================================
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 "../UI/PluginWindow.h"
//==============================================================================
/** A type that encapsulates a PluginDescription and some preferences regarding
how plugins of that description should be instantiated.
*/
struct PluginDescriptionAndPreference
{
enum class UseARA { no, yes };
PluginDescriptionAndPreference() = default;
explicit PluginDescriptionAndPreference (PluginDescription pd)
: pluginDescription (std::move (pd)),
useARA (pluginDescription.hasARAExtension ? PluginDescriptionAndPreference::UseARA::yes
: PluginDescriptionAndPreference::UseARA::no)
{}
PluginDescriptionAndPreference (PluginDescription pd, UseARA ara)
: pluginDescription (std::move (pd)), useARA (ara)
{}
PluginDescription pluginDescription;
UseARA useARA = UseARA::no;
};
//==============================================================================
/**
A collection of plugins and some connections between them.
*/
class PluginGraph : public FileBasedDocument,
public AudioProcessorListener,
private ChangeListener
{
public:
//==============================================================================
PluginGraph (AudioPluginFormatManager&, KnownPluginList&);
~PluginGraph() override;
//==============================================================================
using NodeID = AudioProcessorGraph::NodeID;
void addPlugin (const PluginDescriptionAndPreference&, Point<double>);
AudioProcessorGraph::Node::Ptr getNodeForName (const String& name) const;
void setNodePosition (NodeID, Point<double>);
Point<double> getNodePosition (NodeID) const;
//==============================================================================
void clear();
PluginWindow* getOrCreateWindowFor (AudioProcessorGraph::Node*, PluginWindow::Type);
void closeCurrentlyOpenWindowsFor (AudioProcessorGraph::NodeID);
bool closeAnyOpenPluginWindows();
//==============================================================================
void audioProcessorParameterChanged (AudioProcessor*, int, float) override {}
void audioProcessorChanged (AudioProcessor*, const ChangeDetails&) override { changed(); }
//==============================================================================
std::unique_ptr<XmlElement> createXml() const;
void restoreFromXml (const XmlElement&);
static const char* getFilenameSuffix() { return ".filtergraph"; }
static const char* getFilenameWildcard() { return "*.filtergraph"; }
//==============================================================================
void newDocument();
String getDocumentTitle() override;
Result loadDocument (const File& file) override;
Result saveDocument (const File& file) override;
File getLastDocumentOpened() override;
void setLastDocumentOpened (const File& file) override;
static File getDefaultGraphDocumentOnMobile();
//==============================================================================
AudioProcessorGraph graph;
private:
//==============================================================================
AudioPluginFormatManager& formatManager;
KnownPluginList& knownPlugins;
OwnedArray<PluginWindow> activePluginWindows;
NodeID lastUID;
NodeID getNextUID() noexcept;
void createNodeFromXml (const XmlElement&);
void addPluginCallback (std::unique_ptr<AudioPluginInstance>,
const String& error,
Point<double>,
PluginDescriptionAndPreference::UseARA useARA);
void changeListenerCallback (ChangeBroadcaster*) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginGraph)
};

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)
};