From: Takashi Sakamoto Date: Mon, 18 Nov 2019 04:22:44 +0000 (+0900) Subject: rawmidi: substream_info: add properties X-Git-Tag: v0.1.0~186 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=14ea809a8a8da4748e0d2d51c59ffc31bac216d4;p=alsa-gobject.git rawmidi: substream_info: add properties Signed-off-by: Takashi Sakamoto --- diff --git a/src/rawmidi/substream-info.c b/src/rawmidi/substream-info.c index 82c0288..1b218ad 100644 --- a/src/rawmidi/substream-info.c +++ b/src/rawmidi/substream-info.c @@ -1,11 +1,153 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "substream-info.h" -G_DEFINE_TYPE(ALSARawmidiSubstreamInfo, alsarawmidi_substream_info, G_TYPE_OBJECT) +#include + +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) diff --git a/src/rawmidi/substream-info.h b/src/rawmidi/substream-info.h index dd3be01..fcab034 100644 --- a/src/rawmidi/substream-info.h +++ b/src/rawmidi/substream-info.h @@ -5,6 +5,8 @@ #include #include +#include + 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 { diff --git a/tests/alsarawmidi-substream-info b/tests/alsarawmidi-substream-info index cdf36c8..f4dcf8e 100644 --- a/tests/alsarawmidi-substream-info +++ b/tests/alsarawmidi-substream-info @@ -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 = ()