- duplicating a scene now duplicates its sequence strips too.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 25 Jun 2010 12:04:04 +0000 (12:04 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 25 Jun 2010 12:04:04 +0000 (12:04 +0000)
- bugfix for copying a scene with FFMPEG properties set (wasnt copying the ID properties, could crash blender)
- relative path option for adding sequence strips and replaceing images.

source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_sequencer/sequencer_edit.c

index ad95780..6fe1c2a 100644 (file)
@@ -191,14 +191,14 @@ int shuffle_seq(struct ListBase * seqbasep, struct Sequence *test, struct Scene
 int shuffle_seq_time(ListBase * seqbasep, struct Scene *evil_scene);
 int seqbase_isolated_sel_check(struct ListBase *seqbase);
 void free_imbuf_seq(struct Scene *scene, struct ListBase * seqbasep, int check_mem_usage);
-struct Sequence        *seq_dupli_recursive(struct Scene *scene, struct Sequence * seq);
+struct Sequence        *seq_dupli_recursive(struct Scene *scene, struct Sequence * seq, int dupe_flag);
 int seq_swap(struct Sequence *seq_a, struct Sequence *seq_b);
 
 void seq_update_sound(struct Scene* scene, struct Sequence *seq);
 void seq_update_muting(struct Scene* scene, struct Editing *ed);
 void seqbase_sound_reload(Scene *scene, ListBase *seqbase);
 void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq);
-void seqbase_dupli_recursive(struct Scene *scene, ListBase *nseqbase, ListBase *seqbase, int do_context);
+void seqbase_dupli_recursive(struct Scene *scene, ListBase *nseqbase, ListBase *seqbase, int dupe_flag);
 
 void clear_scene_in_allseqs(struct Scene *sce);
 
@@ -228,6 +228,11 @@ typedef struct SeqLoadInfo {
 #define SEQ_LOAD_MOVIE_SOUND   1<<2
 #define SEQ_LOAD_SOUND_CACHE   1<<3
 
+
+/* seq_dupli' flags */
+#define SEQ_DUPE_UNIQUE_NAME   1<<0
+#define SEQ_DUPE_CONTEXT               1<<1
+
 /* use as an api function */
 typedef struct Sequence *(*SeqLoadFunc)(struct bContext *, ListBase *, struct SeqLoadInfo *);
 
index 6f049df..a2fdf35 100644 (file)
@@ -198,6 +198,10 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
        }
        
+       if(sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
+               scen->r.ffcodecdata.properties= IDP_CopyProperty(scen->r.ffcodecdata.properties);
+       }
+
        /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
         * are done outside of blenkernel with ED_objects_single_users! */
 
@@ -212,6 +216,12 @@ Scene *copy_scene(Main *bmain, Scene *sce, int type)
                        id_us_plus((ID *)scen->world);
                        scen->world= copy_world(scen->world);
                }
+
+               if(sce->ed) {
+                       scen->ed= MEM_callocN( sizeof(Editing), "addseq");
+                       scen->ed->seqbasep= &scen->ed->seqbase;
+                       seqbase_dupli_recursive(sce, &scen->ed->seqbase, &sce->ed->seqbase, 0);
+               }
        }
 
        sound_create_scene(scen);
index f16b169..4241f48 100644 (file)
@@ -3991,7 +3991,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
 
        AUD_SoundInfo info;
 
-       sound = sound_new_file(CTX_data_main(C), seq_load->path);
+       sound = sound_new_file(CTX_data_main(C), seq_load->path); /* handles relative paths */
 
        if (sound==NULL || sound->playback_handle == NULL) {
                //if(op)
@@ -4039,6 +4039,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
 Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load)
 {
        Scene *scene= CTX_data_scene(C); /* only for sound */
+       char path[sizeof(seq_load->path)];
 
        Sequence *seq, *soundseq;       /* generic strip vars */
        Strip *strip;
@@ -4046,7 +4047,10 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
 
        struct anim *an;
 
-       an = openanim(seq_load->path, IB_rect);
+       BLI_strncpy(path, seq_load->path, sizeof(path));
+       BLI_path_abs(path, G.sce);
+
+       an = openanim(path, IB_rect);
 
        if(an==NULL)
                return NULL;
@@ -4088,7 +4092,7 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
 }
 
 
-static Sequence *dupli_seq(struct Scene *scene, Sequence *seq)
+static Sequence *seq_dupli(struct Scene *scene, Sequence *seq, int dupe_flag)
 {
        Sequence *seqn = MEM_dupallocN(seq);
 
@@ -4164,18 +4168,19 @@ static Sequence *dupli_seq(struct Scene *scene, Sequence *seq)
                                                " now...\n");
        }
 
