How do I put the bop-she-bop in the MIDI clock?

Okay now that I have a fancy sample-accurate metronome, what do I need to do in order to insert the ticks into the Juce MIDI message chain? So that plugins and external devices have access to the clock?

If I have an external device that sends a MIDI clock signal what do I put in my Juce app to receive the signal and synchronize to it?

Yeesh. Syncing to an external clock is hardcore. You’d have to look for all the MidiMessage::isQuarterFrame() stuff, but doing the maths is nasty. I had to do this for tracktion, and I remember it being pretty ugly.

Well how do I send a clock signal? do I just put the clock message at the proper sample locations in a MidiBuffer and pass it to AudioProcessor::processBlock() ?

Where’s the static MidiMessage member that returns a midi clock MidiMessage ? Or else, how do I construct a MidiMessage clock signal?

For syncing to an external clock, how do I receive the midi messages? Do I just attach a MidiInputCallback to the midi input device? They come into MidiBuffer?

I really can’t remember how all the midi clock stuff works - you’ll need to do some research on what the messages mean. But yes, they do just arrive like any other midi message.

Are there any plugins that provide diagnostics and debugging / visualization information about midi clock signals?

For plugins, it’s actually quite easy, since you’ll just create an AudioPlayhead (see AudioPlayhead class). For external devices, you have to send 0xf8 24x per quarter. I did this using a high-priority thread that gets told the times to send out the 0xF8’s by the Audio Thread and just sits there and does that (because the audio thread is the reference clock). This has to be extremely accurate. A further problem is that some devices like sync-boxes seem to only be able to sync if you send out the 0xF8’s in not to short distances - a problem that could arise would be that the user moves in time (forward) and you’d have to send a lot of 0xF8’s to move forward - so there you have to insert a wait distance for the 0xF8’s. Syncing to an external clock is actually a bit easier. Mind to take in account the latency of the soundcard for all your calculations - and make sure to check if the sync is right using some “tick” sounds to see if they match (tick sound of hardware midi instrument must match tick sound of metronome etc…). It takes a while to get it right! Even well known sequencers still have problems to perform well in this domain, I’ve made some research and comparisons.

I know it’s a zombie thread but what was the solution?