[#21102] Nonunique ID names in sequencer!
authorCampbell Barton <ideasman42@gmail.com>
Tue, 16 Feb 2010 17:58:50 +0000 (17:58 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 16 Feb 2010 17:58:50 +0000 (17:58 +0000)
now uniqute names are ensured with recursive name checking on the scene

source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/sequencer.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/makesrna/intern/rna_sequencer.c

index 2004db9a70a375d802854a6528693cbf2a797cd4..b0a810203cf1f6054821a4dd1e200f530a3234fa 100644 (file)
@@ -194,6 +194,7 @@ void free_imbuf_seq(struct Scene *scene, struct ListBase * seqbasep, int check_m
 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 clear_scene_in_allseqs(struct Scene *sce);
 
 struct Sequence *get_seq_by_name(struct ListBase *seqbase, const char *name, int recursive);
@@ -228,8 +229,6 @@ struct Sequence *alloc_sequence(ListBase *lb, int cfra, int machine);
 
 void seq_load_apply(struct Scene *scene, struct Sequence *seq, struct SeqLoadInfo *seq_load);
 
-void seqUniqueName(ListBase *seqbasep, struct Sequence *seq);
-
 struct Sequence *sequencer_add_image_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);
 struct Sequence *sequencer_add_sound_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);
 struct Sequence *sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);
index d7d63e850de1f8a1dd84bfb784e90ea540a4ea31..ce09fe8817f0b8a5c88bb5bf47269effc5084b45 100644 (file)
@@ -640,7 +640,7 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq)
                }
 
                BLI_strncpy(seq->name+2, sce->id.name + 2, SEQ_NAME_MAXSTR-2);
-               seqUniqueName(scene->ed->seqbasep, seq);
+               seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
                
                seq->len= seq->scene->r.efra - seq->scene->r.sfra + 1;
                seq->len -= seq->anim_startofs;
@@ -720,6 +720,62 @@ void clear_scene_in_allseqs(Scene *scene)
        }
 }
 
+typedef struct SeqUniqueInfo {
+       Sequence *seq;
+       char name_src[32];
+       char name_dest[32];
+       int count;
+       int match;
+} SeqUniqueInfo;
+
+/*
+static void seqbase_unique_name(ListBase *seqbasep, Sequence *seq)
+{
+        BLI_uniquename(seqbasep, seq, "Sequence", '.', offsetof(Sequence, name), SEQ_NAME_MAXSTR);
+}*/
+
+static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui)
+{
+       Sequence *seq;
+       for(seq=seqbasep->first; seq; seq= seq->next) {
+               if (sui->seq != seq && strcmp(sui->name_dest, seq->name+2)==0) {
+                       sprintf(sui->name_dest, "%.18s.%03d",  sui->name_src, sui->count++);
+                       sui->match= 1; /* be sure to re-scan */
+               }
+       }
+}
+
+static int seqbase_unique_name_recursive_cb(Sequence *seq, void *arg_pt)
+{
+       if(seq->seqbase.first)
+               seqbase_unique_name(&seq->seqbase, (SeqUniqueInfo *)arg_pt);
+       return 1;
+}
+
+void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq)
+{
+       SeqUniqueInfo sui;
+       char *dot;
+       sui.seq= seq;
+       strcpy(sui.name_src, seq->name+2);
+       strcpy(sui.name_dest, seq->name+2);
+
+       /* Strip off the suffix */
+       if ((dot=strrchr(sui.name_src, '.')))
+               *dot= '\0';
+
+       sui.count= 1;
+       sui.match= 1; /* assume the worst to start the loop */
+
+       while(sui.match) {
+               sui.match= 0;
+               seqbase_unique_name(seqbasep, &sui);
+               seqbase_recursive_apply(seqbasep, seqbase_unique_name_recursive_cb, &sui);
+       }
+
+       strcpy(seq->name+2, sui.name_dest);
+}
+
 static char *give_seqname_by_type(int type)
 {
        switch(type) {
@@ -3685,7 +3741,7 @@ void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load)
 {
        if(seq) {
                strcpy(seq->name, seq_load->name);
-               seqUniqueName(scene->ed->seqbasep, seq);
+               seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
 
                if(seq_load->flag & SEQ_LOAD_FRAME_ADVANCE) {
                        seq_load->start_frame += (seq->enddisp - seq->startdisp);
@@ -3728,11 +3784,6 @@ Sequence *alloc_sequence(ListBase *lb, int cfra, int machine)
        return seq;
 }
 
-void seqUniqueName(ListBase *seqbasep, Sequence *seq)
-{
-        BLI_uniquename(seqbasep, seq, "Sequence", '.', offsetof(Sequence, name), SEQ_NAME_MAXSTR);
-}
-
 /* NOTE: this function doesn't fill in image names */
 Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load)
 {
@@ -3744,7 +3795,7 @@ Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
        seq = alloc_sequence(seqbasep, seq_load->start_frame, seq_load->channel);
        seq->type= SEQ_IMAGE;
        BLI_strncpy(seq->name+2, "Image", SEQ_NAME_MAXSTR-2);
-       seqUniqueName(seqbasep, seq);
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
        
        /* basic defaults */
        seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
@@ -3793,7 +3844,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
        seq->type= SEQ_SOUND;
        seq->sound= sound;
        BLI_strncpy(seq->name+2, "Sound", SEQ_NAME_MAXSTR-2);
-       seqUniqueName(seqbasep, seq);
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
 
        /* basic defaults */
        seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
@@ -3837,7 +3888,7 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo
        seq->anim= an;
        seq->anim_preseek = IMB_anim_get_preseek(an);
        BLI_strncpy(seq->name+2, "Movie", SEQ_NAME_MAXSTR-2);
-       seqUniqueName(seqbasep, seq);
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
 
        /* basic defaults */
        seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
index 627e086ba9418f6939cdbb8e32b4852043f70e0d..5b17cc14ff2903808700958d5a04863288fc32f5 100644 (file)
@@ -10120,7 +10120,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                {
                                        seq=sce->ed->seqbasep->first;
                                        while(seq) {
-                                               seqUniqueName(sce->ed->seqbasep, seq);
+                                               seqbase_unique_name_recursive(&sce->ed->seqbase, seq);
                                                seq=seq->next;
                                        }
                                }
index bae4467e40c0065d9297740d784de87c246ca972..bd1053d8d776106faea81d7ddfeda30ba898f440 100644 (file)
@@ -513,7 +513,7 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
        else
                strcpy(seq->name+2, give_seqname(seq));
 
-       seqUniqueName(ed->seqbasep, seq);
+       seqbase_unique_name_recursive(&ed->seqbase, seq);
 
        sh = get_sequence_effect(seq);
 
index 0fe074a4012969ce90c6ded5b7566e5479678eb2..ce8d99da3a93c4a1d6daf6db240bb84f818b3868 100644 (file)
@@ -862,7 +862,7 @@ static Sequence *dupli_seq(struct Scene *scene, Sequence *seq)
                                                " now...\n");
        }
 
-       seqUniqueName(scene->ed->seqbasep, seqn);
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seqn);
 
        return seqn;
 }
