I had a play with this today and tried various solutions with varying degrees of success. In the end I decided on leaving the live loops running all the time, but switching their volume to 0 when not required. By syncing changes to the start of loop a you can simulate stopping and restarting loop b. Or you can just change the volume at any time.
I found it more convenient to experiment using OSC to give the external inputs, but this is easily changed back to midi_cc inputs.
Here is what I came up with. I used TouchOSC with three toggle switches, running on a tablet at 192.168.1.240 These switches send data 1 when turned on and 0 when turned off
I used time_state values to pass data to the loops controlling the mix and the volumes.
set :mval,0 #set initial mix value
set :vola,0
set :volb,0
#initialise virtual toggle switches on TouchOSC
osc_send "192.168.1.240",9000, "/1/toggle1",1
osc_send "192.168.1.240",9000, "/1/toggle2",1
osc_send "192.168.1.240",9000, "/1/toggle4",0
use_osc "localhost",4559 #send initial OSC messages to Sonic Pi
osc "/1/toggle1",1 #turn on live_loop a
osc "/1/toggle2",1 #turn on live_loop b
osc "/1/toggle4",0 #turn off mix on slicer
with_fx :slicer,mix: 0 do |m1| #applied to all enclosed live loops
in_thread do
loop do
control m1,mix: get(:mval)
sleep 0.05
end
end
with_fx :level, amp: 1 do |vol| #control volume of live_loopa
in_thread do
loop do
control vol,amp: get(:vola)
sleep 0.05
end
end
live_loop :a do
sample :ambi_choir, beat_stretch: 4
sleep 4
end #live_loop
end #fx level a
with_fx :level, amp: 1 do |vol| #control volume of live_loop b
in_thread do
loop do
control vol,amp: get(:volb)
sleep 0.05
end
end
live_loop :b,sync: :a do
sample :ambi_drone, beat_stretch: 4
sleep 4
end #live_loop
end #fx level b
end #fx slicer
live_loop :getVol1 do #control 2nd live_loop on/off
use_real_time
b= sync "/osc/1/toggle1" #returns 0 or 1
if b[0]==1
set :vola,1
else
set :vola,0
end
puts "vola is #{get(:vola)}"
end
live_loop :getVol2 do #control 2nd live_loop on/off
use_real_time
b= sync "/osc/1/toggle2" #returns 0 or 1
sync :a #change at start of loop a #omit if you want to change immediately
if b[0]==1
set :volb,1
else
set :volb,0
end
puts "volb is #{get(:volb)}"
end
live_loop :getMix do #control fx mix
use_real_time
b = sync "/osc/1/toggle4" #returns 0 or 1
set :mval,b[0]
puts "mix value #{get(:mval)}"
end