How to repeat .play, "resetting" the current playback and starting as a new StreamEvent, until I stop it?

~sound =,"C:/Users/momom/OneDrive/Documentos/Ableton/Ableton Samples/Zero-G Ambient 1/MISC VCS 2/BLEEPS DOWN.wav", 2);
~soundFrames = ~sound.numFrames;
{, ~sound,1.0,1.0,~soundFrames.rand)))}.play;

I want to make that sound play indefinitely until I somehow stop it. The thing is that I don’t know how to do that, and each time I manually play it, it adds up in the server and just plays over the current Stream. How can I do both of those things? New to SC, but enjoying it a lot.

When you run your { ... }.play; line, watch in the post window. You should see -> Synth(...) where the stuff inside () is different every time.

This is the thing you need to stop.

To manipulate this synth, you need to have access to it = to hold onto a reference to it.

For starters, references may be held in variables. There are other ways to keep references, but you don’t need them yet. You will, but not now.

a = {, ~sound, 1.0, 1.0, ~soundFrames.rand)) }.play;

Now the “interpreter variable” a refers to the Synth object, and you can use it to do things like:


Do be careful, though, to release the synth before rerunning your synth line. If you don’t, then a's reference will be changed to point to the new synth. The reference to the old one will be lost. At that point, you won’t be able to release it except by cmd-. .

Next steps would be to package this into a SynthDef so that it doesn’t have to rebuild the synthesis graph every time. Then you’ll need to learn about envelopes and gates, but, one step at a time.


1 Like