Skip to contentSkip to conversation

amixer and special 'front...' channels

PATCH Elimar Riesebieter 2 participants 2 messages Jul 7, 2007 – Jul 9, 2007 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

This isn't Ubuntu/Debian specific and should be applied upstream?

On Sat, 07 Jul 2007 the mental interface of
David Decotigny told:

Quoted 115 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Imagine you have this kind of control:

Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Mic'

... and you want to set it to 'Front Mic':

shell> amixer sset 'Input Source' 'Front Mic'
Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Mic'

This does not work ! Because amixer will think that 'Front' is a modifier for 'Mic'.

Attached is a patch against alsa-utils-1.0.13-1ubuntu5 that solves this. With this patch, one can bypass the modifier parsing: one simply escapes the parameter with one or more backslash(es), and that's all:

shell> amixer sset 'Input Source' '\Front Mic'
Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Front Mic'

What this patch also does, is that it adds correct identification of items. With the original version, given the following enumeration:
foo foobar
Then the parameter 'foobar' will be identified as 'foo', not 'foobar'. The patch should solve this potential problem (not tested though).

Bye,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGj/X0ld7vhusVrCERAjIZAJ9w9GLD+QBwDCaTs32hpW6i9nVMfgCfdS5w jhipZ2jm87fq4zx4f5Q9Vsc=
=M2KP
-----END PGP SIGNATURE-----

diff -ru alsa-utils-1.0.13/amixer/amixer.1 alsa-utils-1.0.13-mine/amixer/amixer.1

amixer/amixer.1 +8 -5
@@ -44,11 +44,14 @@
 The parameters \fIcap, nocap, mute, unmute, toggle\fP are used to
 change capture (recording) and muting for the group specified.
 
-The optional modifiers can be put as extra parameters to specify
-the stream direction or channels to apply.
-The modifiers \fIplayback\fP and \fIcapture\fP specify the stream,
-and the modifiers \fIfront, rear, center, woofer\fP are used to specify
-channels to be changed. 
+The optional modifiers can be put as extra parameters to specify the
+stream direction or channels to apply.  The modifiers \fIplayback\fP
+and \fIcapture\fP specify the stream, and the modifiers \fIfront,
+rear, center, woofer\fP are used to specify channels to be changed. If
+there is a confusion between the parameter and these modifiers, then
+any character in the parameter may be escaped with a backslash to
+disambiguate: '\\Front Mic' will be understood as "parameter 'Front
+Mic'", and not as "modifier 'Front' applied to 'Mic' parameter".
 
 A simple mixer control must be specified. Only one device can be controlled
 at a time.

diff -ru alsa-utils-1.0.13/amixer/amixer.c alsa-utils-1.0.13-mine/amixer/amixer.c

amixer/amixer.c +12 -1
@@ -1333,6 +1333,16 @@
 	return def;
 }
 