-       seqbase_unique_name_recursive(&scene->ed->seqbase, seqn);
+       if(dupe_flag & SEQ_DUPE_UNIQUE_NAME)
+               seqbase_unique_name_recursive(&scene->ed->seqbase, seqn);
 
        return seqn;
 }
 
-Sequence * seq_dupli_recursive(struct Scene *scene, Sequence * seq)
+Sequence * seq_dupli_recursive(struct Scene *scene, Sequence * seq, int dupe_flag)
 {
-       Sequence * seqn = dupli_seq(scene, seq);
+       Sequence * seqn = seq_dupli(scene, seq, dupe_flag);
        if (seq->type == SEQ_META) {
-               Sequence * s;
+               Sequence *s;
                for(s= seq->seqbase.first; s; s = s->next) {
-                       Sequence *n = seq_dupli_recursive(scene, s);
+                       Sequence *n = seq_dupli_recursive(scene, s, dupe_flag);
                        if (n) {
                                BLI_addtail(&seqn->seqbase, n);
                        }
@@ -4184,7 +4189,7 @@ Sequence * seq_dupli_recursive(struct Scene *scene, Sequence * seq)
        return seqn;
 }
 
-void seqbase_dupli_recursive(Scene *scene, ListBase *nseqbase, ListBase *seqbase, int do_context)
+void seqbase_dupli_recursive(Scene *scene, ListBase *nseqbase, ListBase *seqbase, int dupe_flag)
 {
        Sequence *seq;
        Sequence *seqn = 0;
@@ -4193,18 +4198,18 @@ void seqbase_dupli_recursive(Scene *scene, ListBase *nseqbase, ListBase *seqbase
        for(seq= seqbase->first; seq; seq= seq->next) {
                seq->tmp= NULL;
                if(seq->flag & SELECT) {
-                       seqn = dupli_seq(scene, seq);
+                       seqn = seq_dupli(scene, seq, dupe_flag);
                        if (seqn) { /*should never fail */
-                               if(do_context) {
+                               if(dupe_flag & SEQ_DUPE_CONTEXT) {
                                        seq->flag &= ~SEQ_ALLSEL;
                                        seqn->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL+SEQ_LOCK);
                                }
 
                                BLI_addtail(nseqbase, seqn);
                                if(seq->type==SEQ_META)
-                                       seqbase_dupli_recursive(scene, &seqn->seqbase, &seq->seqbase, do_context);
+                                       seqbase_dupli_recursive(scene, &seqn->seqbase, &seq->seqbase, dupe_flag);
 
-                               if(do_context) {
+                               if(dupe_flag & SEQ_DUPE_CONTEXT) {
                                        if (seq == last_seq) {
                                                seq_active_set(scene, seqn);
                                        }
index 36aecd0..96cf79d 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
 
@@ -129,6 +130,10 @@ static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
        RNA_string_set(op->ptr, "filepath", str);
        MEM_freeN(str);
 
+       if(RNA_struct_find_property(op->ptr, "relative_path"))
+               if(!RNA_property_is_set(op->ptr, "relative_path"))
+                       RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
        WM_event_add_fileselect(C, op); 
        
        return OPERATOR_RUNNING_MODAL;
@@ -147,6 +152,6 @@ void BUTTONS_OT_file_browse(wmOperatorType *ot)
        ot->cancel= file_browse_cancel;
 
        /* properties */
-       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, 0);
+       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
 }
 
index c4265c6..f84fd6f 100644 (file)
@@ -780,7 +780,6 @@ static int replace_exec(bContext *C, wmOperator *op)
 static int replace_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        SpaceImage *sima= CTX_wm_space_image(C);
-       char *path= (sima->image)? sima->image->name: U.textudir;
 
        if(!sima->image)
                return OPERATOR_CANCELLED;
@@ -788,7 +787,10 @@ static int replace_invoke(bContext *C, wmOperator *op, wmEvent *event)
        if(RNA_property_is_set(op->ptr, "filepath"))
                return replace_exec(C, op);
 
-       image_filesel(C, op, path);
+       if(!RNA_property_is_set(op->ptr, "relative_path"))
+               RNA_boolean_set(op->ptr, "relative_path", (strncmp(sima->image->name, "//", 2))==0);
+
+       image_filesel(C, op, sima->image->name);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -808,7 +810,7 @@ void IMAGE_OT_replace(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
        /* properties */
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, 0); //XXX TODO, relative_path
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
 }
 
 /******************** save image as operator ********************/
index 2c7082e..1a56cb6 100644 (file)
@@ -43,6 +43,7 @@
 
 
 #include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
@@ -313,6 +314,9 @@ static int sequencer_add_movie_strip_invoke(bContext *C, wmOperator *op, wmEvent
                return OPERATOR_CANCELLED;
        }
 
+       if(!RNA_property_is_set(op->ptr, "relative_path"))
+               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
        sequencer_generic_invoke_xy__internal(C, op, event, 0);
        return WM_operator_filesel(C, op, event);
        //return sequencer_add_movie_strip_exec(C, op);
@@ -336,7 +340,7 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, 0); //XXX TODO, relative_path
+       WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
        RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie");
 }
@@ -355,6 +359,9 @@ static int sequencer_add_sound_strip_invoke(bContext *C, wmOperator *op, wmEvent
                return OPERATOR_CANCELLED;
        }
 
+       if(!RNA_property_is_set(op->ptr, "relative_path"))
+               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
        sequencer_generic_invoke_xy__internal(C, op, event, 0);
        return WM_operator_filesel(C, op, event);
        //return sequencer_add_sound_strip_exec(C, op);
@@ -378,7 +385,7 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL, FILE_OPENFILE, 0);  //XXX TODO, relative_path
+       WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
        RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory.");
 }
@@ -446,6 +453,9 @@ static int sequencer_add_image_strip_invoke(bContext *C, wmOperator *op, wmEvent
                return OPERATOR_CANCELLED;
        }
 
+       if(!RNA_property_is_set(op->ptr, "relative_path"))
+               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
        sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_ENDFRAME);
        return WM_operator_filesel(C, op, event);       
        //return sequencer_add_image_strip_exec(C, op);
@@ -469,7 +479,7 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, 0);  //XXX TODO, relative_path
+       WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME|SEQPROP_FILES);
 }
 
