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

@ -0,0 +1,71 @@
if(CLAP_WRAP_PROJUCER_PLUGIN)
set(PATH_TO_JUCE "${JUCE_SOURCE_DIR}")
set(PATH_TO_CLAP_EXTENSIONS ${CMAKE_CURRENT_SOURCE_DIR}/../..)
if(APPLE)
set(JUCER_GENERATOR "Xcode")
elseif(WIN32)
set(JUCER_GENERATOR "VisualStudio2019")
else() # Linux
set(JUCER_GENERATOR "LinuxMakefile")
endif()
include(${PATH_TO_CLAP_EXTENSIONS}/cmake/JucerClap.cmake)
create_jucer_clap_target(
TARGET "GainPlugin"
PLUGIN_NAME "GainPlugin"
BINARY_NAME "MyGreatGainPlugin"
PLUGIN_CODE "Gplg"
MANUFACTURER_NAME "${COMPANY_NAME}"
MANUFACTURER_CODE "${COMPANY_CODE}"
VERSION_STRING "${CMAKE_PROJECT_VERSION}"
CLAP_ID "org.free-audio.GainPlugin"
CLAP_FEATURES audio-effect utility
CLAP_PROCESS_EVENTS_RESOLUTION_SAMPLES 64
)
return()
endif()
juce_add_plugin(GainPlugin
COMPANY_NAME "${COMPANY_NAME}"
PLUGIN_MANUFACTURER_CODE "${COMPANY_CODE}"
PLUGIN_CODE Gplg
FORMATS ${JUCE_FORMATS}
PRODUCT_NAME "GainPlugin"
)
clap_juce_extensions_plugin(
TARGET GainPlugin
CLAP_ID "org.free-audio.GainPlugin"
CLAP_FEATURES audio-effect utility
CLAP_PROCESS_EVENTS_RESOLUTION_SAMPLES 64
)
target_sources(GainPlugin PRIVATE
GainPlugin.cpp
PluginEditor.cpp
)
target_compile_definitions(GainPlugin PUBLIC
JUCE_DISPLAY_SPLASH_SCREEN=1
JUCE_REPORT_APP_USAGE=0
JUCE_WEB_BROWSER=0
JUCE_USE_CURL=0
JUCE_JACK=1
JUCE_ALSA=1
JUCE_MODAL_LOOPS_PERMITTED=1 # required for Linux FileChooser with JUCE 6.0.7
JUCE_VST3_CAN_REPLACE_VST2=0
)
target_link_libraries(GainPlugin
PRIVATE
juce::juce_audio_utils
juce::juce_audio_plugin_client
juce::juce_dsp
clap_juce_extensions
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)

View File

@ -0,0 +1,89 @@
#include "GainPlugin.h"
#include "PluginEditor.h"
namespace
{
static const juce::String gainParamTag = "gain_db";
}
GainPlugin::GainPlugin()
: juce::AudioProcessor(BusesProperties()
.withInput("Input", juce::AudioChannelSet::stereo(), true)
.withOutput("Output", juce::AudioChannelSet::stereo(), true)),
vts(*this, nullptr, juce::Identifier("Parameters"), createParameters())
{
gainDBParameter = dynamic_cast<ModulatableFloatParameter *>(vts.getParameter(gainParamTag));
}
juce::AudioProcessorValueTreeState::ParameterLayout GainPlugin::createParameters()
{
std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
params.push_back(std::make_unique<ModulatableFloatParameter>(
gainParamTag, "Gain", juce::NormalisableRange<float>{-30.0f, 30.0f}, 0.0f,
[](float val) {
juce::String gainStr = juce::String(val, 2, false);
return gainStr + " dB";
},
[](const juce::String &s) { return s.getFloatValue(); }));
return {params.begin(), params.end()};
}
bool GainPlugin::isBusesLayoutSupported(const juce::AudioProcessor::BusesLayout &layouts) const
{
// only supports mono and stereo
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono() &&
layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
return false;
// input and output layout must be the same
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
return true;
}
void GainPlugin::prepareToPlay(double sampleRate, int samplesPerBlock)
{
gain.prepare(
{sampleRate, (juce::uint32)samplesPerBlock, (juce::uint32)getMainBusNumOutputChannels()});
gain.setRampDurationSeconds(0.05);
}
void GainPlugin::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiBuffer &)
{
auto &&block = juce::dsp::AudioBlock<float>{buffer};
gain.setGainDecibels(gainDBParameter->getCurrentValue());
gain.process(juce::dsp::ProcessContextReplacing<float>{block});
}
juce::AudioProcessorEditor *GainPlugin::createEditor() { return new PluginEditor(*this); }
juce::String GainPlugin::getPluginTypeString() const
{
if (wrapperType == juce::AudioProcessor::wrapperType_Undefined && is_clap)
return "CLAP";
return juce::AudioProcessor::getWrapperTypeDescription(wrapperType);
}
void GainPlugin::getStateInformation(juce::MemoryBlock &data)
{
auto state = vts.copyState();
std::unique_ptr<juce::XmlElement> xml(state.createXml());
copyXmlToBinary(*xml, data);
}
void GainPlugin::setStateInformation(const void *data, int sizeInBytes)
{
std::unique_ptr<juce::XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
if (xmlState != nullptr)
if (xmlState->hasTagName(vts.state.getType()))
vts.replaceState(juce::ValueTree::fromXml(*xmlState));
}
// This creates new instances of the plugin
juce::AudioProcessor *JUCE_CALLTYPE createPluginFilter() { return new GainPlugin(); }

View File

@ -0,0 +1,53 @@
#pragma once
#include <juce_dsp/juce_dsp.h>
#include "ModulatableFloatParameter.h"
class ModulatableFloatParameter;
class GainPlugin : public juce::AudioProcessor,
public clap_juce_extensions::clap_juce_audio_processor_capabilities,
protected clap_juce_extensions::clap_properties
{
public:
GainPlugin();
static juce::AudioProcessorValueTreeState::ParameterLayout createParameters();
const juce::String getName() const override { return JucePlugin_Name; }
bool acceptsMidi() const override { return false; }
bool producesMidi() const override { return false; }
bool isMidiEffect() const override { return false; }
double getTailLengthSeconds() const override { return 0.0; }
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram(int) override {}
const juce::String getProgramName(int) override { return juce::String(); }
void changeProgramName(int, const juce::String &) override {}
bool isBusesLayoutSupported(const juce::AudioProcessor::BusesLayout &layouts) const override;
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
void releaseResources() override {}
void processBlock(juce::AudioBuffer<float> &, juce::MidiBuffer &) override;
void processBlock(juce::AudioBuffer<double> &, juce::MidiBuffer &) override {}
bool hasEditor() const override { return true; }
juce::AudioProcessorEditor *createEditor() override;
void getStateInformation(juce::MemoryBlock &data) override;
void setStateInformation(const void *data, int sizeInBytes) override;
juce::String getPluginTypeString() const;
auto *getGainParameter() { return gainDBParameter; }
auto &getValueTreeState() { return vts; }
private:
ModulatableFloatParameter *gainDBParameter = nullptr;
juce::AudioProcessorValueTreeState vts;
juce::dsp::Gain<float> gain;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GainPlugin)
};

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<JUCERPROJECT id="luqvtz" name="GainPlugin" projectType="audioplug" useAppConfig="0"
jucerFormatVersion="1" headerPath="../../../../include&#10;../../../../clap-libs/clap/include&#10;../../../../clap-libs/clap-helpers/include"
cppLanguageStandard="17" defines="HAS_CLAP_JUCE_EXTENSIONS=1"
addUsingNamespaceToJuceHeader="0">
<MAINGROUP id="YenzOu" name="GainPlugin">
<GROUP id="{38320511-2ECE-0246-11DC-4FBB99C5617C}" name="CLAP">
<FILE id="i719ku" name="clap-juce-extensions.cpp" compile="1" resource="0"
file="../../src/extensions/clap-juce-extensions.cpp"/>
</GROUP>
<GROUP id="{422CF038-C3ED-FE29-2115-57EAEE923726}" name="Source">
<FILE id="sfdoog" name="GainPlugin.cpp" compile="1" resource="0" file="GainPlugin.cpp"/>
<FILE id="CwQ2Yq" name="GainPlugin.h" compile="0" resource="0" file="GainPlugin.h"/>
<FILE id="fADOqj" name="ModulatableFloatParameter.h" compile="0" resource="0"
file="ModulatableFloatParameter.h"/>
<FILE id="R7b3jn" name="PluginEditor.cpp" compile="1" resource="0"
file="PluginEditor.cpp"/>
<FILE id="ehXQhT" name="PluginEditor.h" compile="0" resource="0" file="PluginEditor.h"/>
</GROUP>
</MAINGROUP>
<JUCEOPTIONS JUCE_STRICT_REFCOUNTEDPOINTER="1" JUCE_VST3_CAN_REPLACE_VST2="0"
FOLEYS_SHOW_GUI_EDITOR_PALLETTE="0" FOLEYS_ENABLE_BINARY_DATA="1"
JUCE_USE_CURL="0" JUCE_WEB_BROWSER="0"/>
<EXPORTFORMATS>
<LINUX_MAKE targetFolder="Builds/LinuxMakefile">
<CONFIGURATIONS>
<CONFIGURATION isDebug="1" name="Debug" targetName="GainPlugin"/>
<CONFIGURATION isDebug="0" name="Release" targetName="GainPlugin"/>
</CONFIGURATIONS>
<MODULEPATHS>
<MODULEPATH id="juce_core" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_devices" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_events" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_formats" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_utils" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_processors" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_extra" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_graphics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_data_structures" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_dsp" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_plugin_client" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="chowdsp_plugin_base"/>
</MODULEPATHS>
</LINUX_MAKE>
<VS2019 targetFolder="Builds/VisualStudio2019">
<CONFIGURATIONS>
<CONFIGURATION isDebug="1" name="Debug" targetName="GainPlugin"/>
<CONFIGURATION isDebug="0" name="Release" targetName="GainPlugin"/>
</CONFIGURATIONS>
<MODULEPATHS>
<MODULEPATH id="juce_core" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_devices" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_events" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_formats" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_utils" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_processors" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_extra" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_graphics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_data_structures" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_dsp" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_plugin_client" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="chowdsp_plugin_base"/>
</MODULEPATHS>
</VS2019>
<XCODE_MAC targetFolder="Builds/MacOSX">
<CONFIGURATIONS>
<CONFIGURATION isDebug="1" name="Debug" targetName="GainPlugin" enablePluginBinaryCopyStep="0"/>
<CONFIGURATION isDebug="0" name="Release" targetName="GainPlugin" enablePluginBinaryCopyStep="0"/>
</CONFIGURATIONS>
<MODULEPATHS>
<MODULEPATH id="juce_core" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_devices" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_events" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_formats" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_utils" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_processors" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_extra" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_gui_basics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_graphics" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_data_structures" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_dsp" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="juce_audio_plugin_client" path="../../build/_deps/juce-src/modules"/>
<MODULEPATH id="chowdsp_plugin_base"/>
</MODULEPATHS>
</XCODE_MAC>
</EXPORTFORMATS>
<MODULES>
<MODULE id="juce_audio_basics" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_audio_devices" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_audio_formats" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_audio_plugin_client" showAllCode="1" useLocalCopy="0"
useGlobalPath="0"/>
<MODULE id="juce_audio_processors" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_audio_utils" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_core" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_data_structures" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_dsp" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_events" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_graphics" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_gui_basics" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_gui_extra" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
</MODULES>
</JUCERPROJECT>

View File

