# Usage of "sync". The difference between ver.2 and ver.3

**URL:** <https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795>\
**Category:** Support, Help & Resources\
**Created:** [December 10, 2018, 3:41am UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795 "2018-12-10T03:41:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_Tachibana](https://avatars.discourse-cdn.com/v4/letter/h/e68b1a/32.png) [@H\_Tachibana](https://in-thread.sonic-pi.net/u/H_Tachibana)\
**Post date:** [December 10, 2018, 3:41am UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/1 "2018-12-10T03:41:25Z")

</div>

Question about the usage of sync.

In Sonic Pi ver.2 the following program worked normally.

live\_loop :d1 do  
8.times do  
sample :drum\_cymbal\_closed  
sleep 0.5  
end  
end

live\_loop :d2 do  
sync :d1  
2.times do  
sample :drum\_bass\_hard  
sleep 2  
end  
end

But in ver.3 the second loop :d2 does not work correctly.  
If I changed “sleep 2.0” to “sleep 1.999” it worked well.

live\_loop :d1 do  
8.times do  
sample :drum\_cymbal\_closed  
sleep 0.5  
end  
end

live\_loop :d2 do  
sync :d1  
2.times do  
sample :drum\_bass\_hard  
sleep 1.999 # \<\<\<\<\<\<\<\<\<  
end  
end

Is there something wrong with me?  
macOS 10.10.5, Sonic Pi 3.10

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [December 10, 2018, 6:31am UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/2 "2018-12-10T06:31:22Z")

</div>

Hi,

no, nothing wrong with you 😉 See [First little diddy](http://in-thread.sonic-pi.net/t/first-little-diddy/1449/7) for a discussion on this behaviour. And yes, there is a difference betweet 2.x and 3.1, see [https://github.com/samaaron/sonic-pi/issues/1730](https://github.com/samaaron/sonic-pi/issues/1730)

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [December 10, 2018, 12:24pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/3 "2018-12-10T12:24:24Z")

</div>

Hi,

Yes it’s an important problem which i would call a bug. As you and maybe many users, i was very surprised and upset about this point.

I think the doc should be improved or updated to clearly explain how does it really work or a tutorial.  
Cheers

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [December 10, 2018, 1:22pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/4 "2018-12-10T13:22:11Z")

</div>

Hi,

well, actually it seems to me that it is the opposite of a bug i. e. a bugfix. But I agree, it is a behaviour which is somehow counter-intuitive in the beginning.

I am a bit confused though… wasn’t it you who brought up (and ended) [this fruitful discussion in the Patreons area](http://in-thread.sonic-pi.net/t/live-loops-sync-questions/1172/29)? I had the impression that the issue is somehow resolved for you?

---

<div class="post-metadata">

**Author:** ![H\_Tachibana](https://avatars.discourse-cdn.com/v4/letter/h/e68b1a/32.png) [@H\_Tachibana](https://in-thread.sonic-pi.net/u/H_Tachibana)\
**Post date:** [December 10, 2018, 1:34pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/5 "2018-12-10T13:34:59Z")

</div>

Thank you Martin.

I’m sorry to have made the same question in the past.

I think I will use  
live\_loop :d2, sync: d1 do  
or  
live\_loop :d2, auto\_sync: d1 do

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [December 10, 2018, 1:48pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/6 "2018-12-10T13:48:02Z")

</div>

Oh, don’t be sorry. It happens to me quite often 😉

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [December 10, 2018, 3:31pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/7 "2018-12-10T15:31:24Z")

</div>

> [@H\_Tachibana](#):
>
> live\_loop :d1 do  
> 8.times do  
> sample :drum\_cymbal\_closed  
> sleep 0.5  
> end  
> end
> 
> live\_loop :d2 do  
> sync :d1  
> 2.times do  
> sample :drum\_bass\_hard  
> sleep 1.999 # \<\<\<\<\<\<\<\<\<  
> end  
> end

I find this the neatest solution to use.

```ruby
live_loop :d1,delay: 0.001 do #delay ensures loop :d2 starts before loop :d1
  8.times do
    sample :drum_cymbal_closed
    sleep 0.5
  end
end

live_loop :d2 do
  sync :d1
  2.times do
    sample :drum_bass_hard
    sleep 2
  end
end

```

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [December 10, 2018, 4:25pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/8 "2018-12-10T16:25:10Z")

</div>

Yes it was me 🙂 but i am always frustrated and confused by this as you say “counter-intuitive” way to work. And it’s not yet clear in my little head 🙂  
But it’s clear that is not intuitive because so many users meet the problem no ?

---

<div class="post-metadata">

**Author:** ![H\_Tachibana](https://avatars.discourse-cdn.com/v4/letter/h/e68b1a/32.png) [@H\_Tachibana](https://in-thread.sonic-pi.net/u/H_Tachibana)\
**Post date:** [December 10, 2018, 4:51pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/9 "2018-12-10T16:51:27Z")

</div>

Thank you, Robin.

However, I think, the second loop had to be:  
live\_loop :d2, sync: :d1 do

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [December 13, 2018, 9:47pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/10 "2018-12-13T21:47:59Z")

</div>

hi,

I think @robin.newman does not answer to the same problematic. His solution is for the d2 to “start” at the same time of d1 and not to have to wait your 8 beats of d1 for d2 to start

@H_Tachibana is more worried by the problem of

```ruby
live_loop :d3 do
  4.times do
    sample :drum_cymbal_closed
    sleep 1
  end
end

live_loop :d4 do
  sync :d3
  sample :drum_bass_hard
  sleep 4 # the drummer is busy to count not time to catch the cue but next time he will play for sure
end

live_loop :d5 do
  sync :d3
  sample :drum_roll
  sleep 3.99 # the drummer count until 3.99 and rise his head for 0.01 to see the cue
end

```

Hope it helps !  
Cheers

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [December 13, 2018, 10:00pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/11 "2018-12-13T22:00:48Z")

</div>

I think you’re right @robin.newman made a little mistake. It would be nice if he can confirm himself, please to avoid more confusion ?

```ruby
live_loop :d1, delay: 0.01 do # delay ensures loop :d2 starts before loop :d1
  #stop
  8.times do
    sample :drum_cymbal_closed
    sleep 0.5
  end
end

live_loop :d2, sync: :d1 do
  #stop
  2.times do
    sample :drum_snare_soft
    sleep 2
  end
end

```

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [December 13, 2018, 10:39pm UTC](https://in-thread.sonic-pi.net/t/usage-of-sync-the-difference-between-ver-2-and-ver-3/1795/12 "2018-12-13T22:39:59Z")

</div>

Hi guys  
Yes you are right. I had the sync in the wrong place. nlb’s last post is correct.
