1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
4 * 2011 Mathieu Duponchelle <mathieu.duponchelle@epitech.eu>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:ges-timeline-layer
24 * @short_description: Non-overlapping sequence of #GESTimelineObject
26 * Responsible for the ordering of the various contained TimelineObject(s). A
27 * timeline layer has a "priority" property, which is used to manage the
28 * priorities of individual TimelineObjects. Two layers should not have the
29 * same priority within a given timeline.
32 #include "ges-internal.h"
33 #include "ges-timeline-layer.h"
35 #include "ges-timeline-source.h"
37 #define LAYER_HEIGHT 1000
40 track_object_removed_cb (GESTimelineObject * object,
41 GESTrackObject * track_object);
42 static void track_object_added_cb (GESTimelineObject * object,
43 GESTrackObject * track_object, GHashTable * signal_table);
44 static void track_object_changed_cb (GESTrackObject * track_object,
45 GParamSpec * arg G_GNUC_UNUSED);
46 static void calculate_transitions (GESTrackObject * track_object);
47 static void calculate_next_transition (GESTrackObject * track_object,
48 GESTimelineLayer * layer);
51 timeline_object_height_changed_cb (GESTimelineObject * obj,
52 GESTrackEffect * tr_eff, GESTimelineObject * second_obj);
54 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_INITIALLY_UNOWNED);
56 struct _GESTimelineLayerPrivate
59 GList *objects_start; /* The TimelineObjects sorted by start and
62 guint32 priority; /* The priority of the layer within the
63 * containing timeline */
65 gboolean auto_transition;
68 GHashTable *signal_table;
86 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
88 static gboolean ges_timeline_layer_resync_priorities (GESTimelineLayer * layer);
90 static GList *track_get_by_layer (GESTimelineLayer * layer, GESTrack * track);
92 static void compare (GList * compared, GESTrackObject * track_object,
96 ges_timeline_layer_get_property (GObject * object, guint property_id,
97 GValue * value, GParamSpec * pspec)
99 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
101 switch (property_id) {
103 g_value_set_uint (value, layer->priv->priority);
105 case PROP_AUTO_TRANSITION:
106 g_value_set_boolean (value, layer->priv->auto_transition);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 ges_timeline_layer_set_property (GObject * object, guint property_id,
115 const GValue * value, GParamSpec * pspec)
117 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
119 switch (property_id) {
121 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
123 case PROP_AUTO_TRANSITION:
124 ges_timeline_layer_set_auto_transition (layer,
125 g_value_get_boolean (value));
128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
133 ges_timeline_layer_dispose (GObject * object)
135 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
136 GESTimelineLayerPrivate *priv = layer->priv;
138 GST_DEBUG ("Disposing layer");
140 while (priv->objects_start)
141 ges_timeline_layer_remove_object (layer,
142 (GESTimelineObject *) priv->objects_start->data);
144 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
148 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
150 GObjectClass *object_class = G_OBJECT_CLASS (klass);
152 g_type_class_add_private (klass, sizeof (GESTimelineLayerPrivate));
154 object_class->get_property = ges_timeline_layer_get_property;
155 object_class->set_property = ges_timeline_layer_set_property;
156 object_class->dispose = ges_timeline_layer_dispose;
159 * GESTimelineLayer:priority
161 * The priority of the layer in the #GESTimeline. 0 is the highest
162 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
163 * and the priority of the layer represents its position in the stack. Two
164 * layers should not have the same priority within a given GESTimeline.
166 g_object_class_install_property (object_class, PROP_PRIORITY,
167 g_param_spec_uint ("priority", "Priority",
168 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
171 * GESTimelineLayer:auto-transition
173 * Sets whether transitions are added automagically when timeline objects overlap.
175 g_object_class_install_property (object_class, PROP_AUTO_TRANSITION,
176 g_param_spec_boolean ("auto-transition", "Auto-Transition",
177 "whether the transitions are added", FALSE, G_PARAM_READWRITE));
180 * GESTimelineLayer::object-added
181 * @layer: the #GESTimelineLayer
182 * @object: the #GESTimelineObject that was added.
184 * Will be emitted after the object was added to the layer.
186 ges_timeline_layer_signals[OBJECT_ADDED] =
187 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
188 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
189 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
190 GES_TYPE_TIMELINE_OBJECT);
193 * GESTimelineLayer::object-removed
194 * @layer: the #GESTimelineLayer
195 * @object: the #GESTimelineObject that was removed
197 * Will be emitted after the object was removed from the layer.
199 ges_timeline_layer_signals[OBJECT_REMOVED] =
200 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
201 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
202 object_removed), NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
203 1, GES_TYPE_TIMELINE_OBJECT);
207 ges_timeline_layer_init (GESTimelineLayer * self)
209 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
210 GES_TYPE_TIMELINE_LAYER, GESTimelineLayerPrivate);
212 self->priv->priority = 0;
213 self->priv->auto_transition = FALSE;
214 self->min_gnl_priority = 0;
215 self->max_gnl_priority = LAYER_HEIGHT;
216 self->priv->signal_table =
217 g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref,
222 * ges_timeline_layer_new:
224 * Creates a new #GESTimelineLayer.
226 * Returns: A new #GESTimelineLayer
229 ges_timeline_layer_new (void)
231 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
235 * ges_timeline_layer_get_timeline:
236 * @layer: The #GESTimelineLayer to get the parent #GESTimeline from
238 * Get the #GESTimeline in which #GESTimelineLayer currently is.
240 * Returns: (transfer none): the #GESTimeline in which #GESTimelineLayer
241 * currently is or %NULL if not in any timeline yet.
244 ges_timeline_layer_get_timeline (GESTimelineLayer * layer)
246 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
248 return layer->timeline;
252 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
253 GESTimeline * timeline)
255 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
257 layer->timeline = timeline;
261 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
263 if (a->start == b->start) {
264 if (a->priority < b->priority)
266 if (a->priority > b->priority)
270 if (a->start < b->start)
272 if (a->start > b->start)
278 track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
280 GList *tck_objects_list = NULL, *tmp = NULL, *return_list = NULL;
281 GESTimelineObject *tl_obj;
283 tck_objects_list = ges_track_get_objects (track);
284 for (tmp = tck_objects_list; tmp; tmp = tmp->next) {
285 tl_obj = ges_track_object_get_timeline_object (tmp->data);
287 if (ges_timeline_object_get_layer (tl_obj) == layer) {
288 /* We steal the reference from tck_objects_list */
289 return_list = g_list_append (return_list, tmp->data);
292 g_object_unref (tmp->data);
299 * ges_timeline_layer_add_object:
300 * @layer: a #GESTimelineLayer
301 * @object: (transfer full): the #GESTimelineObject to add.
303 * Adds the given object to the layer. Sets the object's parent, and thus
304 * takes ownership of the object.
306 * An object can only be added to one layer.
308 * Returns: TRUE if the object was properly added to the layer, or FALSE
309 * if the @layer refuses to add the object.
312 ges_timeline_layer_add_object (GESTimelineLayer * layer,
313 GESTimelineObject * object)
315 GESTimelineLayer *tl_obj_layer;
316 guint32 maxprio, minprio, prio;
318 GST_DEBUG ("layer:%p, object:%p", layer, object);
320 tl_obj_layer = ges_timeline_object_get_layer (object);
322 if (G_UNLIKELY (tl_obj_layer)) {
323 GST_WARNING ("TimelineObject %p already belongs to another layer", object);
324 g_object_unref (tl_obj_layer);
328 g_object_ref_sink (object);
330 /* Take a reference to the object and store it stored by start/priority */
331 layer->priv->objects_start =
332 g_list_insert_sorted (layer->priv->objects_start, object,
333 (GCompareFunc) objects_start_compare);
335 /* We have to wait for the track objects to be created to calculate transitions */
336 if (layer->priv->auto_transition) {
337 if (GES_IS_TIMELINE_SOURCE (object)) {
338 g_signal_connect (G_OBJECT (object), "track-object-added",
339 G_CALLBACK (track_object_added_cb), layer->priv->signal_table);
340 g_signal_connect (G_OBJECT (object), "track-object-removed",
341 G_CALLBACK (track_object_removed_cb), NULL);
345 /* Inform the object it's now in this layer */
346 ges_timeline_object_set_layer (object, layer);
348 GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
349 GES_TIMELINE_OBJECT_PRIORITY (object),
350 layer->min_gnl_priority, layer->max_gnl_priority);
352 /* Set the priority. */
353 maxprio = layer->max_gnl_priority;
354 minprio = layer->min_gnl_priority;
355 prio = GES_TIMELINE_OBJECT_PRIORITY (object);
356 if (minprio + prio > (maxprio)) {
357 GST_WARNING ("%p is out of the layer %p space, setting its priority to "
358 "setting its priority %d to failthe maximum priority of the layer %d",
359 object, layer, prio, maxprio - minprio);
360 ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
362 /* If the object has an acceptable priority, we just let it with its current
365 ges_timeline_layer_resync_priorities (layer);
367 /* emit 'object-added' */
368 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
374 track_object_duration_cb (GESTrackObject * track_object,
375 GParamSpec * arg G_GNUC_UNUSED)
377 GESTimelineLayer *layer;
378 GESTimelineObject *tlobj;
380 tlobj = ges_track_object_get_timeline_object (track_object);
381 layer = ges_timeline_object_get_layer (tlobj);
382 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
383 GST_DEBUG ("Here we should recalculate");
384 calculate_next_transition (track_object, layer);
388 track_object_deleted_cb (GESTrack * track, GESTrackObject * track_object)
390 GList *track_objects, *tmp, *cur;
391 GESTimelineLayer *layer;
393 track_objects = ges_track_get_objects (track);
394 cur = g_list_find (track_objects, track_object);
395 for (tmp = cur->next; tmp; tmp = tmp->next) {
396 if (GES_IS_TRACK_SOURCE (tmp->data)) {
399 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
400 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
402 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
404 if (ges_timeline_layer_get_auto_transition (layer)) {
405 ges_track_enable_update (track, FALSE);
406 ges_timeline_layer_remove_object (layer,
407 ges_track_object_get_timeline_object (tmp->data));
408 ges_track_enable_update (track, TRUE);
410 g_object_unref (layer);
414 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
415 if (GES_IS_TRACK_SOURCE (tmp->data)) {
418 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
419 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
421 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
423 if (ges_timeline_layer_get_auto_transition (layer)) {
424 ges_track_enable_update (track, FALSE);
425 ges_timeline_layer_remove_object (layer,
426 ges_track_object_get_timeline_object (tmp->data));
427 ges_track_enable_update (track, TRUE);
429 g_object_unref (layer);
432 g_object_unref (track_object);
436 track_object_added_cb (GESTimelineObject * object,
437 GESTrackObject * track_object, GHashTable * signal_table)
442 if (GES_IS_TRACK_SOURCE (track_object)) {
443 g_signal_connect (G_OBJECT (track_object), "notify::start",
444 G_CALLBACK (track_object_changed_cb), NULL);
445 g_signal_connect (G_OBJECT (track_object), "notify::duration",
446 G_CALLBACK (track_object_duration_cb), NULL);
447 calculate_transitions (track_object);
449 track = ges_track_object_get_track (track_object);
450 if (!g_hash_table_lookup (signal_table, track)) {
451 ptr = g_signal_connect (track, "track-object-removed",
452 (GCallback) track_object_deleted_cb, NULL);
453 g_hash_table_insert (signal_table, track, GINT_TO_POINTER (ptr));
459 track_object_removed_cb (GESTimelineObject * object,
460 GESTrackObject * track_object)
463 if (GES_IS_TRACK_SOURCE (track_object)) {
464 g_signal_handlers_disconnect_by_func (track_object, track_object_changed_cb,
471 timeline_object_height_changed_cb (GESTimelineObject * obj,
472 GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
474 gint priority, height;
475 g_object_get (obj, "height", &height, "priority", &priority, NULL);
476 g_object_set (second_obj, "priority", priority + height, NULL);
480 track_object_changed_cb (GESTrackObject * track_object,
481 GParamSpec * arg G_GNUC_UNUSED)
483 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
484 calculate_transitions (track_object);
488 calculate_next_transition_with_list (GESTrackObject * track_object,
489 GList * tckobjs_in_layer, GESTimelineLayer * layer)
493 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
496 if (compared == NULL)
497 /* This is the last TrackObject of the Track */
501 compared = compared->next;
502 if (compared == NULL)
504 } while (!GES_IS_TRACK_SOURCE (compared->data));
506 compare (compared, track_object, FALSE);
511 calculate_next_transition (GESTrackObject * track_object,
512 GESTimelineLayer * layer)
514 GESTrack *track = ges_track_object_get_track (track_object);
515 GList *tckobjs_in_layer = track_get_by_layer (layer, track);
517 if (ges_track_object_get_track (track_object)) {
518 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
521 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
522 g_list_free (tckobjs_in_layer);
526 calculate_transitions (GESTrackObject * track_object)
528 GList *tckobjs_in_layer, *compared;
529 GESTrack *track = ges_track_object_get_track (track_object);
530 GESTimelineLayer *layer;
531 GESTimelineObject *tlobj;
533 tlobj = ges_track_object_get_timeline_object (track_object);
534 layer = ges_timeline_object_get_layer (tlobj);
535 tckobjs_in_layer = track_get_by_layer (layer, track);
536 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
539 compared = compared->prev;
541 if (compared == NULL) {
542 /* Nothing before, let's check after */
543 calculate_next_transition_with_list (track_object, tckobjs_in_layer,
548 } while (!GES_IS_TRACK_SOURCE (compared->data));
550 compare (compared, track_object, TRUE);
552 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
555 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
556 g_list_free (tckobjs_in_layer);
561 * @compared: The #GList of #GESTrackObjects that we compare with @track_object
562 * @track_object: The #GESTrackObject that serves as a reference
563 * @ahead: %TRUE if we are comparing frontward %FALSE if we are comparing
566 compare (GList * compared, GESTrackObject * track_object, gboolean ahead)
569 gint64 start, duration, compared_start, compared_duration, end, compared_end,
570 tr_start, tr_duration;
571 GESTimelineStandardTransition *trans = NULL;
573 GESTimelineLayer *layer;
574 GESTimelineObject *object, *compared_object, *first_object, *second_object;
577 g_return_if_fail (compared);
579 GST_DEBUG ("Recalculating transitions");
581 object = ges_track_object_get_timeline_object (track_object);
584 GST_WARNING ("Trackobject not in a timeline object: "
585 "Can not calulate transitions");
590 compared_object = ges_track_object_get_timeline_object (compared->data);
591 layer = ges_timeline_object_get_layer (object);
593 start = ges_track_object_get_start (track_object);
594 duration = ges_track_object_get_duration (track_object);
595 compared_start = ges_track_object_get_start (compared->data);
596 compared_duration = ges_track_object_get_duration (compared->data);
597 end = start + duration;
598 compared_end = compared_start + compared_duration;
601 /* Make sure we remove the last transition we created it is not needed
602 * FIXME make it a smarter way */
603 if (compared->prev && GES_IS_TRACK_TRANSITION (compared->prev->data)) {
604 trans = GES_TIMELINE_STANDARD_TRANSITION
605 (ges_track_object_get_timeline_object (compared->prev->data));
606 g_object_get (compared->prev->data, "start", &tr_start, "duration",
608 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
609 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
613 for (tmp = compared->next; tmp; tmp = tmp->next) {
614 /* If we have a transitionmnmnm we recaluculuculate its values */
615 if (GES_IS_TRACK_TRANSITION (tmp->data)) {
616 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
619 if (tr_start + tr_duration == compared_start + compared_duration) {
620 GESTimelineObject *tlobj;
621 tlobj = ges_track_object_get_timeline_object (tmp->data);
623 trans = GES_TIMELINE_STANDARD_TRANSITION (tlobj);
629 if (compared_end <= start) {
631 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
632 g_object_get (compared_object, "priority", &priority, NULL);
633 g_object_set (object, "priority", priority, NULL);
637 } else if (start > compared_start && end < compared_end) {
639 /* Transition not needed anymore */
640 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
643 } else if (start <= compared_start) {
645 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
652 if (compared->next && GES_IS_TRACK_TRANSITION (compared->next->data)) {
653 trans = GES_TIMELINE_STANDARD_TRANSITION
654 (ges_track_object_get_timeline_object (compared->next->data));
655 g_object_get (compared->prev->data, "start", &tr_start, "duration",
657 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
658 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
661 for (tmp = compared->prev; tmp; tmp = tmp->prev) {
662 if GES_IS_TRACK_TRANSITION
664 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
666 if (tr_start == compared_start) {
667 trans = GES_TIMELINE_STANDARD_TRANSITION
668 (ges_track_object_get_timeline_object (tmp->data));
674 if (start + duration <= compared_start) {
676 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
677 g_object_get (object, "priority", &priority, NULL);
678 g_object_set (compared_object, "priority", priority, NULL);
682 } else if (start > compared_start) {
684 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
687 } else if (start < compared_start && end > compared_end) {
689 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
700 ges_timeline_standard_transition_new_for_nick ((gchar *) "crossfade");
701 track = ges_track_object_get_track (track_object);
703 ges_timeline_object_set_supported_formats (GES_TIMELINE_OBJECT (trans),
706 ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (trans));
709 first_object = ges_track_object_get_timeline_object (compared->data);
710 second_object = object;
712 second_object = ges_track_object_get_timeline_object (compared->data);
713 first_object = object;
716 g_object_get (first_object, "priority", &priority, "height", &height, NULL);
717 g_object_set (second_object, "priority", priority + height, NULL);
718 g_signal_connect (first_object, "notify::height",
719 (GCallback) timeline_object_height_changed_cb, second_object);
723 g_object_set (trans, "start", start, "duration",
724 compared_duration + compared_start - start, NULL);
726 g_object_set (trans, "start", compared_start, "duration",
727 start + duration - compared_start, NULL);
731 g_object_unref (layer);
735 look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
738 GList *track_objects, *tmp, *cur;
740 track = ges_track_object_get_track (track_object);
742 track_objects = ges_track_get_objects (track);
744 cur = g_list_find (track_objects, track_object);
746 for (tmp = cur->next; tmp; tmp = tmp->next) {
747 if (GES_IS_TRACK_SOURCE (tmp->data)) {
750 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
751 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
752 ges_timeline_layer_remove_object (layer,
753 ges_track_object_get_timeline_object (tmp->data));
757 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
758 if (GES_IS_TRACK_SOURCE (tmp->data)) {
761 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
762 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
763 ges_timeline_layer_remove_object (layer,
764 ges_track_object_get_timeline_object (tmp->data));
767 g_list_foreach (track_objects, (GFunc) g_object_unref, NULL);
768 g_list_free (track_objects);
772 disconnect_handlers (GESTrack * track, gpointer * ptr)
774 g_signal_handler_disconnect (track, GPOINTER_TO_INT (ptr));
780 * ges_timeline_layer_remove_object:
781 * @layer: a #GESTimelineLayer
782 * @object: the #GESTimelineObject to remove
784 * Removes the given @object from the @layer and unparents it.
785 * Unparenting it means the reference owned by @layer on the @object will be
786 * removed. If you wish to use the @object after this function, make sure you
787 * call g_object_ref() before removing it from the @layer.
789 * Returns: TRUE if the object could be removed, FALSE if the layer does
790 * not want to remove the object.
793 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
794 GESTimelineObject * object)
796 GESTimelineLayer *tl_obj_layer;
797 GList *trackobjects, *tmp;
799 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
800 g_return_val_if_fail (GES_IS_TIMELINE_OBJECT (object), FALSE);
802 GST_DEBUG ("layer:%p, object:%p", layer, object);
804 tl_obj_layer = ges_timeline_object_get_layer (object);
805 if (G_UNLIKELY (tl_obj_layer != layer)) {
806 GST_WARNING ("TimelineObject doesn't belong to this layer");
807 if (tl_obj_layer != NULL)
808 g_object_unref (tl_obj_layer);
811 g_object_unref (tl_obj_layer);
813 if (layer->priv->auto_transition) {
814 trackobjects = ges_timeline_object_get_track_objects (object);
816 for (tmp = trackobjects; tmp; tmp = tmp->next) {
817 look_for_transition (tmp->data, layer);
820 g_list_foreach (trackobjects, (GFunc) g_object_unref, NULL);
821 g_list_free (trackobjects);
824 g_hash_table_foreach_remove (layer->priv->signal_table,
825 (GHRFunc) disconnect_handlers, NULL);
827 /* emit 'object-removed' */
828 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
830 /* inform the object it's no longer in a layer */
831 ges_timeline_object_set_layer (object, NULL);
833 /* Remove it from our list of controlled objects */
834 layer->priv->objects_start =
835 g_list_remove (layer->priv->objects_start, object);
837 /* Remove our reference to the object */
838 g_object_unref (object);
844 * ges_timeline_layer_resync_priorities:
845 * @layer: a #GESTimelineLayer
847 * Resyncs the priorities of the objects controlled by @layer.
851 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
854 GESTimelineObject *obj;
856 GST_DEBUG ("Resync priorities of %p", layer);
858 /* TODO : Inhibit composition updates while doing this.
859 * Ideally we want to do it from an even higher level, but here will
860 * do in the meantime. */
862 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
863 obj = GES_TIMELINE_OBJECT (tmp->data);
864 ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
871 * ges_timeline_layer_set_priority:
872 * @layer: a #GESTimelineLayer
873 * @priority: the priority to set
875 * Sets the layer to the given @priority. See the documentation of the
876 * priority property for more information.
879 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
881 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
883 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
885 if (priority != layer->priv->priority) {
886 layer->priv->priority = priority;
887 layer->min_gnl_priority = (priority * LAYER_HEIGHT);
888 layer->max_gnl_priority = ((priority + 1) * LAYER_HEIGHT) - 1;
890 ges_timeline_layer_resync_priorities (layer);
895 * ges_timeline_layer_get_auto_transition:
896 * @layer: a #GESTimelineLayer
898 * Gets whether transitions are automatically added when objects
901 * Returns: %TRUE if transitions are automatically added, else %FALSE.
904 ges_timeline_layer_get_auto_transition (GESTimelineLayer * layer)
906 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
908 return layer->priv->auto_transition;
912 * ges_timeline_layer_set_auto_transition:
913 * @layer: a #GESTimelineLayer
914 * @auto_transition: whether the auto_transition is active
916 * Sets the layer to the given @auto_transition. See the documentation of the
917 * property auto_transition for more information.
920 ges_timeline_layer_set_auto_transition (GESTimelineLayer * layer,
921 gboolean auto_transition)
925 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
927 if (auto_transition) {
928 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
929 if (GES_IS_TIMELINE_SOURCE (tmp->data)) {
930 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
931 G_CALLBACK (track_object_added_cb), layer);
932 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
933 G_CALLBACK (track_object_removed_cb), layer);
936 /* FIXME calculate all the transitions at that time */
938 layer->priv->auto_transition = auto_transition;
942 * ges_timeline_layer_get_priority:
943 * @layer: a #GESTimelineLayer
945 * Get the priority of @layer within the timeline.
947 * Returns: The priority of the @layer within the timeline.
950 ges_timeline_layer_get_priority (GESTimelineLayer * layer)
952 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
954 return layer->priv->priority;
958 * ges_timeline_layer_get_objects:
959 * @layer: a #GESTimelineLayer
961 * Get the timeline objects this layer contains.
963 * Returns: (transfer full) (element-type GESTimelineObject): a #GList of
964 * timeline objects. The user is responsible for
965 * unreffing the contained objects and freeing the list.
969 ges_timeline_layer_get_objects (GESTimelineLayer * layer)
973 GESTimelineLayerClass *klass;
975 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
977 klass = GES_TIMELINE_LAYER_GET_CLASS (layer);
979 if (klass->get_objects) {
980 return klass->get_objects (layer);
983 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
984 ret = g_list_prepend (ret, tmp->data);
985 g_object_ref (tmp->data);
988 ret = g_list_reverse (ret);