Question About 'control' Keyword

Hello, all! Quick question about ‘control’; when I run this code, the loop goes from ‘bright’ to ‘dull’ as expected:

with_fx :rlpf, cutoff: 120, cutoff_slide: 5 do |c|
  live_loop :loop do
    sample :loop_amen
    sleep sample_duration(:loop_amen)
    control c, cutoff: 40, cutoff_slide: 5
  end
end

However-- as the code is running, I would expect the sound to go from ‘dull’ to ‘bright’ if I change “cutoff: 40” to “cutoff: 120” in my ‘control’ statement and run the code again, but nothing happens when I do that. In other words, the cutoff value should transition from ‘40’ back to ‘120’…

Can someone help me understand how control works?

Thanks!
Bryan

Hi Bryan
Nice question. I’ve had a play and come up with the following code which I think works.

#experimenting with changing cutoff using a live loop
#by Robin Newman

set :st,sample_duration(:loop_amen)

with_fx :rlpf, cutoff: 120 do |c|
  set :cv,c #comment after first run from stop, before re-run
  live_loop :cont do
    l=60;h=100
    st=get(:st)
    puts "change cuttoff down to",l
    control get(:cv), cutoff: l, cutoff_slide: 2*st
    sleep 4*st
    puts "change cuttoff up to ",h
    control get(:cv),cutoff: h, cutoff_slide: 2*st
    
    sleep 4*st
  end
  
  live_loop :loop do
    st=get(:st)
    sample :loop_amen
    sleep st
  end
end

The first time your code runs, the value of c in the live loop points correctly to the fx control and it reduces the cut off value. However you cannot change the value in the live loop and rerun, as this reruns everything, and the reference between the value of c in the live loop and with the fx call (and this has been rerun too) is not kept.
In my version I store the value c using set :cv immediately after it is created, and get it back again using the reverse get(:cv) inside the controlling live_loop :cont . However, it is important also to comment out the set :cv,c line AFTER the first run (where everything was previously stopped) but BEFORE you rerun the program to pick up the updated to a live_loop you have changed. So If you run as shown, the cutoff will go up and down between the set values l (60) and h (100). If you then comment out the set :cv,c line, and alter either the l or h value and then rerun, it will pick up the new values on the next pass.

Of course if you don’t want it to oscillate, a simpler version is shown below. This just does a single change each time it is run, but as above remember to comment out the set:cv,c line AFTER the first run but BEFORE subsequent ones.

#experimenting with changing cutoff using a single command line
#by Robin Newman

set :st,sample_duration(:loop_amen) #store duration of the sample

with_fx :rlpf, cutoff: 120 do |c|
  set :cv,c #comment after first run from stop, before re-run

  control get(:cv),cutoff: 40,cutoff_slide: 4*get(:st)
  
  live_loop :loop do
    st=get(:st)
    sample :loop_amen
    sleep st
  end
end

Also because I liked the changes to be sychronised to the live loop I changed the delays and time slide times to be multiples of the sample duration. Again I used the set and get functions to store and recover these as required.

2 Likes

Works like a charm-- thanks for this, I really appreciate it!

That’s great! One obvious comment I missed out in the asnwer is that of course you have to renable the set :cv,c line if you stop the program completely and re comment it after the first subsequent run the next time you use the program.

1 Like

Yep, got it-- and I forgot to say thanks for explaining why the code works as it does (versus just giving a working example); it’s all starting to make more sense now. :slight_smile:

Bryan

1 Like