|
Blender
V2.59
|
00001 /* 00002 * $Id: sequencer_edit.c 39048 2011-08-05 06:26:54Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * Contributor(s): Blender Foundation, 2003-2009 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <stdlib.h> 00034 #include <math.h> 00035 #include <string.h> 00036 00037 #ifndef WIN32 00038 #include <unistd.h> 00039 #else 00040 #include <io.h> 00041 #endif 00042 #include <sys/types.h> 00043 00044 #include "MEM_guardedalloc.h" 00045 00046 #include "BLI_blenlib.h" 00047 #include "BLI_math.h" 00048 #include "BLI_storage_types.h" 00049 #include "BLI_utildefines.h" 00050 00051 #include "DNA_scene_types.h" 00052 #include "DNA_userdef_types.h" 00053 00054 #include "BKE_context.h" 00055 #include "BKE_global.h" 00056 #include "BKE_main.h" 00057 #include "BKE_sequencer.h" 00058 #include "BKE_report.h" 00059 #include "BKE_sound.h" 00060 00061 #include "WM_api.h" 00062 #include "WM_types.h" 00063 00064 #include "RNA_define.h" 00065 #include "RNA_enum_types.h" 00066 00067 /* for menu/popup icons etc etc*/ 00068 00069 #include "ED_screen.h" 00070 #include "ED_transform.h" 00071 #include "ED_sequencer.h" 00072 00073 #include "UI_view2d.h" 00074 00075 /* own include */ 00076 #include "sequencer_intern.h" 00077 00078 static void error(const char *UNUSED(dummy)) {} 00079 static void waitcursor(int UNUSED(val)) {} 00080 static void activate_fileselect(int UNUSED(d1), const char *UNUSED(d2), const char *UNUSED(d3), void *UNUSED(d4)) {} 00081 static int pupmenu(const char *UNUSED(dummy)) {return 0;} 00082 static int okee(const char *UNUSED(dummy)) {return 0;} 00083 00084 00085 /* XXX */ 00086 /* RNA Enums, used in multiple files */ 00087 EnumPropertyItem sequencer_prop_effect_types[] = { 00088 {SEQ_CROSS, "CROSS", 0, "Crossfade", "Crossfade effect strip type"}, 00089 {SEQ_ADD, "ADD", 0, "Add", "Add effect strip type"}, 00090 {SEQ_SUB, "SUBTRACT", 0, "Subtract", "Subtract effect strip type"}, 00091 {SEQ_ALPHAOVER, "ALPHA_OVER", 0, "Alpha Over", "Alpha Over effect strip type"}, 00092 {SEQ_ALPHAUNDER, "ALPHA_UNDER", 0, "Alpha Under", "Alpha Under effect strip type"}, 00093 {SEQ_GAMCROSS, "GAMMA_CROSS", 0, "Gamma Cross", "Gamma Cross effect strip type"}, 00094 {SEQ_MUL, "MULTIPLY", 0, "Multiply", "Multiply effect strip type"}, 00095 {SEQ_OVERDROP, "OVER_DROP", 0, "Alpha Over Drop", "Alpha Over Drop effect strip type"}, 00096 {SEQ_PLUGIN, "PLUGIN", 0, "Plugin", "Plugin effect strip type"}, 00097 {SEQ_WIPE, "WIPE", 0, "Wipe", "Wipe effect strip type"}, 00098 {SEQ_GLOW, "GLOW", 0, "Glow", "Glow effect strip type"}, 00099 {SEQ_TRANSFORM, "TRANSFORM", 0, "Transform", "Transform effect strip type"}, 00100 {SEQ_COLOR, "COLOR", 0, "Color", "Color effect strip type"}, 00101 {SEQ_SPEED, "SPEED", 0, "Speed", "Color effect strip type"}, 00102 {SEQ_MULTICAM, "MULTICAM", 0, "Multicam Selector", ""}, 00103 {SEQ_ADJUSTMENT, "ADJUSTMENT", 0, "Adjustment Layer", ""}, 00104 {0, NULL, 0, NULL, NULL} 00105 }; 00106 00107 /* mute operator */ 00108 00109 EnumPropertyItem prop_side_types[] = { 00110 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""}, 00111 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""}, 00112 {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""}, 00113 {0, NULL, 0, NULL, NULL} 00114 }; 00115 00116 static EnumPropertyItem prop_side_lr_types[] = { 00117 {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""}, 00118 {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""}, 00119 {0, NULL, 0, NULL, NULL} 00120 }; 00121 00122 typedef struct TransSeq { 00123 int start, machine; 00124 int startstill, endstill; 00125 int startdisp, enddisp; 00126 int startofs, endofs; 00127 int anim_startofs, anim_endofs; 00128 /* int final_left, final_right; */ /* UNUSED */ 00129 int len; 00130 } TransSeq; 00131 00132 void seq_rectf(Sequence *seq, rctf *rectf) 00133 { 00134 if(seq->startstill) rectf->xmin= seq->start; 00135 else rectf->xmin= seq->startdisp; 00136 rectf->ymin= seq->machine+SEQ_STRIP_OFSBOTTOM; 00137 if(seq->endstill) rectf->xmax= seq->start+seq->len; 00138 else rectf->xmax= seq->enddisp; 00139 rectf->ymax= seq->machine+SEQ_STRIP_OFSTOP; 00140 } 00141 00142 static void change_plugin_seq(Scene *scene, char *str) /* called from fileselect */ 00143 { 00144 Editing *ed= seq_give_editing(scene, FALSE); 00145 struct SeqEffectHandle sh; 00146 Sequence *last_seq= seq_active_get(scene); 00147 00148 if(last_seq==NULL || last_seq->type != SEQ_PLUGIN) return; 00149 00150 sh = get_sequence_effect(last_seq); 00151 sh.free(last_seq); 00152 sh.init_plugin(last_seq, str); 00153 00154 last_seq->machine = MAX3(last_seq->seq1->machine, 00155 last_seq->seq2->machine, 00156 last_seq->seq3->machine); 00157 00158 if( seq_test_overlap(ed->seqbasep, last_seq) ) shuffle_seq(ed->seqbasep, last_seq, scene); 00159 00160 } 00161 00162 00163 void boundbox_seq(Scene *scene, rctf *rect) 00164 { 00165 Sequence *seq; 00166 Editing *ed= seq_give_editing(scene, FALSE); 00167 float min[2], max[2]; 00168 00169 00170 if(ed==NULL) return; 00171 00172 min[0]= 0.0; 00173 max[0]= EFRA+1; 00174 min[1]= 0.0; 00175 max[1]= 8.0; 00176 00177 seq= ed->seqbasep->first; 00178 while(seq) { 00179 00180 if( min[0] > seq->startdisp-1) min[0]= seq->startdisp-1; 00181 if( max[0] < seq->enddisp+1) max[0]= seq->enddisp+1; 00182 if( max[1] < seq->machine+2) max[1]= seq->machine+2; 00183 00184 seq= seq->next; 00185 } 00186 00187 rect->xmin= min[0]; 00188 rect->xmax= max[0]; 00189 rect->ymin= min[1]; 00190 rect->ymax= max[1]; 00191 00192 } 00193 00194 static int mouse_frame_side(View2D *v2d, short mouse_x, int frame ) 00195 { 00196 int mval[2]; 00197 float mouseloc[2]; 00198 00199 mval[0]= mouse_x; 00200 mval[1]= 0; 00201 00202 /* choose the side based on which side of the playhead the mouse is on */ 00203 UI_view2d_region_to_view(v2d, mval[0], mval[1], &mouseloc[0], &mouseloc[1]); 00204 00205 return mouseloc[0] > frame ? SEQ_SIDE_RIGHT : SEQ_SIDE_LEFT; 00206 } 00207 00208 00209 Sequence *find_neighboring_sequence(Scene *scene, Sequence *test, int lr, int sel) 00210 { 00211 /* sel - 0==unselected, 1==selected, -1==done care*/ 00212 Sequence *seq; 00213 Editing *ed= seq_give_editing(scene, FALSE); 00214 00215 if(ed==NULL) return NULL; 00216 00217 if (sel>0) sel = SELECT; 00218 00219 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 00220 if( (seq!=test) && 00221 (test->machine==seq->machine) && 00222 ((sel == -1) || (sel && (seq->flag & SELECT)) || (sel==0 && (seq->flag & SELECT)==0) )) 00223 { 00224 switch (lr) { 00225 case SEQ_SIDE_LEFT: 00226 if (test->startdisp == (seq->enddisp)) { 00227 return seq; 00228 } 00229 break; 00230 case SEQ_SIDE_RIGHT: 00231 if (test->enddisp == (seq->startdisp)) { 00232 return seq; 00233 } 00234 break; 00235 } 00236 } 00237 } 00238 return NULL; 00239 } 00240 00241 static Sequence *find_next_prev_sequence(Scene *scene, Sequence *test, int lr, int sel) 00242 { 00243 /* sel - 0==unselected, 1==selected, -1==done care*/ 00244 Sequence *seq,*best_seq = NULL; 00245 Editing *ed= seq_give_editing(scene, FALSE); 00246 00247 int dist, best_dist; 00248 best_dist = MAXFRAME*2; 00249 00250 00251 if(ed==NULL) return NULL; 00252 00253 seq= ed->seqbasep->first; 00254 while(seq) { 00255 if( (seq!=test) && 00256 (test->machine==seq->machine) && 00257 (test->depth==seq->depth) && 00258 ((sel == -1) || (sel==(seq->flag & SELECT)))) 00259 { 00260 dist = MAXFRAME*2; 00261 00262 switch (lr) { 00263 case SEQ_SIDE_LEFT: 00264 if (seq->enddisp <= test->startdisp) { 00265 dist = test->enddisp - seq->startdisp; 00266 } 00267 break; 00268 case SEQ_SIDE_RIGHT: 00269 if (seq->startdisp >= test->enddisp) { 00270 dist = seq->startdisp - test->enddisp; 00271 } 00272 break; 00273 } 00274 00275 if (dist==0) { 00276 best_seq = seq; 00277 break; 00278 } else if (dist < best_dist) { 00279 best_dist = dist; 00280 best_seq = seq; 00281 } 00282 } 00283 seq= seq->next; 00284 } 00285 return best_seq; /* can be null */ 00286 } 00287 00288 00289 Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[2]) 00290 { 00291 Sequence *seq; 00292 Editing *ed= seq_give_editing(scene, FALSE); 00293 float x, y; 00294 float pixelx; 00295 float handsize; 00296 float displen; 00297 *hand= SEQ_SIDE_NONE; 00298 00299 00300 if(ed==NULL) return NULL; 00301 00302 pixelx = (v2d->cur.xmax - v2d->cur.xmin)/(v2d->mask.xmax - v2d->mask.xmin); 00303 00304 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y); 00305 00306 seq= ed->seqbasep->first; 00307 00308 while(seq) { 00309 if(seq->machine == (int)y) { 00310 /* check for both normal strips, and strips that have been flipped horizontally */ 00311 if( ((seq->startdisp < seq->enddisp) && (seq->startdisp<=x && seq->enddisp>=x)) || 00312 ((seq->startdisp > seq->enddisp) && (seq->startdisp>=x && seq->enddisp<=x)) ) 00313 { 00314 if(seq_tx_test(seq)) { 00315 00316 /* clamp handles to defined size in pixel space */ 00317 00318 handsize = seq->handsize; 00319 displen = (float)abs(seq->startdisp - seq->enddisp); 00320 00321 if (displen / pixelx > 16) { /* dont even try to grab the handles of small strips */ 00322 /* Set the max value to handle to 1/3 of the total len when its less then 28. 00323 * This is important because otherwise selecting handles happens even when you click in the middle */ 00324 00325 if ((displen/3) < 30*pixelx) { 00326 handsize = displen/3; 00327 } else { 00328 CLAMP(handsize, 7*pixelx, 30*pixelx); 00329 } 00330 00331 if( handsize+seq->startdisp >=x ) 00332 *hand= SEQ_SIDE_LEFT; 00333 else if( -handsize+seq->enddisp <=x ) 00334 *hand= SEQ_SIDE_RIGHT; 00335 } 00336 } 00337 return seq; 00338 } 00339 } 00340 seq= seq->next; 00341 } 00342 return NULL; 00343 } 00344 00345 00346 static int seq_is_parent(Sequence *par, Sequence *seq) 00347 { 00348 return ((par->seq1 == seq) || (par->seq2 == seq) || (par->seq3 == seq)); 00349 } 00350 00351 static int seq_is_predecessor(Sequence *pred, Sequence *seq) 00352 { 00353 if (!pred) return 0; 00354 if(pred == seq) return 0; 00355 else if(seq_is_parent(pred, seq)) return 1; 00356 else if(pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1; 00357 else if(pred->seq2 && seq_is_predecessor(pred->seq2, seq)) return 1; 00358 else if(pred->seq3 && seq_is_predecessor(pred->seq3, seq)) return 1; 00359 00360 return 0; 00361 } 00362 00363 void deselect_all_seq(Scene *scene) 00364 { 00365 Sequence *seq; 00366 Editing *ed= seq_give_editing(scene, FALSE); 00367 00368 00369 if(ed==NULL) return; 00370 00371 SEQP_BEGIN(ed, seq) { 00372 seq->flag &= ~SEQ_ALLSEL; 00373 } 00374 SEQ_END 00375 00376 } 00377 00378 void recurs_sel_seq(Sequence *seqm) 00379 { 00380 Sequence *seq; 00381 00382 seq= seqm->seqbase.first; 00383 while(seq) { 00384 00385 if(seqm->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL)) seq->flag &= ~SEQ_ALLSEL; 00386 else if(seqm->flag & SELECT) seq->flag |= SELECT; 00387 else seq->flag &= ~SEQ_ALLSEL; 00388 00389 if(seq->seqbase.first) recurs_sel_seq(seq); 00390 00391 seq= seq->next; 00392 } 00393 } 00394 00395 int event_to_efftype(int event) 00396 { 00397 if(event==2) return SEQ_CROSS; 00398 if(event==3) return SEQ_GAMCROSS; 00399 if(event==4) return SEQ_ADD; 00400 if(event==5) return SEQ_SUB; 00401 if(event==6) return SEQ_MUL; 00402 if(event==7) return SEQ_ALPHAOVER; 00403 if(event==8) return SEQ_ALPHAUNDER; 00404 if(event==9) return SEQ_OVERDROP; 00405 if(event==10) return SEQ_PLUGIN; 00406 if(event==13) return SEQ_WIPE; 00407 if(event==14) return SEQ_GLOW; 00408 if(event==15) return SEQ_TRANSFORM; 00409 if(event==16) return SEQ_COLOR; 00410 if(event==17) return SEQ_SPEED; 00411 if(event==18) return SEQ_ADJUSTMENT; 00412 return 0; 00413 } 00414 00415 #if 0 00416 static void reload_sound_strip(Scene *scene, char *name) 00417 { 00418 Editing *ed; 00419 Sequence *seq, *seqact; 00420 SpaceFile *sfile; 00421 Sequence *last_seq= seq_active_get(scene); 00422 00423 ed= scene->ed; 00424 00425 if(last_seq==0 || last_seq->type!=SEQ_SOUND) return; 00426 seqact= last_seq; /* last_seq changes in alloc_sequence */ 00427 00428 /* search sfile */ 00429 // sfile= scrarea_find_space_of_type(curarea, SPACE_FILE); 00430 if(sfile==0) return; 00431 00432 waitcursor(1); 00433 00434 seq = sfile_to_snd_sequence(sfile, seqact->start, seqact->machine); 00435 printf("seq->type: %i\n", seq->type); 00436 if(seq && seq!=seqact) { 00437 /* i'm not sure about this one, seems to work without it -- sgefant */ 00438 seq_free_strip(seqact->strip); 00439 00440 seqact->strip= seq->strip; 00441 00442 seqact->len= seq->len; 00443 calc_sequence(scene, seqact); 00444 00445 seq->strip= 0; 00446 seq_free_sequence(scene, seq); 00447 BLI_remlink(ed->seqbasep, seq); 00448 00449 seq= ed->seqbasep->first; 00450 00451 } 00452 00453 waitcursor(0); 00454 00455 } 00456 #endif 00457 00458 static void reload_image_strip(Scene *scene, char *UNUSED(name)) 00459 { 00460 Editing *ed= seq_give_editing(scene, FALSE); 00461 Sequence *seq=NULL, *seqact; 00462 SpaceFile *sfile=NULL; 00463 Sequence *last_seq= seq_active_get(scene); 00464 00465 00466 00467 if(last_seq==NULL || last_seq->type!=SEQ_IMAGE) return; 00468 seqact= last_seq; /* last_seq changes in alloc_sequence */ 00469 00470 /* search sfile */ 00471 // sfile= scrarea_find_space_of_type(curarea, SPACE_FILE); 00472 if(sfile == NULL) return; 00473 00474 waitcursor(1); 00475 00476 // seq= sfile_to_sequence(scene, sfile, seqact->start, seqact->machine, 1); // XXX ADD BACK 00477 if(seq && seq!=seqact) { 00478 seq_free_strip(seqact->strip); 00479 00480 seqact->strip= seq->strip; 00481 00482 seqact->len= seq->len; 00483 calc_sequence(scene, seqact); 00484 00485 seq->strip= NULL; 00486 seq_free_sequence(scene, seq); 00487 BLI_remlink(ed->seqbasep, seq); 00488 00489 update_changed_seq_and_deps(scene, seqact, 1, 1); 00490 } 00491 waitcursor(0); 00492 00493 } 00494 00495 00496 static void change_sequence(Scene *scene) 00497 { 00498 Editing *ed= seq_give_editing(scene, FALSE); 00499 Sequence *last_seq= seq_active_get(scene); 00500 Scene *sce; 00501 short event; 00502 00503 if(last_seq == NULL) return; 00504 00505 if(last_seq->type & SEQ_EFFECT) { 00506 event = pupmenu("Change Effect%t" 00507 "|Switch A <-> B %x1" 00508 "|Switch B <-> C %x10" 00509 "|Plugin%x11" 00510 "|Recalculate%x12" 00511 "|Cross%x2" 00512 "|Gamma Cross%x3" 00513 "|Add%x4" 00514 "|Sub%x5" 00515 "|Mul%x6" 00516 "|Alpha Over%x7" 00517 "|Alpha Under%x8" 00518 "|Alpha Over Drop%x9" 00519 "|Wipe%x13" 00520 "|Glow%x14" 00521 "|Transform%x15" 00522 "|Color Generator%x16" 00523 "|Speed Control%x17" 00524 "|Adjustment Layer%x18"); 00525 if(event > 0) { 00526 if(event==1) { 00527 SWAP(Sequence *,last_seq->seq1,last_seq->seq2); 00528 } 00529 else if(event==10) { 00530 SWAP(Sequence *,last_seq->seq2,last_seq->seq3); 00531 } 00532 else if(event==11) { 00533 activate_fileselect( 00534 FILE_SPECIAL, "Select Plugin", 00535 U.plugseqdir, change_plugin_seq); 00536 } 00537 else if(event==12); 00538 /* recalculate: only new_stripdata */ 00539 else { 00540 /* free previous effect and init new effect */ 00541 struct SeqEffectHandle sh; 00542 00543 if (get_sequence_effect_num_inputs( 00544 last_seq->type) 00545 < get_sequence_effect_num_inputs( 00546 event_to_efftype(event))) { 00547 error("New effect needs more " 00548 "input strips!"); 00549 } else { 00550 sh = get_sequence_effect(last_seq); 00551 sh.free(last_seq); 00552 00553 last_seq->type 00554 = event_to_efftype(event); 00555 00556 sh = get_sequence_effect(last_seq); 00557 sh.init(last_seq); 00558 } 00559 } 00560 00561 update_changed_seq_and_deps(scene, last_seq, 0, 1); 00562 } 00563 } 00564 else if(last_seq->type == SEQ_IMAGE) { 00565 if(okee("Change images")) { 00566 activate_fileselect(FILE_SPECIAL, 00567 "Select Images", 00568 ed->act_imagedir, 00569 reload_image_strip); 00570 } 00571 } 00572 else if(last_seq->type == SEQ_MOVIE) { 00573 ; 00574 } 00575 else if(last_seq->type == SEQ_SCENE) { 00576 event= pupmenu("Change Scene%t|Update Start and End"); 00577 00578 if(event==1) { 00579 sce= last_seq->scene; 00580 00581 last_seq->len= sce->r.efra - sce->r.sfra + 1; 00582 last_seq->sfra= sce->r.sfra; 00583 00584 /* bad code to change seq->len? update_changed_seq_and_deps() expects the strip->len to be OK */ 00585 new_tstripdata(last_seq); 00586 00587 update_changed_seq_and_deps(scene, last_seq, 1, 1); 00588 00589 } 00590 } 00591 00592 } 00593 00594 int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str) 00595 { 00596 Editing *ed = seq_give_editing(scene, FALSE); 00597 Sequence *seq1= NULL, *seq2= NULL, *seq3= NULL, *seq; 00598 00599 *error_str= NULL; 00600 00601 if (!activeseq) 00602 seq2= seq_active_get(scene); 00603 00604 for(seq=ed->seqbasep->first; seq; seq=seq->next) { 00605 if(seq->flag & SELECT) { 00606 if (seq->type == SEQ_SOUND && get_sequence_effect_num_inputs(type) != 0) { 00607 *error_str= "Can't apply effects to audio sequence strips"; 00608 return 0; 00609 } 00610 if((seq != activeseq) && (seq != seq2)) { 00611 if(seq2 == NULL) seq2= seq; 00612 else if(seq1 == NULL) seq1= seq; 00613 else if(seq3 == NULL) seq3= seq; 00614 else { 00615 *error_str= "Can't apply effect to more than 3 sequence strips"; 00616 return 0; 00617 } 00618 } 00619 } 00620 } 00621 00622 /* make sequence selection a little bit more intuitive 00623 for 3 strips: the last-strip should be sequence3 */ 00624 if (seq3 != NULL && seq2 != NULL) { 00625 Sequence *tmp = seq2; 00626 seq2 = seq3; 00627 seq3 = tmp; 00628 } 00629 00630 00631 switch(get_sequence_effect_num_inputs(type)) { 00632 case 0: 00633 *selseq1 = *selseq2 = *selseq3 = NULL; 00634 return 1; /* succsess */ 00635 case 1: 00636 if(seq2==NULL) { 00637 *error_str= "Need at least one selected sequence strip"; 00638 return 0; 00639 } 00640 if(seq1==NULL) seq1= seq2; 00641 if(seq3==NULL) seq3= seq2; 00642 case 2: 00643 if(seq1==NULL || seq2==NULL) { 00644 *error_str= "Need 2 selected sequence strips"; 00645 return 0; 00646 } 00647 if(seq3 == NULL) seq3= seq2; 00648 } 00649 00650 if (seq1==NULL && seq2==NULL && seq3==NULL) { 00651 *error_str= "TODO: in what cases does this happen?"; 00652 return 0; 00653 } 00654 00655 *selseq1= seq1; 00656 *selseq2= seq2; 00657 *selseq3= seq3; 00658 00659 return 1; 00660 } 00661 00662 static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq) 00663 { 00664 Sequence *seq1, *seq2, *seq3; 00665 00666 /* try to find a replacement input sequence, and flag for later deletion if 00667 no replacement can be found */ 00668 00669 if(!seq) 00670 return NULL; 00671 else if(!(seq->type & SEQ_EFFECT)) 00672 return ((seq->flag & SELECT)? NULL: seq); 00673 else if(!(seq->flag & SELECT)) { 00674 /* try to find replacement for effect inputs */ 00675 seq1= del_seq_find_replace_recurs(scene, seq->seq1); 00676 seq2= del_seq_find_replace_recurs(scene, seq->seq2); 00677 seq3= del_seq_find_replace_recurs(scene, seq->seq3); 00678 00679 if(seq1==seq->seq1 && seq2==seq->seq2 && seq3==seq->seq3); 00680 else if(seq1 || seq2 || seq3) { 00681 seq->seq1= (seq1)? seq1: (seq2)? seq2: seq3; 00682 seq->seq2= (seq2)? seq2: (seq1)? seq1: seq3; 00683 seq->seq3= (seq3)? seq3: (seq1)? seq1: seq2; 00684 00685 update_changed_seq_and_deps(scene, seq, 1, 1); 00686 } 00687 else 00688 seq->flag |= SELECT; /* mark for delete */ 00689 } 00690 00691 if (seq->flag & SELECT) { 00692 if((seq1 = del_seq_find_replace_recurs(scene, seq->seq1))) return seq1; 00693 if((seq2 = del_seq_find_replace_recurs(scene, seq->seq2))) return seq2; 00694 if((seq3 = del_seq_find_replace_recurs(scene, seq->seq3))) return seq3; 00695 else return NULL; 00696 } 00697 else 00698 return seq; 00699 } 00700 00701 static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall) 00702 { 00703 Sequence *seq, *seqn; 00704 Sequence *last_seq = seq_active_get(scene); 00705 00706 seq= lb->first; 00707 while(seq) { 00708 seqn= seq->next; 00709 if((seq->flag & flag) || deleteall) { 00710 BLI_remlink(lb, seq); 00711 if(seq==last_seq) seq_active_set(scene, NULL); 00712 if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1); 00713 seq_free_sequence(scene, seq); 00714 } 00715 seq= seqn; 00716 } 00717 } 00718 00719 00720 static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe) 00721 { 00722 TransSeq ts; 00723 Sequence *seqn = NULL; 00724 int skip_dup = FALSE; 00725 00726 /* backup values */ 00727 ts.start= seq->start; 00728 ts.machine= seq->machine; 00729 ts.startstill= seq->startstill; 00730 ts.endstill= seq->endstill; 00731 ts.startdisp= seq->startdisp; 00732 ts.enddisp= seq->enddisp; 00733 ts.startofs= seq->startofs; 00734 ts.endofs= seq->endofs; 00735 ts.anim_startofs= seq->anim_startofs; 00736 ts.anim_endofs= seq->anim_endofs; 00737 ts.len= seq->len; 00738 00739 /* First Strip! */ 00740 /* strips with extended stillfames before */ 00741 00742 if ((seq->startstill) && (cutframe <seq->start)) { 00743 /* don't do funny things with METAs ... */ 00744 if (seq->type == SEQ_META) { 00745 skip_dup = TRUE; 00746 seq->startstill = seq->start - cutframe; 00747 } else { 00748 seq->start= cutframe -1; 00749 seq->startstill= cutframe -seq->startdisp -1; 00750 seq->anim_endofs += seq->len - 1; 00751 seq->endstill= 0; 00752 } 00753 } 00754 /* normal strip */ 00755 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) { 00756 seq->endofs = 0; 00757 seq->endstill = 0; 00758 seq->anim_endofs += (seq->start+seq->len) - cutframe; 00759 } 00760 /* strips with extended stillframes after */ 00761 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) { 00762 seq->endstill -= seq->enddisp - cutframe; 00763 /* don't do funny things with METAs ... */ 00764 if (seq->type == SEQ_META) { 00765 skip_dup = TRUE; 00766 } 00767 } 00768 00769 reload_sequence_new_file(scene, seq, FALSE); 00770 calc_sequence(scene, seq); 00771 new_tstripdata(seq); 00772 00773 if (!skip_dup) { 00774 /* Duplicate AFTER the first change */ 00775 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); 00776 } 00777 00778 if (seqn) { 00779 seqn->flag |= SELECT; 00780 00781 /* Second Strip! */ 00782 /* strips with extended stillframes before */ 00783 if ((seqn->startstill) && (cutframe == seqn->start + 1)) { 00784 seqn->start = ts.start; 00785 seqn->startstill= ts.start- cutframe; 00786 seqn->anim_endofs = ts.anim_endofs; 00787 seqn->endstill = ts.endstill; 00788 } 00789 00790 /* normal strip */ 00791 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) { 00792 seqn->start = cutframe; 00793 seqn->startstill = 0; 00794 seqn->startofs = 0; 00795 seqn->endofs = ts.endofs; 00796 seqn->anim_startofs += cutframe - ts.start; 00797 seqn->anim_endofs = ts.anim_endofs; 00798 seqn->endstill = ts.endstill; 00799 } 00800 00801 /* strips with extended stillframes after */ 00802 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) { 00803 seqn->start = cutframe; 00804 seqn->startofs = 0; 00805 seqn->anim_startofs += ts.len-1; 00806 seqn->endstill = ts.enddisp - cutframe -1; 00807 seqn->startstill = 0; 00808 } 00809 00810 reload_sequence_new_file(scene, seqn, FALSE); 00811 calc_sequence(scene, seqn); 00812 new_tstripdata(seqn); 00813 } 00814 return seqn; 00815 } 00816 00817 static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe) 00818 { 00819 TransSeq ts; 00820 Sequence *seqn = NULL; 00821 int skip_dup = FALSE; 00822 00823 /* backup values */ 00824 ts.start= seq->start; 00825 ts.machine= seq->machine; 00826 ts.startstill= seq->startstill; 00827 ts.endstill= seq->endstill; 00828 ts.startdisp= seq->startdisp; 00829 ts.enddisp= seq->enddisp; 00830 ts.startofs= seq->startofs; 00831 ts.endofs= seq->endofs; 00832 ts.anim_startofs= seq->anim_startofs; 00833 ts.anim_endofs= seq->anim_endofs; 00834 ts.len= seq->len; 00835 00836 /* First Strip! */ 00837 /* strips with extended stillfames before */ 00838 00839 if ((seq->startstill) && (cutframe <seq->start)) { 00840 /* don't do funny things with METAs ... */ 00841 if (seq->type == SEQ_META) { 00842 skip_dup = TRUE; 00843 seq->startstill = seq->start - cutframe; 00844 } else { 00845 seq->start= cutframe -1; 00846 seq->startstill= cutframe -seq->startdisp -1; 00847 seq->endofs = seq->len - 1; 00848 seq->endstill= 0; 00849 } 00850 } 00851 /* normal strip */ 00852 else if ((cutframe >=seq->start)&&(cutframe <=(seq->start+seq->len))) { 00853 seq->endofs = (seq->start+seq->len) - cutframe; 00854 } 00855 /* strips with extended stillframes after */ 00856 else if (((seq->start+seq->len) < cutframe) && (seq->endstill)) { 00857 seq->endstill -= seq->enddisp - cutframe; 00858 /* don't do funny things with METAs ... */ 00859 if (seq->type == SEQ_META) { 00860 skip_dup = TRUE; 00861 } 00862 } 00863 00864 calc_sequence(scene, seq); 00865 new_tstripdata(seq); 00866 00867 if (!skip_dup) { 00868 /* Duplicate AFTER the first change */ 00869 seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); 00870 } 00871 00872 if (seqn) { 00873 seqn->flag |= SELECT; 00874 00875 /* Second Strip! */ 00876 /* strips with extended stillframes before */ 00877 if ((seqn->startstill) && (cutframe == seqn->start + 1)) { 00878 seqn->start = ts.start; 00879 seqn->startstill= ts.start- cutframe; 00880 seqn->endofs = ts.endofs; 00881 seqn->endstill = ts.endstill; 00882 } 00883 00884 /* normal strip */ 00885 else if ((cutframe>=seqn->start)&&(cutframe<=(seqn->start+seqn->len))) { 00886 seqn->startstill = 0; 00887 seqn->startofs = cutframe - ts.start; 00888 seqn->endofs = ts.endofs; 00889 seqn->endstill = ts.endstill; 00890 } 00891 00892 /* strips with extended stillframes after */ 00893 else if (((seqn->start+seqn->len) < cutframe) && (seqn->endstill)) { 00894 seqn->start = cutframe - ts.len +1; 00895 seqn->startofs = ts.len-1; 00896 seqn->endstill = ts.enddisp - cutframe -1; 00897 seqn->startstill = 0; 00898 } 00899 00900 calc_sequence(scene, seqn); 00901 new_tstripdata(seqn); 00902 } 00903 return seqn; 00904 } 00905 00906 00907 /* like duplicate, but only duplicate and cut overlapping strips, 00908 * strips to the left of the cutframe are ignored and strips to the right are moved into the new list */ 00909 static int cut_seq_list(Scene *scene, ListBase *old, ListBase *new, int cutframe, 00910 Sequence * (*cut_seq)(Scene *, Sequence *, int)) 00911 { 00912 int did_something = FALSE; 00913 Sequence *seq, *seq_next_iter; 00914 00915 seq= old->first; 00916 00917 while(seq) { 00918 seq_next_iter = seq->next; /* we need this because we may remove seq */ 00919 00920 seq->tmp= NULL; 00921 if(seq->flag & SELECT) { 00922 if(cutframe > seq->startdisp && 00923 cutframe < seq->enddisp) { 00924 Sequence * seqn = cut_seq(scene, seq, cutframe); 00925 if (seqn) { 00926 BLI_addtail(new, seqn); 00927 } 00928 did_something = TRUE; 00929 } else if (seq->enddisp <= cutframe) { 00930 /* do nothing */ 00931 } else if (seq->startdisp >= cutframe) { 00932 /* move into new list */ 00933 BLI_remlink(old, seq); 00934 BLI_addtail(new, seq); 00935 } 00936 } 00937 seq = seq_next_iter; 00938 } 00939 return did_something; 00940 } 00941 00942 static int insert_gap(Scene *scene, int gap, int cfra) 00943 { 00944 Sequence *seq; 00945 Editing *ed= seq_give_editing(scene, FALSE); 00946 int done=0; 00947 00948 /* all strips >= cfra are shifted */ 00949 00950 if(ed==NULL) return 0; 00951 00952 SEQP_BEGIN(ed, seq) { 00953 if(seq->startdisp >= cfra) { 00954 seq->start+= gap; 00955 calc_sequence(scene, seq); 00956 done= 1; 00957 } 00958 } 00959 SEQ_END 00960 00961 return done; 00962 } 00963 00964 static void touch_seq_files(Scene *scene) 00965 { 00966 Sequence *seq; 00967 Editing *ed= seq_give_editing(scene, FALSE); 00968 char str[256]; 00969 00970 /* touch all strips with movies */ 00971 00972 if(ed==NULL) return; 00973 00974 if(okee("Touch and print selected movies")==0) return; 00975 00976 waitcursor(1); 00977 00978 SEQP_BEGIN(ed, seq) { 00979 if(seq->flag & SELECT) { 00980 if(seq->type==SEQ_MOVIE) { 00981 if(seq->strip && seq->strip->stripdata) { 00982 BLI_make_file_string(G.main->name, str, seq->strip->dir, seq->strip->stripdata->name); 00983 BLI_touch(seq->name); 00984 } 00985 } 00986 00987 } 00988 } 00989 SEQ_END 00990 00991 waitcursor(0); 00992 } 00993 00994 /* 00995 static void set_filter_seq(Scene *scene) 00996 { 00997 Sequence *seq; 00998 Editing *ed= seq_give_editing(scene, FALSE); 00999 01000 01001 if(ed==NULL) return; 01002 01003 if(okee("Set Deinterlace")==0) return; 01004 01005 SEQP_BEGIN(ed, seq) { 01006 if(seq->flag & SELECT) { 01007 if(seq->type==SEQ_MOVIE) { 01008 seq->flag |= SEQ_FILTERY; 01009 reload_sequence_new_file(scene, seq, FALSE); 01010 calc_sequence(scene, seq); 01011 } 01012 01013 } 01014 } 01015 SEQ_END 01016 } 01017 */ 01018 01019 static void seq_remap_paths(Scene *scene) 01020 { 01021 Sequence *seq, *last_seq = seq_active_get(scene); 01022 Editing *ed= seq_give_editing(scene, FALSE); 01023 char from[FILE_MAX], to[FILE_MAX], stripped[FILE_MAX]; 01024 01025 01026 if(last_seq==NULL) 01027 return; 01028 01029 BLI_strncpy(from, last_seq->strip->dir, FILE_MAX); 01030 // XXX if (0==sbutton(from, 0, sizeof(from)-1, "From: ")) 01031 // return; 01032 01033 strcpy(to, from); 01034 // XXX if (0==sbutton(to, 0, sizeof(to)-1, "To: ")) 01035 // return; 01036 01037 if (strcmp(to, from)==0) 01038 return; 01039 01040 SEQP_BEGIN(ed, seq) { 01041 if(seq->flag & SELECT) { 01042 if(strncmp(seq->strip->dir, from, strlen(from))==0) { 01043 printf("found %s\n", seq->strip->dir); 01044 01045 /* strip off the beginning */ 01046 stripped[0]= 0; 01047 BLI_strncpy(stripped, seq->strip->dir + strlen(from), FILE_MAX); 01048 01049 /* new path */ 01050 BLI_snprintf(seq->strip->dir, sizeof(seq->strip->dir), "%s%s", to, stripped); 01051 printf("new %s\n", seq->strip->dir); 01052 } 01053 } 01054 } 01055 SEQ_END 01056 01057 } 01058 01059 01060 static void no_gaps(Scene *scene) 01061 { 01062 Editing *ed= seq_give_editing(scene, FALSE); 01063 int cfra, first= 0, done; 01064 01065 01066 if(ed==NULL) return; 01067 01068 for(cfra= CFRA; cfra<=EFRA; cfra++) { 01069 if(first==0) { 01070 if( evaluate_seq_frame(scene, cfra) ) first= 1; 01071 } 01072 else { 01073 done= 1; 01074 while( evaluate_seq_frame(scene, cfra) == 0) { 01075 done= insert_gap(scene, -1, cfra); 01076 if(done==0) break; 01077 } 01078 if(done==0) break; 01079 } 01080 } 01081 01082 } 01083 01084 #if 0 01085 static int seq_get_snaplimit(View2D *v2d) 01086 { 01087 /* fake mouse coords to get the snap value 01088 a bit lazy but its only done once pre transform */ 01089 float xmouse, ymouse, x; 01090 int mval[2] = {24, 0}; /* 24 screen px snap */ 01091 01092 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse); 01093 x = xmouse; 01094 mval[0] = 0; 01095 UI_view2d_region_to_view(v2d, mval[0], mval[1], &xmouse, &ymouse); 01096 return (int)(x - xmouse); 01097 } 01098 #endif 01099 01100 /* Operator functions */ 01101 int sequencer_edit_poll(bContext *C) 01102 { 01103 return (seq_give_editing(CTX_data_scene(C), FALSE) != NULL); 01104 } 01105 01106 int sequencer_view_poll(bContext *C) 01107 { 01108 SpaceSeq *sseq= CTX_wm_space_seq(C); 01109 Editing *ed= seq_give_editing(CTX_data_scene(C), FALSE); 01110 if (ed && sseq && (sseq->mainb == SEQ_DRAW_IMG_IMBUF)) 01111 return 1; 01112 01113 return 0; 01114 } 01115 01116 /* snap operator*/ 01117 static int sequencer_snap_exec(bContext *C, wmOperator *op) 01118 { 01119 Scene *scene= CTX_data_scene(C); 01120 01121 Editing *ed= seq_give_editing(scene, FALSE); 01122 Sequence *seq; 01123 int snap_frame; 01124 01125 snap_frame= RNA_int_get(op->ptr, "frame"); 01126 01127 /* also check metas */ 01128 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01129 if (seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK) && 01130 seq_tx_test(seq)) { 01131 if((seq->flag & (SEQ_LEFTSEL+SEQ_RIGHTSEL))==0) { 01132 /* simple but no anim update */ 01133 /* seq->start= snap_frame-seq->startofs+seq->startstill; */ 01134 01135 seq_translate(scene, seq, (snap_frame-seq->startofs+seq->startstill) - seq->start); 01136 } else { 01137 if(seq->flag & SEQ_LEFTSEL) { 01138 seq_tx_set_final_left(seq, snap_frame); 01139 } else { /* SEQ_RIGHTSEL */ 01140 seq_tx_set_final_right(seq, snap_frame); 01141 } 01142 seq_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL); 01143 } 01144 calc_sequence(scene, seq); 01145 } 01146 } 01147 01148 /* test for effects and overlap 01149 * dont use SEQP_BEGIN since that would be recursive */ 01150 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01151 if(seq->flag & SELECT && !(seq->depth==0 && seq->flag & SEQ_LOCK)) { 01152 seq->flag &= ~SEQ_OVERLAP; 01153 if( seq_test_overlap(ed->seqbasep, seq) ) { 01154 shuffle_seq(ed->seqbasep, seq, scene); 01155 } 01156 } 01157 else if(seq->type & SEQ_EFFECT) { 01158 if(seq->seq1 && (seq->seq1->flag & SELECT)) 01159 calc_sequence(scene, seq); 01160 else if(seq->seq2 && (seq->seq2->flag & SELECT)) 01161 calc_sequence(scene, seq); 01162 else if(seq->seq3 && (seq->seq3->flag & SELECT)) 01163 calc_sequence(scene, seq); 01164 } 01165 } 01166 01167 /* as last: */ 01168 sort_seq(scene); 01169 01170 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01171 01172 return OPERATOR_FINISHED; 01173 } 01174 01175 static int sequencer_snap_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 01176 { 01177 Scene *scene = CTX_data_scene(C); 01178 01179 int snap_frame; 01180 01181 snap_frame= CFRA; 01182 01183 RNA_int_set(op->ptr, "frame", snap_frame); 01184 return sequencer_snap_exec(C, op); 01185 } 01186 01187 void SEQUENCER_OT_snap(struct wmOperatorType *ot) 01188 { 01189 /* identifiers */ 01190 ot->name= "Snap strips"; 01191 ot->idname= "SEQUENCER_OT_snap"; 01192 ot->description="Frame where selected strips will be snapped"; 01193 01194 /* api callbacks */ 01195 ot->invoke= sequencer_snap_invoke; 01196 ot->exec= sequencer_snap_exec; 01197 ot->poll= sequencer_edit_poll; 01198 01199 /* flags */ 01200 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01201 01202 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be snapped", INT_MIN, INT_MAX); 01203 } 01204 01205 /* mute operator */ 01206 static int sequencer_mute_exec(bContext *C, wmOperator *op) 01207 { 01208 Scene *scene= CTX_data_scene(C); 01209 Editing *ed= seq_give_editing(scene, FALSE); 01210 Sequence *seq; 01211 int selected; 01212 01213 selected= !RNA_boolean_get(op->ptr, "unselected"); 01214 01215 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01216 if ((seq->flag & SEQ_LOCK)==0) { 01217 if(selected){ /* mute unselected */ 01218 if(seq->flag & SELECT) 01219 seq->flag |= SEQ_MUTE; 01220 } 01221 else { 01222 if((seq->flag & SELECT)==0) 01223 seq->flag |= SEQ_MUTE; 01224 } 01225 } 01226 } 01227 01228 seq_update_muting(scene, ed); 01229 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01230 01231 return OPERATOR_FINISHED; 01232 } 01233 01234 void SEQUENCER_OT_mute(struct wmOperatorType *ot) 01235 { 01236 /* identifiers */ 01237 ot->name= "Mute Strips"; 01238 ot->idname= "SEQUENCER_OT_mute"; 01239 ot->description="Mute selected strips"; 01240 01241 /* api callbacks */ 01242 ot->exec= sequencer_mute_exec; 01243 ot->poll= sequencer_edit_poll; 01244 01245 /* flags */ 01246 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01247 01248 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Mute unselected rather than selected strips."); 01249 } 01250 01251 01252 /* unmute operator */ 01253 static int sequencer_unmute_exec(bContext *C, wmOperator *op) 01254 { 01255 Scene *scene= CTX_data_scene(C); 01256 Editing *ed= seq_give_editing(scene, FALSE); 01257 Sequence *seq; 01258 int selected; 01259 01260 selected= !RNA_boolean_get(op->ptr, "unselected"); 01261 01262 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01263 if ((seq->flag & SEQ_LOCK)==0) { 01264 if(selected){ /* unmute unselected */ 01265 if(seq->flag & SELECT) 01266 seq->flag &= ~SEQ_MUTE; 01267 } 01268 else { 01269 if((seq->flag & SELECT)==0) 01270 seq->flag &= ~SEQ_MUTE; 01271 } 01272 } 01273 } 01274 01275 seq_update_muting(scene, ed); 01276 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01277 01278 return OPERATOR_FINISHED; 01279 } 01280 01281 void SEQUENCER_OT_unmute(struct wmOperatorType *ot) 01282 { 01283 /* identifiers */ 01284 ot->name= "Un-Mute Strips"; 01285 ot->idname= "SEQUENCER_OT_unmute"; 01286 ot->description="Un-Mute unselected rather than selected strips"; 01287 01288 /* api callbacks */ 01289 ot->exec= sequencer_unmute_exec; 01290 ot->poll= sequencer_edit_poll; 01291 01292 /* flags */ 01293 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01294 01295 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "UnMute unselected rather than selected strips."); 01296 } 01297 01298 01299 /* lock operator */ 01300 static int sequencer_lock_exec(bContext *C, wmOperator *UNUSED(op)) 01301 { 01302 Scene *scene= CTX_data_scene(C); 01303 Editing *ed= seq_give_editing(scene, FALSE); 01304 Sequence *seq; 01305 01306 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01307 if (seq->flag & SELECT) { 01308 seq->flag |= SEQ_LOCK; 01309 } 01310 } 01311 01312 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01313 01314 return OPERATOR_FINISHED; 01315 } 01316 01317 void SEQUENCER_OT_lock(struct wmOperatorType *ot) 01318 { 01319 /* identifiers */ 01320 ot->name= "Lock Strips"; 01321 ot->idname= "SEQUENCER_OT_lock"; 01322 ot->description="Lock the active strip so that it can't be transformed"; 01323 01324 /* api callbacks */ 01325 ot->exec= sequencer_lock_exec; 01326 ot->poll= sequencer_edit_poll; 01327 01328 /* flags */ 01329 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01330 } 01331 01332 /* unlock operator */ 01333 static int sequencer_unlock_exec(bContext *C, wmOperator *UNUSED(op)) 01334 { 01335 Scene *scene= CTX_data_scene(C); 01336 Editing *ed= seq_give_editing(scene, FALSE); 01337 Sequence *seq; 01338 01339 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01340 if (seq->flag & SELECT) { 01341 seq->flag &= ~SEQ_LOCK; 01342 } 01343 } 01344 01345 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01346 01347 return OPERATOR_FINISHED; 01348 } 01349 01350 void SEQUENCER_OT_unlock(struct wmOperatorType *ot) 01351 { 01352 /* identifiers */ 01353 ot->name= "UnLock Strips"; 01354 ot->idname= "SEQUENCER_OT_unlock"; 01355 ot->description="Unlock the active strip so that it can't be transformed"; 01356 01357 /* api callbacks */ 01358 ot->exec= sequencer_unlock_exec; 01359 ot->poll= sequencer_edit_poll; 01360 01361 /* flags */ 01362 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01363 } 01364 01365 /* reload operator */ 01366 static int sequencer_reload_exec(bContext *C, wmOperator *UNUSED(op)) 01367 { 01368 Scene *scene= CTX_data_scene(C); 01369 Editing *ed= seq_give_editing(scene, FALSE); 01370 Sequence *seq; 01371 01372 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 01373 if(seq->flag & SELECT) { 01374 update_changed_seq_and_deps(scene, seq, 0, 1); 01375 } 01376 } 01377 01378 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01379 01380 return OPERATOR_FINISHED; 01381 } 01382 01383 void SEQUENCER_OT_reload(struct wmOperatorType *ot) 01384 { 01385 /* identifiers */ 01386 ot->name= "Reload Strips"; 01387 ot->idname= "SEQUENCER_OT_reload"; 01388 ot->description="Reload strips in the sequencer"; 01389 01390 /* api callbacks */ 01391 ot->exec= sequencer_reload_exec; 01392 ot->poll= sequencer_edit_poll; 01393 01394 /* flags */ 01395 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01396 } 01397 01398 /* reload operator */ 01399 static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op)) 01400 { 01401 Scene *scene= CTX_data_scene(C); 01402 Editing *ed= seq_give_editing(scene, FALSE); 01403 01404 free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); 01405 01406 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01407 01408 return OPERATOR_FINISHED; 01409 } 01410 01411 void SEQUENCER_OT_refresh_all(struct wmOperatorType *ot) 01412 { 01413 /* identifiers */ 01414 ot->name= "Refresh Sequencer"; 01415 ot->idname= "SEQUENCER_OT_refresh_all"; 01416 ot->description="Refresh the sequencer editor"; 01417 01418 /* api callbacks */ 01419 ot->exec= sequencer_refresh_all_exec; 01420 ot->poll= sequencer_edit_poll; 01421 01422 /* flags */ 01423 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01424 } 01425 01426 static int sequencer_reassign_inputs_exec(bContext *C, wmOperator *op) 01427 { 01428 Scene *scene= CTX_data_scene(C); 01429 Sequence *seq1, *seq2, *seq3, *last_seq = seq_active_get(scene); 01430 const char *error_msg; 01431 01432 if(!seq_effect_find_selected(scene, last_seq, last_seq->type, &seq1, &seq2, &seq3, &error_msg)) { 01433 BKE_report(op->reports, RPT_ERROR, error_msg); 01434 return OPERATOR_CANCELLED; 01435 } 01436 /* see reassigning would create a cycle */ 01437 if( seq_is_predecessor(seq1, last_seq) || 01438 seq_is_predecessor(seq2, last_seq) || 01439 seq_is_predecessor(seq3, last_seq) 01440 ) { 01441 BKE_report(op->reports, RPT_ERROR, "Can't reassign inputs: no cycles allowed"); 01442 return OPERATOR_CANCELLED; 01443 } 01444 01445 last_seq->seq1 = seq1; 01446 last_seq->seq2 = seq2; 01447 last_seq->seq3 = seq3; 01448 01449 update_changed_seq_and_deps(scene, last_seq, 1, 1); 01450 01451 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01452 01453 return OPERATOR_FINISHED; 01454 } 01455 01456 static int sequencer_effect_poll(bContext *C) 01457 { 01458 Scene *scene= CTX_data_scene(C); 01459 Editing *ed= seq_give_editing(scene, FALSE); 01460 01461 if(ed) { 01462 Sequence *last_seq= seq_active_get(scene); 01463 if(last_seq && (last_seq->type & SEQ_EFFECT)) { 01464 return 1; 01465 } 01466 } 01467 01468 return 0; 01469 } 01470 01471 void SEQUENCER_OT_reassign_inputs(struct wmOperatorType *ot) 01472 { 01473 /* identifiers */ 01474 ot->name= "Reassign Inputs"; 01475 ot->idname= "SEQUENCER_OT_reassign_inputs"; 01476 ot->description="Reassign the inputs for the effects strip"; 01477 01478 /* api callbacks */ 01479 ot->exec= sequencer_reassign_inputs_exec; 01480 ot->poll= sequencer_effect_poll; 01481 01482 /* flags */ 01483 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01484 } 01485 01486 01487 static int sequencer_swap_inputs_exec(bContext *C, wmOperator *op) 01488 { 01489 Scene *scene= CTX_data_scene(C); 01490 Sequence *seq, *last_seq = seq_active_get(scene); 01491 01492 if(last_seq->seq1==NULL || last_seq->seq2 == NULL) { 01493 BKE_report(op->reports, RPT_ERROR, "No valid inputs to swap"); 01494 return OPERATOR_CANCELLED; 01495 } 01496 01497 seq = last_seq->seq1; 01498 last_seq->seq1 = last_seq->seq2; 01499 last_seq->seq2 = seq; 01500 01501 update_changed_seq_and_deps(scene, last_seq, 1, 1); 01502 01503 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01504 01505 return OPERATOR_FINISHED; 01506 } 01507 void SEQUENCER_OT_swap_inputs(struct wmOperatorType *ot) 01508 { 01509 /* identifiers */ 01510 ot->name= "Swap Inputs"; 01511 ot->idname= "SEQUENCER_OT_swap_inputs"; 01512 ot->description="Swap the first two inputs for the effects strip"; 01513 01514 /* api callbacks */ 01515 ot->exec= sequencer_swap_inputs_exec; 01516 ot->poll= sequencer_effect_poll; 01517 01518 /* flags */ 01519 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01520 } 01521 01522 01523 /* cut operator */ 01524 static EnumPropertyItem prop_cut_types[] = { 01525 {SEQ_CUT_SOFT, "SOFT", 0, "Soft", ""}, 01526 {SEQ_CUT_HARD, "HARD", 0, "Hard", ""}, 01527 {0, NULL, 0, NULL, NULL} 01528 }; 01529 01530 static int sequencer_cut_exec(bContext *C, wmOperator *op) 01531 { 01532 Scene *scene= CTX_data_scene(C); 01533 Editing *ed= seq_give_editing(scene, FALSE); 01534 int cut_side, cut_hard, cut_frame; 01535 01536 ListBase newlist; 01537 int changed; 01538 01539 cut_frame= RNA_int_get(op->ptr, "frame"); 01540 cut_hard= RNA_enum_get(op->ptr, "type"); 01541 cut_side= RNA_enum_get(op->ptr, "side"); 01542 01543 newlist.first= newlist.last= NULL; 01544 01545 if (cut_hard==SEQ_CUT_HARD) { 01546 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_hard); 01547 } else { 01548 changed = cut_seq_list(scene, ed->seqbasep, &newlist, cut_frame, cut_seq_soft); 01549 } 01550 01551 if (newlist.first) { /* got new strips ? */ 01552 Sequence *seq; 01553 BLI_movelisttolist(ed->seqbasep, &newlist); 01554 01555 if (cut_side != SEQ_SIDE_BOTH) { 01556 SEQP_BEGIN(ed, seq) { 01557 if (cut_side==SEQ_SIDE_LEFT) { 01558 if ( seq->startdisp >= cut_frame ) { 01559 seq->flag &= ~SEQ_ALLSEL; 01560 } 01561 } else { 01562 if ( seq->enddisp <= cut_frame ) { 01563 seq->flag &= ~SEQ_ALLSEL; 01564 } 01565 } 01566 } 01567 SEQ_END; 01568 } 01569 /* as last: */ 01570 sort_seq(scene); 01571 } 01572 01573 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01574 01575 return OPERATOR_FINISHED; 01576 } 01577 01578 01579 static int sequencer_cut_invoke(bContext *C, wmOperator *op, wmEvent *event) 01580 { 01581 Scene *scene = CTX_data_scene(C); 01582 View2D *v2d= UI_view2d_fromcontext(C); 01583 01584 int cut_side= SEQ_SIDE_BOTH; 01585 int cut_frame= CFRA; 01586 01587 if (ED_operator_sequencer_active(C) && v2d) 01588 cut_side= mouse_frame_side(v2d, event->mval[0], cut_frame); 01589 01590 RNA_int_set(op->ptr, "frame", cut_frame); 01591 RNA_enum_set(op->ptr, "side", cut_side); 01592 /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */ 01593 01594 return sequencer_cut_exec(C, op); 01595 } 01596 01597 01598 void SEQUENCER_OT_cut(struct wmOperatorType *ot) 01599 { 01600 /* identifiers */ 01601 ot->name= "Cut Strips"; 01602 ot->idname= "SEQUENCER_OT_cut"; 01603 ot->description="Cut the selected strips"; 01604 01605 /* api callbacks */ 01606 ot->invoke= sequencer_cut_invoke; 01607 ot->exec= sequencer_cut_exec; 01608 ot->poll= sequencer_edit_poll; 01609 01610 /* flags */ 01611 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01612 01613 RNA_def_int(ot->srna, "frame", 0, INT_MIN, INT_MAX, "Frame", "Frame where selected strips will be cut", INT_MIN, INT_MAX); 01614 RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips"); 01615 RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting"); 01616 } 01617 01618 /* duplicate operator */ 01619 static int apply_unique_name_cb(Sequence *seq, void *arg_pt) 01620 { 01621 Scene *scene= (Scene *)arg_pt; 01622 char name[sizeof(seq->name)-2]; 01623 01624 strcpy(name, seq->name+2); 01625 seqbase_unique_name_recursive(&scene->ed->seqbase, seq); 01626 seq_dupe_animdata(scene, name, seq->name+2); 01627 return 1; 01628 01629 } 01630 01631 static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) 01632 { 01633 Scene *scene= CTX_data_scene(C); 01634 Editing *ed= seq_give_editing(scene, FALSE); 01635 01636 ListBase nseqbase= {NULL, NULL}; 01637 01638 if(ed==NULL) 01639 return OPERATOR_CANCELLED; 01640 01641 seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT); 01642 01643 if(nseqbase.first) { 01644 Sequence * seq= nseqbase.first; 01645 /* rely on the nseqbase list being added at the end */ 01646 BLI_movelisttolist(ed->seqbasep, &nseqbase); 01647 01648 for( ; seq; seq= seq->next) 01649 seq_recursive_apply(seq, apply_unique_name_cb, scene); 01650 01651 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01652 return OPERATOR_FINISHED; 01653 } 01654 01655 return OPERATOR_CANCELLED; 01656 } 01657 01658 static int sequencer_add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 01659 { 01660 sequencer_add_duplicate_exec(C, op); 01661 01662 RNA_enum_set(op->ptr, "mode", TFM_TRANSLATION); 01663 WM_operator_name_call(C, "TRANSFORM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr); 01664 01665 return OPERATOR_FINISHED; 01666 } 01667 01668 void SEQUENCER_OT_duplicate(wmOperatorType *ot) 01669 { 01670 /* identifiers */ 01671 ot->name= "Duplicate Strips"; 01672 ot->idname= "SEQUENCER_OT_duplicate"; 01673 ot->description="Duplicate the selected strips"; 01674 01675 /* api callbacks */ 01676 ot->invoke= sequencer_add_duplicate_invoke; 01677 ot->exec= sequencer_add_duplicate_exec; 01678 ot->poll= ED_operator_sequencer_active; 01679 01680 /* flags */ 01681 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01682 01683 /* to give to transform */ 01684 RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", ""); 01685 } 01686 01687 /* delete operator */ 01688 static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op)) 01689 { 01690 Scene *scene= CTX_data_scene(C); 01691 Editing *ed= seq_give_editing(scene, FALSE); 01692 Sequence *seq; 01693 MetaStack *ms; 01694 int nothingSelected = TRUE; 01695 01696 seq=seq_active_get(scene); 01697 if (seq && seq->flag & SELECT) { /* avoid a loop since this is likely to be selected */ 01698 nothingSelected = FALSE; 01699 } else { 01700 for (seq = ed->seqbasep->first; seq; seq = seq->next) { 01701 if (seq->flag & SELECT) { 01702 nothingSelected = FALSE; 01703 break; 01704 } 01705 } 01706 } 01707 01708 if (nothingSelected) 01709 return OPERATOR_FINISHED; 01710 01711 /* for effects, try to find a replacement input */ 01712 for(seq=ed->seqbasep->first; seq; seq=seq->next) 01713 if((seq->type & SEQ_EFFECT) && !(seq->flag & SELECT)) 01714 del_seq_find_replace_recurs(scene, seq); 01715 01716 /* delete all selected strips */ 01717 recurs_del_seq_flag(scene, ed->seqbasep, SELECT, 0); 01718 01719 /* updates lengths etc */ 01720 seq= ed->seqbasep->first; 01721 while(seq) { 01722 calc_sequence(scene, seq); 01723 seq= seq->next; 01724 } 01725 01726 /* free parent metas */ 01727 ms= ed->metastack.last; 01728 while(ms) { 01729 ms->parseq->strip->len= 0; /* force new alloc */ 01730 calc_sequence(scene, ms->parseq); 01731 ms= ms->prev; 01732 } 01733 01734 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01735 01736 return OPERATOR_FINISHED; 01737 } 01738 01739 01740 void SEQUENCER_OT_delete(wmOperatorType *ot) 01741 { 01742 01743 /* identifiers */ 01744 ot->name= "Erase Strips"; 01745 ot->idname= "SEQUENCER_OT_delete"; 01746 ot->description="Erase selected strips from the sequencer"; 01747 01748 /* api callbacks */ 01749 ot->invoke= WM_operator_confirm; 01750 ot->exec= sequencer_delete_exec; 01751 ot->poll= sequencer_edit_poll; 01752 01753 /* flags */ 01754 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01755 } 01756 01757 01758 /* separate_images operator */ 01759 static int sequencer_separate_images_exec(bContext *C, wmOperator *op) 01760 { 01761 Scene *scene= CTX_data_scene(C); 01762 Editing *ed= seq_give_editing(scene, FALSE); 01763 01764 Sequence *seq, *seq_new; 01765 Strip *strip_new; 01766 StripElem *se, *se_new; 01767 int start_ofs, cfra, frame_end; 01768 int step= RNA_int_get(op->ptr, "length"); 01769 01770 seq= ed->seqbasep->first; /* poll checks this is valid */ 01771 01772 while (seq) { 01773 if((seq->flag & SELECT) && (seq->type == SEQ_IMAGE) && (seq->len > 1)) { 01774 /* remove seq so overlap tests dont conflict, 01775 see seq_free_sequence below for the real free'ing */ 01776 BLI_remlink(ed->seqbasep, seq); 01777 /* if(seq->ipo) seq->ipo->id.us--; */ 01778 /* XXX, remove fcurve and assign to split image strips */ 01779 01780 start_ofs = cfra = seq_tx_get_final_left(seq, 0); 01781 frame_end = seq_tx_get_final_right(seq, 0); 01782 01783 while (cfra < frame_end) { 01784 /* new seq */ 01785 se = give_stripelem(seq, cfra); 01786 01787 seq_new= seq_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME); 01788 BLI_addtail(ed->seqbasep, seq_new); 01789 01790 seq_new->start= start_ofs; 01791 seq_new->type= SEQ_IMAGE; 01792 seq_new->len = 1; 01793 seq_new->endstill = step-1; 01794 01795 /* new strip */ 01796 strip_new= seq_new->strip; 01797 strip_new->len= 1; 01798 strip_new->us= 1; 01799 01800 /* new stripdata */ 01801 se_new= strip_new->stripdata; 01802 BLI_strncpy(se_new->name, se->name, sizeof(se_new->name)); 01803 calc_sequence(scene, seq_new); 01804 01805 if(step > 1) { 01806 seq_new->flag &= ~SEQ_OVERLAP; 01807 if (seq_test_overlap(ed->seqbasep, seq_new)) { 01808 shuffle_seq(ed->seqbasep, seq_new, scene); 01809 } 01810 } 01811 01812 /* XXX, COPY FCURVES */ 01813 01814 cfra++; 01815 start_ofs += step; 01816 } 01817 01818 seq_free_sequence(scene, seq); 01819 seq = seq->next; 01820 } else { 01821 seq = seq->next; 01822 } 01823 } 01824 01825 /* as last: */ 01826 sort_seq(scene); 01827 01828 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01829 01830 return OPERATOR_FINISHED; 01831 } 01832 01833 01834 void SEQUENCER_OT_images_separate(wmOperatorType *ot) 01835 { 01836 /* identifiers */ 01837 ot->name= "Separate Images"; 01838 ot->idname= "SEQUENCER_OT_images_separate"; 01839 ot->description="On image sequences strips, it return a strip for each image"; 01840 01841 /* api callbacks */ 01842 ot->exec= sequencer_separate_images_exec; 01843 ot->poll= sequencer_edit_poll; 01844 01845 /* flags */ 01846 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01847 01848 RNA_def_int(ot->srna, "length", 1, 1, 1000, "Length", "Length of each frame", 1, INT_MAX); 01849 } 01850 01851 01852 /* META Operators */ 01853 01854 /* separate_meta_toggle operator */ 01855 static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op)) 01856 { 01857 Scene *scene= CTX_data_scene(C); 01858 Editing *ed= seq_give_editing(scene, FALSE); 01859 Sequence *last_seq= seq_active_get(scene); 01860 MetaStack *ms; 01861 01862 if(last_seq && last_seq->type==SEQ_META && last_seq->flag & SELECT) { 01863 /* Enter Metastrip */ 01864 ms= MEM_mallocN(sizeof(MetaStack), "metastack"); 01865 BLI_addtail(&ed->metastack, ms); 01866 ms->parseq= last_seq; 01867 ms->oldbasep= ed->seqbasep; 01868 01869 ed->seqbasep= &last_seq->seqbase; 01870 01871 seq_active_set(scene, NULL); 01872 01873 } 01874 else { 01875 /* Exit Metastrip (if possible) */ 01876 01877 Sequence *seq; 01878 01879 if(ed->metastack.first==NULL) 01880 return OPERATOR_CANCELLED; 01881 01882 ms= ed->metastack.last; 01883 BLI_remlink(&ed->metastack, ms); 01884 01885 ed->seqbasep= ms->oldbasep; 01886 01887 /* recalc all: the meta can have effects connected to it */ 01888 for(seq= ed->seqbasep->first; seq; seq= seq->next) 01889 calc_sequence(scene, seq); 01890 01891 seq_active_set(scene, ms->parseq); 01892 01893 ms->parseq->flag |= SELECT; 01894 recurs_sel_seq(ms->parseq); 01895 01896 MEM_freeN(ms); 01897 01898 } 01899 01900 seq_update_muting(scene, ed); 01901 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01902 01903 return OPERATOR_FINISHED; 01904 } 01905 01906 void SEQUENCER_OT_meta_toggle(wmOperatorType *ot) 01907 { 01908 /* identifiers */ 01909 ot->name= "Toggle Meta Strip"; 01910 ot->idname= "SEQUENCER_OT_meta_toggle"; 01911 ot->description="Toggle a metastrip (to edit enclosed strips)"; 01912 01913 /* api callbacks */ 01914 ot->exec= sequencer_meta_toggle_exec; 01915 ot->poll= sequencer_edit_poll; 01916 01917 /* flags */ 01918 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01919 } 01920 01921 01922 /* separate_meta_make operator */ 01923 static int sequencer_meta_make_exec(bContext *C, wmOperator *op) 01924 { 01925 Scene *scene= CTX_data_scene(C); 01926 Editing *ed= seq_give_editing(scene, FALSE); 01927 01928 Sequence *seq, *seqm, *next, *last_seq = seq_active_get(scene); 01929 int channel_max= 1; 01930 01931 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) { 01932 BKE_report(op->reports, RPT_ERROR, "Please select all related strips"); 01933 return OPERATOR_CANCELLED; 01934 } 01935 01936 /* remove all selected from main list, and put in meta */ 01937 01938 seqm= alloc_sequence(ed->seqbasep, 1, 1); /* channel number set later */ 01939 strcpy(seqm->name+2, "MetaStrip"); 01940 seqm->type= SEQ_META; 01941 seqm->flag= SELECT; 01942 01943 seq= ed->seqbasep->first; 01944 while(seq) { 01945 next= seq->next; 01946 if(seq!=seqm && (seq->flag & SELECT)) { 01947 channel_max= MAX2(seq->machine, channel_max); 01948 BLI_remlink(ed->seqbasep, seq); 01949 BLI_addtail(&seqm->seqbase, seq); 01950 } 01951 seq= next; 01952 } 01953 seqm->machine= last_seq ? last_seq->machine : channel_max; 01954 calc_sequence(scene, seqm); 01955 01956 seqm->strip= MEM_callocN(sizeof(Strip), "metastrip"); 01957 seqm->strip->len= seqm->len; 01958 seqm->strip->us= 1; 01959 01960 seq_active_set(scene, seqm); 01961 01962 if( seq_test_overlap(ed->seqbasep, seqm) ) shuffle_seq(ed->seqbasep, seqm, scene); 01963 01964 seq_update_muting(scene, ed); 01965 01966 seqbase_unique_name_recursive(&scene->ed->seqbase, seqm); 01967 01968 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 01969 01970 return OPERATOR_FINISHED; 01971 } 01972 01973 void SEQUENCER_OT_meta_make(wmOperatorType *ot) 01974 { 01975 /* identifiers */ 01976 ot->name= "Make Meta Strip"; 01977 ot->idname= "SEQUENCER_OT_meta_make"; 01978 ot->description="Group selected strips into a metastrip"; 01979 01980 /* api callbacks */ 01981 ot->invoke= WM_operator_confirm; 01982 ot->exec= sequencer_meta_make_exec; 01983 ot->poll= sequencer_edit_poll; 01984 01985 /* flags */ 01986 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01987 } 01988 01989 01990 static int seq_depends_on_meta(Sequence *seq, Sequence *seqm) 01991 { 01992 if (seq == seqm) return 1; 01993 else if (seq->seq1 && seq_depends_on_meta(seq->seq1, seqm)) return 1; 01994 else if (seq->seq2 && seq_depends_on_meta(seq->seq2, seqm)) return 1; 01995 else if (seq->seq3 && seq_depends_on_meta(seq->seq3, seqm)) return 1; 01996 else return 0; 01997 } 01998 01999 /* separate_meta_make operator */ 02000 static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op)) 02001 { 02002 Scene *scene= CTX_data_scene(C); 02003 Editing *ed= seq_give_editing(scene, FALSE); 02004 02005 Sequence *seq, *last_seq = seq_active_get(scene); /* last_seq checks ed==NULL */ 02006 02007 if(last_seq==NULL || last_seq->type!=SEQ_META) 02008 return OPERATOR_CANCELLED; 02009 02010 BLI_movelisttolist(ed->seqbasep, &last_seq->seqbase); 02011 02012 last_seq->seqbase.first= NULL; 02013 last_seq->seqbase.last= NULL; 02014 02015 BLI_remlink(ed->seqbasep, last_seq); 02016 seq_free_sequence(scene, last_seq); 02017 02018 /* emtpy meta strip, delete all effects depending on it */ 02019 for(seq=ed->seqbasep->first; seq; seq=seq->next) 02020 if((seq->type & SEQ_EFFECT) && seq_depends_on_meta(seq, last_seq)) 02021 seq->flag |= SEQ_FLAG_DELETE; 02022 02023 recurs_del_seq_flag(scene, ed->seqbasep, SEQ_FLAG_DELETE, 0); 02024 02025 /* test for effects and overlap 02026 * dont use SEQP_BEGIN since that would be recursive */ 02027 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 02028 if(seq->flag & SELECT) { 02029 seq->flag &= ~SEQ_OVERLAP; 02030 if(seq_test_overlap(ed->seqbasep, seq)) { 02031 shuffle_seq(ed->seqbasep, seq, scene); 02032 } 02033 } 02034 } 02035 02036 sort_seq(scene); 02037 seq_update_muting(scene, ed); 02038 02039 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 02040 02041 return OPERATOR_FINISHED; 02042 } 02043 02044 void SEQUENCER_OT_meta_separate(wmOperatorType *ot) 02045 { 02046 /* identifiers */ 02047 ot->name= "UnMeta Strip"; 02048 ot->idname= "SEQUENCER_OT_meta_separate"; 02049 ot->description="Put the contents of a metastrip back in the sequencer"; 02050 02051 /* api callbacks */ 02052 ot->invoke= WM_operator_confirm; 02053 ot->exec= sequencer_meta_separate_exec; 02054 ot->poll= sequencer_edit_poll; 02055 02056 /* flags */ 02057 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02058 } 02059 02060 /* view_all operator */ 02061 static int sequencer_view_all_exec(bContext *C, wmOperator *UNUSED(op)) 02062 { 02063 //Scene *scene= CTX_data_scene(C); 02064 bScreen *sc= CTX_wm_screen(C); 02065 ScrArea *area= CTX_wm_area(C); 02066 //ARegion *ar= CTX_wm_region(C); 02067 View2D *v2d= UI_view2d_fromcontext(C); 02068 02069 v2d->cur= v2d->tot; 02070 UI_view2d_curRect_validate(v2d); 02071 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY); 02072 02073 ED_area_tag_redraw(CTX_wm_area(C)); 02074 return OPERATOR_FINISHED; 02075 } 02076 02077 void SEQUENCER_OT_view_all(wmOperatorType *ot) 02078 { 02079 /* identifiers */ 02080 ot->name= "View All"; 02081 ot->idname= "SEQUENCER_OT_view_all"; 02082 ot->description="View all the strips in the sequencer"; 02083 02084 /* api callbacks */ 02085 ot->exec= sequencer_view_all_exec; 02086 ot->poll= ED_operator_sequencer_active; 02087 02088 /* flags */ 02089 ot->flag= OPTYPE_REGISTER; 02090 } 02091 02092 /* view_all operator */ 02093 static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op)) 02094 { 02095 bScreen *sc= CTX_wm_screen(C); 02096 ScrArea *area= CTX_wm_area(C); 02097 #if 0 02098 ARegion *ar= CTX_wm_region(C); 02099 SpaceSeq *sseq= area->spacedata.first; 02100 Scene *scene= CTX_data_scene(C); 02101 #endif 02102 View2D *v2d= UI_view2d_fromcontext(C); 02103 02104 v2d->cur= v2d->tot; 02105 UI_view2d_curRect_validate(v2d); 02106 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY); 02107 02108 #if 0 02109 /* Like zooming on an image view */ 02110 float zoomX, zoomY; 02111 int width, height, imgwidth, imgheight; 02112 02113 width = ar->winx; 02114 height = ar->winy; 02115 02116 seq_reset_imageofs(sseq); 02117 02118 imgwidth= (scene->r.size*scene->r.xsch)/100; 02119 imgheight= (scene->r.size*scene->r.ysch)/100; 02120 02121 /* Apply aspect, dosnt need to be that accurate */ 02122 imgwidth= (int)(imgwidth * (scene->r.xasp / scene->r.yasp)); 02123 02124 if (((imgwidth >= width) || (imgheight >= height)) && 02125 ((width > 0) && (height > 0))) { 02126 02127 /* Find the zoom value that will fit the image in the image space */ 02128 zoomX = ((float)width) / ((float)imgwidth); 02129 zoomY = ((float)height) / ((float)imgheight); 02130 sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY; 02131 02132 sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) ); 02133 } 02134 else { 02135 sseq->zoom= 1.0f; 02136 } 02137 #endif 02138 02139 ED_area_tag_redraw(CTX_wm_area(C)); 02140 return OPERATOR_FINISHED; 02141 } 02142 02143 void SEQUENCER_OT_view_all_preview(wmOperatorType *ot) 02144 { 02145 /* identifiers */ 02146 ot->name= "View All"; 02147 ot->idname= "SEQUENCER_OT_view_all_preview"; 02148 ot->description="Zoom preview to fit in the area"; 02149 02150 /* api callbacks */ 02151 ot->exec= sequencer_view_all_preview_exec; 02152 ot->poll= ED_operator_sequencer_active; 02153 02154 /* flags */ 02155 ot->flag= OPTYPE_REGISTER; 02156 } 02157 02158 02159 static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op) 02160 { 02161 RenderData *r= &CTX_data_scene(C)->r; 02162 View2D *v2d= UI_view2d_fromcontext(C); 02163 02164 float ratio= RNA_float_get(op->ptr, "ratio"); 02165 02166 float winx= (int)(r->size * r->xsch)/100; 02167 float winy= (int)(r->size * r->ysch)/100; 02168 02169 float facx= (v2d->mask.xmax - v2d->mask.xmin) / winx; 02170 float facy= (v2d->mask.ymax - v2d->mask.ymin) / winy; 02171 02172 BLI_resize_rctf(&v2d->cur, (int)(winx*facx*ratio) + 1, (int)(winy*facy*ratio) + 1); 02173 02174 ED_region_tag_redraw(CTX_wm_region(C)); 02175 02176 return OPERATOR_FINISHED; 02177 } 02178 02179 void SEQUENCER_OT_view_zoom_ratio(wmOperatorType *ot) 02180 { 02181 /* identifiers */ 02182 ot->name= "Sequencer View Zoom Ratio"; 02183 ot->idname= "SEQUENCER_OT_view_zoom_ratio"; 02184 ot->description = "Change zoom ratio of sequencer preview"; 02185 02186 /* api callbacks */ 02187 ot->exec= sequencer_view_zoom_ratio_exec; 02188 ot->poll= ED_operator_sequencer_active; 02189 02190 /* properties */ 02191 RNA_def_float(ot->srna, "ratio", 1.0f, 0.0f, FLT_MAX, 02192 "Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out.", -FLT_MAX, FLT_MAX); 02193 } 02194 02195 02196 #if 0 02197 static EnumPropertyItem view_type_items[] = { 02198 {SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""}, 02199 {SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""}, 02200 {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SEQUENCER, "Sequencer and Image Preview", ""}, 02201 {0, NULL, 0, NULL, NULL}}; 02202 #endif 02203 02204 /* view_all operator */ 02205 static int sequencer_view_toggle_exec(bContext *C, wmOperator *UNUSED(op)) 02206 { 02207 SpaceSeq *sseq= (SpaceSeq *)CTX_wm_space_data(C); 02208 02209 sseq->view++; 02210 if (sseq->view > SEQ_VIEW_SEQUENCE_PREVIEW) sseq->view = SEQ_VIEW_SEQUENCE; 02211 02212 ED_sequencer_update_view(C, sseq->view); 02213 02214 return OPERATOR_FINISHED; 02215 } 02216 02217 void SEQUENCER_OT_view_toggle(wmOperatorType *ot) 02218 { 02219 /* identifiers */ 02220 ot->name= "View Toggle"; 02221 ot->idname= "SEQUENCER_OT_view_toggle"; 02222 ot->description="Toggle between sequencer views (sequence, preview, both)"; 02223 02224 /* api callbacks */ 02225 ot->exec= sequencer_view_toggle_exec; 02226 ot->poll= ED_operator_sequencer_active; 02227 02228 /* flags */ 02229 ot->flag= OPTYPE_REGISTER; 02230 } 02231 02232 02233 /* view_selected operator */ 02234 static int sequencer_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) 02235 { 02236 Scene *scene= CTX_data_scene(C); 02237 View2D *v2d= UI_view2d_fromcontext(C); 02238 ScrArea *area= CTX_wm_area(C); 02239 bScreen *sc= CTX_wm_screen(C); 02240 Editing *ed= seq_give_editing(scene, FALSE); 02241 Sequence *seq; 02242 02243 int xmin= MAXFRAME*2; 02244 int xmax= -MAXFRAME*2; 02245 int ymin= MAXSEQ+1; 02246 int ymax= 0; 02247 int orig_height; 02248 int ymid; 02249 int ymargin= 1; 02250 int xmargin= FPS; 02251 02252 if(ed==NULL) 02253 return OPERATOR_CANCELLED; 02254 02255 for(seq=ed->seqbasep->first; seq; seq=seq->next) { 02256 if(seq->flag & SELECT) { 02257 xmin= MIN2(xmin, seq->startdisp); 02258 xmax= MAX2(xmax, seq->enddisp); 02259 02260 ymin= MIN2(ymin, seq->machine); 02261 ymax= MAX2(ymax, seq->machine); 02262 } 02263 } 02264 02265 if (ymax != 0) { 02266 02267 xmax += xmargin; 02268 xmin -= xmargin; 02269 ymax += ymargin; 02270 ymin -= ymargin; 02271 02272 orig_height= v2d->cur.ymax - v2d->cur.ymin; 02273 02274 v2d->cur.xmin= xmin; 02275 v2d->cur.xmax= xmax; 02276 02277 v2d->cur.ymin= ymin; 02278 v2d->cur.ymax= ymax; 02279 02280 /* only zoom out vertically */ 02281 if (orig_height > v2d->cur.ymax - v2d->cur.ymin) { 02282 ymid= (v2d->cur.ymax + v2d->cur.ymin) / 2; 02283 02284 v2d->cur.ymin= ymid - (orig_height/2); 02285 v2d->cur.ymax= ymid + (orig_height/2); 02286 } 02287 02288 UI_view2d_curRect_validate(v2d); 02289 UI_view2d_sync(sc, area, v2d, V2D_LOCK_COPY); 02290 02291 ED_area_tag_redraw(CTX_wm_area(C)); 02292 } 02293 02294 return OPERATOR_FINISHED; 02295 } 02296 02297 void SEQUENCER_OT_view_selected(wmOperatorType *ot) 02298 { 02299 /* identifiers */ 02300 ot->name= "View Selected"; 02301 ot->idname= "SEQUENCER_OT_view_selected"; 02302 ot->description="Zoom the sequencer on the selected strips"; 02303 02304 /* api callbacks */ 02305 ot->exec= sequencer_view_selected_exec; 02306 ot->poll= ED_operator_sequencer_active; 02307 02308 /* flags */ 02309 ot->flag= OPTYPE_REGISTER; 02310 } 02311 02312 02313 static int find_next_prev_edit(Scene *scene, int cfra, int side) 02314 { 02315 Editing *ed= seq_give_editing(scene, FALSE); 02316 Sequence *seq,*best_seq = NULL,*frame_seq = NULL; 02317 02318 int dist, best_dist; 02319 best_dist = MAXFRAME*2; 02320 02321 if(ed==NULL) return cfra; 02322 02323 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 02324 dist = MAXFRAME*2; 02325 02326 switch (side) { 02327 case SEQ_SIDE_LEFT: 02328 if (seq->startdisp < cfra) { 02329 dist = cfra - seq->startdisp; 02330 } 02331 break; 02332 case SEQ_SIDE_RIGHT: 02333 if (seq->startdisp > cfra) { 02334 dist = seq->startdisp - cfra; 02335 } else if (seq->startdisp == cfra) { 02336 frame_seq=seq; 02337 } 02338 break; 02339 } 02340 02341 if (dist < best_dist) { 02342 best_dist = dist; 02343 best_seq = seq; 02344 } 02345 } 02346 02347 /* if no sequence to the right is found and the 02348 frame is on the start of the last sequence, 02349 move to the end of the last sequence */ 02350 if (frame_seq) cfra = frame_seq->enddisp; 02351 02352 return best_seq ? best_seq->startdisp : cfra; 02353 } 02354 02355 static int next_prev_edit_internal(Scene *scene, int side) 02356 { 02357 int change=0; 02358 int cfra = CFRA; 02359 int nfra= find_next_prev_edit(scene, cfra, side); 02360 02361 if (nfra != cfra) { 02362 CFRA = nfra; 02363 change= 1; 02364 } 02365 02366 return change; 02367 } 02368 02369 /* move frame to next edit point operator */ 02370 static int sequencer_next_edit_exec(bContext *C, wmOperator *UNUSED(op)) 02371 { 02372 Scene *scene= CTX_data_scene(C); 02373 02374 if(!next_prev_edit_internal(scene, SEQ_SIDE_RIGHT)) 02375 return OPERATOR_CANCELLED; 02376 02377 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); 02378 02379 return OPERATOR_FINISHED; 02380 } 02381 02382 void SEQUENCER_OT_next_edit(wmOperatorType *ot) 02383 { 02384 /* identifiers */ 02385 ot->name= "Next Edit"; 02386 ot->idname= "SEQUENCER_OT_next_edit"; 02387 ot->description="Move frame to next edit point"; 02388 02389 /* api callbacks */ 02390 ot->exec= sequencer_next_edit_exec; 02391 ot->poll= sequencer_edit_poll; 02392 02393 /* flags */ 02394 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02395 02396 /* properties */ 02397 } 02398 02399 /* move frame to previous edit point operator */ 02400 static int sequencer_previous_edit_exec(bContext *C, wmOperator *UNUSED(op)) 02401 { 02402 Scene *scene= CTX_data_scene(C); 02403 02404 if(!next_prev_edit_internal(scene, SEQ_SIDE_LEFT)) 02405 return OPERATOR_CANCELLED; 02406 02407 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); 02408 02409 return OPERATOR_FINISHED; 02410 } 02411 02412 void SEQUENCER_OT_previous_edit(wmOperatorType *ot) 02413 { 02414 /* identifiers */ 02415 ot->name= "Previous Edit"; 02416 ot->idname= "SEQUENCER_OT_previous_edit"; 02417 ot->description="Move frame to previous edit point"; 02418 02419 /* api callbacks */ 02420 ot->exec= sequencer_previous_edit_exec; 02421 ot->poll= sequencer_edit_poll; 02422 02423 /* flags */ 02424 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02425 02426 /* properties */ 02427 } 02428 02429 static void swap_sequence(Scene* scene, Sequence* seqa, Sequence* seqb) 02430 { 02431 int gap = seqb->startdisp - seqa->enddisp; 02432 seqb->start = (seqb->start - seqb->startdisp) + seqa->startdisp; 02433 calc_sequence(scene, seqb); 02434 seqa->start = (seqa->start - seqa->startdisp) + seqb->enddisp + gap; 02435 calc_sequence(scene, seqa); 02436 } 02437 02438 #if 0 02439 static Sequence* sequence_find_parent(Scene* scene, Sequence* child) 02440 { 02441 Editing *ed= seq_give_editing(scene, FALSE); 02442 Sequence *parent= NULL; 02443 Sequence *seq; 02444 02445 if(ed==NULL) return NULL; 02446 02447 for(seq= ed->seqbasep->first; seq; seq= seq->next) { 02448 if ( (seq != child) && seq_is_parent(seq, child) ) { 02449 parent = seq; 02450 break; 02451 } 02452 } 02453 02454 return parent; 02455 } 02456 #endif 02457 02458 static int sequencer_swap_exec(bContext *C, wmOperator *op) 02459 { 02460 Scene *scene= CTX_data_scene(C); 02461 Editing *ed= seq_give_editing(scene, FALSE); 02462 Sequence *active_seq = seq_active_get(scene); 02463 Sequence *seq, *iseq; 02464 int side= RNA_enum_get(op->ptr, "side"); 02465 02466 if(active_seq==NULL) return OPERATOR_CANCELLED; 02467 02468 seq = find_next_prev_sequence(scene, active_seq, side, -1); 02469 02470 if(seq) { 02471 02472 /* disallow effect strips */ 02473 if (get_sequence_effect_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3)) 02474 return OPERATOR_CANCELLED; 02475 if ((get_sequence_effect_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3)) 02476 return OPERATOR_CANCELLED; 02477 02478 switch (side) { 02479 case SEQ_SIDE_LEFT: 02480 swap_sequence(scene, seq, active_seq); 02481 break; 02482 case SEQ_SIDE_RIGHT: 02483 swap_sequence(scene, active_seq, seq); 02484 break; 02485 } 02486 02487 // XXX - should be a generic function 02488 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) { 02489 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) { 02490 calc_sequence(scene, iseq); 02491 } 02492 } 02493 02494 /* do this in a new loop since both effects need to be calculated first */ 02495 for(iseq= scene->ed->seqbasep->first; iseq; iseq= iseq->next) { 02496 if((iseq->type & SEQ_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) { 02497 /* this may now overlap */ 02498 if( seq_test_overlap(ed->seqbasep, iseq) ) { 02499 shuffle_seq(ed->seqbasep, iseq, scene); 02500 } 02501 } 02502 } 02503 02504 02505 02506 sort_seq(scene); 02507 02508 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 02509 02510 return OPERATOR_FINISHED; 02511 } 02512 02513 return OPERATOR_CANCELLED; 02514 } 02515 02516 void SEQUENCER_OT_swap(wmOperatorType *ot) 02517 { 02518 /* identifiers */ 02519 ot->name= "Swap Strip"; 02520 ot->idname= "SEQUENCER_OT_swap"; 02521 ot->description="Swap active strip with strip to the left"; 02522 02523 /* api callbacks */ 02524 ot->exec= sequencer_swap_exec; 02525 ot->poll= sequencer_edit_poll; 02526 02527 /* flags */ 02528 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02529 02530 /* properties */ 02531 RNA_def_enum(ot->srna, "side", prop_side_lr_types, SEQ_SIDE_RIGHT, "Side", "Side of the strip to swap"); 02532 } 02533 02534 static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op)) 02535 { 02536 int retval = OPERATOR_CANCELLED; 02537 Scene *scene= CTX_data_scene(C); 02538 Sequence *active_seq = seq_active_get(scene); 02539 StripElem *se = NULL; 02540 02541 if(active_seq==NULL) 02542 return OPERATOR_CANCELLED; 02543 02544 02545 if (active_seq->strip) { 02546 switch (active_seq->type) { 02547 case SEQ_IMAGE: 02548 se = give_stripelem(active_seq, scene->r.cfra); 02549 break; 02550 case SEQ_MOVIE: 02551 se = active_seq->strip->stripdata; 02552 break; 02553 case SEQ_SCENE: 02554 case SEQ_META: 02555 case SEQ_RAM_SOUND: 02556 case SEQ_HD_SOUND: 02557 default: 02558 break; 02559 } 02560 } 02561 02562 if (se) { 02563 // prevent setting the render size if sequence values aren't initialized 02564 if ( (se->orig_width > 0) && (se->orig_height > 0) ) { 02565 scene->r.xsch= se->orig_width; 02566 scene->r.ysch= se->orig_height; 02567 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); 02568 retval = OPERATOR_FINISHED; 02569 } 02570 } 02571 02572 return retval; 02573 } 02574 02575 void SEQUENCER_OT_rendersize(wmOperatorType *ot) 02576 { 02577 /* identifiers */ 02578 ot->name= "Set Render Size"; 02579 ot->idname= "SEQUENCER_OT_rendersize"; 02580 ot->description="Set render size and aspect from active sequence"; 02581 02582 /* api callbacks */ 02583 ot->exec= sequencer_rendersize_exec; 02584 ot->poll= sequencer_edit_poll; 02585 02586 /* flags */ 02587 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02588 02589 /* properties */ 02590 } 02591 02592 static void seq_del_sound(Scene *scene, Sequence *seq) 02593 { 02594 if(seq->type == SEQ_META) { 02595 Sequence *iseq; 02596 for(iseq= seq->seqbase.first; iseq; iseq= iseq->next) { 02597 seq_del_sound(scene, iseq); 02598 } 02599 } 02600 else if(seq->scene_sound) { 02601 sound_remove_scene_sound(scene, seq->scene_sound); 02602 seq->scene_sound = NULL; 02603 } 02604 } 02605 02606 /* TODO, validate scenes */ 02607 static int sequencer_copy_exec(bContext *C, wmOperator *op) 02608 { 02609 Scene *scene= CTX_data_scene(C); 02610 Editing *ed= seq_give_editing(scene, FALSE); 02611 Sequence *seq; 02612 02613 ListBase nseqbase= {NULL, NULL}; 02614 02615 seq_free_clipboard(); 02616 02617 if(seqbase_isolated_sel_check(ed->seqbasep)==FALSE) { 02618 BKE_report(op->reports, RPT_ERROR, "Please select all related strips"); 02619 return OPERATOR_CANCELLED; 02620 } 02621 02622 seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME); 02623 02624 /* To make sure the copied strips have unique names between each other add 02625 * them temporarily to the end of the original seqbase. (bug 25932) 02626 */ 02627 if(nseqbase.first) { 02628 Sequence *seq, *first_seq = nseqbase.first; 02629 BLI_movelisttolist(ed->seqbasep, &nseqbase); 02630 02631 for(seq=first_seq; seq; seq=seq->next) 02632 seq_recursive_apply(seq, apply_unique_name_cb, scene); 02633 02634 seqbase_clipboard.first = first_seq; 02635 seqbase_clipboard.last = ed->seqbasep->last; 02636 02637 if(first_seq->prev) { 02638 first_seq->prev->next = NULL; 02639 ed->seqbasep->last = first_seq->prev; 02640 first_seq->prev = NULL; 02641 } 02642 } 02643 02644 seqbase_clipboard_frame= scene->r.cfra; 02645 02646 /* Need to remove anything that references the current scene */ 02647 for(seq= seqbase_clipboard.first; seq; seq= seq->next) { 02648 seq_del_sound(scene, seq); 02649 } 02650 02651 return OPERATOR_FINISHED; 02652 } 02653 02654 void SEQUENCER_OT_copy(wmOperatorType *ot) 02655 { 02656 /* identifiers */ 02657 ot->name= "Copy"; 02658 ot->idname= "SEQUENCER_OT_copy"; 02659 ot->description=""; 02660 02661 /* api callbacks */ 02662 ot->exec= sequencer_copy_exec; 02663 ot->poll= sequencer_edit_poll; 02664 02665 /* flags */ 02666 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02667 02668 /* properties */ 02669 } 02670 02671 static int sequencer_paste_exec(bContext *C, wmOperator *UNUSED(op)) 02672 { 02673 Scene *scene= CTX_data_scene(C); 02674 Editing *ed= seq_give_editing(scene, TRUE); /* create if needed */ 02675 ListBase nseqbase = {NULL, NULL}; 02676 int ofs; 02677 Sequence *iseq; 02678 02679 deselect_all_seq(scene); 02680 ofs = scene->r.cfra - seqbase_clipboard_frame; 02681 02682 seqbase_dupli_recursive(scene, NULL, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME); 02683 02684 /* transform pasted strips before adding */ 02685 if(ofs) { 02686 for(iseq= nseqbase.first; iseq; iseq= iseq->next) { 02687 seq_translate(scene, iseq, ofs); 02688 seq_sound_init(scene, iseq); 02689 } 02690 } 02691 02692 iseq = nseqbase.first; 02693 02694 BLI_movelisttolist(ed->seqbasep, &nseqbase); 02695 02696 /* make sure the pasted strips have unique names between them */ 02697 for(; iseq; iseq=iseq->next) 02698 seq_recursive_apply(iseq, apply_unique_name_cb, scene); 02699 02700 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 02701 02702 return OPERATOR_FINISHED; 02703 } 02704 02705 void SEQUENCER_OT_paste(wmOperatorType *ot) 02706 { 02707 /* identifiers */ 02708 ot->name= "Paste"; 02709 ot->idname= "SEQUENCER_OT_paste"; 02710 ot->description=""; 02711 02712 /* api callbacks */ 02713 ot->exec= sequencer_paste_exec; 02714 ot->poll= ED_operator_sequencer_active; 02715 02716 /* flags */ 02717 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02718 02719 /* properties */ 02720 } 02721 02722 static int sequencer_swap_data_exec(bContext *C, wmOperator *op) 02723 { 02724 Scene *scene= CTX_data_scene(C); 02725 Sequence *seq_act; 02726 Sequence *seq_other; 02727 const char *error_msg; 02728 02729 if(seq_active_pair_get(scene, &seq_act, &seq_other) == 0) { 02730 BKE_report(op->reports, RPT_ERROR, "Must select 2 strips"); 02731 return OPERATOR_CANCELLED; 02732 } 02733 02734 if(seq_swap(seq_act, seq_other, &error_msg) == 0) { 02735 BKE_report(op->reports, RPT_ERROR, error_msg); 02736 return OPERATOR_CANCELLED; 02737 } 02738 02739 sound_remove_scene_sound(scene, seq_act->scene_sound); 02740 sound_remove_scene_sound(scene, seq_other->scene_sound); 02741 02742 seq_act->scene_sound= NULL; 02743 seq_other->scene_sound= NULL; 02744 02745 calc_sequence(scene, seq_act); 02746 calc_sequence(scene, seq_other); 02747 02748 if(seq_act->sound) sound_add_scene_sound(scene, seq_act, seq_act->startdisp, seq_act->enddisp, seq_act->startofs + seq_act->anim_startofs); 02749 if(seq_other->sound) sound_add_scene_sound(scene, seq_other, seq_other->startdisp, seq_other->enddisp, seq_other->startofs + seq_other->anim_startofs); 02750 02751 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 02752 02753 return OPERATOR_FINISHED; 02754 } 02755 02756 void SEQUENCER_OT_swap_data(wmOperatorType *ot) 02757 { 02758 /* identifiers */ 02759 ot->name= "Sequencer Swap Data"; 02760 ot->idname= "SEQUENCER_OT_swap_data"; 02761 ot->description="Swap 2 sequencer strips"; 02762 02763 /* api callbacks */ 02764 ot->exec= sequencer_swap_data_exec; 02765 ot->poll= ED_operator_sequencer_active; 02766 02767 /* flags */ 02768 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 02769 02770 /* properties */ 02771 } 02772 02773 /* borderselect operator */ 02774 static int view_ghost_border_exec(bContext *C, wmOperator *op) 02775 { 02776 Scene *scene= CTX_data_scene(C); 02777 Editing *ed= seq_give_editing(scene, FALSE); 02778 View2D *v2d= UI_view2d_fromcontext(C); 02779 02780 rctf rect; 02781 02782 /* convert coordinates of rect to 'tot' rect coordinates */ 02783 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmin"), RNA_int_get(op->ptr, "ymin"), &rect.xmin, &rect.ymin); 02784 UI_view2d_region_to_view(v2d, RNA_int_get(op->ptr, "xmax"), RNA_int_get(op->ptr, "ymax"), &rect.xmax, &rect.ymax); 02785 02786 if(ed==NULL) 02787 return OPERATOR_CANCELLED; 02788 02789 rect.xmin /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin)); 02790 rect.ymin /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin)); 02791 02792 rect.xmax /= (float)(ABS(v2d->tot.xmax - v2d->tot.xmin)); 02793 rect.ymax /= (float)(ABS(v2d->tot.ymax - v2d->tot.ymin)); 02794 02795 rect.xmin+=0.5f; 02796 rect.xmax+=0.5f; 02797 rect.ymin+=0.5f; 02798 rect.ymax+=0.5f; 02799 02800 CLAMP(rect.xmin, 0.0f, 1.0f); 02801 CLAMP(rect.ymin, 0.0f, 1.0f); 02802 CLAMP(rect.xmax, 0.0f, 1.0f); 02803 CLAMP(rect.ymax, 0.0f, 1.0f); 02804 02805 scene->ed->over_border= rect; 02806 02807 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); 02808 02809 return OPERATOR_FINISHED; 02810 } 02811 02812 /* ****** Border Select ****** */ 02813 void SEQUENCER_OT_view_ghost_border(wmOperatorType *ot) 02814 { 02815 /* identifiers */ 02816 ot->name= "Border Offset View"; 02817 ot->idname= "SEQUENCER_OT_view_ghost_border"; 02818 ot->description="Enable border select mode"; 02819 02820 /* api callbacks */ 02821 ot->invoke= WM_border_select_invoke; 02822 ot->exec= view_ghost_border_exec; 02823 ot->modal= WM_border_select_modal; 02824 ot->poll= sequencer_view_poll; 02825 ot->cancel= WM_border_select_cancel; 02826 02827 /* flags */ 02828 ot->flag= 0; 02829 02830 /* rna */ 02831 WM_operator_properties_gesture_border(ot, FALSE); 02832 }