]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem_info: add accessor APIs for triplet data of integer element
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 12 Jun 2020 04:19:45 +0000 (13:19 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Fri, 12 Jun 2020 06:45:37 +0000 (15:45 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/ctl/alsactl.map
src/ctl/elem-info.c
src/ctl/elem-info.h
tests/alsactl-elem-info

index 49696c1b66ca68e8710937825004bcfdc3d6d7fa..ba51b69721231548015a1de9cb962017f620e247 100644 (file)
@@ -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";
index 2b913f5991a2a803ec646128c1ed3076f904c7e2..7e9cbc10357e451b5c20be5b03ac87f40b88f8ff 100644 (file)
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "privates.h"
 
+#include <errno.h>
+
 /**
  * SECTION: elem-info
  * @Title: ALSACtlElemInfo
  */
 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)
 {
index ea6d7e7457901eaf57d89a6195f512ae83301ebd..fef08a7a48761520303a9e442724a66cf4ba3c26 100644 (file)
@@ -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
index 36c0acde9e744ba7c74789cb0cdcfacc9a10c582..270d3f77186c522d34204415f6b71c31a7780339 100644 (file)
@@ -16,7 +16,10 @@ props = (
     'access',
     'owner',
 )
-methods = ()
+methods = (
+    'get_int_data',
+    'set_int_data',
+)
 signals = ()
 
 if not test(target, props, methods, signals):