Best way to toggle between 2 different live_loops

Wondering what the best way would be to toggle between 2 different live_loops?

In general, I know that live_loops tend to ‘layer on top of each other’. I’ve been using the approach to CMD + s, then CMD + r, to stop then play when I decide to comment out a loop.

Curious:
a) What is the best way to stop a single running loop
b) What is the best way to programmatically turn ON and OFF loops between 2 loops when the program is running.

Note: I’ve seen the use of creating a ring to cycle between beats on the amp: opts for a sound, but not sure if this is the best way to do such.

1 Like

Here’s an example controlling three live loops which can independently be stopped and started.
This is done by embedding each loop in a function, and using that to control a stop command inside each loop

use_synth :tri

define :lone do |action|
  if action==1
    set :k1,false
    live_loop :one do
      play scale(:c5,:minor_pentatonic).choose,release: 0.1
      sleep 0.1
      stop if get(:k1)
    end
  else
    set :k1,true
  end
end

define :ltwo do |action|
  if action==1
    set :k2,false
    live_loop :two do
      
      play scale(:g5,:minor_pentatonic).choose,release: 0.1
      sleep 0.1
      stop if get(:k2)
    end
  else
    set :k2,true
  end
end

define :lthree do |action|
  if action==1
    set :k3,false
    live_loop :three do
      play scale(:c6,:minor_pentatonic).tick,release: 0.1
      sleep 0.1
      stop if get(:k3)
    end
  else
    set :k3,true
  end
end


live_loop :control do
  puts "start live_loop :lone"
  lone 1
  sleep 4
  puts "stop live_loop :lone"
  puts "start live_loop :ltwo"
  lone 0
  ltwo 1
  sleep 4
  puts "stop live_loop :ltwo"
  puts "start live_loop :lthree"
  ltwo 0
  lthree 1
  sleep 4
  puts "ADD live_loop :lone"
  lone 1
  sleep 2
  puts "ADD live_loop :ltwo"
  ltwo 1
  sleep 4
  puts "stop live_loop :one"
  puts "stop live_loop :ltwo"
  puts "stop live_loop :lthree"
  lone 0
  ltwo 0
  lthree 0
  sleep 2
end
4 Likes

Thank you for this.

What about for an already running live_loop? If I want to remove a progression that has been added?

Or is the best to do so to have a variable assigned to the amp on the sound?

Ultimately, I want to be able to fade between 2 sounds, and currently experimenting with this as a type of fade on volume, but getting errors on updating the numeric value.

live_loop :fade do
  vol = get[:volume]
  vol = vol * 0.5 # <-- error on this.
  set :volume, vol
  sleep 2
end

Is multiplication not allowed?

It should work but you have to make sure that you have set an initial value BEFORE starting the loop as otherwise the value will be nil and you cant multiply nil by 0.5!

Try this:

set :volume,1 #make sure you have stored a value for :volume BEFORE the first get
live_loop :fade do
  vol = get[:volume]
  vol = vol * 0.5 
  set :volume, vol
  puts vol
  sleep 2
end

Will try thank you. And any suggestions for this? Or do you think setting a local variable is the best way?

Not sure exactly what you mena by adding or removing a “progression” from a live loop.
You can certainly switch on and off bits of a live loop.
eg try altering the two values for :bh and :dc in this loop. from true to false or vice versa

set :bh,true
set :dc,true

live_loop :test do
  sample :bd_haus if get(:bh)
  sleep 0.5
  sample :drum_cymbal_hard if get(:dc)
  sleep 0.5
end

if you want to change the timings too, you could put the control inside an if…end construct eg

set :bh,true
set :dc,true

live_loop :test do
 if get(:bh)
    sample :bd_haus
    sleep 0.5
end
  sample :drum_cymbal_hard if get(:dc)
  sleep 0.5
end

but make sure there is still some sleep time in the loop if you switch off all the sections

EDIT

if you are controlling from outside the loop as here, best to use set and get.

1 Like