Just looking at this whole setParameter(int p, float v) business. There doesn't seem to be any strong guarantee of which thread this is called on. Certainly browsing the usual sources the options seem to be "audio thread", "message thread" and "other thread" Is that right - it's really completely uncertain?
Yes, depending on the host it could be called from any number of threads, possibly simultaneously.
Yummy. Then my lock-free-fifo solution isn't looking so hot at the moment.
It's tempting to put a quick CriticalSection in there, and have a dedicated FIFO.
Alternatives look like:
- Assuming that at the host is at least consistently using a single-thread, and avoiding calling setParameter from within the plugin. Then carrying on with a single-writer in setParameter()
- Implementing a multi-writer lock free FIFO / using distruptor.
I don't suppose there's a really standard answer for this one? :)
I've tweaked it so that:
- setParameter() has a critical section and updates a std::vector<float> of parameter values for the main thread
- The main thread has a timerCallback with the same critical section and updates only values that are different in the ValueTree
I can't think that there's any reason that that won't run quickly enough for the critical section to not be a problem.