| 33 | } |
| 34 | |
| 35 | void VUMeter::paint(juce::Graphics& g) |
| 36 | { |
| 37 | // Ensure all level values are clamped between [0, 1] for drawing |
| 38 | const auto rms0 = juce::jlimit(0.0f, 1.0f, mRmsCh0Level); |
| 39 | const auto rms1 = juce::jlimit(0.0f, 1.0f, mRmsCh1Level); |
| 40 | const auto peak0 = juce::jlimit(0.0f, 1.0f, mPeakCh0Level); |
| 41 | const auto peak1 = juce::jlimit(0.0f, 1.0f, mPeakCh1Level); |
| 42 | const auto peakHold0 = juce::jlimit(0.0f, 1.0f, mPeakHoldCh0Level); |
| 43 | const auto peakHold1 = juce::jlimit(0.0f, 1.0f, mPeakHoldCh1Level); |
| 44 | |
| 45 | // 1. Draw Backgrounds |
| 46 | g.setColour(COLOUR6); |
| 47 | if (mProcessor->getTotalNumInputChannels() == 2) |
| 48 | { |
| 49 | g.fillRect(leftMeterBounds); |
| 50 | g.fillRect(rightMeterBounds); |
| 51 | } |
| 52 | else // Mono |
| 53 | { |
| 54 | g.fillRect(leftMeterBounds); |
| 55 | } |
| 56 | |
| 57 | // 2. Calculate Fill Heights |
| 58 | const auto h = (float) getHeight(); |
| 59 | const auto rmsCh0FillY = h - h * rms0; |
| 60 | const auto rmsCh1FillY = h - h * rms1; |
| 61 | const auto peakCh0FillY = h - h * peak0; |
| 62 | const auto peakCh1FillY = h - h * peak1; |
| 63 | |
| 64 | // 3. Draw Peak Level Bars (Light color) |
| 65 | g.setColour(juce::Colours::yellowgreen.withAlpha(0.6f)); |
| 66 | if (mProcessor->getTotalNumInputChannels() == 2) |
| 67 | { |
| 68 | g.fillRect((float) leftMeterBounds.getX(), peakCh0FillY, (float) leftMeterBounds.getWidth(), h - peakCh0FillY); |
| 69 | g.fillRect((float) rightMeterBounds.getX(), peakCh1FillY, (float) rightMeterBounds.getWidth(), h - peakCh1FillY); |
| 70 | } |
| 71 | else // Mono |
| 72 | { |
| 73 | g.fillRect((float) leftMeterBounds.getX(), peakCh0FillY, (float) leftMeterBounds.getWidth(), h - peakCh0FillY); |
| 74 | } |
| 75 | |
| 76 | // 4. Draw RMS Level Bars (Dark color) |
| 77 | g.setColour(juce::Colours::yellowgreen); |
| 78 | if (mProcessor->getTotalNumInputChannels() == 2) |
| 79 | { |
| 80 | g.fillRect((float) leftMeterBounds.getX(), rmsCh0FillY, (float) leftMeterBounds.getWidth(), h - rmsCh0FillY); |
| 81 | g.fillRect((float) rightMeterBounds.getX(), rmsCh1FillY, (float) rightMeterBounds.getWidth(), h - rmsCh1FillY); |
| 82 | } |
| 83 | else // Mono |
| 84 | { |
| 85 | g.fillRect((float) leftMeterBounds.getX(), rmsCh0FillY, (float) leftMeterBounds.getWidth(), h - rmsCh0FillY); |
| 86 | } |
| 87 | |
| 88 | // 5. Draw Peak-Hold Lines |
| 89 | g.setColour(juce::Colours::yellowgreen.withBrightness(0.5f)); |
| 90 | const auto peakHoldCh0Y = h - h * peakHold0; |
| 91 | const auto peakHoldCh1Y = h - h * peakHold1; |
| 92 | |