Here’s an example controlling three live loops which can independently be stopped and started.
This is done by embedding each loop in a function, and using that to control a stop command inside each loop
use_synth :tri
define :lone do |action|
if action==1
set :k1,false
live_loop :one do
play scale(:c5,:minor_pentatonic).choose,release: 0.1
sleep 0.1
stop if get(:k1)
end
else
set :k1,true
end
end
define :ltwo do |action|
if action==1
set :k2,false
live_loop :two do
play scale(:g5,:minor_pentatonic).choose,release: 0.1
sleep 0.1
stop if get(:k2)
end
else
set :k2,true
end
end
define :lthree do |action|
if action==1
set :k3,false
live_loop :three do
play scale(:c6,:minor_pentatonic).tick,release: 0.1
sleep 0.1
stop if get(:k3)
end
else
set :k3,true
end
end
live_loop :control do
puts "start live_loop :lone"
lone 1
sleep 4
puts "stop live_loop :lone"
puts "start live_loop :ltwo"
lone 0
ltwo 1
sleep 4
puts "stop live_loop :ltwo"
puts "start live_loop :lthree"
ltwo 0
lthree 1
sleep 4
puts "ADD live_loop :lone"
lone 1
sleep 2
puts "ADD live_loop :ltwo"
ltwo 1
sleep 4
puts "stop live_loop :one"
puts "stop live_loop :ltwo"
puts "stop live_loop :lthree"
lone 0
ltwo 0
lthree 0
sleep 2
end