Delay of Recorded Midi

In general my DAW is working fine. I can record audio, mix, render, etc.

I have found one issue, however. When I record midi, at the time of recording, I hear it in sync with the playback. But, when I stop recording, the midi has a delay of 1 to 3 beats depending on the speed of the computer. The new midi displays with this delay, and plays back with this delay! So, the visual representation and the playback matches. And the delay is consistent. In other words, all the notes are delayed by exactly the same amount. I can grab them in the editor, and slide them forward to where they are supposed to be, and then everything is fine.

And, I can import midi and it is shown and played back as expected.

As Best as I can tell, the code related to recording midi is internal to TrackionEngine. So, I am wondering, where does this delay come from, and how can I fix it?

You haven’t got anything set for MidiInputDevice::getManualAdjustmentMs have you?
Also, is this an attached physical MIDI device, like a MIDI keyboard, not recording MIDI from the output of another track (I fixed a bug relating to that last week).

I am not using MidiInputDevice::getManualAdjustments. Should I be using it?

Its a USB keyboard. And it is strange because notes played along with other tracks while recording midi are heard in time as expected, but once I hit stop, the notes are delayed by a constant amount. And the delay is both visible in the editor and audible on playback.

I fear this may be another example of my minimalist programming style. I do not include any code that is not necessary for basic functionality. As such, I may not be doing some initialization or setup for the midi device that may be required, such as the MidiInputDevice::getManualAdjustments. So, an additional question might be, how to properly initialize midi devices?

All I currently do is connect as below;

// example code
if (inputDevice->getInputDevice().getDeviceType() == te::InputDevice::physicalMidiDevice)
	inputDevice->setTargetTrack(*currentAudioTrack, 0, true);

Should I be doing more?

Does the “MidiRecordingDemo” example also suffer from this problem?

There is no grid in MidiRecordingDemo, and I can’t load a complete edit from my DAW.

All I can say is that the midi is recorded consistent with one track to the other. My DAW gives the same result.

I will do some more testing in my studio this evening.

By the way, and if this is help in narrowing this down, my development computer and my studio computer both show the delay or “offset” after the midi is recorded.

In both cases, on each computer the offset is consistent for each note, so that selecting all the notes and sliding them forward corrects the offset.

The only difference is that the studio computer is older and slower and the offset is larger. This suggests that adding the notes to the midi sequence is delayd by the processing speed.

I still feel like I am not doing something in the setup that is necessary to keep everything in sync.

Is there any initialization that needs to be done to make sure audio and midi are in sync?

Do you see this problem in Waveform? I’m wondering if there is something about your MIDI driver timing.
Also, are you on the tip of develop?

I will test with Waveform in the studio tonight. That is something I was going to do anyway.

If Waveform is OK, then we know it is something I am overlooking in initializing my DAW.

I will report back, when I know more.

And I forgot to say, I am using the most recent develop versions of both JUCE and TracktionEngine downloaded today.

Waveform records midi exactly as expected.

Additionally, if I open that Waveform edit in my DAW, it displays and plays back correctly.

So, there no doubt that there is a setting somewhere that I am missing when initializing my DAW. And, in this regard I noticed there is a setting in Waveform “Use Midi Driver for Midi timing”. Is that setting related to this issue? And, how do I go about settings it?


I do not use the Traction Engine, but from what you say it seems that when the real time incoming MIDI message is converted / printed to a clip, the timestamp gets wrong.
I would start putting breakpoints to follow the journey of an incoming message to see how its final timestamp is computed.
In theory, it should be able to get the current playhead time (sample accurate). So for it to work it needs to get that time as soon as the message is captured from the device.

Thanks. And, that is what is strange. Waveform uses TracktionEngine, and Waveform works fine on the same system. All I do is call the code that starts recording. Its basically the same call for audio or midi.

The thing that is probably missing is that I am not doing a setup step that is required for the midi to sync when recording. In all other respects my DAW works fine, and I can even play the files created by Waveform correctly in my DAW. It is only when specifically recording midi that there is any issue.

Since Waveform works, with the same TracktionEngine code, it has to be a missing setting somewhere in my code. So, I need @dave96, who is very familiar with the inner workings of Waveform, to guide me as to what to I am missing.

Sure, I’m just telling you that at some point in the Traktion code, messages are printed to a clip. And when it happens, a timestamp is assigned. By debugging and stepping into this, you could see where the delay comes from. Might be quicker that waiting for Dave to guess what’s wrong. Just my 2 cents :slight_smile:

I had issues with importing audio clips until I added


So, now I am wondering if the pitch and time have any affect on recording the midi?

I do not use any pitch or time effects, so, if they are an issue, how do I disable them for midi tracks?

Bump. I have not found a fix for this yet, and I will greatly apprciate any suggestions?

I am convinced it is caused by a setting that I am not aware of, but I need help to know what the setting might be? For example, in Waveform there is a setting called “Use Midi driver for Midi timing”. It is enabled on my systems and midi recording in Waveform is correct. If that setting could be the issue, how will I set that in my DAW?

Well the first thing to try would be to disable that setting on your Windows machines running Waveform and see if the timing is still ok? All that does is change the clock from the MIDI device to the system clock so really only affects timing in the ms range.

The reality is though that tracktion_engine and Waveform is over 500k lines of code and I can’t remember exactly what all of it does (decent estimates for knowing what every lines of code in a codebase does is about 20k so we’re orders of magnitude over that). If you’re building a DAW, you will have to get your hands dirty and be able to debug through the code base to some degree, even if it’s just to let me know what parts of the code are behaving suspiciously.

See EngineBehaviour::isMidiDriverUsedForIncommingMessageTiming(). Try returning false for that and see if anything changes. You can see where that’s called in PhysicalMidiInputDevice::handleIncomingMidiMessage

Greatly appreciated! I have been going through the code. But, it is slow going when trying to understand what each bit does and how they interact. Your suggestions are usually spot on, so I will did deeper into the code you mentioned.

Thanks again!

It looks like midiDevice->setManualAdjustmentMs() in tracktion_MidiInputDevice.cpp is the place to do the compensation for the recorded midi.

I can provide an empirically derived value to the method, but that value will be different from one system to another. So, what would be a way to derive this value in the code?