Redefining Loop

To stop a live loop (or at first run prevent it from running in the first place) you can add stop:

live_loop :dont_stop_me_now do
  stop
  sample :loop_amen, beat_stretch: 2, amp: 1
  sleep 2
end

Note: Once you stopped a loop by putting a stop somewhere in the loop body (probably at the beginning) you will have to 1. remove/ or comment the stop and then 2. re-evaluate the code (hit run) to start this loop again. Alternatively you could just comment the sample ... line or set the amp to 0 (and let the loop running contineously).

There are also some discussions going on to dynamically create and control live_loops (e. g. here and here). But this is somehow more complicated.

One more thing: If you use live_loops you don’t need the in_thread construct anymore: a live_loop automatically creates its own thread. You will see, once you removed all in_tread statements your code will behave exactly the same.

2 Likes