[pitivi] Use the new frame accurate APIs from GES
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Use the new frame accurate APIs from GES
- Date: Wed, 1 Apr 2020 00:03:30 +0000 (UTC)
commit e16bbd58437220f54c912d2db373509d864b3cc6
Author: Thibault Saunier <tsaunier igalia com>
Date: Tue Mar 3 15:25:17 2020 -0300
Use the new frame accurate APIs from GES
And cleanup some code and remove dead code
pitivi/timeline/ruler.py | 24 ++++++++----------------
pitivi/timeline/timeline.py | 13 +------------
pitivi/utils/timeline.py | 11 +++++++++++
3 files changed, 20 insertions(+), 28 deletions(-)
---
diff --git a/pitivi/timeline/ruler.py b/pitivi/timeline/ruler.py
index 5ce0578e..0d9e08db 100644
--- a/pitivi/timeline/ruler.py
+++ b/pitivi/timeline/ruler.py
@@ -113,10 +113,6 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
self.pixbuf_offset_painted = 0
self.position = 0 # In nanoseconds
- self.frame_rate = Gst.Fraction(1 / 1)
- self.ns_per_frame = float(1 / self.frame_rate) * Gst.SECOND
-
- self.scales = SCALES
def _hadj_value_changed_cb(self, hadj):
"""Handles the adjustment value change."""
@@ -236,12 +232,6 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
def do_scroll_event(self, event):
self.timeline.timeline.do_scroll_event(event)
- def set_project_frame_rate(self, rate):
- """Sets the lowest scale based on the specified project framerate."""
- self.frame_rate = rate
- self.ns_per_frame = float(Gst.SECOND / self.frame_rate)
- self.scales = (2 / rate, 5 / rate, 10 / rate) + SCALES
-
def __set_tooltip_text(self, position, seeking=False):
"""Updates the tooltip."""
if seeking:
@@ -249,7 +239,7 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
if position > timeline_duration:
position = timeline_duration
human_time = beautify_length(position)
- cur_frame = int(position / self.ns_per_frame) + 1
+ cur_frame = self.timeline.ges_timeline.get_frame_at(position) + 1
self.set_tooltip_text(human_time + "\n" + _("Frame #%d") % cur_frame)
# Drawing methods
@@ -374,7 +364,11 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
These are based on the project's framerate settings, not the actual
frames on the assets.
"""
- frame_width = self.ns_to_pixel(self.ns_per_frame)
+ if not self.timeline.ges_timeline:
+ # Timeline not set yet
+ return
+
+ frame_width = self.ns_to_pixel(self.timeline.ges_timeline.get_frame_time(1))
if not frame_width >= FRAME_MIN_WIDTH_PIXELS:
return
@@ -382,13 +376,11 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
height = context.get_target().get_height()
y = int(height - FRAME_HEIGHT_PIXELS)
- frame_num = int(
- self.pixel_to_ns(self.pixbuf_offset) * float(self.frame_rate) / Gst.SECOND)
+ frame_num = self.timeline.ges_timeline.get_frame_at(self.pixel_to_ns(self.pixbuf_offset))
paintpos = self.pixbuf_offset - offset
max_pos = context.get_target().get_width() + self.pixbuf_offset
while paintpos < max_pos:
- paintpos = self.ns_to_pixel(
- 1 / float(self.frame_rate) * Gst.SECOND * frame_num)
+ paintpos = self.ns_to_pixel(self.timeline.ges_timeline.get_frame_time(frame_num))
if frame_num % 2:
set_cairo_color(context, self._color_frame)
context.rectangle(
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index f088b765..44e7b72c 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -926,7 +926,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
max_duration = clip_duration
ges_clip = ges_layer.add_asset(asset, start, 0, clip_duration,
- asset.get_supported_formats())
+ asset.get_supported_formats())
if not ges_clip:
return ges_clip
@@ -936,7 +936,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
ges_clip.props.max_duration = max_duration
return ges_clip
-
def __create_clips(self, x, y):
"""Creates the clips for an asset drag operation.
@@ -1537,14 +1536,11 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
def set_project(self, project):
"""Connects to the project's timeline and pipeline."""
if self._project:
- self._project.disconnect_by_func(self._rendering_settings_changed_cb)
self.markers.markers_container = None
self._project = project
if project:
- project.connect("rendering-settings-changed",
- self._rendering_settings_changed_cb)
self.ges_timeline = project.ges_timeline
else:
self.ges_timeline = None
@@ -1554,7 +1550,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
if project:
self.ruler.set_pipeline(project.pipeline)
self.ruler.zoom_changed()
- self.ruler.set_project_frame_rate(project.videorate)
self.timeline.set_best_zoom_ratio(allow_zoom_in=True)
self.timeline.update_snapping_distance()
@@ -1597,7 +1592,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self.ruler = ScaleRuler(self)
self.ruler.props.hexpand = True
- self.ruler.set_project_frame_rate(24.)
builder = Gtk.Builder()
builder.add_from_file(os.path.join(get_ui_dir(), "timelinetoolbar.ui"))
@@ -2119,11 +2113,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self.log("Timeline has lost focus")
self.update_actions()
- def _rendering_settings_changed_cb(self, project, item):
- """Handles Project metadata changes."""
- if item == "videorate" or item is None:
- self.ruler.set_project_frame_rate(project.videorate)
-
def __timeline_size_allocate_cb(self, unused_widget, allocation):
fits = self.timeline.layout.props.height <= allocation.height
self.vscrollbar.set_opacity(0 if fits else 1)
diff --git a/pitivi/utils/timeline.py b/pitivi/utils/timeline.py
index 7e608fa8..cef9ad75 100644
--- a/pitivi/utils/timeline.py
+++ b/pitivi/utils/timeline.py
@@ -320,6 +320,17 @@ class EditingContext(GObject.Object, Loggable):
self.new_position = position
self.new_priority = priority
+ if self.with_video:
+ frame = self.timeline.get_frame_at(position)
+ time = self.timeline.get_frame_time(frame)
+ if position != time:
+ frame_dur = self.timeline.get_frame_time(1)
+ next_time = self.timeline.get_frame_time(frame + 1)
+ if abs(position - next_time) < frame_dur / 2:
+ position = next_time
+ else:
+ position = time
+
res = self.focus.edit([], priority, self.mode, self.edge, int(position))
self.app.write_action("edit-container",
container_name=self.focus.get_name(),
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]