@@ -1735,11 +1735,20 @@ static int sequencer_add_duplicate_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
 
        recurs_dupli_seq(scene, ed->seqbasep, &new, TRUE);
-       addlisttolist(ed->seqbasep, &new);
 
-       WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
+       if(new.first) {
+               Sequence * seq= new.first;
+               /* rely on the new list being added at the end */
+               addlisttolist(ed->seqbasep, &new);
 
-       return OPERATOR_FINISHED;
+               for( ; seq; seq= seq->next)
+                       seqbase_unique_name_recursive(&ed->seqbase, seq);
+
+               WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
+               return OPERATOR_FINISHED;
+       }
+
+       return OPERATOR_CANCELLED;
 }
 
 static int sequencer_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
@@ -1905,7 +1914,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
                                        shuffle_seq(ed->seqbasep, seq_new, scene);
                                }
 
-                               seqUniqueName(scene->ed->seqbasep, seq_new);
+                               seqbase_unique_name_recursive(&scene->ed->seqbase, seq_new);
 
                                cfra++;
                                start_ofs += step;
@@ -2069,7 +2078,7 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
 
        seq_update_muting(scene, ed);
 
-       seqUniqueName(scene->ed->seqbasep, seqm);
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seqm);
 
        WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
 
index 2346b0c3033c44342ec96c9175f6616ddd6d106c..17dbbbf9d05a94925cbf1d0535845cfc97b56386 100644 (file)
@@ -235,22 +235,10 @@ static int rna_Sequence_name_length(PointerRNA *ptr)
 static void rna_Sequence_name_set(PointerRNA *ptr, const char *value)
 {
        Scene *scene= (Scene*)ptr->id.data;
-//     Editing *ed= seq_give_editing(scene, FALSE);
        Sequence *seq= (Sequence*)ptr->data;
-//     Sequence *iseq;
        BLI_strncpy(seq->name+2, value, sizeof(seq->name)-2);
 
-       seqUniqueName(&scene->ed->seqbase, seq);
-
-       // TODO, unique name for all meta's
-       /*
-       SEQ_BEGIN(ed, iseq) {
-               if(iseq->seqbase.first)
-                       seqUniqueName(&iseq->seqbase, seq);
-
-       }
-       SEQ_END
-       */
+       seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
 }
 
 static StructRNA* rna_Sequence_refine(struct PointerRNA *ptr)