[Bf-blender-cvs] [e49bf4019b4] master: Cleanup: VSE animation handling

Richard Antalik noreply at git.blender.org
Wed Jan 19 14:19:44 CET 2022


Commit: e49bf4019b498be42b9a39657604ad750a99bbea
Author: Richard Antalik
Date:   Wed Jan 19 14:12:23 2022 +0100
Branches: master
https://developer.blender.org/rBe49bf4019b498be42b9a39657604ad750a99bbea

Cleanup: VSE animation handling

- Move functions that handle animation to own file - `animation.c`
- Refactor `SEQ_offset_animdata` and `SEQ_free_animdata` functions
- Add function `SEQ_fcurves_by_strip_get` to provide more granular
  and explicit way for operators to handle animation
- Remove function `SEQ_dupe_animdata`, do curve duplication explicitly
  in operator code, which makes more sense to do. Further this function
  was also used for renaming strips which makes no sense.
- Refactor usage of function `SEQ_free_animdata` and remove XXX comment.
  Now this functiuon is no longer called when `Sequence` data is freed
  implicitly, it is done explicitly in high level function
  `SEQ_edit_remove_flagged_sequences`

Reviewed By: sergey

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

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

M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_sequencer/sequencer_thumbnails.c
M	source/blender/editors/transform/transform_convert_sequencer.c
M	source/blender/sequencer/CMakeLists.txt
A	source/blender/sequencer/SEQ_animation.h
M	source/blender/sequencer/SEQ_sequencer.h
A	source/blender/sequencer/intern/animation.c
M	source/blender/sequencer/intern/clipboard.c
M	source/blender/sequencer/intern/proxy.c
M	source/blender/sequencer/intern/sequencer.c
M	source/blender/sequencer/intern/sequencer.h
M	source/blender/sequencer/intern/strip_edit.c
M	source/blender/sequencer/intern/strip_transform.c
M	source/blender/sequencer/intern/utils.c

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

diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index d43ff38edf9..7203c31d7ed 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -39,6 +39,7 @@
 #include "DNA_sound_types.h"
 
 #include "BKE_context.h"
+#include "BKE_fcurve.h"
 #include "BKE_global.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
@@ -46,6 +47,7 @@
 #include "BKE_sound.h"
 
 #include "SEQ_add.h"
+#include "SEQ_animation.h"
 #include "SEQ_clipboard.h"
 #include "SEQ_edit.h"
 #include "SEQ_effects.h"
@@ -66,6 +68,7 @@
 #include "RNA_enum_types.h"
 
 /* For menu, popup, icons, etc. */
+#include "ED_keyframing.h"
 #include "ED_numinput.h"
 #include "ED_outliner.h"
 #include "ED_screen.h"
@@ -1655,6 +1658,35 @@ void SEQUENCER_OT_split(struct wmOperatorType *ot)
 /** \name Duplicate Strips Operator
  * \{ */
 
+static void sequencer_backup_original_animation(Scene *scene, ListBase *list)
+{
+  if (scene->adt == NULL || scene->adt->action == NULL ||
+      BLI_listbase_is_empty(&scene->adt->action->curves)) {
+    return;
+  }
+
+  BLI_movelisttolist(list, &scene->adt->action->curves);
+}
+
+static void sequencer_restore_original_animation(Scene *scene, ListBase *list)
+{
+  if (scene->adt == NULL || scene->adt->action == NULL || BLI_listbase_is_empty(list)) {
+    return;
+  }
+
+  BLI_movelisttolist(&scene->adt->action->curves, list);
+}
+
+static void sequencer_duplicate_animation(Scene *scene, Sequence *seq, ListBase *curves_backup)
+{
+  GSet *fcurves = SEQ_fcurves_by_strip_get(seq, curves_backup);
+  GSET_FOREACH_BEGIN (FCurve *, fcu, fcurves) {
+    FCurve *fcu_cpy = BKE_fcurve_copy(fcu);
+    BLI_addtail(&scene->adt->action->curves, fcu_cpy);
+  }
+  GSET_FOREACH_END();
+}
+
 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
 {
   Scene *scene = CTX_data_scene(C);
@@ -1665,32 +1697,44 @@ static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
   }
 
   Sequence *active_seq = SEQ_select_active_get(scene);
-  ListBase duplicated = {NULL, NULL};
+  ListBase duplicated_strips = {NULL, NULL};
 
