Blender V5.3
compositor_nodes_srna.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10
11#include "BLI_listbase.hh"
12#include "BLI_string.hh"
13
15#include "NOD_socket.hh"
16
17#include "DNA_node_types.h"
18#include "DNA_sequence_types.h"
19
20#include "BKE_idprop.hh"
21#include "BKE_node_runtime.hh"
22
23#include "SEQ_iterator.hh"
24#include "SEQ_sequencer.hh"
25
26#include "RNA_access.hh"
27#include "RNA_define.hh"
28#include "RNA_prototypes.hh"
29
30namespace blender::nodes {
31
33 int(CompositorNodesInputType::Fallback), "FALLBACK", 0, "Fallback", "Fallback"};
35 int(CompositorNodesInputType::Value), "VALUE", 0, "Value", "Pass a single value"};
36
41
46
51
52static std::pair<const Strip *, const StripModifierData *>
54{
55 if (const auto modifier = RNA_struct_search_closest_ancestor_by_type(ptr, RNA_StripModifier)) {
56 if (const auto strip = RNA_struct_search_closest_ancestor_by_type(ptr, RNA_Strip)) {
57 return {static_cast<const Strip *>(strip->data),
58 static_cast<const StripModifierData *>(modifier->data)};
59 }
60 }
61 const Scene *sequencer_scene = id_cast<const Scene *>(ptr->owner_id);
62 const Editing *ed = seq::editing_get(sequencer_scene);
64 for (Strip *strip : seq::query_all_strips_recursive(&ed->seqbase)) {
65 for (StripModifierData &md : strip->modifiers) {
66 bool found = false;
68 if (id_prop == ptr->data) {
69 found = true;
70 }
71 });
72 if (found) {
73 return {strip, &md};
74 }
75 }
76 }
77 return {};
78}
79
81{
82 if (const auto strip = RNA_struct_search_closest_ancestor_by_type(ptr, RNA_Strip)) {
83 return static_cast<const Strip *>(strip->data);
84 }
85 const Scene *sequencer_scene = id_cast<const Scene *>(ptr->owner_id);
86 const Editing *ed = seq::editing_get(sequencer_scene);
88 for (Strip *strip : seq::query_all_strips_recursive(&ed->seqbase)) {
89 if (strip->type != STRIP_TYPE_COMPOSITOR || strip->effectdata == nullptr) {
90 continue;
91 }
92 const auto *comp = static_cast<const CompositorEffectVars *>(strip->effectdata);
93 bool found = false;
94 IDP_foreach_property(comp->system_properties, 0, [&](IDProperty *id_prop) {
95 if (id_prop == ptr->data) {
96 found = true;
97 }
98 });
99 if (found) {
100 return strip;
101 }
102 }
103 return nullptr;
104}
105
106static std::optional<std::string> rna_CompositorNodesModifierPropertyInput_path(
107 const PointerRNA *ptr)
108{
109 StructRNA *srna = ptr->type;
110 const char *identifier = RNA_struct_identifier(srna);
111 const auto [strip, smd] = find_strip_and_modifier_data_from_system_property(ptr);
112 BLI_assert(strip && smd);
113 std::string strip_name_esc = BLI_str_escape(strip->name + 2);
114 std::string modifier_name_esc = BLI_str_escape(smd->name);
115 return fmt::format("sequence_editor.strips_all[\"{}\"].modifiers[\"{}\"].properties.inputs.{}",
116 strip_name_esc,
117 modifier_name_esc,
118 identifier);
119}
120
121static std::optional<std::string> rna_CompositorNodesEffectPropertyInput_path(
122 const PointerRNA *ptr)
123{
124 StructRNA *srna = ptr->type;
125 const char *identifier = RNA_struct_identifier(srna);
127 BLI_assert(strip);
128 std::string strip_name_esc = BLI_str_escape(strip->name + 2);
129 return fmt::format(
130 "sequence_editor.strips_all[\"{}\"].properties.inputs.{}", strip_name_esc, identifier);
131}
132
134 const bNodeTreeInterfaceSocket &socket,
135 const CompositorNodesSrnaContext &context,
136 GeneratedTreeSrnaData &r_generated)
137{
138 const bke::bNodeSocketType *stype = socket.socket_typeinfo();
139 if (!stype) {
140 return nullptr;
141 }
142 const StringRefNull srna_identifier = r_generated.scope.allocator().copy_string(
143 socket.identifier);
144
146 r_generated.generated_rna, srna_identifier.c_str(), RNA_PropertyGroup);
147 RNA_def_struct_path_func_runtime(srna, context.path_func);
149 stype->make_compositor_nodes_input_srna(tree, *srna, socket, r_generated);
150 }
151
152 return srna;
153}
154
156 const CompositorNodesSrnaContext &context,
157 GeneratedTreeSrnaData &r_generated)
158{
160 r_generated.generated_rna, "CompositorNodesInterfaceInputs", RNA_PropertyGroup);
161
162 for (const bNodeTreeInterfaceSocket *socket : tree.interface_inputs()) {
163 StructRNA *socket_srna = get_input_socket_struct_rna(tree, *socket, context, r_generated);
164 if (!socket_srna) {
165 continue;
166 }
167 const StringRefNull identifier = r_generated.scope.allocator().copy_string(socket->identifier);
168 RNA_def_pointer_runtime(srna, identifier.c_str(), socket_srna, socket->name().c_str(), "");
169 }
170
171 return srna;
172}
173
175{
177 r_generated.generated_rna, "CompositorNodesInterfacePanels", RNA_PropertyGroup);
178
179 LinearAllocator<> &allocator = r_generated.scope.allocator();
180
181 tree.ensure_interface_cache();
182 for (const bNodeTreeInterfaceItem *item : tree.interface_items()) {
183 if (item->item_type != NodeTreeInterfaceItemType::Panel) {
184 continue;
185 }
186 const auto &panel = *reinterpret_cast<const bNodeTreeInterfacePanel *>(item);
187 const StringRefNull identifier = allocator.copy_string(
188 fmt::format("open_{}", panel.identifier));
189 PropertyRNA *prop = RNA_def_boolean(srna,
190 identifier.c_str(),
192 "Is Open",
193 "");
195 }
196
197 return srna;
198}
199
200static std::shared_ptr<GeneratedTreeSrnaData> create_compositor_nodes_rna(
201 const bNodeTree &tree, const CompositorNodesSrnaContext &context)
202{
203 auto generated = std::make_unique<GeneratedTreeSrnaData>();
204 tree.ensure_interface_cache();
205
207 generated->generated_rna, "CompositorNodesInterface", context.properties_struct);
208 generated->properties_struct = srna;
209
210 StructRNA *inputs_srna = create_inputs_srna(tree, context, *generated);
211 /* Note: We don't generate any srna for the outputs because they are unused by the compositor. */
212 StructRNA *panels_srna = create_panels_srna(tree, *generated);
213
214 PropertyRNA *prop;
216 srna, "inputs", inputs_srna, "Inputs", "Settings for input sockets");
218 prop = RNA_def_pointer_runtime(srna, "panels", panels_srna, "Panels", "Settings for panels");
220
221 return generated;
222}
223
224std::shared_ptr<GeneratedTreeSrnaData> create_compositor_nodes_rna_for_strip_modifier(
225 const bNodeTree &tree)
226{
227 const CompositorNodesSrnaContext context{RNA_SequencerCompositorModifierProperties,
229 return create_compositor_nodes_rna(tree, context);
230}
231
232std::shared_ptr<GeneratedTreeSrnaData> create_compositor_nodes_rna_for_effect(
233 const bNodeTree &tree)
234{
235 const CompositorNodesSrnaContext context{RNA_SequencerCompositorEffectProperties,
237 return create_compositor_nodes_rna(tree, context);
238}
239
240} // namespace blender::nodes
StringRefNull copy_string(StringRef str)
LinearAllocator & allocator()
constexpr const char * c_str() const
static StructRNA * create_inputs_srna(const bNodeTree &tree, const CompositorNodesSrnaContext &context, GeneratedTreeSrnaData &r_generated)
static const Strip * find_effect_strip_from_system_property(const PointerRNA *ptr)
const EnumPropertyItem compositor_nodes_input_type_items_value[]
const EnumPropertyItem compositor_nodes_input_type_items_fallback[]
static std::pair< const Strip *, const StripModifierData * > find_strip_and_modifier_data_from_system_property(const PointerRNA *ptr)
static StructRNA * create_panels_srna(const bNodeTree &tree, GeneratedTreeSrnaData &r_generated)
static StructRNA * get_input_socket_struct_rna(const bNodeTree &tree, const bNodeTreeInterfaceSocket &socket, const CompositorNodesSrnaContext &context, GeneratedTreeSrnaData &r_generated)
std::shared_ptr< GeneratedTreeSrnaData > create_compositor_nodes_rna_for_effect(const bNodeTree &tree)
static constexpr EnumPropertyItem input_type_item_fallback
static constexpr EnumPropertyItem input_type_item_value
std::shared_ptr< GeneratedTreeSrnaData > create_compositor_nodes_rna_for_strip_modifier(const bNodeTree &tree)
static std::optional< std::string > rna_CompositorNodesEffectPropertyInput_path(const PointerRNA *ptr)
static std::shared_ptr< GeneratedTreeSrnaData > create_compositor_nodes_rna(const bNodeTree &tree, const CompositorNodesSrnaContext &context)
static std::optional< std::string > rna_CompositorNodesModifierPropertyInput_path(const PointerRNA *ptr)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
VectorSet< Strip * > query_all_strips_recursive(const ListBaseT< Strip > *seqbase)
Definition iterator.cc:123
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
std::optional< AncestorPointerRNA > RNA_struct_search_closest_ancestor_by_type(const PointerRNA *ptr, const StructRNA *srna)
PropertyRNA * RNA_def_pointer_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
StructRNA RNA_PropertyGroup
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
const char * RNA_struct_identifier(const StructRNA *type)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_struct_path_func_runtime(StructRNA *srna, StructPathFunc path_fn)
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:509
std::optional< std::string >(*)(const PointerRNA *ptr) StructPathFunc
Definition RNA_types.hh:858
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
StructRNA * type
Definition RNA_types.hh:63
struct IDProperty * system_properties
Defines a socket type.
Definition BKE_node.hh:163
SocketMakeNodesInputSrnaFunction make_compositor_nodes_input_srna
Definition BKE_node.hh:219