[Bf-blender-cvs] [7afcfe111aa] master: VSE: Make time operations self-contained

Richard Antalik noreply at git.blender.org
Thu Jun 2 03:17:04 CEST 2022


Commit: 7afcfe111aacc8bc3f456a3287d3cc34765b798a
Author: Richard Antalik
Date:   Thu Jun 2 01:39:40 2022 +0200
Branches: master
https://developer.blender.org/rB7afcfe111aacc8bc3f456a3287d3cc34765b798a

VSE: Make time operations self-contained

This patch makes it possible to manipulate strips without need to use
update functions to recalculate effect and meta strips.

Prior to this change function `SEQ_time_update_sequence` had to be used
to update mainly effects and meta strips. This was implemented in a way
that relied on sorted list of strips, which can't always be done and in
rare cases this approach failed.

In case of meta strips, `seqbase` had to be passed and compared with
"active" one to determine whether meta strip should be updated or not.
This is especially weak system that is prone to bugs when functions are
used by python API functions.

Finally, other strip types had startdisp` and `enddisp` fields updated
by this function and a lot of code relied on these fields even if strip
start, length and offsets are available. This is completely
unnecessary.

Implemented changes:
All effects and meta strips are updated when strip handles are moved or
strip is translated, without need to call any update function.

Function `SEQ_time_update_sequence` has been split to
`SEQ_time_update_meta_strip_range` and
`seq_time_update_effects_strip_range`. These functions should be only
used within sequencer module code. Meta update is used for versioning,
which is only reason for it not being declared internally.

Sequence fields `startdisp` and `enddisp` are now only used for
effects to store strip start and end points. These fields should be
used only internally within sequencer module code.
Use function `SEQ_time_*_handle_frame_get` to get strip start and end
points.

To update effects and meta strips with reasonable performance, cache
for "parent" meta strip and attached effects is added to
`SequenceLookup` cache, so it shares invalidation mechanisms.
All caches are populated during single iteration.

There should be no functional changes.

Differential Revision: https://developer.blender.org/D14990

===================================================================

M	source/blender/blenkernel/BKE_sound.h
M	source/blender/blenkernel/intern/sound.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/editors/space_sequencer/sequencer_drag_drop.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_sequencer/sequencer_select.c
M	source/blender/editors/space_sequencer/sequencer_thumbnails.c
M	source/blender/editors/space_sequencer/sequencer_view.c
M	source/blender/editors/transform/transform_convert_sequencer.c
M	source/blender/editors/transform/transform_snap_sequencer.c
M	source/blender/makesdna/DNA_sequence_types.h
M	source/blender/makesrna/intern/rna_sequencer.c
M	source/blender/makesrna/intern/rna_sequencer_api.c
M	source/blender/sequencer/SEQ_add.h
M	source/blender/sequencer/SEQ_sequencer.h
M	source/blender/sequencer/SEQ_time.h
M	source/blender/sequencer/SEQ_transform.h
M	source/blender/sequencer/SEQ_utils.h
M	source/blender/sequencer/intern/disk_cache.c
M	source/blender/sequencer/intern/effects.c
M	source/blender/sequencer/intern/image_cache.c
M	source/blender/sequencer/intern/proxy.c
M	source/blender/sequencer/intern/render.c
M	source/blender/sequencer/intern/sequence_lookup.c
M	source/blender/sequencer/intern/sequencer.h
M	source/blender/sequencer/intern/sound.c
M	source/blender/sequencer/intern/strip_add.c
M	source/blender/sequencer/intern/strip_edit.c
M	source/blender/sequencer/intern/strip_relations.c
M	source/blender/sequencer/intern/strip_time.c
M	source/blender/sequencer/intern/strip_time.h
M	source/blender/sequencer/intern/strip_transform.c
M	source/blender/sequencer/intern/utils.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index edb301f06bf..9965b6f1351 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -136,7 +136,7 @@ void BKE_sound_remove_scene_sound(struct Scene *scene, void *handle);
 
 void BKE_sound_mute_scene_sound(void *handle, char mute);
 
-void BKE_sound_move_scene_sound(struct Scene *scene,
+void BKE_sound_move_scene_sound(const struct Scene *scene,
                                 void *handle,
                                 int startframe,
                                 int endframe,
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index de5589cf5dc..5bafce15b34 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -54,6 +54,7 @@
 
 #include "SEQ_sequencer.h"
 #include "SEQ_sound.h"
+#include "SEQ_time.h"
 
 static void sound_free_audio(bSound *sound);
 
@@ -719,8 +720,8 @@ void *BKE_sound_scene_add_scene_sound_defaults(Scene *scene, Sequence *sequence)
 {
   return BKE_sound_scene_add_scene_sound(scene,
                                          sequence,
-                                         sequence->startdisp,
-                                         sequence->enddisp,
+                                         SEQ_time_left_handle_frame_get(sequence),
+                                         SEQ_time_right_handle_frame_get(sequence),
                                          sequence->startofs + sequence->anim_startofs);
 }
 
@@ -745,8 +746,8 @@ void *BKE_sound_add_scene_sound_defaults(Scene *scene, Sequence *sequence)
 {
   return BKE_sound_add_scene_sound(scene,
                                    sequence,
-                                   sequence->startdisp,
-                                   sequence->enddisp,
+                                   SEQ_time_left_handle_frame_get(sequence),
+                                   SEQ_time_right_handle_frame_get(sequence),
                                    sequence->startofs + sequence->anim_startofs);
 }
 
@@ -760,8 +761,12 @@ void BKE_sound_mute_scene_sound(void *handle, char mute)
   AUD_SequenceEntry_setMuted(handle, mute);
 }
 
-void BKE_sound_move_scene_sound(
-    Scene *scene, void *handle, int startframe, int endframe, int frameskip, double audio_offset)
+void BKE_sound_move_scene_sound(const Scene *scene,
+                                void *handle,
+                                int startframe,
+                                int endframe,
+                                int frameskip,
+                                double audio_offset)
 {
   sound_verify_evaluated_id(&scene->id);
   const double fps = FPS;
@@ -774,8 +779,8 @@ void BKE_sound_move_scene_sound_defaults(Scene *scene, Sequence *sequence)
   if (sequence->scene_sound) {
     BKE_sound_move_scene_sound(scene,
                                sequence->scene_sound,
-                               sequence->startdisp,
-                               sequence->enddisp,
+                               SEQ_time_left_handle_frame_get(sequence),
+                               SEQ_time_right_handle_frame_get(sequence),
                                sequence->startofs + sequence->anim_startofs,
                                0.0);
   }
@@ -1344,7 +1349,7 @@ void BKE_sound_remove_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle))
 void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute))
 {
 }
-void BKE_sound_move_scene_sound(Scene *UNUSED(scene),
+void BKE_sound_move_scene_sound(const Scene *UNUSED(scene),
                                 void *UNUSED(handle),
                                 int UNUSED(startframe),
                                 int UNUSED(endframe),
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 585ada3b2d8..cd56adfe60c 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -347,8 +347,9 @@ static void seq_convert_transform_crop_lb_2(const Scene *scene,
   }
 }
 
-static void seq_update_meta_disp_range(Editing *ed)
+static void seq_update_meta_disp_range(Scene *scene)
 {
+  Editing *ed = SEQ_editing_get(scene);
   if (ed == NULL) {
     return;
   }
@@ -356,21 +357,14 @@ static void seq_update_meta_disp_range(Editing *ed)
   LISTBASE_FOREACH_BACKWARD (MetaStack *, ms, &ed->metastack) {
     /* Update ms->disp_range from meta. */
     if (ms->disp_range[0] == ms->disp_range[1]) {
-      copy_v2_v2_int(ms->disp_range, &ms->parseq->startdisp);
+      ms->disp_range[0] = SEQ_time_left_handle_frame_get(ms->parseq);
+      ms->disp_range[1] = SEQ_time_right_handle_frame_get(ms->parseq);
     }
 
     /* Update meta strip endpoints. */
-    SEQ_time_left_handle_frame_set(ms->parseq, ms->disp_range[0]);
-    SEQ_time_right_handle_frame_set(ms->parseq, ms->disp_range[1]);
-    SEQ_transform_fix_single_image_seq_offsets(ms->parseq);
-
-    /* Recalculate effects using meta strip. */
-    LISTBASE_FOREACH (Sequence *, seq, ms->oldbasep) {
-      if (seq->seq2) {
-        seq->start = seq->startdisp = max_ii(seq->seq1->startdisp, seq->seq2->startdisp);
-        seq->enddisp = min_ii(seq->seq1->enddisp, seq->seq2->enddisp);
-      }
-    }
+    SEQ_time_left_handle_frame_set(scene, ms->parseq, ms->disp_range[0]);
+    SEQ_time_right_handle_frame_set(scene, ms->parseq, ms->disp_range[1]);
+    SEQ_transform_fix_single_image_seq_offsets(scene, ms->parseq);
 
     /* Ensure that active seqbase points to active meta strip seqbase. */
     MetaStack *active_ms = SEQ_meta_stack_active_get(ed);
@@ -647,7 +641,7 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports))
 
   if (!MAIN_VERSION_ATLEAST(bmain, 293, 16)) {
     LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
-      seq_update_meta_disp_range(SEQ_editing_get(scene));
+      seq_update_meta_disp_range(scene);
     }
 
     /* Add a separate socket for Grid node X and Y size. */
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index fa6b0571326..98c860792b2 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -405,7 +405,9 @@ static void do_versions_sequencer_speed_effect_recursive(Scene *scene, const Lis
           v->speed_control_type = SEQ_SPEED_MULTIPLY;
           v->speed_fader = globalSpeed *
                            ((float)seq->seq1->len /
-                            max_ff((float)(seq->seq1->enddisp - seq->seq1->start), 1.0f));
+                            max_ff((float)(SEQ_time_right_handle_frame_get(seq->seq1) -
+                                           seq->seq1->start),
+                                   1.0f));
         }
       }
       else if (v->flags & SEQ_SPEED_INTEGRATE) {
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index 10c6e828e96..ddd9286e6f8 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -191,10 +191,11 @@ static int sequencer_generic_invoke_xy_guess_channel(bContext *C, int type)
   }
 
   for (seq = ed->seqbasep->first; seq; seq = seq->next) {
-    if ((ELEM(type, -1, seq->type)) && (seq->enddisp < timeline_frame) &&
-        (timeline_frame - seq->enddisp < proximity)) {
+    const int strip_end = SEQ_time_right_handle_frame_get(seq);
+    if ((ELEM(type, -1, seq->type)) && (strip_end < timeline_frame) &&
+        (timeline_frame - strip_end < proximity)) {
       tgt = seq;
-      proximity = timeline_frame - seq->enddisp;
+      proximity = timeline_frame - strip_end;
     }
   }
 
@@ -793,9 +794,8 @@ static void sequencer_add_movie_clamp_sound_strip_length(Scene *scene,
     return;
   }
 
-  SEQ_time_right_handle_frame_set(seq_sound, SEQ_time_right_handle_frame_get(seq_movie));
-  SEQ_time_left_handle_frame_set(seq_sound, SEQ_time_left_handle_frame_get(seq_movie));
-  SEQ_time_update_sequence(scene, seqbase, seq_sound);
+  SEQ_time_right_handle_frame_set(scene, seq_sound, SEQ_time_right_handle_frame_get(seq_movie));
+  SEQ_time_left_handle_frame_set(scene, seq_sound, SEQ_time_left_handle_frame_get(seq_movie));
 }
 
 static void sequencer_add_movie_multiple_strips(bContext *C,
@@ -842,7 +842,8 @@ static void sequencer_add_movie_multiple_strips(bContext *C,
         }
       }
 
-      load_data->start_frame += seq_movie->enddisp - seq_movie->startdisp;
+      load_data->start_frame += SEQ_time_right_handle_frame_get(seq_movie) -
+                                SEQ_time_left_handle_frame_get(seq_movie);
       if (overlap_shuffle_override) {
         has_seq_overlap |= seq_load_apply_generic_options_only_test_overlap(
             C, op, seq_sound, strip_col);
@@ -1073,7 +1074,8 @@ static void sequencer_add_sound_multiple_strips(bContext *C,
     }
     else {
       seq_load_apply_generic_options(C, op, seq);
-      load_data->start_frame += seq->enddisp - seq->startdisp;
+      load_data->start_frame += SEQ_time_right_handle_frame_get(seq) -
+                                SEQ_time_left_handle_frame_get(seq);
     }
   }
   RNA_END;
@@ -1300,8 +1302,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
 
   /* Adjust length. */
   if (load_data.image.len == 1) {
-    SEQ_time_right_handle_frame_set(seq, load_data.image.end_frame);
-    SEQ_time_update_sequence(scene, SEQ_active_seqbase_get(ed), seq);
+    SEQ_time_right_handle_frame_set(scene, seq, load_data.image.end_frame);
   }
 
   seq_load_apply_generic_options(C, op, seq);
diff --git a/source/blender/editors/space_sequencer/sequencer_drag_drop.c b/source/blender/editors/space_sequencer/sequencer_drag_drop.c
index 645c0dc9a1d..8dadb9360e3 100644
--- a/source/blender/editors/space_sequencer/sequencer_drag_drop.c
+++ b/source/blender/editors/space_sequencer/sequencer_drag_drop.c
@@ -231,9 +231,8 @@ static void update_overlay_strip_poistion_data(bContext *C, const int mval[2])
   else {
     /* Check if there is a strip tha

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list