Alternatively, you could use the Control Surface library, it'll filter the analog input for you, and it supports MIDI routing as well.

For example:

#include <Control_Surface.h> // Include the...