No specs on Ndefs with a SynthDef source with specs

I’d like to use my SynthDefs as a source for new Ndefs. However, SC doesn’t copy the specs from the SynthDef to the corresponding Ndef. I’ve tried two methods, and neither of them works. There are no specs in the Ndef afterward! I don’t want to define global specs; instead, I want to have them on a per-Ndef basis, defined in my SynthDef sources.

Does anyone know how to do this?

What doesn’t work:

(
SynthDef(\synth1, {
	arg out=0, freq=200, amp=0.2;
	var drive = \drive.kr(1, spec: [0.1, 10, \exp, 0.01].asSpec);
	var sig;
	sig = (SinOsc.ar(freq ! 2) * drive).tanh ;
	Out.ar(out, sig * amp);
}).add;
)

Ndef(\ndef1).source_(\synth1)
Ndef(\ndef1).gui


(
SynthDef(\synth2, {
	arg out=0, freq=200, amp=0.2, drive=1;
	var sig;
	sig = (SinOsc.ar(freq ! 2) * drive).tanh ;
	Out.ar(out, sig * amp);
}, metadata: (
	specs: (
		drive: ControlSpec(0.1, 10, \exp, 0.01)
	)
)).add;
)

Ndef(\ndef2).source_(\synth2)
Ndef(\ndef2).gui


hello, if you have JITLibExtensions installed you could maybe do it like this.

(
var name = "synth2";

var ugenFunc = {
	arg freq=200, amp=0.2, drive=1;
	var sig;
	sig = (SinOsc.ar(freq ! 2) * drive).tanh ;
	sig * amp;
};

var specs = (
		drive: ControlSpec(0.1, 10, \exp, 0.01)
	);

SynthDef(name.asSymbol, { Out.ar(0, ugenFunc.value) }, metadata: (
	specs: specs
)).add;

Ndef.clear;
~ndef = Ndef(name.asSymbol, ugenFunc).addSpec(\drive, specs.drive);
)

// Play the Synth
Synth(\synth2)

// Use the ndef via gui
~ndef.gui;

Thanks for the answer, but i have no extensions installed and i’m looking for a vanilla option.

I was playing arround a lot now and figuret it out:

x = Ndef(\ndef1).source_(SynthDescLib.global[\synth1].def);

This creates a Ndef, but as an Control-Proxy, and all the Specs works from the SynthDef and also the NdefGui works.

Honestly i don’t know why, it was just luck. And it is very confusing that there is no monitor synth with this! It is the pure source synth that is started only, and it needs an Out UGen like a normal SynthDef.

Maybe someone knows exactly why this works and the other way not, and why this creates only a Control-Proxy without monitor synths like normally in Ndefs?