? =
? stamp-h1
? libgnome/.gnome-init.c.swp
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnome/ChangeLog,v
retrieving revision 1.205
diff -u -r1.205 ChangeLog
--- ChangeLog	13 May 2002 17:11:54 -0000	1.205
+++ ChangeLog	14 May 2002 17:57:49 -0000
@@ -1,3 +1,14 @@
+2002-05-14  Jorn Baayen  <jorn@nl.linux.org>
+
+	* configure.in:
+	* libgnome/gnome-init.c:
+	* libgnome/gnome-program.c:
+	* libgnome/gnome-sound.c:
+	* libgnome/gnome-sound.h:
+	* libgnome/gnome-triggers.c:
+	* libgnome/libgnome-2.0.pc.in:
+	* schemas/desktop_gnome_sound.schemas: port sound code to MonkeyMedia
+
 2002-05-13  Anders Carlsson  <andersca@gnu.org>
 
 	* configure.in: Release 1.117.0
Index: configure.in
===================================================================
RCS file: /cvs/gnome/libgnome/configure.in,v
retrieving revision 1.121
diff -u -r1.121 configure.in
--- configure.in	13 May 2002 17:11:54 -0000	1.121
+++ configure.in	14 May 2002 17:57:49 -0000
@@ -83,23 +83,9 @@
 dnl
 dnl Start of pkg-config checks
 dnl
-dnl We first check for esound and audiofile (which has conditional
-dnl support built in)
-dnl
-
-AUDIOFILE_MODULE="audiofile >= 0.2.3"
-ESOUND_MODULE="esound >= 0.2.25"
-PKG_CHECK_MODULES(SOUND_TEST, $ESOUND_MODULE $AUDIOFILE_MODULE, [
-	AC_DEFINE(HAVE_LIBAUDIOFILE)
-	AC_DEFINE(HAVE_ESD)
-],[
-	AUDIOFILE_MODULE=""
-	ESOUND_MODULE=""
-])
 
 PKG_CHECK_MODULES(LIBGNOME, glib-2.0 >= 2.0.1 gmodule-2.0 >= 2.0.1 gnome-vfs-2.0 >= 1.9.13 \
-libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0 gconf-2.0 >= 1.1.9 \
-$AUDIOFILE_MODULE $ESOUND_MODULE)
+libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0 gconf-2.0 >= 1.1.9 monkey-media >= 0.5.0)
 
 PKG_CHECK_MODULES(HELP_VFS_MODULE, glib-2.0 >= 2.0.1 gmodule-2.0 >= 2.0.1 gnome-vfs-2.0 >= 1.9.13 gnome-vfs-module-2.0 >= 1.9.13 \
 libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0)
Index: doc/reference/tmpl/gnome-sound.sgml
===================================================================
RCS file: /cvs/gnome/libgnome/doc/reference/tmpl/gnome-sound.sgml,v
retrieving revision 1.3
diff -u -r1.3 gnome-sound.sgml
--- doc/reference/tmpl/gnome-sound.sgml	6 Oct 2001 16:15:34 -0000	1.3
+++ doc/reference/tmpl/gnome-sound.sgml	14 May 2002 17:57:49 -0000
@@ -26,6 +26,7 @@
 
 </para>
 
+<!-- # Unused Parameters # -->
 @hostname: 
 
 
@@ -41,24 +42,8 @@
 
 </para>
 
+@uri: 
+<!-- # Unused Parameters # -->
 @filename: 
-
-
-<!-- ##### FUNCTION gnome_sound_sample_load ##### -->
-<para>
-
-</para>
-
-@sample_name: 
-@filename: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gnome_sound_connection_get ##### -->
-<para>
-
-</para>
-
-@Returns: 
 
 
Index: libgnome/gnome-init.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-init.c,v
retrieving revision 1.102
diff -u -r1.102 gnome-init.c
--- libgnome/gnome-init.c	29 Apr 2002 11:12:54 -0000	1.102
+++ libgnome/gnome-init.c	14 May 2002 17:57:49 -0000
@@ -158,7 +158,7 @@
  * libgnome
  *****************************************************************************/
 
-enum { ARG_DISABLE_SOUND = 1, ARG_ENABLE_SOUND, ARG_ESPEAKER, ARG_VERSION };
+enum { ARG_DISABLE_SOUND = 1, ARG_ENABLE_SOUND, ARG_VERSION };
 
 static char *gnome_user_dir = NULL;
 static char *gnome_user_private_dir = NULL;
