Cannot .set any parameter for a Ref inside SynthDef

Hello!

I am new into SuperCollider and i can’t seem to find understand how Ref inside SynthDef works. I have found this sound example and tried to tweak it around, making it into a SynthDef and trying to get various parts of the SynthDef available for parametrization. this is what i have so far:

(

SynthDef(\bass, { |outbus = 0, speed = 3, soundmod = 60, test2 = 0.1 |
	var exc = BrownNoise.ar(Decay2.kr(Impulse.kr(speed,0,[0.04,0.04]), (0.005), 0.05));

	var insideKlankRef = Ref.new([ [soundmod], nil, Array.fill(16, {1.1})]);

	var s = (Klank.ar(insideKlankRef, exc) * test2 ).softclip;

    Out.ar(outbus, s );
}).store;
)

x = Synth(\bass); //create a synth instance
//now i try to set the variables
x.set(\speed, 5); //this one works
x.set(\test2, 0.2); // this one too
x.set(\soundmod, 10); //this has no effect :(

Setting “speed” and “test2” works fine, but changing the value of soundmod, that is an input into the new Ref doesn’t seem to work. Now, i thought that maybe the Ref is created once in memory and i can’t touch it ever again in any other way than .set method, so i tried doing something like this

(

var insideKlankRef = Ref(nil);

SynthDef(\bass, { |outbus = 0, speed = 3, soundmod = 60, test2 = 0.1 |
	var exc = BrownNoise.ar(Decay2.kr(Impulse.kr(speed,0,[0.04,0.04]), (0.005), 0.05));

	var referenced =  [ [60], nil, Array.fill(16, { 1.1})];
	var a = insideKlankRef.set(referenced); // if i don't use var assignment, and instead just write insideKlankRef.set(referenced);  the SynthDef crashes (don't know why)

	var s = (Klank.ar(insideKlankRef, exc) * test2 ).softclip;

    Out.ar(outbus, s );
}).store;
)
x = Synth(\bass); 
x.set(\soundmod, 10); //still nothing

Defining the ref outside synthdef and then just setting it’s value in SynthDef doesn’t help to change it neither.

Could you please help me out? what am i doing wrong? why does the parameters of the ref don’t change via set?

hi Roman,

var s = (Klank.ar(insideKlankRef, exc) * test2 ).softclip;

so close.
check out DynKlank. your example will work if you just replace Klank with that. for efficiency reasons (i believe) the standard Klank won’t let you dynamically update the parameters.

_f

#|
fredrikolofsson.com musicalfieldsforever.com

ooh, so it was Klank that was immutable, not Ref, thank you!