[gweled] 35/72: Merge revision 65: Sound handling rewritten.

Stephen Kitt skitt at moszumanska.debian.org
Thu May 26 16:55:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

skitt pushed a commit to branch debian-sid
in repository gweled.

commit 1af2985df63e3831cbab95dd05d492cb932d4784
Author: Ondřej Surý <ondrej at sury.org>
Date:   Fri Aug 6 09:18:34 2010 +0200

    Merge revision 65: Sound handling rewritten.
    
    Now open audio device only if sound or music are enabled.
    Do not segfault on audio errors. This fix bug #345304 and bug #614135.
    
    (Closes: #588694)
---
 debian/patches/002-release-sound-if-not-used.patch | 631 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 2 files changed, 632 insertions(+)

diff --git a/debian/patches/002-release-sound-if-not-used.patch b/debian/patches/002-release-sound-if-not-used.patch
new file mode 100644
index 0000000..3491807
--- /dev/null
+++ b/debian/patches/002-release-sound-if-not-used.patch
@@ -0,0 +1,631 @@
+=== modified file 'src/Makefile.am'
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -21,7 +21,7 @@ gweled_SOURCES = \
+ 	graphic_engine.c graphic_engine.h \
+ 	sge_core.c sge_core.h \
+ 	sge_utils.c sge_utils.h \
+-	music.c music.h \
++	sound.c sound.h \
+ 	games-score.c games-score.h \
+ 	games-scores.c games-scores.h \
+ 	games-scores-backend.c games-scores-backend.h \
+--- a/src/board_engine.c
++++ b/src/board_engine.c
+@@ -30,7 +30,6 @@
+ #include <gtk/gtk.h>
+ #include <glib/gprintf.h>
+ #include <glib/gi18n-lib.h>
+-#include <mikmod.h>
+ 
+ #include "games-scores.h"
+ 
+@@ -39,6 +38,7 @@
+ #include "sge_core.h"
+ #include "board_engine.h"
+ #include "graphic_engine.h"
++#include "sound.h"
+ 
+ #define FIRST_BONUS_AT	100	// needs tweaking
+ #define NB_BONUS_GEMS	8	// same
+@@ -62,8 +62,6 @@ typedef struct s_alignment {
+ 	gint length;
+ } T_Alignment;
+ 
+-SAMPLE *swap_sfx;
+-
+ gint gi_score, gi_current_score, gi_game_running, gi_game_paused;
+ 
+ gint gi_total_gems_removed;
+@@ -595,8 +593,8 @@ board_engine_loop (gpointer data)
+ 				sge_object_move_to (g_gem_objects[x2][y2],
+ 						x1 * prefs.tile_size,
+ 						y1 * prefs.tile_size);
+-				if(swap_sfx && prefs.sounds_on == TRUE)
+-				Sample_Play(swap_sfx, 0, 0);
++				if(prefs.sounds_on == TRUE)
++				    sound_play_sample(SWAP_EVENT);
+ 				gi_state = _SECOND_GEM_CLICKED;
+ 			} else if((x1 == x2) && (y1 == y2)) {
+ 				if (cursor[1])
+--- a/src/callbacks.c
++++ b/src/callbacks.c
+@@ -24,10 +24,9 @@
+ 
+ #include <gtk/gtk.h>
+ #include <glib/gi18n-lib.h>
+-#include <mikmod.h>
+ 
+ #include "main.h"
+-#include "music.h"
++#include "sound.h"
+ #include "sge_core.h"
+ #include "board_engine.h"
+ #include "graphic_engine.h"
+@@ -43,6 +42,8 @@ extern GtkWidget *g_score_window;
+ extern GtkWidget *g_drawing_area;
+ extern GdkPixmap *g_buffer_pixmap;
+ extern GtkWidget *g_menu_pause;
++extern GtkWidget *g_pref_music_button;
++extern GtkWidget *g_pref_sounds_button;
+ 
+ extern gint gi_gem_clicked;
+ extern gint gi_x_click;
+@@ -55,8 +56,6 @@ extern gint gi_y_drag;
+ extern guint board_engine_id;
+ extern GweledPrefs prefs;
+ 
+-SAMPLE *click_sfx;
+-
+ static gint gi_dragging = 0;
+ 
+ void
+@@ -207,8 +206,8 @@ drawing_area_button_event_cb (GtkWidget 
+ 			gi_gem_clicked = -1;
+ 			gi_dragging = -1;
+ 
+-			if(click_sfx && prefs.sounds_on == TRUE)
+-				Sample_Play(click_sfx, 0, 0);
++			if(prefs.sounds_on)
++			    sound_play_sample(CLICK_EVENT);
+ 		}
+ 		break;
+ 
+@@ -385,10 +384,20 @@ void
+ on_music_checkbutton_toggled (GtkToggleButton * togglebutton, gpointer user_data)
+ {
+ 	if (gtk_toggle_button_get_active (togglebutton)) {
+-		music_play();
+-	}
+-	else {
+-		music_stop();
++	    prefs.music_on = TRUE;
++	    if(sound_get_enabled() == FALSE) {
++	        sound_init();
++		    if(sound_get_enabled() == FALSE) {
++	            gtk_widget_set_sensitive(g_pref_music_button, FALSE);
++	            gtk_widget_set_sensitive(g_pref_sounds_button, FALSE);
++	        }
++		}
++		sound_music_play();
++	} else {
++	    prefs.music_on = FALSE;
++		sound_music_stop();
++		if(prefs.sounds_on == FALSE)
++		    sound_destroy();
+ 	}
+ }
+ 
+@@ -396,9 +405,19 @@ void
+ on_sounds_checkbutton_toggled (GtkToggleButton * togglebutton, gpointer user_data)
+ {
+ 	if (gtk_toggle_button_get_active (togglebutton)) {
+-		prefs.sounds_on = TRUE;
+-	}
+-	else {
++ 		prefs.sounds_on = TRUE;
++		if(sound_get_enabled() == FALSE) {
++	        sound_init();
++		    if(sound_get_enabled() == FALSE) {
++	            gtk_widget_set_sensitive(g_pref_music_button, FALSE);
++	            gtk_widget_set_sensitive(g_pref_sounds_button, FALSE);
++	        }
++		}
++		sound_load_samples();
++	} else {
+ 		prefs.sounds_on = FALSE;
+-	}
++		sound_unload_samples();
++		if(prefs.music_on == FALSE)
++		    sound_destroy();
++        }
+ }
+--- a/src/main.c
++++ b/src/main.c
+@@ -33,13 +33,10 @@
+ #include "games-scores.h"
+ #include "games-scores-dialog.h"
+ 
+-#include <pthread.h>
+-#include <mikmod.h>
+-
+ #include "sge_core.h"
+ #include "board_engine.h"
+ #include "graphic_engine.h"
+-#include "music.h"
++#include "sound.h"
+ #include "main.h"
+ 
+ // GLOBALS
+@@ -53,13 +50,14 @@ GtkWidget *g_progress_bar;
+ GtkWidget *g_score_label;
+ GtkWidget *g_bonus_label;
+ GtkWidget *g_menu_pause;
++GtkWidget *g_pref_music_button;
++GtkWidget *g_pref_sounds_button;
+ GdkPixmap *g_buffer_pixmap = NULL;
+ GRand *g_random_generator;
+ 
+ guint board_engine_id;
+ 
+ GweledPrefs prefs;
+-pthread_t thread;
+ 
+ static const GamesScoresCategory scorecats[] = {
+   {"Normal", NC_("game type", "Normal")  },
+@@ -68,8 +66,6 @@ static const GamesScoresCategory scoreca
+ 
+ GamesScores *highscores;
+ 
+-SAMPLE *swap_sfx, *click_sfx;
+-
+ extern gint gi_game_running;
+ 
+ void save_preferences(void)
+@@ -262,14 +258,6 @@ show_hiscores (gint pos, gboolean endofg
+   return result;
+ }
+ 
+-void mikmod_thread(void *ptr)
+-{
+-	while (1) {
+-	    g_usleep(10000);
+-		MikMod_Update();
+-    }
+-}
+-
+ int main (int argc, char **argv)
+ {
+ 	GError* error = NULL;
+@@ -294,7 +282,6 @@ int main (int argc, char **argv)
+ 
+ 	gtk_window_set_default_icon_name ("gweled");
+ 
+-    music_init ();
+ 	sge_init ();
+ 
+ 	g_random_generator = g_rand_new_with_seed (time (NULL));
+@@ -312,6 +299,8 @@ int main (int argc, char **argv)
+     g_score_label = GTK_WIDGET (gtk_builder_get_object (gweled_xml, "scoreLabel"));
+     g_drawing_area = GTK_WIDGET (gtk_builder_get_object (gweled_xml, "boardDrawingarea"));
+     g_menu_pause = GTK_WIDGET (gtk_builder_get_object (gweled_xml, "pause1"));
++    g_pref_music_button = GTK_WIDGET (gtk_builder_get_object (gweled_xml, "music_checkbutton"));
++    g_pref_sounds_button = GTK_WIDGET (gtk_builder_get_object (gweled_xml, "sounds_checkbutton"));
+ 
+ 	load_preferences();
+ 	init_pref_window();
+@@ -339,29 +328,20 @@ int main (int argc, char **argv)
+ 
+ 	gi_game_running = 0;
+ 
+-	// load sound fx
+-    swap_sfx = Sample_Load(DATADIR "/sounds/gweled/swap.wav");
+-    if (!swap_sfx) {
+-        g_warning("Could not load swap.wav, reason: %s", MikMod_strerror(MikMod_errno));
+-
+-    }
+-    click_sfx = Sample_Load(DATADIR "/sounds/gweled/click.wav");
+-    if (!click_sfx) {
+-        g_warning("Could not load click.wav, reason: %s", MikMod_strerror(MikMod_errno));
+-    }
+-
+-    MikMod_SetNumVoices(-1, 4);
+-	Voice_SetVolume(0, 255);
+-	Voice_SetVolume(1, 255);
+-	Voice_SetVolume(2, 255);
+-	Voice_SetVolume(3, 255);
++	if(prefs.music_on || prefs.sounds_on) {
++	    sound_init();
++	    if(sound_get_enabled() == FALSE) {
++	        gtk_widget_set_sensitive(g_pref_music_button, FALSE);
++	        gtk_widget_set_sensitive(g_pref_sounds_button, FALSE);
++	    }
++	}
+ 
+-    MikMod_EnableOutput();
+ 
+-    pthread_create(&thread, NULL, (void *)&music_thread, NULL);
++	if (prefs.sounds_on)
++	    sound_load_samples();
+ 
+ 	if (prefs.music_on)
+-		music_play();
++	    sound_music_play();
+ 
+ 	sge_set_drawing_area (g_drawing_area, g_buffer_pixmap,
+ 			      BOARD_WIDTH * prefs.tile_size,
+@@ -372,7 +352,7 @@ int main (int argc, char **argv)
+ 
+ 	gtk_main ();
+ 
+-    MikMod_DisableOutput();
++    sound_destroy();
+ 
+ 	sge_destroy ();
+ 	if(board_engine_id)
+@@ -380,15 +360,6 @@ int main (int argc, char **argv)
+ 	g_rand_free (g_random_generator);
+ 	g_object_unref(G_OBJECT(gweled_xml));
+ 
+-	music_stop();
+-
+-	if(swap_sfx)
+-		Sample_Free(swap_sfx);
+-	if(click_sfx)
+-		Sample_Free(click_sfx);
+-
+-	MikMod_Exit();
+-
+ 	return 0;
+ }
+ 
+--- a/src/music.c
++++ /dev/null
+@@ -1,102 +0,0 @@
+-/* Gweled
+- *
+- * Copyright (C) 2003-2005 Sebastien Delestaing <sebastien.delestaing at wanadoo.fr>
+- * Copyright (C) 2010 Daniele Napolitano <dnax88 at gmail.com>
+- *
+- * This program is free software; you can redistribute it and/or
+- * modify it under the terms of the GNU General Public License
+- * as published by the Free Software Foundation; either version 2
+- * of the License, or (at your option) any later version.
+- *
+- * This program is distributed in the hope that it will be useful,
+- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+- * GNU General Public License for more details.
+- *
+- * You should have received a copy of the GNU General Public License
+- * along with this program; if not, write to the Free Software
+- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+- */
+-
+-#include <mikmod.h>
+-#include <pthread.h>
+-#include <glib.h>
+-
+-#include "music.h"
+-#include "board_engine.h"
+-
+-extern GweledPrefs prefs;
+-extern pthread_t thread;
+-
+-static MODULE *module;
+-static gboolean is_playing;
+-
+-void music_init()
+-{
+-    /* register all the drivers */
+-    MikMod_RegisterDriver(&drv_AF);
+-    MikMod_RegisterDriver(&drv_esd);
+-    MikMod_RegisterDriver(&drv_alsa);
+-    MikMod_RegisterDriver(&drv_oss);
+-    MikMod_RegisterDriver(&drv_nos);
+-
+-    /* register all the module loaders */
+-    MikMod_RegisterAllLoaders();
+-
+-    /* initialize the library */
+-    if (MikMod_Init(""))
+-	{
+-        fprintf(stderr, "Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
+-        //return; don't fail on sound problems
+-    }
+-    is_playing = FALSE;
+-
+-}
+-
+-void music_thread(void *ptr)
+-{
+-	while (1) {
+-	    g_usleep(10000);
+-		MikMod_Update();
+-    }
+-}
+-
+-void music_play()
+-{
+-	if (!music_isplaying())
+-	{
+-	    // load module
+-	    module = Player_Load(DATADIR "/sounds/gweled/autonom.s3m", 64, 0);
+-    	if (module) {
+-    	    Player_Start(module);
+-			Player_SetVolume(64);
+-			pthread_create(&thread, NULL, (void *)&music_thread, NULL);
+-			prefs.music_on = TRUE;
+-			is_playing = TRUE;
+-
+-    	} else
+-    	    fprintf(stderr, "Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno));
+-	}
+-}
+-
+-void music_stop()
+-{
+-	if (music_isplaying()){
+-    	if (module)
+-		{
+-	    	Player_Stop();
+-	    	Player_Free(module);
+-			pthread_cancel(thread);
+-			pthread_join(thread, NULL);
+-	    	prefs.music_on = FALSE;
+-	    	is_playing = FALSE;
+-		}
+-	}
+-
+-}
+-
+-gboolean music_isplaying()
+-{
+-	return is_playing;
+-}
+-
+--- /dev/null
++++ b/src/sound.c
+@@ -0,0 +1,168 @@
++/* Gweled
++ *
++ * Copyright (C) 2003-2005 Sebastien Delestaing <sebastien.delestaing at wanadoo.fr>
++ * Copyright (C) 2010 Daniele Napolitano <dnax88 at gmail.com>
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version 2
++ * of the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
++ */
++
++#include <mikmod.h>
++#include <pthread.h>
++#include <glib.h>
++
++#include "sound.h"
++#include "board_engine.h"
++
++static pthread_t thread;
++
++static MODULE *module;
++static SAMPLE *swap_sfx = NULL;
++static SAMPLE *click_sfx = NULL;
++
++static gboolean is_playing;
++static gboolean sound_available;
++
++void sound_thread(void *ptr)
++{
++	while (1) {
++	    g_usleep(10000);
++		MikMod_Update();
++    }
++}
++
++void sound_init()
++{
++    /* register all the drivers */
++    MikMod_RegisterDriver(&drv_esd);
++    MikMod_RegisterDriver(&drv_alsa);
++    MikMod_RegisterDriver(&drv_oss);
++    MikMod_RegisterDriver(&drv_nos);
++
++    /* register all the module loaders */
++    MikMod_RegisterAllLoaders();
++
++    /* initialize the library */
++    if (MikMod_Init("")) {
++        g_printerr("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
++        MikMod_Exit();
++        sound_available = FALSE;
++    } else {
++        sound_available = TRUE;
++        MikMod_EnableOutput();
++        pthread_create(&thread, NULL, (void *)&sound_thread, NULL);
++        g_print("Audio driver choosen: %s\n", md_driver->Name);
++    }
++
++    is_playing = FALSE;
++
++}
++
++void sound_music_play()
++{
++	if (!is_playing && sound_available) {
++	    // load module
++	    module = Player_Load(DATADIR "/sounds/gweled/autonom.s3m", 64, 0);
++    	if (module) {
++    	    Player_Start(module);
++			Player_SetVolume(64);
++			is_playing = TRUE;
++
++    	} else
++    	    fprintf(stderr, "Could not load module, reason: %s\n", MikMod_strerror(MikMod_errno));
++	}
++}
++
++void sound_music_stop()
++{
++	if (is_playing && sound_available) {
++    	if (module)
++		{
++	    	Player_Stop();
++	    	Player_Free(module);
++	    	is_playing = FALSE;
++		}
++	}
++}
++
++// load sound fx
++void sound_load_samples()
++{
++    if (sound_available == FALSE)
++        return;
++
++    if (!swap_sfx)
++        swap_sfx = Sample_Load(DATADIR "/sounds/gweled/swap.wav");
++    if (!swap_sfx)
++        g_warning("Could not load swap.wav, reason: %s", MikMod_strerror(MikMod_errno));
++
++    if (!click_sfx)
++        click_sfx = Sample_Load(DATADIR "/sounds/gweled/click.wav");
++    if (!click_sfx)
++        g_warning("Could not load click.wav, reason: %s", MikMod_strerror(MikMod_errno));
++
++    MikMod_SetNumVoices(-1, 2);
++}
++
++void sound_unload_samples()
++{
++    if (swap_sfx) {
++		Sample_Free(swap_sfx);
++		swap_sfx = NULL;
++	}
++	if (click_sfx) {
++		Sample_Free(click_sfx);
++		click_sfx = NULL;
++	}
++}
++
++// play sound fx
++void sound_play_sample(gweled_sound_samples sample)
++{
++    if (sound_available == FALSE)
++        return;
++
++    switch (sample) {
++        case CLICK_EVENT:
++            if(click_sfx)
++                Sample_Play(click_sfx, 0, 0);
++            break;
++        case SWAP_EVENT:
++            if(swap_sfx)
++                Sample_Play(swap_sfx, 0, 0);
++            break;
++    }
++}
++
++void sound_destroy()
++{
++    if (sound_available) {
++        sound_music_stop();
++
++        pthread_cancel(thread);
++        pthread_join(thread, NULL);
++
++        sound_unload_samples();
++
++        MikMod_DisableOutput();
++	    MikMod_Exit();
++
++	    sound_available = FALSE;
++	}
++}
++
++gboolean sound_get_enabled()
++{
++    return sound_available;
++}
+--- a/src/music.h
++++ /dev/null
+@@ -1,27 +0,0 @@
+-/* Gweled
+- *
+- * Copyright (C) 2003-2005 Sebastien Delestaing <sebastien.delestaing at wanadoo.fr>
+- * Copyright (C) 2010 Daniele Napolitano <dnax88 at gmail.com>
+- *
+- * This program is free software; you can redistribute it and/or
+- * modify it under the terms of the GNU General Public License
+- * as published by the Free Software Foundation; either version 2
+- * of the License, or (at your option) any later version.
+- *
+- * This program is distributed in the hope that it will be useful,
+- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+- * GNU General Public License for more details.
+- *
+- * You should have received a copy of the GNU General Public License
+- * along with this program; if not, write to the Free Software
+- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+- */
+-
+-#include <mikmod.h>
+-
+-void music_init();
+-void music_thread(void *ptr);
+-void music_play();
+-void music_stop();
+-int music_isplaying();
+--- /dev/null
++++ b/src/sound.h
+@@ -0,0 +1,41 @@
++/* Gweled
++ *
++ * Copyright (C) 2003-2005 Sebastien Delestaing <sebastien.delestaing at wanadoo.fr>
++ * Copyright (C) 2010 Daniele Napolitano <dnax88 at gmail.com>
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version 2
++ * of the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
++ */
++
++#ifndef _SOUND_H_
++#define _SOUND_H_
++
++#include <glib.h>
++
++typedef enum e_gweled_sound_samples
++{
++    CLICK_EVENT,
++    SWAP_EVENT
++} gweled_sound_samples;
++
++void sound_init(void);
++void sound_music_play(void);
++void sound_music_stop(void);
++void sound_load_samples(void);
++void sound_unload_samples(void);
++void sound_play_sample(gweled_sound_samples sample);
++void sound_destroy(void);
++gboolean sound_get_enabled();
++
++#endif
diff --git a/debian/patches/series b/debian/patches/series
index a963690..416c853 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 001-potfiles.patch
+002-release-sound-if-not-used.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/gweled.git



More information about the Pkg-games-commits mailing list