@ -0,0 +1,61 @@
#pragma once
#include <juce_audio_utils/juce_audio_utils.h>
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE("-Wunused-parameter", "-Wextra-semi", "-Wnon-virtual-dtor")
#include <clap-juce-extensions/clap-juce-extensions.h>
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
class ModulatableFloatParameter : public juce::AudioParameterFloat,
public clap_juce_extensions::clap_juce_parameter_capabilities
{
public:
ModulatableFloatParameter(const juce::String &parameterID, const juce::String &parameterName,
const juce::NormalisableRange<float> &valueRange,
float defaultFloatValue,
const std::function<juce::String(float)> &valueToTextFunction,
std::function<float(const juce::String &)> &&textToValueFunction)
#if JUCE_VERSION < 0x070000
: juce::AudioParameterFloat(
parameterID, parameterName, valueRange, defaultFloatValue, juce::String(),
AudioProcessorParameter::genericParameter,
valueToTextFunction == nullptr
? std::function<juce::String(float v, int)>()
: [valueToTextFunction](float v, int) { return valueToTextFunction(v); },
std::move(textToValueFunction)),
#else
: juce::AudioParameterFloat(
parameterID, parameterName, valueRange, defaultFloatValue,
juce::AudioParameterFloatAttributes()
.withStringFromValueFunction(
[valueToTextFunction](float v, int) { return valueToTextFunction(v); })
.withValueFromStringFunction(std::move(textToValueFunction))),
#endif
unsnappedDefault(valueRange.convertTo0to1(defaultFloatValue)),
normalisableRange(valueRange)
{
}
float getDefaultValue() const override { return unsnappedDefault; }
bool supportsMonophonicModulation() override { return true; }
void applyMonophonicModulation(double modulationValue) override
{
modulationAmount = (float)modulationValue;
}
float getCurrentValue() const noexcept
{
return normalisableRange.convertFrom0to1(
juce::jlimit(0.0f, 1.0f, normalisableRange.convertTo0to1(get()) + modulationAmount));
}
private:
const float unsnappedDefault;
const juce::NormalisableRange<float> normalisableRange;
float modulationAmount = 0.0f;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModulatableFloatParameter)
};

View File

@ -0,0 +1,53 @@
#include "PluginEditor.h"
PluginEditor::PluginEditor(GainPlugin &plug) : juce::AudioProcessorEditor(plug), plugin(plug)
{
setSize(300, 300);
addAndMakeVisible(gainSlider);
gainSlider.setSliderStyle(juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag);
gainSlider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 100, 20);
auto *gainParameter = plugin.getGainParameter();
sliderAttachment =
std::make_unique<juce::SliderParameterAttachment>(*gainParameter, gainSlider, nullptr);
plugin.getValueTreeState().addParameterListener(gainParameter->paramID, this);
}
PluginEditor::~PluginEditor()
{
auto *gainParameter = plugin.getGainParameter();
plugin.getValueTreeState().removeParameterListener(gainParameter->paramID, this);
}
void PluginEditor::resized()
{
gainSlider.setBounds(juce::Rectangle<int>{200, 200}.withCentre(getLocalBounds().getCentre()));
}
void PluginEditor::paint(juce::Graphics &g)
{
g.fillAll(juce::Colours::grey);
g.setColour(juce::Colours::black);
g.setFont(25.0f);
const auto titleBounds = getLocalBounds().removeFromTop(30);
const auto titleText = "Gain Plugin " + plugin.getPluginTypeString();
g.drawFittedText(titleText, titleBounds, juce::Justification::centred, 1);
}
void PluginEditor::parameterChanged(const juce::String &, float)
{
// visual feedback so we know the parameter listeners are getting called:
struct FlashComponent : Component
{
void paint(juce::Graphics &g) override { g.fillAll(juce::Colours::red); }
} flashComp;
addAndMakeVisible(flashComp);
flashComp.setBounds(juce::Rectangle<int>{getWidth() - 10, 0, 10, 10});
auto &animator = juce::Desktop::getInstance().getAnimator();
animator.fadeOut(&flashComp, 100);
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "GainPlugin.h"
class PluginEditor : public juce::AudioProcessorEditor,
private juce::AudioProcessorValueTreeState::Listener
{
public:
explicit PluginEditor(GainPlugin &plugin);
~PluginEditor() override;
void resized() override;
void paint(juce::Graphics &g) override;
private:
void parameterChanged(const juce::String &parameterID, float newValue) override;
GainPlugin &plugin;
juce::Slider gainSlider;
std::unique_ptr<juce::SliderParameterAttachment> sliderAttachment;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginEditor)
};