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