Skip to content

Commit ff69577

Browse files
committed
#33 Add limiter checkbox.
1 parent 9118882 commit ff69577

File tree

9 files changed

+95
-22
lines changed

9 files changed

+95
-22
lines changed

Source/Parameters.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Parameters::Parameters(AeolusAudioProcessor& proc)
3131
processor.addParameter(reverbWet = new AudioParameterFloat(ParameterID{"reverb_wet", 1}, "Reverb", 0.0f, 1.0f, 0.25f));
3232
processor.addParameter(volume = new AudioParameterFloat(ParameterID{"volume", 1}, "Volume", 0.0f, 1.0f, 0.5f));
3333

34+
35+
auto onOffAttributes = AudioParameterBoolAttributes()
36+
.withStringFromValueFunction([] (auto x, auto) { return x ? "On" : "Off"; })
37+
.withLabel("enabled");
38+
39+
processor.addParameter(limiterEnabled = new AudioParameterBool(ParameterID{"limiter", 1}, "Limiter", false, onOffAttributes));
40+
3441
auto& engine = proc.getEngine();
3542

3643
for (int i = 0; i < engine.getDivisionCount(); ++i) {

Source/Parameters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct Parameters
3434

3535
std::vector<juce::AudioParameterFloat*> divisionsGain;
3636

37+
juce::AudioParameterBool* limiterEnabled;
38+
3739
Parameters(AeolusAudioProcessor& proc);
3840

3941
juce::var toVar() const;

Source/PluginEditor.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ AeolusAudioProcessorEditor::AeolusAudioProcessorEditor (AeolusAudioProcessor& p)
7373
setScaleFactor(1e-2f * _uiScalingPercent);
7474

7575
addAndMakeVisible(_versionLabel);
76-
_versionLabel.setFont (Font(Font::getDefaultMonospacedFontName(), 10, Font::plain));
76+
_versionLabel.setFont(Font(FontOptions(Font::getDefaultMonospacedFontName(), 10, Font::plain)));
7777
_versionLabel.setJustificationType (Justification::right);
7878

7979
addAndMakeVisible(_cpuLoadLabel);
80-
_cpuLoadValueLabel.setFont (Font(Font::getDefaultMonospacedFontName(), 12, Font::plain));
80+
_cpuLoadValueLabel.setFont(Font(FontOptions(Font::getDefaultMonospacedFontName(), 12, Font::plain)));
8181
_cpuLoadValueLabel.setJustificationType (Justification::right);
8282
_cpuLoadValueLabel.setColour(Label::textColourId, Colours::lightyellow);
8383
addAndMakeVisible(_cpuLoadValueLabel);
8484

8585
addAndMakeVisible(_voiceCountLabel);
86-
_voiceCountValueLabel.setFont (Font(Font::getDefaultMonospacedFontName(), 12, Font::plain));
86+
_voiceCountValueLabel.setFont(Font(FontOptions(Font::getDefaultMonospacedFontName(), 12, Font::plain)));
8787
_voiceCountValueLabel.setJustificationType (Justification::right);
8888
_voiceCountValueLabel.setColour(Label::textColourId, Colours::lightyellow);
8989
addAndMakeVisible(_voiceCountValueLabel);
@@ -207,15 +207,20 @@ AeolusAudioProcessorEditor::AeolusAudioProcessorEditor (AeolusAudioProcessor& p)
207207
}
208208

