GP as MIDI Clock Master

This has been a topic for a while and there are some interesting threads on the matter, notably these Using GP as Midi Clock Master and MIDI clock questions - #8 by JeremyUnoMusic.

So I decided to have a go at improving the proposition of GP as clock master. Clearly the way to go is Ableton link for distribution, but when it comes to hardware MIDI is still king. The objective was to provide a MIDI clock output with Ableton Link so that it can be easily controlled via GP (or any other Ableton Link capable software).

@pianopaul did a patch for MAX that looked interesting. As i did not want to get the editor locked out after the trial, I looked at Pure Data , this was also mentioned in the thread above. It was free and open source. After a bit of digging I found Plug Data which is Pure Data in a VST wrapper, this looked perfect as it could be dropped into the wiring view. Unfortunately Plug Data does not work with external extensions like Pure Data . As I was going to use the Ableton Link extension in Pure Data, Plug Data was a non-starter.

As well as the clock, start and stop messages should be sent and it seemed like a good idea to send MIDI Active Sense when an Ableton link is present. This is the Pure Data patch (it is my first ever patch so may not be optimum) …


ableton-link-midi-slave.zip (633 Bytes) This has been updated see the solution.

The abl_link~ object connects to an existing Ableton Link peer if present. The tempo is extracted and converted to mS for the PD internal clock (metro). The clock divides the mS interval by 24 to get the timing for the MIDI clock. Each clock bang will then send MIDI Clock (F8). The run state from Ableton Link is converted to MIDI Start (FA) and MIDI Stop (FC) and finally when the number of peers is not zero MIDI Active Sense messages are sent.

So to get this working with any Ableton Link peer, first install the required version of Pure Data. The funky part about this is that is can be installed on any machine on the local LAN, it does not need to be on your GP machine. Once installed you will need to add the Ableton Link Extension. Click the Help / Find Externals Menu in Pure Data. Search for abl* this should find the extension. Select the extension and click the Install button.

Load the ableton-link-midi-slave patch into Pure Data and configure the MIDI and audio, under the Media Menu dropdown. I have turned off the audio channels (not required) and selected the MIDI output I want to use. For testing I used good old loopMIDI, but any MIDI port visible to the OS can be selected. Don’t forget to apply the settings.

image
If you now look at the output end of the MIDI cable (or virtual MIDI cable) you should now have a MIDI clock at 120BPM, this is the default clock for the abl_lnk~ object. Note that the Active Sense message is not in the trace.

Next start GP I am using an empty gig for this (no scripts). Then click the LINK button in the transport bar. If everything is working you will see a [1] in the link button this is the number of discovered peers.

Check the MIDI monitor and you should now have active sense messages in with the clock. These are sent every 250mS (the MIDI spec requires faster than 300mS).

If you have got this far, then adjusting the BPM in GP will change the MIDI clock out. This can be viewed in the Pure Data patch. So when setting the tempo in a rackspace or songs the PD MIDI slave will follow the changes.
image

This also works if you are setting the global tempo via a widget and the system actions block.

One final check is the GP Transport. Make sure that Sync Start/Stop with Ableton Link is enabled in the General Options tab, then clicking the Play button produces the following messages (clock and active sense filtered from the monitor).

Footnotes:

This produces a MIDI clock/sync stream and in its current form no additional MIDI data is in the stream. Additional data would need to be merged into the stream. It could easily be added to the Pure Data patch.

The Plug Data wrapper for Pure Data can include additional extensions but it must be recompiled to include the extensions, so could be made to work. However the libraries included by default in Plug Data may allow a plugin that uses the internal GP clock control, this would then allow a VST in GP to become a clock master. I have checked and you can get MIDI clocks thru GP MIDI Out blocks. Maybe another day…

6 Likes

Hi Spav, appreciate you working on this. I’m giving it a try but I keep getting this error in PD. Any ideas?

image

Yep, you need to install the abl_link~ extesion, look under Help / Find Externals in Pure Data. I will add some instructions into the post.

1 Like

Works well, pretty cool alternative for those that don’t have Ableton Live. I won’t use it just because I can’t be restricted to the grid/quantization of Ableton Link but awesome solution either way.

1 Like

This is just MIDI clock only and not restricted to the AL notion of grid and quantisation. The midi clock at the moment is free phase so +/- half of 1/24th of a beat. This can be refined as the information from AL includes phase information.

How would you go about aligning it to quantization?

Right, I get that but with Link being turned on within GP to make this work it causes GP itself to snap to the Link tempo “grid” (which is what it is supposed to do, it’s how Link was designed to work). In my use case I need to use the GP metronome and I can’t wait until Link hits beat one to finally start playing back the GP metronome, needs to be instantaneous for me. Make sense?

