Hi all, this is my first post. I have just recently gotten started with Sonic Pi, and I’m tremendously excited about the possibilities, but for now I’m stuck scratching my head with the following issue:
Let’s say I have a pattern that I’d like to start from the beginning at arbitrary times; the analogy would be a “reset” input on a sequencer. I can get a live_loop to do this with the following code:
define :play_patt do |restart = false|
live_loop :run_patt do
use_bpm tempo
if restart
tick_reset
restart = false
end
play patt.ring.tick
sleep 1
end
end
play_patt true
and then I just need to hit M-r and the loop starts from the pattern’s first element accordingly.
But if I want to quantize the loop restart, for example to only take effect when a new bar comes around, I’m trying to do this:
sync :new_bar
play_patt true
the :new_bar cue comes from this code:
live_loop :pulse do
cue :new_bar
use_bpm tempo
sleep 4
end
My problem is that the pattern restarts on the beat after the new bar. It appears that waiting for the :new_bar cue “wastes” that actual step, and the pattern restart can only happen the next time around. That’s not what I’m looking for, so I’d be quite grateful for any thoughts on how to quantize user-entered events to an upcoming bar change (or any arbitrary time), and not the next available step after that happens.
If the above doesn’t make sense, here’s an entire example that highlights the issue, with a metronome as well. Any interested respondents should see when hitting M-r, that the pattern only resets on the step after the bar changes. Any suggestions? Thanks in advance for any help.
tempo = 90
beats_per_bar = 4
patt = [:c2, :d2, :e2, :f2, :g2, :a2, :b2, :c3, :c3, :d3, :e3, :f3, :g3, :a3, :b3, :c4]
live_loop :pulse do
cue :new_bar
use_bpm tempo
sleep 4
end
live_loop :metronome do
use_bpm tempo
n = (knit 96, 1, 84, beats_per_bar - 1).tick
play n, release: 0.15
sleep 1
end
define :play_patt do |restart = false|
live_loop :run_patt do
use_bpm tempo
if restart
tick_reset
restart = false
end
play patt.ring.tick
sleep 1
end
end
sync :new_bar
play_patt true