Can't get a noteOff message to work

Hello,
I am trying to sent noteOn en noteOffs from a midi effect plugin that I am making. The basic idea is to translate a midi cc message into notes.
The noteOn works fine, but the noteOff doesn’t. Whatever I tried, nothing worked so far. Debugging shows that the noteOff is created and added to the buffer as is the noteOn. The noteOn works, but the noteOff does not (when running it in Logic). Here is the code:

First the function that creates the noteOff:

void StripToNotesAudioProcessor::SentNotesOff(juce::MidiBuffer& processedMidi, int exceptNote, int time)
{
    //loop through array for all notes
    for(int i=0;i<MAX_NOTES;i++)
    {
        //if note was pressed, the channel was set.
        if(notePressedChannel[i]>0 && i!=exceptNote)
        {
            auto message = juce::MidiMessage::noteOff(notePressedChannel[i],noteValues[i]);
            notePressedChannel[i]=-1;
            processedMidi.addEvent(message, time);
        }
    }
}

And here the function that calls the SentNotesOff function and creates the new noteOn:

void StripToNotesAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    // A pure MIDI plugin shouldn't be provided any audio data
    jassert (buffer.getNumChannels() == 0);

    // however we use the buffer to get timing information
    auto numSamples = buffer.getNumSamples();
    
    buffer.clear();

    //create a new buffer
    juce::MidiBuffer processedMidi;
    
    //loop through the incoming messages
    for(const auto metadata : midiMessages)
    {
        auto message = metadata.getMessage();
        auto time = metadata.samplePosition;
        // in case the message is a controller message of the specified controller number,
        // replace it with a noteOn message.
        if(message.isController() && message.getControllerNumber() == midiCC)
        {
            auto ccval = message.getControllerValue();
            auto channel = message.getChannel();
            for(int i=0 ; i < numberOfZones+1 ;i++)
            {
                if(ccval<1)
                {
                    //if ccval is 0, then stop any note from sounding
                    SentNotesOff(processedMidi,-1);
                    break;
                }
                //if ccval is in range according to spliValues array, start the note
                if(ccval < splitValues[i])
                {
                    //only do something if the same note is not already pressed
                    if(notePressedChannel[i] != channel)
                    {
                        //first send noteOff for previous note.
                        SentNotesOff(processedMidi, i, time);
                        //create new noteOn
                        message = juce::MidiMessage::noteOn(channel,
                                                            noteValues[i-1],
                                                            noteVelocity);
                        notePressedChannel[i] = channel;
                    }
                    //stop the loop as soon as a range was valid
                    break;
                }
            }
        }
        //add the noteOn event to the buffer
        processedMidi.addEvent(message,time);
    }
    //swap the original buffer with the new created one
    midiMessages.swapWith(processedMidi);
}

Is notePressedChannel a juceArray? If so then notePressedChannel[i] returns a copy of the element (not a reference like with std::vector). This would mean that when you do notePressedChannel[i] = channel, you’re not actually updating the array.

What is the target for the message? Alot of synths (hardware and soft) don’t actually respond to note offs, but to a note on with velocity of 0. Worth checking.

Thank you for your response. No, it is an array of ints.

Thank you. I added the note on with velocity 0 just to be sure. But it was not the cause.

Okay, this was just a stupid mistake. The note on was actually created wrong with noteValues[i-1]. So sending note off to noteValues[i] is of course not going to work.
I do not now what I was thinking when I typed i-1.

Sorry to have bothered you all and thank you for your responses.