Sharing a parameter between multiple instances of a plugin


#1

Not a biggie if it’s really hard, but i have a midi effect that can be used multiple times on different channels, and i’d like the option of sharing the mode (scale) and key between multiple instances, so that when i use a combo box in one to change the values, it would send that change to any and all other instances.

is that doable?


#2

There are probably lots of ways of doing this. The plugin is only one instance (probably) of your binary with multiple instances of the AudioProcessor and Editor classes.

So if you do something that’s backed onto a global variable then you’ll be able to share data.

Doing it directly is probably ugly and fraught with tripwires for the fast and unwary. However maybe something like a class GlobalConfiguration wrapped with a SharedResourcePointer<> or other singleton arrangement would work. Perhaps if your GlobalConfiguration object used a JUCE ListenerList so you can find out when one of your objects calls setGlobalScaleSetting(…).

There might be some existing JUCE class that’ll work. You maybe could look at PropertiesFile as well… I don’t know if it has the right notification behaviour.

Or you could use a common message bus arrangement between your objects or some kind…


#3

I can confirm that the singleton approach works. I have some shared parameters and store them in a singleton (that is a broadcaster so that each instance can be a listener). I can imagine this approach could break in AUs in sandboxed environments at some point in the future but it works fine in GarageBand 10. I haven’t tried it but I’m pretty sure this wouldn’t work if you use the Reaper feature to run plugin instances in their own processes. Perhaps some interprocess comms stuff would be the way to go in this case.

One issue is where to store the parameter, i.e., which instance has the responsibility? I’m only storing a small amount of data in the singleton so storing a copy of the data in each instance works fine for my needs.


#4

so, pretty tricky eh?


#5

Bare bones:

class SharedVariable : public ChangeBroadcaster { public: void setVariable(int newValue) { value = newValue; sendChangeMessage(); } int getVariable() { return value; }};

// … then in your class somewhere:

SharedResourcePointer<SharedVariable> myvariable

There may be a more straightforward or better way someone will point out in a second. Maybe you can do it with a Value object.