Safety of ValueTree inside processBlock()


#1

Is it safe to retrieve properties from a ValueTree inside AudioProcessor’s processBlock function and use them during the process?
Should I use a lock?


#2

ValueTree is definitely not thread-safe, you’d need to use locking.


#3

Good to know, thank you.


#4

…and I should also say that I strongly recommend NOT using it in realtime code. Its operations can block unpredictably.


#5

So what would be the best way? All the informations I need are stored into ValueTrees…
Should I use variables to store the infos, updating them with ValueTree::Listener?


#6

I did a similar thing before (had multiple issues when using a ValueTree in the audio thread) so I used a local set of atomics which I set in the value tree callback and used these in the audio callbacks. May not be the most efficient way of storing variable but it worked.


#7

Give each thread it’s own copy of the data and use a thread queue to propagate changes.