MIDI Zero Velocity

ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

MIDI Zero Velocity

Post by ColinP »

You can also count Zero velocity Note On messages as either Note On or Note Off. e.g. I have seen many midi files that use Note On Velocity 0 to turn off notes, this is incorrect as it's relying on the device it's talking to honour velocity data (it may not be built to).
Hi, I just noticed the above on your MIDI Note on-off checker module page.

In fact all MIDI devices must respond to zero velocity Note On messages in exactly the same way as Note Off messages. In practice Note Off messages aren't used much because of a MIDI data compaction feature called "Running Status".

Running Status enables a single Note On status byte to be sent and then a long stream of just data bytes in note number/velocity pairs with zero velocity values causing notes to be turned off. This reduces the number of bytes required to transmit a string of note on/off messages by a third.
User avatar
PoohBear
Posts: 45
Joined: Mon Jul 13, 2020 2:06 pm

Re: MIDI Zero Velocity

Post by PoohBear »

ColinP wrote: Thu Oct 28, 2021 4:32 pm
In fact all MIDI devices must respond to zero velocity Note On messages in exactly the same way as Note Off messages.
In the real world this is not true as I have experienced this first hand.
ColinP wrote: Thu Oct 28, 2021 4:32 pm In practice Note Off messages aren't used much because of a MIDI data compaction feature called "Running Status".
All my hardware seams to be sending full Midi messages.. Also the vast majority of midi files I have looked at again are using full midi messages, Note Off..

So to me this is a classic case of "how it should be" to "how it actually is".
User avatar
PoohBear
Posts: 45
Joined: Mon Jul 13, 2020 2:06 pm

Re: MIDI Zero Velocity

Post by PoohBear »

Hmm, a thought has just occurred that a lot of midi editors (including the Java calls) have converted a lot of the data already so we are left with seeing fully formed midi messages, so I might crack open a few midi files with HexEditor to check..
ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

Re: MIDI Zero Velocity

Post by ColinP »

I'm not making this stuff up. It's in the official MIDI specification.
Running status is based on the fact that it is very common for a string of consecutive messages
to be of the same message type. For instance, when a chord is played on a keyboard, ten
successive Note On messages may be generated, followed by ten Note Off messages. When
running status is used, a status byte is sent for a message only when the message is not of the
same type as the last message sent on the same Channel. The status byte for subsequent
messages of the same type may be omitted (only the data bytes are sent for these subsequent
messages).

The effectiveness of running status can be enhanced by sending Note On messages with a
velocity of zero in place of Note Off messages.
In this case, long strings of Note On messages
will often occur. Changes in some of the MIDI controllers or movement of the pitch bend wheel
on a musical instrument can produce a staggering number of MIDI Channel voice messages,
and running status can also help a great deal in these instances.
If you have bought devices that don't treat note on with zero velocity as note off then they are faulty. If you contact the manufacturer there may be driver or firmware updates available that fix the bug otherwise you should be entitled to a refund.
ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

Re: MIDI Zero Velocity

Post by ColinP »

I think the very common misconception about this is a result of the mere existence of the note off message.

Why, if a note on message with a velocity of zero turns a note off should there be any need for a note off message?

The answer is that the clever guys at Sequential Circuits who invented MIDI figured that release velocity would be a cool thing to support. So they added a note off message with its own independent velocity value. Unfortunately few synth manufacturers have bothered to adopt release velocity modulation for reasons that baffle me.

This is all made clear in the note off section of the official MIDI specification...
MIDI provides two roughly equivalent means of turning off a note (voice). A note may be turned off either by sending a Note-Off message for the same note number and channel, or by sending a Note-On message for that note and channel with a velocity value of zero. The advantage to using "Note-On at zero velocity" is that it can avoid sending additional status bytes when Running Status is employed.

Due to this efficiency, sending Note-On messages with velocity values of zero is the most commonly used method. However, some keyboard instruments implement release velocity where a Note-Off code (8nH) accompanied by a "velocity off" byte is used. A receiver must be capable of recognizing either method of turning off a note, and should treat them identically.
User avatar
PoohBear
Posts: 45
Joined: Mon Jul 13, 2020 2:06 pm

Re: MIDI Zero Velocity

Post by PoohBear »

ColinP wrote: Sun Nov 07, 2021 1:38 pm I'm not making this stuff up. It's in the official MIDI specification.
I did not say you were making it up, I know it as I have read it myself but there is the real world..

ColinP wrote: Sun Nov 07, 2021 1:38 pm If you have bought devices that don't treat note on with zero velocity as note off then they are faulty. If you contact the manufacturer there may be driver or firmware updates available that fix the bug otherwise you should be entitled to a refund.
A lot of my equipment is over 30 years old so I doubt there will be any fixes or refunds :lol:
I do also have new software that is experiencing issues with Note On zero velocity but due to a few loops the midi goes through first I don't have time to debug all these processes however by converting a Note On Zero vel. to a Note Off Message fixes those issues..
ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

Re: MIDI Zero Velocity

