diff options
author | Richard Antalik <richardantalik@gmail.com> | 2022-01-19 16:12:23 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2022-01-19 16:12:23 +0300 |
commit | e49bf4019b498be42b9a39657604ad750a99bbea (patch) | |
tree | 3694759dab31e9fa63801c3bd939525dc1af8645 /source/blender/editors | |
parent | 17882988042e3b8adeffbc2072a5a457cb6efb52 (diff) |
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
Diffstat (limited to 'source/blender/editors')
3 files changed, 81 insertions, 22 deletions
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" |