From: Takashi Sakamoto Date: Fri, 12 Jun 2020 04:19:45 +0000 (+0900) Subject: ctl: elem_info: add accessor APIs for triplet data of integer element X-Git-Tag: v0.1.0~76 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=ed26d91c734678678f7c1c16d295eca1c1153651;p=alsa-gobject.git ctl: elem_info: add accessor APIs for triplet data of integer element Signed-off-by: Takashi Sakamoto --- diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 49696c1..ba51b69 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -43,6 +43,8 @@ ALSA_GOBJECT_0_0_0 { "alsactl_elem_id_equal"; "alsactl_elem_info_get_type"; + "alsactl_elem_info_get_int_data"; + "alsactl_elem_info_set_int_data"; "alsactl_elem_info_bool_get_type"; "alsactl_elem_info_bool_new"; diff --git a/src/ctl/elem-info.c b/src/ctl/elem-info.c index 2b913f5..7e9cbc1 100644 --- a/src/ctl/elem-info.c +++ b/src/ctl/elem-info.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "privates.h" +#include + /** * SECTION: elem-info * @Title: ALSACtlElemInfo @@ -14,6 +16,12 @@ */ struct _ALSACtlElemInfoPrivate { struct snd_ctl_elem_info info; + + struct { + gint32 min; + gint32 max; + gint32 step; + } int_data; }; G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(ALSACtlElemInfo, alsactl_elem_info, G_TYPE_OBJECT) @@ -117,6 +125,68 @@ static void alsactl_elem_info_init(ALSACtlElemInfo *self) return; } +/** + * alsactl_elem_info_get_int_data: + * @self: A #ALSACtlElemInfo. + * @data: (array fixed-size=3)(out)(transfer none): The array with elements for + * the data of integer element; minimum value, maximum value, and value + * step in the order. + * @error: A #GError. + * + * Refer to the array with elements for the data of integer element; minimum + * value, maximum value, and value step in the order. The call of function is + * successful as long as the information is for integer type. + */ +void alsactl_elem_info_get_int_data(ALSACtlElemInfo *self, + const gint32 *data[3], GError **error) +{ + ALSACtlElemInfoPrivate *priv; + + g_return_if_fail(ALSACTL_IS_ELEM_INFO(self)); + priv = alsactl_elem_info_get_instance_private(self); + + if (priv->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER) { + generate_error(error, ENXIO); + return; + } + + priv->int_data.min = (gint32)priv->info.value.integer.min; + priv->int_data.max = (gint32)priv->info.value.integer.max; + priv->int_data.step = (gint32)priv->info.value.integer.step; + + *data = (const gint32 *)&priv->int_data; +} + +/** + * alsactl_elem_info_set_int_data: + * @self: A #ALSACtlElemInfo. + * @data: (array fixed-size=3)(transfer none): The array with elements for + * the data of integer element; minimum value, maximum value, and value + * step in the order. + * @error: A #GError. + * + * Get the array with elements for the data of integer element; minimum value, + * maximum value, and value step in the order. The call of function is + * successful as long as the information is for integer type. + */ +void alsactl_elem_info_set_int_data(ALSACtlElemInfo *self, + const gint32 data[3], GError **error) +{ + ALSACtlElemInfoPrivate *priv; + + g_return_if_fail(ALSACTL_IS_ELEM_INFO(self)); + priv = alsactl_elem_info_get_instance_private(self); + + if (priv->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER) { + generate_error(error, ENXIO); + return; + } + + priv->info.value.integer.min = (long)data[0]; + priv->info.value.integer.max = (long)data[1]; + priv->info.value.integer.step = (long)data[2]; +} + void ctl_elem_info_refer_private(ALSACtlElemInfo *self, struct snd_ctl_elem_info **info) { diff --git a/src/ctl/elem-info.h b/src/ctl/elem-info.h index ea6d7e7..fef08a7 100644 --- a/src/ctl/elem-info.h +++ b/src/ctl/elem-info.h @@ -49,6 +49,11 @@ struct _ALSACtlElemInfoClass { GType alsactl_elem_info_get_type() G_GNUC_CONST; +void alsactl_elem_info_get_int_data(ALSACtlElemInfo *self, + const gint32 *data[3], GError **error); +void alsactl_elem_info_set_int_data(ALSACtlElemInfo *self, + const gint32 data[3], GError **error); + G_END_DECLS #endif diff --git a/tests/alsactl-elem-info b/tests/alsactl-elem-info index 36c0acd..270d3f7 100644 --- a/tests/alsactl-elem-info +++ b/tests/alsactl-elem-info @@ -16,7 +16,10 @@ props = ( 'access', 'owner', ) -methods = () +methods = ( + 'get_int_data', + 'set_int_data', +) signals = () if not test(target, props, methods, signals):