Skip to contentSkip to conversation

Change alsamixer to show different views. Playback controls, or Capture controls.

PATCH In review James Courtier-Dutton 4 participants 10 messages Aug 27, 2004 – Aug 30, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Change alsamixer to show different views. Playback controls, or Capture controls.

I attach a diff file against ./alsa-utils/alsamixer/alsamixer.c

It causes alsamixer to display 2 different views of the mixer controls.
One view shows only the "Playback" controls, the other view shows only the "Capture" controls, with a hidden mode (Press F1, then Enter) to show the old method of all controls together.

Cheers

James

alsamixer.c renamed from alsamixer.c.org +104 -53
@@ -167,6 +167,8 @@
 /* --- views --- */
 enum {
   VIEW_CHANNELS,
+  VIEW_PLAYBACK,
+  VIEW_CAPTURE,
   VIEW_HELP,
   VIEW_PROCINFO
 };
@@ -177,7 +179,7 @@
 static int	 mixer_needs_resize = 0;
 static int	 mixer_minimize = 0;
 static int	 mixer_no_lrcorner = 0;
-static int	 mixer_view = VIEW_CHANNELS;
+static int	 mixer_view = VIEW_PLAYBACK;
 static int	 mixer_max_x = 0;
 static int	 mixer_max_y = 0;
 static int	 mixer_ofs_x = 0;
@@ -227,6 +229,7 @@
 
 /* split scontrols */
 static int	 mixer_n_elems = 0;
+static int	 mixer_n_view_elems = 0;
 static int	 mixer_n_vis_elems = 0;
 static int	 mixer_first_vis_elem = 0;
 static int	 mixer_focus_elem = 0;
@@ -254,6 +257,8 @@
  " Esc     exit alsamixer\n"
  " F1      show Help screen\n"
  " F2      show /proc info screen\n"
+ " F3      show Playback controls only\n"
+ " F4      show Capture controls only\n"
  " Return  return to main screen\n"
  " Space   toggle Capture facility\n"
  " Tab     toggle ExactMode\n"
@@ -545,7 +550,7 @@
 
   if (mixer_sid == NULL)
     return;
-  
+
   sid = (snd_mixer_selem_id_t *)(((char *)mixer_sid) + snd_mixer_selem_id_sizeof() * mixer_grpidx[elem_index]);
   elem = snd_mixer_find_selem(mixer_handle, sid);
   if (elem == NULL)
@@ -758,7 +763,7 @@
       vright = vleft;
     }
   }