-  SEQ_sequence_base_dupli_recursive(scene, scene, &duplicated, ed->seqbasep, 0, 0);
+  SEQ_sequence_base_dupli_recursive(scene, scene, &duplicated_strips, ed->seqbasep, 0, 0);
   ED_sequencer_deselect_all(scene);
 
-  if (duplicated.first) {
-    Sequence *seq = duplicated.first;
-    /* Rely on the nseqbase list being added at the end.
-     * Their UUIDs has been re-generated by the SEQ_sequence_base_dupli_recursive(), */
-    BLI_movelisttolist(ed->seqbasep, &duplicated);
-
-    /* Handle duplicated strips: set active, select, ensure unique name and duplicate animation
-     * data. */
-    for (; seq; seq = seq->next) {
-      if (active_seq != NULL && STREQ(seq->name, active_seq->name)) {
-        SEQ_select_active_set(scene, seq);
-      }
-      seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL + SEQ_LOCK);
-      SEQ_ensure_unique_name(seq, scene);
-    }
+  if (duplicated_strips.first == NULL) {
+    return OPERATOR_CANCELLED;
+  }
 
-    WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
-    return OPERATOR_FINISHED;
+  /* Duplicate animation.
+   * First backup original curves from scene and duplicate strip curves from backup into scene.
+   * This way, when pasted strips are renamed, curves are renamed with them. Finally, restore
+   * original curves from backup.
+   */
+  ListBase fcurves_original_backup = {NULL, NULL};
+  sequencer_backup_original_animation(scene, &fcurves_original_backup);
+
+  Sequence *seq = duplicated_strips.first;
+
+  /* Rely on the nseqbase list being added at the end.
+   * Their UUIDs has been re-generated by the SEQ_sequence_base_dupli_recursive(), */
+  BLI_movelisttolist(ed->seqbasep, &duplicated_strips);
+
+  /* Handle duplicated strips: set active, select, ensure unique name and duplicate animation
+   * data. */
+  for (; seq; seq = seq->next) {
+    if (active_seq != NULL && STREQ(seq->name, active_seq->name)) {
+      SEQ_select_active_set(scene, seq);
+    }
+    seq->flag &= ~(SEQ_LEFTSEL + SEQ_RIGHTSEL + SEQ_LOCK);
+    sequencer_duplicate_animation(scene, seq, &fcurves_original_backup);
+    SEQ_ensure_unique_name(seq, scene);
   }
 
-  return OPERATOR_CANCELLED;
+  sequencer_restore_original_animation(scene, &fcurves_original_backup);
+
+  WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
+  return OPERATOR_FINISHED;
 }
 
 void SEQUENCER_OT_duplicate(wmOperatorType *ot)
@@ -1905,7 +1949,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
       }
 
       seq_next = seq->next;
-      SEQ_sequence_free(scene, seq, true);
+      SEQ_edit_flag_for_removal(scene, seqbase, seq);
       seq = seq_next;
     }
     else {
@@ -1913,6 +1957,8 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
     }
   }
 
+  SEQ_edit_remove_flagged_sequences(scene, seqbase);
+
   SEQ_sort(seqbase);
 
   WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
@@ -2542,6 +2588,14 @@ static int sequencer_paste_exec(bContext *C, wmOperator *op)
     ofs = scene->r.cfra - min_seq_startdisp;
   }
 
+  /* Paste animation.
+   * First backup original curves from scene and duplicate strip curves from backup into scene.
+   * This way, when pasted strips are renamed, curves are renamed with them. Finally, restore
+   * original curves from backup.
+   */
+  ListBase fcurves_original_backup = {NULL, NULL};
+  sequencer_backup_original_animation(scene, &fcurves_original_backup);
+
   /* Copy strips, temporarily restoring pointers to actual data-blocks. This
    * must happen on the clipboard itself, so that copying does user counting
    * on the actual data-blocks. */
@@ -2560,6 +2614,8 @@ static int sequencer_paste_exec(bContext *C, wmOperator *op)
       SEQ_select_active_set(scene, iseq);
     }
 