+/** Transform '\a\b c \de' into 'ab c de' */
+static void unescape(char * arg)
+{
+  char * c;
+  for (c = arg ; arg && *arg ; arg ++)
+    if (*arg != '\\')
+      *(c++) = *arg;
+  *c = '\0';
+}
+
 static int get_enum_item_index(snd_mixer_elem_t *elem, char **ptrp)
 {
 	char *ptr = *ptrp;
@@ -1347,7 +1357,7 @@
 		if (snd_mixer_selem_get_enum_item_name(elem, i, sizeof(name)-1, name) < 0)
 			continue;
 		len = strlen(name);
-		if (! strncmp(name, ptr, len)) {
+		if (!strncmp(name, ptr, len) && (ptr[len] == '\0')) {
 			if (! ptr[len] || ptr[len] == ',' || ptr[len] == '\n') {
 				ptr += len;
 				*ptrp = ptr;
@@ -1428,6 +1438,7 @@
 		dir = dir_mask(&ptr, dir);
 		if (*ptr == '\0')
 			continue;
+		unescape(ptr);
 		multi = (strchr(ptr, ',') != NULL);
 		optr = ptr;
 		for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {

_______________________________________________
Pkg-alsa-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/pkg-alsa-devel

Signature · 3 lines
  "Talking much about oneself can also 
   be a means to conceal oneself."
         -Friedrich Nietzsche

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw

At Sun, 8 Jul 2007 00:19:25 +0200,

Quoted 3 lines · Elimar Riesebieter

This isn't Ubuntu/Debian specific and should be applied upstream?

Sorry, no, it's too hackish.

There is no reason to parse the channel for enum items. It should be passed simply as it is. I'll fix (and clean up the mess) later...

Takashi

Quoted 124 lines

On Sat, 07 Jul 2007 the mental interface of
David Decotigny told:

Quoted 115 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Imagine you have this kind of control:

Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Mic'

... and you want to set it to 'Front Mic':

shell> amixer sset 'Input Source' 'Front Mic'
Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Mic'

This does not work ! Because amixer will think that 'Front' is a modifier for 'Mic'.

Attached is a patch against alsa-utils-1.0.13-1ubuntu5 that solves this. With this patch, one can bypass the modifier parsing: one simply escapes the parameter with one or more backslash(es), and that's all:

shell> amixer sset 'Input Source' '\Front Mic'
Simple mixer control 'Input Source',0
Capabilities: enum
Items: 'Mic' 'Front Mic' 'Line'
Item0: 'Front Mic'

What this patch also does, is that it adds correct identification of items. With the original version, given the following enumeration:
foo foobar
Then the parameter 'foobar' will be identified as 'foo', not 'foobar'. The patch should solve this potential problem (not tested though).

Bye,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGj/X0ld7vhusVrCERAjIZAJ9w9GLD+QBwDCaTs32hpW6i9nVMfgCfdS5w jhipZ2jm87fq4zx4f5Q9Vsc=
=M2KP
-----END PGP SIGNATURE-----

diff -ru alsa-utils-1.0.13/amixer/amixer.1 alsa-utils-1.0.13-mine/amixer/amixer.1

amixer/amixer.1 +8 -5
@@ -44,11 +44,14 @@
 The parameters \fIcap, nocap, mute, unmute, toggle\fP are used to
 change capture (recording) and muting for the group specified.
 
-The optional modifiers can be put as extra parameters to specify
-the stream direction or channels to apply.
-The modifiers \fIplayback\fP and \fIcapture\fP specify the stream,
-and the modifiers \fIfront, rear, center, woofer\fP are used to specify
-channels to be changed. 
+The optional modifiers can be put as extra parameters to specify the
+stream direction or channels to apply.  The modifiers \fIplayback\fP
+and \fIcapture\fP specify the stream, and the modifiers \fIfront,
+rear, center, woofer\fP are used to specify channels to be changed. If
+there is a confusion between the parameter and these modifiers, then
+any character in the parameter may be escaped with a backslash to
+disambiguate: '\\Front Mic' will be understood as "parameter 'Front
+Mic'", and not as "modifier 'Front' applied to 'Mic' parameter".
 
 A simple mixer control must be specified. Only one device can be controlled
 at a time.

diff -ru alsa-utils-1.0.13/amixer/amixer.c alsa-utils-1.0.13-mine/amixer/amixer.c

amixer/amixer.c +12 -1
@@ -1333,6 +1333,16 @@
 	return def;
 }
 
+/** Transform '\a\b c \de' into 'ab c de' */
+static void unescape(char * arg)
+{
+  char * c;
+  for (c = arg ; arg && *arg ; arg ++)
+    if (*arg != '\\')
+      *(c++) = *arg;
+  *c = '\0';
+}
+
 static int get_enum_item_index(snd_mixer_elem_t *elem, char **ptrp)
 {
 	char *ptr = *ptrp;
@@ -1347,7 +1357,7 @@
 		if (snd_mixer_selem_get_enum_item_name(elem, i, sizeof(name)-1, name) < 0)
 			continue;
 		len = strlen(name);
-		if (! strncmp(name, ptr, len)) {
+		if (!strncmp(name, ptr, len) && (ptr[len] == '\0')) {
 			if (! ptr[len] || ptr[len] == ',' || ptr[len] == '\n') {
 				ptr += len;
 				*ptrp = ptr;
@@ -1428,6 +1438,7 @@
 		dir = dir_mask(&ptr, dir);
 		if (*ptr == '\0')
 			continue;
+		unescape(ptr);
 		multi = (strchr(ptr, ',') != NULL);
 		optr = ptr;
 		for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {

_______________________________________________
Pkg-alsa-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/pkg-alsa-devel

Signature · 3 lines
  "Talking much about oneself can also 
   be a means to conceal oneself."
         -Friedrich Nietzsche