-  
+
   if (type == MIXER_ELEM_CAPTURE && snd_mixer_selem_has_capture_volume(elem)) {
     long vmin, vmax;
     snd_mixer_selem_get_capture_volume_range(elem, &vmin, &vmax);
@@ -779,7 +784,21 @@
     if (xlen > 63)
       xlen = 63;
     mixer_dc (DC_PROMPT);
-    mvaddstr (3, 2, "Item: ");
+    mvaddstr (3, 2, "View: ");
+    mixer_dc (DC_TEXT);
+    switch (mixer_view) {
+    case VIEW_PLAYBACK:
+      mvaddstr (3, 8, "Playback");
+      break;
+    case VIEW_CAPTURE:
+      mvaddstr (3, 8, "Capture");
+      break;
+    default:
+      mvaddstr (3, 8, "All");
+      break;
+    }
+    mixer_dc (DC_PROMPT);
+    mvaddstr (4, 2, "Item: ");
     mixer_dc (DC_TEXT);
     string1[8] = 0;
     for (i = 0; i < 63; i++)
@@ -952,7 +971,6 @@
   static int o_y = 0;
   int i, x, y;
   
-  
   if (!mixer_cbar_get_pos (mixer_focus_elem, &x, &y))
     {
       if (mixer_focus_elem < mixer_first_vis_elem)
@@ -961,15 +979,15 @@
 	mixer_first_vis_elem = mixer_focus_elem - mixer_n_vis_elems + 1;
       mixer_cbar_get_pos (mixer_focus_elem, &x, &y);
     }
-  if (mixer_first_vis_elem + mixer_n_vis_elems >= mixer_n_elems) {
-     mixer_first_vis_elem = mixer_n_elems - mixer_n_vis_elems;
+  if (mixer_first_vis_elem + mixer_n_vis_elems >= mixer_n_view_elems) {
+     mixer_first_vis_elem = mixer_n_view_elems - mixer_n_vis_elems;
      if (mixer_first_vis_elem < 0)
        mixer_first_vis_elem = 0;
      mixer_cbar_get_pos (mixer_focus_elem, &x, &y);
   }
   mixer_write_cbar(mixer_focus_elem);
   for (i = 0; i < mixer_n_vis_elems; i++) {
-    if (i + mixer_first_vis_elem >= mixer_n_elems)
+    if (i + mixer_first_vis_elem >= mixer_n_view_elems)
       continue;
     mixer_update_cbar (i + mixer_first_vis_elem);
   }
@@ -1521,53 +1539,57 @@
     elem = snd_mixer_find_selem(mixer_handle, sid);
     if (elem == NULL)
       CHECK_ABORT (ERR_FCN, "snd_mixer_find_selem()", -EINVAL);
-    for (i = 0; i < MIXER_ELEM_CAPTURE; i++) {
-      int ok;
-      for (j = ok = 0; j < 2; j++) {
-	if (mixer_changed_state)
-	  goto __again;
-	if (snd_mixer_selem_has_playback_channel(elem, mixer_elem_chn[i][j]))
-	  ok++;
+    if ( (mixer_view == VIEW_PLAYBACK) || (mixer_view == VIEW_CHANNELS) ) {
+      for (i = 0; i < MIXER_ELEM_CAPTURE; i++) {
+        int ok;
+        for (j = ok = 0; j < 2; j++) {
+	  if (mixer_changed_state)
+	    goto __again;
+ 	  if (snd_mixer_selem_has_playback_channel(elem, mixer_elem_chn[i][j]))
+	    ok++;
+        }
+        if (ok) {
+	  sid = (snd_mixer_selem_id_t *)(((char *)mixer_sid) + snd_mixer_selem_id_sizeof() * idx);
+	  mixer_grpidx[elem_index] = idx;
+	  if (snd_mixer_selem_is_enumerated(elem)) {
+	    mixer_type[elem_index] = MIXER_ELEM_ENUM;
+	  } else {
+	    mixer_type[elem_index] = i;
+	    if (i == 0 && snd_mixer_selem_has_playback_switch(elem))
+	      mixer_type[elem_index] |= MIXER_ELEM_MUTE_SWITCH;
+	    if (snd_mixer_selem_has_playback_volume(elem))
+	      mixer_type[elem_index] |= MIXER_ELEM_HAS_VOLUME;
+	  }
+	  elem_index++;
+	  nelems_added++;
+	  if (elem_index >= mixer_n_elems)
+	    break;
+        }
       }
-      if (ok) {
-	sid = (snd_mixer_selem_id_t *)(((char *)mixer_sid) + snd_mixer_selem_id_sizeof() * idx);
-	mixer_grpidx[elem_index] = idx;
-	if (snd_mixer_selem_is_enumerated(elem)) {
-	  mixer_type[elem_index] = MIXER_ELEM_ENUM;
-	} else {
-	  mixer_type[elem_index] = i;
-	  if (i == 0 && snd_mixer_selem_has_playback_switch(elem))
-	    mixer_type[elem_index] |= MIXER_ELEM_MUTE_SWITCH;
-	  if (snd_mixer_selem_has_playback_volume(elem))
-	    mixer_type[elem_index] |= MIXER_ELEM_HAS_VOLUME;
-	  if (i == 0 && snd_mixer_selem_has_capture_switch(elem))
-	    mixer_type[elem_index] |= MIXER_ELEM_CAPTURE_SWITCH;
-	}
-	elem_index++;
-	nelems_added++;
-	if (elem_index >= mixer_n_elems)
+    }
+
+    if ( (mixer_view == VIEW_CAPTURE) || (mixer_view == VIEW_CHANNELS) ) {
+      if (snd_mixer_selem_has_capture_volume(elem) ||
+	  (nelems_added == 0 && snd_mixer_selem_has_capture_switch(elem))) {
+        mixer_grpidx[elem_index] = idx;
+        mixer_type[elem_index] = MIXER_ELEM_CAPTURE;
+        if (nelems_added == 0 && snd_mixer_selem_has_capture_switch(elem))
+	  mixer_type[elem_index] |= MIXER_ELEM_CAPTURE_SWITCH;
+        if (nelems_added)
+	  mixer_type[elem_index] |= MIXER_ELEM_CAPTURE_SUFFIX;
+        if (snd_mixer_selem_has_capture_volume(elem))
+	  mixer_type[elem_index] |= MIXER_ELEM_HAS_VOLUME;
+        elem_index++;
+        if (elem_index >= mixer_n_elems)
 	  break;
       }
     }
-    if (snd_mixer_selem_has_capture_volume(elem) ||
-	(nelems_added == 0 && snd_mixer_selem_has_capture_switch(elem))) {
-      mixer_grpidx[elem_index] = idx;
-      mixer_type[elem_index] = MIXER_ELEM_CAPTURE;
-      if (nelems_added == 0 && snd_mixer_selem_has_capture_switch(elem))
-	mixer_type[elem_index] |= MIXER_ELEM_CAPTURE_SWITCH;
-      if (nelems_added)
-	mixer_type[elem_index] |= MIXER_ELEM_CAPTURE_SUFFIX;
-      if (snd_mixer_selem_has_capture_volume(elem))
-	mixer_type[elem_index] |= MIXER_ELEM_HAS_VOLUME;
-      elem_index++;
-      if (elem_index >= mixer_n_elems)
-	break;
-    }
   }
 
+  mixer_n_view_elems = elem_index;
   mixer_focus_elem = 0;
   if (focus_type >= 0) {
-    for (elem_index = 0; elem_index < mixer_n_elems; elem_index++) {
+    for (elem_index = 0; elem_index < mixer_n_view_elems; elem_index++) {
       sid = (snd_mixer_selem_id_t *)(((char *)mixer_sid) + snd_mixer_selem_id_sizeof() * mixer_grpidx[elem_index]);
       if (!strcmp(snd_mixer_selem_id_get_name(focus_gid),
                   snd_mixer_selem_id_get_name(sid)) &&
@@ -1619,7 +1641,7 @@
 
   /* required allocations */
   mixer_n_vis_elems = (mixer_max_x - mixer_ofs_x * 2 + 1) / 9;
-  mixer_n_vis_elems = CLAMP (mixer_n_vis_elems, 1, mixer_n_elems);
+  mixer_n_vis_elems = CLAMP (mixer_n_vis_elems, 1, mixer_n_view_elems);
   mixer_extra_space = mixer_max_x - mixer_ofs_x * 2 + 1 - mixer_n_vis_elems * 9;
   mixer_extra_space = MAX (0, mixer_extra_space / (mixer_n_vis_elems + 1));
   if (MIXER_TEXT_Y + 10 < mixer_max_y)
@@ -1769,9 +1791,13 @@
       break;
     case 13:	/* Return */
     case 10:	/* NewLine */
-      if (mixer_view == VIEW_CHANNELS)
+      if (mixer_view == VIEW_CHANNELS) {
 	mixer_clear (FALSE);
-      mixer_view = VIEW_CHANNELS;
+      } else {
+        mixer_view = VIEW_CHANNELS;
+        mixer_changed_state=1;
+        mixer_reinit ();
+      } 
       key = 0;
       break;
     case 'h':
@@ -1785,6 +1811,26 @@
       mixer_view = VIEW_PROCINFO;
       key = 0;
       break;
+    case KEY_F (3):
+      if (mixer_view == VIEW_PLAYBACK) {
+	mixer_clear (FALSE);
+      } else {
+        mixer_view = VIEW_PLAYBACK;
+        mixer_changed_state=1;
+        mixer_reinit ();
+      } 
+      key = 0;
+      break;
+    case KEY_F (4):
+      if (mixer_view == VIEW_CAPTURE) {
+	mixer_clear (FALSE);
+      } else {
+        mixer_view = VIEW_CAPTURE;
+        mixer_changed_state=1;
+        mixer_reinit ();
+      } 
+      key = 0;
+      break;
     case '\014':
     case 'L':
     case 'l':
@@ -1855,7 +1901,10 @@
 	break;
       }
   
-  if (key && mixer_view == VIEW_CHANNELS)
+  if (key && 
+    ((mixer_view == VIEW_CHANNELS) ||
+    (mixer_view == VIEW_PLAYBACK) ||
+    (mixer_view == VIEW_CAPTURE)) )
     switch (key)
       {
       case KEY_RIGHT:
@@ -1955,7 +2004,7 @@
   if (old_view != mixer_view)
     mixer_clear (FALSE);
   
-  mixer_focus_elem = CLAMP (mixer_focus_elem, 0, mixer_n_elems - 1);
+  mixer_focus_elem = CLAMP (mixer_focus_elem, 0, mixer_n_view_elems - 1);
   
   return finished;
 }
@@ -2027,7 +2076,7 @@
   mixer_init ();
   mixer_reinit ();
   
-  if (mixer_n_elems == 0) {
+  if (mixer_n_view_elems == 0) {
     fprintf(stderr, "No mixer elems found\n");
     mixer_abort (ERR_NONE, "", 0);
   }
@@ -2060,6 +2109,8 @@
 	  switch (mixer_view)
 	    {
 	    case VIEW_CHANNELS:
+	    case VIEW_PLAYBACK:
+	    case VIEW_CAPTURE:
 	      mixer_update_cbars ();
 	      break;
 	    case VIEW_HELP:
#1 lore raw

At Fri, 27 Aug 2004 13:51:26 +0100,

Quoted 7 lines · James Courtier-Dutton

I attach a diff file against ./alsa-utils/alsamixer/alsamixer.c

It causes alsamixer to display 2 different views of the mixer controls. One view shows only the "Playback" controls, the other view shows only the "Capture" controls, with a hidden mode (Press F1, then Enter) to show the old method of all controls together.

Nice work, applied to cvs.

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#2 lore raw
Quoted 5 lines · Takashi Iwai

At Fri, 27 Aug 2004 13:51:26 +0100,

Quoted 2 lines · James Courtier-Dutton

I attach a diff file against ./alsa-utils/alsamixer/alsamixer.c

Quoted 9 lines
Quoted 2 lines

It causes alsamixer to display 2 different views of the mixer controls.
One view shows only the "Playback" controls, the other view shows only the "Capture" controls, with a hidden mode (Press F1, then Enter) to show the old method of all controls together.

Nice work, applied to cvs.

Takashi

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#3 lore raw

At Fri, 27 Aug 2004 17:42:41 +0100,

Quoted 16 lines · James Courtier-Dutton
Quoted 14 lines · Takashi Iwai

At Fri, 27 Aug 2004 13:51:26 +0100,

Quoted 6 lines · James Courtier-Dutton

I attach a diff file against ./alsa-utils/alsamixer/alsamixer.c

It causes alsamixer to display 2 different views of the mixer controls. One view shows only the "Playback" controls, the other view shows only the "Capture" controls, with a hidden mode (Press F1, then Enter) to show the old method of all controls together.

Nice work, applied to cvs.

Quoted 6 lines
Quoted 2 lines

Takashi

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

I don't mind it, but maybe it would be wiser to change alsa-lib simple.c to handle 'Mic Boost' as capture?

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#4 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 2 lines

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

What does the name have to be compatible with?
I.e. What program might break if we change this in ac97_codec.c ?

Quoted 8 lines

I don't mind it, but maybe it would be wiser to change alsa-lib simple.c to handle 'Mic Boost' as capture?

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#5 lore raw

At Fri, 27 Aug 2004 18:34:21 +0100,

Quoted 8 lines · James Courtier-Dutton
Quoted 6 lines · Takashi Iwai
Quoted 4 lines

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Quoted 5 lines
Quoted 2 lines

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

What does the name have to be compatible with?
I.e. What program might break if we change this in ac97_codec.c ?

Dunno. But, at least, when you run "alsactl restore", the status won't be restored.

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#6 lore raw
Quoted 10 lines · Takashi Iwai

At Fri, 27 Aug 2004 18:34:21 +0100,

Quoted 8 lines · James Courtier-Dutton
Quoted 6 lines · Takashi Iwai
Quoted 4 lines

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

What does the name have to be compatible with?
I.e. What program might break if we change this in ac97_codec.c ?

Dunno. But, at least, when you run "alsactl restore", the status won't be restored.

Is it possible to have alsactl restore ignore controls that it does not understand, leaving them set to the default value, rather than the entire alsactl restore failing if it encounters an error? I have been bitten by this a few times when upgrading ALSA.

Lee

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#8 lore raw
In reply to Takashi Iwai
Quoted 15 lines · Takashi Iwai

At Fri, 27 Aug 2004 18:34:21 +0100,

Quoted 10 lines · James Courtier-Dutton
Quoted 5 lines · Takashi Iwai
Quoted 1 line

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

What does the name have to be compatible with?
I.e. What program might break if we change this in ac97_codec.c ?

Quoted 7 lines

Dunno. But, at least, when you run "alsactl restore", the status won't be restored.

Takashi

Thats true, but from a purely conceptual point of view, I think the Mic Boost should be associated with Capture and not associated with Playback.

I attach a patch to do just that.

James

Index: alsa-driver/alsa-kernel/pci/ac97/ac97_codec.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/pci/ac97/ac97_codec.c,v retrieving revision 1.144

alsa-kernel/pci/ac97/ac97_codec.c +1 -1
diff -u -r1.144 ac97_codec.c
@@ -687,7 +687,7 @@
 static const snd_kcontrol_new_t snd_ac97_controls_mic[3] = {
 AC97_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1),
 AC97_SINGLE("Mic Playback Volume", AC97_MIC, 0, 15, 1),
-AC97_SINGLE("Mic Boost (+20dB)", AC97_MIC, 6, 1, 0)
+AC97_SINGLE("Mic Boost (+20dB) Capture Switch", AC97_MIC, 6, 1, 0)
 };
 
 static const snd_kcontrol_new_t snd_ac97_control_capture_src = {
#9 lore raw
In reply to Takashi Iwai
Quoted 2 lines · Takashi Iwai

I don't mind it, but maybe it would be wiser to change alsa-lib simple.c to handle 'Mic Boost' as capture?

Mic Boost is for both directions, isn't?

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

#7 lore raw
In reply to Lee Revell

At Fri, 27 Aug 2004 14:37:14 -0400,

Quoted 18 lines · Lee Revell
Quoted 16 lines · Takashi Iwai

At Fri, 27 Aug 2004 18:34:21 +0100,

Quoted 13 lines · James Courtier-Dutton
Quoted 8 lines · Takashi Iwai
Quoted 4 lines

I have a question. The "Mic Boost" seems to think it is a "Playback" control. What would be the best way to getting that to be a "Capture" control. Would simply editing it in ac97_codec.c be enough?

Hmm, when you change the control name itself, it breaks slightly compatibility with older version.

What does the name have to be compatible with?
I.e. What program might break if we change this in ac97_codec.c ?

Quoted 8 lines
Quoted 3 lines

Dunno. But, at least, when you run "alsactl restore", the status won't be restored.

Is it possible to have alsactl restore ignore controls that it does not understand, leaving them set to the default value, rather than the entire alsactl restore failing if it encounters an error? I have been bitten by this a few times when upgrading ALSA.

-F option does it although it still print warnings. alsasound init script already uses this option.

However, using a default value means the lost of information, of course :)

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click