Function play and stop

Hi list,

I noticed that in the statements below the second version does not work. That is, starts the function, but x.stop does not stop it. I have some longer synths that are created as functions that I wish to start and stop in this way. Is it the case I will have to make them into SynthDefs…?

//this works
x = { arg freq=900;[1,1]), freq, 0.01) }.play(s, 0);
//this not...
x = { arg freq=900;[1,1]), freq, 0.01) };;

No problem,
SynthDefs will need to be made - if .play isn’t part of the function’s definition it won’t have any effect calling .stop.

You’re making a slight conceptual error - {} is a function, and {}.play creates a SynthDef out of the function and then plays it. .play() returns the synth you created, but in your case x still refers to the function, NOT the synth playing on the server. To do what you’re trying to do, you want something like:

~func = {};
~synth =; // store the returned synth
~synth.stop(): // THIS is the thing you want to stop

This is why your first case works, and your second case doesn’t .


Ok, great thanks. That makes sense.