Changing value in a Key with pattern

Hello everyone,
I can’t figure out how to do the same thing using Pbindef e SynthDef.
The goal is just to avoid to create new synths, I just need to change the “ratio” .
Thank you very much for your attention.

(
Ndef(\simpleSine, {|ratio = 1.0,freq = 120, amp1 = 0.1, amp2 =0.1, ph2 =0.01, panFreq = 0|

	var sig =SinOsc.ar(freq,0,mul:amp1)
	+SinOsc.ar(freq*ratio,phase:ph2,mul:amp2);
	Pan2.ar(sig,0);
});
)

(
Ndef(\simpleSine).play;
)

(
r = Routine {
	loop{
    5.do({ arg a;

		Ndef(\simpleSine).set(\ratio, [1,1.11,1.13,1.14,1.17].wrapAt(a).postln);
       2.yield;

	})
	
	}
	}.play;
)

Pmono creates only one synth and just sets its parameters instead of creating/destroying nodes.

Alternatively, if your Synth is already “alive”, you can use a Pbind with eventType \set to achieve the same behaviour:

Pdef(\test,Pbind(
    \type,\set
    \id,Ndef(\simpleSine).nodeID, // put your synth's ID here instead
    \ratio,Pseq([1,1.11,1.13,1.14,1.17],inf),
    \dur,0.1
)).play

Also check out NodeProxy Roles if you are working with NodeProxies.
Then you can do this too:

Ndef(\simpleSine)[1] = \set -> Pbind(
    \dur, 2,
    \ratio, Pseq([1,1.11,1.13,1.14,1.17],inf)
)

And you can change both source and patterns in real time

2 Likes

Thank you very much @elgiano,
trying to keep consistency in the project I opted for this way.

// Metro
(
~bpm = 80;
~beatsPerBar = 4;
~secondPerBar= (60/~bpm)*~beatsPerBar;
"Bar dur: ".post;~secondPerBar.postln;
)
// Init
s.scope
// Metro base
(
~metroBase = TempoClock.new;
~metroBase.tempo = ~bpm/60;
~metroBase.permanent_(true);
~metroBase.schedAbs(~metroBase.nextBar,{~metroBase.beatsPerBar_(~beatsPerBar)});
)

//

(
SynthDef(\lissaSine_set,{|ratio = 1.0,freq = 120, amp1 = 0.1, amp2 =0.1, ph2 =0.01, panning = 0|

	var sig =SinOsc.ar(freq,0,mul:amp1) + SinOsc.ar(freq*ratio,phase:ph2,mul:amp2);
	var out = Pan2.ar(sig,panning);
	Out.ar(0,out);
}
).add;
)

s.plotTree;
a =  Synth(\lissaSine_set);


(
Pbindef(\changeRatio).stop;
Pbindef(\changeRatio,
	\instrument, \lissaSine_set,
	\type, \set,
    \id, a,
	\args, #[],
	\stretch,4,
	\freq,55.midicps,
	\ratio,Pseq([1.1,1.16,1.34,1.7],inf),
	\dur,1/4
).play(~metroBase,quant:[~metroBase.timeToNextBeat,0]);
)

Pbindef(\changeRatio).stop;