[pitivi: 1/8] timeline: getObjs* optimizations
- From: Edward Hervey <edwardrv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 1/8] timeline: getObjs* optimizations
- Date: Wed, 22 Sep 2010 09:43:47 +0000 (UTC)
commit 39896266225dddc262ef81cd4976be5ea46cbb33
Author: Luis de Bethencourt <luis debethencourt com>
Date: Fri Sep 17 17:42:17 2010 +0200
timeline: getObjs* optimizations
pitivi/timeline/timeline.py | 49 +++++++++++++++--------
tests/test_timeline.py | 88 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+), 17 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index c589309..e16d7b0 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1908,34 +1908,49 @@ class Timeline(Signallable, Loggable):
self.emit("disable-updates", False)
- def getObjsAtTime(self, time_):
- objects = self.timeline_objects
- return [obj for obj in objects if
- (obj.start < time_) and
- ((obj.start + obj.duration) > time_)]
+ def getObjsAtTime(self, time):
+ objects = []
+ for obj in self.timeline_objects:
+ if obj.start < time:
+ if (obj.start + obj.duration) > time:
+ objects.append(obj)
+ else:
+ break
+ return objects
def getObjsAfterObj(self, obj):
return self.getObjsAfterTime(obj.start + obj.duration)
def getObjsAfterTime(self, target):
- return [to for to in self.timeline_objects
- if to.start >= target]
+ objects = []
+ for i in range(0, len(self.timeline_objects)):
+ if self.timeline_objects[i].start >= target:
+ objects.extend(self.timeline_objects[i:])
+ break
+ return objects
def getObjsBeforeObj(self, obj):
return self.getObjsBeforeTime(obj.start)
def getObjsBeforeTime(self, target):
- return [to for to in self.timeline_objects
- if to.start + to.duration <=target]
+ objects = []
+ for obj in self.timeline_objects:
+ if obj.start > target:
+ break
+ elif obj.start + obj.duration <= target:
+ objects.append(obj)
+ return objects
def getObjsInRegion(self, start, end, min_priority=0,
max_priority=4294967295L):
- objs = []
- for to in self.timeline_objects:
- if ((to.start >= start) and
- ((to.start + to.duration) <= end) and
- (to.priority >= min_priority) and
- (to.priority <= max_priority)):
- objs.append(to)
- return objs
+ objects = []
+ for obj in self.timeline_objects:
+ if obj.start >= start:
+ if ((obj.start + obj.duration) <= end and
+ obj.priority >= min_priority and
+ obj.priority <= max_priority):
+ objects.append(obj)
+ elif obj.start > end:
+ break
+ return objects
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index c3c4da1..1abeabf 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -19,6 +19,8 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
+import pygst
+pygst.require("0.10")
import gst
from tests.common import FakeSourceFactory
@@ -28,6 +30,7 @@ from pitivi.timeline.timeline import Timeline, TimelineObject, TimelineError, \
from pitivi.timeline.track import Track, SourceTrackObject
from pitivi.stream import AudioStream, VideoStream
from pitivi.utils import UNKNOWN_DURATION
+from pitivi.factories.test import AudioTestSourceFactory
from common import SignalMonitor, TestCase, StubFactory
@@ -542,6 +545,91 @@ class TestTimeline(TestCase):
self.failUnlessEqual(clip4.duration + clip4.start,
fourclipsoneselected)
+ def testGetObjs(self):
+ obj1 = self.makeTimelineObject()
+ obj2 = self.makeTimelineObject()
+ obj3 = self.makeTimelineObject()
+ obj4 = self.makeTimelineObject()
+
+ obj1.start = 0 * gst.SECOND
+ obj1.duration = 5 * gst.SECOND
+ obj1.priority = 1
+
+ obj2.start = 5 * gst.SECOND
+ obj2.duration = 5 * gst.SECOND
+ obj2.priority = 2
+
+ obj3.start = 8 * gst.SECOND
+ obj3.duration = 5 * gst.SECOND
+ obj3.priority = 3
+
+ obj4.start = 15 * gst.SECOND
+ obj4.duration = 5 * gst.SECOND
+ obj4.priority = 4
+
+ timeline = self.timeline
+
+ time1 = 0 * gst.SECOND
+ time2 = 5 * gst.SECOND
+ time3 = 9 * gst.SECOND
+ time4 = 14 * gst.SECOND
+ tmp_obj_list = []
+
+ # Objects before time.
+ tmp_obj_list = []
+ result = timeline.getObjsBeforeTime(time1)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj1]
+ result = timeline.getObjsBeforeTime(time2)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj1]
+ result = timeline.getObjsBeforeTime(time3)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj1, obj2, obj3]
+ result = timeline.getObjsBeforeTime(time4)
+ self.failUnlessEqual(result, tmp_obj_list)
+
+ # Objects after time.
+ tmp_obj_list = [obj1, obj2, obj3, obj4]
+ result = timeline.getObjsAfterTime(time1)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj2, obj3, obj4]
+ result = timeline.getObjsAfterTime(time2)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj4]
+ result = timeline.getObjsAfterTime(time3)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj4]
+ result = timeline.getObjsAfterTime(time4)
+ self.failUnlessEqual(result, tmp_obj_list)
+
+ # Objects at time.
+ tmp_obj_list = []
+ result = timeline.getObjsAtTime(time1)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = []
+ result = timeline.getObjsAtTime(time2)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj2, obj3]
+ result = timeline.getObjsAtTime(time3)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = []
+ result = timeline.getObjsAtTime(time4)
+ self.failUnlessEqual(result, tmp_obj_list)
+
+ # Objects in region.
+ tmp_obj_list = [obj1]
+ result = timeline.getObjsInRegion(time1, time2)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = []
+ result = timeline.getObjsInRegion(time3, time4)
+ self.failUnlessEqual(result, tmp_obj_list)
+ tmp_obj_list = [obj3]
+ result = timeline.getObjsInRegion(time1, time4, \
+ min_priority=3, max_priority=4)
+ self.failUnlessEqual(result, tmp_obj_list)
+
+
class TestLink(TestCase):
def test(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]