Skip to contentSkip to conversation

control: Allow cset'ing specific values in the multi-value case

PATCH Applied [email protected] 2 participants 4 messages Jun 9, 2015 – Jun 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 control: Allow cset'ing specific values in the multi-value case

From: Arun Raghavan <[email protected]>

This works with syntax like ...

amixer cset 'IIR1 Band1' ,,200

... to set the third value of the control to 200.

---
 src/control/ctlparse.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/control/ctlparse.c +6 -4
index 8d6c385..64c6480 100644
@@ -48,9 +48,9 @@ static inline long int convert_prange1(long val, long min, long max)
 #define check_range(val, min, max) \
 	((val < min) ? (min) : ((val > max) ? (max) : (val)))
 
-static long get_integer(const char **ptr, long min, long max)
+static long get_integer(const char **ptr, long def, long min, long max)
 {
-	long val = min;
+	long val = def;
 	char *p = (char *)*ptr, *s;
 
 	if (*p == ':')
@@ -351,6 +351,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 			break;
 		case SND_CTL_ELEM_TYPE_INTEGER:
 			tmp = get_integer(&ptr,
+					  snd_ctl_elem_value_get_integer(dst,
+									 idx),
 					  snd_ctl_elem_info_get_min(info),
 					  snd_ctl_elem_info_get_max(info));
 			snd_ctl_elem_value_set_integer(dst, idx, tmp);
@@ -364,12 +366,12 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 		case SND_CTL_ELEM_TYPE_ENUMERATED:
 			tmp = get_ctl_enum_item_index(handle, info, &ptr);
 			if (tmp < 0)
-				tmp = get_integer(&ptr, 0,
+				tmp = get_integer(&ptr, 0, 0,
 					snd_ctl_elem_info_get_items(info) - 1);
 			snd_ctl_elem_value_set_enumerated(dst, idx, tmp);
 			break;
 		case SND_CTL_ELEM_TYPE_BYTES:
-			tmp = get_integer(&ptr, 0, 255);
+			tmp = get_integer(&ptr, 0, 0, 255);
 			snd_ctl_elem_value_set_byte(dst, idx, tmp);
 			break;
 		default:
Signature · 1 line
2.4.2
#1 lore raw

At Tue, 9 Jun 2015 16:25:07 +0530,

Quoted 41 lines · [email protected] wrote:

From: Arun Raghavan <[email protected]>

This works with syntax like ...

amixer cset 'IIR1 Band1' ,,200

... to set the third value of the control to 200.

---
 src/control/ctlparse.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/control/ctlparse.c +4 -2
index 8d6c385..64c6480 100644
@@ -48,9 +48,9 @@ static inline long int convert_prange1(long val, long min, long max)
 #define check_range(val, min, max) \
 	((val < min) ? (min) : ((val > max) ? (max) : (val)))
 
-static long get_integer(const char **ptr, long min, long max)
+static long get_integer(const char **ptr, long def, long min, long max)
 {
-	long val = min;
+	long val = def;
 	char *p = (char *)*ptr, *s;
 
 	if (*p == ':')
@@ -351,6 +351,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 			break;
 		case SND_CTL_ELEM_TYPE_INTEGER:
 			tmp = get_integer(&ptr,
+					  snd_ctl_elem_value_get_integer(dst,
+									 idx),
 					  snd_ctl_elem_info_get_min(info),
 					  snd_ctl_elem_info_get_max(info));
 			snd_ctl_elem_value_set_integer(dst, idx, tmp);
@@ -364,12 +366,12 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 		case SND_CTL_ELEM_TYPE_ENUMERATED:
 			tmp = get_ctl_enum_item_index(handle, info, &ptr);
 			if (tmp < 0)

src/control/ctlparse.c int snd_ctl_ascii_value_parse(snd_ctl_t *handle, · line 376

Quoted 10 lines
src/control/ctlparse.c +2 -2
-				tmp = get_integer(&ptr, 0,
+				tmp = get_integer(&ptr, 0, 0,
 					snd_ctl_elem_info_get_items(info) - 1);
 			snd_ctl_elem_value_set_enumerated(dst, idx, tmp);
 			break;
 		case SND_CTL_ELEM_TYPE_BYTES:
-			tmp = get_integer(&ptr, 0, 255);
+			tmp = get_integer(&ptr, 0, 0, 255);
 			snd_ctl_elem_value_set_byte(dst, idx, tmp);
 			break;

Hmm, if it's just about skipping the empty element, how about the patch below instead?

thanks,

Takashi

---

src/control/ctlparse.c +3 -0
index 8d6c3859bec4..877a05e3a1f1 100644
@@ -325,6 +325,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 	snd_ctl_elem_value_set_id(dst, myid);
 	
 	for (idx = 0; idx < count && idx < 128 && ptr && *ptr; idx++) {
+		if (*ptr == ',')
+			goto skip;
 		switch (type) {
 		case SND_CTL_ELEM_TYPE_BOOLEAN:
 			tmp = 0;
@@ -375,6 +377,7 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
 		default:
 			break;
 		}
+	skip:
 		if (!strchr(value, ','))
 			ptr = value;
 		else if (*ptr == ',')
#2 lore raw
Quoted 48 lines · Takashi Iwai

At Tue, 9 Jun 2015 16:25:07 +0530,

Quoted 46 lines · [email protected] wrote:

From: Arun Raghavan <[email protected]>

This works with syntax like ...

amixer cset 'IIR1 Band1' ,,200

... to set the third value of the control to 200.

---
 src/control/ctlparse.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/control/ctlparse.c +5 -3
index 8d6c385..64c6480 100644
@@ -48,9 +48,9 @@ static inline long int convert_prange1(long val, long min, long max)
 #define check_range(val, min, max) \
      ((val < min) ? (min) : ((val > max) ? (max) : (val)))
 
-static long get_integer(const char **ptr, long min, long max)
+static long get_integer(const char **ptr, long def, long min, long max)
 {
-     long val = min;
+     long val = def;
      char *p = (char *)*ptr, *s;
 
      if (*p == ':')
@@ -351,6 +351,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
                      break;
              case SND_CTL_ELEM_TYPE_INTEGER:
                      tmp = get_integer(&ptr,
+                                       snd_ctl_elem_value_get_integer(dst,
+                                                                      idx),
                                        snd_ctl_elem_info_get_min(info),
                                        snd_ctl_elem_info_get_max(info));
                      snd_ctl_elem_value_set_integer(dst, idx, tmp);
@@ -364,12 +366,12 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
              case SND_CTL_ELEM_TYPE_ENUMERATED:
                      tmp = get_ctl_enum_item_index(handle, info, &ptr);
                      if (tmp < 0)
-                             tmp = get_integer(&ptr, 0,
+                             tmp = get_integer(&ptr, 0, 0,
                                      snd_ctl_elem_info_get_items(info) - 1);
                      snd_ctl_elem_value_set_enumerated(dst, idx, tmp);
                      break;
Quoted 8 lines

src/control/ctlparse.c int snd_ctl_ascii_value_parse(snd_ctl_t *handle, · line 376

Quoted 5 lines
src/control/ctlparse.c +1 -1
              case SND_CTL_ELEM_TYPE_BYTES:
-                     tmp = get_integer(&ptr, 0, 255);
+                     tmp = get_integer(&ptr, 0, 0, 255);
                      snd_ctl_elem_value_set_byte(dst, idx, tmp);
                      break;

Hmm, if it's just about skipping the empty element, how about the patch below instead?

Thanks, this works and does look better.

Cheers,
Arun

Quoted 22 lines

---

src/control/ctlparse.c +3 -0
index 8d6c3859bec4..877a05e3a1f1 100644
@@ -325,6 +325,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
        snd_ctl_elem_value_set_id(dst, myid);
 
        for (idx = 0; idx < count && idx < 128 && ptr && *ptr; idx++) {
+               if (*ptr == ',')
+                       goto skip;
                switch (type) {
                case SND_CTL_ELEM_TYPE_BOOLEAN:
                        tmp = 0;
@@ -375,6 +377,7 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
                default:
                        break;
                }
+       skip:
                if (!strchr(value, ','))
                        ptr = value;
                else if (*ptr == ',')
Applied
#3 lore raw

At Wed, 10 Jun 2015 14:26:48 +0530,

Quoted 59 lines · Arun Raghavan
Quoted 48 lines · Takashi Iwai

At Tue, 9 Jun 2015 16:25:07 +0530,

Quoted 46 lines · [email protected] wrote:

From: Arun Raghavan <[email protected]>

This works with syntax like ...

amixer cset 'IIR1 Band1' ,,200

... to set the third value of the control to 200.

---
 src/control/ctlparse.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/control/ctlparse.c +5 -3
index 8d6c385..64c6480 100644
@@ -48,9 +48,9 @@ static inline long int convert_prange1(long val, long min, long max)
 #define check_range(val, min, max) \
      ((val < min) ? (min) : ((val > max) ? (max) : (val)))
 
-static long get_integer(const char **ptr, long min, long max)
+static long get_integer(const char **ptr, long def, long min, long max)
 {
-     long val = min;
+     long val = def;
      char *p = (char *)*ptr, *s;
 
      if (*p == ':')
@@ -351,6 +351,8 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
                      break;
              case SND_CTL_ELEM_TYPE_INTEGER:
                      tmp = get_integer(&ptr,
+                                       snd_ctl_elem_value_get_integer(dst,
+                                                                      idx),
                                        snd_ctl_elem_info_get_min(info),
                                        snd_ctl_elem_info_get_max(info));
                      snd_ctl_elem_value_set_integer(dst, idx, tmp);
@@ -364,12 +366,12 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
              case SND_CTL_ELEM_TYPE_ENUMERATED:
                      tmp = get_ctl_enum_item_index(handle, info, &ptr);
                      if (tmp < 0)
-                             tmp = get_integer(&ptr, 0,
+                             tmp = get_integer(&ptr, 0, 0,
                                      snd_ctl_elem_info_get_items(info) - 1);
                      snd_ctl_elem_value_set_enumerated(dst, idx, tmp);
                      break;
Quoted 8 lines

src/control/ctlparse.c int snd_ctl_ascii_value_parse(snd_ctl_t *handle, · line 376

Quoted 5 lines
src/control/ctlparse.c +1 -1
              case SND_CTL_ELEM_TYPE_BYTES:
-                     tmp = get_integer(&ptr, 0, 255);
+                     tmp = get_integer(&ptr, 0, 0, 255);
                      snd_ctl_elem_value_set_byte(dst, idx, tmp);
                      break;

Hmm, if it's just about skipping the empty element, how about the patch below instead?

Quoted 1 line

Thanks, this works and does look better.

Pushed to git tree now. Thanks.

Takashi