[pitivi: 3/8] timeline/track: removing the keyframes out of bounds of the split.



commit d7d32e8b7e28691c311da16cda1c2a9b9af13add
Author: Luis de Bethencourt <luis debethencourt com>
Date:   Mon Sep 20 19:21:51 2010 +0200

    timeline/track: removing the keyframes out of bounds of the split.

 pitivi/timeline/track.py |   15 +++++++++++++++
 tests/test_track.py      |   38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index 065b93b..0594c00 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -566,6 +566,7 @@ class TrackObject(Signallable, Loggable):
     def splitObject(self, position):
         start = self.gnl_object.props.start
         duration = self.gnl_object.props.duration
+        in_point = self.gnl_object.props.media_start
         if position <= start or position >= start + duration:
             raise TrackError("can't split at position %s" % gst.TIME_ARGS(position))
 
@@ -575,10 +576,24 @@ class TrackObject(Signallable, Loggable):
         for prop, i in self.interpolators.itervalues():
             value = i.valueAt(position)
             i.end.setValue(value)
+            keyframes = i.getInteriorKeyframes()
+            duplicates = []
+            for kf in keyframes:
+                if kf.getTime() >= (position - start + in_point):
+                    duplicates.append(kf)
+            for kf in duplicates:
+                i.removeKeyframe(kf)
 
         for prop, i in other.interpolators.itervalues():
             value = i.valueAt(position)
             i.start.setValue(value)
+            keyframes = i.getInteriorKeyframes()
+            duplicates = []
+            for kf in keyframes:
+                if kf.getTime() <= (position - start + in_point):
+                    duplicates.append(kf)
+            for kf in duplicates:
+                i.removeKeyframe(kf)
 
         other.trimObjectStart(position)
         self.setObjectDuration(position - self.gnl_object.props.start)
diff --git a/tests/test_track.py b/tests/test_track.py
index 8a9601d..afa4966 100644
--- a/tests/test_track.py
+++ b/tests/test_track.py
@@ -315,7 +315,6 @@ class TestTrackObject(TestCase):
         monitor = TrackSignalMonitor(other1)
 
         other2 = other1.splitObject(6 * gst.SECOND)
-        self.failUnlessEqual(expected, getKeyframes(other2))
         self.failUnlessEqual(other1.start, 1 * gst.SECOND)
         self.failUnlessEqual(other1.in_point, 1 * gst.SECOND)
         self.failUnlessEqual(other1.duration, 5 * gst.SECOND)
@@ -329,6 +328,43 @@ class TestTrackObject(TestCase):
         self.failUnlessEqual(monitor.start_changed_count, 0)
         self.failUnlessEqual(monitor.duration_changed_count, 1)
 
+    def testSplitObjectKeyframes(self):
+        DURATION = 10 * gst.SECOND
+
+        factory = AudioTestSourceFactory()
+        factory.duration = DURATION
+        stream_ = AudioStream(gst.Caps("audio/x-raw-int"))
+        obj = SourceTrackObject(factory, stream_)
+        track = Track(stream_)
+        track.addTrackObject(obj)
+
+        obj.start = 3 * gst.SECOND
+        obj.duration = DURATION
+
+
+        # create a three keyframes at: 3, 6 and 9 seconds
+        interpolator = obj.getInterpolator("volume")
+        keyframes = dict(((t * gst.SECOND, (t % 2, gst.INTERPOLATE_LINEAR))
+            for t in xrange(3, 10, 3)))
+        expected = []
+        expected2 = []
+        for time, (value, mode) in keyframes.iteritems():
+            kf = interpolator.newKeyframe(time, value, mode)
+            if time < (5 * gst.SECOND):
+                expected.append(kf)
+            else:
+                expected2.append(kf)
+
+        def getKeyframes(obj):
+            keyframes = obj.getInterpolator("volume").getInteriorKeyframes()
+            return list(keyframes)
+
+        obj2 = obj.splitObject(8 * gst.SECOND)
+
+        keyframes =  getKeyframes(obj)
+        keyframes2 = getKeyframes(obj2)
+        self.failUnlessEqual(keyframes, expected)
+        self.failUnlessEqual(keyframes2, expected2)
 
 class TestTrack(TestCase):
     def setUp(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]