diff --git a/Assets/CrilleBassStrip.png b/Assets/CrilleBassStrip.png new file mode 100644 index 0000000..4b85fb9 Binary files /dev/null and b/Assets/CrilleBassStrip.png differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f7263c..2364e77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,9 @@ juce_add_gui_app(CrilleBassStripApp PRODUCT_NAME "Crille Bass Strip" COMPANY_NAME "Crille Audio" BUNDLE_ID "org.crilleaudio.crillebassstrip" + + ICON_BIG "${CMAKE_CURRENT_SOURCE_DIR}/Assets/CrilleBassStrip.png" + ICON_SMALL "${CMAKE_CURRENT_SOURCE_DIR}/Assets/CrilleBassStrip.png" ) juce_generate_juce_header(CrilleBassStripApp) diff --git a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Info.plist b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Info.plist index 62e8fbc..d568539 100644 --- a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Info.plist +++ b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Info.plist @@ -6,7 +6,7 @@ CFBundleExecutable Crille Bass Strip CFBundleIconFile - + Icon.icns CFBundleIdentifier org.crilleaudio.crillebassstrip CFBundleName diff --git a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/MacOS/Crille Bass Strip b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/MacOS/Crille Bass Strip index cbbfb8d..e74902e 100755 Binary files a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/MacOS/Crille Bass Strip and b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/MacOS/Crille Bass Strip differ diff --git a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/CrilleBassStrip.icns b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/CrilleBassStrip.icns new file mode 100644 index 0000000..f2096f8 Binary files /dev/null and b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/CrilleBassStrip.icns differ diff --git a/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/RecentFilesMenuTemplate.nib b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/RecentFilesMenuTemplate.nib new file mode 100644 index 0000000..cec7f7c Binary files /dev/null and b/Release/macOS/Standalone/Crille Bass Strip.app/Contents/Resources/RecentFilesMenuTemplate.nib differ diff --git a/Release/macOS/VST3/Crille Bass Strip.vst3/Contents/MacOS/Crille Bass Strip b/Release/macOS/VST3/Crille Bass Strip.vst3/Contents/MacOS/Crille Bass Strip index a411e53..c059964 100755 Binary files a/Release/macOS/VST3/Crille Bass Strip.vst3/Contents/MacOS/Crille Bass Strip and b/Release/macOS/VST3/Crille Bass Strip.vst3/Contents/MacOS/Crille Bass Strip differ diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 19c21e0..f7d0dae 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -212,6 +212,61 @@ void CrilleBassStripAudioProcessorEditor::LevelMeter::paint( ); } +CrilleBassStripAudioProcessorEditor::SectionToggleButton:: +SectionToggleButton( + const juce::String& sectionName, + juce::Colour activeColour) + : juce::ToggleButton(sectionName), + sectionColour(activeColour) +{ + setClickingTogglesState(true); + setMouseCursor(juce::MouseCursor::PointingHandCursor); +} + +void CrilleBassStripAudioProcessorEditor::SectionToggleButton::paintButton( + juce::Graphics& g, + bool shouldDrawButtonAsHighlighted, + bool shouldDrawButtonAsDown) +{ + const bool active = getToggleState(); + const auto bounds = getLocalBounds().toFloat(); + + const float ledSize = 9.0f; + auto ledBounds = juce::Rectangle( + 5.0f, + (bounds.getHeight() - ledSize) * 0.5f, + ledSize, + ledSize); + + auto ledColour = active + ? sectionColour + : juce::Colour(0xff454a51); + + if (shouldDrawButtonAsDown) + ledColour = ledColour.brighter(0.25f); + else if (shouldDrawButtonAsHighlighted) + ledColour = ledColour.brighter(0.12f); + + g.setColour(ledColour.withAlpha(active ? 0.25f : 0.12f)); + g.fillEllipse(ledBounds.expanded(3.0f)); + + g.setColour(ledColour); + g.fillEllipse(ledBounds); + + g.setColour(active + ? juce::Colour(0xfff0f1f2) + : juce::Colour(0xff686e76)); + + g.setFont(juce::Font(15.0f, juce::Font::bold)); + g.drawText( + getButtonText(), + 20, + 0, + getWidth() - 25, + getHeight(), + juce::Justification::centred); +} + CrilleBassStripAudioProcessorEditor:: CrilleBassStripAudioProcessorEditor( CrilleBassStripAudioProcessor& p) @@ -251,6 +306,43 @@ CrilleBassStripAudioProcessorEditor( downTuneButton ); + addAndMakeVisible(gateToggleButton); + addAndMakeVisible(compressorToggleButton); + addAndMakeVisible(distortionToggleButton); + addAndMakeVisible(eqToggleButton); + + gateToggleAttachment = + std::make_unique< + juce::AudioProcessorValueTreeState::ButtonAttachment + >( + processor.apvts, + "gateOn", + gateToggleButton); + + compressorToggleAttachment = + std::make_unique< + juce::AudioProcessorValueTreeState::ButtonAttachment + >( + processor.apvts, + "compressorOn", + compressorToggleButton); + + distortionToggleAttachment = + std::make_unique< + juce::AudioProcessorValueTreeState::ButtonAttachment + >( + processor.apvts, + "distortionOn", + distortionToggleButton); + + eqToggleAttachment = + std::make_unique< + juce::AudioProcessorValueTreeState::ButtonAttachment + >( + processor.apvts, + "eqOn", + eqToggleButton); + addKnob( "gateThreshold", "THRESHOLD" @@ -325,6 +417,8 @@ CrilleBassStripAudioProcessorEditor( addAndMakeVisible(compressorInputMeter); addAndMakeVisible(compressorReductionMeter); + updateSectionStates(); + setSize(760, 720); startTimerHz(30); } @@ -399,6 +493,40 @@ void CrilleBassStripAudioProcessorEditor::addKnob( knobs.push_back(std::move(k)); } +void CrilleBassStripAudioProcessorEditor::setKnobSectionEnabled( + int firstKnob, + int numberOfKnobs, + bool enabled) +{ + const float alpha = enabled ? 1.0f : 0.35f; + + for (int i = firstKnob; + i < firstKnob + numberOfKnobs; + ++i) + { + knobs[static_cast(i)]->slider.setEnabled(enabled); + knobs[static_cast(i)]->slider.setAlpha(alpha); + knobs[static_cast(i)]->label.setAlpha(alpha); + } +} + +void CrilleBassStripAudioProcessorEditor::updateSectionStates() +{ + const bool gateEnabled = gateToggleButton.getToggleState(); + const bool compressorEnabled = compressorToggleButton.getToggleState(); + const bool distortionEnabled = distortionToggleButton.getToggleState(); + const bool eqEnabled = eqToggleButton.getToggleState(); + + setKnobSectionEnabled(0, 3, gateEnabled); + setKnobSectionEnabled(3, 3, compressorEnabled); + setKnobSectionEnabled(6, 3, distortionEnabled); + setKnobSectionEnabled(9, 5, eqEnabled); + + gateInputMeter.setAlpha(gateEnabled ? 1.0f : 0.25f); + compressorInputMeter.setAlpha(compressorEnabled ? 1.0f : 0.25f); + compressorReductionMeter.setAlpha(compressorEnabled ? 1.0f : 0.25f); +} + float CrilleBassStripAudioProcessorEditor::smoothMeter( float current, float target, @@ -414,6 +542,8 @@ float CrilleBassStripAudioProcessorEditor::smoothMeter( void CrilleBassStripAudioProcessorEditor::timerCallback() { + updateSectionStates(); + smoothedGateDb = smoothMeter( smoothedGateDb, @@ -499,70 +629,55 @@ void CrilleBassStripAudioProcessorEditor::paint( juce::Justification::centredLeft ); - const struct + const bool panelStates[] { - juce::Rectangle bounds; - juce::String title; - juce::Colour border; - } - panels[] - { - { - { 15, 85, 180, 300 }, - "DOWNTUNE", - juce::Colour(0xff4b79a8) - }, - { - { 205, 85, 265, 300 }, - "NOISE GATE", - juce::Colour(0xff3c424a) - }, - { - { 480, 85, 265, 300 }, - "COMPRESSOR", - juce::Colour(0xff3c424a) - }, - { - { 15, 395, 300, 310 }, - "DISTORTION", - juce::Colour(0xffb85c45) - }, - { - { 325, 395, 420, 310 }, - "EQUALIZER", - juce::Colour(0xff3c424a) - } + downTuneButton.getToggleState(), + gateToggleButton.getToggleState(), + compressorToggleButton.getToggleState(), + distortionToggleButton.getToggleState(), + eqToggleButton.getToggleState() }; - for (const auto& panel : panels) + const juce::Rectangle panelBounds[] { - auto bounds = panel.bounds; + { 15, 85, 180, 300 }, + { 205, 85, 265, 300 }, + { 480, 85, 265, 300 }, + { 15, 395, 300, 310 }, + { 325, 395, 420, 310 } + }; - g.setColour(juce::Colour(0xff1b1f24)); + for (int i = 0; i < 5; ++i) + { + const auto bounds = panelBounds[i].toFloat(); + const bool active = panelStates[i]; - g.fillRoundedRectangle( - bounds.toFloat(), - 10.0f - ); + g.setColour(active + ? juce::Colour(0xff1b1f24) + : juce::Colour(0xff171a1e)); - g.setColour(panel.border); + g.fillRoundedRectangle(bounds, 10.0f); - g.drawRoundedRectangle( - bounds.toFloat(), - 10.0f, - 2.0f - ); + g.setColour(active + ? juce::Colour(0xff4a5058) + : juce::Colour(0xff2a2e34)); - g.setColour(juce::Colour(0xfff0f1f2)); - g.setFont(15.0f); - - g.drawText( - panel.title, - bounds.removeFromTop(38), - juce::Justification::centred - ); + g.drawRoundedRectangle(bounds, 10.0f, 2.0f); } + g.setColour(downTuneButton.getToggleState() + ? juce::Colour(0xfff0f1f2) + : juce::Colour(0xff686e76)); + + g.setFont(juce::Font(15.0f, juce::Font::bold)); + g.drawText( + "DOWNTUNE", + 15, + 85, + 180, + 38, + juce::Justification::centred); + const float inputFrequency = processor.getDetectedFrequencyHz(); @@ -722,6 +837,30 @@ void CrilleBassStripAudioProcessorEditor::paint( void CrilleBassStripAudioProcessorEditor::resized() { + gateToggleButton.setBounds( + 245, + 91, + 185, + 28); + + compressorToggleButton.setBounds( + 520, + 91, + 185, + 28); + + distortionToggleButton.setBounds( + 70, + 401, + 190, + 28); + + eqToggleButton.setBounds( + 435, + 401, + 200, + 28); + downTuneButton.setBounds( 35, 135, diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 4ec4959..94336b7 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -1,12 +1,16 @@ #pragma once + #include #include "PluginProcessor.h" -class CrilleBassStripAudioProcessorEditor final : public juce::AudioProcessorEditor, - private juce::Timer +class CrilleBassStripAudioProcessorEditor final + : public juce::AudioProcessorEditor, + private juce::Timer { public: - explicit CrilleBassStripAudioProcessorEditor(CrilleBassStripAudioProcessor&); + explicit CrilleBassStripAudioProcessorEditor( + CrilleBassStripAudioProcessor&); + ~CrilleBassStripAudioProcessorEditor() override = default; void paint(juce::Graphics&) override; @@ -16,9 +20,14 @@ private: class LevelMeter final : public juce::Component { public: - enum class Mode { inputLevel, gainReduction }; + enum class Mode + { + inputLevel, + gainReduction + }; explicit LevelMeter(Mode meterMode); + void setLevel(float newLevelDb); void setThreshold(float newThresholdDb); void paint(juce::Graphics&) override; @@ -29,6 +38,22 @@ private: float thresholdDb = -80.0f; }; + class SectionToggleButton final : public juce::ToggleButton + { + public: + SectionToggleButton( + const juce::String& sectionName, + juce::Colour activeColour); + + void paintButton( + juce::Graphics& g, + bool shouldDrawButtonAsHighlighted, + bool shouldDrawButtonAsDown) override; + + private: + juce::Colour sectionColour; + }; + struct Knob { juce::Slider slider; @@ -36,25 +61,90 @@ private: }; CrilleBassStripAudioProcessor& processor; + std::vector> knobs; - std::vector> attachments; -juce::ToggleButton downTuneButton; -std::unique_ptr< - juce::AudioProcessorValueTreeState::ButtonAttachment -> downTuneAttachment; + std::vector> + attachments; - LevelMeter gateInputMeter { LevelMeter::Mode::inputLevel }; - LevelMeter compressorInputMeter { LevelMeter::Mode::inputLevel }; - LevelMeter compressorReductionMeter { LevelMeter::Mode::gainReduction }; + juce::ToggleButton downTuneButton; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + downTuneAttachment; + + SectionToggleButton gateToggleButton { + "NOISE GATE", + juce::Colour(0xffe5a536) + }; + + SectionToggleButton compressorToggleButton { + "COMPRESSOR", + juce::Colour(0xffe5a536) + }; + + SectionToggleButton distortionToggleButton { + "DISTORTION", + juce::Colour(0xffd26b4f) + }; + + SectionToggleButton eqToggleButton { + "EQUALIZER", + juce::Colour(0xffe5a536) + }; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + gateToggleAttachment; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + compressorToggleAttachment; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + distortionToggleAttachment; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + eqToggleAttachment; + + LevelMeter gateInputMeter { + LevelMeter::Mode::inputLevel + }; + + LevelMeter compressorInputMeter { + LevelMeter::Mode::inputLevel + }; + + LevelMeter compressorReductionMeter { + LevelMeter::Mode::gainReduction + }; float smoothedGateDb = -80.0f; float smoothedCompressorDb = -80.0f; float smoothedReductionDb = 0.0f; - void addKnob(const juce::String& parameter, const juce::String& caption); - void timerCallback() override; - static float smoothMeter(float current, float target, float attack, float release); + void addKnob( + const juce::String& parameter, + const juce::String& caption); - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessorEditor) -}; + void timerCallback() override; + + void updateSectionStates(); + + void setKnobSectionEnabled( + int firstKnob, + int numberOfKnobs, + bool enabled); + + static float smoothMeter( + float current, + float target, + float attack, + float release); + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR( + CrilleBassStripAudioProcessorEditor) +}; \ No newline at end of file diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 3cb100f..bbdb242 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -21,24 +21,130 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso { using P = juce::AudioParameterFloat; juce::AudioProcessorValueTreeState::ParameterLayout p; + p.add(std::make_unique( - pid("downTuneOn"), - "DownTune", - false)); - p.add(std::make_unique

(pid("gateThreshold"), "Gate Threshold", juce::NormalisableRange(-80.f, -10.f, 0.1f), -45.f, "dB")); - p.add(std::make_unique

(pid("gateRelease"), "Gate Release", juce::NormalisableRange(20.f, 500.f, 1.f, 0.5f), 150.f, "ms")); - p.add(std::make_unique

(pid("gateGain"), "Gate Gain", juce::NormalisableRange(-24.f, 12.f, 0.1f), 0.f, "dB")); - p.add(std::make_unique

(pid("compThreshold"), "Comp Threshold", juce::NormalisableRange(-60.f, 0.f, 0.1f), -18.f, "dB")); - p.add(std::make_unique

(pid("compRatio"), "Comp Ratio", juce::NormalisableRange(1.f, 20.f, 0.1f, 0.5f), 4.f, ":1")); - p.add(std::make_unique

(pid("compGain"), "Comp Gain", juce::NormalisableRange(-12.f, 18.f, 0.1f), 3.f, "dB")); - p.add(std::make_unique

(pid("drive"), "Drive", juce::NormalisableRange(0.f, 24.f, 0.1f), 5.f, "dB")); - p.add(std::make_unique

(pid("mix"), "Distortion Mix", juce::NormalisableRange(0.f, 100.f, 1.f), 25.f, "%")); - p.add(std::make_unique

(pid("distGain"), "Distortion Gain", juce::NormalisableRange(-18.f, 12.f, 0.1f), 0.f, "dB")); - p.add(std::make_unique

(pid("bass"), "Bass", juce::NormalisableRange(-12.f, 12.f, 0.1f), 2.f, "dB")); - p.add(std::make_unique

(pid("lowMid"), "Low Mid", juce::NormalisableRange(-12.f, 12.f, 0.1f), -2.f, "dB")); - p.add(std::make_unique

(pid("middle"), "Middle", juce::NormalisableRange(-12.f, 12.f, 0.1f), 0.f, "dB")); - p.add(std::make_unique

(pid("treble"), "Treble", juce::NormalisableRange(-12.f, 12.f, 0.1f), 1.f, "dB")); - p.add(std::make_unique

(pid("output"), "Output", juce::NormalisableRange(-24.f, 12.f, 0.1f), -1.f, "dB")); + pid("downTuneOn"), + "DownTune", + false)); + + p.add(std::make_unique( + pid("gateOn"), + "Gate On", + true)); + + p.add(std::make_unique( + pid("compressorOn"), + "Compressor On", + true)); + + p.add(std::make_unique( + pid("distortionOn"), + "Distortion On", + true)); + + p.add(std::make_unique( + pid("eqOn"), + "EQ On", + true)); + + p.add(std::make_unique

( + pid("gateThreshold"), + "Gate Threshold", + juce::NormalisableRange(-80.f, -10.f, 0.1f), + -55.f, + "dB")); + + p.add(std::make_unique

( + pid("gateRelease"), + "Gate Release", + juce::NormalisableRange(20.f, 500.f, 1.f, 0.5f), + 150.f, + "ms")); + + p.add(std::make_unique

( + pid("gateGain"), + "Gate Gain", + juce::NormalisableRange(-24.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("compThreshold"), + "Comp Threshold", + juce::NormalisableRange(-60.f, 0.f, 0.1f), + -30.f, + "dB")); + + p.add(std::make_unique

( + pid("compRatio"), + "Comp Ratio", + juce::NormalisableRange(1.f, 20.f, 0.1f, 0.5f), + 3.f, + ":1")); + + p.add(std::make_unique

( + pid("compGain"), + "Comp Gain", + juce::NormalisableRange(-12.f, 18.f, 0.1f), + 2.f, + "dB")); + + p.add(std::make_unique

( + pid("drive"), + "Drive", + juce::NormalisableRange(0.f, 24.f, 0.1f), + 5.f, + "dB")); + + p.add(std::make_unique

( + pid("mix"), + "Distortion Mix", + juce::NormalisableRange(0.f, 100.f, 1.f), + 25.f, + "%")); + + p.add(std::make_unique

( + pid("distGain"), + "Distortion Gain", + juce::NormalisableRange(-18.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("bass"), + "Bass", + juce::NormalisableRange(-12.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("lowMid"), + "Low Mid", + juce::NormalisableRange(-12.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("middle"), + "Middle", + juce::NormalisableRange(-12.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("treble"), + "Treble", + juce::NormalisableRange(-12.f, 12.f, 0.1f), + 0.f, + "dB")); + + p.add(std::make_unique

( + pid("output"), + "Output", + juce::NormalisableRange(-24.f, 12.f, 0.1f), + 0.f, + "dB")); + return p; } @@ -60,14 +166,16 @@ void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block) setLatencySamples( downTune.inputLatency() + downTune.outputLatency()); + downTuneLatencyMs = - 1000.0 * - (downTune.inputLatency() + downTune.outputLatency()) / - sr; + 1000.0 * + (downTune.inputLatency() + downTune.outputLatency()) / + sr; + //debug börjar DBG("DownTune input latency: " - << downTune.inputLatency() - << " samples"); + << downTune.inputLatency() + << " samples"); DBG("DownTune output latency: " << downTune.outputLatency() @@ -80,40 +188,61 @@ void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block) DBG("DownTune latency ms: " << 1000.0 * (downTune.inputLatency() + downTune.outputLatency()) / sr); // debug slutar - juce::dsp::ProcessSpec spec { sr, static_cast(block), static_cast(getTotalNumOutputChannels()) }; + + juce::dsp::ProcessSpec spec { + sr, + static_cast(block), + static_cast(getTotalNumOutputChannels()) + }; + compressor.prepare(spec); lowShelf.prepare(spec); lowMid.prepare(spec); mid.prepare(spec); highShelf.prepare(spec); + compressor.reset(); lowShelf.reset(); lowMid.reset(); mid.reset(); highShelf.reset(); - gateEnvelope.assign(static_cast(getTotalNumOutputChannels()), 0.f); + + gateEnvelope.assign( + static_cast(getTotalNumOutputChannels()), + 0.f); + gateInputLevelDb.store(meterFloorDb); compressorInputLevelDb.store(meterFloorDb); compressorGainReductionDb.store(0.0f); + updateFilters(); } bool CrilleBassStripAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const { - const auto input = layouts.getMainInputChannelSet(); + const auto input = layouts.getMainInputChannelSet(); const auto output = layouts.getMainOutputChannelSet(); return input == juce::AudioChannelSet::mono() && output == juce::AudioChannelSet::stereo(); } -float CrilleBassStripAudioProcessor::getBufferPeak(const juce::AudioBuffer& buffer) noexcept +float CrilleBassStripAudioProcessor::getBufferPeak( + const juce::AudioBuffer& buffer) noexcept { float peak = 0.0f; + for (int channel = 0; channel < buffer.getNumChannels(); ++channel) - peak = juce::jmax(peak, buffer.getMagnitude(channel, 0, buffer.getNumSamples())); + peak = juce::jmax( + peak, + buffer.getMagnitude( + channel, + 0, + buffer.getNumSamples())); + return peak; } + void CrilleBassStripAudioProcessor::updatePitchDetector( const float* input, int numSamples) @@ -302,21 +431,67 @@ void CrilleBassStripAudioProcessor::analysePitch() void CrilleBassStripAudioProcessor::updateFilters() { - const auto bass = apvts.getRawParameterValue("bass")->load(); - const auto lm = apvts.getRawParameterValue("lowMid")->load(); - const auto m = apvts.getRawParameterValue("middle")->load(); - const auto tr = apvts.getRawParameterValue("treble")->load(); - *lowShelf.state = *juce::dsp::IIR::Coefficients::makeLowShelf(currentSampleRate, 80.0, 0.707, dbToGain(bass)); - *lowMid.state = *juce::dsp::IIR::Coefficients::makePeakFilter(currentSampleRate, 300.0, 0.8, dbToGain(lm)); - *mid.state = *juce::dsp::IIR::Coefficients::makePeakFilter(currentSampleRate, 900.0, 0.8, dbToGain(m)); - *highShelf.state = *juce::dsp::IIR::Coefficients::makeHighShelf(currentSampleRate, 3500.0, 0.707, dbToGain(tr)); + const auto bass = + apvts.getRawParameterValue("bass")->load(); + + const auto lm = + apvts.getRawParameterValue("lowMid")->load(); + + const auto m = + apvts.getRawParameterValue("middle")->load(); + + const auto tr = + apvts.getRawParameterValue("treble")->load(); + + *lowShelf.state = + *juce::dsp::IIR::Coefficients::makeLowShelf( + currentSampleRate, + 80.0, + 0.707, + dbToGain(bass)); + + *lowMid.state = + *juce::dsp::IIR::Coefficients::makePeakFilter( + currentSampleRate, + 300.0, + 0.8, + dbToGain(lm)); + + *mid.state = + *juce::dsp::IIR::Coefficients::makePeakFilter( + currentSampleRate, + 900.0, + 0.8, + dbToGain(m)); + + *highShelf.state = + *juce::dsp::IIR::Coefficients::makeHighShelf( + currentSampleRate, + 3500.0, + 0.707, + dbToGain(tr)); } -void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffer, juce::MidiBuffer&) +void CrilleBassStripAudioProcessor::processBlock( + juce::AudioBuffer& buffer, + juce::MidiBuffer&) { juce::ScopedNoDenormals noDenormals; const int numSamples = buffer.getNumSamples(); + + const bool gateEnabled = + apvts.getRawParameterValue("gateOn")->load() > 0.5f; + + const bool compressorEnabled = + apvts.getRawParameterValue("compressorOn")->load() > 0.5f; + + const bool distortionEnabled = + apvts.getRawParameterValue("distortionOn")->load() > 0.5f; + + const bool eqEnabled = + apvts.getRawParameterValue("eqOn")->load() > 0.5f; + if (buffer.getNumChannels() > 0) { updatePitchDetector( @@ -370,47 +545,65 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe // Copy the processed mono bass signal to both stereo output channels. if (buffer.getNumChannels() >= 2) buffer.copyFrom(1, 0, buffer, 0, 0, numSamples); - + // Measure input level before the noise gate. const float gateInputPeak = getBufferPeak(buffer); + gateInputLevelDb.store( - juce::Decibels::gainToDecibels(gateInputPeak, meterFloorDb), + juce::Decibels::gainToDecibels( + gateInputPeak, + meterFloorDb), std::memory_order_relaxed); // Noise gate - const float threshold = - dbToGain(apvts.getRawParameterValue("gateThreshold")->load()); - - const float releaseMs = - apvts.getRawParameterValue("gateRelease")->load(); - - const float releaseCoeff = - std::exp(-1.f / (0.001f * releaseMs * - static_cast(currentSampleRate))); - - const float gateGain = - dbToGain(apvts.getRawParameterValue("gateGain")->load()); - - for (int c = 0; c < buffer.getNumChannels(); ++c) + if (gateEnabled) { - auto* x = buffer.getWritePointer(c); - auto& env = gateEnvelope[static_cast(c)]; + const float threshold = + dbToGain( + apvts.getRawParameterValue("gateThreshold")->load()); - for (int i = 0; i < buffer.getNumSamples(); ++i) + const float releaseMs = + apvts.getRawParameterValue("gateRelease")->load(); + + const float releaseCoeff = + std::exp( + -1.f / + (0.001f * releaseMs * + static_cast(currentSampleRate))); + + const float gateGain = + dbToGain( + apvts.getRawParameterValue("gateGain")->load()); + + for (int c = 0; c < buffer.getNumChannels(); ++c) { - const float target = - std::abs(x[i]) >= threshold ? 1.f : 0.f; + auto* x = buffer.getWritePointer(c); + auto& env = gateEnvelope[static_cast(c)]; - env = target > env - ? target - : releaseCoeff * env; + for (int i = 0; i < buffer.getNumSamples(); ++i) + { + const float target = + std::abs(x[i]) >= threshold ? 1.f : 0.f; - x[i] *= env * gateGain; + env = target > env + ? target + : releaseCoeff * env; + + x[i] *= env * gateGain; + } } } + else + { + std::fill( + gateEnvelope.begin(), + gateEnvelope.end(), + 1.0f); + } // Measure compressor input level. - const float compressorInputPeak = getBufferPeak(buffer); + const float compressorInputPeak = + getBufferPeak(buffer); compressorInputLevelDb.store( juce::Decibels::gainToDecibels( @@ -418,73 +611,95 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe meterFloorDb), std::memory_order_relaxed); - // Compressor - compressor.setThreshold( - apvts.getRawParameterValue("compThreshold")->load()); - - compressor.setRatio( - apvts.getRawParameterValue("compRatio")->load()); - - compressor.setAttack(15.f); - compressor.setRelease(100.f); - juce::dsp::AudioBlock block(buffer); juce::dsp::ProcessContextReplacing context(block); - compressor.process(context); + // Compressor + if (compressorEnabled) + { + compressor.setThreshold( + apvts.getRawParameterValue("compThreshold")->load()); - // Calculate compressor gain reduction. - const float compressorOutputPeak = getBufferPeak(buffer); + compressor.setRatio( + apvts.getRawParameterValue("compRatio")->load()); - const float gainReduction = - compressorInputPeak > 0.0f - ? juce::jmax( - 0.0f, - juce::Decibels::gainToDecibels( - compressorInputPeak / - juce::jmax(compressorOutputPeak, 1.0e-9f))) - : 0.0f; + compressor.setAttack(15.f); + compressor.setRelease(100.f); + compressor.process(context); - compressorGainReductionDb.store( - juce::jlimit(0.0f, 24.0f, gainReduction), - std::memory_order_relaxed); + // Calculate compressor gain reduction. + const float compressorOutputPeak = + getBufferPeak(buffer); - // Compressor makeup gain. - buffer.applyGain( - dbToGain( - apvts.getRawParameterValue("compGain")->load())); + const float gainReduction = + compressorInputPeak > 0.0f + ? juce::jmax( + 0.0f, + juce::Decibels::gainToDecibels( + compressorInputPeak / + juce::jmax( + compressorOutputPeak, + 1.0e-9f))) + : 0.0f; + + compressorGainReductionDb.store( + juce::jlimit( + 0.0f, + 24.0f, + gainReduction), + std::memory_order_relaxed); + + // Compressor makeup gain. + buffer.applyGain( + dbToGain( + apvts.getRawParameterValue("compGain")->load())); + } + else + { + compressorGainReductionDb.store( + 0.0f, + std::memory_order_relaxed); + } // Distortion - const float drive = - dbToGain(apvts.getRawParameterValue("drive")->load()); - - const float mix = - apvts.getRawParameterValue("mix")->load() * 0.01f; - - const float dg = - dbToGain(apvts.getRawParameterValue("distGain")->load()); - - for (int c = 0; c < buffer.getNumChannels(); ++c) + if (distortionEnabled) { - auto* x = buffer.getWritePointer(c); + const float drive = + dbToGain( + apvts.getRawParameterValue("drive")->load()); - for (int i = 0; i < buffer.getNumSamples(); ++i) + const float mix = + apvts.getRawParameterValue("mix")->load() * 0.01f; + + const float dg = + dbToGain( + apvts.getRawParameterValue("distGain")->load()); + + for (int c = 0; c < buffer.getNumChannels(); ++c) { - const float dry = x[i]; - const float wet = std::tanh(dry * drive); + auto* x = buffer.getWritePointer(c); - x[i] = - ((1.f - mix) * dry + mix * wet) * dg; + for (int i = 0; i < buffer.getNumSamples(); ++i) + { + const float dry = x[i]; + const float wet = std::tanh(dry * drive); + + x[i] = + ((1.f - mix) * dry + mix * wet) * dg; + } } } // EQ - updateFilters(); + if (eqEnabled) + { + updateFilters(); - lowShelf.process(context); - lowMid.process(context); - mid.process(context); - highShelf.process(context); + lowShelf.process(context); + lowMid.process(context); + mid.process(context); + highShelf.process(context); + } // Final output gain. buffer.applyGain( @@ -492,20 +707,28 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe apvts.getRawParameterValue("output")->load())); } -void CrilleBassStripAudioProcessor::getStateInformation(juce::MemoryBlock& dest) +void CrilleBassStripAudioProcessor::getStateInformation( + juce::MemoryBlock& dest) { if (auto xml = apvts.copyState().createXml()) copyXmlToBinary(*xml, dest); } -void CrilleBassStripAudioProcessor::setStateInformation(const void* data, int size) +void CrilleBassStripAudioProcessor::setStateInformation( + const void* data, + int size) { if (auto xml = getXmlFromBinary(data, size); - xml != nullptr && xml->hasTagName(apvts.state.getType())) - apvts.replaceState(juce::ValueTree::fromXml(*xml)); + xml != nullptr + && xml->hasTagName(apvts.state.getType())) + { + apvts.replaceState( + juce::ValueTree::fromXml(*xml)); + } } -juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor() +juce::AudioProcessorEditor* +CrilleBassStripAudioProcessor::createEditor() { return new CrilleBassStripAudioProcessorEditor(*this); } @@ -513,4 +736,4 @@ juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor() juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new CrilleBassStripAudioProcessor(); -} +} \ No newline at end of file