From: Takashi Sakamoto Date: Mon, 18 Nov 2019 04:22:44 +0000 (+0900) Subject: ctl: elem_value: add APIs to set/get values of boolean type X-Git-Tag: v0.1.0~385 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=edcec99db343fe5867c403cc6baeeb670641fdc5;p=alsa-gobject.git ctl: elem_value: add APIs to set/get values of boolean type --- diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 2d06a24..01b28c3 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -63,6 +63,8 @@ ALSA_GOBJECT_0_0_0 { "alsactl_elem_value_get_type"; "alsactl_elem_value_new"; + "alsactl_elem_value_set_bool"; + "alsactl_elem_value_get_bool"; local: *; }; diff --git a/src/ctl/elem-value.c b/src/ctl/elem-value.c index 2e88691..07ff619 100644 --- a/src/ctl/elem-value.c +++ b/src/ctl/elem-value.c @@ -71,3 +71,52 @@ void ctl_elem_value_refer_private(ALSACtlElemValue *self, alsactl_elem_value_get_instance_private(self); *value = &priv->value; } + +/** + * alsactl_elem_value_set_bool: + * @self: A #ALSACtlElemValue. + * @values: (array length=value_count): The array for values of boolean type. + * @value_count: The number of values up to 128. + * + * Copy the array for values of boolean type into internal data. + */ +void alsactl_elem_value_set_bool(ALSACtlElemValue *self, + const gboolean *values, gsize value_count) +{ + ALSACtlElemValuePrivate *priv; + struct snd_ctl_elem_value *value; + int i; + + g_return_if_fail(ALSACTL_IS_ELEM_VALUE(self)); + priv = alsactl_elem_value_get_instance_private(self); + value = &priv->value; + + value_count = MIN(value_count, G_N_ELEMENTS(value->value.integer.value)); + for (i = 0; i < value_count; ++i) + value->value.integer.value[i] = (long)values[i]; +} + +/** + * alsactl_elem_value_get_bool: + * @self: A #ALSACtlElemValue. + * @values: (array length=value_count)(inout): The array for values of boolean + * type. + * @value_count: The number of values up to 128. + * + * Copy the array for values of boolean type from internal data. + */ +void alsactl_elem_value_get_bool(ALSACtlElemValue *self, + gboolean *const *values, gsize *value_count) +{ + ALSACtlElemValuePrivate *priv; + struct snd_ctl_elem_value *value; + int i; + + g_return_if_fail(ALSACTL_IS_ELEM_VALUE(self)); + priv = alsactl_elem_value_get_instance_private(self); + value = &priv->value; + + *value_count = MIN(*value_count, G_N_ELEMENTS(value->value.integer.value)); + for (i = 0; i < *value_count; ++i) + (*values)[i] = (gboolean)value->value.integer.value[i]; +} diff --git a/src/ctl/elem-value.h b/src/ctl/elem-value.h index c31efb7..ece6312 100644 --- a/src/ctl/elem-value.h +++ b/src/ctl/elem-value.h @@ -49,6 +49,11 @@ GType alsactl_elem_value_get_type() G_GNUC_CONST; ALSACtlElemValue *alsactl_elem_value_new(); +void alsactl_elem_value_set_bool(ALSACtlElemValue *self, + const gboolean *values, gsize value_count); +void alsactl_elem_value_get_bool(ALSACtlElemValue *self, + gboolean *const *values, gsize *value_count); + G_END_DECLS #endif diff --git a/tests/alsactl-elem-value b/tests/alsactl-elem-value index 7e5675b..d2623ff 100644 --- a/tests/alsactl-elem-value +++ b/tests/alsactl-elem-value @@ -13,7 +13,11 @@ target = ALSACtl.ElemValue() props = ( 'elem-id', ) -methods = () +props = () +methods = ( + 'set_bool', + 'get_bool', +) signals = () if not test(target, props, methods, signals):