Blender V5.3
strip_lookup.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "SEQ_sequencer.hh"
10#include "sequencer.hh"
11
12#include "DNA_listBase.h"
13#include "DNA_node_types.h"
14#include "DNA_scene_types.h"
15#include "DNA_sequence_types.h"
16
17#include "BLI_listbase.hh"
18#include "BLI_mutex.hh"
19
20#include <cstring>
21
22#include "MEM_guardedalloc.h"
23
24namespace blender::seq {
25
27
37
38static void strip_lookup_append_effect(const Strip *input, Strip *effect, StripLookup *lookup)
39{
40 if (input == nullptr) {
41 return;
42 }
43
44 VectorSet<Strip *> &effects = lookup->effects_by_strip.lookup_or_add_default(input);
45
46 effects.add(effect);
47}
48
49static void strip_by_scene_lookup_build(Strip *strip, StripLookup *lookup)
50{
51 if (strip->scene == nullptr) {
52 return;
53 }
54 VectorSet<Strip *> &strips = lookup->strips_by_scene.lookup_or_add_default(strip->scene);
55 strips.add(strip);
56}
57
59{
60 if (strip->type == STRIP_TYPE_COMPOSITOR && strip->effectdata) {
61 const CompositorEffectVars *comp_data = static_cast<CompositorEffectVars *>(strip->effectdata);
62 if (comp_data->node_group) {
63 VectorSet<Strip *> &strips = lookup->strips_by_compositor_node_group.lookup_or_add_default(
64 comp_data->node_group);
65 strips.add(strip);
66 }
67 }
68
69 for (StripModifierData &modifier : strip->modifiers) {
71 continue;
72 }
73
74 const SequencerCompositorModifierData *modifier_data =
75 reinterpret_cast<SequencerCompositorModifierData *>(&modifier);
76 if (!modifier_data->node_group) {
77 continue;
78 }
79
80 VectorSet<Strip *> &strips = lookup->strips_by_compositor_node_group.lookup_or_add_default(
81 modifier_data->node_group);
82 strips.add(strip);
83 }
84}
85
86static void strip_lookup_build_effect(Strip *strip, StripLookup *lookup)
87{
88 if (!strip->is_effect()) {
89 return;
90 }
91
92 strip_lookup_append_effect(strip->input1, strip, lookup);
93 strip_lookup_append_effect(strip->input2, strip, lookup);
94}
95
96static void strip_lookup_build_from_seqbase(Strip *parent_meta,
97 const ListBaseT<Strip> *seqbase,
98 StripLookup *lookup)
99{
100 if (parent_meta != nullptr) {
101 for (SeqTimelineChannel &channel : parent_meta->channels) {
102 lookup->owner_by_channel.add(&channel, parent_meta);
103 }
104 }
105
106 for (Strip &strip : *seqbase) {
107 lookup->strip_by_name.add(strip.name + 2, &strip);
108 lookup->meta_by_strip.add(&strip, parent_meta);
109 strip_lookup_build_effect(&strip, lookup);
110 strip_by_scene_lookup_build(&strip, lookup);
112
113 if (strip.type == STRIP_TYPE_META) {
114 strip_lookup_build_from_seqbase(&strip, &strip.seqbase, lookup);
115 }
116 }
117}
118
119static void strip_lookup_build(const Editing *ed, StripLookup *lookup)
120{
121 strip_lookup_build_from_seqbase(nullptr, &ed->seqbase, lookup);
122 lookup->is_valid = true;
123}
124
126{
127 StripLookup *lookup = MEM_new<StripLookup>(__func__);
128 return lookup;
129}
130
131static void strip_lookup_free(StripLookup **lookup)
132{
133 MEM_delete(*lookup);
134 *lookup = nullptr;
135}
136
137static void strip_lookup_rebuild(const Editing *ed, StripLookup **lookup)
138{
139 strip_lookup_free(lookup);
140 *lookup = strip_lookup_new();
141 strip_lookup_build(ed, *lookup);
142}
143
145{
146 if (!ed) {
147 return;
148 }
149 if (*lookup && (*lookup)->is_valid) {
150 return;
151 }
152
153 strip_lookup_rebuild(ed, lookup);
154}
155
157{
158 BLI_assert(ed != nullptr);
159 std::lock_guard lock(lookup_lock);
160 strip_lookup_free(&ed->runtime->strip_lookup);
161}
162
164{
165 BLI_assert(ed != nullptr);
166 std::lock_guard lock(lookup_lock);
167 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
168 StripLookup *lookup = ed->runtime->strip_lookup;
169 return lookup->strip_by_name.lookup_default(key, nullptr);
170}
171
173{
174 BLI_assert(ed != nullptr);
175 std::lock_guard lock(lookup_lock);
176 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
177 StripLookup *lookup = ed->runtime->strip_lookup;
178 VectorSet<Strip *> &strips = lookup->strips_by_scene.lookup_or_add_default(key);
179 return strips.as_span();
180}
181
183{
184 BLI_assert(ed != nullptr);
185 std::lock_guard lock(lookup_lock);
186 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
187 StripLookup *lookup = ed->runtime->strip_lookup;
188 return lookup->strips_by_scene;
189}
190
192{
193 BLI_assert(ed != nullptr);
195
196 std::lock_guard lock(lookup_lock);
197 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
198 StripLookup *lookup = ed->runtime->strip_lookup;
199 VectorSet<Strip *> &strips = lookup->strips_by_compositor_node_group.lookup_or_add_default(key);
200 return strips.as_span();
201}
202
204{
205 BLI_assert(ed != nullptr);
206 std::lock_guard lock(lookup_lock);
207 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
208 StripLookup *lookup = ed->runtime->strip_lookup;
209 return lookup->meta_by_strip.lookup_default(key, nullptr);
210}
211
213{
214 BLI_assert(ed != nullptr);
215 std::lock_guard lock(lookup_lock);
216 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
217 StripLookup *lookup = ed->runtime->strip_lookup;
218 VectorSet<Strip *> &effects = lookup->effects_by_strip.lookup_or_add_default(key);
219 return effects.as_span();
220}
221
223{
224 BLI_assert(ed != nullptr);
225 std::lock_guard lock(lookup_lock);
226 strip_lookup_update_if_needed(ed, &ed->runtime->strip_lookup);
227 StripLookup *lookup = ed->runtime->strip_lookup;
228 return lookup->owner_by_channel.lookup_default(channel, nullptr);
229}
230
232{
233 if (ed == nullptr) {
234 return;
235 }
236
237 std::lock_guard lock(lookup_lock);
238 StripLookup *lookup = ed->runtime->strip_lookup;
239 if (lookup != nullptr) {
240 lookup->is_valid = false;
241 }
242}
243
244} // namespace blender::seq
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
volatile int lock
bool add(const Key &key)
Span< Key > as_span() const
Strip * lookup_meta_by_strip(Editing *ed, const Strip *key)
Map< const Scene *, VectorSet< Strip * > > & lookup_strips_by_scene_map_get(Editing *ed)
Strip * lookup_strip_by_name(Editing *ed, const char *key)
Span< Strip * > lookup_strips_by_scene(Editing *ed, const Scene *key)
static void strip_lookup_rebuild(const Editing *ed, StripLookup **lookup)
static void strip_lookup_build_effect(Strip *strip, StripLookup *lookup)
Span< Strip * > lookup_strips_by_compositor_node_group(Editing *ed, const bNodeTree *key)
Strip * lookup_strip_by_channel_owner(Editing *ed, const SeqTimelineChannel *channel)
Span< Strip * > lookup_effects_by_strip(Editing *ed, const Strip *key)
static void strip_lookup_update_if_needed(const Editing *ed, StripLookup **lookup)
static Mutex lookup_lock
static void strip_by_scene_lookup_build(Strip *strip, StripLookup *lookup)
static void strip_lookup_build(const Editing *ed, StripLookup *lookup)
static void strip_lookup_build_from_seqbase(Strip *parent_meta, const ListBaseT< Strip > *seqbase, StripLookup *lookup)
void strip_lookup_invalidate(const Editing *ed)
static void strip_by_compositor_node_group_lookup_build(Strip *strip, StripLookup *lookup)
void strip_lookup_free(Editing *ed)
static void strip_lookup_append_effect(const Strip *input, Strip *effect, StripLookup *lookup)
static StripLookup * strip_lookup_new()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
std::mutex Mutex
Definition BLI_mutex.hh:51
@ eSeqModifierType_Compositor
eNodeTree_Type type
Map< const bNodeTree *, VectorSet< Strip * > > strips_by_compositor_node_group
Map< const SeqTimelineChannel *, Strip * > owner_by_channel
Map< const Strip *, VectorSet< Strip * > > effects_by_strip
Map< const Strip *, Strip * > meta_by_strip
Map< const Scene *, VectorSet< Strip * > > strips_by_scene
Map< std::string, Strip * > strip_by_name