rewrite `processEvents` as `handle_midi`