Blender V4.5
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_scene_types.h"
14#include "DNA_sequence_types.h"
15
16#include "BLI_listbase.h"
17#include "BLI_map.hh"
18#include "BLI_mutex.hh"
19#include "BLI_vector_set.hh"
20
21#include <cstring>
22
23#include "MEM_guardedalloc.h"
24
25namespace blender::seq {
26
28
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
58static void strip_lookup_build_effect(Strip *strip, StripLookup *lookup)
59{
60 if ((strip->type & STRIP_TYPE_EFFECT) == 0) {
61 return;
62 }
63
64 strip_lookup_append_effect(strip->input1, strip, lookup);
65 strip_lookup_append_effect(strip->input2, strip, lookup);
66}
67
68static void strip_lookup_build_from_seqbase(Strip *parent_meta,
69 const ListBase *seqbase,
70 StripLookup *lookup)
71{
72 if (parent_meta != nullptr) {
73 LISTBASE_FOREACH (SeqTimelineChannel *, channel, &parent_meta->channels) {
74 lookup->owner_by_channel.add(channel, parent_meta);
75 }
76 }
77
78 LISTBASE_FOREACH (Strip *, strip, seqbase) {
79 lookup->strip_by_name.add(strip->name + 2, strip);
80 lookup->meta_by_strip.add(strip, parent_meta);
81 strip_lookup_build_effect(strip, lookup);
82 strip_by_scene_lookup_build(strip, lookup);
83
84 if (strip->type == STRIP_TYPE_META) {
85 strip_lookup_build_from_seqbase(strip, &strip->seqbase, lookup);
86 }
87 }
88}
89
90static void strip_lookup_build(const Editing *ed, StripLookup *lookup)
91{
92 strip_lookup_build_from_seqbase(nullptr, &ed->seqbase, lookup);
93 lookup->is_valid = true;
94}
95
97{
98 StripLookup *lookup = MEM_new<StripLookup>(__func__);
99 return lookup;
100}
101
102static void strip_lookup_free(StripLookup **lookup)
103{
104 MEM_delete(*lookup);
105 *lookup = nullptr;
106}
107
108static void strip_lookup_rebuild(const Editing *ed, StripLookup **lookup)
109{
110 strip_lookup_free(lookup);
111 *lookup = strip_lookup_new();
112 strip_lookup_build(ed, *lookup);
113}
114
116{
117 if (!ed) {
118 return;
119 }
120 if (*lookup && (*lookup)->is_valid) {
121 return;
122 }
123
124 strip_lookup_rebuild(ed, lookup);
125}
126
128{
129 BLI_assert(ed != nullptr);
130 std::lock_guard lock(lookup_lock);
131 strip_lookup_free(&ed->runtime.strip_lookup);
132}
133
135{
136 BLI_assert(ed != nullptr);
137 std::lock_guard lock(lookup_lock);
138 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
139 StripLookup *lookup = ed->runtime.strip_lookup;
140 return lookup->strip_by_name.lookup_default(key, nullptr);
141}
142
144{
145 BLI_assert(ed != nullptr);
146 std::lock_guard lock(lookup_lock);
147 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
148 StripLookup *lookup = ed->runtime.strip_lookup;
149 VectorSet<Strip *> &strips = lookup->strips_by_scene.lookup_or_add_default(key);
150 return strips.as_span();
151}
152
154{
155 BLI_assert(ed != nullptr);
156 std::lock_guard lock(lookup_lock);
157 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
158 StripLookup *lookup = ed->runtime.strip_lookup;
159 return lookup->meta_by_strip.lookup_default(key, nullptr);
160}
161
163{
164 BLI_assert(ed != nullptr);
165 std::lock_guard lock(lookup_lock);
166 strip_lookup_update_if_needed(ed, &ed->runtime.strip_lookup);
167 StripLookup *lookup = ed->runtime.strip_lookup;
168 blender::VectorSet<Strip *> &effects = lookup->effects_by_strip.lookup_or_add_default(key);
169 return effects.as_span();
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 return lookup->owner_by_channel.lookup_default(channel, nullptr);
179}
180
182{
183 if (ed == nullptr) {
184 return;
185 }
186
187 std::lock_guard lock(lookup_lock);
188 StripLookup *lookup = ed->runtime.strip_lookup;
189 if (lookup != nullptr) {
190 lookup->is_valid = false;
191 }
192}
193
194} // 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.
@ STRIP_TYPE_EFFECT
@ 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)
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)
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_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
struct Strip * input2
ListBase channels
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