Csound Csound-dev Csound-tekno Search About

[Csnd] MIDI input question: "note off" messages

Date2019-11-08 01:35
FromDave Seidel
Subject[Csnd] MIDI input question: "note off" messages
I have been learning to use midiin (along with "massign 0,0") for a more direct handling of MIDI input. I've noticed that I only get "note on" messages (status 144) and never "note off" (status 128). Instead of "note off", I see another "note on" but with velocity of 0.

I've got logic to handle this fine, but I'd like to understand what's going on. I can verify (using aseqdump on Linux and MIDI-Ox on Win) that my input consists of note on and off messages, but Csound apparently translates the "note off" messages. Is this by design?

Thanks,
Dave
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-11-08 01:52
FromJoseph Hughes
SubjectRe: [Csnd] MIDI input question: "note off" messages
I ran into this recently and learned about it. The following is a thorough and clear description I found on an audio forum. I think this is likely what's going on:

"There's a thing in MIDI called "running status". Normally a MIDI message consists of a status byte (which always begins with the high order bit set to one: 1xxxxxxx), followed by 2 data bytes (which always have the high order bit set to zero: 0xxxxxxx).

The status byte is used to describe the type of message, there's one code for note-on, another for note-off, another for control change, etc...

Then the first data byte describes WHICH control or note has been changed. i.e. the CC# or the note #. Because we never use the high-bit, we get a range of 0 - 127.

And the second data byte describes the position of the control or the velocity of the note. Again we have a range of 0 - 127 (however for note velocities, zero is reserved to mean note off because...)

