Hi, new to Sonic Pi and very keen to use it. I’ve been through the tutorials and got very excited about using cues and syncs for controlling many arps and voices…but…clearly something I don’t understand about the model. Without a solid mechanism for doing this I can’t build what I need. If anyone could point me in the right direction I’d be very grateful.
In the simplified code (at the end of this post) I have one live loop that cycles between two chords and plays the current one, and another loop that plays the current chord. I use the ‘set’ command to both set the chord globally and create cue to play it.
What I thought should happen (in pseudo code) is
in loop 'changechord' choose a chord set it send out the cue in loop 'playchord' receive the cue, so start running code... get the new chord play it
BUT I found this only works if I put a short delay ‘sleep 0.001’ in the ‘playchord’ loop - otherwise it doesn’t pick up new chord.
I know that the loops are running concurrently, but don’t the statements within a loop run sequentially? What’s wrong my with understanding of the model. Is this a valid workaround?
use_bpm 60 chord1 = [:C4, :Eb4, :G4] chord2 = [:F4, :A4, :C5] seq = [chord1, chord2].ring live_loop "playchord" do sync "/set/currentchord" ########### sleep 0.001 ########### c = get[:currentchord] sleep 1 puts "b " + c.to_s play c end live_loop "changechord" do c = seq.tick puts "a " + c.to_s set :currentchord, c use_synth :tri play c 4.times do sample :drum_cymbal_closed, amp: 0.3 sleep 1 end end