# Adding midi message sequences together

**URL:** <https://forum.juce.com/t/adding-midi-message-sequences-together/67780>\
**Category:** General JUCE discussion\
**Created:** [December 11, 2025, 3:12pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780 "2025-12-11T15:12:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [December 11, 2025, 3:12pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/1 "2025-12-11T15:12:45Z")

</div>

Hi, so i have 2 midi sequences of the form:

Seq1  
0: Note On : 72(C), time: 192  
1: Note Off: 72(C), time: 216  
2: Note On : 76(E), time: 216  
3: Note Off: 76(E), time: 240

Seq2  
0: Note On : 76(E), time: 192  
1: Note Off: 76(E), time: 216  
2: Note On : 81(A), time: 216  
3: Note Off: 81(A), time: 240

All good. If i were to create .mid files from these and import them into a DAW everything is expected.

Now, if I add one sequence to the other using addSequence() I get the following:

combined  
0: Note On : 72(C), time: 192  
1: Note On : 76(E), time: 192  
2: Note Off: 72(C), time: 216  
3: Note Off: 76(E), time: 216

4: Note On : 76(E), time: 216  
5: Note Off: 76(E), time: 216  
6: Note On : 81(A), time: 216  
7: Note Off: 76(E), time: 240

here 4 and 5 create a very short note

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/4/9/49dba176e323729d55aff515945e2cf1a9c579e5.png)

If i shorten the length of each note by 1 then all is good but when loaded into a DAW, the notes don’t quite span correctly.

Seq1  
0: Note On : 72(C), time: 192  
1: Note Off: 72(C), time: 215  
2: Note On : 76(E), time: 216  
3: Note Off: 76(E), time: 239

Seq2  
0: Note On : 76(E), time: 192  
1: Note Off: 76(E), time: 215  
2: Note On : 81(A), time: 216  
3: Note Off: 81(A), time: 239

combined  
0: Note On : 72(C), time: 192  
1: Note On : 76(E), time: 192  
2: Note Off: 72(C), time: 215  
3: Note Off: 76(E), time: 215

4: Note On : 76(E), time: 216  
5: Note On : 81(A), time: 216  
6: Note Off: 76(E), time: 239  
7: Note Off: 81(A), time: 239

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/f/0/f027e0b56d6785ad2a0c28751c7ff6bc3d3fc3de.png)

Should the addSequence() deal with the first situation correctly? FYI, this is running on JUCE 7.

Thanks

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [December 16, 2025, 1:13pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/2 "2025-12-16T13:13:25Z")

</div>

Any comments from the JUCE team here? thx

---

<div class="post-metadata">

**Author:** ![oxxyyd](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@oxxyyd](https://forum.juce.com/u/oxxyyd)\
**Post date:** [December 16, 2025, 3:46pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/4 "2025-12-16T15:46:40Z")

</div>

Did you remember to call updateMatchedPairs() after addSequence()?

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [December 16, 2025, 4:03pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/5 "2025-12-16T16:03:18Z")

</div>

Hi, yes. I think the problem has already happened by then as there is an incorrect match when adding the sequence

---

<div class="post-metadata">

**Author:** ![oxxyyd](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@oxxyyd](https://forum.juce.com/u/oxxyyd)\
**Post date:** [December 16, 2025, 4:46pm UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/6 "2025-12-16T16:46:19Z")

</div>

Hmm, incorrect match between what? Any previous note-off matching is cleared before doing the new matching in updateMatchedPairs().

But this is of course only relevant if you add and play the two sequences in your own code. When exporting to a file, there’s no updated pairs in the file, only note-on and note-off events.

Where are your images coming from? Another daw or is it your own midi-player?

Edit:  
Beside that, you have 4 events in total with a timestamp of 216 in the two separate sequences, but 5 when combined. That looks wrong while addSequence shouldn’t change the timestamps. (Apart from adding an optional offset, but in that case that would affect all events alike).

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [December 17, 2025, 11:43am UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/7 "2025-12-17T11:43:35Z")

</div>

sorry, i was talking about the extra E note off at 216.

the images are from Ableton Live - i write out the contents of the combined MIDI to a file in each case then load that into Live.

---

<div class="post-metadata">

**Author:** ![oxxyyd](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@oxxyyd](https://forum.juce.com/u/oxxyyd)\
**Post date:** [December 18, 2025, 10:43am UTC](https://forum.juce.com/t/adding-midi-message-sequences-together/67780/8 "2025-12-18T10:43:50Z")

</div>

Try again without calling updateMatchedPairs(). That function is broken and inserts noteOffs at its own discretion. You don’t need that if your aim is just to merge to midi clips and save to file.
