]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: substream_params: add properties
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 18 Nov 2019 04:22:44 +0000 (13:22 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 12 Apr 2020 05:30:33 +0000 (14:30 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/rawmidi/substream-params.c
src/rawmidi/substream-params.h
tests/alsarawmidi-substream-params

index c08769b0357c654e45399a6fef5cd7ce996bf3e2..0f5f0787d7ad036ff87eb1a804edad8587d5cda1 100644 (file)
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "substream-params.h"
 
-G_DEFINE_TYPE(ALSARawmidiSubstreamParams, alsarawmidi_substream_params, G_TYPE_OBJECT)
+#include <unistd.h>
+
+#include <sound/asound.h>
+
+struct _ALSARawmidiSubstreamParamsPrivate {
+    struct snd_rawmidi_params params;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(ALSARawmidiSubstreamParams, alsarawmidi_substream_params, G_TYPE_OBJECT)
+
+enum rawmidi_substream_params_prop_type {
+    RAWMIDI_SUBSTREAM_PARAMS_PROP_BUFFER_SIZE = 1,
+    RAWMIDI_SUBSTREAM_PARAMS_PROP_AVAIL_MIN,
+    RAWMIDI_SUBSTREAM_PARAMS_PROP_ACTIVE_SENSING,
+    RAWMIDI_SUBSTREAM_PARAMS_PROP_COUNT,
+};
+static GParamSpec *rawmidi_substream_params_props[RAWMIDI_SUBSTREAM_PARAMS_PROP_COUNT] = { NULL, };
+
+static void rawmidi_substream_params_set_property(GObject *obj, guint id,
+                                        const GValue *val, GParamSpec *spec)
+{
+    ALSARawmidiSubstreamParams *self = ALSARAWMIDI_SUBSTREAM_PARAMS(obj);
+    ALSARawmidiSubstreamParamsPrivate *priv =
+                        alsarawmidi_substream_params_get_instance_private(self);
+
+    switch (id) {
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_BUFFER_SIZE:
+        priv->params.buffer_size = g_value_get_uint(val);
+        break;
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_AVAIL_MIN:
+        priv->params.avail_min = g_value_get_uint(val);
+        break;
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_ACTIVE_SENSING:
+        priv->params.no_active_sensing = !g_value_get_boolean(val);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
+
+static void rawmidi_substream_params_get_property(GObject *obj, guint id,
+                                                GValue *val, GParamSpec *spec)
+{
+    ALSARawmidiSubstreamParams *self = ALSARAWMIDI_SUBSTREAM_PARAMS(obj);
+    ALSARawmidiSubstreamParamsPrivate *priv =
+                        alsarawmidi_substream_params_get_instance_private(self);
+
+    switch (id) {
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_BUFFER_SIZE:
+        g_value_set_uint(val, priv->params.buffer_size);
+        break;
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_AVAIL_MIN:
+        g_value_set_uint(val, priv->params.avail_min);
+        break;
+    case RAWMIDI_SUBSTREAM_PARAMS_PROP_ACTIVE_SENSING:
+        g_value_set_boolean(val, !priv->params.no_active_sensing);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
 
 static void alsarawmidi_substream_params_class_init(ALSARawmidiSubstreamParamsClass *klass)
 {
-    return;
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+    long page_size = sysconf(_SC_PAGESIZE);
+
+    gobject_class->set_property = rawmidi_substream_params_set_property;
+    gobject_class->get_property = rawmidi_substream_params_get_property;
+
+    rawmidi_substream_params_props[RAWMIDI_SUBSTREAM_PARAMS_PROP_BUFFER_SIZE] =
+        g_param_spec_uint("buffer-size", "buffer-size",
+                          "The size of intermediate buffer for substream.",
+                          32, 1024 * 1024,
+                          page_size,
+                          G_PARAM_READWRITE);
+
+    rawmidi_substream_params_props[RAWMIDI_SUBSTREAM_PARAMS_PROP_AVAIL_MIN] =
+        g_param_spec_uint("avail-min", "avail-min",
+                          "The threshold to wake up from any blocking "
+                          "operation such as poll(2), read(2) and write(2).",
+                          1, G_MAXUINT,
+                          1,
+                          G_PARAM_READWRITE);
+
+    rawmidi_substream_params_props[RAWMIDI_SUBSTREAM_PARAMS_PROP_ACTIVE_SENSING] =
+        g_param_spec_boolean("active-sensing", "active-sensing",
+                             "Whether to emit 0xfe one time when closing "
+                             "substream.",
+                             FALSE,
+                             G_PARAM_READWRITE);
+
+    g_object_class_install_properties(gobject_class,
+                                      RAWMIDI_SUBSTREAM_PARAMS_PROP_COUNT,
+                                      rawmidi_substream_params_props);
 }
 
 static void alsarawmidi_substream_params_init(ALSARawmidiSubstreamParams *self)
index a8deb52b033c51b6a849a9742e0512a2a42754ad..1c662a3ac16bc990eb6704ef0ed6b0ab44dd1634 100644 (file)
@@ -31,9 +31,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSARawmidiSubstreamParams          ALSARawmidiSubstreamParams;
 typedef struct _ALSARawmidiSubstreamParamsClass     ALSARawmidiSubstreamParamsClass;
+typedef struct _ALSARawmidiSubstreamParamsPrivate   ALSARawmidiSubstreamParamsPrivate;
 
 struct _ALSARawmidiSubstreamParams {
     GObject parent_instance;
+
+    ALSARawmidiSubstreamParamsPrivate *priv;
 };
 
 struct _ALSARawmidiSubstreamParamsClass {
index 8212a82afb21c8d0e01708f078b8ae6e19bfe620..f85a18644ef3c0e7e53838f0ca89502709f36e69 100644 (file)
@@ -10,7 +10,11 @@ gi.require_version('ALSARawmidi', '0.0')
 from gi.repository import ALSARawmidi
 
 target = ALSARawmidi.SubstreamParams()
-props = ()
+props = (
+    'buffer-size',
+    'avail-min',
+    'active-sensing',
+)
 methods = (
     'new',
 )