serious refactoring of midi framework