ges: Keep layers sorted by priorities in the timeline

This commit is contained in:
Thibault Saunier 2011-06-02 22:03:19 -04:00
parent ee5c67de2f
commit 2bbcbab174

View file

@ -246,6 +246,26 @@ ges_timeline_init (GESTimeline * self)
gst_discoverer_start (self->priv->discoverer); gst_discoverer_start (self->priv->discoverer);
} }
static gint
sort_layers (gpointer a, gpointer b)
{
GESTimelineLayer *layer_a, *layer_b;
guint prio_a, prio_b;
layer_a = GES_TIMELINE_LAYER (a);
layer_b = GES_TIMELINE_LAYER (b);
prio_a = ges_timeline_layer_get_priority (layer_a);
prio_b = ges_timeline_layer_get_priority (layer_b);
if ((gint) prio_a > (guint) prio_b)
return 1;
if ((guint) prio_a < (guint) prio_b)
return -1;
return 0;
}
/** /**
* ges_timeline_new: * ges_timeline_new:
* *
@ -613,6 +633,13 @@ layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
GST_DEBUG ("done"); GST_DEBUG ("done");
} }
static void
layer_priority_changed_cb (GESTimelineLayer * layer,
GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
{
timeline->priv->layers = g_list_sort (timeline->priv->layers, (GCompareFunc)
sort_layers);
}
static void static void
layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object, layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
@ -688,7 +715,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
} }
g_object_ref_sink (layer); g_object_ref_sink (layer);
priv->layers = g_list_append (priv->layers, layer); priv->layers = g_list_insert_sorted (priv->layers, layer,
(GCompareFunc) sort_layers);
/* Inform the layer that it belongs to a new timeline */ /* Inform the layer that it belongs to a new timeline */
ges_timeline_layer_set_timeline (layer, timeline); ges_timeline_layer_set_timeline (layer, timeline);
@ -698,6 +726,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
timeline); timeline);
g_signal_connect (layer, "object-removed", g_signal_connect (layer, "object-removed",
G_CALLBACK (layer_object_removed_cb), timeline); G_CALLBACK (layer_object_removed_cb), timeline);
g_signal_connect (layer, "notify::priority",
G_CALLBACK (layer_priority_changed_cb), timeline);
GST_DEBUG ("Done adding layer, emitting 'layer-added' signal"); GST_DEBUG ("Done adding layer, emitting 'layer-added' signal");
g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer); g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer);
@ -1022,7 +1052,7 @@ ges_timeline_get_tracks (GESTimeline * timeline)
* Get the list of #GESTimelineLayer present in the Timeline. * Get the list of #GESTimelineLayer present in the Timeline.
* *
* Returns: (transfer full) (element-type GESTimelineLayer): the list of * Returns: (transfer full) (element-type GESTimelineLayer): the list of
* #GESTimelineLayer present in the Timeline. * #GESTimelineLayer present in the Timeline sorted by priority.
* The caller should unref each Layer once he is done with them. * The caller should unref each Layer once he is done with them.
*/ */
GList * GList *
@ -1031,7 +1061,8 @@ ges_timeline_get_layers (GESTimeline * timeline)
GList *tmp, *res = NULL; GList *tmp, *res = NULL;
for (tmp = timeline->priv->layers; tmp; tmp = g_list_next (tmp)) { for (tmp = timeline->priv->layers; tmp; tmp = g_list_next (tmp)) {
res = g_list_append (res, g_object_ref (tmp->data)); res = g_list_insert_sorted (res, g_object_ref (tmp->data),
(GCompareFunc) sort_layers);
} }
return res; return res;