# Sync and the place into the code

**URL:** <https://in-thread.sonic-pi.net/t/sync-and-the-place-into-the-code/1997>\
**Category:** Support, Help & Resources\
**Created:** [February 12, 2019, 9:39pm UTC](https://in-thread.sonic-pi.net/t/sync-and-the-place-into-the-code/1997 "2019-02-12T21:39:12Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [February 12, 2019, 9:39pm UTC](https://in-thread.sonic-pi.net/t/sync-and-the-place-into-the-code/1997/1 "2019-02-12T21:39:12Z")

</div>

Hi again,

Let’s try this piece of code. We have to declare the live\_loop who trigger a cue to the live\_loops we want to be synced **after** them.

```ruby
# The importance of the place into the code

use_bpm 60
use_synth :piano

live_loop :name_of_live_loop_every_8_beats, delay: 1 do
  cue :_every_8_beats
  sleep 8
end

# ok every 4 beats the live_loop is played and it's a real pleasure
live_loop :foo_01 do
  sync :_every_4_beats
  play_pattern_timed [:c, :d, :e, :f] , 1
end

# this loop will be played for 4 beats then stop 4 beats
live_loop :foo_02 do
  sync :name_of_live_loop_every_4_beats
  use_octave 2
  play_pattern_timed [:c, :d, :e, :f] , 1
end

# this loop will be played every 8 beats then stop for 8 beats

live_loop :foo_03 do
  sync :_every_8_beats
  use_synth :prophet
  use_octave 2
  play_pattern_timed scale(:c, :major), 1
end

# the good place to be into the code AFTER the loop we want to be synced.
live_loop :name_of_live_loop_every_4_beats, delay: 1 do
  cue :_every_4_beats
  sleep 4
end

```

Cheers

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [February 13, 2019, 11:50am UTC](https://in-thread.sonic-pi.net/t/sync-and-the-place-into-the-code/1997/2 "2019-02-13T11:50:04Z")

</div>

Hi @nlb,

I’m ~~fairly certain~~ wondering whether this is still due to the deterministic behaviour that Sam introduced in v3. In [his comment on my github issue](https://github.com/samaaron/sonic-pi/issues/1730#issuecomment-353114957) he stated that for threads syncing and cue-ing on the same logical time, what determines whether the cue or the sync happens first is the id of the thread. (This ~~is, I suspect,~~ could be why the behaviour is fine here if the cue-ing threads come _after_ the syncing threads in the file, though @samaaron would be the one to confirm this. The reason I’m a little unsure is that I would think that thread id for a given live\_loop would stay the same even if we cut and paste it into a different section of the file).

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [February 13, 2019, 12:05pm UTC](https://in-thread.sonic-pi.net/t/sync-and-the-place-into-the-code/1997/3 "2019-02-13T12:05:09Z")

</div>

(I do also have to say that obviously there is a difference between syncing on a live\_loop’s name vs syncing on a separate cue inside the same live\_loop - exactly what is going on _there_ I am not 100% sure about. So it’s definitely something that could be a bit clearer!)
