[monkey-bubble: 585/753] New func. (gnome_sound_cache_add_sample): New func.
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monkey-bubble: 585/753] New func. (gnome_sound_cache_add_sample): New func.
- Date: Wed, 14 Jul 2010 22:44:50 +0000 (UTC)
commit 352c93599f5b301ce52bbcbaca10eaa3545edd36
Author: Martin Baulig <baulig suse de>
Date: Fri Aug 3 22:08:49 2001 +0000
New func. (gnome_sound_cache_add_sample): New func.
2001-08-04 Martin Baulig <baulig suse de>
* gnome-sound.h (gnome_sound_sample_new_from_cache): New func.
(gnome_sound_cache_add_sample): New func.
(gnome_sound_cache_remove_sample): New func.
* gnome-triggers.c: Re-enable this file.
libgnome/ChangeLog | 8 ++
libgnome/Makefile.am | 1 +
libgnome/gnome-program.h | 2 +-
libgnome/gnome-sound-csl.c | 44 ++++++++++-
libgnome/gnome-sound.c | 37 ++++++++-
libgnome/gnome-sound.h | 20 +++++
libgnome/gnome-triggers.c | 199 ++++----------------------------------------
libgnome/gnome-triggers.h | 3 +-
libgnome/test-sound.c | 62 ++++++++++++++-
9 files changed, 189 insertions(+), 187 deletions(-)
---
diff --git a/libgnome/ChangeLog b/libgnome/ChangeLog
index 90a5ac4..7103fd0 100644
--- a/libgnome/ChangeLog
+++ b/libgnome/ChangeLog
@@ -1,3 +1,11 @@
+2001-08-04 Martin Baulig <baulig suse de>
+
+ * gnome-sound.h (gnome_sound_sample_new_from_cache): New func.
+ (gnome_sound_cache_add_sample): New func.
+ (gnome_sound_cache_remove_sample): New func.
+
+ * gnome-triggers.c: Re-enable this file.
+
2001-08-03 Martin Baulig <baulig suse de>
* libgnome-init.c (libbonobo_post_args_parse): Initialize the
diff --git a/libgnome/Makefile.am b/libgnome/Makefile.am
index fbac89d..c416a2e 100644
--- a/libgnome/Makefile.am
+++ b/libgnome/Makefile.am
@@ -55,6 +55,7 @@ libgnome_src = \
libgnometypebuiltins.c \
gnome-program.c \
gnome-sound.c \
+ gnome-triggers.c \
gnome-exec.c \
gnome-url.c \
gnome-util.c \
diff --git a/libgnome/gnome-program.h b/libgnome/gnome-program.h
index c76250f..96c444e 100644
--- a/libgnome/gnome-program.h
+++ b/libgnome/gnome-program.h
@@ -100,7 +100,7 @@ gnome_program_locate_file (GnomeProgram *program,
#define GNOME_PARAM_POPT_FLAGS "popt-flags"
#define GNOME_PARAM_POPT_CONTEXT "popt-context"
#define GNOME_PARAM_CREATE_DIRECTORIES "create-directories"
-#define GNOME_PARAM_ESPEAKER "espeaker"
+#define GNOME_PARAM_SOUND_DRIVER "sound-driver"
#define GNOME_PARAM_ENABLE_SOUND "enable-sound"
#define GNOME_PARAM_FILE_LOCATOR "file-locator"
#define GNOME_PARAM_APP_ID "app-id"
diff --git a/libgnome/gnome-sound-csl.c b/libgnome/gnome-sound-csl.c
index c743ba8..9c4017a 100644
--- a/libgnome/gnome-sound-csl.c
+++ b/libgnome/gnome-sound-csl.c
@@ -86,6 +86,33 @@ gnome_sound_csl_sample_new_from_file (const char *filename, GError **error)
}
static GnomeSoundSample *
+gnome_sound_csl_sample_new_from_cache (const char *name, GError **error)
+{
+ CslErrorType err;
+ CslSample *sample;
+ GnomeSoundSample *retval;
+
+ if (!gnome_sound_csl_driver)
+ return NULL;
+
+ err = csl_sample_new_from_cache (gnome_sound_csl_driver, name,
+ "gnome_sound_csl_sample_new", NULL,
+ &sample);
+ if (err) {
+ csl_warning ("unable to create sample from cache '%s': %s",
+ name, csl_strerror (err));
+ return NULL;
+ }
+
+ retval = g_new0 (GnomeSoundSample, 1);
+ retval->sample = sample;
+
+ g_ptr_array_add (active_samples, retval);
+
+ return retval;
+}
+
+static GnomeSoundSample *
gnome_sound_csl_sample_new (const char *sample_name, GError **error)
{
CslErrorType err;
@@ -112,6 +139,18 @@ gnome_sound_csl_sample_new (const char *sample_name, GError **error)
return retval;
}
+static void
+gnome_sound_csl_cache_add_sample (GnomeSoundSample *gs, GError **error)
+{
+ csl_sample_cache_add (gs->sample);
+}
+
+static void
+gnome_sound_csl_cache_remove_sample (GnomeSoundSample *gs, GError **error)
+{
+ csl_sample_cache_remove (gs->sample);
+}
+
static int
gnome_sound_csl_sample_write (GnomeSoundSample *gs,
guint n_bytes, gpointer bytes,
@@ -121,7 +160,7 @@ gnome_sound_csl_sample_write (GnomeSoundSample *gs,
}
static void
-gnome_sound_csl_sample_write_done (GnomeSoundSample *gs)
+gnome_sound_csl_sample_write_done (GnomeSoundSample *gs, GError **error)
{
csl_sample_write_done (gs->sample);
}
@@ -209,7 +248,10 @@ GnomeSoundPlugin gnome_sound_plugin = {
gnome_sound_csl_sample_new,
gnome_sound_csl_sample_write,
gnome_sound_csl_sample_write_done,
+ gnome_sound_csl_cache_add_sample,
+ gnome_sound_csl_cache_remove_sample,
gnome_sound_csl_sample_new_from_file,
+ gnome_sound_csl_sample_new_from_cache,
gnome_sound_csl_sample_play,
gnome_sound_csl_sample_is_playing,
gnome_sound_csl_sample_stop,
diff --git a/libgnome/gnome-sound.c b/libgnome/gnome-sound.c
index 1fbf2a1..f37dc94 100644
--- a/libgnome/gnome-sound.c
+++ b/libgnome/gnome-sound.c
@@ -53,7 +53,25 @@ gnome_sound_play (const char *filename, GError **error)
if (sound_plugin)
sound_plugin->play_file (filename, error);
else
- _gnome_sound_error_nodriver (error);
+ _gnome_sound_error_nodriver (error);
+}
+
+void
+gnome_sound_cache_add_sample (GnomeSoundSample *gs, GError **error)
+{
+ if (sound_plugin)
+ sound_plugin->cache_add_sample (gs, error);
+ else
+ _gnome_sound_error_nodriver (error);
+}
+
+void
+gnome_sound_cache_remove_sample (GnomeSoundSample *gs, GError **error)
+{
+ if (sound_plugin)
+ sound_plugin->cache_remove_sample (gs, error);
+ else
+ _gnome_sound_error_nodriver (error);
}
GnomeSoundSample *
@@ -68,6 +86,17 @@ gnome_sound_sample_new_from_file (const char *filename, GError **error)
}
GnomeSoundSample *
+gnome_sound_sample_new_from_cache (const char *name, GError **error)
+{
+ if (sound_plugin)
+ return sound_plugin->sample_new_from_cache (name, error);
+ else {
+ _gnome_sound_error_nodriver (error);
+ return NULL;
+ }
+}
+
+GnomeSoundSample *
gnome_sound_sample_new (const char *sample_name, GError **error)
{
if (sound_plugin)
@@ -223,3 +252,9 @@ gnome_sound_shutdown (GError **error)
sound_plugin_module = NULL;
}
}
+
+gboolean
+gnome_sound_enabled (void)
+{
+ return sound_plugin != NULL;
+}
diff --git a/libgnome/gnome-sound.h b/libgnome/gnome-sound.h
index 8433fe0..9ea102a 100644
--- a/libgnome/gnome-sound.h
+++ b/libgnome/gnome-sound.h
@@ -52,8 +52,16 @@ struct _GnomeSoundPlugin {
void (*sample_write_done) (GnomeSoundSample *gs,
GError **error);
+ void (*cache_add_sample) (GnomeSoundSample *sample,
+ GError **error);
+ void (*cache_remove_sample) (GnomeSoundSample *sample,
+ GError **error);
+
GnomeSoundSample * (*sample_new_from_file) (const gchar *filename,
GError **error);
+ GnomeSoundSample * (*sample_new_from_cache) (const gchar *name,
+ GError **error);
+
void (*sample_play) (GnomeSoundSample *gs,
GError **error);
gboolean (*sample_is_playing) (GnomeSoundSample *gs,
@@ -92,14 +100,26 @@ void gnome_sound_init (const gchar *driver_name,
void gnome_sound_shutdown (GError **error);
+gboolean gnome_sound_enabled (void);
+
void gnome_sound_play (const char *filename,
GError **error);
+void
+gnome_sound_cache_add_sample (GnomeSoundSample *sample, GError **error);
+
+void
+gnome_sound_cache_remove_sample (GnomeSoundSample *sample, GError **error);
+
GnomeSoundSample *
gnome_sound_sample_new_from_file (const char *filename,
GError **error);
GnomeSoundSample *
+gnome_sound_sample_new_from_cache (const char *name,
+ GError **error);
+
+GnomeSoundSample *
gnome_sound_sample_new (const char *sample_name,
GError **error);
diff --git a/libgnome/gnome-triggers.c b/libgnome/gnome-triggers.c
index b67c558..4daec50 100644
--- a/libgnome/gnome-triggers.c
+++ b/libgnome/gnome-triggers.c
@@ -29,16 +29,9 @@
#include "gnome-triggers.h"
#include "gnome-triggersP.h"
-#include "gnome-config.h"
#include "gnome-util.h"
-#if 0
#include "gnome-sound.h"
-#ifdef HAVE_ESD
-#include <esd.h>
-#endif
-#endif
-
#include <unistd.h>
#include <stdio.h>
#include <string.h>
@@ -93,158 +86,6 @@ gnome_triggers_init(void)
{
}
-#if 0
-/* snarfed almost directly from sound-properties. */
-static gint
-gnome_triggers_read_path(const char *config_path)
-{
- DIR *dirh;
- char *category_name, *sample_name, *sample_file, *ctmp;
- gpointer top_iter, event_iter;
- struct dirent *dent;
- GnomeTrigger nt;
- GString *tmpstr;
-
- nt.type = GTRIG_MEDIAPLAY;
- nt.level = NULL;
- nt.u.media.cache_id = -1;
-
- dirh = opendir(config_path);
- if(!dirh)
- return -1;
-
- tmpstr = g_string_new(NULL);
-
- while((dent = readdir(dirh))) {
- /* ignore no-good dir entries.
- We ignore "gnome" because the system sounds are listed in there.
- */
- if (!strcmp(dent->d_name, ".")
- || !strcmp(dent->d_name, "..")
- || !strcmp(dent->d_name, "gnome")
- || !strcmp(dent->d_name, "gnome.soundlist"))
- continue;
-
- g_string_sprintf(tmpstr, "=%s/%s=", config_path, dent->d_name);
-
- gnome_config_push_prefix(tmpstr->str);
-
- event_iter = gnome_config_init_iterator_sections(tmpstr->str);
- while((event_iter = gnome_config_iterator_next(event_iter,
- &sample_name, NULL))) {
- if(!strcmp(sample_name, "__section_info__"))
- goto continue_loop;
-
- g_string_sprintf(tmpstr, "%s/file", sample_name);
- sample_file = gnome_config_get_string(tmpstr->str);
-
- if(!sample_file || !*sample_file) {
- g_free(sample_name);
- continue;
- }
-
- if(*sample_file != '/') {
- char *tmp = gnome_sound_file(sample_file);
- g_free(sample_file);
- sample_file = tmp;
- }
-
- ctmp = g_strdup(dent->d_name);
- if(strstr(ctmp, ".soundlist"))
- *strstr(ctmp, ".soundlist") = '\0';
-
- nt.u.media.file = sample_file;
- gnome_triggers_add_trigger(&nt, ctmp, sample_name, NULL);
-
- g_free(ctmp);
-
- continue_loop:
- g_free(sample_name);
- }
-
- gnome_config_pop_prefix();
- }
- closedir(dirh);
-
- g_string_free(tmpstr, TRUE);
-
- return 0;
-}
-/**
- * gnome_triggers_readfile:
- * @infilename: A file listing triggers to install in the currently
- * running program.
- *
- * The file should be of the format:
- *
- * level section type params
- *
- * Where 'level' indicates the message severity at which this trigger
- * 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
- * 'params').
- *
- * Returns 0 on success. 1 otherwise.
- *
- */
-gint
-gnome_triggers_readfile(const char *infilename)
-{
- GnomeTrigger* nt;
- char aline[512];
- char **subnames = NULL;
- char **parts = NULL;
- FILE *infile;
- int i;
-
- infile = fopen(infilename, "r");
- if(infile == NULL)
- return 1;
-
- nt = gnome_trigger_dup(NULL);
- while(fgets(aline, sizeof(aline), infile)) {
- i = strlen(aline) - 1;
- while(isspace(aline[i])) aline[i--] = '\0';
-
- if(aline[0] == '\0' || aline[0] == '#')
- continue;
-
- parts = g_strsplit(aline, " ", 4);
- if(!parts || !parts[0] || !parts[1] || !parts[2] || !parts[3]) {
- g_strfreev(parts);
- g_warning("Invalid triggers line \'%s\'\n", aline);
- continue;
- }
-
- if(!strcmp(parts[1], "NULL")) {
- subnames = g_malloc(sizeof(gchar *));
- subnames[0] = NULL;
- } else
- subnames = g_strsplit(parts[1], ":", -1);
-
- if(!strcmp(parts[2], "command"))
- nt->type = GTRIG_COMMAND;
- else if(!strcmp(parts[2], "play"))
- nt->type = GTRIG_MEDIAPLAY;
- nt->u.command = parts[3];
- if(!strcmp(parts[0], "NULL"))
- nt->level = NULL;
- else
- nt->level = parts[0];
- gnome_triggers_vadd_trigger(nt, subnames);
-
- g_strfreev(subnames);
- g_strfreev(parts);
- }
- g_free(nt);
- fclose(infile);
-
- return 0;
-}
-#endif
-
/**
* gnome_triggers_add_trigger:
* @nt: Information on the new trigger to be added.
@@ -412,28 +253,24 @@ gnome_triggers_do(const char *msg, const char *level, ...)
static void
gnome_triggers_play_sound(const char *sndname)
{
-#if defined(HAVE_ESD) && 0
- int sid;
- static GHashTable *sound_ids = NULL;
+ GnomeSoundSample *sample;
+ static GHashTable *sound_samples = NULL;
- if(gnome_sound_connection < 0) return;
+ if(!gnome_sound_enabled()) return;
- if(!sound_ids)
- sound_ids = g_hash_table_new(g_str_hash, g_str_equal);
+ if(!sound_samples)
+ sound_samples = g_hash_table_new(g_str_hash, g_str_equal);
- sid = GPOINTER_TO_INT(g_hash_table_lookup(sound_ids, sndname));
+ sample = g_hash_table_lookup(sound_samples, sndname);
- if(!sid) {
- sid = esd_sample_getid(gnome_sound_connection, sndname);
- if(sid >= 0) sid++;
- g_hash_table_insert(sound_ids, g_strdup(sndname), GINT_TO_POINTER(sid));
+ if(!sample) {
+ sample = gnome_sound_sample_new_from_cache(sndname, NULL);
+ if(sample)
+ g_hash_table_insert(sound_samples, g_strdup(sndname), sample);
}
- if(sid < 0) return;
- sid--;
- esd_sample_play(gnome_sound_connection, sid);
-#endif
- /* If there's no esound, this is just a no-op */
+ if(!sample) return;
+ gnome_sound_sample_play(sample, NULL);
}
/**
@@ -593,13 +430,11 @@ gnome_trigger_do_mediaplay(GnomeTrigger* t,
const char *level,
const char *supinfo[])
{
-#if defined(HAVE_ESD) && 0
- if(gnome_sound_connection == -1)
+ if(!gnome_sound_enabled())
return;
- if(t->u.media.cache_id >= 0)
- esd_sample_play(gnome_sound_connection, t->u.media.cache_id);
- else if(t->u.media.cache_id == -1)
- gnome_sound_play(t->u.media.file);
-#endif
+ if(t->u.media.sample)
+ gnome_sound_sample_play(t->u.media.sample, NULL);
+ else if(t->u.media.file)
+ gnome_sound_play(t->u.media.file, NULL);
}
diff --git a/libgnome/gnome-triggers.h b/libgnome/gnome-triggers.h
index 5afb019..4ad55c4 100644
--- a/libgnome/gnome-triggers.h
+++ b/libgnome/gnome-triggers.h
@@ -27,6 +27,7 @@
#define __GNOME_TRIGGERS_H__
#include <glib.h>
+#include <libgnome/gnome-sound.h>
G_BEGIN_DECLS
@@ -50,7 +51,7 @@ struct _GnomeTrigger {
gchar *command;
struct {
gchar *file;
- int cache_id;
+ GnomeSoundSample *sample;
} media;
} u;
gchar *level;
diff --git a/libgnome/test-sound.c b/libgnome/test-sound.c
index 08e581a..d7c923a 100644
--- a/libgnome/test-sound.c
+++ b/libgnome/test-sound.c
@@ -4,16 +4,60 @@
#include <stdio.h>
#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <libgnome/libgnome-init.h>
#include <libgnome/gnome-sound.h>
+#include <libgnome/gnome-triggers.h>
+
+int global_cntr = 0;
+
+static void
+sample_trigger_function(char *msg, char *level, char *supinfo[])
+{
+ int i;
+ for(i = 0; supinfo[i]; i++)
+ g_print("%s ", supinfo[i]);
+ g_print("[%s] %s\n", level, msg);
+ fflush(stdout);
+
+ global_cntr++;
+}
+
+static void
+sample_read_from_file (GnomeSoundSample *gs, const gchar *name)
+{
+ int fd = open (name, O_RDONLY);
+
+ if (fd >= 0) {
+ char buffer[4096];
+ int len;
+
+ do {
+ do
+ len = read (fd, buffer, sizeof (buffer));
+ while (len < 0 && errno == EINTR);
+
+ if (len > 0)
+ gnome_sound_sample_write (gs, len, buffer, NULL);
+ }
+
+ while (len > 0);
+ close (fd);
+ }
+
+ gnome_sound_sample_write_done (gs, NULL);
+}
int
main (int argc, char **argv)
{
+ struct _GnomeTrigger trig;
GnomeProgram *program;
+ GnomeSoundSample *gs;
program = gnome_program_init ("test-sound", VERSION,
&libgnome_module_info,
@@ -21,7 +65,23 @@ main (int argc, char **argv)
gnome_sound_init ("csl", NULL, NULL, NULL);
- gnome_sound_play ("gameover.wav", NULL);
+ gs = gnome_sound_sample_new ("gnome/warning", NULL);
+ sample_read_from_file (gs, "/usr/share/sounds/phone.wav");
+ gnome_sound_cache_add_sample (gs, NULL);
+ gnome_sound_sample_release (gs, NULL);
+
+ gs = gnome_sound_sample_new ("test/one", NULL);
+ sample_read_from_file (gs, "/usr/share/sounds/panel/slide.wav");
+ gnome_sound_cache_add_sample (gs, NULL);
+ gnome_sound_sample_release (gs, NULL);
+
+ trig.type = GTRIG_FUNCTION;
+ trig.u.function = sample_trigger_function;
+ trig.level = NULL;
+
+ gnome_triggers_init ();
+ gnome_triggers_add_trigger (&trig, "test", "one", NULL);
+ gnome_triggers_do ("Test of direct hit", "warning", "test", "one", NULL);
sleep(5);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]