Accessing the value of a GUI object from an audio thread


#1

If the processing of an audio buffer in getNextAudioBlock depends on the value of a GUI object, what's the safest way to access that value?

In the second "audio basics" tutorial, the value of a slider is read directly from the slider object by getNextAudioBlock. Although it doesn't state why this is not good practice, I presume it's because the slider value is updated in the context of another thread, and that reading it in the context of an audio thread may return an incorrect value.

Is it true to say that the only safe way to access the value of a GUI object from an audio thread is to use a critical section or some other OS resource?

Thanks.


#2

http://www.juce.com/forum/topic/whats-best-practice-gui-change-notification


#3

Though there's best practice, and there's good enough ... 


#4

I think reading a GUI value from the audio thread is fine as long as you ensure that the GUI object has a longer lifetime than the audio processing thread. This is typically *not* the case for plug-in editors and therefore you will need a thread safe way of checking if the editor and slider are still around,