[gnome-taquin/arnaudb/wip/gtk4: 105/108] Use Gtk for sounds.




commit 28ed9af20d6d79686eab161950c49c83d59cf61e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Apr 29 18:06:09 2020 +0200

    Use Gtk for sounds.

 COPYING.sounds                       |   3 +-
 data/{gameover.ogg => game-over.ogg} | Bin
 data/meson.build                     |   9 -----
 meson.build                          |   3 --
 src/meson.build                      |   1 -
 src/taquin-main.vala                 |  67 ++++++-----------------------------
 src/taquin.gresource.xml             |   5 +++
 src/vapi/config.vapi                 |   1 -
 8 files changed, 17 insertions(+), 72 deletions(-)
---
diff --git a/COPYING.sounds b/COPYING.sounds
index 566f51d..c5ba5c0 100644
--- a/COPYING.sounds
+++ b/COPYING.sounds
@@ -5,6 +5,7 @@ data/sliding-n.ogg
     originally named “ui_button_click.ogg” and “ui_button_longclick.ogg”
     see http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/mod/audio/interface/ui?order=name
 
-data/gameover.ogg
+data/game-over.ogg
     distributed under GPL v. 3 or later (see COPYING)
     originated from GNOME games (under GPL v. 2 or later)
+    originally named “gameover.ogg”
diff --git a/data/gameover.ogg b/data/game-over.ogg
similarity index 100%
rename from data/gameover.ogg
rename to data/game-over.ogg
diff --git a/data/meson.build b/data/meson.build
index 9eb1c79..8c5bfe6 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,12 +1,3 @@
-install_data(
-    [
-        'gameover.ogg',
-        'sliding-1.ogg',
-        'sliding-n.ogg'
-    ],
-    install_dir: soundsdir
-)
-
 # Make D-Bus activatable
 service_conf = configuration_data()
 service_conf.set('bindir', bindir)
diff --git a/meson.build b/meson.build
index 01dcfc8..c602278 100644
--- a/meson.build
+++ b/meson.build
@@ -15,7 +15,6 @@ valac = meson.get_compiler('vala')
 
 gio_dependency = dependency('gio-2.0', version: '>= 2.42.0')
 glib_dependency = dependency('glib-2.0', version: '>= 2.42.0')
-gsound_dependency = dependency('gsound', version: '>= 1.0.2')
 gtk_dependency = dependency('gtk4', version: '>= 3.99.1')
 libm_dependency = cc.find_library('m', required: false) # some platforms do not have libm separated from libc
 posix_dependency = valac.find_library('posix')
@@ -31,12 +30,10 @@ localedir   = join_paths(get_option('prefix'), get_option('localedir'))
 datadir     = join_paths(get_option('prefix'), get_option('datadir'))
 bindir      = join_paths(get_option('prefix'), get_option('bindir'))
 pkgdatadir  = join_paths(datadir, meson.project_name())
-soundsdir   = join_paths(pkgdatadir, 'sounds')
 
 conf = configuration_data ()
 conf.set_quoted('VERSION', meson.project_version())
 conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
-conf.set_quoted('SOUND_DIRECTORY', soundsdir)
 conf.set_quoted('LOCALEDIR', localedir)
 conf.set_quoted('DATA_DIRECTORY', pkgdatadir)
 
