[pitivi/ges: 61/287] Properly handle timeline duration
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 61/287] Properly handle timeline duration
- Date: Thu, 15 Mar 2012 16:30:57 +0000 (UTC)
commit 5ec316d9ed2580f30a3467f7f356bbccfb122936
Author: Thibault Saunier <thibault saunier collabora com>
Date: Sat Oct 8 18:11:06 2011 -0300
Properly handle timeline duration
pitivi/ui/mainwindow.py | 37 +++++++++++++++++++++----------------
pitivi/ui/timeline.py | 35 ++++++++++++++++++++++++++---------
pitivi/ui/viewer.py | 7 ++++---
3 files changed, 51 insertions(+), 28 deletions(-)
---
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 07eb1d0..8346f7c 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -358,6 +358,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
vpaned.show()
self.timeline = Timeline(instance, self.uimanager)
+ self.timeline.connect("duration-changed",
+ self._timelineDurationChangedCb)
self.project = None
vpaned.pack2(self.timeline, resize=True, shrink=False)
@@ -955,36 +957,25 @@ class PitiviMainWindow(gtk.Window, Loggable):
return res
## Current Project Pipeline
+# We handle the pipeline here
def setProjectPipeline(self, pipeline):
self._project_pipeline = pipeline
if self._project_pipeline:
- # connect to timeline
- #self.project_pipeline.activatePositionListener()
- gobject.timeout_add(300, self._timelinePipelinePositionChangedCb)
+ bus = self._project_pipeline.get_bus()
+ bus.add_signal_watch()
+ bus.connect('message', self._busMessageCb)
def getProjectPipeline(self):
return self._project_pipeline
project_pipeline = property(getProjectPipeline, setProjectPipeline, None, "The Gst.Pipeline of the project")
- # handler(project_pipeline, "error")
- def _pipelineErrorCb(self, unused_pipeline, error, detail):
- pass
-
- def _timelinePipelinePositionChangedCb(self, pipeline, position):
- self.timeline.timelinePositionChanged(position)
- self.timelinepos = position
-
- # handler(project_pipeline, "state-changed")
- def _timelinePipelineStateChangedCb(self, pipeline, state):
+ def _timelinePipelineStateChanged(self, pipeline, state):
self.timeline.stateChanged(state)
## Project Timeline (not to be confused with UI timeline)
- #project_timeline = receiver()
-
- # handler(project_timeline, "duration-changed")
def _timelineDurationChangedCb(self, timeline, duration):
if duration > 0:
sensitive = True
@@ -995,6 +986,20 @@ class PitiviMainWindow(gtk.Window, Loggable):
sensitive = False
self.render_button.set_sensitive(sensitive)
+#Pipeline messages
+ def _busMessageCb(self, unused_bus, message):
+ if message.type == gst.MESSAGE_EOS:
+ self.warning("eos")
+ elif message.type == gst.MESSAGE_STATE_CHANGED:
+ prev, new, pending = message.parse_state_changed()
+
+ if message.src == self._project_pipeline:
+ self.debug("Pipeline change state prev:%r, new:%r, pending:%r", prev, new, pending)
+
+ state_change = pending == gst.STATE_VOID_PENDING
+
+ if state_change:
+ self._timelinePipelineStateChanged(self, new)
## other
def _showSaveAsDialog(self, project):
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index 8290f02..2ba70b3 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -182,6 +182,12 @@ class InfoStub(gtk.HBox, Loggable):
class Timeline(gtk.Table, Loggable, Zoomable):
+ __gtype_name__ = 'Timeline'
+ __gsignals__ = {
+ "duration-changed": (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE, (gobject.TYPE_INT,)),
+ }
+
def __init__(self, instance, ui_manager):
gtk.Table.__init__(self, rows=2, columns=1, homogeneous=False)
Loggable.__init__(self)
@@ -203,6 +209,8 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self._timeline = None
self._duration = 0
+ self._tcks_sig_ids = {}
+
self._temp_objects = []
def _createUI(self):
@@ -445,14 +453,16 @@ class Timeline(gtk.Table, Loggable, Zoomable):
return False
def setDuration(self, unused1=None, unused2=None):
- self._duration = 0
+ duration = 0
for track in self._timeline.get_tracks():
- if track.props.duration > self._duration:
- self._duration = track.props.duration
+ if track.props.duration > duration:
+ duration = track.props.duration
- self.debug("Duration changed %s", self._duration)
- return self._duration
+ if (duration != self._duration):
+ self.debug("Duration changed %s", self._duration)
+ self._duration = duration
+ self.emit("duration-changed", duration)
def getDuration(self):
return self._duration
@@ -675,14 +685,23 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.debug("Setting timeline %s", timeline)
self._controls.timeline = self._timeline
+ self.delTimeline()
self._timeline = timeline
for track in self._timeline.get_tracks():
- track.connect("notify::duration", self.setDuration)
+ self._tcks_sig_ids[track] = track.connect("notify::duration",
+ self.setDuration)
def getTimeline(self):
return self._timeline
- timeline = property(getTimeline, setTimeline, None, "The GESTimeline")
+ def delTimeline(self):
+ for track, sigid in self._tcks_sig_ids.iteritems():
+ track.disconnect(sigid)
+
+ self._timeline = None
+
+ timeline = property(getTimeline, setTimeline, delTimeline,
+ "The GESTimeline")
def _updateScrollAdjustments(self):
a = self.get_allocation()
@@ -704,7 +723,6 @@ class Timeline(gtk.Table, Loggable, Zoomable):
Zoomable.zoomOut()
def deleteSelected(self, unused_action):
- self.app.projectManager.current.pipeline.set_state(gst.STATE_NULL)
if self.timeline:
self.app.action_log.begin("delete clip")
for track_object in self.timeline.selected:
@@ -720,7 +738,6 @@ class Timeline(gtk.Table, Loggable, Zoomable):
lyr = obj.get_layer()
lyr.remove_object(obj)
self.app.action_log.commit()
- self.app.projectManager.current.pipeline.set_state(gst.STATE_PAUSED)
def unlinkSelected(self, unused_action):
if self.timeline:
diff --git a/pitivi/ui/viewer.py b/pitivi/ui/viewer.py
index 110e158..7b2a5e2 100644
--- a/pitivi/ui/viewer.py
+++ b/pitivi/ui/viewer.py
@@ -146,6 +146,9 @@ class PitiviViewer(gtk.VBox, Loggable):
bus.set_sync_handler(self._elementMessageCb)
self.pipeline.set_state(gst.STATE_PAUSED)
self.currentState = gst.STATE_PAUSED
+
+ gobject.timeout_add(300, self._posCb)
+
self._setUiActive()
self.seeker = self.app.projectManager.current.seeker
@@ -172,7 +175,7 @@ class PitiviViewer(gtk.VBox, Loggable):
def _busMessageCb(self, unused_bus, message):
if message.type == gst.MESSAGE_EOS:
- self.warning("eos")
+ print "eos"
elif message.type == gst.MESSAGE_STATE_CHANGED:
prev, new, pending = message.parse_state_changed()
@@ -601,8 +604,6 @@ class PitiviViewer(gtk.VBox, Loggable):
self.warning("seek failed")
def _posCb(self):
- if not self.playing:
- return False
try:
position = self.pipeline.query_position(gst.FORMAT_TIME)[0]
except:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]