Code for MIDI alignment