2009-08-04 15:13:11 +00:00
|
|
|
/* GStreamer Editing Services
|
2009-11-30 14:14:25 +00:00
|
|
|
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* 2009 Nokia Corporation
|
2009-08-04 15:13:11 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-09-10 16:40:51 +00:00
|
|
|
/**
|
|
|
|
* SECTION:ges-simple-timeline-layer
|
|
|
|
* @short_description: High-level #GESTimelineLayer
|
|
|
|
*
|
|
|
|
* #GESSimpleTimelineLayer allows using #GESTimelineObject(s) with a list-like
|
2010-05-31 16:59:12 +00:00
|
|
|
* API. Clients can add any type of GESTimelineObject to a
|
|
|
|
* GESSimpleTimelineLayer, and the layer will automatically compute the
|
2010-11-17 18:53:32 +00:00
|
|
|
* appropriate start times.
|
2010-07-06 14:27:21 +00:00
|
|
|
*
|
2010-05-31 16:59:12 +00:00
|
|
|
* Users should be aware that GESTimelineTransition objects are considered to
|
|
|
|
* have a negative duration for the purposes of positioning GESTimelineSource
|
|
|
|
* objects (i.e., adding a GESTimelineTransition creates an overlap between
|
2010-07-06 14:27:21 +00:00
|
|
|
* the two adjacent sources.
|
2009-09-10 16:40:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-09 16:09:11 +00:00
|
|
|
#include <ges/ges.h>
|
2009-08-06 17:51:29 +00:00
|
|
|
#include "ges-internal.h"
|
2010-08-05 10:50:19 +00:00
|
|
|
#include "gesmarshal.h"
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ges_simple_timeline_layer_object_removed (GESTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_simple_timeline_layer_object_added (GESTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object);
|
2009-08-04 15:13:11 +00:00
|
|
|
|
2010-07-09 16:27:19 +00:00
|
|
|
static void
|
|
|
|
timeline_object_height_changed_cb (GESTimelineObject * object G_GNUC_UNUSED,
|
|
|
|
GParamSpec * arg G_GNUC_UNUSED, GESSimpleTimelineLayer * layer);
|
|
|
|
|
2010-09-22 11:32:47 +00:00
|
|
|
static GList *get_objects (GESTimelineLayer * layer);
|
|
|
|
|
2009-08-04 15:16:31 +00:00
|
|
|
G_DEFINE_TYPE (GESSimpleTimelineLayer, ges_simple_timeline_layer,
|
2009-08-06 15:38:43 +00:00
|
|
|
GES_TYPE_TIMELINE_LAYER);
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
struct _GESSimpleTimelineLayerPrivate
|
|
|
|
{
|
|
|
|
/* Sorted list of objects */
|
|
|
|
GList *objects;
|
|
|
|
|
|
|
|
gboolean adding_object;
|
|
|
|
gboolean valid;
|
|
|
|
};
|
|
|
|
|
2010-08-05 10:50:19 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
OBJECT_MOVED,
|
|
|
|
LAST_SIGNAL,
|
|
|
|
};
|
|
|
|
|
2010-08-05 13:21:57 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_VALID,
|
|
|
|
LAST_PROP,
|
|
|
|
};
|
|
|
|
|
2010-08-05 10:50:19 +00:00
|
|
|
static guint gstl_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2009-08-06 15:38:43 +00:00
|
|
|
static void
|
|
|
|
ges_simple_timeline_layer_get_property (GObject * object,
|
2009-08-04 15:16:31 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec)
|
2009-08-04 15:13:11 +00:00
|
|
|
{
|
2010-08-05 13:21:57 +00:00
|
|
|
GESSimpleTimelineLayer *self;
|
|
|
|
self = GES_SIMPLE_TIMELINE_LAYER (object);
|
|
|
|
|
2009-08-04 15:13:11 +00:00
|
|
|
switch (property_id) {
|
2010-08-05 13:21:57 +00:00
|
|
|
case PROP_VALID:
|
2010-11-17 18:53:32 +00:00
|
|
|
g_value_set_boolean (value, self->priv->valid);
|
2010-08-05 13:21:57 +00:00
|
|
|
break;
|
2009-08-04 15:16:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2009-08-04 15:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-04 15:16:31 +00:00
|
|
|
ges_simple_timeline_layer_set_property (GObject * object, guint property_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-08-04 15:13:11 +00:00
|
|
|
{
|
|
|
|
switch (property_id) {
|
2009-08-04 15:16:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2009-08-04 15:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-04 15:16:31 +00:00
|
|
|
ges_simple_timeline_layer_class_init (GESSimpleTimelineLayerClass * klass)
|
2009-08-04 15:13:11 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2009-09-29 13:27:55 +00:00
|
|
|
GESTimelineLayerClass *layer_class = GES_TIMELINE_LAYER_CLASS (klass);
|
2009-08-04 15:13:11 +00:00
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GESSimpleTimelineLayerPrivate));
|
|
|
|
|
2009-08-04 15:13:11 +00:00
|
|
|
object_class->get_property = ges_simple_timeline_layer_get_property;
|
|
|
|
object_class->set_property = ges_simple_timeline_layer_set_property;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
/* Be informed when objects are being added/removed from elsewhere */
|
|
|
|
layer_class->object_removed = ges_simple_timeline_layer_object_removed;
|
|
|
|
layer_class->object_added = ges_simple_timeline_layer_object_added;
|
2010-09-22 11:32:47 +00:00
|
|
|
layer_class->get_objects = get_objects;
|
2010-08-05 10:50:19 +00:00
|
|
|
|
2010-08-05 13:21:57 +00:00
|
|
|
/**
|
|
|
|
* GESSimpleTimelineLayer:valid:
|
|
|
|
*
|
|
|
|
* FALSE when the arrangement of objects in the layer would cause errors or
|
|
|
|
* unexpected output during playback. Do not set the containing pipeline
|
|
|
|
* state to PLAYING when this property is FALSE.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_VALID,
|
|
|
|
g_param_spec_boolean ("valid", "Valid",
|
|
|
|
"Layer is in a valid configuration", FALSE, G_PARAM_READABLE));
|
|
|
|
|
2010-08-05 13:21:04 +00:00
|
|
|
/**
|
|
|
|
* GESSimpleTimelineLayer::object-moved
|
|
|
|
* @layer: the #GESSimpleTimelineLayer
|
|
|
|
* @object: the #GESTimelineObject that was added
|
|
|
|
* @old: the previous position of the object
|
|
|
|
* @new: the new position of the object
|
|
|
|
*
|
|
|
|
* Will be emitted when an object is moved with
|
|
|
|
* #ges_simple_timeline_layer_move_object.
|
|
|
|
*/
|
2010-08-05 10:50:19 +00:00
|
|
|
gstl_signals[OBJECT_MOVED] =
|
|
|
|
g_signal_new ("object-moved", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESSimpleTimelineLayerClass,
|
|
|
|
object_moved),
|
|
|
|
NULL, NULL,
|
|
|
|
ges_marshal_VOID__OBJECT_INT_INT, G_TYPE_NONE, 3,
|
|
|
|
GES_TYPE_TIMELINE_OBJECT, G_TYPE_INT, G_TYPE_INT);
|
2009-08-04 15:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-04 15:16:31 +00:00
|
|
|
ges_simple_timeline_layer_init (GESSimpleTimelineLayer * self)
|
2009-08-04 15:13:11 +00:00
|
|
|
{
|
2010-11-17 18:53:32 +00:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
|
|
GES_TYPE_SIMPLE_TIMELINE_LAYER, GESSimpleTimelineLayerPrivate);
|
|
|
|
|
|
|
|
self->priv->objects = NULL;
|
2009-09-29 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gstl_recalculate (GESSimpleTimelineLayer * self)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GstClockTime pos = 0;
|
2010-06-09 16:56:55 +00:00
|
|
|
gint priority = 0;
|
|
|
|
gint transition_priority = 0;
|
2010-07-09 10:10:06 +00:00
|
|
|
gint height;
|
2010-05-27 21:36:10 +00:00
|
|
|
GESTimelineObject *prev_object = NULL;
|
2010-06-04 17:53:35 +00:00
|
|
|
GESTimelineObject *prev_transition = NULL;
|
2010-08-05 13:21:57 +00:00
|
|
|
gboolean valid = TRUE;
|
2010-11-17 18:53:32 +00:00
|
|
|
GESSimpleTimelineLayerPrivate *priv = self->priv;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
2010-07-14 11:14:54 +00:00
|
|
|
priority = GES_TIMELINE_LAYER (self)->min_gnl_priority + 2;
|
2010-06-09 16:56:55 +00:00
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
GST_DEBUG ("recalculating values");
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
if (priv->objects && GES_IS_TIMELINE_TRANSITION (priv->objects->data)) {
|
2010-08-05 13:46:02 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
for (tmp = priv->objects; tmp; tmp = tmp->next) {
|
2010-06-09 14:27:43 +00:00
|
|
|
GESTimelineObject *obj;
|
|
|
|
guint64 dur;
|
|
|
|
GList *l_next;
|
|
|
|
|
|
|
|
obj = (GESTimelineObject *) tmp->data;
|
|
|
|
dur = GES_TIMELINE_OBJECT_DURATION (obj);
|
2010-07-09 10:10:06 +00:00
|
|
|
height = GES_TIMELINE_OBJECT_HEIGHT (obj);
|
2010-06-09 14:27:43 +00:00
|
|
|
|
2010-05-27 21:36:10 +00:00
|
|
|
if (GES_IS_TIMELINE_SOURCE (obj)) {
|
2010-06-09 16:56:55 +00:00
|
|
|
|
2010-07-14 11:14:54 +00:00
|
|
|
GST_LOG ("%p obj: height: %d: priority %d", obj, height, priority);
|
2010-05-27 21:36:10 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (GES_TIMELINE_OBJECT_START (obj) != pos)) {
|
|
|
|
ges_timeline_object_set_start (obj, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (GES_TIMELINE_OBJECT_PRIORITY (obj) != priority)) {
|
|
|
|
ges_timeline_object_set_priority (obj, priority);
|
|
|
|
}
|
|
|
|
|
2010-07-14 11:14:54 +00:00
|
|
|
transition_priority = MAX (0, priority - 1);
|
|
|
|
priority += height;
|
2010-05-27 22:11:51 +00:00
|
|
|
pos += dur;
|
2010-06-09 16:56:55 +00:00
|
|
|
|
|
|
|
g_assert (priority != -1);
|
|
|
|
|
2010-05-27 21:36:10 +00:00
|
|
|
} else if (GES_IS_TIMELINE_TRANSITION (obj)) {
|
|
|
|
|
2010-06-09 16:56:55 +00:00
|
|
|
pos -= dur;
|
2010-07-14 11:14:54 +00:00
|
|
|
|
|
|
|
GST_LOG ("%p obj: height: %d: trans_priority %d", obj, height,
|
|
|
|
transition_priority);
|
2010-06-09 16:56:55 +00:00
|
|
|
|
|
|
|
g_assert (transition_priority != -1);
|
2010-05-27 21:36:10 +00:00
|
|
|
|
2010-06-09 16:56:55 +00:00
|
|
|
if (G_UNLIKELY (GES_TIMELINE_OBJECT_START (obj) != pos))
|
|
|
|
ges_timeline_object_set_start (obj, pos);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (GES_TIMELINE_OBJECT_PRIORITY (obj) !=
|
|
|
|
transition_priority)) {
|
|
|
|
ges_timeline_object_set_priority (obj, transition_priority);
|
2010-05-27 21:36:10 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 16:56:55 +00:00
|
|
|
/* sanity checks */
|
|
|
|
l_next = g_list_next (tmp);
|
|
|
|
|
|
|
|
if (GES_IS_TIMELINE_TRANSITION (prev_object)) {
|
|
|
|
GST_ERROR ("two transitions in sequence!");
|
2010-08-05 13:21:57 +00:00
|
|
|
valid = FALSE;
|
2010-05-27 21:36:10 +00:00
|
|
|
}
|
2009-09-29 13:27:55 +00:00
|
|
|
|
2010-05-28 09:42:29 +00:00
|
|
|
if (prev_object && (GES_TIMELINE_OBJECT_DURATION (prev_object) < dur)) {
|
2010-05-27 22:11:51 +00:00
|
|
|
GST_ERROR ("transition duration exceeds that of previous neighbor!");
|
2010-08-05 13:21:57 +00:00
|
|
|
valid = FALSE;
|
2010-05-27 22:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (l_next && (GES_TIMELINE_OBJECT_DURATION (l_next->data) < dur)) {
|
2010-06-04 17:53:35 +00:00
|
|
|
GST_ERROR ("transition duration exceeds that of next neighbor!");
|
2010-08-05 13:21:57 +00:00
|
|
|
valid = FALSE;
|
2010-05-27 22:11:51 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 17:53:35 +00:00
|
|
|
if (prev_transition) {
|
|
|
|
guint64 start, end;
|
|
|
|
end = (GES_TIMELINE_OBJECT_DURATION (prev_transition) +
|
|
|
|
GES_TIMELINE_OBJECT_START (prev_transition));
|
|
|
|
|
2010-06-09 16:56:55 +00:00
|
|
|
start = pos;
|
2010-06-04 17:53:35 +00:00
|
|
|
|
2010-08-05 13:21:57 +00:00
|
|
|
if (end > start) {
|
2010-06-04 17:53:35 +00:00
|
|
|
GST_ERROR ("%d, %d: overlapping transitions!", start, end);
|
2010-08-05 13:21:57 +00:00
|
|
|
valid = FALSE;
|
|
|
|
}
|
2010-06-04 17:53:35 +00:00
|
|
|
}
|
|
|
|
prev_transition = obj;
|
2009-09-29 13:27:55 +00:00
|
|
|
}
|
2010-05-27 21:36:10 +00:00
|
|
|
|
|
|
|
prev_object = obj;
|
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
}
|
2010-05-27 21:36:10 +00:00
|
|
|
|
2010-08-05 13:46:02 +00:00
|
|
|
if (prev_object && GES_IS_TIMELINE_TRANSITION (prev_object)) {
|
|
|
|
valid = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-09 16:56:55 +00:00
|
|
|
GST_DEBUG ("Finished recalculating: final start pos is: " GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (pos));
|
|
|
|
|
2010-05-27 21:36:10 +00:00
|
|
|
GES_TIMELINE_LAYER (self)->max_gnl_priority = priority;
|
2010-08-05 13:21:57 +00:00
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
if (valid != self->priv->valid) {
|
|
|
|
self->priv->valid = valid;
|
2010-08-05 13:21:57 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "valid");
|
|
|
|
}
|
2009-08-04 15:13:11 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 10:37:45 +00:00
|
|
|
/**
|
|
|
|
* ges_simple_timeline_layer_add_object:
|
|
|
|
* @layer: a #GESSimpleTimelineLayer
|
|
|
|
* @object: the #GESTimelineObject to add
|
|
|
|
* @position: the position at which to add the object
|
|
|
|
*
|
|
|
|
* Adds the object at the given position in the layer. The position is where
|
|
|
|
* the object will be inserted. To put the object before all objects, use
|
|
|
|
* position 0. To put after all objects, use position -1.
|
2010-11-17 18:53:32 +00:00
|
|
|
*
|
2010-05-31 16:59:12 +00:00
|
|
|
* When adding transitions, it is important that the adjacent objects
|
|
|
|
* (objects at position, and position + 1) be (1) A derivative of
|
|
|
|
* GESTimelineSource or other non-transition, and (2) have a duration at least
|
|
|
|
* as long as the duration of the transition.
|
2009-09-16 10:37:45 +00:00
|
|
|
*
|
|
|
|
* The layer will steal a reference to the provided object.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the object was successfuly added, else FALSE.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_simple_timeline_layer_add_object (GESSimpleTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object, gint position)
|
|
|
|
{
|
2009-09-29 13:27:55 +00:00
|
|
|
gboolean res;
|
2010-06-09 14:27:43 +00:00
|
|
|
GList *nth;
|
2010-11-17 18:53:32 +00:00
|
|
|
GESSimpleTimelineLayerPrivate *priv = layer->priv;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("layer:%p, object:%p, position:%d", layer, object, position);
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
nth = g_list_nth (priv->objects, position);
|
2010-05-27 21:37:11 +00:00
|
|
|
|
|
|
|
if (GES_IS_TIMELINE_TRANSITION (object)) {
|
|
|
|
GList *lprev = g_list_previous (nth);
|
|
|
|
|
|
|
|
GESTimelineObject *prev = GES_TIMELINE_OBJECT (lprev ? lprev->data : NULL);
|
|
|
|
GESTimelineObject *next = GES_TIMELINE_OBJECT (nth ? nth->data : NULL);
|
|
|
|
|
|
|
|
if ((prev && GES_IS_TIMELINE_TRANSITION (prev)) ||
|
|
|
|
(next && GES_IS_TIMELINE_TRANSITION (next))) {
|
|
|
|
GST_ERROR ("Not adding transition: Only insert transitions between two"
|
|
|
|
" sources, or at the begining or end the layer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
priv->adding_object = TRUE;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
2010-12-15 16:40:59 +00:00
|
|
|
/* provisionally insert the object */
|
|
|
|
priv->objects = g_list_insert (priv->objects, object, position);
|
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
res = ges_timeline_layer_add_object ((GESTimelineLayer *) layer, object);
|
|
|
|
|
|
|
|
/* Add to layer */
|
|
|
|
if (G_UNLIKELY (!res)) {
|
2010-11-17 18:53:32 +00:00
|
|
|
priv->adding_object = FALSE;
|
2010-12-15 16:40:59 +00:00
|
|
|
/* we failed to add the object, so remove it from our list */
|
|
|
|
priv->objects = g_list_remove (priv->objects, object);
|
2009-09-29 13:27:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
priv->adding_object = FALSE;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("Adding object %p to the list", object);
|
2010-05-19 10:14:34 +00:00
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
|
2010-07-09 16:27:19 +00:00
|
|
|
g_signal_connect (G_OBJECT (object), "notify::height", G_CALLBACK
|
|
|
|
(timeline_object_height_changed_cb), layer);
|
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
/* recalculate positions */
|
|
|
|
gstl_recalculate (layer);
|
2009-09-16 10:37:45 +00:00
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
return TRUE;
|
2009-09-16 10:37:45 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 15:51:23 +00:00
|
|
|
/**
|
|
|
|
* ges_simple_timeline_layer_nth:
|
|
|
|
* @layer: a #GESSimpleTimelineLayer
|
|
|
|
* @position: The position in position to get, starting from 0.
|
|
|
|
*
|
|
|
|
* Gets the timeline object at the given position.
|
|
|
|
*
|
|
|
|
* Returns: The #GESTimelineObject at the given position or NULL if
|
|
|
|
* the position is off the end of the layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GESTimelineObject *
|
|
|
|
ges_simple_timeline_layer_nth (GESSimpleTimelineLayer * layer, gint position)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GESSimpleTimelineLayerPrivate *priv = layer->priv;
|
|
|
|
|
|
|
|
list = g_list_nth (priv->objects, position);
|
|
|
|
|
|
|
|
if (list)
|
|
|
|
return GES_TIMELINE_OBJECT (list->data);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:37:45 +00:00
|
|
|
/**
|
|
|
|
* ges_simple_timeline_layer_move_object:
|
|
|
|
* @layer: a #GESSimpleTimelineLayer
|
|
|
|
* @object: the #GESTimelineObject to move
|
|
|
|
* @newposition: the new position at which to move the object
|
|
|
|
*
|
|
|
|
* Moves the object to the given position in the layer. To put the object before
|
|
|
|
* all other objects, use position 0. To put the objects after all objects, use
|
|
|
|
* position -1.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the object was successfuly moved, else FALSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ges_simple_timeline_layer_move_object (GESSimpleTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object, gint newposition)
|
|
|
|
{
|
2009-09-29 13:27:55 +00:00
|
|
|
gint idx;
|
2010-11-17 18:53:32 +00:00
|
|
|
GESSimpleTimelineLayerPrivate *priv = layer->priv;
|
2010-11-28 12:24:07 +00:00
|
|
|
GESTimelineLayer *tl_obj_layer;
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("layer:%p, object:%p, newposition:%d", layer, object, newposition);
|
|
|
|
|
2010-11-28 12:24:07 +00:00
|
|
|
tl_obj_layer = ges_timeline_object_get_layer (object);
|
|
|
|
if (G_UNLIKELY (tl_obj_layer != (GESTimelineLayer *) layer)) {
|
2009-09-29 13:27:55 +00:00
|
|
|
GST_WARNING ("TimelineObject doesn't belong to this layer");
|
2010-11-28 12:24:07 +00:00
|
|
|
if (tl_obj_layer != NULL)
|
|
|
|
g_object_unref (tl_obj_layer);
|
2009-09-29 13:27:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-28 12:24:07 +00:00
|
|
|
if (tl_obj_layer != NULL)
|
|
|
|
g_object_unref (tl_obj_layer);
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
/* Find it's current position */
|
2010-11-17 18:53:32 +00:00
|
|
|
idx = g_list_index (priv->objects, object);
|
2009-09-29 13:27:55 +00:00
|
|
|
if (G_UNLIKELY (idx == -1)) {
|
|
|
|
GST_WARNING ("TimelineObject not controlled by this layer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("Object was previously at position %d", idx);
|
|
|
|
|
|
|
|
/* If we don't have to change its position, don't */
|
|
|
|
if (idx == newposition)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* pop it off the list */
|
2010-11-17 18:53:32 +00:00
|
|
|
priv->objects = g_list_remove (priv->objects, object);
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
/* re-add it at the proper position */
|
2010-11-17 18:53:32 +00:00
|
|
|
priv->objects = g_list_insert (priv->objects, object, newposition);
|
2009-09-29 13:27:55 +00:00
|
|
|
|
|
|
|
/* recalculate positions */
|
|
|
|
gstl_recalculate (layer);
|
2009-09-16 10:37:45 +00:00
|
|
|
|
2010-08-05 10:50:19 +00:00
|
|
|
g_signal_emit (layer, gstl_signals[OBJECT_MOVED], 0, object, idx,
|
|
|
|
newposition);
|
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
return TRUE;
|
2009-09-16 10:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_simple_timeline_layer_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GESSimpleTimelineLayer.
|
|
|
|
*
|
|
|
|
* Returns: The new #GESSimpleTimelineLayer
|
|
|
|
*/
|
2009-08-04 15:16:31 +00:00
|
|
|
GESSimpleTimelineLayer *
|
2009-08-04 15:13:11 +00:00
|
|
|
ges_simple_timeline_layer_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GES_TYPE_SIMPLE_TIMELINE_LAYER, NULL);
|
|
|
|
}
|
2009-09-29 13:27:55 +00:00
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_simple_timeline_layer_is_valid:
|
2010-12-08 14:36:55 +00:00
|
|
|
* @layer: a #GESSimpleTimelineLayer
|
2010-11-17 18:53:32 +00:00
|
|
|
*
|
2010-12-08 14:36:55 +00:00
|
|
|
* Checks whether the arrangement of objects in the layer would cause errors
|
|
|
|
* or unexpected output during playback. Do not set the containing pipeline
|
2010-11-17 18:53:32 +00:00
|
|
|
* state to PLAYING when this property is FALSE.
|
|
|
|
*
|
2010-12-08 14:36:55 +00:00
|
|
|
* Returns: #TRUE if current arrangement of the layer is valid else #FALSE.
|
2010-11-17 18:53:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_simple_timeline_layer_is_valid (GESSimpleTimelineLayer * layer)
|
|
|
|
{
|
|
|
|
return layer->priv->valid;
|
|
|
|
}
|
|
|
|
|
2009-09-29 13:27:55 +00:00
|
|
|
static void
|
|
|
|
ges_simple_timeline_layer_object_removed (GESTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object)
|
|
|
|
{
|
|
|
|
GESSimpleTimelineLayer *sl = (GESSimpleTimelineLayer *) layer;
|
|
|
|
|
|
|
|
/* remove object from our list */
|
2010-11-17 18:53:32 +00:00
|
|
|
sl->priv->objects = g_list_remove (sl->priv->objects, object);
|
2009-09-29 13:27:55 +00:00
|
|
|
gstl_recalculate (sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_simple_timeline_layer_object_added (GESTimelineLayer * layer,
|
|
|
|
GESTimelineObject * object)
|
|
|
|
{
|
|
|
|
GESSimpleTimelineLayer *sl = (GESSimpleTimelineLayer *) layer;
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
if (sl->priv->adding_object == FALSE) {
|
2009-09-29 13:27:55 +00:00
|
|
|
/* remove object from our list */
|
2010-11-17 18:53:32 +00:00
|
|
|
sl->priv->objects = g_list_append (sl->priv->objects, object);
|
2009-09-29 13:27:55 +00:00
|
|
|
gstl_recalculate (sl);
|
|
|
|
}
|
2010-05-19 10:14:34 +00:00
|
|
|
g_signal_connect_swapped (object, "notify::duration",
|
|
|
|
G_CALLBACK (gstl_recalculate), layer);
|
2009-09-29 13:27:55 +00:00
|
|
|
}
|
2010-07-09 16:27:19 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
timeline_object_height_changed_cb (GESTimelineObject * object,
|
|
|
|
GParamSpec * arg G_GNUC_UNUSED, GESSimpleTimelineLayer * layer)
|
|
|
|
{
|
|
|
|
GST_LOG ("layer %p: notify height changed %p", layer, object);
|
|
|
|
gstl_recalculate (layer);
|
|
|
|
}
|
2010-09-22 11:32:47 +00:00
|
|
|
|
|
|
|
static GList *
|
|
|
|
get_objects (GESTimelineLayer * l)
|
|
|
|
{
|
|
|
|
GList *ret;
|
|
|
|
GList *tmp;
|
|
|
|
GESSimpleTimelineLayer *layer = (GESSimpleTimelineLayer *) l;
|
|
|
|
|
2010-11-17 18:53:32 +00:00
|
|
|
ret = g_list_copy (layer->priv->objects);
|
2010-09-22 11:32:47 +00:00
|
|
|
|
|
|
|
for (tmp = ret; tmp; tmp = tmp->next) {
|
|
|
|
g_object_ref (tmp->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|