Search code examples
midialsa

MIDI with ALSA: how to detect subscription on a port


I would like to see/detect if something connects to my virtual midi port.

So I create a port:

 snd_seq_create_simple_port(handle, "my port",
        SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
        SND_SEQ_PORT_TYPE_MIDI_GENERIC);

Now before I start producing MIDI events on that port, I would like to know if someone connected/mapped that port (e.g. using aconnect or patchage or so).


Solution

  • Subscribe to 0:1 (SND_SEQ_CLIENT_SYSTEM:SND_SEQ_PORT_SYSTEM_ANNOUNCE) to receive events about subscriptions. See the output of aseqdump -p 0:1 for examples.

    Please note that it is possible to send events directly to a port without a subscription.