How to listen for plugins being added to a track

Hi there,

I’m struggling to find a way to listen for plugins being added (and removed) from a track. I am adding a plugin as follows:

auto newPlugin = track->edit.getPluginCache().createNewPlugin(
track->pluginList.insertPlugin(newPlugin, -1, nullptr);

I noticed that Track exposes the state value tree and I thought I could listen for this and reload the plugins for the track from there.

I am successfully getting into valueTreeChildAdded when the plugin is added, but when I reload the plugins:

for(auto p : track->pluginList.getPlugins()) {

The new one is not there.

I can’t see another listener for Track or AudioTrack so I was wondering if I’ve either missed something, or whether my approach is wrong.

Any help greatly appreciated!


p.s. I have noticed there is PluginCache.newPluginAddedCallback but that seems to be only called when adding a plugin (not removing/deleting one) and at the point it is called, the plugin would not yet have been added to the track.

If you look in Edit::TreeWatcher you’ll see there’s a check for c.hasType (IDs::PLUGIN) to see if a plugin was added or removed (childAddedOrRemoved).

Because ValueTree listeners are difficult to determine the order in which they get called, you’ll have to asynchronously update to get the new plugin.

The newPluginAddedCallback was really added so you can update recently used lists etc. not really as a notification for being added/removed from a track.

Thanks very much @dave96. Updating asynchronously was the missing bit for me. This post: CachedValue not updated - how to use correctly? - #16 by dave96 was very useful for that.

Thanks again