Syncing best practice

I am just wondering what is best practice with regards to syncing. If I have a simple program like the one below, with three live_loops running constantly but with various sleep periods, should I use sync explicitly or will the live_loops automatically sync if one is changed and they all are relaunched with “Alt+R”?

use_bpm 120

live_loop :a do
  play :c
  sleep 0.5
end

live_loop :b do
  play :e
  sleep 0.25
end

live_loop :c do
  play :g
  sleep 1
end

Hi,

basically everything will be in sync if you will run this code, because you have started all loops at the same time.

As soon as you e. g. update the code and one loop stops because of some (syntax) error, you fix the error and evaluate the code again it is almost sure that the loops will be out of sync (more exactly: the one with the former error will be out of sync). That’s a good reason for explicitly syncing all loops by refering to one of it or an extra metronome loop. There are probably quite a few ways to do that but for a start you might want to have a look at these practical examples.

Hope that helps a bit.

3 Likes

Sorry for the late reply to this but many thanks for sharing the examples. I understand this better now. Good idea to have a metro at top and then a second loop to control the phrase.

I will use sync in the future when running a program that I will update live, but if I have a static program with three loops where there is no issue that the code will stop running due to syntax error, will the loops then run in sync because they were started at the same time, or will there potentially be a small chance of “drifting” over time if the loops run for a longer period?

Hi @keys,

having two interdependant loops (as in one of my examples) is of course by no means necessary but might serve a special purpose.

As to your question: There should be no drift regardless of how long your code is running. I am sure that Sam and the inner workings of SP are taking care of that (unless you are overloading your processor, which I quite often manage to achieve :wink: ).