Singleton instance shared between plugin instances

From reading the thread I’m not entirely sure what kind of data you want to store and access, so the best solution to chose always depends on the use case.

An obvious choice when working with JUCE that proved to work quite well with complex real world plugin projects is the AudioProcessorValueTreeState. It serves multiple jobs:

  • Keeping your parameters in one place and managing to notify everything that needs notification, e.g. the DSP functions to be controlled, the GUI widgets that control those DSP functions and the host that wants to interact with the parameters through automation.
  • The public state member which is a ValueTree does not only hold the parameters data structure but allows you to story any kind of state data that can be converted to a var object. Examples from real world applications: GUI states like Plugin window size, Processing states like if some analysis phase has already passed (which should be reflected by a certain GUI widget) or the last BPM value reported by the playhead (which e.g. affects some tempo setting GUI widget)
  • Giving you an easy way to serialize the whole plugin state in the get or set state information callbacks

All you have to do is passing a reference to the APVTS to all classes that need it. As the instance should live in your plugin processor and the processor is the first thing that is gonna be constructed, this pattern works quite straightforward. You can even define your own baseclass for e.g. Components that should be able to attach to parameters and listen to state changes and just need a pointer to the component that constructed them (which should follow the same pattern) to do all this, which can significantly reduce the amount of boilerplate code even further.

But even if the APVTS is not the data structure of choice for your application keeping a senseful hirachy is always an important way to build any piece of code that can grow in a good way.

And singletons are not always completely bad. They should just refer to things that are really singleton in the scope of the users machine, e.g. a settings file accessed by multiple plugin instances