GESTimelineStandardTransition: keep track of TrackVideoTransition
authorThibault Saunier <thibault.saunier@collabora.co.uk>
Wed, 27 Apr 2011 13:11:44 +0000 (10:11 -0300)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Thu, 19 May 2011 19:58:51 +0000 (21:58 +0200)
Use the new track_object_added/release vfunc to get cleaner code

ges/ges-timeline-standard-transition.c

index 325a9279eb63f910e8752395f3ad1f39f6789928..713b82a08ae1ab4fa43256f4300e8395ee17a7f8 100644 (file)
@@ -42,8 +42,7 @@
 
 struct _GESTimelineStandardTransitionPrivate
 {
-  /* Dummy variable */
-  void *nothing;
+  GSList *track_video_transitions;
 };
 
 enum
@@ -56,32 +55,28 @@ G_DEFINE_TYPE (GESTimelineStandardTransition, ges_timeline_standard_transition,
 
 static GESTrackObject *ges_tl_transition_create_track_object (GESTimelineObject
     * self, GESTrack * track);
+static void
+ges_timeline_standard_transition_track_object_added (GESTimelineObject * obj,
+    GESTrackObject * tckobj);
+static void
+ges_timeline_standard_transition_track_object_released (GESTimelineObject * obj,
+    GESTrackObject * tckobj);
 
 static void
 ges_timeline_standard_transition_update_vtype_internal (GESTimelineObject *
     self, GESVideoStandardTransitionType value)
 {
-  GList *tmp, *trackobjects;
+  GSList *tmp;
   GESTimelineStandardTransition *trself =
-      (GESTimelineStandardTransition *) self;
-
-  /* FIXME : We need a much less crack way to find the trackobject to change */
-  trackobjects = ges_timeline_object_get_track_objects (self);
-  for (tmp = trackobjects; tmp; tmp = tmp->next) {
-    GESTrackVideoTransition *obj;
-    if (GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
-      obj = (GESTrackVideoTransition *) tmp->data;
-      if (!ges_track_video_transition_set_transition_type (obj, value))
-        goto beach;
-    }
+      GES_TIMELINE_STANDARD_TRANSITION (self);
+
+  for (tmp = trself->priv->track_video_transitions; tmp; tmp = tmp->next) {
+    if (!ges_track_video_transition_set_transition_type
+        (GES_TRACK_VIDEO_TRANSITION (tmp->data), value))
+      return;
   }
 
   trself->vtype = value;
-
-beach:
-  g_list_foreach (trackobjects, (GFunc) g_object_unref, NULL);
-  g_list_free (trackobjects);
-  return;
 }
 
 static void
@@ -143,6 +138,10 @@ ges_timeline_standard_transition_class_init (GESTimelineStandardTransitionClass
 
   timobj_class->create_track_object = ges_tl_transition_create_track_object;
   timobj_class->need_fill_track = FALSE;
+  timobj_class->track_object_added =
+      ges_timeline_standard_transition_track_object_added;
+  timobj_class->track_object_released =
+      ges_timeline_standard_transition_track_object_released;
 }
 
 static void
@@ -156,6 +155,36 @@ ges_timeline_standard_transition_init (GESTimelineStandardTransition * self)
   self->vtype = GES_VIDEO_STANDARD_TRANSITION_TYPE_NONE;
 }
 
+static void
+ges_timeline_standard_transition_track_object_released (GESTimelineObject * obj,
+    GESTrackObject * tckobj)
+{
+  GESTimelineStandardTransitionPrivate *priv =
+      GES_TIMELINE_STANDARD_TRANSITION (obj)->priv;
+
+  /* If this is called, we should be sure the tckobj exists */
+  if (GES_IS_TRACK_VIDEO_TRANSITION (tckobj)) {
+    GST_DEBUG ("GESTrackVideoTransition %p released from %p", tckobj, obj);
+    priv->track_video_transitions =
+        g_slist_remove (priv->track_video_transitions, tckobj);
+    g_object_unref (tckobj);
+  }
+}
+
+static void
+ges_timeline_standard_transition_track_object_added (GESTimelineObject * obj,
+    GESTrackObject * tckobj)
+{
+  GESTimelineStandardTransitionPrivate *priv =
+      GES_TIMELINE_STANDARD_TRANSITION (obj)->priv;
+
+  if (GES_IS_TRACK_VIDEO_TRANSITION (tckobj)) {
+    GST_DEBUG ("GESTrackVideoTransition %p added to %p", tckobj, obj);
+    priv->track_video_transitions =
+        g_slist_prepend (priv->track_video_transitions, g_object_ref (tckobj));
+  }
+}
+
 static GESTrackObject *
 ges_tl_transition_create_track_object (GESTimelineObject * obj,
     GESTrack * track)