Hi, I am trying to implement this feature for a hardware synth. I decided to write notes and velocity into separate arrays - here could someone explain why I need to shift the note array -1 to have both of them in sync. This part of the patch works great.
Now imagine this scenario. On a 6 voice synth I hold for example 3 notes chord in the bottom and play monophonic lines on top, with the aftertouch effecting only the last top note. But as soon as I play two notes on top, than if I release last one of the top notes I want the previous one to take priority.
Here is the algorithm I am trying to achieve: if there is a noteoff message, go back in the array and compare stored notes to the noteoff number. If you find another noteoff message, store its number and go further back. This way it should be possible to to find the last note that you still hold and assign aftertouch to it. To ensure there wouldn’t be endless loop in case you release all note I added a counter object and it lets the algorithm run only 6 times (size of the arrays). Each new noteoff message resets the counter.
Right now the note numbers after a noteoff event either don’t come out at all or the result is wrong.
Can you see why the patch is faulty or maybe suggest a cleaner way to do this?
Here is a link to the patch