Distance Sensor to single MIDI note

The variables duration and distance are not the same thing. You never get to convert duration into distance, in fact I can't see anything that changes distance from the value given it in the initial deceleration.

How are you communicating with your MIDI device and what type of Arduino are you using? Once we know that we can advise on how to send a MIDI note.

You may want to read this before you proceed:-
how to get the best out of this forum
It tells you how to ask a question and what information you need to supply.