]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: queue-timer-alsa: add class for queue timer specialized to ALSA Timer
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 1 Jun 2022 02:35:44 +0000 (11:35 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Thu, 2 Jun 2022 09:33:12 +0000 (18:33 +0900)
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 <o-takashi@sakamocchi.jp>
src/seq/alsaseq.h
src/seq/alsaseq.map
src/seq/meson.build
src/seq/privates.h
src/seq/queue-timer-alsa.c [new file with mode: 0644]
src/seq/queue-timer-alsa.h [new file with mode: 0644]
src/seq/queue-timer-common.c
tests/alsaseq-queue-timer-alsa [new file with mode: 0644]
tests/meson.build

index 148cbc33a1e91d2c9b9f1bc644c4f0f3a539b154..4164b414a70a9e9a49936339fb6c9644689a787a 100644 (file)
@@ -32,6 +32,7 @@
 #include <queue-tempo.h>
 #include <queue-timer-data-alsa.h>
 #include <queue-timer.h>
+#include <queue-timer-alsa.h>
 
 #include <user-client.h>
 
index 3a1fd30d012f8dae53992fdde4413c9357584088..446f31fc533e9e3b0284fb6a3fef207093dc4db2 100644 (file)
@@ -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;
index bec7739536455436c3aa57cb461194c89a76abb5..ed52440a2a73ebac2b403deacdd7e29c65f41be5 100644 (file)
@@ -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(
index 37d3542cf33df823c655daae04f9aa6a8ef22d48..c0c6a6650c7613dc3c5eeba965ffc901b55134a3 100644 (file)
@@ -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 (file)
index 0000000..077958a
--- /dev/null
@@ -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 (file)
index 0000000..080e0ad
--- /dev/null
@@ -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 <alsaseq.h>
+#include <alsatimer.h>
+
+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
index cf13b1947ce6ae5637946293e5ebcf894d325a9e..e21734b4fa0b7313d2246939a22eeb2ee7fe3f42 100644 (file)
@@ -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 (file)
index 0000000..afba868
--- /dev/null
@@ -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)
index f427f0afbb902719b58e2de5c4758af1d9aa5293..6df94d53c7f4677ca04ba756bbd1958deb408d22 100644 (file)
@@ -36,6 +36,7 @@ tests = {
     'alsaseq-queue-status',
     'alsaseq-queue-tempo',
     'alsaseq-queue-timer',
+    'alsaseq-queue-timer-alsa',
     'alsaseq-event-cntr',
   ],
   'hwdep': [