Clean up calculate_pitch

Removed unnecessary checks for keyboard tracking with gross switch
statements. There's less repetition in this, so it's more flexible. It's
also easier to read.