MultiChannelNoteTracker Sustain

I have an AU that doesn’t respond to sustain. So I created the following scriptlet. But it doesn’t behave as expected. Note off seems to behave backwards. I would simply assume that if I track a NoteOn, then a NoteOff came in for the same note, the MultiChannelNoteTracker would flag the note as a PendingNote and thus send a note off using the MultiChannelNoteTracker_StopAllPendingNotes() function. At the same time if I manually held notes during the time at which I release sustain, the notes in tracker would only release the notes for which it received a GotNoteOff.

The code:

var pedal : Boolean
var mt : MultiChannelNoteTracker

// Called automatically after script is loaded
    pedal = false
    MultiChannelNoteTracker_Clear(mt, 2)

//Called when a CC message is received
On ControlChangeEvent(c : ControlChangeMessage)
    // If we received a sustain control change event
    if GetCCNumber(c) == 64 then
        // If it is pressed down, then change the control toggle variable to true
        if GetCCValue(c) == 127 then
            pedal = true
        // If sustain is up, change control toggle to false, stop all remaining notes in the tracker and clean up the tracker
            pedal = false

// Process any received MIDI note information
On NoteEvent(m: NoteMessage)
    // If we received a MIDI note ON, send it to the scriptlet MIDI out and add to the tracker
    if IsNoteOn(m) then
        MultiChannelNoteTracker_GotNoteOn(mt, GetNoteNumber(m), GetChannel(m))

    // if we received a MIDI note OFF, and no sustain pedal is pressed, send it out and remove from the tracker
    if IsNoteOff(m) then
        MultiChannelNoteTracker_GotNoteOff(mt, GetNoteNumber(m), GetChannel(m))
        if !pedal then

The observed behavior:

Note On → Note Off with no sustain → Works
Note On → Add Sustain → Note Off → Release Sustain = Note Off not sent
Sustain On → Note On → Note Off → Release Sustain = Note Off not sent
Note On → Add Sustain → Release Sustain = Note Off sent even though I’m still holding the note down

What am I missing here?

Probably the way Note Trackers work. Also a sustain Scriptlet is not the easiest Scriptlet you could start with. Have a look here:

I hope it helps :wink: