Blender V4.3
strip_connect.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_blenlib.h"
10
11#include "DNA_sequence_types.h"
12
13#include "SEQ_connect.hh"
14#include "SEQ_time.hh"
15
17{
18 if (seq == nullptr) {
19 return;
20 }
21 ListBase *connections = &seq->connections;
22 LISTBASE_FOREACH_MUTABLE (SeqConnection *, con, connections) {
23 MEM_delete(con);
24 }
25 BLI_listbase_clear(connections);
26}
27
28void SEQ_connections_duplicate(ListBase *connections_dst, ListBase *connections_src)
29{
30 LISTBASE_FOREACH (SeqConnection *, con, connections_src) {
31 SeqConnection *con_duplicate = MEM_cnew<SeqConnection>(__func__, *con);
32 BLI_addtail(connections_dst, con_duplicate);
33 }
34}
35
37{
38 if (seq == nullptr || BLI_listbase_is_empty(&seq->connections)) {
39 return false;
40 }
41 /* Remove `SeqConnections` from other strips' `connections` list that point to `seq`. */
42 LISTBASE_FOREACH (SeqConnection *, con_seq, &seq->connections) {
43 Sequence *other = con_seq->seq_ref;
44 LISTBASE_FOREACH_MUTABLE (SeqConnection *, con_other, &other->connections) {
45 if (con_other->seq_ref == seq) {
46 BLI_remlink(&other->connections, con_other);
47 MEM_delete(con_other);
48 }
49 }
50 }
51 /* Now clear `connections` for `seq` itself.*/
53
54 return true;
55}
56
58{
59 bool changed = false;
60 for (Sequence *seq : seq_list) {
61 changed |= SEQ_disconnect(seq);
62 }
63
64 return changed;
65}
66
68{
69 if (seq == nullptr) {
70 return;
71 }
73 Sequence *other = con_seq->seq_ref;
74 bool is_one_way = true;
75 LISTBASE_FOREACH (SeqConnection *, con_other, &other->connections) {
76 if (con_other->seq_ref == seq) {
77 /* The `other` sequence has a bidirectional connection with `seq`. */
78 is_one_way = false;
79 break;
80 }
81 }
82 if (is_one_way) {
83 BLI_remlink(&seq->connections, con_seq);
84 MEM_delete(con_seq);
85 }
86 }
87}
88
89void SEQ_connect(Sequence *seq1, Sequence *seq2)
90{
91 if (seq1 == nullptr || seq2 == nullptr) {
92 return;
93 }
95 seq_list.add(seq1);
96 seq_list.add(seq2);
97
98 SEQ_connect(seq_list);
99}
100
102{
103 seq_list.remove_if([&](Sequence *seq) { return seq == nullptr; });
104
105 for (Sequence *seq1 : seq_list) {
106 SEQ_disconnect(seq1);
107 for (Sequence *seq2 : seq_list) {
108 if (seq1 == seq2) {
109 continue;
110 }
111 SeqConnection *con = MEM_cnew<SeqConnection>("seqconnection");
112 con->seq_ref = seq2;
113 BLI_addtail(&seq1->connections, con);
114 }
115 }
116}
117
119{
121 if (seq != nullptr) {
123 connections.add(con->seq_ref);
124 }
125 }
126 return connections;
127}
128
130{
131 if (seq == nullptr) {
132 return false;
133 }
134 return !BLI_listbase_is_empty(&seq->connections);
135}
136
138{
139 const int expected_connection_num = seq_list.size() - 1;
140 for (Sequence *seq1 : seq_list) {
142 int found_connection_num = connections.size();
143 if (found_connection_num != expected_connection_num) {
144 return false;
145 }
146 for (Sequence *seq2 : connections) {
147 if (!seq_list.contains(seq2)) {
148 return false;
149 }
150 }
151 }
152 return true;
153}
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
bool add(const Key &key)
int64_t size() const
bool contains(const Key &key) const
int64_t remove_if(Predicate &&predicate)
void SEQ_connections_duplicate(ListBase *connections_dst, ListBase *connections_src)
bool SEQ_disconnect(Sequence *seq)
void SEQ_connect(Sequence *seq1, Sequence *seq2)
static void seq_connections_free(Sequence *seq)
bool SEQ_is_strip_connected(const Sequence *seq)
void SEQ_cut_one_way_connections(Sequence *seq)
blender::VectorSet< Sequence * > SEQ_get_connected_strips(const Sequence *seq)
bool SEQ_are_strips_connected_together(blender::VectorSet< Sequence * > &seq_list)
ListBase connections