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 *****
28 /** \file blender/editors/space_sequencer/sequencer_edit.c
42 #include <sys/types.h>
44 #include "MEM_guardedalloc.h"
46 #include "BLI_blenlib.h"
48 #include "BLI_storage_types.h"
49 #include "BLI_utildefines.h"
51 #include "DNA_scene_types.h"
52 #include "DNA_userdef_types.h"
54 #include "BKE_context.h"
55 #include "BKE_global.h"
57 #include "BKE_sequencer.h"
58 #include "BKE_report.h"
59 #include "BKE_sound.h"
64 #include "RNA_define.h"
65 #include "RNA_enum_types.h"
67 /* for menu/popup icons etc etc*/
69 #include "ED_screen.h"
70 #include "ED_transform.h"
71 #include "ED_sequencer.h"
73 #include "UI_view2d.h"
76 #include "sequencer_intern.h"
78 static void error(const char *UNUSED(dummy)) {}
79 static void waitcursor(int UNUSED(val)) {}
80 static void activate_fileselect(int UNUSED(d1), const char *UNUSED(d2), const char *UNUSED(d3), void *UNUSED(d4)) {}
81 static int pupmenu(const char *UNUSED(dummy)) {return 0;}
82 static int okee(const char *UNUSED(dummy)) {return 0;}
86 /* RNA Enums, used in multiple files */
87 EnumPropertyItem sequencer_prop_effect_types[] = {
88 {SEQ_CROSS, "CROSS", 0, "Crossfade", "Crossfade effect strip type"},
89 {SEQ_ADD, "ADD", 0, "Add", "Add effect strip type"},
90 {SEQ_SUB, "SUBTRACT", 0, "Subtract", "Subtract effect strip type"},
91 {SEQ_ALPHAOVER, "ALPHA_OVER", 0, "Alpha Over", "Alpha Over effect strip type"},
92 {SEQ_ALPHAUNDER, "ALPHA_UNDER", 0, "Alpha Under", "Alpha Under effect strip type"},
93 {SEQ_GAMCROSS, "GAMMA_CROSS", 0, "Gamma Cross", "Gamma Cross effect strip type"},
94 {SEQ_MUL, "MULTIPLY", 0, "Multiply", "Multiply effect strip type"},
95 {SEQ_OVERDROP, "OVER_DROP", 0, "Alpha Over Drop", "Alpha Over Drop effect strip type"},
96 {SEQ_PLUGIN, "PLUGIN", 0, "Plugin", "Plugin effect strip type"},
97 {SEQ_WIPE, "WIPE", 0, "Wipe", "Wipe effect strip type"},
98 {SEQ_GLOW, "GLOW", 0, "Glow", "Glow effect strip type"},
99 {SEQ_TRANSFORM, "TRANSFORM", 0, "Transform", "Transform effect strip type"},
100 {SEQ_COLOR, "COLOR", 0, "Color", "Color effect strip type"},
101 {SEQ_SPEED, "SPEED", 0, "Speed", "Color effect strip type"},
102 {SEQ_MULTICAM, "MULTICAM", 0, "Multicam Selector", ""},
103 {SEQ_ADJUSTMENT, "ADJUSTMENT", 0, "Adjustment Layer", ""},
104 {0, NULL, 0, NULL, NULL}
109 EnumPropertyItem prop_side_types[] = {
110 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
111 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
112 {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""},
113 {0, NULL, 0, NULL, NULL}
116 static EnumPropertyItem prop_side_lr_types[] = {
117 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
118 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
119 {0, NULL, 0, NULL, NULL}
122 typedef struct TransSeq {
124 int startstill, endstill;
125 int startdisp, enddisp;
126 int startofs, endofs;
127 int anim_startofs, anim_endofs;
128 /* int final_left, final_right; */ /* UNUSED */
132 void seq_rectf(Sequence *seq, rctf *rectf)
134 if(seq->startstill) rectf->xmin= seq->start;
135 else rectf->xmin= seq->startdisp;
136 rectf->ymin= seq->machine+SEQ_STRIP_OFSBOTTOM;
137 if(seq->endstill) rectf->xmax= seq->start+seq->len;
138 else rectf->xmax= seq->enddisp;
139 rectf->ymax= seq->machine+SEQ_STRIP_OFSTOP;
142 static void change_plugin_seq(Scene *scene, char *str) /* called from fileselect */
144 Editing *ed= seq_give_editing(scene, FALSE);
145 struct SeqEffectHandle sh;
146 Sequence *last_seq= seq_active_get(scene);
148 if(last_seq==NULL || last_seq->type != SEQ_PLUGIN) return;
150 sh = get_sequence_effect(last_seq);
152 sh.init_plugin(last_seq, str);
154 last_seq->machine = MAX3(last_seq->seq1->machine,
155 last_seq->seq2->machine,
156 last_seq->seq3->machine);
158 if( seq_test_overlap(ed->seqbasep, last_seq) ) shuffle_seq(ed->seqbasep, last_seq, scene);
163 void boundbox_seq(Scene *scene, rctf *rect)
166 Editing *ed= seq_give_editing(scene, FALSE);
167 float min[2], max[2];
177 seq= ed->seqbasep->first;
180 if( min[0] > seq->startdisp-1) min[0]= seq->startdisp-1;
181 if( max[0] < seq->enddisp+1) max[0]= seq->enddisp+1;
182 if( max[1] < seq->machine+2) max[1]= seq->machine+2;
194 static int mouse_frame_side(View2D *v2d, short mouse_x, int frame )
202 /* choose the side based on which side of the playhead the mouse is on */
203 UI_view2d_region_to_view(v2d, mval[0], mval[1], &mouseloc[0], &mouseloc[1]);
205 return mouseloc[0] > frame ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT;
209 Sequence *find_neighboring_sequence(Scene *scene, Sequence *test, int lr, int sel)
211 /* sel - 0==unselected, 1==selected, -1==done care*/
213 Editing *ed= seq_give_editing(scene, FALSE);
215 if(ed==NULL) return NULL;
217 if (sel>0) sel = SELECT;
219 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
221 (test->machine==seq->machine) &&
222 ((sel == -1) || (sel && (seq->flag & SELECT)) || (sel==0 && (seq->flag & SELECT)==0) ))
226 if (test->startdisp == (seq->enddisp)) {
231 if (test->enddisp == (seq->startdisp)) {
241 static Sequence *find_next_prev_sequence(Scene *scene, Sequence *test, int lr, int sel)
243 /* sel - 0==unselected, 1==selected, -1==done care*/
244 Sequence *seq,*best_seq = NULL;
245 Editing *ed= seq_give_editing(scene, FALSE);
248 best_dist = MAXFRAME*2;
251 if(ed==NULL) return NULL;
253 seq= ed->seqbasep->first;
256 (test->machine==seq->machine) &&
257 (test->depth==seq->depth) &&
258 ((sel == -1) || (sel==(seq->flag & SELECT))))
264 if (seq->enddisp <= test->startdisp) {
265 dist = test->enddisp - seq->startdisp;
269 if (seq->startdisp >= test->enddisp) {
270 dist = seq->startdisp - test->enddisp;
278 } else if (dist < best_dist) {
285 return best_seq; /* can be null */
289 Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[2])
292 Editing *ed= seq_give_editing(scene, FALSE);
297 *hand= SEQ_SIDE_NONE;
300 if(ed==NULL) return NULL;
302 pixelx = (v2d->cur.xmax - v2d->cur.xmin)/(v2d->mask.xmax - v2d->mask.xmin);
304 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
306 seq= ed->seqbasep->first;
309 if(seq->machine == (int)y) {
310 /* check for both normal strips, and strips that have been flipped horizontally */
311 if( ((seq->startdisp < seq->enddisp) && (seq->startdisp<=x && seq->enddisp>=x)) ||
312 ((seq->startdisp > seq->enddisp) && (seq->startdisp>=x && seq->enddisp<=x)) )
314 if(seq_tx_test(seq)) {
316 /* clamp handles to defined size in pixel space */
318 handsize = seq->handsize;
319 displen = (float)abs(seq->startdisp - seq->enddisp);
321 if (displen / pixelx > 16) { /* dont even try to grab the handles of small strips */
322 /* Set the max value to handle to 1/3 of the total len when its less then 28.
323 * This is important because otherwise selecting handles happens even when you click in the middle */
325 if ((displen/3) < 30*pixelx) {
326 handsize = displen/3;
328 CLAMP(handsize, 7*pixelx, 30*pixelx);
331 if( handsize+seq->startdisp >=x )
332 *hand= SEQ_SIDE_LEFT;
333 else if( -handsize+seq->enddisp <=x )
334 *hand= SEQ_SIDE_RIGHT;
346 static int seq_is_parent(Sequence *par, Sequence *seq)
348 return ((par->seq1 == seq) || (par->seq2 == seq) || (par->seq3 == seq));
351 static int seq_is_predecessor(Sequence *pred, Sequence *seq)
354 if(pred == seq) return 0;
355 else if(seq_is_parent(pred, seq)) return 1;
356 else if(pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1;
357 else if(pred->seq2 && seq_is_predecessor(pred->seq2, seq)) return 1;
358 else if(pred->seq3 && seq_is_predecessor(pred->seq3, seq)) return 1;
363 void deselect_all_seq(Scene *scene)
366 Editing *ed= seq_give_editing(scene, FALSE);
371 SEQP_BEGIN(ed, seq) {
372 seq->flag &= ~SEQ_ALLSEL;
378 void recurs_sel_seq(Sequence *seqm)
382 seq= seqm->seqbase.first;
385 if(seqm->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL)) seq->flag &= ~SEQ_ALLSEL;
386 else if(seqm->flag & SELECT) seq->flag |= SELECT;
387 else seq->flag &= ~SEQ_ALLSEL;
389 if(seq->seqbase.first) recurs_sel_seq(seq);
395 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str)
397 Editing *ed = seq_give_editing(scene, FALSE);
398 Sequence *seq1= NULL, *seq2= NULL, *seq3= NULL, *seq;
403 seq2= seq_active_get(scene);
405 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
406 if(seq->flag & SELECT) {
407 if (seq->type == SEQ_SOUND && get_sequence_effect_num_inputs(type) != 0) {
408 *error_str= "Can't apply effects to audio sequence strips";
411 if((seq != activeseq) && (seq != seq2)) {
412 if(seq2 == NULL) seq2= seq;
413 else if(seq1 == NULL) seq1= seq;
414 else if(seq3 == NULL) seq3= seq;
416 *error_str= "Can't apply effect to more than 3 sequence strips";
423 /* make sequence selection a little bit more intuitive
424 for 3 strips: the last-strip should be sequence3 */
425 if (seq3 != NULL && seq2 != NULL) {
426 Sequence *tmp = seq2;
432 switch(get_sequence_effect_num_inputs(type)) {
434 *selseq1 = *selseq2 = *selseq3 = NULL;
435 return 1; /* succsess */
438 *error_str= "Need at least one selected sequence strip";
441 if(seq1==NULL) seq1= seq2;
442 if(seq3==NULL) seq3= seq2;
444 if(seq1==NULL || seq2==NULL) {
445 *error_str= "Need 2 selected sequence strips";
448 if(seq3 == NULL) seq3= seq2;
451 if (seq1==NULL && seq2==NULL && seq3==NULL) {
452 *error_str= "TODO: in what cases does this happen?";
463 static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq)
465 Sequence *seq1, *seq2, *seq3;
467 /* try to find a replacement input sequence, and flag for later deletion if
468 no replacement can be found */
472 else if(!(seq->type & SEQ_EFFECT))
473 return ((seq->flag & SELECT)? NULL: seq);
474 else if(!(seq->flag & SELECT)) {
475 /* try to find replacement for effect inputs */
476 seq1= del_seq_find_replace_recurs(scene, seq->seq1);
477 seq2= del_seq_find_replace_recurs(scene, seq->seq2);
478 seq3= del_seq_find_replace_recurs(scene, seq->seq3);
480 if(seq1==seq->seq1 && seq2==seq->seq2 && seq3==seq->seq3);
481 else if(seq1 || seq2 || seq3) {
482 seq->seq1= (seq1)? seq1: (seq2)? seq2: seq3;
483 seq->seq2= (seq2)? seq2: (seq1)? seq1: seq3;
484 seq->seq3= (seq3)? seq3: (seq1)? seq1: seq2;
486 update_changed_seq_and_deps(scene, seq, 1, 1);
489 seq->flag |= SELECT; /* mark for delete */
492 if (seq->flag & SELECT) {
493 if((seq1 = del_seq_find_replace_recurs(scene, seq->seq1))) return seq1;
494 if((seq2 = del_seq_find_replace_recurs(scene, seq->seq2))) return seq2;
495 if((seq3 = del_seq_find_replace_recurs(scene, seq->seq3))) return seq3;
502 static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall)
504 Sequence *seq, *seqn;
505 Sequence *last_seq = seq_active_get(scene);
510 if((seq->flag & flag) || deleteall) {
511 BLI_remlink(lb, seq);
512 if(seq==last_seq) seq_active_set(scene, NULL);
513 if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1);
514 seq_free_sequence(scene, seq);
521 static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe)
524 Sequence *seqn = NULL;
525 int skip_dup = FALSE;
528 ts.start= seq->start;
529 ts.machine= seq->machine;
530 ts.startstill= seq->startstill;
531 ts.endstill= seq->endstill;
532 ts.startdisp= seq->startdisp;
533 ts.enddisp= seq->enddisp;
534 ts.startofs= seq->startofs;
535 ts.endofs= seq->endofs;
536 ts.anim_startofs= seq->anim_startofs;
537 ts.anim_endofs= seq->anim_endofs;
541 /* strips with extended stillfames before */
543 if ((seq->startstill) && (cutframe <seq->start)) {
544 /* don't do funny things with METAs ... */
545 if (seq->type == SEQ_META) {
547 seq->startstill = seq->start - cutframe;
549 seq->start= cutframe -1;
550 seq->startstill= cutframe -seq->startdisp -1;
551 seq->anim_endofs += seq->len - 1;
556 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
559 seq->anim_endofs += (seq->start+seq->len) - cutframe;
561 /* strips with extended stillframes after */
562 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
563 seq->endstill -= seq->enddisp - cutframe;
564 /* don't do funny things with METAs ... */
565 if (seq->type == SEQ_META) {
570 reload_sequence_new_file(scene, seq, FALSE);
571 calc_sequence(scene, seq);
575 /* Duplicate AFTER the first change */
576 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
580 seqn->flag |= SELECT;
583 /* strips with extended stillframes before */
584 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
585 seqn->start = ts.start;
586 seqn->startstill= ts.start- cutframe;
587 seqn->anim_endofs = ts.anim_endofs;
588 seqn->endstill = ts.endstill;
592 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
593 seqn->start = cutframe;
594 seqn->startstill = 0;
596 seqn->endofs = ts.endofs;
597 seqn->anim_startofs += cutframe - ts.start;
598 seqn->anim_endofs = ts.anim_endofs;
599 seqn->endstill = ts.endstill;
602 /* strips with extended stillframes after */
603 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
604 seqn->start = cutframe;
606 seqn->anim_startofs += ts.len-1;
607 seqn->endstill = ts.enddisp - cutframe -1;
608 seqn->startstill = 0;
611 reload_sequence_new_file(scene, seqn, FALSE);
612 calc_sequence(scene, seqn);
613 new_tstripdata(seqn);
618 static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe)
621 Sequence *seqn = NULL;
622 int skip_dup = FALSE;
625 ts.start= seq->start;
626 ts.machine= seq->machine;
627 ts.startstill= seq->startstill;
628 ts.endstill= seq->endstill;
629 ts.startdisp= seq->startdisp;
630 ts.enddisp= seq->enddisp;
631 ts.startofs= seq->startofs;
632 ts.endofs= seq->endofs;
633 ts.anim_startofs= seq->anim_startofs;
634 ts.anim_endofs= seq->anim_endofs;
638 /* strips with extended stillfames before */
640 if ((seq->startstill) && (cutframe <seq->start)) {
641 /* don't do funny things with METAs ... */
642 if (seq->type == SEQ_META) {
644 seq->startstill = seq->start - cutframe;
646 seq->start= cutframe -1;
647 seq->startstill= cutframe -seq->startdisp -1;
648 seq->endofs = seq->len - 1;
653 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
654 seq->endofs = (seq->start+seq->len) - cutframe;
656 /* strips with extended stillframes after */
657 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
658 seq->endstill -= seq->enddisp - cutframe;
659 /* don't do funny things with METAs ... */
660 if (seq->type == SEQ_META) {
665 calc_sequence(scene, seq);
669 /* Duplicate AFTER the first change */
670 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
674 seqn->flag |= SELECT;
677 /* strips with extended stillframes before */
678 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
679 seqn->start = ts.start;
680 seqn->startstill= ts.start- cutframe;
681 seqn->endofs = ts.endofs;
682 seqn->endstill = ts.endstill;
686 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
687 seqn->startstill = 0;
688 seqn->startofs = cutframe - ts.start;
689 seqn->endofs = ts.endofs;
690 seqn->endstill = ts.endstill;
693 /* strips with extended stillframes after */
694 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
695 seqn->start = cutframe - ts.len +1;
696 seqn->startofs = ts.len-1;
697 seqn->endstill = ts.enddisp - cutframe -1;
698 seqn->startstill = 0;
701 calc_sequence(scene, seqn);
702 new_tstripdata(seqn);
708 /* like duplicate, but only duplicate and cut overlapping strips,
709 * strips to the left of the cutframe are ignored and strips to the right are moved into the new list */
710 static int cut_seq_list(Scene *scene, ListBase *old, ListBase *new, int cutframe,
711 Sequence * (*cut_seq)(Scene *, Sequence *, int))
713 int did_something = FALSE;
714 Sequence *seq, *seq_next_iter;
719 seq_next_iter = seq->next; /* we need this because we may remove seq */
722 if(seq->flag & SELECT) {
723 if(cutframe > seq->startdisp &&
724 cutframe < seq->enddisp) {
725 Sequence * seqn = cut_seq(scene, seq, cutframe);
727 BLI_addtail(new, seqn);
729 did_something = TRUE;
730 } else if (seq->enddisp <= cutframe) {
732 } else if (seq->startdisp >= cutframe) {
733 /* move into new list */
734 BLI_remlink(old, seq);
735 BLI_addtail(new, seq);
740 return did_something;
743 static int insert_gap(Scene *scene, int gap, int cfra)
746 Editing *ed= seq_give_editing(scene, FALSE);
749 /* all strips >= cfra are shifted */
751 if(ed==NULL) return 0;
753 SEQP_BEGIN(ed, seq) {
754 if(seq->startdisp >= cfra) {
756 calc_sequence(scene, seq);
765 static void touch_seq_files(Scene *scene)
768 Editing *ed= seq_give_editing(scene, FALSE);
771 /* touch all strips with movies */
775 if(okee("Touch and print selected movies")==0) return;
779 SEQP_BEGIN(ed, seq) {
780 if(seq->flag & SELECT) {
781 if(seq->type==SEQ_MOVIE) {
782 if(seq->strip && seq->strip->stripdata) {
783 BLI_make_file_string(G.main->name, str, seq->strip->dir, seq->strip->stripdata->name);
784 BLI_touch(seq->name);
796 static void set_filter_seq(Scene *scene)
799 Editing *ed= seq_give_editing(scene, FALSE);
804 if(okee("Set Deinterlace")==0) return;
806 SEQP_BEGIN(ed, seq) {
807 if(seq->flag & SELECT) {
808 if(seq->type==SEQ_MOVIE) {
809 seq->flag |= SEQ_FILTERY;
810 reload_sequence_new_file(scene, seq, FALSE);
811 calc_sequence(scene, seq);
820 static void seq_remap_paths(Scene *scene)
822 Sequence *seq, *last_seq = seq_active_get(scene);
823 Editing *ed= seq_give_editing(scene, FALSE);
824 char from[FILE_MAX], to[FILE_MAX], stripped[FILE_MAX];
830 BLI_strncpy(from, last_seq->strip->dir, FILE_MAX);
831 // XXX if (0==sbutton(from, 0, sizeof(from)-1, "From: "))
835 // XXX if (0==sbutton(to, 0, sizeof(to)-1, "To: "))
838 if (strcmp(to, from)==0)
841 SEQP_BEGIN(ed, seq) {
842 if(seq->flag & SELECT) {
843 if(strncmp(seq->strip->dir, from, strlen(from))==0) {
844 printf("found %s\n", seq->strip->dir);
846 /* strip off the beginning */
848 BLI_strncpy(stripped, seq->strip->dir + strlen(from), FILE_MAX);
851 BLI_snprintf(seq->strip->dir, sizeof(seq->strip->dir), "%s%s", to, stripped);
852 printf("new %s\n", seq->strip->dir);
861 static void no_gaps(Scene *scene)
863 Editing *ed= seq_give_editing(scene, FALSE);
864 int cfra, first= 0, done;
869 for(cfra= CFRA; cfra<=EFRA; cfra++) {
871 if( evaluate_seq_frame(scene, cfra) ) first= 1;
875 while( evaluate_seq_frame(scene, cfra) == 0) {
876 done= insert_gap(scene, -1, cfra);
886 static int seq_get_snaplimit(View2D *v2d)
888 /* fake mouse coords to get the snap value
889 a bit lazy but its only done once pre transform */
890 float xmouse, ymouse, x;
891 int mval[2] = {24, 0}; /* 24 screen px snap */
893 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
896 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
897 return (int)(x - xmouse);
901 /* Operator functions */
902 int sequencer_edit_poll(bContext *C)
904 return (seq_give_editing(CTX_data_scene(C), FALSE) != NULL);
907 int sequencer_strip_poll(bContext *C)
910 return (((ed= seq_give_editing(CTX_data_scene(C), FALSE)) != NULL) && (ed->act_seq != NULL));
913 int sequencer_strip_has_path_poll(bContext *C)
917 return (((ed= seq_give_editing(CTX_data_scene(C), FALSE)) != NULL) && ((seq= ed->act_seq) != NULL) && (SEQ_HAS_PATH(seq)));
920 int sequencer_view_poll(bContext *C)
922 SpaceSeq *sseq= CTX_wm_space_seq(C);
923 Editing *ed= seq_give_editing(CTX_data_scene(C), FALSE);
924 if (ed && sseq && (sseq->mainb == SEQ_DRAW_IMG_IMBUF))
931 static int sequencer_snap_exec(bContext *C, wmOperator *op)
933 Scene *scene= CTX_data_scene(C);
935 Editing *ed= seq_give_editing(scene, FALSE);
939 snap_frame= RNA_int_get(op->ptr, "frame");
941 /* also check metas */
942 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
943 if (seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK) &&
945 if((seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))==0) {
946 /* simple but no anim update */
947 /* seq->start= snap_frame-seq->startofs+seq->startstill; */
949 seq_translate(scene, seq, (snap_frame-seq->startofs+seq->startstill) - seq->start);
951 if(seq->flag & SEQ_LEFTSEL) {
952 seq_tx_set_final_left(seq, snap_frame);
953 } else { /* SEQ_RIGHTSEL */
954 seq_tx_set_final_right(seq, snap_frame);
956 seq_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL);
958 calc_sequence(scene, seq);
962 /* test for effects and overlap
963 * dont use SEQP_BEGIN since that would be recursive */
964 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
965 if(seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK)) {
966 seq->flag &= ~SEQ_OVERLAP;
967 if( seq_test_overlap(ed->seqbasep, seq) ) {
968 shuffle_seq(ed->seqbasep, seq, scene);
971 else if(seq->type & SEQ_EFFECT) {
972 if(seq->seq1 && (seq->seq1->flag & SELECT))
973 calc_sequence(scene, seq);
974 else if(seq->seq2 && (seq->seq2->flag & SELECT))
975 calc_sequence(scene, seq);
976 else if(seq->seq3 && (seq->seq3->flag & SELECT))
977 calc_sequence(scene, seq);
984 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
986 return OPERATOR_FINISHED;
989 static int sequencer_snap_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
991 Scene *scene = CTX_data_scene(C);
997 RNA_int_set(op->ptr, "frame", snap_frame);
998 return sequencer_snap_exec(C, op);
1001 void SEQUENCER_OT_snap(struct wmOperatorType *ot)
1004 ot->name= "Snap strips";
1005 ot->idname= "SEQUENCER_OT_snap";
1006 ot->description="Frame where selected strips will be snapped";
1009 ot->invoke= sequencer_snap_invoke;
1010 ot->exec= sequencer_snap_exec;
1011 ot->poll= sequencer_edit_poll;
1014 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1016 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be snapped", INT_MIN, INT_MAX);
1020 static int sequencer_mute_exec(bContext *C, wmOperator *op)
1022 Scene *scene= CTX_data_scene(C);
1023 Editing *ed= seq_give_editing(scene, FALSE);
1027 selected= !RNA_boolean_get(op->ptr, "unselected");
1029 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1030 if ((seq->flag & SEQ_LOCK)==0) {
1031 if(selected){ /* mute unselected */
1032 if(seq->flag & SELECT)
1033 seq->flag |= SEQ_MUTE;
1036 if((seq->flag & SELECT)==0)
1037 seq->flag |= SEQ_MUTE;
1042 seq_update_muting(scene, ed);
1043 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1045 return OPERATOR_FINISHED;
1048 void SEQUENCER_OT_mute(struct wmOperatorType *ot)
1051 ot->name= "Mute Strips";
1052 ot->idname= "SEQUENCER_OT_mute";
1053 ot->description="Mute selected strips";
1056 ot->exec= sequencer_mute_exec;
1057 ot->poll= sequencer_edit_poll;
1060 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1062 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Mute unselected rather than selected strips.");
1066 /* unmute operator */
1067 static int sequencer_unmute_exec(bContext *C, wmOperator *op)
1069 Scene *scene= CTX_data_scene(C);
1070 Editing *ed= seq_give_editing(scene, FALSE);
1074 selected= !RNA_boolean_get(op->ptr, "unselected");
1076 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1077 if ((seq->flag & SEQ_LOCK)==0) {
1078 if(selected){ /* unmute unselected */
1079 if(seq->flag & SELECT)
1080 seq->flag &= ~SEQ_MUTE;
1083 if((seq->flag & SELECT)==0)
1084 seq->flag &= ~SEQ_MUTE;
1089 seq_update_muting(scene, ed);
1090 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1092 return OPERATOR_FINISHED;
1095 void SEQUENCER_OT_unmute(struct wmOperatorType *ot)
1098 ot->name= "Un-Mute Strips";
1099 ot->idname= "SEQUENCER_OT_unmute";
1100 ot->description="Un-Mute unselected rather than selected strips";
1103 ot->exec= sequencer_unmute_exec;
1104 ot->poll= sequencer_edit_poll;
1107 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1109 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "UnMute unselected rather than selected strips.");
1114 static int sequencer_lock_exec(bContext *C, wmOperator *UNUSED(op))
1116 Scene *scene= CTX_data_scene(C);
1117 Editing *ed= seq_give_editing(scene, FALSE);
1120 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1121 if (seq->flag & SELECT) {
1122 seq->flag |= SEQ_LOCK;
1126 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1128 return OPERATOR_FINISHED;
1131 void SEQUENCER_OT_lock(struct wmOperatorType *ot)
1134 ot->name= "Lock Strips";
1135 ot->idname= "SEQUENCER_OT_lock";
1136 ot->description="Lock the active strip so that it can't be transformed";
1139 ot->exec= sequencer_lock_exec;
1140 ot->poll= sequencer_edit_poll;
1143 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1146 /* unlock operator */
1147 static int sequencer_unlock_exec(bContext *C, wmOperator *UNUSED(op))
1149 Scene *scene= CTX_data_scene(C);
1150 Editing *ed= seq_give_editing(scene, FALSE);
1153 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1154 if (seq->flag & SELECT) {
1155 seq->flag &= ~SEQ_LOCK;
1159 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1161 return OPERATOR_FINISHED;
1164 void SEQUENCER_OT_unlock(struct wmOperatorType *ot)
1167 ot->name= "UnLock Strips";
1168 ot->idname= "SEQUENCER_OT_unlock";
1169 ot->description="Unlock the active strip so that it can't be transformed";
1172 ot->exec= sequencer_unlock_exec;
1173 ot->poll= sequencer_edit_poll;
1176 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1179 /* reload operator */
1180 static int sequencer_reload_exec(bContext *C, wmOperator *UNUSED(op))
1182 Scene *scene= CTX_data_scene(C);
1183 Editing *ed= seq_give_editing(scene, FALSE);
1186 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1187 if(seq->flag & SELECT) {
1188 update_changed_seq_and_deps(scene, seq, 0, 1);
1192 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1194 return OPERATOR_FINISHED;
1197 void SEQUENCER_OT_reload(struct wmOperatorType *ot)
1200 ot->name= "Reload Strips";
1201 ot->idname= "SEQUENCER_OT_reload";
1202 ot->description="Reload strips in the sequencer";
1205 ot->exec= sequencer_reload_exec;
1206 ot->poll= sequencer_edit_poll;
1209 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1212 /* reload operator */
1213 static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op))
1215 Scene *scene= CTX_data_scene(C);
1216 Editing *ed= seq_give_editing(scene, FALSE);
1218 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE);
1220 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1222 return OPERATOR_FINISHED;
1225 void SEQUENCER_OT_refresh_all(struct wmOperatorType *ot)
1228 ot->name= "Refresh Sequencer";
1229 ot->idname= "SEQUENCER_OT_refresh_all";
1230 ot->description="Refresh the sequencer editor";
1233 ot->exec= sequencer_refresh_all_exec;
1234 ot->poll= sequencer_edit_poll;
1237 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1240 static int sequencer_reassign_inputs_exec(bContext *C, wmOperator *op)
1242 Scene *scene= CTX_data_scene(C);
1243 Sequence *seq1, *seq2, *seq3, *last_seq = seq_active_get(scene);
1244 const char *error_msg;
1246 if(!seq_effect_find_selected(scene, last_seq, last_seq->type, &seq1, &seq2, &seq3, &error_msg)) {
1247 BKE_report(op->reports, RPT_ERROR, error_msg);
1248 return OPERATOR_CANCELLED;
1250 /* see reassigning would create a cycle */
1251 if( seq_is_predecessor(seq1, last_seq) ||
1252 seq_is_predecessor(seq2, last_seq) ||
1253 seq_is_predecessor(seq3, last_seq)
1255 BKE_report(op->reports, RPT_ERROR, "Can't reassign inputs: no cycles allowed");
1256 return OPERATOR_CANCELLED;
1259 last_seq->seq1 = seq1;
1260 last_seq->seq2 = seq2;
1261 last_seq->seq3 = seq3;
1263 update_changed_seq_and_deps(scene, last_seq, 1, 1);
1265 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1267 return OPERATOR_FINISHED;
1270 static int sequencer_effect_poll(bContext *C)
1272 Scene *scene= CTX_data_scene(C);
1273 Editing *ed= seq_give_editing(scene, FALSE);
1276 Sequence *last_seq= seq_active_get(scene);
1277 if(last_seq && (last_seq->type & SEQ_EFFECT)) {
1285 void SEQUENCER_OT_reassign_inputs(struct wmOperatorType *ot)
1288 ot->name= "Reassign Inputs";
1289 ot->idname= "SEQUENCER_OT_reassign_inputs";
1290 ot->description="Reassign the inputs for the effects strip";
1293 ot->exec= sequencer_reassign_inputs_exec;
1294 ot->poll= sequencer_effect_poll;
1297 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1301 static int sequencer_swap_inputs_exec(bContext *C, wmOperator *op)
1303 Scene *scene= CTX_data_scene(C);
1304 Sequence *seq, *last_seq = seq_active_get(scene);
1306 if(last_seq->seq1==NULL || last_seq->seq2 == NULL) {
1307 BKE_report(op->reports, RPT_ERROR, "No valid inputs to swap");
1308 return OPERATOR_CANCELLED;
1311 seq = last_seq->seq1;
1312 last_seq->seq1 = last_seq->seq2;
1313 last_seq->seq2 = seq;
1315 update_changed_seq_and_deps(scene, last_seq, 1, 1);
1317 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1319 return OPERATOR_FINISHED;
1321 void SEQUENCER_OT_swap_inputs(struct wmOperatorType *ot)
1324 ot->name= "Swap Inputs";
1325 ot->idname= "SEQUENCER_OT_swap_inputs";
1326 ot->description="Swap the first two inputs for the effects strip";
1329 ot->exec= sequencer_swap_inputs_exec;
1330 ot->poll= sequencer_effect_poll;
1333 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1338 static EnumPropertyItem prop_cut_types[] = {
1339 {SEQ_CUT_SOFT, "SOFT", 0, "Soft", ""},
1340 {SEQ_CUT_HARD, "HARD", 0, "Hard", ""},
1341 {0, NULL, 0, NULL, NULL}
1344 static int sequencer_cut_exec(bContext *C, wmOperator *op)
1346 Scene *scene= CTX_data_scene(C);
1347 Editing *ed= seq_give_editing(scene, FALSE);
1348 int cut_side, cut_hard, cut_frame;
1353 cut_frame= RNA_int_get(op->ptr, "frame");
1354 cut_hard= RNA_enum_get(op->ptr, "type");
1355 cut_side= RNA_enum_get(op->ptr, "side");
1357 newlist.first= newlist.last= NULL;
1359 if (cut_hard==SEQ_CUT_HARD) {
1360 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_hard);
1362 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_soft);
1365 if (newlist.first) { /* got new strips ? */
1367 BLI_movelisttolist(ed->seqbasep, &newlist);
1369 if (cut_side != SEQ_SIDE_BOTH) {
1370 SEQP_BEGIN(ed, seq) {
1371 if (cut_side==SEQ_SIDE_LEFT) {
1372 if ( seq->startdisp >= cut_frame ) {
1373 seq->flag &= ~SEQ_ALLSEL;
1376 if ( seq->enddisp <= cut_frame ) {
1377 seq->flag &= ~SEQ_ALLSEL;
1387 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1389 return OPERATOR_FINISHED;
1393 static int sequencer_cut_invoke(bContext *C, wmOperator *op, wmEvent *event)
1395 Scene *scene = CTX_data_scene(C);
1396 View2D *v2d= UI_view2d_fromcontext(C);
1398 int cut_side= SEQ_SIDE_BOTH;
1399 int cut_frame= CFRA;
1401 if (ED_operator_sequencer_active(C) && v2d)
1402 cut_side= mouse_frame_side(v2d, event->mval[0], cut_frame);
1404 RNA_int_set(op->ptr, "frame", cut_frame);
1405 RNA_enum_set(op->ptr, "side", cut_side);
1406 /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */
1408 return sequencer_cut_exec(C, op);
1412 void SEQUENCER_OT_cut(struct wmOperatorType *ot)
1415 ot->name= "Cut Strips";
1416 ot->idname= "SEQUENCER_OT_cut";
1417 ot->description="Cut the selected strips";
1420 ot->invoke= sequencer_cut_invoke;
1421 ot->exec= sequencer_cut_exec;
1422 ot->poll= sequencer_edit_poll;
1425 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1427 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be cut", INT_MIN, INT_MAX);
1428 RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips");
1429 RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting");
1432 /* duplicate operator */
1433 static int apply_unique_name_cb(Sequence *seq, void *arg_pt)
1435 Scene *scene= (Scene *)arg_pt;
1436 char name[sizeof(seq->name)-2];
1438 strcpy(name, seq->name+2);
1439 seqbase_unique_name_recursive(&scene->ed->seqbase, seq);
1440 seq_dupe_animdata(scene, name, seq->name+2);
1445 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
1447 Scene *scene= CTX_data_scene(C);
1448 Editing *ed= seq_give_editing(scene, FALSE);
1450 ListBase nseqbase= {NULL, NULL};
1453 return OPERATOR_CANCELLED;
1455 seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT);
1457 if(nseqbase.first) {
1458 Sequence * seq= nseqbase.first;
1459 /* rely on the nseqbase list being added at the end */
1460 BLI_movelisttolist(ed->seqbasep, &nseqbase);
1462 for( ; seq; seq= seq->next)
1463 seq_recursive_apply(seq, apply_unique_name_cb, scene);
1465 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1466 return OPERATOR_FINISHED;
1469 return OPERATOR_CANCELLED;
1472 static int sequencer_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1474 sequencer_add_duplicate_exec(C, op);
1476 RNA_enum_set(op->ptr, "mode", TFM_TRANSLATION);
1477 WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
1479 return OPERATOR_FINISHED;
1482 void SEQUENCER_OT_duplicate(wmOperatorType *ot)
1485 ot->name= "Duplicate Strips";
1486 ot->idname= "SEQUENCER_OT_duplicate";
1487 ot->description="Duplicate the selected strips";
1490 ot->invoke= sequencer_add_duplicate_invoke;
1491 ot->exec= sequencer_add_duplicate_exec;
1492 ot->poll= ED_operator_sequencer_active;
1495 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1497 /* to give to transform */
1498 RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
1501 /* delete operator */
1502 static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op))
1504 Scene *scene= CTX_data_scene(C);
1505 Editing *ed= seq_give_editing(scene, FALSE);
1508 int nothingSelected = TRUE;
1510 seq=seq_active_get(scene);
1511 if (seq && seq->flag & SELECT) { /* avoid a loop since this is likely to be selected */
1512 nothingSelected = FALSE;
1514 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1515 if (seq->flag & SELECT) {
1516 nothingSelected = FALSE;
1522 if (nothingSelected)
1523 return OPERATOR_FINISHED;
1525 /* for effects, try to find a replacement input */
1526 for(seq=ed->seqbasep->first; seq; seq=seq->next)
1527 if((seq->type & SEQ_EFFECT) && !(seq->flag & SELECT))
1528 del_seq_find_replace_recurs(scene, seq);
1530 /* delete all selected strips */
1531 recurs_del_seq_flag(scene, ed->seqbasep, SELECT, 0);
1533 /* updates lengths etc */
1534 seq= ed->seqbasep->first;
1536 calc_sequence(scene, seq);
1540 /* free parent metas */
1541 ms= ed->metastack.last;
1543 ms->parseq->strip->len= 0; /* force new alloc */
1544 calc_sequence(scene, ms->parseq);
1548 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1550 return OPERATOR_FINISHED;
1554 void SEQUENCER_OT_delete(wmOperatorType *ot)
1558 ot->name= "Erase Strips";
1559 ot->idname= "SEQUENCER_OT_delete";
1560 ot->description="Erase selected strips from the sequencer";
1563 ot->invoke= WM_operator_confirm;
1564 ot->exec= sequencer_delete_exec;
1565 ot->poll= sequencer_edit_poll;
1568 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1572 /* offset clear operator */
1573 static int sequencer_offset_clear_exec(bContext *C, wmOperator *UNUSED(op))
1575 Scene *scene= CTX_data_scene(C);
1576 Editing *ed= seq_give_editing(scene, FALSE);
1579 /* for effects, try to find a replacement input */
1580 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
1581 if((seq->type & SEQ_EFFECT)==0 && (seq->flag & SELECT)) {
1582 seq->startofs= seq->endofs= seq->startstill= seq->endstill= 0;
1586 /* updates lengths etc */
1587 seq= ed->seqbasep->first;
1589 calc_sequence(scene, seq);
1593 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
1594 if((seq->type & SEQ_EFFECT)==0 && (seq->flag & SELECT)) {
1595 if(seq_test_overlap(ed->seqbasep, seq)) {
1596 shuffle_seq(ed->seqbasep, seq, scene);
1601 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1603 return OPERATOR_FINISHED;
1607 void SEQUENCER_OT_offset_clear(wmOperatorType *ot)
1611 ot->name= "Clear Strip Offset";
1612 ot->idname= "SEQUENCER_OT_offset_clear";
1613 ot->description="Clear strip offsets from the start and end frames";
1616 ot->exec= sequencer_offset_clear_exec;
1617 ot->poll= sequencer_edit_poll;
1620 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1624 /* separate_images operator */
1625 static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
1627 Scene *scene= CTX_data_scene(C);
1628 Editing *ed= seq_give_editing(scene, FALSE);
1630 Sequence *seq, *seq_new;
1632 StripElem *se, *se_new;
1633 int start_ofs, cfra, frame_end;
1634 int step= RNA_int_get(op->ptr, "length");
1636 seq= ed->seqbasep->first; /* poll checks this is valid */
1639 if((seq->flag & SELECT) && (seq->type == SEQ_IMAGE) && (seq->len > 1)) {
1640 /* remove seq so overlap tests dont conflict,
1641 see seq_free_sequence below for the real free'ing */
1642 BLI_remlink(ed->seqbasep, seq);
1643 /* if(seq->ipo) seq->ipo->id.us--; */
1644 /* XXX, remove fcurve and assign to split image strips */
1646 start_ofs = cfra = seq_tx_get_final_left(seq, 0);
1647 frame_end = seq_tx_get_final_right(seq, 0);
1649 while (cfra < frame_end) {
1651 se = give_stripelem(seq, cfra);
1653 seq_new= seq_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME);
1654 BLI_addtail(ed->seqbasep, seq_new);
1656 seq_new->start= start_ofs;
1657 seq_new->type= SEQ_IMAGE;
1659 seq_new->endstill = step-1;
1662 strip_new= seq_new->strip;
1667 se_new= strip_new->stripdata;
1668 BLI_strncpy(se_new->name, se->name, sizeof(se_new->name));
1669 calc_sequence(scene, seq_new);
1672 seq_new->flag &= ~SEQ_OVERLAP;
1673 if (seq_test_overlap(ed->seqbasep, seq_new)) {
1674 shuffle_seq(ed->seqbasep, seq_new, scene);
1678 /* XXX, COPY FCURVES */
1684 seq_free_sequence(scene, seq);
1694 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1696 return OPERATOR_FINISHED;
1700 void SEQUENCER_OT_images_separate(wmOperatorType *ot)
1703 ot->name= "Separate Images";
1704 ot->idname= "SEQUENCER_OT_images_separate";
1705 ot->description="On image sequences strips, it return a strip for each image";
1708 ot->exec= sequencer_separate_images_exec;
1709 ot->poll= sequencer_edit_poll;
1712 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1714 RNA_def_int(ot->srna, "length", 1, 1, 1000, "Length", "Length of each frame", 1, INT_MAX);
1718 /* META Operators */
1720 /* separate_meta_toggle operator */
1721 static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1723 Scene *scene= CTX_data_scene(C);
1724 Editing *ed= seq_give_editing(scene, FALSE);
1725 Sequence *last_seq= seq_active_get(scene);
1728 if(last_seq && last_seq->type==SEQ_META && last_seq->flag & SELECT) {
1729 /* Enter Metastrip */
1730 ms= MEM_mallocN(sizeof(MetaStack), "metastack");
1731 BLI_addtail(&ed->metastack, ms);
1732 ms->parseq= last_seq;
1733 ms->oldbasep= ed->seqbasep;
1735 ed->seqbasep= &last_seq->seqbase;
1737 seq_active_set(scene, NULL);
1741 /* Exit Metastrip (if possible) */
1745 if(ed->metastack.first==NULL)
1746 return OPERATOR_CANCELLED;
1748 ms= ed->metastack.last;
1749 BLI_remlink(&ed->metastack, ms);
1751 ed->seqbasep= ms->oldbasep;
1753 /* recalc all: the meta can have effects connected to it */
1754 for(seq= ed->seqbasep->first; seq; seq= seq->next)
1755 calc_sequence(scene, seq);
1757 seq_active_set(scene, ms->parseq);
1759 ms->parseq->flag |= SELECT;
1760 recurs_sel_seq(ms->parseq);
1766 seq_update_muting(scene, ed);
1767 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1769 return OPERATOR_FINISHED;
1772 void SEQUENCER_OT_meta_toggle(wmOperatorType *ot)
1775 ot->name= "Toggle Meta Strip";
1776 ot->idname= "SEQUENCER_OT_meta_toggle";
1777 ot->description="Toggle a metastrip (to edit enclosed strips)";
1780 ot->exec= sequencer_meta_toggle_exec;
1781 ot->poll= sequencer_edit_poll;
1784 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1788 /* separate_meta_make operator */
1789 static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
1791 Scene *scene= CTX_data_scene(C);
1792 Editing *ed= seq_give_editing(scene, FALSE);
1794 Sequence *seq, *seqm, *next, *last_seq = seq_active_get(scene);
1797 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
1798 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
1799 return OPERATOR_CANCELLED;
1802 /* remove all selected from main list, and put in meta */
1804 seqm= alloc_sequence(ed->seqbasep, 1, 1); /* channel number set later */
1805 strcpy(seqm->name+2, "MetaStrip");
1806 seqm->type= SEQ_META;
1809 seq= ed->seqbasep->first;
1812 if(seq!=seqm && (seq->flag & SELECT)) {
1813 channel_max= MAX2(seq->machine, channel_max);
1814 BLI_remlink(ed->seqbasep, seq);
1815 BLI_addtail(&seqm->seqbase, seq);
1819 seqm->machine= last_seq ? last_seq->machine : channel_max;
1820 calc_sequence(scene, seqm);
1822 seqm->strip= MEM_callocN(sizeof(Strip), "metastrip");
1823 seqm->strip->len= seqm->len;
1826 seq_active_set(scene, seqm);
1828 if( seq_test_overlap(ed->seqbasep, seqm) ) shuffle_seq(ed->seqbasep, seqm, scene);
1830 seq_update_muting(scene, ed);
1832 seqbase_unique_name_recursive(&scene->ed->seqbase, seqm);
1834 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1836 return OPERATOR_FINISHED;
1839 void SEQUENCER_OT_meta_make(wmOperatorType *ot)
1842 ot->name= "Make Meta Strip";
1843 ot->idname= "SEQUENCER_OT_meta_make";
1844 ot->description="Group selected strips into a metastrip";
1847 ot->invoke= WM_operator_confirm;
1848 ot->exec= sequencer_meta_make_exec;
1849 ot->poll= sequencer_edit_poll;
1852 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1856 static int seq_depends_on_meta(Sequence *seq, Sequence *seqm)
1858 if (seq == seqm) return 1;
1859 else if (seq->seq1 && seq_depends_on_meta(seq->seq1, seqm)) return 1;
1860 else if (seq->seq2 && seq_depends_on_meta(seq->seq2, seqm)) return 1;
1861 else if (seq->seq3 && seq_depends_on_meta(seq->seq3, seqm)) return 1;
1865 /* separate_meta_make operator */
1866 static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op))
1868 Scene *scene= CTX_data_scene(C);
1869 Editing *ed= seq_give_editing(scene, FALSE);
1871 Sequence *seq, *last_seq = seq_active_get(scene); /* last_seq checks ed==NULL */
1873 if(last_seq==NULL || last_seq->type!=SEQ_META)
1874 return OPERATOR_CANCELLED;
1876 BLI_movelisttolist(ed->seqbasep, &last_seq->seqbase);
1878 last_seq->seqbase.first= NULL;
1879 last_seq->seqbase.last= NULL;
1881 BLI_remlink(ed->seqbasep, last_seq);
1882 seq_free_sequence(scene, last_seq);
1884 /* emtpy meta strip, delete all effects depending on it */
1885 for(seq=ed->seqbasep->first; seq; seq=seq->next)
1886 if((seq->type & SEQ_EFFECT) && seq_depends_on_meta(seq, last_seq))
1887 seq->flag |= SEQ_FLAG_DELETE;
1889 recurs_del_seq_flag(scene, ed->seqbasep, SEQ_FLAG_DELETE, 0);
1891 /* test for effects and overlap
1892 * dont use SEQP_BEGIN since that would be recursive */
1893 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1894 if(seq->flag & SELECT) {
1895 seq->flag &= ~SEQ_OVERLAP;
1896 if(seq_test_overlap(ed->seqbasep, seq)) {
1897 shuffle_seq(ed->seqbasep, seq, scene);
1903 seq_update_muting(scene, ed);
1905 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1907 return OPERATOR_FINISHED;
1910 void SEQUENCER_OT_meta_separate(wmOperatorType *ot)
1913 ot->name= "UnMeta Strip";
1914 ot->idname= "SEQUENCER_OT_meta_separate";
1915 ot->description="Put the contents of a metastrip back in the sequencer";
1918 ot->invoke= WM_operator_confirm;
1919 ot->exec= sequencer_meta_separate_exec;
1920 ot->poll= sequencer_edit_poll;
1923 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1926 /* view_all operator */
1927 static int sequencer_view_all_exec(bContext *C, wmOperator *UNUSED(op))
1929 //Scene *scene= CTX_data_scene(C);
1930 bScreen *sc= CTX_wm_screen(C);
1931 ScrArea *area= CTX_wm_area(C);
1932 //ARegion *ar= CTX_wm_region(C);
1933 View2D *v2d= UI_view2d_fromcontext(C);
1936 UI_view2d_curRect_validate(v2d);
1937 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
1939 ED_area_tag_redraw(CTX_wm_area(C));
1940 return OPERATOR_FINISHED;
1943 void SEQUENCER_OT_view_all(wmOperatorType *ot)
1946 ot->name= "View All";
1947 ot->idname= "SEQUENCER_OT_view_all";
1948 ot->description="View all the strips in the sequencer";
1951 ot->exec= sequencer_view_all_exec;
1952 ot->poll= ED_operator_sequencer_active;
1955 ot->flag= OPTYPE_REGISTER;
1958 /* view_all operator */
1959 static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op))
1961 bScreen *sc= CTX_wm_screen(C);
1962 ScrArea *area= CTX_wm_area(C);
1964 ARegion *ar= CTX_wm_region(C);
1965 SpaceSeq *sseq= area->spacedata.first;
1966 Scene *scene= CTX_data_scene(C);
1968 View2D *v2d= UI_view2d_fromcontext(C);
1971 UI_view2d_curRect_validate(v2d);
1972 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
1975 /* Like zooming on an image view */
1977 int width, height, imgwidth, imgheight;
1982 seq_reset_imageofs(sseq);
1984 imgwidth= (scene->r.size*scene->r.xsch)/100;
1985 imgheight= (scene->r.size*scene->r.ysch)/100;
1987 /* Apply aspect, dosnt need to be that accurate */
1988 imgwidth= (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
1990 if (((imgwidth >= width) || (imgheight >= height)) &&
1991 ((width > 0) && (height > 0))) {
1993 /* Find the zoom value that will fit the image in the image space */
1994 zoomX = ((float)width) / ((float)imgwidth);
1995 zoomY = ((float)height) / ((float)imgheight);
1996 sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY;
1998 sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) );
2005 ED_area_tag_redraw(CTX_wm_area(C));
2006 return OPERATOR_FINISHED;
2009 void SEQUENCER_OT_view_all_preview(wmOperatorType *ot)
2012 ot->name= "View All";
2013 ot->idname= "SEQUENCER_OT_view_all_preview";
2014 ot->description="Zoom preview to fit in the area";
2017 ot->exec= sequencer_view_all_preview_exec;
2018 ot->poll= ED_operator_sequencer_active;
2021 ot->flag= OPTYPE_REGISTER;
2025 static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op)
2027 RenderData *r= &CTX_data_scene(C)->r;
2028 View2D *v2d= UI_view2d_fromcontext(C);
2030 float ratio= RNA_float_get(op->ptr, "ratio");
2032 float winx= (int)(r->size * r->xsch)/100;
2033 float winy= (int)(r->size * r->ysch)/100;
2035 float facx= (v2d->mask.xmax - v2d->mask.xmin) / winx;
2036 float facy= (v2d->mask.ymax - v2d->mask.ymin) / winy;
2038 BLI_resize_rctf(&v2d->cur, (int)(winx*facx*ratio) + 1, (int)(winy*facy*ratio) + 1);
2040 ED_region_tag_redraw(CTX_wm_region(C));
2042 return OPERATOR_FINISHED;
2045 void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot)
2048 ot->name= "Sequencer View Zoom Ratio";
2049 ot->idname= "SEQUENCER_OT_view_zoom_ratio";
2050 ot->description = "Change zoom ratio of sequencer preview";
2053 ot->exec= sequencer_view_zoom_ratio_exec;
2054 ot->poll= ED_operator_sequencer_active;
2057 RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, FLT_MAX,
2058 "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out.", -FLT_MAX, FLT_MAX);
2063 static EnumPropertyItem view_type_items[] = {
2064 {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""},
2065 {SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""},
2066 {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""},
2067 {0, NULL, 0, NULL, NULL}};
2070 /* view_all operator */
2071 static int sequencer_view_toggle_exec(bContext *C, wmOperator *UNUSED(op))
2073 SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
2076 if (sseq->view > SEQ_VIEW_SEQUENCE_PREVIEW) sseq->view = SEQ_VIEW_SEQUENCE;
2078 ED_sequencer_update_view(C, sseq->view);
2080 return OPERATOR_FINISHED;
2083 void SEQUENCER_OT_view_toggle(wmOperatorType *ot)
2086 ot->name= "View Toggle";
2087 ot->idname= "SEQUENCER_OT_view_toggle";
2088 ot->description="Toggle between sequencer views (sequence, preview, both)";
2091 ot->exec= sequencer_view_toggle_exec;
2092 ot->poll= ED_operator_sequencer_active;
2095 ot->flag= OPTYPE_REGISTER;
2099 /* view_selected operator */
2100 static int sequencer_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
2102 Scene *scene= CTX_data_scene(C);
2103 View2D *v2d= UI_view2d_fromcontext(C);
2104 ScrArea *area= CTX_wm_area(C);
2105 bScreen *sc= CTX_wm_screen(C);
2106 Editing *ed= seq_give_editing(scene, FALSE);
2109 int xmin= MAXFRAME*2;
2110 int xmax= -MAXFRAME*2;
2119 return OPERATOR_CANCELLED;
2121 for(seq=ed->seqbasep->first; seq; seq=seq->next) {
2122 if(seq->flag & SELECT) {
2123 xmin= MIN2(xmin, seq->startdisp);
2124 xmax= MAX2(xmax, seq->enddisp);
2126 ymin= MIN2(ymin, seq->machine);
2127 ymax= MAX2(ymax, seq->machine);
2138 orig_height= v2d->cur.ymax - v2d->cur.ymin;
2140 v2d->cur.xmin= xmin;
2141 v2d->cur.xmax= xmax;
2143 v2d->cur.ymin= ymin;
2144 v2d->cur.ymax= ymax;
2146 /* only zoom out vertically */
2147 if (orig_height > v2d->cur.ymax - v2d->cur.ymin) {
2148 ymid= (v2d->cur.ymax + v2d->cur.ymin) / 2;
2150 v2d->cur.ymin= ymid - (orig_height/2);
2151 v2d->cur.ymax= ymid + (orig_height/2);
2154 UI_view2d_curRect_validate(v2d);
2155 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2157 ED_area_tag_redraw(CTX_wm_area(C));
2160 return OPERATOR_FINISHED;
2163 void SEQUENCER_OT_view_selected(wmOperatorType *ot)
2166 ot->name= "View Selected";
2167 ot->idname= "SEQUENCER_OT_view_selected";
2168 ot->description="Zoom the sequencer on the selected strips";
2171 ot->exec= sequencer_view_selected_exec;
2172 ot->poll= ED_operator_sequencer_active;
2175 ot->flag= OPTYPE_REGISTER;
2179 static int find_next_prev_edit(Scene *scene, int cfra, int side)
2181 Editing *ed= seq_give_editing(scene, FALSE);
2182 Sequence *seq,*best_seq = NULL,*frame_seq = NULL;
2184 int dist, best_dist;
2185 best_dist = MAXFRAME*2;
2187 if(ed==NULL) return cfra;
2189 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2194 if (seq->startdisp < cfra) {
2195 dist = cfra - seq->startdisp;
2198 case SEQ_SIDE_RIGHT:
2199 if (seq->startdisp > cfra) {
2200 dist = seq->startdisp - cfra;
2201 } else if (seq->startdisp == cfra) {
2207 if (dist < best_dist) {
2213 /* if no sequence to the right is found and the
2214 frame is on the start of the last sequence,
2215 move to the end of the last sequence */
2216 if (frame_seq) cfra = frame_seq->enddisp;
2218 return best_seq ? best_seq->startdisp : cfra;
2221 static int next_prev_edit_internal(Scene *scene, int side)
2225 int nfra= find_next_prev_edit(scene, cfra, side);
2235 /* move frame to next edit point operator */
2236 static int sequencer_next_edit_exec(bContext *C, wmOperator *UNUSED(op))
2238 Scene *scene= CTX_data_scene(C);
2240 if(!next_prev_edit_internal(scene, SEQ_SIDE_RIGHT))
2241 return OPERATOR_CANCELLED;
2243 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2245 return OPERATOR_FINISHED;
2248 void SEQUENCER_OT_next_edit(wmOperatorType *ot)
2251 ot->name= "Next Edit";
2252 ot->idname= "SEQUENCER_OT_next_edit";
2253 ot->description="Move frame to next edit point";
2256 ot->exec= sequencer_next_edit_exec;
2257 ot->poll= sequencer_edit_poll;
2260 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2265 /* move frame to previous edit point operator */
2266 static int sequencer_previous_edit_exec(bContext *C, wmOperator *UNUSED(op))
2268 Scene *scene= CTX_data_scene(C);
2270 if(!next_prev_edit_internal(scene, SEQ_SIDE_LEFT))
2271 return OPERATOR_CANCELLED;
2273 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2275 return OPERATOR_FINISHED;
2278 void SEQUENCER_OT_previous_edit(wmOperatorType *ot)
2281 ot->name= "Previous Edit";
2282 ot->idname= "SEQUENCER_OT_previous_edit";
2283 ot->description="Move frame to previous edit point";
2286 ot->exec= sequencer_previous_edit_exec;
2287 ot->poll= sequencer_edit_poll;
2290 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2295 static void swap_sequence(Scene* scene, Sequence* seqa, Sequence* seqb)
2297 int gap = seqb->startdisp - seqa->enddisp;
2298 seqb->start = (seqb->start - seqb->startdisp) + seqa->startdisp;
2299 calc_sequence(scene, seqb);
2300 seqa->start = (seqa->start - seqa->startdisp) + seqb->enddisp + gap;
2301 calc_sequence(scene, seqa);
2305 static Sequence* sequence_find_parent(Scene* scene, Sequence* child)
2307 Editing *ed= seq_give_editing(scene, FALSE);
2308 Sequence *parent= NULL;
2311 if(ed==NULL) return NULL;
2313 for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2314 if ( (seq != child) && seq_is_parent(seq, child) ) {
2324 static int sequencer_swap_exec(bContext *C, wmOperator *op)
2326 Scene *scene= CTX_data_scene(C);
2327 Editing *ed= seq_give_editing(scene, FALSE);
2328 Sequence *active_seq = seq_active_get(scene);
2329 Sequence *seq, *iseq;
2330 int side= RNA_enum_get(op->ptr, "side");
2332 if(active_seq==NULL) return OPERATOR_CANCELLED;
2334 seq = find_next_prev_sequence(scene, active_seq, side, -1);
2338 /* disallow effect strips */
2339 if (get_sequence_effect_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3))
2340 return OPERATOR_CANCELLED;
2341 if ((get_sequence_effect_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3))
2342 return OPERATOR_CANCELLED;
2346 swap_sequence(scene, seq, active_seq);
2348 case SEQ_SIDE_RIGHT:
2349 swap_sequence(scene, active_seq, seq);
2353 // XXX - should be a generic function
2354 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2355 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2356 calc_sequence(scene, iseq);
2360 /* do this in a new loop since both effects need to be calculated first */
2361 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2362 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2363 /* this may now overlap */
2364 if( seq_test_overlap(ed->seqbasep, iseq) ) {
2365 shuffle_seq(ed->seqbasep, iseq, scene);
2374 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2376 return OPERATOR_FINISHED;
2379 return OPERATOR_CANCELLED;
2382 void SEQUENCER_OT_swap(wmOperatorType *ot)
2385 ot->name= "Swap Strip";
2386 ot->idname= "SEQUENCER_OT_swap";
2387 ot->description="Swap active strip with strip to the left";
2390 ot->exec= sequencer_swap_exec;
2391 ot->poll= sequencer_edit_poll;
2394 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2397 RNA_def_enum(ot->srna, "side", prop_side_lr_types, SEQ_SIDE_RIGHT, "Side", "Side of the strip to swap");
2400 static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op))
2402 int retval = OPERATOR_CANCELLED;
2403 Scene *scene= CTX_data_scene(C);
2404 Sequence *active_seq = seq_active_get(scene);
2405 StripElem *se = NULL;
2407 if(active_seq==NULL)
2408 return OPERATOR_CANCELLED;
2411 if (active_seq->strip) {
2412 switch (active_seq->type) {
2414 se = give_stripelem(active_seq, scene->r.cfra);
2417 se = active_seq->strip->stripdata;
2429 // prevent setting the render size if sequence values aren't initialized
2430 if ( (se->orig_width > 0) && (se->orig_height > 0) ) {
2431 scene->r.xsch= se->orig_width;
2432 scene->r.ysch= se->orig_height;
2433 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
2434 retval = OPERATOR_FINISHED;
2441 void SEQUENCER_OT_rendersize(wmOperatorType *ot)
2444 ot->name= "Set Render Size";
2445 ot->idname= "SEQUENCER_OT_rendersize";
2446 ot->description="Set render size and aspect from active sequence";
2449 ot->exec= sequencer_rendersize_exec;
2450 ot->poll= sequencer_edit_poll;
2453 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2458 static void seq_del_sound(Scene *scene, Sequence *seq)
2460 if(seq->type == SEQ_META) {
2462 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) {
2463 seq_del_sound(scene, iseq);
2466 else if(seq->scene_sound) {
2467 sound_remove_scene_sound(scene, seq->scene_sound);
2468 seq->scene_sound = NULL;
2472 /* TODO, validate scenes */
2473 static int sequencer_copy_exec(bContext *C, wmOperator *op)
2475 Scene *scene= CTX_data_scene(C);
2476 Editing *ed= seq_give_editing(scene, FALSE);
2479 ListBase nseqbase= {NULL, NULL};
2481 seq_free_clipboard();
2483 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
2484 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
2485 return OPERATOR_CANCELLED;
2488 seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME);
2490 /* To make sure the copied strips have unique names between each other add
2491 * them temporarily to the end of the original seqbase. (bug 25932)
2493 if(nseqbase.first) {
2494 Sequence *seq, *first_seq = nseqbase.first;
2495 BLI_movelisttolist(ed->seqbasep, &nseqbase);
2497 for(seq=first_seq; seq; seq=seq->next)
2498 seq_recursive_apply(seq, apply_unique_name_cb, scene);
2500 seqbase_clipboard.first = first_seq;
2501 seqbase_clipboard.last = ed->seqbasep->last;
2503 if(first_seq->prev) {
2504 first_seq->prev->next = NULL;
2505 ed->seqbasep->last = first_seq->prev;
2506 first_seq->prev = NULL;
2510 seqbase_clipboard_frame= scene->r.cfra;
2512 /* Need to remove anything that references the current scene */
2513 for(seq= seqbase_clipboard.first; seq; seq= seq->next) {
2514 seq_del_sound(scene, seq);
2517 return OPERATOR_FINISHED;
2520 void SEQUENCER_OT_copy(wmOperatorType *ot)
2524 ot->idname= "SEQUENCER_OT_copy";
2528 ot->exec= sequencer_copy_exec;
2529 ot->poll= sequencer_edit_poll;
2532 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2537 static int sequencer_paste_exec(bContext *C, wmOperator *UNUSED(op))
2539 Scene *scene= CTX_data_scene(C);
2540 Editing *ed= seq_give_editing(scene, TRUE); /* create if needed */
2541 ListBase nseqbase = {NULL, NULL};
2545 deselect_all_seq(scene);
2546 ofs = scene->r.cfra - seqbase_clipboard_frame;
2548 seqbase_dupli_recursive(scene, NULL, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME);
2550 /* transform pasted strips before adding */
2552 for(iseq= nseqbase.first; iseq; iseq= iseq->next) {
2553 seq_translate(scene, iseq, ofs);
2554 seq_sound_init(scene, iseq);
2558 iseq = nseqbase.first;
2560 BLI_movelisttolist(ed->seqbasep, &nseqbase);
2562 /* make sure the pasted strips have unique names between them */
2563 for(; iseq; iseq=iseq->next)
2564 seq_recursive_apply(iseq, apply_unique_name_cb, scene);
2566 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2568 return OPERATOR_FINISHED;
2571 void SEQUENCER_OT_paste(wmOperatorType *ot)
2575 ot->idname= "SEQUENCER_OT_paste";
2579 ot->exec= sequencer_paste_exec;
2580 ot->poll= ED_operator_sequencer_active;
2583 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2588 static int sequencer_swap_data_exec(bContext *C, wmOperator *op)
2590 Scene *scene= CTX_data_scene(C);
2592 Sequence *seq_other;
2593 const char *error_msg;
2595 if(seq_active_pair_get(scene, &seq_act, &seq_other) == 0) {
2596 BKE_report(op->reports, RPT_ERROR, "Must select 2 strips");
2597 return OPERATOR_CANCELLED;
2600 if(seq_swap(seq_act, seq_other, &error_msg) == 0) {
2601 BKE_report(op->reports, RPT_ERROR, error_msg);
2602 return OPERATOR_CANCELLED;
2605 sound_remove_scene_sound(scene, seq_act->scene_sound);
2606 sound_remove_scene_sound(scene, seq_other->scene_sound);
2608 seq_act->scene_sound= NULL;
2609 seq_other->scene_sound= NULL;
2611 calc_sequence(scene, seq_act);
2612 calc_sequence(scene, seq_other);
2614 if(seq_act->sound) sound_add_scene_sound(scene, seq_act, seq_act->startdisp, seq_act->enddisp, seq_act->startofs + seq_act->anim_startofs);
2615 if(seq_other->sound) sound_add_scene_sound(scene, seq_other, seq_other->startdisp, seq_other->enddisp, seq_other->startofs + seq_other->anim_startofs);
2617 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2619 return OPERATOR_FINISHED;
2622 void SEQUENCER_OT_swap_data(wmOperatorType *ot)
2625 ot->name= "Sequencer Swap Data";
2626 ot->idname= "SEQUENCER_OT_swap_data";
2627 ot->description="Swap 2 sequencer strips";
2630 ot->exec= sequencer_swap_data_exec;
2631 ot->poll= ED_operator_sequencer_active;
2634 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2639 /* borderselect operator */
2640 static int view_ghost_border_exec(bContext *C, wmOperator *op)
2642 Scene *scene= CTX_data_scene(C);
2643 Editing *ed= seq_give_editing(scene, FALSE);
2644 View2D *v2d= UI_view2d_fromcontext(C);
2648 /* convert coordinates of rect to 'tot' rect coordinates */
2649 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin);
2650 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax);
2653 return OPERATOR_CANCELLED;
2655 rect.xmin /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin));
2656 rect.ymin /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin));
2658 rect.xmax /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin));
2659 rect.ymax /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin));
2666 CLAMP(rect.xmin, 0.0f, 1.0f);
2667 CLAMP(rect.ymin, 0.0f, 1.0f);
2668 CLAMP(rect.xmax, 0.0f, 1.0f);
2669 CLAMP(rect.ymax, 0.0f, 1.0f);
2671 scene->ed->over_border= rect;
2673 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2675 return OPERATOR_FINISHED;
2678 /* ****** Border Select ****** */
2679 void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot)
2682 ot->name= "Border Offset View";
2683 ot->idname= "SEQUENCER_OT_view_ghost_border";
2684 ot->description="Enable border select mode";
2687 ot->invoke= WM_border_select_invoke;
2688 ot->exec= view_ghost_border_exec;
2689 ot->modal= WM_border_select_modal;
2690 ot->poll= sequencer_view_poll;
2691 ot->cancel= WM_border_select_cancel;
2697 WM_operator_properties_gesture_border(ot, FALSE);
2703 static EnumPropertyItem prop_change_effect_input_types[] = {
2704 {0, "A_B", 0, "A -> B", ""},
2705 {1, "B_C", 0, "B -> C", ""},
2706 {2, "A_C", 0, "A -> C", ""},
2707 {0, NULL, 0, NULL, NULL}
2710 static int sequencer_change_effect_input_exec(bContext *C, wmOperator *op)
2712 Scene *scene= CTX_data_scene(C);
2713 Editing *ed= seq_give_editing(scene, FALSE);
2714 Sequence *seq= seq_active_get(scene);
2716 Sequence **seq_1, **seq_2;
2718 switch(RNA_enum_get(op->ptr, "swap")) {
2733 if(*seq_1 == NULL || *seq_2 == NULL) {
2734 BKE_report(op->reports, RPT_ERROR, "One of the effect inputs is unset, can't swap");
2735 return OPERATOR_CANCELLED;
2738 SWAP(Sequence *, *seq_1, *seq_2);
2741 update_changed_seq_and_deps(scene, seq, 0, 1);
2743 /* important else we dont get the imbuf cache flushed */
2744 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE);
2746 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2748 return OPERATOR_FINISHED;
2751 void SEQUENCER_OT_change_effect_input(struct wmOperatorType *ot)
2754 ot->name= "Change Effect Input";
2755 ot->idname= "SEQUENCER_OT_change_effect_input";
2759 ot->exec= sequencer_change_effect_input_exec;
2760 ot->poll= sequencer_effect_poll;
2763 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2765 ot->prop= RNA_def_enum(ot->srna, "swap", prop_change_effect_input_types, 0, "Swap", "The effect inputs to swap");
2768 static int sequencer_change_effect_type_exec(bContext *C, wmOperator *op)
2770 Scene *scene= CTX_data_scene(C);
2771 Editing *ed= seq_give_editing(scene, FALSE);
2772 Sequence *seq= seq_active_get(scene);
2773 const int new_type= RNA_enum_get(op->ptr, "type");
2775 /* free previous effect and init new effect */
2776 struct SeqEffectHandle sh;
2778 if ((seq->type & SEQ_EFFECT) == 0) {
2779 return OPERATOR_CANCELLED;
2782 /* can someone explain the logic behind only allowing to increse this,
2783 * copied from 2.4x - campbell */
2784 if (get_sequence_effect_num_inputs(seq->type) <
2785 get_sequence_effect_num_inputs(new_type)
2787 BKE_report(op->reports, RPT_ERROR, "New effect needs more input strips");
2788 return OPERATOR_CANCELLED;
2791 sh = get_sequence_effect(seq);
2794 seq->type= new_type;
2796 sh = get_sequence_effect(seq);
2801 update_changed_seq_and_deps(scene, seq, 0, 1);
2803 /* important else we dont get the imbuf cache flushed */
2804 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE);
2806 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2808 return OPERATOR_FINISHED;
2811 void SEQUENCER_OT_change_effect_type(struct wmOperatorType *ot)
2814 ot->name= "Change Effect Type";
2815 ot->idname= "SEQUENCER_OT_change_effect_type";
2819 ot->exec= sequencer_change_effect_type_exec;
2820 ot->poll= sequencer_effect_poll;
2823 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2825 ot->prop= RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, SEQ_CROSS, "Type", "Sequencer effect type");
2828 static int sequencer_change_path_exec(bContext *C, wmOperator *op)
2830 Scene *scene= CTX_data_scene(C);
2831 Editing *ed= seq_give_editing(scene, FALSE);
2832 Sequence *seq= seq_active_get(scene);
2834 if(seq->type == SEQ_IMAGE) {
2835 char directory[FILE_MAX];
2836 const int len= RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files"));
2840 return OPERATOR_CANCELLED;
2842 RNA_string_get(op->ptr, "directory", directory);
2843 BLI_strncpy(seq->strip->dir, directory, sizeof(seq->strip->dir));
2845 if(seq->strip->stripdata) {
2846 MEM_freeN(seq->strip->stripdata);
2848 seq->strip->stripdata= se= MEM_callocN(len*sizeof(StripElem), "stripelem");
2850 RNA_BEGIN(op->ptr, itemptr, "files") {
2851 char *filename= RNA_string_get_alloc(&itemptr, "name", NULL, 0);
2852 BLI_strncpy(se->name, filename, sizeof(se->name));
2853 MEM_freeN(filename);
2858 /* reset these else we wont see all the images */
2859 seq->anim_startofs= seq->anim_endofs= 0;
2861 /* correct start/end frames so we dont move
2862 * important not to set seq->len= len; allow the function to handle it */
2863 reload_sequence_new_file(scene, seq, TRUE);
2865 calc_sequence(scene, seq);
2867 /* important else we dont get the imbuf cache flushed */
2868 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE);
2871 /* lame, set rna filepath */
2873 char filepath[FILE_MAX];
2875 RNA_pointer_create(&scene->id, &RNA_Sequence, seq, &seq_ptr);
2877 RNA_string_get(op->ptr, "filepath", filepath);
2878 RNA_string_set(&seq_ptr, "filepath", filepath);
2881 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2883 return OPERATOR_FINISHED;
2886 static int sequencer_change_path_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
2888 Scene *scene= CTX_data_scene(C);
2889 Sequence *seq= seq_active_get(scene);
2891 RNA_string_set(op->ptr, "directory", seq->strip->dir);
2893 /* set default display depending on seq type */
2894 if(seq->type == SEQ_IMAGE) {
2895 RNA_boolean_set(op->ptr, "filter_movie", 0);
2898 RNA_boolean_set(op->ptr, "filter_image", 0);
2901 WM_event_add_fileselect(C, op);
2903 return OPERATOR_RUNNING_MODAL;
2906 void SEQUENCER_OT_change_path(struct wmOperatorType *ot)
2909 ot->name= "Change Data/Files";
2910 ot->idname= "SEQUENCER_OT_change_path";
2914 ot->exec= sequencer_change_path_exec;
2915 ot->invoke= sequencer_change_path_invoke;
2916 ot->poll= sequencer_strip_has_path_poll;
2919 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2921 WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY|WM_FILESEL_RELPATH|WM_FILESEL_FILEPATH|WM_FILESEL_FILES);