From: P. F. Chimento Date: Sun, 30 Jan 2011 15:24:05 +0000 (+0100) Subject: Implemented sound notification events X-Git-Tag: v0.9~152^2~2 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=ac30e8631fb7fc29e2954e9bfca734d9aeaa642b;p=projects%2Fchimara%2Fchimara.git Implemented sound notification events Sound notification events now work. --- diff --git a/libchimara/gestalt.c b/libchimara/gestalt.c index 0615459..ebeb765 100644 --- a/libchimara/gestalt.c +++ b/libchimara/gestalt.c @@ -126,8 +126,10 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_GraphicsTransparency: return 1; + /* Capabilities supported if compiled with GStreamer */ case gestalt_Sound: case gestalt_SoundVolume: + case gestalt_SoundNotify: #ifdef GSTREAMER_SOUND return 1; #else @@ -135,7 +137,6 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) #endif /* Unsupported capabilities */ - case gestalt_SoundNotify: case gestalt_SoundMusic: /* Selector not supported */ default: diff --git a/libchimara/schannel.c b/libchimara/schannel.c index e9f7052..70bb7e1 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -11,6 +11,7 @@ #include "gi_dispa.h" #include "gi_blorb.h" #include "resource.h" +#include "event.h" extern GPrivate *glk_data_key; @@ -81,6 +82,9 @@ on_pipeline_message(GstBus *bus, GstMessage *message, schanid_t s) } } else { clean_up_after_playing_sound(s); + /* Sound ended normally, send a notification if requested */ + if(s->notify) + event_throw(s->glk, evtype_SoundNotify, NULL, s->resource, s->notify); } break; default: @@ -182,6 +186,9 @@ glk_schannel_create(glui32 rock) glk_data->schannel_list = g_list_prepend(glk_data->schannel_list, s); s->schannel_list = glk_data->schannel_list; + /* Add a pointer to the ChimaraGlk widget, for convenience */ + s->glk = glk_data->self; + /* Create a GStreamer pipeline for the sound channel */ gchar *pipeline_name = g_strdup_printf("pipeline-%p", s); s->pipeline = gst_pipeline_new(pipeline_name); @@ -428,6 +435,8 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) } chan->repeats = repeats; + chan->resource = snd; + chan->notify = notify; g_object_set(chan->source, "stream", stream, NULL); g_object_unref(stream); /* Now owned by GStreamer element */ diff --git a/libchimara/schannel.h b/libchimara/schannel.h index 4a4b1fd..465e7dc 100644 --- a/libchimara/schannel.h +++ b/libchimara/schannel.h @@ -5,6 +5,7 @@ #include #include "glk.h" #include "gi_dispa.h" +#include "chimara-glk.h" #ifdef GSTREAMER_SOUND #include #endif @@ -17,7 +18,11 @@ struct glk_schannel_struct /* Pointer to the list node in the global sound channel list that contains this sound channel */ GList *schannel_list; + /* Pointer to the GTK widget this sound channel belongs to, for convenience */ + ChimaraGlk *glk; + /* Resource number and notification ID of last played sound */ + glui32 resource, notify; /* How many times to repeat the last sound played (-1 = forever) */ glui32 repeats; diff --git a/tests/soundtest.c b/tests/soundtest.c index d9ff17a..b301479 100644 --- a/tests/soundtest.c +++ b/tests/soundtest.c @@ -37,6 +37,7 @@ glk_main(void) char buffer[1024]; int len; int finish = 0; + int repeat = 1; event_t ev; while(!finish) { @@ -45,7 +46,11 @@ glk_main(void) glk_select(&ev); printf("Received event:\n"); printf("Type: %d\n", ev.type); - printf("Win: %d\n", glk_window_get_rock(ev.win) ); + printf("Win: "); + if(ev.win) + printf( "%d\n", glk_window_get_rock(ev.win) ); + else + printf("NULL\n"); printf("Var1: %d\n", ev.val1); printf("Var2: %d\n", ev.val2); switch(ev.type) { @@ -59,15 +64,34 @@ glk_main(void) finish = 1; } else if(strcmp(buffer, "play") == 0) { glk_put_string("Playing sound.\n"); - if(!glk_schannel_play(sc, 3)) { + if(!glk_schannel_play_ext(sc, 3, repeat, 1)) { fprintf(stderr, "Could not start sound channel.\n"); finish = 1; } + } else if(strcmp(buffer, "stop") == 0) { + glk_put_string("Stopping sound.\n"); + glk_schannel_stop(sc); + } else if(strcmp(buffer, "repeat") == 0) { + glk_put_string("Setting repeat to "); + if(repeat == 1) { + glk_put_string("TWICE.\n"); + repeat = 2; + } else if(repeat == 2) { + glk_put_string("INFINITE.\n"); + repeat = -1; + } else if(repeat == -1) { + glk_put_string("DON'T PLAY.\n"); + repeat = 0; + } else if(repeat == 0) { + glk_put_string("ONCE.\n"); + repeat = 1; + } } else if(strcmp(buffer, "help") == 0) { - glk_put_string("Type PLAY or QUIT.\n"); + glk_put_string("Type PLAY or REPEAT or STOP or QUIT.\n"); } break; case evtype_SoundNotify: + glk_cancel_line_event(mainwin, NULL); glk_put_string("\nGot sound notify event!\n"); break; default: