I use two techniques to switch live_loop audio on and off. The first stops the live loop and restarts it when required. The second leaves the live_loop running but controls its volume using an fx :level wrapper.
In the first example you could use osc messages to call doloop to start and to set :go,0 to stop.
In the second example you could use osc messages to adjust the value of :vol using set :vol,0 or set :vol,1
use_bpm 120
#technique 1 use stop to stop a live loop
#the function call will restart it next time it is called
define :doLoop do
use_synth :tb303
set :go,1
live_loop :doodle do
n=scale(:c3,:minor_pentatonic,num_octaves: 2).choose
play n, cutoff: rrand(50,110),release: 0.1 if spread(5,8).tick
sleep 0.2
stop if get(:go)==0
end
end
#illustrate starting and stopping the loop 4 times
4.times do
doLoop
sleep 4
set :go,0
sleep rrand_i(1,4)
end
#technique 2
# have a continously running live loop
#and embed it within fx :level
#control the level to switch the loop audio off and on
with_fx :level,amp: 1 do |v| #could start with amp: 0 if you want the loop to start silently
in_thread do
loop do
control v,amp: get(:vol),amp_slide: 0.1
sleep 0.1
end
end
use_synth :tb303
live_loop :doodle2 do
n=scale(:c4,:minor_pentatonic,num_octaves: 2).tick
play n, cutoff: rrand(50,110),release: 0.1 if spread(5,8).look
sleep 0.2
end
end
#illustrate controlling the volumn on and off 4 times
4.times do
set :vol,1
sleep 4
set :vol,0
sleep 4
end