Implemented sound notification events
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 15:24:05 +0000 (16:24 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 15:24:05 +0000 (16:24 +0100)
Sound notification events now work.

libchimara/gestalt.c
libchimara/schannel.c
libchimara/schannel.h
tests/soundtest.c

index 06154591117d7d8d6ede5204e1141761e6ffd3c7..ebeb765f20a9f59d00697fa5758d345f1f6f33c1 100644 (file)
@@ -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:
index e9f705245111d5418c939bee0949c7744f61c315..70bb7e182797ba1a1ee76d8e2c02f1e934cf25a5 100644 (file)
@@ -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 */
        
index 4a4b1fdcfea5964d184f4fb5746a936c127bbc90..465e7dc51fe9b7095dbf870ffec104dd0a14bc2a 100644 (file)
@@ -5,6 +5,7 @@
 #include <glib.h>
 #include "glk.h"
 #include "gi_dispa.h"
+#include "chimara-glk.h"
 #ifdef GSTREAMER_SOUND
 #include <gst/gst.h>
 #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;
        
index d9ff17aa941d29ff51dc75acab1959bb47279094..b3014797f6f14435be4d40c744fe16814828d4c6 100644 (file)
@@ -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: