From dea5b2f0371d40caf08ed8363cc2bc0bf28e9d17 Mon Sep 17 00:00:00 2001 From: Yifeng Yu Date: Wed, 22 May 2024 11:40:37 -0400 Subject: [PATCH] Add max value for VU meters and improve GUI --- .../ControlPanel/Graph Components/VUMeter.cpp | 46 +++++++++++++++++-- .../ControlPanel/Graph Components/VUMeter.h | 4 ++ .../ControlPanel/Graph Components/VUPanel.cpp | 18 +++++--- .../ControlPanel/Graph Components/VUPanel.h | 2 + 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Source/Panels/ControlPanel/Graph Components/VUMeter.cpp b/Source/Panels/ControlPanel/Graph Components/VUMeter.cpp index 5f78f35..9594e9d 100644 --- a/Source/Panels/ControlPanel/Graph Components/VUMeter.cpp +++ b/Source/Panels/ControlPanel/Graph Components/VUMeter.cpp @@ -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); @@ -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) @@ -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() @@ -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; @@ -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() diff --git a/Source/Panels/ControlPanel/Graph Components/VUMeter.h b/Source/Panels/ControlPanel/Graph Components/VUMeter.h index 8bcc1d4..29b7e85 100644 --- a/Source/Panels/ControlPanel/Graph Components/VUMeter.h +++ b/Source/Panels/ControlPanel/Graph Components/VUMeter.h @@ -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) }; diff --git a/Source/Panels/ControlPanel/Graph Components/VUPanel.cpp b/Source/Panels/ControlPanel/Graph Components/VUPanel.cpp index 581400e..cedbc64 100644 --- a/Source/Panels/ControlPanel/Graph Components/VUPanel.cpp +++ b/Source/Panels/ControlPanel/Graph Components/VUPanel.cpp @@ -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) { @@ -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) diff --git a/Source/Panels/ControlPanel/Graph Components/VUPanel.h b/Source/Panels/ControlPanel/Graph Components/VUPanel.h index 31f40b0..4703b23 100644 --- a/Source/Panels/ControlPanel/Graph Components/VUPanel.h +++ b/Source/Panels/ControlPanel/Graph Components/VUPanel.h @@ -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) };