+    sequencer_duplicate_animation(scene, iseq, &fcurves_original_backup);
+
     /* Make sure, that pasted strips have unique names. */
     SEQ_ensure_unique_name(iseq, scene);
     /* Translate after name has been changed, otherwise this will affect animdata of original
@@ -2571,6 +2627,8 @@ static int sequencer_paste_exec(bContext *C, wmOperator *op)
     }
   }
 
+  sequencer_restore_original_animation(scene, &fcurves_original_backup);
+
   DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
   DEG_relations_tag_update(bmain);
   WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
diff --git a/source/blender/editors/space_sequencer/sequencer_thumbnails.c b/source/blender/editors/space_sequencer/sequencer_thumbnails.c
index c6fecdb1fc6..82ba17d4db1 100644
--- a/source/blender/editors/space_sequencer/sequencer_thumbnails.c
+++ b/source/blender/editors/space_sequencer/sequencer_thumbnails.c
@@ -66,7 +66,7 @@ typedef struct ThumbDataItem {
 static void thumbnail_hash_data_free(void *val)
 {
   ThumbDataItem *item = val;
-  SEQ_sequence_free(item->scene, item->seq_dupli, 0);
+  SEQ_sequence_free(item->scene, item->seq_dupli);
   MEM_freeN(val);
 }
 
diff --git a/source/blender/editors/transform/transform_convert_sequencer.c b/source/blender/editors/transform/transform_convert_sequencer.c
index 2244f82509f..01eae36e846 100644
--- a/source/blender/editors/transform/transform_convert_sequencer.c
+++ b/source/blender/editors/transform/transform_convert_sequencer.c
@@ -34,6 +34,7 @@
 
 #include "ED_markers.h"
 
+#include "SEQ_animation.h"
 #include "SEQ_edit.h"
 #include "SEQ_effects.h"
 #include "SEQ_iterator.h"
diff --git a/source/blender/sequencer/CMakeLists.txt b/source/blender/sequencer/CMakeLists.txt
index eccc336141a..54524e453d4 100644
--- a/source/blender/sequencer/CMakeLists.txt
+++ b/source/blender/sequencer/CMakeLists.txt
@@ -46,6 +46,7 @@ set(INC_SYS
 
 set(SRC
   SEQ_add.h
+  SEQ_animation.h
   SEQ_clipboard.h
   SEQ_edit.h
   SEQ_effects.h
@@ -62,6 +63,7 @@ set(SRC
   SEQ_transform.h
   SEQ_utils.h
 
+  intern/animation.c
   intern/clipboard.c
   intern/disk_cache.c
   intern/disk_cache.h
diff --git a/source/blender/sequencer/intern/sequencer.h b/source/blender/sequencer/SEQ_animation.h
similarity index 70%
copy from source/blender/sequencer/intern/sequencer.h
copy to source/blender/sequencer/SEQ_animation.h
index aff81255d7d..028f932344f 100644
--- a/source/blender/sequencer/intern/sequencer.h
+++ b/source/blender/sequencer/SEQ_animation.h
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2004 Blender Foundation.
+ * The Original Code is Copyright (C) 2022 Blender Foundation.
  * All rights reserved.
  */
 
@@ -27,17 +27,14 @@
 extern "C" {
 #endif
 
+struct GSet;
+struct ListBase;
 struct Scene;
 struct Sequence;
 
-/**
- * Cache must be freed before calling this function
- * since it leaves the seqbase in an invalid state.
- */
-void seq_free_sequence_recurse(struct Scene *scene,
-                               struct Sequence *seq,
-                               bool do_id_user,
-                               bool do_clean_animdata);
+void SEQ_free_animdata(struct Scene *scene, struct Sequence *seq);
+void SEQ_offset_animdata(struct Scene *scene, struct Sequence *seq, int ofs);
+struct GSet *SEQ_fcurves_by_strip_get(const struct Sequence *seq, struct ListBase *fcurve_base);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/sequencer/SEQ_sequencer.h b/source/blender/sequencer/SEQ_sequencer.h
index 1229f6f7bea..2e340049dbd 100644
--- a/source/blender/sequencer/SEQ_sequencer.h
+++ b/source/blender/sequencer/SEQ_sequencer.h
@@ -84,7 +84,7 @@ struct ListBase *SEQ_active_seqbase_get(const struct Editing *ed);
  */
 void SEQ_seqbase_active_set(struct Editing *ed, struct ListBase *seqbase);
 struct Sequence *SEQ_sequence_alloc(ListBase *lb, int timeline_frame, int machine, int type);
-void SEQ_sequence_free(struct Scene *scene, struct Sequence *seq, bool do_clean_animdata);
+void SEQ_sequence_free(struct Scene *scene, struct Sequence *seq);
 /**
  * Create and initialize #MetaStack, append it to `ed->metastack` ListBase
  *
@@ -107,8 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list