I found only an example of the digital input of a note with constant vleocity and it works well:
Not that code I hope. Their is lots wrong with what you posted. Basically it uses pins 0&1 which should be left for the serial communications. You should be using the pinMode statement in the setup function to enable the internal pull ups.
Notes 7 to 24 are way too low for most MIDI sound generators, and you have no include statements to pull in the libiary.
And that is just for a start.