diff --git a/ges/ges-internal.h b/ges/ges-internal.h index 3e62730629..19da68d89d 100644 --- a/ges/ges-internal.h +++ b/ges/ges-internal.h @@ -385,6 +385,7 @@ G_GNUC_INTERNAL GESVideoTestSource * ges_video_test_source_new (void); * GESTimelineElement * ****************************************************/ G_GNUC_INTERNAL gdouble ges_timeline_element_get_media_duration_factor(GESTimelineElement *self); +G_GNUC_INTERNAL GESTimelineElement * ges_timeline_element_get_copied_from (GESTimelineElement *self); /****************************** * GESMultiFile internal API * diff --git a/ges/ges-timeline-element.c b/ges/ges-timeline-element.c index 82ddad68f0..583b369f80 100644 --- a/ges/ges-timeline-element.c +++ b/ges/ges-timeline-element.c @@ -1857,3 +1857,12 @@ ges_timeline_element_get_media_duration_factor (GESTimelineElement * self) g_type_class_unref (class); return media_duration_factor; } + +/* Internal */ +GESTimelineElement * +ges_timeline_element_get_copied_from (GESTimelineElement * self) +{ + GESTimelineElement *copied_from = self->priv->copied_from; + self->priv->copied_from = NULL; + return copied_from; +} diff --git a/ges/ges-timeline.c b/ges/ges-timeline.c index 71f5247bd4..9febf1f2d1 100644 --- a/ges/ges-timeline.c +++ b/ges/ges-timeline.c @@ -3730,3 +3730,59 @@ ges_timeline_get_layer (GESTimeline * timeline, guint priority) return layer; } + +/** + * ges_timeline_paste_element: + * @timeline: The #GESTimeline onto which the #GESTimelineElement should be pasted + * @element: The #GESTimelineElement to paste + * @position: The position in the timeline the element should + * be pasted to, meaning it will become the start of @element + * @layer_priority: The #GESLayer to which the element should be pasted to. + * -1 means paste to the same layer from which the @element has been copied from. + * + * Paste @element inside the timeline. @element must have been + * created using ges_timeline_element_copy with deep=TRUE set, + * i.e. it must be a deep copy, otherwise it will fail. + * + * Returns: (transfer none): Shallow copy of the @element pasted + */ +GESTimelineElement * +ges_timeline_paste_element (GESTimeline * timeline, + GESTimelineElement * element, GstClockTime position, gint layer_priority) +{ + GESTimelineElement *res, *copied_from; + GESTimelineElementClass *element_class; + + g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE); + g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (element), FALSE); + + element_class = GES_TIMELINE_ELEMENT_GET_CLASS (element); + copied_from = ges_timeline_element_get_copied_from (element); + + if (!copied_from) { + GST_ERROR_OBJECT (element, "Is not being 'deeply' copied!"); + + return NULL; + } + + if (!element_class->paste) { + GST_ERROR_OBJECT (element, "No paste vmethod implemented"); + + return NULL; + } + + /* + * Currently the API only supports pasting onto the same layer from which + * the @element has been copied from, i.e., @layer_priority needs to be -1. + */ + if (layer_priority != -1) { + GST_WARNING_OBJECT (timeline, + "Only -1 value for layer priority is supported"); + } + + res = element_class->paste (element, copied_from, position); + + g_clear_object (&copied_from); + + return g_object_ref (res); +} diff --git a/ges/ges-timeline.h b/ges/ges-timeline.h index 1d0527a09d..477a5e42aa 100644 --- a/ges/ges-timeline.h +++ b/ges/ges-timeline.h @@ -158,6 +158,9 @@ GST_EXPORT GESTimelineElement * ges_timeline_get_element (GESTimeline * timeline, const gchar *name); GST_EXPORT gboolean ges_timeline_is_empty (GESTimeline * timeline); +GST_EXPORT +GESTimelineElement * ges_timeline_paste_element (GESTimeline * timeline, + GESTimelineElement * element, GstClockTime position, gint layer_priority); G_END_DECLS