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

**URL:** <https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237>\
**Category:** Tracktion Engine\
**Created:** [May 16, 2023, 3:36pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237 "2023-05-16T15:36:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ujam](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@ujam](https://forum.juce.com/u/ujam)\
**Post date:** [May 16, 2023, 3:36pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/1 "2023-05-16T15:36:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [May 16, 2023, 5:38pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/2 "2023-05-16T17:38:24Z")

</div>

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

```auto
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…

---

<div class="post-metadata">

**Author:** ![ujam](https://avatars.discourse-cdn.com/v4/letter/u/2bfe46/32.png) [@ujam](https://forum.juce.com/u/ujam)\
**Post date:** [May 17, 2023, 10:04am UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/3 "2023-05-17T10:04:25Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [May 17, 2023, 7:11pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/4 "2023-05-17T19:11:25Z")

</div>

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

Perhaps by adding a virtual function to Plugin like this:

```auto
/** 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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![chrhaase](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chrhaase/32/12648_2.png) [@chrhaase](https://forum.juce.com/u/chrhaase)\
**Post date:** [October 10, 2023, 1:34pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/5 "2023-10-10T13:34:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chrhaase](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chrhaase/32/12648_2.png) [@chrhaase](https://forum.juce.com/u/chrhaase)\
**Post date:** [October 10, 2023, 1:47pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/6 "2023-10-10T13:47:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 26, 2024, 3:14pm UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/7 "2024-06-26T15:14:59Z")

</div>

I’ve lost track of the original requirement here but there’s `EngineBehaviour::shouldProcessMutedTracks()` you might want to return true from.

---

<div class="post-metadata">

**Author:** ![chrhaase](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chrhaase/32/12648_2.png) [@chrhaase](https://forum.juce.com/u/chrhaase)\
**Post date:** [June 27, 2024, 6:53am UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/8 "2024-06-27T06:53:38Z")

</div>

> [@dave96](#):
>
> ```auto
> /** 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 };
> 
> ```

This would be a great add for my use!

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 27, 2024, 8:06am UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/9 "2024-06-27T08:06:06Z")

</div>

What’s the use case? I don’t think that will work for tracks that are muted, the plugins simply won’t be processed if that’s the case.

---

<div class="post-metadata">

**Author:** ![chrhaase](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chrhaase/32/12648_2.png) [@chrhaase](https://forum.juce.com/u/chrhaase)\
**Post date:** [June 27, 2024, 8:41am UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/10 "2024-06-27T08:41:26Z")

</div>

Ah yes, but if I have muted track processing enabled they will, right?  
If I have a long reverb on a track and I turn it off, I wouldn’t expect it to continue to play when I turn it back on, which could be minutes later. So I want to just handle this some way - I think a reasonable thing to do with a reverb is just resetting when disabled.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 27, 2024, 10:46am UTC](https://forum.juce.com/t/how-does-a-tracktion-plugin-know-it-was-unmuted-enabled/56237/11 "2024-06-27T10:46:11Z")

</div>

I agree, I think we should just call `juce::AudioProcessor::reset()` when a track is muted or a plugin is disabled.

If we did that, is the `shouldProcessWhenDisabled` change not required anymore? Presumably not as you’ll get the `reset` callback instead and then no processing blocks.