If a whole bunch of messages come through, all for the same status, MIDI has the ability to save a some bandwidth by leaving out the status byte. This is called "running status". And obvious use for it is when performing a control change, you can save 1/3 of the traffic on the MIDI cable by only sending the status byte at the beginning of the stream (note that this works only as long as the stream isn't interrupted by any other type of message status. As soon as another type of message comes through, the running status is broken).

And to take advantage of this for note data, a stream of note-ons and note-offs can be differentiated by the velocity value in the 2nd data byte, without needing to send a new status byte every time your performance switches from note-on to note-off.

So by the MIDI spec, you are required to treat a note-on with zero velocity exactly the same as you would a note-off."

Credit: AdmiralQuality on the kvraudio.com forums


On Thu, Nov 7, 2019 at 8:37 PM Dave Seidel <dave.seidel@gmail.com> wrote:
I have been learning to use midiin (along with "massign 0,0") for a more direct handling of MIDI input. I've noticed that I only get "note on" messages (status 144) and never "note off" (status 128). Instead of "note off", I see another "note on" but with velocity of 0.

I've got logic to handle this fine, but I'd like to understand what's going on. I can verify (using aseqdump on Linux and MIDI-Ox on Win) that my input consists of note on and off messages, but Csound apparently translates the "note off" messages. Is this by design?

Thanks,
Dave
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-11-08 01:55
FromDave Seidel
SubjectRe: [Csnd] MIDI input question: "note off" messages
Very interesting! Makes sense, but it doesn't explain why I see note-offs when I monitor MIDI using aseqdump or MIDI-Ox, but the same input looks different in Csound. Also in my case, I'm sending notes very slowly, sometimes seconds apart, and not sending any control or programs changes at all -- very sparse.

On Thu, Nov 7, 2019 at 8:53 PM Joseph Hughes <joehughesmail@gmail.com> wrote:
I ran into this recently and learned about it. The following is a thorough and clear description I found on an audio forum. I think this is likely what's going on:

"There's a thing in MIDI called "running status". Normally a MIDI message consists of a status byte (which always begins with the high order bit set to one: 1xxxxxxx), followed by 2 data bytes (which always have the high order bit set to zero: 0xxxxxxx).

The status byte is used to describe the type of message, there's one code for note-on, another for note-off, another for control change, etc...

Then the first data byte describes WHICH control or note has been changed. i.e. the CC# or the note #. Because we never use the high-bit, we get a range of 0 - 127.

And the second data byte describes the position of the control or the velocity of the note. Again we have a range of 0 - 127 (however for note velocities, zero is reserved to mean note off because...)

If a whole bunch of messages come through, all for the same status, MIDI has the ability to save a some bandwidth by leaving out the status byte. This is called "running status". And obvious use for it is when performing a control change, you can save 1/3 of the traffic on the MIDI cable by only sending the status byte at the beginning of the stream (note that this works only as long as the stream isn't interrupted by any other type of message status. As soon as another type of message comes through, the running status is broken).

And to take advantage of this for note data, a stream of note-ons and note-offs can be differentiated by the velocity value in the 2nd data byte, without needing to send a new status byte every time your performance switches from note-on to note-off.

So by the MIDI spec, you are required to treat a note-on with zero velocity exactly the same as you would a note-off."

Credit: AdmiralQuality on the kvraudio.com forums


On Thu, Nov 7, 2019 at 8:37 PM Dave Seidel <dave.seidel@gmail.com> wrote:
I have been learning to use midiin (along with "massign 0,0") for a more direct handling of MIDI input. I've noticed that I only get "note on" messages (status 144) and never "note off" (status 128). Instead of "note off", I see another "note on" but with velocity of 0.

I've got logic to handle this fine, but I'd like to understand what's going on. I can verify (using aseqdump on Linux and MIDI-Ox on Win) that my input consists of note on and off messages, but Csound apparently translates the "note off" messages. Is this by design?

Thanks,
Dave
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-11-08 02:50
FromPete Goodeve
SubjectRe: [Csnd] MIDI input question: "note off" messages
AttachmentsNone  

Date2019-11-08 03:20
FromPete Goodeve
SubjectRe: [Csnd] MIDI input question: "note off" messages
AttachmentsNone  

Date2019-11-08 03:45
FromPete Goodeve
SubjectRe: [Csnd] MIDI input question: "note off" messages
AttachmentsNone  None  OnOff.mid  

Date2019-11-08 03:58
FromDave Seidel
SubjectRe: [Csnd] MIDI input question: "note off" messages
Thanks, Pete, this is helpful. I will test my results again in this light tomorrow night.

On Thu, Nov 7, 2019 at 10:45 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
Hah! MAybe I see the problem!  Are you *sure* your source
is sending true note-offs?  If I send my K/B's note-on-0s
to aseqdump, it reports them as "Note off"!

The difference is, if it's a true 128 note-off it prints
the data2 value as well:

  129:0   Note off                0, note 60, velocity 64

If it's a note-on-0, you get no "velocity"

Is that perhaps your case?

I'll attach my test midi.

        -- Pete --


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-11-08 22:42
FromJacques
SubjectRe: [Csnd] MIDI input question: "note off" messages
Hello Dave,

I ran accross missing note off when dealing with General MIDI files generated by a sequencer. In General MIDI Channel 10 is reserved for percussive instruments, some software puts in note off, some does not. It’s a few years ago, I remember having the same problems when loading the midi files. I then found out that omitting note off in channel 10 is tolerated in General MIDI.

All the best,

Jacques

On 8 Nov 2019, at 01:35, Dave Seidel <dave.seidel@GMAIL.COM> wrote:

I have been learning to use midiin (along with "massign 0,0") for a more direct handling of MIDI input. I've noticed that I only get "note on" messages (status 144) and never "note off" (status 128). Instead of "note off", I see another "note on" but with velocity of 0.

I've got logic to handle this fine, but I'd like to understand what's going on. I can verify (using aseqdump on Linux and MIDI-Ox on Win) that my input consists of note on and off messages, but Csound apparently translates the "note off" messages. Is this by design?

Thanks,
Dave
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2019-11-09 21:21
FromPete Goodeve
SubjectRe: [Csnd] MIDI input question: "note off" messages
AttachmentsNone  

Date2019-11-09 21:33
FromDave Seidel
SubjectRe: [Csnd] MIDI input question: "note off" messages
Great tip, did not consider using "od"! Yes, I guess it's just the reality that most (or at least many) devices don't send note-offs. But that's fine -- my code is already dealing with this properly. Thanks for everyone's comments, I learned a few things.

By the way, the code I'm referring to is v3 of the Implication Organ, which I just updated today: https://github.com/DaveSeidel/music-src/tree/master/implication-organ

- Dave

On Sat, Nov 9, 2019 at 4:22 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
Hi,
I came across some other points while playing that might be of interest.

On Linux, I realized there's a simple way to see exactly what your device is sending:

   od -tu1 -An -w3 </dev/midi1

-- adjusted for whatever device you're using.
(unsigned decimal bytes, no address field, 3 bytes/line)

The output is neat, as long as you only send 3-byte messages.
Alternatively you could use '-w1' and see each byte as it's sent.

On the matter of "Running Status", I found that neither of my keyboards
ever sends it.  I guess it would be pretty pointless for the USB connection,
but my older serial-MIDI one doesn't either.

Thinking about "True Note Off" with its release velocity, I realized it might
be nice to have -- a light release could increase decay time ,  for instance --
so I did a bit of web walking to see if I could find which keyboard controllers
provide it.  Not all that many, it seems, according to the forum posts I found.

Kutzweils and some Rolands do, and a few others that I didn't recognize.
Some of them, though, seem to just have a fixed velocity, which wouldn't
gain you anything.  Most of the popular makes seem to stick to 'Note-on-0'.

        -- Pete --

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2019-11-10 23:36
FromDave Seidel
SubjectRe: [Csnd] MIDI input question: "note off" messages
Thanks again for the od tip, got it working using the appropriate device on my system, which is /dev/snd/midiC1D0. And as predicted, it is not sending note-offs at all, just note-ons with 127 or 0 velocity. Specifically, the first byte is either 144 (i.e.: 144+0 for the first channel) and 145 (i.e, 144+1 for the second channel). I am happy to be assured that Csound is correctly representing the input it sees! :-) Also great to have a method to see the uninterpreted data.

On Sat, Nov 9, 2019 at 4:22 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
Hi,
I came across some other points while playing that might be of interest.

On Linux, I realized there's a simple way to see exactly what your device is sending:

   od -tu1 -An -w3 </dev/midi1

-- adjusted for whatever device you're using.
(unsigned decimal bytes, no address field, 3 bytes/line)

The output is neat, as long as you only send 3-byte messages.
Alternatively you could use '-w1' and see each byte as it's sent.

On the matter of "Running Status", I found that neither of my keyboards
ever sends it.  I guess it would be pretty pointless for the USB connection,
but my older serial-MIDI one doesn't either.

Thinking about "True Note Off" with its release velocity, I realized it might
be nice to have -- a light release could increase decay time ,  for instance --
so I did a bit of web walking to see if I could find which keyboard controllers
provide it.  Not all that many, it seems, according to the forum posts I found.

Kutzweils and some Rolands do, and a few others that I didn't recognize.
Some of them, though, seem to just have a fixed velocity, which wouldn't
gain you anything.  Most of the popular makes seem to stick to 'Note-on-0'.

        -- Pete --

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


--
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here