Best practice when updating UI from underlying data


Hi all,

I currently use timers to update all GUI components so that they change to reflect the underlying data model. This isn’t just for level meters or things that need updating at high FPS, but also for knobs and sliders and other things that rarely change. The timer update calls are wasteful but have worked ok until now. I now have a HashMap container (but I’d be happy to use whatever container makes my life easiest) in the underlying data model and a table component in the UI that reflects the stored data. I would like the UI table to update when the underlying data changes, but using the timer method to repaint the table as it grows is beginning to smell really fishy.

I’m guessing that the data should sense when it has been changed and fire an event off to the UI components somehow. However, the best way to do this is a bit of a mystery to me.

Any clarification, hints, or tricks would be great to hear and thanks for taking the time to read this post.


Updating with a timer is OK to a certain point but as you say, there is always going to be a certain amount of waste.

I’d say your best bet is to use listeners for most of your widgets and stick with the timer for animations. Maybe take a look at the Value class and see if you can use that for your application. It should contain a lot of the functionality you’re looking for.


That was my gut feeling. I’m currently trying to work out what is going on behind the scenes in JUCE by looking at files like juce_FileBrowserListener.h and the files that include it to see if I can do something similar with my data-table class.

Thanks for the Value class suggestion. The other option might be to somehow shoehorn my class into a Value and work that way maybe. Lots of learning to do :shock: .

Keep suggestions coming folks!


Just discovered the beginnings of haydxn’s ValueTree tutorial on the wiki. Excellent timing sir, you have a very interested reader right here.