[pitivi: 1/4] Use an alternate, less annoying approach to avoid clip overlaps.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi: 1/4] Use an alternate, less annoying approach to avoid clip overlaps.
- Date: Mon, 27 Jul 2009 09:41:10 +0000 (UTC)
commit 955adfaf1c38dcb7707240170bc46f8bec78f5c5
Author: Alessandro Decina <alessandro d gmail com>
Date: Sun Jul 26 03:37:00 2009 +0200
Use an alternate, less annoying approach to avoid clip overlaps.
pitivi/timeline/timeline.py | 61 ++++++++++++++++++++++++++++++++----------
tests/test_timeline.py | 1 +
2 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 09a5696..bc93fff 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1108,27 +1108,58 @@ class MoveContext(EditingContext):
def _finishDefault(self):
self._restoreValues(self.default_originals)
- def _defaultTo(self, position, priority):
- if self._snap:
- position = self.timeline.snapToEdge(position,
- position + self.default_span)
+ def finish(self):
+ EditingContext.finish(self)
- priority = max(self.min_priority, priority)
- left_gap, right_gap = self._getGapsAtPriority(priority)
+ initial_position = self.default_originals[self.focus.timeline_object][0]
+ initial_priority = self.default_originals[self.focus.timeline_object][-1]
- if left_gap is invalid_gap or right_gap is invalid_gap:
- if priority == self._last_priority:
- # abort move
- return self._last_position, self._last_priority
+ final_priority = self.focus.priority
+ final_position = self.focus.start
- # try to do the same time move, using the current priority
- return self._defaultTo(position, self._last_priority)
+ # adjust priority
+ priority = final_priority
+ overlap = False
+ while True:
+ left_gap, right_gap = self._getGapsAtPriority(priority)
- delta = position - self.focus.start
+ if left_gap is invalid_gap or right_gap is invalid_gap:
+ overlap = True
+
+ if priority == initial_priority:
+ break
+
+ if priority > initial_priority:
+ priority -= 1
+ else:
+ priority += 1
+
+
+ self._defaultTo(final_position, priority)
+ else:
+ overlap = False
+ break
+
+ if not overlap:
+ return
+
+ self._defaultTo(initial_position, priority)
+ left_gap, right_gap = self._getGapsAtPriority(priority)
+
+ delta = final_position - initial_position
if delta > 0 and right_gap.duration < delta:
- position = self.focus.start + right_gap.duration
+ final_position = initial_position + right_gap.duration
elif delta < 0 and left_gap.duration < abs(delta):
- position = self.focus.start - left_gap.duration
+ final_position = initial_position - left_gap.duration
+
+ self._defaultTo(final_position, priority)
+
+ def _defaultTo(self, position, priority):
+ if self._snap:
+ position = self.timeline.snapToEdge(position,
+ position + self.default_span)
+
+ priority = max(self.min_priority, priority)
self.focus.priority = priority
self.focus.setStart(position, snap = self._snap)
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index f28f6b4..587908d 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -959,6 +959,7 @@ class TestContexts(TestCase):
# move past right margin, should clamp
context = MoveContext(self.timeline, self.track_object2, self.other)
context.editTo(20 * gst.SECOND, 0)
+ context.finish()
self.failUnlessEqual(self.track_object1.start, 16 * gst.SECOND)
self.failUnlessEqual(self.track_object2.start, 11 * gst.SECOND)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]