From: Takashi Sakamoto Date: Wed, 1 Apr 2020 09:13:28 +0000 (+0900) Subject: seq: event: add properties and access methods X-Git-Tag: v0.1.0~282 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=705922cb38c3eb9712bff2ee52114457d0c4ce1c;p=alsa-gobject.git seq: event: add properties and access methods Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/event.c b/src/seq/event.c index a3557e3..8d6a08e 100644 --- a/src/seq/event.c +++ b/src/seq/event.c @@ -1,11 +1,231 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -#include "event.h" +#include "privates.h" -G_DEFINE_ABSTRACT_TYPE(ALSASeqEvent, alsaseq_event, G_TYPE_OBJECT) +#include + +struct _ALSASeqEventPrivate { + struct snd_seq_event ev; +}; +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(ALSASeqEvent, alsaseq_event, G_TYPE_OBJECT) + +enum seq_event_prop_type { + SEQ_EVENT_PROP_EVENT_TYPE = 1, + SEQ_EVENT_PROP_MODE_TIMESTAMP, + SEQ_EVENT_PROP_MODE_TIME, + SEQ_EVENT_PROP_MODE_LENGTH, + SEQ_EVENT_PROP_MODE_PRIORITY, + SEQ_EVENT_PROP_TAG, + SEQ_EVENT_PROP_QUEUE_ID, + SEQ_EVENT_PROP_TSTAMP, + SEQ_EVENT_PROP_SRC_ADDR, + SEQ_EVENT_PROP_DST_ADDR, + SEQ_EVENT_PROP_COUNT, +}; +static GParamSpec *seq_event_props[SEQ_EVENT_PROP_COUNT] = { NULL, }; + +static void seq_event_set_property(GObject *obj, guint id, const GValue *val, + GParamSpec *spec) +{ + ALSASeqEvent *self = ALSASEQ_EVENT(obj); + ALSASeqEventPrivate *priv = alsaseq_event_get_instance_private(self); + struct snd_seq_event *ev = &priv->ev; + + switch (id) { + case SEQ_EVENT_PROP_EVENT_TYPE: + ev->type = (snd_seq_event_type_t)g_value_get_enum(val); + break; + case SEQ_EVENT_PROP_MODE_TIMESTAMP: + ev->flags &= ~SNDRV_SEQ_TIME_STAMP_MASK; + ev->flags |= (unsigned char)g_value_get_enum(val); + break; + case SEQ_EVENT_PROP_MODE_TIME: + ev->flags &= ~SNDRV_SEQ_TIME_MODE_MASK; + ev->flags |= (unsigned char)g_value_get_enum(val); + break; + case SEQ_EVENT_PROP_MODE_LENGTH: + ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK; + ev->flags |= (unsigned char)g_value_get_enum(val); + break; + case SEQ_EVENT_PROP_MODE_PRIORITY: + ev->flags &= ~SNDRV_SEQ_PRIORITY_MASK; + ev->flags |= (unsigned char)g_value_get_enum(val); + break; + case SEQ_EVENT_PROP_TAG: + ev->tag = g_value_get_schar(val); + break; + case SEQ_EVENT_PROP_QUEUE_ID: + ev->queue = g_value_get_uchar(val); + break; + case SEQ_EVENT_PROP_TSTAMP: + { + ALSASeqTstamp *tstamp = g_value_get_boxed(val); + if (tstamp != NULL) + ev->time = *tstamp; + break; + } + case SEQ_EVENT_PROP_SRC_ADDR: + { + ALSASeqAddr *addr = g_value_get_boxed(val); + if (addr != NULL) + ev->source = *addr; + break; + } + case SEQ_EVENT_PROP_DST_ADDR: + { + ALSASeqAddr *addr = g_value_get_boxed(val); + if (addr != NULL) + ev->dest = *addr; + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} + +static void seq_event_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSASeqEvent *self = ALSASEQ_EVENT(obj); + ALSASeqEventPrivate *priv = alsaseq_event_get_instance_private(self); + struct snd_seq_event *ev = &priv->ev; + + switch (id) { + case SEQ_EVENT_PROP_EVENT_TYPE: + g_value_set_enum(val, (ALSASeqEventType)ev->type); + break; + case SEQ_EVENT_PROP_MODE_TIMESTAMP: + { + ALSASeqEventTimestampMode entry; + entry = ev->flags & SNDRV_SEQ_TIME_STAMP_MASK; + g_value_set_enum(val, entry); + break; + } + case SEQ_EVENT_PROP_MODE_TIME: + { + ALSASeqEventTimeMode entry; + entry = ev->flags & SNDRV_SEQ_TIME_MODE_MASK; + g_value_set_enum(val, entry); + break; + } + case SEQ_EVENT_PROP_MODE_LENGTH: + { + ALSASeqEventLengthMode entry; + entry = ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK; + g_value_set_enum(val, entry); + break; + } + case SEQ_EVENT_PROP_MODE_PRIORITY: + { + ALSASeqEventPriorityMode entry; + entry = ev->flags & SNDRV_SEQ_PRIORITY_MASK; + g_value_set_enum(val, entry); + break; + } + case SEQ_EVENT_PROP_TAG: + g_value_set_schar(val, ev->tag); + break; + case SEQ_EVENT_PROP_QUEUE_ID: + g_value_set_uchar(val, ev->queue); + break; + case SEQ_EVENT_PROP_TSTAMP: + g_value_set_static_boxed(val, &ev->time); + break; + case SEQ_EVENT_PROP_SRC_ADDR: + g_value_set_static_boxed(val, &ev->source); + break; + case SEQ_EVENT_PROP_DST_ADDR: + g_value_set_static_boxed(val, &ev->dest); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} static void alsaseq_event_class_init(ALSASeqEventClass *klass) { - return; + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = seq_event_set_property; + gobject_class->get_property = seq_event_get_property; + + seq_event_props[SEQ_EVENT_PROP_EVENT_TYPE] = + g_param_spec_enum("type", "type", + "The type of event, one of ALSASeqEventType.", + ALSASEQ_TYPE_EVENT_TYPE, + ALSASEQ_EVENT_TYPE_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + seq_event_props[SEQ_EVENT_PROP_MODE_TIMESTAMP] = + g_param_spec_enum("timestamp-mode", "timestamp-mode", + "The mode of timestamp for the event, one of " + "ALSASeqEventTimestampMode", + ALSASEQ_TYPE_EVENT_TIMESTAMP_MODE, + ALSASEQ_EVENT_TIMESTAMP_MODE_TICK, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_MODE_TIME] = + g_param_spec_enum("time-mode", "time-mode", + "The mode of time for the event, one of " + "ALSASeqEventTimeMode", + ALSASEQ_TYPE_EVENT_TIME_MODE, + ALSASEQ_EVENT_TIME_MODE_ABS, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_MODE_LENGTH] = + g_param_spec_enum("length-mode", "length-mode", + "The mode of length for the event, one of " + "ALSASeqEventLengthMode", + ALSASEQ_TYPE_EVENT_LENGTH_MODE, + ALSASEQ_EVENT_LENGTH_MODE_FIXED, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + + seq_event_props[SEQ_EVENT_PROP_MODE_PRIORITY] = + g_param_spec_enum("priority-mode", "priority-mode", + "The mode of priority for the event, one of " + "ALSASeqEventPriorityMode", + ALSASEQ_TYPE_EVENT_PRIORITY_MODE, + ALSASEQ_EVENT_PRIORITY_MODE_NORMAL, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_TAG] = + g_param_spec_char("tag", "tag", + "The arbitrary tag associated to the event.", + G_MININT8, G_MAXINT8, + 0, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_QUEUE_ID] = + g_param_spec_uchar("queue-id", "queue-id", + "The numerical ID of queue to deliver the event. " + "One of ALSASeqSpecificQueueId is available as well.", + 0, G_MAXUINT8, + 0, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_TSTAMP] = + g_param_spec_boxed("tstamp", "tstamp", + "The timestamp for the event. The content is " + "decided according to timestamp-mode property.", + ALSASEQ_TYPE_TSTAMP, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_SRC_ADDR] = + g_param_spec_boxed("src-addr", "src-addr", + "The address of source for the event.", + ALSASEQ_TYPE_ADDR, + G_PARAM_READWRITE); + + seq_event_props[SEQ_EVENT_PROP_DST_ADDR] = + g_param_spec_boxed("dst-addr", "dst-addr", + "The address of destination for the event.", + ALSASEQ_TYPE_ADDR, + G_PARAM_READWRITE); + + g_object_class_install_properties(gobject_class, + SEQ_EVENT_PROP_COUNT, + seq_event_props); } static void alsaseq_event_init(ALSASeqEvent *self) diff --git a/src/seq/event.h b/src/seq/event.h index 7205bed..7553d15 100644 --- a/src/seq/event.h +++ b/src/seq/event.h @@ -5,6 +5,11 @@ #include #include +#include +#include + +#include + G_BEGIN_DECLS #define ALSASEQ_TYPE_EVENT (alsaseq_event_get_type()) @@ -31,9 +36,12 @@ G_BEGIN_DECLS typedef struct _ALSASeqEvent ALSASeqEvent; typedef struct _ALSASeqEventClass ALSASeqEventClass; +typedef struct _ALSASeqEventPrivate ALSASeqEventPrivate; struct _ALSASeqEvent { GObject parent_instance; + + ALSASeqEventPrivate *priv; }; struct _ALSASeqEventClass { diff --git a/src/seq/privates.h b/src/seq/privates.h index 3d3407a..6604029 100644 --- a/src/seq/privates.h +++ b/src/seq/privates.h @@ -11,6 +11,7 @@ #include "client-info.h" #include "port-info.h" #include "client-pool.h" +#include "event.h" #include diff --git a/tests/alsaseq-event b/tests/alsaseq-event index 9cd0181..986b05b 100644 --- a/tests/alsaseq-event +++ b/tests/alsaseq-event @@ -10,7 +10,17 @@ gi.require_version('ALSASeq', '0.0') from gi.repository import ALSASeq target = ALSASeq.Event -props = () +props = ( + 'type', + 'timestamp-mode', + 'time-mode', + 'priority-mode', + 'tag', + 'queue-id', + 'tstamp', + 'src-addr', + 'dst-addr', +) methods = () signals = ()