# Live coding syncopated rhythms - best practice help

**URL:** <https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722>\
**Category:** Support, Help & Resources\
**Created:** [June 7, 2025, 5:52pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722 "2025-06-07T17:52:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 7, 2025, 5:52pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/1 "2025-06-07T17:52:06Z")

</div>

Hi Pilots  
I am trying to find ‘best’ practice approaches to live coding/sequencing rhythms, and I have found that using the spread function, and the good old pattern.look method really useful, and immediate. Having to work out each duration/sleep value on-the-fly for each note is a bit time consuming for live coding specifically. So, consider the rhythm “x - - x - - x -” in 4/4 (2 dotted quarter notes and one quarter note). I have tried using spread and pattern.look, without success. How would YOU approach this? The first loop uses the appropriate pitch/sleep values, but is it possible with spread or a .look please?

```ruby
#trying for a 3 note syncopated maj arpeggio
notes = chord(:c3, :major)

use_synth :bass_foundation
live_loop :riff1 do
  #stop
  tick
  play chord(:c3, :maj).look #if spread(3,8).look #doesn't work as expected
  sleep knit(0.75,2, 0.5,1).look
end

ptn = "x--x--x-"
live_loop :riff2 do
  stop
  tick
  play chord(:c3, :maj).look if ptn.look == "x"
  sleep 0.25
end

/
rhythms are easier and quicker to live code via ptn.look and spread; 
rather than working out each duration for sleep; does that make me lazy? :D
/

PD-Pi

```

---

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [June 7, 2025, 7:03pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/2 "2025-06-07T19:03:52Z")

</div>

Solution: The code needs a separate “tick(:a)” on the chord

```ruby
ptn = "x--x--x-"
live_loop :riff2 do
  # stop
  tick
  play chord(:c3, :maj).tick(:a) if ptn.look == "x"
  sleep 0.25
end

```

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 7, 2025, 7:17pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/3 "2025-06-07T19:17:38Z")

</div>

Separate ticks, of course! Thank you \<3

---

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [June 7, 2025, 7:19pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/4 "2025-06-07T19:19:43Z")

</div>

Other ways of coding the rhythm

```ruby
#ptn = "x--x--x-"
live_loop :riff2 do
  # stop
  tick
  #play chord(:c3, :maj).tick(:a) if ptn.look == "x"
  play chord(:c3, :maj).tick(:a) if (spread(1,3)*2+spread(1,2)).look
  # play chord(:c3, :maj).tick(:a) if bools(1,0,0,1,0,0,1,0).look
  sleep 0.25
end

```

```ruby
#ptn = "x--x--x-"
live_loop :riff2 do
  # stop
  tick
  #play chord(:c3, :maj).tick(:a) if ptn.look == "x"
  #play chord(:c3, :maj).tick(:a) if (spread(1,3)*2+spread(1,2)).look
  play chord(:c3, :maj).tick(:a) if bools(1,0,0,1,0,0,1,0).look
  sleep 0.25
end

```

```ruby
define :s do |a,b|
  spread(a,b)
end

live_loop :riff2 do
  tick
  play chord(:c3, :maj).tick(:a) if (s(1,3)*2+s(1,2)).look
  sleep 0.25
end

```

---

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [June 7, 2025, 7:27pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/5 "2025-06-07T19:27:22Z")

</div>

Started to play a bit with this 🙂

```ruby
class SonicPi::Core::RingVector # r() only works on s() - doesnt work on an array like [].r()
  def r(n)
    self.rotate(n)
  end
end

define :s do |a,b|
  spread(a,b)
end

live_loop :riff2 do
  tick
  play chord(:c3, :maj).tick(:a) if (s(1,3)*2+s(1,2)).look
  play chord(:c3, :maj).tick(:b)+12 if (s(1,3)*2+s(1,2)).r(1).look
  sleep 0.25
end

```

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 7, 2025, 9:13pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/6 "2025-06-07T21:13:39Z")

</div>

I knew the Master of the spread function would offer several solutions! I personally prefer spread(1,3)\*2 + (1,2), it offers more immediate ‘flexibility’

---

<div class="post-metadata">

**Author:** ![HarryLeBlanc](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/harryleblanc/32/2813_2.png) [@HarryLeBlanc](https://in-thread.sonic-pi.net/u/HarryLeBlanc)\
**Post date:** [June 8, 2025, 11:06pm UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/7 "2025-06-08T23:06:59Z")

</div>

Why not just use spread(3,8)? It outputs this:  
(ring true, false, false, true, false, false, true, false)

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [June 9, 2025, 7:59am UTC](https://in-thread.sonic-pi.net/t/live-coding-syncopated-rhythms-best-practice-help/9722/8 "2025-06-09T07:59:45Z")

</div>

It offers a little more flexibility over the distribution, one spread function can only have one outcome - unless we rotate, shuffle, push etc. For example, compare:

```ruby
puts spread(6,8)
sleep 1
puts spread(4,6) + spread(2,2)

```

PD-Pi
