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
n=get(:n)
puts n
play n
sleep 1
end
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