Multiplexer read problem/Midi controller


I'm trying to make a midi controller, as many other users here. After many attempts, i must ask you all here for help. My programing level is rather low. But I'm determined to finish the project and learn more. I'm using the code created by Notes and Voltes, with my own little changes to work with Arcore Midi on Arduino Pro Micro. This is working great. Midi messages are sent by usb without problem. Problem is with reading mux channels (74hc4051/74hc4067). Moving one potentiometer triggers several midi signals. Other potentiometers do nothing. If i manually switch S0 pin to high, then second potentiometer triggers all messages, and first is inactive. Maybe i messed up when converted to usb-midi. Originally code is written for Arduino UNO only. I believe that together we can find the cause of the problem:)

There are 3 files. Main project code, and two (cpp and h) library files.

I do not know whether to put the code content or attach files. What do you prefer?