@@ -593,6 +603,10 @@ static int sequencer_add_effect_strip_invoke(bContext *C, wmOperator *op, wmEven
        sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_ENDFRAME);
 
        if (RNA_property_is_set(op->ptr, "type") && RNA_enum_get(op->ptr, "type")==SEQ_PLUGIN) {
+
+               if(!RNA_property_is_set(op->ptr, "relative_path"))
+                       RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
                /* only plugins need the file selector */
                return WM_operator_filesel(C, op, event);
        }
@@ -617,7 +631,7 @@ void SEQUENCER_OT_effect_strip_add(struct wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, 0);  //XXX TODO, relative_path
+       WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, FILE_RELPATH);
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME);
        RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, SEQ_CROSS, "Type", "Sequencer effect type");
        RNA_def_float_vector(ot->srna, "color", 3, NULL, 0.0f, 1.0f, "Color", "Initialize the strip with this color (only used when type='COLOR')", 0.0f, 1.0f);
index 31e0eea..6d22564 100644 (file)
@@ -821,7 +821,7 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe)
 
        if (!skip_dup) {
                /* Duplicate AFTER the first change */
-               seqn = seq_dupli_recursive(scene, seq);
+               seqn = seq_dupli_recursive(scene, seq, SEQ_DUPE_UNIQUE_NAME);
        }
        
        if (seqn) { 
@@ -910,7 +910,7 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe)
 
        if (!skip_dup) {
                /* Duplicate AFTER the first change */
-               seqn = seq_dupli_recursive(scene, seq);
+               seqn = seq_dupli_recursive(scene, seq, SEQ_DUPE_UNIQUE_NAME);
        }
        
        if (seqn) { 
@@ -1566,7 +1566,7 @@ static int sequencer_add_duplicate_exec(bContext *C, wmOperator *op)
        if(ed==NULL)
                return OPERATOR_CANCELLED;
 
-       seqbase_dupli_recursive(scene, &nseqbase, ed->seqbasep, TRUE);
+       seqbase_dupli_recursive(scene, &nseqbase, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME|SEQ_DUPE_CONTEXT);
 
        if(nseqbase.first) {
                Sequence * seq= nseqbase.first;
@@ -2540,7 +2540,7 @@ static int sequencer_copy_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
 
-       seqbase_dupli_recursive(scene, &seqbase_clipboard, ed->seqbasep, FALSE);
+       seqbase_dupli_recursive(scene, &seqbase_clipboard, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME);
        seqbase_clipboard_frame= scene->r.cfra;
 
        /* Need to remove anything that references the current scene */
@@ -2594,7 +2594,7 @@ static int sequencer_paste_exec(bContext *C, wmOperator *op)
        deselect_all_seq(scene);
        ofs = scene->r.cfra - seqbase_clipboard_frame;
 
-       seqbase_dupli_recursive(scene, &nseqbase, &seqbase_clipboard, FALSE);
+       seqbase_dupli_recursive(scene, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME);
 
        /* transform pasted strips before adding */
        if(ofs) {