diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:10:42 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:10:42 +0300 |
commit | 58d6cbba6da31db8dc8a2b42d528b9a353081904 (patch) | |
tree | 04b57a2f809c6f08d84a082edf061f3ece631860 /source/blender/editors/space_sequencer/sequencer_add.c | |
parent | 94549adec4b6857fb6ec4cf77606da51ff7c26b7 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-setopstemp-ghash-setops
Diffstat (limited to 'source/blender/editors/space_sequencer/sequencer_add.c')
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_add.c | 190 |
1 files changed, 176 insertions, 14 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 38a01bcd78c..86d1fe71ade 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <math.h> #include <string.h> +#include <ctype.h> #include "MEM_guardedalloc.h" @@ -60,6 +61,7 @@ #include "ED_screen.h" #include "ED_sequencer.h" +#include "UI_interface.h" #include "BKE_sound.h" @@ -70,6 +72,10 @@ /* own include */ #include "sequencer_intern.h" +typedef struct SequencerAddData { + ImageFormatData im_format; +} SequencerAddData; + /* Generic functions, reused by add strip operators */ /* avoid passing multiple args and be more verbose */ @@ -222,6 +228,19 @@ static void seq_load_operator_info(SeqLoadInfo *seq_load, wmOperator *op) } RNA_PROP_END; } + + if ((prop = RNA_struct_find_property(op->ptr, "use_multiview")) && RNA_property_boolean_get(op->ptr, prop)) { + if (op->customdata) { + SequencerAddData *sad = op->customdata; + ImageFormatData *imf = &sad->im_format; + + seq_load->views_format = imf->views_format; + seq_load->flag |= SEQ_USE_VIEWS; + + /* operator custom data is always released after the SeqLoadInfo, no need to handle the memory here */ + seq_load->stereo3d_format = &imf->stereo3d_format; + } + } } /** @@ -287,7 +306,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) BLI_strncpy(seq->name + 2, sce_seq->id.name + 2, sizeof(seq->name) - 2); BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq); - seq->scene_sound = sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + seq->len, 0); + seq->scene_sound = BKE_sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + seq->len, 0); BKE_sequence_calc_disp(scene, seq); BKE_sequencer_sort(scene); @@ -573,6 +592,9 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad return OPERATOR_CANCELLED; } + if (op->customdata) + MEM_freeN(op->customdata); + BKE_sequencer_sort(scene); BKE_sequencer_update_muting(ed); @@ -581,15 +603,40 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad return OPERATOR_FINISHED; } +/* add sequencer operators */ +static void sequencer_add_init(bContext *UNUSED(C), wmOperator *op) +{ + op->customdata = MEM_callocN(sizeof(SequencerAddData), __func__); +} + +static void sequencer_add_cancel(bContext *UNUSED(C), wmOperator *op) +{ + if (op->customdata) + MEM_freeN(op->customdata); + op->customdata = NULL; +} + +static bool sequencer_add_draw_check_prop(PointerRNA *UNUSED(ptr), PropertyRNA *prop) +{ + const char *prop_id = RNA_property_identifier(prop); + + return !(STREQ(prop_id, "filepath") || + STREQ(prop_id, "directory") || + STREQ(prop_id, "filename") + ); +} + /* add movie operator */ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) { return sequencer_add_generic_strip_exec(C, op, BKE_sequencer_add_movie_strip); } - static int sequencer_add_movie_strip_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + PropertyRNA *prop; + Scene *scene = CTX_data_scene(C); + /* This is for drag and drop */ if ((RNA_struct_property_is_set(op->ptr, "files") && RNA_collection_length(op->ptr, "files")) || RNA_struct_property_is_set(op->ptr, "filepath")) @@ -599,13 +646,37 @@ static int sequencer_add_movie_strip_invoke(bContext *C, wmOperator *op, const w } sequencer_generic_invoke_xy__internal(C, op, 0, SEQ_TYPE_MOVIE); - + + sequencer_add_init(C, op); + + /* show multiview save options only if scene has multiviews */ + prop = RNA_struct_find_property(op->ptr, "show_multiview"); + RNA_property_boolean_set(op->ptr, prop, (scene->r.scemode & R_MULTIVIEW) != 0); + WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; //return sequencer_add_movie_strip_exec(C, op); } +static void sequencer_add_draw(bContext *UNUSED(C), wmOperator *op) +{ + uiLayout *layout = op->layout; + SequencerAddData *sad = op->customdata; + ImageFormatData *imf = &sad->im_format; + PointerRNA imf_ptr, ptr; + + /* main draw call */ + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + uiDefAutoButsRNA(layout, &ptr, sequencer_add_draw_check_prop, '\0'); + + /* image template */ + RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr); + + /* multiview template */ + if (RNA_boolean_get(op->ptr, "show_multiview")) + uiTemplateImageFormatViews(layout, &imf_ptr, op->ptr); +} void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) { @@ -618,9 +689,11 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = sequencer_add_movie_strip_invoke; ot->exec = sequencer_add_movie_strip_exec; + ot->cancel = sequencer_add_cancel; + ot->ui = sequencer_add_draw; ot->poll = ED_operator_sequencer_active_editable; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -679,11 +752,74 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot) RNA_def_boolean(ot->srna, "cache", false, "Cache", "Cache the sound in memory"); } +int sequencer_image_seq_get_minmax_frame(wmOperator *op, int sfra, int *r_minframe, int *r_numdigits) +{ + int minframe = INT32_MAX, maxframe = INT32_MIN; + int numdigits = 0; + + RNA_BEGIN (op->ptr, itemptr, "files") + { + char *filename; + int frame; + /* just get the first filename */ + filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); + + if (filename) { + if (BLI_path_frame_get(filename, &frame, &numdigits)) { + minframe = min_ii(minframe, frame); + maxframe = max_ii(maxframe, frame); + } + + MEM_freeN(filename); + } + } + RNA_END; + + if (minframe == INT32_MAX) { + minframe = sfra; + maxframe = minframe + 1; + } + + *r_minframe = minframe; + *r_numdigits = numdigits; + + return maxframe - minframe + 1; +} + +void sequencer_image_seq_reserve_frames(wmOperator *op, StripElem *se, int len, int minframe, int numdigits) +{ + int i; + char *filename = NULL; + RNA_BEGIN (op->ptr, itemptr, "files") + { + /* just get the first filename */ + filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); + break; + } + RNA_END; + + if (filename) { + char ext[PATH_MAX]; + char filename_stripped[PATH_MAX]; + /* strip the frame from filename and substitute with # */ + BLI_path_frame_strip(filename, true, ext); + + for (i = 0; i < len; i++, se++) { + BLI_strncpy(filename_stripped, filename, sizeof(filename_stripped)); + BLI_path_frame(filename_stripped, minframe + i, numdigits); + BLI_snprintf(se->name, sizeof(se->name), "%s%s", filename_stripped, ext); + } + + MEM_freeN(filename); + } +} + + /* add image operator */ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) { + int minframe, numdigits; /* cant use the generic function for this */ - Scene *scene = CTX_data_scene(C); /* only for sound */ Editing *ed = BKE_sequencer_editing_get(scene, true); SeqLoadInfo seq_load; @@ -691,11 +827,17 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) Strip *strip; StripElem *se; + const bool use_placeholders = RNA_boolean_get(op->ptr, "use_placeholders"); seq_load_operator_info(&seq_load, op); /* images are unique in how they handle this - 1 per strip elem */ - seq_load.len = RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files")); + if (use_placeholders) { + seq_load.len = sequencer_image_seq_get_minmax_frame(op, seq_load.start_frame, &minframe, &numdigits); + } + else { + seq_load.len = RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files")); + } if (seq_load.len == 0) return OPERATOR_CANCELLED; @@ -703,20 +845,24 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) if (seq_load.flag & SEQ_LOAD_REPLACE_SEL) ED_sequencer_deselect_all(scene); - /* main adding function */ seq = BKE_sequencer_add_image_strip(C, ed->seqbasep, &seq_load); strip = seq->strip; se = strip->stripdata; - RNA_BEGIN (op->ptr, itemptr, "files") - { - char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); - BLI_strncpy(se->name, filename, sizeof(se->name)); - MEM_freeN(filename); - se++; + if (use_placeholders) { + sequencer_image_seq_reserve_frames(op, se, seq_load.len, minframe, numdigits); + } + else { + RNA_BEGIN (op->ptr, itemptr, "files") + { + char *filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); + BLI_strncpy(se->name, filename, sizeof(se->name)); + MEM_freeN(filename); + se++; + } + RNA_END; } - RNA_END; if (seq_load.len == 1) { if (seq_load.start_frame < seq_load.end_frame) { @@ -735,6 +881,9 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) sequencer_add_apply_overlap(C, op, seq); + if (op->customdata) + MEM_freeN(op->customdata); + WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -742,6 +891,9 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) static int sequencer_add_image_strip_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + PropertyRNA *prop; + Scene *scene = CTX_data_scene(C); + /* drag drop has set the names */ if (RNA_struct_property_is_set(op->ptr, "files") && RNA_collection_length(op->ptr, "files")) { sequencer_generic_invoke_xy__internal(C, op, SEQPROP_ENDFRAME | SEQPROP_NOPATHS, SEQ_TYPE_IMAGE); @@ -750,6 +902,12 @@ static int sequencer_add_image_strip_invoke(bContext *C, wmOperator *op, const w sequencer_generic_invoke_xy__internal(C, op, SEQPROP_ENDFRAME, SEQ_TYPE_IMAGE); + sequencer_add_init(C, op); + + /* show multiview save options only if scene has multiviews */ + prop = RNA_struct_find_property(op->ptr, "show_multiview"); + RNA_property_boolean_set(op->ptr, prop, (scene->r.scemode & R_MULTIVIEW) != 0); + WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL; } @@ -766,6 +924,8 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = sequencer_add_image_strip_invoke; ot->exec = sequencer_add_image_strip_exec; + ot->cancel = sequencer_add_cancel; + ot->ui = sequencer_add_draw; ot->poll = ED_operator_sequencer_active_editable; @@ -775,6 +935,8 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot) WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME | SEQPROP_ENDFRAME); + + RNA_def_boolean(ot->srna, "use_placeholders", false, "Use Placeholders", "Use placeholders for missing frames of the strip"); } |