UI updates from Processor

Hello JUCE Community,

I’m working on a project in JUCE and am at a crossroads regarding the UI update logic.
The concept is to color the keys blue when a sample is recorded onto them.

I’m deliberating between two approaches:

Should I use a timer to periodically check each key’s state and update the UI if a sample is recorded? This seems straightforward, but could be less efficient due to constant polling, especially if changes are sporadic.

Alternatively, would a callback mechanism be more effective, where the UI update is directly triggered by the event of a sample being recorded? This could be more efficient as updates occur only when necessary. However, I’m concerned about the complexity and ensuring thread safety.

I look forward to hearing your thoughts,
thank you!
Sol.

1 Like

Somewhere you must have a list/array/vector of keys mapped to samples. In your PluginProcessor function, you must be playing those samples back.

In your PluginEditor function, you must be handling the UI events which are generated by the user recording new samples to the specified key, and you must have code there which assigns a sample to the key in the list/array/vector.

So, all you’d need to do, in the PluginEditor method, is check the contents of that list/array/vector and render the results to your UI.