1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "gesmarshal.h"
21 #include "ges-internal.h"
22 #include "ges-timeline.h"
23 #include "ges-track.h"
24 #include "ges-timeline-layer.h"
30 * Top-level container for pipelines
32 * Contains a list of TimelineLayer which users should use to arrange the
33 * various timeline objects.
37 G_DEFINE_TYPE (GESTimeline, ges_timeline, GST_TYPE_BIN);
49 static guint ges_timeline_signals[LAST_SIGNAL] = { 0 };
52 ges_timeline_get_property (GObject * object, guint property_id,
53 GValue * value, GParamSpec * pspec)
55 switch (property_id) {
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
62 ges_timeline_set_property (GObject * object, guint property_id,
63 const GValue * value, GParamSpec * pspec)
65 switch (property_id) {
67 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72 ges_timeline_dispose (GObject * object)
74 G_OBJECT_CLASS (ges_timeline_parent_class)->dispose (object);
78 ges_timeline_finalize (GObject * object)
80 G_OBJECT_CLASS (ges_timeline_parent_class)->finalize (object);
84 ges_timeline_class_init (GESTimelineClass * klass)
86 GObjectClass *object_class = G_OBJECT_CLASS (klass);
88 object_class->get_property = ges_timeline_get_property;
89 object_class->set_property = ges_timeline_set_property;
90 object_class->dispose = ges_timeline_dispose;
91 object_class->finalize = ges_timeline_finalize;
100 ges_timeline_signals[TRACK_ADDED] =
101 g_signal_new ("track-added", G_TYPE_FROM_CLASS (klass),
102 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, track_added), NULL,
103 NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GES_TYPE_TRACK);
105 ges_timeline_signals[TRACK_REMOVED] =
106 g_signal_new ("track-removed", G_TYPE_FROM_CLASS (klass),
107 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, track_removed),
108 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GES_TYPE_TRACK);
110 ges_timeline_signals[LAYER_ADDED] =
111 g_signal_new ("layer-added", G_TYPE_FROM_CLASS (klass),
112 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, layer_added), NULL,
113 NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GES_TYPE_TIMELINE_LAYER);
115 ges_timeline_signals[LAYER_REMOVED] =
116 g_signal_new ("layer-removed", G_TYPE_FROM_CLASS (klass),
117 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, layer_removed),
118 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
119 GES_TYPE_TIMELINE_LAYER);
123 ges_timeline_init (GESTimeline * self)
130 ges_timeline_new (void)
132 return g_object_new (GES_TYPE_TIMELINE, NULL);
136 ges_timeline_load_from_uri (gchar * uri)
138 /* FIXME : IMPLEMENT */
143 ges_timeline_save (GESTimeline * timeline, gchar * uri)
145 /* FIXME : IMPLEMENT */
150 layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
151 GESTimeline * timeline)
155 GST_DEBUG ("New TimelineObject %p added to layer %p", object, layer);
157 for (tmp = timeline->tracks; tmp; tmp = g_list_next (tmp)) {
158 GESTrack *track = (GESTrack *) tmp->data;
159 GESTrackObject *trobj;
161 GST_LOG ("Trying with track %p", track);
163 if (G_UNLIKELY (!(trobj =
164 ges_timeline_object_create_track_object (object, track)))) {
165 GST_WARNING ("Couldn't create TrackObject for TimelineObject");
169 GST_LOG ("Got new TrackObject %p, adding it to track", trobj);
170 ges_track_add_object (track, trobj);
178 layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
179 GESTimeline * timeline)
183 GST_DEBUG ("TimelineObject %p removed from layer %p", object, layer);
185 /* Go over the object's track objects and figure out which one belongs to
186 * the list of tracks we control */
188 for (tmp = object->trackobjects; tmp; tmp = g_list_next (tmp)) {
189 GESTrackObject *trobj = (GESTrackObject *) tmp->data;
191 GST_DEBUG ("Trying to remove TrackObject %p", trobj);
193 if (G_LIKELY (g_list_find (timeline->tracks, trobj->track))) {
194 GST_DEBUG ("Belongs to one of the tracks we control");
195 ges_track_remove_object (trobj->track, trobj);
197 ges_timeline_object_release_track_object (object, trobj);
206 ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
208 GST_DEBUG ("timeline:%p, layer:%p", timeline, layer);
210 /* We can only add a layer that doesn't already belong to another timeline */
211 if (G_UNLIKELY (layer->timeline)) {
212 GST_WARNING ("Layer belongs to another timeline, can't add it");
216 /* Add to the list of layers, make sure we don't already control it */
217 if (G_UNLIKELY (g_list_find (timeline->layers, (gconstpointer) layer))) {
218 GST_WARNING ("Layer is already controlled by this timeline");
222 /* Reference is taken */
223 timeline->layers = g_list_append (timeline->layers, g_object_ref (layer));
225 /* Inform the layer that it belongs to a new timeline */
226 ges_timeline_layer_set_timeline (layer, timeline);
228 /* FIXME : GO OVER THE LIST OF ALREADY EXISTING TIMELINE OBJECTS IN THAT
229 * LAYER AND ADD THEM !!! */
231 /* Connect to 'object-added'/'object-removed' signal from the new layer */
232 g_signal_connect (layer, "object-added", G_CALLBACK (layer_object_added_cb),
234 g_signal_connect (layer, "object-removed",
235 G_CALLBACK (layer_object_removed_cb), timeline);
237 GST_DEBUG ("Done adding layer, emitting 'layer-added' signal");
238 g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer);
244 ges_timeline_remove_layer (GESTimeline * timeline, GESTimelineLayer * layer)
246 GST_DEBUG ("timeline:%p, layer:%p", timeline, layer);
248 if (G_UNLIKELY (!g_list_find (timeline->layers, layer))) {
249 GST_WARNING ("Layer doesn't belong to this timeline");
253 /* Disconnect signals */
254 GST_DEBUG ("Disconnecting signal callbacks");
255 g_signal_handlers_disconnect_by_func (layer, layer_object_added_cb, timeline);
256 g_signal_handlers_disconnect_by_func (layer, layer_object_removed_cb,
259 timeline->layers = g_list_remove (timeline->layers, layer);
261 ges_timeline_layer_set_timeline (layer, NULL);
263 g_signal_emit (timeline, ges_timeline_signals[LAYER_REMOVED], 0, layer);
265 g_object_unref (layer);
271 ges_timeline_add_track (GESTimeline * timeline, GESTrack * track)
273 GST_DEBUG ("timeline:%p, track:%p", timeline, track);
275 /* make sure we don't already control it */
276 if (G_UNLIKELY (g_list_find (timeline->tracks, (gconstpointer) track))) {
277 GST_WARNING ("Track is already controlled by this timeline");
281 /* Add the track to ourself (as a GstBin)
282 * Reference is taken ! */
283 if (G_UNLIKELY (!gst_bin_add (GST_BIN (timeline), GST_ELEMENT (track)))) {
284 GST_WARNING ("Couldn't add track to ourself (GST)");
288 /* Add the track to the list of tracks we track */
289 timeline->tracks = g_list_append (timeline->tracks, track);
291 /* Inform the track that it's currently being used by ourself */
292 ges_track_set_timeline (track, timeline);
294 GST_DEBUG ("Done adding track, emitting 'track-added' signal");
296 /* emit 'track-added' */
297 g_signal_emit (timeline, ges_timeline_signals[TRACK_ADDED], 0, track);
303 ges_timeline_remove_track (GESTimeline * timeline, GESTrack * track)
305 GST_DEBUG ("timeline:%p, track:%p", timeline, track);
307 if (G_UNLIKELY (!g_list_find (timeline->tracks, track))) {
308 GST_WARNING ("Track doesn't belong to this timeline");
312 timeline->tracks = g_list_remove (timeline->tracks, track);
314 ges_track_set_timeline (track, NULL);
316 /* remove track from our bin */
317 if (G_UNLIKELY (!gst_bin_remove (GST_BIN (timeline), GST_ELEMENT (track)))) {
318 GST_WARNING ("Couldn't remove track to ourself (GST)");
322 /* Signal track removal to all layers/objects */
323 g_signal_emit (timeline, ges_timeline_signals[TRACK_REMOVED], 0, track);