Replace chip (PCB) in usb midi keyboard with arduino

The sketch I used when I've got the strange behavior is other than the one I originally posted about. This one uses demultiplexers like most of other project, so I just tried to make it work with no demiltiplexers code and got that.

So I am back to the project that suppose to be right the stuff that I need, cuz it's for the velocity matrix keyboard and for arduino mega. But it refuses to work. I actually bought the mega just because I've saw that project.