Skip to content

Commit

Permalink
Add max value for VU meters and improve GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryuhoo committed May 22, 2024
1 parent a5d16aa commit dea5b2f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
46 changes: 42 additions & 4 deletions Source/Panels/ControlPanel/Graph Components/VUMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ VUMeter::VUMeter(FireAudioProcessor* inProcessor)
: mProcessor(inProcessor),
mIsInput(true),
mCh0Level(0),
mCh1Level(0)
mCh1Level(0),
mMaxCh0Level(-96.0f),
mMaxCh1Level(-96.0f),
mMaxValueDecayCounter(0)
{
setInterceptsMouseClicks(false, false);
startTimerHz(60);
Expand Down Expand Up @@ -58,6 +61,7 @@ void VUMeter::paint (juce::Graphics& g)
ch1fill = 0;
}

// draw VU meter values
g.setColour(juce::Colours::yellowgreen.withBrightness(0.9));

if (mProcessor->getTotalNumInputChannels() == 2)
Expand All @@ -70,6 +74,21 @@ void VUMeter::paint (juce::Graphics& g)
g.fillRect(meterWidth, ch0fill, meterWidth, getHeight());
}

// draw max VU meter values
g.setColour(juce::Colours::yellowgreen.withBrightness(0.5));
int maxCh0fill = getHeight() - (getHeight() * mMaxCh0Level);
int maxCh1fill = getHeight() - (getHeight() * mMaxCh1Level);

if (mProcessor->getTotalNumInputChannels() == 2)
{
g.drawLine(0, maxCh0fill, meterWidth, maxCh0fill, 2.0f);
g.drawLine(meterWidth * 2, maxCh1fill, meterWidth * 3, maxCh1fill, 2.0f);
}
else
{
g.drawLine(meterWidth, maxCh0fill, meterWidth * 2, maxCh0fill, 2.0f);
}

}

void VUMeter::resized()
Expand Down Expand Up @@ -98,6 +117,10 @@ void VUMeter::timerCallback()
updatedCh1Level = mProcessor->getOutputMeterRMSLevel(1, mMeterName);
}

// update max values
mMaxCh0Level = juce::jmax(mMaxCh0Level, updatedCh0Level);
mMaxCh1Level = juce::jmax(mMaxCh1Level, updatedCh1Level);

if (updatedCh0Level > mCh0Level)
{
mCh0Level = updatedCh0Level;
Expand All @@ -119,11 +142,26 @@ void VUMeter::timerCallback()
mCh0Level = helper_denormalize(mCh0Level);
mCh1Level = helper_denormalize(mCh1Level);

// repaint if not equal to 0
if (mCh0Level && mCh1Level)
// decay max values
if (mMaxCh0Level > mCh0Level || mMaxCh1Level > mCh1Level)
{
repaint();
if (mMaxValueDecayCounter < MAX_VALUE_HOLD_FRAMES)
{
++mMaxValueDecayCounter;
}
else
{
mMaxCh0Level -= 0.01f;
mMaxCh1Level -= 0.01f;
}
}
else
{
mMaxValueDecayCounter = 0;
}

repaint();

}

float VUMeter::getLeftChannelLevel()
Expand Down
4 changes: 4 additions & 0 deletions Source/Panels/ControlPanel/Graph Components/VUMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ class VUMeter : public juce::Component, juce::Timer
juce::String mMeterName;
float mCh0Level;
float mCh1Level;
float mMaxCh0Level;
float mMaxCh1Level;
int mMaxValueDecayCounter;
const int MAX_VALUE_HOLD_FRAMES = 60;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VUMeter)
};
18 changes: 12 additions & 6 deletions Source/Panels/ControlPanel/Graph Components/VUPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,35 @@ void VUPanel::paint (juce::Graphics& g)

// draw compressor threshold line
g.setColour(KNOB_SUBFONT_COLOUR);

juce::String threshID = "";


bool isGlobal = false;
if (focusBandNum == 0)
{
vuMeterIn.setParameters(true, "Band1");
vuMeterOut.setParameters(false, "Band1");
threshID = COMP_THRESH_ID1;
compBypassID = COMP_BYPASS_ID1;
}
else if (focusBandNum == 1)
{
vuMeterIn.setParameters(true, "Band2");
vuMeterOut.setParameters(false, "Band2");
threshID = COMP_THRESH_ID2;
compBypassID = COMP_BYPASS_ID2;
}
else if (focusBandNum == 2)
{
vuMeterIn.setParameters(true, "Band3");
vuMeterOut.setParameters(false, "Band3");
threshID = COMP_THRESH_ID3;
compBypassID = COMP_BYPASS_ID3;
}
else if (focusBandNum == 3)
{
vuMeterIn.setParameters(true, "Band4");
vuMeterOut.setParameters(false, "Band4");
threshID = COMP_THRESH_ID4;
compBypassID = COMP_BYPASS_ID4;
}
else if (focusBandNum == -1)
{
Expand All @@ -87,9 +89,13 @@ void VUPanel::paint (juce::Graphics& g)
{
pointerX = VU_METER_X_1 + vuMeterIn.getWidth() / 3.0f;
}

g.setColour(juce::Colours::yellowgreen);
g.drawLine(pointerX + vuMeterIn.getWidth() / 3.0f, compressorLineY, pointerX + vuMeterIn.getWidth() / 3.0f * 2.0f, compressorLineY, 1);

bool compBypassState = *(processor.treeState.getRawParameterValue(compBypassID));
if (compBypassState)
{
g.setColour(juce::Colours::yellowgreen);
g.drawLine(pointerX + vuMeterIn.getWidth() / 3.0f, compressorLineY, pointerX + vuMeterIn.getWidth() / 3.0f * 2.0f, compressorLineY, 1.0f);
}
}

if (mZoomState)
Expand Down
2 changes: 2 additions & 0 deletions Source/Panels/ControlPanel/Graph Components/VUPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ class VUPanel : public GraphTemplate, juce::Timer
int updateCounter = 0;
float displayInputValue = 0.0f;
float displayOutputValue = 0.0f;
juce::String threshID = "";
juce::String compBypassID = "";
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VUPanel)
};

0 comments on commit dea5b2f

Please sign in to comment.