From a6e09730670a6a5572faa340a7dee45428278e00 Mon Sep 17 00:00:00 2001 From: Daniel Walz Date: Wed, 27 Nov 2024 22:03:33 +0100 Subject: [PATCH] Fixed warnings new with juce 8 --- .../APVTS_Tutorial/Source/PluginProcessor.cpp | 38 +-- .../Source/PluginProcessor.cpp | 290 ++++++++---------- .../FoleysSynth/Source/PluginProcessor.cpp | 2 +- .../Source/PluginProcessor.cpp | 140 ++++----- .../General/foleys_MagicJUCEFactories.cpp | 2 +- .../Layout/foleys_Decorator.cpp | 4 +- .../Widgets/foleys_MagicLevelMeter.cpp | 6 +- .../Widgets/foleys_MagicLevelMeter.h | 8 +- 8 files changed, 220 insertions(+), 270 deletions(-) diff --git a/Examples/APVTS_Tutorial/Source/PluginProcessor.cpp b/Examples/APVTS_Tutorial/Source/PluginProcessor.cpp index e3c55e1d..1c7e86b6 100644 --- a/Examples/APVTS_Tutorial/Source/PluginProcessor.cpp +++ b/Examples/APVTS_Tutorial/Source/PluginProcessor.cpp @@ -11,22 +11,22 @@ #include "../JuceLibraryCode/JuceHeader.h" -class TutorialProcessor : public foleys::MagicProcessor +class TutorialProcessor : public foleys::MagicProcessor { public: //============================================================================== TutorialProcessor() - : parameters (*this, nullptr, juce::Identifier ("APVTSTutorial"), - { - std::make_unique ("gain", // parameterID - "Gain", // parameter name - 0.0f, // minimum value - 1.0f, // maximum value - 0.5f), // default value - std::make_unique ("invertPhase", // parameterID - "Invert Phase", // parameter name - false) // default value - }) + : parameters (*this, nullptr, juce::Identifier ("APVTSTutorial"), + { + std::make_unique (juce::ParameterID ("gain", 1), // parameterID + "Gain", // parameter name + 0.0f, // minimum value + 1.0f, // maximum value + 0.5f), // default value + std::make_unique (juce::ParameterID ("invertPhase", 1), // parameterID + "Invert Phase", // parameter name + false) // default value + }) { FOLEYS_SET_SOURCE_PATH (__FILE__); @@ -37,18 +37,18 @@ class TutorialProcessor : public foleys::MagicProcessor //============================================================================== void prepareToPlay (double, int) override { - auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f; + auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f; previousGain = *gainParameter * phase; } - void releaseResources() override {} + void releaseResources() override { } void processBlock (juce::AudioSampleBuffer& buffer, juce::MidiBuffer&) override { - auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f; + auto phase = *phaseParameter < 0.5f ? 1.0f : -1.0f; auto currentGain = *gainParameter * phase; - if (currentGain == previousGain) + if (juce::approximatelyEqual (currentGain, previousGain)) { buffer.applyGain (currentGain); } @@ -60,14 +60,14 @@ class TutorialProcessor : public foleys::MagicProcessor } //============================================================================== - const juce::String getName() const override { return "APVTS Tutorial"; } + const juce::String getName() const override { return "APVTS Tutorial"; } - double getTailLengthSeconds() const override { return 0; } + double getTailLengthSeconds() const override { return 0; } private: //============================================================================== juce::AudioProcessorValueTreeState parameters; - float previousGain; // [1] + float previousGain; // [1] std::atomic* phaseParameter = nullptr; std::atomic* gainParameter = nullptr; diff --git a/Examples/EqualizerExample/Source/PluginProcessor.cpp b/Examples/EqualizerExample/Source/PluginProcessor.cpp index 746e6805..8289eef7 100644 --- a/Examples/EqualizerExample/Source/PluginProcessor.cpp +++ b/Examples/EqualizerExample/Source/PluginProcessor.cpp @@ -12,109 +12,69 @@ namespace IDs { - static juce::String paramOutput { "output" }; - static juce::String paramType { "type" }; - static juce::String paramFreq { "freq" }; - static juce::String paramGain { "gain" }; - static juce::String paramQuality { "quality" }; - static juce::String paramActive { "active" }; -} - -juce::StringArray filterNames = -{ - NEEDS_TRANS ("No filter"), - NEEDS_TRANS ("High pass"), - NEEDS_TRANS ("1st order high pass"), - NEEDS_TRANS ("Low shelf"), - NEEDS_TRANS ("Band pass"), - NEEDS_TRANS ("Notch"), - NEEDS_TRANS ("Peak"), - NEEDS_TRANS ("High shelf"), - NEEDS_TRANS ("1st order low pass"), - NEEDS_TRANS ("Low pass") -}; +static juce::String paramOutput { "output" }; +static juce::String paramType { "type" }; +static juce::String paramFreq { "freq" }; +static juce::String paramGain { "gain" }; +static juce::String paramQuality { "quality" }; +static juce::String paramActive { "active" }; +} // namespace IDs + +juce::StringArray filterNames = { NEEDS_TRANS ("No filter"), NEEDS_TRANS ("High pass"), NEEDS_TRANS ("1st order high pass"), + NEEDS_TRANS ("Low shelf"), NEEDS_TRANS ("Band pass"), NEEDS_TRANS ("Notch"), + NEEDS_TRANS ("Peak"), NEEDS_TRANS ("High shelf"), NEEDS_TRANS ("1st order low pass"), + NEEDS_TRANS ("Low pass") }; static float maxLevel = 24.0f; -std::unique_ptr createParametersForFilter (const juce::String& prefix, - const juce::String& name, - EqualizerExampleAudioProcessor::FilterType type, - float frequency, - float gain = 0.0f, - float quality = 1.0f, - bool active = true) +static std::unique_ptr createParametersForFilter (const juce::String& prefix, const juce::String& name, + EqualizerExampleAudioProcessor::FilterType type, float frequency, + float gain = 0.0f, float quality = 1.0f, bool active = true) { - auto typeParameter = std::make_unique (juce::ParameterID (prefix + IDs::paramType, 1), - name + ": " + TRANS ("Filter Type"), - filterNames, - type); - - auto actvParameter = std::make_unique (juce::ParameterID (prefix + IDs::paramActive, 1), - name + ": " + TRANS ("Active"), - active, - juce::String(), - [](float value, int) {return value > 0.5f ? TRANS ("active") : TRANS ("bypassed");}, - [](juce::String text) {return text == TRANS ("active");}); - - auto freqParameter = std::make_unique (juce::ParameterID (prefix + IDs::paramFreq, 1), - name + ": " + TRANS ("Frequency"), - foleys::Conversions::makeLogarithmicRange(20.0f, 20000.0f), - frequency, - juce::String(), - juce::AudioProcessorParameter::genericParameter, - [](float value, int) { return (value < 1000) ? - juce::String (value, 0) + " Hz" : - juce::String (value / 1000.0) + " kHz"; }, - [](juce::String text) { return text.endsWith(" kHz") ? - text.getFloatValue() * 1000.0f : - text.getFloatValue(); }); - - auto qltyParameter = std::make_unique (juce::ParameterID (prefix + IDs::paramQuality, 1), - name + ": " + TRANS ("Quality"), - juce::NormalisableRange {0.1f, 10.0f, 0.1f, std::log (0.5f) / std::log (0.9f / 9.9f)}, - quality, - juce::String(), - juce::AudioProcessorParameter::genericParameter, - [](float value, int) { return juce::String (value, 1); }, - [](const juce::String& text) { return text.getFloatValue(); }); - - auto gainParameter = std::make_unique (juce::ParameterID (prefix + IDs::paramGain, 1), - name + ": " + TRANS ("Gain"), - juce::NormalisableRange {-maxLevel, maxLevel, 0.1f}, - gain, - juce::String(), - juce::AudioProcessorParameter::genericParameter, - [](float value, int) {return juce::String (value, 1) + " dB";}, - [](juce::String text) {return text.getFloatValue();}); - - auto group = std::make_unique ("band" + prefix, name, "|", - std::move (typeParameter), - std::move (actvParameter), - std::move (freqParameter), - std::move (qltyParameter), - std::move (gainParameter)); + auto typeParameter = + std::make_unique (juce::ParameterID (prefix + IDs::paramType, 1), name + ": " + TRANS ("Filter Type"), filterNames, type); + + auto actvParameter = std::make_unique ( + juce::ParameterID (prefix + IDs::paramActive, 1), name + ": " + TRANS ("Active"), active, juce::String(), + [] (float value, int) { return value > 0.5f ? TRANS ("active") : TRANS ("bypassed"); }, [] (juce::String text) { return text == TRANS ("active"); }); + + auto freqParameter = std::make_unique ( + juce::ParameterID (prefix + IDs::paramFreq, 1), name + ": " + TRANS ("Frequency"), foleys::Conversions::makeLogarithmicRange (20.0f, 20000.0f), + frequency, juce::String(), juce::AudioProcessorParameter::genericParameter, + [] (float value, int) { return (value < 1000) ? juce::String (value, 0) + " Hz" : juce::String (value / 1000.0) + " kHz"; }, + [] (juce::String text) { return text.endsWith (" kHz") ? text.getFloatValue() * 1000.0f : text.getFloatValue(); }); + + auto qltyParameter = std::make_unique ( + juce::ParameterID (prefix + IDs::paramQuality, 1), name + ": " + TRANS ("Quality"), + juce::NormalisableRange { 0.1f, 10.0f, 0.1f, std::log (0.5f) / std::log (0.9f / 9.9f) }, quality, juce::String(), juce::AudioProcessorParameter::genericParameter, + [] (float value, int) { return juce::String (value, 1); }, [] (const juce::String& text) { return text.getFloatValue(); }); + + auto gainParameter = std::make_unique ( + juce::ParameterID (prefix + IDs::paramGain, 1), name + ": " + TRANS ("Gain"), juce::NormalisableRange { -maxLevel, maxLevel, 0.1f }, gain, + juce::String(), juce::AudioProcessorParameter::genericParameter, [] (float value, int) { return juce::String (value, 1) + " dB"; }, + [] (juce::String text) { return text.getFloatValue(); }); + + auto group = std::make_unique ("band" + prefix, name, "|", std::move (typeParameter), std::move (actvParameter), + std::move (freqParameter), std::move (qltyParameter), std::move (gainParameter)); return group; } -juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() +static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() { std::vector> params; - params.push_back (createParametersForFilter ("Q1", NEEDS_TRANS ("Q1"), EqualizerExampleAudioProcessor::HighPass, 40.0f)); - params.push_back (createParametersForFilter ("Q2", NEEDS_TRANS ("Q2"), EqualizerExampleAudioProcessor::LowShelf, 250.0f)); - params.push_back (createParametersForFilter ("Q3", NEEDS_TRANS ("Q3"), EqualizerExampleAudioProcessor::Peak, 500.0f)); - params.push_back (createParametersForFilter ("Q4", NEEDS_TRANS ("Q4"), EqualizerExampleAudioProcessor::Peak, 1000.0f)); - params.push_back (createParametersForFilter ("Q5", NEEDS_TRANS ("Q5"), EqualizerExampleAudioProcessor::HighShelf, 5000.0f)); - params.push_back (createParametersForFilter ("Q6", NEEDS_TRANS ("Q6"), EqualizerExampleAudioProcessor::LowPass, 12000.0f)); - - auto param = std::make_unique (juce::ParameterID (IDs::paramOutput, 1), - TRANS ("Output"), - juce::NormalisableRange (0.0f, 2.0f, 0.01f), 1.0f, - juce::String(), - juce::AudioProcessorParameter::genericParameter, - [](float value, int) {return juce::String (juce::Decibels::gainToDecibels(value), 1) + " dB";}, - [](juce::String text) {return juce::Decibels::decibelsToGain (text.getFloatValue());}); + params.push_back (createParametersForFilter ("Q1", NEEDS_TRANS ("Q1"), EqualizerExampleAudioProcessor::HighPass, 40.0f)); + params.push_back (createParametersForFilter ("Q2", NEEDS_TRANS ("Q2"), EqualizerExampleAudioProcessor::LowShelf, 250.0f)); + params.push_back (createParametersForFilter ("Q3", NEEDS_TRANS ("Q3"), EqualizerExampleAudioProcessor::Peak, 500.0f)); + params.push_back (createParametersForFilter ("Q4", NEEDS_TRANS ("Q4"), EqualizerExampleAudioProcessor::Peak, 1000.0f)); + params.push_back (createParametersForFilter ("Q5", NEEDS_TRANS ("Q5"), EqualizerExampleAudioProcessor::HighShelf, 5000.0f)); + params.push_back (createParametersForFilter ("Q6", NEEDS_TRANS ("Q6"), EqualizerExampleAudioProcessor::LowPass, 12000.0f)); + + auto param = std::make_unique ( + juce::ParameterID (IDs::paramOutput, 1), TRANS ("Output"), juce::NormalisableRange (0.0f, 2.0f, 0.01f), 1.0f, juce::String(), + juce::AudioProcessorParameter::genericParameter, [] (float value, int) { return juce::String (juce::Decibels::gainToDecibels (value), 1) + " dB"; }, + [] (juce::String text) { return juce::Decibels::decibelsToGain (text.getFloatValue()); }); auto group = std::make_unique ("global", TRANS ("Globals"), "|", std::move (param)); params.push_back (std::move (group)); @@ -122,9 +82,9 @@ juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() return { params.begin(), params.end() }; } -auto createPostUpdateLambda (foleys::MagicProcessorState& magicState, const juce::String& plotID) +static auto createPostUpdateLambda (foleys::MagicProcessorState& magicState, const juce::String& plotID) { - return [plot = magicState.getObjectWithType(plotID)] (const EqualizerExampleAudioProcessor::FilterAttachment& a) + return [plot = magicState.getObjectWithType (plotID)] (const EqualizerExampleAudioProcessor::FilterAttachment& a) { if (plot != nullptr) { @@ -137,41 +97,41 @@ auto createPostUpdateLambda (foleys::MagicProcessorState& magicState, const juce //============================================================================== EqualizerExampleAudioProcessor::EqualizerExampleAudioProcessor() #ifndef JucePlugin_PreferredChannelConfigurations - : MagicProcessor (BusesProperties() - #if ! JucePlugin_IsMidiEffect - #if ! JucePlugin_IsSynth - .withInput ("Input", juce::AudioChannelSet::stereo(), true) - #endif - .withOutput ("Output", juce::AudioChannelSet::stereo(), true) - #endif - ), + : MagicProcessor (BusesProperties() + #if !JucePlugin_IsMidiEffect + #if !JucePlugin_IsSynth + .withInput ("Input", juce::AudioChannelSet::stereo(), true) + #endif + .withOutput ("Output", juce::AudioChannelSet::stereo(), true) + #endif + ), #else - : + : #endif treeState (*this, nullptr, JucePlugin_Name, createParameterLayout()), gainAttachment (treeState, gain, IDs::paramOutput) { FOLEYS_SET_SOURCE_PATH (__FILE__); - + // GUI MAGIC: add plots to be displayed in the GUI for (size_t i = 0; i < attachments.size(); ++i) { auto name = "plot" + juce::String (i + 1); - magicState.createAndAddObject(name); + magicState.createAndAddObject (name); attachments.at (i)->postFilterUpdate = createPostUpdateLambda (magicState, name); } - plotSum = magicState.createAndAddObject("plotSum"); + plotSum = magicState.createAndAddObject ("plotSum"); // GUI MAGIC: add analyser plots - inputAnalyser = magicState.createAndAddObject("input"); - outputAnalyser = magicState.createAndAddObject("output"); + inputAnalyser = magicState.createAndAddObject ("input"); + outputAnalyser = magicState.createAndAddObject ("output"); // MAGIC GUI: add a meter at the output - outputMeter = magicState.createAndAddObject("outputMeter"); + outputMeter = magicState.createAndAddObject ("outputMeter"); - for (auto* parameter : getParameters()) - if (auto* p = dynamic_cast(parameter)) + for (auto* parameter: getParameters()) + if (auto* p = dynamic_cast (parameter)) treeState.addParameterListener (p->paramID, this); // MAGIC GUI: add properties to connect visibility to @@ -184,8 +144,8 @@ EqualizerExampleAudioProcessor::EqualizerExampleAudioProcessor() EqualizerExampleAudioProcessor::~EqualizerExampleAudioProcessor() { - for (auto* parameter : getParameters()) - if (auto* p = dynamic_cast(parameter)) + for (auto* parameter: getParameters()) + if (auto* p = dynamic_cast (parameter)) treeState.removeParameterListener (p->paramID, this); } @@ -199,38 +159,36 @@ void EqualizerExampleAudioProcessor::prepareToPlay (double sampleRate, int sampl outputMeter->setupSource (getTotalNumOutputChannels(), sampleRate, 500); juce::dsp::ProcessSpec spec; - spec.sampleRate = sampleRate; + spec.sampleRate = sampleRate; spec.maximumBlockSize = juce::uint32 (samplesPerBlock); - spec.numChannels = juce::uint32 (numChannels); + spec.numChannels = juce::uint32 (numChannels); filter.get<6>().setGainLinear (*treeState.getRawParameterValue (IDs::paramOutput)); - for (auto* a : attachments) + for (auto* a: attachments) a->setSampleRate (sampleRate); filter.prepare (spec); } -void EqualizerExampleAudioProcessor::releaseResources() -{ -} +void EqualizerExampleAudioProcessor::releaseResources() { } #ifndef JucePlugin_PreferredChannelConfigurations bool EqualizerExampleAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const { -#if JucePlugin_IsMidiEffect + #if JucePlugin_IsMidiEffect ignoreUnused (layouts); return true; -#else + #else - // This checks if the input layout matches the output layout -#if ! JucePlugin_IsSynth + // This checks if the input layout matches the output layout + #if !JucePlugin_IsSynth if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet()) return false; -#endif + #endif return true; -#endif + #endif } #endif @@ -239,12 +197,12 @@ void EqualizerExampleAudioProcessor::processBlock (juce::AudioBuffer& buf juce::ScopedNoDenormals noDenormals; ignoreUnused (midiMessages); - filter.setBypassed<0>(attachment1.isActive() == false); - filter.setBypassed<1>(attachment2.isActive() == false); - filter.setBypassed<2>(attachment3.isActive() == false); - filter.setBypassed<3>(attachment4.isActive() == false); - filter.setBypassed<4>(attachment5.isActive() == false); - filter.setBypassed<5>(attachment6.isActive() == false); + filter.setBypassed<0> (attachment1.isActive() == false); + filter.setBypassed<1> (attachment2.isActive() == false); + filter.setBypassed<2> (attachment3.isActive() == false); + filter.setBypassed<3> (attachment4.isActive() == false); + filter.setBypassed<4> (attachment5.isActive() == false); + filter.setBypassed<5> (attachment6.isActive() == false); filter.get<6>().setGainLinear (gain); @@ -253,7 +211,7 @@ void EqualizerExampleAudioProcessor::processBlock (juce::AudioBuffer& buf inputAnalyser->pushSamples (buffer); juce::dsp::AudioBlock ioBuffer (buffer); - juce::dsp::ProcessContextReplacing context (ioBuffer); + juce::dsp::ProcessContextReplacing context (ioBuffer); filter.process (context); // GUI MAGIC: measure after processing @@ -265,19 +223,22 @@ void EqualizerExampleAudioProcessor::processBlock (juce::AudioBuffer& buf //============================================================================== -EqualizerExampleAudioProcessor::FilterAttachment::FilterAttachment (juce::AudioProcessorValueTreeState& stateToUse, FilterBand& filterToControl, const juce::String& prefixToUse, const juce::CriticalSection& lock) - : state (stateToUse), - filter (filterToControl), - prefix (prefixToUse), - callbackLock (lock), - typeAttachment (state, type, prefix + IDs::paramType, [&]{ updateFilter(); }), - frequencyAttachment (state, frequency, prefix + IDs::paramFreq, [&]{ updateFilter(); }), - gainAttachment (state, gain, prefix + IDs::paramGain, [&]{ updateFilter(); }), - qualityAttachment (state, quality, prefix + IDs::paramQuality, [&]{ updateFilter(); }), - activeAttachment (state, active, prefix + IDs::paramActive, [&] - { if (postFilterUpdate) - postFilterUpdate (*this); - }) +EqualizerExampleAudioProcessor::FilterAttachment::FilterAttachment (juce::AudioProcessorValueTreeState& stateToUse, FilterBand& filterToControl, + const juce::String& prefixToUse, const juce::CriticalSection& lock) + : state (stateToUse), + filter (filterToControl), + prefix (prefixToUse), + callbackLock (lock), + typeAttachment (state, type, prefix + IDs::paramType, [&] { updateFilter(); }), + frequencyAttachment (state, frequency, prefix + IDs::paramFreq, [&] { updateFilter(); }), + gainAttachment (state, gain, prefix + IDs::paramGain, [&] { updateFilter(); }), + qualityAttachment (state, quality, prefix + IDs::paramQuality, [&] { updateFilter(); }), + activeAttachment (state, active, prefix + IDs::paramActive, + [&] + { + if (postFilterUpdate) + postFilterUpdate (*this); + }) { updateFilter(); } @@ -289,18 +250,24 @@ void EqualizerExampleAudioProcessor::FilterAttachment::updateFilter() switch (type) { - case NoFilter: coefficients = new juce::dsp::IIR::Coefficients (1, 0, 1, 0); break; - case LowPass: coefficients = juce::dsp::IIR::Coefficients::makeLowPass (sampleRate, frequency, quality); break; - case LowPass1st: coefficients = juce::dsp::IIR::Coefficients::makeFirstOrderLowPass (sampleRate, frequency); break; - case LowShelf: coefficients = juce::dsp::IIR::Coefficients::makeLowShelf (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); break; - case BandPass: coefficients = juce::dsp::IIR::Coefficients::makeBandPass (sampleRate, frequency, quality); break; - case Notch: coefficients = juce::dsp::IIR::Coefficients::makeNotch (sampleRate, frequency, quality); break; - case Peak: coefficients = juce::dsp::IIR::Coefficients::makePeakFilter (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); break; - case HighShelf: coefficients = juce::dsp::IIR::Coefficients::makeHighShelf (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); break; + case NoFilter: coefficients = new juce::dsp::IIR::Coefficients (1, 0, 1, 0); break; + case LowPass: coefficients = juce::dsp::IIR::Coefficients::makeLowPass (sampleRate, frequency, quality); break; + case LowPass1st: coefficients = juce::dsp::IIR::Coefficients::makeFirstOrderLowPass (sampleRate, frequency); break; + case LowShelf: + coefficients = juce::dsp::IIR::Coefficients::makeLowShelf (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); + break; + case BandPass: coefficients = juce::dsp::IIR::Coefficients::makeBandPass (sampleRate, frequency, quality); break; + case Notch: coefficients = juce::dsp::IIR::Coefficients::makeNotch (sampleRate, frequency, quality); break; + case Peak: + coefficients = juce::dsp::IIR::Coefficients::makePeakFilter (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); + break; + case HighShelf: + coefficients = juce::dsp::IIR::Coefficients::makeHighShelf (sampleRate, frequency, quality, juce::Decibels::decibelsToGain (gain.load())); + break; case HighPass1st: coefficients = juce::dsp::IIR::Coefficients::makeFirstOrderHighPass (sampleRate, frequency); break; - case HighPass: coefficients = juce::dsp::IIR::Coefficients::makeHighPass (sampleRate, frequency, quality); break; + case HighPass: coefficients = juce::dsp::IIR::Coefficients::makeHighPass (sampleRate, frequency, quality); break; case LastFilterID: - default: return; + default: return; } { @@ -321,14 +288,9 @@ void EqualizerExampleAudioProcessor::FilterAttachment::setSampleRate (double sam //============================================================================== template -AttachedValue::AttachedValue (juce::AudioProcessorValueTreeState& stateToUse, - std::atomic& valueToUse, - const juce::String& paramToUse, - std::function changedLambda) - : state (stateToUse), - value (valueToUse), - paramID (paramToUse), - onParameterChanged (changedLambda) +AttachedValue::AttachedValue (juce::AudioProcessorValueTreeState& stateToUse, std::atomic& valueToUse, const juce::String& paramToUse, + std::function changedLambda) + : state (stateToUse), value (valueToUse), paramID (paramToUse), onParameterChanged (changedLambda) { // Oh uh, tried to attach to a non existing parameter jassert (state.getParameter (paramID) != nullptr); @@ -388,7 +350,7 @@ void EqualizerExampleAudioProcessor::parameterChanged (const juce::String&, floa void EqualizerExampleAudioProcessor::handleAsyncUpdate() { std::vector::Ptr> coefficients; - for (auto* a : attachments) + for (auto* a: attachments) if (a->isActive()) coefficients.push_back (a->coefficients); diff --git a/Examples/FoleysSynth/Source/PluginProcessor.cpp b/Examples/FoleysSynth/Source/PluginProcessor.cpp index 04d671ff..6d64a9d1 100644 --- a/Examples/FoleysSynth/Source/PluginProcessor.cpp +++ b/Examples/FoleysSynth/Source/PluginProcessor.cpp @@ -13,7 +13,7 @@ //============================================================================== -juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() +static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() { juce::AudioProcessorValueTreeState::ParameterLayout layout; FoleysSynth::addADSRParameters (layout); diff --git a/Examples/SignalGenerator/Source/PluginProcessor.cpp b/Examples/SignalGenerator/Source/PluginProcessor.cpp index e4755975..3f0339aa 100644 --- a/Examples/SignalGenerator/Source/PluginProcessor.cpp +++ b/Examples/SignalGenerator/Source/PluginProcessor.cpp @@ -14,68 +14,62 @@ namespace IDs { - static juce::String mainType { "mainType" }; - static juce::String mainFreq { "mainfreq" }; - static juce::String mainLevel { "mainlevel" }; - static juce::String lfoType { "lfoType" }; - static juce::String lfoFreq { "lfofreq" }; - static juce::String lfoLevel { "lfolevel" }; - static juce::String vfoType { "vfoType" }; - static juce::String vfoFreq { "vfofreq" }; - static juce::String vfoLevel { "vfolevel" }; - - static juce::Identifier oscilloscope { "oscilloscope" }; -} - -juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() +static juce::String mainType { "mainType" }; +static juce::String mainFreq { "mainfreq" }; +static juce::String mainLevel { "mainlevel" }; +static juce::String lfoType { "lfoType" }; +static juce::String lfoFreq { "lfofreq" }; +static juce::String lfoLevel { "lfolevel" }; +static juce::String vfoType { "vfoType" }; +static juce::String vfoFreq { "vfofreq" }; +static juce::String vfoLevel { "vfolevel" }; + +static juce::Identifier oscilloscope { "oscilloscope" }; +} // namespace IDs + +static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() { - auto freqRange = juce::NormalisableRange {20.0f, 20000.0f, - [](float start, float end, float normalised) - { - return start + (std::pow (2.0f, normalised * 10.0f) - 1.0f) * (end - start) / 1023.0f; - }, - [](float start, float end, float value) - { - return (std::log (((value - start) * 1023.0f / (end - start)) + 1.0f) / std::log ( 2.0f)) / 10.0f; - }, - [](float start, float end, float value) - { - if (value > 3000.0f) - return juce::jlimit (start, end, 100.0f * juce::roundToInt (value / 100.0f)); - - if (value > 1000.0f) - return juce::jlimit (start, end, 10.0f * juce::roundToInt (value / 10.0f)); - - return juce::jlimit (start, end, float (juce::roundToInt (value))); - }}; + auto freqRange = juce::NormalisableRange { 20.0f, 20000.0f, [] (float start, float end, float normalised) + { return start + (std::pow (2.0f, normalised * 10.0f) - 1.0f) * (end - start) / 1023.0f; }, + [] (float start, float end, float value) + { return (std::log (((value - start) * 1023.0f / (end - start)) + 1.0f) / std::log (2.0f)) / 10.0f; }, + [] (float start, float end, float value) + { + if (value > 3000.0f) + return juce::jlimit (start, end, 100.0f * juce::roundToInt (value / 100.0f)); + + if (value > 1000.0f) + return juce::jlimit (start, end, 10.0f * juce::roundToInt (value / 10.0f)); + + return juce::jlimit (start, end, float (juce::roundToInt (value))); + } }; juce::AudioProcessorValueTreeState::ParameterLayout layout; - auto generator = std::make_unique("Generator", TRANS ("Generator"), "|"); - generator->addChild (std::make_unique(juce::ParameterID (IDs::mainType, 1), "Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 1), - std::make_unique(juce::ParameterID (IDs::mainFreq, 1), "Frequency", freqRange, 440.0f), - std::make_unique(juce::ParameterID (IDs::mainLevel, 1), "Level", juce::NormalisableRange(-100.0f, 0.0f, 1.0f), -6.0f)); + auto generator = std::make_unique ("Generator", TRANS ("Generator"), "|"); + generator->addChild (std::make_unique (juce::ParameterID (IDs::mainType, 1), "Type", + juce::StringArray ("None", "Sine", "Triangle", "Square"), 1), + std::make_unique (juce::ParameterID (IDs::mainFreq, 1), "Frequency", freqRange, 440.0f), + std::make_unique (juce::ParameterID (IDs::mainLevel, 1), "Level", + juce::NormalisableRange (-100.0f, 0.0f, 1.0f), -6.0f)); - auto lfo = std::make_unique("lfo", TRANS ("LFO"), "|"); - lfo->addChild (std::make_unique(juce::ParameterID (IDs::lfoType, 1), "LFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0), - std::make_unique(juce::ParameterID (IDs::lfoFreq, 1), "Frequency", juce::NormalisableRange(0.25f, 10.0f), 2.0f), - std::make_unique(juce::ParameterID (IDs::lfoLevel, 1), "Level", juce::NormalisableRange(0.0f, 1.0f), 0.0f)); + auto lfo = std::make_unique ("lfo", TRANS ("LFO"), "|"); + lfo->addChild (std::make_unique (juce::ParameterID (IDs::lfoType, 1), "LFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0), + std::make_unique (juce::ParameterID (IDs::lfoFreq, 1), "Frequency", juce::NormalisableRange (0.25f, 10.0f), 2.0f), + std::make_unique (juce::ParameterID (IDs::lfoLevel, 1), "Level", juce::NormalisableRange (0.0f, 1.0f), 0.0f)); - auto vfo = std::make_unique("vfo", TRANS ("VFO"), "|"); - vfo->addChild (std::make_unique(juce::ParameterID (IDs::vfoType, 1), "VFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0), - std::make_unique(juce::ParameterID (IDs::vfoFreq, 1), "Frequency", juce::NormalisableRange(0.5f, 10.0f), 2.0f), - std::make_unique(juce::ParameterID (IDs::vfoLevel, 1), "Level", juce::NormalisableRange(0.0f, 1.0), 0.0f)); + auto vfo = std::make_unique ("vfo", TRANS ("VFO"), "|"); + vfo->addChild (std::make_unique (juce::ParameterID (IDs::vfoType, 1), "VFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0), + std::make_unique (juce::ParameterID (IDs::vfoFreq, 1), "Frequency", juce::NormalisableRange (0.5f, 10.0f), 2.0f), + std::make_unique (juce::ParameterID (IDs::vfoLevel, 1), "Level", juce::NormalisableRange (0.0f, 1.0), 0.0f)); - layout.add (std::move (generator), - std::move (lfo), - std::move (vfo)); + layout.add (std::move (generator), std::move (lfo), std::move (vfo)); return layout; } //============================================================================== SignalGeneratorAudioProcessor::SignalGeneratorAudioProcessor() - : foleys::MagicProcessor (juce::AudioProcessor::BusesProperties() - .withOutput ("Output", juce::AudioChannelSet::stereo(), true)), + : foleys::MagicProcessor (juce::AudioProcessor::BusesProperties().withOutput ("Output", juce::AudioChannelSet::stereo(), true)), treeState (*this, nullptr, "PARAMETERS", createParameterLayout()) { FOLEYS_SET_SOURCE_PATH (__FILE__); @@ -102,27 +96,25 @@ SignalGeneratorAudioProcessor::SignalGeneratorAudioProcessor() // MAGIC GUI: register an oscilloscope to display in the GUI. // We keep a pointer to push samples into in processBlock(). // And we are only interested in channel 0 - oscilloscope = magicState.createAndAddObject(IDs::oscilloscope, 0); + oscilloscope = magicState.createAndAddObject (IDs::oscilloscope, 0); magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize); } -SignalGeneratorAudioProcessor::~SignalGeneratorAudioProcessor() -{ -} +SignalGeneratorAudioProcessor::~SignalGeneratorAudioProcessor() { } //============================================================================== void SignalGeneratorAudioProcessor::setOscillator (juce::dsp::Oscillator& osc, WaveType type) { if (type == WaveType::Sine) - osc.initialise ([](auto in) { return std::sin (in); }); + osc.initialise ([] (auto in) { return std::sin (in); }); else if (type == WaveType::Triangle) - osc.initialise ([](auto in) { return in / juce::MathConstants::pi; }); + osc.initialise ([] (auto in) { return in / juce::MathConstants::pi; }); else if (type == WaveType::Square) - osc.initialise ([](auto in) { return in < 0 ? 1.0f : -1.0f; }); + osc.initialise ([] (auto in) { return in < 0 ? 1.0f : -1.0f; }); else - osc.initialise ([](auto) { return 0.0f; }); + osc.initialise ([] (auto) { return 0.0f; }); } void SignalGeneratorAudioProcessor::parameterChanged (const juce::String& param, float value) @@ -144,9 +136,9 @@ void SignalGeneratorAudioProcessor::prepareToPlay (double sampleRate, int sample const auto numChannels = getTotalNumOutputChannels(); juce::dsp::ProcessSpec spec; - spec.sampleRate = sampleRate; + spec.sampleRate = sampleRate; spec.maximumBlockSize = juce::uint32 (samplesPerBlock); - spec.numChannels = juce::uint32 (numChannels); + spec.numChannels = juce::uint32 (numChannels); mainOSC.prepare (spec); lfoOSC.prepare (spec); @@ -160,17 +152,15 @@ void SignalGeneratorAudioProcessor::prepareToPlay (double sampleRate, int sample magicState.prepareToPlay (sampleRate, samplesPerBlock); } -void SignalGeneratorAudioProcessor::releaseResources() -{ -} +void SignalGeneratorAudioProcessor::releaseResources() { } void SignalGeneratorAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) { ignoreUnused (midiMessages); juce::ScopedNoDenormals noDenormals; - auto totalNumInputChannels = getTotalNumInputChannels(); - auto totalNumOutputChannels = getTotalNumOutputChannels(); + auto totalNumInputChannels = getTotalNumInputChannels(); + auto totalNumOutputChannels = getTotalNumOutputChannels(); // In case we have more outputs than inputs, this code clears any output // channels that didn't contain input data, (because these aren't @@ -191,11 +181,10 @@ void SignalGeneratorAudioProcessor::processBlock (juce::AudioBuffer& buff for (int i = 0; i < buffer.getNumSamples(); ++i) { mainOSC.setFrequency (frequency->load() * (1.0f + vfoOSC.processSample (0.0f) * vfoLevel->load())); - channelData [i] = juce::jlimit (-1.0f, 1.0f, - mainOSC.processSample (0.0f) * gain * ( 1.0f - (lfoLevel->load() * lfoOSC.processSample (0.0f)))); + channelData[i] = juce::jlimit (-1.0f, 1.0f, mainOSC.processSample (0.0f) * gain * (1.0f - (lfoLevel->load() * lfoOSC.processSample (0.0f)))); } - for (int i=1; i < getTotalNumOutputChannels(); ++i) + for (int i = 1; i < getTotalNumOutputChannels(); ++i) buffer.copyFrom (i, 0, buffer.getReadPointer (0), buffer.getNumSamples()); // MAGIC GUI: push the samples to be displayed @@ -206,24 +195,23 @@ void SignalGeneratorAudioProcessor::processBlock (juce::AudioBuffer& buff #ifndef JucePlugin_PreferredChannelConfigurations bool SignalGeneratorAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const { -#if JucePlugin_IsMidiEffect + #if JucePlugin_IsMidiEffect ignoreUnused (layouts); return true; -#else + #else // This is the place where you check if the layout is supported. // In this template code we only support mono or stereo. - if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono() - && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo()) + if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono() && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo()) return false; - // This checks if the input layout matches the output layout -#if ! JucePlugin_IsSynth + // This checks if the input layout matches the output layout + #if !JucePlugin_IsSynth if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet()) return false; -#endif + #endif return true; -#endif + #endif } #endif diff --git a/modules/foleys_gui_magic/General/foleys_MagicJUCEFactories.cpp b/modules/foleys_gui_magic/General/foleys_MagicJUCEFactories.cpp index 3228c919..c270f2d7 100644 --- a/modules/foleys_gui_magic/General/foleys_MagicJUCEFactories.cpp +++ b/modules/foleys_gui_magic/General/foleys_MagicJUCEFactories.cpp @@ -471,7 +471,7 @@ class LabelItem : public GuiItem else label.setJustificationType (juce::Justification::centredLeft); - label.setFont (juce::Font (getProperty (pFontSize))); + label.setFont (juce::FontOptions().withHeight (getProperty (pFontSize))); label.setEditable (getProperty (pEditable)); diff --git a/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp b/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp index 1c9e4d52..8b586b08 100644 --- a/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp +++ b/modules/foleys_gui_magic/Layout/foleys_Decorator.cpp @@ -139,8 +139,8 @@ Decorator::ClientBounds Decorator::getClientBounds (juce::Rectangle overall captionBox = box.removeFromBottom (captionSize).toNearestInt(); else { - juce::Font f (captionSize * 0.8f); - auto w = float (f.getStringWidth (caption)); + juce::Font f (juce::FontOptions().withHeight (captionSize * 0.8f)); + auto w = float (f.getStringWidth (caption)); if (justification.getOnlyHorizontalFlags() & juce::Justification::left) captionBox = box.removeFromLeft (w).toNearestInt(); diff --git a/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.cpp b/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.cpp index b68330c0..244a3088 100644 --- a/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.cpp +++ b/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.cpp @@ -52,12 +52,12 @@ MagicLevelMeter::MagicLevelMeter() void MagicLevelMeter::paint (juce::Graphics& g) { - actualLookAndFeel->drawLevelMeter (g, *this, source, getLocalBounds()); + actualLookAndFeel->drawMagicLevelMeter (g, *this, magicLevelSource, getLocalBounds()); } void MagicLevelMeter::setLevelSource (MagicLevelSource* newSource) { - source = newSource; + magicLevelSource = newSource; } void MagicLevelMeter::timerCallback() @@ -79,7 +79,7 @@ void MagicLevelMeter::lookAndFeelChanged() // ================================================================================ -void MagicLevelMeter::LookAndFeelFallback::drawLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) +void MagicLevelMeter::LookAndFeelFallback::drawMagicLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) { const auto backgroundColour = meter.findColour (backgroundColourId); if (!backgroundColour.isTransparent()) diff --git a/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.h b/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.h index 0c554f59..c97e8cb5 100644 --- a/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.h +++ b/modules/foleys_gui_magic/Widgets/foleys_MagicLevelMeter.h @@ -57,8 +57,8 @@ class MagicLevelMeter struct LookAndFeelMethods { - virtual ~LookAndFeelMethods() = default; - virtual void drawLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) = 0; + virtual ~LookAndFeelMethods() = default; + virtual void drawMagicLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) = 0; }; MagicLevelMeter(); @@ -72,13 +72,13 @@ class MagicLevelMeter void lookAndFeelChanged() override; private: - juce::WeakReference source; + juce::WeakReference magicLevelSource; class LookAndFeelFallback : public LookAndFeel, public LookAndFeelMethods { public: LookAndFeelFallback() = default; - void drawLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) override; + void drawMagicLevelMeter (juce::Graphics& g, MagicLevelMeter& meter, MagicLevelSource* source, juce::Rectangle bounds) override; }; LookAndFeelFallback lookAndFeelFallback;