Hi
I have been working on a setup where I send an osc message from a DAW to Sonic Pi for each first beat in a bar. This works fine but I have a syncing issue. What I hope to do is to play 45 one the first beat, 47 on the second, 48 on the third and 52 on the fourth. However this always ends up having 52 as the first beat. I know there is something I am missing here but I would really appreciate if someone can enlighten me. Thanks
live_loop :firstbeat do
use_real_time
a = sync "/osc*/firstbeat"
end
live_loop :t1, sync: :metro do
notes = (ring 45,47,48,52)
note = notes.tick
puts note # play comes here...
sleep 0.5
end
Edit : this does not make the job … I misunderstood your request yesterday.
# osc signal is sent by spi itself for the example
use_osc "localhost", 4560
live_loop :send do
osc "/osc/firstbeat"
sleep 0.5
end
# you only need this live_loop as the osc signal comes from your daw
live_loop :firstbeat do
use_real_time
sync "/osc:127.0.0.1:4560/osc/firstbeat"
notes = (ring 45,47,48,52)
play notes.tick # play comes here...
end
use_osc "localhost", 4560
live_loop :send do
osc "/osc/firstbeat"
sleep 2
end
live_loop :firstbeat do
use_real_time
sync "/osc:127.0.0.1:4560/osc/firstbeat"
use_synth :piano
notes = (ring 45,47,48,52)
(notes.length).times do
play notes.tick
sleep 1
end
end
Thanks for the advise. I have played around with your suggestion, and it was a good idea to use the osc directly in the live loop and then run through the ring. But sometimes it skips a run when using it this way with an external application. I have to look into this a bit more to understand what is going on, but it seems like the final sleep is occasionally causing the osc heartbeat to be missed for the next run.
use_osc "localhost", 4560
live_loop :send do
osc "/osc/firstbeat"
sleep 1
end
notes = (ring 45,47,48,52)
live_loop :firstbeat do
use_real_time
sync "/osc:127.0.0.1:4560/osc/firstbeat"
use_synth :piano
play notes.tick
end
so the live_loop will be launched each time it receives the signal. And the signal is sent every one beat.
If you want to get some 1/2 beat = quaver, put sleep 0.5
now i guess that you’re not going to send the signal every beat via your DAW do you ?
Note that next example and the specific latest line.
use_osc "localhost", 4560
live_loop :send do
osc "/osc/firstbeat"
sleep 2
end
live_loop :firstbeat do
use_real_time
sync "/osc:127.0.0.1:4560/osc/firstbeat"
use_synth :piano
notes = (ring 45,47,48,52)
(notes.length-1).times do
play notes.tick
sleep 1
end
play notes.tick
sleep 0.99 # it's weird but it's the way to follow
end
Yes missing out a final sleep or reducing it makes sure that the sync controls things. Otherwise the cue in the form of an incoming OSC message my be sent before the receiver is waiting for it and the sync will have to wait for the next incoming message. It is the same whatever the source of the cue message is and there have been long threads discussing this topic on the site.
Thank you both for the advise. Leaving out the final sleep did the trick.
The good thing with this setup is that the ring now can be as long as I want it to be, and it will only pick up a new “firstbeat” when all the tones in the ring have been played.