The problem is that each time you press run a new with_fx wrapper created. However you are not altering live_loop :drums and so its code is not reevaluated and the new lpf reference is not the same as the one the live_loop is using.
The solution I use is to alter the program as below, and to comment out the line after the first run, before you rerun with an altered set:t in the control2 loop. That way the value of :lp is set only once and the correct value of lpf is use for the control. Its a bit finnicky to do but works.
Or you can change the live_loop :control2 to receive data from an external OSC call, which can be generated either from a simple program in a different Sonic Pi buffer which you run, or from a program like TouchOSC (well worth purchasing) which can send the data from a smart phone or tablet
There are several other discussions on this topic which is raised quite often. See here and here
solution 1
use_bpm 110
live_loop :control2 do
set :t, 100
sleep 0.25
end
with_fx :rlpf, cutoff: get[:t] do |lpf|
set :lp,lpf #comment this line after first run BEFORE running again
#you will need to uncomment it if you alter live_loop :drums1 OR if you press stop
#before running as if for the first time.
live_loop :drums1 do
sample :loop_amen, beat_stretch: 4
sleep 2
control get(:lp), cutoff: get[:t]
puts get[:t]
sleep 2
2.times do
sample :loop_amen, beat_stretch: 4
sleep 4
end
end
solution 2 EDIT initial value of :t now set and extraneous . removed from 90. in osc send program
#run in first buffer
use_bpm 110
set :t,100 #set an initial value for :t. OR run the osc send program once before running this to set it
live_loop :control2 do
use_real_time
n= sync "/osc*/cutoff"
set :t,n[0]
end
with_fx :rlpf, cutoff: get[:t] do |lpf|
live_loop :drums1 do
sample :loop_amen, beat_stretch: 4
sleep 2
control lpf, cutoff: get[:t]
puts get[:t]
sleep 2
2.times do
sample :loop_amen, beat_stretch: 4
sleep 4
end
end
end
Run program below in a separate buffer whenever you want to change the cutoff value
use_osc "localhost",4560
osc "/cutoff", 90 # alter the 90 to whatever value you want (max 120)