How to diagnose midi timing problems?

I’ve been having a play with feeding the midi back into Sonic Pi and using it to play notes. I think that there may be a potential problem here.
One thing that occurs to me is that you are not explicitly defining the length of the notes you are sending. If you do not then each note (time between midi on and midi off is 1 beat, and since you don’t explicltly set the tempo that will be 1 second. So you will have lots of notes stacking up.
I think you are driving percussive outputs which probably only need the note_on to trigger. have you tried setting a very small sustain value, less than the loop time which is 1.0/8? Does that make any difference?

I have now used the program below on both RPi and mac. Both have jitter in third decimal place. I think it improves if you reduce the sustain time of the midi note sent. I haven’t played the received note, just worked out the timing separations.

use_debug false
use_midi_logging false
use_cue_logging false
set :kill,false
#change the following port to suit your system
#here set for mac virtual port
#on RPi use midi through port
use_midi_defaults port: "iac_driver_sonic-pi",channel: 1
use_bpm 60
live_loop :msend do
  use_real_time
  midi :c4 #,sustain: 0.0625
  sleep 0.125
  stop if get(:kill)
end
t=0 #set initial time offset
live_loop :min do
  use_real_time
  n = sync "/midi*/note_on"
  puts (vt-t).round(3) #print delta time EDIT ADDED ROUNDING
  t=vt #missed out. put back in edit
end

at 10 do #run for seconds then stop
  set :kill,true
end

Look at the times in the log when run.
Compare with the sustain time uncommented.

1 Like