Skip to content

Commit

Permalink
An improved VUMeter
Browse files Browse the repository at this point in the history
Good enough for people to look at in conduit, at least.
Vertical only still
  • Loading branch information
baconpaul committed Sep 19, 2023
1 parent 71df218 commit 2d45c1e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
39 changes: 35 additions & 4 deletions include/sst/jucegui/components/VUMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ struct VUMeter : public juce::Component, public style::StyleConsumer, public sty
using sprop = style::StyleSheet::Property;
static constexpr sclass styleClass{"vumeter"};

static constexpr sprop vugutter{"vumetergutter.color"};
static constexpr sprop vugradstart{"vumetergradstart.color"};
static constexpr sprop vugradend{"vumetergradend.color"};
static constexpr sprop vuoverload{"vumeteroverload.color"};

static void initialize()
{
style::StyleSheet::addClass(styleClass).withBaseClass(ControlStyles::styleClass);
style::StyleSheet::addClass(styleClass)
.withBaseClass(ControlStyles::styleClass)
.withProperty(vugutter)
.withProperty(vugradstart)
.withProperty(vugradend)
.withProperty(vuoverload);
}
};

Expand All @@ -58,6 +68,9 @@ struct VUMeter : public juce::Component, public style::StyleConsumer, public sty
{
if (direction == VERTICAL)
{
g.setColour(getColour(Styles::vugutter));
g.fillRect(getLocalBounds().reduced(1));

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

g.setColour(juce::Colour(100, 100, 140));
g.fillRect(0.f, vl, getWidth() / 2.f, 1.f * getHeight() - vl);
g.fillRect(getWidth() / 2.f, vr, getWidth() / 2.f, 1.f * getHeight() - vr);
auto fg = juce::ColourGradient::vertical(getColour(Styles::vugradend), zerodb,
getColour(Styles::vugradstart), getHeight());
g.setGradientFill(fg);
g.fillRect(0.f, vl, getWidth() / 2.f - 0.5, 1.f * getHeight() - vl);
g.fillRect(getWidth() / 2.f + 0.5, vr, getWidth() / 2.f - 0.5, 1.f * getHeight() - vr);

if (vl < getHeight() - zerodb)
{
g.setColour(getColour(Styles::vuoverload));
g.fillRect(0.f, vl, getWidth() / 2.f - 0.5, getHeight() - zerodb - vl);
}

if (vr < getHeight() - zerodb)
{
g.setColour(getColour(Styles::vuoverload));
g.fillRect(getWidth() / 2.f + 0.5, vr, getWidth() / 2.f - 0.5,
getHeight() - zerodb - vr);
}

g.setColour(getColour(Styles::regionBorder));
g.drawRect(getLocalBounds(), 1);
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions src/sst/jucegui/style/StyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <sst/jucegui/components/WindowPanel.h>
#include <sst/jucegui/components/SevenSegmentControl.h>
#include <sst/jucegui/components/Label.h>
#include <sst/jucegui/components/VUMeter.h>
#include <sst/jucegui/util/DebugHelpers.h>

#include <cassert>
Expand Down Expand Up @@ -247,6 +248,14 @@ struct DarkSheet : public StyleSheetBuiltInImpl
setColour(n::styleClass, n::knobbase, juce::Colour(82, 82, 82));
}

{
using n = components::VUMeter::Styles;
setColour(n::styleClass, n::vugutter, juce::Colour(0, 0, 0));
setColour(n::styleClass, n::vugradstart, juce::Colour(200, 200, 100));
setColour(n::styleClass, n::vugradend, juce::Colour(100, 100, 220));
setColour(n::styleClass, n::vuoverload, juce::Colour(200, 50, 50));
}

{
using n = components::VSlider::Styles;
}
Expand Down Expand Up @@ -353,6 +362,14 @@ struct LightSheet : public StyleSheetBuiltInImpl
setColour(n::styleClass, n::knobbase, juce::Colour(194, 194, 194));
}

{
using n = components::VUMeter::Styles;
setColour(n::styleClass, n::vugutter, juce::Colour(0, 0, 0));
setColour(n::styleClass, n::vugradstart, juce::Colour(200, 200, 100));
setColour(n::styleClass, n::vugradend, juce::Colour(100, 100, 220));
setColour(n::styleClass, n::vuoverload, juce::Colour(200, 50, 50));
}

{
using n = components::VSlider::Styles;
// bass class is fine
Expand Down Expand Up @@ -505,6 +522,7 @@ void StyleSheet::initializeStyleSheets(std::function<void()> userClassInitialize
n::MultiSwitch::Styles::initialize();
n::DraggableTextEditableValue::Styles::initialize();
n::SevenSegmentControl::Styles::initialize();
n::VUMeter::Styles::initialize();

n::TabularizedTreeViewer::Styles::initialize();
}
Expand Down

0 comments on commit 2d45c1e

Please sign in to comment.