In addition to animation usages, I’ve started (happily) using VBlankAttachment as an alternative to timers in the UI (to trigger repainting of visualizers and other UI that update on parameter changes).
The approach I was using before was using timers to pick up atomics (set by the audio thread on param change), which seems to be the safest approach, as calling repaint from the audio thread is dubious, AsyncUpdater isn’t to be used on the audio thread, and the parameter changed callbacks (like in the apvts) are again not the best place to be doing things with components.
Now, when parameters change, I still set an atomic flag on the component. The component has a VBlank callback looking for that flag. When true, it calls repaint()
, flagging the component as dirty. The nice part about this is it happens immediately inline with the next paint call (the timer approach sometimes had drawbacks and glitches since the timer fires at unrelated rates to paint calls).
Edit: I’ve also been assigning the VBlankAttachment to be empty/default constructed on visibilityChanged
to save polling for the atomic when the components aren’t visible.