Blender V5.3
tree_display_sequencer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
12#include "BLI_utildefines.hh"
13
14#include "DNA_sequence_types.h"
15#include "DNA_space_types.h"
16#include "DNA_workspace_types.h"
17
18#include "SEQ_sequencer.hh"
19
20#include "../outliner_intern.hh"
21#include "tree_display.hh"
22#include "tree_element_seq.hh"
23
24namespace blender::ed::outliner {
25
26template<typename T> using List = ListBaseWrapper<T>;
27
32
33ListBaseT<TreeElement> TreeDisplaySequencer::build_tree(const TreeSourceData &source_data)
34{
35 ListBaseT<TreeElement> tree = {nullptr};
36 Scene *sequencer_scene = source_data.workspace->sequencer_scene;
37 if (!sequencer_scene) {
38 return tree;
39 }
40
41 Editing *ed = seq::editing_get(sequencer_scene);
42 if (ed == nullptr) {
43 return tree;
44 }
45
46 for (Strip *strip : List<Strip>(ed->current_strips())) {
47 StripAddOp op = need_add_strip_dup(strip);
48 if (op == StripAddOp::None) {
49 add_element<TreeElementStrip>({.lb = &tree}, *strip);
50 }
51 else if (op == StripAddOp::Add) {
52 TreeElement *te = add_element<TreeElementStripDuplicate>({.lb = &tree}, *strip);
53 add_strip_dup(strip, te, 0);
54 }
55 }
56
57 return tree;
58}
59
60StripAddOp TreeDisplaySequencer::need_add_strip_dup(Strip *strip) const
61{
62 if ((!strip->data) || (!strip->data->stripdata)) {
63 return StripAddOp::None;
64 }
65
66 /*
67 * First check backward, if we found a duplicate
68 * sequence before this, don't need it, just return.
69 */
70 Strip *p = strip->prev;
71 while (p) {
72 if ((!p->data) || (!p->data->stripdata)) {
73 p = p->prev;
74 continue;
75 }
76
77 if (STREQ(p->data->stripdata->filename, strip->data->stripdata->filename)) {
78 return StripAddOp::Noop;
79 }
80 p = p->prev;
81 }
82
83 p = strip->next;
84 while (p) {
85 if ((!p->data) || (!p->data->stripdata)) {
86 p = p->next;
87 continue;
88 }
89
90 if (STREQ(p->data->stripdata->filename, strip->data->stripdata->filename)) {
91 return StripAddOp::Add;
92 }
93 p = p->next;
94 }
95
96 return StripAddOp::None;
97}
98
99void TreeDisplaySequencer::add_strip_dup(Strip *strip, TreeElement *te, short index)
100{
101 Strip *p = strip;
102 while (p) {
103 if ((!p->data) || (!p->data->stripdata) || (p->data->stripdata->filename[0] == '\0')) {
104 p = p->next;
105 continue;
106 }
107
108 if (STREQ(p->data->stripdata->filename, strip->data->stripdata->filename)) {
109 add_element<TreeElementStrip>({.parent = te, .index = index}, *p);
110 }
111 p = p->next;
112 }
113}
114
115} // namespace blender::ed::outliner
#define STREQ(a, b)
const T & data(const Action &owning_action) const
AbstractTreeDisplay(SpaceOutliner &space_outliner)
TreeElement * add_element(const TreeElementAddParams &params, Args &&...args)
ListBaseT< TreeElement > build_tree(const TreeSourceData &source_data) override
TreeDisplaySequencer(SpaceOutliner &space_outliner)
#define index(i)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
ListBaseWrapperTemplate< ListBase, T > ListBaseWrapper
struct Scene * sequencer_scene
The data to build the tree from.
Establish and manage Outliner trees for different display modes.