[quadrapassel/arnaudb/use-gsound] Use GSound.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [quadrapassel/arnaudb/use-gsound] Use GSound.
- Date: Thu, 25 Jul 2019 11:11:40 +0000 (UTC)
commit a7518b60377bb4a7ba0d6780cabfea77b1cd1af2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jul 25 12:42:04 2019 +0200
Use GSound.
Instead of Canberra.
flatpak/org.gnome.Quadrapassel.json | 10 ++++++
meson.build | 11 +++---
src/game-view.vala | 69 +++++++++++++++++++++++++++++++------
src/meson.build | 5 ++-
4 files changed, 75 insertions(+), 20 deletions(-)
---
diff --git a/flatpak/org.gnome.Quadrapassel.json b/flatpak/org.gnome.Quadrapassel.json
index e570b32..0bf7aab 100644
--- a/flatpak/org.gnome.Quadrapassel.json
+++ b/flatpak/org.gnome.Quadrapassel.json
@@ -25,6 +25,16 @@
"/share/dbus-1", "/share/doc", "/share/gir-1.0"
],
"modules": [
+ {
+ "name" : "gsound",
+ "buildsystem" : "autotools",
+ "sources" : [
+ {
+ "type" : "git",
+ "url" : "https://gitlab.gnome.org/GNOME/gsound.git"
+ }
+ ]
+ },
{
"name": "libevdev",
"sources": [
diff --git a/meson.build b/meson.build
index c9c6023..f7e2535 100644
--- a/meson.build
+++ b/meson.build
@@ -2,18 +2,18 @@ project('quadrapassel', 'vala', 'c',
version: '3.32.0')
project_id = 'org.gnome.Quadrapassel'
-i18n = import('i18n')
+
# used to install help
gnome = import('gnome')
+# used for internationalization
+i18n = import('i18n')
# used to run post install script
python3 = import('python3')
-
-canberra_dependency = dependency('libcanberra')
-canberra_gtk3_dependency = dependency('libcanberra-gtk3', version: '>= 0.26')
-cogl_dependency = dependency('cogl-1.0')
clutter_dependency = dependency('clutter-1.0', version: '>= 1.0.0')
clutter_gtk_dependency = dependency('clutter-gtk-1.0', version: '>= 0.91.6')
+cogl_dependency = dependency('cogl-1.0')
+gsound_dependency = dependency('gsound', version: '>= 1.0.2')
gtk_dependency = dependency('gtk+-3.0', version: '>= 3.12.0')
manette_dependency = dependency('manette-0.2', version: '>= 0.2.0')
pango_depepdency = dependency('pango')
@@ -21,7 +21,6 @@ pango_cairo_dependency = dependency('pangocairo')
posix_dependency = meson.get_compiler('vala').find_library('posix')
rsvg_dependency = dependency('librsvg-2.0', version: '>= 2.32.0')
-
# Set gettext package name
add_global_arguments('-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name()), language: 'c')
diff --git a/src/game-view.vala b/src/game-view.vala
index bd7e437..0564b01 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -57,9 +57,6 @@ public class GameView : GtkClutter.Embed
}
}
- /* false to play sound effects */
- public bool mute;
-
/* Theme to use */
public string theme
{
@@ -141,14 +138,6 @@ public class GameView : GtkClutter.Embed
}
}
- private void play_sound (string name)
- {
- if (!mute)
- CanberraGtk.play_for_widget (this, 0,
- Canberra.PROP_MEDIA_NAME, name,
- Canberra.PROP_MEDIA_FILENAME, Path.build_filename (SOUND_DIRECTORY,
"%s.ogg".printf (name)));
- }
-
private void shape_added_cb ()
{
shape = new Clutter.Actor ();
@@ -349,6 +338,64 @@ public class GameView : GtkClutter.Embed
else
text_overlay.text = null;
}
+
+ /*\
+ * * Sound
+ \*/
+
+ /* false to play sound effects */
+ internal bool mute { internal set; private get; default = true; }
+
+ private GSound.Context sound_context;
+ private SoundContextState sound_context_state = SoundContextState.INITIAL;
+
+ 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 (string name)
+ {
+ if (!mute)
+ {
+ if (sound_context_state == SoundContextState.INITIAL)
+ init_sound ();
+ if (sound_context_state == SoundContextState.WORKING)
+ _play_sound (name, sound_context);
+ }
+ }
+
+ private static void _play_sound (string _name, GSound.Context sound_context)
+ {
+ string name = _name + ".ogg";
+ 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);
+ }
+ }
}
private class BlockActor : Clutter.Clone
diff --git a/src/meson.build b/src/meson.build
index 88316e7..8696d9b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -18,11 +18,10 @@ executable(meson.project_name(),
'--vapidir', join_paths(meson.current_source_dir(), 'vapi')
],
dependencies: [
- canberra_dependency,
- canberra_gtk3_dependency,
- cogl_dependency,
clutter_dependency,
clutter_gtk_dependency,
+ cogl_dependency,
+ gsound_dependency,
gtk_dependency,
manette_dependency,
pango_depepdency,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]