Hi, I’m pretty new to Sonic Pi. I have three loops: metronome, main, and bass. Metronome contains only a sleep 32. Main and bass start with a sync :metronome. I’m having an issue where despite metronome being defined last, it ends up executing first, causing main and bass to have to wait for metronome to run again. This happens again after they run, effectively causing them to alternate 32 beats on, 32 beats off. Am I doing something wrong? What can I do to fix this?
welcome to Sonic Pi and to
(It’s quite helpful to post the code so others can try it out. You can start with 3 backticks in the first line and end with another line of 3 backticks. This will show your code nicely formated.)
But, as far as I understand from your description you are stumbeling on an implementation detail which somehow causes trouble for quite a few users. If I am right, this thread might be of some help.
Let us know what you are doing with Sonic Pi and post some code (as soon as you ready for it).
Thanks for the help! I didn’t bother posting code because I figured it was such a fundamental thing what I provided would be sufficient, and in fact it was. You nailed it with that link. Putting sync as part of the loop definition fixed the issue where it was every other; now it’s just the first time. I fixed that with a sleep 0.01 before the metronome loop.
I do have another question though: In that diagram, why does blue always come after red and miss the first beat? In my case, blue is either main or bass and red is metronome. I have metronome last, so why does it seem to run before the others the first time if I don’t have the sleep 0.01?
I am not entirely sure but right now my explanation is summarised in my later comment: A loop does only sync if it is not running. So actually, there is not such thing as permanent, reevaluated syncing while continuously running. That is why having the sync statemant as
parameter in the
live_loop :go, sync: :towhatever do # do something end
and not using the
live_loop :go do sync :towhatever # do something end
is a solution.
Does that help?
Right, I understand that it’s not a permanent thing. I still don’t fully understand the ordering issue, but it’s not really a problem, just a curiosity. Thank you!
I see… actually the order of the source code does not matter in this case. You are using
live_loop is a separate
thread they all will start at the same time once you evaluate the code and play independant of each other (except - of course - if they are bound to each other by
sync/cue). They will not start together if you use the param
delay or put
sleeps between them). In your case - I guess - the metronome loop will start playing, the others will wait for a sync signal (independant of the position in the source code).