New volume change interrupts old one
authorPhilip Chimento <philip.chimento@gmail.com>
Sat, 16 Jul 2011 19:37:23 +0000 (21:37 +0200)
committerPhilip Chimento <philip.chimento@gmail.com>
Sat, 16 Jul 2011 19:37:23 +0000 (21:37 +0200)
Also, add guards for compiling without GStreamer

libchimara/schannel.c
libchimara/schannel.h

index f4c7bd63a43bdc7f62b1d3826e170f5f07fa4ab5..d176d7d87caf7ef04aa878340aea32943863b2a1 100644 (file)
@@ -680,21 +680,6 @@ glk_schannel_unpause(schanid_t chan)
        }
 }
 
-static double
-volume_glk_to_gstreamer(glui32 volume_glk)
-{
-       return CLAMP(((double)volume_glk / 0x10000), 0.0, 10.0);
-}
-
-static void
-channel_set_volume_immediately(schanid_t chan, double volume, glui32 notify)
-{
-       g_object_set(chan->filter, "volume", volume, NULL);
-
-       if(notify != 0)
-               event_throw(chan->glk, evtype_VolumeNotify, NULL, 0, notify);
-}
-
 /**
  * glk_schannel_set_volume:
  * @chan: Channel to set the volume of.
@@ -727,15 +712,16 @@ channel_set_volume_immediately(schanid_t chan, double volume, glui32 notify)
 void 
 glk_schannel_set_volume(schanid_t chan, glui32 vol)
 {
-       VALID_SCHANNEL(chan, return);
-       /* Silently ignore out-of-range volume values */
+       glk_schannel_set_volume_ext(chan, vol, 0, 0);
+}
 
-#ifdef GSTREAMER_SOUND
-       double volume = volume_glk_to_gstreamer(vol);
-       channel_set_volume_immediately(chan, volume, 0);
-#endif
+static double
+volume_glk_to_gstreamer(glui32 volume_glk)
+{
+       return CLAMP(((double)volume_glk / 0x10000), 0.0, 10.0);
 }
 
+#ifdef GSTREAMER_SOUND
 static gboolean
 volume_change_timeout(schanid_t chan)
 {
@@ -749,6 +735,7 @@ volume_change_timeout(schanid_t chan)
                if(chan->volume_notify)
                        event_throw(chan->glk, evtype_VolumeNotify, NULL, 0, chan->volume_notify);
 
+               chan->volume_timer_id = 0;
                return FALSE;
        }
 
@@ -765,6 +752,7 @@ volume_change_timeout(schanid_t chan)
 
        return TRUE;
 }
+#endif /* GSTREAMER_SOUND */
 
 /**
  * glk_schannel_set_volume_ext:
@@ -809,12 +797,20 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32
 {
        VALID_SCHANNEL(chan, return);
        /* Silently ignore out-of-range volume values */
-       
+
 #ifdef GSTREAMER_SOUND
+       /* Interrupt a previous volume change */
+       if(chan->volume_timer_id > 0)
+               g_source_remove(chan->volume_timer_id);
+       
        double target_volume = volume_glk_to_gstreamer(vol);
 
        if(duration == 0) {
-               channel_set_volume_immediately(chan, target_volume, notify);
+               g_object_set(chan->filter, "volume", target_volume, NULL);
+
+               if(notify != 0)
+                       event_throw(chan->glk, evtype_VolumeNotify, NULL, 0, notify);
+
                return;
        }
 
@@ -828,7 +824,7 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32
        chan->volume_notify = notify;
 
        /* Set up a timer for the volume */
-       g_timeout_add(VOLUME_TIMER_RESOLUTION, (GSourceFunc)volume_change_timeout, chan);
+       chan->volume_timer_id = g_timeout_add(VOLUME_TIMER_RESOLUTION, (GSourceFunc)volume_change_timeout, chan);
 #endif
 }
 
index 9a7712d72f80b60548da4559d1745237bdbf7e4b..a0eba8715520ac91d800fd8c9614c563397d32f0 100644 (file)
@@ -31,6 +31,7 @@ struct glk_schannel_struct
        /* Volume change information */
        double target_volume;
        long target_time_sec, target_time_usec;
+       guint volume_timer_id;
        glui32 volume_notify;
 
 #ifdef GSTREAMER_SOUND