Lägg till inbyggd stämapparat i DownTune
This commit is contained in:
1 parent
aa94048f53
commit
53f9515ac9
5 files changed
+257
-120
No files matched your search
Binary file not shown.
BIN
Binary file not shown.
+216
-119
@@ -212,6 +212,135 @@ void CrilleBassStripAudioProcessorEditor::LevelMeter::paint(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CrilleBassStripAudioProcessorEditor::TunerDisplay::TunerDisplay()
|
||||||
|
{
|
||||||
|
setInterceptsMouseClicks(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::TunerDisplay::setFrequency(
|
||||||
|
float newFrequencyHz)
|
||||||
|
{
|
||||||
|
frequencyHz = newFrequencyHz;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrilleBassStripAudioProcessorEditor::TunerDisplay::paint(
|
||||||
|
juce::Graphics& g)
|
||||||
|
{
|
||||||
|
auto bounds = getLocalBounds();
|
||||||
|
const bool hasSignal = frequencyHz > 0.0f;
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff777f89));
|
||||||
|
g.setFont(juce::Font(10.0f, juce::Font::bold));
|
||||||
|
g.drawText(
|
||||||
|
"INPUT",
|
||||||
|
bounds.removeFromTop(14),
|
||||||
|
juce::Justification::centred);
|
||||||
|
|
||||||
|
if (!hasSignal)
|
||||||
|
{
|
||||||
|
g.setColour(juce::Colour(0xfff0f1f2));
|
||||||
|
g.setFont(juce::Font(26.0f, juce::Font::bold));
|
||||||
|
g.drawText("--", 0, 14, getWidth(), 30, juce::Justification::centred);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xffaeb4bc));
|
||||||
|
g.setFont(10.0f);
|
||||||
|
g.drawText("-- Hz", 0, 43, getWidth(), 15, juce::Justification::centred);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff454a51));
|
||||||
|
g.drawLine(18.0f, 70.0f, static_cast<float>(getWidth() - 18), 70.0f, 2.0f);
|
||||||
|
g.fillEllipse(static_cast<float>(getWidth()) * 0.5f - 4.0f, 66.0f, 8.0f, 8.0f);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff686e76));
|
||||||
|
g.setFont(9.0f);
|
||||||
|
g.drawText("PLAY A NOTE", 0, 78, getWidth(), 16, juce::Justification::centred);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float midiNote =
|
||||||
|
69.0f + 12.0f * std::log2(frequencyHz / 440.0f);
|
||||||
|
|
||||||
|
const int nearestMidiNote =
|
||||||
|
static_cast<int>(std::round(midiNote));
|
||||||
|
|
||||||
|
const float targetFrequency =
|
||||||
|
440.0f * std::pow(
|
||||||
|
2.0f,
|
||||||
|
static_cast<float>(nearestMidiNote - 69) / 12.0f);
|
||||||
|
|
||||||
|
const float cents =
|
||||||
|
1200.0f * std::log2(frequencyHz / targetFrequency);
|
||||||
|
|
||||||
|
const bool inTune = std::abs(cents) <= 5.0f;
|
||||||
|
const auto noteName = frequencyToNoteName(targetFrequency);
|
||||||
|
|
||||||
|
g.setColour(inTune
|
||||||
|
? juce::Colour(0xff45c95a)
|
||||||
|
: juce::Colour(0xfff0f1f2));
|
||||||
|
g.setFont(juce::Font(26.0f, juce::Font::bold));
|
||||||
|
g.drawText(noteName, 0, 14, getWidth(), 30, juce::Justification::centred);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xffaeb4bc));
|
||||||
|
g.setFont(10.0f);
|
||||||
|
g.drawText(
|
||||||
|
juce::String(frequencyHz, 1) + " Hz",
|
||||||
|
0,
|
||||||
|
43,
|
||||||
|
getWidth(),
|
||||||
|
15,
|
||||||
|
juce::Justification::centred);
|
||||||
|
|
||||||
|
const float centreX = static_cast<float>(getWidth()) * 0.5f;
|
||||||
|
const float indicatorY = 70.0f;
|
||||||
|
const auto orange = juce::Colour(0xffe5a536);
|
||||||
|
const auto inactive = juce::Colour(0xff454a51);
|
||||||
|
const auto green = juce::Colour(0xff45c95a);
|
||||||
|
|
||||||
|
g.setColour(juce::Colour(0xff3c424a));
|
||||||
|
g.drawLine(20.0f, indicatorY, static_cast<float>(getWidth() - 20), indicatorY, 2.0f);
|
||||||
|
|
||||||
|
juce::Path leftArrow;
|
||||||
|
leftArrow.addTriangle(
|
||||||
|
12.0f, indicatorY,
|
||||||
|
28.0f, indicatorY - 9.0f,
|
||||||
|
28.0f, indicatorY + 9.0f);
|
||||||
|
|
||||||
|
juce::Path rightArrow;
|
||||||
|
rightArrow.addTriangle(
|
||||||
|
static_cast<float>(getWidth() - 12), indicatorY,
|
||||||
|
static_cast<float>(getWidth() - 28), indicatorY - 9.0f,
|
||||||
|
static_cast<float>(getWidth() - 28), indicatorY + 9.0f);
|
||||||
|
|
||||||
|
g.setColour(!inTune && cents > 5.0f ? orange : inactive);
|
||||||
|
g.fillPath(leftArrow);
|
||||||
|
|
||||||
|
g.setColour(!inTune && cents < -5.0f ? orange : inactive);
|
||||||
|
g.fillPath(rightArrow);
|
||||||
|
|
||||||
|
g.setColour(inTune ? green : juce::Colour(0xff686e76));
|
||||||
|
g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f);
|
||||||
|
|
||||||
|
g.setColour(inTune ? green : orange);
|
||||||
|
g.setFont(juce::Font(9.0f, juce::Font::bold));
|
||||||
|
|
||||||
|
juce::String statusText;
|
||||||
|
|
||||||
|
if (inTune)
|
||||||
|
statusText = "IN TUNE";
|
||||||
|
else if (cents < 0.0f)
|
||||||
|
statusText = "TUNE UP " + juce::String(std::round(std::abs(cents)), 0) + " ct";
|
||||||
|
else
|
||||||
|
statusText = "TUNE DOWN " + juce::String(std::round(std::abs(cents)), 0) + " ct";
|
||||||
|
|
||||||
|
g.drawText(
|
||||||
|
statusText,
|
||||||
|
0,
|
||||||
|
80,
|
||||||
|
getWidth(),
|
||||||
|
16,
|
||||||
|
juce::Justification::centred);
|
||||||
|
}
|
||||||
|
|
||||||
CrilleBassStripAudioProcessorEditor::SectionToggleButton::
|
CrilleBassStripAudioProcessorEditor::SectionToggleButton::
|
||||||
SectionToggleButton(
|
SectionToggleButton(
|
||||||
const juce::String& sectionName,
|
const juce::String& sectionName,
|
||||||
@@ -295,6 +424,8 @@ CrilleBassStripAudioProcessorEditor(
|
|||||||
);
|
);
|
||||||
|
|
||||||
addAndMakeVisible(downTuneButton);
|
addAndMakeVisible(downTuneButton);
|
||||||
|
addAndMakeVisible(tunerToggleButton);
|
||||||
|
addAndMakeVisible(tunerDisplay);
|
||||||
|
|
||||||
downTuneAttachment =
|
downTuneAttachment =
|
||||||
std::make_unique<
|
std::make_unique<
|
||||||
@@ -306,6 +437,14 @@ CrilleBassStripAudioProcessorEditor(
|
|||||||
downTuneButton
|
downTuneButton
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tunerToggleAttachment =
|
||||||
|
std::make_unique<
|
||||||
|
juce::AudioProcessorValueTreeState::ButtonAttachment
|
||||||
|
>(
|
||||||
|
processor.apvts,
|
||||||
|
"tunerOn",
|
||||||
|
tunerToggleButton);
|
||||||
|
|
||||||
addAndMakeVisible(gateToggleButton);
|
addAndMakeVisible(gateToggleButton);
|
||||||
addAndMakeVisible(compressorToggleButton);
|
addAndMakeVisible(compressorToggleButton);
|
||||||
addAndMakeVisible(distortionToggleButton);
|
addAndMakeVisible(distortionToggleButton);
|
||||||
@@ -544,6 +683,11 @@ void CrilleBassStripAudioProcessorEditor::timerCallback()
|
|||||||
{
|
{
|
||||||
updateSectionStates();
|
updateSectionStates();
|
||||||
|
|
||||||
|
const bool tunerEnabled = tunerToggleButton.getToggleState();
|
||||||
|
tunerDisplay.setVisible(tunerEnabled);
|
||||||
|
tunerDisplay.setFrequency(
|
||||||
|
tunerEnabled ? processor.getDetectedFrequencyHz() : 0.0f);
|
||||||
|
|
||||||
smoothedGateDb =
|
smoothedGateDb =
|
||||||
smoothMeter(
|
smoothMeter(
|
||||||
smoothedGateDb,
|
smoothedGateDb,
|
||||||
@@ -678,136 +822,75 @@ void CrilleBassStripAudioProcessorEditor::paint(
|
|||||||
38,
|
38,
|
||||||
juce::Justification::centred);
|
juce::Justification::centred);
|
||||||
|
|
||||||
const float inputFrequency =
|
const bool tunerEnabled = tunerToggleButton.getToggleState();
|
||||||
processor.getDetectedFrequencyHz();
|
|
||||||
|
|
||||||
const bool downTuneEnabled =
|
if (tunerEnabled)
|
||||||
processor.apvts
|
{
|
||||||
.getRawParameterValue("downTuneOn")
|
const float inputFrequency =
|
||||||
->load() > 0.5f;
|
processor.getDetectedFrequencyHz();
|
||||||
|
|
||||||
const float outputFrequency =
|
const bool downTuneEnabled =
|
||||||
downTuneEnabled
|
processor.apvts
|
||||||
? transposeFrequency(
|
.getRawParameterValue("downTuneOn")
|
||||||
inputFrequency,
|
->load() > 0.5f;
|
||||||
-1
|
|
||||||
)
|
|
||||||
: inputFrequency;
|
|
||||||
|
|
||||||
const auto inputNote =
|
const float outputFrequency =
|
||||||
frequencyToNoteName(inputFrequency);
|
downTuneEnabled
|
||||||
|
? transposeFrequency(
|
||||||
|
inputFrequency,
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
: inputFrequency;
|
||||||
|
|
||||||
const auto outputNote =
|
const auto outputNote =
|
||||||
frequencyToNoteName(outputFrequency);
|
frequencyToNoteName(outputFrequency);
|
||||||
|
|
||||||
g.setColour(juce::Colour(0xff777f89));
|
g.setColour(juce::Colour(0xff777f89));
|
||||||
g.setFont(
|
g.setFont(juce::Font(11.0f, juce::Font::bold));
|
||||||
juce::Font(
|
|
||||||
11.0f,
|
|
||||||
juce::Font::bold
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
g.drawText(
|
g.drawText(
|
||||||
"INPUT",
|
"OUTPUT",
|
||||||
30,
|
30,
|
||||||
220,
|
300,
|
||||||
150,
|
150,
|
||||||
18,
|
16,
|
||||||
juce::Justification::centred
|
juce::Justification::centred
|
||||||
);
|
);
|
||||||
|
|
||||||
g.setColour(juce::Colour(0xfff0f1f2));
|
g.setColour(
|
||||||
g.setFont(
|
downTuneEnabled
|
||||||
juce::Font(
|
? juce::Colour(0xffffc247)
|
||||||
28.0f,
|
: juce::Colour(0xfff0f1f2)
|
||||||
juce::Font::bold
|
);
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
g.drawText(
|
g.setFont(juce::Font(27.0f, juce::Font::bold));
|
||||||
inputNote,
|
|
||||||
30,
|
|
||||||
238,
|
|
||||||
150,
|
|
||||||
36,
|
|
||||||
juce::Justification::centred
|
|
||||||
);
|
|
||||||
|
|
||||||
g.setColour(juce::Colour(0xffaeb4bc));
|
g.drawText(
|
||||||
g.setFont(11.0f);
|
outputNote,
|
||||||
|
30,
|
||||||
|
315,
|
||||||
|
150,
|
||||||
|
30,
|
||||||
|
juce::Justification::centred
|
||||||
|
);
|
||||||
|
|
||||||
const auto inputFrequencyText =
|
g.setColour(juce::Colour(0xffaeb4bc));
|
||||||
inputFrequency > 0.0f
|
g.setFont(10.0f);
|
||||||
? juce::String(inputFrequency, 1)
|
|
||||||
+ " Hz"
|
|
||||||
: "-- Hz";
|
|
||||||
|
|
||||||
g.drawText(
|
const auto outputFrequencyText =
|
||||||
inputFrequencyText,
|
outputFrequency > 0.0f
|
||||||
30,
|
? juce::String(outputFrequency, 1) + " Hz"
|
||||||
270,
|
: "-- Hz";
|
||||||
150,
|
|
||||||
20,
|
|
||||||
juce::Justification::centred
|
|
||||||
);
|
|
||||||
|
|
||||||
g.setColour(juce::Colour(0xff777f89));
|
g.drawText(
|
||||||
g.setFont(
|
outputFrequencyText,
|
||||||
juce::Font(
|
30,
|
||||||
11.0f,
|
342,
|
||||||
juce::Font::bold
|
150,
|
||||||
)
|
16,
|
||||||
);
|
juce::Justification::centred
|
||||||
|
);
|
||||||
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 =
|
const auto latencyText =
|
||||||
"LATENCY: "
|
"LATENCY: "
|
||||||
@@ -863,11 +946,25 @@ void CrilleBassStripAudioProcessorEditor::resized()
|
|||||||
|
|
||||||
downTuneButton.setBounds(
|
downTuneButton.setBounds(
|
||||||
35,
|
35,
|
||||||
135,
|
120,
|
||||||
140,
|
140,
|
||||||
50
|
50
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tunerToggleButton.setBounds(
|
||||||
|
50,
|
||||||
|
175,
|
||||||
|
110,
|
||||||
|
30
|
||||||
|
);
|
||||||
|
|
||||||
|
tunerDisplay.setBounds(
|
||||||
|
30,
|
||||||
|
210,
|
||||||
|
150,
|
||||||
|
100
|
||||||
|
);
|
||||||
|
|
||||||
gateInputMeter.setBounds(
|
gateInputMeter.setBounds(
|
||||||
215,
|
215,
|
||||||
125,
|
125,
|
||||||
|
|||||||
@@ -54,6 +54,18 @@ private:
|
|||||||
juce::Colour sectionColour;
|
juce::Colour sectionColour;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TunerDisplay final : public juce::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TunerDisplay();
|
||||||
|
|
||||||
|
void setFrequency(float newFrequencyHz);
|
||||||
|
void paint(juce::Graphics& g) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float frequencyHz = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
struct Knob
|
struct Knob
|
||||||
{
|
{
|
||||||
juce::Slider slider;
|
juce::Slider slider;
|
||||||
@@ -74,6 +86,17 @@ private:
|
|||||||
juce::AudioProcessorValueTreeState::ButtonAttachment>
|
juce::AudioProcessorValueTreeState::ButtonAttachment>
|
||||||
downTuneAttachment;
|
downTuneAttachment;
|
||||||
|
|
||||||
|
SectionToggleButton tunerToggleButton {
|
||||||
|
"TUNER",
|
||||||
|
juce::Colour(0xffe5a536)
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<
|
||||||
|
juce::AudioProcessorValueTreeState::ButtonAttachment>
|
||||||
|
tunerToggleAttachment;
|
||||||
|
|
||||||
|
TunerDisplay tunerDisplay;
|
||||||
|
|
||||||
SectionToggleButton gateToggleButton {
|
SectionToggleButton gateToggleButton {
|
||||||
"NOISE GATE",
|
"NOISE GATE",
|
||||||
juce::Colour(0xffe5a536)
|
juce::Colour(0xffe5a536)
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso
|
|||||||
"DownTune",
|
"DownTune",
|
||||||
false));
|
false));
|
||||||
|
|
||||||
|
p.add(std::make_unique<juce::AudioParameterBool>(
|
||||||
|
pid("tunerOn"),
|
||||||
|
"Tuner On",
|
||||||
|
false));
|
||||||
|
|
||||||
p.add(std::make_unique<juce::AudioParameterBool>(
|
p.add(std::make_unique<juce::AudioParameterBool>(
|
||||||
pid("gateOn"),
|
pid("gateOn"),
|
||||||
"Gate On",
|
"Gate On",
|
||||||
@@ -492,13 +497,25 @@ void CrilleBassStripAudioProcessor::processBlock(
|
|||||||
const bool eqEnabled =
|
const bool eqEnabled =
|
||||||
apvts.getRawParameterValue("eqOn")->load() > 0.5f;
|
apvts.getRawParameterValue("eqOn")->load() > 0.5f;
|
||||||
|
|
||||||
if (buffer.getNumChannels() > 0)
|
const bool tunerEnabled =
|
||||||
|
apvts.getRawParameterValue("tunerOn")->load() > 0.5f;
|
||||||
|
|
||||||
|
if (tunerEnabled && buffer.getNumChannels() > 0)
|
||||||
{
|
{
|
||||||
updatePitchDetector(
|
updatePitchDetector(
|
||||||
buffer.getReadPointer(0),
|
buffer.getReadPointer(0),
|
||||||
numSamples
|
numSamples
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
detectedFrequencyHz.store(
|
||||||
|
0.0f,
|
||||||
|
std::memory_order_relaxed);
|
||||||
|
|
||||||
|
pitchSamplesCollected = 0;
|
||||||
|
pitchAnalysisCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear output channels that do not contain input data.
|
// Clear output channels that do not contain input data.
|
||||||
for (int c = getTotalNumInputChannels();
|
for (int c = getTotalNumInputChannels();
|
||||||
|
|||||||
Reference in new issue
Block a user