Play every nth beat

Hi gang!

I’m curious as to how people tend to do stuff like
play notes / pattern every 4 beats
sample/play/synth on every 7th beat
play sample(s) on beats 1,5,7

So I thought I’d create a topic to compare notes!

:pray:t2::metal:t2:

Hi jonny
the spread and bools conditional functions are very flexible - generate an event only if the condition is true:

fourfour = spread(1,4)

puts fourfour

sevenfour = spread(1,7)

puts sevenfour

onefiveseven = bools(1,0,0,0,1,0,1)

puts onefiveseven

Output:

{run: 2, time: 0.0}
 ├─ (ring true, false, false, false)
 ├─ (ring true, false, false, false, false, false, false)
 └─ (ring true, false, false, false, true, false, true)

PD-Pi

1 Like

pattern.ring.tick == “x”

First the awesome pattern method, as seen in BlockGame (and all over the forum: )

define :pattern do |pattern|
  return pattern.ring.tick == "x"
end

usage example (1,5,7): sample :bd_tek if pattern "x---x-x-"

This can be tweaked, so you can use named ticks,
or using look (after a loop tick) to allow multiple patterns in the same loop

define :pattern do |pattern|
  return pattern.ring.look == "x"
end

live_loop :a do
  tick
  sample :bd_tek if pattern "x---x-x-"
  sample :drum_tom_mid_hard if pattern "-xx---x-"
  sleep 0.25
end
1 Like

Thanks @brendanmac , the spread method is awesome, and bools is useful too :ok_hand:t2:

One stupid question I’m curious about, what does the four denote in sevenfour?!

sevenfour = spread(1,7)
# true, false, false, false, false, false, false

I wrote sevenfour, meaning 7 crotchet or quarter note beats - it’s not strictly relevant :wink:

I love the pattern approach too, but can never get my head round how the ring is actually populated, i.e. how many elements it has - or does that not happen until you actually call the function, with “x—x—”, so now it has 8 elements. I use it sometimes, and it works fine, I just don’t like not understanding it entirely.

PD-Pi

Of course! Thank you👍🏻

on truthy

I just had my first play with on … this ain’t pretty, but it works!

on ((look - 1) % 4).zero? do #1,5,9
    play chord :c, :M
end

With the pattern, you’re correct that the length is determined by the length of the string.

Interestingly I had similar uncertainty with your approach, wondering where to declare the variable (inside the loop, or outside? a: doesn’t matter : )

There’s a little bit of ambiguity with the :pattern method because the parameter shares the same name…

Also the return appears to be optional, but makes the code more readable.
This does the same thing (assumes you’ve already ticked)

define :pattern do |p|
  p.ring.look == "x"
end

also a helper method for clarity…

define :pattern_info do |p|
  "p is a #{p.class} of length #{p.size}"
end

puts pattern_info "xxxx"
#p is a String of length 4

Hope this helps!

1 Like

That’s very clear indeed thanks