# updateMatchedPairs not doing what it's supposed to do?

**URL:** <https://forum.juce.com/t/updatematchedpairs-not-doing-what-its-supposed-to-do/54904>\
**Category:** General JUCE discussion\
**Created:** [February 7, 2023, 3:33pm UTC](https://forum.juce.com/t/updatematchedpairs-not-doing-what-its-supposed-to-do/54904 "2023-02-07T15:33:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [February 7, 2023, 3:33pm UTC](https://forum.juce.com/t/updatematchedpairs-not-doing-what-its-supposed-to-do/54904/1 "2023-02-07T15:33:34Z")

</div>

Hi everyone,

Perhaps I completely misunderstand the purpose of `MidiMessageSequence::updateMatchedPairs` but my assumption was that this function is supposed to “fix” note-on messages that do not have a matching note-off and therefore will cause a hanging note when played back in a sequencer.

I wrote this example piece of code below. After calling `updateMatchedPairs`, nothing really changes in the sequence object even though I expected it to either remove the note-on or append a note-off (both could be reasonable solutions for fixing a hanging note).

```auto
juce::MidiMessageSequence sequence;
sequence.addEvent(juce::MidiMessage::noteOn(1, 60, 1.0f), 0);
DBG(sequence.getNumEvents()); // 1
sequence.updateMatchedPairs();
DBG(sequence.getNumEvents()); // 1

```

Could anyone explain to me what is going on here?

Thank you very much,  
Jelle

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [February 7, 2023, 4:47pm UTC](https://forum.juce.com/t/updatematchedpairs-not-doing-what-its-supposed-to-do/54904/2 "2023-02-07T16:47:14Z")

</div>

No, but with only one event in your sequence, stepping into ‘updateMatchedPairs’ with the debugger should be simple, and the problem made obvious. 🤓

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [February 7, 2023, 5:01pm UTC](https://forum.juce.com/t/updatematchedpairs-not-doing-what-its-supposed-to-do/54904/3 "2023-02-07T17:01:26Z")

</div>

From the docs, it looks like the main purpose of `updateMatchedPairs` is to update `MidiEventHolder::noteOffObject` for each note-on event. Extra note-offs will only be inserted if there are two note-ons in a row on the same note + channel.
