#3208·sonic-pi

Set/get not synced in all threads

Author: synchronisatorCreated Sep 10, 2022Updated Sep 11, 2022

I am playing around with the use of set/get. I tried this code: `live_loop :met do; sleep 1; end live_loop :met4 do; sleep 4; end live_loop :met8 do; sleep 8; end live_loop :met16 do; sleep 16; end

live_loop :chordSwitcher, sync: :met do chords = [ [:C4, :major, 4], [:G4, :major, 4], [:A4, :minor, 2], [:G4, :major, 2], [:F4, :major, 4], [:C4, :major, 2], [:G4, :major, 6], ].ring

c = chords[tick]

print("set chord #{c}") set :ch, c set :chl, c[2] set :chc, (chord c[0], c[1]) set :chs, (scale c[0], c[1] == :major ? :harmonic_major : :harmonic_minor)

print("set chord #{c} end") sleep c[2] end

live_loop :bg ,sync: :chordSwitcher do tick print("play chord #{get(:chc)}") play_chord get(:chc), sustain: get(:chl) sleep get(:chl) end

live_loop :mel ,sync: :chordSwitcher do tick print("play mel #{get(:chs)}") use_random_seed 11 + look%8 play (get(:chs).choose) sleep [0.5,1,1,2].choose end`

But unfortunately the melody sometime keeps an old scale instead of switching to the new one.

`{run: 40, time: 21.2, thread: :live_loop_chordSwitcher} ├─ "set chord [:G4, :major, 4]" └─ "set chord [:G4, :major, 4] end"

{run: 40, time: 21.2, thread: :live_loop_mel} ├─ "play mel (ring <SonicPi::Scale :C :harmonic_major [60, 62, 64, 65, 67, 68, 71, 72])" └─ synth :beep, {note: 64.0, release: 0.4}

{run: 40, time: 21.2, thread: :live_loop_bg} ├─ "play chord (ring <SonicPi::Chord :G :major [67, 71, 74])" └─ synth :beep, {note: [67.0, 71.0, 74.0], sustain: 1.6, release: 0.4}`

This problem is reproducable on Linux Mint 20 (Mate 64-bit) with Sonic Pi 3.2.2