[gnome-robots/arnaudb/use-gsound] Use GSound.



commit ac2e8e7e732a03457a4ec3e9926594630ffccafa
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jul 25 18:08:20 2019 +0200

    Use GSound.
    
    Instead of Canberra.

 build-aux/org.gnome.Robots.json | 10 +++++++++-
 meson.build                     |  8 ++++----
 src/meson.build                 | 10 +++++-----
 src/sound.c                     | 35 +++++++++++++++++++++++------------
 src/sound.h                     |  2 +-
 5 files changed, 42 insertions(+), 23 deletions(-)
---
diff --git a/build-aux/org.gnome.Robots.json b/build-aux/org.gnome.Robots.json
index b0f3fb6..7a3ddd4 100644
--- a/build-aux/org.gnome.Robots.json
+++ b/build-aux/org.gnome.Robots.json
@@ -43,6 +43,14 @@
                 }
             ]
         },
+        {
+            "name" : "gsound",
+            "buildsystem" : "autotools",
+            "sources" : [{
+                "type" : "git",
+                "url" : "https://gitlab.gnome.org/GNOME/gsound.git";
+            }]
+        },
         {
             "name": "gnome-robots",
             "buildsystem": "meson",
@@ -52,4 +60,4 @@
             }]
         }
     ]
-}
\ No newline at end of file
+}
diff --git a/meson.build b/meson.build
index 628ad39..734ae7b 100644
--- a/meson.build
+++ b/meson.build
@@ -7,12 +7,12 @@ i18n = import('i18n')
 
 application_id = 'org.gnome.Robots'
 
-gtk_dependency = dependency('gtk+-3.0', version: '>= 3.15.0')
-glib_dependency = dependency('glib-2.0', version: '>= 2.32')
 gio_dependency = dependency('gio-2.0', version: '>= 2.32')
-rsvg_dependency = dependency('librsvg-2.0', version: '>= 2.36.2')
+glib_dependency = dependency('glib-2.0', version: '>= 2.32')
 gnome_games_dependency = dependency('libgnome-games-support-1')
-canberra_gtk3_dependency = dependency('libcanberra-gtk3', version: '>= 0.26')
+gsound_dependency = dependency('gsound', version: '>= 1.0.2')
+gtk_dependency = dependency('gtk+-3.0', version: '>= 3.15.0')
+rsvg_dependency = dependency('librsvg-2.0', version: '>= 2.36.2')
 
 pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
 
diff --git a/src/meson.build b/src/meson.build
index d2b1935..c26cefd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -28,12 +28,12 @@ executable(
     sources + resources,
     config_header,
     dependencies: [
-        gtk_dependency,
-        glib_dependency,
         gio_dependency,
-        rsvg_dependency,
+        glib_dependency,
         gnome_games_dependency,
-        canberra_gtk3_dependency
+        gsound_dependency,
+        gtk_dependency,
+        rsvg_dependency
     ],
     c_args: [
         '-DHAVE_CONFIG_H',
@@ -41,4 +41,4 @@ executable(
     ],
     install_dir: get_option('bindir'),
     install: true
-)
\ No newline at end of file
+)
diff --git a/src/sound.c b/src/sound.c
index 254ceb1..d433910 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -21,7 +21,7 @@
 #include <config.h>
 
 #include <gdk/gdk.h>
-#include <canberra-gtk.h>
+#include <gsound.h>
 
 #include "gbdefs.h"
 #include "sound.h"
@@ -54,16 +54,13 @@ init_sound (void)
  *
  * Description:
  * Plays a game sound
- *
- * Returns:
- * TRUE on success FALSE otherwise
  **/
-gboolean
+void
 play_sound (gint sno)
 {
 
   if ((sno < 0) || (sno >= NUM_SOUNDS)) {
-    return FALSE;
+    return;
   }
 
   if (properties_sound ()) {
@@ -93,20 +90,34 @@ play_sound (gint sno)
     if (name)
     {
       gchar *filename, *path;
+      GSoundContext *ctx;
+      GError *error = NULL;
+
+      ctx = gsound_context_new(NULL, &error);
+      if (error != NULL) {
+        g_warning ("Failed to create gsound context: %s", error->message);
+        g_error_free (error);
+        return;
+      }
 
       filename = g_strdup_printf ("%s.ogg", name);
       path = g_build_filename (SOUND_DIRECTORY, filename, NULL);
       g_free (filename);
 
-      ca_context_play (ca_gtk_context_get_for_screen (gdk_screen_get_default ()),
-                      0,
-                      CA_PROP_MEDIA_NAME, name,
-                      CA_PROP_MEDIA_FILENAME, path, NULL);
+      gsound_context_play_simple(ctx, NULL, &error,
+                                 GSOUND_ATTR_MEDIA_NAME, name,
+                                 GSOUND_ATTR_MEDIA_FILENAME, path,
+                                 NULL);
+
+      if (error != NULL) {
+        g_warning ("Failed to play sound \"%s\": %s", name, error->message);
+        g_error_free (error);
+      }
+
+      g_object_unref (ctx);
       g_free (path);
     }
   }
-
-  return TRUE;
 }
 
 /**********************************************************************/
diff --git a/src/sound.h b/src/sound.h
index 750a2d1..837687c 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -19,7 +19,7 @@
 /* Exported functions                                                 */
 /**********************************************************************/
 gboolean init_sound (void);
-gboolean play_sound (gint);
+void     play_sound (gint);
 /**********************************************************************/
 
 #endif /* SOUND_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]