I’m trying to build a plugin which needs to be synchronized with all of its instances (i.e., it affects a track’s output depending both on its audio content and on the other tracks audio content).
My current approach is to use a SharedResourcePointer object with waitable events that signal when all instances have finished processing the current window. The heavy load of the audio processing is done on a separate thread (one per instance, per channel), because I understand that it is not a good idea to put a lock or wait inside the audio thread. In fact, when I tried having all the processing inside the audio thread and telling the instance to wait for the other instances to finish inside the processBlock function, I got into a deadlock where the other instances didn’t event start. Could anybody explain this to me? Shouldn’t different instances of a plugin run in different processes or at least, different threads? I’m building an AU and testing in Logic Pro 10.2.1.
Anyways, I decided to spun a thread to do the processing and the waiting, which frees the lock once all the instances are done. However, I’m not very confident on this approach because I’m not sure wether the process is actually finished before the audio thread reads the output. Is there a way to tell the audio thread to wait without locking? I’d highly appreciate recommendations for the architecture of this plugin, I’m a quite new to plugin development with JUCE, and this seems to be a little over my experience.