diwic / alsa-rs

Thin but safe ALSA wrappers for Rust
Apache License 2.0
139 stars 66 forks source link

Seq: CC events incorrectly formatted after sending SysEx #50

Closed kelytha closed 4 years ago

kelytha commented 4 years ago

When trying to work with external hardware, I have noticed a possible bug in the Seq implementation that caused some me some trouble. Basically what happens is that after sending a piece of SysEx data every CC message becomes malformed, with their status byte zeroed out.

The issue seems to "fix" itself after sending a note event, which is what I currently use as a work around, ending every SysEx message with a note sent to an unused channel.

An easy way to reproduce this is to run the following piece of code and connect it to a raw MIDI endpoint, such as amidi: https://gist.github.com/kelytha/24dfda03ab7eca203d34119a462e429c

The output looks like this on my end:

$ amidi -p virtual -d
90 08 7F  // Note on
   08 00  // Note off
B0 08 7F  // CC up
   08 00  // CC down
F0 00 21 09 15 00 4D 50 00 01 4D 01 F7 // SysEx
F0 00 21 09 15 00 4D 50 00 01 4D 00 F7 // SysEx
08  // ...
7F  // ... garbled CC
08  // ...
00  // ...
90 08 7F  // Note on
   08 00  // Note off
B0 08 7F  // Now CC looks good again!
   08 00
diwic commented 4 years ago

Hmm, so I tried to reproduce this but could not. The amidi -p virtual -d command receives no output. I also tried aseqdump which receives:

$ aseqdump -p 128:0
Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
128:0   Note on                 0, note 8, velocity 127
128:0   Note off                0, note 8
128:0   Control change          0, controller 8, value 127
128:0   Control change          0, controller 8, value 0
128:0   System exclusive           F0 00 21 09 15 00 4D 50 00 01 4D 01 F7
128:0   System exclusive           F0 00 21 09 15 00 4D 50 00 01 4D 00 F7
128:0   Control change          0, controller 8, value 127
128:0   Control change          0, controller 8, value 0
128:0   Note on                 0, note 8, velocity 127
128:0   Note off                0, note 8
128:0   Control change          0, controller 8, value 127
128:0   Control change          0, controller 8, value 0
  0:1   Port unsubscribed          128:0 -> 129:0

...which looks correct to me, so possibly the error is further down the stack, i e in the ALSA library or even the kernel?

kelytha commented 4 years ago

Yes, in aseqdump looks good on my end as well. But in Bitwig Studio or on a HW synth, the CC messages right after the SysEx are not recognized.

I will try to rewrite my test code in C to verify on which side the issue is.

kelytha commented 4 years ago

Also just realized, you may be not getting output from amidi because you need to use aconnect to connect the ports of the two processes together.

kelytha commented 4 years ago

I was able to reproduce the same issue in C code.