Skip to contentSkip to conversation

ascenario: Small updates for new API.

PATCH New Stefan Schmidt 1 participant 4 messages Oct 7, 2009

lore
Share & tools
lore
#0 lore raw

Hello.

[PATCH 1/3] ascenario: Rename SND_SCN_INT_QOS to SND_SCN_INT_QOS_POWER As proposed by Jaroslav. Emphasis the power consumption relationship.

[PATCH 2/3] ascenario: Fix snd_scenario_get_control_id() declaration to match implementation Just different names in declaration and implementation. I favoured _control_id().

[PATCH 3/3] ascenario: Implement snd_scenario_get_control_id() Replace the four explicit functions with a generic one. I was not able to find another way to get the id from the given numid then getting the full list and iterate through it. If there is something easier let me know. :)

regards
Stefan Schmidt

#1 lore raw

PATCH 1/3 ascenario: Rename SND_SCN_INT_QOS to SND_SCN_INT_QOS_POWER

From: Stefan Schmidt <[email protected]>

This brings it in line with SND_POWER_QOS_* and emphasis the power consumption background.

---
 include/ascenario.h |    2 +-
 src/ascenario.c     |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/ascenario.h +1 -1
index b139551..3055cfa 100644
@@ -125,7 +125,7 @@ extern "C" {
  * Integer types
  */
 /** QoS volume */
-#define SND_SCN_INT_QOS				1
+#define SND_SCN_INT_QOS_POWER			1
 
 /** Scenario container */
 typedef struct snd_scenario snd_scenario_t;
src/ascenario.c +2 -2
index 19d3856..f90192c 100644
@@ -1323,7 +1323,7 @@ const char *snd_scenario_get_scn(snd_scenario_t *scn)
 int snd_scenario_set_integer(snd_scenario_t *scn, int type, int value)
 {
 	switch (type) {
-	case SND_SCN_INT_QOS:
+	case SND_SCN_INT_QOS_POWER:
 		scn->scenario[scn->current_scenario].qos = value;
 		return 0;
 	default:
@@ -1336,7 +1336,7 @@ int snd_scenario_get_integer(snd_scenario_t *scn, int type, int *value)
 	if (value == NULL)
 		return -EINVAL;
 	switch (type) {
-	case SND_SCN_INT_QOS:
+	case SND_SCN_INT_QOS_POWER:
 		*value = scn->scenario[scn->current_scenario].qos;
 		return 0;
 	default:
Signature · 1 line
1.6.4.3
#2 lore raw

PATCH 2/3 ascenario: Fix snd_scenario_get_control_id() declaration to match implementation

In reply to Stefan Schmidt

From: Stefan Schmidt <[email protected]>

---
 include/ascenario.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/ascenario.h +2 -2
index 3055cfa..6119f49 100644
@@ -166,8 +166,8 @@ const char *snd_scenario_get_scn(snd_scenario_t *scn);
  *
  * Get the control id for the current scenario.
  */
-int snd_scenario_get_kcontrol(snd_scenario_t *scn,
-                              int kctl_type, snd_ctl_elem_id_t *id);
+int snd_scenario_get_control_id(snd_scenario_t *scn,
+                                int kctl_type, snd_ctl_elem_id_t *id);
 
 /**
  * \brief set integer value
Signature · 1 line
1.6.4.3
#3 lore raw

PATCH 3/3 ascenario: Implement snd_scenario_get_control_id()

In reply to Stefan Schmidt

From: Stefan Schmidt <[email protected]>

This new function is used to get the control ids for our aliased control. It replaces the different functions for {playback, capture}_{volume, switch}.

---
 src/ascenario.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 78 insertions(+), 2 deletions(-)
src/ascenario.c +78 -2
index f90192c..d753de0 100644
@@ -1347,8 +1347,84 @@ int snd_scenario_get_integer(snd_scenario_t *scn, int type, int *value)
 int snd_scenario_get_control_id(snd_scenario_t *scn, int type,
 				snd_ctl_elem_id_t *id)
 {
-	/* not yet implemented */
-	return -EINVAL;
+	int numid, ret, i, count, tmp;
+	snd_ctl_t *handle;
+	snd_ctl_card_info_t *info;
+	snd_ctl_elem_list_t *list;
+
+	snd_ctl_card_info_alloca(&info);
+	snd_ctl_elem_list_alloca(&list);
+
+	switch (type) {
+	case SND_SCN_KCTL_MASTER_PLAYBACK_VOLUME:
+		numid = scn->scenario[scn->current_scenario].playback_volume_id;
+		break;
+	case SND_SCN_KCTL_MASTER_PLAYBACK_SWITCH:
+		numid = scn->scenario[scn->current_scenario].playback_switch_id;
+		 break;
+	case SND_SCN_KCTL_MASTER_CAPTURE_VOLUME:
+		numid = scn->scenario[scn->current_scenario].capture_volume_id;
+		break;
+	case SND_SCN_KCTL_MASTER_CAPTURE_SWITCH:
+		numid = scn->scenario[scn->current_scenario].capture_switch_id;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Where is id lookup from numid if you need it?
+	 * Get a list of all controls to step through */
+	ret = snd_ctl_open(&handle, scn->card_name, SND_CTL_READONLY);
+	if (ret < 0) {
+		scn_error("%s: control %s open retor: %s\n", __func__,
+			scn->card_name, snd_strerror(ret));
+		return ret;
+	}
+
+	ret = snd_ctl_card_info(handle, info);
+	if (ret < 0) {
+		scn_error("%s :control %s local retor: %s\n", __func__,
+			scn->card_name, snd_strerror(ret));
+		goto close;
+	}
+
+	ret = snd_ctl_elem_list(handle, list);
+	if (ret < 0) {
+		scn_error("%s: cannot determine controls: %s\n", __func__,
+			snd_strerror(ret));
+		goto close;
+	}
+
+	count = snd_ctl_elem_list_get_count(list);
+	if (count < 0) {
+		ret = 0;
+		goto close;
+	}
+
+	snd_ctl_elem_list_set_offset(list, 0);
+	if (snd_ctl_elem_list_alloc_space(list, count) < 0) {
+		scn_error("%s: not enough memory...\n", __func__);
+		ret =  -ENOMEM;
+		goto close;
+	}
+	if ((ret = snd_ctl_elem_list(handle, list)) < 0) {
+		scn_error("%s: cannot determine controls: %s\n", __func__,
+			snd_strerror(ret));
+		goto free;
+	}
+
+	/* Iterate through list and check for the right numid to find our id */
+	for (i = 0; i < count; ++i) {
+		snd_ctl_elem_list_get_id(list, i, id);
+		tmp = snd_ctl_elem_id_get_numid(id);
+		if (numid == tmp)
+			break;
+	}
+free:
+	snd_ctl_elem_list_free_space(list);
+close:
+	snd_ctl_close(handle);
+	return ret;
 }
 
 int snd_scenario_list(snd_scenario_t *scn, const char **list[])
Signature · 1 line
1.6.4.3