Cleanup: quiet warnings with descriptions ending with a '.'
[blender-addons.git] / power_sequencer / operators / trim_to_surrounding_cuts.py
blob5e04ec6cb443c716e52d0ebb196b1c0fc9485174
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 # Copyright (C) 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 """
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.
6 """
7 import bpy
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
22 """
24 doc = {
25 "name": doc_name(__qualname__),
26 "demo": "",
27 "description": doc_description(__doc__),
28 "shortcuts": [
30 {"type": "LEFTMOUSE", "value": "PRESS", "shift": True, "alt": True},
31 {},
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(
43 name="Trim margin",
44 description="Margin to leave on either sides of the trim in seconds",
45 default=0.2,
46 min=0,
48 gap_remove: bpy.props.BoolProperty(
49 name="Remove gaps",
50 description="When trimming the sequences, remove gaps automatically",
51 default=True,
54 @classmethod
55 def poll(cls, context):
56 return context
58 def invoke(self, context, event):
59 if not context.sequences:
60 return {"CANCELLED"}
62 frame = context.region.view2d.region_to_view(
63 x=event.mouse_region_x, y=event.mouse_region_y
64 )[0]
65 frame = round(frame)
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:
70 self.report(
71 {"WARNING"},
72 ("The trim margin is larger than the gap\n" "Use snap trim or reduce the margin"),
74 return {"CANCELLED"}
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)
83 if self.gap_remove:
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
90 return {"FINISHED"}