Move some sequencer functions about, no functional changes.
[blender-staging.git] / source / blender / editors / space_sequencer / sequencer_edit.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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.
10  *
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.
15  *
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.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation, 2003-2009
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include <stdlib.h>
29 #include <math.h>
30 #include <string.h>
31
32 #ifndef WIN32
33 #include <unistd.h>
34 #else
35 #include <io.h>
36 #endif
37 #include <sys/types.h>
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_storage_types.h"
44
45
46 #include "DNA_ipo_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_userdef_types.h"
49
50 #include "BKE_context.h"
51 #include "BKE_global.h"
52 #include "BKE_image.h"
53 #include "BKE_library.h"
54 #include "BKE_main.h"
55 #include "BKE_plugin_types.h"
56 #include "BKE_sequencer.h"
57 #include "BKE_scene.h"
58 #include "BKE_utildefines.h"
59 #include "BKE_report.h"
60 #include "BKE_sound.h"
61
62 #include "WM_api.h"
63 #include "WM_types.h"
64
65 #include "RNA_define.h"
66
67 /* for menu/popup icons etc etc*/
68
69 #include "ED_screen.h"
70 #include "ED_transform.h"
71 #include "ED_sequencer.h"
72
73 #include "UI_view2d.h"
74
75 /* own include */
76 #include "sequencer_intern.h"
77
78 static void error(const char *dummy) {}
79 static void waitcursor(int val) {}
80 static void activate_fileselect(int d1, char *d2, char *d3, void *d4) {}
81 static int pupmenu(const char *dummy) {return 0;}
82 static int okee(const char *dummy) {return 0;}
83
84
85 /* XXX */
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         {0, NULL, 0, NULL, NULL}
104 };
105
106 /* mute operator */
107
108 EnumPropertyItem prop_side_types[] = {
109         {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
110         {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
111         {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""},
112         {0, NULL, 0, NULL, NULL}
113 };
114
115 EnumPropertyItem prop_side_lr_types[] = {
116         {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
117         {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
118         {0, NULL, 0, NULL, NULL}
119 };
120
121 typedef struct TransSeq {
122         int start, machine;
123         int startstill, endstill;
124         int startdisp, enddisp;
125         int startofs, endofs;
126         int final_left, final_right;
127         int len;
128 } TransSeq;
129
130 Sequence *get_foreground_frame_seq(Scene *scene, int frame)
131 {
132         Editing *ed= seq_give_editing(scene, FALSE);
133         Sequence *seq, *best_seq=NULL;
134         int best_machine = -1;
135         
136         if(!ed) return NULL;
137         
138         for (seq=ed->seqbasep->first; seq; seq= seq->next) {
139                 if(seq->flag & SEQ_MUTE || seq->startdisp > frame || seq->enddisp <= frame)
140                         continue;
141                 /* only use elements you can see - not */
142                 if (ELEM5(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_COLOR)) {
143                         if (seq->machine > best_machine) {
144                                 best_seq = seq;
145                                 best_machine = seq->machine;
146                         }
147                 }
148         }
149         return best_seq;
150 }
151
152 void seq_rectf(Sequence *seq, rctf *rectf)
153 {
154         if(seq->startstill) rectf->xmin= seq->start;
155         else rectf->xmin= seq->startdisp;
156         rectf->ymin= seq->machine+SEQ_STRIP_OFSBOTTOM;
157         if(seq->endstill) rectf->xmax= seq->start+seq->len;
158         else rectf->xmax= seq->enddisp;
159         rectf->ymax= seq->machine+SEQ_STRIP_OFSTOP;
160 }
161
162 static void change_plugin_seq(Scene *scene, char *str)  /* called from fileselect */
163 {
164         Editing *ed= seq_give_editing(scene, FALSE);
165         struct SeqEffectHandle sh;
166         Sequence *last_seq= seq_active_get(scene);
167
168         if(last_seq && last_seq->type != SEQ_PLUGIN) return;
169
170         sh = get_sequence_effect(last_seq);
171         sh.free(last_seq);
172         sh.init_plugin(last_seq, str);
173
174         last_seq->machine = MAX3(last_seq->seq1->machine, 
175                                  last_seq->seq2->machine, 
176                                  last_seq->seq3->machine);
177
178         if( seq_test_overlap(ed->seqbasep, last_seq) ) shuffle_seq(ed->seqbasep, last_seq, scene);
179         
180 }
181
182
183 void boundbox_seq(Scene *scene, rctf *rect)
184 {
185         Sequence *seq;
186         Editing *ed= seq_give_editing(scene, FALSE);
187         float min[2], max[2];
188
189         
190         if(ed==NULL) return;
191
192         min[0]= 0.0;
193         max[0]= EFRA+1;
194         min[1]= 0.0;
195         max[1]= 8.0;
196
197         seq= ed->seqbasep->first;
198         while(seq) {
199
200                 if( min[0] > seq->startdisp-1) min[0]= seq->startdisp-1;
201                 if( max[0] < seq->enddisp+1) max[0]= seq->enddisp+1;
202                 if( max[1] < seq->machine+2.0) max[1]= seq->machine+2.0;
203
204                 seq= seq->next;
205         }
206
207         rect->xmin= min[0];
208         rect->xmax= max[0];
209         rect->ymin= min[1];
210         rect->ymax= max[1];
211
212 }
213
214 int mouse_frame_side(View2D *v2d, short mouse_x, int frame ) 
215 {
216         short mval[2];
217         float mouseloc[2];
218         
219         mval[0]= mouse_x;
220         mval[1]= 0;
221         
222         /* choose the side based on which side of the playhead the mouse is on */
223         UI_view2d_region_to_view(v2d, mval[0], mval[1], &mouseloc[0], &mouseloc[1]);
224         
225         return mouseloc[0] > frame ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT;
226 }
227
228
229 Sequence *find_neighboring_sequence(Scene *scene, Sequence *test, int lr, int sel) 
230 {
231         /* sel - 0==unselected, 1==selected, -1==done care*/
232         Sequence *seq;
233         Editing *ed= seq_give_editing(scene, FALSE);
234
235         if(ed==NULL) return NULL;
236
237         if (sel>0) sel = SELECT;
238         
239         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
240                 if(     (seq!=test) &&
241                         (test->machine==seq->machine) &&
242                         ((sel == -1) || (sel && (seq->flag & SELECT)) || (sel==0 && (seq->flag & SELECT)==0)  ))
243                 {
244                         switch (lr) {
245                         case SEQ_SIDE_LEFT:
246                                 if (test->startdisp == (seq->enddisp)) {
247                                         return seq;
248                                 }
249                                 break;
250                         case SEQ_SIDE_RIGHT:
251                                 if (test->enddisp == (seq->startdisp)) {
252                                         return seq;
253                                 }
254                                 break;
255                         }
256                 }
257         }
258         return NULL;
259 }
260
261 Sequence *find_next_prev_sequence(Scene *scene, Sequence *test, int lr, int sel) 
262 {
263         /* sel - 0==unselected, 1==selected, -1==done care*/
264         Sequence *seq,*best_seq = NULL;
265         Editing *ed= seq_give_editing(scene, FALSE);
266         
267         int dist, best_dist;
268         best_dist = MAXFRAME*2;
269
270         
271         if(ed==NULL) return NULL;
272
273         seq= ed->seqbasep->first;
274         while(seq) {
275                 if(             (seq!=test) &&
276                                 (test->machine==seq->machine) &&
277                                 (test->depth==seq->depth) &&
278                                 ((sel == -1) || (sel==(seq->flag & SELECT))))
279                 {
280                         dist = MAXFRAME*2;
281                         
282                         switch (lr) {
283                         case SEQ_SIDE_LEFT:
284                                 if (seq->enddisp <= test->startdisp) {
285                                         dist = test->enddisp - seq->startdisp;
286                                 }
287                                 break;
288                         case SEQ_SIDE_RIGHT:
289                                 if (seq->startdisp >= test->enddisp) {
290                                         dist = seq->startdisp - test->enddisp;
291                                 }
292                                 break;
293                         }
294                         
295                         if (dist==0) {
296                                 best_seq = seq;
297                                 break;
298                         } else if (dist < best_dist) {
299                                 best_dist = dist;
300                                 best_seq = seq;
301                         }
302                 }
303                 seq= seq->next;
304         }
305         return best_seq; /* can be null */
306 }
307
308
309 Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, short mval[2])
310 {
311         Sequence *seq;
312         Editing *ed= seq_give_editing(scene, FALSE);
313         float x, y;
314         float pixelx;
315         float handsize;
316         float displen;
317         *hand= SEQ_SIDE_NONE;
318
319         
320         if(ed==NULL) return NULL;
321         
322         pixelx = (v2d->cur.xmax - v2d->cur.xmin)/(v2d->mask.xmax - v2d->mask.xmin);
323
324         UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
325         
326         seq= ed->seqbasep->first;
327         
328         while(seq) {
329                 if(seq->machine == (int)y) {
330                         /* check for both normal strips, and strips that have been flipped horizontally */
331                         if( ((seq->startdisp < seq->enddisp) && (seq->startdisp<=x && seq->enddisp>=x)) ||
332                                 ((seq->startdisp > seq->enddisp) && (seq->startdisp>=x && seq->enddisp<=x)) )
333                         {
334                                 if(seq_tx_test(seq)) {
335                                         
336                                         /* clamp handles to defined size in pixel space */
337                                         
338                                         handsize = seq->handsize;
339                                         displen = (float)abs(seq->startdisp - seq->enddisp);
340                                         
341                                         if (displen / pixelx > 16) { /* dont even try to grab the handles of small strips */
342                                                 /* Set the max value to handle to 1/3 of the total len when its less then 28.
343                                                 * This is important because otherwise selecting handles happens even when you click in the middle */
344                                                 
345                                                 if ((displen/3) < 30*pixelx) {
346                                                         handsize = displen/3;
347                                                 } else {
348                                                         CLAMP(handsize, 7*pixelx, 30*pixelx);
349                                                 }
350                                                 
351                                                 if( handsize+seq->startdisp >=x )
352                                                         *hand= SEQ_SIDE_LEFT;
353                                                 else if( -handsize+seq->enddisp <=x )
354                                                         *hand= SEQ_SIDE_RIGHT;
355                                         }
356                                 }
357                                 return seq;
358                         }
359                 }
360                 seq= seq->next;
361         }
362         return 0;
363 }
364
365
366 static int seq_is_parent(Sequence *par, Sequence *seq)
367 {
368         return ((par->seq1 == seq) || (par->seq2 == seq) || (par->seq3 == seq));
369 }
370
371 static int seq_is_predecessor(Sequence *pred, Sequence *seq)
372 {
373         if (!pred) return 0;
374         if(pred == seq) return 0;
375         else if(seq_is_parent(pred, seq)) return 1;
376         else if(pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1;
377         else if(pred->seq2 && seq_is_predecessor(pred->seq2, seq)) return 1;
378         else if(pred->seq3 && seq_is_predecessor(pred->seq3, seq)) return 1;
379
380         return 0;
381 }
382
383 void deselect_all_seq(Scene *scene)
384 {
385         Sequence *seq;
386         Editing *ed= seq_give_editing(scene, FALSE);
387
388         
389         if(ed==NULL) return;
390
391         SEQP_BEGIN(ed, seq) {
392                 seq->flag &= ~SEQ_ALLSEL;
393         }
394         SEQ_END
395                 
396 }
397
398 void recurs_sel_seq(Sequence *seqm)
399 {
400         Sequence *seq;
401
402         seq= seqm->seqbase.first;
403         while(seq) {
404
405                 if(seqm->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL)) seq->flag &= ~SEQ_ALLSEL;
406                 else if(seqm->flag & SELECT) seq->flag |= SELECT;
407                 else seq->flag &= ~SEQ_ALLSEL;
408
409                 if(seq->seqbase.first) recurs_sel_seq(seq);
410
411                 seq= seq->next;
412         }
413 }
414
415 int event_to_efftype(int event)
416 {
417         if(event==2) return SEQ_CROSS;
418         if(event==3) return SEQ_GAMCROSS;
419         if(event==4) return SEQ_ADD;
420         if(event==5) return SEQ_SUB;
421         if(event==6) return SEQ_MUL;
422         if(event==7) return SEQ_ALPHAOVER;
423         if(event==8) return SEQ_ALPHAUNDER;
424         if(event==9) return SEQ_OVERDROP;
425         if(event==10) return SEQ_PLUGIN;
426         if(event==13) return SEQ_WIPE;
427         if(event==14) return SEQ_GLOW;
428         if(event==15) return SEQ_TRANSFORM;
429         if(event==16) return SEQ_COLOR;
430         if(event==17) return SEQ_SPEED;
431         return 0;
432 }
433
434 #if 0
435 static void reload_sound_strip(Scene *scene, char *name)
436 {
437         Editing *ed;
438         Sequence *seq, *seqact;
439         SpaceFile *sfile;
440         Sequence *last_seq= seq_active_get(scene);
441
442         ed= scene->ed;
443
444         if(last_seq==0 || last_seq->type!=SEQ_SOUND) return;
445         seqact= last_seq;       /* last_seq changes in alloc_sequence */
446
447         /* search sfile */
448 //      sfile= scrarea_find_space_of_type(curarea, SPACE_FILE);
449         if(sfile==0) return;
450
451         waitcursor(1);
452
453         seq = sfile_to_snd_sequence(sfile, seqact->start, seqact->machine);
454         printf("seq->type: %i\n", seq->type);
455         if(seq && seq!=seqact) {
456                 /* i'm not sure about this one, seems to work without it -- sgefant */
457                 seq_free_strip(seqact->strip);
458
459                 seqact->strip= seq->strip;
460
461                 seqact->len= seq->len;
462                 calc_sequence(scene, seqact);
463
464                 seq->strip= 0;
465                 seq_free_sequence(scene, seq);
466                 BLI_remlink(ed->seqbasep, seq);
467
468                 seq= ed->seqbasep->first;
469
470         }
471
472         waitcursor(0);
473
474 }
475 #endif
476
477 static void reload_image_strip(Scene *scene, char *name)
478 {
479         Editing *ed= seq_give_editing(scene, FALSE);
480         Sequence *seq=NULL, *seqact;
481         SpaceFile *sfile=NULL;
482         Sequence *last_seq= seq_active_get(scene);
483
484
485
486         if(last_seq==0 || last_seq->type!=SEQ_IMAGE) return;
487         seqact= last_seq;       /* last_seq changes in alloc_sequence */
488
489         /* search sfile */
490 //      sfile= scrarea_find_space_of_type(curarea, SPACE_FILE);
491         if(sfile==0) return;
492
493         waitcursor(1);
494
495 //      seq= sfile_to_sequence(scene, sfile, seqact->start, seqact->machine, 1); // XXX ADD BACK
496         if(seq && seq!=seqact) {
497                 seq_free_strip(seqact->strip);
498
499                 seqact->strip= seq->strip;
500
501                 seqact->len= seq->len;
502                 calc_sequence(scene, seqact);
503
504                 seq->strip= 0;
505                 seq_free_sequence(scene, seq);
506                 BLI_remlink(ed->seqbasep, seq);
507
508                 update_changed_seq_and_deps(scene, seqact, 1, 1);
509         }
510         waitcursor(0);
511
512 }
513
514
515 void change_sequence(Scene *scene)
516 {
517         Editing *ed= seq_give_editing(scene, FALSE);
518         Sequence *last_seq= seq_active_get(scene);
519         Scene *sce;
520         short event;
521
522         if(last_seq==0) return;
523
524         if(last_seq->type & SEQ_EFFECT) {
525                 event = pupmenu("Change Effect%t"
526                                 "|Switch A <-> B %x1"
527                                 "|Switch B <-> C %x10"
528                                 "|Plugin%x11"
529                                 "|Recalculate%x12"
530                                 "|Cross%x2"
531                                 "|Gamma Cross%x3"
532                                 "|Add%x4"
533                                 "|Sub%x5"
534                                 "|Mul%x6"
535                                 "|Alpha Over%x7"
536                                 "|Alpha Under%x8"
537                                 "|Alpha Over Drop%x9"
538                                 "|Wipe%x13"
539                                 "|Glow%x14"
540                                 "|Transform%x15"
541                                 "|Color Generator%x16"
542                                 "|Speed Control%x17");
543                 if(event > 0) {
544                         if(event==1) {
545                                 SWAP(Sequence *,last_seq->seq1,last_seq->seq2);
546                         }
547                         else if(event==10) {
548                                 SWAP(Sequence *,last_seq->seq2,last_seq->seq3);
549                         }
550                         else if(event==11) {
551                                 activate_fileselect(
552                                         FILE_SPECIAL, "Select Plugin", 
553                                         U.plugseqdir, change_plugin_seq);
554                         }
555                         else if(event==12);     
556                                                                 /* recalculate: only new_stripdata */
557                         else {
558                                 /* free previous effect and init new effect */
559                                 struct SeqEffectHandle sh;
560
561                                 if (get_sequence_effect_num_inputs(
562                                                 last_seq->type)
563                                         < get_sequence_effect_num_inputs(
564                                                 event_to_efftype(event))) {
565                                         error("New effect needs more "
566                                                   "input strips!");
567                                 } else {
568                                         sh = get_sequence_effect(last_seq);
569                                         sh.free(last_seq);
570                                         
571                                         last_seq->type 
572                                                 = event_to_efftype(event);
573                                         
574                                         sh = get_sequence_effect(last_seq);
575                                         sh.init(last_seq);
576                                 }
577                         }
578
579                         update_changed_seq_and_deps(scene, last_seq, 0, 1);
580                 }
581         }
582         else if(last_seq->type == SEQ_IMAGE) {
583                 if(okee("Change images")) {
584                         activate_fileselect(FILE_SPECIAL, 
585                                                 "Select Images", 
586                                                 ed->act_imagedir, 
587                                                 reload_image_strip);
588                 }
589         }
590         else if(last_seq->type == SEQ_MOVIE) {
591                 ;
592         }
593         else if(last_seq->type == SEQ_SCENE) {
594                 event= pupmenu("Change Scene%t|Update Start and End");
595
596                 if(event==1) {
597                         sce= last_seq->scene;
598
599                         last_seq->len= sce->r.efra - sce->r.sfra + 1;
600                         last_seq->sfra= sce->r.sfra;
601                         
602                         /* bad code to change seq->len? update_changed_seq_and_deps() expects the strip->len to be OK */
603                         new_tstripdata(last_seq);
604                         
605                         update_changed_seq_and_deps(scene, last_seq, 1, 1);
606
607                 }
608         }
609
610 }
611
612 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, char **error_str)
613 {
614         Editing *ed = seq_give_editing(scene, FALSE);
615         Sequence *seq1= 0, *seq2= 0, *seq3= 0, *seq;
616         
617         *error_str= NULL;
618
619         if (!activeseq)
620                 seq2= seq_active_get(scene);
621
622         for(seq=ed->seqbasep->first; seq; seq=seq->next) {
623                 if(seq->flag & SELECT) {
624                         if (seq->type == SEQ_SOUND) {
625                                 *error_str= "Can't apply effects to audio sequence strips";
626                                 return 0;
627                         }
628                         if((seq != activeseq) && (seq != seq2)) {
629                                                                 if(seq2==0) seq2= seq;
630                                                                 else if(seq1==0) seq1= seq;
631                                                                 else if(seq3==0) seq3= seq;
632                                                                 else {
633                                                                         *error_str= "Can't apply effect to more than 3 sequence strips";
634                                                                         return 0;
635                                                                 }
636                         }
637                 }
638         }
639        
640         /* make sequence selection a little bit more intuitive
641            for 3 strips: the last-strip should be sequence3 */
642         if (seq3 != 0 && seq2 != 0) {
643                 Sequence *tmp = seq2;
644                 seq2 = seq3;
645                 seq3 = tmp;
646         }
647         
648
649         switch(get_sequence_effect_num_inputs(type)) {
650         case 0:
651                 *selseq1 = *selseq2 = *selseq3 = 0;
652                 return 1; /* succsess */
653         case 1:
654                 if(seq2==0)  {
655                         *error_str= "Need at least one selected sequence strip";
656                         return 0;
657                 }
658                 if(seq1==0) seq1= seq2;
659                 if(seq3==0) seq3= seq2;
660         case 2:
661                 if(seq1==0 || seq2==0) {
662                         *error_str= "Need 2 selected sequence strips";
663                         return 0;
664                 }
665                 if(seq3==0) seq3= seq2;
666         }
667         
668         if (seq1==NULL && seq2==NULL && seq3==NULL) {
669                 *error_str= "TODO: in what cases does this happen?";
670                 return 0;
671         }
672         
673         *selseq1= seq1;
674         *selseq2= seq2;
675         *selseq3= seq3;
676
677         return 1;
678 }
679
680 void reassign_inputs_seq_effect(Scene *scene)
681 {
682         Editing *ed= seq_give_editing(scene, FALSE);
683         Sequence *seq1, *seq2, *seq3, *last_seq = seq_active_get(scene);
684         char *error_msg;
685
686         if(last_seq==0 || !(last_seq->type & SEQ_EFFECT)) return;
687         if(ed==NULL) return;
688
689         if(!seq_effect_find_selected(scene, last_seq, last_seq->type, &seq1, &seq2, &seq3, &error_msg)) {
690                 //BKE_report(op->reports, RPT_ERROR, error_msg); // XXX operatorify
691                 return;
692         }
693         /* see reassigning would create a cycle */
694         if(     seq_is_predecessor(seq1, last_seq) ||
695                 seq_is_predecessor(seq2, last_seq) ||
696                 seq_is_predecessor(seq3, last_seq)
697         ) {
698                 //BKE_report(op->reports, RPT_ERROR, "Can't reassign inputs: no cycles allowed"); // XXX operatorify
699                    return;
700         }
701         
702         last_seq->seq1 = seq1;
703         last_seq->seq2 = seq2;
704         last_seq->seq3 = seq3;
705
706         update_changed_seq_and_deps(scene, last_seq, 1, 1);
707
708 }
709
710 static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq)
711 {
712         Sequence *seq1, *seq2, *seq3;
713
714         /* try to find a replacement input sequence, and flag for later deletion if
715            no replacement can be found */
716
717         if(!seq)
718                 return NULL;
719         else if(!(seq->type & SEQ_EFFECT))
720                 return ((seq->flag & SELECT)? NULL: seq);
721         else if(!(seq->flag & SELECT)) {
722                 /* try to find replacement for effect inputs */
723                 seq1= del_seq_find_replace_recurs(scene, seq->seq1);
724                 seq2= del_seq_find_replace_recurs(scene, seq->seq2);
725                 seq3= del_seq_find_replace_recurs(scene, seq->seq3);
726
727                 if(seq1==seq->seq1 && seq2==seq->seq2 && seq3==seq->seq3);
728                 else if(seq1 || seq2 || seq3) {
729                         seq->seq1= (seq1)? seq1: (seq2)? seq2: seq3;
730                         seq->seq2= (seq2)? seq2: (seq1)? seq1: seq3;
731                         seq->seq3= (seq3)? seq3: (seq1)? seq1: seq2;
732
733                         update_changed_seq_and_deps(scene, seq, 1, 1);
734                 }
735                 else
736                         seq->flag |= SELECT; /* mark for delete */
737         }
738
739         if (seq->flag & SELECT) {
740                 if((seq1 = del_seq_find_replace_recurs(scene, seq->seq1))) return seq1;
741                 if((seq2 = del_seq_find_replace_recurs(scene, seq->seq2))) return seq2;
742                 if((seq3 = del_seq_find_replace_recurs(scene, seq->seq3))) return seq3;
743                 else return NULL;
744         }
745         else
746                 return seq;
747 }
748
749 static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall)
750 {
751         Sequence *seq, *seqn;
752         Sequence *last_seq = seq_active_get(scene);
753
754         seq= lb->first;
755         while(seq) {
756                 seqn= seq->next;
757                 if((seq->flag & flag) || deleteall) {
758                         if(seq->type==SEQ_SOUND && seq->sound)
759                                 seq->sound->id.us--;
760
761                         BLI_remlink(lb, seq);
762                         if(seq==last_seq) seq_active_set(scene, NULL);
763                         if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1);
764                         if(seq->ipo) seq->ipo->id.us--;
765                         seq_free_sequence(scene, seq);
766                 }
767                 seq= seqn;
768         }
769 }
770
771
772 static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe)
773 {
774         TransSeq ts;
775         Sequence *seqn = 0;
776         int skip_dup = FALSE;
777
778         /* backup values */
779         ts.start= seq->start;
780         ts.machine= seq->machine;
781         ts.startstill= seq->startstill;
782         ts.endstill= seq->endstill;
783         ts.startdisp= seq->startdisp;
784         ts.enddisp= seq->enddisp;
785         ts.startofs= seq->anim_startofs;
786         ts.endofs= seq->anim_endofs;
787         ts.len= seq->len;
788         
789         /* First Strip! */
790         /* strips with extended stillfames before */
791         
792         if ((seq->startstill) && (cutframe <seq->start)) {
793                 /* don't do funny things with METAs ... */
794                 if (seq->type == SEQ_META) {
795                         skip_dup = TRUE;
796                         seq->startstill = seq->start - cutframe;
797                 } else {
798                         seq->start= cutframe -1;
799                         seq->startstill= cutframe -seq->startdisp -1;
800                         seq->anim_endofs += seq->len - 1;
801                         seq->endstill= 0;
802                 }
803         }
804         /* normal strip */
805         else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
806                 seq->endofs = 0;
807                 seq->endstill = 0;
808                 seq->anim_endofs += (seq->start+seq->len) - cutframe;
809         }
810         /* strips with extended stillframes after */
811         else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
812                 seq->endstill -= seq->enddisp - cutframe;
813                 /* don't do funny things with METAs ... */
814                 if (seq->type == SEQ_META) {
815                         skip_dup = TRUE;
816                 }
817         }
818         
819         reload_sequence_new_file(scene, seq, FALSE);
820         calc_sequence(scene, seq);
821
822         if (!skip_dup) {
823                 /* Duplicate AFTER the first change */
824                 seqn = seq_dupli_recursive(scene, seq);
825         }
826         
827         if (seqn) { 
828                 seqn->flag |= SELECT;
829                         
830                 /* Second Strip! */
831                 /* strips with extended stillframes before */
832                 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
833                         seqn->start = ts.start;
834                         seqn->startstill= ts.start- cutframe;
835                         seqn->anim_endofs = ts.endofs;
836                         seqn->endstill = ts.endstill;
837                 }
838                 
839                 /* normal strip */
840                 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
841                         seqn->start = cutframe;
842                         seqn->startstill = 0;
843                         seqn->startofs = 0;
844                         seqn->anim_startofs += cutframe - ts.start;
845                         seqn->anim_endofs = ts.endofs;
846                         seqn->endstill = ts.endstill;
847                 }                               
848                 
849                 /* strips with extended stillframes after */
850                 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
851                         seqn->start = cutframe;
852                         seqn->startofs = 0;
853                         seqn->anim_startofs += ts.len-1;
854                         seqn->endstill = ts.enddisp - cutframe -1;
855                         seqn->startstill = 0;
856                 }
857                 
858                 reload_sequence_new_file(scene, seqn, FALSE);
859                 calc_sequence(scene, seq);
860         }
861         return seqn;
862 }
863
864 static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe)
865 {
866         TransSeq ts;
867         Sequence *seqn = 0;
868         int skip_dup = FALSE;
869
870         /* backup values */
871         ts.start= seq->start;
872         ts.machine= seq->machine;
873         ts.startstill= seq->startstill;
874         ts.endstill= seq->endstill;
875         ts.startdisp= seq->startdisp;
876         ts.enddisp= seq->enddisp;
877         ts.startofs= seq->startofs;
878         ts.endofs= seq->endofs;
879         ts.len= seq->len;
880         
881         /* First Strip! */
882         /* strips with extended stillfames before */
883         
884         if ((seq->startstill) && (cutframe <seq->start)) {
885                 /* don't do funny things with METAs ... */
886                 if (seq->type == SEQ_META) {
887                         skip_dup = TRUE;
888                         seq->startstill = seq->start - cutframe;
889                 } else {
890                         seq->start= cutframe -1;
891                         seq->startstill= cutframe -seq->startdisp -1;
892                         seq->endofs = seq->len - 1;
893                         seq->endstill= 0;
894                 }
895         }
896         /* normal strip */
897         else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) {
898                 seq->endofs = (seq->start+seq->len) - cutframe;
899         }
900         /* strips with extended stillframes after */
901         else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) {
902                 seq->endstill -= seq->enddisp - cutframe;
903                 /* don't do funny things with METAs ... */
904                 if (seq->type == SEQ_META) {
905                         skip_dup = TRUE;
906                 }
907         }
908         
909         calc_sequence(scene, seq);
910
911         if (!skip_dup) {
912                 /* Duplicate AFTER the first change */
913                 seqn = seq_dupli_recursive(scene, seq);
914         }
915         
916         if (seqn) { 
917                 seqn->flag |= SELECT;
918                         
919                 /* Second Strip! */
920                 /* strips with extended stillframes before */
921                 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
922                         seqn->start = ts.start;
923                         seqn->startstill= ts.start- cutframe;
924                         seqn->endofs = ts.endofs;
925                         seqn->endstill = ts.endstill;
926                 }
927                 
928                 /* normal strip */
929                 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) {
930                         seqn->startstill = 0;
931                         seqn->startofs = cutframe - ts.start;
932                         seqn->endofs = ts.endofs;
933                         seqn->endstill = ts.endstill;
934                 }                               
935                 
936                 /* strips with extended stillframes after */
937                 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) {
938                         seqn->start = cutframe - ts.len +1;
939                         seqn->startofs = ts.len-1;
940                         seqn->endstill = ts.enddisp - cutframe -1;
941                         seqn->startstill = 0;
942                 }
943                 
944                 calc_sequence(scene, seqn);
945         }
946         return seqn;
947 }
948
949
950 /* like duplicate, but only duplicate and cut overlapping strips,
951  * strips to the left of the cutframe are ignored and strips to the right are moved into the new list */
952 static int cut_seq_list(Scene *scene, ListBase *old, ListBase *new, int cutframe,
953                         Sequence * (*cut_seq)(Scene *, Sequence *, int))
954 {
955         int did_something = FALSE;
956         Sequence *seq, *seq_next;
957         
958         seq= old->first;
959         
960         while(seq) {
961                 seq_next = seq->next; /* we need this because we may remove seq */
962                 
963                 seq->tmp= NULL;
964                 if(seq->flag & SELECT) {
965                         if(cutframe > seq->startdisp && 
966                            cutframe < seq->enddisp) {
967                                 Sequence * seqn = cut_seq(scene, seq, cutframe);
968                                 if (seqn) {
969                                         BLI_addtail(new, seqn);
970                                 }
971                                 did_something = TRUE;
972                         } else if (seq->enddisp <= cutframe) {
973                                 /* do nothing */
974                         } else if (seq->startdisp >= cutframe) {
975                                 /* move into new list */
976                                 BLI_remlink(old, seq);
977                                 BLI_addtail(new, seq);
978                         }
979                 }
980                 seq = seq_next;
981         }
982         return did_something;
983 }
984
985 int insert_gap(Scene *scene, int gap, int cfra)
986 {
987         Sequence *seq;
988         Editing *ed= seq_give_editing(scene, FALSE);
989         int done=0;
990
991         /* all strips >= cfra are shifted */
992         
993         if(ed==NULL) return 0;
994
995         SEQP_BEGIN(ed, seq) {
996                 if(seq->startdisp >= cfra) {
997                         seq->start+= gap;
998                         calc_sequence(scene, seq);
999                         done= 1;
1000                 }
1001         }
1002         SEQ_END
1003
1004         return done;
1005 }
1006
1007 void touch_seq_files(Scene *scene)
1008 {
1009         Sequence *seq;
1010         Editing *ed= seq_give_editing(scene, FALSE);
1011         char str[256];
1012
1013         /* touch all strips with movies */
1014         
1015         if(ed==NULL) return;
1016
1017         if(okee("Touch and print selected movies")==0) return;
1018
1019         waitcursor(1);
1020
1021         SEQP_BEGIN(ed, seq) {
1022                 if(seq->flag & SELECT) {
1023                         if(seq->type==SEQ_MOVIE) {
1024                                 if(seq->strip && seq->strip->stripdata) {
1025                                         BLI_make_file_string(G.sce, str, seq->strip->dir, seq->strip->stripdata->name);
1026                                         BLI_touch(seq->name);
1027                                 }
1028                         }
1029
1030                 }
1031         }
1032         SEQ_END
1033
1034         waitcursor(0);
1035 }
1036
1037 void set_filter_seq(Scene *scene)
1038 {
1039         Sequence *seq;
1040         Editing *ed= seq_give_editing(scene, FALSE);
1041
1042         
1043         if(ed==NULL) return;
1044
1045         if(okee("Set Deinterlace")==0) return;
1046
1047         SEQP_BEGIN(ed, seq) {
1048                 if(seq->flag & SELECT) {
1049                         if(seq->type==SEQ_MOVIE) {
1050                                 seq->flag |= SEQ_FILTERY;
1051                                 reload_sequence_new_file(scene, seq, FALSE);
1052                                 calc_sequence(scene, seq);
1053                         }
1054
1055                 }
1056         }
1057         SEQ_END
1058
1059 }
1060
1061 void seq_remap_paths(Scene *scene)
1062 {
1063         Sequence *seq, *last_seq = seq_active_get(scene);
1064         Editing *ed= seq_give_editing(scene, FALSE);
1065         char from[FILE_MAX], to[FILE_MAX], stripped[FILE_MAX];
1066         
1067         
1068         if(last_seq==NULL) 
1069                 return;
1070         
1071         BLI_strncpy(from, last_seq->strip->dir, FILE_MAX);
1072 // XXX  if (0==sbutton(from, 0, sizeof(from)-1, "From: "))
1073 //              return;
1074         
1075         strcpy(to, from);
1076 // XXX  if (0==sbutton(to, 0, sizeof(to)-1, "To: "))
1077 //              return;
1078         
1079         if (strcmp(to, from)==0)
1080                 return;
1081         
1082         SEQP_BEGIN(ed, seq) {
1083                 if(seq->flag & SELECT) {
1084                         if(strncmp(seq->strip->dir, from, strlen(from))==0) {
1085                                 printf("found %s\n", seq->strip->dir);
1086                                 
1087                                 /* strip off the beginning */
1088                                 stripped[0]= 0;
1089                                 BLI_strncpy(stripped, seq->strip->dir + strlen(from), FILE_MAX);
1090                                 
1091                                 /* new path */
1092                                 BLI_strncpy(seq->strip->dir, to, FILE_MAX);
1093                                 strcat(seq->strip->dir, stripped);
1094                                 printf("new %s\n", seq->strip->dir);
1095                         }
1096                 }
1097         }
1098         SEQ_END
1099                 
1100 }
1101
1102
1103 void no_gaps(Scene *scene)
1104 {
1105         Editing *ed= seq_give_editing(scene, FALSE);
1106         int cfra, first= 0, done;
1107
1108         
1109         if(ed==NULL) return;
1110
1111         for(cfra= CFRA; cfra<=EFRA; cfra++) {
1112                 if(first==0) {
1113                         if( evaluate_seq_frame(scene, cfra) ) first= 1;
1114                 }
1115                 else {
1116                         done= 1;
1117                         while( evaluate_seq_frame(scene, cfra) == 0) {
1118                                 done= insert_gap(scene, -1, cfra);
1119                                 if(done==0) break;
1120                         }
1121                         if(done==0) break;
1122                 }
1123         }
1124
1125 }
1126
1127 #if 0
1128 static int seq_get_snaplimit(View2D *v2d)
1129 {
1130         /* fake mouse coords to get the snap value
1131         a bit lazy but its only done once pre transform */
1132         float xmouse, ymouse, x;
1133         short mval[2] = {24, 0}; /* 24 screen px snap */
1134         
1135         UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1136         x = xmouse;
1137         mval[0] = 0;
1138         UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1139         return (int)(x - xmouse);
1140 }
1141 #endif
1142
1143 /* Operator functions */
1144 int sequencer_edit_poll(bContext *C)
1145 {
1146         return (seq_give_editing(CTX_data_scene(C), FALSE) != NULL);
1147 }
1148
1149
1150 /* snap operator*/
1151 static int sequencer_snap_exec(bContext *C, wmOperator *op)
1152 {
1153         Scene *scene= CTX_data_scene(C);
1154         
1155         Editing *ed= seq_give_editing(scene, FALSE);
1156         Sequence *seq;
1157         int snap_frame;
1158
1159         snap_frame= RNA_int_get(op->ptr, "frame");
1160
1161         /* problem: contents of meta's are all shifted to the same position... */
1162
1163         /* also check metas */
1164         SEQP_BEGIN(ed, seq) {
1165                 if (seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK) &&
1166                         seq_tx_test(seq)) {
1167                         if((seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))==0) {
1168                                 seq->start= snap_frame-seq->startofs+seq->startstill;
1169                         } else { 
1170                                 if(seq->flag & SEQ_LEFTSEL) {
1171                                         seq_tx_set_final_left(seq, snap_frame);
1172                                 } else { /* SEQ_RIGHTSEL */
1173                                         seq_tx_set_final_right(seq, snap_frame);
1174                                 }
1175                                 seq_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL);
1176                         }
1177                         calc_sequence(scene, seq);
1178                 }
1179         }
1180         SEQ_END
1181
1182         /* test for effects and overlap */
1183         SEQP_BEGIN(ed, seq) {
1184                 if(seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK)) {
1185                         seq->flag &= ~SEQ_OVERLAP;
1186                         if( seq_test_overlap(ed->seqbasep, seq) ) {
1187                                 shuffle_seq(ed->seqbasep, seq, scene);
1188                         }
1189                 }
1190                 else if(seq->type & SEQ_EFFECT) {
1191                         if(seq->seq1 && (seq->seq1->flag & SELECT)) 
1192                                 calc_sequence(scene, seq);
1193                         else if(seq->seq2 && (seq->seq2->flag & SELECT)) 
1194                                 calc_sequence(scene, seq);
1195                         else if(seq->seq3 && (seq->seq3->flag & SELECT)) 
1196                                 calc_sequence(scene, seq);
1197                 }
1198         }
1199         SEQ_END;
1200
1201         /* as last: */
1202         sort_seq(scene);
1203         
1204         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1205         
1206         return OPERATOR_FINISHED;
1207 }
1208
1209 static int sequencer_snap_invoke(bContext *C, wmOperator *op, wmEvent *event)
1210 {
1211         Scene *scene = CTX_data_scene(C);
1212         
1213         int snap_frame;
1214         
1215         snap_frame= CFRA;
1216         
1217         RNA_int_set(op->ptr, "frame", snap_frame);
1218         return sequencer_snap_exec(C, op);
1219 }
1220
1221 void SEQUENCER_OT_snap(struct wmOperatorType *ot)
1222 {
1223         /* identifiers */
1224         ot->name= "Snap strips";
1225         ot->idname= "SEQUENCER_OT_snap";
1226         ot->description="Frame where selected strips will be snapped";
1227         
1228         /* api callbacks */
1229         ot->invoke= sequencer_snap_invoke;
1230         ot->exec= sequencer_snap_exec;
1231         ot->poll= sequencer_edit_poll;
1232         
1233         /* flags */
1234         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1235         
1236         RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be snapped", INT_MIN, INT_MAX);
1237 }
1238
1239 /* mute operator */
1240 static int sequencer_mute_exec(bContext *C, wmOperator *op)
1241 {
1242         Scene *scene= CTX_data_scene(C);
1243         Editing *ed= seq_give_editing(scene, FALSE);
1244         Sequence *seq;
1245         int selected;
1246
1247         selected= !RNA_boolean_get(op->ptr, "unselected");
1248         
1249         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1250                 if ((seq->flag & SEQ_LOCK)==0) {
1251                         if(selected){ /* mute unselected */
1252                                 if(seq->flag & SELECT)
1253                                         seq->flag |= SEQ_MUTE;
1254                         }
1255                         else {
1256                                 if((seq->flag & SELECT)==0)
1257                                         seq->flag |= SEQ_MUTE;
1258                         }
1259                 }
1260         }
1261         
1262         seq_update_muting(scene, ed);
1263         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1264         
1265         return OPERATOR_FINISHED;
1266 }
1267
1268 void SEQUENCER_OT_mute(struct wmOperatorType *ot)
1269 {
1270         /* identifiers */
1271         ot->name= "Mute Strips";
1272         ot->idname= "SEQUENCER_OT_mute";
1273         ot->description="Mute selected strips";
1274         
1275         /* api callbacks */
1276         ot->exec= sequencer_mute_exec;
1277         ot->poll= sequencer_edit_poll;
1278         
1279         /* flags */
1280         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1281         
1282         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Mute unselected rather than selected strips.");
1283 }
1284
1285
1286 /* unmute operator */
1287 static int sequencer_unmute_exec(bContext *C, wmOperator *op)
1288 {
1289         Scene *scene= CTX_data_scene(C);
1290         Editing *ed= seq_give_editing(scene, FALSE);
1291         Sequence *seq;
1292         int selected;
1293
1294         selected= !RNA_boolean_get(op->ptr, "unselected");
1295         
1296         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1297                 if ((seq->flag & SEQ_LOCK)==0) {
1298                         if(selected){ /* unmute unselected */
1299                                 if(seq->flag & SELECT)
1300                                         seq->flag &= ~SEQ_MUTE;
1301                         }
1302                         else {
1303                                 if((seq->flag & SELECT)==0)
1304                                         seq->flag &= ~SEQ_MUTE;
1305                         }
1306                 }
1307         }
1308         
1309         seq_update_muting(scene, ed);
1310         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1311         
1312         return OPERATOR_FINISHED;
1313 }
1314
1315 void SEQUENCER_OT_unmute(struct wmOperatorType *ot)
1316 {
1317         /* identifiers */
1318         ot->name= "Un-Mute Strips";
1319         ot->idname= "SEQUENCER_OT_unmute";
1320         ot->description="Un-Mute unselected rather than selected strips";
1321         
1322         /* api callbacks */
1323         ot->exec= sequencer_unmute_exec;
1324         ot->poll= sequencer_edit_poll;
1325         
1326         /* flags */
1327         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1328         
1329         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "UnMute unselected rather than selected strips.");
1330 }
1331
1332
1333 /* lock operator */
1334 static int sequencer_lock_exec(bContext *C, wmOperator *op)
1335 {
1336         Scene *scene= CTX_data_scene(C);
1337         Editing *ed= seq_give_editing(scene, FALSE);
1338         Sequence *seq;
1339
1340         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1341                 if (seq->flag & SELECT) {
1342                         seq->flag |= SEQ_LOCK;
1343                 }
1344         }
1345
1346         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1347
1348         return OPERATOR_FINISHED;
1349 }
1350
1351 void SEQUENCER_OT_lock(struct wmOperatorType *ot)
1352 {
1353         /* identifiers */
1354         ot->name= "Lock Strips";
1355         ot->idname= "SEQUENCER_OT_lock";
1356         ot->description="Lock the active strip so that it can't be transformed";
1357         
1358         /* api callbacks */
1359         ot->exec= sequencer_lock_exec;
1360         ot->poll= sequencer_edit_poll;
1361         
1362         /* flags */
1363         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1364 }
1365
1366 /* unlock operator */
1367 static int sequencer_unlock_exec(bContext *C, wmOperator *op)
1368 {
1369         Scene *scene= CTX_data_scene(C);
1370         Editing *ed= seq_give_editing(scene, FALSE);
1371         Sequence *seq;
1372
1373         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1374                 if (seq->flag & SELECT) {
1375                         seq->flag &= ~SEQ_LOCK;
1376                 }
1377         }
1378
1379         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1380
1381         return OPERATOR_FINISHED;
1382 }
1383
1384 void SEQUENCER_OT_unlock(struct wmOperatorType *ot)
1385 {
1386         /* identifiers */
1387         ot->name= "UnLock Strips";
1388         ot->idname= "SEQUENCER_OT_unlock";
1389         ot->description="Unlock the active strip so that it can't be transformed";
1390         
1391         /* api callbacks */
1392         ot->exec= sequencer_unlock_exec;
1393         ot->poll= sequencer_edit_poll;
1394         
1395         /* flags */
1396         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1397 }
1398
1399 /* reload operator */
1400 static int sequencer_reload_exec(bContext *C, wmOperator *op)
1401 {
1402         Scene *scene= CTX_data_scene(C);
1403         Editing *ed= seq_give_editing(scene, FALSE);
1404         Sequence *seq;
1405
1406         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
1407                 if(seq->flag & SELECT) {
1408                         update_changed_seq_and_deps(scene, seq, 0, 1);
1409                 }
1410         }
1411
1412         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1413
1414         return OPERATOR_FINISHED;
1415 }
1416
1417 void SEQUENCER_OT_reload(struct wmOperatorType *ot)
1418 {
1419         /* identifiers */
1420         ot->name= "Reload Strips";
1421         ot->idname= "SEQUENCER_OT_reload";
1422         ot->description="Reload strips in the sequencer";
1423         
1424         /* api callbacks */
1425         ot->exec= sequencer_reload_exec;
1426         ot->poll= sequencer_edit_poll;
1427         
1428         /* flags */
1429         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1430 }
1431
1432 /* reload operator */
1433 static int sequencer_refresh_all_exec(bContext *C, wmOperator *op)
1434 {
1435         Scene *scene= CTX_data_scene(C);
1436         Editing *ed= seq_give_editing(scene, FALSE);
1437
1438         free_imbuf_seq(scene, &ed->seqbase, FALSE);
1439
1440         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1441
1442         return OPERATOR_FINISHED;
1443 }
1444
1445 void SEQUENCER_OT_refresh_all(struct wmOperatorType *ot)
1446 {
1447         /* identifiers */
1448         ot->name= "Refresh Sequencer";
1449         ot->idname= "SEQUENCER_OT_refresh_all";
1450         ot->description="Refresh the sequencer editor";
1451         
1452         /* api callbacks */
1453         ot->exec= sequencer_refresh_all_exec;
1454         ot->poll= sequencer_edit_poll;
1455         
1456         /* flags */
1457         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1458 }
1459
1460 /* cut operator */
1461 static EnumPropertyItem prop_cut_types[] = {
1462         {SEQ_CUT_SOFT, "SOFT", 0, "Soft", ""},
1463         {SEQ_CUT_HARD, "HARD", 0, "Hard", ""},
1464         {0, NULL, 0, NULL, NULL}
1465 };
1466
1467 static int sequencer_cut_exec(bContext *C, wmOperator *op)
1468 {
1469         Scene *scene= CTX_data_scene(C);
1470         Editing *ed= seq_give_editing(scene, FALSE);
1471         int cut_side, cut_hard, cut_frame;
1472
1473         ListBase newlist;
1474         int changed;
1475
1476         cut_frame= RNA_int_get(op->ptr, "frame");
1477         cut_hard= RNA_enum_get(op->ptr, "type");
1478         cut_side= RNA_enum_get(op->ptr, "side");
1479         
1480         newlist.first= newlist.last= NULL;
1481
1482         if (cut_hard==SEQ_CUT_HARD) {
1483                 changed = cut_seq_list(scene,
1484                         ed->seqbasep, &newlist, cut_frame, cut_seq_hard);
1485         } else {
1486                 changed = cut_seq_list(scene,
1487                         ed->seqbasep, &newlist, cut_frame, cut_seq_soft);
1488         }
1489         
1490         if (newlist.first) { /* got new strips ? */
1491                 Sequence *seq;
1492                 addlisttolist(ed->seqbasep, &newlist);
1493
1494                 if (cut_side != SEQ_SIDE_BOTH) {
1495                         SEQP_BEGIN(ed, seq) {
1496                                 if (cut_side==SEQ_SIDE_LEFT) {
1497                                         if ( seq->startdisp >= cut_frame ) {
1498                                                 seq->flag &= ~SEQ_ALLSEL;
1499                                         }
1500                                 } else {
1501                                         if ( seq->enddisp <= cut_frame ) {
1502                                                 seq->flag &= ~SEQ_ALLSEL;
1503                                         }
1504                                 }
1505                         }
1506                         SEQ_END;
1507                 }
1508                 /* as last: */
1509                 sort_seq(scene);
1510         }
1511
1512         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1513         
1514         return OPERATOR_FINISHED;
1515 }
1516
1517
1518 static int sequencer_cut_invoke(bContext *C, wmOperator *op, wmEvent *event)
1519 {
1520         Scene *scene = CTX_data_scene(C);
1521         ARegion *ar= CTX_wm_region(C);
1522         View2D *v2d= UI_view2d_fromcontext(C);
1523
1524         int cut_side= SEQ_SIDE_BOTH;
1525         int cut_frame= CFRA;
1526
1527         if (ED_operator_sequencer_active(C) && v2d)
1528                 cut_side= mouse_frame_side(v2d, event->x - ar->winrct.xmin, cut_frame);
1529         
1530         RNA_int_set(op->ptr, "frame", cut_frame);
1531         RNA_enum_set(op->ptr, "side", cut_side);
1532         /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */
1533
1534         return sequencer_cut_exec(C, op);
1535 }
1536
1537
1538 void SEQUENCER_OT_cut(struct wmOperatorType *ot)
1539 {
1540         /* identifiers */
1541         ot->name= "Cut Strips";
1542         ot->idname= "SEQUENCER_OT_cut";
1543         ot->description="Cut the selected strips";
1544         
1545         /* api callbacks */
1546         ot->invoke= sequencer_cut_invoke;
1547         ot->exec= sequencer_cut_exec;
1548         ot->poll= sequencer_edit_poll;
1549         
1550         /* flags */
1551         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1552         
1553         RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be cut", INT_MIN, INT_MAX);
1554         RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips");
1555         RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting");
1556 }
1557
1558 /* duplicate operator */
1559 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *op)
1560 {
1561         Scene *scene= CTX_data_scene(C);
1562         Editing *ed= seq_give_editing(scene, FALSE);
1563
1564         ListBase nseqbase= {NULL, NULL};
1565
1566         if(ed==NULL)
1567                 return OPERATOR_CANCELLED;
1568
1569         seqbase_dupli_recursive(scene, &nseqbase, ed->seqbasep, TRUE);
1570
1571         if(nseqbase.first) {
1572                 Sequence * seq= nseqbase.first;
1573                 /* rely on the nseqbase list being added at the end */
1574                 addlisttolist(ed->seqbasep, &nseqbase);
1575
1576                 for( ; seq; seq= seq->next)
1577                         seqbase_unique_name_recursive(&ed->seqbase, seq);
1578
1579                 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1580                 return OPERATOR_FINISHED;
1581         }
1582
1583         return OPERATOR_CANCELLED;
1584 }
1585
1586 static int sequencer_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
1587 {
1588         sequencer_add_duplicate_exec(C, op);
1589
1590         RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
1591         WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
1592
1593         return OPERATOR_FINISHED;
1594 }
1595
1596 void SEQUENCER_OT_duplicate(wmOperatorType *ot)
1597 {
1598         /* identifiers */
1599         ot->name= "Duplicate";
1600         ot->idname= "SEQUENCER_OT_duplicate";
1601         ot->description="Duplicate the selected strips";
1602         
1603         /* api callbacks */
1604         ot->invoke= sequencer_add_duplicate_invoke;
1605         ot->exec= sequencer_add_duplicate_exec;
1606         ot->poll= ED_operator_sequencer_active;
1607         
1608         /* flags */
1609         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1610         
1611         /* to give to transform */
1612         RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
1613 }
1614
1615 /* delete operator */
1616 static int sequencer_delete_exec(bContext *C, wmOperator *op)
1617 {
1618         Scene *scene= CTX_data_scene(C);
1619         Editing *ed= seq_give_editing(scene, FALSE);
1620         Sequence *seq;
1621         MetaStack *ms;
1622         int nothingSelected = TRUE;
1623
1624         seq=seq_active_get(scene);
1625         if (seq && seq->flag & SELECT) { /* avoid a loop since this is likely to be selected */
1626                 nothingSelected = FALSE;
1627         } else {
1628                 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1629                         if (seq->flag & SELECT) {
1630                                 nothingSelected = FALSE;
1631                                 break;
1632                         }
1633                 }
1634         }
1635
1636         if (nothingSelected)
1637                 return OPERATOR_FINISHED;
1638
1639         /* free imbufs of all dependent strips */
1640         for(seq=ed->seqbasep->first; seq; seq=seq->next)
1641                 if(seq->flag & SELECT)
1642                         update_changed_seq_and_deps(scene, seq, 1, 0);
1643
1644         /* for effects, try to find a replacement input */
1645         for(seq=ed->seqbasep->first; seq; seq=seq->next)
1646                 if((seq->type & SEQ_EFFECT) && !(seq->flag & SELECT))
1647                         del_seq_find_replace_recurs(scene, seq);
1648
1649         /* delete all selected strips */
1650         recurs_del_seq_flag(scene, ed->seqbasep, SELECT, 0);
1651
1652         /* updates lengths etc */
1653         seq= ed->seqbasep->first;
1654         while(seq) {
1655                 calc_sequence(scene, seq);
1656                 seq= seq->next;
1657         }
1658
1659         /* free parent metas */
1660         ms= ed->metastack.last;
1661         while(ms) {
1662                 ms->parseq->strip->len= 0;              /* force new alloc */
1663                 calc_sequence(scene, ms->parseq);
1664                 ms= ms->prev;
1665         }
1666
1667         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1668         
1669         return OPERATOR_FINISHED;
1670 }
1671
1672
1673 void SEQUENCER_OT_delete(wmOperatorType *ot)
1674 {
1675
1676         /* identifiers */
1677         ot->name= "Erase Strips";
1678         ot->idname= "SEQUENCER_OT_delete";
1679         ot->description="Erase selected strips from the sequencer";
1680         
1681         /* api callbacks */
1682         ot->invoke= WM_operator_confirm;
1683         ot->exec= sequencer_delete_exec;
1684         ot->poll= sequencer_edit_poll;
1685         
1686         /* flags */
1687         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1688 }
1689
1690
1691 /* separate_images operator */
1692 static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
1693 {
1694         Scene *scene= CTX_data_scene(C);
1695         Editing *ed= seq_give_editing(scene, FALSE);
1696         
1697         Sequence *seq, *seq_new, *seq_next;
1698         Strip *strip_new;
1699         StripElem *se, *se_new;
1700         int start_ofs, cfra, frame_end;
1701         int step= RNA_int_get(op->ptr, "length");
1702
1703         if(ed==NULL)
1704                 return OPERATOR_CANCELLED;
1705
1706         seq= ed->seqbasep->first;
1707
1708         while (seq) {
1709                 if((seq->flag & SELECT) && (seq->type == SEQ_IMAGE) && (seq->len > 1)) {
1710                         /* remove seq so overlap tests dont conflict,
1711                         see seq_free_sequence below for the real free'ing */
1712                         seq_next = seq->next;
1713                         BLI_remlink(ed->seqbasep, seq);
1714                         if(seq->ipo) seq->ipo->id.us--;
1715
1716                         start_ofs = cfra = seq_tx_get_final_left(seq, 0);
1717                         frame_end = seq_tx_get_final_right(seq, 0);
1718
1719                         while (cfra < frame_end) {
1720                                 /* new seq */
1721                                 se = give_stripelem(seq, cfra);
1722
1723                                 seq_new= alloc_sequence(ed->seqbasep, start_ofs, seq->machine);
1724                                 seq_new->type= SEQ_IMAGE;
1725                                 seq_new->len = 1;
1726                                 seq_new->endstill = step-1;
1727
1728                                 /* new strip */
1729                                 seq_new->strip= strip_new= MEM_callocN(sizeof(Strip)*1, "strip");
1730                                 strip_new->len= 1;
1731                                 strip_new->us= 1;
1732                                 strncpy(strip_new->dir, seq->strip->dir, FILE_MAXDIR-1);
1733
1734                                 /* new stripdata */
1735                                 strip_new->stripdata= se_new= MEM_callocN(sizeof(StripElem)*1, "stripelem");
1736                                 strncpy(se_new->name, se->name, FILE_MAXFILE-1);
1737                                 calc_sequence(scene, seq_new);
1738                                 seq_new->flag &= ~SEQ_OVERLAP;
1739                                 if (seq_test_overlap(ed->seqbasep, seq_new)) {
1740                                         shuffle_seq(ed->seqbasep, seq_new, scene);
1741                                 }
1742
1743                                 seqbase_unique_name_recursive(&scene->ed->seqbase, seq_new);
1744
1745                                 cfra++;
1746                                 start_ofs += step;
1747                         }
1748
1749                         seq_free_sequence(scene, seq);
1750                         seq = seq->next;
1751                 } else {
1752                         seq = seq->next;
1753                 }
1754         }
1755
1756         /* as last: */
1757         sort_seq(scene);
1758         
1759         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1760
1761         return OPERATOR_FINISHED;
1762 }
1763
1764
1765 void SEQUENCER_OT_images_separate(wmOperatorType *ot)
1766 {
1767         /* identifiers */
1768         ot->name= "Separate Images";
1769         ot->idname= "SEQUENCER_OT_images_separate";
1770         ot->description="On image sequences strips, it return a strip for each image";
1771         
1772         /* api callbacks */
1773         ot->invoke= WM_operator_props_popup;
1774         ot->exec= sequencer_separate_images_exec;
1775         ot->poll= sequencer_edit_poll;
1776         
1777         /* flags */
1778         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1779
1780         RNA_def_int(ot->srna, "length", 1, 1, 1000, "Length", "Length of each frame", 1, INT_MAX);
1781 }
1782
1783
1784 /* META Operators */
1785
1786 /* separate_meta_toggle operator */
1787 static int sequencer_meta_toggle_exec(bContext *C, wmOperator *op)
1788 {
1789         Scene *scene= CTX_data_scene(C);
1790         Editing *ed= seq_give_editing(scene, FALSE);
1791         Sequence *last_seq= seq_active_get(scene);
1792         MetaStack *ms;
1793
1794         if(last_seq && last_seq->type==SEQ_META && last_seq->flag & SELECT) {
1795                 /* Enter Metastrip */
1796                 ms= MEM_mallocN(sizeof(MetaStack), "metastack");
1797                 BLI_addtail(&ed->metastack, ms);
1798                 ms->parseq= last_seq;
1799                 ms->oldbasep= ed->seqbasep;
1800
1801                 ed->seqbasep= &last_seq->seqbase;
1802
1803                 seq_active_set(scene, NULL);
1804
1805         }
1806         else {
1807                 /* Exit Metastrip (if possible) */
1808
1809                 Sequence *seq;
1810
1811                 if(ed->metastack.first==NULL)
1812                         return OPERATOR_CANCELLED;
1813
1814                 ms= ed->metastack.last;
1815                 BLI_remlink(&ed->metastack, ms);
1816
1817                 ed->seqbasep= ms->oldbasep;
1818
1819                 /* recalc all: the meta can have effects connected to it */
1820                 for(seq= ed->seqbasep->first; seq; seq= seq->next)
1821                         calc_sequence(scene, seq);
1822
1823                 seq_active_set(scene, ms->parseq);
1824
1825                 ms->parseq->flag |= SELECT;
1826                 recurs_sel_seq(ms->parseq);
1827
1828                 MEM_freeN(ms);
1829
1830         }
1831
1832         seq_update_muting(scene, ed);
1833         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1834
1835         return OPERATOR_FINISHED;
1836 }
1837
1838 void SEQUENCER_OT_meta_toggle(wmOperatorType *ot)
1839 {
1840         /* identifiers */
1841         ot->name= "Toggle Meta Strip";
1842         ot->idname= "SEQUENCER_OT_meta_toggle";
1843         ot->description="Toggle a metastrip (to edit enclosed strips)";
1844         
1845         /* api callbacks */
1846         ot->exec= sequencer_meta_toggle_exec;
1847         ot->poll= sequencer_edit_poll;
1848         
1849         /* flags */
1850         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1851 }
1852
1853
1854 /* separate_meta_make operator */
1855 static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
1856 {
1857         Scene *scene= CTX_data_scene(C);
1858         Editing *ed= seq_give_editing(scene, FALSE);
1859         
1860         Sequence *seq, *seqm, *next;
1861         
1862         int channel_max= 1;
1863
1864         if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
1865                 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
1866                 return OPERATOR_CANCELLED;
1867         }
1868
1869         /* remove all selected from main list, and put in meta */
1870
1871         seqm= alloc_sequence(ed->seqbasep, 1, 1); /* channel number set later */
1872         strcpy(seqm->name+2, "MetaStrip");
1873         seqm->type= SEQ_META;
1874         seqm->flag= SELECT;
1875
1876         seq= ed->seqbasep->first;
1877         while(seq) {
1878                 next= seq->next;
1879                 if(seq!=seqm && (seq->flag & SELECT)) {
1880                         channel_max= MAX2(seq->machine, channel_max);
1881                         BLI_remlink(ed->seqbasep, seq);
1882                         BLI_addtail(&seqm->seqbase, seq);
1883                 }
1884                 seq= next;
1885         }
1886         seqm->machine= channel_max;
1887         calc_sequence(scene, seqm);
1888
1889         seqm->strip= MEM_callocN(sizeof(Strip), "metastrip");
1890         seqm->strip->len= seqm->len;
1891         seqm->strip->us= 1;
1892         
1893         seq_active_set(scene, seqm);
1894
1895         if( seq_test_overlap(ed->seqbasep, seqm) ) shuffle_seq(ed->seqbasep, seqm, scene);
1896
1897         seq_update_muting(scene, ed);
1898
1899         seqbase_unique_name_recursive(&scene->ed->seqbase, seqm);
1900
1901         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1902
1903         return OPERATOR_FINISHED;
1904 }
1905
1906 void SEQUENCER_OT_meta_make(wmOperatorType *ot)
1907 {
1908         /* identifiers */
1909         ot->name= "Make Meta Strip";
1910         ot->idname= "SEQUENCER_OT_meta_make";
1911         ot->description="Group selected strips into a metastrip";
1912         
1913         /* api callbacks */
1914         ot->invoke= WM_operator_confirm;
1915         ot->exec= sequencer_meta_make_exec;
1916         ot->poll= sequencer_edit_poll;
1917         
1918         /* flags */
1919         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1920 }
1921
1922
1923 static int seq_depends_on_meta(Sequence *seq, Sequence *seqm)
1924 {
1925         if (seq == seqm) return 1;
1926         else if (seq->seq1 && seq_depends_on_meta(seq->seq1, seqm)) return 1;
1927         else if (seq->seq2 && seq_depends_on_meta(seq->seq2, seqm)) return 1;
1928         else if (seq->seq3 && seq_depends_on_meta(seq->seq3, seqm)) return 1;
1929         else return 0;
1930 }
1931
1932 /* separate_meta_make operator */
1933 static int sequencer_meta_separate_exec(bContext *C, wmOperator *op)
1934 {
1935         Scene *scene= CTX_data_scene(C);
1936         Editing *ed= seq_give_editing(scene, FALSE);
1937
1938         Sequence *seq, *last_seq = seq_active_get(scene); /* last_seq checks ed==NULL */
1939
1940         if(last_seq==NULL || last_seq->type!=SEQ_META)
1941                 return OPERATOR_CANCELLED;
1942
1943         addlisttolist(ed->seqbasep, &last_seq->seqbase);
1944
1945         last_seq->seqbase.first= 0;
1946         last_seq->seqbase.last= 0;
1947
1948         BLI_remlink(ed->seqbasep, last_seq);
1949         seq_free_sequence(scene, last_seq);
1950
1951         /* emtpy meta strip, delete all effects depending on it */
1952         for(seq=ed->seqbasep->first; seq; seq=seq->next)
1953                 if((seq->type & SEQ_EFFECT) && seq_depends_on_meta(seq, last_seq))
1954                         seq->flag |= SEQ_FLAG_DELETE;
1955
1956         recurs_del_seq_flag(scene, ed->seqbasep, SEQ_FLAG_DELETE, 0);
1957
1958         /* test for effects and overlap */
1959         SEQP_BEGIN(ed, seq) {
1960                 if(seq->flag & SELECT) {
1961                         seq->flag &= ~SEQ_OVERLAP;
1962                         if( seq_test_overlap(ed->seqbasep, seq) ) {
1963                                 shuffle_seq(ed->seqbasep, seq, scene);
1964                         }
1965                 }
1966         }
1967         SEQ_END;
1968
1969         sort_seq(scene);
1970         seq_update_muting(scene, ed);
1971
1972         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
1973
1974         return OPERATOR_FINISHED;
1975 }
1976
1977 void SEQUENCER_OT_meta_separate(wmOperatorType *ot)
1978 {
1979         /* identifiers */
1980         ot->name= "UnMeta Strip";
1981         ot->idname= "SEQUENCER_OT_meta_separate";
1982         ot->description="Put the contents of a metastrip back in the sequencer";
1983         
1984         /* api callbacks */
1985         ot->invoke= WM_operator_confirm;
1986         ot->exec= sequencer_meta_separate_exec;
1987         ot->poll= sequencer_edit_poll;
1988         
1989         /* flags */
1990         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1991 }
1992
1993 /* view_all operator */
1994 static int sequencer_view_all_exec(bContext *C, wmOperator *op)
1995 {
1996         //Scene *scene= CTX_data_scene(C);
1997         bScreen *sc= CTX_wm_screen(C);
1998         ScrArea *area= CTX_wm_area(C);
1999         //ARegion *ar= CTX_wm_region(C);
2000         View2D *v2d= UI_view2d_fromcontext(C);
2001
2002         v2d->cur= v2d->tot;
2003         UI_view2d_curRect_validate(v2d);
2004         UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2005         
2006         ED_area_tag_redraw(CTX_wm_area(C));
2007         return OPERATOR_FINISHED;
2008 }
2009
2010 void SEQUENCER_OT_view_all(wmOperatorType *ot)
2011 {
2012         /* identifiers */
2013         ot->name= "View All";
2014         ot->idname= "SEQUENCER_OT_view_all";
2015         ot->description="View all the strips in the sequencer";
2016         
2017         /* api callbacks */
2018         ot->exec= sequencer_view_all_exec;
2019         ot->poll= ED_operator_sequencer_active;
2020         
2021         /* flags */
2022         ot->flag= OPTYPE_REGISTER;
2023 }
2024
2025 /* view_all operator */
2026 static int sequencer_view_all_preview_exec(bContext *C, wmOperator *op)
2027 {
2028         bScreen *sc= CTX_wm_screen(C);
2029         ScrArea *area= CTX_wm_area(C);
2030 #if 0
2031         ARegion *ar= CTX_wm_region(C);
2032         SpaceSeq *sseq= area->spacedata.first;
2033         Scene *scene= CTX_data_scene(C);
2034 #endif
2035         View2D *v2d= UI_view2d_fromcontext(C);
2036
2037         v2d->cur= v2d->tot;
2038         UI_view2d_curRect_validate(v2d);
2039         UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2040         
2041 #if 0
2042         /* Like zooming on an image view */
2043         float zoomX, zoomY;
2044         int width, height, imgwidth, imgheight;
2045
2046         width = ar->winx;
2047         height = ar->winy;
2048
2049         seq_reset_imageofs(sseq);
2050
2051         imgwidth= (scene->r.size*scene->r.xsch)/100;
2052         imgheight= (scene->r.size*scene->r.ysch)/100;
2053
2054         /* Apply aspect, dosnt need to be that accurate */
2055         imgwidth= (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
2056
2057         if (((imgwidth >= width) || (imgheight >= height)) &&
2058                 ((width > 0) && (height > 0))) {
2059
2060                 /* Find the zoom value that will fit the image in the image space */
2061                 zoomX = ((float)width) / ((float)imgwidth);
2062                 zoomY = ((float)height) / ((float)imgheight);
2063                 sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY;
2064
2065                 sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) );
2066         }
2067         else {
2068                 sseq->zoom= 1.0f;
2069         }
2070 #endif
2071
2072         ED_area_tag_redraw(CTX_wm_area(C));
2073         return OPERATOR_FINISHED;
2074 }
2075
2076 void SEQUENCER_OT_view_all_preview(wmOperatorType *ot)
2077 {
2078         /* identifiers */
2079         ot->name= "View All";
2080         ot->idname= "SEQUENCER_OT_view_all_preview";
2081         ot->description="Zoom preview to fit in the area";
2082         
2083         /* api callbacks */
2084         ot->exec= sequencer_view_all_preview_exec;
2085         ot->poll= ED_operator_sequencer_active;
2086         
2087         /* flags */
2088         ot->flag= OPTYPE_REGISTER;
2089 }
2090
2091
2092 static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op)
2093 {
2094         RenderData *r= &CTX_data_scene(C)->r;
2095         View2D *v2d= UI_view2d_fromcontext(C);
2096
2097         float ratio= RNA_float_get(op->ptr, "ratio");
2098
2099         float winx= (int)(r->size * r->xsch)/100;
2100         float winy= (int)(r->size * r->ysch)/100;
2101
2102         float facx= (v2d->mask.xmax - v2d->mask.xmin) / winx;
2103         float facy= (v2d->mask.ymax - v2d->mask.ymin) / winy;
2104
2105         BLI_resize_rctf(&v2d->cur, winx*facx*ratio, winy*facy*ratio);
2106
2107         ED_region_tag_redraw(CTX_wm_region(C));
2108
2109         return OPERATOR_FINISHED;
2110 }
2111
2112 void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot)
2113 {
2114         /* identifiers */
2115         ot->name= "Sequencer View Zoom Ratio";
2116         ot->idname= "SEQUENCER_OT_view_zoom_ratio";
2117
2118         /* api callbacks */
2119         ot->exec= sequencer_view_zoom_ratio_exec;
2120         ot->poll= ED_operator_sequencer_active;
2121
2122         /* properties */
2123         RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, FLT_MAX,
2124                 "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out.", -FLT_MAX, FLT_MAX);
2125 }
2126
2127
2128 #if 0
2129 static EnumPropertyItem view_type_items[] = {
2130                 {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""},
2131                 {SEQ_VIEW_PREVIEW,  "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""},
2132                 {SEQ_VIEW_SEQUENCE_PREVIEW,  "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""},
2133                 {0, NULL, 0, NULL, NULL}};
2134 #endif
2135
2136 /* view_all operator */
2137 static int sequencer_view_toggle_exec(bContext *C, wmOperator *op)
2138 {
2139         SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C);
2140
2141         sseq->view++;
2142         if (sseq->view > SEQ_VIEW_SEQUENCE_PREVIEW) sseq->view = SEQ_VIEW_SEQUENCE;
2143
2144         ED_sequencer_update_view(C, sseq->view);
2145
2146         return OPERATOR_FINISHED;
2147 }
2148
2149 void SEQUENCER_OT_view_toggle(wmOperatorType *ot)
2150 {
2151         /* identifiers */
2152         ot->name= "View Toggle";
2153         ot->idname= "SEQUENCER_OT_view_toggle";
2154         ot->description="Toggle between sequencer views (sequence, preview, both)";
2155         
2156         /* api callbacks */
2157         ot->exec= sequencer_view_toggle_exec;
2158         ot->poll= ED_operator_sequencer_active;
2159         
2160         /* flags */
2161         ot->flag= OPTYPE_REGISTER;
2162 }
2163
2164
2165 /* view_selected operator */
2166 static int sequencer_view_selected_exec(bContext *C, wmOperator *op)
2167 {
2168         Scene *scene= CTX_data_scene(C);
2169         View2D *v2d= UI_view2d_fromcontext(C);
2170         ScrArea *area= CTX_wm_area(C);
2171         bScreen *sc= CTX_wm_screen(C);
2172         Editing *ed= seq_give_editing(scene, FALSE);
2173         Sequence *seq;
2174
2175         int xmin=  MAXFRAME*2;
2176         int xmax= -MAXFRAME*2;
2177         int ymin=  MAXSEQ+1;
2178         int ymax= 0;
2179         int orig_height;
2180         int ymid;
2181         int ymargin= 1;
2182         int xmargin= FPS;
2183
2184         if(ed==NULL)
2185                 return OPERATOR_CANCELLED;
2186
2187         for(seq=ed->seqbasep->first; seq; seq=seq->next) {
2188                 if(seq->flag & SELECT) {
2189                         xmin= MIN2(xmin, seq->startdisp);
2190                         xmax= MAX2(xmax, seq->enddisp);
2191
2192                         ymin= MIN2(ymin, seq->machine);
2193                         ymax= MAX2(ymax, seq->machine);
2194                 }
2195         }
2196
2197         if (ymax != 0) {
2198                 
2199                 xmax += xmargin;
2200                 xmin -= xmargin;
2201                 ymax += ymargin;
2202                 ymin -= ymargin;
2203
2204                 orig_height= v2d->cur.ymax - v2d->cur.ymin;
2205
2206                 v2d->cur.xmin= xmin;
2207                 v2d->cur.xmax= xmax;
2208
2209                 v2d->cur.ymin= ymin;
2210                 v2d->cur.ymax= ymax;
2211
2212                 /* only zoom out vertically */
2213                 if (orig_height > v2d->cur.ymax - v2d->cur.ymin) {
2214                         ymid= (v2d->cur.ymax + v2d->cur.ymin) / 2;
2215
2216                         v2d->cur.ymin= ymid - (orig_height/2);
2217                         v2d->cur.ymax= ymid + (orig_height/2);
2218                 }
2219
2220                 UI_view2d_curRect_validate(v2d);
2221                 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2222
2223                 ED_area_tag_redraw(CTX_wm_area(C));
2224         }
2225         
2226         return OPERATOR_FINISHED;
2227 }
2228
2229 void SEQUENCER_OT_view_selected(wmOperatorType *ot)
2230 {
2231         /* identifiers */
2232         ot->name= "View Selected";
2233         ot->idname= "SEQUENCER_OT_view_selected";
2234         ot->description="Zoom the sequencer on the selected strips";
2235         
2236         /* api callbacks */
2237         ot->exec= sequencer_view_selected_exec;
2238         ot->poll= ED_operator_sequencer_active;
2239         
2240         /* flags */
2241         ot->flag= OPTYPE_REGISTER;
2242 }
2243
2244
2245 static int find_next_prev_edit(Scene *scene, int cfra, int side)
2246 {
2247         Editing *ed= seq_give_editing(scene, FALSE);
2248         Sequence *seq,*best_seq = NULL,*frame_seq = NULL;
2249         
2250         int dist, best_dist;
2251         best_dist = MAXFRAME*2;
2252
2253         if(ed==NULL) return cfra;
2254         
2255         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2256                 dist = MAXFRAME*2;
2257                         
2258                 switch (side) {
2259                         case SEQ_SIDE_LEFT:
2260                                 if (seq->startdisp < cfra) {
2261                                         dist = cfra - seq->startdisp;
2262                                 }
2263                                 break;
2264                         case SEQ_SIDE_RIGHT:
2265                                 if (seq->startdisp > cfra) {
2266                                         dist = seq->startdisp - cfra;
2267                                 } else if (seq->startdisp == cfra) {
2268                                         frame_seq=seq;
2269                                 }
2270                                 break;
2271                 }
2272
2273                 if (dist < best_dist) {
2274                         best_dist = dist;
2275                         best_seq = seq;
2276                 }
2277         }
2278
2279         /* if no sequence to the right is found and the
2280            frame is on the start of the last sequence,
2281            move to the end of the last sequence */
2282         if (frame_seq) cfra = frame_seq->enddisp;
2283
2284         return best_seq ? best_seq->startdisp : cfra;
2285 }
2286
2287 static int next_prev_edit_internal(Scene *scene, int side)
2288 {
2289         int change=0;
2290         int cfra = CFRA;
2291         int nfra= find_next_prev_edit(scene, cfra, side);
2292         
2293         if (nfra != cfra) {
2294                 CFRA = nfra;
2295                 change= 1;
2296         }
2297
2298         return change;
2299 }
2300
2301 /* move frame to next edit point operator */
2302 static int sequencer_next_edit_exec(bContext *C, wmOperator *op)
2303 {
2304         Scene *scene= CTX_data_scene(C);
2305         
2306         if(!next_prev_edit_internal(scene, SEQ_SIDE_RIGHT))
2307                 return OPERATOR_CANCELLED;
2308
2309         WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2310
2311         return OPERATOR_FINISHED;
2312 }
2313
2314 void SEQUENCER_OT_next_edit(wmOperatorType *ot)
2315 {
2316         /* identifiers */
2317         ot->name= "Next Edit";
2318         ot->idname= "SEQUENCER_OT_next_edit";
2319         ot->description="Move frame to next edit point";
2320         
2321         /* api callbacks */
2322         ot->exec= sequencer_next_edit_exec;
2323         ot->poll= sequencer_edit_poll;
2324         
2325         /* flags */
2326         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2327         
2328         /* properties */
2329 }
2330
2331 /* move frame to previous edit point operator */
2332 static int sequencer_previous_edit_exec(bContext *C, wmOperator *op)
2333 {
2334         Scene *scene= CTX_data_scene(C);
2335         
2336         if(!next_prev_edit_internal(scene, SEQ_SIDE_LEFT))
2337                 return OPERATOR_CANCELLED;
2338
2339         WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
2340         
2341         return OPERATOR_FINISHED;
2342 }
2343
2344 void SEQUENCER_OT_previous_edit(wmOperatorType *ot)
2345 {
2346         /* identifiers */
2347         ot->name= "Previous Edit";
2348         ot->idname= "SEQUENCER_OT_previous_edit";
2349         ot->description="Move frame to previous edit point";
2350         
2351         /* api callbacks */
2352         ot->exec= sequencer_previous_edit_exec;
2353         ot->poll= sequencer_edit_poll;
2354         
2355         /* flags */
2356         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2357         
2358         /* properties */
2359 }
2360
2361 static void swap_sequence(Scene* scene, Sequence* seqa, Sequence* seqb)
2362 {
2363         int gap = seqb->startdisp - seqa->enddisp;
2364         seqb->start = seqa->start;
2365         calc_sequence(scene, seqb);
2366         seqa->start = seqb->enddisp + gap;
2367         calc_sequence(scene, seqa);
2368 }
2369
2370 #if 0
2371 static Sequence* sequence_find_parent(Scene* scene, Sequence* child)
2372 {
2373         Editing *ed= seq_give_editing(scene, FALSE);
2374         Sequence *parent= NULL;
2375         Sequence *seq;
2376
2377         if(ed==NULL) return NULL;
2378
2379         for(seq= ed->seqbasep->first; seq; seq= seq->next) {
2380                 if ( (seq != child) && seq_is_parent(seq, child) ) {
2381                         parent = seq;
2382                         break;
2383                 }
2384         }
2385
2386         return parent;
2387 }
2388 #endif
2389
2390 static int sequencer_swap_exec(bContext *C, wmOperator *op)
2391 {
2392         Scene *scene= CTX_data_scene(C);
2393         Editing *ed= seq_give_editing(scene, FALSE);
2394         Sequence *active_seq = seq_active_get(scene);
2395         Sequence *seq, *iseq;
2396         int side= RNA_enum_get(op->ptr, "side");
2397
2398         if(active_seq==NULL) return OPERATOR_CANCELLED;
2399
2400         seq = find_next_prev_sequence(scene, active_seq, side, -1);
2401         
2402         if(seq) {
2403                 
2404                 /* disallow effect strips */
2405                 if (get_sequence_effect_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3))
2406                         return OPERATOR_CANCELLED;
2407                 if ((get_sequence_effect_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3))
2408                         return OPERATOR_CANCELLED;
2409
2410                 switch (side) {
2411                         case SEQ_SIDE_LEFT: 
2412                                 swap_sequence(scene, seq, active_seq);
2413                                 break;
2414                         case SEQ_SIDE_RIGHT: 
2415                                 swap_sequence(scene, active_seq, seq);
2416                                 break;
2417                 }
2418
2419                 // XXX - should be a generic function
2420                 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2421                         if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2422                                 calc_sequence(scene, iseq);
2423                         }
2424                 }
2425
2426                 /* do this in a new loop since both effects need to be calculated first */
2427                 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) {
2428                         if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
2429                                 /* this may now overlap */
2430                                 if( seq_test_overlap(ed->seqbasep, iseq) ) {
2431                                         shuffle_seq(ed->seqbasep, iseq, scene);
2432                                 }
2433                         }
2434                 }
2435
2436
2437
2438                 sort_seq(scene);
2439
2440                 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2441
2442                 return OPERATOR_FINISHED;
2443         }
2444
2445         return OPERATOR_CANCELLED;
2446 }
2447
2448 void SEQUENCER_OT_swap(wmOperatorType *ot)
2449 {
2450         /* identifiers */
2451         ot->name= "Swap Strip";
2452         ot->idname= "SEQUENCER_OT_swap";
2453         ot->description="Swap active strip with strip to the left";
2454         
2455         /* api callbacks */
2456         ot->exec= sequencer_swap_exec;
2457         ot->poll= sequencer_edit_poll;
2458         
2459         /* flags */
2460         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2461         
2462         /* properties */
2463         RNA_def_enum(ot->srna, "side", prop_side_lr_types, SEQ_SIDE_RIGHT, "Side", "Side of the strip to swap");
2464 }
2465
2466 static int sequencer_rendersize_exec(bContext *C, wmOperator *op)
2467 {
2468         int retval = OPERATOR_CANCELLED;
2469         Scene *scene= CTX_data_scene(C);
2470         Sequence *active_seq = seq_active_get(scene);
2471
2472         if(active_seq==NULL)
2473                 return OPERATOR_CANCELLED;
2474
2475         switch (active_seq->type) {
2476                 case SEQ_IMAGE:
2477                 case SEQ_MOVIE:
2478                         if (active_seq->strip) {
2479                                 // prevent setting the render size if sequence values aren't initialized
2480                                 if ( (active_seq->strip->orx>0) && (active_seq->strip->ory>0) ) {
2481                                         scene->r.xsch= active_seq->strip->orx;
2482                                         scene->r.ysch= active_seq->strip->ory;
2483                                         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
2484                                         retval = OPERATOR_FINISHED;
2485                                 }
2486                         }
2487                         break;
2488                 case SEQ_SCENE:
2489                 case SEQ_META:
2490                 case SEQ_RAM_SOUND:
2491                 case SEQ_HD_SOUND:
2492                 default:
2493                         break;
2494         }
2495         return retval;
2496 }
2497
2498 void SEQUENCER_OT_rendersize(wmOperatorType *ot)
2499 {
2500         /* identifiers */
2501         ot->name= "Set Render Size";
2502         ot->idname= "SEQUENCER_OT_rendersize";
2503         ot->description="Set render size and aspect from active sequence";
2504         
2505         /* api callbacks */
2506         ot->exec= sequencer_rendersize_exec;
2507         ot->poll= sequencer_edit_poll;
2508         
2509         /* flags */
2510         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2511         
2512         /* properties */
2513 }
2514
2515 static void seq_del_sound(Scene *scene, Sequence *seq)
2516 {
2517         if(seq->type == SEQ_META) {
2518                 Sequence *iseq;
2519                 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) {
2520                         seq_del_sound(scene, iseq);
2521                 }
2522         }
2523         else if(seq->scene_sound) {
2524                 sound_remove_scene_sound(scene, seq->scene_sound);
2525                 seq->scene_sound = NULL;
2526         }
2527 }
2528
2529 /* TODO, validate scenes */
2530 static int sequencer_copy_exec(bContext *C, wmOperator *op)
2531 {
2532         Scene *scene= CTX_data_scene(C);
2533         Editing *ed= seq_give_editing(scene, FALSE);
2534         Sequence *seq;
2535
2536         seq_free_clipboard();
2537
2538         if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) {
2539                 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
2540                 return OPERATOR_CANCELLED;
2541         }
2542
2543         seqbase_dupli_recursive(scene, &seqbase_clipboard, ed->seqbasep, FALSE);
2544         seqbase_clipboard_frame= scene->r.cfra;
2545
2546         /* Need to remove anything that references the current scene */
2547         for(seq= seqbase_clipboard.first; seq; seq= seq->next) {
2548                 seq_del_sound(scene, seq);
2549         }
2550
2551         return OPERATOR_FINISHED;
2552 }
2553
2554 void SEQUENCER_OT_copy(wmOperatorType *ot)
2555 {
2556         /* identifiers */
2557         ot->name= "Copy";
2558         ot->idname= "SEQUENCER_OT_copy";
2559         ot->description="";
2560
2561         /* api callbacks */
2562         ot->exec= sequencer_copy_exec;
2563         ot->poll= sequencer_edit_poll;
2564
2565         /* flags */
2566         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2567
2568         /* properties */
2569 }
2570
2571 static void seq_offset(Scene *scene, Sequence *seq, int ofs)
2572 {
2573         if(seq->type == SEQ_META) {
2574                 Sequence *iseq;
2575                 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) {
2576                         seq_offset(scene, iseq, ofs);
2577                 }
2578         }
2579         else {
2580                 seq->start += ofs;
2581         }
2582
2583         calc_sequence_disp(scene, seq);
2584 }
2585
2586 static int sequencer_paste_exec(bContext *C, wmOperator *op)
2587 {
2588         Scene *scene= CTX_data_scene(C);
2589         Editing *ed= seq_give_editing(scene, TRUE); /* create if needed */
2590         ListBase nseqbase = {NULL, NULL};
2591         int ofs;
2592         Sequence *iseq;
2593
2594         deselect_all_seq(scene);
2595         ofs = scene->r.cfra - seqbase_clipboard_frame;
2596
2597         seqbase_dupli_recursive(scene, &nseqbase, &seqbase_clipboard, FALSE);
2598
2599         /* transform pasted strips before adding */
2600         if(ofs) {
2601                 for(iseq= nseqbase.first; iseq; iseq= iseq->next) {
2602                         seq_offset(scene, iseq, ofs);
2603                 }
2604         }
2605
2606         addlisttolist(ed->seqbasep, &nseqbase);
2607
2608         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2609
2610         return OPERATOR_FINISHED;
2611 }
2612
2613 void SEQUENCER_OT_paste(wmOperatorType *ot)
2614 {
2615         /* identifiers */
2616         ot->name= "Paste";
2617         ot->idname= "SEQUENCER_OT_paste";
2618         ot->description="";
2619
2620         /* api callbacks */
2621         ot->exec= sequencer_paste_exec;
2622         ot->poll= ED_operator_sequencer_active;
2623
2624         /* flags */
2625         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2626
2627         /* properties */
2628 }
2629
2630 static int sequencer_swap_data_exec(bContext *C, wmOperator *op)
2631 {
2632         Scene *scene= CTX_data_scene(C);
2633         Sequence *seq_act;
2634         Sequence *seq_other;
2635
2636         if(seq_active_pair_get(scene, &seq_act, &seq_other) == 0) {
2637                 BKE_report(op->reports, RPT_ERROR, "Must select 2 strips");
2638                 return OPERATOR_CANCELLED;
2639         }
2640
2641         if(seq_swap(seq_act, seq_other) == 0) {
2642                 BKE_report(op->reports, RPT_ERROR, "Strips were not compatible");
2643                 return OPERATOR_CANCELLED;
2644         }
2645
2646         calc_sequence(scene, seq_act);
2647         calc_sequence(scene, seq_other);
2648
2649         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
2650
2651         return OPERATOR_FINISHED;
2652 }
2653
2654 void SEQUENCER_OT_swap_data(wmOperatorType *ot)
2655 {
2656         /* identifiers */
2657         ot->name= "Sequencer Swap Data";
2658         ot->idname= "SEQUENCER_OT_swap_data";
2659         ot->description="Swap 2 sequencer strips";
2660
2661         /* api callbacks */
2662         ot->exec= sequencer_swap_data_exec;
2663         ot->poll= ED_operator_sequencer_active;
2664
2665         /* flags */
2666         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2667
2668         /* properties */
2669 }
2670