209209
_fxButton.onClick = [this] {
210-
auto content = std::make_unique<ui::FxComponent>();
211-
content->setSize(240, 220);
210+
auto& params{ _audioProcessor.getParametersContainer() };
211+
auto content = std::make_unique<ui::FxComponent>(params);
212+
content->setSize(240, 120);
212213
auto* contentPtr = content.get();
214+
bool limiterWasEnabled{ _audioProcessor.getParametersContainer().limiterEnabled->get() };
213215

214216
auto& box = CallOutBox::launchAsynchronously(std::move(content), _fxButton.getBounds(), this);
215-
contentPtr->onCancel = [&box] { box.dismiss(); };
216-
contentPtr->onOk = [&box, contentPtr] {
217-
// @todo Enable limiter and set its parameters
218-
//_audioProcessor.getEngine().setReverbWet(contentPtr->getReverbWet());
217+
contentPtr->onCancel = [&box, &params, limiterWasEnabled] {
218+
// Return to the original state
219+
(*params.limiterEnabled) = limiterWasEnabled;
220+
box.dismiss();
221+
};
222+
contentPtr->onOk = [&box, &params, contentPtr] {
223+
(*params.limiterEnabled) = contentPtr->isLimiterEnabled();
219224
box.dismiss();
220225
};
221226
};

Source/PluginProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void AeolusAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::
244244

245245
_engine.setReverbWet(_parameters.reverbWet->get());
246246
_engine.setVolume(_parameters.volume->get());
247+
_engine.enableLimiter(_parameters.limiterEnabled->get());
247248
_engine.process(outL, outR, buffer.getNumSamples(), isNonRealtime());
248249

249250
#endif // AEOLUS_MULTIBUS_OUTPUT

Source/aeolus/engine.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ void EngineGlobal::setMTSEnabled(bool shouldBeEnabled)
244244
void EngineGlobal::setUIScalingFactor(float f)
245245
{
246246
_uiScalingFactor = jlimit(UI_SCALING_MIN, UI_SCALING_MAX, f);
247-
DBG("SCALE: " << _uiScalingFactor);
248247
_listeners.call([&](Listener& listener){ listener.onUIScalingFactorChanged(_uiScalingFactor); });
249248
}
250249

@@ -397,7 +396,7 @@ void EngineGlobal::loadIRs()
397396
std::unique_ptr<AudioFormatReader> reader{manager.createReaderFor(std::move(stream))};
398397
ir.waveform.setSize(reader->numChannels, (int)reader->lengthInSamples);
399398
const auto offset{ (juce::int64)ir.startOffset };
400-
reader->read(&ir.waveform, 0, ir.waveform.getNumSamples() - offset, offset, true, true);
399+
reader->read(&ir.waveform, 0, (int)(ir.waveform.getNumSamples() - offset), offset, true, true);
401400

402401
ir.waveform.applyGain(ir.gain);
403402

@@ -473,8 +472,8 @@ void Engine::prepareToPlay(float sampleRate, int frameSize)
473472
auto* g = EngineGlobal::getInstance();
474473
g->updateStops(SAMPLE_RATE_F);
475474

476-
_limiterSpec.threshold = 0.75f;
477-
_limiterSpec.attack = 10000.0f / sampleRate;
475+
_limiterSpec.threshold = 0.8f;
476+
_limiterSpec.attack = 1000.0f / sampleRate;
478477
_limiterSpec.release = 1.0f / sampleRate;
479478
_limiterSpec.sustain = std::max(0, int(sampleRate * 0.5f));
480479

@@ -533,6 +532,16 @@ void Engine::setVolume(float v)
533532
_params[VOLUME].setValue(v);
534533
}
535534

