Skip to content

Commit

Permalink
Update VU meter
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryuhoo committed May 22, 2024
1 parent e97aed6 commit a5d16aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/GUI/InterfaceDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@
#define LIMITER_COLOUR juce::Colours::mediumpurple

// VU meters
#define SMOOTH_COEFF 0.2
#define SMOOTH_COEFF 0.5
36 changes: 24 additions & 12 deletions Source/Panels/ControlPanel/Graph Components/VUPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void VUPanel::paint (juce::Graphics& g)
if (!isGlobal)
{
float threshValue = *(processor.treeState.getRawParameterValue(threshID));
float compressorLineY = VU_METER_Y + VU_METER_HEIGHT * -threshValue / 96.0f; // 96 is VU meter range
float compressorLineY = VU_METER_Y + VU_METER_HEIGHT * -threshValue / VU_METER_RANGE;
float pointerX;
if (processor.getTotalNumInputChannels() == 2)
{
Expand All @@ -87,19 +87,19 @@ void VUPanel::paint (juce::Graphics& g)
{
pointerX = VU_METER_X_1 + vuMeterIn.getWidth() / 3.0f;
}
g.drawLine(pointerX, compressorLineY, pointerX - getWidth() / 20, compressorLineY - getHeight() / 20, 1);
g.drawLine(pointerX - getWidth() / 20, compressorLineY - getHeight() / 20, pointerX - getWidth() / 20, compressorLineY + getHeight() / 20, 1);
g.drawLine(pointerX, compressorLineY, pointerX - getWidth() / 20, compressorLineY + getHeight() / 20, 1);

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

if (mZoomState)
{
// show db meter scale text
float textX = (VU_METER_X_1 + VU_METER_X_2 - VU_METER_WIDTH) / 2.0f;
float text20Y = VU_METER_Y + 20.0f / 96.0f * VU_METER_HEIGHT;
float text40Y = VU_METER_Y + 40.0f / 96.0f * VU_METER_HEIGHT;
float text60Y = VU_METER_Y + 60.0f / 96.0f * VU_METER_HEIGHT;
float text80Y = VU_METER_Y + 80.0f / 96.0f * VU_METER_HEIGHT;
float text20Y = VU_METER_Y + 20.0f / VU_METER_RANGE * VU_METER_HEIGHT;
float text40Y = VU_METER_Y + 40.0f / VU_METER_RANGE * VU_METER_HEIGHT;
float text60Y = VU_METER_Y + 60.0f / VU_METER_RANGE * VU_METER_HEIGHT;
float text80Y = VU_METER_Y + 80.0f / VU_METER_RANGE * VU_METER_HEIGHT;
float textWidth = getWidth() / 5;
float textHeight = getHeight() / 10;
// g.drawText(" 0", textX, VU_METER_Y - textHeight / 2.0f, textWidth, textHeight, juce::Justification::centred);
Expand All @@ -111,14 +111,26 @@ void VUPanel::paint (juce::Graphics& g)

// show input/output db
g.setColour(juce::Colours::yellowgreen);
float inputValue = ((vuMeterIn.getLeftChannelLevel() + vuMeterIn.getRightChannelLevel()) / 2.0f) * 96.0f - 96.0f;
float outputValue = ((vuMeterOut.getLeftChannelLevel() + vuMeterOut.getRightChannelLevel()) / 2.0f) * 96.0f - 96.0f;
float inputValue = ((vuMeterIn.getLeftChannelLevel() + vuMeterIn.getRightChannelLevel()) / 2.0f) * VU_METER_RANGE - VU_METER_RANGE;
float outputValue = ((vuMeterOut.getLeftChannelLevel() + vuMeterOut.getRightChannelLevel()) / 2.0f) * VU_METER_RANGE - VU_METER_RANGE;

if (updateCounter == 5)
{
displayInputValue = inputValue;
displayOutputValue = outputValue;
updateCounter = 0;
}
else
{
updateCounter++;
}

juce::Rectangle<int> localBounds = getLocalBounds();
juce::Rectangle<int> leftArea = localBounds.removeFromLeft(getWidth() / 4);
juce::Rectangle<int> rightArea = localBounds.removeFromRight(getWidth() / 3);
g.setFont(juce::Font(KNOB_FONT, 20.0f * getHeight() / 150.0f, juce::Font::bold));
g.drawText(juce::String(inputValue, 1), leftArea, juce::Justification::centred);
g.drawText(juce::String(outputValue, 1), rightArea, juce::Justification::centred);
g.drawText(juce::String(displayInputValue, 1), leftArea, juce::Justification::centred);
g.drawText(juce::String(displayOutputValue, 1), rightArea, juce::Justification::centred);

g.setColour(juce::Colours::yellowgreen.withAlpha(0.5f));
g.setFont(juce::Font(KNOB_FONT, 14.0f * getHeight() / 150.0f, juce::Font::plain));
Expand Down
5 changes: 5 additions & 0 deletions Source/Panels/ControlPanel/Graph Components/VUPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class VUPanel : public GraphTemplate, juce::Timer
private:
FireAudioProcessor &processor;
int focusBandNum;
const float VU_METER_RANGE = 96.0f;
VUMeter vuMeterIn;
VUMeter vuMeterOut;
// for smoothing meter values
int updateCounter = 0;
float displayInputValue = 0.0f;
float displayOutputValue = 0.0f;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VUPanel)
};

0 comments on commit a5d16aa

Please sign in to comment.