Monophonic filtering using Scripter in Mainstage/Logic Pro

I was recently building a patch in Mainstage where I wanted both a string/pad as well as a bell sound that would accent the top note of each chord that I played. I looked around for a technique to only keep the top note in a chord for Mainstage, and came across this post; but unfortunately the linked site for the Polyphonic Filter was not accessible. But it pointed me towards the Scripter plugin.

The Scripter plugin in Mainstage/Logic Pro allows Javascript to handle the MIDI signal. Based on some examples from Apple, I created the following script, which keeps the top-most note in a chord and silences the lower notes. I put this script just on my bells channel strip, so the string/pad wouldn’t be affected.

The result was a little hit and miss in a live setting – it worked when I played ascending chord progressions, but was inconsistent when playing descending progressions, depending on when my fingers hit the keyboard. The script would be ok in a sequenced performance where you can specify the order of notes being played. I needed it in a live performance; I ended up not using the plugin, and just played the bells accent separately with my right hand and string/pad chords with my left hand.