Fix io_anim_camera error exporting cameras with quotes in their name
[blender-addons.git] / power_sequencer / operators / jump_to_cut.py
blobadd0dab9b188fa166829c5c7b1a5a94bce249300
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.
6 import bpy
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):
13 """
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.
19 """
21 doc = {
22 "name": doc_name(__qualname__),
23 "demo": "",
24 "description": doc_description(__doc__),
25 "shortcuts": [
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",
37 "keymap": "Frames",
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(
45 name="Direction",
46 description="Jump direction, either forward or backward",
47 items=[
48 ("RIGHT", "Forward", "Jump forward in time"),
49 ("LEFT", "Backward", "Jump backward in time"),
53 @classmethod
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")
63 fcurves = []
64 animation_data = context.scene.animation_data
65 if animation_data and animation_data.action:
66 fcurves = animation_data.action.fcurves
68 frame_target = -1
69 if self.direction == "RIGHT":
70 sequences = [s for s in sorted_sequences if s.frame_final_end > frame_current]
71 for s in sequences:
73 frame_target = (
74 s.frame_final_end
75 if s.frame_final_start <= frame_current
76 else s.frame_final_start
79 for f in fcurves:
80 for k in f.keyframe_points:
81 frame = k.co[0]
82 if frame <= context.scene.frame_current:
83 continue
84 frame_target = min(frame_target, frame)
85 break
87 elif self.direction == "LEFT":
88 sequences = [
89 s for s in reversed(sorted_sequences) if s.frame_final_start < frame_current
91 for s in sequences:
93 frame_target = (
94 s.frame_final_start if s.frame_final_end >= frame_current else s.frame_final_end
97 for f in fcurves:
98 for k in f.keyframe_points:
99 frame = k.co[0]
100 if frame >= context.scene.frame_current:
101 continue
102 frame_target = max(frame_target, frame)
103 break
105 if frame_target != -1:
106 context.scene.frame_current = max(1, frame_target)
108 return {"FINISHED"}