Blender V5.3
transform_convert_sequencer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_screen_types.h"
10#include "DNA_sequence_types.h"
11#include "DNA_space_types.h"
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_listbase.hh"
16#include "BLI_math_matrix_c.hh"
17#include "BLI_math_vector_c.hh"
18
19#include "BKE_context.hh"
20
21#include "RNA_access.hh"
22
23#include "ED_markers.hh"
24#include "ED_sequencer.hh"
25
26#include "SEQ_animation.hh"
27#include "SEQ_channels.hh"
28#include "SEQ_edit.hh"
29#include "SEQ_iterator.hh"
30#include "SEQ_relations.hh"
31#include "SEQ_sequencer.hh"
32#include "SEQ_transform.hh"
33
34#include "UI_view2d.hh"
35
36#include "transform.hh"
37#include "transform_convert.hh"
38#include "transform_mode.hh"
39
40namespace blender::ed::transform {
41
42#define STRIP_EDGE_PAN_INSIDE_PAD 3.5f
43#define STRIP_EDGE_PAN_OUTSIDE_PAD 0.0f /* Disable clamping for panning, use whole screen. */
44#define STRIP_EDGE_PAN_SPEED_RAMP 1.0f
45#define STRIP_EDGE_PAN_MAX_SPEED 26.0f /* In UI units per second, slower than default. */
46#define STRIP_EDGE_PAN_DELAY 0.5f
47#define STRIP_EDGE_PAN_ZOOM_INFLUENCE 0.0f
48
49namespace {
50
52struct TransDataSeq {
53 Strip *strip;
55 int flag;
58 int start_offset;
60 short sel_flag;
61};
62
63} // namespace
64
65/* -------------------------------------------------------------------- */
68
69/* This function applies the rules for transforming a strip so duplicate
70 * checks don't need to be added in multiple places.
71 *
72 * count and flag MUST be set.
73 */
74static void SeqTransInfo(TransInfo *t, Strip *strip, int *r_count, int *r_flag)
75{
77 Editing *ed = seq::editing_get(scene);
78 const ListBaseT<SeqTimelineChannel> *channels = seq::channels_displayed_get(ed);
79
80 /* For extend we need to do some tricks. */
81 if (t->mode == TFM_TIME_EXTEND) {
82
83 /* *** Extend Transform *** */
84 int cfra = scene->r.cfra;
85 int left = strip->left_handle();
86 int right = strip->right_handle(scene);
87
88 if ((strip->flag & SEQ_SELECT) == 0 || seq::transform_is_locked(channels, strip)) {
89 *r_count = 0;
90 *r_flag = 0;
91 }
92 else {
93 *r_count = 1; /* Unless its set to 0, extend will never set 2 handles at once. */
94 *r_flag = (strip->flag | SEQ_SELECT) & ~(SEQ_LEFTSEL | SEQ_RIGHTSEL);
95
96 if (t->frame_side == 'R') {
97 if (right <= cfra) {
98 *r_count = *r_flag = 0;
99 } /* Ignore. */
100 else if (left > cfra) {
101 } /* Keep the selection. */
102 else {
103 *r_flag |= SEQ_RIGHTSEL;
104 }
105 }
106 else {
107 if (left >= cfra) {
108 *r_count = *r_flag = 0;
109 } /* Ignore. */
110 else if (right < cfra) {
111 } /* Keep the selection. */
112 else {
113 *r_flag |= SEQ_LEFTSEL;
114 }
115 }
116 }
117 }
118 else {
119
120 t->frame_side = 'B';
121
122 /* *** Normal Transform *** */
123
124 /* Count. */
125
126 /* Non nested strips (reset selection and handles). */
127 if ((strip->flag & SEQ_SELECT) == 0 || seq::transform_is_locked(channels, strip)) {
128 *r_count = 0;
129 *r_flag = 0;
130 }
131 else {
132 if ((strip->flag & (SEQ_LEFTSEL | SEQ_RIGHTSEL)) == (SEQ_LEFTSEL | SEQ_RIGHTSEL)) {
133 *r_flag = strip->flag;
134 *r_count = 2; /* We need 2 transdata's. */
135 }
136 else {
137 *r_flag = strip->flag;
138 *r_count = 1; /* Selected or with a handle selected. */
139 }
140 }
141 }
142}
143
144static int SeqTransCount(TransInfo *t, ListBaseT<Strip> *seqbase)
145{
146 int tot = 0, count, flag;
147
148 for (Strip &strip : *seqbase) {
149 SeqTransInfo(t, &strip, &count, &flag); /* Ignore the flag. */
150 tot += count;
151 }
152
153 return tot;
154}
155
157 TransData *td,
158 TransData2D *td2d,
159 TransDataSeq *tdsq,
160 Strip *strip,
161 int flag,
162 int sel_flag)
163{
164 int start_left;
165
166 switch (sel_flag) {
167 case SEQ_SELECT:
168 /* Use seq_tx_get_final_left() and an offset here
169 * so transform has the left hand location of the strip.
170 * `tdsq->start_offset` is used when flushing the tx data back. */
171 start_left = strip->left_handle();
172 td2d->loc[0] = start_left;
173 tdsq->start_offset = start_left - strip->start; /* Use to apply the original location. */
174 break;
175 case SEQ_LEFTSEL:
176 start_left = strip->left_handle();
177 td2d->loc[0] = start_left;
178 break;
179 case SEQ_RIGHTSEL:
180 td2d->loc[0] = strip->right_handle(scene);
181 break;
182 }
183
184 td2d->loc[1] = strip->channel; /* Channel - Y location. */
185 td2d->loc[2] = 0.0f;
186 td2d->loc2d = nullptr;
187
188 tdsq->strip = strip;
189
190 /* Use instead of strip->flag for nested strips and other
191 * cases where the selection may need to be modified. */
192 tdsq->flag = flag;
193 tdsq->sel_flag = sel_flag;
194
195 td->extra = static_cast<void *>(tdsq); /* Allow us to update the strip from here. */
196
197 td->flag = 0;
198 td->loc = td2d->loc;
199 copy_v3_v3(td->center, td->loc);
200 copy_v3_v3(td->iloc, td->loc);
201
202 memset(td->axismtx, 0, sizeof(td->axismtx));
203 td->axismtx[2][2] = 1.0f;
204
205 td->val = nullptr;
206
207 td->flag |= TD_SELECTED;
208 td->dist = 0.0;
209
210 unit_m3(td->mtx);
211 unit_m3(td->smtx);
212
213 /* Time Transform (extend). */
214 td->val = td2d->loc;
215 td->ival = td2d->loc[0];
216
217 return td;
218}
219
221 TransInfo *t, ListBaseT<Strip> *seqbase, TransData *td, TransData2D *td2d, TransDataSeq *tdsq)
222{
224 int count, flag;
225 int tot = 0;
226
227 for (Strip &strip : *seqbase) {
228
229 SeqTransInfo(t, &strip, &count, &flag);
230
231 /* Use 'flag' which is derived from strip->flag but modified for special cases. */
232 if (flag & SEQ_SELECT) {
233 if (flag & (SEQ_LEFTSEL | SEQ_RIGHTSEL)) {
234 if (flag & SEQ_LEFTSEL) {
235 SeqToTransData(scene, td++, td2d++, tdsq++, &strip, flag, SEQ_LEFTSEL);
236 tot++;
237 }
238 if (flag & SEQ_RIGHTSEL) {
239 SeqToTransData(scene, td++, td2d++, tdsq++, &strip, flag, SEQ_RIGHTSEL);
240 tot++;
241 }
242 }
243 else {
244 SeqToTransData(scene, td++, td2d++, tdsq++, &strip, flag, SEQ_SELECT);
245 tot++;
246 }
247 }
248 }
249 return tot;
250}
251
253{
254 if ((custom_data->data != nullptr) && custom_data->use_free) {
255 TransSeq *ts = static_cast<TransSeq *>(custom_data->data);
256 MEM_delete(static_cast<TransDataSeq *>(ts->tdseq));
257 MEM_delete(ts);
258 custom_data->data = nullptr;
259 }
260}
261
262/* Canceled, need to update the strips display. */
263static void seq_transform_cancel(TransInfo *t, Span<Strip *> transformed_strips)
264{
266 ListBaseT<Strip> *seqbase = seq::active_seqbase_get(seq::editing_get(scene));
267
268 if (t->remove_on_cancel) {
269 for (Strip *strip : transformed_strips) {
270 seq::edit_flag_for_removal(scene, strip);
271 }
272 seq::edit_remove_flagged_strips(scene, seqbase);
274 return;
275 }
276
278
279 for (Strip *strip : transformed_strips) {
280 /* Handle pre-existing overlapping strips even when operator is canceled.
281 * This is necessary for #SEQUENCER_OT_duplicate_move macro for example. */
282 seq::transform_shuffle_vertical(seqbase, {strip}, scene);
283 }
284}
285
286static ListBaseT<Strip> *seqbase_active_get(const TransInfo *t)
287{
289 Editing *ed = seq::editing_get(scene);
291}
292
294{
295 for (Strip *strip : transformed_strips) {
296 if (flag_is_set(strip->runtime->flag, seq::StripRuntimeFlag::Overlap)) {
297 return true;
298 }
299 }
300 return false;
301}
302
304{
305 VectorSet<Strip *> strips;
306 TransData *td = tc->data;
307 for (int a = 0; a < tc->data_len; a++, td++) {
308 Strip *strip = (static_cast<TransDataSeq *>(td->extra))->strip;
309 strips.add(strip);
310 }
311 return strips;
312}
313
314static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data)
315{
317 Editing *ed = seq::editing_get(scene);
318 TransSeq *ts = static_cast<TransSeq *>(tc->custom.type.data);
319 if (ed == nullptr) {
320 free_transform_custom_data(custom_data);
321 return;
322 }
323
324 ed->edit_point_set(scene, std::nullopt);
325
326 VectorSet transformed_strips = seq_transform_collection_from_transdata(tc);
328
329 for (Strip *strip : transformed_strips) {
331 strip->runtime->flag &= ~seq::StripRuntimeFlag::IgnoreChannelLock;
332 }
333
334 if (t->state == TRANS_CANCEL) {
336 seq_transform_cancel(t, transformed_strips);
337 free_transform_custom_data(custom_data);
338 return;
339 }
340
342 free_transform_custom_data(custom_data);
343}
344
346{
347 VectorSet<Strip *> strips;
348 for (Strip &strip : *seqbase) {
349 if ((strip.flag & SEQ_SELECT) != 0 && ((strip.flag & (SEQ_LEFTSEL | SEQ_RIGHTSEL)) == 0)) {
350 strips.add(&strip);
351 }
352 }
353 return strips;
354}
355
360
362{
363 Strip *input = effect->input1;
364 if (effect->input2 && (effect->input2->left_handle() - effect->input1->left_handle()) * side > 0)
365 {
366 input = effect->input2;
367 }
368 return input;
369}
370
372{
373 Strip *input = effect, *strip_iter = effect;
374 while (strip_iter != nullptr) {
375 input = strip_iter;
376 strip_iter = effect_input_get(strip_iter, side);
377 }
378 return input;
379}
380
386 VectorSet<Strip *> &time_dependent_strips)
387{
389 Editing *ed = seq::editing_get(scene);
390 ListBaseT<Strip> *seqbase = seqbase_active_get(t);
391
392 /* Query dependent strips where used strips do not have handles selected.
393 * If all inputs of any effect even indirectly(through another effect) points to selected strip,
394 * its position will change. */
395
396 VectorSet<Strip *> strips_no_handles = query_selected_strips_no_handles(seqbase);
397 time_dependent_strips.add_multiple(strips_no_handles);
398
400 bool strip_added = true;
401
402 while (strip_added) {
403 strip_added = false;
404
405 for (Strip *strip : strips_no_handles) {
406 if (time_dependent_strips.contains(strip)) {
407 continue; /* Strip is already in collection, skip it. */
408 }
409
410 /* If both input1 and input2 exist, both must be selected. */
411 if (strip->input1 && time_dependent_strips.contains(strip->input1)) {
412 if (strip->input2 && !time_dependent_strips.contains(strip->input2)) {
413 continue;
414 }
415 strip_added = true;
416 time_dependent_strips.add(strip);
417 }
418 }
419 }
420
421 /* Query dependent strips where used strips do have handles selected.
422 * If any 2-input effect changes position because handles were moved, animation should be offset.
423 * With single input effect, it is less likely desirable to move animation. */
424
425 VectorSet selected_strips = seq::query_selected_strips(seqbase);
427 for (Strip *strip : selected_strips) {
428 /* Check only 2 input effects. */
429 if (strip->input1 == nullptr || strip->input2 == nullptr) {
430 continue;
431 }
432
433 /* Find immediate base inputs(left and right side). */
434 Strip *input_left = effect_base_input_get(strip, SEQ_INPUT_LEFT);
435 Strip *input_right = effect_base_input_get(strip, SEQ_INPUT_RIGHT);
436
437 if ((input_left->flag & SEQ_RIGHTSEL) != 0 && (input_right->flag & SEQ_LEFTSEL) != 0) {
438 time_dependent_strips.add(strip);
439 }
440 }
441
442 /* Remove all non-effects. */
443 time_dependent_strips.remove_if(
444 [&](Strip *strip) { return seq::transform_strip_can_be_translated(strip); });
445}
446
447static void create_trans_seq_clamp_data(TransInfo *t, const Scene *scene)
448{
449 TransSeq *ts = static_cast<TransSeq *>(TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data);
450 const Editing *ed = seq::editing_get(scene);
451
452 bool only_handles_selected = true;
453
454 /* Prevent snaps and change in `values` past `offset_clamp` for all selected strips. */
456
458 for (Strip *strip : strips) {
459 if (!strip->is_effect_with_inputs()) {
460 continue;
461 }
462 /* If there is an effect strip without its inputs selected, prevent any x-direction movement,
463 * since these strips are tied to their inputs and can only move up and down. */
464 if (!(strip->input1->flag & SEQ_SELECT) &&
465 (!strip->input2 || !(strip->input2->flag & SEQ_SELECT)))
466 {
467 ts->offset_clamp.xmin = 0;
468 ts->offset_clamp.xmax = 0;
469 }
470 }
471
472 const bool clamp_default = (U.sequencer_editor_flag & USER_SEQ_ED_CLAMP_STRIPS_BY_DEFAULT);
473 if (clamp_default) {
475 }
476
477 ts->hold_clamp_min = INT_MIN;
479 for (Strip *strip : strips) {
481 continue;
482 }
483
484 bool left_sel = (strip->flag & SEQ_LEFTSEL);
485 bool right_sel = (strip->flag & SEQ_RIGHTSEL);
486
487 /* If any strips start out with hold offsets visible, disable handle clamping on init. */
488 if (clamp_default && (strip->startofs < 0 || strip->end_offset() < 0) &&
490 {
492 }
493
494 /* If both handles are selected, there must be enough underlying content to clamp holds. */
495 bool can_clamp_holds = !(left_sel && right_sel) ||
496 (strip->content_length() >=
497 strip->right_handle(scene) - strip->left_handle());
498 can_clamp_holds &= !seq::transform_single_image_check(strip);
499
500 /* A handle is selected. Update x-axis clamping data. */
501 if (left_sel || right_sel) {
502 if (left_sel) {
503 /* Ensure that this strip's left handle cannot pass its right handle. */
504 if (!(left_sel && right_sel)) {
505 int offset = (strip->right_handle(scene) - 1) - strip->left_handle();
506 ts->offset_clamp.xmax = min_ii(ts->offset_clamp.xmax, offset);
507 }
508
509 if (can_clamp_holds) {
510 /* Ensure that the left handle's frame is greater than or equal to the content start. */
511 ts->hold_clamp_min = max_ii(ts->hold_clamp_min, -strip->startofs);
512 }
513 }
514 if (right_sel) {
515 if (!(left_sel && right_sel)) {
516 /* Ensure that this strip's right handle cannot pass its left handle. */
517 int offset = (strip->left_handle() + 1) - strip->right_handle(scene);
518 ts->offset_clamp.xmin = max_ii(ts->offset_clamp.xmin, offset);
519 }
520
521 if (can_clamp_holds) {
522 /* Ensure that the right handle's frame is less than or equal to the content end. */
523 ts->hold_clamp_max = min_ii(ts->hold_clamp_max, strip->end_offset());
524 }
525 }
526 }
527 /* No handles are selected. Update y-axis channel clamping data. */
528 else {
529 ts->offset_clamp.ymin = max_ii(ts->offset_clamp.ymin, 1 - strip->channel);
530 ts->offset_clamp.ymax = min_ii(ts->offset_clamp.ymax, seq::MAX_CHANNELS - strip->channel);
531 only_handles_selected = false;
532 }
533 }
534
535 /* TODO(john): This ensures that y-axis movement is restricted only if all of the selected items
536 * are handles, since currently it is possible to select whole strips and handles at the same
537 * time. This should be removed for 5.0 when we make this behavior impossible. */
538 if (only_handles_selected) {
539 ts->offset_clamp.ymin = 0;
540 ts->offset_clamp.ymax = 0;
541 }
542
543 /* If either axis is locked (min/max offset is zero), then movement is only possible along one
544 * axis, and distinguishing them makes no sense, so just disable both axis constraints. */
545 if ((ts->offset_clamp.xmin == 0 && ts->offset_clamp.xmax == 0) ||
546 (ts->offset_clamp.ymin == 0 && ts->offset_clamp.ymax == 0))
547 {
548 t->flag |= T_NO_CONSTRAINT;
549 }
550}
551
553{
555 if (!scene) {
556 return;
557 }
558 Editing *ed = seq::editing_get(scene);
559 TransData *td = nullptr;
560 TransData2D *td2d = nullptr;
561 TransDataSeq *tdsq = nullptr;
562 TransSeq *ts = nullptr;
563
564 int count = 0;
565
567
568 if (ed == nullptr) {
569 tc->data_len = 0;
570 return;
571 }
572
573 /* Disable cursor wrapping for edge pan. */
574 if (t->mode == TFM_TRANSLATION) {
576 }
577
580
581 count = SeqTransCount(t, ed->current_strips());
582
583 /* Allocate memory for data. */
584 tc->data_len = count;
585
586 /* Stop if trying to build list if nothing selected. */
587 if (count == 0) {
588 return;
589 }
590
591 tc->custom.type.data = ts = MEM_new<TransSeq>(__func__);
592 tc->custom.type.use_free = true;
593 td = tc->data = MEM_new_array_zeroed<TransData>(tc->data_len, "TransSeq TransData");
594 td2d = tc->data_2d = MEM_new_array_zeroed<TransData2D>(tc->data_len, "TransSeq TransData2D");
595 ts->tdseq = tdsq = MEM_new_array_zeroed<TransDataSeq>(tc->data_len, "TransSeq TransDataSeq");
596
597 /* Custom data to enable edge panning during transformation. */
598 view2d_edge_pan_init(t->context,
599 &ts->edge_pan,
606 view2d_edge_pan_set_limits(&ts->edge_pan, -FLT_MAX, FLT_MAX, 1, seq::MAX_CHANNELS + 1);
607 ts->initial_v2d_cur = t->region->v2d.cur;
608
609 /* Loop 2: build transdata array. */
610 SeqToTransData_build(t, ed->current_strips(), td, td2d, tdsq);
611
613
615
617}
618
620
621/* -------------------------------------------------------------------- */
624
625static void view2d_edge_pan_loc_compensate(TransInfo *t, float r_offset[2])
626{
627 TransSeq *ts = static_cast<TransSeq *>(TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data);
628
629 const rctf rect_prev = t->region->v2d.cur;
630
631 if (t->options & CTX_VIEW2D_EDGE_PAN) {
632 if (t->state == TRANS_CANCEL) {
633 view2d_edge_pan_cancel(t->context, &ts->edge_pan);
634 }
635 else {
636 /* Edge panning functions expect window coordinates, mval is relative to region. */
637 const int xy[2] = {
638 t->region->winrct.xmin + int(t->mval[0]),
639 t->region->winrct.ymin + int(t->mval[1]),
640 };
641 view2d_edge_pan_apply(t->context, &ts->edge_pan, xy);
642 }
643 }
644
645 if (t->state != TRANS_CANCEL) {
646 if (!BLI_rctf_compare(&rect_prev, &t->region->v2d.cur, FLT_EPSILON)) {
647 /* Additional offset due to change in view2D rect. */
648 BLI_rctf_transform_pt_v(&t->region->v2d.cur, &rect_prev, r_offset, r_offset);
650 }
651 }
652}
653
655{
656 /* Editing null check already done. */
657 ListBaseT<Strip> *seqbasep = seqbase_active_get(t);
659
661 TransData *td = tc->data;
662
663 /* This is calculated for offsetting animation of effects that change position with inputs.
664 * Maximum(positive or negative) value is used, because individual strips can be clamped. This
665 * works fairly well in most scenarios, but there can be some edge cases.
666 *
667 * Better solution would be to store effect position and calculate real offset. However with many
668 * (>5) effects in chain, there is visible lag in strip position update, because during
669 * recalculation, hierarchy is not taken into account. */
670 int max_offset = 0;
671
672 float edge_pan_offset[2] = {0.0f, 0.0f};
673 view2d_edge_pan_loc_compensate(t, edge_pan_offset);
674
675 /* Flush to 2D vector from internally used 3D vector. */
676 for (int a = 0; a < tc->data_len; a++, td++) {
677 TransDataSeq *tdsq = static_cast<TransDataSeq *>(td->extra);
678 Strip *strip = tdsq->strip;
679
680 /* Apply extra offset caused by edge panning. */
681 add_v2_v2(td->loc, edge_pan_offset);
682
683 float offset[2];
684 float offset_clamped[2];
685 sub_v2_v2v2(offset, td->loc, td->iloc);
686 copy_v2_v2(offset_clamped, offset);
687
688 if (t->state != TRANS_CANCEL) {
689 transform_convert_sequencer_clamp(t, offset_clamped);
690 }
691 const int new_frame = round_fl_to_int(td->iloc[0] + offset_clamped[0]);
692 const int new_channel = round_fl_to_int(td->iloc[1] + offset_clamped[1]);
693
694 /* Compute handle clamping state to be drawn. */
695 if (tdsq->sel_flag & SEQ_LEFTSEL) {
696 strip->runtime->flag &= ~seq::StripRuntimeFlag::ClampedLH;
697 }
698 if (tdsq->sel_flag & SEQ_RIGHTSEL) {
699 strip->runtime->flag &= ~seq::StripRuntimeFlag::ClampedRH;
700 }
701 if (!seq::transform_single_image_check(strip) && !strip->is_effect()) {
702 if (offset_clamped[0] > offset[0] && new_frame == strip->content_start()) {
703 strip->runtime->flag |= seq::StripRuntimeFlag::ClampedLH;
704 }
705 else if (offset_clamped[0] < offset[0] && new_frame == strip->content_end(scene)) {
706 strip->runtime->flag |= seq::StripRuntimeFlag::ClampedRH;
707 }
708 }
709
710 switch (tdsq->sel_flag) {
711 case SEQ_SELECT: {
712 int offset = new_frame - tdsq->start_offset - strip->start;
714 seq::transform_translate_strip(scene, strip, offset);
715 if (abs(offset) > abs(max_offset)) {
716 max_offset = offset;
717 }
718 }
719 strip->channel_set(new_channel);
720 break;
721 }
722 case SEQ_LEFTSEL: { /* No vertical transform. */
723 /* Update right handle first if both handles are selected and the `new_frame` is right of
724 * the old one to avoid unexpected left handle clamping when canceling. See #126191. */
725 const bool both_handles_selected = (tdsq->flag & (SEQ_LEFTSEL | SEQ_RIGHTSEL)) ==
727 if (both_handles_selected && new_frame >= strip->right_handle(scene)) {
728 /* For now, move the right handle far enough to avoid the left handle getting clamped.
729 * The final, correct position will be calculated later. */
730 strip->right_handle_set(scene, new_frame + 1);
731 }
732
733 int old_startdisp = strip->left_handle();
734 strip->left_handle_set(scene, new_frame);
735
736 if (abs(strip->left_handle() - old_startdisp) > abs(max_offset)) {
737 max_offset = strip->left_handle() - old_startdisp;
738 }
739 break;
740 }
741 case SEQ_RIGHTSEL: { /* No vertical transform. */
742 int old_enddisp = strip->right_handle(scene);
743 strip->right_handle_set(scene, new_frame);
744
745 if (abs(strip->right_handle(scene) - old_enddisp) > abs(max_offset)) {
746 max_offset = strip->right_handle(scene) - old_enddisp;
747 }
748 break;
749 }
750 }
751 }
752
753 TransSeq *ts = static_cast<TransSeq *>(TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data);
754
755 /* Update animation for effects. */
756 for (Strip *strip : ts->time_dependent_strips) {
757 seq::offset_animdata(scene, strip, max_offset);
758 }
759
760 /* Need to do the overlap check in a new loop otherwise adjacent strips
761 * will not be updated and we'll get false positives. */
762 VectorSet transformed_strips = seq_transform_collection_from_transdata(tc);
764
765 for (Strip *strip : transformed_strips) {
766 /* Test overlap, displays red outline. */
767 strip->runtime->flag &= ~seq::StripRuntimeFlag::Overlap;
768 if (seq::transform_test_overlap(scene, seqbasep, strip)) {
769 strip->runtime->flag |= seq::StripRuntimeFlag::Overlap;
770 }
771 }
772}
773
775{
776 Editing *ed = seq::editing_get(scene);
777 const Strip *strip = ed->act_strip;
778 std::optional<int> edit_point;
779 if (strip != nullptr && (strip->flag & SEQ_SELECT)) {
780 if (strip->flag & SEQ_RIGHTSEL) {
781 edit_point = strip->right_handle(scene) - 1;
782 }
783 else if (strip->flag & SEQ_LEFTSEL) {
784 edit_point = strip->left_handle();
785 }
786 }
787 ed->edit_point_set(scene, edit_point);
788}
789
791{
792 TransData *td;
793 int a;
794 Strip *strip_prev = nullptr;
795
798
799 for (a = 0, td = tc->data; a < tc->data_len; a++, td++) {
800 TransDataSeq *tdsq = static_cast<TransDataSeq *>(td->extra);
801 Strip *strip = tdsq->strip;
802
803 if (strip != strip_prev) {
805 }
806
807 strip_prev = strip;
808 }
809
812
813 flushTransSeq(t);
815}
816
818
819/* -------------------------------------------------------------------- */
822
825 wmOperator *op,
826 const bool use_sync_markers)
827{
828 const TransSeq *ts = static_cast<TransSeq *>(tc->custom.type.data);
829
830 Editing *ed = seq::editing_get(scene);
831 VectorSet transformed_strips = seq_transform_collection_from_transdata(tc);
833 if (!seq_transform_check_overlap(transformed_strips)) {
834 return;
835 }
836
839 /* We need to check that the props exist because "time extend" on `E` press can reach here. */
840 if (op != nullptr && RNA_struct_property_is_set(op->ptr, "overlap_mode")) {
841 overlap_mode = eSeqOverlapMode(RNA_enum_get(op->ptr, "overlap_mode"));
843 ripple_flag, RNA_boolean_get(op->ptr, "all_channels"), SEQ_RIPPLE_ALL_CHANNELS);
844 SET_FLAG_FROM_TEST(ripple_flag, RNA_boolean_get(op->ptr, "markers"), SEQ_RIPPLE_MARKERS);
845 SET_FLAG_FROM_TEST(ripple_flag, RNA_boolean_get(op->ptr, "insert"), SEQ_RIPPLE_INSERT);
846 }
847
850 transformed_strips,
851 use_sync_markers,
852 overlap_mode,
853 ripple_flag,
855}
856
857/* Restore handles to their deselected state. */
859{
861 for (Strip *strip : strips) {
862 strip->flag &= ~(SEQ_LEFTSEL | SEQ_RIGHTSEL);
863 }
864}
865
867{
870 SpaceSeq *sseq = t->area->spacedata.first_as<SpaceSeq>();
871
872 const bool deselect_handles = (sseq->flag & SPACE_SEQ_DESELECT_STRIP_HANDLE) != 0 &&
875
876 /* #freeSeqData in `transform_conversions.cc` does this
877 * keep here so the `else` at the end won't run. */
878 if (t->state == TRANS_CANCEL) {
879 if (deselect_handles) {
881 }
882 return;
883 }
884
885 /* Marker transform, not especially nice but we may want to move markers
886 * at the same time as strips in the Video Sequencer. */
887 if (sseq->flag & SEQ_MARKER_TRANS) {
888 /* Can't use #TFM_TIME_EXTEND
889 * for some reason EXTEND is changed into TRANSLATE, so use frame_side instead. */
890
891 if (t->mode == TFM_SEQ_SLIDE) {
892 if (t->frame_side == 'B') {
894 &scene->markers, scene, TFM_TIME_TRANSLATE, t->values_final[0], t->frame_side);
895 }
896 }
897 else if (ELEM(t->frame_side, 'L', 'R')) {
899 &scene->markers, scene, TFM_TIME_EXTEND, t->values_final[0], t->frame_side);
900 }
901 }
902
904 tc,
906 (sseq->flag & SEQ_MARKER_TRANS) != 0);
907
909
910 if (deselect_handles) {
912 }
913}
914
915bool transform_convert_sequencer_clamp(const TransInfo *t, float r_val[2])
916{
917 if (t->data_container_len == 0) {
918 /* During drag and drop, there is no custom data. We don't need to clamp here anyways,
919 * since we're not adjusting handles, and channels are already clamped in drag/drop code. */
920 return false;
921 }
922
923 const TransSeq *ts = static_cast<TransSeq *>(
924 TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->custom.type.data);
925 int val[2] = {round_fl_to_int(r_val[0]), round_fl_to_int(r_val[1])};
926 bool clamped = false;
927
928 /* Unconditional channel, retiming key, and handle clamping. Should never be ignored. */
929 if (BLI_rcti_clamp_pt_v(&ts->offset_clamp, val)) {
930 r_val[0] = float(val[0]);
931 r_val[1] = float(val[1]);
932 clamped = true;
933 }
934
935 /* Optional clamping of handles to underlying holds. Can be disabled by the user. */
937 if (val[0] < ts->hold_clamp_min) {
938 r_val[0] = float(ts->hold_clamp_min);
939 clamped = true;
940 }
941 else if (val[0] > ts->hold_clamp_max) {
942 r_val[0] = float(ts->hold_clamp_max);
943 clamped = true;
944 }
945 }
946
947 return clamped;
948}
949
951
953 /*flags*/ (T_POINTS | T_2D_EDIT),
954 /*create_trans_data*/ createTransSeqData,
955 /*recalc_data*/ recalcData_sequencer,
956 /*special_aftertrans_update*/ special_aftertrans_update__sequencer,
957};
958
959} // namespace blender::ed::transform
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
bool add(const Key &key)
void add_multiple(Span< Key > keys)
bool contains(const Key &key) const
int64_t remove_if(Predicate &&predicate)
#define FLT_MAX
#define INT_MAX
#define FLT_EPSILON
#define abs
static void free_transform_custom_data(TransCustomData *custom_data)
static ListBaseT< Strip > * seqbase_active_get(const TransInfo *t)
TransConvertTypeInfo TransConvertType_Sequencer
static void query_time_dependent_strips_strips(TransInfo *t, VectorSet< Strip * > &time_dependent_strips)
static void special_aftertrans_update__sequencer(bContext *C, TransInfo *t)
static Strip * effect_base_input_get(Strip *effect, SeqInputSide side)
static void flushTransSeq(TransInfo *t)
char transform_convert_frame_side_dir_get(TransInfo *t, float cframe)
static void view2d_edge_pan_loc_compensate(TransInfo *t, float r_offset[2])
static TransData * SeqToTransData(Scene *scene, TransData *td, TransData2D *td2d, TransDataSeq *tdsq, Strip *strip, int flag, int sel_flag)
static int SeqTransCount(TransInfo *t, ListBaseT< Strip > *seqbase)
static void seq_transform_cancel(TransInfo *t, Span< Strip * > transformed_strips)
bool transform_mode_edge_seq_slide_use_restore_handle_selection(const TransInfo *t)
static VectorSet< Strip * > seq_transform_collection_from_transdata(TransDataContainer *tc)
wmOperator * transform_mode_edge_seq_slide_operator_get(const TransInfo *t)
bool transform_convert_sequencer_clamp(const TransInfo *t, float r_val[2])
static void seq_transform_handle_overlap(Scene *scene, TransDataContainer *tc, wmOperator *op, const bool use_sync_markers)
static void SeqTransInfo(TransInfo *t, Strip *strip, int *r_count, int *r_flag)
static void seq_transform_edit_point_update(Scene *scene)
void transformViewUpdate(TransInfo *t)
static void createTransSeqData(bContext *C, TransInfo *t)
static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data)
static VectorSet< Strip * > query_selected_strips_no_handles(ListBaseT< Strip > *seqbase)
static void recalcData_sequencer(TransInfo *t)
static int SeqToTransData_build(TransInfo *t, ListBaseT< Strip > *seqbase, TransData *td, TransData2D *td2d, TransDataSeq *tdsq)
static void create_trans_seq_clamp_data(TransInfo *t, const Scene *scene)
static void seq_transform_restore_handle_selection(TransDataContainer *tc)
bool seq_transform_check_overlap(Span< Strip * > transformed_strips)
static Strip * effect_input_get(Strip *effect, SeqInputSide side)
void sync_active_scene_and_time_with_scene_strip(bContext &C)
void relations_invalidate_cache(Scene *scene, Strip *strip)
VectorSet< Strip * > query_selected_strips(ListBaseT< Strip > *seqbase)
Definition iterator.cc:164
void transform_translate_strip(Scene *evil_scene, Strip *strip, int delta)
ListBaseT< Strip > * active_seqbase_get(const Editing *ed)
Definition sequencer.cc:463
void transform_handle_overlap(Scene *scene, ListBaseT< Strip > *seqbasep, Span< Strip * > source_strips, bool use_sync_markers, Span< Strip * > time_dependent_strips)
bool transform_test_overlap(const Scene *scene, Strip *strip1, Strip *strip2)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
void edit_remove_flagged_strips(Scene *scene, ListBaseT< Strip > *seqbase)
void offset_animdata(const Scene *scene, Strip *strip, float ofs)
Definition animation.cc:42
void expand_strips(Editing *ed, VectorSet< Strip * > &strips, const StripRelation include)
Definition iterator.cc:70
bool transform_single_image_check(const Strip *strip)
constexpr int MAX_CHANNELS
void edit_flag_for_removal(Scene *scene, Strip *strip)
eSeqRippleFlag tool_settings_ripple_flag_get(Scene *scene)
Definition sequencer.cc:451
void transform_shuffle_vertical(ListBaseT< Strip > *seqbasep, Span< Strip * > strips, Scene *scene, const int channel_delta)
bool transform_is_locked(const ListBaseT< SeqTimelineChannel > *channels, const Strip *strip)
ListBaseT< SeqTimelineChannel > * channels_displayed_get(const Editing *ed)
Definition channels.cc:26
bool transform_strip_can_be_translated(const Strip *strip)
void tool_settings_overlap_mode_set(Scene *scene, eSeqOverlapMode overlap_mode)
Definition sequencer.cc:439
eSeqOverlapMode tool_settings_overlap_mode_get(Scene *scene)
Definition sequencer.cc:445
UserDef U
Definition blender.cc:58
int RNA_enum_get(PointerRNA *ptr, const char *name)
Scene * CTX_data_sequencer_scene(const bContext *C)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE int round_fl_to_int(float a)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE int max_ii(int a, int b)
MINLINE void add_v2_v2(float r[2], const float a[2])
bool BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, float limit)
void DEG_id_tag_update(ID *id, unsigned int flags)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
@ SEQ_RIPPLE_ALL_CHANNELS
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
@ USER_SEQ_ED_CLAMP_STRIPS_BY_DEFAULT
void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2])
Definition rct.cc:540
void unit_m3(float m[3][3])
@ ID_RECALC_SEQUENCER_STRIPS
Definition DNA_ID.h:1122
MINLINE int min_ii(int a, int b)
int ED_markers_post_apply_transform(ListBaseT< TimeMarker > *markers, Scene *scene, int mode, float value, char side)
bool BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2])
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ SPACE_SEQ_DESELECT_STRIP_HANDLE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< TimeMarker > markers
struct RenderData r
ListBaseT< SpaceLink > spacedata
eSpaceSeq_Flag flag
void(*) free_cb(TransInfo *, TransDataContainer *tc, TransCustomData *custom_data)
Definition transform.hh:655
VectorSet< Strip * > time_dependent_strips
#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t)
Definition transform.hh:45
conversion and adaptation of different datablocks to a common struct.
#define STRIP_EDGE_PAN_OUTSIDE_PAD
#define STRIP_EDGE_PAN_SPEED_RAMP
#define STRIP_EDGE_PAN_INSIDE_PAD
#define STRIP_EDGE_PAN_MAX_SPEED
#define STRIP_EDGE_PAN_DELAY
#define STRIP_EDGE_PAN_ZOOM_INFLUENCE
transform modes used by different operators.