Förbättrar tuner med tydligare stämindikering

This commit is contained in:
crille committed 2026-11-26 16:09:49 +01:00
1 parent 8e0f162947
commit 606c011c31
3 files changed
+88 -62

No files matched your search

Binary file not shown.
+88 -62
View File
@@ -237,85 +237,129 @@ void CrilleBassStripAudioProcessorEditor::TunerDisplay::paint(
bounds.removeFromTop(14),
juce::Justification::centred);
const float centreX = static_cast<float>(getWidth()) * 0.5f;
const float indicatorY = 62.0f;
const auto orange = juce::Colour(0xffe5a536);
const auto inactive = juce::Colour(0xff454a51);
const auto green = juce::Colour(0xff45c95a);
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.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(inactive);
for (int i = 0; i < 3; ++i)
{
const float leftX = 12.0f + static_cast<float>(i) * 15.0f;
juce::Path leftArrow;
leftArrow.addTriangle(
leftX,
indicatorY,
leftX + 10.0f,
indicatorY - 7.0f,
leftX + 10.0f,
indicatorY + 7.0f);
g.fillPath(leftArrow);
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);
const float rightX = static_cast<float>(getWidth() - 12) - static_cast<float>(i) * 15.0f;
juce::Path rightArrow;
rightArrow.addTriangle(
rightX,
indicatorY,
rightX - 10.0f,
indicatorY - 7.0f,
rightX - 10.0f,
indicatorY + 7.0f);
g.fillPath(rightArrow);
}
g.setColour(juce::Colour(0xff686e76));
g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f);
g.setFont(9.0f);
g.drawText("PLAY A NOTE", 0, 78, getWidth(), 16, juce::Justification::centred);
g.drawText(
"PLAY A NOTE",
0,
76,
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 float absoluteCents = std::abs(cents);
const bool inTune = absoluteCents <= 5.0f;
const auto noteName = frequencyToNoteName(targetFrequency);
int litArrowCount = 0;
if (!inTune)
{
if (absoluteCents > 30.0f)
litArrowCount = 3;
else if (absoluteCents > 15.0f)
litArrowCount = 2;
else
litArrowCount = 1;
}
g.setColour(inTune
? juce::Colour(0xff45c95a)
? green
: 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",
noteName,
0,
43,
14,
getWidth(),
15,
30,
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);
for (int i = 0; i < 3; ++i)
{
const bool leftIsLit = cents > 5.0f && i < litArrowCount;
const bool rightIsLit = cents < -5.0f && i < litArrowCount;
const float leftX = 12.0f + static_cast<float>(i) * 15.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);
leftX,
indicatorY,
leftX + 10.0f,
indicatorY - 7.0f,
leftX + 10.0f,
indicatorY + 7.0f);
g.setColour(leftIsLit ? orange : inactive);
g.fillPath(leftArrow);
g.setColour(!inTune && cents < -5.0f ? orange : inactive);
const float rightX = static_cast<float>(getWidth() - 12) - static_cast<float>(i) * 15.0f;
juce::Path rightArrow;
rightArrow.addTriangle(
rightX,
indicatorY,
rightX - 10.0f,
indicatorY - 7.0f,
rightX - 10.0f,
indicatorY + 7.0f);
g.setColour(rightIsLit ? orange : inactive);
g.fillPath(rightArrow);
}
g.setColour(inTune ? green : juce::Colour(0xff686e76));
g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f);
@@ -324,18 +368,17 @@ void CrilleBassStripAudioProcessorEditor::TunerDisplay::paint(
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";
statusText = "TUNE UP";
else
statusText = "TUNE DOWN " + juce::String(std::round(std::abs(cents)), 0) + " ct";
statusText = "TUNE DOWN";
g.drawText(
statusText,
0,
80,
76,
getWidth(),
16,
juce::Justification::centred);
@@ -873,23 +916,6 @@ void CrilleBassStripAudioProcessorEditor::paint(
30,
juce::Justification::centred
);
g.setColour(juce::Colour(0xffaeb4bc));
g.setFont(10.0f);
const auto outputFrequencyText =
outputFrequency > 0.0f
? juce::String(outputFrequency, 1) + " Hz"
: "-- Hz";
g.drawText(
outputFrequencyText,
30,
342,
150,
16,
juce::Justification::centred
);
}
const auto latencyText =