diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2022-05-16 20:46:20 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2022-05-16 20:46:20 +0300 |
commit | be84fe4ce1d8521ec91aa8bd6f56e9cdf4f7d8fe (patch) | |
tree | c8c1197f173c35441f500f89e330ae439422e969 /source | |
parent | 205c6d8d0853ada1c3d087b31bb2bec42d5597f1 (diff) |
VSE: Add new Scene and Strip
This operator allows to add a new scene at the same time that the strip. This is very handy for storyboarding.
Reviewed By: ISS
Maniphest Tasks: T97678
Differential Revision: https://developer.blender.org/D14790
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_scene.h | 5 | ||||
-rw-r--r-- | source/blender/editors/scene/scene_edit.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_add.c | 119 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_ops.c | 1 |
5 files changed, 136 insertions, 2 deletions
diff --git a/source/blender/editors/include/ED_scene.h b/source/blender/editors/include/ED_scene.h index f1a2e5795ee..f67bdb9c1d7 100644 --- a/source/blender/editors/include/ED_scene.h +++ b/source/blender/editors/include/ED_scene.h @@ -18,6 +18,11 @@ struct Scene *ED_scene_add(struct Main *bmain, struct bContext *C, struct wmWindow *win, enum eSceneCopyMethod method) ATTR_NONNULL(); +/** Special mode for adding a scene assigned to sequencer strip. */ +struct Scene *ED_scene_sequencer_add(struct Main *bmain, + struct bContext *C, + enum eSceneCopyMethod method, + const bool assign_strip); /** * \note Only call outside of area/region loops. * \return true if successful. diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c index a13177942a8..57a9e6be917 100644 --- a/source/blender/editors/scene/scene_edit.c +++ b/source/blender/editors/scene/scene_edit.c @@ -67,7 +67,10 @@ static Scene *scene_add(Main *bmain, Scene *scene_old, eSceneCopyMethod method) } /** Add a new scene in the sequence editor. */ -static Scene *ED_scene_sequencer_add(Main *bmain, bContext *C, eSceneCopyMethod method) +Scene *ED_scene_sequencer_add(Main *bmain, + bContext *C, + eSceneCopyMethod method, + const bool assign_strip) { Sequence *seq = NULL; Scene *scene_active = CTX_data_scene(C); @@ -88,6 +91,11 @@ static Scene *ED_scene_sequencer_add(Main *bmain, bContext *C, eSceneCopyMethod Scene *scene_new = scene_add(bmain, scene_strip, method); + /* If don't need assign the scene to the strip, nothing else to do. */ + if (!assign_strip) { + return scene_new; + } + /* As the scene is created in sequencer, do not set the new scene as active. * This is useful for story-boarding where we want to keep actual scene active. * The new scene is linked to the active strip and the viewport updated. */ @@ -291,7 +299,7 @@ static int scene_new_sequencer_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); int type = RNA_enum_get(op->ptr, "type"); - if (ED_scene_sequencer_add(bmain, C, type) == NULL) { + if (ED_scene_sequencer_add(bmain, C, type, true) == NULL) { return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 469169cf4cc..fb5983dcf76 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -31,6 +31,7 @@ #include "BKE_mask.h" #include "BKE_movieclip.h" #include "BKE_report.h" +#include "BKE_scene.h" #include "BKE_sound.h" #include "IMB_imbuf.h" @@ -54,6 +55,7 @@ #include "SEQ_transform.h" #include "SEQ_utils.h" +#include "ED_scene.h" /* For menu, popup, icons, etc. */ #include "ED_screen.h" #include "ED_sequencer.h" @@ -469,6 +471,123 @@ void SEQUENCER_OT_scene_strip_add(struct wmOperatorType *ot) ot->prop = prop; } +static EnumPropertyItem strip_new_scene_items[] = { + {SCE_COPY_NEW, "NEW", 0, "New", "Add new Strip with a new empty Scene with default settings"}, + {SCE_COPY_EMPTY, + "EMPTY", + 0, + "Copy Settings", + "Add a new Strip, with an empty scene, and copy settings from the current scene"}, + {SCE_COPY_LINK_COLLECTION, + "LINK_COPY", + 0, + "Linked Copy", + "Add a Strip and link in the collections from the current scene (shallow copy)"}, + {SCE_COPY_FULL, + "FULL_COPY", + 0, + "Full Copy", + "Add a Strip and make a full copy of the current scene"}, + {0, NULL, 0, NULL, NULL}, +}; + +static int sequencer_add_scene_strip_new_exec(bContext *C, wmOperator *op) +{ + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + const Editing *ed = SEQ_editing_ensure(scene); + + if (RNA_boolean_get(op->ptr, "replace_sel")) { + ED_sequencer_deselect_all(scene); + } + + SeqLoadData load_data; + load_data_init_from_operator(&load_data, C, op); + + int type = RNA_enum_get(op->ptr, "type"); + Scene *scene_new = ED_scene_sequencer_add(bmain, C, type, false); + if (scene_new == NULL) { + return OPERATOR_CANCELLED; + } + load_data.scene = scene_new; + + Sequence *seq = SEQ_add_scene_strip(scene, ed->seqbasep, &load_data); + seq_load_apply_generic_options(C, op, seq); + + 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); + + return OPERATOR_FINISHED; +} + +static int sequencer_add_scene_strip_new_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + sequencer_disable_one_time_properties(C, op); + sequencer_generic_invoke_xy__internal(C, op, 0, SEQ_TYPE_SCENE); + return sequencer_add_scene_strip_new_exec(C, op); +} + +static const EnumPropertyItem *strip_new_sequencer_enum_itemf(bContext *C, + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + EnumPropertyItem *item = NULL; + int totitem = 0; + uint item_index; + + item_index = RNA_enum_from_value(strip_new_scene_items, SCE_COPY_NEW); + RNA_enum_item_add(&item, &totitem, &strip_new_scene_items[item_index]); + + bool has_scene_or_no_context = false; + if (C == NULL) { + /* For documentation generation. */ + has_scene_or_no_context = true; + } + else { + Scene *scene = CTX_data_scene(C); + Sequence *seq = SEQ_select_active_get(scene); + if ((seq && (seq->type == SEQ_TYPE_SCENE) && (seq->scene != NULL))) { + has_scene_or_no_context = true; + } + } + + if (has_scene_or_no_context) { + int values[] = {SCE_COPY_EMPTY, SCE_COPY_LINK_COLLECTION, SCE_COPY_FULL}; + for (int i = 0; i < ARRAY_SIZE(values); i++) { + item_index = RNA_enum_from_value(strip_new_scene_items, values[i]); + RNA_enum_item_add(&item, &totitem, &strip_new_scene_items[item_index]); + } + } + + RNA_enum_item_end(&item, &totitem); + *r_free = true; + return item; +} + +void SEQUENCER_OT_scene_strip_add_new(struct wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Add Strip with a new Scene"; + ot->idname = "SEQUENCER_OT_scene_strip_add_new"; + ot->description = "Create a new Strip and add a assign a new Scene as source"; + + /* Api callbacks. */ + ot->invoke = sequencer_add_scene_strip_new_invoke; + ot->exec = sequencer_add_scene_strip_new_exec; + ot->poll = ED_operator_sequencer_active_editable; + + /* Flags. */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); + + ot->prop = RNA_def_enum(ot->srna, "type", strip_new_scene_items, SCE_COPY_NEW, "Type", ""); + RNA_def_enum_funcs(ot->prop, strip_new_sequencer_enum_itemf); + RNA_def_property_flag(ot->prop, PROP_ENUM_NO_TRANSLATE); +} + static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index fd08fad94cb..3307c3fde2f 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -232,6 +232,7 @@ void SEQUENCER_OT_select_grouped(struct wmOperatorType *ot); /* sequencer_add.c */ void SEQUENCER_OT_scene_strip_add(struct wmOperatorType *ot); +void SEQUENCER_OT_scene_strip_add_new(struct wmOperatorType *ot); void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot); void SEQUENCER_OT_movieclip_strip_add(struct wmOperatorType *ot); void SEQUENCER_OT_mask_strip_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index 88a46035225..f7a9bcf41e6 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -82,6 +82,7 @@ void sequencer_operatortypes(void) /* sequencer_add.c */ WM_operatortype_append(SEQUENCER_OT_scene_strip_add); + WM_operatortype_append(SEQUENCER_OT_scene_strip_add_new); WM_operatortype_append(SEQUENCER_OT_movieclip_strip_add); WM_operatortype_append(SEQUENCER_OT_mask_strip_add); WM_operatortype_append(SEQUENCER_OT_movie_strip_add); |