MIDI timestamps on macOS are broken

This is with tip of develop

The documentation of juce::MidiInputCallback::handleIncomingMidiMessage says

The message’s timestamp is set to a value equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the time when the message arrived

If I add some debugging code in handleIncomingMidiMessage

void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
{
    DBG(juce::Time::getMillisecondCounter() / 1000.0);
    DBG(message.getTimeStamp());

    messageCollector.addMessageToQueue (message);
}

I get the following results:

348542
2.26779e+13

They are off by a factor of 1 trillion.

Issue is this line here:

const auto juceTimeMillis = startTimeMillis + (1e6 * (double) timeConversions.hostTimeToNanos (elapsedTime));

it should be:

const auto juceTimeMillis = startTimeMillis + ((double) timeConversions.hostTimeToNanos (elapsedTime) / 1e6);

You should divide by 1e6 not multiply.

This is a show stopper for us, it has completely broken recording of MIDI.

3 Likes

std::chrono FTW

Where in the JUCE source code is that line? I was curious about it but couldn’t find it.

EDIT: LOL, should have switched to develop. :slight_smile:

They probably meant to write 1e-6 :slight_smile:

1 Like

Yes, let’s say that :slight_smile:

Thanks for the report, this bug is fixed on the develop branch:

1 Like