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 9, 2023
1 parent e96e1f9 commit 8be1b18
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,15 +15,15 @@

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

namespace
namespace detail
{
inline constexpr float kNeg6dbGain = 0.5011872336f;
inline constexpr int kOversampleFactor = 2;
inline constexpr float kDownSampleRate = 27500.0f;
inline constexpr float kRmsTime = 50.0f;
inline constexpr double kDryWetRampLength = .10;

juce::String precisionShiftingValueString (float value)
inline juce::String precisionShiftingValueString (float value)
{
const auto absValue = std::abs (value);

Expand All @@ -38,7 +38,8 @@ juce::String precisionShiftingValueString (float value)
return juce::String (static_cast<int> (value));
}

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

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

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

params.push_back (std::make_unique<juce::AudioParameterFloat> (
juce::ParameterID {FFCompParameterID()[i], ValentineParameterVersion},
Expand Down Expand Up @@ -227,7 +228,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 @@ -245,14 +247,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 @@ -597,11 +599,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 8be1b18

Please sign in to comment.