diff --git a/src/meson.build b/src/meson.build
index c9368d3..122804a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -45,7 +45,6 @@ executable(meson.project_name(),[
     ],
     dependencies: [
         glib_dependency,
-        gsound_dependency,
         gtk_dependency,
         libm_dependency,
         posix_dependency,
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index df76cbc..5a596a9 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -275,9 +275,6 @@ private class Taquin : Gtk.Application, BaseApplication
         // TODO window.add_action (settings.create_action ("size"));        // Problem: cannot use this way 
for an integer from a menu; works for radiobuttons in Iagno
         // TODO window.add_action (settings.create_action ("theme"));
 
-        if (settings.get_boolean ("sound"))
-            init_sound ();
-
         add_window (window);
     }
 
@@ -541,9 +538,6 @@ private class Taquin : Gtk.Application, BaseApplication
     * * Sound
     \*/
 
-    private GSound.Context sound_context;
-    private SoundContextState sound_context_state = SoundContextState.INITIAL;
-
     private enum Sound
     {
         SLIDING_1,
@@ -551,67 +545,26 @@ private class Taquin : Gtk.Application, BaseApplication
         GAME_OVER;
     }
 
-    private enum SoundContextState
-    {
-        INITIAL,
-        WORKING,
-        ERRORED;
-    }
-
-    private void init_sound ()
-     // requires (sound_context_state == SoundContextState.INITIAL)
-    {
-        try
-        {
-            sound_context = new GSound.Context ();
-            sound_context_state = SoundContextState.WORKING;
-        }
-        catch (Error e)
-        {
-            warning (e.message);
-            sound_context_state = SoundContextState.ERRORED;
-        }
-    }
-
     private void play_sound (Sound sound)
     {
         if (settings.get_boolean ("sound"))
-        {
-            if (sound_context_state == SoundContextState.INITIAL)
-                init_sound ();
-            if (sound_context_state == SoundContextState.WORKING)
-                _play_sound (sound, sound_context);
-        }
+            _play_sound (sound);
     }
 
-    private static void _play_sound (Sound sound, GSound.Context sound_context)
-     // requires (sound_context_state == SoundContextState.WORKING)
+    private MediaStream stream;     // for keeping in memory
+    private void _play_sound (Sound sound)
     {
         string name;
         switch (sound)
         {
-            case Sound.SLIDING_1:
-                name = "sliding-1.ogg";
-                break;
-            case Sound.SLIDING_N:
-                name = "sliding-n.ogg";
-                break;
-            case Sound.GAME_OVER:
-                name = "gameover.ogg";
-                break;
-            default:
-                return;
-        }
-        string path = Path.build_filename (SOUND_DIRECTORY, name);
-        try
-        {
-            sound_context.play_simple (null, GSound.Attribute.MEDIA_NAME, name,
-                                             GSound.Attribute.MEDIA_FILENAME, path);
-        }
-        catch (Error e)
-        {
-            warning (e.message);
+            case Sound.SLIDING_1:   name = "sliding-1"; break;
+            case Sound.SLIDING_N:   name = "sliding-n"; break;
+            case Sound.GAME_OVER:   name = "game-over"; break;
+            default: assert_not_reached ();
         }
+        stream = MediaFile.for_resource (@"/org/gnome/Taquin/sounds/$name.ogg");
+        stream.set_volume (1.0);
+        stream.play ();
     }
 
     /*\
diff --git a/src/taquin.gresource.xml b/src/taquin.gresource.xml
index 4ec58a3..1314d6a 100644
--- a/src/taquin.gresource.xml
+++ b/src/taquin.gresource.xml
@@ -4,6 +4,11 @@
     <file preprocess="to-pixdata" alias="15-Puzzle.png">../data/schema-15.png</file>
     <file preprocess="to-pixdata" alias="16-Puzzle.png">../data/schema-16.png</file>
   </gresource>
+  <gresource prefix="/org/gnome/Taquin/sounds">
+    <file alias="game-over.ogg">../data/game-over.ogg</file>
+    <file alias="sliding-1.ogg">../data/sliding-1.ogg</file>
+    <file alias="sliding-n.ogg">../data/sliding-n.ogg</file>
+  </gresource>
   <gresource prefix="/org/gnome/Taquin/ui">
     <file preprocess="xml-stripblanks" alias="adaptative-window.ui"             
../data/ui/adaptative-window.ui</file>
     <file preprocess="xml-stripblanks" alias="base-headerbar.ui"                
../data/ui/base-headerbar.ui</file>
diff --git a/src/vapi/config.vapi b/src/vapi/config.vapi
index 0ecd75c..22d36aa 100644
--- a/src/vapi/config.vapi
+++ b/src/vapi/config.vapi
@@ -21,5 +21,4 @@
 private const string VERSION;
 private const string GETTEXT_PACKAGE;
 private const string DATA_DIRECTORY;
-private const string SOUND_DIRECTORY;
 private const string LOCALEDIR;


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