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

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

Hi,

no, nothing wrong with you :wink: See First little diddy 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

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

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? I had the impression that the issue is somehow resolved for you?

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

Oh, donā€™t be sorry. It happens to me quite often :wink:

I find this the neatest solution to use.

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

Yes it was me :slight_smile: 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 :slight_smile:
But itā€™s clear that is not intuitive because so many users meet the problem no ?

Thank you, Robin.

However, I think, the second loop had to be:
live_loop :d2, sync: :d1 do

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

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

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 ?

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

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

1 Like