How does a Tracktion plugin know it was unmuted/enabled?

I tried this with the 4OSC synth and with VST plugins.

If you disable a synth plugin while playing a note, you hear the note release when enabling again. The plugin doesn’t seem to know there was a break in audio rendering. How can a tracktion::engine::Plugin detect that?

If you disable a plugin, I think its applyToBuffer function still gets called so you can check the isEnabled state. E.g.

void ExternalPlugin::applyToBuffer (const PluginRenderContext& fc)
{
    const bool processedBypass = fc.allowBypassedProcessing && ! isEnabled();

Although looking at this a bit more deeply (in PluginNode::process), maybe that only happens when the plugin introduces latency…

It looks like this only works for ExternalPlugin, not mine derived from Plugin:

canProcessBypassed = balanceLatency
                            && dynamic_cast<ExternalPlugin*> (plugin.get()) != nullptr
                            && latencyNumSamples > 0;

Hmm, I’m trying to think about the best way to handle this.

Perhaps by adding a virtual function to Plugin like this:

/** Return true here to make your plugin subclass always be processed, even when disabled.
    If you return true here, you must check the isEnabled() state to determine if the audio should be as normal or if you should do some special disabling.
 */
virtual bool shouldProcessWhenDisabled() { return false };

Then I could make the Node code:

canProcessBypassed = plugin->shouldProcessWhenDisabled()
                     || (balanceLatency
                         && dynamic_cast<ExternalPlugin*> (plugin.get()) != nullptr
                         && latencyNumSamples > 0);

Can you make those changes in your local copy and see if they do what you need?

I have a similar need, so just tried adding the above and it does exactly what I need. Any chance this could get into the library, @dave96?

One thing, though:
Plugins are not processed if the track is muted. So hitting a note on a synth and muting/unmuting the track will result in the same behaviour as bypassing the plugin does right now. Also reproducible in Waveform.