Timing of exported MIDI

Hi Team,

First some background info: In one of my bands, we’re using an M-Live B.Beat machine to play some backing tracks and have click and cues in our In-Ears. I produce the stems in Ardour.

The B.Beat can also use MIDI files to pilot pedalboards, digital mixer, lights, etc …
We’re not using that today but my experimenting this capibility is the reason for this message :slight_smile:

The song has tempo defined with a tempo marker (93 bpm) and is perfectly in sync with the metronome.
I’ve created a MIDI track and a MIDI region that’s the duration of the song.
On that MIDI track, I’ve created a few MIDI CC events using the automation lanes and a couple of PCs too.
For the sake of testing, these are cleanly aligned on beat 1 of the measures.

Making the begining of the son the Time Origin, I can observe that the beat 1 of the measures (where my MIDI events occur) are:
Measure 1 : 0s
Measure 2 : 2.58s
Measure 3 : 5.161s
etc
image
image
image

So, next, I do a Stem Export of that channel for the Time Span of my song, which gives me a MIDI file that should be in sync with the exported audio stems.

Trying the MIDI file in the B.Beat machine, I was surprised that the MIDI events are not aligned properly with the beats …

So I opened the MIDI file in a decoder, which shows me (filtering only on the CC13 for simplicity):

0.000s | tick 0 | track 1 | ch 1 | Control Change CC 13 value 0
2.000s | tick 7680 | track 1 | ch 1 | Control Change CC 13 value 64
4.000s | tick 15360 | track 1 | ch 1 | Control Change CC 13 value 100
4.000s | tick 15360 | track 1 | Sequencer Specific (3 bytes)
4.000s | tick 15360 | track 1 | Sequencer Specific (3 bytes)
4.000s | tick 15360 | track 1 | Sequencer Specific (3 bytes)
6.000s | tick 23040 | track 1 | ch 1 | Control Change CC 13 value 127
8.000s | tick 30720 | track 1 | ch 1 | Control Change CC 13 value 30
18.000s | tick 69120 | track 1 | ch 1 | Control Change CC 13 value 70
18.000s | tick 69120 | track 1 | Sequencer Specific (3 bytes)
18.000s | tick 69120 | track 1 | Sequencer Specific (3 bytes)
18.000s | tick 69120 | track 1 | Sequencer Specific (3 bytes)
18.000s | tick 69120 | track 1 | End of Track

Timing is not what it should :face_with_diagonal_mouth:
It would be right if the tempo was 120 bpm.

Any thoughts ?
Is it linked to Ardour not exporting tempo maps ?

Out of curiosity, I imported my MIDI file in Qtractor, added my 93bpm tempo and re-exported.

Now the timing looks OK:

0.000s | tick 0 | track 1 | Track Name: “Africa_Automation”
0.000s | tick 0 | track 1 | Tempo 93.00 BPM (645161 us/qn)
0.000s | tick 0 | track 1 | Time Signature 4/4 (clocks 32, 32nds 4)
0.000s | tick 0 | track 1 | ch 1 | Control Change CC 13 value 0
2.581s | tick 3840 | track 1 | ch 1 | Control Change CC 13 value 64
5.161s | tick 7680 | track 1 | ch 1 | Control Change CC 13 value 100
7.742s | tick 11520 | track 1 | ch 1 | Control Change CC 13 value 127
10.323s | tick 15360 | track 1 | ch 1 | Control Change CC 13 value 30
18.065s | tick 26880 | track 1 | End of Track

So I guess I have my answer … Ardour not exporting the tempo in the MIDI file is the issue.
But at least I have a workaround.

I wonder if fixing up the exported MIDI file with that information is something that could be done with a lua script. I haven’t checked to see if there is a hook to automatically run a particular script on export, but maybe that would be a way to get the tempo line added to the file.