For this kind of musical behaviour, you might want to explore tick and look which are thread local counters that you manually increment and give you a lot of control.
For example:
live_loop :drums do
sample :drum_cymbal_closed
sample :drum_bass_soft, on: tick % 2
sleep 1
end
actually, this is required when using if. Ruby doesn’t see 0 as being false - only nil and false are considered falsey. That’s one of the benefits of on: as it relaxes this to also include 0 in addition to not requiring to be at the end of the line.
You therefore need the following if you want to use if (which, to be honest I rarely do).
live_loop :drums do
sample :drum_cymbal_closed
sample :drum_bass_soft if tick % 2 == 0
sleep 1
end
I’m not sure how it’s more tricky than beat which already requires learners to know about an internal counter associated with sleep.
tick just increments a counter every time it is called and returns the latest value of that counter. It’s basically a code version of a hand-held click-counter used to count the number of people entering a room (and it only counts upwards). It’s independent of sleep and only increments when you call it, so you get more control.