Moved midi event detection up into the event loop.