Search code examples
midilibalsa

How to list ALSA MIDI clients without reading `/proc/asound/seq/clients`?


Is there a known way to list existing MIDI clients using the ALSA API only, without reading the special file /proc/asound/seq/clients?

I searched the ALSA MIDI API reference, and could not find any match. I believe there must be a way to achieve this using the API, otherwise that's a lot surprising.


Solution

  • As shown in the source code of aplaymidi and similar tools, ALSA sequencer clients are enumerated with snd_seq_query_next_client():

    snd_seq_client_info_alloca(&cinfo);
    snd_seq_client_info_set_client(cinfo, -1);
    while (snd_seq_query_next_client(seq, cinfo) >= 0) {
        int client = snd_seq_client_info_get_client(cinfo);
        ...
    }