Menu

#1272 midiout not working correctly on ALSA

v0.47
open
None
5
2017-01-08
2016-10-16
No

This has been there forever, and affects all Linux systems when using ALSA MIDI devices.

sys_alsa_putmidibyte() in s_midi_alsa.c outputs individual bytes instead of complete MIDI messages. You can clearly see this, e.g., when sending a sysex message from Pd to an ALSA MIDI output and looking at the results in kmidimon. Instead of a proper sysex message you'll get a sequence of (malformed) single-byte messages.

You can't just output single bytes of a multi-byte MIDI message with snd_seq_event_output_direct(), this only works with single-byte (such as system realtime) messages. The proper way to do this, so that it works with any MIDI message, is to use snd_midi_event_encode_byte() and output the message when it's complete. The following fix is from the pd-l2ork repo, but it should apply cleanly on the current pure-data master branch:
https://github.com/pd-l2ork/pd/commit/9f5a265

Related

Bugs: #1272

Discussion

  • Albert Graef

    Albert Graef - 2016-10-16

    I'm attaching this as a patch against the current master.

     
  • Anonymous

    Anonymous - 2016-10-16

    Out of curiosity, is it not up to the receiving device to parse the received bytes in such a way that they form a coherent message? Or is there a "timeout" after which a sysex message is considered aborted ?I don't remember the latter from the specs, so I always assumed the former.

     

    Last edit: IOhannes m zmölnig 2016-10-16
    • Anonymous

      Anonymous - 2016-10-18

      AFAICT that's not the way ALSA works. I haven't really looked in the ALSA code, but it seems that assembling the MIDI messages has to be done using the corresponding sequencer API calls. There might be some drivers which handle this, but I never had this working properly when outputting sysex using either internal ALSA connections or external MIDI gear via a USB-MIDI device.

      All I can say is that the suggested patch seems to be the right way to do this (those API calls are there for a reason), and that it works for me with every MIDI equipment I tried it with.

       

      Last edit: IOhannes m zmölnig 2016-10-18
  • Albert Graef

    Albert Graef - 2016-10-16

    Attached a little test patch. Output from kmidimon without the patch:

    258669,538.8942,130:1,-,System exclusive,1,,f0
    258669,538.8984,130:1,-,System exclusive,1,,7e
    258669,538.9020,130:1,-,System exclusive,1,,7f
    258669,538.9057,130:1,-,System exclusive,1,,06
    258669,538.9098,130:1,-,System exclusive,1,,01
    258669,538.9141,130:1,-,System exclusive,1,,f7
    

    And with the patch:

    278162,579.5051,130:1,-,System exclusive,6,,f0 7e 7f 06 01 f7
    
     
  • Anonymous

    Anonymous - 2016-12-02

    In the case of external midi it does seem that the interface makes a difference. A MOTU Miditimepiece will send sysex from pd with no problem, either thru Mac USB or even the hacked, unsupported output only linux paralel port driver. Not so with one of the old flash-firmware-at-boot Midiman interfaces, which will not send sysex at all (but will recieve it).

     
  • Albert Graef

    Albert Graef - 2017-01-03

    Not so with one of the old flash-firmware-at-boot Midiman interfaces, which will not send sysex at all (but will recieve it).

    I can only repeat that it's not because of a shortcoming in the driver of these devices, it's just because the implementation of sys_alsa_putmidibyte() is simply wrong.

    Ok, I've posted the patch, I'm sure that it's the right way to resolve this issue. I also provided a test case which demonstrates the issue. That's all I can do.

     
    • Miller Puckette

      Miller Puckette - 2017-01-04

      Thanks - I grabbed it from pd-llorc and applied it (then saw that you had
      also stuck the patch in the bug report :)

      M

      On Tue, Jan 03, 2017 at 02:44:01PM +0000, Albert Graef wrote:

      Not so with one of the old flash-firmware-at-boot Midiman interfaces, which will not send sysex at all (but will recieve it).

      I can only repeat that it's not because of a shortcoming in the driver of these devices, it's just because the implementation of sys_alsa_putmidibyte() is simply wrong.

      Ok, I've posted the patch, I'm sure that it's the right way to resolve this issue. I also provided a test case which demonstrates the issue. That's all I can do.


      ** [bugs:#1272] midiout not working correctly on ALSA**

      Status: open
      Group: v0.47
      Created: Sun Oct 16, 2016 05:17 PM UTC by Albert Graef
      Last Updated: Fri Dec 02, 2016 05:14 AM UTC
      Owner: Miller Puckette

      This has been there forever, and affects all Linux systems when using ALSA MIDI devices.

      sys_alsa_putmidibyte() in s_midi_alsa.c outputs individual bytes instead of complete MIDI messages. You can clearly see this, e.g., when sending a sysex message from Pd to an ALSA MIDI output and looking at the results in kmidimon. Instead of a proper sysex message you'll get a sequence of (malformed) single-byte messages.

      You can't just output single bytes of a multi-byte MIDI message with snd_seq_event_output_direct(), this only works with single-byte (such as system realtime) messages. The proper way to do this, so that it works with any MIDI message, is to use snd_midi_event_encode_byte() and output the message when it's complete. The following fix is from the pd-l2ork repo, but it should apply cleanly on the current pure-data master branch:
      https://github.com/pd-l2ork/pd/commit/9f5a265


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/pure-data/bugs/1272/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #1272

  • Albert Graef

    Albert Graef - 2017-01-04

    Thanks, works great now. :)

    Now can we also get my other pet peeve fixed, the bendin issue? See #1262

     
  • Albert Graef

    Albert Graef - 2017-01-08

    Well, as the issue is fixed, maybe close it? (Can't find a way to do that myself, even though I reported the issue.)

     

Anonymous
Anonymous

Add attachments
Cancel