]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi; add global method to get sysname for rawmidi device of sound card
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/alsarawmidi.map
src/rawmidi/query.c
src/rawmidi/query.h

index 589359aa82dee3f50f8e027a453aabcb9a7c2bd0..efe4be47e74dfc4b6c7d919442b26e6d68ed93a3 100644 (file)
@@ -4,6 +4,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsarawmidi_stream_pair_info_flag_get_type";
 
     "alsarawmidi_get_device_id_list";
+    "alsarawmidi_get_rawmidi_sysname";
   local:
     *;
 };
index 1f1371a2ef0d64e3d42e0151f5cc729c211bfc82..442a6cb1c1e65b87276c5c4b9b16f72e61752abf 100644 (file)
@@ -13,6 +13,7 @@ G_DEFINE_QUARK("alsarawmidi-error", alsarawmidi_error)
 
 // 'C' is required apart from emulation of Open Sound System.
 #define PREFIX_SYSNAME_TEMPLATE     "midiC%u"
+#define RAWMIDI_SYSNAME_TEMPLATE    "midiC%uD%u"
 
 static void prepare_udev_enum(struct udev_enumerate **enumerator, GError **error)
 {
@@ -195,3 +196,48 @@ end:
     g_free(prefix);
     release_udev_enum(enumerator);
 }
+
+/**
+ * alsarawmidi_get_rawmidi_sysname:
+ * @card_id: The numeridcal ID of sound card.
+ * @device_id: The numerical ID of rawmidi device for the sound card.
+ * @sysname: (out): The string for sysname of rawmidi device.
+ * @error: A #GError.
+ *
+ * Allocate sysname for rawmidi device and return it when it exists.
+ */
+void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id,
+                                     char **sysname, GError **error)
+{
+    unsigned int length;
+    char *name;
+    struct udev *ctx;
+    struct udev_device *dev;
+
+    length = strlen(RAWMIDI_SYSNAME_TEMPLATE) + calculate_digits(card_id) +
+             calculate_digits(device_id) + 1;
+    name = g_try_malloc0(length);
+    if (name == NULL) {
+        generate_error(error, ENOMEM);
+        return;
+    }
+    snprintf(name, length, RAWMIDI_SYSNAME_TEMPLATE, card_id, device_id);
+
+    ctx = udev_new();
+    if (ctx == NULL) {
+        generate_error(error, errno);
+        g_free(name);
+        return;
+    }
+
+    dev = udev_device_new_from_subsystem_sysname(ctx, "sound", name);
+    if (dev == NULL) {
+        generate_error(error, ENODEV);
+        g_free(name);
+    } else {
+        *sysname = name;
+        udev_device_unref(dev);
+    }
+
+    udev_unref(ctx);
+}
index bb7e5b2f62a1e5e521881532915df1d838e285a3..c853226c26aa5e79a06c317bc61dbdd1c9f2af54 100644 (file)
@@ -11,6 +11,9 @@ void alsarawmidi_get_device_id_list(guint card_id,
                                     guint **entries, gsize *entry_count,
                                     GError **error);
 
+void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id,
+                                     char **sysname, GError **error);
+
 G_END_DECLS
 
 #endif