This is the code for an apparatus to play a piano based on midi inputs. The whole system runs on a micro-controller running MicroPython.
This project was the main part of my MFA thesis project, Beep-Boopatronics, which you can take a look at here.
Here is a video of the device playing a John Cage composition, adapted for a chord organ
The MicroPython MIDI library used was this one here by @SpotlightKid.
The servos are controlled with this bit of kit by Adafruit.
The 3D printed parts can be found over at Thingiverse.
Yeah, so, it is probably not super easy to make your own version of this project, but I hope you can take what's needed, to that it will be useful as inspiration.