MIDI Buffer overruns

I’m seeing these errors when I playback with Musescore/JACK/Ardour. Even when I hit transport rewind in Musescore I see the messages (although Musescore does send a lot of Notes Off/zero values at that time). It triggers when I hit play too in the exact same way. Maybe it’s just Musescore sending so many silly note offs on every freaking MIDI port/channel/controller, 100s of messages in an instance), that it overruns the jack MIDI buffers. I may be answering my own question here. I’ll leave the post in case others find it more useful. I might see if I can edit Musescore’s playback source code to get rid of this MIDI Panic “feature” at playback.

I had JACK with a 192 buffer, and I increased it to 1024 but it’s exactly the same error messages.
I do have a lot of MIDI Tracks that relay to a MIDI Buss. Would this create a problem because JACK creates MIDI buffers to match audio buffers, and I have more MIDI connections then I have audio connections?

2021-10-18T18:10:18 [ERROR]: JACK: JackMidiBuffer::ReserveEvent - the buffer does not have enough room to enqueue a 3 byte event
2021-10-18T18:10:18 [ERROR]: JACK: JackMidiBuffer::ReserveEvent - the buffer does not have enough room to enqueue a 3 byte event
2021-10-18T18:10:18 [ERROR]: JACK: JackMidiBuffer::ReserveEvent - the buffer does not have enough room to enqueue a 3 byte event
2021-10-18T18:10:19 [ERROR]: JACK: JackMidiBuffer::ReserveEvent - the buffer does not have enough room to enqueue a 3 byte event

MIDI buffer-size of JACK is different from the audio buffers.

jack1 has a -M --midi-bufsize option, while jack2 has fixed size MIDI buffers (IIRC 32kB).
Filling up 32kB in one process cycle will need a lot of data though.

In the past the issue came up with jack1 (which has a small MIDI buffersize by default) when sending MIDI panic messages (16 channels * 3 messages * 3 bytes/message) and merging data from many sources to a single destination port.

Looking through the musescore source code I think it sends essentially a MIDI panic on every MIDI port, MIDI channel, and on at least 5 different controller settings, and all with exact same timestamp. I’m not sure how many messages I’m getting, but I think it’s pretty huge. I can try capturing it all in the MIDI Tracer, but not sure of how to make sure I capture all MIDI messages in there.

edit: It’s probably better to fix this in musescore. It might take awhile, but I’m probably going to try and fix it there and recompile. It should at least try and not shove all the messages out all at once. Better to delay the transport for a second and not overload the buffers. Although musescore seems to do the same thing for loops and if the user taps on a single note, which is overkill.

Ardour does that as well at transport-stop (and region boundaries).

3 CC messages (all notes off, reset controllers, raise sustain-pedal) 3 bytes each for all 16 channels.

but even for 10 MIDI tracks going to a single bus that is only 1.4 kBytes.

perhaps with jack_midi_dump and then count lines with wc -l

Well, I have probably 20 MIDI Busses, and each buss probably has on average about 6 MIDI tracks routed to it. Should still be shy but not by much.

At transport-stop is probably OK. Does Ardour do it also at transport-start? That’s the main issue with musescore I think.
This is on windows, but I should be able to capture it to a file then use wc in linux.

I’ll probably pare the session down to just a couple of MIDI busses, and do some more testing and make sure I’m not doing something stupid.

I don’t see how to run jack_midi_dump.exe to see any midi data.
I tried launching a command window as Administrator, and then ran it, but it doesn’t show any messages and I see lots of data in MIDI Tracer. jack_midi_dump.exe --help says it defaults to “midi monitor” but I’m not sure what that refers to.

Also, while using the transport_start, I got a dialog error box that said something like “Memory POOL exceeded. Recompile program with increased size”. Something like that, it disappeared after a second and then Ardour crashed. It’s happened to me before.

Have you connected jack_midi_dump’s input port?

ie, launch jack_midi_dump.exe and then use ardour or qjackctl to connect rosegarden’s MIDI output to jack_midi_dump’s input.

Hmmm, I think you lost me. :slight_smile:

I’m in windows, and I have a script that launches jackd with all the config. Do I launch jack_midi_dump first, and then launch the script?

I don’t know what rosegarden’s MIDI output refers to. Sorry.

From my qjackctl map, I now see that jack_midi_dump DID create a midi input object. It was easily lost in the morass of stuff I have in jack. I see that I probably need to route all the 100 midi connections to it and I’m guessing it will probably output everything. Maybe I’ll just connect one, and then extrapolate. Thx!

Apparently it’s not so easy to redirect to a file in windows. It must be with only certain programs.
I did see some MIDI messages initially, but now when I try it, I just see this:

Error: Ringbuffer was full. skipping event

with an occasional MIDI:ReserveEvent. 3 byte event enqueue something something.

I did write a batch file to connect all the musescore ports to the midi monitor.
Maybe this will work for outputting?:
jack_midi_dump.exe 1> C:\temp\output.txt 2>&1

1 Like

