如何列出ALSA MIDI客户端而不读取“/proc/ sound/seq/clients”



是否有已知的方法来列出仅使用ALSA API的现有MIDI客户端,而不读取特殊文件/proc/asound/seq/clients ?

我搜索了ALSA MIDI API参考,没有找到任何匹配。我相信一定有一种方法可以使用API来实现这一点,否则这就太令人惊讶了。

aplaymidi和类似工具的源代码所示,使用snd_seq_query_next_client():

枚举ALSA测序器客户端。
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);
    ...
}

我可以弄清楚,最后:snd_seq_get_any_client_info获取关于第一个客户端的信息(至少应该有一个,系统一个)和snd_seq_query_next_client。得到下一个

下面是列出MIDI客户端的代码片段:

static void list_clients(void) {
   int count = 0;
   int status;
   snd_seq_client_info_t* info;
   snd_seq_client_info_alloca(&info);
   status = snd_seq_get_any_client_info(seq_handle, 0, info);
   while (status >= 0) {
      count += 1;
      int id = snd_seq_client_info_get_client(info);
      char const* name = snd_seq_client_info_get_name(info);
      int num_ports = snd_seq_client_info_get_num_ports(info);
      printf("Client “%s” #%i, with %i portsn", name, id, num_ports);
      status = snd_seq_query_next_client(seq_handle, info);
   }
   printf("Found %i clientsn", count);
}

代码段假设seq_handle在别处声明并初始化(用snd_seq_open初始化)。

snd_seq_get_any_client_info的调用中使用0作为客户端ID,是一个猜测:ALSA使用负数表示错误,所以我猜第一个有效的客户端ID是0。

最新更新