Merge branch 'blender-v4.0-release'
[blender-addons.git] / power_sequencer / operators / crossfade_edit.py
blob7ecc31eb9f6ead22d0ea724f134529dcea1a89a5
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 import bpy
7 from .utils.global_settings import SequenceTypes
8 from .utils.doc import doc_name, doc_idname, doc_brief, doc_description
11 class POWER_SEQUENCER_OT_crossfade_edit(bpy.types.Operator):
12 """
13 *brief* Adjust the location of the crossfade between 2 strips
16 Selects the handles of both inputs of a crossfade strip's input and
17 calls the grab operator. Allows you to quickly change the location
18 of a fade transition between two strips.
19 """
21 doc = {
22 "name": doc_name(__qualname__),
23 "demo": "https://i.imgur.com/rCmLhg6.gif",
24 "description": doc_description(__doc__),
25 "shortcuts": [],
26 "keymap": "Sequencer",
28 bl_idname = doc_idname(__qualname__)
29 bl_label = doc["name"]
30 bl_description = doc_brief(doc["description"])
31 bl_options = {"REGISTER", "UNDO"}
33 crossfade_types = ["CROSS", "GAMMA_CROSS"]
35 @classmethod
36 def poll(cls, context):
37 return context.scene.sequence_editor.active_strip and context.selected_sequences
39 def execute(self, context):
40 active = context.scene.sequence_editor.active_strip
41 if active.type not in self.crossfade_types:
42 effect = self.find_cross_effect(context, active)
43 if not effect:
44 return {"CANCELLED"}
45 active = context.scene.sequence_editor.active_strip = effect
47 bpy.ops.sequencer.select_all(action="DESELECT")
48 active.select = True
49 active.input_1.select_right_handle = True
50 active.input_2.select_left_handle = True
51 active.input_1.select = True
52 active.input_2.select = True
53 bpy.ops.transform.seq_slide("INVOKE_DEFAULT")
54 return {"FINISHED"}
56 def find_cross_effect(self, sequence):
57 """
58 Takes a single strip and finds effect strips that use it as input
59 Returns the effect strip(s) found as a list, ordered by starting frame
60 Returns None if no effect was found
61 """
62 if sequence.type not in SequenceTypes.VIDEO + SequenceTypes.IMAGE:
63 return
65 effect_sequences = (s for s in context.sequences if s.type in SequenceTypes.EFFECT)
66 found_effect_strips = []
67 for s in effect_sequences:
68 if s.input_1.name == sequence.name:
69 found_effect_strips.append(s)
70 if s.input_count == 2:
71 if s.input_2.name == sequence.name:
72 found_effect_strips.append(s)
73 for e in found_effect_strips:
74 if e.type not in self.crossfade_types:
75 continue
76 return e