]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: substream_info: 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-info.c
src/rawmidi/substream-info.h
tests/alsarawmidi-substream-info

index 82c028867ea52c616d0c1627dca10b70f69f0646..1b218adb2713dea710e013191b8532db02565868 100644 (file)
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "substream-info.h"
 
-G_DEFINE_TYPE(ALSARawmidiSubstreamInfo, alsarawmidi_substream_info, G_TYPE_OBJECT)
+#include <sound/asound.h>
+
+struct _ALSARawmidiSubstreamInfoPrivate {
+    struct snd_rawmidi_info info;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(ALSARawmidiSubstreamInfo, alsarawmidi_substream_info, G_TYPE_OBJECT)
+
+enum rawmidi_substream_info_prop_type {
+    RAWMIDI_SUBSTREAM_INFO_PROP_DEVICE_ID = 1,
+    RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICE_ID,
+    RAWMIDI_SUBSTREAM_INFO_PROP_DIRECTION,
+    RAWMIDI_SUBSTREAM_INFO_PROP_CARD_ID,
+    RAWMIDI_SUBSTREAM_INFO_PROP_FLAGS,
+    RAWMIDI_SUBSTREAM_INFO_PROP_ID,
+    RAWMIDI_SUBSTREAM_INFO_PROP_NAME,
+    RAWMIDI_SUBSTREAM_INFO_PROP_SUBNAME,
+    RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_COUNT,
+    RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_AVAIL,
+    RAWMIDI_SUBSTREAM_INFO_PROP_COUNT,
+};
+static GParamSpec *rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_COUNT] = { NULL, };
+
+static void rawmidi_substream_info_get_property(GObject *obj, guint id,
+                                                GValue *val, GParamSpec *spec)
+{
+    ALSARawmidiSubstreamInfo *self = ALSARAWMIDI_SUBSTREAM_INFO(obj);
+    ALSARawmidiSubstreamInfoPrivate *priv =
+                        alsarawmidi_substream_info_get_instance_private(self);
+
+    switch (id) {
+    case RAWMIDI_SUBSTREAM_INFO_PROP_DEVICE_ID:
+        g_value_set_uint(val, priv->info.device);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICE_ID:
+        g_value_set_uint(val, priv->info.subdevice);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_DIRECTION:
+        g_value_set_enum(val, priv->info.stream);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_CARD_ID:
+        g_value_set_int(val, priv->info.card);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_FLAGS:
+        g_value_set_flags(val, priv->info.flags);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_ID:
+        g_value_set_static_string(val, (gchar *)priv->info.id);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_NAME:
+        g_value_set_static_string(val, (gchar *)priv->info.name);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_SUBNAME:
+        g_value_set_static_string(val, (gchar *)priv->info.subname);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_COUNT:
+        g_value_set_uint(val, priv->info.subdevices_count);
+        break;
+    case RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_AVAIL:
+        g_value_set_uint(val, priv->info.subdevices_avail);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
 
 static void alsarawmidi_substream_info_class_init(ALSARawmidiSubstreamInfoClass *klass)
 {
-    return;
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->get_property = rawmidi_substream_info_get_property;
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_DEVICE_ID] =
+        g_param_spec_uint("device-id", "device-id",
+                         "The numerical ID of rawmidi device.",
+                         0, G_MAXINT,
+                         0,
+                         G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICE_ID] =
+        g_param_spec_uint("subdevice-id", "subdevice-id",
+                          "The numerical ID of subdevice for rawmidi device..",
+                          0, G_MAXINT,
+                          0,
+                          G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_DIRECTION] =
+        g_param_spec_enum("direction", "direction",
+                          "The direction of stream, one of "
+                          "ALSARawmidiStreamDirection",
+                          ALSARAWMIDI_TYPE_STREAM_DIRECTION,
+                          ALSARAWMIDI_STREAM_DIRECTION_OUTPUT,
+                          G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_CARD_ID] =
+        g_param_spec_int("card-id", "card-id",
+                         "The numerical ID of sound card.",
+                         G_MININT, G_MAXINT,
+                         -1,
+                         G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_FLAGS] =
+        g_param_spec_flags("flags", "flags",
+                           "The information flags of rawmidi device with flags "
+                           "of ALSARawmidiStreamPairInfoFlag.",
+                          ALSARAWMIDI_TYPE_STREAM_PAIR_INFO_FLAG,
+                          0,
+                          G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_ID] =
+        g_param_spec_string("id", "id",
+                            "The string ID of rawmidi device.",
+                            "",
+                            G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_NAME] =
+        g_param_spec_string("name", "name",
+                            "The name of rawmidi device.",
+                            "",
+                            G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_SUBNAME] =
+        g_param_spec_string("subdevice-name", "subdevice-name",
+                            "The name of subdevice for the direction and the "
+                            "subdevice-id",
+                            "",
+                            G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_COUNT] =
+        g_param_spec_uint("subdevices-count", "subdevices-count",
+                          "The number of subdevices on the rawmidi device for "
+                          "the direction",
+                          0, G_MAXINT,
+                          0,
+                          G_PARAM_READABLE);
+
+    rawmidi_substream_info_props[RAWMIDI_SUBSTREAM_INFO_PROP_SUBDEVICES_AVAIL] =
+        g_param_spec_uint("subdevices-avail", "subdevices-avail",
+                          "The current number of available subdevices on the "
+                          "rawmidi device for the direction.",
+                          0, G_MAXINT,
+                          0,
+                          G_PARAM_READABLE);
+
+    g_object_class_install_properties(gobject_class,
+                                      RAWMIDI_SUBSTREAM_INFO_PROP_COUNT,
+                                      rawmidi_substream_info_props);
 }
 
 static void alsarawmidi_substream_info_init(ALSARawmidiSubstreamInfo *self)
index dd3be010798fd21ddaf9d057e56cd130713bccdf..fcab03465bd5c9f3ca4d1a1d5f5c02e429fc410a 100644 (file)
@@ -5,6 +5,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <rawmidi/alsarawmidi-enums.h>
+
 G_BEGIN_DECLS
 
 #define ALSARAWMIDI_TYPE_SUBSTREAM_INFO (alsarawmidi_substream_info_get_type())
@@ -31,9 +33,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSARawmidiSubstreamInfo        ALSARawmidiSubstreamInfo;
 typedef struct _ALSARawmidiSubstreamInfoClass   ALSARawmidiSubstreamInfoClass;
+typedef struct _ALSARawmidiSubstreamInfoPrivate ALSARawmidiSubstreamInfoPrivate;
 
 struct _ALSARawmidiSubstreamInfo {
     GObject parent_instance;
+
+    ALSARawmidiSubstreamInfoPrivate *priv;
 };
 
 struct _ALSARawmidiSubstreamInfoClass {
index cdf36c8852d4bc980c5f86db10e06e3d6904544e..f4dcf8eb2f09e253f0750f46bd7f6c3595398101 100644 (file)
@@ -10,7 +10,18 @@ gi.require_version('ALSARawmidi', '0.0')
 from gi.repository import ALSARawmidi
 
 target = ALSARawmidi.SubstreamInfo()
-props = ()
+props = (
+    'device-id',
+    'subdevice-id',
+    'direction',
+    'card-id',
+    'flags',
+    'id',
+    'name',
+    'subdevice-name',
+    'subdevices-count',
+    'subdevices-avail',
+)
 methods = ()
 signals = ()