197 lines
7.6 KiB
C++
197 lines
7.6 KiB
C++
#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)
|
|
: AudioProcessorEditor(&p), processor(p)
|
|
{
|
|
addKnob("gateThreshold", "THRESHOLD");
|
|
addKnob("gateRelease", "RELEASE");
|
|
addKnob("gateGain", "GAIN");
|
|
addKnob("compThreshold", "THRESHOLD");
|
|
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)
|
|
{
|
|
auto k = std::make_unique<Knob>();
|
|
k->slider.setSliderStyle(juce::Slider::RotaryHorizontalVerticalDrag);
|
|
k->slider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 72, 20);
|
|
k->slider.setColour(juce::Slider::rotarySliderFillColourId, juce::Colour(0xffe5a536));
|
|
k->slider.setColour(juce::Slider::rotarySliderOutlineColourId, juce::Colour(0xff30343a));
|
|
k->slider.setColour(juce::Slider::thumbColourId, juce::Colour(0xffffd275));
|
|
k->label.setText(caption, juce::dontSendNotification);
|
|
k->label.setJustificationType(juce::Justification::centred);
|
|
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));
|
|
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)
|
|
{
|
|
g.fillAll(juce::Colour(0xff111317));
|
|
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.setColour(juce::Colour(0xff777f89));
|
|
g.setFont(13.f);
|
|
g.drawText("GATE > COMPRESSOR > DISTORTION > EQ", 28, 50, getWidth() - 56, 22, juce::Justification::centredLeft);
|
|
|
|
const juce::StringArray names { "NOISE GATE", "COMPRESSOR", "DISTORTION", "EQUALIZER" };
|
|
const int widths[] { 255, 265, 205, 315 };
|
|
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()
|
|
{
|
|
const int starts[] { 70, 345, 565, 780 };
|
|
const int counts[] { 3, 3, 3, 5 };
|
|
int index = 0;
|
|
|
|
for (int section = 0; section < 4; ++section)
|
|
{
|
|
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);
|
|
}
|