Beginner trouble with coding MIDI transpose function (actually more Arduino code

Im having trouble understanding how to solve this and I think its too complicated, have spent soon 3 days of trying to code this and im getting nowhere. It seems the code needs a whole rearrangement from start and I don't think its worth it