Just a quick follow-up. Apparently Musescore sends a note off to all 128 possible notes on every MIDI port/channel. In addition there’s lots of controller data sent too.

Oh wow. that is insane.

If you were using a physical MIDI port with cable it takes about 2 seconds to transmit that!
(at 31.25kbaud it takes ~1m per 3 byte message, * 128 * 16)

Thanks for filing the musescore bug report.

So I actually dove into the musescore code and got rid of the flood of messages.
But I’m trying to see if normal All Notes Off message is being sent. If I understood you correctly, an ALL_NOTES_OFF message is sent on every MIDI channel normally, which looks there’s something in the MIDI spec for that.

I’m not very familiar with midi specifications. What kind of message should I expect to see in jack midi dump with a normal all notes off.
Here’s an example of what I see on some controller data:
0: b0 02 50 control change (channel 0): controller 2, value 80

Thanks.

 b0 7b 00 control change (channel  0): controller 123, value   0

A complete “panic” message consists of 3 messages for each channel and looks like

1023: b0 40 00 control change (channel  0): controller  64, value   0
1023: b0 7b 00 control change (channel  0): controller 123, value   0
1023: b0 79 00 control change (channel  0): controller 121, value   0
1023: b1 40 00 control change (channel  1): controller  64, value   0
1023: b1 7b 00 control change (channel  1): controller 123, value   0
1023: b1 79 00 control change (channel  1): controller 121, value   0
1023: b2 40 00 control change (channel  2): controller  64, value   0
1023: b2 7b 00 control change (channel  2): controller 123, value   0
1023: b2 79 00 control change (channel  2): controller 121, value   0
1023: b3 40 00 control change (channel  3): controller  64, value   0
1023: b3 7b 00 control change (channel  3): controller 123, value   0
1023: b3 79 00 control change (channel  3): controller 121, value   0
1023: b4 40 00 control change (channel  4): controller  64, value   0
1023: b4 7b 00 control change (channel  4): controller 123, value   0
1023: b4 79 00 control change (channel  4): controller 121, value   0
1023: b5 40 00 control change (channel  5): controller  64, value   0
1023: b5 7b 00 control change (channel  5): controller 123, value   0
1023: b5 79 00 control change (channel  5): controller 121, value   0
1023: b6 40 00 control change (channel  6): controller  64, value   0
1023: b6 7b 00 control change (channel  6): controller 123, value   0
1023: b6 79 00 control change (channel  6): controller 121, value   0
1023: b7 40 00 control change (channel  7): controller  64, value   0
1023: b7 7b 00 control change (channel  7): controller 123, value   0
1023: b7 79 00 control change (channel  7): controller 121, value   0
1023: b8 40 00 control change (channel  8): controller  64, value   0
1023: b8 7b 00 control change (channel  8): controller 123, value   0
1023: b8 79 00 control change (channel  8): controller 121, value   0
1023: b9 40 00 control change (channel  9): controller  64, value   0
1023: b9 7b 00 control change (channel  9): controller 123, value   0
1023: b9 79 00 control change (channel  9): controller 121, value   0
1023: ba 40 00 control change (channel 10): controller  64, value   0
1023: ba 7b 00 control change (channel 10): controller 123, value   0
1023: ba 79 00 control change (channel 10): controller 121, value   0
1023: bb 40 00 control change (channel 11): controller  64, value   0
1023: bb 7b 00 control change (channel 11): controller 123, value   0
1023: bb 79 00 control change (channel 11): controller 121, value   0
1023: bc 40 00 control change (channel 12): controller  64, value   0
1023: bc 7b 00 control change (channel 12): controller 123, value   0
1023: bc 79 00 control change (channel 12): controller 121, value   0
1023: bd 40 00 control change (channel 13): controller  64, value   0
1023: bd 7b 00 control change (channel 13): controller 123, value   0
1023: bd 79 00 control change (channel 13): controller 121, value   0
1023: be 40 00 control change (channel 14): controller  64, value   0
1023: be 7b 00 control change (channel 14): controller 123, value   0
1023: be 79 00 control change (channel 14): controller 121, value   0
1023: bf 40 00 control change (channel 15): controller  64, value   0
1023: bf 7b 00 control change (channel 15): controller 123, value   0
1023: bf 79 00 control change (channel 15): controller 121, value   0

Some C code to send it looks like

for (uint8_t channel = 0; channel < 16; ++channel) {
  uint8_t ev[3];
  ev[0] = 0xb0 | channel; // MIDI CC
  ev[2] = 0; // value is zero

  ev[1] = 0x40; // MIDI_CTL_SUSTAIN -> raise sustain pedal
  send_3_byte_midi_event (ev);

  ev[1] = 0x7B; // MIDI_CTL_ALL_NOTES_OFF
  send_3_byte_midi_event (ev);

  ev[1] = 0x79; // MIDI_CTL_RESET_CONTROLLERS
  send_3_byte_midi_event (ev);
}

That’s awesome! Very much appreciated. This will make the effort so much easier.

Does ardour’s “transport-start” include all note offs as well?
I think not, but I thought I’d check.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.