Global link_sync doesn't stop

I have played a bit with Ableton Link syncing. link_sync works perfectly except it doesn’t stop threads when the session stops if it’s called in the global scope.
If I set it inside a live_loop it also stops the loop, but in this case the loop triggers on the beat, instead of following its own sleep time.

Example, this live_loop is synchronized to the start of the Link session, and it follows its own timing, but it doesn’t stop when the Link session is stopped:

link_sync

live_loop :hi do
  midi :c4, channel: 1
  sleep 0.5
end

The following links the loop to the session start and stop, but it’s tied to the link beat, as if it was synced to a cue set on the beat:

live_loop :hi do
  link_sync
  midi :c4, channel: 1
  sleep 0.5
end

I can stop the threads with som.ething like in the following example, but I cannot “restart” the loop when
:continueplay is reset to true

link_sync
set :continueplay,true

live_loop :hi do
  midi :c4, channel: 1
  sleep 0.5
  stop unless get(:continueplay)
end

live_loop :startcue do
  sync "/link/start"
  set :continueplay,true
end

live_loop :stopcue do
  sync "/link/stop"
  set :continueplay,false
end

I hope the solution is not wrapping every loop in a conditional statement…

So, how to achieve a global Link start and stop :slight_smile: ?

Hi there,

I’m sorry but Sonic Pi doesn’t support a global stop other than hitting the stop button in the GUI.

Hi Sam,

I see, thanks. Is the behavior of live_sync inside the live_loop expected? I mean live_loop looping at the pace of the link beat, instead of following it’s own sleep time.

Hi @giohappy,

link_sync will only sync the current thread by waiting for the current session to be playing and if it already to then behave identically to link. Just to be clear - this behaviour is only for the current thread - the thread that calls it. Sonic Pi doesn’t have a global notion of time - each thread can have its own BPM or link its BPM to the Ableton Link network BPM.

Happy to answer any other questions or clarify anything else. There’s unfortunately not much else I’m aware of that behaves like Sonic Pi so it’s hard to make analogies :slight_smile:

Ok, thanks for clarfying it further.

I guess I still miss something though. What’s not clear to me is why linked threads loop at the beat. With beat and phase alignment threads could loop integer times faster or slower. How can I, for example, make my thread loop over one bar instead of one beat?

The unit of sleep time is beats. So if your bar contains 4 beats, you just need to sleep 4. If it’s 3 beats, you need to sleep 3.

That’s clear to me Sam. Probably I’m doing something wrong but whatever the value of the sleep time the midi out is triggered every bar (4 beats).

Here, for example, I set it to 2 but and the image shows the triggered notes

live_loop :hi do
  link_sync
  midi :c4, channel: 1
  sleep 2
end