Beat phase information is available in the AL, so just need to lock the clock start with phase. I will add a lock to it when I get chance.

1 Like

Start the apps the other way round and the slave will snap to GP (clock phase excepted). If you can work with GP as it is now this app is just a slave. The order of starting was purely for the for flow of the description.

Still sticks to an “invisible” grid either way. That’s just the nature of Ableton Link, it’s supposed to work that way. It’s fine there’s nothing you can do about that specifically.

This version is now locking the MIDI clock phase to the AL beat. I have checked the output clock is synchronous with the beat count change from the abl_link~ object, within the bounds of MIDI clocks.

image
ableton-link-sync-midi-slave.zip (674 Bytes) This has been updated see the solution

2 Likes

What’s the jitter like? I had tried PD midi clock a long time ago, and it looked like the internal timers/callbacks weren’t that accurate. This was partly why I started looking into using a plugin, where the audio processing thread can be used for more accurate timing.

The jitter on the first file was ok. On the second file, it was all over the place.

Now I sync the clock on every beat it looks pretty good for overall timing, unfortunately MIDI is not a great way of keeping accurate time but as long as the tempo is not drifting I find jitter not an issue for live, when running sequencers. I will pour some clock data into a file and have a look.

Thinking about this, it think running the clock out of the MIDI hardware and putting a scope on it will be the best measurement.

The jitter you are seeing is the beat resync. The clock inside Pure Data’s metro object is running slow, I can see this in the scope trace. The reason the first one looked better is there was no resync on the beat., but this would eventually run out of sync. I will add a trim to the clock so that the internal object timing can be adjusted. excluding the resync the jitter looks good (as per the first version).

1 Like

So hopefully this is the final version but feel free to play. The last resync version was crude after a bit more getting used to Pure Data, I have refined the patch and provided a clean phase lock to the Ableton Link timing so the lock to beats is now synchronised every beat and the sub-beat drift is imperceptible. The internal timing of PD turned out to be very good.

ableton-link-sync2-midi-slave.zip (755 Bytes) This has been updated see posts below.

In addition I have done some jitter measurements. This is running on an old G4 Mac Pro that has not been optimised for any audio work as it is a development machine and has browser, anti-virus and screen savers running. I only have Roland USB 2.0 MIDI interfaces on this machine.

The scope trace is looking at the end of the MIDI cable. In the top trace ‘T’ in the top left, is the trigger point and the trigger is compound, so that it only triggers on clocks and not the active sense messages. To the left of the trigger are the partial triggers from active sense. In the magnified section, the lower trace, the dashed vertical line is exactly one MIDI clock from the trigger point (rising edge after start bit). To the left of the dashed line is previous clock late jitter and to the right is this clock late jitter. Up to 1mS of jitter can be accounted for in the USB driver interface. There will be some small amount of jitter from the USB-MIDI interface, but this will be very small. The remainder of the jitter comes from the OS. It is fairly consistant with just one oddity, all remaining jitter is <2.38mS @ 120 BPM. This trace was running for about 10 minutes and every clock is in this trace.

I found no difference between connected and unconnected AL peers.

Using pd -nogui -realtime ableton-link-sync2-midi-slave.pd from a command line (or shortcut) will start PD without a GUI, this improves performance. The MIDI port may also be specified on the command line with the option -midiaddoutdev “your midi device”

3 Likes

Great work. This clock is very stable.

2 Likes

Added a sync and safe bang to output Active Sense on the next MIDI clock, so clock is not held up. Active Sense scales so as the MIDI Clock traffic increases the number of Active Sense messages decreases, but remains within MIDI spec.
ableton-link-sync3-midi-slave.zip (890 Bytes)

1 Like

Hi, I wonder if I miss something. I tested the Pure Data script outside with LoopMidi, having LoopMidi out as the target for Pure Data and took a monitoring on the corresponding LM in-port. All fine, could see communication happening (Active Sense, as expected no Clock with no link established). In the next test I fired up GP, activated Link and could see that after pressing GPs play button a start clock signal was received. But: the monitoring showed no Clock Signal, only Active Sensing. Changing tempo in GP though changed the tempo shown in PD.
OK, maybe the clock signal is not monitored by the monitoring SW. So I changed the outport in PD, added a corresponding LoopMidi In in GP, connected Midi Monitor - nothing. Went to Rig Manager, gave ports an Alias and enabled the option to honour Midi Clock. Nothing. Went to the Rackspace properties, enabled the Midi Clock option - Nothing. Are there any other places in GP I have to look?

Thanks! Marcus

What are you trying to achieve? Isn’t the point of this that you don’t need to activate midi clock input in GP? Because all communication between GP and PD is handled by Ableton Link?