[monkey-bubble: 736/753] replace gstreamer with libcanberra



commit 29b567fe78b89e5eb4f8293e5cfe2393eb4547fb
Author: Sven Herzberg <herzi gnome-de org>
Date:   Wed Jul 14 13:49:04 2010 +0200

    replace gstreamer with libcanberra
    
    * configure.in: update the dependencies
    * src/audio/Makefile.am,
    * src/audio/gst-mbmem-content.c,
    * src/audio/gst-mbmem-content.h,
    * src/audio/gst-mbmem-src.c,
    * src/audio/gst-mbmem-src.h,
    * src/audio/mb-audio-engine.c,
    * src/audio/mb-audio-engine.h,
    * src/audio/mb-music-bin.c,
    * src/audio/mb-music-bin.h,
    * src/audio/sound-manager.c,
    * src/audio/sound-manager.h: rewrite the internal audio engine
    * src/ui/main.c: drop gstreamer initialization
    * src/view/monkey-canvas.c: some code cleanup

 configure.in                  |    8 +-
 src/audio/Makefile.am         |    4 -
 src/audio/gst-mbmem-content.c |  265 -----------------------------------
 src/audio/gst-mbmem-content.h |   48 -------
 src/audio/gst-mbmem-src.c     |  175 -----------------------
 src/audio/gst-mbmem-src.h     |   74 ----------
 src/audio/mb-audio-engine.c   |  305 -----------------------------------------
 src/audio/mb-audio-engine.h   |   52 -------
 src/audio/mb-music-bin.c      |  175 -----------------------
 src/audio/mb-music-bin.h      |   43 ------
 src/audio/sound-manager.c     |  130 ++++++++++++------
 src/audio/sound-manager.h     |    3 +-
 src/ui/main.c                 |    2 -
 src/view/monkey-canvas.c      |   89 ++++++------
 14 files changed, 140 insertions(+), 1233 deletions(-)
---
diff --git a/configure.in b/configure.in
index 1dd4b1e..3d222d0 100644
--- a/configure.in
+++ b/configure.in
@@ -119,7 +119,8 @@ AC_SUBST(LIBMONKEYVIEW_A_LIBS)
 PKG_CHECK_MODULES(LIBMONKEYAUDIO_A,[
 	gtk+-2.0
 	gthread-2.0
-	gstreamer-0.10
+	libcanberra
+	libcanberra-gtk
 	])
 AC_SUBST(LIBMONKEYAUDIO_A_CFLAGS)
 AC_SUBST(LIBMONKEYAUDIO_A_LIBS)
@@ -137,9 +138,8 @@ PKG_CHECK_MODULES(UI,[
 	gtk+-2.0 >= 2.10
 	gthread-2.0
 	librsvg-2.0
-	gstreamer-0.10
-        gstreamer-base-0.10
-        gstreamer-controller-0.10
+	libcanberra
+	libcanberra-gtk
 	gconf-2.0
 	libglade-2.0
 	])
diff --git a/src/audio/Makefile.am b/src/audio/Makefile.am
index 9a194a7..d3a9774 100644
--- a/src/audio/Makefile.am
+++ b/src/audio/Makefile.am
@@ -10,9 +10,5 @@ noinst_LIBRARIES = libmonkeyaudio.a
 
 libmonkeyaudio_a_SOURCES = \
 	sound-manager.h sound-manager.c \
-	gst-mbmem-content.h gst-mbmem-content.c \
-	gst-mbmem-src.h gst-mbmem-src.c \
-	mb-audio-engine.h mb-audio-engine.c \
-	mb-music-bin.h mb-music-bin.c \
 	$(NULL)
 
diff --git a/src/audio/sound-manager.c b/src/audio/sound-manager.c
index 270fb7a..a551c4d 100644
--- a/src/audio/sound-manager.c
+++ b/src/audio/sound-manager.c
@@ -19,30 +19,50 @@
 #include <gtk/gtk.h>
 #include "sound-manager.h"
 #include "playground.h"
-#include <gst/gst.h>
-#include "mb-audio-engine.h"
+#include <canberra.h>
+
+enum
+{
+  PLAY_ID_0,
+  PLAY_ID_FX,
+  PLAY_ID_MUSIC
+};
 
 #define PRIVATE(sound_manager) (sound_manager->private)
 
 static GObjectClass* parent_class = NULL;
 
