Lade till visuella mätare på Gate och Kompressor
This commit is contained in:
1 parent
5b1d22c745
commit
f0570b1313
4 files changed
+295
-38
No files matched your search
+164
-18
@@ -1,13 +1,107 @@
|
|||||||
#include "PluginEditor.h"
|
#include "PluginEditor.h"
|
||||||
|
|
||||||
|
CrilleBassStripAudioProcessorEditor::LevelMeter::LevelMeter(Mode meterMode)
|
||||||
|
: mode(meterMode)
|
||||||
|
{
|
||||||
|
setInterceptsMouseClicks(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::LevelMeter::setLevel(float newLevelDb)
|
||||||
|
{
|
||||||
|
displayedDb = newLevelDb;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::LevelMeter::setThreshold(float newThresholdDb)
|
||||||
|
{
|
||||||
|
thresholdDb = newThresholdDb;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::LevelMeter::paint(juce::Graphics& g)
|
||||||
|
{
|
||||||
|
auto bounds = getLocalBounds().toFloat();
|
||||||
|
auto titleArea = bounds.removeFromTop(18.0f);
|
||||||
|
auto valueArea = bounds.removeFromBottom(20.0f);
|
||||||
|
auto meterArea = bounds.reduced(5.0f, 3.0f);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xffaeb4bc));
|
||||||
|
g.setFont(juce::Font(10.0f, juce::Font::bold));
|
||||||
|
g.drawText(mode == Mode::inputLevel ? "IN" : "GR", titleArea, juce::Justification::centred);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff0b0d10));
|
||||||
|
g.fillRoundedRectangle(meterArea, 3.0f);
|
||||||
|
g.setColour(juce::Colour(0xff3c424a));
|
||||||
|
g.drawRoundedRectangle(meterArea, 3.0f, 1.0f);
|
||||||
|
|
||||||
|
auto inner = meterArea.reduced(3.0f);
|
||||||
|
|
||||||
|
if (mode == Mode::inputLevel)
|
||||||
|
{
|
||||||
|
const float normalized = juce::jmap(juce::jlimit(-80.0f, 0.0f, displayedDb), -80.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
const float litHeight = inner.getHeight() * normalized;
|
||||||
|
auto lit = inner.withTop(inner.getBottom() - litHeight);
|
||||||
|
|
||||||
|
juce::Colour colour = juce::Colour(0xff45c95a);
|
||||||
|
if (displayedDb > -12.0f) colour = juce::Colour(0xffffc247);
|
||||||
|
if (displayedDb > -3.0f) colour = juce::Colour(0xffff5c5c);
|
||||||
|
g.setColour(colour);
|
||||||
|
g.fillRoundedRectangle(lit, 2.0f);
|
||||||
|
|
||||||
|
const float thresholdNorm = juce::jmap(juce::jlimit(-80.0f, 0.0f, thresholdDb), -80.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
const float thresholdY = inner.getBottom() - inner.getHeight() * thresholdNorm;
|
||||||
|
g.setColour(juce::Colours::white.withAlpha(0.9f));
|
||||||
|
g.drawLine(inner.getX() - 2.0f, thresholdY, inner.getRight() + 2.0f, thresholdY, 1.5f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const float normalized = juce::jlimit(0.0f, 1.0f, displayedDb / 24.0f);
|
||||||
|
const float litHeight = inner.getHeight() * normalized;
|
||||||
|
auto lit = inner.withHeight(litHeight);
|
||||||
|
g.setColour(juce::Colour(0xffd34a43));
|
||||||
|
g.fillRoundedRectangle(lit, 2.0f);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff777f89));
|
||||||
|
g.setFont(9.0f);
|
||||||
|
for (float db : { 6.0f, 12.0f, 18.0f })
|
||||||
|
{
|
||||||
|
const float y = inner.getY() + inner.getHeight() * (db / 24.0f);
|
||||||
|
g.drawLine(inner.getX(), y, inner.getRight(), y, 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xffd9dde3));
|
||||||
|
g.setFont(9.5f);
|
||||||
|
const auto value = mode == Mode::inputLevel
|
||||||
|
? juce::String(displayedDb, 1) + " dB"
|
||||||
|
: juce::String(displayedDb, 1) + " dB";
|
||||||
|
g.drawText(value, valueArea, juce::Justification::centred);
|
||||||
|
}
|
||||||
|
|
||||||
CrilleBassStripAudioProcessorEditor::CrilleBassStripAudioProcessorEditor(CrilleBassStripAudioProcessor& p)
|
CrilleBassStripAudioProcessorEditor::CrilleBassStripAudioProcessorEditor(CrilleBassStripAudioProcessor& p)
|
||||||
: AudioProcessorEditor(&p), processor(p)
|
: AudioProcessorEditor(&p), processor(p)
|
||||||
{
|
{
|
||||||
addKnob("gateThreshold", "THRESHOLD"); addKnob("gateRelease", "RELEASE"); addKnob("gateGain", "GAIN");
|
addKnob("gateThreshold", "THRESHOLD");
|
||||||
addKnob("compThreshold", "THRESHOLD"); addKnob("compRatio", "RATIO"); addKnob("compGain", "GAIN");
|
addKnob("gateRelease", "RELEASE");
|
||||||
addKnob("drive", "DRIVE"); addKnob("mix", "MIX"); addKnob("distGain", "GAIN");
|
addKnob("gateGain", "GAIN");
|
||||||
addKnob("bass", "BASS"); addKnob("lowMid", "LOW MID"); addKnob("middle", "MIDDLE"); addKnob("treble", "TREBLE"); addKnob("output", "OUTPUT");
|
addKnob("compThreshold", "THRESHOLD");
|
||||||
setSize(980, 430);
|
addKnob("compRatio", "RATIO");
|
||||||
|
addKnob("compGain", "GAIN");
|
||||||
|
addKnob("drive", "DRIVE");
|
||||||
|
addKnob("mix", "MIX");
|
||||||
|
addKnob("distGain", "GAIN");
|
||||||
|
addKnob("bass", "BASS");
|
||||||
|
addKnob("lowMid", "LOW MID");
|
||||||
|
addKnob("middle", "MIDDLE");
|
||||||
|
addKnob("treble", "TREBLE");
|
||||||
|
addKnob("output", "OUTPUT");
|
||||||
|
|
||||||
|
addAndMakeVisible(gateInputMeter);
|
||||||
|
addAndMakeVisible(compressorInputMeter);
|
||||||
|
addAndMakeVisible(compressorReductionMeter);
|
||||||
|
|
||||||
|
setSize(1080, 430);
|
||||||
|
startTimerHz(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrilleBassStripAudioProcessorEditor::addKnob(const juce::String& id, const juce::String& caption)
|
void CrilleBassStripAudioProcessorEditor::addKnob(const juce::String& id, const juce::String& caption)
|
||||||
@@ -18,33 +112,85 @@ void CrilleBassStripAudioProcessorEditor::addKnob(const juce::String& id, const
|
|||||||
k->slider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour(0xffe5a536));
|
k->slider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour(0xffe5a536));
|
||||||
k->slider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour(0xff30343a));
|
k->slider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour(0xff30343a));
|
||||||
k->slider.setColour(juce::Slider::thumbColourId, juce::Colour(0xffffd275));
|
k->slider.setColour(juce::Slider::thumbColourId, juce::Colour(0xffffd275));
|
||||||
k->label.setText(caption, juce::dontSendNotification); k->label.setJustificationType(juce::Justification::centred);
|
k->label.setText(caption, juce::dontSendNotification);
|
||||||
k->label.setColour(juce::Label::textColourId, juce::Colour(0xffd9dde3)); k->label.setFont(juce::Font(12.f, juce::Font::bold));
|
k->label.setJustificationType(juce::Justification::centred);
|
||||||
addAndMakeVisible(k->slider); addAndMakeVisible(k->label);
|
k->label.setColour(juce::Label::textColourId, juce::Colour(0xffd9dde3));
|
||||||
|
k->label.setFont(juce::Font(12.f, juce::Font::bold));
|
||||||
|
addAndMakeVisible(k->slider);
|
||||||
|
addAndMakeVisible(k->label);
|
||||||
attachments.push_back(std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(processor.apvts, id, k->slider));
|
attachments.push_back(std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(processor.apvts, id, k->slider));
|
||||||
knobs.push_back(std::move(k));
|
knobs.push_back(std::move(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float CrilleBassStripAudioProcessorEditor::smoothMeter(float current, float target, float attack, float release)
|
||||||
|
{
|
||||||
|
const float coefficient = target > current ? attack : release;
|
||||||
|
return current + coefficient * (target - current);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::timerCallback()
|
||||||
|
{
|
||||||
|
smoothedGateDb = smoothMeter(smoothedGateDb, processor.getGateInputLevelDb(), 0.65f, 0.10f);
|
||||||
|
smoothedCompressorDb = smoothMeter(smoothedCompressorDb, processor.getCompressorInputLevelDb(), 0.65f, 0.10f);
|
||||||
|
smoothedReductionDb = smoothMeter(smoothedReductionDb, processor.getCompressorGainReductionDb(), 0.55f, 0.12f);
|
||||||
|
|
||||||
|
gateInputMeter.setLevel(smoothedGateDb);
|
||||||
|
compressorInputMeter.setLevel(smoothedCompressorDb);
|
||||||
|
compressorReductionMeter.setLevel(smoothedReductionDb);
|
||||||
|
|
||||||
|
gateInputMeter.setThreshold(processor.apvts.getRawParameterValue("gateThreshold")->load());
|
||||||
|
compressorInputMeter.setThreshold(processor.apvts.getRawParameterValue("compThreshold")->load());
|
||||||
|
}
|
||||||
|
|
||||||
void CrilleBassStripAudioProcessorEditor::paint(juce::Graphics& g)
|
void CrilleBassStripAudioProcessorEditor::paint(juce::Graphics& g)
|
||||||
{
|
{
|
||||||
g.fillAll(juce::Colour(0xff111317));
|
g.fillAll(juce::Colour(0xff111317));
|
||||||
g.setColour(juce::Colour(0xffe5a536)); g.setFont(juce::Font(28.f, juce::Font::bold));
|
g.setColour(juce::Colour(0xffe5a536));
|
||||||
|
g.setFont(juce::Font(28.f, juce::Font::bold));
|
||||||
g.drawText("CRILLE BASS STRIP", 25, 15, getWidth() - 50, 40, juce::Justification::centredLeft);
|
g.drawText("CRILLE BASS STRIP", 25, 15, getWidth() - 50, 40, juce::Justification::centredLeft);
|
||||||
g.setColour(juce::Colour(0xff777f89)); g.setFont(13.f);
|
g.setColour(juce::Colour(0xff777f89));
|
||||||
|
g.setFont(13.f);
|
||||||
g.drawText("GATE > COMPRESSOR > DISTORTION > EQ", 28, 50, getWidth() - 56, 22, juce::Justification::centredLeft);
|
g.drawText("GATE > COMPRESSOR > DISTORTION > EQ", 28, 50, getWidth() - 56, 22, juce::Justification::centredLeft);
|
||||||
|
|
||||||
const juce::StringArray names { "NOISE GATE", "COMPRESSOR", "DISTORTION", "EQUALIZER" };
|
const juce::StringArray names { "NOISE GATE", "COMPRESSOR", "DISTORTION", "EQUALIZER" };
|
||||||
const int widths[]{205,205,205,315}; int x=15;
|
const int widths[] { 255, 265, 205, 315 };
|
||||||
for (int i=0;i<4;++i) { auto r=juce::Rectangle<int>(x,85,widths[i],325); g.setColour(juce::Colour(0xff1b1f24)); g.fillRoundedRectangle(r.toFloat(),10.f); g.setColour(i==2?juce::Colour(0xffb85c45):juce::Colour(0xff3c424a)); g.drawRoundedRectangle(r.toFloat(),10.f,2.f); g.setColour(juce::Colour(0xfff0f1f2)); g.setFont(15.f); g.drawText(names[i],r.removeFromTop(38),juce::Justification::centred); x+=widths[i]+10; }
|
int x = 15;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
auto r = juce::Rectangle<int>(x, 85, widths[i], 325);
|
||||||
|
g.setColour(juce::Colour(0xff1b1f24));
|
||||||
|
g.fillRoundedRectangle(r.toFloat(), 10.f);
|
||||||
|
g.setColour(i == 2 ? juce::Colour(0xffb85c45) : juce::Colour(0xff3c424a));
|
||||||
|
g.drawRoundedRectangle(r.toFloat(), 10.f, 2.f);
|
||||||
|
g.setColour(juce::Colour(0xfff0f1f2));
|
||||||
|
g.setFont(15.f);
|
||||||
|
g.drawText(names[i], r.removeFromTop(38), juce::Justification::centred);
|
||||||
|
x += widths[i] + 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrilleBassStripAudioProcessorEditor::resized()
|
void CrilleBassStripAudioProcessorEditor::resized()
|
||||||
{
|
{
|
||||||
const int starts[]{20,235,450,665}; const int counts[]{3,3,3,5}; int index=0;
|
const int starts[] { 70, 345, 565, 780 };
|
||||||
for (int section=0;section<4;++section) {
|
const int counts[] { 3, 3, 3, 5 };
|
||||||
int cols = section==3 ? 3 : 2; int cellW = section==3 ? 100 : 95;
|
int index = 0;
|
||||||
for(int n=0;n<counts[section];++n,++index) {
|
|
||||||
int row=n/cols, col=n%cols; int x=starts[section]+8+col*cellW, y=130+row*135;
|
for (int section = 0; section < 4; ++section)
|
||||||
knobs[index]->slider.setBounds(x,y,88,102); knobs[index]->label.setBounds(x,y+102,88,22);
|
{
|
||||||
|
const int cols = section == 3 ? 3 : 2;
|
||||||
|
const int cellW = section == 3 ? 100 : 95;
|
||||||
|
for (int n = 0; n < counts[section]; ++n, ++index)
|
||||||
|
{
|
||||||
|
const int row = n / cols;
|
||||||
|
const int col = n % cols;
|
||||||
|
const int x = starts[section] + 8 + col * cellW;
|
||||||
|
const int y = 130 + row * 135;
|
||||||
|
knobs[index]->slider.setBounds(x, y, 88, 102);
|
||||||
|
knobs[index]->label.setBounds(x, y + 102, 88, 22);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gateInputMeter.setBounds(25, 125, 42, 255);
|
||||||
|
compressorInputMeter.setBounds(290, 125, 42, 255);
|
||||||
|
compressorReductionMeter.setBounds(500, 125, 42, 255);
|
||||||
}
|
}
|
||||||
+38
-2
@@ -2,18 +2,54 @@
|
|||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "PluginProcessor.h"
|
#include "PluginProcessor.h"
|
||||||
|
|
||||||
class CrilleBassStripAudioProcessorEditor final : public juce::AudioProcessorEditor
|
class CrilleBassStripAudioProcessorEditor final : public juce::AudioProcessorEditor,
|
||||||
|
private juce::Timer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CrilleBassStripAudioProcessorEditor(CrilleBassStripAudioProcessor&);
|
explicit CrilleBassStripAudioProcessorEditor(CrilleBassStripAudioProcessor&);
|
||||||
~CrilleBassStripAudioProcessorEditor() override = default;
|
~CrilleBassStripAudioProcessorEditor() override = default;
|
||||||
|
|
||||||
void paint(juce::Graphics&) override;
|
void paint(juce::Graphics&) override;
|
||||||
void resized() override;
|
void resized() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Knob { juce::Slider slider; juce::Label label; };
|
class LevelMeter final : public juce::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class Mode { inputLevel, gainReduction };
|
||||||
|
|
||||||
|
explicit LevelMeter(Mode meterMode);
|
||||||
|
void setLevel(float newLevelDb);
|
||||||
|
void setThreshold(float newThresholdDb);
|
||||||
|
void paint(juce::Graphics&) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Mode mode;
|
||||||
|
float displayedDb = -80.0f;
|
||||||
|
float thresholdDb = -80.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Knob
|
||||||
|
{
|
||||||
|
juce::Slider slider;
|
||||||
|
juce::Label label;
|
||||||
|
};
|
||||||
|
|
||||||
CrilleBassStripAudioProcessor& processor;
|
CrilleBassStripAudioProcessor& processor;
|
||||||
std::vector<std::unique_ptr<Knob>> knobs;
|
std::vector<std::unique_ptr<Knob>> knobs;
|
||||||
std::vector<std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment>> attachments;
|
std::vector<std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment>> attachments;
|
||||||
|
|
||||||
|
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 addKnob(const juce::String& parameter, const juce::String& caption);
|
||||||
|
void timerCallback() override;
|
||||||
|
static float smoothMeter(float current, float target, float attack, float release);
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessorEditor)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessorEditor)
|
||||||
};
|
};
|
||||||
+80
-18
@@ -2,15 +2,19 @@
|
|||||||
#include "PluginEditor.h"
|
#include "PluginEditor.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace {
|
namespace
|
||||||
|
{
|
||||||
constexpr auto pid = [](const char* s) { return juce::ParameterID { s, 1 }; };
|
constexpr auto pid = [](const char* s) { return juce::ParameterID { s, 1 }; };
|
||||||
float dbToGain(float db) { return juce::Decibels::decibelsToGain(db); }
|
float dbToGain(float db) { return juce::Decibels::decibelsToGain(db); }
|
||||||
|
constexpr float meterFloorDb = -80.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
CrilleBassStripAudioProcessor::CrilleBassStripAudioProcessor()
|
CrilleBassStripAudioProcessor::CrilleBassStripAudioProcessor()
|
||||||
: AudioProcessor(BusesProperties().withInput("Input", juce::AudioChannelSet::stereo(), true)
|
: AudioProcessor(BusesProperties().withInput("Input", juce::AudioChannelSet::stereo(), true)
|
||||||
.withOutput("Output", juce::AudioChannelSet::stereo(), true)),
|
.withOutput("Output", juce::AudioChannelSet::stereo(), true)),
|
||||||
apvts(*this, nullptr, "PARAMETERS", createParameterLayout()) {}
|
apvts(*this, nullptr, "PARAMETERS", createParameterLayout())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcessor::createParameterLayout()
|
juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcessor::createParameterLayout()
|
||||||
{
|
{
|
||||||
@@ -37,16 +41,36 @@ void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block)
|
|||||||
{
|
{
|
||||||
currentSampleRate = sr;
|
currentSampleRate = sr;
|
||||||
juce::dsp::ProcessSpec spec { sr, static_cast<juce::uint32>(block), static_cast<juce::uint32>(getTotalNumOutputChannels()) };
|
juce::dsp::ProcessSpec spec { sr, static_cast<juce::uint32>(block), static_cast<juce::uint32>(getTotalNumOutputChannels()) };
|
||||||
compressor.prepare(spec); lowShelf.prepare(spec); lowMid.prepare(spec); mid.prepare(spec); highShelf.prepare(spec);
|
compressor.prepare(spec);
|
||||||
compressor.reset(); lowShelf.reset(); lowMid.reset(); mid.reset(); highShelf.reset();
|
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<size_t>(getTotalNumOutputChannels()), 0.f);
|
gateEnvelope.assign(static_cast<size_t>(getTotalNumOutputChannels()), 0.f);
|
||||||
|
gateInputLevelDb.store(meterFloorDb);
|
||||||
|
compressorInputLevelDb.store(meterFloorDb);
|
||||||
|
compressorGainReductionDb.store(0.0f);
|
||||||
updateFilters();
|
updateFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CrilleBassStripAudioProcessor::isBusesLayoutSupported(const BusesLayout& l) const
|
bool CrilleBassStripAudioProcessor::isBusesLayoutSupported(const BusesLayout& l) const
|
||||||
{
|
{
|
||||||
const auto out = l.getMainOutputChannelSet();
|
const auto out = l.getMainOutputChannelSet();
|
||||||
return (out == juce::AudioChannelSet::mono() || out == juce::AudioChannelSet::stereo()) && out == l.getMainInputChannelSet();
|
return (out == juce::AudioChannelSet::mono() || out == juce::AudioChannelSet::stereo())
|
||||||
|
&& out == l.getMainInputChannelSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
float CrilleBassStripAudioProcessor::getBufferPeak(const juce::AudioBuffer<float>& buffer) noexcept
|
||||||
|
{
|
||||||
|
float peak = 0.0f;
|
||||||
|
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
|
||||||
|
peak = juce::jmax(peak, buffer.getMagnitude(channel, 0, buffer.getNumSamples()));
|
||||||
|
return peak;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrilleBassStripAudioProcessor::updateFilters()
|
void CrilleBassStripAudioProcessor::updateFilters()
|
||||||
@@ -64,52 +88,90 @@ void CrilleBassStripAudioProcessor::updateFilters()
|
|||||||
void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer&)
|
void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer&)
|
||||||
{
|
{
|
||||||
juce::ScopedNoDenormals noDenormals;
|
juce::ScopedNoDenormals noDenormals;
|
||||||
for (int c = getTotalNumInputChannels(); c < getTotalNumOutputChannels(); ++c) buffer.clear(c, 0, buffer.getNumSamples());
|
for (int c = getTotalNumInputChannels(); c < getTotalNumOutputChannels(); ++c)
|
||||||
|
buffer.clear(c, 0, buffer.getNumSamples());
|
||||||
|
|
||||||
|
const float gateInputPeak = getBufferPeak(buffer);
|
||||||
|
gateInputLevelDb.store(juce::Decibels::gainToDecibels(gateInputPeak, meterFloorDb), std::memory_order_relaxed);
|
||||||
|
|
||||||
const float threshold = dbToGain(apvts.getRawParameterValue("gateThreshold")->load());
|
const float threshold = dbToGain(apvts.getRawParameterValue("gateThreshold")->load());
|
||||||
const float releaseMs = apvts.getRawParameterValue("gateRelease")->load();
|
const float releaseMs = apvts.getRawParameterValue("gateRelease")->load();
|
||||||
const float releaseCoeff = std::exp(-1.f / (0.001f * releaseMs * static_cast<float>(currentSampleRate)));
|
const float releaseCoeff = std::exp(-1.f / (0.001f * releaseMs * static_cast<float>(currentSampleRate)));
|
||||||
const float gateGain = dbToGain(apvts.getRawParameterValue("gateGain")->load());
|
const float gateGain = dbToGain(apvts.getRawParameterValue("gateGain")->load());
|
||||||
for (int c = 0; c < buffer.getNumChannels(); ++c) {
|
|
||||||
auto* x = buffer.getWritePointer(c); auto& env = gateEnvelope[static_cast<size_t>(c)];
|
for (int c = 0; c < buffer.getNumChannels(); ++c)
|
||||||
for (int i = 0; i < buffer.getNumSamples(); ++i) {
|
{
|
||||||
|
auto* x = buffer.getWritePointer(c);
|
||||||
|
auto& env = gateEnvelope[static_cast<size_t>(c)];
|
||||||
|
for (int i = 0; i < buffer.getNumSamples(); ++i)
|
||||||
|
{
|
||||||
const float target = std::abs(x[i]) >= threshold ? 1.f : 0.f;
|
const float target = std::abs(x[i]) >= threshold ? 1.f : 0.f;
|
||||||
env = target > env ? target : releaseCoeff * env;
|
env = target > env ? target : releaseCoeff * env;
|
||||||
x[i] *= env * gateGain;
|
x[i] *= env * gateGain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float compressorInputPeak = getBufferPeak(buffer);
|
||||||
|
compressorInputLevelDb.store(juce::Decibels::gainToDecibels(compressorInputPeak, meterFloorDb), std::memory_order_relaxed);
|
||||||
|
|
||||||
compressor.setThreshold(apvts.getRawParameterValue("compThreshold")->load());
|
compressor.setThreshold(apvts.getRawParameterValue("compThreshold")->load());
|
||||||
compressor.setRatio(apvts.getRawParameterValue("compRatio")->load());
|
compressor.setRatio(apvts.getRawParameterValue("compRatio")->load());
|
||||||
compressor.setAttack(15.f); compressor.setRelease(100.f);
|
compressor.setAttack(15.f);
|
||||||
|
compressor.setRelease(100.f);
|
||||||
|
|
||||||
juce::dsp::AudioBlock<float> block(buffer);
|
juce::dsp::AudioBlock<float> block(buffer);
|
||||||
juce::dsp::ProcessContextReplacing<float> context(block);
|
juce::dsp::ProcessContextReplacing<float> context(block);
|
||||||
compressor.process(context);
|
compressor.process(context);
|
||||||
|
|
||||||
|
const float compressorOutputPeak = getBufferPeak(buffer);
|
||||||
|
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);
|
||||||
|
|
||||||
buffer.applyGain(dbToGain(apvts.getRawParameterValue("compGain")->load()));
|
buffer.applyGain(dbToGain(apvts.getRawParameterValue("compGain")->load()));
|
||||||
|
|
||||||
const float drive = dbToGain(apvts.getRawParameterValue("drive")->load());
|
const float drive = dbToGain(apvts.getRawParameterValue("drive")->load());
|
||||||
const float mix = apvts.getRawParameterValue("mix")->load() * 0.01f;
|
const float mix = apvts.getRawParameterValue("mix")->load() * 0.01f;
|
||||||
const float dg = dbToGain(apvts.getRawParameterValue("distGain")->load());
|
const float dg = dbToGain(apvts.getRawParameterValue("distGain")->load());
|
||||||
for (int c = 0; c < buffer.getNumChannels(); ++c) {
|
for (int c = 0; c < buffer.getNumChannels(); ++c)
|
||||||
|
{
|
||||||
auto* x = buffer.getWritePointer(c);
|
auto* x = buffer.getWritePointer(c);
|
||||||
for (int i = 0; i < buffer.getNumSamples(); ++i) {
|
for (int i = 0; i < buffer.getNumSamples(); ++i)
|
||||||
const float dry = x[i]; const float wet = std::tanh(dry * drive);
|
{
|
||||||
|
const float dry = x[i];
|
||||||
|
const float wet = std::tanh(dry * drive);
|
||||||
x[i] = ((1.f - mix) * dry + mix * wet) * dg;
|
x[i] = ((1.f - mix) * dry + mix * wet) * dg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFilters();
|
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);
|
||||||
buffer.applyGain(dbToGain(apvts.getRawParameterValue("output")->load()));
|
buffer.applyGain(dbToGain(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);
|
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));
|
if (auto xml = getXmlFromBinary(data, size);
|
||||||
|
xml != nullptr && xml->hasTagName(apvts.state.getType()))
|
||||||
|
apvts.replaceState(juce::ValueTree::fromXml(*xml));
|
||||||
|
}
|
||||||
|
|
||||||
|
juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor()
|
||||||
|
{
|
||||||
|
return new CrilleBassStripAudioProcessorEditor(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
||||||
|
{
|
||||||
|
return new CrilleBassStripAudioProcessor();
|
||||||
}
|
}
|
||||||
juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor() { return new CrilleBassStripAudioProcessorEditor(*this); }
|
|
||||||
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new CrilleBassStripAudioProcessor(); }
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
class CrilleBassStripAudioProcessor final : public juce::AudioProcessor
|
class CrilleBassStripAudioProcessor final : public juce::AudioProcessor
|
||||||
{
|
{
|
||||||
@@ -30,12 +31,24 @@ public:
|
|||||||
juce::AudioProcessorValueTreeState apvts;
|
juce::AudioProcessorValueTreeState apvts;
|
||||||
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
|
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
|
||||||
|
|
||||||
|
float getGateInputLevelDb() const noexcept { return gateInputLevelDb.load(); }
|
||||||
|
float getCompressorInputLevelDb() const noexcept { return compressorInputLevelDb.load(); }
|
||||||
|
float getCompressorGainReductionDb() const noexcept { return compressorGainReductionDb.load(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Filter = juce::dsp::IIR::Filter<float>;
|
using Filter = juce::dsp::IIR::Filter<float>;
|
||||||
|
|
||||||
juce::dsp::Compressor<float> compressor;
|
juce::dsp::Compressor<float> compressor;
|
||||||
juce::dsp::ProcessorDuplicator<Filter, juce::dsp::IIR::Coefficients<float>> lowShelf, lowMid, mid, highShelf;
|
juce::dsp::ProcessorDuplicator<Filter, juce::dsp::IIR::Coefficients<float>> lowShelf, lowMid, mid, highShelf;
|
||||||
double currentSampleRate = 44100.0;
|
double currentSampleRate = 44100.0;
|
||||||
std::vector<float> gateEnvelope;
|
std::vector<float> gateEnvelope;
|
||||||
|
|
||||||
|
std::atomic<float> gateInputLevelDb { -80.0f };
|
||||||
|
std::atomic<float> compressorInputLevelDb { -80.0f };
|
||||||
|
std::atomic<float> compressorGainReductionDb { 0.0f };
|
||||||
|
|
||||||
void updateFilters();
|
void updateFilters();
|
||||||
|
static float getBufferPeak(const juce::AudioBuffer<float>& buffer) noexcept;
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessor)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CrilleBassStripAudioProcessor)
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user