remove redundant assignments & unused vars.
[blender-staging.git] / source / blender / editors / space_sequencer / sequencer_add.c
1 /**
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * Contributor(s): Blender Foundation, 2003-2009, Campbell Barton
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include <stdlib.h>
28 #include <math.h>
29 #include <string.h>
30
31 #ifndef WIN32
32 #include <unistd.h>
33 #else
34 #include <io.h>
35 #endif
36 #include <sys/types.h>
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_math.h"
42 #include "BLI_storage_types.h"
43 #include "BLI_utildefines.h"
44
45 #include "DNA_scene_types.h"
46 #include "DNA_userdef_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
54
55 #include "WM_api.h"
56 #include "WM_types.h"
57
58 #include "RNA_define.h"
59 #include "RNA_enum_types.h"
60
61 /* for menu/popup icons etc etc*/
62
63 #include "ED_screen.h"
64
65 #include "UI_view2d.h"
66
67 #include "BKE_sound.h"
68 #include "AUD_C-API.h"
69
70 /* own include */
71 #include "sequencer_intern.h"
72
73 /* Generic functions, reused by add strip operators */
74
75 /* avoid passing multiple args and be more verbose */
76 #define SEQPROP_STARTFRAME      (1<<0)
77 #define SEQPROP_ENDFRAME        (1<<1)
78 #define SEQPROP_FILES           (1<<2)
79 #define SEQPROP_NOPATHS         (1<<3)
80
81 static void sequencer_generic_props__internal(wmOperatorType *ot, int flag)
82 {
83         if(flag & SEQPROP_STARTFRAME)
84                 RNA_def_int(ot->srna, "frame_start", 0, INT_MIN, INT_MAX, "Start Frame", "Start frame of the sequence strip", INT_MIN, INT_MAX);
85         
86         if(flag & SEQPROP_ENDFRAME)
87                 RNA_def_int(ot->srna, "frame_end", 0, INT_MIN, INT_MAX, "End Frame", "End frame for the color strip", INT_MIN, INT_MAX); /* not useual since most strips have a fixed length */
88         
89         RNA_def_int(ot->srna, "channel", 1, 1, MAXSEQ, "Channel", "Channel to place this strip into", 1, MAXSEQ);
90         
91         RNA_def_boolean(ot->srna, "replace_sel", 1, "Replace Selection", "replace the current selection");
92
93         if(flag & SEQPROP_FILES)
94                 RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
95 }
96
97 static void sequencer_generic_invoke_path__internal(bContext *C, wmOperator *op, const char *identifier)
98 {
99         if(RNA_struct_find_property(op->ptr, identifier)) {
100                 Scene *scene= CTX_data_scene(C);
101                 Sequence *last_seq= seq_active_get(scene);
102                 if(last_seq && last_seq->strip && SEQ_HAS_PATH(last_seq)) {
103                         char path[sizeof(last_seq->strip->dir)];
104                         BLI_strncpy(path, last_seq->strip->dir, sizeof(path));
105                         BLI_path_abs(path, G.main->name);
106                         RNA_string_set(op->ptr, identifier, path);
107                 }
108         }
109 }
110
111 static void sequencer_generic_invoke_xy__internal(bContext *C, wmOperator *op, wmEvent *event, int flag)
112 {
113         ARegion *ar= CTX_wm_region(C);
114         View2D *v2d= UI_view2d_fromcontext(C);
115         
116         short mval[2];  
117         float mval_v2d[2];
118         
119
120         mval[0]= event->x - ar->winrct.xmin;
121         mval[1]= event->y - ar->winrct.ymin;
122         
123         UI_view2d_region_to_view(v2d, mval[0], mval[1], &mval_v2d[0], &mval_v2d[1]);
124         
125         RNA_int_set(op->ptr, "channel", (int)mval_v2d[1]+0.5f);
126         RNA_int_set(op->ptr, "frame_start", (int)mval_v2d[0]);
127         
128         if ((flag & SEQPROP_ENDFRAME) && RNA_property_is_set(op->ptr, "frame_end")==0)
129                 RNA_int_set(op->ptr, "frame_end", (int)mval_v2d[0] + 25); // XXX arbitary but ok for now.
130
131         if (!(flag & SEQPROP_NOPATHS)) {
132                 sequencer_generic_invoke_path__internal(C, op, "filepath");
133                 sequencer_generic_invoke_path__internal(C, op, "directory");
134         }
135 }
136
137 static void seq_load_operator_info(SeqLoadInfo *seq_load, wmOperator *op)
138 {
139         int relative= RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path");
140         int is_file= -1;
141         memset(seq_load, 0, sizeof(SeqLoadInfo));
142
143         seq_load->start_frame=  RNA_int_get(op->ptr, "frame_start");
144         seq_load->end_frame=    seq_load->start_frame; /* un-set */
145
146         seq_load->channel=              RNA_int_get(op->ptr, "channel");
147         seq_load->len=                  1; // images only, if endframe isnt set!
148
149         if(RNA_struct_find_property(op->ptr, "filepath")) {
150                 RNA_string_get(op->ptr, "filepath", seq_load->path); /* full path, file is set by the caller */
151                 is_file= 1;
152         } else if (RNA_struct_find_property(op->ptr, "directory")) {
153                 RNA_string_get(op->ptr, "directory", seq_load->path); /* full path, file is set by the caller */
154                 is_file= 0;
155         }
156
157         if((is_file != -1) && relative)
158                 BLI_path_rel(seq_load->path, G.main->name);
159
160         
161         if (RNA_struct_find_property(op->ptr, "frame_end")) {
162                 seq_load->end_frame = RNA_int_get(op->ptr, "frame_end");
163         }
164
165         if (RNA_struct_find_property(op->ptr, "replace_sel") && RNA_boolean_get(op->ptr, "replace_sel"))
166                 seq_load->flag |= SEQ_LOAD_REPLACE_SEL;
167
168         if (RNA_struct_find_property(op->ptr, "cache") && RNA_boolean_get(op->ptr, "cache"))
169                 seq_load->flag |= SEQ_LOAD_SOUND_CACHE;
170
171         if (RNA_struct_find_property(op->ptr, "sound") && RNA_boolean_get(op->ptr, "sound"))
172                 seq_load->flag |= SEQ_LOAD_MOVIE_SOUND;
173
174         /* always use this for ops */
175         seq_load->flag |= SEQ_LOAD_FRAME_ADVANCE;
176
177
178         if(is_file==1) {
179                 BLI_strncpy(seq_load->name, BLI_path_basename(seq_load->path), sizeof(seq_load->name));
180         }
181         else if(RNA_struct_find_property(op->ptr, "files")) {
182                 /* used for image strip */
183                 /* best guess, first images name */
184                 RNA_BEGIN(op->ptr, itemptr, "files") {
185                         char *name= RNA_string_get_alloc(&itemptr, "name", NULL, 0);
186                         BLI_strncpy(seq_load->name, name, sizeof(seq_load->name));
187                         MEM_freeN(name);
188                         break;
189                 }
190                 RNA_END;
191         }
192 }
193
194 /* add scene operator */
195 static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
196 {
197         Scene *scene= CTX_data_scene(C);
198         Editing *ed= seq_give_editing(scene, TRUE);
199         
200         Scene *sce_seq;
201
202         Sequence *seq;  /* generic strip vars */
203         Strip *strip;
204         
205         int start_frame, channel; /* operator props */
206         
207         start_frame= RNA_int_get(op->ptr, "frame_start");
208         channel= RNA_int_get(op->ptr, "channel");
209         
210         sce_seq= BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene"));
211         
212         if (sce_seq==NULL) {
213                 BKE_report(op->reports, RPT_ERROR, "Scene not found");
214                 return OPERATOR_CANCELLED;
215         }
216         
217         seq = alloc_sequence(ed->seqbasep, start_frame, channel);
218         seq->type= SEQ_SCENE;
219         seq->blend_mode= SEQ_CROSS; /* so alpha adjustment fade to the strip below */
220
221         seq->scene= sce_seq;
222         seq->sfra= sce_seq->r.sfra;
223         
224         /* basic defaults */
225         seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
226         strip->len = seq->len = sce_seq->r.efra - sce_seq->r.sfra + 1;
227         strip->us= 1;
228         
229         strip->stripdata= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
230         
231         strcpy(seq->name+2, sce_seq->id.name+2);
232         seqbase_unique_name_recursive(&ed->seqbase, seq);
233
234         seq->scene_sound = sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + strip->len, 0);
235
236         calc_sequence_disp(scene, seq);
237         sort_seq(scene);
238         
239         if (RNA_boolean_get(op->ptr, "replace_sel")) {
240                 deselect_all_seq(scene);
241                 seq_active_set(scene, seq);
242                 seq->flag |= SELECT;
243         }
244         
245         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
246         
247         return OPERATOR_FINISHED;
248 }
249
250
251 static int sequencer_add_scene_strip_invoke(bContext *C, wmOperator *op, wmEvent *event)
252 {
253         if(!ED_operator_sequencer_active(C)) {
254                 BKE_report(op->reports, RPT_ERROR, "Sequencer area not active");
255                 return OPERATOR_CANCELLED;
256         }
257
258         if(!RNA_property_is_set(op->ptr, "scene"))
259                 return WM_enum_search_invoke(C, op, event);
260
261         sequencer_generic_invoke_xy__internal(C, op, event, 0);
262         return sequencer_add_scene_strip_exec(C, op);
263         // needs a menu
264         // return WM_menu_invoke(C, op, event);
265 }
266
267
268 void SEQUENCER_OT_scene_strip_add(struct wmOperatorType *ot)
269 {
270         PropertyRNA *prop;
271         
272         /* identifiers */
273         ot->name= "Add Scene Strip";
274         ot->idname= "SEQUENCER_OT_scene_strip_add";
275         ot->description= "Add a strip to the sequencer using a blender scene as a source";
276
277         /* api callbacks */
278         ot->invoke= sequencer_add_scene_strip_invoke;
279         ot->exec= sequencer_add_scene_strip_exec;
280
281         ot->poll= ED_operator_scene_editable;
282         
283         /* flags */
284         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
285         
286         sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME);
287         prop= RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
288         RNA_def_enum_funcs(prop, RNA_scene_itemf);
289         ot->prop= prop;
290 }
291
292 static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoadFunc seq_load_func)
293 {
294         Scene *scene= CTX_data_scene(C); /* only for sound */
295         Editing *ed= seq_give_editing(scene, TRUE);
296         SeqLoadInfo seq_load;
297         Sequence *seq;
298         int tot_files;
299
300         seq_load_operator_info(&seq_load, op);
301
302         if (seq_load.flag & SEQ_LOAD_REPLACE_SEL)
303                 deselect_all_seq(scene);
304
305         tot_files= RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files"));
306
307         if(tot_files) {
308                 /* multiple files */
309                 char dir_only[FILE_MAX];
310                 char file_only[FILE_MAX];
311
312                 BLI_split_dirfile(seq_load.path, dir_only, NULL);
313
314                 RNA_BEGIN(op->ptr, itemptr, "files") {
315                         RNA_string_get(&itemptr, "name", file_only);
316                         BLI_join_dirfile(seq_load.path, dir_only, file_only);
317
318                         seq= seq_load_func(C, ed->seqbasep, &seq_load);
319                 }
320                 RNA_END;
321         }
322         else {
323                 /* single file */
324                 seq= seq_load_func(C, ed->seqbasep, &seq_load);
325         }
326
327         if (seq_load.tot_success==0) {
328                 BKE_reportf(op->reports, RPT_ERROR, "File \"%s\" could not be loaded", seq_load.path);
329                 return OPERATOR_CANCELLED;
330         }
331
332         sort_seq(scene);
333         seq_update_muting(scene, ed);
334
335         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
336
337         return OPERATOR_FINISHED;
338 }
339
340 /* add movie operator */
341 static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op)
342 {
343         return sequencer_add_generic_strip_exec(C, op, sequencer_add_movie_strip);
344 }
345
346
347 static int sequencer_add_movie_strip_invoke(bContext *C, wmOperator *op, wmEvent *event)
348 {
349
350         if(!ED_operator_sequencer_active(C)) {
351                 BKE_report(op->reports, RPT_ERROR, "Sequencer area not active");
352                 return OPERATOR_CANCELLED;
353         }
354
355         /* This is for drag and drop */
356         if(RNA_collection_length(op->ptr, "files") || RNA_property_is_set(op->ptr, "filepath")) {
357                 sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_NOPATHS);
358                 return sequencer_add_movie_strip_exec(C, op);
359         }
360         
361         sequencer_generic_invoke_xy__internal(C, op, event, 0);
362         
363         if(!RNA_property_is_set(op->ptr, "relative_path"))
364                 RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
365         
366         WM_event_add_fileselect(C, op);
367         return OPERATOR_RUNNING_MODAL;
368
369         //return sequencer_add_movie_strip_exec(C, op);
370 }
371
372
373 void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot)
374 {
375         
376         /* identifiers */
377         ot->name= "Add Movie Strip";
378         ot->idname= "SEQUENCER_OT_movie_strip_add";
379         ot->description= "Add a movie strip to the sequencer";
380
381         /* api callbacks */
382         ot->invoke= sequencer_add_movie_strip_invoke;
383         ot->exec= sequencer_add_movie_strip_exec;
384
385         ot->poll= ED_operator_scene_editable;
386         
387         /* flags */
388         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
389         
390         WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH);
391         sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
392         RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie");
393 }
394
395 /* add sound operator */
396
397 static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op)
398 {
399         return sequencer_add_generic_strip_exec(C, op, sequencer_add_sound_strip);
400 }
401
402 static int sequencer_add_sound_strip_invoke(bContext *C, wmOperator *op, wmEvent *event)
403 {
404
405         if(!ED_operator_sequencer_active(C)) {
406                 BKE_report(op->reports, RPT_ERROR, "Sequencer area not active");
407                 return OPERATOR_CANCELLED;
408         }
409         
410         /* This is for drag and drop */
411         if(RNA_collection_length(op->ptr, "files") || RNA_property_is_set(op->ptr, "filepath")) {
412                 sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_NOPATHS);
413                 return sequencer_add_sound_strip_exec(C, op);
414         }
415         
416         sequencer_generic_invoke_xy__internal(C, op, event, 0);
417         
418         if(!RNA_property_is_set(op->ptr, "relative_path"))
419                 RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
420         
421         WM_event_add_fileselect(C, op);
422         return OPERATOR_RUNNING_MODAL;
423
424         //return sequencer_add_sound_strip_exec(C, op);
425 }
426
427
428 void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot)
429 {
430         
431         /* identifiers */
432         ot->name= "Add Sound Strip";
433         ot->idname= "SEQUENCER_OT_sound_strip_add";
434         ot->description= "Add a sound strip to the sequencer";
435
436         /* api callbacks */
437         ot->invoke= sequencer_add_sound_strip_invoke;
438         ot->exec= sequencer_add_sound_strip_exec;
439
440         ot->poll= ED_operator_scene_editable;
441         
442         /* flags */
443         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
444         
445         WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH);
446         sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILES);
447         RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory.");
448 }
449
450 /* add image operator */
451 static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
452 {
453         /* cant use the generic function for this */
454
455         Scene *scene= CTX_data_scene(C); /* only for sound */
456         Editing *ed= seq_give_editing(scene, TRUE);
457         SeqLoadInfo seq_load;
458         Sequence *seq;
459
460         Strip *strip;
461         StripElem *se;
462
463         seq_load_operator_info(&seq_load, op);
464
465         /* images are unique in how they handle this - 1 per strip elem */
466         seq_load.len= RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files"));
467
468         if(seq_load.len==0)
469                 return OPERATOR_CANCELLED;
470
471         if(seq_load.flag & SEQ_LOAD_REPLACE_SEL)
472                 deselect_all_seq(scene);
473
474
475         /* main adding function */
476         seq= sequencer_add_image_strip(C, ed->seqbasep, &seq_load);
477         strip= seq->strip;
478         se= strip->stripdata;
479
480         RNA_BEGIN(op->ptr, itemptr, "files") {
481                 char *filename= RNA_string_get_alloc(&itemptr, "name", NULL, 0);
482                 BLI_strncpy(se->name, filename, sizeof(se->name));
483                 MEM_freeN(filename);
484                 se++;
485         }
486         RNA_END;
487
488         if(seq_load.len == 1) {
489                 if(seq_load.start_frame < seq_load.end_frame) {
490                         seq->endstill= seq_load.end_frame - seq_load.start_frame;
491                 }
492         }
493         
494         calc_sequence_disp(scene, seq);
495
496         sort_seq(scene);
497
498         /* last active name */
499         strncpy(ed->act_imagedir, strip->dir, FILE_MAXDIR-1);
500         
501         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
502
503         return OPERATOR_FINISHED;
504 }
505
506 static int sequencer_add_image_strip_invoke(bContext *C, wmOperator *op, wmEvent *event)
507 {
508
509         if(!ED_operator_sequencer_active(C)) {
510                 BKE_report(op->reports, RPT_ERROR, "Sequencer area not active");
511                 return OPERATOR_CANCELLED;
512         }
513
514
515         /* drag drop has set the names */
516         if(RNA_collection_length(op->ptr, "files")) {
517                 sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_ENDFRAME|SEQPROP_NOPATHS);
518                 return sequencer_add_image_strip_exec(C, op);
519         }
520         
521         sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_ENDFRAME);
522         
523         if(!RNA_property_is_set(op->ptr, "relative_path"))
524                 RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
525
526         WM_event_add_fileselect(C, op);
527         return OPERATOR_RUNNING_MODAL;
528 }
529
530
531 void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot)
532 {
533         
534         /* identifiers */
535         ot->name= "Add Image Strip";
536         ot->idname= "SEQUENCER_OT_image_strip_add";
537         ot->description= "Add an image or image sequence to the sequencer";
538
539         /* api callbacks */
540         ot->invoke= sequencer_add_image_strip_invoke;
541         ot->exec= sequencer_add_image_strip_exec;
542
543         ot->poll= ED_operator_scene_editable;
544         
545         /* flags */
546         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
547         
548         WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY|WM_FILESEL_RELPATH);
549         sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME|SEQPROP_FILES);
550 }
551
552
553 /* add_effect_strip operator */
554 static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
555 {
556         Scene *scene= CTX_data_scene(C);
557         Editing *ed= seq_give_editing(scene, TRUE);
558
559         Sequence *seq;  /* generic strip vars */
560         Strip *strip;
561         struct SeqEffectHandle sh;
562
563         int start_frame, end_frame, channel, type; /* operator props */
564         
565         Sequence *seq1, *seq2, *seq3;
566         const char *error_msg;
567
568         start_frame= RNA_int_get(op->ptr, "frame_start");
569         end_frame= RNA_int_get(op->ptr, "frame_end");
570         channel= RNA_int_get(op->ptr, "channel");
571
572         type= RNA_enum_get(op->ptr, "type");
573         
574         // XXX move to invoke
575         if(!seq_effect_find_selected(scene, NULL, type, &seq1, &seq2, &seq3, &error_msg)) {
576                 BKE_report(op->reports, RPT_ERROR, error_msg);
577                 return OPERATOR_CANCELLED;
578         }
579
580         /* If seq1 is NULL and no error was rasied it means the seq is standalone
581          * (like color strips) and we need to check its start and end frames are valid */
582         if (seq1==NULL && end_frame <= start_frame) {
583                 BKE_report(op->reports, RPT_ERROR, "Start and end frame are not set");
584                 return OPERATOR_CANCELLED;
585         }
586
587         seq = alloc_sequence(ed->seqbasep, start_frame, channel);
588         seq->type= type;
589
590         BLI_strncpy(seq->name+2, give_seqname(seq), sizeof(seq->name)-2);
591         seqbase_unique_name_recursive(&ed->seqbase, seq);
592
593         sh = get_sequence_effect(seq);
594
595         seq->seq1= seq1;
596         seq->seq2= seq2;
597         seq->seq3= seq3;
598
599         sh.init(seq);
600
601         if (!seq1) { /* effect has no deps */
602                 seq->len= 1;
603                 seq_tx_set_final_right(seq, end_frame);
604         }
605
606         seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE;
607
608         calc_sequence(scene, seq);
609         
610         /* basic defaults */
611         seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
612         strip->len = seq->len;
613         strip->us= 1;
614         if(seq->len>0)
615                 strip->stripdata= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
616
617         if (seq->type==SEQ_PLUGIN) {
618                 char path[FILE_MAX];
619                 RNA_string_get(op->ptr, "filepath", path);
620
621                 sh.init_plugin(seq, path);
622
623                 if(seq->plugin==NULL) {
624                         BLI_remlink(ed->seqbasep, seq);
625                         seq_free_sequence(scene, seq);
626                         BKE_reportf(op->reports, RPT_ERROR, "Sequencer plugin \"%s\" could not load.", path);
627                         return OPERATOR_CANCELLED;
628                 }
629         }
630         else if (seq->type==SEQ_COLOR) {
631                 SolidColorVars *colvars= (SolidColorVars *)seq->effectdata;
632                 RNA_float_get_array(op->ptr, "color", colvars->col);
633                 seq->blend_mode= SEQ_CROSS; /* so alpha adjustment fade to the strip below */
634
635         }
636
637         // XXX, this conflicts with giving a channel with invoke, perhaps we should have an active channel
638         // but for now this is much more usable
639         if(seq->seq1 || seq->seq2 || seq->seq3) {
640                 int chan= MAX3( seq->seq1 ? seq->seq1->machine : 0,
641                                                 seq->seq2 ? seq->seq2->machine : 0,
642                                                 seq->seq3 ? seq->seq3->machine : 0);
643                 if(chan < MAXSEQ)
644                         seq->machine= chan;
645         }
646
647         if(seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene);
648
649         update_changed_seq_and_deps(scene, seq, 1, 1); /* runs calc_sequence */
650
651
652         /* not sure if this is needed with update_changed_seq_and_deps.
653          * it was NOT called in blender 2.4x, but wont hurt */
654         sort_seq(scene); 
655
656         if (RNA_boolean_get(op->ptr, "replace_sel")) {
657                 deselect_all_seq(scene);
658                 seq_active_set(scene, seq);
659                 seq->flag |= SELECT;
660         }
661
662         WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene);
663
664         return OPERATOR_FINISHED;
665 }
666
667
668 /* add color */
669 static int sequencer_add_effect_strip_invoke(bContext *C, wmOperator *op, wmEvent *event)
670 {
671         if(!ED_operator_sequencer_active(C)) {
672                 BKE_report(op->reports, RPT_ERROR, "Sequencer area not active");
673                 return OPERATOR_CANCELLED;
674         }
675
676         sequencer_generic_invoke_xy__internal(C, op, event, SEQPROP_ENDFRAME);
677
678         if (RNA_property_is_set(op->ptr, "type") && RNA_enum_get(op->ptr, "type")==SEQ_PLUGIN) {
679
680                 if(!RNA_property_is_set(op->ptr, "relative_path"))
681                         RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
682
683                 /* only plugins need the file selector */
684                 return WM_operator_filesel(C, op, event);
685         }
686         else {
687                 return sequencer_add_effect_strip_exec(C, op);
688         }
689 }
690
691 void SEQUENCER_OT_effect_strip_add(struct wmOperatorType *ot)
692 {
693         /* identifiers */
694         ot->name= "Add Effect Strip";
695         ot->idname= "SEQUENCER_OT_effect_strip_add";
696         ot->description= "Add an effect to the sequencer, most are applied on top of existing strips";
697
698         /* api callbacks */
699         ot->invoke= sequencer_add_effect_strip_invoke;
700         ot->exec= sequencer_add_effect_strip_exec;
701
702         ot->poll= ED_operator_scene_editable;
703         
704         /* flags */
705         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
706         
707         WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH|WM_FILESEL_RELPATH);
708         sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_ENDFRAME);
709         RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, SEQ_CROSS, "Type", "Sequencer effect type");
710         RNA_def_float_vector(ot->srna, "color", 3, NULL, 0.0f, 1.0f, "Color", "Initialize the strip with this color (only used when type='COLOR')", 0.0f, 1.0f);
711 }