1 # SPDX-License-Identifier: GPL-3.0-or-later
2 # Copyright 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
4 # This file is part of Power Sequencer.
7 from operator
import attrgetter
9 from .utils
.doc
import doc_name
, doc_idname
, doc_brief
, doc_description
12 class POWER_SEQUENCER_OT_jump_to_cut(bpy
.types
.Operator
):
14 *brief* Jump to next/previous cut
17 Jump to the next or the previous cut in the edit. Unlike Blender's default tool, also
18 works during playback.
22 "name": doc_name(__qualname__
),
24 "description": doc_description(__doc__
),
27 {"type": "UP_ARROW", "value": "PRESS"},
28 {"direction": "RIGHT"},
29 "Jump to next cut or keyframe",
32 {"type": "DOWN_ARROW", "value": "PRESS"},
33 {"direction": "LEFT"},
34 "Jump to previous cut or keyframe",
39 bl_idname
= doc_idname(__qualname__
)
40 bl_label
= doc
["name"]
41 bl_description
= doc_brief(doc
["description"])
42 bl_options
= {"REGISTER", "UNDO"}
44 direction
: bpy
.props
.EnumProperty(
46 description
="Jump direction, either forward or backward",
48 ("RIGHT", "Forward", "Jump forward in time"),
49 ("LEFT", "Backward", "Jump backward in time"),
54 def poll(cls
, context
):
55 return context
.sequences
57 def execute(self
, context
):
58 frame_current
= context
.scene
.frame_current
59 sorted_sequences
= sorted(
60 context
.sequences
, key
=attrgetter("frame_final_start", "frame_final_end")
64 animation_data
= context
.scene
.animation_data
65 if animation_data
and animation_data
.action
:
66 fcurves
= animation_data
.action
.fcurves
69 if self
.direction
== "RIGHT":
70 sequences
= [s
for s
in sorted_sequences
if s
.frame_final_end
> frame_current
]
75 if s
.frame_final_start
<= frame_current
76 else s
.frame_final_start
80 for k
in f
.keyframe_points
:
82 if frame
<= context
.scene
.frame_current
:
84 frame_target
= min(frame_target
, frame
)
87 elif self
.direction
== "LEFT":
89 s
for s
in reversed(sorted_sequences
) if s
.frame_final_start
< frame_current
94 s
.frame_final_start
if s
.frame_final_end
>= frame_current
else s
.frame_final_end
98 for k
in f
.keyframe_points
:
100 if frame
>= context
.scene
.frame_current
:
102 frame_target
= max(frame_target
, frame
)
105 if frame_target
!= -1:
106 context
.scene
.frame_current
= max(1, frame_target
)