4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, 2003-2009
25 * ***** END GPL LICENSE BLOCK *****
37 #include <sys/types.h>
39 #include "MEM_guardedalloc.h"
41 #include "BLI_blenlib.h"
43 #include "BLI_storage_types.h"
44 #include "BLI_utildefines.h"
46 #include "DNA_scene_types.h"
47 #include "DNA_userdef_types.h"
49 #include "BKE_context.h"
50 #include "BKE_global.h"
52 #include "BKE_sequencer.h"
53 #include "BKE_report.h"
54 #include "BKE_sound.h"
59 #include "RNA_define.h"
61 /* for menu/popup icons etc etc*/
63 #include "ED_screen.h"
64 #include "ED_transform.h"
65 #include "ED_sequencer.h"
67 #include "UI_view2d.h"
70 #include "sequencer_intern.h"
72 static void error(const char *UNUSED(dummy)) {}
73 static void waitcursor(int UNUSED(val)) {}
74 static void activate_fileselect(int UNUSED(d1), const char *UNUSED(d2), const char *UNUSED(d3), void *UNUSED(d4)) {}
75 static int pupmenu(const char *UNUSED(dummy)) {return 0;}
76 static int okee(const char *UNUSED(dummy)) {return 0;}
80 /* RNA Enums, used in multiple files */
81 EnumPropertyItem sequencer_prop_effect_types[] = {
82 {SEQ_CROSS, "CROSS", 0, "Crossfade", "Crossfade effect strip type"},
83 {SEQ_ADD, "ADD", 0, "Add", "Add effect strip type"},
84 {SEQ_SUB, "SUBTRACT", 0, "Subtract", "Subtract effect strip type"},
85 {SEQ_ALPHAOVER, "ALPHA_OVER", 0, "Alpha Over", "Alpha Over effect strip type"},
86 {SEQ_ALPHAUNDER, "ALPHA_UNDER", 0, "Alpha Under", "Alpha Under effect strip type"},
87 {SEQ_GAMCROSS, "GAMMA_CROSS", 0, "Gamma Cross", "Gamma Cross effect strip type"},
88 {SEQ_MUL, "MULTIPLY", 0, "Multiply", "Multiply effect strip type"},
89 {SEQ_OVERDROP, "OVER_DROP", 0, "Alpha Over Drop", "Alpha Over Drop effect strip type"},
90 {SEQ_PLUGIN, "PLUGIN", 0, "Plugin", "Plugin effect strip type"},
91 {SEQ_WIPE, "WIPE", 0, "Wipe", "Wipe effect strip type"},
92 {SEQ_GLOW, "GLOW", 0, "Glow", "Glow effect strip type"},
93 {SEQ_TRANSFORM, "TRANSFORM", 0, "Transform", "Transform effect strip type"},
94 {SEQ_COLOR, "COLOR", 0, "Color", "Color effect strip type"},
95 {SEQ_SPEED, "SPEED", 0, "Speed", "Color effect strip type"},
96 {SEQ_MULTICAM, "MULTICAM", 0, "Multicam Selector", ""},
97 {0, NULL, 0, NULL, NULL}
102 EnumPropertyItem prop_side_types[] = {
103 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
104 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
105 {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""},
106 {0, NULL, 0, NULL, NULL}
109 static EnumPropertyItem prop_side_lr_types[] = {
110 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
111 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
112 {0, NULL, 0, NULL, NULL}
115 typedef struct TransSeq {
117 int startstill, endstill;
118 int startdisp, enddisp;
119 int startofs, endofs;
120 int final_left, final_right;
124 static Sequence *get_foreground_frame_seq(Scene *scene, int frame)
126 Editing *ed= seq_give_editing(scene, FALSE);
127 Sequence *seq, *best_seq=NULL;
128 int best_machine = -1;
132 for (seq=ed->seqbasep->first; seq; seq= seq->next) {
133 if(seq->flag & SEQ_MUTE || seq->startdisp > frame || seq->enddisp <= frame)
135 /* only use elements you can see - not */
136 if (ELEM5(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_COLOR)) {
137 if (seq->machine > best_machine) {
139 best_machine = seq->machine;
146 void seq_rectf(Sequence *seq, rctf *rectf)
148 if(seq->startstill) rectf->xmin= seq->start;
149 else rectf->xmin= seq->startdisp;
150 rectf->ymin= seq->machine+SEQ_STRIP_OFSBOTTOM;
151 if(seq->endstill) rectf->xmax= seq->start+seq->len;
152 else rectf->xmax= seq->enddisp;
153 rectf->ymax= seq->machine+SEQ_STRIP_OFSTOP;
156 static void change_plugin_seq(Scene *scene, char *str) /* called from fileselect */
158 Editing *ed= seq_give_editing(scene, FALSE);
159 struct SeqEffectHandle sh;
160 Sequence *last_seq= seq_active_get(scene);
162 if(last_seq==NULL || last_seq->type != SEQ_PLUGIN) return;
164 sh = get_sequence_effect(last_seq);
166 sh.init_plugin(last_seq, str);
168 last_seq->machine = MAX3(last_seq->seq1->machine,
169 last_seq->seq2->machine,
170 last_seq->seq3->machine);
172 if( seq_test_overlap(ed->seqbasep, last_seq) ) shuffle_seq(ed->seqbasep, last_seq, scene);
177 void boundbox_seq(Scene *scene, rctf *rect)
180 Editing *ed= seq_give_editing(scene, FALSE);
181 float min[2], max[2];
191 seq= ed->seqbasep->first;
194 if( min[0] > seq->startdisp-1) min[0]= seq->startdisp-1;
195 if( max[0] < seq->enddisp+1) max[0]= seq->enddisp+1;
196 if( max[1] < seq->machine+2.0) max[1]= seq->machine+2.0;
208 static int mouse_frame_side(View2D *v2d, short mouse_x, int frame )
216 /* choose the side based on which side of the playhead the mouse is on */
217 UI_view2d_region_to_view(v2d, mval[0], mval[1], &mouseloc[0], &mouseloc[1]);
219 return mouseloc[0] > frame ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT;
223 Sequence *find_neighboring_sequence(Scene *scene, Sequence *test, int lr, int sel)
225 /* sel - 0==unselected, 1==selected, -1==done care*/
227 Editing *ed= seq_give_editing(scene, FALSE);
229 if(ed==NULL) return NULL;
231 if (sel>0) sel = SELECT;
233 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
235 (test->machine==seq->machine) &&
236 ((sel == -1) || (sel && (seq->flag & SELECT)) || (sel==0 && (seq->flag & SELECT)==0) ))
240 if (test->startdisp == (seq->enddisp)) {
245 if (test->enddisp == (seq->startdisp)) {
255 static Sequence *find_next_prev_sequence(Scene *scene, Sequence *test, int lr, int sel)
257 /* sel - 0==unselected, 1==selected, -1==done care*/
258 Sequence *seq,*best_seq = NULL;
259 Editing *ed= seq_give_editing(scene, FALSE);
262 best_dist = MAXFRAME*2;
265 if(ed==NULL) return NULL;
267 seq= ed->seqbasep->first;
270 (test->machine==seq->machine) &&
271 (test->depth==seq->depth) &&
272 ((sel == -1) || (sel==(seq->flag & SELECT))))
278 if (seq->enddisp <= test->startdisp) {
279 dist = test->enddisp - seq->startdisp;
283 if (seq->startdisp >= test->enddisp) {
284 dist = seq->startdisp - test->enddisp;
292 } else if (dist < best_dist) {
299 return best_seq; /* can be null */
303 Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, short mval[2])
306 Editing *ed= seq_give_editing(scene, FALSE);
311 *hand= SEQ_SIDE_NONE;
314 if(ed==NULL) return NULL;
316 pixelx = (v2d->cur.xmax - v2d->cur.xmin)/(v2d->mask.xmax - v2d->mask.xmin);
318 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
320 seq= ed->seqbasep->first;
323 if(seq->machine == (int)y) {
324 /* check for both normal strips, and strips that have been flipped horizontally */
325 if( ((seq->startdisp < seq->enddisp) && (seq->startdisp<=x && seq->enddisp>=x)) ||
326 ((seq->startdisp > seq->enddisp) && (seq->startdisp>=x && seq->enddisp<=x)) )
328 if(seq_tx_test(seq)) {
330 /* clamp handles to defined size in pixel space */
332 handsize = seq->handsize;
333 displen = (float)abs(seq->startdisp - seq->enddisp);
335 if (displen / pixelx > 16) { /* dont even try to grab the handles of small strips */
336 /* Set the max value to handle to 1/3 of the total len when its less then 28.
337 * This is important because otherwise selecting handles happens even when you click in the middle */
339 if ((displen/3) < 30*pixelx) {
340 handsize = displen/3;
342 CLAMP(handsize, 7*pixelx, 30*pixelx);
345 if( handsize+seq->startdisp >=x )
346 *hand= SEQ_SIDE_LEFT;
347 else if( -handsize+seq->enddisp <=x )
348 *hand= SEQ_SIDE_RIGHT;
360 static int seq_is_parent(Sequence *par, Sequence *seq)
362 return ((par->seq1 == seq) || (par->seq2 == seq) || (par->seq3 == seq));
365 static int seq_is_predecessor(Sequence *pred, Sequence *seq)
368 if(pred == seq) return 0;
369 else if(seq_is_parent(pred, seq)) return 1;
370 else if(pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1;
371 else if(pred->seq2 && seq_is_predecessor(pred->seq2, seq)) return 1;
372 else if(pred->seq3 && seq_is_predecessor(pred->seq3, seq)) return 1;
377 void deselect_all_seq(Scene *scene)
380 Editing *ed= seq_give_editing(scene, FALSE);
385 SEQP_BEGIN(ed, seq) {
386 seq->flag &= ~SEQ_ALLSEL;
392 void recurs_sel_seq(Sequence *seqm)
396 seq= seqm->seqbase.first;
399 if(seqm->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL)) seq->flag &= ~SEQ_ALLSEL;
400 else if(seqm->flag & SELECT) seq->flag |= SELECT;
401 else seq->flag &= ~SEQ_ALLSEL;
403 if(seq->seqbase.first) recurs_sel_seq(seq);
409 int event_to_efftype(int event)
411 if(event==2) return SEQ_CROSS;
412 if(event==3) return SEQ_GAMCROSS;
413 if(event==4) return SEQ_ADD;
414 if(event==5) return SEQ_SUB;
415 if(event==6) return SEQ_MUL;
416 if(event==7) return SEQ_ALPHAOVER;
417 if(event==8) return SEQ_ALPHAUNDER;
418 if(event==9) return SEQ_OVERDROP;
419 if(event==10) return SEQ_PLUGIN;
420 if(event==13) return SEQ_WIPE;
421 if(event==14) return SEQ_GLOW;
422 if(event==15) return SEQ_TRANSFORM;
423 if(event==16) return SEQ_COLOR;
424 if(event==17) return SEQ_SPEED;
429 static void reload_sound_strip(Scene *scene, char *name)
432 Sequence *seq, *seqact;
434 Sequence *last_seq= seq_active_get(scene);
438 if(last_seq==0 || last_seq->type!=SEQ_SOUND) return;
439 seqact= last_seq; /* last_seq changes in alloc_sequence */
442 // sfile= scrarea_find_space_of_type(curarea, SPACE_FILE);
447 seq = sfile_to_snd_sequence(sfile, seqact->start, seqact->machine);
448 printf("seq->type: %i\n", seq->type);
449 if(seq && seq!=seqact) {
450 /* i'm not sure about this one, seems to work without it -- sgefant */
451 seq_free_strip(seqact->strip);
453 seqact->strip= seq->strip;
455 seqact->len= seq->len;
456 calc_sequence(scene, seqact);
459 seq_free_sequence(scene, seq);
460 BLI_remlink(ed->seqbasep, seq);
462 seq= ed->seqbasep->first;
471 static void reload_image_strip(Scene *scene, char *UNUSED(name))
473 Editing *ed= seq_give_editing(scene, FALSE);
474 Sequence *seq=NULL, *seqact;
475 SpaceFile *sfile=NULL;
476 Sequence *last_seq= seq_active_get(scene);
480 if(last_seq==0 || last_seq->type!=SEQ_IMAGE) return;
481 seqact= last_seq; /* last_seq changes in alloc_sequence */
484 // sfile= scrarea_find_space_of_type(curarea, SPACE_FILE);
489 // seq= sfile_to_sequence(scene, sfile, seqact->start, seqact->machine, 1); // XXX ADD BACK
490 if(seq && seq!=seqact) {
491 seq_free_strip(seqact->strip);
493 seqact->strip= seq->strip;
495 seqact->len= seq->len;
496 calc_sequence(scene, seqact);
499 seq_free_sequence(scene, seq);
500 BLI_remlink(ed->seqbasep, seq);
502 update_changed_seq_and_deps(scene, seqact, 1, 1);
509 static void change_sequence(Scene *scene)
511 Editing *ed= seq_give_editing(scene, FALSE);
512 Sequence *last_seq= seq_active_get(scene);
516 if(last_seq==0) return;
518 if(last_seq->type & SEQ_EFFECT) {
519 event = pupmenu("Change Effect%t"
520 "|Switch A <-> B %x1"
521 "|Switch B <-> C %x10"
531 "|Alpha Over Drop%x9"
535 "|Color Generator%x16"
536 "|Speed Control%x17");
539 SWAP(Sequence *,last_seq->seq1,last_seq->seq2);
542 SWAP(Sequence *,last_seq->seq2,last_seq->seq3);
546 FILE_SPECIAL, "Select Plugin",
547 U.plugseqdir, change_plugin_seq);
550 /* recalculate: only new_stripdata */
552 /* free previous effect and init new effect */
553 struct SeqEffectHandle sh;
555 if (get_sequence_effect_num_inputs(
557 < get_sequence_effect_num_inputs(
558 event_to_efftype(event))) {
559 error("New effect needs more "
562 sh = get_sequence_effect(last_seq);
566 = event_to_efftype(event);
568 sh = get_sequence_effect(last_seq);
573 update_changed_seq_and_deps(scene, last_seq, 0, 1);
576 else if(last_seq->type == SEQ_IMAGE) {
577 if(okee("Change images")) {
578 activate_fileselect(FILE_SPECIAL,
584 else if(last_seq->type == SEQ_MOVIE) {
587 else if(last_seq->type == SEQ_SCENE) {
588 event= pupmenu("Change Scene%t|Update Start and End");
591 sce= last_seq->scene;
593 last_seq->len= sce->r.efra - sce->r.sfra + 1;
594 last_seq->sfra= sce->r.sfra;
596 /* bad code to change seq->len? update_changed_seq_and_deps() expects the strip->len to be OK */
597 new_tstripdata(last_seq);
599 update_changed_seq_and_deps(scene, last_seq, 1, 1);
606 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str)
608 Editing *ed = seq_give_editing(scene, FALSE);
609 Sequence *seq1= 0, *seq2= 0, *seq3= 0, *seq;
614 seq2= seq_active_get(scene);
616 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
617 if(seq->flag & SELECT) {
618 if (seq->type == SEQ_SOUND && get_sequence_effect_num_inputs(type) != 0) {
619 *error_str= "Can't apply effects to audio sequence strips";
622 if((seq != activeseq) && (seq != seq2)) {
623 if(seq2==0) seq2= seq;
624 else if(seq1==0) seq1= seq;
625 else if(seq3==0) seq3= seq;
627 *error_str= "Can't apply effect to more than 3 sequence strips";
634 /* make sequence selection a little bit more intuitive
635 for 3 strips: the last-strip should be sequence3 */
636 if (seq3 != 0 && seq2 != 0) {
637 Sequence *tmp = seq2;
643 switch(get_sequence_effect_num_inputs(type)) {
645 *selseq1 = *selseq2 = *selseq3 = 0;
646 return 1; /* succsess */
649 *error_str= "Need at least one selected sequence strip";
652 if(seq1==0) seq1= seq2;
653 if(seq3==0) seq3= seq2;
655 if(seq1==0 || seq2==0) {
656 *error_str= "Need 2 selected sequence strips";
659 if(seq3==0) seq3= seq2;
662 if (seq1==NULL && seq2==NULL && seq3==NULL) {
663 *error_str= "TODO: in what cases does this happen?";
674 static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq)
676 Sequence *seq1, *seq2, *seq3;
678 /* try to find a replacement input sequence, and flag for later deletion if
679 no replacement can be found */
683 else if(!(seq->type & SEQ_EFFECT))
684 return ((seq->flag & SELECT)? NULL: seq);
685 else if(!(seq->flag & SELECT)) {
686 /* try to find replacement for effect inputs */
687 seq1= del_seq_find_replace_recurs(scene, seq->seq1);
688 seq2= del_seq_find_replace_recurs(scene, seq->seq2);
689 seq3= del_seq_find_replace_recurs(scene, seq->seq3);
691 if(seq1==seq->seq1 && seq2==seq->seq2 && seq3==seq->seq3);
692 else if(seq1 || seq2 || seq3) {
693 seq->seq1= (seq1)? seq1: (seq2)? seq2: seq3;
694 seq->seq2= (seq2)? seq2: (seq1)? seq1: seq3;
695 seq->seq3= (seq3)? seq3: (seq1)? seq1: seq2;
697 update_changed_seq_and_deps(scene, seq, 1, 1);
700 seq->flag |= SELECT; /* mark for delete */
703 if (seq->flag & SELECT) {
704 if((seq1 = del_seq_find_replace_recurs(scene, seq->seq1))) return seq1;
705 if((seq2 = del_seq_find_replace_recurs(scene, seq->seq2))) return seq2;
706 if((seq3 = del_seq_find_replace_recurs(scene, seq->seq3))) return seq3;
713 static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall)
715 Sequence *seq, *seqn;
716 Sequence *last_seq = seq_active_get(scene);
721 if((seq->flag & flag) || deleteall) {
722 if(seq->type==SEQ_SOUND && seq->sound) {
723 ((ID *)seq->sound)->us--; /* TODO, could be moved into seq_free_sequence() */
726 BLI_remlink(lb, seq);
727 if(seq==last_seq) seq_active_set(scene, NULL);
728 if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1);
729 /* if(seq->ipo) seq->ipo->id.us--; */
730 /* XXX, remove fcurve */
731 seq_free_sequence(scene, seq);
738 static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe)
742 int skip_dup = FALSE;
745 ts.start= seq->start;
746 ts.machine= seq->machine;
747 ts.startstill= seq->startstill;
748 ts.endstill= seq->endstill;
749 ts.startdisp= seq->startdisp;
750 ts.enddisp= seq->enddisp;
751 ts.startofs= seq->anim_startofs;
752 ts.endofs= seq->anim_endofs;
756 /* strips with extended stillfames before */
758 if ((seq->startstill) && (cutframe <seq->start)) {
759 /* don't do funny things with METAs ... */
760 if (seq->type == SEQ_META) {
762 seq->startstill = seq->start - cutframe;
764 seq->start= cutframe -1;
765 seq->startstill= cutframe -seq->startdisp -1;
766 seq->anim_endofs += seq->len - 1;
771 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
774 seq->anim_endofs += (seq->start+seq->len) - cutframe;
776 /* strips with extended stillframes after */
777 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
778 seq->endstill -= seq->enddisp - cutframe;
779 /* don't do funny things with METAs ... */
780 if (seq->type == SEQ_META) {
785 reload_sequence_new_file(scene, seq, FALSE);
786 calc_sequence(scene, seq);
790 /* Duplicate AFTER the first change */
791 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
795 seqn->flag |= SELECT;
798 /* strips with extended stillframes before */
799 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
800 seqn->start = ts.start;
801 seqn->startstill= ts.start- cutframe;
802 seqn->anim_endofs = ts.endofs;
803 seqn->endstill = ts.endstill;
807 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
808 seqn->start = cutframe;
809 seqn->startstill = 0;
811 seqn->anim_startofs += cutframe - ts.start;
812 seqn->anim_endofs = ts.endofs;
813 seqn->endstill = ts.endstill;
816 /* strips with extended stillframes after */
817 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
818 seqn->start = cutframe;
820 seqn->anim_startofs += ts.len-1;
821 seqn->endstill = ts.enddisp - cutframe -1;
822 seqn->startstill = 0;
825 reload_sequence_new_file(scene, seqn, FALSE);
826 calc_sequence(scene, seqn);
827 new_tstripdata(seqn);
832 static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe)
836 int skip_dup = FALSE;
839 ts.start= seq->start;
840 ts.machine= seq->machine;
841 ts.startstill= seq->startstill;
842 ts.endstill= seq->endstill;
843 ts.startdisp= seq->startdisp;
844 ts.enddisp= seq->enddisp;
845 ts.startofs= seq->startofs;
846 ts.endofs= seq->endofs;
850 /* strips with extended stillfames before */
852 if ((seq->startstill) && (cutframe <seq->start)) {
853 /* don't do funny things with METAs ... */
854 if (seq->type == SEQ_META) {
856 seq->startstill = seq->start - cutframe;
858 seq->start= cutframe -1;
859 seq->startstill= cutframe -seq->startdisp -1;
860 seq->endofs = seq->len - 1;
865 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
866 seq->endofs = (seq->start+seq->len) - cutframe;
868 /* strips with extended stillframes after */
869 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
870 seq->endstill -= seq->enddisp - cutframe;
871 /* don't do funny things with METAs ... */
872 if (seq->type == SEQ_META) {
877 calc_sequence(scene, seq);
881 /* Duplicate AFTER the first change */
882 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
886 seqn->flag |= SELECT;
889 /* strips with extended stillframes before */
890 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
891 seqn->start = ts.start;
892 seqn->startstill= ts.start- cutframe;
893 seqn->endofs = ts.endofs;
894 seqn->endstill = ts.endstill;
898 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
899 seqn->startstill = 0;
900 seqn->startofs = cutframe - ts.start;
901 seqn->endofs = ts.endofs;
902 seqn->endstill = ts.endstill;
905 /* strips with extended stillframes after */
906 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
907 seqn->start = cutframe - ts.len +1;
908 seqn->startofs = ts.len-1;
909 seqn->endstill = ts.enddisp - cutframe -1;
910 seqn->startstill = 0;
913 calc_sequence(scene, seqn);
914 new_tstripdata(seqn);
920 /* like duplicate, but only duplicate and cut overlapping strips,
921 * strips to the left of the cutframe are ignored and strips to the right are moved into the new list */
922 static int cut_seq_list(Scene *scene, ListBase *old, ListBase *new, int cutframe,
923 Sequence * (*cut_seq)(Scene *, Sequence *, int))
925 int did_something = FALSE;
926 Sequence *seq, *seq_next_iter;
931 seq_next_iter = seq->next; /* we need this because we may remove seq */
934 if(seq->flag & SELECT) {
935 if(cutframe > seq->startdisp &&
936 cutframe < seq->enddisp) {
937 Sequence * seqn = cut_seq(scene, seq, cutframe);
939 BLI_addtail(new, seqn);
941 did_something = TRUE;
942 } else if (seq->enddisp <= cutframe) {
944 } else if (seq->startdisp >= cutframe) {
945 /* move into new list */
946 BLI_remlink(old, seq);
947 BLI_addtail(new, seq);
952 return did_something;
955 static int insert_gap(Scene *scene, int gap, int cfra)
958 Editing *ed= seq_give_editing(scene, FALSE);
961 /* all strips >= cfra are shifted */
963 if(ed==NULL) return 0;
965 SEQP_BEGIN(ed, seq) {
966 if(seq->startdisp >= cfra) {
968 calc_sequence(scene, seq);
977 static void touch_seq_files(Scene *scene)
980 Editing *ed= seq_give_editing(scene, FALSE);
983 /* touch all strips with movies */
987 if(okee("Touch and print selected movies")==0) return;
991 SEQP_BEGIN(ed, seq) {
992 if(seq->flag & SELECT) {
993 if(seq->type==SEQ_MOVIE) {
994 if(seq->strip && seq->strip->stripdata) {
995 BLI_make_file_string(G.main->name, str, seq->strip->dir, seq->strip->stripdata->name);
996 BLI_touch(seq->name);
1008 static void set_filter_seq(Scene *scene)
1011 Editing *ed= seq_give_editing(scene, FALSE);
1014 if(ed==NULL) return;
1016 if(okee("Set Deinterlace")==0) return;
1018 SEQP_BEGIN(ed, seq) {
1019 if(seq->flag & SELECT) {
1020 if(seq->type==SEQ_MOVIE) {
1021 seq->flag |= SEQ_FILTERY;
1022 reload_sequence_new_file(scene, seq, FALSE);
1023 calc_sequence(scene, seq);
1032 static void seq_remap_paths(Scene *scene)
1034 Sequence *seq, *last_seq = seq_active_get(scene);
1035 Editing *ed= seq_give_editing(scene, FALSE);
1036 char from[FILE_MAX], to[FILE_MAX], stripped[FILE_MAX];
1042 BLI_strncpy(from, last_seq->strip->dir, FILE_MAX);
1043 // XXX if (0==sbutton(from, 0, sizeof(from)-1, "From: "))
1047 // XXX if (0==sbutton(to, 0, sizeof(to)-1, "To: "))
1050 if (strcmp(to, from)==0)
1053 SEQP_BEGIN(ed, seq) {
1054 if(seq->flag & SELECT) {
1055 if(strncmp(seq->strip->dir, from, strlen(from))==0) {
1056 printf("found %s\n", seq->strip->dir);
1058 /* strip off the beginning */
1060 BLI_strncpy(stripped, seq->strip->dir + strlen(from), FILE_MAX);
1063 BLI_snprintf(seq->strip->dir, sizeof(seq->strip->dir), "%s%s", to, stripped);
1064 printf("new %s\n", seq->strip->dir);
1073 static void no_gaps(Scene *scene)
1075 Editing *ed= seq_give_editing(scene, FALSE);
1076 int cfra, first= 0, done;
1079 if(ed==NULL) return;
1081 for(cfra= CFRA; cfra<=EFRA; cfra++) {
1083 if( evaluate_seq_frame(scene, cfra) ) first= 1;
1087 while( evaluate_seq_frame(scene, cfra) == 0) {
1088 done= insert_gap(scene, -1, cfra);
1098 static int seq_get_snaplimit(View2D *v2d)
1100 /* fake mouse coords to get the snap value
1101 a bit lazy but its only done once pre transform */
1102 float xmouse, ymouse, x;
1103 short mval[2] = {24, 0}; /* 24 screen px snap */
1105 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1108 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1109 return (int)(x - xmouse);
1113 /* Operator functions */
1114 int sequencer_edit_poll(bContext *C)
1116 return (seq_give_editing(CTX_data_scene(C), FALSE) != NULL);
1119 int sequencer_view_poll(bContext *C)
1121 SpaceSeq *sseq= CTX_wm_space_seq(C);
1122 Editing *ed= seq_give_editing(CTX_data_scene(C), FALSE);
1123 if (ed && sseq && (sseq->mainb == SEQ_DRAW_IMG_IMBUF))
1130 static int sequencer_snap_exec(bContext *C, wmOperator *op)
1132 Scene *scene= CTX_data_scene(C);
1134 Editing *ed= seq_give_editing(scene, FALSE);
1138 snap_frame= RNA_int_get(op->ptr, "frame");
1140 /* also check metas */
1141 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1142 if (seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK) &&
1144 if((seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))==0) {
1145 /* simple but no anim update */
1146 /* seq->start= snap_frame-seq->startofs+seq->startstill; */
1148 seq_translate(scene, seq, (snap_frame-seq->startofs+seq->startstill) - seq->start);
1150 if(seq->flag & SEQ_LEFTSEL) {
1151 seq_tx_set_final_left(seq, snap_frame);
1152 } else { /* SEQ_RIGHTSEL */
1153 seq_tx_set_final_right(seq, snap_frame);
1155 seq_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL);
1157 calc_sequence(scene, seq);
1161 /* test for effects and overlap
1162 * dont use SEQP_BEGIN since that would be recursive */
1163 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1164 if(seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK)) {
1165 seq->flag &= ~SEQ_OVERLAP;
1166 if( seq_test_overlap(ed->seqbasep, seq) ) {
1167 shuffle_seq(ed->seqbasep, seq, scene);
1170 else if(seq->type & SEQ_EFFECT) {
1171 if(seq->seq1 && (seq->seq1->flag & SELECT))
1172 calc_sequence(scene, seq);
1173 else if(seq->seq2 && (seq->seq2->flag & SELECT))
1174 calc_sequence(scene, seq);
1175 else if(seq->seq3 && (seq->seq3->flag & SELECT))
1176 calc_sequence(scene, seq);
1183 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1185 return OPERATOR_FINISHED;
1188 static int sequencer_snap_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1190 Scene *scene = CTX_data_scene(C);
1196 RNA_int_set(op->ptr, "frame", snap_frame);
1197 return sequencer_snap_exec(C, op);
1200 void SEQUENCER_OT_snap(struct wmOperatorType *ot)
1203 ot->name= "Snap strips";
1204 ot->idname= "SEQUENCER_OT_snap";
1205 ot->description="Frame where selected strips will be snapped";
1208 ot->invoke= sequencer_snap_invoke;
1209 ot->exec= sequencer_snap_exec;
1210 ot->poll= sequencer_edit_poll;
1213 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1215 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be snapped", INT_MIN, INT_MAX);
1219 static int sequencer_mute_exec(bContext *C, wmOperator *op)
1221 Scene *scene= CTX_data_scene(C);
1222 Editing *ed= seq_give_editing(scene, FALSE);
1226 selected= !RNA_boolean_get(op->ptr, "unselected");
1228 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1229 if ((seq->flag & SEQ_LOCK)==0) {
1230 if(selected){ /* mute unselected */
1231 if(seq->flag & SELECT)
1232 seq->flag |= SEQ_MUTE;
1235 if((seq->flag & SELECT)==0)
1236 seq->flag |= SEQ_MUTE;
1241 seq_update_muting(scene, ed);
1242 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1244 return OPERATOR_FINISHED;
1247 void SEQUENCER_OT_mute(struct wmOperatorType *ot)
1250 ot->name= "Mute Strips";
1251 ot->idname= "SEQUENCER_OT_mute";
1252 ot->description="Mute selected strips";
1255 ot->exec= sequencer_mute_exec;
1256 ot->poll= sequencer_edit_poll;
1259 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1261 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Mute unselected rather than selected strips.");
1265 /* unmute operator */
1266 static int sequencer_unmute_exec(bContext *C, wmOperator *op)
1268 Scene *scene= CTX_data_scene(C);
1269 Editing *ed= seq_give_editing(scene, FALSE);
1273 selected= !RNA_boolean_get(op->ptr, "unselected");
1275 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1276 if ((seq->flag & SEQ_LOCK)==0) {
1277 if(selected){ /* unmute unselected */
1278 if(seq->flag & SELECT)
1279 seq->flag &= ~SEQ_MUTE;
1282 if((seq->flag & SELECT)==0)
1283 seq->flag &= ~SEQ_MUTE;
1288 seq_update_muting(scene, ed);
1289 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1291 return OPERATOR_FINISHED;
1294 void SEQUENCER_OT_unmute(struct wmOperatorType *ot)
1297 ot->name= "Un-Mute Strips";
1298 ot->idname= "SEQUENCER_OT_unmute";
1299 ot->description="Un-Mute unselected rather than selected strips";
1302 ot->exec= sequencer_unmute_exec;
1303 ot->poll= sequencer_edit_poll;
1306 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1308 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "UnMute unselected rather than selected strips.");
1313 static int sequencer_lock_exec(bContext *C, wmOperator *UNUSED(op))
1315 Scene *scene= CTX_data_scene(C);
1316 Editing *ed= seq_give_editing(scene, FALSE);
1319 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1320 if (seq->flag & SELECT) {
1321 seq->flag |= SEQ_LOCK;
1325 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1327 return OPERATOR_FINISHED;
1330 void SEQUENCER_OT_lock(struct wmOperatorType *ot)
1333 ot->name= "Lock Strips";
1334 ot->idname= "SEQUENCER_OT_lock";
1335 ot->description="Lock the active strip so that it can't be transformed";
1338 ot->exec= sequencer_lock_exec;
1339 ot->poll= sequencer_edit_poll;
1342 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1345 /* unlock operator */
1346 static int sequencer_unlock_exec(bContext *C, wmOperator *UNUSED(op))
1348 Scene *scene= CTX_data_scene(C);
1349 Editing *ed= seq_give_editing(scene, FALSE);
1352 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1353 if (seq->flag & SELECT) {
1354 seq->flag &= ~SEQ_LOCK;
1358 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1360 return OPERATOR_FINISHED;
1363 void SEQUENCER_OT_unlock(struct wmOperatorType *ot)
1366 ot->name= "UnLock Strips";
1367 ot->idname= "SEQUENCER_OT_unlock";
1368 ot->description="Unlock the active strip so that it can't be transformed";
1371 ot->exec= sequencer_unlock_exec;
1372 ot->poll= sequencer_edit_poll;
1375 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1378 /* reload operator */
1379 static int sequencer_reload_exec(bContext *C, wmOperator *UNUSED(op))
1381 Scene *scene= CTX_data_scene(C);
1382 Editing *ed= seq_give_editing(scene, FALSE);
1385 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1386 if(seq->flag & SELECT) {
1387 update_changed_seq_and_deps(scene, seq, 0, 1);
1391 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1393 return OPERATOR_FINISHED;
1396 void SEQUENCER_OT_reload(struct wmOperatorType *ot)
1399 ot->name= "Reload Strips";
1400 ot->idname= "SEQUENCER_OT_reload";
1401 ot->description="Reload strips in the sequencer";
1404 ot->exec= sequencer_reload_exec;
1405 ot->poll= sequencer_edit_poll;
1408 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1411 /* reload operator */
1412 static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op))
1414 Scene *scene= CTX_data_scene(C);
1415 Editing *ed= seq_give_editing(scene, FALSE);
1417 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE);
1419 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1421 return OPERATOR_FINISHED;
1424 void SEQUENCER_OT_refresh_all(struct wmOperatorType *ot)
1427 ot->name= "Refresh Sequencer";
1428 ot->idname= "SEQUENCER_OT_refresh_all";
1429 ot->description="Refresh the sequencer editor";
1432 ot->exec= sequencer_refresh_all_exec;
1433 ot->poll= sequencer_edit_poll;
1436 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1439 static int sequencer_reassign_inputs_exec(bContext *C, wmOperator *op)
1441 Scene *scene= CTX_data_scene(C);
1442 Sequence *seq1, *seq2, *seq3, *last_seq = seq_active_get(scene);
1443 const char *error_msg;
1445 if(!seq_effect_find_selected(scene, last_seq, last_seq->type, &seq1, &seq2, &seq3, &error_msg)) {
1446 BKE_report(op->reports, RPT_ERROR, error_msg);
1447 return OPERATOR_CANCELLED;
1449 /* see reassigning would create a cycle */
1450 if( seq_is_predecessor(seq1, last_seq) ||
1451 seq_is_predecessor(seq2, last_seq) ||
1452 seq_is_predecessor(seq3, last_seq)
1454 BKE_report(op->reports, RPT_ERROR, "Can't reassign inputs: no cycles allowed");
1455 return OPERATOR_CANCELLED;
1458 last_seq->seq1 = seq1;
1459 last_seq->seq2 = seq2;
1460 last_seq->seq3 = seq3;
1462 update_changed_seq_and_deps(scene, last_seq, 1, 1);
1464 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1466 return OPERATOR_FINISHED;
1469 static int sequencer_effect_poll(bContext *C)
1471 Scene *scene= CTX_data_scene(C);
1472 Editing *ed= seq_give_editing(scene, FALSE);
1475 Sequence *last_seq= seq_active_get(scene);
1476 if(last_seq && (last_seq->type & SEQ_EFFECT)) {
1484 void SEQUENCER_OT_reassign_inputs(struct wmOperatorType *ot)
1487 ot->name= "Reassign Inputs";
1488 ot->idname= "SEQUENCER_OT_reassign_inputs";
1489 ot->description="Reassign the inputs for the effects strip";
1492 ot->exec= sequencer_reassign_inputs_exec;
1493 ot->poll= sequencer_effect_poll;
1496 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1500 static int sequencer_swap_inputs_exec(bContext *C, wmOperator *op)
1502 Scene *scene= CTX_data_scene(C);
1503 Sequence *seq, *last_seq = seq_active_get(scene);
1505 if(last_seq->seq1==NULL || last_seq->seq2 == NULL) {
1506 BKE_report(op->reports, RPT_ERROR, "No valid inputs to swap");
1507 return OPERATOR_CANCELLED;
1510 seq = last_seq->seq1;
1511 last_seq->seq1 = last_seq->seq2;
1512 last_seq->seq2 = seq;
1514 update_changed_seq_and_deps(scene, last_seq, 1, 1);
1516 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1518 return OPERATOR_FINISHED;
1520 void SEQUENCER_OT_swap_inputs(struct wmOperatorType *ot)
1523 ot->name= "Swap Inputs";
1524 ot->idname= "SEQUENCER_OT_swap_inputs";
1525 ot->description="Swap the first two inputs for the effects strip";
1528 ot->exec= sequencer_swap_inputs_exec;
1529 ot->poll= sequencer_effect_poll;
1532 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1537 static EnumPropertyItem prop_cut_types[] = {
1538 {SEQ_CUT_SOFT, "SOFT", 0, "Soft", ""},
1539 {SEQ_CUT_HARD, "HARD", 0, "Hard", ""},
1540 {0, NULL, 0, NULL, NULL}
1543 static int sequencer_cut_exec(bContext *C, wmOperator *op)
1545 Scene *scene= CTX_data_scene(C);
1546 Editing *ed= seq_give_editing(scene, FALSE);
1547 int cut_side, cut_hard, cut_frame;
1552 cut_frame= RNA_int_get(op->ptr, "frame");
1553 cut_hard= RNA_enum_get(op->ptr, "type");
1554 cut_side= RNA_enum_get(op->ptr, "side");
1556 newlist.first= newlist.last= NULL;
1558 if (cut_hard==SEQ_CUT_HARD) {
1559 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_hard);
1561 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_soft);
1564 if (newlist.first) { /* got new strips ? */
1566 BLI_movelisttolist(ed->seqbasep, &newlist);
1568 if (cut_side != SEQ_SIDE_BOTH) {
1569 SEQP_BEGIN(ed, seq) {
1570 if (cut_side==SEQ_SIDE_LEFT) {
1571 if ( seq->startdisp >= cut_frame ) {
1572 seq->flag &= ~SEQ_ALLSEL;
1575 if ( seq->enddisp <= cut_frame ) {
1576 seq->flag &= ~SEQ_ALLSEL;
1586 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1588 return OPERATOR_FINISHED;
1592 static int sequencer_cut_invoke(bContext *C, wmOperator *op, wmEvent *event)
1594 Scene *scene = CTX_data_scene(C);
1595 ARegion *ar= CTX_wm_region(C);
1596 View2D *v2d= UI_view2d_fromcontext(C);
1598 int cut_side= SEQ_SIDE_BOTH;
1599 int cut_frame= CFRA;
1601 if (ED_operator_sequencer_active(C) && v2d)
1602 cut_side= mouse_frame_side(v2d, event->x - ar->winrct.xmin, cut_frame);
1604 RNA_int_set(op->ptr, "frame", cut_frame);
1605 RNA_enum_set(op->ptr, "side", cut_side);
1606 /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */
1608 return sequencer_cut_exec(C, op);
1612 void SEQUENCER_OT_cut(struct wmOperatorType *ot)
1615 ot->name= "Cut Strips";
1616 ot->idname= "SEQUENCER_OT_cut";
1617 ot->description="Cut the selected strips";
1620 ot->invoke= sequencer_cut_invoke;
1621 ot->exec= sequencer_cut_exec;
1622 ot->poll= sequencer_edit_poll;
1625 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1627 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be cut", INT_MIN, INT_MAX);
1628 RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips");
1629 RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting");
1632 /* duplicate operator */
1633 static int apply_unique_name_cb(Sequence *seq, void *arg_pt)
1635 Scene *scene= (Scene *)arg_pt;
1636 char name[sizeof(seq->name)-2];
1638 strcpy(name, seq->name+2);
1639 seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
1640 seq_dupe_animdata(scene, name, seq->name+2);
1645 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
1647 Scene *scene= CTX_data_scene(C);
1648 Editing *ed= seq_give_editing(scene, FALSE);
1650 ListBase nseqbase= {NULL, NULL};
1653 return OPERATOR_CANCELLED;
1655 seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT);
1657 if(nseqbase.first) {
1658 Sequence * seq= nseqbase.first;
1659 /* rely on the nseqbase list being added at the end */
1660 BLI_movelisttolist(ed->seqbasep, &nseqbase);
1662 for( ; seq; seq= seq->next)
1663 seq_recursive_apply(seq, apply_unique_name_cb, scene);
1665 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1666 return OPERATOR_FINISHED;
1669 return OPERATOR_CANCELLED;
1672 static int sequencer_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1674 sequencer_add_duplicate_exec(C, op);
1676 RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
1677 WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
1679 return OPERATOR_FINISHED;
1682 void SEQUENCER_OT_duplicate(wmOperatorType *ot)
1685 ot->name= "Duplicate";
1686 ot->idname= "SEQUENCER_OT_duplicate";
1687 ot->description="Duplicate the selected strips";
1690 ot->invoke= sequencer_add_duplicate_invoke;
1691 ot->exec= sequencer_add_duplicate_exec;
1692 ot->poll= ED_operator_sequencer_active;
1695 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1697 /* to give to transform */
1698 RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
1701 /* delete operator */
1702 static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op))
1704 Scene *scene= CTX_data_scene(C);
1705 Editing *ed= seq_give_editing(scene, FALSE);
1708 int nothingSelected = TRUE;
1710 seq=seq_active_get(scene);
1711 if (seq && seq->flag & SELECT) { /* avoid a loop since this is likely to be selected */
1712 nothingSelected = FALSE;
1714 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1715 if (seq->flag & SELECT) {
1716 nothingSelected = FALSE;
1722 if (nothingSelected)
1723 return OPERATOR_FINISHED;
1725 /* free imbufs of all dependent strips */
1726 for(seq=ed->seqbasep->first; seq; seq=seq->next)
1727 if(seq->flag & SELECT)
1728 update_changed_seq_and_deps(scene, seq, 1, 0);
1730 /* for effects, try to find a replacement input */
1731 for(seq=ed->seqbasep->first; seq; seq=seq->next)
1732 if((seq->type & SEQ_EFFECT) && !(seq->flag & SELECT))
1733 del_seq_find_replace_recurs(scene, seq);
1735 /* delete all selected strips */
1736 recurs_del_seq_flag(scene, ed->seqbasep, SELECT, 0);
1738 /* updates lengths etc */
1739 seq= ed->seqbasep->first;
1741 calc_sequence(scene, seq);
1745 /* free parent metas */
1746 ms= ed->metastack.last;
1748 ms->parseq->strip->len= 0; /* force new alloc */
1749 calc_sequence(scene, ms->parseq);
1753 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1755 return OPERATOR_FINISHED;
1759 void SEQUENCER_OT_delete(wmOperatorType *ot)
1763 ot->name= "Erase Strips";
1764 ot->idname= "SEQUENCER_OT_delete";
1765 ot->description="Erase selected strips from the sequencer";
1768 ot->invoke= WM_operator_confirm;
1769 ot->exec= sequencer_delete_exec;
1770 ot->poll= sequencer_edit_poll;
1773 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1777 /* separate_images operator */
1778 static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
1780 Scene *scene= CTX_data_scene(C);
1781 Editing *ed= seq_give_editing(scene, FALSE);
1783 Sequence *seq, *seq_new;
1785 StripElem *se, *se_new;
1786 int start_ofs, cfra, frame_end;
1787 int step= RNA_int_get(op->ptr, "length");
1789 seq= ed->seqbasep->first; /* poll checks this is valid */
1792 if((seq->flag & SELECT) && (seq->type == SEQ_IMAGE) && (seq->len > 1)) {
1793 /* remove seq so overlap tests dont conflict,
1794 see seq_free_sequence below for the real free'ing */
1795 BLI_remlink(ed->seqbasep, seq);
1796 /* if(seq->ipo) seq->ipo->id.us--; */
1797 /* XXX, remove fcurve and assign to split image strips */
1799 start_ofs = cfra = seq_tx_get_final_left(seq, 0);
1800 frame_end = seq_tx_get_final_right(seq, 0);
1802 while (cfra < frame_end) {
1804 se = give_stripelem(seq, cfra);
1806 seq_new= alloc_sequence(ed->seqbasep, start_ofs, seq->machine);
1807 seq_new->type= SEQ_IMAGE;
1809 seq_new->endstill = step-1;
1812 seq_new->strip= strip_new= MEM_callocN(sizeof(Strip)*1, "strip");
1815 strncpy(strip_new->dir, seq->strip->dir, FILE_MAXDIR-1);
1818 strip_new->stripdata= se_new= MEM_callocN(sizeof(StripElem)*1, "stripelem");
1819 BLI_strncpy(se_new->name, se->name, sizeof(se_new->name));
1820 calc_sequence(scene, seq_new);
1823 seq_new->flag &= ~SEQ_OVERLAP;
1824 if (seq_test_overlap(ed->seqbasep, seq_new)) {
1825 shuffle_seq(ed->seqbasep, seq_new, scene);
1829 /* XXX, COPY FCURVES */
1830 strncpy(seq_new->name+2, seq->name+2, sizeof(seq->name)-2);
1831 seqbase_unique_name_recursive(&scene->ed->seqbase, seq_new);
1837 seq_free_sequence(scene, seq);
1847 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1849 return OPERATOR_FINISHED;
1853 void SEQUENCER_OT_images_separate(wmOperatorType *ot)
1856 ot->name= "Separate Images";
1857 ot->idname= "SEQUENCER_OT_images_separate";
1858 ot->description="On image sequences strips, it return a strip for each image";
1861 ot->invoke= WM_operator_props_popup;
1862 ot->exec= sequencer_separate_images_exec;
1863 ot->poll= sequencer_edit_poll;
1866 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1868 RNA_def_int(ot->srna, "length", 1, 1, 1000, "Length", "Length of each frame", 1, INT_MAX);
1872 /* META Operators */
1874 /* separate_meta_toggle operator */
1875 static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1877 Scene *scene= CTX_data_scene(C);
1878 Editing *ed= seq_give_editing(scene, FALSE);
1879 Sequence *last_seq= seq_active_get(scene);
1882 if(last_seq && last_seq->type==SEQ_META && last_seq->flag & SELECT) {
1883 /* Enter Metastrip */
1884 ms= MEM_mallocN(sizeof(MetaStack), "metastack");
1885 BLI_addtail(&ed->metastack, ms);
1886 ms->parseq= last_seq;
1887 ms->oldbasep= ed->seqbasep;
1889 ed->seqbasep= &last_seq->seqbase;
1891 seq_active_set(scene, NULL);
1895 /* Exit Metastrip (if possible) */
1899 if(ed->metastack.first==NULL)
1900 return OPERATOR_CANCELLED;
1902 ms= ed->metastack.last;
1903 BLI_remlink(&ed->metastack, ms);
1905 ed->seqbasep= ms->oldbasep;
1907 /* recalc all: the meta can have effects connected to it */
1908 for(seq= ed->seqbasep->first; seq; seq= seq->next)
1909 calc_sequence(scene, seq);
1911 seq_active_set(scene, ms->parseq);
1913 ms->parseq->flag |= SELECT;
1914 recurs_sel_seq(ms->parseq);
1920 seq_update_muting(scene, ed);
1921 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1923 return OPERATOR_FINISHED;
1926 void SEQUENCER_OT_meta_toggle(wmOperatorType *ot)
1929 ot->name= "Toggle Meta Strip";
1930 ot->idname= "SEQUENCER_OT_meta_toggle";
1931 ot->description="Toggle a metastrip (to edit enclosed strips)";
1934 ot->exec= sequencer_meta_toggle_exec;
1935 ot->poll= sequencer_edit_poll;
1938 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1942 /* separate_meta_make operator */
1943 static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
1945 Scene *scene= CTX_data_scene(C);
1946 Editing *ed= seq_give_editing(scene, FALSE);
1948 Sequence *seq, *seqm, *next, *last_seq = seq_active_get(scene);
1951 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
1952 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
1953 return OPERATOR_CANCELLED;
1956 /* remove all selected from main list, and put in meta */
1958 seqm= alloc_sequence(ed->seqbasep, 1, 1); /* channel number set later */
1959 strcpy(seqm->name+2, "MetaStrip");
1960 seqm->type= SEQ_META;
1963 seq= ed->seqbasep->first;
1966 if(seq!=seqm && (seq->flag & SELECT)) {
1967 channel_max= MAX2(seq->machine, channel_max);
1968 BLI_remlink(ed->seqbasep, seq);
1969 BLI_addtail(&seqm->seqbase, seq);
1973 seqm->machine= last_seq ? last_seq->machine : channel_max;
1974 calc_sequence(scene, seqm);
1976 seqm->strip= MEM_callocN(sizeof(Strip), "metastrip");
1977 seqm->strip->len= seqm->len;
1980 seq_active_set(scene, seqm);
1982 if( seq_test_overlap(ed->seqbasep, seqm) ) shuffle_seq(ed->seqbasep, seqm, scene);
1984 seq_update_muting(scene, ed);
1986 seqbase_unique_name_recursive(&scene->ed->seqbase, seqm);
1988 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1990 return OPERATOR_FINISHED;
1993 void SEQUENCER_OT_meta_make(wmOperatorType *ot)
1996 ot->name= "Make Meta Strip";
1997 ot->idname= "SEQUENCER_OT_meta_make";
1998 ot->description="Group selected strips into a metastrip";
2001 ot->invoke= WM_operator_confirm;
2002 ot->exec= sequencer_meta_make_exec;
2003 ot->poll= sequencer_edit_poll;
2006 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2010 static int seq_depends_on_meta(Sequence *seq, Sequence *seqm)
2012 if (seq == seqm) return 1;
2013 else if (seq->seq1 && seq_depends_on_meta(seq->seq1, seqm)) return 1;
2014 else if (seq->seq2 && seq_depends_on_meta(seq->seq2, seqm)) return 1;
2015 else if (seq->seq3 && seq_depends_on_meta(seq->seq3, seqm)) return 1;
2019 /* separate_meta_make operator */
2020 static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op))
2022 Scene *scene= CTX_data_scene(C);
2023 Editing *ed= seq_give_editing(scene, FALSE);
2025 Sequence *seq, *last_seq = seq_active_get(scene); /* last_seq checks ed==NULL */
2027 if(last_seq==NULL || last_seq->type!=SEQ_META)
2028 return OPERATOR_CANCELLED;
2030 BLI_movelisttolist(ed->seqbasep, &last_seq->seqbase);
2032 last_seq->seqbase.first= 0;
2033 last_seq->seqbase.last= 0;
2035 BLI_remlink(ed->seqbasep, last_seq);
2036 seq_free_sequence(scene, last_seq);
2038 /* emtpy meta strip, delete all effects depending on it */
2039 for(seq=ed->seqbasep->first; seq; seq=seq->next)
2040 if((seq->type & SEQ_EFFECT) && seq_depends_on_meta(seq, last_seq))
2041 seq->flag |= SEQ_FLAG_DELETE;
2043 recurs_del_seq_flag(scene, ed->seqbasep, SEQ_FLAG_DELETE, 0);
2045 /* test for effects and overlap
2046 * dont use SEQP_BEGIN since that would be recursive */
2047 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2048 if(seq->flag & SELECT) {
2049 seq->flag &= ~SEQ_OVERLAP;
2050 if(seq_test_overlap(ed->seqbasep, seq)) {
2051 shuffle_seq(ed->seqbasep, seq, scene);
2057 seq_update_muting(scene, ed);
2059 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2061 return OPERATOR_FINISHED;
2064 void SEQUENCER_OT_meta_separate(wmOperatorType *ot)
2067 ot->name= "UnMeta Strip";
2068 ot->idname= "SEQUENCER_OT_meta_separate";
2069 ot->description="Put the contents of a metastrip back in the sequencer";
2072 ot->invoke= WM_operator_confirm;
2073 ot->exec= sequencer_meta_separate_exec;
2074 ot->poll= sequencer_edit_poll;
2077 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2080 /* view_all operator */
2081 static int sequencer_view_all_exec(bContext *C, wmOperator *UNUSED(op))
2083 //Scene *scene= CTX_data_scene(C);
2084 bScreen *sc= CTX_wm_screen(C);
2085 ScrArea *area= CTX_wm_area(C);
2086 //ARegion *ar= CTX_wm_region(C);
2087 View2D *v2d= UI_view2d_fromcontext(C);
2090 UI_view2d_curRect_validate(v2d);
2091 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2093 ED_area_tag_redraw(CTX_wm_area(C));
2094 return OPERATOR_FINISHED;
2097 void SEQUENCER_OT_view_all(wmOperatorType *ot)
2100 ot->name= "View All";
2101 ot->idname= "SEQUENCER_OT_view_all";
2102 ot->description="View all the strips in the sequencer";
2105 ot->exec= sequencer_view_all_exec;
2106 ot->poll= ED_operator_sequencer_active;
2109 ot->flag= OPTYPE_REGISTER;
2112 /* view_all operator */
2113 static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op))
2115 bScreen *sc= CTX_wm_screen(C);
2116 ScrArea *area= CTX_wm_area(C);
2118 ARegion *ar= CTX_wm_region(C);
2119 SpaceSeq *sseq= area->spacedata.first;
2120 Scene *scene= CTX_data_scene(C);
2122 View2D *v2d= UI_view2d_fromcontext(C);
2125 UI_view2d_curRect_validate(v2d);
2126 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2129 /* Like zooming on an image view */
2131 int width, height, imgwidth, imgheight;
2136 seq_reset_imageofs(sseq);
2138 imgwidth= (scene->r.size*scene->r.xsch)/100;
2139 imgheight= (scene->r.size*scene->r.ysch)/100;
2141 /* Apply aspect, dosnt need to be that accurate */
2142 imgwidth= (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
2144 if (((imgwidth >= width) || (imgheight >= height)) &&
2145 ((width > 0) && (height > 0))) {
2147 /* Find the zoom value that will fit the image in the image space */
2148 zoomX = ((float)width) / ((float)imgwidth);
2149 zoomY = ((float)height) / ((float)imgheight);
2150 sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY;
2152 sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) );
2159 ED_area_tag_redraw(CTX_wm_area(C));
2160 return OPERATOR_FINISHED;
2163 void SEQUENCER_OT_view_all_preview(wmOperatorType *ot)
2166 ot->name= "View All";
2167 ot->idname= "SEQUENCER_OT_view_all_preview";
2168 ot->description="Zoom preview to fit in the area";
2171 ot->exec= sequencer_view_all_preview_exec;
2172 ot->poll= ED_operator_sequencer_active;
2175 ot->flag= OPTYPE_REGISTER;
2179 static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op)
2181 RenderData *r= &CTX_data_scene(C)->r;
2182 View2D *v2d= UI_view2d_fromcontext(C);
2184 float ratio= RNA_float_get(op->ptr, "ratio");
2186 float winx= (int)(r->size * r->xsch)/100;
2187 float winy= (int)(r->size * r->ysch)/100;
2189 float facx= (v2d->mask.xmax - v2d->mask.xmin) / winx;
2190 float facy= (v2d->mask.ymax - v2d->mask.ymin) / winy;
2192 BLI_resize_rctf(&v2d->cur, (int)(winx*facx*ratio) + 1, (int)(winy*facy*ratio) + 1);
2194 ED_region_tag_redraw(CTX_wm_region(C));
2196 return OPERATOR_FINISHED;
2199 void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot)
2202 ot->name= "Sequencer View Zoom Ratio";
2203 ot->idname= "SEQUENCER_OT_view_zoom_ratio";
2204 ot->description = "Change zoom ratio of sequencer preview";
2207 ot->exec= sequencer_view_zoom_ratio_exec;
2208 ot->poll= ED_operator_sequencer_active;
2211 RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, FLT_MAX,
2212 "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out.", -FLT_MAX, FLT_MAX);
2217 static EnumPropertyItem view_type_items[] = {
2218 {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""},
2219 {SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""},
2220 {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""},
2221 {0, NULL, 0, NULL, NULL}};
2224 /* view_all operator */
2225 static int sequencer_view_toggle_exec(bContext *C, wmOperator *UNUSED(op))
2227 SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
2230 if (sseq->view > SEQ_VIEW_SEQUENCE_PREVIEW) sseq->view = SEQ_VIEW_SEQUENCE;
2232 ED_sequencer_update_view(C, sseq->view);
2234 return OPERATOR_FINISHED;
2237 void SEQUENCER_OT_view_toggle(wmOperatorType *ot)
2240 ot->name= "View Toggle";
2241 ot->idname= "SEQUENCER_OT_view_toggle";
2242 ot->description="Toggle between sequencer views (sequence, preview, both)";
2245 ot->exec= sequencer_view_toggle_exec;
2246 ot->poll= ED_operator_sequencer_active;
2249 ot->flag= OPTYPE_REGISTER;
2253 /* view_selected operator */
2254 static int sequencer_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
2256 Scene *scene= CTX_data_scene(C);
2257 View2D *v2d= UI_view2d_fromcontext(C);
2258 ScrArea *area= CTX_wm_area(C);
2259 bScreen *sc= CTX_wm_screen(C);
2260 Editing *ed= seq_give_editing(scene, FALSE);
2263 int xmin= MAXFRAME*2;
2264 int xmax= -MAXFRAME*2;
2273 return OPERATOR_CANCELLED;
2275 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
2276 if(seq->flag & SELECT) {
2277 xmin= MIN2(xmin, seq->startdisp);
2278 xmax= MAX2(xmax, seq->enddisp);
2280 ymin= MIN2(ymin, seq->machine);
2281 ymax= MAX2(ymax, seq->machine);
2292 orig_height= v2d->cur.ymax - v2d->cur.ymin;
2294 v2d->cur.xmin= xmin;
2295 v2d->cur.xmax= xmax;
2297 v2d->cur.ymin= ymin;
2298 v2d->cur.ymax= ymax;
2300 /* only zoom out vertically */
2301 if (orig_height > v2d->cur.ymax - v2d->cur.ymin) {
2302 ymid= (v2d->cur.ymax + v2d->cur.ymin) / 2;
2304 v2d->cur.ymin= ymid - (orig_height/2);
2305 v2d->cur.ymax= ymid + (orig_height/2);
2308 UI_view2d_curRect_validate(v2d);
2309 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2311 ED_area_tag_redraw(CTX_wm_area(C));
2314 return OPERATOR_FINISHED;
2317 void SEQUENCER_OT_view_selected(wmOperatorType *ot)
2320 ot->name= "View Selected";
2321 ot->idname= "SEQUENCER_OT_view_selected";
2322 ot->description="Zoom the sequencer on the selected strips";
2325 ot->exec= sequencer_view_selected_exec;
2326 ot->poll= ED_operator_sequencer_active;
2329 ot->flag= OPTYPE_REGISTER;
2333 static int find_next_prev_edit(Scene *scene, int cfra, int side)
2335 Editing *ed= seq_give_editing(scene, FALSE);
2336 Sequence *seq,*best_seq = NULL,*frame_seq = NULL;
2338 int dist, best_dist;
2339 best_dist = MAXFRAME*2;
2341 if(ed==NULL) return cfra;
2343 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2348 if (seq->startdisp < cfra) {
2349 dist = cfra - seq->startdisp;
2352 case SEQ_SIDE_RIGHT:
2353 if (seq->startdisp > cfra) {
2354 dist = seq->startdisp - cfra;
2355 } else if (seq->startdisp == cfra) {
2361 if (dist < best_dist) {
2367 /* if no sequence to the right is found and the
2368 frame is on the start of the last sequence,
2369 move to the end of the last sequence */
2370 if (frame_seq) cfra = frame_seq->enddisp;
2372 return best_seq ? best_seq->startdisp : cfra;
2375 static int next_prev_edit_internal(Scene *scene, int side)
2379 int nfra= find_next_prev_edit(scene, cfra, side);
2389 /* move frame to next edit point operator */
2390 static int sequencer_next_edit_exec(bContext *C, wmOperator *UNUSED(op))
2392 Scene *scene= CTX_data_scene(C);
2394 if(!next_prev_edit_internal(scene, SEQ_SIDE_RIGHT))
2395 return OPERATOR_CANCELLED;
2397 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2399 return OPERATOR_FINISHED;
2402 void SEQUENCER_OT_next_edit(wmOperatorType *ot)
2405 ot->name= "Next Edit";
2406 ot->idname= "SEQUENCER_OT_next_edit";
2407 ot->description="Move frame to next edit point";
2410 ot->exec= sequencer_next_edit_exec;
2411 ot->poll= sequencer_edit_poll;
2414 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2419 /* move frame to previous edit point operator */
2420 static int sequencer_previous_edit_exec(bContext *C, wmOperator *UNUSED(op))
2422 Scene *scene= CTX_data_scene(C);
2424 if(!next_prev_edit_internal(scene, SEQ_SIDE_LEFT))
2425 return OPERATOR_CANCELLED;
2427 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2429 return OPERATOR_FINISHED;
2432 void SEQUENCER_OT_previous_edit(wmOperatorType *ot)
2435 ot->name= "Previous Edit";
2436 ot->idname= "SEQUENCER_OT_previous_edit";
2437 ot->description="Move frame to previous edit point";
2440 ot->exec= sequencer_previous_edit_exec;
2441 ot->poll= sequencer_edit_poll;
2444 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2449 static void swap_sequence(Scene* scene, Sequence* seqa, Sequence* seqb)
2451 int gap = seqb->startdisp - seqa->enddisp;
2452 seqb->start = (seqb->start - seqb->startdisp) + seqa->startdisp;
2453 calc_sequence(scene, seqb);
2454 seqa->start = (seqa->start - seqa->startdisp) + seqb->enddisp + gap;
2455 calc_sequence(scene, seqa);
2459 static Sequence* sequence_find_parent(Scene* scene, Sequence* child)
2461 Editing *ed= seq_give_editing(scene, FALSE);
2462 Sequence *parent= NULL;
2465 if(ed==NULL) return NULL;
2467 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2468 if ( (seq != child) && seq_is_parent(seq, child) ) {
2478 static int sequencer_swap_exec(bContext *C, wmOperator *op)
2480 Scene *scene= CTX_data_scene(C);
2481 Editing *ed= seq_give_editing(scene, FALSE);
2482 Sequence *active_seq = seq_active_get(scene);
2483 Sequence *seq, *iseq;
2484 int side= RNA_enum_get(op->ptr, "side");
2486 if(active_seq==NULL) return OPERATOR_CANCELLED;
2488 seq = find_next_prev_sequence(scene, active_seq, side, -1);
2492 /* disallow effect strips */
2493 if (get_sequence_effect_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3))
2494 return OPERATOR_CANCELLED;
2495 if ((get_sequence_effect_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3))
2496 return OPERATOR_CANCELLED;
2500 swap_sequence(scene, seq, active_seq);
2502 case SEQ_SIDE_RIGHT:
2503 swap_sequence(scene, active_seq, seq);
2507 // XXX - should be a generic function
2508 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2509 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2510 calc_sequence(scene, iseq);
2514 /* do this in a new loop since both effects need to be calculated first */
2515 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2516 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2517 /* this may now overlap */
2518 if( seq_test_overlap(ed->seqbasep, iseq) ) {
2519 shuffle_seq(ed->seqbasep, iseq, scene);
2528 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2530 return OPERATOR_FINISHED;
2533 return OPERATOR_CANCELLED;
2536 void SEQUENCER_OT_swap(wmOperatorType *ot)
2539 ot->name= "Swap Strip";
2540 ot->idname= "SEQUENCER_OT_swap";
2541 ot->description="Swap active strip with strip to the left";
2544 ot->exec= sequencer_swap_exec;
2545 ot->poll= sequencer_edit_poll;
2548 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2551 RNA_def_enum(ot->srna, "side", prop_side_lr_types, SEQ_SIDE_RIGHT, "Side", "Side of the strip to swap");
2554 static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op))
2556 int retval = OPERATOR_CANCELLED;
2557 Scene *scene= CTX_data_scene(C);
2558 Sequence *active_seq = seq_active_get(scene);
2559 StripElem *se = NULL;
2561 if(active_seq==NULL)
2562 return OPERATOR_CANCELLED;
2565 if (active_seq->strip) {
2566 switch (active_seq->type) {
2568 se = give_stripelem(active_seq, scene->r.cfra);
2571 se = active_seq->strip->stripdata;
2583 // prevent setting the render size if sequence values aren't initialized
2584 if ( (se->orig_width > 0) && (se->orig_height > 0) ) {
2585 scene->r.xsch= se->orig_width;
2586 scene->r.ysch= se->orig_height;
2587 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
2588 retval = OPERATOR_FINISHED;
2595 void SEQUENCER_OT_rendersize(wmOperatorType *ot)
2598 ot->name= "Set Render Size";
2599 ot->idname= "SEQUENCER_OT_rendersize";
2600 ot->description="Set render size and aspect from active sequence";
2603 ot->exec= sequencer_rendersize_exec;
2604 ot->poll= sequencer_edit_poll;
2607 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2612 static void seq_del_sound(Scene *scene, Sequence *seq)
2614 if(seq->type == SEQ_META) {
2616 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) {
2617 seq_del_sound(scene, iseq);
2620 else if(seq->scene_sound) {
2621 sound_remove_scene_sound(scene, seq->scene_sound);
2622 seq->scene_sound = NULL;
2626 /* TODO, validate scenes */
2627 static int sequencer_copy_exec(bContext *C, wmOperator *op)
2629 Scene *scene= CTX_data_scene(C);
2630 Editing *ed= seq_give_editing(scene, FALSE);
2633 seq_free_clipboard();
2635 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
2636 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
2637 return OPERATOR_CANCELLED;
2640 seqbase_dupli_recursive(scene, NULL, &seqbase_clipboard, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME);
2641 seqbase_clipboard_frame= scene->r.cfra;
2643 /* Need to remove anything that references the current scene */
2644 for(seq= seqbase_clipboard.first; seq; seq= seq->next) {
2645 seq_del_sound(scene, seq);
2648 return OPERATOR_FINISHED;
2651 void SEQUENCER_OT_copy(wmOperatorType *ot)
2655 ot->idname= "SEQUENCER_OT_copy";
2659 ot->exec= sequencer_copy_exec;
2660 ot->poll= sequencer_edit_poll;
2663 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2668 static void seq_offset(Scene *scene, Sequence *seq, int ofs)
2670 if(seq->type == SEQ_META) {
2672 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) {
2673 seq_offset(scene, iseq, ofs);
2680 calc_sequence_disp(scene, seq);
2683 static int sequencer_paste_exec(bContext *C, wmOperator *UNUSED(op))
2685 Scene *scene= CTX_data_scene(C);
2686 Editing *ed= seq_give_editing(scene, TRUE); /* create if needed */
2687 ListBase nseqbase = {NULL, NULL};
2691 deselect_all_seq(scene);
2692 ofs = scene->r.cfra - seqbase_clipboard_frame;
2694 seqbase_dupli_recursive(scene, NULL, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME);
2696 /* transform pasted strips before adding */
2698 for(iseq= nseqbase.first; iseq; iseq= iseq->next) {
2699 seq_offset(scene, iseq, ofs);
2703 BLI_movelisttolist(ed->seqbasep, &nseqbase);
2705 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2707 return OPERATOR_FINISHED;
2710 void SEQUENCER_OT_paste(wmOperatorType *ot)
2714 ot->idname= "SEQUENCER_OT_paste";
2718 ot->exec= sequencer_paste_exec;
2719 ot->poll= ED_operator_sequencer_active;
2722 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2727 static int sequencer_swap_data_exec(bContext *C, wmOperator *op)
2729 Scene *scene= CTX_data_scene(C);
2731 Sequence *seq_other;
2733 if(seq_active_pair_get(scene, &seq_act, &seq_other) == 0) {
2734 BKE_report(op->reports, RPT_ERROR, "Must select 2 strips");
2735 return OPERATOR_CANCELLED;
2738 if(seq_swap(seq_act, seq_other) == 0) {
2739 BKE_report(op->reports, RPT_ERROR, "Strips were not compatible");
2740 return OPERATOR_CANCELLED;
2743 sound_remove_scene_sound(scene, seq_act->scene_sound);
2744 sound_remove_scene_sound(scene, seq_other->scene_sound);
2746 seq_act->scene_sound= NULL;
2747 seq_other->scene_sound= NULL;
2749 calc_sequence(scene, seq_act);
2750 calc_sequence(scene, seq_other);
2752 if(seq_act->sound) sound_add_scene_sound(scene, seq_act, seq_act->startdisp, seq_act->enddisp, seq_act->startofs + seq_act->anim_startofs);
2753 if(seq_other->sound) sound_add_scene_sound(scene, seq_other, seq_other->startdisp, seq_other->enddisp, seq_other->startofs + seq_other->anim_startofs);
2755 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2757 return OPERATOR_FINISHED;
2760 void SEQUENCER_OT_swap_data(wmOperatorType *ot)
2763 ot->name= "Sequencer Swap Data";
2764 ot->idname= "SEQUENCER_OT_swap_data";
2765 ot->description="Swap 2 sequencer strips";
2768 ot->exec= sequencer_swap_data_exec;
2769 ot->poll= ED_operator_sequencer_active;
2772 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2777 /* borderselect operator */
2778 static int view_ghost_border_exec(bContext *C, wmOperator *op)
2780 Scene *scene= CTX_data_scene(C);
2781 Editing *ed= seq_give_editing(scene, FALSE);
2782 View2D *v2d= UI_view2d_fromcontext(C);
2786 /* convert coordinates of rect to 'tot' rect coordinates */
2787 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
2788 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
2791 return OPERATOR_CANCELLED;
2793 rect.xmin /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin));
2794 rect.ymin /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin));
2796 rect.xmax /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin));
2797 rect.ymax /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin));
2804 CLAMP(rect.xmin, 0.0f, 1.0f);
2805 CLAMP(rect.ymin, 0.0f, 1.0f);
2806 CLAMP(rect.xmax, 0.0f, 1.0f);
2807 CLAMP(rect.ymax, 0.0f, 1.0f);
2809 scene->ed->over_border= rect;
2811 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2813 return OPERATOR_FINISHED;
2816 /* ****** Border Select ****** */
2817 void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot)
2820 ot->name= "Border Offset View";
2821 ot->idname= "SEQUENCER_OT_view_ghost_border";
2822 ot->description="Enable border select mode";
2825 ot->invoke= WM_border_select_invoke;
2826 ot->exec= view_ghost_border_exec;
2827 ot->modal= WM_border_select_modal;
2828 ot->poll= sequencer_view_poll;
2834 WM_operator_properties_gesture_border(ot, FALSE);