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