How to free Pbind/pattern?

Hello, I’m trying to free the pattern and/or the synth. Could anybody guide me on how to do that effectively? I tried to use " Pbind’s name.stop; ", but it doesn’t work.

Thank you very much for your help.

V


(
b= SynthDef(\perc,{ |freq=800, rel=4.5, pan =2, amp = 0.2,mxdt = 0.4, dt=0.3,dct =0.5|
	var sig,efx;
sig=LPF.ar(Mix(SinOsc.ar(freq,0,0.5),SinOsc.ar(2*freq,0,0.3),SinOsc.ar(3*freq,0,0.2))*EnvGen.kr(Env.perc(0.01,rel),doneAction:2),3000,amp);
	efx = CombC.ar(sig,mxdt, dt, dct);
	Out.ar(0,Pan2.ar(sig, SinOsc.ar(pan),level:amp));


}).add;
)

(

z=SynthDef(\pad,{| freq=740,vol=0.5, relOne =1,relTwo =1 amp =0.4, pan = 1 |
	var sig;
sig=LPF.ar(Mix(Blip.ar(freq,0,0.3),LFSaw.ar(2*freq,0,0.3),SinOsc.ar(3.01*freq,0,0.3))*EnvGen.ar(Env([0,0.4,0],[relOne,relTwo]),doneAction:2),1000, amp);
	Out.ar(0,Pan2.ar(sig,FSinOsc.kr(pan),level:amp));
}).add;
)


(
{

	~perc.play;"perc play".postln;
	5.wait;
	~pad.play;"pad play".postln;
	5.wait;
	b.free;
	z.free;
}.fork;
)

It’s an error every SC user is running into sooner or later. The Pbind is only a template, the playing object is an EventStreamPlayer, which can be stopped and resumed. So try

p = Pbind(...);

x = p.play;  // see post window, an EventStreamPlayer has been made

x.stop;

x.play;

...

Another issue in the code is that you’re freeing SynthDefs, but you rather want to free the running Synths. In most cases, you don’t need to assign SynthDefs to variables. When added, their data is stored in the language anyway (as a SynthDesc)

I forgot to include the Pbind. Here is the complete code.

(
b= SynthDef(\perc,{ |freq=800, rel=4.5, pan =2, amp = 0.2,mxdt = 0.4, dt=0.3,dct =0.5|
	var sig,efx;
sig=LPF.ar(Mix(SinOsc.ar(freq,0,0.5),SinOsc.ar(2*freq,0,0.3),SinOsc.ar(3*freq,0,0.2))*EnvGen.kr(Env.perc(0.01,rel),doneAction:2),3000,amp);
	efx = CombC.ar(sig,mxdt, dt, dct);
	Out.ar(0,Pan2.ar(sig, SinOsc.ar(pan),level:amp));


}).add;
)

(

z=SynthDef(\pad,{| freq=740,vol=0.5, relOne =1,relTwo =1 amp =0.4, pan = 1 |
	var sig;
sig=LPF.ar(Mix(Blip.ar(freq,0,0.3),LFSaw.ar(2*freq,0,0.3),SinOsc.ar(3.01*freq,0,0.3))*EnvGen.ar(Env([0,0.4,0],[relOne,relTwo]),doneAction:2),1000, amp);
	Out.ar(0,Pan2.ar(sig,FSinOsc.kr(pan),level:amp));
}).add;
)


(

~perc = Pbind(
  \instrument,\perc,
	\midinote, Pseg([60.2, 60.3,60.7,62,64.5,65,66,68,70.2,72,72.2,74.5,75,76.6],inf),
	\dur, Pxrand([4.6,5.2,4,2.5],inf),
	\sustain, Prand([3,4.5,6,3.5],inf),
	\pan, Prand([1,0.5,0.2],inf),
	\amp,0.4
);


~pad= Pbind(
	\instrument,\pad,
	\freq,Pexprand(590,603),
	//\freq ,Pfunc({602.rand+0.3}).
	\relOne,Pseg([2.1,0.8,1],inf,'exp'),
	\relTwo, Pseg([2,1,1.3],inf,'exp'),
	\dur, Pxrand([5,7],inf),
	\pan, Prand([1.5,2,2.6],inf),
	\amp, 0.6

);


)

(
{

	~perc.play;"perc play".postln;
	5.wait;
	~pad.play;"pad play".postln;
	5.wait;
	b.free;
	z.free;
}.fork;
)