Post by ColinP »

I've been giving this more thought and perhaps we can build a consensus opinion.

In my view a MIDI device should behave according to the MIDI spec. If it doesn't then it is by definition non-compliant and therefore faulty.

You referring to something that does comply with the spec as "incorrect" was what threw me.

It isn't incorrect to use or interpret a zero velocity in a note on message as a note off.

However, as you say in the "real world" you have encountered faulty devices - indeed my main objection to your language is that it potentially increases the likelihood that such faulty devices will be created in future.

I also think that running status is an important aspect of the MIDI standard because it helps reduce timing jitter (and to a lesser extent latency).
And the use of zero velocity note on being interpreted correctly as note off has a bearing on this.

But on closer analysis in most practical situations the zero velocity optimisation isn't very significant. Running status still reduces jitter and latency a hell of a lot even without it.

I was thinking that without the optimisation a typical note event would expand from four to six bytes - resulting in a 50% increase in jitter but this is just the worst case scenario. A more realistic scenario with say a chord stab is that only two extra bytes would be needed, as all the note ons would still be optimised by running status and then all the note offs would also be optimised.

And given that there are apparently some faulty devices out there that don't handle the MIDI protocol correctly then I can now see that on balance on the transmission side it makes sense to use note off messages as a safety precaution.

What is important though is that on the reception side zero velocity note on messages are treated as note off.

Also in reference to an earlier point you made, yes as far as I can determine running status is all concealed within drivers. Only full-sized messages are seen at the application programming level.
User avatar
PoohBear
Posts: 45
Joined: Mon Jul 13, 2020 2:06 pm

Re: MIDI Zero Velocity

Post by PoohBear »

I agree that the wording I used was not the best and I have updated it.

I disagree with your use of the word "faulty", if something is not compliant it does not make it faulty as it has been built that way, it just makes it Non-compliant.

I'm just about to release a video and touched very briefly on this, there are Midi Compatible and Midi Complaint devices and this is where holes appear, something being Compatible does not mean it has to be fully complaint and follow all the rules.. That is crap it happens but that is the real world..

It took me years to accept people taking about Midi software devices as to me Midi is a hardware spec for machines talking to each other, once in the computer you are no longer talking between 2 pieces of hardware but that is another story..

and just to touch on "indeed my main objection to your language is that it potentially increases the likelihood that such faulty devices will be created in future." it's been going on for decades it's not something new, if you look at a lot of tutorials out there, so many state that a Note On message needs a Note Off Message not a Note On Zero velocity.

I also thought this was an interesting comment from this site and I'm not trying to take it out of context, just that this is what's being taught.. (https://www.cs.cmu.edu/~music/cmsip/rea ... mmers.html)
"You can also use this MIDI RUNNING STATUS when you generate MIDI messages, but you should care about how the target synthesizer or software will receive it, to be sure it is well interpreted." **Note this site was picked at random from a search for write Midi**
ColinP
Posts: 939
Joined: Mon Aug 03, 2020 7:46 pm

Re: MIDI Zero Velocity

Post by ColinP »

I think we will have to agree to disagree.

For me if a device produces hanging notes when sent messages that are fully compliant with the MIDI Protocol then I'd describe that device as faulty.

Running Status is handled by the device driver so you'll get it whether you want it or not (unless you are writing a device driver rather than application programming). However zero velocity note on might not be automatically converted by the driver so it's important to handle it at the application level.

The MIDI spec is quite large and if one just does a quick glance at it then one might easily miss important details. Yes every time that note off is mentioned it doesn't say (and remember that zero velocity note on counts as note off), but it's made absolutely clear in the section about note off.
User avatar
PoohBear
Posts: 45
Joined: Mon Jul 13, 2020 2:06 pm

Re: MIDI Zero Velocity

Post by PoohBear »

I would agree that if a device produces hanging notes when sent the correct messages that are meant to be "Fully Compliant" I would also call that faulty but you used the words non compliant for faulty..

Anyway I ran some tests, I downloaded a large amount of midi files (142274)
717 were bad...
75,741 used Note On Zero Velocity out of 141,557 files, that figure did surprise me.

I thought I would have a look for midi files on my C drive that would have manly been installed via VST's etc.
number of files: 10408 (I have how many!!!! very small midi size over 80% < 1KB, the smallest being 34 bytes)
Bad files 65
Final result 219 Note On Zero Velocity files out of 10,343.. now this is % is what I thought I was going to see from the first test...
To be fair on the above finding as I stated a lot of these midi files have been installed along with VST's and it could be large number of the files have come from the same source so the first test would be where I base my findings on and not those.

So for me it's lot higher than I expected and for you a lot lower LOL...

I have only written one module which has a Midi in, on checking I did write it looking for Note On Zero and Note Off but for the released version I remarked out the Note On Zero, now off the top of my head I think I would have done that after seeing external (to VM) applications not respond to Note On Zero vel correctly.. one to think about for me...
Post Reply

Return to “PoohBear”