Live_Loop does not update

Got myself a Raspberry Pi and discovered Sonic Pi shortly thereafter.

Been having a bit of fun with it, however I can never seem to get Live_Loops working the way I expect them to, that is to say when I change a variable, it is not reflected in the sound output; I have to hit “run” again Is there a setting somewhere I need to change or is this the expected behavior?

I’ve copied code straight from the tutorial and this does not work either. super simple code until I worked out…

    live_loop :foo do
      play 50
      sleep 1

Raspbian is up to date, as in Sonic Pi.

Thank you in advance :slight_smile:

Believe that I have now answered my own question… as far as I can tell, you need to run the code again.

Is this assumption correct - re-read the tutorial, but couldn’t find any clarity from this.

Thanks again

Hi @Toro, you’re correct, you need to execute a run in order for the code to update. This tells the editor “I’m done with this change, apply it now”.

Hi Toro
Welcome to in-thread

What you are experiencing is what is expected.
Basically a live_loop repeats the code within itself when run is pressed. In this case a repeating note of 50. If you redefine the loop by altering the 50 to say 72, it registers this when you press Run again. However, it finishes the current iteration of the loop and then changes to the new definition on the next run. This keeps things going in time.
You can see it working if you change things via the program.
Consider this program:

set :n,50

live_loop :foo do
  puts n
  play n
  sleep 1

sleep 3.5
set :n,72

This stores the value 50 for :n in the time state.
The live loop starts,retrieves the value of :n and prints and plays it.
after 3.5 beats the value of :n is set to 3.5
This is picked up byt the live loop which uses the new value on the next iteration, and 72 is printed and played at time 4

here is the printed output:

=> Starting run 90

=> Redefining fn :live_loop_foo

{run: 90, time: 0.0}
 ├─ set :n, 50
 └─ set :n, 50
{run: 90, time: 0.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
{run: 90, time: 1.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
{run: 90, time: 2.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
{run: 90, time: 3.0, thread: :live_loop_foo}
 ├─ 50
 └─ synth :beep, {note: 50.0}
{run: 90, time: 3.5}
 ├─ set :n, 72
 └─ set :n, 72
{run: 90, time: 4.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}
{run: 90, time: 5.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}
{run: 90, time: 6.0, thread: :live_loop_foo}
 ├─ 72
 └─ synth :beep, {note: 72.0}

Notive the times at which the varies notes are played:
at 0,1,2 and 3 50 is played and printed
at 3.5 n is changed to 72
at 4,5,…72 is printed and played


Thanks for your replies, greatly appreciated.

Read the tutorial over and over, but this fact did not appear to be explicitly stated (or maybe it is and I’m struggling to see the woods for the trees).

Also had a look at the keyboard shortcuts which make it work better too :blush: