Friday, April 27, 2018

Designing a Polyphonic Music Keyboard Algorithm.


-->
After several weeks of development, I’m discovering quite how hard programming a polyphonic keyboard for Eurorack is!  There are several well-known algorithms for dealing with voice stealing, that is, when your system is 4 note polyphonic and someone presses 5 notes,  these can be dealt with buy top note priority, bottom note priority or last note priority (http://electronicmusic.wikia.com/wiki/Note_priority).  But a polyphonic keyboard for Eurorack produces some unique problems.

First of all, lets describe the problem, our controller has 4 voltage outputs coupled with 4 gates.  A simple algorithm will assign the first note pressed to the first output, the second note to the second and so on.  This works pretty well, but has a major problem, voice changing.    Suppose we press two keys,  a low C (C0) and a  high A (A3),  C0 will go to output 1 and A3 to output 2. If you now release C0, the A3 will change to output 0.  The problem is the patch connected to output 0 might be very different to the patch on output 1.  When the A3 moves from output 1 to output 0 the sound produced will be very different.

To solve this, the algorithm needs to make the notes stick to a output.  In this situation note A3 once assigned to output 1 will stick to it that output until it is released, other new notes are assigned to free outputs, if no notes are free the new note is ignored!  This works pretty well but introduces a new problem, it is impossible to play the keyboard in legato mode!

Suppose you press C0 and then A3.  You want to move the A3 to G3 smoothly so that A3 moves to G3 on output 1.  What happens with the “Sticky” algorithm is that G3 is assigned to output 2 because for a short while both A3 and G3 are pressed together:

Ouput
Key
Keys
Keys
Keys
0
C0
C0
C0
C0
1
A3
A3
2
G3
G3
3

The problem here is that the algorithm needs to distinguish between a new note being pressed and held and the player playing in legato mode.  The difference is in legato mode a new key is pressed and then an older one released within a certain time, so simply delay the new note for a short period of time to see if this new note is part of a legato mode. This of course does mean that adding the new note will be delayed slowing down the playing mode.

This is the current state of play, I’m experimenting with the delay and seeing what effect it has on the playability of the keyboard. I can’t help feeling there is a better way, let me know if you know of one !

The source code is at: