[pitivi: 6/9] tests: mixer: track: Add tests for removing track objects with related fixes



commit dce2036dfb97d78c6201d4633f52ff29f8c025c3
Author: Robert Swain <robert swain collabora co uk>
Date:   Tue Aug 10 14:23:41 2010 +0200

    tests: mixer: track: Add tests for removing track objects with related fixes
    
    Removed some dead code from mixer. Fixed some alpha keyframe state-related
    code when a track object is removed from a track.

 pitivi/elements/mixer.py        |   46 +++++++++++++++++++++-----------------
 tests/test_alpha_passthrough.py |   21 +++++++++++++++++
 2 files changed, 46 insertions(+), 21 deletions(-)
---
diff --git a/pitivi/elements/mixer.py b/pitivi/elements/mixer.py
index b2859d0..768c5e7 100644
--- a/pitivi/elements/mixer.py
+++ b/pitivi/elements/mixer.py
@@ -209,25 +209,8 @@ class SmartVideomixerBinPropertyHelper(Signallable):
         # connect track-object-{added,removed} signals from track to callbacks
         track.connect("track-object-added", self._trackAddedCb)
         track.connect("track-object-removed", self._trackRemovedCb)
-        # connect track_objects' alpha interpolator keyframe-moved signals
-        # to callback and configure initial alpha state
-        for track_object in track.track_objects:
-            try:
-                interpolator =  track_object.getInterpolator("alpha")
-            except TrackError:
-                # no alpha
-                pass
-            else:
-                interpolator.connect("keyframe-added", self._keyframeChangedCb)
-                interpolator.connect("keyframe-moved", self._keyframeChangedCb)
-                interpolator.connect("keyframe-removed", self._keyframeChangedCb)
-                for kf in interpolator.getKeyframes():
-                    if interpolator.valueAt(kf.time) < 1.0:
-                        self.alpha_count += 1
-        if self.alpha_count != 0:
-            self.alphaStateChanged(True)
-        else:
-            self.alphaStateChanged(False)
+        # configure initial alpha state
+        self.alphaStateChanged(False)
 
 
     def _trackAddedCb(self, track, track_object):
@@ -239,6 +222,15 @@ class SmartVideomixerBinPropertyHelper(Signallable):
             # no alpha
             pass
         else:
+            # we must increment alpha_count and update the alpha state as
+            # appropriate
+            old_alpha_count = self.alpha_count
+            for kf in interpolator.getKeyframes():
+                if interpolator.valueAt(kf.time) < 1.0:
+                    self.alpha_count += 1
+            # as we're only incrementing, this should be the only case to check
+            if old_alpha_count == 0 and self.alpha_count > 0:
+                self.alphaStateChanged(True)
             interpolator.connect("keyframe-added", self._keyframeChangedCb)
             interpolator.connect("keyframe-moved", self._keyframeChangedCb)
             interpolator.connect("keyframe-removed", self._keyframeChangedCb)
@@ -247,11 +239,23 @@ class SmartVideomixerBinPropertyHelper(Signallable):
         # this import is here because of a circular dependence
         from pitivi.timeline.track import TrackError
         try:
-            interpolator = track_object.getInterpolator("alpha")
-        except TrackError:
+            # FIXME: .interpolators is accessed directly as the track object
+            # has been removed and its gnl_object doesn't contain any
+            # controllable element anymore
+            interpolator = track_object.interpolators["alpha"][1]
+        except (KeyError, TrackError):
             # no alpha
             pass
         else:
+            # we must decrement alpha_count and update the alpha state as
+            # appropriate
+            old_alpha_count = self.alpha_count
+            for kf in interpolator.getKeyframes():
+                if interpolator.valueAt(kf.time) < 1.0:
+                    self.alpha_count -= 1
+            # as we're only decrementing, this should be the only case to check
+            if old_alpha_count > 0 and self.alpha_count == 0:
+                self.alphaStateChanged(False)
             interpolator.disconnect_by_func(self._keyframeChangedCb)
 
     def _keyframeChangedCb(self, interpolator, keyframe, old_value=None):
diff --git a/tests/test_alpha_passthrough.py b/tests/test_alpha_passthrough.py
index 0f8efc9..8582d17 100644
--- a/tests/test_alpha_passthrough.py
+++ b/tests/test_alpha_passthrough.py
@@ -47,12 +47,14 @@ class TestAlpha(TestCase):
         # make a track, make track objects from the streams and add the track objects to the track
         offset = 0
         self.track1 = Track(streams[0][0])
+        self.track_objects = []
         for item in streams:
             stream = item[0]
             factory = item[1]
             factory.duration = 15 * gst.SECOND
             factory.addOutputStream(stream)
             track_object = SourceTrackObject(factory, stream)
+            self.track_objects.append(track_object)
             track_object.start = offset
             self.track1.addTrackObject(track_object)
             offset += 15 * gst.SECOND
@@ -129,6 +131,16 @@ class TestAlpha(TestCase):
             svmbin_input_capsfilter = input[2]
             self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
 
+        # remove a track object
+        self.track1.removeTrackObject(self.track1.track_objects[2])
+        # check that there are now just 2 track objects
+        self.failUnlessEqual(len(self.track1.track_objects), 2)
+        # check that each SmartVideomixerBin input has alpha set on its capsfilter
+        for input in svmbin_inputs:
+            svmbin_input_capsfilter = input[2]
+            self.failUnlessEqual(svmbin_input_capsfilter.props.caps[0]["format"], gst.Fourcc('AYUV'))
+
+
         # adjust all up to 1.0 again
         for track_obj in self.track1.track_objects:
             interpolator = track_obj.getInterpolator("alpha")
@@ -140,3 +152,12 @@ class TestAlpha(TestCase):
             svmbin_input_capsfilter = input[2]
             self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
 
+        # remove a track object
+        self.track1.removeTrackObject(self.track1.track_objects[0])
+        # check that there is now just 1 track object
+        self.failUnlessEqual(len(self.track1.track_objects), 1)
+        # check that each SmartVideomixerBin input has alpha _not_ set on its capsfilter
+        for input in svmbin_inputs:
+            svmbin_input_capsfilter = input[2]
+            self.failIf(svmbin_input_capsfilter.props.caps[0].has_key("format"))
+



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