Blender V5.3
iterator.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 * SPDX-FileCopyrightText: 2003-2024 Blender Authors
3 * SPDX-FileCopyrightText: 2005-2006 Peter Schlaile <peter [at] schlaile [dot] de>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later */
6
10
11#include <cstring>
12
13#include "DNA_sequence_types.h"
14
15#include "BLI_listbase.hh"
16
17#include "SEQ_connect.hh"
18#include "SEQ_iterator.hh"
19#include "SEQ_relations.hh"
20#include "SEQ_render.hh"
21#include "SEQ_sequencer.hh"
22
23namespace blender::seq {
24
25static bool strip_for_each_recursive(ListBaseT<Strip> *seqbase,
26 ForEachFunc callback,
27 void *user_data)
28{
29 for (Strip &strip : *seqbase) {
30 if (!callback(&strip, user_data)) {
31 /* Callback signaled stop, return. */
32 return false;
33 }
34 if (strip.type == STRIP_TYPE_META) {
35 if (!strip_for_each_recursive(&strip.seqbase, callback, user_data)) {
36 return false;
37 }
38 }
39 }
40 return true;
41}
42
43static bool strip_for_each_recursive(ListBaseT<Strip> *seqbase,
44 FunctionRef<bool(Strip *)> callback)
45{
46 for (Strip &strip : *seqbase) {
47 if (!callback(&strip)) {
48 /* Callback signaled stop, return. */
49 return false;
50 }
51 if (strip.type == STRIP_TYPE_META) {
52 if (!strip_for_each_recursive(&strip.seqbase, callback)) {
53 return false;
54 }
55 }
56 }
57 return true;
58}
59
60void foreach_strip(ListBaseT<Strip> *seqbase, ForEachFunc callback, void *user_data)
61{
62 strip_for_each_recursive(seqbase, callback, user_data);
63}
64
65void foreach_strip(ListBaseT<Strip> *seqbase, FunctionRef<bool(Strip *)> callback)
66{
67 strip_for_each_recursive(seqbase, callback);
68}
69
71{
72 BLI_assert(!(flag_is_set(include, StripRelation::Connected) &&
73 flag_is_set(include, StripRelation::SelectedConnected)));
74 /* Process strips through iteration, since some callers expect no reordering of the #VectorSet.
75 * Its keys remain in insertion order as long as none are removed, which we guarantee here.
76 * Since newly found strips are appended, they will all be eventually visited. */
77 for (int64_t i = 0; i < strips.size(); i++) {
78 Strip *strip = strips[i];
79
80 if (flag_is_set(include, StripRelation::Effects)) {
81 for (Strip *effect_strip : lookup_effects_by_strip(ed, strip)) {
82 strips.add(effect_strip);
83 }
84 }
85 if (flag_is_set(include, StripRelation::Inputs) && strip->is_effect()) {
86 if (strip->input1) {
87 strips.add(strip->input1);
88 }
89 if (strip->input2) {
90 strips.add(strip->input2);
91 }
92 }
93 if (flag_is_set(include, StripRelation::MetaContents) && strip->type == STRIP_TYPE_META) {
94 for (Strip &meta_child : strip->seqbase) {
95 strips.add(&meta_child);
96 }
97 }
98 if (flag_is_set(include, StripRelation::Connected)) {
99 for (Strip *connection : connected_strips_get(strip)) {
100 strips.add(connection);
101 }
102 }
103 if (flag_is_set(include, StripRelation::SelectedConnected)) {
104 for (Strip *connection : connected_strips_get(strip)) {
105 if (connection->flag & SEQ_SELECT) {
106 strips.add(connection);
107 }
108 }
109 }
110 }
111}
112
113static void query_all_strips_recursive(const ListBaseT<Strip> *seqbase, VectorSet<Strip *> &strips)
114{
115 for (Strip &strip : *seqbase) {
116 if (strip.type == STRIP_TYPE_META) {
117 query_all_strips_recursive(&strip.seqbase, strips);
118 }
119 strips.add(&strip);
120 }
121}
122
123VectorSet<Strip *> query_all_strips_recursive(const ListBaseT<Strip> *seqbase)
124{
125 VectorSet<Strip *> strips;
126 query_all_strips_recursive(seqbase, strips);
127 return strips;
128}
129
130static void query_strips_recursive_at_frame(const Scene *scene,
131 const ListBaseT<Strip> *seqbase,
132 const int timeline_frame,
133 VectorSet<Strip *> &strips)
134{
135 for (Strip &strip : *seqbase) {
136 if (!strip.intersects_frame(scene, timeline_frame)) {
137 continue;
138 }
139 if (strip.type == STRIP_TYPE_META) {
140 query_strips_recursive_at_frame(scene, &strip.seqbase, timeline_frame, strips);
141 }
142 strips.add(&strip);
143 }
144}
145
147 const ListBaseT<Strip> *seqbase,
148 const int timeline_frame)
149{
150 VectorSet<Strip *> strips;
151 query_strips_recursive_at_frame(scene, seqbase, timeline_frame, strips);
152 return strips;
153}
154
155VectorSet<Strip *> query_all_strips(ListBaseT<Strip> *seqbase)
156{
157 VectorSet<Strip *> strips;
158 for (Strip &strip : *seqbase) {
159 strips.add(&strip);
160 }
161 return strips;
162}
163
165{
166 VectorSet<Strip *> strips;
167 for (Strip &strip : *seqbase) {
168 if ((strip.flag & SEQ_SELECT) != 0) {
169 strips.add(&strip);
170 }
171 }
172 return strips;
173}
174
176 ListBaseT<Strip> *seqbase,
177 const int timeline_frame)
178{
179 VectorSet<Strip *> strips;
180
181 for (Strip &strip : *seqbase) {
182 if (strip.intersects_frame(scene, timeline_frame)) {
183 strips.add(&strip);
184 }
185 }
186 return strips;
187}
188
190 const int channel)
191{
192 strip_stack.remove_if([&](Strip *strip) { return strip->channel > channel; });
193}
194
195bool must_render_strip(const VectorSet<Strip *> &strip_stack, Strip *target_strip)
196{
197 bool strip_have_effect_in_stack = false;
198 for (Strip *strip : strip_stack) {
199 /* Strips below another strip with replace blending are never directly rendered. */
200 if (strip->blend_mode == STRIP_BLEND_REPLACE && target_strip->channel < strip->channel) {
201 return false;
202 }
203 if (strip->is_effect() && relation_is_effect_of_strip(strip, target_strip)) {
204 /* Strips at the same channel or above their effect are rendered. */
205 if (target_strip->channel >= strip->channel) {
206 return true;
207 }
208 /* Mark that this strip has an effect in the stack that is above the strip. */
209 strip_have_effect_in_stack = true;
210 }
211 }
212
213 /* All effects with inputs are rendered assuming they pass the above checks. */
214 if (target_strip->is_effect_with_inputs()) {
215 return true;
216 }
217
218 /* If strip has effects in stack, and all effects are above this strip, it is not rendered. */
219 if (strip_have_effect_in_stack) {
220 return false;
221 }
222
223 return true;
224}
225
226/* Remove strips we don't want to render from VectorSet. */
228 ListBaseT<SeqTimelineChannel> *channels)
229{
230 /* Remove sound strips and muted strips from VectorSet, because these are not rendered.
231 * Function #must_render_strip() don't have to check for these strips anymore. */
232 strip_stack.remove_if([&](Strip *strip) {
233 return strip->type == STRIP_TYPE_SOUND || render_is_muted(channels, strip);
234 });
235
236 strip_stack.remove_if([&](Strip *strip) { return !must_render_strip(strip_stack, strip); });
237}
238
240 ListBaseT<SeqTimelineChannel> *channels,
241 ListBaseT<Strip> *seqbase,
242 const int timeline_frame,
243 const int displayed_channel)
244{
245 VectorSet strips = query_strips_at_frame(scene, seqbase, timeline_frame);
246 if (displayed_channel != 0) {
247 collection_filter_channel_up_to_incl(strips, displayed_channel);
248 }
249 collection_filter_rendered_strips(strips, channels);
250 return strips;
251}
252
254 ListBaseT<SeqTimelineChannel> *channels,
255 ListBaseT<Strip> *seqbase,
256 const int timeline_frame,
257 const int chanshown)
258{
259 VectorSet strips = query_rendered_strips(scene, channels, seqbase, timeline_frame, chanshown);
260
261 Vector<Strip *> strips_vec = strips.extract_vector();
262 /* Sort strips by channel. */
263 std::ranges::sort(strips_vec,
264 [](const Strip *a, const Strip *b) { return a->channel < b->channel; });
265 return strips_vec;
266}
267
269{
270 VectorSet<Strip *> strips;
271 for (Strip &strip : *seqbase) {
272 if ((strip.flag & SEQ_SELECT) != 0) {
273 continue;
274 }
275 strips.add(&strip);
276 }
277 return strips;
278}
279
280} // namespace blender::seq
bool add(const Key &key)
int64_t size() const
int64_t remove_if(Predicate &&predicate)
static void collection_filter_rendered_strips(VectorSet< Strip * > &strip_stack, ListBaseT< SeqTimelineChannel > *channels)
Definition iterator.cc:227
VectorSet< Strip * > query_selected_strips(ListBaseT< Strip > *seqbase)
Definition iterator.cc:164
void foreach_strip(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:60
bool must_render_strip(const VectorSet< Strip * > &strip_stack, Strip *target_strip)
Definition iterator.cc:195
static void query_all_strips_recursive(const ListBaseT< Strip > *seqbase, VectorSet< Strip * > &strips)
Definition iterator.cc:113
bool render_is_muted(const ListBaseT< SeqTimelineChannel > *channels, const Strip *strip)
Definition render.cc:2241
void expand_strips(Editing *ed, VectorSet< Strip * > &strips, const StripRelation include)
Definition iterator.cc:70
VectorSet< Strip * > query_all_strips(ListBaseT< Strip > *seqbase)
Definition iterator.cc:155
static void query_strips_recursive_at_frame(const Scene *scene, const ListBaseT< Strip > *seqbase, const int timeline_frame, VectorSet< Strip * > &strips)
Definition iterator.cc:130
Vector< Strip * > query_rendered_strips_sorted(const Scene *scene, ListBaseT< SeqTimelineChannel > *channels, ListBaseT< Strip > *seqbase, const int timeline_frame, const int chanshown)
Definition iterator.cc:253
static bool strip_for_each_recursive(ListBaseT< Strip > *seqbase, ForEachFunc callback, void *user_data)
Definition iterator.cc:25
Span< Strip * > lookup_effects_by_strip(Editing *ed, const Strip *key)
bool(*)(Strip *strip, void *user_data) ForEachFunc
static VectorSet< Strip * > query_strips_at_frame(const Scene *scene, ListBaseT< Strip > *seqbase, const int timeline_frame)
Definition iterator.cc:175
VectorSet< Strip * > connected_strips_get(const Strip *strip)
bool relation_is_effect_of_strip(const Strip *effect, const Strip *input)
VectorSet< Strip * > query_unselected_strips(ListBaseT< Strip > *seqbase)
Definition iterator.cc:268
static void collection_filter_channel_up_to_incl(VectorSet< Strip * > &strip_stack, const int channel)
Definition iterator.cc:189
VectorSet< Strip * > query_rendered_strips(const Scene *scene, ListBaseT< SeqTimelineChannel > *channels, ListBaseT< Strip > *seqbase, const int timeline_frame, const int displayed_channel)
Definition iterator.cc:239
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90