Syncing midi clock?

NiDBiLD

2016-02-26 01:00:12

Right now, I have a working translator receiving F8 midi clock from Studio One. It works fine and syncs correctly as long as my loop length is in sync with the beat. I am trying to build a pretty rudimentary step sequencer at the moment.

However, as soon as I make a loop that is somehow the wrong length, or as soon as I move the playhead inside the DAW manually, the timer falls out of sync.

The timer runs on a simple F8 00 00 00 message sent 24 times per beat.

I can also get ClockStop (FC 00 00 00) signals when stopping the playhead.

I can choose between getting either ClockContinue (FB 00 00 00) or ClockStart (FA 00 00 00) signals from S1, when pressing play.

When I place the playhead manually, S1 sends a F2 [?? ?? ??] SongPointer. However, this seems far to low-res to be of any use for me.

If I want to, I can get QuarterFrame (F1 ?? ?? 00) as well. However, they aren't synced to the tempo of the song, and seem to always send as frequently.

If the playhead has been stopped and then started again, S1 waits until an even beat to sync, and then sends ClockStart, before returning to sending MIDI clock. So resyncing is not a problem. I just null all the beat counter variables and whatever at ClockStop. When I press play, the clock waits nicely until the next bar, and then starts up again, in sync.

Problem comes when I use an uneven loop length inside the DAW. This tilts the beat off sync, in relation to the DAW timeline. If my loop is 4 bars 1 beat, the beat will syncopate backwards at a rate of one beat per loop, falling in sync again every fourth time.

Is there some way to know which beat the playhead is on at a given time? If my loop is uneven, can BMT somehow know that I just went from beat 2 directly to beat 1, effectively cutting 2 beats short (assuming 4/4)? Is there a way to ensure that the song position is taken into account in this manner? How is this kind of thing usually handled?

Oh, and at this point, I feel I need to say that I'm sorry for spamming up your forum with my incessant inquiries. If I'm a pest, please tell me and I'll try to figure it out on my own next time.

DvlsAdvct

2016-03-01 02:16:19

Seriously, don't worry. You aren't being a pest.

But the reality of this question is there is no "how it is usually done"

What you are looking to do is, mathematically, complicated. I have a feeling there aren't many people who have attempted it. Is it possible to figure out? Probably. It comes down to how you count beats. For example, you can assign a global variable to the 24 counts of F8, and then one to each segment of the beat (1/4, 1/8, etc) and THEN one to each beat in the count (1-4). You could use these variables to measure the current playhead, and the loop length, but it would be a challenge. It's definitely not going to be an easy process, though.

You can't really know what beat the playhead is on unless you are constantly counting. So, you could set a global variable to how many beats in the measure have elapsed, but if you move that in any way you'd need to account for it in the global variable. The exception to this is if there is a MIDI value that the software can send out to MT Pro.

You can, at least, get a sync on the downbeat, so if things do drive it can be dealt with relatively easily. Send over some ideas and let's see if we can't figure this out.