-struct SoundManagerPrivate {
-  MbAudioEngine * engine;
-  gchar ** samples_path;
-  gint current_music_id;
-  MbMusic current_music;
-  gboolean active;
-
+struct SoundManagerPrivate
+{
+  ca_context* context;
+  gchar     **samples_path;
+  int       * sample_ids;
+  gint        current_music_id;
+  MbMusic     current_music;
+  gboolean    active;
 };
 
 
-static SoundManager * sound_manager_new( void );
-static void load_samples(SoundManager * m);
-
-static void sound_manager_instance_init(SoundManager * sound_manager) {
-  sound_manager->private =g_new0 (SoundManagerPrivate, 1);			
-  sound_manager->private->engine = mb_audio_engine_new();
+static SoundManager* sound_manager_new (void);
+static void          load_samples      (SoundManager* m);
 
+static void
+sound_manager_instance_init (SoundManager* sound_manager)
+{
+  int result;
+
+  sound_manager->private =g_new0 (SoundManagerPrivate, 1);
+
+  result = ca_context_create (&PRIVATE (sound_manager)->context);
+  if (result != CA_SUCCESS)
+    {
+      g_warning ("ca_context_create(): %d", result);
+    }
+  result = ca_context_open (PRIVATE (sound_manager)->context);
+  if (result != CA_SUCCESS)
+    {
+      g_warning ("ca_context_open(): %d", result);
+    }
 }
 
 static void sound_manager_finalize(GObject* object) {
@@ -116,8 +136,10 @@ GType sound_manager_get_type(void) {
 
 
 static void load_sample(SoundManager * m,int i) {
+#if 0
   mb_audio_engine_cache_audio_file(  PRIVATE(m)->engine,
 				     PRIVATE(m)->samples_path[i]);
+#endif
 }
 
 static void load_samples(SoundManager * m) {
@@ -151,35 +173,59 @@ static SoundManager * sound_manager_new( void ) {
 }
 
 
-void sound_manager_play_music(SoundManager *m,MbMusic music)
+void
+sound_manager_play_music (SoundManager* m,
+                          MbMusic       music)
 {
-
-	g_assert(IS_SOUND_MANAGER(m));
-	if( PRIVATE(m)->current_music_id != -1 ) {
-		mb_audio_engine_stop( PRIVATE(m)->engine, PRIVATE(m)->current_music_id );
-		PRIVATE(m)->current_music_id = -1;
-	}
-
-	PRIVATE(m)->current_music = music;
-	switch(music) {
-	case MB_MUSIC_SPLASH : {
-		PRIVATE(m)->current_music_id = 
-			mb_audio_engine_play_audio_file_full(PRIVATE(m)->engine,
-							DATADIR"/monkey-bubble/sounds/splash.ogg",TRUE);
-		break;
-		}
-	case MB_MUSIC_GAME : {
-		PRIVATE(m)->current_music_id = 
-			mb_audio_engine_play_audio_file_full(PRIVATE(m)->engine,
-							DATADIR"/monkey-bubble/sounds/game.ogg",TRUE);
-		break;
-		}
-	}
+  g_return_if_fail (IS_SOUND_MANAGER (m));
+
+  if (PRIVATE (m)->current_music_id != NO_MUSIC)
+    {
+      int result = ca_context_cancel (PRIVATE (m)->context, PLAY_ID_MUSIC);
+
+      if (result != CA_SUCCESS)
+        {
+          g_warning ("ca_context_cancel(): %d", result);
+        }
+    }
+
+  PRIVATE (m)->current_music_id = music;
+
+  if (PRIVATE (m)->current_music_id != NO_MUSIC)
+    {
+      gchar const* paths[] =
+        {
+          DATADIR "/monkey-bubble/sounds/splash.ogg",
+          DATADIR "/monkey-bubble/sounds/game.ogg"
+        };
+      int result = ca_context_play (PRIVATE (m)->context,
+                                    PLAY_ID_MUSIC,
+                                    CA_PROP_MEDIA_FILENAME, paths[PRIVATE (m)->current_music_id],
+                                    NULL);
+
+      g_print ("trying to play %s\n", paths[PRIVATE (m)->current_music_id]);
+
+      /* FIXME: set up the looping */
+
+      if (result != CA_SUCCESS)
+        {
+          g_warning ("ca_context_play(): %d", result);
+        }
+    }
 }
 
-void sound_manager_play_fx(SoundManager *m,MbSample sample) 
+void sound_manager_play_fx (SoundManager* m,
+                            MbSample      sample)
 {
-
-
-  mb_audio_engine_play_audio_file(PRIVATE(m)->engine,PRIVATE(m)->samples_path[sample]);
+  int result = ca_context_play (PRIVATE (m)->context,
+                                PLAY_ID_FX,
+                                CA_PROP_MEDIA_FILENAME, PRIVATE (m)->samples_path[sample],
+                                NULL);
+
+  if (result != CA_SUCCESS)
+    {
+      g_print ("ca_context_play(): %d\n", result);
+    }
 }
+
+/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
diff --git a/src/audio/sound-manager.h b/src/audio/sound-manager.h
index 526901f..615c27c 100644
--- a/src/audio/sound-manager.h
+++ b/src/audio/sound-manager.h
@@ -36,7 +36,8 @@ typedef enum {
 typedef enum {
   MB_MUSIC_SPLASH,
   MB_MUSIC_GAME,
-  NO_MUSIC
+  NO_MUSIC,
+  MB_N_MUSICS = NO_MUSIC
 } MbMusic;
 
 #define TYPE_SOUND_MANAGER      (sound_manager_get_type())
diff --git a/src/ui/main.c b/src/ui/main.c
index 272b46b..928e221 100644
--- a/src/ui/main.c
+++ b/src/ui/main.c
@@ -12,7 +12,6 @@
 #include "input-manager.h"
 
 #include <gtk/gtk.h>
-#include <gst/gst.h>
 #include <glib/gi18n.h>
 #ifdef GNOME
 #include <libgnome/gnome-score.h>
@@ -89,7 +88,6 @@ int main(int  argc, char **argv)
   context = g_option_context_new ("");
   g_option_context_set_summary (context, _("Monkey Bubble is a Bust'a'Move clone for GNOME"));
   g_option_context_add_group   (context, gtk_get_option_group (TRUE));
-  g_option_context_add_group   (context, gst_init_get_option_group ());
   if (!g_option_context_parse (context, &argc, &argv, &error)) {
     g_printerr ("%s\n", error->message);
     g_error_free (error);
diff --git a/src/view/monkey-canvas.c b/src/view/monkey-canvas.c
index ef5e5c5..149e0ac 100644
--- a/src/view/monkey-canvas.c
+++ b/src/view/monkey-canvas.c
@@ -498,10 +498,13 @@ void create_pixbuf_svg(Image * i ) {
   }
 }
 
-void image_create_pixbuf(Image * i,MonkeyCanvas * canvas) {
-    
+void
+image_create_pixbuf (Image       * i,
+                     MonkeyCanvas* canvas)
+{
   i->create_pixbuf(i);
 
+  g_warn_if_fail (i->scaled_pixbuf != NULL);
 }
 
 Layer * monkey_canvas_get_root_layer(MonkeyCanvas * canvas) {
@@ -634,53 +637,51 @@ void monkey_canvas_unref_block(MonkeyCanvas * canvas,
 }
 
 
-void layer_draw( Layer* l,
-		 GdkDrawable * d,
-		 GdkGC *gc,
-		 GdkRectangle * rect) {
-
-  GList * next;
-    
-  next = l->block_list;
-  while( next != NULL ) {
-
-    block_draw( (Block *) next->data,
-		d,
-		gc,
-		rect  );
-    next = g_list_next( next );    
-	
-  }
-
+void
+layer_draw (Layer       * l,
+            GdkDrawable * d,
+            GdkGC       * gc,
+            GdkRectangle* rect)
+{
+  GList* iter;
+
+  for (iter = l->block_list; iter; iter = iter->next)
+    {
+      block_draw (iter->data,
+                  d,
+                  gc,
+                  rect);
+    }
 }
 
 
-void block_draw(Block * block,
-		GdkDrawable * d,
-		GdkGC *gc,
-		GdkRectangle * rect) {
-
+void
+block_draw (Block       * block,
+            GdkDrawable * d,
+            GdkGC       * gc,
+            GdkRectangle* rect)
+{
   GdkRectangle irect;
   GdkRectangle r;
-    
-  block_get_rectangle(block,&r);
-
-
-  if( gdk_rectangle_intersect( &r,rect,&irect)){
-    gdk_draw_pixbuf
-      (d,
-       gc,
-       block->image->scaled_pixbuf,
-       irect.x - r.x ,irect.y - r.y,
-       irect.x,
-       irect.y,
-       irect.width,irect.height,
-       GDK_RGB_DITHER_NONE,
-       0,0);
-    
-    
-  }
 
+  g_return_if_fail (block->image->scaled_pixbuf);
+
+  block_get_rectangle (block, &r);
+
+  if (gdk_rectangle_intersect(&r, rect, &irect))
+    {
+      gdk_draw_pixbuf (d,
+                       gc,
+                       block->image->scaled_pixbuf,
+                       irect.x - r.x,
+                       irect.y - r.y,
+                       irect.x,
+                       irect.y,
+                       irect.width,
+                       irect.height,
+                       GDK_RGB_DITHER_NONE,
+                       0,0);
+    }
 }
 
 
@@ -764,3 +765,5 @@ void monkey_canvas_paint(MonkeyCanvas * monkey_canvas){
   gdk_region_destroy( screen);
   
 }
+
+/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */



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