Making synth nodes survive Ctl-period

Hi list,

albeit this might have been discussed already, I am trying to .add a
synth def to my server and making that that synth survive ctl-period.

Following this helpful startpage.com search result
https://www.reddit.com/r/supercollider/comments/virv1c/synth_surviving_cmdperiod/
I am able to add the Synth to the ServerTree and the synth node is
re-created upon Ctl-period like this:

(
~init = { Synth(\default) };
ServerTree.add(~init);
Synth(\default);
)

In this code I have to start the synth once.

Now, I am running into the issue that this synth node is
created a second time whenever I (have to) re-evaluate that code as part
of a bigger initialization block.

I wonder if there is an even better way to achieve the permanent node
but avoiding the double-creation?

Thanks for all ideas!
best, Peter

You have to be careful if you call such a block multiple times if you redefine ~init and then add it again you will end up with multiple copies of the function. You need to define ~init outside the block, or check to see if it exists before defining like ~init = ~init ? {your function}

you’ll also want to store your synth somewhere and check if it exists before recreating the synth like:

~synth.isNil.if {~synth = Synth(\default) }

beyond that you might want to register your synth Synth(\default).register so that you can check if its running with ~synth.isRunning so that you can recreate it if it has been stopped.

For persistent nodes another way is to write a Class so that stuff is added to the ServerTree during class tree initialization - you can check out one of the Quarks that does this like SafetyLimiter for example.

Thanks for the useful tips and examples Michael!

Which Quark is the SafetyLimiter in? I couldn’t find it by browsing the
list of Quarks in the IDE and it seems there is no search function for
classes provided by Quarks(?).

best, P

To search Quarks check out Baryon - here’s another quark that may be useful to you Baryon _ PersistentMainFX

And here is StageLimiter (sorry I had gotten the name wrong plus it’s part of the Batlib quark! ) BatLib/StageLimiter.sc at master · supercollider-quarks/BatLib · GitHub

There’s also SafetyNet. That seems more robust to me, but in practice I’ve never had any issues doing it the way that Batlib does it.

Also, if you’re doing this because you need a limiter at the end of the chain, then Nathan Ho wrote a good one.

You could use it with SafetyNet.

If you want a mixer channel at the end, then PersistentMainFx might be useful - but I’m less familiar with that one.

This is Nathan’s extension:
Safety Limiter