From alsa-devel-owner@alsa.jcu.cz  Sat Oct  3 09:30:22 1998
Received: from rdaneel.dyn.ml.org (res-1097.usc.edu [128.125.245.177])
	by marvin.jcu.cz (8.9.1a/8.9.1) with ESMTP id JAA04983
	for <alsa-devel@jcu.cz>; Sat, 3 Oct 1998 09:30:19 +0200
Received: from localhost (brion@localhost)
	by rdaneel.dyn.ml.org (8.8.7/8.8.7) with ESMTP id AAA18146;
	Sat, 3 Oct 1998 00:30:17 -0700
Date: Sat, 3 Oct 1998 00:30:16 -0700 (PDT)
From: Brion Vibber <brion@pobox.com>
To: "Christopher T. Lansdown" <lansdoct@screech.cs.alfred.edu>
cc: alsa-devel@jcu.cz
Subject: Re: XAmixer
In-Reply-To: <Pine.LNX.4.05.9810030223460.30563-100000@screech.cs.alfred.edu>
Message-ID: <Pine.LNX.4.03.9810022350290.18073-100000@rdaneel.dyn.ml.org>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list



On Sat, 3 Oct 1998, Christopher T. Lansdown wrote:

> hi,
> 	I fixed the link on the page.  I've updated my code to be more
> modularized, it will take less work to maintain (i.e. the code that
> handles user interaction doesn't need to be duplicated for each channel).
> The reason that I didn't code in the mono channels is that I didn't see them 
> anywhere in the docs.  If you could send me the appropriate SND_MIXER_* names,
>  I'll write it in.  The code has changed significantly, so I doubt a patch
> would work at the moment.  Thanks for offering, though.

From asound.h of alsa-driver-0.2.0-pre8:
#define SND_MIXER_ID_MONO               "Mono"
#define SND_MIXER_ID_MONO1              "Mono 1"
#define SND_MIXER_ID_MONO2              "Mono 2"

> 	The counter-intuitive volume settings are due to gtk, so far as I
> can tell.  I have posted to the gtk-app-devel-list, and am awaiting an
> answer.  I've played with things and looked around as much as I can tell,
> there's no way to get it to be otherwise, which I don't entirely believe.
> At least not yet... :-)

In the mean time it's a simple matter to invert the value... ie if you
have a range of 0-255 and have 64 you set the widget to 255-64=191. Then
when the widget gives you 200 you send 255-200=55 to the card.

> 	You are correct, the |-| button is a lock left\right.  The reason
> that it didn't work for you was that I didn't code it in. :-)

I suspected that was the case but it's worth checking... :)

>  The code is
> now there.  It locks both volume and muting.
> 	Please take a look at the program again, I've updated it on my web
> page, and tell me what you think now.

Great! The locking is working fine now.

As far as modularity... It's definately improved a bit having the channel 
info in its own struct, but one would still (in what I just downloaded 
at least) need to go through the entire source and add sections for:
checking for the presence of the channel, reading the volume, creating the
volume widget, and setting the volume for each new channel.

What I'm thinking of would be something more like this:

...
struct _Card
{
  int number; /* The card's number */
  void *handle; /* The handle for the card */
  snd_mixer_info_t info; /* The info for the card */
  Channel *channels;
}

...
char *MixerChannels[] = {
  SND_MIXER_ID_MASTER,
  ...,
  SND_MIXER_ID_AUXB,
  NULL
};
...

...
int init_cards()
{
  /* Begin variable declarations */
...
  int i, j;
...
  /* Get the numbers of the channels */
  for(i = 0; i < cards; i++) {
    /* Count channels & allocate card[i].channels to n*sizeof(Channel) */
    for(j = 0; MixerChannels[j]; j++) {
          card[i].channels[j].num = snd_mixer_channel(card[i].handle, 
					   MixerChannels[j];
...

It would be fairly trivial with this in place to roll the many similar
bits into loops, and adding support for a new channel would be as simple
as adding it to the list and recompiling. Since the IDs are strings you
can use them for the labels on the widgets too, or you could have a
parallel array with localized names.

If you're really adventurous you could use autoconf or something and
generate the list of channels from <include/asound.h>... Is there a way to
query the device for any channels it supports? That would save a little
more trouble and make the same binary work with any new channels that come
into being without recompiling. I haven't looked at the docs yet so I'm
not sure... I probably should some time so I have a better idea what I'm
doing. :)

-- brion vibber (brion@pobox.com)


