1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:ges-timeline-layer
23 * @short_description: Non-overlaping sequence of #GESTimelineObject
25 * Responsible for the ordering of the various contained TimelineObject(s). A
26 * timeline layer has a "priority" property, which is used to manage the
27 * priorities of individual TimelineObjects. Two layers should not have the
28 * same priority within a given timeline.
31 #include "ges-internal.h"
32 #include "gesmarshal.h"
33 #include "ges-timeline-layer.h"
36 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_OBJECT);
51 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
54 ges_timeline_layer_get_property (GObject * object, guint property_id,
55 GValue * value, GParamSpec * pspec)
57 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
59 switch (property_id) {
61 g_value_set_uint (value, layer->priority);
64 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
69 ges_timeline_layer_set_property (GObject * object, guint property_id,
70 const GValue * value, GParamSpec * pspec)
72 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
74 switch (property_id) {
76 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 ges_timeline_layer_dispose (GObject * object)
86 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
88 if (layer->objects_start) {
89 g_slist_foreach (layer->objects_start, (GFunc) g_object_unref, NULL);
90 g_slist_free (layer->objects_start);
91 layer->objects_start = NULL;
93 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
97 ges_timeline_layer_finalize (GObject * object)
99 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->finalize (object);
103 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
107 object_class->get_property = ges_timeline_layer_get_property;
108 object_class->set_property = ges_timeline_layer_set_property;
109 object_class->dispose = ges_timeline_layer_dispose;
110 object_class->finalize = ges_timeline_layer_finalize;
113 * GESTimelineLayer:priority
115 * The priority of the layer in the #GESTimeline. 0 is the highest
116 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
117 * and the priority of the layer represents its position in the stack. Two
118 * layers should not have the same priority within a given GESTimeline.
120 g_object_class_install_property (object_class, PROP_PRIORITY,
121 g_param_spec_uint ("priority", "Priority",
122 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
125 * GESTimelineLayer::object-added
126 * @layer: the #GESTimelineLayer
127 * @object: the #GESTimelineObject that was added.
129 * Will be emitted after the object was added to the layer.
131 ges_timeline_layer_signals[OBJECT_ADDED] =
132 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
133 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
134 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
135 GES_TYPE_TIMELINE_OBJECT);
138 * GESTimelineLayer::object-removed
139 * @layer: the #GESTimelineLayer
140 * @object: the #GESTimelineObject that was removed
142 * Will be emitted after the object was removed from the layer.
144 ges_timeline_layer_signals[OBJECT_REMOVED] =
145 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
146 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
147 object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
148 GES_TYPE_TIMELINE_OBJECT);
153 ges_timeline_layer_init (GESTimelineLayer * self)
155 /* TODO : Keep those 3 values in sync */
157 self->min_gnl_priority = 0;
158 self->max_gnl_priority = 9;
162 * ges_timeline_layer_new:
164 * Creates a new #GESTimelineLayer.
166 * Returns: A new #GESTimelineLayer
169 ges_timeline_layer_new (void)
171 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
175 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
176 GESTimeline * timeline)
178 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
180 layer->timeline = timeline;
184 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
186 if (a->start == b->start) {
187 if (a->priority < b->priority)
189 if (a->priority > b->priority)
193 if (a->start < b->start)
195 if (a->start > b->start)
201 * ges_timeline_layer_add_object:
202 * @layer: a #GESTimelineLayer
203 * @object: the #GESTimelineObject to add.
205 * Adds the object to the layer. The layer will steal a reference to the
208 * Returns: TRUE if the object was properly added to the layer, or FALSE
209 * if the @layer refused to add the object.
213 ges_timeline_layer_add_object (GESTimelineLayer * layer,
214 GESTimelineObject * object)
216 GST_DEBUG ("layer:%p, object:%p", layer, object);
218 if (G_UNLIKELY (object->layer)) {
219 GST_WARNING ("TimelineObject %p already belongs to another layer");
223 /* Take a reference to the object and store it stored by start/priority */
224 layer->objects_start =
225 g_slist_insert_sorted (layer->objects_start, object,
226 (GCompareFunc) objects_start_compare);
228 /* Inform the object it's now in this layer */
229 ges_timeline_object_set_layer (object, layer);
231 /* Set the priority. */
232 if (GES_TIMELINE_OBJECT_PRIORITY (object) > (layer->max_gnl_priority)) {
233 ges_timeline_object_set_priority (object, layer->max_gnl_priority);
236 else if (GES_TIMELINE_OBJECT_PRIORITY (object) < (layer->min_gnl_priority)) {
237 ges_timeline_object_set_priority (object, layer->min_gnl_priority);
240 /* emit 'object-added' */
241 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
247 * ges_timeline_layer_remove_object:
248 * @layer: a #GESTimelineLayer
249 * @object: the #GESTimelineObject to remove
251 * Removes the given @object from the @layer. The reference stolen by the @layer
252 * when the object was added will be removed. If you wish to use the object after
253 * this function, make sure you take an extra reference to the object before
254 * calling this function.
256 * Returns: TRUE if the object was properly remove, else FALSE.
259 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
260 GESTimelineObject * object)
262 GST_DEBUG ("layer:%p, object:%p", layer, object);
264 if (G_UNLIKELY (object->layer != layer)) {
265 GST_WARNING ("TimelineObject doesn't belong to this layer");
269 /* emit 'object-removed' */
270 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
272 /* inform the object it's no longer in a layer */
273 ges_timeline_object_set_layer (object, NULL);
275 /* Remove it from our list of controlled objects */
276 layer->objects_start = g_slist_remove (layer->objects_start, object);
278 /* Remove our reference to the object */
279 g_object_unref (object);
285 * ges_timeline_layer_resync_priorities:
286 * @layer: a #GESTimelineLayer
288 * Resyncs the priorities of the objects controlled by @layer.
291 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
295 /* TODO : Inhibit composition updates while doing this.
296 * Ideally we want to do it from an even higher level, but here will
297 * do in the meantime. */
299 /* TODO : This is the dumb version where we put everything linearly,
300 * will need to be adjusted for more complex usages (like with
302 for (tmp = layer->objects_start; tmp; tmp = tmp->next) {
303 ges_timeline_object_set_priority ((GESTimelineObject *) tmp->data,
304 layer->min_gnl_priority);
311 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
313 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
315 if (priority != layer->priority) {
316 layer->priority = priority;
317 layer->min_gnl_priority = (priority * 10);
318 layer->max_gnl_priority = ((priority + 1) * 10) - 1;
320 /* FIXME : Update controlled object's gnl priority accordingly */
321 ges_timeline_layer_resync_priorities (layer);