added midi output and optimized playback