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