In this bit
for (uint8_t voiceNumber = voice1; voiceNumber <= voice4; ++voiceNumber) {
allNotesOff(voiceNumber);
}
The synth may not have completed silencing all notes in voice1 before...
Couple of tips:-
void loop() {
// only check the analog inputs 50 times per second,
// to prevent a flood of MIDI messages
if (msec >= 20) {
msec = 0;
int n1 = analogRead(A1);
/*...
Old codger with advanced soldering iron skills.
Pretty much self-taught Electronics/Automotive/Computer Technician/Hacker/Re-Engineer.
Built an Analog Synth ~1978 pretty much from scratch and life being what it is - what you end up doing whilst being busy with other plans, shelved it.
Forced into isolation by challenging health issues, officially retired and looking for a "mental health" project, dug out the box of remains of the original Synth, caught the bug and currently have a clutch of Roland Synths and other goodies.
To any Hacker worth his salt, off-the-shelf kit don't always give you what you're looking for which is why I'm here...