Blender V5.0
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.h"
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 blender::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{
62 continue;
63 }
64
65 const SequencerCompositorModifierData *modifier_data =
66 reinterpret_cast<SequencerCompositorModifierData *>(modifier);
67 if (!modifier_data->node_group) {
68 continue;
69 }
70
71 VectorSet<Strip *> &strips = lookup->strips_by_compositor_node_group.lookup_or_add_default(
72 modifier_data->node_group);
73 strips.add(strip);
74 }
75}
76
77static void strip_lookup_build_effect(Strip *strip, StripLookup *lookup)
78{
79 if (!strip->is_effect()) {
80 return;
81 }
82
83 strip_lookup_append_effect(strip->input1, strip, lookup);
84 strip_lookup_append_effect(strip->input2, strip, lookup);
85}
86
87static void strip_lookup_build_from_seqbase(Strip *parent_meta,
88 const ListBase *seqbase,
89 StripLookup *lookup)
90{
91 if (parent_meta != nullptr) {
92 LISTBASE_FOREACH (SeqTimelineChannel *, channel, &parent_meta->channels) {
93 lookup->owner_by_channel.add(channel, parent_meta);
94 }
95 }
96
97 LISTBASE_FOREACH (Strip *, strip, seqbase) {
98 lookup->strip_by_name.add(strip->name + 2, strip);
99 lookup->meta_by_strip.add(strip, parent_meta);
100 strip_lookup_build_effect(strip, lookup);
101 strip_by_scene_lookup_build(strip, lookup);
103
104 if (strip->type == STRIP_TYPE_META) {
105 strip_lookup_build_from_seqbase(strip, &strip->seqbase, lookup);
106 }
107 }
108}
109
110static void strip_lookup_build(const Editing *ed, StripLookup *lookup)
111{
112 strip_lookup_build_from_seqbase(nullptr, &ed->seqbase, lookup);
113 lookup->is_valid = true;
114}
115
117{
118 StripLookup *lookup = MEM_new<StripLookup>(__func__);
119 return lookup;
120}
121
122static void strip_lookup_free(StripLookup **lookup)
123{
124 MEM_delete(*lookup);
125 *lookup = nullptr;
126}
127
128static void strip_lookup_rebuild(const Editing *ed, StripLookup **lookup)
129{
130 strip_lookup_free(lookup);
131 *lookup = strip_lookup_new();
132 strip_lookup_build(ed, *lookup);
133}
134
136{
137 if (!ed) {
138 return;
139 }
140 if (*lookup && (*lookup)->is_valid) {
141 return;
142 }
143
144 strip_lookup_rebuild(ed, lookup);
145}
146
148{
149 BLI_assert(ed != nullptr);
150 std::lock_guard lock(lookup_lock);
151 strip_lookup_free(&ed->runtime.strip_lookup);
152}
153
155{
156 BLI_assert(ed != nullptr);
157 std::lock_guard lock(lookup_lock);
158 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
159 StripLookup *lookup = ed->runtime.strip_lookup;
160 return lookup->strip_by_name.lookup_default(key, nullptr);
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 VectorSet<Strip *> &strips = lookup->strips_by_scene.lookup_or_add_default(key);
170 return strips.as_span();
171}
172
174{
175 BLI_assert(ed != nullptr);
176 std::lock_guard lock(lookup_lock);
177 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
178 StripLookup *lookup = ed->runtime.strip_lookup;
179 return lookup->strips_by_scene;
180}
181
183{
184 BLI_assert(ed != nullptr);
186
187 std::lock_guard lock(lookup_lock);
188 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
189 StripLookup *lookup = ed->runtime.strip_lookup;
190 VectorSet<Strip *> &strips = lookup->strips_by_compositor_node_group.lookup_or_add_default(key);
191 return strips.as_span();
192}
193
195{
196 BLI_assert(ed != nullptr);
197 std::lock_guard lock(lookup_lock);
198 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
199 StripLookup *lookup = ed->runtime.strip_lookup;
200 return lookup->meta_by_strip.lookup_default(key, nullptr);
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 blender::VectorSet<Strip *> &effects = lookup->effects_by_strip.lookup_or_add_default(key);
210 return effects.as_span();
211}
212
214{
215 BLI_assert(ed != nullptr);
216 std::lock_guard lock(lookup_lock);
217 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
218 StripLookup *lookup = ed->runtime.strip_lookup;
219 return lookup->owner_by_channel.lookup_default(channel, nullptr);
220}
221
223{
224 if (ed == nullptr) {
225 return;
226 }
227
228 std::lock_guard lock(lookup_lock);
229 StripLookup *lookup = ed->runtime.strip_lookup;
230 if (lookup != nullptr) {
231 lookup->is_valid = false;
232 }
233}
234
235} // namespace blender::seq
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
These structs are the foundation for all linked lists in the library system.
@ NTREE_COMPOSIT
@ eSeqModifierType_Compositor
@ STRIP_TYPE_META
Read Guarded memory(de)allocation.
volatile int lock
bool add(const Key &key)
Span< Key > as_span() const
#define input
Strip * lookup_meta_by_strip(Editing *ed, const Strip *key)
blender::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)
blender::Span< Strip * > SEQ_lookup_effects_by_strip(Editing *ed, const Strip *key)
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)
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_free(StripLookup **lookup)
static void strip_lookup_build_from_seqbase(Strip *parent_meta, const ListBase *seqbase, StripLookup *lookup)
static void strip_lookup_build(const Editing *ed, StripLookup *lookup)
void strip_lookup_invalidate(const Editing *ed)
static void strip_by_compositor_node_group_lookup_build(Strip *strip, StripLookup *lookup)
static void strip_lookup_append_effect(const Strip *input, Strip *effect, StripLookup *lookup)
static StripLookup * strip_lookup_new()
std::mutex Mutex
Definition BLI_mutex.hh:47
struct Strip * input1
struct Scene * scene
ListBase modifiers
struct Strip * input2
ListBase channels
blender::Map< const bNodeTree *, VectorSet< Strip * > > strips_by_compositor_node_group
blender::Map< const Scene *, VectorSet< Strip * > > strips_by_scene
blender::Map< const SeqTimelineChannel *, Strip * > owner_by_channel
blender::Map< const Strip *, blender::VectorSet< Strip * > > effects_by_strip
blender::Map< const Strip *, Strip * > meta_by_strip
blender::Map< std::string, Strip * > strip_by_name