Controlling a filter

#1

Why is it that this works fine:

use_bpm 120

live_loop :syn do
  use_synth :noise
  
  sn = with_fx :rlpf, res: 0.9 do
    play 60, sustain: 8
  end
  
  16.times do
    sleep 0.5
    control sn, cutoff: rrand( 50, 110 )
  end
end

But, this doesn’t work. The first time I try to control the synth, it crashes with an error.

use_bpm 120

sn = with_fx :rlpf, res: 0.3, cutoff: 130, cutoff_slide: 4 do
  
  live_loop :drums do
    at [0, 1.5, 2 ] do
      sample :bd_haus
    end
    
    at [ 1, 3 ] do
      sample :sn_dolf
    end
    
    at [ 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 3.75 ] do
      sample :drum_cymbal_closed
    end
    
    sleep 4
    
  end
end

sleep 4

control sn, cutoff: rand_i( 130 )

The error I get is:

Runtime Error: [buffer 2, line 24] - RuntimeError
Thread death!
 Unable to normalise argument with key #<Thread:0x00007fe67b075990@/Applications/Sonic Pi.app/app/server/ruby/lib/sonicpi/runtime.rb:934 sleep> and value {:cutoff=>97}
#2

Oh, it needs to be done like this:

use_bpm 125
use_debug false

cutoff = 50
increment = 1

with_fx :rlpf, cutoff: 50, res: 0.7, cutoff_slide: 0.25 do |sn|
  
  live_loop :drums do
    at [ 0, 1, 2, 3 ], [1.0, 0.6, 0.8, 0.6] do |p|
      sample :bd_haus
    end
    
    at  [1, 3] do
      sample :sn_dolf
    end
    
    at [ 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 3.75 ],
    [1.0, 0.6, 0.8, 0.6, 0.9, 0.6, 0.8, 0.6, 0.4] do |a|
      sample :drum_cymbal_closed, amp: a
    end
    
    sleep 4
  end
  
  live_loop :controller do
    
    cutoff = cutoff + increment
    
    if cutoff < 30
      cutoff = 30
      increment = -increment
    end
    
    if cutoff > 130
      cutoff = 130
      increment = -increment
    end
    
    control sn, cutoff: cutoff
    
    sleep 0.0625
  end
end