902 lines
16 KiB
C++
902 lines
16 KiB
C++
#include "PluginEditor.h"
|
|
|
|
#include <cmath>
|
|
|
|
namespace
|
|
{
|
|
juce::String frequencyToNoteName(float frequency)
|
|
{
|
|
if (frequency <= 0.0f)
|
|
return "--";
|
|
|
|
const float midiNote =
|
|
69.0f
|
|
+ 12.0f
|
|
* std::log2(frequency / 440.0f);
|
|
|
|
const int roundedMidiNote =
|
|
static_cast<int>(std::round(midiNote));
|
|
|
|
static const juce::StringArray noteNames
|
|
{
|
|
"C",
|
|
"C#",
|
|
"D",
|
|
"Eb",
|
|
"E",
|
|
"F",
|
|
"F#",
|
|
"G",
|
|
"Ab",
|
|
"A",
|
|
"Bb",
|
|
"B"
|
|
};
|
|
|
|
const int noteIndex =
|
|
((roundedMidiNote % 12) + 12) % 12;
|
|
|
|
return noteNames[noteIndex];
|
|
}
|
|
|
|
float transposeFrequency(float frequency, int semitones)
|
|
{
|
|
if (frequency <= 0.0f)
|
|
return 0.0f;
|
|
|
|
return frequency
|
|
* std::pow(
|
|
2.0f,
|
|
static_cast<float>(semitones) / 12.0f
|
|
);
|
|
}
|
|
}
|
|
|
|
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 =
|
|
juce::String(displayedDb, 1) + " dB";
|
|
|
|
g.drawText(
|
|
value,
|
|
valueArea,
|
|
juce::Justification::centred
|
|
);
|
|
}
|
|
|
|
CrilleBassStripAudioProcessorEditor::
|
|
CrilleBassStripAudioProcessorEditor(
|
|
CrilleBassStripAudioProcessor& p)
|
|
: AudioProcessorEditor(&p),
|
|
processor(p)
|
|
{
|
|
downTuneButton.setButtonText(
|
|
"DOWN 1/2 STEP"
|
|
);
|
|
|
|
downTuneButton.setClickingTogglesState(true);
|
|
|
|
downTuneButton.setColour(
|
|
juce::ToggleButton::textColourId,
|
|
juce::Colour(0xffd9dde3)
|
|
);
|
|
|
|
downTuneButton.setColour(
|
|
juce::ToggleButton::tickColourId,
|
|
juce::Colour(0xffe5a536)
|
|
);
|
|
|
|
downTuneButton.setColour(
|
|
juce::ToggleButton::tickDisabledColourId,
|
|
juce::Colour(0xff555b63)
|
|
);
|
|
|
|
addAndMakeVisible(downTuneButton);
|
|
|
|
downTuneAttachment =
|
|
std::make_unique<
|
|
juce::AudioProcessorValueTreeState::
|
|
ButtonAttachment
|
|
>(
|
|
processor.apvts,
|
|
"downTuneOn",
|
|
downTuneButton
|
|
);
|
|
|
|
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(760, 720);
|
|
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.0f,
|
|
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()
|
|
);
|
|
|
|
repaint();
|
|
}
|
|
|
|
void CrilleBassStripAudioProcessorEditor::paint(
|
|
juce::Graphics& g)
|
|
{
|
|
g.fillAll(juce::Colour(0xff111317));
|
|
|
|
g.setColour(juce::Colour(0xffe5a536));
|
|
g.setFont(
|
|
juce::Font(
|
|
28.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
"CRILLE BASS STRIP",
|
|
25,
|
|
15,
|
|
getWidth() - 50,
|
|
40,
|
|
juce::Justification::centredLeft
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xff777f89));
|
|
g.setFont(13.0f);
|
|
|
|
g.drawText(
|
|
"DOWNTUNE > GATE > COMPRESSOR > DISTORTION > EQ",
|
|
28,
|
|
50,
|
|
getWidth() - 56,
|
|
22,
|
|
juce::Justification::centredLeft
|
|
);
|
|
|
|
const struct
|
|
{
|
|
juce::Rectangle<int> 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)
|
|
}
|
|
};
|
|
|
|
for (const auto& panel : panels)
|
|
{
|
|
auto bounds = panel.bounds;
|
|
|
|
g.setColour(juce::Colour(0xff1b1f24));
|
|
|
|
g.fillRoundedRectangle(
|
|
bounds.toFloat(),
|
|
10.0f
|
|
);
|
|
|
|
g.setColour(panel.border);
|
|
|
|
g.drawRoundedRectangle(
|
|
bounds.toFloat(),
|
|
10.0f,
|
|
2.0f
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xfff0f1f2));
|
|
g.setFont(15.0f);
|
|
|
|
g.drawText(
|
|
panel.title,
|
|
bounds.removeFromTop(38),
|
|
juce::Justification::centred
|
|
);
|
|
}
|
|
|
|
const float inputFrequency =
|
|
processor.getDetectedFrequencyHz();
|
|
|
|
const bool downTuneEnabled =
|
|
processor.apvts
|
|
.getRawParameterValue("downTuneOn")
|
|
->load() > 0.5f;
|
|
|
|
const float outputFrequency =
|
|
downTuneEnabled
|
|
? transposeFrequency(
|
|
inputFrequency,
|
|
-1
|
|
)
|
|
: inputFrequency;
|
|
|
|
const auto inputNote =
|
|
frequencyToNoteName(inputFrequency);
|
|
|
|
const auto outputNote =
|
|
frequencyToNoteName(outputFrequency);
|
|
|
|
g.setColour(juce::Colour(0xff777f89));
|
|
g.setFont(
|
|
juce::Font(
|
|
11.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
"INPUT",
|
|
30,
|
|
220,
|
|
150,
|
|
18,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xfff0f1f2));
|
|
g.setFont(
|
|
juce::Font(
|
|
28.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
inputNote,
|
|
30,
|
|
238,
|
|
150,
|
|
36,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xffaeb4bc));
|
|
g.setFont(11.0f);
|
|
|
|
const auto inputFrequencyText =
|
|
inputFrequency > 0.0f
|
|
? juce::String(inputFrequency, 1)
|
|
+ " Hz"
|
|
: "-- Hz";
|
|
|
|
g.drawText(
|
|
inputFrequencyText,
|
|
30,
|
|
270,
|
|
150,
|
|
20,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xff777f89));
|
|
g.setFont(
|
|
juce::Font(
|
|
11.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
"OUTPUT",
|
|
30,
|
|
292,
|
|
150,
|
|
18,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
g.setColour(
|
|
downTuneEnabled
|
|
? juce::Colour(0xffffc247)
|
|
: juce::Colour(0xfff0f1f2)
|
|
);
|
|
|
|
g.setFont(
|
|
juce::Font(
|
|
28.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
outputNote,
|
|
30,
|
|
310,
|
|
150,
|
|
36,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
g.setColour(juce::Colour(0xffaeb4bc));
|
|
g.setFont(11.0f);
|
|
|
|
const auto outputFrequencyText =
|
|
outputFrequency > 0.0f
|
|
? juce::String(outputFrequency, 1)
|
|
+ " Hz"
|
|
: "-- Hz";
|
|
|
|
g.drawText(
|
|
outputFrequencyText,
|
|
30,
|
|
342,
|
|
150,
|
|
20,
|
|
juce::Justification::centred
|
|
);
|
|
|
|
const auto latencyText =
|
|
"LATENCY: "
|
|
+ juce::String(
|
|
processor.getDownTuneLatencyMs(),
|
|
1
|
|
)
|
|
+ " ms";
|
|
|
|
g.setColour(juce::Colour(0xffaeb4bc));
|
|
g.setFont(
|
|
juce::Font(
|
|
10.0f,
|
|
juce::Font::bold
|
|
)
|
|
);
|
|
|
|
g.drawText(
|
|
latencyText,
|
|
25,
|
|
362,
|
|
160,
|
|
18,
|
|
juce::Justification::centred
|
|
);
|
|
}
|
|
|
|
void CrilleBassStripAudioProcessorEditor::resized()
|
|
{
|
|
downTuneButton.setBounds(
|
|
35,
|
|
135,
|
|
140,
|
|
50
|
|
);
|
|
|
|
gateInputMeter.setBounds(
|
|
215,
|
|
125,
|
|
42,
|
|
225
|
|
);
|
|
|
|
compressorInputMeter.setBounds(
|
|
490,
|
|
125,
|
|
42,
|
|
225
|
|
);
|
|
|
|
compressorReductionMeter.setBounds(
|
|
693,
|
|
125,
|
|
42,
|
|
225
|
|
);
|
|
|
|
// Noise gate
|
|
knobs[0]->slider.setBounds(
|
|
265,
|
|
125,
|
|
92,
|
|
100
|
|
);
|
|
|
|
knobs[0]->label.setBounds(
|
|
265,
|
|
225,
|
|
92,
|
|
22
|
|
);
|
|
|
|
knobs[1]->slider.setBounds(
|
|
365,
|
|
125,
|
|
92,
|
|
100
|
|
);
|
|
|
|
knobs[1]->label.setBounds(
|
|
365,
|
|
225,
|
|
92,
|
|
22
|
|
);
|
|
|
|
knobs[2]->slider.setBounds(
|
|
315,
|
|
250,
|
|
92,
|
|
100
|
|
);
|
|
|
|
knobs[2]->label.setBounds(
|
|
315,
|
|
350,
|
|
92,
|
|
22
|
|
);
|
|
|
|
// Compressor
|
|
knobs[3]->slider.setBounds(
|
|
540,
|
|
125,
|
|
72,
|
|
100
|
|
);
|
|
|
|
knobs[3]->label.setBounds(
|
|
535,
|
|
225,
|
|
82,
|
|
22
|
|
);
|
|
|
|
knobs[4]->slider.setBounds(
|
|
615,
|
|
125,
|
|
72,
|
|
100
|
|
);
|
|
|
|
knobs[4]->label.setBounds(
|
|
610,
|
|
225,
|
|
82,
|
|
22
|
|
);
|
|
|
|
knobs[5]->slider.setBounds(
|
|
575,
|
|
250,
|
|
82,
|
|
100
|
|
);
|
|
|
|
knobs[5]->label.setBounds(
|
|
575,
|
|
350,
|
|
82,
|
|
22
|
|
);
|
|
|
|
// Distortion
|
|
knobs[6]->slider.setBounds(
|
|
35,
|
|
455,
|
|
82,
|
|
100
|
|
);
|
|
|
|
knobs[6]->label.setBounds(
|
|
35,
|
|
555,
|
|
82,
|
|
22
|
|
);
|
|
|
|
knobs[7]->slider.setBounds(
|
|
124,
|
|
455,
|
|
82,
|
|
100
|
|
);
|
|
|
|
knobs[7]->label.setBounds(
|
|
124,
|
|
555,
|
|
82,
|
|
22
|
|
);
|
|
|
|
knobs[8]->slider.setBounds(
|
|
213,
|
|
455,
|
|
82,
|
|
100
|
|
);
|
|
|
|
knobs[8]->label.setBounds(
|
|
213,
|
|
555,
|
|
82,
|
|
22
|
|
);
|
|
|
|
// Equalizer
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
const int knobIndex = 9 + i;
|
|
const int x = 335 + i * 80;
|
|
|
|
knobs[knobIndex]->slider.setBounds(
|
|
x,
|
|
455,
|
|
76,
|
|
100
|
|
);
|
|
|
|
knobs[knobIndex]->label.setBounds(
|
|
x,
|
|
555,
|
|
76,
|
|
22
|
|
);
|
|
}
|
|
} |