Refactor midi read loop and include error checking
Fixes issue with zynaddsubfx
patch from Hans Petter Selasky