Skip to content

Commit

Permalink
Vertical VU meter tracks closer to wireframe
Browse files Browse the repository at this point in the history
By quite a lot actually!
  • Loading branch information
baconpaul committed Aug 2, 2024
1 parent fd58c83 commit 44d9892
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions include/sst/jucegui/components/VUMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ struct VUMeter : public juce::Component, public style::StyleConsumer, public sty
}
else
{
g.setColour(getColour(Styles::vu_gutter));
g.fillRect(getLocalBounds().reduced(1));

float zerodb = (0.7937 * getWidth());
auto scale = [](float x) {
x = std::clamp(0.5f * x, 0.f, 1.f);
Expand All @@ -114,22 +111,30 @@ struct VUMeter : public juce::Component, public style::StyleConsumer, public sty
auto vl = scale(L) * getWidth();
auto vr = scale(R) * getWidth();

auto rLeft = getLocalBounds().withHeight(getHeight() / 2).reduced(0, 2);
auto rRight = getLocalBounds().withTrimmedTop(getHeight() / 2).reduced(0, 2);

g.setColour(getColour(Styles::vu_gutter));

g.fillRect(rLeft);
g.fillRect(rRight);

auto fg = juce::ColourGradient::horizontal(getColour(Styles::vu_gradend), 0,
getColour(Styles::vu_gradstart), zerodb);
g.setGradientFill(fg);
g.fillRect(0.f, 0.f, vl, getHeight() / 2.f - 0.5);
g.fillRect(0.f, getHeight() / 2.f + 0.5, vr, getHeight() / 2.f - 0.5);
g.fillRect(rLeft.withWidth(vl));
g.fillRect(rRight.withWidth(vr));

if (vl > zerodb)
{
g.setColour(getColour(Styles::vu_overload));
g.fillRect(zerodb, 0.f, vl - zerodb, getWidth() / 2.f - 0.5);
g.fillRect(rLeft.withWidth(vl).withTrimmedLeft(zerodb));
}

if (vr > zerodb)
{
g.setColour(getColour(Styles::vu_overload));
g.fillRect(zerodb, getHeight() / 2.f + 0.5, vr - zerodb, getWidth() / 2.f - 0.5);
g.fillRect(rRight.withWidth(vr).withTrimmedLeft(zerodb));
}

g.setColour(getColour(Styles::outline));
Expand Down

0 comments on commit 44d9892

Please sign in to comment.