Skip to content

Commit

Permalink
Added a clip-color
Browse files Browse the repository at this point in the history
  • Loading branch information
reFX-Mike committed Jan 9, 2025
1 parent 1ab0c9f commit f5c6bbc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
59 changes: 38 additions & 21 deletions modules/gin_dsp/components/gin_levelmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ LevelMeter::LevelMeter (const LevelTracker& l, juce::NormalisableRange<float> 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()
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion modules/gin_dsp/components/gin_levelmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LevelMeter : public juce::Component,
{
lineColourId = 0x1291e10,
backgroundColourId = 0x1291e11,
meterColourId = 0x1291e12
meterColourId = 0x1291e12,
clipColourId = 0x1291e13
};

private:
Expand Down

0 comments on commit f5c6bbc

Please sign in to comment.