Sending midi_stop when using Cmd/S

Hi all,

I’m using this code to sync Ableton Live to Sonic Pi :

live_loop :clock do
  use_bpm 135
  midi_start if tick == 0
  midi_clock beat
  sleep 1
end

When stopping the code Ableton looses sync, as it should.
But this causes some troubles.
I would like to send a midi_stop command when (or slightly before) stopping the code to run.
Is there a solution for that ?

1 Like

Hey @Bohrbug!

Could you expand a little on exactly what troubles are and what you’d like your code to do if it was working correctly?

Hi @samaaron !

When stopping the code to run, Ableton sends a notice that it has lost its sync, and that it is turning it’s external sync option off. So when working on code in Sonic Pi, and stopping the code to run, for some reason, you have to check the external sync button again in Ableton, after clicking the warning message, etc. A lot of actions just to be able to start/stop your loops in Sonic Pi and not have to start up the whole sync setting procedure each time. I assume, that if a midi_clock_stop message was send, before the midi_clock message drops out, Ableton would stop running and would not bother about the sync message not longer being present on the midi stream. When using midi_clock with external hardware sequencers, I even do not need the midi_start function for them to be in sync. But Ableton needs some more midi info than those machines to get start/stop/external-sync working properly.

OK, so what is the exact sequence of messages you’d like to send out when hitting M-r?

Would like to send midi_stop hitting M-s

Would you like the midi_stop to happen after all other messages have been sent?

It should be just before the midi-clock drops out because of stopping to run the code. So, it should be sending the midi-stop message just before M-s gets effective

Apologies, I’m still not 100% sure what you’re asking here.

Could you describe the precise order of messages you’d like to see happen?

When hitting M-s, there’s no midi message this action causes to be send out, right ?
I would like SP to send out midi_stop when hitting M-s

When hitting M-s, Sonic Pi will stop all running threads and also cancel all unsent MIDI messages. It doesn’t explicitly send any other messages out.

As an experiment, if you were to free up an empty buffer and put a MIDI stop call in it. Would it be a (very rough and ready) ‘solution’ to hit M-s, switch to your MIDI stop buffer and hit run? Is that the ordering of messages you’re looking to have happen?

2 Likes

This is another thing I’ve thought to ask for. The MIDI Transport Stop command and midi_all_notes_off when you stop SP. I have to turn off a microsequencer and stop stuck notes unless I hit stop at just the right time. The way I had thought about resolving it was to create a structure in a script that allows any arbitrary thing to happen as a one-shot when you hit stop, you could even code an outro into it or make it sleep 10 seconds so you can catch a long reverb or echo to the end.

I am at ADE Amsterdam, so not much time atm, sorry for delay in testing. Yes, that works. That’s exactly the ordering of messages I’m looking for to happen.

The " MIDI stop buffer" solution is exactly what I do to stop the Mad Music Machine singing away when I hit ‘stop’ :slight_smile:

So cool, I´m also using Ableton live in combination with Sonic Pi, this is exactly what I was looking for!

However, there is a typo:

should be:
midi_clock_beat