535+
void Engine::enableLimiter(bool shouldBeEnabled)
536+
{
537+
_limiterEnabled = shouldBeEnabled;
538+
}
539+
540+
bool Engine::isLimiterEnabled() const
541+
{
542+
return _limiterEnabled;
543+
}
544+
536545
void Engine::process(float* outL, float* outR, int numFrames, bool isNonRealtime)
537546
{
538547
jassert(outL != nullptr);
@@ -592,8 +601,10 @@ void Engine::process(float* outL, float* outR, int numFrames, bool isNonRealtime
592601
applyVolume(origOutL, origOutR, origNumFrames);
593602

594603
// Apply limiter
595-
dsp::Limiter::process(_limiterSpec, _limiterState[0], origOutL, origOutL, origNumFrames);
596-
dsp::Limiter::process(_limiterSpec, _limiterState[1], origOutR, origOutR, origNumFrames);
604+
if (_limiterEnabled) {
605+
dsp::Limiter::process(_limiterSpec, _limiterState[0], origOutL, origOutL, origNumFrames);
606+
dsp::Limiter::process(_limiterSpec, _limiterState[1], origOutR, origOutR, origNumFrames);
607+
}
597608

598609
_volumeLevel.left.process(origOutL, origNumFrames);
599610
_volumeLevel.right.process(origOutR, origNumFrames);

Source/aeolus/engine.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ class Engine
262262
*/
263263
Level& getVolumeLevel() noexcept { return _volumeLevel; }
264264

265+
/**
266+
* Enable or disable master limiter.
267+
*/
268+
void enableLimiter(bool shouldBeEnabled);
269+
270+
/**
271+
* @return Whether the limiter is enabled.
272+
*/
273+
bool isLimiterEnabled() const;
274+
265275
/**
266276
* Returns currently set MIDI control channel.
267277
*/
@@ -389,6 +399,7 @@ class Engine
389399
dsp::Limiter::Spec _limiterSpec;
390400
std::array<dsp::Limiter::State, aeolus::N_OUTPUT_CHANNELS> _limiterState;
391401
dsp::Limiter _limiter;
402+
std::atomic<bool> _limiterEnabled{};
392403

393404
dsp::Convolver _convolver;
394405
std::atomic<int> _selectedIR;

Source/ui/CustomLookAndFeel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ namespace ui {
2626
const Font& CustomLookAndFeel::getStopButtonFont()
2727
{
2828

29-
static Font font(Typeface::createSystemTypefaceFor(BinaryData::WignersFriendRoman1GY8e_ttf,
30-
BinaryData::WignersFriendRoman1GY8e_ttfSize));
29+
static Font font(FontOptions(Typeface::createSystemTypefaceFor(BinaryData::WignersFriendRoman1GY8e_ttf,
30+
BinaryData::WignersFriendRoman1GY8e_ttfSize)));
3131

3232
return font;
3333
}
3434

3535
const Font& CustomLookAndFeel::getManualLabelFont()
3636
{
37-
static Font font(Typeface::createSystemTypefaceFor(BinaryData::BalgrufJRye7_ttf,
38-
BinaryData::BalgrufJRye7_ttfSize));
37+
static Font font(FontOptions(Typeface::createSystemTypefaceFor(BinaryData::BalgrufJRye7_ttf,
38+
BinaryData::BalgrufJRye7_ttfSize)));
3939
return font;
4040
}
4141

Source/ui/FxComponent.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ using namespace juce;
2525

2626
namespace ui {
2727

28-
FxComponent::FxComponent()
29-
: _fxLabel {{}, "Effects"}
28+
FxComponent::FxComponent(Parameters& params)
29+
: _parameters{ params }
30+
, _fxLabel {{}, "Effects"}
31+
, _enableLimiterButton{"Enable master limiter"}
3032
, _okButton{"OK"}
3133
, _cancelButton{"Cancel"}
3234
{
@@ -39,6 +41,10 @@ FxComponent::FxComponent()
3941
font.setHeight(font.getHeight() * 1.2f);
4042
_fxLabel.setFont(font);
4143

44+
addAndMakeVisible(_enableLimiterButton);
45+
_enableLimiterButton.onClick = [this] {
46+
updateEnablement();
47+
};
4248

4349
addAndMakeVisible(_okButton);
4450
_okButton.onClick = [this] {
@@ -52,6 +58,8 @@ FxComponent::FxComponent()
5258

5359
_cancelButton.setColour(TextButton::buttonColourId, Colour(0x66, 0x66, 0x33));
5460
_okButton.setColour(TextButton::buttonColourId, Colour(0x66, 0x66, 0x33));
61+
62+
captureState();
5563
}
5664

5765
void FxComponent::resized()
@@ -66,12 +74,30 @@ void FxComponent::resized()
6674
bounds.removeFromTop(3 * margin);
6775

6876
auto row = bounds.removeFromTop(20);
77+
_enableLimiterButton.setBounds(row);
6978

7079
row = bounds.removeFromBottom(20);
7180
_cancelButton.setBounds(row.removeFromRight(60));
7281
row.removeFromRight(margin);
7382
_okButton.setBounds(row.removeFromRight(60));
7483
}
7584

85+
bool FxComponent::isLimiterEnabled() const
86+
{
87+
return _enableLimiterButton.getToggleState();
88+
}
89+
90+
void FxComponent::captureState()
91+
{
92+
_enableLimiterButton.setToggleState(_parameters.limiterEnabled->get(), dontSendNotification);
93+
}
94+
95+
void FxComponent::updateEnablement()
96+
{
97+
// Update limiter enablement so that the effect can be heard immediately
98+
(*_parameters.limiterEnabled) = _enableLimiterButton.getToggleState();
99+
100+
// Update UI component enablement depending on the current selection of the options
101+
}
76102

77103
} // namespace ui

Source/ui/FxComponent.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <functional>
2323
#include "aeolus/globals.h"
24+
#include "Parameters.h"
2425

2526
namespace ui {
2627

@@ -30,17 +31,26 @@ namespace ui {
3031
class FxComponent : public juce::Component
3132
{
3233
public:
33-
FxComponent();
34+
FxComponent(Parameters& engine);
3435

3536
void resized() override;
3637

38+
bool isLimiterEnabled() const;
39+
3740
std::function<void()> onOk{};
3841
std::function<void()> onCancel{};
3942

4043
private:
4144

45+
void captureState();
46+
void updateEnablement();
47+
48+
Parameters& _parameters;
49+
4250
juce::Label _fxLabel;
4351

52+
juce::ToggleButton _enableLimiterButton;
53+
4454
juce::TextButton _okButton;
4555
juce::TextButton _cancelButton;
4656
};

0 commit comments

Comments
 (0)