Blender V5.3
sequencer_retiming.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 "BLI_listbase.hh"
10#include "BLI_map.hh"
11#include "BLI_math_base_c.hh"
12#include "BLI_set.hh"
13
14#include "DNA_scene_types.h"
15
16#include "BKE_context.hh"
17#include "BKE_report.hh"
18#include "BKE_scene.hh"
19
20#include "ED_select_utils.hh"
21#include "ED_sequencer.hh"
22
23#include "SEQ_connect.hh"
24#include "SEQ_iterator.hh"
25#include "SEQ_relations.hh"
26#include "SEQ_retiming.hh"
27#include "SEQ_select.hh"
28#include "SEQ_sequencer.hh"
29#include "SEQ_transform.hh"
30
31#include "WM_api.hh"
32
33#include "RNA_define.hh"
34
35#include "UI_view2d.hh"
36
37#include "sequencer_intern.hh"
38
39namespace blender::ed::vse {
40
41/* -------------------------------------------------------------------- */
44
46{
48 if (!scene) {
49 return false;
50 }
51 Editing *ed = seq::editing_get(scene);
52 if (!ed) {
53 return false;
54 }
55 Strip *strip = ed->act_strip;
56 if (strip == nullptr) {
57 return false;
58 }
59 if (!seq::retiming_is_allowed(strip)) {
60 CTX_wm_operator_poll_msg_set(C, "This strip type cannot be retimed");
61 return false;
62 }
63 return true;
64}
65
67
68/* -------------------------------------------------------------------- */
71
73{
75 Editing *ed = seq::editing_get(scene);
76
78 selected.remove_if([](Strip *strip) { return !seq::retiming_is_allowed(strip); });
79
80 Set<Strip *> selected_keys;
82 for (Strip *retiming_strip : retiming_sel.values()) {
83 if (seq::retiming_show_keys(retiming_strip)) {
84 selected.add(retiming_strip);
85 }
86 selected_keys.add(retiming_strip);
87 }
88
89 if (selected.is_empty()) {
90 return OPERATOR_CANCELLED;
91 }
92
93 /* If all strips show retiming keys, hide keys for all strips, otherwise, show for all. */
94 const bool all_show = std::ranges::all_of(
95 selected, [](Strip *strip) { return seq::retiming_show_keys(strip); });
96
97 for (Strip *strip : selected) {
98 if (all_show) {
99 strip->flag &= ~SEQ_SHOW_RETIMING;
100 /* Select the strip since we may have only had retiming keys selected before.
101 * This lets the user switch back to retiming mode right away if desired. */
102 strip->flag |= SEQ_SELECT;
103 }
104 else {
105 strip->flag |= SEQ_SHOW_RETIMING;
106 /* If retiming keys are selected, deselect the strip, since both can't happen. */
107 if (selected_keys.contains(strip)) {
108 strip->flag &= ~SEQ_SELECT;
109 }
110 }
111 }
112
114 return OPERATOR_FINISHED;
115}
116
118{
119 /* identifiers */
120 ot->name = "Retime Strips";
121 ot->description = "Show retiming keys in selected strips";
122 ot->idname = "SEQUENCER_OT_retiming_show";
123
124 /* API callbacks. */
127
128 /* flags */
130}
131
133
134/* -------------------------------------------------------------------- */
137
139{
141 const Editing *ed = seq::editing_get(scene);
142
143 for (Strip *strip : seq::query_selected_strips(ed->current_strips())) {
144 seq::retiming_reset(scene, strip);
145 }
146
148 return OPERATOR_FINISHED;
149}
150
152{
153 /* identifiers */
154 ot->name = "Reset Retiming";
155 ot->description = "Reset strip retiming";
156 ot->idname = "SEQUENCER_OT_retiming_reset";
157
158 /* API callbacks. */
160 ot->poll = retiming_poll;
161
162 /* flags */
164}
165
167
168/* -------------------------------------------------------------------- */
171
173 wmOperator *op,
174 Span<Strip *> strips,
175 const int frame)
176{
177 bool inserted = false;
178
179 for (Strip *strip : strips) {
180 if (!seq::retiming_is_allowed(strip)) {
181 continue;
182 }
183 if (seq::retiming_key_add_new_for_strip(scene, op->reports, strip, frame)) {
184 inserted = true;
185 strip->flag |= SEQ_SHOW_RETIMING;
186 }
187 }
188
189 return inserted ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
190}
191
193 wmOperator *op,
194 const int frame)
195{
196 Editing *ed = seq::editing_get(scene);
197 bool inserted = false;
198
200 if (selection.is_empty()) {
201 return OPERATOR_CANCELLED;
202 }
203
204 for (Strip *strip : selection.values()) {
205 if (seq::retiming_key_add_new_for_strip(scene, op->reports, strip, frame)) {
206 inserted = true;
207 strip->flag |= SEQ_SHOW_RETIMING;
208 }
209 }
210
211 return inserted ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
212}
213
215{
217
218 float frame;
219 if (RNA_struct_property_is_set(op->ptr, "timeline_frame")) {
220 frame = RNA_int_get(op->ptr, "timeline_frame");
221 }
222 else {
223 frame = BKE_scene_frame_get(scene);
224 }
225
226 wmOperatorStatus ret_val;
228 if (!strips.is_empty()) {
229 ret_val = retiming_key_add_from_selection(scene, op, strips, frame);
230 }
231 else {
232 ret_val = retiming_key_add_to_editable_strips(scene, op, frame);
233 }
234
236 return ret_val;
237}
238
240{
241 /* identifiers */
242 ot->name = "Add Retiming Key";
243 ot->description = "Add retiming Key";
244 ot->idname = "SEQUENCER_OT_retiming_key_add";
245
246 /* API callbacks. */
248 ot->poll = retiming_poll;
249
250 /* flags */
252
253 RNA_def_int(ot->srna,
254 "timeline_frame",
255 0,
256 0,
257 INT_MAX,
258 "Timeline Frame",
259 "Frame where key will be added",
260 0,
261 INT_MAX);
262}
263
265
266/* -------------------------------------------------------------------- */
269
271 const bContext *C, const wmOperator *op, Strip *strip, const int frame, const int duration)
272{
275
276 // ensure L+R key
277 SeqRetimingKey *key = seq::retiming_add_key(scene, strip, frame);
278
279 if (key == nullptr) {
280 BKE_report(op->reports, RPT_WARNING, "Cannot create freeze frame");
281 return false;
282 }
283
285 BKE_report(op->reports, RPT_WARNING, "Cannot create key inside of speed transition");
286 return false;
287 }
288
290 SeqRetimingKey *freeze = seq::retiming_add_freeze_frame(scene, strip, key, duration);
291
292 if (freeze == nullptr) {
293 BKE_report(op->reports, RPT_WARNING, "Cannot create freeze frame");
294 return false;
295 }
296
297 deselect_all_strips(scene);
299
301
303 return true;
304}
305
307 const wmOperator *op,
308 const int duration)
309{
312 strips.remove_if([&](Strip *strip) { return !seq::retiming_is_allowed(strip); });
313 const int frame = BKE_scene_frame_get(scene);
314 bool success = false;
315
316 for (Strip *strip : strips) {
317 success |= freeze_frame_add_new_for_strip(C, op, strip, frame, duration);
319 }
320 return success;
321}
322
324 const wmOperator *op,
325 const int duration)
326{
328 bool success = false;
329
331
332 for (auto item : selection.items()) {
333 const int frame = seq::retiming_key_frame_get(scene, item.value, item.key);
334 success |= freeze_frame_add_new_for_strip(C, op, item.value, frame, duration);
335 seq::relations_invalidate_cache_raw(scene, item.value);
336 }
337 return success;
338}
339
341{
343 bool success = false;
344
345 int duration = 1;
346
347 if (RNA_property_is_set(op->ptr, RNA_struct_find_property(op->ptr, "duration"))) {
348 duration = RNA_int_get(op->ptr, "duration");
349 }
350
352 success = freeze_frame_add_from_retiming_selection(C, op, duration);
353 }
354 else {
355 success = freeze_frame_add_from_strip_selection(C, op, duration);
356 }
357
359
360 return success ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
361}
362
364{
365 /* identifiers */
366 ot->name = "Add Freeze Frame";
367 ot->description = "Add freeze frame";
368 ot->idname = "SEQUENCER_OT_retiming_freeze_frame_add";
369
370 /* API callbacks. */
372 ot->poll = retiming_poll;
373
374 /* flags */
376
377 /* properties */
378 RNA_def_int(ot->srna,
379 "duration",
380 0,
381 0,
382 INT_MAX,
383 "Duration",
384 "Duration of freeze frame segment",
385 0,
386 INT_MAX);
387}
388
390
391/* -------------------------------------------------------------------- */
394
396 const bContext *C, const wmOperator *op, Strip *strip, const int frame, const int duration)
397{
399
400 // ensure L+R key
402 SeqRetimingKey *key = seq::retiming_add_key(scene, strip, frame);
403
404 if (key == nullptr) {
405 key = seq::retiming_key_get_by_frame(scene, strip, frame);
406 }
407
408 if (seq::retiming_is_last_key(strip, key) || key->strip_frame_index == 0) {
409 BKE_report(op->reports, RPT_WARNING, "Cannot create transition from first or last key");
410 return false;
411 }
412
413 SeqRetimingKey *transition = seq::retiming_add_transition(scene, strip, key, duration);
414
415 if (transition == nullptr) {
416 BKE_report(op->reports, RPT_WARNING, "Cannot create transition");
417 return false;
418 }
419
420 deselect_all_strips(scene);
422
424
426 return true;
427}
428
430 const wmOperator *op,
431 const int duration)
432{
434 bool success = false;
435
437
438 for (auto item : selection.items()) {
439 const int frame = seq::retiming_key_frame_get(scene, item.value, item.key);
440 success |= transition_add_new_for_strip(C, op, item.value, frame, duration);
441 }
442 return success;
443}
444
446{
448 bool success = false;
449
450 int duration = 1;
451
452 if (RNA_property_is_set(op->ptr, RNA_struct_find_property(op->ptr, "duration"))) {
453 duration = RNA_int_get(op->ptr, "duration");
454 }
455
457 success = transition_add_from_retiming_selection(C, op, duration);
458 }
459 else {
460 BKE_report(op->reports, RPT_WARNING, "Retiming key must be selected");
461 return OPERATOR_CANCELLED;
462 }
463
465
466 return success ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
467}
468
470{
471 /* identifiers */
472 ot->name = "Add Speed Transition";
473 ot->description = "Add smooth transition between 2 retimed segments";
474 ot->idname = "SEQUENCER_OT_retiming_transition_add";
475
476 /* API callbacks. */
478 ot->poll = retiming_poll;
479
480 /* flags */
482
483 /* properties */
484 RNA_def_int(ot->srna,
485 "duration",
486 0,
487 0,
488 INT_MAX,
489 "Duration",
490 "Duration of speed transition segment",
491 0,
492 INT_MAX);
493}
494
496
497/* -------------------------------------------------------------------- */
500
502{
504
506 Vector<Strip *> strips_to_handle;
507
508 if (!seq::retiming_keys_are_selected(scene) || selection.size() == 0) {
510 }
511
512 for (Strip *strip : selection.values()) {
513 strips_to_handle.append_non_duplicates(strip);
514 }
515
516 for (Strip *strip : strips_to_handle) {
517 Vector<SeqRetimingKey *> keys_to_delete;
518 for (auto item : selection.items()) {
519 if (item.value != strip) {
520 continue;
521 }
522 keys_to_delete.append(item.key);
523 }
524
525 seq::retiming_remove_multiple_keys(strip, keys_to_delete);
526 }
527
528 for (Strip *strip : strips_to_handle) {
530 }
531
533 return OPERATOR_FINISHED;
534}
535
537 wmOperator *op,
538 const wmEvent *event)
539{
541 ListBaseT<TimeMarker> *markers = &scene->markers;
542
543 if (!markers->is_empty()) {
544 ARegion *region = CTX_wm_region(C);
545 if (region && (region->regiontype == RGN_TYPE_WINDOW)) {
546 /* Bounding box of 30 pixels is used for markers shortcuts,
547 * prevent conflict with markers shortcuts here. */
548 if (event->mval[1] <= 30) {
550 }
551 }
552 }
553
555}
556
558{
559
560 /* Identifiers. */
561 ot->name = "Delete Retiming Keys";
562 ot->idname = "SEQUENCER_OT_retiming_key_delete";
563 ot->description = "Delete selected retiming keys from the sequencer";
564
565 /* API callbacks. */
568 ot->poll = retiming_poll;
569
570 /* Flags. */
572}
573
575
576/* -------------------------------------------------------------------- */
579
580/* Return speed of existing segment or active strip. */
581static float strip_speed_get(const Scene *scene)
582{
583 /* Strip mode. */
585 Strip *strip = seq::editing_get(scene)->act_strip;
586 if (!strip || !seq::retiming_has_keys(strip)) {
587 return 1.0f;
588 }
589 int right_frame = seq::right_fake_key_frame_get(scene, strip);
590 SeqRetimingKey *key = seq::retiming_key_get_by_frame(scene, strip, right_frame);
591 return (key != nullptr) ? seq::retiming_key_speed_get(strip, key) : 1.0f;
592 }
593
595 /* Retiming mode. */
596 if (selection.size() == 1) {
597 for (auto item : selection.items()) {
598 return seq::retiming_key_speed_get(item.value, item.key);
599 }
600 }
601
602 return 1.0f;
603}
604
605static void strip_speed_set(Scene *scene, Strip *strip, const float speed)
606{
608
609 /* Overwrite existing keys, since these hidden/visible keys just add noise when the user wants to
610 * retime the whole strip. Only keep them if explicitly retiming segments with keys selected. */
611 seq::retiming_reset(scene, strip);
612
613 SeqRetimingKey *right_key = seq::ensure_left_and_right_keys(scene, strip);
614 if (right_key == nullptr) {
615 return;
616 }
617
618 /* TODO: it would be nice to multiply speed with complex retiming by a factor. */
619 seq::retiming_key_speed_set(scene, strip, right_key, speed / 100.0f);
620}
621
622static void segment_speed_set(Scene *scene,
624 const float speed)
625{
626 ListBaseT<Strip> *seqbase = seq::active_seqbase_get(seq::editing_get(scene));
627
628 VectorSet<Strip *> retimed_strips;
629 for (auto item : selection.items()) {
630 seq::relations_invalidate_cache_raw(scene, item.value);
631
632 seq::retiming_key_speed_set(scene, item.value, item.key, speed / 100.0f);
633
634 retimed_strips.add(item.value);
635 }
636
637 seq::transform_handle_overlap(scene, seqbase, retimed_strips, false);
638}
639
641{
643 const float speed = RNA_float_get(op->ptr, "speed");
644
645 /* Strip mode. */
648 strips.remove_if([&](Strip *strip) { return !seq::retiming_is_allowed(strip); });
649 for (Strip *strip : strips) {
650 strip_speed_set(scene, strip, speed);
651 }
652 ListBaseT<Strip> *seqbase = seq::active_seqbase_get(seq::editing_get(scene));
653 seq::transform_handle_overlap(scene, seqbase, strips, false);
655 return OPERATOR_FINISHED;
656 }
657
659
660 /* Retiming mode. */
661 if (selection.size() > 0) {
662 segment_speed_set(scene, selection, speed);
664 return OPERATOR_FINISHED;
665 }
666
667 BKE_report(op->reports, RPT_ERROR, "No keys or strips selected");
668 return OPERATOR_CANCELLED;
669}
670
672 wmOperator *op,
673 const wmEvent *event)
674{
675 const Scene *scene = CTX_data_sequencer_scene(C);
676
677 if (!RNA_struct_property_is_set(op->ptr, "speed")) {
678 RNA_float_set(op->ptr, "speed", strip_speed_get(scene) * 100.0f);
679 return WM_operator_props_popup(C, op, event);
680 }
681
683}
684
686{
687 /* identifiers */
688 ot->name = "Set Speed";
689 ot->description = "Set speed of retimed segment";
690 ot->idname = "SEQUENCER_OT_retiming_segment_speed_set";
691
692 /* API callbacks. */
695 ot->poll = retiming_poll;
696
697 /* flags */
699
700 /* properties */
702 "speed",
703 100.0f,
704 0.001f,
705 FLT_MAX,
706 "Speed",
707 "New speed of retimed segment",
708 0.1f,
709 FLT_MAX);
710}
711
713
714/* -------------------------------------------------------------------- */
717
719{
721 return (16.0f * UI_SCALE_FAC);
722}
723
725 const View2D *v2d,
726 const Strip *strip,
727 const int mval[2])
728{
729 int best_distance = INT_MAX;
730 SeqRetimingKey *best_key = nullptr;
731
732 for (SeqRetimingKey &key : seq::retiming_keys_get(strip)) {
735 mval[0]));
736
737 int threshold = retiming_key_mouseover_threshold();
738 if (seq::retiming_key_frame_get(scene, strip, &key) == strip->left_handle() ||
739 seq::retiming_key_frame_get(scene, strip, &key) == strip->right_handle(scene))
740 {
741 threshold *= 2; /* Make first and last key easier to select. */
742 }
743
744 if (distance < threshold && distance < best_distance) {
745 best_distance = distance;
746 best_key = &key;
747 }
748 }
749
750 return best_key;
751}
752
754 const View2D *v2d,
755 const int mval[2],
756 Strip **r_strip)
757{
758 for (Strip *strip : sequencer_visible_strips_get(scene, v2d)) {
759 if (!seq::retiming_show_keys(strip)) {
760 continue;
761 }
762
763 rcti box = strip_retiming_keys_box_get(scene, v2d, strip);
764 if (!BLI_rcti_isect_pt(&box, mval[0], mval[1])) {
765 continue;
766 }
767
768 if (r_strip != nullptr) {
769 *r_strip = strip;
770 }
771
772 SeqRetimingKey *key = mouse_over_key_get_from_strip(scene, v2d, strip, mval);
773
774 if (key == nullptr) {
775 continue;
776 }
777
778 return key;
779 }
780
781 return nullptr;
782}
783
785 const Scene *scene, const View2D *v2d, const Strip *strip, const int mval[2], int &r_frame)
786{
787 rcti box = strip_retiming_keys_box_get(scene, v2d, strip);
788 if (!BLI_rcti_isect_pt(&box, mval[0], mval[1])) {
789 return false;
790 }
791
792 const int left_frame = seq::left_fake_key_frame_get(scene, strip);
793 const float left_distance = fabs(ui::view2d_view_to_region_x(v2d, left_frame) - mval[0]);
794
795 const int right_frame = seq::right_fake_key_frame_get(scene, strip);
796 const int right_x = right_frame;
797 const float right_distance = fabs(ui::view2d_view_to_region_x(v2d, right_x) - mval[0]);
798
799 r_frame = (left_distance < right_distance) ? left_frame : right_frame;
800
801 /* Fake key threshold is doubled to make them easier to select. */
802 return min_ff(left_distance, right_distance) < retiming_key_mouseover_threshold() * 2;
803}
804
806 const Strip *strip,
807 const View2D *v2d,
808 const SpaceSeq *sseq,
809 int mouse_co_region[2])
810{
812 return false;
813 }
814
815 rcti retiming_keys_box = strip_retiming_keys_box_get(scene, v2d, strip);
816 return BLI_rcti_isect_pt_v(&retiming_keys_box, mouse_co_region);
817}
818
820 const View2D *v2d,
821 Strip *strip,
822 const int mval[2])
823{
824 SeqRetimingKey *key = nullptr;
825
826 int key_frame;
827 if (retiming_fake_key_frame_clicked(scene, v2d, strip, mval, key_frame)) {
828 seq::realize_fake_keys(scene, strip);
829 key = seq::retiming_key_get_by_frame(scene, strip, key_frame);
830 }
831 return key;
832}
833
834static bool select_key(const Editing *ed,
835 SeqRetimingKey *key,
836 const bool toggle,
837 const bool deselect_all)
838{
839 bool changed = false;
840
841 if (deselect_all) {
843 }
844
845 if (key == nullptr) {
846 return changed;
847 }
848
849 if (toggle && seq::retiming_selection_contains(ed, key)) {
851 }
852 else {
854 }
855
856 return true;
857}
858
859static bool select_connected_keys(const Scene *scene,
860 const SeqRetimingKey *source,
861 const Strip *source_owner)
862{
863 if (!seq::is_strip_connected(source_owner)) {
864 return false;
865 }
866
867 const int frame = seq::retiming_key_frame_get(scene, source_owner, source);
868 bool changed = false;
869 VectorSet<Strip *> connections = seq::connected_strips_get(source_owner);
870 for (Strip *connection : connections) {
871 SeqRetimingKey *con_key = seq::retiming_key_get_by_frame(scene, connection, frame);
872
873 if (con_key) {
874 seq::retiming_selection_copy(con_key, source);
875 changed = true;
876 }
877 }
878 return changed;
879}
880
882 const bool extend,
883 SeqRetimingKey *key,
884 const Strip *key_owner)
885{
886 Editing *ed = seq::editing_get(scene);
887
888 if (!extend) {
890 }
891 for (; key <= seq::retiming_last_key_get(key_owner); key++) {
892 select_key(ed, key, false, false);
893 select_connected_keys(scene, key, key_owner);
894 }
895}
896
898 wmOperator *op,
899 SeqRetimingKey *key,
900 const Strip *key_owner)
901{
903 const Editing *ed = seq::editing_get(scene);
904
905 const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
906 const bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others");
907 const bool toggle = RNA_boolean_get(op->ptr, "toggle");
908 const bool extend = RNA_boolean_get(op->ptr, "extend");
909
910 if (RNA_boolean_get(op->ptr, "linked_time")) {
911 sequencer_retiming_select_linked_time(scene, extend, key, key_owner);
913 return OPERATOR_FINISHED;
914 }
915
916 /* Clicked on an unselected key. */
917 if (!seq::retiming_selection_contains(ed, key) && !toggle) {
918 select_key(ed, key, false, deselect_all);
919 select_connected_keys(scene, key, key_owner);
920 }
921
922 /* Clicked on a key that is already selected, waiting to click release. */
923 if (wait_to_deselect_others && !toggle) {
925 }
926
927 /* The key is already selected, but deselect other selected keys after click is released if no
928 * transform or toggle happened. */
929 bool changed = select_key(ed, key, toggle, deselect_all);
930 if (!toggle) {
931 changed |= select_connected_keys(scene, key, key_owner);
932 }
933
935 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
936}
937
938static void realize_fake_keys_in_rect(const Scene *scene, Strip *strip, const rctf &rectf)
939{
940 const int content_start = strip->content_start();
941 const int left_key_frame = max_ii(content_start, strip->left_handle());
942 const int content_end = strip->content_end(scene);
943 const int right_key_frame = min_ii(content_end, strip->right_handle(scene));
944
945 /* Realize "fake" keys. */
946 if (left_key_frame > rectf.xmin && left_key_frame < rectf.xmax) {
947 seq::retiming_add_key(scene, strip, left_key_frame);
948 }
949 if (right_key_frame > rectf.xmin && right_key_frame < rectf.xmax) {
950 seq::retiming_add_key(scene, strip, right_key_frame);
951 }
952}
953
955{
956 const Scene *scene = CTX_data_sequencer_scene(C);
957 const View2D *v2d = ui::view2d_fromcontext(C);
958 Editing *ed = seq::editing_get(scene);
959
960 if (ed == nullptr) {
961 return OPERATOR_CANCELLED;
962 }
963
964 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
965 bool changed = false;
966
967 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
969 }
970
971 rctf rectf;
973 ui::view2d_region_to_view_rctf(v2d, &rectf, &rectf);
974
975 Set<SeqRetimingKey *> and_keys;
976
977 for (Strip *strip : sequencer_visible_strips_get(C)) {
978 if (strip->channel < rectf.ymin || strip->channel > rectf.ymax) {
979 continue;
980 }
981 if (!seq::retiming_show_keys(strip)) {
982 continue;
983 }
984 realize_fake_keys_in_rect(scene, strip, rectf);
985
986 for (SeqRetimingKey &key : seq::retiming_keys_get(strip)) {
987 const int key_frame = seq::retiming_key_frame_get(scene, strip, &key);
988 const int strip_start = strip->left_handle();
989 const int strip_end = strip->right_handle(scene);
990 if (key_frame < strip_start || key_frame > strip_end) {
991 continue;
992 }
993 if (key_frame > rectf.xmax || key_frame < rectf.xmin) {
994 continue;
995 }
996
997 switch (sel_op) {
998 case SEL_OP_ADD:
999 case SEL_OP_SET: {
1001 break;
1002 }
1003 case SEL_OP_SUB: {
1005 break;
1006 }
1007 case SEL_OP_XOR: { /* Toggle */
1010 }
1011 else {
1013 }
1014 break;
1015 case SEL_OP_AND: {
1017 and_keys.add(&key);
1018 }
1019 break;
1020 }
1021 }
1022 }
1023 changed = true;
1024 }
1025 }
1026
1027 if (and_keys.size() > 0) {
1029 for (auto *key : and_keys) {
1031 }
1032 }
1033
1034 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1035}
1036
1038{
1040 int action = RNA_enum_get(op->ptr, "action");
1041
1043
1044 if (action == SEL_TOGGLE) {
1045 action = SEL_SELECT;
1046 for (Strip *strip : strips) {
1047 if (!seq::retiming_show_keys(strip)) {
1048 continue;
1049 }
1050 for (SeqRetimingKey &key : seq::retiming_keys_get(strip)) {
1051 if (key.flag & SEQ_KEY_SELECTED) {
1052 action = SEL_DESELECT;
1053 break;
1054 }
1055 }
1056 }
1057 }
1058
1059 if (action == SEL_DESELECT) {
1061 }
1062
1063 for (Strip *strip : strips) {
1064 if (!seq::retiming_show_keys(strip)) {
1065 continue;
1066 }
1067 for (SeqRetimingKey &key : seq::retiming_keys_get(strip)) {
1068 switch (action) {
1069 case SEL_SELECT:
1070 key.flag |= SEQ_KEY_SELECTED;
1071 break;
1072 case SEL_INVERT:
1073 if (key.flag & SEQ_KEY_SELECTED) {
1074 key.flag &= ~SEQ_KEY_SELECTED;
1075 }
1076 else {
1077 key.flag |= SEQ_KEY_SELECTED;
1078 }
1079 break;
1080 }
1081 }
1082 }
1083
1085 return OPERATOR_FINISHED;
1086}
1087
1089
1090} // namespace blender::ed::vse
#define UI_SCALE_FAC
#define SEL_OP_USE_PRE_DESELECT(sel_op)
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER
Definition WM_types.hh:456
#define NC_SCENE
Definition WM_types.hh:391
ValueIterator values() const &
Definition BLI_map.hh:884
int64_t size() const
Definition BLI_map.hh:976
bool is_empty() const
Definition BLI_map.hh:986
ItemIterator items() const &
Definition BLI_map.hh:902
int64_t size() const
Definition BLI_set.hh:606
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool add(const Key &key)
int64_t remove_if(Predicate &&predicate)
void append(const T &value)
void append_non_duplicates(const T &value)
#define FLT_MAX
#define INT_MAX
float distance(float, float) RET
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
VectorSet< Strip * > selected_strips_from_context(bContext *C)
void SEQUENCER_OT_retiming_transition_add(wmOperatorType *ot)
static bool select_connected_keys(const Scene *scene, const SeqRetimingKey *source, const Strip *source_owner)
bool retiming_overlay_enabled(const SpaceSeq *sseq)
static bool freeze_frame_add_from_strip_selection(bContext *C, const wmOperator *op, const int duration)
static wmOperatorStatus sequencer_retiming_transition_add_exec(bContext *C, wmOperator *op)
static bool freeze_frame_add_from_retiming_selection(const bContext *C, const wmOperator *op, const int duration)
static bool retiming_fake_key_frame_clicked(const Scene *scene, const View2D *v2d, const Strip *strip, const int mval[2], int &r_frame)
static wmOperatorStatus sequencer_retiming_key_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void SEQUENCER_OT_retiming_reset(wmOperatorType *ot)
void SEQUENCER_OT_retiming_segment_speed_set(wmOperatorType *ot)
static bool select_key(const Editing *ed, SeqRetimingKey *key, const bool toggle, const bool deselect_all)
bool is_mouse_over_retiming_keys_box(const Scene *scene, const Strip *strip, const View2D *v2d, const SpaceSeq *sseq, int mouse_co_region[2])
static bool transition_add_new_for_strip(const bContext *C, const wmOperator *op, Strip *strip, const int frame, const int duration)
static wmOperatorStatus sequencer_retiming_segment_speed_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus sequencer_retiming_segment_speed_set_exec(bContext *C, wmOperator *op)
SeqRetimingKey * try_to_realize_fake_keys(const Scene *scene, const View2D *v2d, Strip *strip, const int mval[2])
static wmOperatorStatus sequencer_retiming_key_delete_exec(bContext *C, wmOperator *)
static void segment_speed_set(Scene *scene, Map< SeqRetimingKey *, Strip * > selection, const float speed)
bool sequencer_editing_initialized_and_active(bContext *C)
static bool freeze_frame_add_new_for_strip(const bContext *C, const wmOperator *op, Strip *strip, const int frame, const int duration)
static wmOperatorStatus sequencer_retiming_freeze_frame_add_exec(bContext *C, wmOperator *op)
wmOperatorStatus sequencer_retiming_box_select_exec(bContext *C, wmOperator *op)
void SEQUENCER_OT_retiming_key_delete(wmOperatorType *ot)
static wmOperatorStatus sequencer_retiming_key_add_exec(bContext *C, wmOperator *op)
static bool retiming_poll(bContext *C)
void sequencer_select_do_updates(const bContext *C, Scene *scene)
void SEQUENCER_OT_retiming_show(wmOperatorType *ot)
void SEQUENCER_OT_retiming_key_add(wmOperatorType *ot)
bool deselect_all_strips(const Scene *scene)
wmOperatorStatus sequencer_retiming_select_all_exec(bContext *C, wmOperator *op)
static void strip_speed_set(Scene *scene, Strip *strip, const float speed)
SeqRetimingKey * retiming_mouseover_key_get(const Scene *scene, const View2D *v2d, const int mval[2], Strip **r_strip)
static bool transition_add_from_retiming_selection(const bContext *C, const wmOperator *op, const int duration)
static float strip_speed_get(const Scene *scene)
rcti strip_retiming_keys_box_get(const Scene *scene, const View2D *v2d, const Strip *strip)
void SEQUENCER_OT_retiming_freeze_frame_add(wmOperatorType *ot)
static wmOperatorStatus retiming_key_add_from_selection(const Scene *scene, wmOperator *op, Span< Strip * > strips, const int frame)
VectorSet< Strip * > all_strips_from_context(bContext *C)
static wmOperatorStatus sequencer_retiming_reset_exec(bContext *C, wmOperator *)
Vector< Strip * > sequencer_visible_strips_get(const bContext *C)
static void realize_fake_keys_in_rect(const Scene *scene, Strip *strip, const rctf &rectf)
static float retiming_key_mouseover_threshold()
static void sequencer_retiming_select_linked_time(const Scene *scene, const bool extend, SeqRetimingKey *key, const Strip *key_owner)
static SeqRetimingKey * mouse_over_key_get_from_strip(const Scene *scene, const View2D *v2d, const Strip *strip, const int mval[2])
static wmOperatorStatus sequencer_retiming_data_show_exec(bContext *C, wmOperator *)
static wmOperatorStatus retiming_key_add_to_editable_strips(const Scene *scene, wmOperator *op, const int frame)
wmOperatorStatus sequencer_retiming_key_select_exec(bContext *C, wmOperator *op, SeqRetimingKey *key, const Strip *key_owner)
SeqRetimingKey * ensure_left_and_right_keys(const Scene *scene, Strip *strip)
SeqRetimingKey * retiming_key_add_new_for_strip(const Scene *scene, ReportList *reports, Strip *strip, const int frame)
SeqRetimingKey * retiming_add_transition(const Scene *scene, Strip *strip, SeqRetimingKey *key, float offset)
MutableSpan< SeqRetimingKey > retiming_keys_get(const Strip *strip)
void realize_fake_keys(const Scene *scene, Strip *strip)
bool retiming_key_is_transition_start(const SeqRetimingKey *key)
void retiming_reset(Scene *scene, Strip *strip)
bool retiming_selection_contains(const Editing *ed, const SeqRetimingKey *key)
VectorSet< Strip * > query_selected_strips(ListBaseT< Strip > *seqbase)
Definition iterator.cc:164
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)
SeqRetimingKey * retiming_add_key(const Scene *scene, Strip *strip, const int frame)
SeqRetimingKey * retiming_add_freeze_frame(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int offset)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
int retiming_key_frame_get(const Scene *scene, const Strip *strip, const SeqRetimingKey *key)
void relations_invalidate_cache_raw(Scene *scene, Strip *strip)
void retiming_selection_remove(SeqRetimingKey *key)
int right_fake_key_frame_get(const Scene *scene, const Strip *strip)
bool is_strip_connected(const Strip *strip)
void retiming_remove_multiple_keys(Strip *strip, Vector< SeqRetimingKey * > &keys_to_remove)
void retiming_selection_copy(SeqRetimingKey *dst, const SeqRetimingKey *src)
bool retiming_has_keys(const Strip *strip)
bool retiming_selection_clear(const Editing *ed)
float retiming_key_speed_get(const Strip *strip, const SeqRetimingKey *key)
void retiming_key_speed_set(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float speed)
bool retiming_is_allowed(const Strip *strip)
bool retiming_show_keys(const Strip *strip)
int left_fake_key_frame_get(const Scene *scene, const Strip *strip)
SeqRetimingKey * retiming_key_get_by_frame(const Scene *scene, const Strip *strip, const int frame)
VectorSet< Strip * > connected_strips_get(const Strip *strip)
bool retiming_keys_are_selected(const Scene *scene)
Map< SeqRetimingKey *, Strip * > retiming_selection_get(const Editing *ed)
SeqRetimingKey * retiming_last_key_get(const Strip *strip)
void retiming_selection_append(SeqRetimingKey *key)
bool retiming_is_last_key(const Strip *strip, const SeqRetimingKey *key)
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
View2D * view2d_fromcontext(const bContext *C)
Definition view2d.cc:1836
float view2d_view_to_region_x(const View2D *v2d, float x)
Definition view2d.cc:1673
MINLINE float min_ff(float a, float b)
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
Scene * CTX_data_sequencer_scene(const bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
MINLINE int round_fl_to_int(float a)
int RNA_int_get(PointerRNA *ptr, const char *name)
MINLINE int max_ii(int a, int b)
void WM_operator_properties_border_to_rctf(wmOperator *op, rctf *r_rect)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
wmOperatorStatus WM_operator_props_popup(bContext *C, wmOperator *op, const wmEvent *)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
MINLINE int min_ii(int a, int b)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
ARegion * CTX_wm_region(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
#define fabsf
eRegion_Type regiontype
ListBaseT< TimeMarker > markers
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports