@@ -18,6 +18,7 @@ class GainPlugin final
1818 using namespace juce ;
1919 apvts = std::make_unique<AudioProcessorValueTreeState>(*this , nullptr , " state" , createParameterLayout ());
2020 gainValue = apvts->getRawParameterValue (" gain" );
21+ gain2Value = apvts->getRawParameterValue (" gain2" );
2122 midiEnabled = apvts->getRawParameterValue (" midi" );
2223 midiChannel = apvts->getRawParameterValue (" ch" );
2324 midiCc = apvts->getRawParameterValue (" cc" );
@@ -56,7 +57,8 @@ class GainPlugin final
5657 void prepareToPlay (double sampleRate, int samplesPerBlock) override
5758 {
5859 juce::ignoreUnused (sampleRate, samplesPerBlock);
59- gainValueSmoothed.reset (sampleRate, 0 .05f ); // Smooth the gain value with a time constant of 50ms
60+ gainValueSmoothed.reset (sampleRate, 0 .05f ); // Smooth the gain value with a time constant of 50ms
61+ gain2ValueSmoothed.reset (sampleRate, 0 .05f ); // Smooth the gain2 value with a time constant of 50ms
6062 }
6163
6264 void releaseResources () override
@@ -66,6 +68,8 @@ class GainPlugin final
6668 void processBlock (juce::AudioBuffer<float >& buffer, juce::MidiBuffer& midiBuffer) override
6769 {
6870 auto gain = gainValue->load (std::memory_order_acquire);
71+ auto gain2Db = gain2Value->load (std::memory_order_acquire);
72+ auto gain2Linear = juce::Decibels::decibelsToGain (gain2Db);
6973
7074 if (midiEnabled->load (std::memory_order_acquire) > 0 .5f )
7175 {
@@ -89,10 +93,15 @@ class GainPlugin final
8993 for (int channel = 0 ; channel < buffer.getNumChannels (); ++channel)
9094 {
9195 gainValueSmoothed.setTargetValue (gain);
96+ gain2ValueSmoothed.setTargetValue (gain2Linear);
9297 auto * readPtr = buffer.getReadPointer (channel);
9398 auto * writePtr = buffer.getWritePointer (channel);
9499 for (int sample = 0 ; sample < buffer.getNumSamples (); ++sample)
95- writePtr[sample] = readPtr[sample] * gainValueSmoothed.getNextValue ();
100+ {
101+ auto currentGain = gainValueSmoothed.getNextValue ();
102+ auto currentGain2 = gain2ValueSmoothed.getNextValue ();
103+ writePtr[sample] = readPtr[sample] * currentGain * currentGain2;
104+ }
96105 }
97106
98107 if (midiLearn->load (std::memory_order_acquire) > 0 .5f )
@@ -218,17 +227,25 @@ class GainPlugin final
218227
219228 params.push_back (std::make_unique<AudioParameterBool>(ParameterID{" learn" , 1 }, " Learn" , false ));
220229
230+ // Gain2 parameter with -30 to +30 dB range
231+ auto gain2Range = NormalisableRange<float >(-30 .0f , 30 .0f , 0 .1f , 1 .0f );
232+ params.push_back (
233+ std::make_unique<AudioParameterFloat>(ParameterID{" gain2" , 1 }, " Gainsborough" , gain2Range, 0 .0f )
234+ );
235+
221236 return {params.begin (), params.end ()};
222237 }
223238
224239 std::unique_ptr<juce::AudioProcessorValueTreeState> apvts;
225240 std::atomic<float >* gainValue = nullptr ;
241+ std::atomic<float >* gain2Value = nullptr ;
226242 std::atomic<float >* midiEnabled = nullptr ;
227243 std::atomic<float >* midiChannel = nullptr ;
228244 std::atomic<float >* midiCc = nullptr ;
229245 std::atomic<float >* midiLearn = nullptr ;
230246
231247 juce::LinearSmoothedValue<float > gainValueSmoothed;
248+ juce::LinearSmoothedValue<float > gain2ValueSmoothed;
232249
233250 juce::RangedAudioParameter* gainParam = nullptr ;
234251 juce::RangedAudioParameter* channelParam = nullptr ;
0 commit comments