Adding midi message sequences together

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

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

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

Thanks

Any comments from the JUCE team here? thx

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

1 Like

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

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).

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.

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.

1 Like