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
+92 -66

No files matched your search

Binary file not shown.
+92 -66
View File
@@ -237,85 +237,129 @@ void CrilleBassStripAudioProcessorEditor::TunerDisplay::paint(
bounds.removeFromTop(14), bounds.removeFromTop(14),
juce::Justification::centred); 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) if (!hasSignal)
{ {
g.setColour(juce::Colour(0xfff0f1f2)); g.setColour(juce::Colour(0xfff0f1f2));
g.setFont(juce::Font(26.0f, juce::Font::bold)); 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.setColour(inactive);
g.setFont(10.0f); for (int i = 0; i < 3; ++i)
g.drawText("-- Hz", 0, 43, getWidth(), 15, juce::Justification::centred); {
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)); const float rightX = static_cast<float>(getWidth() - 12) - static_cast<float>(i) * 15.0f;
g.drawLine(18.0f, 70.0f, static_cast<float>(getWidth() - 18), 70.0f, 2.0f); juce::Path rightArrow;
g.fillEllipse(static_cast<float>(getWidth()) * 0.5f - 4.0f, 66.0f, 8.0f, 8.0f); 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.setColour(juce::Colour(0xff686e76));
g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f);
g.setFont(9.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; return;
} }
const float midiNote = const float midiNote =
69.0f + 12.0f * std::log2(frequencyHz / 440.0f); 69.0f + 12.0f * std::log2(frequencyHz / 440.0f);
const int nearestMidiNote = const int nearestMidiNote =
static_cast<int>(std::round(midiNote)); static_cast<int>(std::round(midiNote));
const float targetFrequency = const float targetFrequency =
440.0f * std::pow( 440.0f * std::pow(
2.0f, 2.0f,
static_cast<float>(nearestMidiNote - 69) / 12.0f); static_cast<float>(nearestMidiNote - 69) / 12.0f);
const float cents = const float cents =
1200.0f * std::log2(frequencyHz / targetFrequency); 1200.0f * std::log2(frequencyHz / targetFrequency);
const float absoluteCents = std::abs(cents);
const bool inTune = std::abs(cents) <= 5.0f; const bool inTune = absoluteCents <= 5.0f;
const auto noteName = frequencyToNoteName(targetFrequency); 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 g.setColour(inTune
? juce::Colour(0xff45c95a) ? green
: juce::Colour(0xfff0f1f2)); : juce::Colour(0xfff0f1f2));
g.setFont(juce::Font(26.0f, juce::Font::bold)); 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( g.drawText(
juce::String(frequencyHz, 1) + " Hz", noteName,
0, 0,
43, 14,
getWidth(), getWidth(),
15, 30,
juce::Justification::centred); juce::Justification::centred);
const float centreX = static_cast<float>(getWidth()) * 0.5f; for (int i = 0; i < 3; ++i)
const float indicatorY = 70.0f; {
const auto orange = juce::Colour(0xffe5a536); const bool leftIsLit = cents > 5.0f && i < litArrowCount;
const auto inactive = juce::Colour(0xff454a51); const bool rightIsLit = cents < -5.0f && i < litArrowCount;
const auto green = juce::Colour(0xff45c95a);
g.setColour(juce::Colour(0xff3c424a)); const float leftX = 12.0f + static_cast<float>(i) * 15.0f;
g.drawLine(20.0f, indicatorY, static_cast<float>(getWidth() - 20), indicatorY, 2.0f); juce::Path leftArrow;
leftArrow.addTriangle(
leftX,
indicatorY,
leftX + 10.0f,
indicatorY - 7.0f,
leftX + 10.0f,
indicatorY + 7.0f);
g.setColour(leftIsLit ? orange : inactive);
g.fillPath(leftArrow);
juce::Path leftArrow; const float rightX = static_cast<float>(getWidth() - 12) - static_cast<float>(i) * 15.0f;
leftArrow.addTriangle( juce::Path rightArrow;
12.0f, indicatorY, rightArrow.addTriangle(
28.0f, indicatorY - 9.0f, rightX,
28.0f, indicatorY + 9.0f); indicatorY,
rightX - 10.0f,
juce::Path rightArrow; indicatorY - 7.0f,
rightArrow.addTriangle( rightX - 10.0f,
static_cast<float>(getWidth() - 12), indicatorY, indicatorY + 7.0f);
static_cast<float>(getWidth() - 28), indicatorY - 9.0f, g.setColour(rightIsLit ? orange : inactive);
static_cast<float>(getWidth() - 28), indicatorY + 9.0f); g.fillPath(rightArrow);
}
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.setColour(inTune ? green : juce::Colour(0xff686e76));
g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f); 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)); g.setFont(juce::Font(9.0f, juce::Font::bold));
juce::String statusText; juce::String statusText;
if (inTune) if (inTune)
statusText = "IN TUNE"; statusText = "IN TUNE";
else if (cents < 0.0f) else if (cents < 0.0f)
statusText = "TUNE UP " + juce::String(std::round(std::abs(cents)), 0) + " ct"; statusText = "TUNE UP";
else else
statusText = "TUNE DOWN " + juce::String(std::round(std::abs(cents)), 0) + " ct"; statusText = "TUNE DOWN";
g.drawText( g.drawText(
statusText, statusText,
0, 0,
80, 76,
getWidth(), getWidth(),
16, 16,
juce::Justification::centred); juce::Justification::centred);
@@ -873,23 +916,6 @@ void CrilleBassStripAudioProcessorEditor::paint(
30, 30,
juce::Justification::centred 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 = const auto latencyText =