PortMidi/portmidi

Using Pm_Write to send System Exclusive inserts extraneous zeros

Closed this issue · 5 comments

Hi Roger,

I've been doing some further testing of my Pharo Smalltalk binding to PortMidi.

I'm able to send regular multiple regular messages fine. However when I send a System Exclusive message such as:

#[16rF0 16r01 16r02 16r03 16rF7]

PortMidi is inserting extraneous zeros. I have tested this by sending to the receiveMidi utility. You can see the extra zero in the output below:

receiveMidi output:

system-exclusive hex 01 02 00 03 dec

"Strange errors on shut down...not sure what is causing this:"
CoreMIDI error: 419 - ffffffce
CoreMIDI error: 425 - ffffffce
CoreMIDI error: 433 - ffffffce
MIDI input port "Virtual Output" got disconnected, waiting.
CoreMIDI error: 398 - ffffffce

There seems to be a pattern with progressively longer messages:

system-exclusive hex 01 dec
system-exclusive hex 01 02 00 dec
system-exclusive hex 01 02 00 03 dec
system-exclusive hex 01 02 00 03 04 dec
system-exclusive hex 01 02 00 03 04 05 00 dec
system-exclusive hex 01 02 00 03 04 05 00 06 dec
system-exclusive hex 01 02 00 03 04 05 00 06 07 dec

I've put a trace in the midi_write_byte routine. The output shows it is inserting an extra zero:

trace output:

driver com.apple.AppleMIDIIACDriver
driver
driver
driver com.apple.AppleMIDIIACDriver
driver
driver
midi_out_open isIACdevice 0
***** midi_write_byte => 240
***** midi_write_byte => 1
***** midi_write_byte => 2
***** midi_write_byte => 0
***** midi_write_byte => 3
***** midi_write_byte => 247
add 240 to packet 0x137887e20 len 6 timestamp 16472691953188 @ 686362164755541 ns (host 16472691954134)

If I conduct the same test, but sending to MidiMonitor the messages appear as expect.

I've also tried padding the messages to the boundary, but that has no effect either.

I'm not actually using SysEx, but I'm planning on publishing the binding for others to use, so it would be good to get fixed, assuming my analysis is correct.

Please let me know if you need me to conduct any testing. It's on a M1 Mac Mini running Monterey.

I can't explain this behavior. Are you sending with Pm_WriteSysEx or Pm_Write?
Do the PortMidi tests work? Here are the tests (from pm_test/README.txt):
[I believe there's a mistake in the description in that the sysex program's l(oopback) test quits by itself after 100K bytes are sent.]
21. ./sysex [no latency]
[This requires either a hardware loopback (MIDI cable from OUT to IN
on interface) or a software loopback (macOS IAC bus or ALSA MIDI
Through Port)]

l [for loopback test]
Type output device number: >>0 [pick output device to loopback]
Latency in milliseconds: >>0
Type input device number: >>0 [pick input device for loopback]
[Program will run forever. After awhile, program will quit. You can read
the Cummulative bytes/sec value.]

  1. ./sysex [latency > 0]
    [This requires either a hardware loopback (MIDI cable from OUT to IN
    on interface) or a software loopback (macOS IAC bus or ALSA MIDI
    Through Port)]

l [for loopback test]
Type output device number: >>0 [pick output device to loopback]
Latency in milliseconds: >>100
Type input device number: >>0 [pick input device for loopback]
[Program will run forever. After awhile, quit with ^C. You can read
the Cummulative bytes/sec value; it is affected by latency.]

Closing this a problem is resolved as above.

Thanks Roger