[LAD] send midi message

Pedro Lopez-Cabanillas pedro.lopez.cabanillas at gmail.com
Fri Jan 6 10:21:28 UTC 2012


On Friday 06 January 2012, you wrote:
> btw: is there a way to list available clients/ports from the api.
> I know that aconnect -i / -o does this, but is there a c/c++ function?
> 
> Dave

The functions are: snd_seq_query_next_client() and snd_seq_query_next_port(); 
you need to loop calling these functions while they return a correct answer. 
For instance, this is the relevant code in "aconnect.c" :

static void do_search_port(snd_seq_t *seq, int perm, action_func_t do_action)
{
      snd_seq_client_info_t *cinfo;
      snd_seq_port_info_t *pinfo;
      int count;

      snd_seq_client_info_alloca(&cinfo);
      snd_seq_port_info_alloca(&pinfo);
      snd_seq_client_info_set_client(cinfo, -1);
      while (snd_seq_query_next_client(seq, cinfo) >= 0) {
            /* reset query info */
            snd_seq_port_info_set_client(pinfo, 
snd_seq_client_info_get_client(cinfo));
            snd_seq_port_info_set_port(pinfo, -1);
            count = 0;
            while (snd_seq_query_next_port(seq, pinfo) >= 0) {
                  if (check_permission(pinfo, perm)) {
                        do_action(seq, cinfo, pinfo, count);
                        count++;
                  }
            }
      }
}

See: 
http://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=seq/aconnect/aconnect.c
I guess you already know the reference documentation site:
http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html

Just for comparison, a similar enumeration using Drumstick looks like this:

    QListIterator<PortInfo> it(m_Client->getAvailableOutputs());
    while(it.hasNext()) {
        PortInfo p = it.next();
        cout << p.getClientName() << ":" << p.getPort();
    }

See Drumstick's example "drumgrid":
http://drumstick.sourceforge.net/docs/drumgrid.cpp-example.html

Regards,
Pedro



More information about the Linux-audio-dev mailing list