Sequencer: srt export support.
[blender.git] / source / blender / editors / space_sequencer / sequencer_edit.c
1 /*
2  * ***** begin GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation, 2003-2009
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/space_sequencer/sequencer_edit.c
27  *  \ingroup spseq
28  */
29
30
31 #include <stdlib.h>
32 #include <math.h>
33 #include <string.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "BLI_blenlib.h"
38 #include "BLI_fileops.h"
39 #include "BLI_ghash.h"
40 #include "BLI_math.h"
41 #include "BLI_timecode.h"
42 #include "BLI_utildefines.h"
43
44 #include "BLF_translation.h"
45
46 #include "DNA_scene_types.h"
47
48 #include "BKE_context.h"
49 #include "BKE_global.h"
50 #include "BKE_main.h"
51 #include "BKE_sequencer.h"
52 #include "BKE_report.h"
53 #include "BKE_sound.h"
54
55
56 #include "WM_api.h"
57 #include "WM_types.h"
58
59 #include "RNA_define.h"
60 #include "RNA_enum_types.h"
61
62 /* for menu/popup icons etc etc*/
63
64 #include "ED_numinput.h"
65 #include "ED_screen.h"
66 #include "ED_transform.h"
67 #include "ED_sequencer.h"
68 #include "ED_space_api.h"
69
70 #include "UI_view2d.h"
71 #include "UI_interface.h"
72
73
74 /* own include */
75 #include "sequencer_intern.h"
76
77 /* XXX */
78 /* RNA Enums, used in multiple files */
79 EnumPropertyItem sequencer_prop_effect_types[] = {
80         {SEQ_TYPE_CROSS, "CROSS", 0, "Crossfade", "Crossfade effect strip type"},
81         {SEQ_TYPE_ADD, "ADD", 0, "Add", "Add effect strip type"},
82         {SEQ_TYPE_SUB, "SUBTRACT", 0, "Subtract", "Subtract effect strip type"},
83         {SEQ_TYPE_ALPHAOVER, "ALPHA_OVER", 0, "Alpha Over", "Alpha Over effect strip type"},
84         {SEQ_TYPE_ALPHAUNDER, "ALPHA_UNDER", 0, "Alpha Under", "Alpha Under effect strip type"},
85         {SEQ_TYPE_GAMCROSS, "GAMMA_CROSS", 0, "Gamma Cross", "Gamma Cross effect strip type"},
86         {SEQ_TYPE_MUL, "MULTIPLY", 0, "Multiply", "Multiply effect strip type"},
87         {SEQ_TYPE_OVERDROP, "OVER_DROP", 0, "Alpha Over Drop", "Alpha Over Drop effect strip type"},
88         {SEQ_TYPE_WIPE, "WIPE", 0, "Wipe", "Wipe effect strip type"},
89         {SEQ_TYPE_GLOW, "GLOW", 0, "Glow", "Glow effect strip type"},
90         {SEQ_TYPE_TRANSFORM, "TRANSFORM", 0, "Transform", "Transform effect strip type"},
91         {SEQ_TYPE_COLOR, "COLOR", 0, "Color", "Color effect strip type"},
92         {SEQ_TYPE_SPEED, "SPEED", 0, "Speed", "Color effect strip type"},
93         {SEQ_TYPE_MULTICAM, "MULTICAM", 0, "Multicam Selector", ""},
94         {SEQ_TYPE_ADJUSTMENT, "ADJUSTMENT", 0, "Adjustment Layer", ""},
95         {SEQ_TYPE_GAUSSIAN_BLUR, "GAUSSIAN_BLUR", 0, "Gaussian Blur", ""},
96         {SEQ_TYPE_TEXT, "TEXT", 0, "Text", ""},
97         {0, NULL, 0, NULL, NULL}
98 };
99
100 /* mute operator */
101
102 EnumPropertyItem prop_side_types[] = {
103         {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
104         {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
105         {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""},
106         {0, NULL, 0, NULL, NULL}
107 };
108
109 static EnumPropertyItem prop_side_lr_types[] = {
110         {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""},
111         {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""},
112         {0, NULL, 0, NULL, NULL}
113 };
114
115 typedef struct TransSeq {
116         int start, machine;
117         int startstill, endstill;
118         int startdisp, enddisp;
119         int startofs, endofs;
120         int anim_startofs, anim_endofs;
121         /* int final_left, final_right; */ /* UNUSED */
122         int len;
123 } TransSeq;
124
125 /* ********************************************************************** */
126
127 /* ***************** proxy job manager ********************** */
128
129 typedef struct ProxyBuildJob {
130         Scene *scene; 
131         struct Main *main;
132         ListBase queue;
133         int stop;
134 } ProxyJob;
135
136 static void proxy_freejob(void *pjv)
137 {
138         ProxyJob *pj = pjv;
139
140         BLI_freelistN(&pj->queue);
141
142         MEM_freeN(pj);
143 }
144
145 /* only this runs inside thread */
146 static void proxy_startjob(void *pjv, short *stop, short *do_update, float *progress)
147 {
148         ProxyJob *pj = pjv;
149         LinkData *link;
150
151         for (link = pj->queue.first; link; link = link->next) {
152                 struct SeqIndexBuildContext *context = link->data;
153
154                 BKE_sequencer_proxy_rebuild(context, stop, do_update, progress);
155                 
156                 if (*stop) {
157                         pj->stop = 1;
158                         fprintf(stderr,  "Canceling proxy rebuild on users request...\n");
159                         break;
160                 }
161         }
162 }
163
164 static void proxy_endjob(void *pjv)
165 {
166         ProxyJob *pj = pjv;
167         Editing *ed = BKE_sequencer_editing_get(pj->scene, false);
168         LinkData *link;
169
170         for (link = pj->queue.first; link; link = link->next) {
171                 BKE_sequencer_proxy_rebuild_finish(link->data, pj->stop);
172         }
173
174         BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, false);
175
176         WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, pj->scene);
177 }
178
179 static void seq_proxy_build_job(const bContext *C)
180 {
181         wmJob *wm_job;
182         ProxyJob *pj;
183         Scene *scene = CTX_data_scene(C);
184         Editing *ed = BKE_sequencer_editing_get(scene, false);
185         ScrArea *sa = CTX_wm_area(C);
186         Sequence *seq;
187         GSet *file_list;
188         
189         if (ed == NULL) {
190                 return;
191         }
192
193         wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Building Proxies",
194                              WM_JOB_PROGRESS, WM_JOB_TYPE_SEQ_BUILD_PROXY);
195
196         pj = WM_jobs_customdata_get(wm_job);
197
198         if (!pj) {
199                 pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
200         
201                 pj->scene = scene;
202                 pj->main = CTX_data_main(C);
203
204                 WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
205                 WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_SEQUENCER, NC_SCENE | ND_SEQUENCER);
206                 WM_jobs_callbacks(wm_job, proxy_startjob, NULL, NULL, proxy_endjob);
207         }
208
209         file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
210         SEQP_BEGIN (ed, seq)
211         {
212                 if ((seq->flag & SELECT)) {
213                         BKE_sequencer_proxy_rebuild_context(pj->main, pj->scene, seq, file_list, &pj->queue);
214                 }
215         }
216         SEQ_END
217
218         BLI_gset_free(file_list, MEM_freeN);
219         
220         if (!WM_jobs_is_running(wm_job)) {
221                 G.is_break = false;
222                 WM_jobs_start(CTX_wm_manager(C), wm_job);
223         }
224
225         ED_area_tag_redraw(sa);
226 }
227
228 /* ********************************************************************** */
229
230 void seq_rectf(Sequence *seq, rctf *rectf)
231 {
232         if (seq->startstill) rectf->xmin = seq->start;
233         else rectf->xmin = seq->startdisp;
234         rectf->ymin = seq->machine + SEQ_STRIP_OFSBOTTOM;
235         if (seq->endstill) rectf->xmax = seq->start + seq->len;
236         else rectf->xmax = seq->enddisp;
237         rectf->ymax = seq->machine + SEQ_STRIP_OFSTOP;
238 }
239
240 void boundbox_seq(Scene *scene, rctf *rect)
241 {
242         Sequence *seq;
243         Editing *ed = BKE_sequencer_editing_get(scene, false);
244         float min[2], max[2];
245
246         
247         if (ed == NULL) return;
248
249         min[0] = 0.0;
250         max[0] = EFRA + 1;
251         min[1] = 0.0;
252         max[1] = 8.0;
253
254         seq = ed->seqbasep->first;
255         while (seq) {
256
257                 if (min[0] > seq->startdisp - 1) min[0] = seq->startdisp - 1;
258                 if (max[0] < seq->enddisp + 1) max[0] = seq->enddisp + 1;
259                 if (max[1] < seq->machine + 2) max[1] = seq->machine + 2;
260
261                 seq = seq->next;
262         }
263
264         rect->xmin = min[0];
265         rect->xmax = max[0];
266         rect->ymin = min[1];
267         rect->ymax = max[1];
268
269 }
270
271 static int mouse_frame_side(View2D *v2d, short mouse_x, int frame)
272 {
273         int mval[2];
274         float mouseloc[2];
275         
276         mval[0] = mouse_x;
277         mval[1] = 0;
278         
279         /* choose the side based on which side of the playhead the mouse is on */
280         UI_view2d_region_to_view(v2d, mval[0], mval[1], &mouseloc[0], &mouseloc[1]);
281         
282         return mouseloc[0] > frame ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT;
283 }
284
285
286 Sequence *find_neighboring_sequence(Scene *scene, Sequence *test, int lr, int sel) 
287 {
288         /* sel - 0==unselected, 1==selected, -1==done care*/
289         Sequence *seq;
290         Editing *ed = BKE_sequencer_editing_get(scene, false);
291
292         if (ed == NULL) return NULL;
293
294         if (sel > 0) sel = SELECT;
295         
296         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
297                 if ((seq != test) &&
298                     (test->machine == seq->machine) &&
299                     ((sel == -1) || (sel && (seq->flag & SELECT)) || (sel == 0 && (seq->flag & SELECT) == 0)))
300                 {
301                         switch (lr) {
302                                 case SEQ_SIDE_LEFT:
303                                         if (test->startdisp == (seq->enddisp)) {
304                                                 return seq;
305                                         }
306                                         break;
307                                 case SEQ_SIDE_RIGHT:
308                                         if (test->enddisp == (seq->startdisp)) {
309                                                 return seq;
310                                         }
311                                         break;
312                         }
313                 }
314         }
315         return NULL;
316 }
317
318 static Sequence *find_next_prev_sequence(Scene *scene, Sequence *test, int lr, int sel) 
319 {
320         /* sel - 0==unselected, 1==selected, -1==done care*/
321         Sequence *seq, *best_seq = NULL;
322         Editing *ed = BKE_sequencer_editing_get(scene, false);
323         
324         int dist, best_dist;
325         best_dist = MAXFRAME * 2;
326
327         
328         if (ed == NULL) return NULL;
329
330         seq = ed->seqbasep->first;
331         while (seq) {
332                 if ((seq != test) &&
333                     (test->machine == seq->machine) &&
334                     (test->depth == seq->depth) &&
335                     ((sel == -1) || (sel == (seq->flag & SELECT))))
336                 {
337                         dist = MAXFRAME * 2;
338                         
339                         switch (lr) {
340                                 case SEQ_SIDE_LEFT:
341                                         if (seq->enddisp <= test->startdisp) {
342                                                 dist = test->enddisp - seq->startdisp;
343                                         }
344                                         break;
345                                 case SEQ_SIDE_RIGHT:
346                                         if (seq->startdisp >= test->enddisp) {
347                                                 dist = seq->startdisp - test->enddisp;
348                                         }
349                                         break;
350                         }
351                         
352                         if (dist == 0) {
353                                 best_seq = seq;
354                                 break;
355                         }
356                         else if (dist < best_dist) {
357                                 best_dist = dist;
358                                 best_seq = seq;
359                         }
360                 }
361                 seq = seq->next;
362         }
363         return best_seq; /* can be null */
364 }
365
366
367 Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[2])
368 {
369         Sequence *seq;
370         Editing *ed = BKE_sequencer_editing_get(scene, false);
371         float x, y;
372         float pixelx;
373         float handsize;
374         float displen;
375         *hand = SEQ_SIDE_NONE;
376
377         
378         if (ed == NULL) return NULL;
379         
380         pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
381
382         UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
383         
384         seq = ed->seqbasep->first;
385         
386         while (seq) {
387                 if (seq->machine == (int)y) {
388                         /* check for both normal strips, and strips that have been flipped horizontally */
389                         if (((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) ||
390                             ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) )
391                         {
392                                 if (BKE_sequence_tx_test(seq)) {
393                                         
394                                         /* clamp handles to defined size in pixel space */
395                                         
396                                         handsize = seq->handsize;
397                                         displen = (float)abs(seq->startdisp - seq->enddisp);
398                                         
399                                         if (displen / pixelx > 16) { /* don't even try to grab the handles of small strips */
400                                                 /* Set the max value to handle to 1/3 of the total len when its less than 28.
401                                                  * This is important because otherwise selecting handles happens even when you click in the middle */
402                                                 
403                                                 if ((displen / 3) < 30 * pixelx) {
404                                                         handsize = displen / 3;
405                                                 }
406                                                 else {
407                                                         CLAMP(handsize, 7 * pixelx, 30 * pixelx);
408                                                 }
409                                                 
410                                                 if (handsize + seq->startdisp >= x)
411                                                         *hand = SEQ_SIDE_LEFT;
412                                                 else if (-handsize + seq->enddisp <= x)
413                                                         *hand = SEQ_SIDE_RIGHT;
414                                         }
415                                 }
416                                 return seq;
417                         }
418                 }
419                 seq = seq->next;
420         }
421         return NULL;
422 }
423
424
425 static bool seq_is_parent(Sequence *par, Sequence *seq)
426 {
427         return ((par->seq1 == seq) || (par->seq2 == seq) || (par->seq3 == seq));
428 }
429
430 static bool seq_is_predecessor(Sequence *pred, Sequence *seq)
431 {
432         if (!pred) return 0;
433         if (pred == seq) return 0;
434         else if (seq_is_parent(pred, seq)) return 1;
435         else if (pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1;
436         else if (pred->seq2 && seq_is_predecessor(pred->seq2, seq)) return 1;
437         else if (pred->seq3 && seq_is_predecessor(pred->seq3, seq)) return 1;
438
439         return 0;
440 }
441
442 void ED_sequencer_deselect_all(Scene *scene)
443 {
444         Sequence *seq;
445         Editing *ed = BKE_sequencer_editing_get(scene, false);
446
447         
448         if (ed == NULL) return;
449
450         SEQP_BEGIN (ed, seq)
451         {
452                 seq->flag &= ~SEQ_ALLSEL;
453         }
454         SEQ_END
455                 
456 }
457
458 void recurs_sel_seq(Sequence *seqm)
459 {
460         Sequence *seq;
461
462         seq = seqm->seqbase.first;
463         while (seq) {
464
465                 if (seqm->flag & (SEQ_LEFTSEL + SEQ_RIGHTSEL)) seq->flag &= ~SEQ_ALLSEL;
466                 else if (seqm->flag & SELECT) seq->flag |= SELECT;
467                 else seq->flag &= ~SEQ_ALLSEL;
468
469                 if (seq->seqbase.first) recurs_sel_seq(seq);
470
471                 seq = seq->next;
472         }
473 }
474
475 int ED_space_sequencer_maskedit_mask_poll(bContext *C)
476 {
477         /* in this case both funcs are the same, for clip editor not */
478         return ED_space_sequencer_maskedit_poll(C);
479 }
480
481 bool ED_space_sequencer_check_show_maskedit(SpaceSeq *sseq, Scene *scene)
482 {
483         if (sseq && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
484                 return (BKE_sequencer_mask_get(scene) != NULL);
485         }
486
487         return false;
488 }
489
490 int ED_space_sequencer_maskedit_poll(bContext *C)
491 {
492         SpaceSeq *sseq = CTX_wm_space_seq(C);
493
494         if (sseq) {
495                 Scene *scene = CTX_data_scene(C);
496                 return ED_space_sequencer_check_show_maskedit(sseq, scene);
497         }
498
499         return false;
500 }
501
502 /* are we displaying the seq output (not channels or histogram)*/
503 bool ED_space_sequencer_check_show_imbuf(SpaceSeq *sseq)
504 {
505         return (ELEM(sseq->view, SEQ_VIEW_PREVIEW, SEQ_VIEW_SEQUENCE_PREVIEW) &&
506                 ELEM(sseq->mainb, SEQ_DRAW_SEQUENCE, SEQ_DRAW_IMG_IMBUF));
507 }
508
509 bool ED_space_sequencer_check_show_strip(SpaceSeq *sseq)
510 {
511         return (ELEM(sseq->view, SEQ_VIEW_SEQUENCE, SEQ_VIEW_SEQUENCE_PREVIEW) &&
512                 ELEM(sseq->mainb, SEQ_DRAW_SEQUENCE, SEQ_DRAW_IMG_IMBUF));
513 }
514
515
516 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str)
517 {
518         Editing *ed = BKE_sequencer_editing_get(scene, false);
519         Sequence *seq1 = NULL, *seq2 = NULL, *seq3 = NULL, *seq;
520         
521         *error_str = NULL;
522
523         if (!activeseq)
524                 seq2 = BKE_sequencer_active_get(scene);
525
526         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
527                 if (seq->flag & SELECT) {
528                         if (seq->type == SEQ_TYPE_SOUND_RAM && BKE_sequence_effect_get_num_inputs(type) != 0) {
529                                 *error_str = N_("Cannot apply effects to audio sequence strips");
530                                 return 0;
531                         }
532                         if ((seq != activeseq) && (seq != seq2)) {
533                                 if      (seq2 == NULL) seq2 = seq;
534                                 else if (seq1 == NULL) seq1 = seq;
535                                 else if (seq3 == NULL) seq3 = seq;
536                                 else {
537                                         *error_str = N_("Cannot apply effect to more than 3 sequence strips");
538                                         return 0;
539                                 }
540                         }
541                 }
542         }
543
544         /* make sequence selection a little bit more intuitive
545          * for 3 strips: the last-strip should be sequence3 */
546         if (seq3 != NULL && seq2 != NULL) {
547                 Sequence *tmp = seq2;
548                 seq2 = seq3;
549                 seq3 = tmp;
550         }
551         
552
553         switch (BKE_sequence_effect_get_num_inputs(type)) {
554                 case 0:
555                         *selseq1 = *selseq2 = *selseq3 = NULL;
556                         return 1; /* succsess */
557                 case 1:
558                         if (seq2 == NULL) {
559                                 *error_str = N_("At least one selected sequence strip is needed");
560                                 return 0;
561                         }
562                         if (seq1 == NULL) seq1 = seq2;
563                         if (seq3 == NULL) seq3 = seq2;
564                         /* fall-through */
565                 case 2:
566                         if (seq1 == NULL || seq2 == NULL) {
567                                 *error_str = N_("2 selected sequence strips are needed");
568                                 return 0;
569                         }
570                         if (seq3 == NULL) seq3 = seq2;
571                         break;
572         }
573         
574         if (seq1 == NULL && seq2 == NULL && seq3 == NULL) {
575                 *error_str = N_("TODO: in what cases does this happen?");
576                 return 0;
577         }
578         
579         *selseq1 = seq1;
580         *selseq2 = seq2;
581         *selseq3 = seq3;
582
583         return 1;
584 }
585
586 static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq)
587 {
588         Sequence *seq1, *seq2, *seq3;
589
590         /* try to find a replacement input sequence, and flag for later deletion if
591          * no replacement can be found */
592
593         if (!seq)
594                 return NULL;
595         else if (!(seq->type & SEQ_TYPE_EFFECT))
596                 return ((seq->flag & SELECT) ? NULL : seq);
597         else if (!(seq->flag & SELECT)) {
598                 /* try to find replacement for effect inputs */
599                 seq1 = del_seq_find_replace_recurs(scene, seq->seq1);
600                 seq2 = del_seq_find_replace_recurs(scene, seq->seq2);
601                 seq3 = del_seq_find_replace_recurs(scene, seq->seq3);
602
603                 if (seq1 == seq->seq1 && seq2 == seq->seq2 && seq3 == seq->seq3) {
604                         /* pass */
605                 }
606                 else if (seq1 || seq2 || seq3) {
607                         seq->seq1 = (seq1) ? seq1 : (seq2) ? seq2 : seq3;
608                         seq->seq2 = (seq2) ? seq2 : (seq1) ? seq1 : seq3;
609                         seq->seq3 = (seq3) ? seq3 : (seq1) ? seq1 : seq2;
610
611                         BKE_sequencer_update_changed_seq_and_deps(scene, seq, 1, 1);
612                 }
613                 else
614                         seq->flag |= SELECT;  /* mark for delete */
615         }
616
617         if (seq->flag & SELECT) {
618                 if ((seq1 = del_seq_find_replace_recurs(scene, seq->seq1))) return seq1;
619                 if ((seq2 = del_seq_find_replace_recurs(scene, seq->seq2))) return seq2;
620                 if ((seq3 = del_seq_find_replace_recurs(scene, seq->seq3))) return seq3;
621                 else return NULL;
622         }
623         else
624                 return seq;
625 }
626
627 static void del_seq_clear_modifiers_recurs(Scene *scene, Sequence *deleting_sequence)
628 {
629         Editing *ed = BKE_sequencer_editing_get(scene, false);
630         Sequence *current_sequence;
631
632         SEQP_BEGIN(ed, current_sequence)
633         {
634                 if (!(current_sequence->flag & SELECT) && current_sequence != deleting_sequence) {
635                         SequenceModifierData *smd;
636
637                         for (smd = current_sequence->modifiers.first; smd; smd = smd->next) {
638                                 if (smd->mask_sequence == deleting_sequence) {
639                                         smd->mask_sequence = NULL;
640                                 }
641                         }
642                 }
643         }
644         SEQ_END
645 }
646
647 static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall)
648 {
649         Sequence *seq, *seqn;
650         Sequence *last_seq = BKE_sequencer_active_get(scene);
651
652         seq = lb->first;
653         while (seq) {
654                 seqn = seq->next;
655                 if ((seq->flag & flag) || deleteall) {
656                         BLI_remlink(lb, seq);
657                         if (seq == last_seq) BKE_sequencer_active_set(scene, NULL);
658                         if (seq->type == SEQ_TYPE_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1);
659                         BKE_sequence_free(scene, seq);
660                 }
661                 seq = seqn;
662         }
663 }
664
665
666 static Sequence *cut_seq_hard(Scene *scene, Sequence *seq, int cutframe)
667 {
668         TransSeq ts;
669         Sequence *seqn = NULL;
670         bool skip_dup = false;
671
672         /* backup values */
673         ts.start = seq->start;
674         ts.machine = seq->machine;
675         ts.startstill = seq->startstill;
676         ts.endstill = seq->endstill;
677         ts.startdisp = seq->startdisp;
678         ts.enddisp = seq->enddisp;
679         ts.startofs = seq->startofs;
680         ts.endofs = seq->endofs;
681         ts.anim_startofs = seq->anim_startofs;
682         ts.anim_endofs = seq->anim_endofs;
683         ts.len = seq->len;
684         
685         /* First Strip! */
686         /* strips with extended stillfames before */
687         
688         if ((seq->startstill) && (cutframe < seq->start)) {
689                 /* don't do funny things with METAs ... */
690                 if (seq->type == SEQ_TYPE_META) {
691                         skip_dup = true;
692                         seq->startstill = seq->start - cutframe;
693                 }
694                 else {
695                         seq->start = cutframe - 1;
696                         seq->startstill = cutframe - seq->startdisp - 1;
697                         seq->anim_endofs += seq->len - 1;
698                         seq->endstill = 0;
699                 }
700         }
701         /* normal strip */
702         else if ((cutframe >= seq->start) && (cutframe <= (seq->start + seq->len))) {
703                 seq->endofs = 0;
704                 seq->endstill = 0;
705                 seq->anim_endofs += (seq->start + seq->len) - cutframe;
706         }
707         /* strips with extended stillframes after */
708         else if (((seq->start + seq->len) < cutframe) && (seq->endstill)) {
709                 seq->endstill -= seq->enddisp - cutframe;
710                 /* don't do funny things with METAs ... */
711                 if (seq->type == SEQ_TYPE_META) {
712                         skip_dup = true;
713                 }
714         }
715         
716         BKE_sequence_reload_new_file(scene, seq, false);
717         BKE_sequence_calc(scene, seq);
718
719         if (!skip_dup) {
720                 /* Duplicate AFTER the first change */
721                 seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
722         }
723         
724         if (seqn) {
725                 seqn->flag |= SELECT;
726                         
727                 /* Second Strip! */
728                 /* strips with extended stillframes before */
729                 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
730                         seqn->start = ts.start;
731                         seqn->startstill = ts.start - cutframe;
732                         seqn->anim_endofs = ts.anim_endofs;
733                         seqn->endstill = ts.endstill;
734                 }
735                 
736                 /* normal strip */
737                 else if ((cutframe >= seqn->start) && (cutframe <= (seqn->start + seqn->len))) {
738                         seqn->start = cutframe;
739                         seqn->startstill = 0;
740                         seqn->startofs = 0;
741                         seqn->endofs = ts.endofs;
742                         seqn->anim_startofs += cutframe - ts.start;
743                         seqn->anim_endofs = ts.anim_endofs;
744                         seqn->endstill = ts.endstill;
745                 }
746                 
747                 /* strips with extended stillframes after */
748                 else if (((seqn->start + seqn->len) < cutframe) && (seqn->endstill)) {
749                         seqn->start = cutframe;
750                         seqn->startofs = 0;
751                         seqn->anim_startofs += ts.len - 1;
752                         seqn->endstill = ts.enddisp - cutframe - 1;
753                         seqn->startstill = 0;
754                 }
755                 
756                 BKE_sequence_reload_new_file(scene, seqn, false);
757                 BKE_sequence_calc(scene, seqn);
758         }
759         return seqn;
760 }
761
762 static Sequence *cut_seq_soft(Scene *scene, Sequence *seq, int cutframe)
763 {
764         TransSeq ts;
765         Sequence *seqn = NULL;
766         bool skip_dup = false;
767
768         /* backup values */
769         ts.start = seq->start;
770         ts.machine = seq->machine;
771         ts.startstill = seq->startstill;
772         ts.endstill = seq->endstill;
773         ts.startdisp = seq->startdisp;
774         ts.enddisp = seq->enddisp;
775         ts.startofs = seq->startofs;
776         ts.endofs = seq->endofs;
777         ts.anim_startofs = seq->anim_startofs;
778         ts.anim_endofs = seq->anim_endofs;
779         ts.len = seq->len;
780         
781         /* First Strip! */
782         /* strips with extended stillfames before */
783         
784         if ((seq->startstill) && (cutframe < seq->start)) {
785                 /* don't do funny things with METAs ... */
786                 if (seq->type == SEQ_TYPE_META) {
787                         skip_dup = true;
788                         seq->startstill = seq->start - cutframe;
789                 }
790                 else {
791                         seq->start = cutframe - 1;
792                         seq->startstill = cutframe - seq->startdisp - 1;
793                         seq->endofs = seq->len - 1;
794                         seq->endstill = 0;
795                 }
796         }
797         /* normal strip */
798         else if ((cutframe >= seq->start) && (cutframe <= (seq->start + seq->len))) {
799                 seq->endofs = (seq->start + seq->len) - cutframe;
800         }
801         /* strips with extended stillframes after */
802         else if (((seq->start + seq->len) < cutframe) && (seq->endstill)) {
803                 seq->endstill -= seq->enddisp - cutframe;
804                 /* don't do funny things with METAs ... */
805                 if (seq->type == SEQ_TYPE_META) {
806                         skip_dup = true;
807                 }
808         }
809         
810         BKE_sequence_calc(scene, seq);
811
812         if (!skip_dup) {
813                 /* Duplicate AFTER the first change */
814                 seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM);
815         }
816         
817         if (seqn) {
818                 seqn->flag |= SELECT;
819                         
820                 /* Second Strip! */
821                 /* strips with extended stillframes before */
822                 if ((seqn->startstill) && (cutframe == seqn->start + 1)) {
823                         seqn->start = ts.start;
824                         seqn->startstill = ts.start - cutframe;
825                         seqn->endofs = ts.endofs;
826                         seqn->endstill = ts.endstill;
827                 }
828                 
829                 /* normal strip */
830                 else if ((cutframe >= seqn->start) && (cutframe <= (seqn->start + seqn->len))) {
831                         seqn->startstill = 0;
832                         seqn->startofs = cutframe - ts.start;
833                         seqn->endofs = ts.endofs;
834                         seqn->endstill = ts.endstill;
835                 }
836                 
837                 /* strips with extended stillframes after */
838                 else if (((seqn->start + seqn->len) < cutframe) && (seqn->endstill)) {
839                         seqn->start = cutframe - ts.len + 1;
840                         seqn->startofs = ts.len - 1;
841                         seqn->endstill = ts.enddisp - cutframe - 1;
842                         seqn->startstill = 0;
843                 }
844                 
845                 BKE_sequence_calc(scene, seqn);
846         }
847         return seqn;
848 }
849
850
851 /* like duplicate, but only duplicate and cut overlapping strips,
852  * strips to the left of the cutframe are ignored and strips to the right 
853  * are moved to the end of slist
854  * we have to work on the same slist (not using a separate list), since
855  * otherwise dupli_seq can't check for duplicate names properly and
856  * may generate strips with the same name (which will mess up animdata)
857  */
858
859 static bool cut_seq_list(Scene *scene, ListBase *slist, int cutframe,
860                          Sequence * (*cut_seq)(Scene *, Sequence *, int))
861 {
862         Sequence *seq, *seq_next_iter;
863         Sequence *seq_first_new = NULL;
864         
865         seq = slist->first;
866
867         while (seq && seq != seq_first_new) {
868                 seq_next_iter = seq->next; /* we need this because we may remove seq */
869                 seq->tmp = NULL;
870                 if (seq->flag & SELECT) {
871                         if (cutframe > seq->startdisp && 
872                             cutframe < seq->enddisp)
873                         {
874                                 Sequence *seqn = cut_seq(scene, seq, cutframe);
875                                 if (seqn) {
876                                         BLI_addtail(slist, seqn);
877                                         if (seq_first_new == NULL) {
878                                                 seq_first_new = seqn;
879                                         }
880                                 }
881                         }
882                         else if (seq->enddisp <= cutframe) {
883                                 /* do nothing */
884                         }
885                         else if (seq->startdisp >= cutframe) {
886                                 /* move to tail */
887                                 BLI_remlink(slist, seq);
888                                 BLI_addtail(slist, seq);
889
890                                 if (seq_first_new == NULL) {
891                                         seq_first_new = seq;
892                                 }
893                         }
894                 }
895                 seq = seq_next_iter;
896         }
897
898         return (seq_first_new != NULL);
899 }
900
901 static bool sequence_offset_after_frame(Scene *scene, const int delta, const int cfra)
902 {
903         Sequence *seq;
904         Editing *ed = BKE_sequencer_editing_get(scene, false);
905         bool done = false;
906         TimeMarker *marker;
907
908         /* all strips >= cfra are shifted */
909         
910         if (ed == NULL) return 0;
911
912         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
913                 if (seq->startdisp >= cfra) {
914                         BKE_sequence_translate(scene, seq, delta);
915                         BKE_sequence_calc(scene, seq);
916                         done = true;
917                 }
918         }
919
920         if (!scene->toolsettings->lock_markers) {
921                 for (marker = scene->markers.first; marker; marker = marker->next) {
922                         if (marker->frame >= cfra) {
923                                 marker->frame += delta;
924                         }
925                 }
926         }
927
928         return done;
929 }
930
931 static void UNUSED_FUNCTION(touch_seq_files) (Scene *scene)
932 {
933         Sequence *seq;
934         Editing *ed = BKE_sequencer_editing_get(scene, false);
935         char str[256];
936
937         /* touch all strips with movies */
938         
939         if (ed == NULL) return;
940
941         // XXX25 if (okee("Touch and print selected movies")==0) return;
942
943         WM_cursor_wait(1);
944
945         SEQP_BEGIN (ed, seq)
946         {
947                 if (seq->flag & SELECT) {
948                         if (seq->type == SEQ_TYPE_MOVIE) {
949                                 if (seq->strip && seq->strip->stripdata) {
950                                         BLI_make_file_string(G.main->name, str, seq->strip->dir, seq->strip->stripdata->name);
951                                         BLI_file_touch(seq->name);
952                                 }
953                         }
954
955                 }
956         }
957         SEQ_END
958
959         WM_cursor_wait(0);
960 }
961
962 #if 0
963 static void set_filter_seq(Scene *scene)
964 {
965         Sequence *seq;
966         Editing *ed = BKE_sequencer_editing_get(scene, false);
967
968         
969         if (ed == NULL) return;
970
971         if (okee("Set Deinterlace") == 0) return;
972
973         SEQP_BEGIN (ed, seq)
974         {
975                 if (seq->flag & SELECT) {
976                         if (seq->type == SEQ_TYPE_MOVIE) {
977                                 seq->flag |= SEQ_FILTERY;
978                                 BKE_sequence_reload_new_file(scene, seq, false);
979                                 BKE_sequence_calc(scene, seq);
980                         }
981
982                 }
983         }
984         SEQ_END
985 }
986 #endif
987
988 static void UNUSED_FUNCTION(seq_remap_paths) (Scene *scene)
989 {
990         Sequence *seq, *last_seq = BKE_sequencer_active_get(scene);
991         Editing *ed = BKE_sequencer_editing_get(scene, false);
992         char from[FILE_MAX], to[FILE_MAX], stripped[FILE_MAX];
993         
994         
995         if (last_seq == NULL)
996                 return;
997         
998         BLI_strncpy(from, last_seq->strip->dir, sizeof(from));
999 // XXX  if (0 == sbutton(from, 0, sizeof(from) - 1, "From: "))
1000 //              return;
1001         
1002         BLI_strncpy(to, from, sizeof(to));
1003 // XXX  if (0 == sbutton(to, 0, sizeof(to) - 1, "To: "))
1004 //              return;
1005         
1006         if (STREQ(to, from))
1007                 return;
1008         
1009         SEQP_BEGIN (ed, seq)
1010         {
1011                 if (seq->flag & SELECT) {
1012                         if (STREQLEN(seq->strip->dir, from, strlen(from))) {
1013                                 printf("found %s\n", seq->strip->dir);
1014                                 
1015                                 /* strip off the beginning */
1016                                 stripped[0] = 0;
1017                                 BLI_strncpy(stripped, seq->strip->dir + strlen(from), FILE_MAX);
1018                                 
1019                                 /* new path */
1020                                 BLI_snprintf(seq->strip->dir, sizeof(seq->strip->dir), "%s%s", to, stripped);
1021                                 printf("new %s\n", seq->strip->dir);
1022                         }
1023                 }
1024         }
1025         SEQ_END
1026                 
1027 }
1028
1029
1030 static int sequencer_gap_remove_exec(bContext *C, wmOperator *op)
1031 {
1032         Scene *scene = CTX_data_scene(C);
1033         rctf rectf;
1034         int cfra, efra, sfra;
1035         bool first = false, done;
1036         bool do_all = RNA_boolean_get(op->ptr, "all");
1037
1038         /* get first and last frame */
1039         boundbox_seq(scene, &rectf);
1040         sfra = (int)rectf.xmin;
1041         efra = (int)rectf.xmax;
1042         
1043         /* first check if the current frame has a gap already */
1044         for (cfra = CFRA; cfra >= sfra; cfra--) {
1045                 if (BKE_sequencer_evaluate_frame(scene, cfra)) {
1046                         first = true;
1047                         break;
1048                 }
1049         }
1050
1051         for ( ; cfra < efra; cfra++) {
1052                 /* first == 0 means there's still no strip to remove a gap for */
1053                 if (first == false) {
1054                         if (BKE_sequencer_evaluate_frame(scene, cfra) ) first = true;
1055                 }
1056                 else if (BKE_sequencer_evaluate_frame(scene, cfra) == 0) {
1057                         done = true;
1058                         while (BKE_sequencer_evaluate_frame(scene, cfra) == 0) {
1059                                 done = sequence_offset_after_frame(scene, -1, cfra);
1060                                 if (done == false) break;
1061                         }
1062                         if (done == false || do_all == false) break;
1063                 }
1064         }
1065
1066         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1067         
1068         return OPERATOR_FINISHED;
1069
1070 }
1071
1072
1073 void SEQUENCER_OT_gap_remove(struct wmOperatorType *ot)
1074 {
1075         /* identifiers */
1076         ot->name = "Remove Gaps";
1077         ot->idname = "SEQUENCER_OT_gap_remove";
1078         ot->description = "Remove gap at current frame to first strip at the right, independent of selection or locked state of strips";
1079         
1080         /* api callbacks */
1081 //      ot->invoke = sequencer_snap_invoke;
1082         ot->exec = sequencer_gap_remove_exec;
1083         ot->poll = sequencer_edit_poll;
1084         
1085         /* flags */
1086         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1087         
1088         RNA_def_boolean(ot->srna, "all", 0, "All Gaps", "Do all gaps to right of current frame");
1089 }
1090
1091 static int sequencer_gap_insert_exec(bContext *C, wmOperator *op)
1092 {
1093         Scene *scene = CTX_data_scene(C);
1094         int frames = RNA_int_get(op->ptr, "frames");
1095         
1096         sequence_offset_after_frame(scene, frames, CFRA);
1097         
1098         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1099         
1100         return OPERATOR_FINISHED;
1101         
1102 }
1103
1104 void SEQUENCER_OT_gap_insert(struct wmOperatorType *ot)
1105 {
1106         /* identifiers */
1107         ot->name = "Insert Gaps";
1108         ot->idname = "SEQUENCER_OT_gap_insert";
1109         ot->description = "Insert gap at current frame to first strips at the right, independent of selection or locked state of strips";
1110         
1111         /* api callbacks */
1112         //      ot->invoke = sequencer_snap_invoke;
1113         ot->exec = sequencer_gap_insert_exec;
1114         ot->poll = sequencer_edit_poll;
1115         
1116         /* flags */
1117         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1118         
1119         RNA_def_int(ot->srna, "frames", 10, 0, INT_MAX, "Frames", "Frames to insert after current strip", 0, 1000);
1120 }
1121
1122
1123 #if 0
1124 static int seq_get_snaplimit(View2D *v2d)
1125 {
1126         /* fake mouse coords to get the snap value
1127          * a bit lazy but its only done once pre transform */
1128         float xmouse, ymouse, x;
1129         int mval[2] = {24, 0}; /* 24 screen px snap */
1130         
1131         UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1132         x = xmouse;
1133         mval[0] = 0;
1134         UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse);
1135         return (int)(x - xmouse);
1136 }
1137 #endif
1138
1139 /* Operator functions */
1140 int sequencer_edit_poll(bContext *C)
1141 {
1142         return (BKE_sequencer_editing_get(CTX_data_scene(C), false) != NULL);
1143 }
1144
1145 #if 0 /* UNUSED */
1146 int sequencer_strip_poll(bContext *C)
1147 {
1148         Editing *ed;
1149         return (((ed = BKE_sequencer_editing_get(CTX_data_scene(C), false)) != NULL) && (ed->act_seq != NULL));
1150 }
1151 #endif
1152
1153 int sequencer_strip_has_path_poll(bContext *C)
1154 {
1155         Editing *ed;
1156         Sequence *seq;
1157         return (((ed = BKE_sequencer_editing_get(CTX_data_scene(C), false)) != NULL) && ((seq = ed->act_seq) != NULL) && (SEQ_HAS_PATH(seq)));
1158 }
1159
1160 int sequencer_view_preview_poll(bContext *C)
1161 {
1162         SpaceSeq *sseq = CTX_wm_space_seq(C);
1163         Editing *ed = BKE_sequencer_editing_get(CTX_data_scene(C), false);
1164         if (ed && sseq && (sseq->mainb == SEQ_DRAW_IMG_IMBUF))
1165                 return 1;
1166
1167         return 0;
1168 }
1169
1170 int sequencer_view_strips_poll(bContext *C)
1171 {
1172         SpaceSeq *sseq = CTX_wm_space_seq(C);
1173         if (sseq && ED_space_sequencer_check_show_strip(sseq))
1174                 return 1;
1175
1176         return 0;
1177 }
1178
1179 /* snap operator*/
1180 static int sequencer_snap_exec(bContext *C, wmOperator *op)
1181 {
1182         Scene *scene = CTX_data_scene(C);
1183         
1184         Editing *ed = BKE_sequencer_editing_get(scene, false);
1185         Sequence *seq;
1186         int snap_frame;
1187
1188         snap_frame = RNA_int_get(op->ptr, "frame");
1189
1190         /* also check metas */
1191         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1192                 if (seq->flag & SELECT && !(seq->depth == 0 && seq->flag & SEQ_LOCK) &&
1193                     BKE_sequence_tx_test(seq))
1194                 {
1195                         if ((seq->flag & (SEQ_LEFTSEL + SEQ_RIGHTSEL)) == 0) {
1196                                 /* simple but no anim update */
1197                                 /* seq->start = snap_frame-seq->startofs+seq->startstill; */
1198
1199                                 BKE_sequence_translate(scene, seq, (snap_frame - seq->startofs + seq->startstill) - seq->start);
1200                         }
1201                         else {
1202                                 if (seq->flag & SEQ_LEFTSEL) {
1203                                         BKE_sequence_tx_set_final_left(seq, snap_frame);
1204                                 }
1205                                 else { /* SEQ_RIGHTSEL */
1206                                         BKE_sequence_tx_set_final_right(seq, snap_frame);
1207                                 }
1208                                 BKE_sequence_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL);
1209                         }
1210                         BKE_sequence_calc(scene, seq);
1211                 }
1212         }
1213
1214         /* test for effects and overlap
1215          * don't use SEQP_BEGIN since that would be recursive */
1216         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1217                 if (seq->flag & SELECT && !(seq->depth == 0 && seq->flag & SEQ_LOCK)) {
1218                         seq->flag &= ~SEQ_OVERLAP;
1219                         if (BKE_sequence_test_overlap(ed->seqbasep, seq) ) {
1220                                 BKE_sequence_base_shuffle(ed->seqbasep, seq, scene);
1221                         }
1222                 }
1223                 else if (seq->type & SEQ_TYPE_EFFECT) {
1224                         if (seq->seq1 && (seq->seq1->flag & SELECT)) 
1225                                 BKE_sequence_calc(scene, seq);
1226                         else if (seq->seq2 && (seq->seq2->flag & SELECT)) 
1227                                 BKE_sequence_calc(scene, seq);
1228                         else if (seq->seq3 && (seq->seq3->flag & SELECT)) 
1229                                 BKE_sequence_calc(scene, seq);
1230                 }
1231         }
1232
1233         /* as last: */
1234         BKE_sequencer_sort(scene);
1235         
1236         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1237         
1238         return OPERATOR_FINISHED;
1239 }
1240
1241 static int sequencer_snap_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
1242 {
1243         Scene *scene = CTX_data_scene(C);
1244         
1245         int snap_frame;
1246         
1247         snap_frame = CFRA;
1248         
1249         RNA_int_set(op->ptr, "frame", snap_frame);
1250         return sequencer_snap_exec(C, op);
1251 }
1252
1253 void SEQUENCER_OT_snap(struct wmOperatorType *ot)
1254 {
1255         /* identifiers */
1256         ot->name = "Snap Strips";
1257         ot->idname = "SEQUENCER_OT_snap";
1258         ot->description = "Frame where selected strips will be snapped";
1259         
1260         /* api callbacks */
1261         ot->invoke = sequencer_snap_invoke;
1262         ot->exec = sequencer_snap_exec;
1263         ot->poll = sequencer_edit_poll;
1264         
1265         /* flags */
1266         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1267         
1268         RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be snapped", INT_MIN, INT_MAX);
1269 }
1270
1271 typedef struct SlipData {
1272         int init_mouse[2];
1273         float init_mouseloc[2];
1274         TransSeq *ts;
1275         Sequence **seq_array;
1276         bool *trim;
1277         int num_seq;
1278         bool slow;
1279         int slow_offset; /* offset at the point where offset was turned on */
1280         void *draw_handle;
1281         NumInput num_input;
1282 } SlipData;
1283
1284 static void transseq_backup(TransSeq *ts, Sequence *seq)
1285 {
1286         ts->start = seq->start;
1287         ts->machine = seq->machine;
1288         ts->startstill = seq->startstill;
1289         ts->endstill = seq->endstill;
1290         ts->startdisp = seq->startdisp;
1291         ts->enddisp = seq->enddisp;
1292         ts->startofs = seq->startofs;
1293         ts->endofs = seq->endofs;
1294         ts->anim_startofs = seq->anim_startofs;
1295         ts->anim_endofs = seq->anim_endofs;
1296         ts->len = seq->len;
1297 }
1298
1299
1300 static void transseq_restore(TransSeq *ts, Sequence *seq)
1301 {
1302         seq->start = ts->start;
1303         seq->machine = ts->machine;
1304         seq->startstill = ts->startstill;
1305         seq->endstill = ts->endstill;
1306         seq->startdisp = ts->startdisp;
1307         seq->enddisp = ts->enddisp;
1308         seq->startofs = ts->startofs;
1309         seq->endofs = ts->endofs;
1310         seq->anim_startofs = ts->anim_startofs;
1311         seq->anim_endofs = ts->anim_endofs;
1312         seq->len = ts->len;
1313 }
1314
1315 static void draw_slip_extensions(const bContext *C, ARegion *ar, void *data)
1316 {
1317         Scene *scene = CTX_data_scene(C);
1318         SlipData *td = data;
1319         int i;
1320
1321         for (i = 0; i < td->num_seq; i++) {
1322                 Sequence *seq = td->seq_array[i];
1323
1324                 if ((seq->type != SEQ_TYPE_META) && td->trim[i]) {
1325                         draw_sequence_extensions(scene, ar, seq);
1326                 }
1327         }
1328 }
1329
1330 static int slip_add_sequences_rec(ListBase *seqbasep, Sequence **seq_array, bool *trim, int offset, bool do_trim)
1331 {
1332         Sequence *seq;
1333         int num_items = 0;
1334
1335         for (seq = seqbasep->first; seq; seq = seq->next) {
1336                 if (!do_trim || (!(seq->type & SEQ_TYPE_EFFECT) && (seq->flag & SELECT))) {
1337                         seq_array[offset + num_items] = seq;
1338                         trim[offset + num_items] = do_trim;
1339                         num_items++;
1340
1341                         if (seq->type == SEQ_TYPE_META) {
1342                                 /* trim the sub-sequences */
1343                                 num_items += slip_add_sequences_rec(&seq->seqbase, seq_array, trim, num_items + offset, false);
1344                         }
1345                         else if (seq->type & SEQ_TYPE_EFFECT) {
1346                                 trim[offset + num_items] = false;
1347                         }
1348                 }
1349         }
1350
1351         return num_items;
1352 }
1353
1354 static int slip_count_sequences_rec(ListBase *seqbasep, bool first_level)
1355 {
1356         Sequence *seq;
1357         int trimmed_sequences = 0;
1358
1359         for (seq = seqbasep->first; seq; seq = seq->next) {
1360                 if (!first_level || (!(seq->type & SEQ_TYPE_EFFECT) && (seq->flag & SELECT))) {
1361                         trimmed_sequences++;
1362
1363                         if (seq->type == SEQ_TYPE_META) {
1364                                 /* trim the sub-sequences */
1365                                 trimmed_sequences += slip_count_sequences_rec(&seq->seqbase, false);
1366                         }
1367                 }
1368         }
1369
1370         return trimmed_sequences;
1371 }
1372
1373 static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1374 {
1375         SlipData *data;
1376         Scene *scene = CTX_data_scene(C);
1377         Editing *ed = BKE_sequencer_editing_get(scene, false);
1378         ARegion *ar = CTX_wm_region(C);
1379         float mouseloc[2];
1380         int num_seq, i;
1381         View2D *v2d = UI_view2d_fromcontext(C);
1382
1383         /* first recursively cound the trimmed elements */
1384         num_seq = slip_count_sequences_rec(ed->seqbasep, true);
1385
1386         if (num_seq == 0)
1387                 return OPERATOR_CANCELLED;
1388
1389         data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata");
1390         data->ts = MEM_mallocN(num_seq * sizeof(TransSeq), "trimdata_transform");
1391         data->seq_array = MEM_mallocN(num_seq * sizeof(Sequence *), "trimdata_sequences");
1392         data->trim = MEM_mallocN(num_seq * sizeof(bool), "trimdata_trim");
1393         data->num_seq = num_seq;
1394
1395         initNumInput(&data->num_input);
1396         data->num_input.idx_max = 0;
1397         data->num_input.val_flag[0] |= NUM_NO_FRACTION;
1398         data->num_input.unit_sys = USER_UNIT_NONE;
1399         data->num_input.unit_type[0] = 0;
1400
1401
1402         slip_add_sequences_rec(ed->seqbasep, data->seq_array, data->trim, 0, true);
1403
1404         for (i = 0; i < num_seq; i++) {
1405                 transseq_backup(data->ts + i, data->seq_array[i]);
1406         }
1407
1408         data->draw_handle = ED_region_draw_cb_activate(ar->type, draw_slip_extensions, data, REGION_DRAW_POST_VIEW);
1409
1410         UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &mouseloc[0], &mouseloc[1]);
1411
1412         copy_v2_v2_int(data->init_mouse, event->mval);
1413         copy_v2_v2(data->init_mouseloc, mouseloc);
1414
1415         data->slow = false;
1416
1417         WM_event_add_modal_handler(C, op);
1418
1419         /* notify so we draw extensions immediately */
1420         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1421
1422         return OPERATOR_RUNNING_MODAL;
1423 }
1424
1425 static bool sequencer_slip_recursively(Scene *scene, SlipData *data, int offset)
1426 {
1427
1428         /* only data types supported for now */
1429         if (offset != 0) {
1430                 Editing *ed = BKE_sequencer_editing_get(scene, false);
1431                 int i;
1432
1433                 /* we iterate in reverse so metastrips are iterated after their children */
1434                 for (i = data->num_seq - 1; i >= 0; i--) {
1435                         Sequence *seq = data->seq_array[i];
1436                         int endframe;
1437                         /* we have the offset, do the terrible math */
1438
1439                         /* first, do the offset */
1440                         seq->start = data->ts[i].start + offset;
1441
1442                         if (data->trim[i]) {
1443                                 /* find the endframe */
1444                                 endframe = seq->start + seq->len;
1445
1446                                 /* now compute the terrible offsets */
1447                                 if (endframe > seq->enddisp) {
1448                                         seq->endstill = 0;
1449                                         seq->endofs = endframe - seq->enddisp;
1450                                 }
1451                                 else if (endframe <= seq->enddisp) {
1452                                         seq->endstill = seq->enddisp - endframe;
1453                                         seq->endofs = 0;
1454                                 }
1455
1456                                 if (seq->start > seq->startdisp) {
1457                                         seq->startstill = seq->start - seq->startdisp;
1458                                         seq->startofs = 0;
1459                                 }
1460                                 else if (seq->start <= seq->startdisp) {
1461                                         seq->startstill = 0;
1462                                         seq->startofs = seq->startdisp - seq->start;
1463                                 }
1464                         }
1465                         else {
1466                                 /* if no real trim, don't change the data, rather transform the strips themselves */
1467                                 seq->startdisp = data->ts[i].startdisp + offset;
1468                                 seq->enddisp = data->ts[i].enddisp + offset;
1469                         }
1470
1471                         /* effects are only added if we they are in a metastrip. In this case, dependent strips will just be transformed and we can skip calculating for effects
1472                          * This way we can avoid an extra loop just for effects*/
1473                         if (!(seq->type & SEQ_TYPE_EFFECT))
1474                                 BKE_sequence_calc(scene, seq);
1475                 }
1476                 BKE_sequencer_free_imbuf(scene, &ed->seqbase, false);
1477
1478                 return true;
1479         }
1480
1481         return false;
1482 }
1483
1484 static int sequencer_slip_exec(bContext *C, wmOperator *op)
1485 {
1486         SlipData *data;
1487         Scene *scene = CTX_data_scene(C);
1488         Editing *ed = BKE_sequencer_editing_get(scene, false);
1489         int num_seq, i;
1490         int offset = RNA_int_get(op->ptr, "offset");
1491         bool success = false;
1492
1493         /* first recursively cound the trimmed elements */
1494         num_seq = slip_count_sequences_rec(ed->seqbasep, true);
1495
1496         if (num_seq == 0)
1497                 return OPERATOR_CANCELLED;
1498
1499         data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata");
1500         data->ts = MEM_mallocN(num_seq * sizeof(TransSeq), "trimdata_transform");
1501         data->seq_array = MEM_mallocN(num_seq * sizeof(Sequence *), "trimdata_sequences");
1502         data->trim = MEM_mallocN(num_seq * sizeof(bool), "trimdata_trim");
1503         data->num_seq = num_seq;
1504
1505         slip_add_sequences_rec(ed->seqbasep, data->seq_array, data->trim, 0, true);
1506
1507         for (i = 0; i < num_seq; i++) {
1508                 transseq_backup(data->ts + i, data->seq_array[i]);
1509         }
1510
1511         success = sequencer_slip_recursively(scene, data, offset);
1512
1513         MEM_freeN(data->seq_array);
1514         MEM_freeN(data->trim);
1515         MEM_freeN(data->ts);
1516         MEM_freeN(data);
1517
1518         if (success) {
1519                 WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1520                 return OPERATOR_FINISHED;
1521         }
1522         else {
1523                 return OPERATOR_CANCELLED;
1524         }
1525 }
1526
1527
1528 static void sequencer_slip_update_header(Scene *scene, ScrArea *sa, SlipData *data, int offset)
1529 {
1530 #define HEADER_LENGTH 40
1531         char msg[HEADER_LENGTH];
1532
1533         if (sa) {
1534                 if (hasNumInput(&data->num_input)) {
1535                         char num_str[NUM_STR_REP_LEN];
1536                         outputNumInput(&data->num_input, num_str, &scene->unit);
1537                         BLI_snprintf(msg, HEADER_LENGTH, "Trim offset: %s", num_str);
1538                 }
1539                 else {
1540                         BLI_snprintf(msg, HEADER_LENGTH, "Trim offset: %d", offset);
1541                 }
1542         }
1543
1544         ED_area_headerprint(sa, msg);
1545
1546 #undef HEADER_LENGTH
1547 }
1548
1549 static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *event)
1550 {
1551         Scene *scene = CTX_data_scene(C);
1552         SlipData *data = (SlipData *)op->customdata;
1553         ScrArea *sa = CTX_wm_area(C);
1554         ARegion *ar = CTX_wm_region(C);
1555         const bool has_numInput = hasNumInput(&data->num_input);
1556         bool handled = true;
1557
1558         /* Modal numinput active, try to handle numeric inputs first... */
1559         if (event->val == KM_PRESS && has_numInput && handleNumInput(C, &data->num_input, event)) {
1560                 float offset;
1561                 applyNumInput(&data->num_input, &offset);
1562
1563                 sequencer_slip_update_header(scene, sa, data, (int)offset);
1564
1565                 RNA_int_set(op->ptr, "offset", offset);
1566
1567                 if (sequencer_slip_recursively(scene, data, offset)) {
1568                         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1569                 }
1570
1571                 return OPERATOR_RUNNING_MODAL;
1572         }
1573
1574         switch (event->type) {
1575                 case MOUSEMOVE:
1576                 {
1577                         if (!has_numInput) {
1578                                 float mouseloc[2];
1579                                 int offset;
1580                                 int mouse_x;
1581                                 View2D *v2d = UI_view2d_fromcontext(C);
1582
1583                                 if (data->slow) {
1584                                         mouse_x = event->mval[0] - data->slow_offset;
1585                                         mouse_x *= 0.1f;
1586                                         mouse_x += data->slow_offset;
1587                                 }
1588                                 else {
1589                                         mouse_x = event->mval[0];
1590                                 }
1591
1592
1593                                 /* choose the side based on which side of the playhead the mouse is on */
1594                                 UI_view2d_region_to_view(v2d, mouse_x, 0, &mouseloc[0], &mouseloc[1]);
1595                                 offset = mouseloc[0] - data->init_mouseloc[0];
1596
1597                                 sequencer_slip_update_header(scene, sa, data, offset);
1598
1599                                 RNA_int_set(op->ptr, "offset", offset);
1600
1601                                 if (sequencer_slip_recursively(scene, data, offset)) {
1602                                         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1603                                 }
1604                         }
1605                         break;
1606                 }
1607
1608                 case LEFTMOUSE:
1609                 case RETKEY:
1610                 case SPACEKEY:
1611                 {
1612                         ED_region_draw_cb_exit(ar->type, data->draw_handle);
1613                         MEM_freeN(data->seq_array);
1614                         MEM_freeN(data->trim);
1615                         MEM_freeN(data->ts);
1616                         MEM_freeN(data);
1617                         op->customdata = NULL;
1618                         if (sa) {
1619                                 ED_area_headerprint(sa, NULL);
1620                         }
1621                         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1622                         return OPERATOR_FINISHED;
1623                 }
1624
1625                 case ESCKEY:
1626                 case RIGHTMOUSE:
1627                 {
1628                         int i;
1629                         Editing *ed = BKE_sequencer_editing_get(scene, false);
1630
1631                         for (i = 0; i < data->num_seq; i++) {
1632                                 transseq_restore(data->ts + i, data->seq_array[i]);
1633                         }
1634
1635                         for (i = 0; i < data->num_seq; i++) {
1636                                 Sequence *seq = data->seq_array[i];
1637                                 BKE_sequence_reload_new_file(scene, seq, false);
1638                                 BKE_sequence_calc(scene, seq);
1639                         }
1640
1641                         ED_region_draw_cb_exit(ar->type, data->draw_handle);
1642
1643                         MEM_freeN(data->seq_array);
1644                         MEM_freeN(data->ts);
1645                         MEM_freeN(data->trim);
1646                         MEM_freeN(data);
1647                         op->customdata = NULL;
1648
1649                         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1650
1651                         BKE_sequencer_free_imbuf(scene, &ed->seqbase, false);
1652
1653                         if (sa) {
1654                                 ED_area_headerprint(sa, NULL);
1655                         }
1656
1657                         return OPERATOR_CANCELLED;
1658                 }
1659
1660                 case RIGHTSHIFTKEY:
1661                 case LEFTSHIFTKEY:
1662                         if (!has_numInput) {
1663                                 if (event->val == KM_PRESS) {
1664                                         data->slow = true;
1665                                         data->slow_offset = event->mval[0];
1666                                 }
1667                                 else if (event->val == KM_RELEASE) {
1668                                         data->slow = false;
1669                                 }
1670                         }
1671                         break;
1672
1673                 default:
1674                         handled = false;
1675                         break;
1676         }
1677
1678         /* Modal numinput inactive, try to handle numeric inputs last... */
1679         if (!handled && event->val == KM_PRESS && handleNumInput(C, &data->num_input, event)) {
1680                 float offset;
1681                 applyNumInput(&data->num_input, &offset);
1682
1683                 sequencer_slip_update_header(scene, sa, data, (int)offset);
1684
1685                 RNA_int_set(op->ptr, "offset", offset);
1686
1687                 if (sequencer_slip_recursively(scene, data, offset)) {
1688                         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1689                 }
1690         }
1691
1692         return OPERATOR_RUNNING_MODAL;
1693 }
1694
1695 void SEQUENCER_OT_slip(struct wmOperatorType *ot)
1696 {
1697         /* identifiers */
1698         ot->name = "Trim Strips";
1699         ot->idname = "SEQUENCER_OT_slip";
1700         ot->description = "Trim the contents of the active strip";
1701
1702         /* api callbacks */
1703         ot->invoke = sequencer_slip_invoke;
1704         ot->modal = sequencer_slip_modal;
1705         ot->exec = sequencer_slip_exec;
1706         ot->poll = sequencer_edit_poll;
1707
1708         /* flags */
1709         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1710
1711         RNA_def_int(ot->srna, "offset", 0, INT32_MIN, INT32_MAX, "Offset", "Offset to the data of the strip",
1712                     INT32_MIN, INT32_MAX);
1713 }
1714
1715 /* mute operator */
1716 static int sequencer_mute_exec(bContext *C, wmOperator *op)
1717 {
1718         Scene *scene = CTX_data_scene(C);
1719         Editing *ed = BKE_sequencer_editing_get(scene, false);
1720         Sequence *seq;
1721         bool selected;
1722
1723         selected = !RNA_boolean_get(op->ptr, "unselected");
1724         
1725         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1726                 if ((seq->flag & SEQ_LOCK) == 0) {
1727                         if (selected) { /* mute unselected */
1728                                 if (seq->flag & SELECT) {
1729                                         seq->flag |= SEQ_MUTE;
1730                                         BKE_sequence_invalidate_dependent(scene, seq);
1731                                 }
1732                         }
1733                         else {
1734                                 if ((seq->flag & SELECT) == 0) {
1735                                         seq->flag |= SEQ_MUTE;
1736                                         BKE_sequence_invalidate_dependent(scene, seq);
1737                                 }
1738                         }
1739                 }
1740         }
1741         
1742         BKE_sequencer_update_muting(ed);
1743         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1744         
1745         return OPERATOR_FINISHED;
1746 }
1747
1748 void SEQUENCER_OT_mute(struct wmOperatorType *ot)
1749 {
1750         /* identifiers */
1751         ot->name = "Mute Strips";
1752         ot->idname = "SEQUENCER_OT_mute";
1753         ot->description = "Mute (un)selected strips";
1754         
1755         /* api callbacks */
1756         ot->exec = sequencer_mute_exec;
1757         ot->poll = sequencer_edit_poll;
1758         
1759         /* flags */
1760         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1761         
1762         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Mute unselected rather than selected strips");
1763 }
1764
1765
1766 /* unmute operator */
1767 static int sequencer_unmute_exec(bContext *C, wmOperator *op)
1768 {
1769         Scene *scene = CTX_data_scene(C);
1770         Editing *ed = BKE_sequencer_editing_get(scene, false);
1771         Sequence *seq;
1772         bool selected;
1773
1774         selected = !RNA_boolean_get(op->ptr, "unselected");
1775         
1776         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1777                 if ((seq->flag & SEQ_LOCK) == 0) {
1778                         if (selected) { /* unmute unselected */
1779                                 if (seq->flag & SELECT) {
1780                                         seq->flag &= ~SEQ_MUTE;
1781                                         BKE_sequence_invalidate_dependent(scene, seq);
1782                                 }
1783                         }
1784                         else {
1785                                 if ((seq->flag & SELECT) == 0) {
1786                                         seq->flag &= ~SEQ_MUTE;
1787                                         BKE_sequence_invalidate_dependent(scene, seq);
1788                                 }
1789                         }
1790                 }
1791         }
1792         
1793         BKE_sequencer_update_muting(ed);
1794         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1795         
1796         return OPERATOR_FINISHED;
1797 }
1798
1799 void SEQUENCER_OT_unmute(struct wmOperatorType *ot)
1800 {
1801         /* identifiers */
1802         ot->name = "Un-Mute Strips";
1803         ot->idname = "SEQUENCER_OT_unmute";
1804         ot->description = "Unmute (un)selected strips";
1805         
1806         /* api callbacks */
1807         ot->exec = sequencer_unmute_exec;
1808         ot->poll = sequencer_edit_poll;
1809         
1810         /* flags */
1811         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1812         
1813         RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Unmute unselected rather than selected strips");
1814 }
1815
1816
1817 /* lock operator */
1818 static int sequencer_lock_exec(bContext *C, wmOperator *UNUSED(op))
1819 {
1820         Scene *scene = CTX_data_scene(C);
1821         Editing *ed = BKE_sequencer_editing_get(scene, false);
1822         Sequence *seq;
1823
1824         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1825                 if (seq->flag & SELECT) {
1826                         seq->flag |= SEQ_LOCK;
1827                 }
1828         }
1829
1830         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1831
1832         return OPERATOR_FINISHED;
1833 }
1834
1835 void SEQUENCER_OT_lock(struct wmOperatorType *ot)
1836 {
1837         /* identifiers */
1838         ot->name = "Lock Strips";
1839         ot->idname = "SEQUENCER_OT_lock";
1840         ot->description = "Lock the active strip so that it can't be transformed";
1841         
1842         /* api callbacks */
1843         ot->exec = sequencer_lock_exec;
1844         ot->poll = sequencer_edit_poll;
1845         
1846         /* flags */
1847         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1848 }
1849
1850 /* unlock operator */
1851 static int sequencer_unlock_exec(bContext *C, wmOperator *UNUSED(op))
1852 {
1853         Scene *scene = CTX_data_scene(C);
1854         Editing *ed = BKE_sequencer_editing_get(scene, false);
1855         Sequence *seq;
1856
1857         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1858                 if (seq->flag & SELECT) {
1859                         seq->flag &= ~SEQ_LOCK;
1860                 }
1861         }
1862
1863         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1864
1865         return OPERATOR_FINISHED;
1866 }
1867
1868 void SEQUENCER_OT_unlock(struct wmOperatorType *ot)
1869 {
1870         /* identifiers */
1871         ot->name = "UnLock Strips";
1872         ot->idname = "SEQUENCER_OT_unlock";
1873         ot->description = "Unlock the active strip so that it can't be transformed";
1874         
1875         /* api callbacks */
1876         ot->exec = sequencer_unlock_exec;
1877         ot->poll = sequencer_edit_poll;
1878         
1879         /* flags */
1880         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1881 }
1882
1883 /* reload operator */
1884 static int sequencer_reload_exec(bContext *C, wmOperator *op)
1885 {
1886         Scene *scene = CTX_data_scene(C);
1887         Editing *ed = BKE_sequencer_editing_get(scene, false);
1888         Sequence *seq;
1889         const bool adjust_length = RNA_boolean_get(op->ptr, "adjust_length");
1890
1891         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
1892                 if (seq->flag & SELECT) {
1893                         BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1);
1894                         BKE_sequence_reload_new_file(scene, seq, !adjust_length);
1895
1896                         if (adjust_length) {
1897                                 if (BKE_sequence_test_overlap(ed->seqbasep, seq))
1898                                         BKE_sequence_base_shuffle(ed->seqbasep, seq, scene);
1899                         }
1900                 }
1901         }
1902
1903         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1904
1905         return OPERATOR_FINISHED;
1906 }
1907
1908 void SEQUENCER_OT_reload(struct wmOperatorType *ot)
1909 {
1910         PropertyRNA *prop;
1911
1912         /* identifiers */
1913         ot->name = "Reload Strips";
1914         ot->idname = "SEQUENCER_OT_reload";
1915         ot->description = "Reload strips in the sequencer";
1916         
1917         /* api callbacks */
1918         ot->exec = sequencer_reload_exec;
1919         ot->poll = sequencer_edit_poll;
1920         
1921         /* flags */
1922         ot->flag = OPTYPE_REGISTER; /* no undo, the data changed is stored outside 'main' */
1923
1924         prop = RNA_def_boolean(ot->srna, "adjust_length", 0, "Adjust Length",
1925                                "Adjust length of strips to their data length");
1926         RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1927 }
1928
1929 /* reload operator */
1930 static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op))
1931 {
1932         Scene *scene = CTX_data_scene(C);
1933         Editing *ed = BKE_sequencer_editing_get(scene, false);
1934
1935         BKE_sequencer_free_imbuf(scene, &ed->seqbase, false);
1936
1937         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1938
1939         return OPERATOR_FINISHED;
1940 }
1941
1942 void SEQUENCER_OT_refresh_all(struct wmOperatorType *ot)
1943 {
1944         /* identifiers */
1945         ot->name = "Refresh Sequencer";
1946         ot->idname = "SEQUENCER_OT_refresh_all";
1947         ot->description = "Refresh the sequencer editor";
1948         
1949         /* api callbacks */
1950         ot->exec = sequencer_refresh_all_exec;
1951         ot->poll = sequencer_edit_poll;
1952 }
1953
1954 static int sequencer_reassign_inputs_exec(bContext *C, wmOperator *op)
1955 {
1956         Scene *scene = CTX_data_scene(C);
1957         Sequence *seq1, *seq2, *seq3, *last_seq = BKE_sequencer_active_get(scene);
1958         const char *error_msg;
1959
1960         if (!seq_effect_find_selected(scene, last_seq, last_seq->type, &seq1, &seq2, &seq3, &error_msg)) {
1961                 BKE_report(op->reports, RPT_ERROR, error_msg);
1962                 return OPERATOR_CANCELLED;
1963         }
1964         /* see reassigning would create a cycle */
1965         if (seq_is_predecessor(seq1, last_seq) ||
1966             seq_is_predecessor(seq2, last_seq) ||
1967             seq_is_predecessor(seq3, last_seq))
1968         {
1969                 BKE_report(op->reports, RPT_ERROR, "Cannot reassign inputs: no cycles allowed");
1970                 return OPERATOR_CANCELLED;
1971         }
1972
1973         last_seq->seq1 = seq1;
1974         last_seq->seq2 = seq2;
1975         last_seq->seq3 = seq3;
1976
1977         BKE_sequencer_update_changed_seq_and_deps(scene, last_seq, 1, 1);
1978
1979         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
1980
1981         return OPERATOR_FINISHED;
1982 }
1983
1984 static int sequencer_effect_poll(bContext *C)
1985 {
1986         Scene *scene = CTX_data_scene(C);
1987         Editing *ed = BKE_sequencer_editing_get(scene, false);
1988
1989         if (ed) {
1990                 Sequence *last_seq = BKE_sequencer_active_get(scene);
1991                 if (last_seq && (last_seq->type & SEQ_TYPE_EFFECT)) {
1992                         return 1;
1993                 }
1994         }
1995
1996         return 0;
1997 }
1998
1999 void SEQUENCER_OT_reassign_inputs(struct wmOperatorType *ot)
2000 {
2001         /* identifiers */
2002         ot->name = "Reassign Inputs";
2003         ot->idname = "SEQUENCER_OT_reassign_inputs";
2004         ot->description = "Reassign the inputs for the effect strip";
2005
2006         /* api callbacks */
2007         ot->exec = sequencer_reassign_inputs_exec;
2008         ot->poll = sequencer_effect_poll;
2009
2010         /* flags */
2011         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2012 }
2013
2014
2015 static int sequencer_swap_inputs_exec(bContext *C, wmOperator *op)
2016 {
2017         Scene *scene = CTX_data_scene(C);
2018         Sequence *seq, *last_seq = BKE_sequencer_active_get(scene);
2019
2020         if (last_seq->seq1 == NULL || last_seq->seq2 == NULL) {
2021                 BKE_report(op->reports, RPT_ERROR, "No valid inputs to swap");
2022                 return OPERATOR_CANCELLED;
2023         }
2024
2025         seq = last_seq->seq1;
2026         last_seq->seq1 = last_seq->seq2;
2027         last_seq->seq2 = seq;
2028
2029         BKE_sequencer_update_changed_seq_and_deps(scene, last_seq, 1, 1);
2030
2031         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2032
2033         return OPERATOR_FINISHED;
2034 }
2035 void SEQUENCER_OT_swap_inputs(struct wmOperatorType *ot)
2036 {
2037         /* identifiers */
2038         ot->name = "Swap Inputs";
2039         ot->idname = "SEQUENCER_OT_swap_inputs";
2040         ot->description = "Swap the first two inputs for the effect strip";
2041
2042         /* api callbacks */
2043         ot->exec = sequencer_swap_inputs_exec;
2044         ot->poll = sequencer_effect_poll;
2045
2046         /* flags */
2047         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2048 }
2049
2050
2051 /* cut operator */
2052 static EnumPropertyItem prop_cut_types[] = {
2053         {SEQ_CUT_SOFT, "SOFT", 0, "Soft", ""},
2054         {SEQ_CUT_HARD, "HARD", 0, "Hard", ""},
2055         {0, NULL, 0, NULL, NULL}
2056 };
2057
2058 static int sequencer_cut_exec(bContext *C, wmOperator *op)
2059 {
2060         Scene *scene = CTX_data_scene(C);
2061         Editing *ed = BKE_sequencer_editing_get(scene, false);
2062         int cut_side, cut_hard, cut_frame;
2063
2064         bool changed;
2065
2066         cut_frame = RNA_int_get(op->ptr, "frame");
2067         cut_hard = RNA_enum_get(op->ptr, "type");
2068         cut_side = RNA_enum_get(op->ptr, "side");
2069         
2070         if (cut_hard == SEQ_CUT_HARD) {
2071                 changed = cut_seq_list(scene, ed->seqbasep, cut_frame, cut_seq_hard);
2072         }
2073         else {
2074                 changed = cut_seq_list(scene, ed->seqbasep, cut_frame, cut_seq_soft);
2075         }
2076         
2077         if (changed) { /* got new strips ? */
2078                 Sequence *seq;
2079
2080                 if (cut_side != SEQ_SIDE_BOTH) {
2081                         SEQP_BEGIN (ed, seq)
2082                         {
2083                                 if (cut_side == SEQ_SIDE_LEFT) {
2084                                         if (seq->startdisp >= cut_frame) {
2085                                                 seq->flag &= ~SEQ_ALLSEL;
2086                                         }
2087                                 }
2088                                 else {
2089                                         if (seq->enddisp <= cut_frame) {
2090                                                 seq->flag &= ~SEQ_ALLSEL;
2091                                         }
2092                                 }
2093                         }
2094                         SEQ_END;
2095                 }
2096
2097                 SEQP_BEGIN (ed, seq)
2098                 {
2099                         if (seq->seq1 || seq->seq2 || seq->seq3) {
2100                                 BKE_sequence_calc(scene, seq);
2101                         }
2102                 }
2103                 SEQ_END;
2104
2105                 /* as last: */
2106                 BKE_sequencer_sort(scene);
2107         }
2108
2109         if (changed) {
2110                 WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2111                 return OPERATOR_FINISHED;
2112         }
2113         else {
2114                 return OPERATOR_CANCELLED;
2115         }
2116 }
2117
2118
2119 static int sequencer_cut_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2120 {
2121         Scene *scene = CTX_data_scene(C);
2122         View2D *v2d = UI_view2d_fromcontext(C);
2123
2124         int cut_side = SEQ_SIDE_BOTH;
2125         int cut_frame = CFRA;
2126
2127         if (ED_operator_sequencer_active(C) && v2d)
2128                 cut_side = mouse_frame_side(v2d, event->mval[0], cut_frame);
2129         
2130         RNA_int_set(op->ptr, "frame", cut_frame);
2131         RNA_enum_set(op->ptr, "side", cut_side);
2132         /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */
2133
2134         return sequencer_cut_exec(C, op);
2135 }
2136
2137
2138 void SEQUENCER_OT_cut(struct wmOperatorType *ot)
2139 {
2140         /* identifiers */
2141         ot->name = "Cut Strips";
2142         ot->idname = "SEQUENCER_OT_cut";
2143         ot->description = "Cut the selected strips";
2144         
2145         /* api callbacks */
2146         ot->invoke = sequencer_cut_invoke;
2147         ot->exec = sequencer_cut_exec;
2148         ot->poll = sequencer_edit_poll;
2149         
2150         /* flags */
2151         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2152         
2153         RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be cut", INT_MIN, INT_MAX);
2154         RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips");
2155         RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting");
2156 }
2157
2158 /* duplicate operator */
2159 static int apply_unique_name_cb(Sequence *seq, void *arg_pt)
2160 {
2161         Scene *scene = (Scene *)arg_pt;
2162         char name[sizeof(seq->name) - 2];
2163
2164         BLI_strncpy_utf8(name, seq->name + 2, sizeof(name));
2165         BKE_sequence_base_unique_name_recursive(&scene->ed->seqbase, seq);
2166         BKE_sequencer_dupe_animdata(scene, name, seq->name + 2);
2167         return 1;
2168
2169 }
2170
2171 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
2172 {
2173         Scene *scene = CTX_data_scene(C);
2174         Editing *ed = BKE_sequencer_editing_get(scene, false);
2175
2176         ListBase nseqbase = {NULL, NULL};
2177
2178         if (ed == NULL)
2179                 return OPERATOR_CANCELLED;
2180
2181         BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT);
2182
2183         if (nseqbase.first) {
2184                 Sequence *seq = nseqbase.first;
2185                 /* rely on the nseqbase list being added at the end */
2186                 BLI_movelisttolist(ed->seqbasep, &nseqbase);
2187
2188                 for (; seq; seq = seq->next)
2189                         BKE_sequencer_recursive_apply(seq, apply_unique_name_cb, scene);
2190
2191                 WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2192                 return OPERATOR_FINISHED;
2193         }
2194
2195         return OPERATOR_CANCELLED;
2196 }
2197
2198 void SEQUENCER_OT_duplicate(wmOperatorType *ot)
2199 {
2200         /* identifiers */
2201         ot->name = "Duplicate Strips";
2202         ot->idname = "SEQUENCER_OT_duplicate";
2203         ot->description = "Duplicate the selected strips";
2204         
2205         /* api callbacks */
2206         ot->exec = sequencer_add_duplicate_exec;
2207         ot->poll = ED_operator_sequencer_active;
2208         
2209         /* flags */
2210         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2211         
2212         /* to give to transform */
2213         RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
2214 }
2215
2216 /* delete operator */
2217 static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op))
2218 {
2219         Scene *scene = CTX_data_scene(C);
2220         Editing *ed = BKE_sequencer_editing_get(scene, false);
2221         Sequence *seq;
2222         MetaStack *ms;
2223         bool nothingSelected = true;
2224
2225         seq = BKE_sequencer_active_get(scene);
2226         if (seq && seq->flag & SELECT) { /* avoid a loop since this is likely to be selected */
2227                 nothingSelected = false;
2228         }
2229         else {
2230                 for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2231                         if (seq->flag & SELECT) {
2232                                 nothingSelected = false;
2233                                 break;
2234                         }
2235                 }
2236         }
2237
2238         if (nothingSelected)
2239                 return OPERATOR_FINISHED;
2240
2241         /* for effects and modifiers, try to find a replacement input */
2242         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2243                 if (!(seq->flag & SELECT)) {
2244                         if ((seq->type & SEQ_TYPE_EFFECT)) {
2245                                 del_seq_find_replace_recurs(scene, seq);
2246                         }
2247                 }
2248                 else {
2249                         del_seq_clear_modifiers_recurs(scene, seq);
2250                 }
2251         }
2252
2253         /* delete all selected strips */
2254         recurs_del_seq_flag(scene, ed->seqbasep, SELECT, 0);
2255
2256         /* updates lengths etc */
2257         seq = ed->seqbasep->first;
2258         while (seq) {
2259                 BKE_sequence_calc(scene, seq);
2260                 seq = seq->next;
2261         }
2262
2263         /* free parent metas */
2264         ms = ed->metastack.last;
2265         while (ms) {
2266                 BKE_sequence_calc(scene, ms->parseq);
2267                 ms = ms->prev;
2268         }
2269
2270         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2271         
2272         return OPERATOR_FINISHED;
2273 }
2274
2275 static int sequencer_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2276 {
2277         ARegion *ar = CTX_wm_region(C);
2278
2279         if (ar->regiontype == RGN_TYPE_WINDOW) {
2280                 /* bounding box of 30 pixels is used for markers shortcuts,
2281                  * prevent conflict with markers shortcuts here
2282                  */
2283                 if (event->mval[1] <= 30)
2284                         return OPERATOR_PASS_THROUGH;
2285         }
2286
2287         return WM_operator_confirm(C, op, event);
2288 }
2289
2290 void SEQUENCER_OT_delete(wmOperatorType *ot)
2291 {
2292
2293         /* identifiers */
2294         ot->name = "Erase Strips";
2295         ot->idname = "SEQUENCER_OT_delete";
2296         ot->description = "Erase selected strips from the sequencer";
2297         
2298         /* api callbacks */
2299         ot->invoke = sequencer_delete_invoke;
2300         ot->exec = sequencer_delete_exec;
2301         ot->poll = sequencer_edit_poll;
2302         
2303         /* flags */
2304         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2305 }
2306
2307
2308 /* offset clear operator */
2309 static int sequencer_offset_clear_exec(bContext *C, wmOperator *UNUSED(op))
2310 {
2311         Scene *scene = CTX_data_scene(C);
2312         Editing *ed = BKE_sequencer_editing_get(scene, false);
2313         Sequence *seq;
2314
2315         /* for effects, try to find a replacement input */
2316         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2317                 if ((seq->type & SEQ_TYPE_EFFECT) == 0 && (seq->flag & SELECT)) {
2318                         seq->startofs = seq->endofs = seq->startstill = seq->endstill = 0;
2319                 }
2320         }
2321
2322         /* updates lengths etc */
2323         seq = ed->seqbasep->first;
2324         while (seq) {
2325                 BKE_sequence_calc(scene, seq);
2326                 seq = seq->next;
2327         }
2328
2329         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2330                 if ((seq->type & SEQ_TYPE_EFFECT) == 0 && (seq->flag & SELECT)) {
2331                         if (BKE_sequence_test_overlap(ed->seqbasep, seq)) {
2332                                 BKE_sequence_base_shuffle(ed->seqbasep, seq, scene);
2333                         }
2334                 }
2335         }
2336
2337         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2338
2339         return OPERATOR_FINISHED;
2340 }
2341
2342
2343 void SEQUENCER_OT_offset_clear(wmOperatorType *ot)
2344 {
2345
2346         /* identifiers */
2347         ot->name = "Clear Strip Offset";
2348         ot->idname = "SEQUENCER_OT_offset_clear";
2349         ot->description = "Clear strip offsets from the start and end frames";
2350
2351         /* api callbacks */
2352         ot->exec = sequencer_offset_clear_exec;
2353         ot->poll = sequencer_edit_poll;
2354
2355         /* flags */
2356         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2357 }
2358
2359
2360 /* separate_images operator */
2361 static int sequencer_separate_images_exec(bContext *C, wmOperator *op)
2362 {
2363         Scene *scene = CTX_data_scene(C);
2364         Editing *ed = BKE_sequencer_editing_get(scene, false);
2365         
2366         Sequence *seq, *seq_new;
2367         Strip *strip_new;
2368         StripElem *se, *se_new;
2369         int start_ofs, cfra, frame_end;
2370         int step = RNA_int_get(op->ptr, "length");
2371
2372         seq = ed->seqbasep->first; /* poll checks this is valid */
2373
2374         while (seq) {
2375                 if ((seq->flag & SELECT) && (seq->type == SEQ_TYPE_IMAGE) && (seq->len > 1)) {
2376                         Sequence *seq_next;
2377
2378                         /* remove seq so overlap tests don't conflict,
2379                          * see seq_free_sequence below for the real free'ing */
2380                         BLI_remlink(ed->seqbasep, seq);
2381                         /* if (seq->ipo) seq->ipo->id.us--; */
2382                         /* XXX, remove fcurve and assign to split image strips */
2383
2384                         start_ofs = cfra = BKE_sequence_tx_get_final_left(seq, false);
2385                         frame_end = BKE_sequence_tx_get_final_right(seq, false);
2386
2387                         while (cfra < frame_end) {
2388                                 /* new seq */
2389                                 se = BKE_sequencer_give_stripelem(seq, cfra);
2390
2391                                 seq_new = BKE_sequence_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME);
2392                                 BLI_addtail(ed->seqbasep, seq_new);
2393
2394                                 seq_new->start = start_ofs;
2395                                 seq_new->type = SEQ_TYPE_IMAGE;
2396                                 seq_new->len = 1;
2397                                 seq_new->endstill = step - 1;
2398
2399                                 /* new strip */
2400                                 strip_new = seq_new->strip;
2401                                 strip_new->us = 1;
2402
2403                                 /* new stripdata (only one element now!) */
2404                                 /* Note this assume all elements (images) have the same dimension, since we only copy the name here. */
2405                                 se_new = MEM_reallocN(strip_new->stripdata, sizeof(*se_new));
2406                                 BLI_strncpy(se_new->name, se->name, sizeof(se_new->name));
2407                                 strip_new->stripdata = se_new;
2408
2409                                 BKE_sequence_calc(scene, seq_new);
2410
2411                                 if (step > 1) {
2412                                         seq_new->flag &= ~SEQ_OVERLAP;
2413                                         if (BKE_sequence_test_overlap(ed->seqbasep, seq_new)) {
2414                                                 BKE_sequence_base_shuffle(ed->seqbasep, seq_new, scene);
2415                                         }
2416                                 }
2417
2418                                 /* XXX, COPY FCURVES */
2419
2420                                 cfra++;
2421                                 start_ofs += step;
2422                         }
2423
2424                         seq_next = seq->next;
2425                         BKE_sequence_free(scene, seq);
2426                         seq = seq_next;
2427                 }
2428                 else {
2429                         seq = seq->next;
2430                 }
2431         }
2432
2433         /* as last: */
2434         BKE_sequencer_sort(scene);
2435         
2436         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2437
2438         return OPERATOR_FINISHED;
2439 }
2440
2441
2442 void SEQUENCER_OT_images_separate(wmOperatorType *ot)
2443 {
2444         /* identifiers */
2445         ot->name = "Separate Images";
2446         ot->idname = "SEQUENCER_OT_images_separate";
2447         ot->description = "On image sequence strips, it returns a strip for each image";
2448         
2449         /* api callbacks */
2450         ot->exec = sequencer_separate_images_exec;
2451         ot->invoke = WM_operator_props_popup;
2452         ot->poll = sequencer_edit_poll;
2453         
2454         /* flags */
2455         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2456
2457         RNA_def_int(ot->srna, "length", 1, 1, INT_MAX, "Length", "Length of each frame", 1, 1000);
2458 }
2459
2460
2461 /* META Operators */
2462
2463 /* separate_meta_toggle operator */
2464 static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op))
2465 {
2466         Scene *scene = CTX_data_scene(C);
2467         Editing *ed = BKE_sequencer_editing_get(scene, false);
2468         Sequence *last_seq = BKE_sequencer_active_get(scene);
2469         MetaStack *ms;
2470
2471         if (last_seq && last_seq->type == SEQ_TYPE_META && last_seq->flag & SELECT) {
2472                 /* Enter Metastrip */
2473                 ms = MEM_mallocN(sizeof(MetaStack), "metastack");
2474                 BLI_addtail(&ed->metastack, ms);
2475                 ms->parseq = last_seq;
2476                 ms->oldbasep = ed->seqbasep;
2477                 copy_v2_v2_int(ms->disp_range, &ms->parseq->startdisp);
2478
2479                 ed->seqbasep = &last_seq->seqbase;
2480
2481                 BKE_sequencer_active_set(scene, NULL);
2482
2483         }
2484         else {
2485                 /* Exit Metastrip (if possible) */
2486
2487                 Sequence *seq;
2488
2489                 if (BLI_listbase_is_empty(&ed->metastack))
2490                         return OPERATOR_CANCELLED;
2491
2492                 ms = ed->metastack.last;
2493                 BLI_remlink(&ed->metastack, ms);
2494
2495                 ed->seqbasep = ms->oldbasep;
2496
2497                 /* for old files, update from meta */
2498                 if (ms->disp_range[0] ==  ms->disp_range[1]) {
2499                         copy_v2_v2_int(ms->disp_range, &ms->parseq->startdisp);
2500                 }
2501
2502                 /* recalc all: the meta can have effects connected to it */
2503                 for (seq = ed->seqbasep->first; seq; seq = seq->next)
2504                         BKE_sequence_calc(scene, seq);
2505
2506                 /* 2.73+, keeping endpoings is important!
2507                  * moving them around means you can't usefully use metas in a complex edit */
2508 #if 1
2509                 BKE_sequence_tx_set_final_left(ms->parseq, ms->disp_range[0]);
2510                 BKE_sequence_tx_set_final_right(ms->parseq, ms->disp_range[1]);
2511                 BKE_sequence_calc(scene, ms->parseq);
2512 #else
2513                 if (BKE_sequence_test_overlap(ed->seqbasep, ms->parseq))
2514                         BKE_sequence_base_shuffle(ed->seqbasep, ms->parseq, scene);
2515 #endif
2516
2517                 BKE_sequencer_active_set(scene, ms->parseq);
2518
2519                 ms->parseq->flag |= SELECT;
2520                 recurs_sel_seq(ms->parseq);
2521
2522                 MEM_freeN(ms);
2523
2524         }
2525
2526         BKE_sequencer_update_muting(ed);
2527         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2528
2529         return OPERATOR_FINISHED;
2530 }
2531
2532 void SEQUENCER_OT_meta_toggle(wmOperatorType *ot)
2533 {
2534         /* identifiers */
2535         ot->name = "Toggle Meta Strip";
2536         ot->idname = "SEQUENCER_OT_meta_toggle";
2537         ot->description = "Toggle a metastrip (to edit enclosed strips)";
2538         
2539         /* api callbacks */
2540         ot->exec = sequencer_meta_toggle_exec;
2541         ot->poll = sequencer_edit_poll;
2542         
2543         /* flags */
2544         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2545 }
2546
2547
2548 /* separate_meta_make operator */
2549 static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
2550 {
2551         Scene *scene = CTX_data_scene(C);
2552         Editing *ed = BKE_sequencer_editing_get(scene, false);
2553         
2554         Sequence *seq, *seqm, *next, *last_seq = BKE_sequencer_active_get(scene);
2555         int channel_max = 1;
2556
2557         if (BKE_sequence_base_isolated_sel_check(ed->seqbasep) == false) {
2558                 BKE_report(op->reports, RPT_ERROR, "Please select all related strips");
2559                 return OPERATOR_CANCELLED;
2560         }
2561
2562         /* remove all selected from main list, and put in meta */
2563
2564         seqm = BKE_sequence_alloc(ed->seqbasep, 1, 1); /* channel number set later */
2565         strcpy(seqm->name + 2, "MetaStrip");
2566         seqm->type = SEQ_TYPE_META;
2567         seqm->flag = SELECT;
2568
2569         seq = ed->seqbasep->first;
2570         while (seq) {
2571                 next = seq->next;
2572                 if (seq != seqm && (seq->flag & SELECT)) {
2573                         BKE_sequence_invalidate_cache(scene, seq);
2574                         channel_max = max_ii(seq->machine, channel_max);
2575                         BLI_remlink(ed->seqbasep, seq);
2576                         BLI_addtail(&seqm->seqbase, seq);
2577                 }
2578                 seq = next;
2579         }
2580         seqm->machine = last_seq ? last_seq->machine : channel_max;
2581         BKE_sequence_calc(scene, seqm);
2582
2583         seqm->strip = MEM_callocN(sizeof(Strip), "metastrip");
2584         seqm->strip->us = 1;
2585         
2586         BKE_sequencer_active_set(scene, seqm);
2587
2588         if (BKE_sequence_test_overlap(ed->seqbasep, seqm) ) BKE_sequence_base_shuffle(ed->seqbasep, seqm, scene);
2589
2590         BKE_sequencer_update_muting(ed);
2591
2592         BKE_sequence_base_unique_name_recursive(&scene->ed->seqbase, seqm);
2593
2594         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2595
2596         return OPERATOR_FINISHED;
2597 }
2598
2599 void SEQUENCER_OT_meta_make(wmOperatorType *ot)
2600 {
2601         /* identifiers */
2602         ot->name = "Make Meta Strip";
2603         ot->idname = "SEQUENCER_OT_meta_make";
2604         ot->description = "Group selected strips into a metastrip";
2605         
2606         /* api callbacks */
2607         ot->exec = sequencer_meta_make_exec;
2608         ot->poll = sequencer_edit_poll;
2609         
2610         /* flags */
2611         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2612 }
2613
2614
2615 static int seq_depends_on_meta(Sequence *seq, Sequence *seqm)
2616 {
2617         if (seq == seqm) return 1;
2618         else if (seq->seq1 && seq_depends_on_meta(seq->seq1, seqm)) return 1;
2619         else if (seq->seq2 && seq_depends_on_meta(seq->seq2, seqm)) return 1;
2620         else if (seq->seq3 && seq_depends_on_meta(seq->seq3, seqm)) return 1;
2621         else return 0;
2622 }
2623
2624 /* separate_meta_make operator */
2625 static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op))
2626 {
2627         Scene *scene = CTX_data_scene(C);
2628         Editing *ed = BKE_sequencer_editing_get(scene, false);
2629
2630         Sequence *seq, *last_seq = BKE_sequencer_active_get(scene); /* last_seq checks (ed == NULL) */
2631
2632         if (last_seq == NULL || last_seq->type != SEQ_TYPE_META)
2633                 return OPERATOR_CANCELLED;
2634
2635         for (seq = last_seq->seqbase.first; seq != NULL; seq = seq->next) {
2636                 BKE_sequence_invalidate_cache(scene, seq);
2637         }
2638
2639         BLI_movelisttolist(ed->seqbasep, &last_seq->seqbase);
2640
2641         BLI_listbase_clear(&last_seq->seqbase);
2642
2643         BLI_remlink(ed->seqbasep, last_seq);
2644         BKE_sequence_free(scene, last_seq);
2645
2646         /* emtpy meta strip, delete all effects depending on it */
2647         for (seq = ed->seqbasep->first; seq; seq = seq->next)
2648                 if ((seq->type & SEQ_TYPE_EFFECT) && seq_depends_on_meta(seq, last_seq))
2649                         seq->flag |= SEQ_FLAG_DELETE;
2650
2651         recurs_del_seq_flag(scene, ed->seqbasep, SEQ_FLAG_DELETE, 0);
2652
2653         /* test for effects and overlap
2654          * don't use SEQP_BEGIN since that would be recursive */
2655         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2656                 if (seq->flag & SELECT) {
2657                         seq->flag &= ~SEQ_OVERLAP;
2658                         if (BKE_sequence_test_overlap(ed->seqbasep, seq)) {
2659                                 BKE_sequence_base_shuffle(ed->seqbasep, seq, scene);
2660                         }
2661                 }
2662         }
2663
2664         BKE_sequencer_sort(scene);
2665         BKE_sequencer_update_muting(ed);
2666
2667         WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
2668
2669         return OPERATOR_FINISHED;
2670 }
2671
2672 void SEQUENCER_OT_meta_separate(wmOperatorType *ot)
2673 {
2674         /* identifiers */
2675         ot->name = "UnMeta Strip";
2676         ot->idname = "SEQUENCER_OT_meta_separate";
2677         ot->description = "Put the contents of a metastrip back in the sequencer";
2678         
2679         /* api callbacks */
2680         ot->exec = sequencer_meta_separate_exec;
2681         ot->poll = sequencer_edit_poll;
2682         
2683         /* flags */
2684         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2685 }
2686
2687 /* view_all operator */
2688 static int sequencer_view_all_exec(bContext *C, wmOperator *op)
2689 {
2690         ARegion *ar = CTX_wm_region(C);
2691         View2D *v2d = UI_view2d_fromcontext(C);
2692         const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
2693
2694         UI_view2d_smooth_view(C, ar, &v2d->tot, smooth_viewtx);
2695         return OPERATOR_FINISHED;
2696 }
2697
2698 void SEQUENCER_OT_view_all(wmOperatorType *ot)
2699 {
2700         /* identifiers */
2701         ot->name = "View All";
2702         ot->idname = "SEQUENCER_OT_view_all";
2703         ot->description = "View all the strips in the sequencer";
2704         
2705         /* api callbacks */
2706         ot->exec = sequencer_view_all_exec;
2707         ot->poll = ED_operator_sequencer_active;
2708         
2709         /* flags */
2710         ot->flag = OPTYPE_REGISTER;
2711 }
2712
2713 /* view_all operator */
2714 static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op))
2715 {
2716         bScreen *sc = CTX_wm_screen(C);
2717         ScrArea *area = CTX_wm_area(C);
2718 #if 0
2719         ARegion *ar = CTX_wm_region(C);
2720         SpaceSeq *sseq = area->spacedata.first;
2721         Scene *scene = CTX_data_scene(C);
2722 #endif
2723         View2D *v2d = UI_view2d_fromcontext(C);
2724
2725         v2d->cur = v2d->tot;
2726         UI_view2d_curRect_validate(v2d);
2727         UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY);
2728         
2729 #if 0
2730         /* Like zooming on an image view */
2731         float zoomX, zoomY;
2732         int width, height, imgwidth, imgheight;
2733
2734         width = ar->winx;
2735         height = ar->winy;
2736
2737         seq_reset_imageofs(sseq);
2738
2739         imgwidth = (scene->r.size * scene->r.xsch) / 100;
2740         imgheight = (scene->r.size * scene->r.ysch) / 100;
2741
2742         /* Apply aspect, dosnt need to be that accurate */
2743         imgwidth = (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
2744
2745         if (((imgwidth >= width) || (imgheight >= height)) &&
2746             ((width > 0) && (height > 0)))
2747         {
2748                 /* Find the zoom value that will fit the image in the image space */
2749                 zoomX = ((float)width) / ((float)imgwidth);
2750                 zoomY = ((float)height) / ((float)imgheight);
2751                 sseq->zoom = (zoomX < zoomY) ? zoomX : zoomY;
2752
2753                 sseq->zoom = 1.0f / power_of_2(1 / min_ff(zoomX, zoomY));
2754         }
2755         else {
2756                 sseq->zoom = 1.0f;
2757         }
2758 #endif
2759
2760         ED_area_tag_redraw(CTX_wm_area(C));
2761         return OPERATOR_FINISHED;
2762 }
2763
2764 void SEQUENCER_OT_view_all_preview(wmOperatorType *ot)
2765 {
2766         /* identifiers */
2767         ot->name = "View All";
2768         ot->idname = "SEQUENCER_OT_view_all_preview";
2769         ot->description = "Zoom preview to fit in the area";
2770         
2771         /* api callbacks */
2772         ot->exec = sequencer_view_all_preview_exec;
2773         ot->poll = ED_operator_sequencer_active;
2774         
2775         /* flags */
2776         ot->flag = OPTYPE_REGISTER;
2777 }
2778
2779
2780 static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op)
2781 {
2782         RenderData *rd = &CTX_data_scene(C)->r;
2783         View2D *v2d = UI_view2d_fromcontext(C);
2784
2785         float ratio = RNA_float_get(op->ptr, "ratio");
2786
2787         float winx = (int)(rd->size * rd->xsch) / 100;
2788         float winy = (int)(rd->size * rd->ysch) / 100;
2789
2790         float facx = BLI_rcti_size_x(&v2d->mask) / winx;
2791         float facy = BLI_rcti_size_y(&v2d->mask) / winy;
2792
2793         BLI_rctf_resize(&v2d->cur, floorf(winx * facx / ratio + 0.5f), floorf(winy * facy / ratio + 0.5f));
2794
2795         ED_region_tag_redraw(CTX_wm_region(C));
2796
2797         return OPERATOR_FINISHED;
2798 }
2799
2800 void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot)
2801 {
2802         /* identifiers */
2803         ot->name = "Sequencer View Zoom Ratio";
2804         ot->idname = "SEQUENCER_OT_view_zoom_ratio";
2805         ot->description = "Change zoom ratio of sequencer preview";
2806
2807         /* api callbacks */
2808         ot->exec = sequencer_view_zoom_ratio_exec;
2809         ot->poll = ED_operator_sequencer_active;
2810
2811         /* properties */
2812         RNA_def_float(ot->srna, "ratio", 1.0f, -FLT_MAX, FLT_MAX,
2813                       "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out", -FLT_MAX, FLT_MAX);
2814 }
2815
2816
2817 #if 0
2818 static EnumPropertyItem view_type_items[] = {
2819         {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""},
2820         {SEQ_VIEW_PREVIEW,  "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""},
2821         {SEQ_VIEW_SEQUENCE_PREVIEW,  "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""},
2822         {0, NULL, 0, NULL, NULL}
2823 };
2824 #endif
2825
2826 /* view_all operator */
2827 static int sequencer_view_toggle_exec(bContext *C, wmOperator *UNUSED(op))
2828 {
2829         SpaceSeq *sseq = (SpaceSeq *)CTX_wm_space_data(C);
2830
2831         sseq->view++;
2832         if (sseq->view > SEQ_VIEW_SEQUENCE_PREVIEW) sseq->view = SEQ_VIEW_SEQUENCE;
2833
2834         ED_area_tag_refresh(CTX_wm_area(C));
2835
2836         return OPERATOR_FINISHED;
2837 }
2838
2839 void SEQUENCER_OT_view_toggle(wmOperatorType *ot)
2840 {
2841         /* identifiers */
2842         ot->name = "View Toggle";
2843         ot->idname = "SEQUENCER_OT_view_toggle";
2844         ot->description = "Toggle between sequencer views (sequence, preview, both)";
2845         
2846         /* api callbacks */
2847         ot->exec = sequencer_view_toggle_exec;
2848         ot->poll = ED_operator_sequencer_active;
2849         
2850         /* flags */
2851         ot->flag = OPTYPE_REGISTER;
2852 }
2853
2854
2855 /* view_selected operator */
2856 static int sequencer_view_selected_exec(bContext *C, wmOperator *op)
2857 {
2858         Scene *scene = CTX_data_scene(C);
2859         View2D *v2d = UI_view2d_fromcontext(C);
2860         ARegion *ar = CTX_wm_region(C);
2861         Editing *ed = BKE_sequencer_editing_get(scene, false);
2862         Sequence *last_seq = BKE_sequencer_active_get(scene);
2863         Sequence *seq;
2864         rctf cur_new = v2d->cur;
2865
2866         int xmin =  MAXFRAME * 2;
2867         int xmax = -MAXFRAME * 2;
2868         int ymin =  MAXSEQ + 1;
2869         int ymax = 0;
2870         int orig_height;
2871         int ymid;
2872         int ymargin = 1;
2873         int xmargin = FPS;
2874
2875         if (ed == NULL)
2876                 return OPERATOR_CANCELLED;
2877
2878         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
2879                 if ((seq->flag & SELECT) || (seq == last_seq)) {
2880                         xmin = min_ii(xmin, seq->startdisp);
2881                         xmax = max_ii(xmax, seq->enddisp);
2882
2883                         ymin = min_ii(ymin, seq->machine);
2884                         ymax = max_ii(ymax, seq->machine);
2885                 }
2886         }
2887
2888         if (ymax != 0) {
2889                 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
2890                 
2891                 xmax += xmargin;
2892                 xmin -= xmargin;
2893                 ymax += ymargin;
2894                 ymin -= ymargin;
2895
2896                 orig_height = BLI_rctf_size_y(&cur_new);
2897
2898                 cur_new.xmin = xmin;
2899                 cur_new.xmax = xmax;
2900
2901                 cur_new.ymin = ymin;
2902                 cur_new.ymax = ymax;
2903
2904                 /* only zoom out vertically */
2905                 if (orig_height > BLI_rctf_size_y(&cur_new)) {
2906                         ymid = BLI_rctf_cent_y(&cur_new);
2907
2908                         cur_new.ymin = ymid - (orig_height / 2);
2909                         cur_new.ymax = ymid + (orig_height / 2);
2910                 }
2911
2912                 UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx);
2913
2914                 return OPERATOR_FINISHED;
2915         }
2916         else {
2917                 return OPERATOR_CANCELLED;
2918         }
2919         
2920 }
2921
2922 void SEQUENCER_OT_view_selected(wmOperatorType *ot)
2923 {
2924         /* identifiers */
2925         ot->name = "View Selected";
2926         ot->idname = "SEQUENCER_OT_view_selected";
2927         ot->description = "Zoom the sequencer on the selected strips";
2928         
2929         /* api callbacks */
2930         ot->exec = sequencer_view_selected_exec;
2931         ot->poll = ED_operator_sequencer_active;
2932         
2933         /* flags */
2934         ot->flag = OPTYPE_REGISTER;
2935 }
2936
2937 static bool strip_jump_internal(Scene *scene,
2938                                 const short side,
2939                                 const bool do_skip_mute, const bool do_center)
2940 {
2941         bool changed = false;
2942         int cfra = CFRA;
2943         int nfra = BKE_sequencer_find_next_prev_edit(scene, cfra, side, do_skip_mute, do_center, false);
2944         
2945         if (nfra != cfra) {
2946                 CFRA = nfra;
2947                 changed = true;
2948         }
2949
2950         return changed;
2951 }
2952
2953 static int sequencer_strip_jump_poll(bContext *C)
2954 {
2955         /* prevent changes during render */
2956         if (G.is_rendering)
2957                 return 0;
2958
2959         return sequencer_edit_poll(C);
2960 }
2961
2962 /* jump frame to edit point operator */
2963 static int sequencer_strip_jump_exec(bContext *C, wmOperator *op)
2964 {
2965         Scene *scene = CTX_data_scene(C);
2966         const bool next = RNA_boolean_get(op->ptr, "next");
2967         const bool center = RNA_boolean_get(op->ptr, "center");
2968
2969         /* currently do_skip_mute is always true */
2970         if (!strip_jump_internal(scene, next ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT, true, center)) {
2971                 return OPERATOR_CANCELLED;
2972         }
2973
2974         WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
2975         
2976         return OPERATOR_FINISHED;
2977 }
2978
2979 void SEQUENCER_OT_strip_jump(wmOperatorType *ot)
2980 {
2981         /* identifiers */
2982         ot->name = "Jump to Strip";
2983         ot->idname = "SEQUENCER_OT_strip_jump";
2984         ot->description = "Move frame to previous edit point";
2985
2986         /* api callbacks */
2987         ot->exec = sequencer_strip_jump_exec;
2988         ot->poll = sequencer_strip_jump_poll;
2989
2990         /* flags */
2991         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2992         
2993         /* properties */
2994         RNA_def_boolean(ot->srna, "next", true, "Next Strip", "");
2995         RNA_def_boolean(ot->srna, "center", true, "Use strip center", "");
2996 }
2997
2998 static void swap_sequence(Scene *scene, Sequence *seqa, Sequence *seqb)
2999 {
3000         int gap = seqb->startdisp - seqa->enddisp;
3001         int seq_a_start;
3002         int seq_b_start;
3003
3004         seq_b_start = (seqb->start - seqb->startdisp) + seqa->startdisp;
3005         BKE_sequence_translate(scene, seqb, seq_b_start - seqb->start);
3006         BKE_sequence_calc(scene, seqb);
3007
3008         seq_a_start = (seqa->start - seqa->startdisp) + seqb->enddisp + gap;
3009         BKE_sequence_translate(scene, seqa, seq_a_start - seqa->start);
3010         BKE_sequence_calc(scene, seqa);
3011 }
3012
3013 #if 0
3014 static Sequence *sequence_find_parent(Scene *scene, Sequence *child)
3015 {
3016         Editing *ed = BKE_sequencer_editing_get(scene, false);
3017         Sequence *parent = NULL;
3018         Sequence *seq;
3019
3020         if (ed == NULL) return NULL;
3021
3022         for (seq = ed->seqbasep->first; seq; seq = seq->next) {
3023                 if ((seq != child) && seq_is_parent(seq, child)) {
3024                         parent = seq;
3025                         break;
3026                 }
3027         }
3028
3029         return parent;
3030 }
3031 #endif
3032
3033 static int sequencer_swap_exec(bContext *C, wmOperator *op)
3034 {
3035         Scene *scene = CTX_data_scene(C);
3036         Editing *ed = BKE_sequencer_editing_get(scene, false);
3037         Sequence *active_seq = BKE_sequencer_active_get(scene);
3038         Sequence *seq, *iseq;
3039         int side = RNA_enum_get(op->ptr, "side");
3040
3041         if (active_seq == NULL) return OPERATOR_CANCELLED;
3042
3043         seq = find_next_prev_sequence(scene, active_seq, side, -1);
3044         
3045         if (seq) {
3046                 
3047                 /* disallow effect strips */
3048                 if (BKE_sequence_effect_get_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3))
3049                         return OPERATOR_CANCELLED;
3050                 if ((BKE_sequence_effect_get_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3))
3051                         return OPERATOR_CANCELLED;
3052
3053                 switch (side) {
3054                         case SEQ_SIDE_LEFT: 
3055                                 swap_sequence(scene, seq, active_seq);
3056                                 break;
3057                         case SEQ_SIDE_RIGHT: 
3058                                 swap_sequence(scene, active_seq, seq);
3059                                 break;
3060                 }
3061
3062                 // XXX - should be a generic function
3063                 for (iseq = scene->ed->seqbasep->first; iseq; iseq = iseq->next) {
3064                         if ((iseq->type & SEQ_TYPE_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
3065                                 BKE_sequence_calc(scene, iseq);
3066                         }
3067                 }
3068
3069                 /* do this in a new loop since both effects need to be calculated first */
3070                 for (iseq = scene->ed->seqbasep->first; iseq; iseq = iseq->next) {
3071                         if ((iseq->type & SEQ_TYPE_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) {
3072                                 /* this may now overlap */
3073                                 if (BKE_sequence_test_overlap(ed->seqbasep, iseq) ) {
3074                                         BKE_sequence_base_shuffle(ed->seqbasep, iseq, scene);
3075                                 }
3076                         }
3077                 }
3078
3079
3080
3081                 BKE_sequencer_sort(scene);
3082
3083                 WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
3084
3085                 return OPERATOR_FINISHED;
3086         }
3087
3088         return OPERATOR_CANCELLED;
3089 }
3090
3091 void SEQUENCER_OT_swap(wmOperatorType *ot)
3092 {
3093         /* identifiers */
3094         ot->name = "Swap Strip";
3095         ot->idname = "SEQUENCER_OT_swap";
3096         ot->description = "Swap active strip with strip to the right or left";
3097         
3098         /* api callbacks */
3099         ot->exec = sequencer_swap_exec;
3100         ot->poll = sequencer_edit_poll;
3101         
3102         /* flags */
3103         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
3104         
3105         /* properties */
3106         RNA_def_enum(ot->srna, "side", prop_side_lr_types, SEQ_SIDE_RIGHT, "Side", "Side of the strip to swap");
3107 }
3108
3109 static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op))
3110 {
3111         int retval = OPERATOR_CANCELLED;
3112         Scene *scene = CTX_data_scene(C);
3113         Sequence *active_seq = BKE_sequencer_active_get(scene);
3114         StripElem *se = NULL;
3115
3116         if (active_seq == NULL)
3117                 return OPERATOR_CANCELLED;
3118
3119
3120         if (active_seq->strip) {
3121                 switch (active_seq->type) {
3122                         case SEQ_TYPE_IMAGE:
3123                                 se = BKE_sequencer_give_stripelem(active_seq, scene->r.cfra);
3124                                 break;
3125                         case SEQ_TYPE_MOVIE:
3126                                 se = active_seq->strip->stripdata;
3127                                 break;
3128                         case SEQ_TYPE_SCENE:
3129                         case SEQ_TYPE_META:
3130                         case SEQ_TYPE_SOUND_RAM:
3131                         case SEQ_TYPE_SOUND_HD:
3132                         default:
3133                                 break;
3134                 }
3135         }
3136
3137         if (se) {
3138                 // prevent setting the render size if sequence values aren't initialized
3139                 if ((se->orig_width > 0) && (se->orig_height > 0)) {
3140                         scene->r.xsch = se->orig_width;
3141                         scene->r.ysch = se->orig_height;
3142                         WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
3143                         retval = OPERATOR_FINISHED;
3144                 }
3145         }
3146
3147         return retval;
3148 }
3149
3150 void SEQUENCER_OT_rendersize(wmOperatorType *ot)
3151 {
3152         /* identifiers */
3153         ot->name = "Set Render Size";
3154         ot->idname = "SEQUENCER_OT_rendersize";
3155         ot->description = "Set render size and aspect from active sequence";
3156         
3157         /* api callbacks */
3158         ot->exec = sequencer_rendersize_exec;
3159         ot->poll = sequencer_edit_poll;
3160         
3161         /* flags */
3162         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
3163         
3164         /* properties */
3165 }
3166