It’s come the time for my app (which is a daw) to support automation mechanisms.
At the moment everything is based on the ValueTree class: exactly like in the Introjucer there’s a Project with Items (that are wrapped around ValueTree), and every parameter (for example, an amplitude fader) has it’s own property in an Item.
In order to make automations work I’ve created an Automation class (which is wrapped around an Item, with automation points).
My question now is this:
since everything is based on the ValueTree class (which isn’t thread-safe), how can I safely update the gui?
If I do something like this in my processBlock callback
float automationValue = getCurrentAutomationValue(); //this is the value for the automation at the current transport sample channelTree.setProperty(Ids::amplitudeFader, automationValue, nullptr); //set the value for the fader
I’ll get the gui of the fader moving (since the graphical fader is linked to the ValueTree using ValueTree::Listener), but I’ll need locking.
And obviously the audio will stutter.
If I don’t lock I’ll stumble into a Jules’ comment which basically says: “You need to lock”.
What would be the best approach for this?
Thank you for reading!