From f5c6bbcc82fd63ebc5c08f2edb20f5f3a0ba0128 Mon Sep 17 00:00:00 2001 From: Michael Hartmann Date: Wed, 8 Jan 2025 17:09:35 -0800 Subject: [PATCH] Added a clip-color --- modules/gin_dsp/components/gin_levelmeter.cpp | 59 ++++++++++++------- modules/gin_dsp/components/gin_levelmeter.h | 3 +- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/modules/gin_dsp/components/gin_levelmeter.cpp b/modules/gin_dsp/components/gin_levelmeter.cpp index 51046efa48..9ac09a8d5c 100644 --- a/modules/gin_dsp/components/gin_levelmeter.cpp +++ b/modules/gin_dsp/components/gin_levelmeter.cpp @@ -4,8 +4,10 @@ LevelMeter::LevelMeter (const LevelTracker& l, juce::NormalisableRange r) { startTimerHz (60); - setColour (lineColourId, juce::Colours::white); - setColour (meterColourId, juce::Colours::white.withAlpha (0.3f)); + setColour ( lineColourId, juce::Colours::white); + setColour ( meterColourId, juce::Colours::white.withAlpha ( 0.3f ) ); + setColour ( backgroundColourId, juce::Colours::white.withAlpha ( 0.1f ) ); + setColour ( clipColourId, juce::Colours::red ); } LevelMeter::~LevelMeter() @@ -17,25 +19,40 @@ LevelMeter::~LevelMeter() void LevelMeter::paint (juce::Graphics& g) { - g.setColour (findColour (lineColourId)); - g.drawRect (getLocalBounds()); - - auto level = juce::jlimit (range.start, range.end, tracker.getLevel()); - - auto rc = getLocalBounds(); - - if (topDown) - { - rc.removeFromBottom (juce::roundToInt (range.convertTo0to1 (level) * float ( getHeight() ))); - g.setColour (findColour (meterColourId)); - g.fillRect (rc); - } - else - { - rc = rc.removeFromBottom (juce::roundToInt (range.convertTo0to1 (level) * float ( getHeight() ))); - g.setColour (findColour (meterColourId)); - g.fillRect (rc); - } + g.setColour ( findColour ( lineColourId ) ); + g.drawRect ( getLocalBounds () ); + + auto level = juce::jlimit ( range.start, range.end, tracker.getLevel () ); + auto rc = getLocalBounds ().toFloat (); + + if ( topDown ) + { + g.setColour ( findColour ( backgroundColourId ) ); + g.fillRect ( rc.removeFromBottom ( range.convertTo0to1 ( level ) * rc.getHeight () ) ); + + g.setColour ( findColour ( meterColourId ) ); + g.fillRect ( rc ); + + if ( tracker.getClip () ) + { + g.setColour ( findColour ( clipColourId ) ); + g.fillRect ( getLocalBounds ().toFloat ().withTrimmedTop ( getHeight () * 0.95f ) ); + } + } + else + { + g.setColour ( findColour ( meterColourId ) ); + g.fillRect ( rc.removeFromBottom ( range.convertTo0to1 ( level ) * rc.getHeight () ) ); + + g.setColour ( findColour ( backgroundColourId ) ); + g.fillRect ( rc ); + + if ( tracker.getClip () ) + { + g.setColour ( findColour ( clipColourId ) ); + g.fillRect ( getLocalBounds ().toFloat ().withTrimmedBottom ( getHeight () * 0.95f ) ); + } + } } void LevelMeter::timerCallback() diff --git a/modules/gin_dsp/components/gin_levelmeter.h b/modules/gin_dsp/components/gin_levelmeter.h index 55812b8c89..3a114c4089 100644 --- a/modules/gin_dsp/components/gin_levelmeter.h +++ b/modules/gin_dsp/components/gin_levelmeter.h @@ -24,7 +24,8 @@ class LevelMeter : public juce::Component, { lineColourId = 0x1291e10, backgroundColourId = 0x1291e11, - meterColourId = 0x1291e12 + meterColourId = 0x1291e12, + clipColourId = 0x1291e13 }; private: