Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Tanjeff Moos <tanjeff@cccmz.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: How to identify Alsa eLements?
Date: Fri, 3 Jul 2020 09:34:20 +0900	[thread overview]
Message-ID: <20200703003420.GA349540@workstation> (raw)
In-Reply-To: <3e46d988-d2f7-b06d-76e8-c8def2e870d1@cccmz.de>

Hi,

On Thu, Jul 02, 2020 at 10:05:01PM +0200, Tanjeff Moos wrote:
> I'm programming a GUI for the mixer in my Focusrite Scarlett 6i6 interface.
> The Alsa driver supports that functionality, i.e. I can control the mixer
> using alsamixer, for example. Now I'm writing a Qt GUI for it.
> 
> I wonder how I can reliably identify a mixer control element (e.g. the
> master volume control). Each element has an ID (struct snd_ctl_elem_id),
> consisting of multiple elements:
> - numid (seems to change at each boot)
> - iface
> - device
> - subdevice
> - name (is always constant)
> - index
> The docs says I can identify an element by the combination of name and
> index.
> 
> My questions:
> 1) Are name and index enough to identify an element?

In ALSA control core, 'snd_ctl_find_id()' helper function[1] is used to
find control element set by the given information from userspace
application. You can see the algorithm supports two cases:

1. numid matching
2. the combination matching with:
  * iface
  * device
  * subdevice
  * name
  * index is within the range of set

As you know, the numid is not constant between every bootup since it's
assigned dynamically (see __snd_ctl_add_replace() helper function[2]).
Thus the way 2 is available in the case to hard-code in userspace
application.

> 2) How can I obtain the index? The name and numid are shown by 'amixer
>    contents', for example.

The amixer program uses 'snd_ctl_ascii_elem_id_get()' API in alsa-lib to
show identifier information. The API is programmed not to output the
index value if it equals to zero[3]. Potentially you can retrieve the
index value by a call of 'snd_ctl_elem_id_get_index()'.


Anyway, when using alsa-lib application for the purpose, you should pay
enough attention to which API is used since alsa-lib includes several
abstractions of API for control element set in each level:

 * Lower abstraction (snd_ctl_xxx)
 * Higher abstraction (snd_hctl_xxx)
 * Setup control interface (snd_sctl_xxx)
 * Mixer interface (snd_mixer_xxx)
   * Simple Mixer interface (snd_mixer_selem_xxx)

The configuration space of alsa-lib affects Setup control interface
and Mixer interface. On the other hand, it doesn't affect the
lower/higher abstraction. The amixer is a kind of application to use
'snd_hctl_xxx', 'snd_mixer_xxx', and 'snd_mixer_selem_xxx'.


When you'd like to communicate to kernel land implementation without any
effects of alsa-lib's configuration space. it's better to use the lower/higher
abstractions. As long as I've used, 'qashctl' in QasTools[4] is good GUI
application for this purpose. It's written with Qt5 and seems to be helpful
for your work in both of GUI programming and control elements handling.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/tree/sound/core/control.c#n653
[2] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/tree/sound/core/control.c#n338
[3] https://github.com/alsa-project/alsa-lib/blob/master/src/control/ctlparse.c#L110
[4] https://gitlab.com/sebholt/qastools


Regards

Takashi Sakamoto

  reply	other threads:[~2020-07-03  0:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 20:05 How to identify Alsa eLements? Tanjeff Moos
2020-07-03  0:34 ` Takashi Sakamoto [this message]
2020-07-03  0:48   ` Takashi Sakamoto
2020-07-03  6:16   ` Tanjeff Moos
2020-07-03  8:53     ` Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200703003420.GA349540@workstation \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=tanjeff@cccmz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox