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