Set, get, kill, and other deep commands

Robin…

You seem to understand set and get quite well, and I just dont
get it for some reason… any chance of a RBN ‘tutorial’ or a
pointer to examples?

Likewise ‘kill’… I can never seem to get it to work…

Oh… btw, set : foo1, = play_chord chord(:D4, :minor ), attack: 4, release: 2, amp: drop_vol

Yeah, no. Doesn’t work. :slight_smile:

Eli…

# City Lights...
# Eli...

use_bpm 120
use_debug false

tracker = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

set_volume! 3
drop_vol = 1

define :start_loop do |i|
  tracker[i] = 1
end

define :stop_loop do |i|
  tracker[i] = 0
end

# When the loop is 'playing', if you turn it off (tracker[1] = 0), I want to
# kill any remaining echos from the fx's ... Can do? Good man!

live_loop :intro1 do
  if tracker[1]>0 then
    # sync :bar
    use_synth :prophet
    use_synth_defaults cutoff: rrand(70, 110), release: rrand(1, 4)
    with_fx :panslicer, mix: 0.5 do
      with_fx :hpf, cutoff: 70 do
        with_fx :reverb, mix: 0.4 do
          with_fx :echo, mix: 0.2 do
            1.times do
              foo =  play_chord chord(:D3, :minor ), amp: drop_vol
              sleep 0.75
            end
            sleep 0.5
            foo1 =  play_chord chord(:D4, :minor ), attack: 4, release: 2, amp: drop_vol
            sleep 2
          end
        end
      end
    end
  else
    kill foo
    kill foo1
    sleep 0.25
  end
end

start_loop 1
sleep 16
tracker[1] = 0

Hi Eli A good explanation of Set and Get is in the Tutorial section 10. I use them essentially when I want to pass information form the main thread to a live loop (or loops) or to pass information from one live loop to another. MY understanding is that when you use something like set :flag,1 it stores in the time state the value 1, referenced by :flag and importantly at a specific time.This value is fixed. When you subsequently use `puts get(:flag) it retrieves this value and you can use iote if you subsequently use set :flag,2 it stores in the time state the value 2 referenced by :flag and this is the value that will be retrieved by subsequent calls to get (:flag). Note that if you store an array or ring, you cannot alter it when you retrieve it. However you can build a new ring or array using the data from the retrieved one and then use set with that one.
Another useful thing you can do is to save the reference for use with a control command.
if you use

use_synth :tb303
b = play 72, attack: 0.5,sustain: 9.0,release: 0.5,cutoff: 60
set :cont,b

live_loop :vary do
  cv= (ring 60,70,80,90,100,110,100,90,80,70)
  control get(:cont),cutoff: cv.tick,cutoff_slide: 0.1 #control reference passed into the loop
  sleep 0.1
  at 10 do
    stop
  end
end
#following code illustrates use of kill to kill a running synth. NOT documented and therefore not guaranteed
c = play 84,attack: 0.5,sustain: 10,release: 0.5
at 5 do
  kill c
end

Note this example also shows use of kill to stop a running synth. It is NOT documented as a command ans so should be used with caution. It could change.

3 Likes

Hmmm… oki, got it.

Kill, does not seem to work UNLESS it is within the same ‘block’ of code as the
thing it needs to kill…

However if you trigger the kill using a variable, the variable can be altered from elsewhere
in the code… argueably you could set: and get: the variable for forms sake… but this mod
to my previous code does work…

silencer = 0

live_loop :intro1 do
  if tracker[1]>0 then
    # sync :bar
    use_synth :prophet
    use_synth_defaults cutoff: rrand(70, 110), release: rrand(1, 4)
    with_fx :panslicer, mix: 0.5 do
      with_fx :hpf, cutoff: 70 do
        with_fx :reverb, mix: 0.4 do
          with_fx :echo, mix: 0.2 do
            2.times do
              x  =  play_chord chord(:D3, :minor ), amp: drop_vol
              kill x if silencer == 1
              sleep 0.75
            end
            sleep 0.5
            y =  play_chord chord(:D4, :minor ), attack: 4, release: 2, amp: drop_vol
            kill y if silencer == 1
            sleep 2
          end
        end
      end
    end
  else
    sleep 0.25
  end
end

start_loop 1
sleep 16
silencer = 1
sleep 16
silencer = 0

It does spam the report window a bit, because the loop is still active, so it is
constantly killing the new play_chord each loop… but for the sake of it working,
I can live with that…

{run: 7, time: 14.0, thread: :live_loop_intro1}
 └─ killing sound 2386
 
{run: 7, time: 14.375, thread: :live_loop_intro1}
 └─ killing sound 2390
 
{run: 7, time: 15.0, thread: :live_loop_intro1}
 └─ killing sound 2394

Eli…