pitivi r1375 - in trunk/pitivi: timeline ui
- From: edwardrv svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1375 - in trunk/pitivi: timeline ui
- Date: Fri, 28 Nov 2008 17:04:17 +0000 (UTC)
Author: edwardrv
Date: Fri Nov 28 17:04:17 2008
New Revision: 1375
URL: http://svn.gnome.org/viewvc/pitivi?rev=1375&view=rev
Log:
move edge snapping code from static methods of TimelineObject to instance methods of Timeline
Modified:
trunk/pitivi/timeline/objects.py
trunk/pitivi/timeline/timeline.py
trunk/pitivi/ui/complextimeline.py
Modified: trunk/pitivi/timeline/objects.py
==============================================================================
--- trunk/pitivi/timeline/objects.py (original)
+++ trunk/pitivi/timeline/objects.py Fri Nov 28 17:04:17 2008
@@ -29,7 +29,7 @@
from pitivi.serializable import Serializable
from pitivi.objectfactory import ObjectFactory
from pitivi.signalinterface import Signallable
-from pitivi.utils import closest_item
+import pitivi.instance as instance
(MEDIA_TYPE_NONE,
MEDIA_TYPE_AUDIO,
@@ -343,12 +343,6 @@
"start-duration-changed" : ["start", "duration"]
}
- # for edge snapping
- __edges = []
- __deadband = 0
- __do_updates = True
- __instances = []
-
def __init__(self, factory=None, start=gst.CLOCK_TIME_NONE,
duration=0, media_type=MEDIA_TYPE_NONE, name="", **kwargs):
BrotherObjects.__init__(self, **kwargs)
@@ -363,10 +357,6 @@
self.media_type = media_type
self.gnlobject = None
self.factory = factory
- TimelineObject.registerInstance(self)
-
- def __del__(self):
- TimelineObject.unregisterInstance(self)
## properties
@@ -419,13 +409,36 @@
if self._linked:
self._linked._setStartDurationTime(start, duration)
+ def snapStartDurationTime(self, start=gst.CLOCK_TIME_NONE, duration=0):
+ """ sets the start and/or duration time, with edge snapping """
+ self.setStartDurationTime(
+ instance.PiTiVi.current.timeline.snapObjToEdge(self, start),
+ duration)
+
+ def setInTime(self, time):
+ """Sets the timeline object's in point in the timeline, keeping its
+ out-point constant."""
+ delta = self.start - time
+ self.setStartDurationTime(time, self.duration + delta)
+
+ def setOutTime(self, time):
+ """Set's the timeline object's out point in the timeline, keeping its
+ in-point constant."""
+ self.setStartDurationTime(self.start, time - self.start)
+
+ def snapInTime(self, time):
+ self.setInTime(instance.PiTiVi.current.timeline.snapTimeToEdge(time))
+
+ def snapOutTime(self, time):
+ self.setOutTime(instance.PiTiVi.current.timeline.snapTimeToEdge(time))
+
## methods to override in subclasses
def _makeGnlObject(self):
""" create and return the gnl_object """
raise NotImplementedError
- ## private methods
+## private methods
def __repr__(self):
if hasattr(self, "name"):
@@ -520,12 +533,9 @@
else:
self.gnlobject.debug("duration changed:%s" % gst.TIME_ARGS(duration))
self._duration = long(duration)
- # be sure to update edges
- TimelineObject.updateEdges()
self.emit("start-duration-changed", self._start, self._duration)
-
- # Serializable methods
+## Serializable methods
def toDataFormat(self):
ret = BrotherObjects.toDataFormat(self)
@@ -566,78 +576,3 @@
def isVideo(self):
return self.media_type == MEDIA_TYPE_VIDEO
- ## code for keeping track of edit points, and snapping timestamps to the
- ## nearest edit point. We do this here so we can keep track of edit points
- ## for all layers/tracks.
-
- @classmethod
- def registerInstance(cls, instance):
- cls.__instances.append(weakref.ref(instance))
-
- @classmethod
- def unregisterInstance(cls, instance):
- ref = weakref.ref(instance)
- assert ref in self.__instances
- self.__instances.remove(ref)
-
- @classmethod
- def setDeadband(cls, db):
- cls.__deadband = db
-
- @classmethod
- def enableEdgeUpdates(cls):
- cls.__do_updates = True
- cls.updateEdges()
-
- @classmethod
- def disableEdgeUpdates(cls):
- cls.__do_updates = False
-
- @classmethod
- def updateEdges(cls):
- if not cls.__do_updates:
- return
- #FIXME: this might be more efficient if we used a binary sort tree,
- # filter out duplicate edges in linear time
- edges = {}
- for obj in cls.__instances:
- assert obj()
- obj = obj()
- # start/end of object both considered "edit points"
- edges[obj.start] = None
- edges[obj.start + obj.duration] = None
- # TODO: add other critical object points when these are
- # implemented
- # TODO: filtering mechanism
- cls.__edges = edges.keys()
- cls.__edges.sort()
-
- @classmethod
- def snapTimeToEdge(cls, time):
- """Returns the input time or the nearest edge"""
- res, diff = closest_item(cls.__edges, time)
- if diff <= cls.__deadband:
- return res
- return time
-
- @classmethod
- def snapObjToEdge(cls, obj, time):
- """Returns the input time or the edge which is closest to either the
- start or finish time. The input time is interpreted as the start time
- of obj."""
-
- # need to find the closest edge to both the left and right sides of
- # the object we are draging.
- duration = obj.duration
- left_res, left_diff = closest_item(cls.__edges, time)
- right_res, right_diff = closest_item(cls.__edges, time + duration)
- if left_diff <= right_diff:
- res = left_res
- diff = left_diff
- else:
- res = right_res - duration
- diff = right_diff
- if diff <= cls.__deadband:
- return res
- return time
-
Modified: trunk/pitivi/timeline/timeline.py
==============================================================================
--- trunk/pitivi/timeline/timeline.py (original)
+++ trunk/pitivi/timeline/timeline.py Fri Nov 28 17:04:17 2008
@@ -30,6 +30,7 @@
from objects import MEDIA_TYPE_AUDIO, MEDIA_TYPE_VIDEO
from source import TimelineBlankSource, TimelineFileSource
from pitivi.serializable import Serializable
+from pitivi.utils import closest_item
class Timeline(Serializable):
"""
@@ -78,6 +79,10 @@
self.audiocomp.gnlobject.connect("pad-removed", self._removedAudioPadCb)
self.videocomp.gnlobject.connect("pad-removed", self._removedVideoPadCb)
+ # we need to keep track of every object added to the timeline
+ self.videocomp.connect("source-added", self._sourceAddedCb)
+ self.videocomp.connect("source-removed", self._sourceRemovedCb)
+
def addFactory(self, factory, time=gst.CLOCK_TIME_NONE, shift=False):
"""Add a factory to the timeline using the the specified time as the
start time. If shift is true, then move overlapping sources out of the
@@ -92,12 +97,6 @@
video_source = TimelineFileSource(factory=factory,
media_type=MEDIA_TYPE_VIDEO,
name=factory.name)
- # WARNING: this won't actually catch the linked source, so if the
- # source is ever unlinked its edges will not be seen. On the other
- # hand, this won't matter once we switch to the parent-child
- # model.
- #self.register_instance(video_source)
- # TODO: insert source in proper location
self.videocomp.appendSource(video_source)
# must be elif because of auto-linking, this just catches case where
# factory is only audio
@@ -105,8 +104,6 @@
audio_source = TimelineFileSource(factory=factory,
media_type=MEDIA_TYPE_VIDEO,
name=factory.name)
- #self.register_instance(audio_source)
- # TODO: insert source in proper location
self.audiocomp.appendSource(audio_source)
def _newAudioPadCb(self, unused_audiocomp, pad):
@@ -147,7 +144,78 @@
def getDuration(self):
return max(self.audiocomp.duration, self.videocomp.duration)
- # Serializable methods
+## code for keeping track of edit points, and snapping timestamps to the
+## nearest edit point. We do this here so we can keep track of edit points
+## for all layers/tracks.
+
+ __instances = []
+ __deadband = 0
+ __do_updates = True
+ __edges = None
+
+ def _sourceAddedCb(self, composition, inst):
+ self.__instances.append(inst)
+ self.updateEdges()
+
+ def _sourceRemovedCb(self, composition, inst):
+ assert inst in self.__instances
+ self.__instances.remove(inst)
+
+ def setDeadband(self, db):
+ self.__deadband = db
+
+ def enableEdgeUpdates(self):
+ self.__do_updates = True
+ self.updateEdges()
+
+ def disableEdgeUpdates(self):
+ self.__do_updates = False
+
+ def updateEdges(self):
+ if not self.__do_updates:
+ return
+ #FIXME: this might be more efficient if we used a binary sort tree,
+ # filter out duplicate edges in linear time
+ edges = {}
+ for obj in self.__instances:
+ # start/end of object both considered "edit points"
+ edges[obj.start] = None
+ edges[obj.start + obj.duration] = None
+ # TODO: add other critical object points when these are
+ # implemented
+ # TODO: filtering mechanism
+ self.__edges = edges.keys()
+ self.__edges.sort()
+
+ def snapTimeToEdge(self, time):
+ """Returns the input time or the nearest edge"""
+ res, diff = closest_item(self.__edges, time)
+ if diff <= self.__deadband:
+ return res
+ return time
+
+ def snapObjToEdge(self, obj, time):
+ """Returns the input time or the edge which is closest to either the
+ start or finish time. The input time is interpreted as the start time
+ of obj."""
+
+ # need to find the closest edge to both the left and right sides of
+ # the object we are draging.
+ duration = obj.duration
+ left_res, left_diff = closest_item(self.__edges, time)
+ right_res, right_diff = closest_item(self.__edges, time + duration)
+ if left_diff <= right_diff:
+ res = left_res
+ diff = left_diff
+ else:
+ res = right_res - duration
+ diff = right_diff
+ if diff <= self.__deadband:
+ return res
+ return time
+
+## Serializable interfacemethods
+
def toDataFormat(self):
ret = Serializable.toDataFormat(self)
ret["compositions"] = dict((\
Modified: trunk/pitivi/ui/complextimeline.py
==============================================================================
--- trunk/pitivi/ui/complextimeline.py (original)
+++ trunk/pitivi/ui/complextimeline.py Fri Nov 28 17:04:17 2008
@@ -255,11 +255,11 @@
def _start_drag(self, item):
item.raise_(None)
self._draging = True
- objects.TimelineObject.disableEdgeUpdates()
+ instance.PiTiVi.current.timeline.disableEdgeUpdates()
def _end_drag(self, unused_item):
self.canvas.block_size_request(False)
- objects.TimelineObject.enableEdgeUpdates()
+ instance.PiTiVi.current.timeline.enableEdgeUpdates()
def _move_source_cb(self, item, pos):
element = item.element
@@ -602,7 +602,7 @@
## Zoomable Override
def zoomChanged(self):
- objects.TimelineObject.setDeadband(self.pixelToNs(DEADBAND))
+ instance.PiTiVi.current.timeline.setDeadband(self.pixelToNs(DEADBAND))
def setChildZoomAdjustment(self, adj):
for layer in self.layers:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]