Skip to content

Time state get and set issue #3480

@yuanzhiqian

Description

@yuanzhiqian

I found the sample code in the tutorial highly dependent on the order of live_loop defined, if I switch those two live_loops, as such below, the result would be again in a chaos like before. I believe the key reason is rather happening in the sleep 0.5, when shuffle may take part in no matter whether you use getter and setter or not. Anyone agree with me?

## An Example of Deterministic Behaviour
## (despite concurrent access of shared state)
## using Sonic Pi's new Time State system.
##
## When this code is executed, the list that's
## printed is always sorted!
set :a, (ring 6, 5, 4, 3, 2, 1)

live_loop :sorted do
  set :a, get[:a].sort
  sleep 0.5
  puts "sorted: ", get[:a]
end

live_loop :shuffled do
  set :a, get[:a].shuffle
  sleep 0.5
end

the output is:

=> Starting run 11

=> Redefining fn :live_loop_sorted

=> Redefining fn :live_loop_shuffled

{run: 11, time: 0.5, thread: :live_loop_sorted}
 └─ "sorted: " (ring 4, 6, 2, 3, 1, 5)
 
{run: 11, time: 1.0, thread: :live_loop_sorted}
 └─ "sorted: " (ring 6, 2, 3, 5, 1, 4)
 
{run: 11, time: 1.5, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 3, 5, 6, 2, 4)
 
{run: 11, time: 2.0002, thread: :live_loop_sorted}
 └─ "sorted: " (ring 3, 2, 4, 1, 6, 5)
 
=> Stopping all runs...

=> Stopping run 11

{run: 11, time: 2.5002, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 4, 6, 5, 2, 3)
 
{run: 11, time: 3.0002, thread: :live_loop_sorted}
 └─ "sorted: " (ring 6, 5, 4, 1, 2, 3)
 
=> Completed run 11

=> All runs completed

=> Pausing SuperCollider Audio Server


but if I change the order of the loops defined, like this

## An Example of Deterministic Behaviour
## (despite concurrent access of shared state)
## using Sonic Pi's new Time State system.
##
## When this code is executed, the list that's
## printed is always sorted!
set :a, (ring 6, 5, 4, 3, 2, 1)

live_loop :shuffled do
  set :a, get[:a].shuffle
  sleep 0.5
end

live_loop :sorted do
  set :a, get[:a].sort
  sleep 0.5
  puts "sorted: ", get[:a]
end

then the output is changed as well, that means the result can’t be controlled

=> Starting run 17

=> Defining fn :live_loop_shuffled

=> Redefining fn :live_loop_sorted

{run: 17, time: 0.5001, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 2, 3, 4, 5, 6)
 
{run: 17, time: 1.0, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 2, 3, 4, 5, 6)
 
{run: 17, time: 1.5, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 2, 3, 4, 5, 6)
 
=> Stopping all runs...

=> Stopping run 17

{run: 17, time: 2.0, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 2, 3, 4, 5, 6)
 
{run: 17, time: 2.5, thread: :live_loop_sorted}
 └─ "sorted: " (ring 1, 2, 3, 4, 5, 6)
 
=> Completed run 17

=> All runs completed

=> Pausing SuperCollider Audio Server

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions