fbpx
Skip to main content

MIDI Forum

Reordering simultan...
 
Notifications
Clear all

Reordering simultaneous events

7 Posts
5 Users
0 Reactions
9,807 Views
Malcolm
Posts: 9
Active Member
Topic starter
 

Hi there.

I'm developing some midi processing software, and it would suit me if I could put events in a track which occur simultaneously
(i.e. an events followed by events with zero time delta) in a canonical order. For example, I would like to move note off message before note on messages.

Are there any specifications or resources which consider this issue?

The concern I have is a situation where a note on event is followed by some event X followed by a note off event (not for the same note). Is there any scenario where the result would be different if I reorder these events?

Thanks for any advice and suggestions.

Malcolm

 
Posted : 04/09/2021 2:22 am
JohnG
Posts: 225
Estimable Member
 

An interesting question.

The answer to the first question, AFAIK, is no.
Certainly I've never seen in any of the specs anything that addresses the ordering of events in this way.
Nor have I ever seen any Sequencing software that does this, but then again, I haven't really looked.

As to processing note off events before note on, as far as I can surmise, the only time where it might matter is when the polyphony of the playback device is somewhat limited and the music features rather rapid play.

The only other scenario I can currently imagine is where a Program Change message has been inserted at the same delta time as a note on event, but that is very bad programming practice. PC's should occur a few milliseconds before a note on.

Any help?
JohnG.

 
Posted : 04/09/2021 3:01 am
Sema
 Sema
Posts: 180
Reputable Member
 

If the "Note Off" is for the same note as in the following "Note On", you can (and should) remove the "Note Off".
If they are for different notes, then the order does not matter.

 
Posted : 04/09/2021 8:42 am
Bavi_H
Posts: 266
Reputable Member
 

[quotePost id=10571]The concern I have is a situation where a note on event is followed by some event X followed by a note off event (not for the same note). Is there any scenario where the result would be different if I reorder these events?[/quotePost]
I can't immediately think of a situation that would cause a problem. But may I suggest you clearly document what your software is doing, and possibly add some option to disable the re-arrangement processing? If a person authoring a MIDI file really needs to send events in a certain order for some reason, it could be frustrating when the software they are using secretly rearranges things. However, I might be a little biased as a MIDI technical enthusiast, perhaps it's not needed for typical cases and typical users.

You only mentioned re-arranging events of a single track. But I observed a related effect when I was experimenting with putting notes of the same channel on different tracks (scroll down to "CHANNEL ON MULTIPLE TRACKS"). I inadvertently made a note start and note end for the same pitch and time on different tracks. One of the MIDI players I use cuts the new note that is starting off, presumably because it sends the note start then immediately sends the note end for the same pitch. But other MIDI players I use play the new note fine, and so I guess they must be re-arranging the note end to get sent before the new note start.

So those results I observed seem to imply that some MIDI software might have considered this kind of issue and decided to re-arrange note ends to get sent before note starts of the same tick, channel, and pitch.

[quotePost id=10576]If the "Note Off" is for the same note as in the following "Note On", you can (and should) remove the "Note Off".
If they are for different notes, then the order does not matter.[/quotePost]
Sema: You shouldn't remove the Note Off. In MIDI, it is important that every note start [Note On with non-zero velocity] should eventually be followed by a note end [Note Off or Note On with zero velocity] for the same pitch.

Some MIDI devices may treat another note start of the same pitch as cutting off the first note of that pitch. But some MIDI devices will add another note of the same pitch to what is already sounding. Because of that, the MIDI specs say you should always send a note ending message for every note starting message. In the MIDI 1.0 Detailed Specification, PDF page 67 (printed page A-4):

ASSIGNMENT OF NOTE ON/OFF COMMANDS

If an instrument receives two or more Note On messages with the same key number and MIDI channel, it must make a determination of how to handle the additional Note Ons. It is up to the receiver as to whether the same voice or another voice will be sounded, or if the messages will be ignored. The transmitter, however, must send a corresponding Note Off message for every Note On sent. If the transmitter were to send only one Note Off message, and if the receiver in fact assigned the two Note On messages to different voices, then one note would linger. Since there is no harm or negative side effect in sending redundant Note Off messages this is the recommended practice.

 
Posted : 04/09/2021 10:43 am
Mike Kent
Posts: 85
Trusted Member
 

Reordering of events can be problematic. It is not recommended.

Your specific example of a Note Off and a Note One can cause a problem, although not in all cases. Sometimes a synthesizer will use this order in a meaningful way. For example, in Mono Mode, many synthesizers will perform a legato transition if they receive a new Note On before receiving a Note Off for the previous note. Another example would be a sophisticated piano, such as those that use 3 key sensors, which might use that same order to signify when a key is returned only half way up then restruck such that the damper does not touch the string between hammer strikes. In either of those examples, switching the order of events changes the response of the receiver.

Mike.
MIDI Association, Technical Standards Board

Chair of MIDI 2.0 Working Group

 
Posted : 04/09/2021 11:16 am
Malcolm
Posts: 9
Active Member
Topic starter
 

Thanks for all the really useful replies! It sounds like the reordering is not safe, so I will live without it.

For the curious: my intention was to avoid false polyphony that might arise when a note on proceeds a simultaneous note off.

Thanks again,

Malcolm

 
Posted : 04/09/2021 12:32 pm
Bavi_H
Posts: 266
Reputable Member
 

Oh no, I think I was too harsh. I would say moving note ends before note starts that have the same tick time position is a good idea. It's just the technical part of me likes to know how the MIDI software I use is behaving under the hood. In rare cases of needing to troubleshoot something odd, there's lots of little things like this that can get changed around by software that you have to be aware of. But for this case (moving note ends before note starts at the same time), I don't know of any specific examples where this caused a problem or confusion. [EDIT: Oh, I just saw Mike's response, with some examples that might cause problems.]

By the way, I just did some tests by connecting MIDI player software I have on my computer to MIDI monitor software MIDI-OX using a virtual MIDI cable loopMIDI, then checking the message order shown in the MIDI-OX monitor window. It looks like about half of the MIDI players I have move note ends before note starts if they happen at the same time position in the MIDI file. So some other MIDI software developers have also considered this a good idea.

Rearranged note end before note start?

Yes:
Cakewalk by BandLab 2018.11
Notation Player 4.0.2

No:
Sekaiju 7.0
vanBasco's Karaoke Player 2.53
Windows Media Player 12.0.9600.19482

Download: re-arrange-test.zip

 
Posted : 04/09/2021 1:53 pm
Share: