[pitivi] undo: Fix ControlSourceKeyframeChanged



commit bfa61bbe0a9dade8295008e88e365e308a376363
Author: Fabian Orccon <fabian orccon pucp pe>
Date:   Mon Apr 18 20:15:07 2016 +0000

    undo: Fix ControlSourceKeyframeChanged
    
    Fix confussion between track_element and control_source.
    Apply the changes to the InterpolationControlSource (control_source).
    
    Differential Revision: https://phabricator.freedesktop.org/D684

 pitivi/undo/timeline.py     |   24 +++++++++++-------------
 tests/test_undo_timeline.py |   22 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 217d6fe..5fe7fdd 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -281,10 +281,10 @@ class KeyframeChangeTracker(GObject.Object):
     def _keyframeAddedCb(self, control_source, keyframe):
         self.keyframes[keyframe.timestamp] = self._getKeyframeSnapshot(keyframe)
 
-    def _keyframeRemovedCb(self, control_source, keyframe, old_value=None):
-        pass  # FIXME: this has not been implemented
+    def _keyframeRemovedCb(self, control_source, keyframe):
+        del self.keyframes[keyframe.timestamp]
 
-    def _keyframeMovedCb(self, control_source, keyframe, old_value=None):
+    def _keyframeMovedCb(self, control_source, keyframe):
         old_snapshot = self.keyframes[keyframe.timestamp]
         new_snapshot = self._getKeyframeSnapshot(keyframe)
         self.keyframes[keyframe.timestamp] = new_snapshot
@@ -502,25 +502,23 @@ class ControlSourceValueRemoved(UndoableAction):
 
 class ControlSourceKeyframeChanged(UndoableAction):
 
-    def __init__(self, track_element, keyframe, old_snapshot, new_snapshot):
+    def __init__(self, control_source, old_snapshot, new_snapshot):
         UndoableAction.__init__(self)
-        self.track_element = track_element
-        self.keyframe = keyframe
+        self.control_source = control_source
         self.old_snapshot = old_snapshot
         self.new_snapshot = new_snapshot
 
     def do(self):
-        self._setSnapshot(self.new_snapshot)
+        self._applySnapshot(self.new_snapshot)
         self._done()
 
     def undo(self):
-        self._setSnapshot(self.old_snapshot)
+        self._applySnapshot(self.old_snapshot)
         self._undone()
 
-    def _setSnapshot(self, snapshot):
+    def _applySnapshot(self, snapshot):
         time, value = snapshot
-        self.keyframe.setTime(time)
-        self.keyframe.setValue(value)
+        self.control_source.set(time, value)
 
 
 class ActivePropertyChanged(UndoableAction):
@@ -742,9 +740,9 @@ class TimelineObserver(Loggable):
         action = self.activePropertyChangedAction(add_effect_action, active)
         self.action_log.push(action)
 
-    def _controlSourceKeyFrameMovedCb(self, tracker, track_element,
+    def _controlSourceKeyFrameMovedCb(self, tracker, control_source,
                                       keyframe, old_snapshot, new_snapshot):
-        action = ControlSourceKeyframeChanged(track_element, keyframe,
+        action = ControlSourceKeyframeChanged(control_source,
                                               old_snapshot, new_snapshot)
         self.action_log.push(action)
 
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index e00e4ca..243ef42 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -214,6 +214,28 @@ class TestTimelineUndo(TestCase):
         self.action_log.redo()
         self.assertEqual(0, len(control_source.get_all()))
 
+    def testControlSourceValueChanged(self):
+        uri = common.get_sample_uri("tears_of_steel.webm")
+        asset = GES.UriClipAsset.request_sync(uri)
+        clip = asset.extract()
+        self.layer.add_clip(clip)
+        source = clip.get_children(False)[1]
+        self.assertTrue(isinstance(source, GES.VideoUriSource))
+
+        control_source = GstController.InterpolationControlSource()
+        control_source.props.mode = GstController.InterpolationMode.LINEAR
+        source.set_control_source(control_source, "alpha", "direct")
+        self.assertTrue(control_source.set(Gst.SECOND * 0.5, 0.2))
+
+        with self.action_log.started("keyframe changed"):
+            self.assertTrue(control_source.set(Gst.SECOND * 0.5, 0.9))
+
+        self.assertEqual(0.9, control_source.get_all()[0].value)
+        self.action_log.undo()
+        self.assertEqual(0.2, control_source.get_all()[0].value)
+        self.action_log.redo()
+        self.assertEqual(0.9, control_source.get_all()[0].value)
+
     def testAddClip(self):
         stacks = []
         self.action_log.connect("commit", TestTimelineUndo.commitCb, stacks)


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