Skip to content

Commit

Permalink
Cleanup: Use detail namespace in plugin processor instead of anonymous
Browse files Browse the repository at this point in the history
Use of anonymous namespace gives the variables and functions declared
there global scope, which is kind of the opposite of what I wanted.
  • Loading branch information
JoseDiazRohena committed Jul 11, 2023
1 parent 887e2be commit 41081b4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

namespace
namespace detail
{
inline constexpr float kNeg6dbGain = 0.5011872336f;
inline constexpr int kOversampleFactor = 2;
Expand All @@ -27,7 +27,7 @@ inline constexpr double kDryWetRampLength = .10;
* the level of precision adjusted based on the value
* size.
*/
juce::String getPrecisionAdjustedValueString (float value)
inline juce::String getPrecisionAdjustedValueString (float value)
{
const auto absValue = std::abs (value);

Expand All @@ -42,7 +42,8 @@ juce::String getPrecisionAdjustedValueString (float value)
return juce::String (juce::roundToInt (value));
}

std::function<juce::String (float, int)> makeStringFromValueFunction (VParameter param)
inline std::function<juce::String (float, int)>
makeStringFromValueFunction (VParameter param)
{
if ((param == VParameter::attack) || (param == VParameter::release)
|| (param == VParameter::inputGain) || (param == VParameter::makeupGain))
Expand All @@ -66,7 +67,7 @@ std::function<juce::String (float, int)> makeStringFromValueFunction (VParameter
return [] (float value, int) { return juce::String (juce::roundToInt (value)); };
}
}
}
} // namespace detail

ValentineAudioProcessor::ValentineAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
Expand Down Expand Up @@ -148,7 +149,7 @@ juce::AudioProcessorValueTreeState::ParameterLayout
FFCompParameterIncrement[i]);
rangeToUse.setSkewForCentre (FFCompParamCenter[i]);

auto stringFromValue = makeStringFromValueFunction (paramType);
auto stringFromValue = detail::makeStringFromValueFunction (paramType);

params.push_back (std::make_unique<juce::AudioParameterFloat> (
juce::ParameterID {FFCompParameterID()[i], ValentineParameterVersion},
Expand Down Expand Up @@ -231,7 +232,8 @@ void ValentineAudioProcessor::changeProgramName (int, const juce::String&)
//==============================================================================
void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
const auto oversampleMultiplier = static_cast<int> (pow (2, kOversampleFactor));
const auto oversampleMultiplier =
static_cast<int> (pow (2, detail::kOversampleFactor));

processBuffer.setSize (2, samplesPerBlock);
processBuffer.clear();
Expand All @@ -249,14 +251,14 @@ void ValentineAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBl

saturator->reset (sampleRate);
boundedSaturator->reset (sampleRate);
simpleZOH->setParams (static_cast<float> (sampleRate / kDownSampleRate));
simpleZOH->setParams (static_cast<float> (sampleRate / detail::kDownSampleRate));

updateLatencyCompensation (true);

dryWet.reset (sampleRate, kDryWetRampLength);
dryWet.reset (sampleRate, detail::kDryWetRampLength);

const auto rmsWindow =
juce::roundToInt (kRmsTime * 0.001f * sampleRate / samplesPerBlock);
juce::roundToInt (detail::kRmsTime * 0.001f * sampleRate / samplesPerBlock);
inputMeterSource.resize (getTotalNumInputChannels(), rmsWindow);

grMeterSource.resize (1, rmsWindow);
Expand Down Expand Up @@ -601,11 +603,11 @@ void ValentineAudioProcessor::initializeDSP()
std::make_unique<Saturation> (Saturation::Type::inverseHyperbolicSineInterp, .6f);

boundedSaturator = std::make_unique<Saturation> (Saturation::Type::hyperbolicTangent);
boundedSaturator->setParams (kNeg6dbGain);
boundedSaturator->setParams (detail::kNeg6dbGain);

oversampler =
std::make_unique<Oversampling> (2,
kOversampleFactor,
detail::kOversampleFactor,
Oversampling::filterHalfBandPolyphaseIIR);
simpleZOH = std::make_unique<SimpleZOH>();
bitCrush = std::make_unique<Bitcrusher>();
Expand Down

0 comments on commit 41081b4

Please sign in to comment.