@@ -218,14 +218,6 @@
 	switch(reason) {
 	case POPT_CALLBACK_REASON_OPTION:
 		switch(opt->val) {
-		case ARG_ESPEAKER:
-			g_value_init (&value, G_TYPE_STRING);
-			g_value_set_string (&value, opt->arg);
-			g_object_set_property (G_OBJECT (program),
-					       GNOME_PARAM_ESPEAKER, &value);
-			g_value_unset (&value);
-			break;
-
 		case ARG_DISABLE_SOUND:
 			g_value_init (&value, G_TYPE_BOOLEAN);
 			g_value_set_boolean (&value, FALSE);
@@ -314,8 +306,7 @@
 			  GnomeModuleInfo *mod_info)
 {
 	GValue value = { 0 };
-	gboolean enable_val = TRUE, create_dirs_val = TRUE;                           
-	char *espeaker_val = NULL;                                                    
+	gboolean enable_val = TRUE, create_dirs_val = TRUE;
 
 	g_value_init (&value, G_TYPE_BOOLEAN);
 	g_object_get_property (G_OBJECT (program),
@@ -330,15 +321,8 @@
 	enable_val = g_value_get_boolean (&value);
 	g_value_unset (&value);
 
-	g_value_init (&value, G_TYPE_STRING);
-	g_object_get_property (G_OBJECT (program), 
-			       GNOME_PARAM_ESPEAKER, &value);
-	espeaker_val = g_value_dup_string (&value);
-	g_value_unset (&value);
-
-
 	if (enable_val) {
-		gnome_sound_init(espeaker_val);
+		gnome_sound_init();
 	}
 
 	libgnome_userdir_setup (create_dirs_val);
@@ -362,11 +346,6 @@
 
 	{ "enable-sound", '\0', POPT_ARG_NONE,                                  
 	  NULL, ARG_ENABLE_SOUND, N_("Enable sound server usage"), NULL},       
-
-	{ "espeaker", '\0', POPT_ARG_STRING,                                    
-	  NULL, ARG_ESPEAKER, N_("Host:port on which the sound server to use is"
-				 " running"),
-	  N_("HOSTNAME:PORT")},                                                 
 
 	{"version", '\0', POPT_ARG_NONE, NULL, ARG_VERSION },
 
Index: libgnome/gnome-program.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-program.c,v
retrieving revision 1.57
diff -u -r1.57 gnome-program.c
--- libgnome/gnome-program.c	22 Mar 2002 16:02:45 -0000	1.57
+++ libgnome/gnome-program.c	14 May 2002 17:57:50 -0000
@@ -75,7 +75,6 @@
     gchar *prop_app_datadir;
     gboolean prop_create_directories;
     gboolean prop_enable_sound;
-    gchar *prop_espeaker;
 
     gchar **gnome_path;
 
@@ -109,7 +108,6 @@
     PROP_APP_SYSCONFDIR,
     PROP_CREATE_DIRECTORIES,
     PROP_ENABLE_SOUND,
-    PROP_ESPEAKER,
     PROP_POPT_TABLE,
     PROP_POPT_FLAGS,
     PROP_POPT_CONTEXT,
@@ -203,10 +201,6 @@
     case PROP_ENABLE_SOUND:
 	program->_priv->prop_enable_sound = g_value_get_boolean (value);
 	break;
-    case PROP_ESPEAKER:
-	g_free (program->_priv->prop_espeaker);
-	program->_priv->prop_espeaker = g_value_dup_string (value);
-	break;
     default: {
 	    GObjectSetPropertyFunc set_func;
 
@@ -281,9 +275,6 @@
     case PROP_ENABLE_SOUND:
 	g_value_set_boolean (value, program->_priv->prop_enable_sound);
 	break;
-    case PROP_ESPEAKER:
-	g_value_set_string (value, program->_priv->prop_espeaker);
-	break;
     default: {
 	    GObjectSetPropertyFunc get_func;
 
@@ -581,16 +572,6 @@
 			       (G_PARAM_READABLE | G_PARAM_WRITABLE |
 				G_PARAM_CONSTRUCT_ONLY)));
 
-    g_object_class_install_property
-	(object_class,
-	 PROP_ESPEAKER,
-	 g_param_spec_string (GNOME_PARAM_ESPEAKER,
-			      _("Espeaker"), 
-			      _("How to connect to esd"),
-			      NULL,
-			      (G_PARAM_READABLE | G_PARAM_WRITABLE |
-			       G_PARAM_CONSTRUCT_ONLY)));
-
     object_class->finalize  = gnome_program_finalize;
 }
 
@@ -648,8 +629,6 @@
 	self->_priv->prop_app_sysconfdir = NULL;
 	g_free (self->_priv->prop_app_datadir);
 	self->_priv->prop_app_datadir = NULL;
-	g_free (self->_priv->prop_espeaker);
-	self->_priv->prop_espeaker = NULL;
 
 	g_strfreev (self->_priv->gnome_path);
 	self->_priv->gnome_path = NULL;
Index: libgnome/gnome-sound.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-sound.c,v
retrieving revision 1.32
diff -u -r1.32 gnome-sound.c
--- libgnome/gnome-sound.c	8 Jan 2002 21:17:34 -0000	1.32
+++ libgnome/gnome-sound.c	14 May 2002 17:57:50 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1997-1998 Stuart Parmenter and Elliot Lee
+ * Copyright (C) 2002 Jorn Baayen
  * All rights reserved.
  *
  * This file is part of the Gnome Library.
@@ -28,527 +29,136 @@
 #include "libgnome.h"
 #include "gnome-sound.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#ifdef HAVE_ESD
-#include <esd.h>
-#endif
-
-#ifdef HAVE_ESD
-static char *esound_hostname = NULL;
-static gboolean esound_hostname_null_ok = FALSE;
-static int gnome_sound_connection = -1;
-#endif
-
-typedef struct _sample
-  {
-    int rate, format, samples, id, size;
-    short *data;
-  }
-GnomeSoundSample;
+#include <monkey-media.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
 
-#ifndef HAVE_LIBAUDIOFILE
-typedef struct _WAVFormatChunk
-  {
-    char chunkID[4];
-    int chunkSize;
-
-    unsigned int dwSamplesPerSec;
-    unsigned int dwAvgBytesPerSec;
-    short wFormatTag;
-    unsigned short wChannels;
-    unsigned short wBlockAlign;
-    unsigned short wBitsPerSample;
-  }
-WAVFormatChunk;
+#include <stdlib.h>
 
-#ifdef WORDS_BIGENDIAN
-#define SWAP_SHORT( x ) x = ( ( x & 0x00ff ) << 8 ) | ( ( x >> 8 ) & 0x00ff )
-#define SWAP_LONG( x ) x = ( ( ( x & 0x000000ff ) << 24 ) |\
-( ( x & 0x0000ff00 ) << 8 ) |\
-( ( x & 0x00ff0000 ) >> 8 ) |\
-( ( x & 0xff000000 ) >> 24 ) )
-#endif
+static MonkeyMediaMixer *mixer = NULL;
+static GHashTable *cache = NULL;
 
 /**
- * gnome_sound_sample_load_wav:
- * @file: filename to try loading a WAV file from.
- * 
- * Used to load a .wav file into esound.
- *
- * Returns a GnomeSoundSample or NULL if file did not exist.
+ * gnome_sound_play:
+ * @uri URI containing the sound sample.
  *
+ * Plays the audio stored in @uri, if possible. Fail quietly if playing is
+ * not possible (due to missing sound support or for other reasons).
  */
-#ifdef HAVE_ESD
-static GnomeSoundSample *
-gnome_sound_sample_load_wav(const char *file)
+void 
+gnome_sound_play (const char * uri)
 {
-  FILE *f;
-  GnomeSoundSample *s;
-  char buf[4];
-  WAVFormatChunk fmt;
-  int skipl = 0;
-  int skipr = 0;
-  char bytes = 0;
-  char stereo = 0;
-  int len;
-
-  /* int                 count; */
-
-  f = fopen (file, "r");
-  if (!f)
-    return NULL;
-  s = g_malloc (sizeof (GnomeSoundSample));
-  if (!s)
-    {
-      fclose (f);
-      return NULL;
-    }
-  s->rate = 44100;
-  s->format = ESD_STREAM | ESD_PLAY;
-  s->samples = 0;
-  s->data = NULL;
-  s->id = 0;
-  fread (buf, 1, 4, f);
-  if ((buf[0] != 'R') ||
-      (buf[1] != 'I') ||
-      (buf[2] != 'F') ||
-      (buf[3] != 'F'))
-    {
-      /* not a RIFF WAV file */
-      fclose (f);
-      g_free (s);
-      return NULL;
-    }
-  fread (buf, 1, 4, f);
-  fread (buf, 1, 4, f);
-  fread (fmt.chunkID, 1, 4, f);
-  fread (&(fmt.chunkSize), 1, 4, f);
-
-#ifdef WORDS_BIGENDIAN
-  SWAP_LONG (fmt.chunkSize);
-#endif
-
-  if ((fmt.chunkID[0] == 'f') &&
-      (fmt.chunkID[1] == 'm') &&
-      (fmt.chunkID[2] == 't') &&
-      (fmt.chunkID[3] == ' ') &&
-      16 == fmt.chunkSize)
-    /* fmt chunk */
-    {
-      fread (&(fmt.wFormatTag), 1, 2, f);
-      fread (&(fmt.wChannels), 1, 2, f);
-      fread (&(fmt.dwSamplesPerSec), 1, 4, f);
-      fread (&(fmt.dwAvgBytesPerSec), 1, 4, f);
-      fread (&(fmt.wBlockAlign), 1, 2, f);
-      fread (&(fmt.wBitsPerSample), 1, 2, f);
-#ifdef WORDS_BIGENDIAN
-      SWAP_SHORT (fmt.wFormatTag);
-      SWAP_SHORT (fmt.wChannels);
-      SWAP_LONG (fmt.dwSamplesPerSec);
-      SWAP_LONG (fmt.dwAvgBytesPerSec);
-      SWAP_SHORT (fmt.wBlockAlign);
-      SWAP_SHORT (fmt.wBitsPerSample);
-#endif
-
-      if (fmt.wFormatTag != 1)
-	{
-	  /* unknown WAV encoding format - exit */
-	  fclose (f);
-	  g_free (s);
-	  return NULL;
-	}
-      skipl = 0;
-      skipr = 0;
-      bytes = 0;
-      stereo = 0;
-      if (fmt.wChannels == 1)
-	s->format |= ESD_MONO;
-      else if (fmt.wChannels == 2)
-	{
-	  stereo = 1;
-	  s->format |= ESD_STEREO;
-	}
-      else
-	{
-	  stereo = 1;
-	  s->format |= ESD_STEREO;
-	  if (fmt.wChannels == 3)
-	    {
-	      skipl = 0;
-	      skipr = 1;
-	    }
-	  else if (fmt.wChannels == 4)
-	    {
-	      skipl = 0;
-	      skipr = 2;
-	    }
-	  else if (fmt.wChannels == 4)
-	    {
-	      skipl = 0;
-	      skipr = 2;
-	    }
-	  else if (fmt.wChannels == 6)
-	    {
-	      skipl = 3;
-	      skipr = 1;
-	    }
-	  else
-	    {
-	      /* unknown channel encoding */
-	      fclose (f);
-	      g_free (s);
-	      return NULL;
-	    }
-	}
-      s->rate = fmt.dwSamplesPerSec;
-      if (fmt.wBitsPerSample <= 8)
-	{
-	  bytes = 1;
-	  s->format |= ESD_BITS8;
-	}
-      else if (fmt.wBitsPerSample <= 16)
-	s->format |= ESD_BITS16;
-      else
-	{
-	  /* unknown bits encoding encoding */
-	  fclose (f);
-	  g_free (s);
-	  return NULL;
-	}
-    }
-  for (;;)
-    {
-      if (fread (buf, 1, 4, f) &&
-	  fread (&len, 4, 1, f))
-	{
-#ifdef WORDS_BIGENDIAN
-	  SWAP_LONG (len);
-#endif
-
-	  if ((buf[0] != 'd') ||
-	      (buf[1] != 'a') ||
-	      (buf[2] != 't') ||
-	      (buf[3] != 'a'))
-	    fseek (f, len, SEEK_CUR);
-	  else
-	    {
-	      s->data = g_malloc (len);
-	      if (!s->data)
-		{
-		  fclose (f);
-		  g_free (s);
-		  return NULL;
-		}
-	      if ((skipl == 0) && (skipr == 0))
-		{
-		  fread (s->data, len, 1, f);
-#ifdef WORDS_BIGENDIAN
-		  if (fmt.wBitsPerSample > 8 && fmt.wBitsPerSample <= 16)
-		    {
-		      char *tmp;
-		      char tmpval;
-		      int i;
-
-		      tmp = (char *) (s->data);
-
-		      for (i = 0; i < len; i++)
-			{
-			  tmpval = tmp[i];
-			  tmp[i] = tmp[i + 1];
-			  tmp[i + 1] = tmpval;
-			}
-		    }
-#endif
-		}
-	      else
-		{
-		}
-	      s->samples = len;
-	      if (stereo)
-		s->samples /= 2;
-	      if (!bytes)
-		s->samples /= 2;
-	      fclose (f);
-	      return s;
-	    }
-	}
-      else
-	{
-	  fclose (f);
-	  return NULL;
-	}
-    }
-  fclose (f);
-  g_free (s);
-  if (s->data)
-    g_free (s->data);
+  MonkeyMediaAudioStream *stream;
+  char *real_uri;
+
+  if (mixer == NULL)
+    return;
+
+  real_uri = gnome_vfs_get_uri_from_local_path (uri);
+  stream = monkey_media_audio_stream_new (real_uri, NULL);
+  g_free (real_uri);
+  if (stream == NULL)
+    return;
+  
+  monkey_media_mixer_append_audio_stream (mixer, stream);
+  monkey_media_mixer_set_playing_audio_stream (mixer, stream);
+  monkey_media_mixer_set_state (mixer, MONKEY_MEDIA_MIXER_STATE_PLAYING);
 
-  return NULL;
+  /* mixer holds a reference */
+  g_object_unref (G_OBJECT (stream));
 }
-#endif
-#endif
 
-#ifdef HAVE_ESD
-/*
- * This does delayed initialization of Esound
+/**
+ * gnome_sound_init:
+ *
+ * Initialize the sound system.
  */
-static gboolean
-use_sound (void)
+void
+gnome_sound_init(void)
 {
-  if (gnome_sound_connection == -1){
-    if (esound_hostname || esound_hostname_null_ok){
-      gnome_sound_connection = esd_open_sound (esound_hostname);
-      if (gnome_sound_connection == -1){
-	g_free (esound_hostname);
-	esound_hostname = NULL;
-	esound_hostname_null_ok = FALSE;
-	return FALSE;
-      }
-    }
-  }
-  return TRUE;
+  monkey_media_init (NULL, NULL);
+  
+  mixer = monkey_media_mixer_new (NULL);
+  if (mixer == NULL)
+    return;
 }
-#endif
 
-#if defined(HAVE_LIBAUDIOFILE) && defined(HAVE_ESD)
-#include <audiofile.h>
-
-static GnomeSoundSample *
-gnome_sound_sample_load_audiofile(const char *file)
+static void
+gnome_sound_unref_stream (char *key, GObject *stream, gpointer unused)
 {
-  AFfilehandle in_file;
-  GnomeSoundSample *s;
-  int in_format, in_width, in_channels;
-  double in_rate;
-  int bytes_per_frame;
-  AFframecount frame_count, frames_read;
-
-  int out_bits, out_channels, out_rate;
-  int out_mode = ESD_STREAM, out_func = ESD_PLAY;
-  esd_format_t out_format;
-
-  in_file = afOpenFile(file, "r", NULL);
-  if(!in_file)
-    return NULL;
-
-  frame_count = afGetFrameCount(in_file, AF_DEFAULT_TRACK);
-  in_channels = afGetChannels(in_file, AF_DEFAULT_TRACK);
-  in_rate = afGetRate (in_file, AF_DEFAULT_TRACK);
-  afGetSampleFormat (in_file, AF_DEFAULT_TRACK, &in_format, &in_width);
-  if (in_width == 8)
-    out_bits = ESD_BITS8;
-  else if (in_width == 16)
-    out_bits = ESD_BITS16;
-  else {
-      g_warning ("only sample widths of 8 and 16 supported");
-      return NULL;
-  }
-
-  bytes_per_frame = in_width / 8;
-
-  if (in_channels == 1)
-    out_channels = ESD_MONO;
-  else if (in_channels == 2)
-    out_channels = ESD_STEREO;
-  else {
-      g_warning ("only 1 or 2 channel samples supported");
-      return NULL;
-  }
-
-  out_format = out_bits | out_channels | out_mode | out_func;
-
-  out_rate = (int) in_rate;
-
-  s = g_new0 (GnomeSoundSample, 1);
-
-  s->rate = out_rate;
-  s->format = out_format;
-  s->samples = frame_count;
-  s->data = g_malloc(frame_count * in_channels * bytes_per_frame);
-  s->id = 0;
-
-  frames_read = afReadFrames(in_file, AF_DEFAULT_TRACK, s->data,
-			     frame_count * in_channels);
-
-  afCloseFile(in_file);
-
-  return s;
+  g_object_unref (stream);
+  g_free (key);
 }
-#endif
 
-
-/**
- * gnome_sound_sample_load:
- * @sample_name: The name of the sample.
- * @filename: The filename where the audio is stored.
- *
- * Loads the audio from @filename and load it into the esd cache for later
- * playing. Programs will rarely want to call this function directly. Use
- * gnome_sound_play() instead for fire and forget sound playing.
+/** 
+ * gnome_sound_shutdown:
  *
- * Returns: The esound sample_id or %-1 if the sample was unable to be cached
- * for esound.
+ * Shuts down the gnome sound support.
  */
-int
-gnome_sound_sample_load(const char *sample_name, const char *filename)
+void
+gnome_sound_shutdown (void)
 {
-#ifdef HAVE_ESD
-  GnomeSoundSample *s = NULL;
-  int sample_id;
-  int size;
-  int confirm = 0;
-
-  if (!use_sound ())
-    return -2;
-
-  if(!filename || !*filename)
-    return -2;
-
-#ifdef HAVE_LIBAUDIOFILE
-  s = gnome_sound_sample_load_audiofile(filename);
-#else
-  s = gnome_sound_sample_load_wav(filename);
-#endif
-  if(s)
-    goto playsamp;
-
-  /* XXX: Add handlers for more formats here */
-
- playsamp:
-  if (!s)
-    return -1;
-
-  size = s->samples;
-  if (s->format & ESD_STEREO)
-    size *= 2;
-  if (s->format & ESD_BITS16)
-    size *= 2;
-
-  if (gnome_sound_connection >= 0)
-    {
-      if (s->data)
-	{
-	  /* "name" of all samples is currently "E", should be name of sound 
-	   * file, or event type, for later identification */
-	  s->id = esd_sample_cache (gnome_sound_connection, s->format, s->rate,
-				    size, (char *)sample_name);
-	  write (gnome_sound_connection, s->data, size);
-	  confirm = esd_confirm_sample_cache (gnome_sound_connection);
-	  if (s->id <= 0 || confirm != s->id)
-	    {
-	      g_warning ("error caching sample <%d>!\n", s->id);
-	      s->id = 0;
-	    }
-	  g_free (s->data);
-	  s->data = NULL;
-	}
-    }
-
-  sample_id = s->id;
-
-  g_free(s->data); g_free(s);
-
-  return sample_id;
-#else
-  return -1;
-#endif
+  if (cache != NULL) {
+    g_hash_table_foreach (cache, (GHFunc) gnome_sound_unref_stream, NULL);
+    g_hash_table_destroy (cache);
+    cache = NULL;
+  }
+
+  monkey_media_shutdown ();
 }
 
 /**
- * gnome_sound_play:
- * @filename: File containing the sound sample.
+ * gnome_sound_cache:
  *
- * Plays the audio stored in @filename, if possible. Fail quietly if playing is
- * not possible (due to missing sound support or for other reasons).
+ * Cache an audio stream.
+ *
+ * @uri: URI to be loaded
+ * @sndname: Name in the cache 
  */
-void 
-gnome_sound_play (const char * filename)
+void
+gnome_sound_cache (const char * uri, const char * sndname)
 {
-#ifdef HAVE_ESD
-  char buf[256];
-  int sample;
-  static guint cookie = 0;
-
-  if(!use_sound ())
+  MonkeyMediaAudioStream *stream;
+  char *real_uri;
+  gpointer origname, origstream;
+
+  if (cache == NULL)
+    cache = g_hash_table_new (g_str_hash, g_str_equal);
+
+  real_uri = gnome_vfs_get_uri_from_local_path (uri);
+  stream = monkey_media_audio_stream_new (real_uri, NULL);
+  g_free (real_uri);
+  if (stream == NULL)
     return;
 
-  if (cookie == 0)
-	  cookie = rand ();
+  /* free old one */
+  if (g_hash_table_lookup_extended (cache, sndname, &origname, &origstream)) {
+    g_free (origname);
+    g_object_unref (G_OBJECT (origstream));
+  }
 
-  g_snprintf(buf, sizeof(buf), "%d-%u-%d",
-	     getpid(), cookie++, rand ());
- 
-  /* overflow, make sure we don't reinit with rand again */
-  if (cookie == 0)
-	  cookie = 1;
-
-  sample = gnome_sound_sample_load (buf, filename);
-
-  esd_sample_play(gnome_sound_connection, sample);
-  fsync (gnome_sound_connection);
-  esd_sample_free(gnome_sound_connection, sample);
-#endif
+  g_hash_table_insert (cache, g_strdup (sndname), stream);
 }
 
 /**
- * gnome_sound_init:
- * @hostname: Hostname where esd daemon resides.
+ * gnome_sound_play_cached:
  *
- * Initialize the esd connection.
- */
-void
-gnome_sound_init(const char *hostname)
-{
-#ifdef HAVE_ESD
-	srand(time(NULL));
-	g_free (esound_hostname);
-	if (hostname)
-		esound_hostname = g_strdup (hostname);
-	else
-		esound_hostname_null_ok = TRUE;
-#endif
-}
-
-/** 
- * gnome_sound_shutdown:
+ * Play a cached audio stream
  *
- * Shuts down the gnome sound support.
+ * @sndname: name of the cached stream
  */
 void
-gnome_sound_shutdown(void)
+gnome_sound_play_cached (const char * sndname)
 {
-#ifdef HAVE_ESD
-	g_free (esound_hostname);
-	esound_hostname = NULL;
-	if(gnome_sound_connection >= 0){
-		esd_close(gnome_sound_connection);
-		gnome_sound_connection = -1;
-	}
-#endif
-}
+  MonkeyMediaAudioStream *stream;
 
-/** 
- * gnome_sound_connection_get:
- *
- * Rarely needed to by programs directly, this function may be useful if a
- * program has cached a sample with gnome_sound_sample_load() and now wishes to
- * call esd_sample_play() to play the sample.
- *
- * Returns: the file descriptor of our esound connection or %-1
- * on error.
- **/
-int
-gnome_sound_connection_get (void)
-{
-#ifdef HAVE_ESD
-	if ( ! use_sound ())
-		return -1;
-	return gnome_sound_connection;
-#else
-	return -1;
-#endif
+  if (cache == NULL)
+    return;
+
+  stream = g_hash_table_lookup (cache, sndname);
+  if (stream == NULL)
+    return;
+
+  monkey_media_mixer_append_audio_stream (mixer, stream);
+  monkey_media_mixer_set_playing_audio_stream (mixer, stream);
+  monkey_media_mixer_set_state (mixer, MONKEY_MEDIA_MIXER_STATE_PLAYING);
 }
Index: libgnome/gnome-sound.h
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-sound.h,v
retrieving revision 1.18
diff -u -r1.18 gnome-sound.h
--- libgnome/gnome-sound.h	3 Sep 2001 06:42:03 -0000	1.18
+++ libgnome/gnome-sound.h	14 May 2002 17:57:50 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1997-1998 Stuart Parmenter and Elliot Lee
+ * Copyright (C) 2002 Jorn Baayen
  * All rights reserved.
  *
  * This file is part of the Gnome Library.
@@ -30,20 +31,19 @@
 
 G_BEGIN_DECLS
 
-/* Use this with the Esound functions */
-int gnome_sound_connection_get (void);
+/* Initialize sound system */
+void gnome_sound_init (void);
 
-/* Initialize esd connection */
-void gnome_sound_init(const char *hostname);
+/* Closes sound system */
+void gnome_sound_shutdown (void);
 
-/* Closes esd connection */
-void gnome_sound_shutdown(void);
+/* Plays a stream */
+void gnome_sound_play (const char * uri);
 
-/* Returns the Esound sample ID for the sample */
-int gnome_sound_sample_load(const char *sample_name, const char *filename);
+/* Stream caching */
+void gnome_sound_cache (const char * uri, const char * sndname);
 
-/* Loads sample, plays sample, frees sample */
-void gnome_sound_play (const char * filename);
+void gnome_sound_play_cached (const char * sndname);
 
 G_END_DECLS
 
Index: libgnome/gnome-triggers.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-triggers.c,v
retrieving revision 1.48
diff -u -r1.48 gnome-triggers.c
--- libgnome/gnome-triggers.c	25 Jan 2002 20:08:02 -0000	1.48
+++ libgnome/gnome-triggers.c	14 May 2002 17:57:51 -0000
@@ -32,9 +32,6 @@
 #include "gnome-config.h"
 #include "gnome-util.h"
 #include "gnome-sound.h"
-#ifdef HAVE_ESD
- #include <esd.h>
-#endif
 
 #include <unistd.h>
 #include <stdio.h>
@@ -182,7 +179,7 @@
  * should be activated, 'section' is a colon-separated list indicating
  * which part of the "message classification tree" this trigger will
  * be activated for, 'type' is either "command" (run the command
- * specified in 'params') or 'play' (play the esd sound sample named
+ * specified in 'params') or 'play' (play the sound sample named
  * 'params').
  *
  * Returns 0 on success.  1 otherwise.
@@ -412,28 +409,7 @@
 static void
 gnome_triggers_play_sound(const char *sndname)
 {
-#ifdef HAVE_ESD
-  int sid;
-  static GHashTable *sound_ids = NULL;
-
-  if(gnome_sound_connection_get () < 0) return;
-
-  if(!sound_ids)
-    sound_ids = g_hash_table_new(g_str_hash, g_str_equal);
-
-  sid = GPOINTER_TO_INT(g_hash_table_lookup(sound_ids, sndname));
-
-  if(!sid) {
-    sid = esd_sample_getid(gnome_sound_connection_get (), sndname);
-    if(sid >= 0) sid++;
-    g_hash_table_insert(sound_ids, g_strdup(sndname), GINT_TO_POINTER(sid));
-  }
-
-  if(sid < 0) return;
-  sid--;
-  esd_sample_play(gnome_sound_connection_get (), sid);
-#endif
-  /* If there's no esound, this is just a no-op */
+  gnome_sound_play_cached(sndname);
 }
 
 /**
@@ -595,14 +571,9 @@
 			   const char *level,
 			   const char *supinfo[])
 {
-#if defined(HAVE_ESD)
-  if(gnome_sound_connection_get () == -1)
-    return;
-
   if(t->u.media.cache_id >= 0)
-    esd_sample_play(gnome_sound_connection_get (), t->u.media.cache_id);
+    gnome_sound_play_cached(t->u.media.cache_id);
   else if(t->u.media.cache_id == -1)
     gnome_sound_play(t->u.media.file);
-#endif
 }
 
Index: libgnome/libgnome-2.0.pc.in
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/libgnome-2.0.pc.in,v
retrieving revision 1.13
diff -u -r1.13 libgnome-2.0.pc.in
--- libgnome/libgnome-2.0.pc.in	30 Oct 2001 17:28:46 -0000	1.13
+++ libgnome/libgnome-2.0.pc.in	14 May 2002 17:57:51 -0000
@@ -5,7 +5,7 @@
 
 Name: libgnome
 Description: libgnome
-Requires: glib-2.0 ORBit-2.0 libbonobo-2.0 gconf-2.0 gnome-vfs-2.0
+Requires: glib-2.0 ORBit-2.0 libbonobo-2.0 gconf-2.0 gnome-vfs-2.0 monkey-media
 Version: @VERSION@
 Libs: -L${libdir} -lgnome-2
 Cflags: -I${includedir}/libgnome-2.0
Index: schemas/desktop_gnome_sound.schemas
===================================================================
RCS file: /cvs/gnome/libgnome/schemas/desktop_gnome_sound.schemas,v
retrieving revision 1.1
diff -u -r1.1 desktop_gnome_sound.schemas
--- schemas/desktop_gnome_sound.schemas	26 Mar 2002 15:49:37 -0000	1.1
+++ schemas/desktop_gnome_sound.schemas	14 May 2002 17:57:51 -0000
@@ -2,17 +2,6 @@
 <gconfschemafile>
   <schemalist>
     <schema>
-      <applyto>/desktop/gnome/sound/enable_esd</applyto>
-      <key>/schemas/desktop/gnome/sound/enable_esd</key>
-      <owner>gnome</owner>
-      <type>bool</type>
-      <default>false</default>
-      <locale name="C">
-        <short>Enable ESD</short>
-        <long>Enable sound server startup.</long>
-      </locale>
-    </schema>
-    <schema>
       <applyto>/desktop/gnome/sound/event_sounds</applyto>
       <key>/schemas/desktop/gnome/sound/event_sounds</key>
       <owner>gnome</owner>
