How to stop loop at specific timeframe

Hi, I am looking for a way to essentially stop a loop at a specific time frame,

I tried using the at command, which works for starting loops at specific time,

in_thread do
  at 16 do
    bass_synth
  end
end

but I would like to know how to stop a loop, in a similar fashion

You could use something like this

set :kill,false #initialise kill flag

use_synth :tb303
live_loop :doodle do #just a sample loop
  play scale(:e3,:minor_pentatonic,num_octaves: 2).choose, release: 0.25
  sleep [0.125,0.25].choose
  stop if (get :kill) #test if time to stop
end

at 5 do #will trigger stopping the live_loop
  set :kill,true #will trigger stopping the live_loop
end

You can stop a loop from inside itself by calling stop, and use something like the time state, or just a counter, to determine when to stop:

live_loop :bass_synth do
  stop if get[:stop_bass_synth]
  # Rest of your loop here
end

# somewhere else:
at 32 do
  set :stop_bass_synth, true
end

or

live_loop :bass_synth do
  stop if tick(:stop) == 42 # use a named tick to avoid clashing with rest of loop
  # Rest of your loop here
end
1 Like