From: Takashi Sakamoto Date: Wed, 1 Jun 2022 02:35:44 +0000 (+0900) Subject: seq: queue-timer-alsa: add class for queue timer specialized to ALSA Timer X-Git-Tag: v0.3.0~109 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=c430e11d35664455a38961cbe2d98bab3f48db76;p=alsa-gobject.git seq: queue-timer-alsa: add class for queue timer specialized to ALSA Timer One of the backend timer for queue is an instance of timer in ALSA Timer. This commit adds gobject class for the type of queue timer. It has two properties; the identifier of timer and the count of ticks as resolution. Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.h b/src/seq/alsaseq.h index 148cbc3..4164b41 100644 --- a/src/seq/alsaseq.h +++ b/src/seq/alsaseq.h @@ -32,6 +32,7 @@ #include #include #include +#include #include diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index 3a1fd30..446f31f 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -226,4 +226,7 @@ ALSA_GOBJECT_0_3_0 { "alsaseq_event_cntr_set_result_data"; "alsaseq_queue_timer_common_get_type"; + + "alsaseq_queue_timer_alsa_get_type"; + "alsaseq_queue_timer_alsa_new"; } ALSA_GOBJECT_0_2_0; diff --git a/src/seq/meson.build b/src/seq/meson.build index bec7739..ed52440 100644 --- a/src/seq/meson.build +++ b/src/seq/meson.build @@ -31,6 +31,7 @@ sources = files( 'remove-filter.c', 'event-cntr.c', 'queue-timer-common.c', + 'queue-timer-alsa.c', ) headers = files( @@ -56,6 +57,7 @@ headers = files( 'remove-filter.h', 'event-cntr.h', 'queue-timer-common.h', + 'queue-timer-alsa.h', ) privates = files( diff --git a/src/seq/privates.h b/src/seq/privates.h index 37d3542..c0c6a66 100644 --- a/src/seq/privates.h +++ b/src/seq/privates.h @@ -42,6 +42,20 @@ void seq_event_cntr_get_buf(ALSASeqEventCntr *self, gsize count, #define QUEUE_ID_PROP_NAME "queue-id" #define TIMER_TYPE_PROP_NAME "timer-type" +enum queue_timer_common_prop_type { + QUEUE_TIMER_COMMON_PROP_QUEUE_ID = 1, + QUEUE_TIMER_COMMON_PROP_TIMER_TYPE, + QUEUE_TIMER_COMMON_PROP_COUNT, +}; + +void queue_timer_common_class_override_properties(GObjectClass *gobject_class); + +void queue_timer_common_set_property(struct snd_seq_queue_timer *data, GObject *obj, guint id, + const GValue *val, GParamSpec *spec); + +void queue_timer_common_get_property(const struct snd_seq_queue_timer *data, GObject *obj, guint id, + GValue *val, GParamSpec *spec); + G_END_DECLS #endif diff --git a/src/seq/queue-timer-alsa.c b/src/seq/queue-timer-alsa.c new file mode 100644 index 0000000..077958a --- /dev/null +++ b/src/seq/queue-timer-alsa.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#include "privates.h" + +/** + * ALSASeqQueueTimerAlsa: + * An object to express queue timer specific to instance in ALSA Timer. + * + * A [class@GObject.Object] derived object class for queue timer specific to any instance in ALSA + * Timer. + */ +typedef struct { + struct snd_seq_queue_timer data; +} ALSASeqQueueTimerAlsaPrivate; + +static void queue_timer_common_iface_init(ALSASeqQueueTimerCommonInterface *iface); + +G_DEFINE_TYPE_WITH_CODE(ALSASeqQueueTimerAlsa, alsaseq_queue_timer_alsa, G_TYPE_OBJECT, + G_ADD_PRIVATE(ALSASeqQueueTimerAlsa) + G_IMPLEMENT_INTERFACE(ALSASEQ_TYPE_QUEUE_TIMER_COMMON, + queue_timer_common_iface_init)) + +enum queue_timer_alsa_prop_type { + QUEUE_TIMER_ALSA_PROP_DEVICE_ID = QUEUE_TIMER_COMMON_PROP_COUNT, + QUEUE_TIMER_ALSA_PROP_RESOLUTION_TICKS, + QUEUE_TIMER_ALSA_PROP_COUNT, +}; + +static void seq_queue_timer_alsa_set_property(GObject *obj, guint id, const GValue *val, + GParamSpec *spec) +{ + ALSASeqQueueTimerAlsa *self = ALSASEQ_QUEUE_TIMER_ALSA(obj); + ALSASeqQueueTimerAlsaPrivate *priv = alsaseq_queue_timer_alsa_get_instance_private(self); + struct snd_seq_queue_timer *data = &priv->data; + + switch (id) { + case QUEUE_TIMER_ALSA_PROP_DEVICE_ID: + { + const struct snd_timer_id *src = (const struct snd_timer_id *)g_value_get_boxed(val); + data->u.alsa.id = *src; + break; + } + case QUEUE_TIMER_ALSA_PROP_RESOLUTION_TICKS: + data->u.alsa.resolution = g_value_get_uint(val); + break; + default: + queue_timer_common_set_property(data, obj, id, val, spec); + break; + } +} + +static void seq_queue_timer_alsa_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSASeqQueueTimerAlsa *self = ALSASEQ_QUEUE_TIMER_ALSA(obj); + ALSASeqQueueTimerAlsaPrivate *priv = alsaseq_queue_timer_alsa_get_instance_private(self); + const struct snd_seq_queue_timer *data = &priv->data; + + switch (id) { + case QUEUE_TIMER_ALSA_PROP_DEVICE_ID: + g_value_set_static_boxed(val, &data->u.alsa.id); + break; + case QUEUE_TIMER_ALSA_PROP_RESOLUTION_TICKS: + g_value_set_uint(val, data->u.alsa.resolution); + break; + default: + queue_timer_common_get_property(data, obj, id, val, spec); + break; + } +} + +static void alsaseq_queue_timer_alsa_class_init(ALSASeqQueueTimerAlsaClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = seq_queue_timer_alsa_set_property; + gobject_class->get_property = seq_queue_timer_alsa_get_property; + + queue_timer_common_class_override_properties(gobject_class); + + /** + * ALSASeqQueueTimerAlsa:device-id: + * + * The identifier of associated timer instance in ALSA Timer. + * + * Since: 0.3. + */ + g_object_class_install_property(gobject_class, QUEUE_TIMER_ALSA_PROP_DEVICE_ID, + g_param_spec_boxed("device-id", "device-id", + "The identifier of associated timer instance in ALSA Timer", + ALSATIMER_TYPE_DEVICE_ID, + G_PARAM_READWRITE)); + + /** + * ALSASeqQueueTimerAlsa:resolution-ticks: + * + * The number of ticks as resolution of timer. + * + * Since: 0.3. + */ + g_object_class_install_property(gobject_class, QUEUE_TIMER_ALSA_PROP_RESOLUTION_TICKS, + g_param_spec_uint("resolution-ticks", "resolution-ticks", + "The number of ticks as resolution of timer.", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE)); +} + +static void alsaseq_queue_timer_alsa_init(ALSASeqQueueTimerAlsa *self) +{ + return; +} + +static void queue_timer_common_iface_init(ALSASeqQueueTimerCommonInterface *iface) +{ + return; +} + +/** + * alsaseq_queue_timer_alsa_new: + * + * Allocate and return an instance of [class@QueueTimerAlsa]. + * + * Returns: An instance of [class@QueueTimerAlsa]. + */ +ALSASeqQueueTimerAlsa *alsaseq_queue_timer_alsa_new() +{ + return g_object_new(ALSASEQ_TYPE_QUEUE_TIMER_ALSA, NULL); +} diff --git a/src/seq/queue-timer-alsa.h b/src/seq/queue-timer-alsa.h new file mode 100644 index 0000000..080e0ad --- /dev/null +++ b/src/seq/queue-timer-alsa.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#ifndef __ALSA_GOBJECT_ALSASEQ_QUEUE_TIMER_ALSA_H__ +#define __ALSA_GOBJECT_ALSASEQ_QUEUE_TIMER_ALSA_H__ + +#include +#include + +G_BEGIN_DECLS + +#define ALSASEQ_TYPE_QUEUE_TIMER_ALSA (alsaseq_queue_timer_alsa_get_type()) + +G_DECLARE_DERIVABLE_TYPE(ALSASeqQueueTimerAlsa, alsaseq_queue_timer_alsa, ALSASEQ, QUEUE_TIMER_ALSA, GObject) + +struct _ALSASeqQueueTimerAlsaClass { + GObjectClass parent_class; +}; + +ALSASeqQueueTimerAlsa *alsaseq_queue_timer_alsa_new(); + +G_END_DECLS + +#endif diff --git a/src/seq/queue-timer-common.c b/src/seq/queue-timer-common.c index cf13b19..e21734b 100644 --- a/src/seq/queue-timer-common.c +++ b/src/seq/queue-timer-common.c @@ -44,3 +44,44 @@ static void alsaseq_queue_timer_common_default_init(ALSASeqQueueTimerCommonInter ALSASEQ_TYPE_QUEUE_TIMER_TYPE, ALSASEQ_QUEUE_TIMER_TYPE_ALSA, G_PARAM_READABLE)); } + +void queue_timer_common_class_override_properties(GObjectClass *gobject_class) +{ + g_object_class_override_property(gobject_class, QUEUE_TIMER_COMMON_PROP_QUEUE_ID, + QUEUE_ID_PROP_NAME); + + g_object_class_override_property(gobject_class, QUEUE_TIMER_COMMON_PROP_TIMER_TYPE, + TIMER_TYPE_PROP_NAME); +} + +void queue_timer_common_set_property(struct snd_seq_queue_timer *data, GObject *obj, guint id, + const GValue *val, GParamSpec *spec) +{ + switch (id) { + case QUEUE_TIMER_COMMON_PROP_QUEUE_ID: + data->queue = (int)g_value_get_uchar(val); + break; + case QUEUE_TIMER_COMMON_PROP_TIMER_TYPE: + data->type = (int)g_value_get_enum(val); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} + +void queue_timer_common_get_property(const struct snd_seq_queue_timer *data, GObject *obj, guint id, + GValue *val, GParamSpec *spec) +{ + switch (id) { + case QUEUE_TIMER_COMMON_PROP_QUEUE_ID: + g_value_set_uchar(val, (guchar)data->queue); + break; + case QUEUE_TIMER_COMMON_PROP_TIMER_TYPE: + g_value_set_enum(val, (ALSASeqQueueTimerType)data->type); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} diff --git a/tests/alsaseq-queue-timer-alsa b/tests/alsaseq-queue-timer-alsa new file mode 100644 index 0000000..afba868 --- /dev/null +++ b/tests/alsaseq-queue-timer-alsa @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from sys import exit +from errno import ENXIO + +from helper import test + +import gi +gi.require_version('ALSASeq', '0.0') +from gi.repository import ALSASeq + +target = ALSASeq.QueueTimerAlsa() +props = ( + 'queue-id', + 'timer-type', + 'device-id', + 'resolution-ticks', +) + +methods = ( + 'new', +) + +signals = () + +if not test(target, props, methods, signals): + exit(ENXIO) diff --git a/tests/meson.build b/tests/meson.build index f427f0a..6df94d5 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -36,6 +36,7 @@ tests = { 'alsaseq-queue-status', 'alsaseq-queue-tempo', 'alsaseq-queue-timer', + 'alsaseq-queue-timer-alsa', 'alsaseq-event-cntr', ], 'hwdep': [