Skip to content

Commit 8349dc8

Browse files
committed
SimpleDistortionProcessor: modified param strategy to use APVTS instead of APF.
1 parent 3b814cb commit 8349dc8

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

modules/squarepine_audio/core/squarepine_InternalProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class InternalProcessor : public AudioPluginInstance
7676
/** @returns a direct Value to a property inside the APVTS.
7777
7878
If no APVTS is present, or if the Value wasn't found,
79-
this will return an empty Value.
79+
this will return an empty (ie: void) Value.
8080
*/
8181
[[nodiscard]] Value getPropertyAsValue (const Identifier&,
8282
UndoManager* undoManager = nullptr,

modules/squarepine_audio/effects/squarepine_GainProcessor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//==============================================================================
12
namespace
23
{
34
String toStringFromGainValue (float value, int)
@@ -20,12 +21,9 @@ GainProcessor::GainProcessor (NormalisableRange<float> gainRange) :
2021
.withCategory (AudioParameterFloatAttributes::Category::outputGain)
2122
.withLabel (getName())
2223
.withStringFromValueFunction (toStringFromGainValue));
23-
2424
gainParameter = vp.get();
2525
gainParameter->addListener (this);
26-
2726
layout.add (std::move (vp));
28-
2927
setGain (getGain());
3028
resetAPVTSWithLayout (std::move (layout));
3129
}

modules/squarepine_audio/effects/squarepine_SimpleDistortionProcessor.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
//==============================================================================
2-
class SimpleDistortionProcessor::AmountParameter final : public AudioParameterFloat
2+
namespace
33
{
4-
public:
5-
AmountParameter() noexcept :
6-
AudioParameterFloat ("AmountId", TRANS ("Amount"), 0.0f, 1.0f, 0.6f)
4+
String toStringFromDistortionAmountValue (float value, int maximumStringLength)
75
{
6+
auto s = String (static_cast<int> (value * 100.0f))
7+
.substring (0, maximumStringLength - 1);
8+
s << "%";
9+
return s;
810
}
9-
10-
int getNumSteps() const override { return 100; }
11-
String getLabel() const override { return "%"; }
12-
13-
String getText (float v, int maximumStringLength) const override
14-
{
15-
return String (static_cast<int> (v * 100.0f)).substring (0, maximumStringLength);
16-
}
17-
18-
private:
19-
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AmountParameter)
20-
};
11+
}
2112

2213
//==============================================================================
2314
SimpleDistortionProcessor::SimpleDistortionProcessor() :
24-
amountParam (new AmountParameter())
15+
InternalProcessor (false)
2516
{
26-
AudioProcessor::addParameter (amountParam);
17+
auto layout = createDefaultParameterLayout();
18+
19+
auto ap = std::make_unique<AudioParameterFloat> (ParameterID ("amount", 1), TRANS ("Amount"),
20+
NormalisableRange<float> (0.0f, 100.0f, 1.0f), 75.0f,
21+
AudioParameterFloatAttributes()
22+
.withLabel (TRANS ("Amount"))
23+
.withStringFromValueFunction (toStringFromDistortionAmountValue));
24+
amountParameter = ap.get();
25+
layout.add (std::move (ap));
26+
resetAPVTSWithLayout (std::move (layout));
2727
}
2828

2929
//==============================================================================
@@ -39,7 +39,7 @@ void SimpleDistortionProcessor::process (juce::AudioBuffer<FloatType>& buffer)
3939
return;
4040

4141
using DistFuncs = DistortionFunctions<FloatType>;
42-
const auto d = static_cast<FloatType> (amountParam->get());
42+
const auto d = static_cast<FloatType> (amountParameter->get());
4343
DistFuncs::perform (buffer, DistFuncs::sigmoid, d, static_cast<FloatType> (100));
4444
}
4545

modules/squarepine_audio/effects/squarepine_SimpleDistortionProcessor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class SimpleDistortionProcessor final : public InternalProcessor
2121

2222
private:
2323
//==============================================================================
24-
class AmountParameter;
25-
AmountParameter* amountParam = nullptr;
24+
AudioParameterFloat* amountParameter = nullptr;
2625

2726
//==============================================================================
2827
template<typename FloatType>

0 commit comments

Comments
 (0)