Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant calls - thanks David Alexander #109

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(FGM_VERSION 1.4.0)
project(foleys_gui_magic
DESCRIPTION "PluginGuiMagic"
HOMEPAGE_URL "https://foleysfinest.com/PluginGuiMagic"
LANGUAGES CXX)
LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeIncludes")

Expand Down
38 changes: 19 additions & 19 deletions Examples/APVTS_Tutorial/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<juce::AudioParameterFloat> ("gain", // parameterID
"Gain", // parameter name
0.0f, // minimum value
1.0f, // maximum value
0.5f), // default value
std::make_unique<juce::AudioParameterBool> ("invertPhase", // parameterID
"Invert Phase", // parameter name
false) // default value
})
: parameters (*this, nullptr, juce::Identifier ("APVTSTutorial"),
{
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID ("gain", 1), // parameterID
"Gain", // parameter name
0.0f, // minimum value
1.0f, // maximum value
0.5f), // default value
std::make_unique<juce::AudioParameterBool> (juce::ParameterID ("invertPhase", 1), // parameterID
"Invert Phase", // parameter name
false) // default value
})
{
FOLEYS_SET_SOURCE_PATH (__FILE__);

Expand All @@ -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);
}
Expand All @@ -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<float>* phaseParameter = nullptr;
std::atomic<float>* gainParameter = nullptr;
Expand Down
290 changes: 126 additions & 164 deletions Examples/EqualizerExample/Source/PluginProcessor.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Examples/FoleysSynth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ juce_add_plugin(${PROJECT_NAME}
NEEDS_MIDI_INPUT yes
FORMATS ${FORMATS}
VST3_CATEGORIES "Instrument" "Synth"
AAX_CATEGORY "AAX_ePlugInCategory_Instrument"
AAX_CATEGORY "SWGenerators"
AU_MAIN_TYPE "kAudioUnitType_MusicDevice"
COMPANY_WEBSITE "https://foleysfinest.com"
COMPANY_EMAIL "info@foleysfinest.com"
Expand Down
2 changes: 1 addition & 1 deletion Examples/FoleysSynth/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//==============================================================================

juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
{
juce::AudioProcessorValueTreeState::ParameterLayout layout;
FoleysSynth::addADSRParameters (layout);
Expand Down
140 changes: 64 additions & 76 deletions Examples/SignalGenerator/Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> {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<float> { 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<juce::AudioProcessorParameterGroup>("Generator", TRANS ("Generator"), "|");
generator->addChild (std::make_unique<juce::AudioParameterChoice>(juce::ParameterID (IDs::mainType, 1), "Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 1),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::mainFreq, 1), "Frequency", freqRange, 440.0f),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::mainLevel, 1), "Level", juce::NormalisableRange<float>(-100.0f, 0.0f, 1.0f), -6.0f));
auto generator = std::make_unique<juce::AudioProcessorParameterGroup> ("Generator", TRANS ("Generator"), "|");
generator->addChild (std::make_unique<juce::AudioParameterChoice> (juce::ParameterID (IDs::mainType, 1), "Type",
juce::StringArray ("None", "Sine", "Triangle", "Square"), 1),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::mainFreq, 1), "Frequency", freqRange, 440.0f),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::mainLevel, 1), "Level",
juce::NormalisableRange<float> (-100.0f, 0.0f, 1.0f), -6.0f));

auto lfo = std::make_unique<juce::AudioProcessorParameterGroup>("lfo", TRANS ("LFO"), "|");
lfo->addChild (std::make_unique<juce::AudioParameterChoice>(juce::ParameterID (IDs::lfoType, 1), "LFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::lfoFreq, 1), "Frequency", juce::NormalisableRange<float>(0.25f, 10.0f), 2.0f),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::lfoLevel, 1), "Level", juce::NormalisableRange<float>(0.0f, 1.0f), 0.0f));
auto lfo = std::make_unique<juce::AudioProcessorParameterGroup> ("lfo", TRANS ("LFO"), "|");
lfo->addChild (std::make_unique<juce::AudioParameterChoice> (juce::ParameterID (IDs::lfoType, 1), "LFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::lfoFreq, 1), "Frequency", juce::NormalisableRange<float> (0.25f, 10.0f), 2.0f),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::lfoLevel, 1), "Level", juce::NormalisableRange<float> (0.0f, 1.0f), 0.0f));

auto vfo = std::make_unique<juce::AudioProcessorParameterGroup>("vfo", TRANS ("VFO"), "|");
vfo->addChild (std::make_unique<juce::AudioParameterChoice>(juce::ParameterID (IDs::vfoType, 1), "VFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::vfoFreq, 1), "Frequency", juce::NormalisableRange<float>(0.5f, 10.0f), 2.0f),
std::make_unique<juce::AudioParameterFloat>(juce::ParameterID (IDs::vfoLevel, 1), "Level", juce::NormalisableRange<float>(0.0f, 1.0), 0.0f));
auto vfo = std::make_unique<juce::AudioProcessorParameterGroup> ("vfo", TRANS ("VFO"), "|");
vfo->addChild (std::make_unique<juce::AudioParameterChoice> (juce::ParameterID (IDs::vfoType, 1), "VFO-Type", juce::StringArray ("None", "Sine", "Triangle", "Square"), 0),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::vfoFreq, 1), "Frequency", juce::NormalisableRange<float> (0.5f, 10.0f), 2.0f),
std::make_unique<juce::AudioParameterFloat> (juce::ParameterID (IDs::vfoLevel, 1), "Level", juce::NormalisableRange<float> (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__);
Expand All @@ -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<foleys::MagicOscilloscope>(IDs::oscilloscope, 0);
oscilloscope = magicState.createAndAddObject<foleys::MagicOscilloscope> (IDs::oscilloscope, 0);

magicState.setGuiValueTree (BinaryData::magic_xml, BinaryData::magic_xmlSize);
}

SignalGeneratorAudioProcessor::~SignalGeneratorAudioProcessor()
{
}
SignalGeneratorAudioProcessor::~SignalGeneratorAudioProcessor() { }

//==============================================================================

void SignalGeneratorAudioProcessor::setOscillator (juce::dsp::Oscillator<float>& 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<float>::pi; });
osc.initialise ([] (auto in) { return in / juce::MathConstants<float>::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)
Expand All @@ -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);
Expand All @@ -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<float>& 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
Expand All @@ -191,11 +181,10 @@ void SignalGeneratorAudioProcessor::processBlock (juce::AudioBuffer<float>& 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
Expand All @@ -206,24 +195,23 @@ void SignalGeneratorAudioProcessor::processBlock (juce::AudioBuffer<float>& 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

Expand Down
2 changes: 1 addition & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ project (FoleysGUIMagicTests
VERSION ${FGM_VERSION}
DESCRIPTION "Unit tests for the foleys_gui_magic JUCE module"
HOMEPAGE_URL "https://foleysfinest.com/developer/pluginguimagic/"
LANGUAGES CXX)
LANGUAGES C CXX)

enable_testing()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
5 changes: 0 additions & 5 deletions modules/foleys_gui_magic/Layout/foleys_Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ void Container::createSubComponents()
if (childItem)
{
containerBox.addAndMakeVisible (childItem.get());
childItem->createSubComponents();

children.push_back (std::move (childItem));
}
}
Expand Down Expand Up @@ -241,9 +239,6 @@ void Container::updateLayout()
for (auto& child : children)
child->setBounds (child->resolvePosition (clientBounds));
}

for (auto& child : children)
child->updateLayout();
}

void Container::updateColours()
Expand Down
4 changes: 2 additions & 2 deletions modules/foleys_gui_magic/Layout/foleys_Decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ Decorator::ClientBounds Decorator::getClientBounds (juce::Rectangle<int> 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();
Expand Down
Loading