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