Change running code


#1

I would like to change a running live loop. How can I do this? E.g changing the BPM from 240 to 120, or changing the reverb mix from 0.5 to 1.0…

use_bpm 240

live_loop :metronome do
  sleep 1
end

with_fx :gverb, tail_level:0.5,mix:0.5  do
  live_loop :loop1, sync: :metronome do
    sample :elec_filt_snare
    sleep 4
  end
end

#2

This works, although slightly kludgy

First run the program below ONCE, but DONT stop it

set :bpm,240
use_bpm get(:bpm)

live_loop :metronome do
  use_bpm get(:bpm)
  sleep 1
end
with_fx :gverb, tail_level:0.5,mix: 0 do |k| #comment out after 1st run
  set :k,k #comment out after 1st run
  live_loop :loop1, sync: :metronome do
    kl=get(:k)
    control kl,mix: 0.4
    use_bpm get(:bpm)
    sample :elec_filt_snare
    sleep 4
  end
end #comment out after 1st run

Then amend it as shown below and re-run

set :bpm,240
use_bpm get(:bpm)

live_loop :metronome do
  use_bpm get(:bpm)
  sleep 1
end
##| with_fx :gverb, tail_level:0.5,mix: 0 do |k| #comment out after 1st run
##|   set :k,k #comment out after 1st run
live_loop :loop1, sync: :metronome do
  kl=get(:k)
  control kl,mix: 0.4
  use_bpm get(:bpm)
  sample :elec_filt_snare
  sleep 4
end
##| end #comment out after 1st run

Now you can run it repeatedly (without stopping), changing the bpm value in the first line and the mix value inside the live_loop and it will respond to both changes.

EDIT changin the control line to

control kl,mix: (range(0,1,0.1)+range(1,0,-0.1)).tick

gives a nice effect.


#3

Here is an example using set and get to vary bpm according to a ring of values.

Eli.

# Eli 17/09/2018.

use_bpm 90

my_bpm = (ring 90,90,100,110,120,120,120,110,100,90,90).mirror

bg1 = (ring 0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.0).mirror
bg2 = (ring 0.6,0.5,0.4,0.3,0.2,0.1,0.0,0.0).mirror

melody_1 = [:c4,:r,:ds4,:ds4,:g4,:c4,:r,:gs4,:r,:r,:gs3,:r,:g3,:r,:r,:r].ring

live_loop :beats do
  sleep 1
end

live_loop :bar do
  sleep 4
end

# Initially set my_bpm, so the loop works, otherwise
# you'd just get an error message.
set :bvol1, bg1.look
set :bvol2, bg2.look
set :speed, my_bpm.look

#this loop updates the value of my_bpm, but only
#once the main loop has triggered.
live_loop :mixer do
  sync :background1
  tick
  set :bvol1, bg1.look
  set :bvol2, bg2.look
  set :speed, my_bpm.look
end

with_fx :reverb, mix: 0.5, room: 0.9 do
  with_fx :ixi_techno, mix: 0.75, room: 0.9 do
    # the main loop making all the noise
    
    live_loop :background1, sync: :beats do
      
      #get the speed for this particular loop
      this_speed = get :speed
      #set the speed for this particular loop
      use_bpm this_speed
      
      use_synth_defaults amp: 2
      use_synth (ring :supersaw, :prophet, :prophet, :tech_saws).tick
      3.times do
        play :C4, cutoff: rrand(60,80)
        sleep 0.5
        play :G3, cutoff: rrand(60,90)
        sleep 0.5
        play :C4, cutoff: rrand(60,70)
        sleep 0.5
        play :Gs3, cutoff: rrand(60,80)
        sleep 0.25
        play :Gs3, cutoff: rrand(70,100)
        sleep 0.25
      end
      1.times do
        play :c4, cutoff: rrand(60,80), release: 1
        sleep 0.5
        play :g4, cutoff: rrand(60,90), release: 1
        sleep 0.5
        play :c4, cutoff: rrand(60,70), release: 1
        sleep 0.5
        play :gs3 + 7, cutoff: rrand(80,100), release: 1
        sleep 0.5
      end
    end
  end
end

#4

Hi @Eli,

Starting and finishing multiple lines of code with ``` will format the code nicely and also colour it in similar to Sonic Pi’s editor.

From:

Cheers
Martin


There's a short way to write a long chord progression than this?
#5

Exactly what I needed, thanks!