VU Meter rendering stratagies

What’s the best VU meter rendering strategy. I’m not asking about communication between audio thread and UI. I’m asking about actual rendering. On windows using the paint directly on a component seems to work quite well but OSX seems a little CPU hungry in release mode. I have tried OpenGL but this seems a little overkill. The other option is lots of small components and setting them visible…

With paint method I have tried a less nieve approach and manually updating just the area that’s changed which yields some improvement.

Is it best to trigger repaint with timer event or is there another mechanism that I’m unaware of?

Calculate the signal gain in the processor (eg with envelope follower) and read the gain and repaint() from timerCallback in the component.


I’ve found that not painting the VU meter once the associated gain value has reached a denormalized value of 0 has helped with CPU load when painting multiple VU meters as well.

A few general repainting tips that may help:

Try setting Component::setBufferedToImage (true) so your components don’t need to redraw themselves unless they’ve actually changed. Especially for Components that have text. Have you VU meter background and needle separate components, and have the background buffered to image so only the needle needs to redraw each frame.

Set your components to opaque so they don’t need to redraw the component underneath.

Check how much the needle has moved before triggering a repaint(), if it’s moved very little, skip the repaint.


Not sure if it’s still the case, but previously on OSX repaints could end up combining multiple components into one dirty rect (possibly quite large if the areas are far apart). You can enable JUCE_ENABLE_REPAINT_DEBUGGING to see if this is happening.