Time travel error ... you can't go backwards in time

I have a patch that is set to use_real_time on all the threads. It’s syncing to a lot of external midi in and generating a lot of midi out. I’m using the midi method to send some fast arpeggios and 32nds.

Every few minutes the patch stops and throws the (now dreaded) “time travel error”. This does not seem to happen when I set use_sched_ahead_time to something generous like a second.

Is this just a matter of the scheduler falling behind and something in the midi system is trying to do work in the past? Or does this suggest some other bug?

Anybody come up against this?

Hi there, which OS are you using?

Hi Sam

I’m using the latest sonic pi on a MacBook Pro with High Sierra. Midi is over usb to an old motu midi express xt.

I’m playing with some smaller patches, and trying to isolate the bug.

Could you try replacing calls to midi with calls to midi_note_on and midi_note_off and see if that also trips the issue. My assumption is that this will fix things.

I changed the code so that I call midi_note_on and then immediately time_warp that thread to when I need the corresponding midi_note_off and I haven’t had any time travel errors since. :slight_smile:

How interesting, especially as this is pretty much how midi is implemented itself:

__midi_send_timed_pc("/note_on", p, c, [n, vel])
time_warp sus - 0.01 do
  __midi_send_timed_pc("/note_off", p, c, [n, rel_vel])

The only difference could be the fudging of the note off time. I can’t currently 100% remember why this 0.01 is subtracted. I believe it is to handle code like this:

midi :e1, sustain: 0.1
sleep 0.1
midi :e2, sustain: 0.1

Where without the time fudge, there’s a race condition between the note off of :e1 and the note on of :e2 and the MIDI device can receive them in different orders across runs.

Could you add this time fudge into your code to see if it re-introduces the error?

I suspected that, so I think it’s a different bug. I’ll try to reproduce it again.

I’m not “pi-ing” right now, but if one accidentally sent a duration of 0.0 wouldn’t you get a time travel failure and a stuck note?