1 # SPDX-License-Identifier: GPL-3.0-or-later
2 # Copyright (C) 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
4 Find the two closest cuts, trims and deletes all strips above in the range but leaves some
5 margin. Removes the newly formed gap.
9 from .utils
.functions
import convert_duration_to_frames
, trim_strips
10 from .utils
.doc
import doc_name
, doc_idname
, doc_brief
, doc_description
11 from .utils
.functions
import find_closest_surrounding_cuts_frames
, find_strips_in_range
14 class POWER_SEQUENCER_OT_trim_to_surrounding_cuts(bpy
.types
.Operator
):
15 """*Brief* Automatically trim to surrounding cuts with some time offset
17 Finds the two cuts closest to the mouse cursor and trims the footage in between, leaving a
18 little time offset. It's useful after you removed some bad audio but you need to keep some
19 video around for a transition.
21 By default, the tool leaves a 0.2 seconds margin on either side of the trim
25 "name": doc_name(__qualname__
),
27 "description": doc_description(__doc__
),
30 {"type": "LEFTMOUSE", "value": "PRESS", "shift": True, "alt": True},
32 "Trim to Surrounding Cuts",
35 "keymap": "Sequencer",
37 bl_idname
= doc_idname(__qualname__
)
38 bl_label
= doc
["name"]
39 bl_description
= doc_brief(doc
["description"])
40 bl_options
= {"REGISTER", "UNDO"}
42 margin
: bpy
.props
.FloatProperty(
44 description
="Margin to leave on either sides of the trim in seconds",
48 gap_remove
: bpy
.props
.BoolProperty(
50 description
="When trimming the sequences, remove gaps automatically",
55 def poll(cls
, context
):
58 def invoke(self
, context
, event
):
59 if not context
.sequences
:
62 frame
= context
.region
.view2d
.region_to_view(
63 x
=event
.mouse_region_x
, y
=event
.mouse_region_y
67 margin_frame
= convert_duration_to_frames(context
, self
.margin
)
68 left_cut_frame
, right_cut_frame
= find_closest_surrounding_cuts_frames(context
, frame
)
69 if abs(left_cut_frame
- right_cut_frame
) <= margin_frame
* 2:
72 ("The trim margin is larger than the gap\n" "Use snap trim or reduce the margin"),
76 to_delete
, to_trim
= find_strips_in_range(
77 left_cut_frame
, right_cut_frame
, context
.sequences
79 trim_start
, trim_end
= (left_cut_frame
+ margin_frame
, right_cut_frame
- margin_frame
)
81 trim_strips(context
, trim_start
, trim_end
, to_trim
, to_delete
)
84 frame_to_remove_gap
= right_cut_frame
- 1 if frame
== right_cut_frame
else frame
85 # bpy.ops.anim.change_frame(frame_to_remove_gap)
86 context
.scene
.frame_current
= frame_to_remove_gap
87 bpy
.ops
.power_sequencer
.gap_remove()
88 context
.scene
.frame_current
= trim_start