== "Extend" Transform Mode for Action + NLA Editors ==
[blender.git] / source / blender / src / editnla.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL *****
28  *
29  * This file is a horrible mess: An attmept to cram some
30  * final functionality into blender before it is too late.
31  *
32  * Hopefully it can be tidied up at a later date...
33 */
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <math.h>
38
39 #include "PIL_time.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44
45 #include "DNA_action_types.h"
46 #include "DNA_constraint_types.h"
47 #include "DNA_curve_types.h"
48 #include "DNA_ipo_types.h"
49 #include "DNA_object_types.h"
50 #include "DNA_nla_types.h"
51 #include "DNA_screen_types.h"
52 #include "DNA_space_types.h"
53 #include "DNA_scene_types.h"
54 #include "DNA_userdef_types.h"
55
56 #include "BKE_action.h"
57 #include "BKE_blender.h"
58 #include "BKE_depsgraph.h"
59 #include "BKE_group.h"
60 #include "BKE_global.h"
61 #include "BKE_ipo.h"
62 #include "BKE_library.h"
63 #include "BKE_main.h"
64 #include "BKE_nla.h"
65 #include "BKE_utildefines.h"
66
67 #include "BIF_screen.h"
68 #include "BIF_interface.h"
69 #include "BIF_butspace.h"
70 #include "BIF_space.h"
71 #include "BIF_mywindow.h"
72 #include "BIF_editview.h"
73 #include "BIF_toolbox.h"
74 #include "BIF_editnla.h"
75 #include "BIF_editaction.h"
76 #include "BIF_transform.h"
77
78 #include "BSE_editipo.h"
79 #include "BSE_editnla_types.h"
80 #include "BSE_headerbuttons.h"
81 #include "BSE_drawipo.h"
82 #include "BSE_editaction_types.h"
83 #include "BSE_trans_types.h"
84 #include "BSE_edit.h"
85 #include "BSE_filesel.h"
86 #include "BDR_editobject.h"
87 #include "BSE_drawnla.h"
88 #include "BSE_time.h"
89
90 #include "blendef.h"
91 #include "mydevice.h"
92
93 #ifdef HAVE_CONFIG_H
94 #include <config.h>
95 #endif
96
97 /* Note: A lot of these pretty much duplicate the behaviour of the
98 action windows.  The functions should be shared, not copy-pasted */
99
100 static void mouse_nla(int selectmode);
101 static Base *get_nearest_nlachannel_ob_key (float *index, short *sel);
102 static bAction *get_nearest_nlachannel_ac_key (float *index, short *sel);
103 static Base *get_nearest_nlastrip (bActionStrip **rstrip, short *sel);
104 static void mouse_nlachannels(short mval[2]);
105
106 /* ******************** SPACE: NLA ********************** */
107
108 void shift_nlastrips_up(void) {
109         
110         Base *base;
111         bActionStrip *strip, *prevstrip;
112
113         for (base=G.scene->base.first; base; base=base->next) {
114                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
115                         continue;
116                 
117                 for (strip = base->object->nlastrips.first; 
118                          strip; strip=strip->next){
119                         if (strip->flag & ACTSTRIP_SELECT) {
120                                 if ( (prevstrip = strip->prev) ) {
121                                         if (prevstrip->prev)
122                                                 prevstrip->prev->next = strip;
123                                         if (strip->next)
124                                                 strip->next->prev = prevstrip;
125                                         strip->prev = prevstrip->prev;
126                                         prevstrip->next = strip->next;
127                                         strip->next = prevstrip;
128                                         prevstrip->prev = strip;
129
130                                         if (prevstrip == base->object->nlastrips.first)
131                                                 base->object->nlastrips.first = strip;
132                                         if (strip == base->object->nlastrips.last)
133                                                 base->object->nlastrips.last = prevstrip;
134
135                                         strip = prevstrip;
136                                 }
137                                 else {
138                                         break;
139                                 }
140                         }
141                 }
142         }
143         BIF_undo_push("Shift NLA strip");
144         allqueue (REDRAWNLA, 0);
145
146 }
147
148 void shift_nlastrips_down(void) {
149         
150         Base *base;
151         bActionStrip *strip, *nextstrip;
152
153         for (base=G.scene->base.first; base; base=base->next) {
154                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
155                         continue;
156                 
157                 for (strip = base->object->nlastrips.last; 
158                          strip; strip=strip->prev){
159                         if (strip->flag & ACTSTRIP_SELECT) {
160                                 if ( (nextstrip = strip->next) ) {
161                                         if (nextstrip->next)
162                                                 nextstrip->next->prev = strip;
163                                         if (strip->prev)
164                                                 strip->prev->next = nextstrip;
165                                         strip->next = nextstrip->next;
166                                         nextstrip->prev = strip->prev;
167                                         strip->prev = nextstrip;
168                                         nextstrip->next = strip;
169
170                                         if (nextstrip == base->object->nlastrips.last)
171                                                 base->object->nlastrips.last = strip;
172                                         if (strip == base->object->nlastrips.first)
173                                                 base->object->nlastrips.first = nextstrip;
174
175                                         strip = nextstrip;
176                                 }
177                                 else {
178                                         break;
179                                 }
180                         }
181                 }
182         }
183         
184         BIF_undo_push("Shift NLA strips");
185         allqueue (REDRAWNLA, 0);
186 }
187
188 void synchronize_action_strips(void)
189 {
190         Base *base;
191         bActionStrip *strip;
192         
193         for (base=G.scene->base.first; base; base=base->next) {
194                 /* step 1: adjust strip-lengths */
195                 for (strip = base->object->nlastrips.last; strip; strip=strip->prev) {
196                         if (strip->flag & ACTSTRIP_LOCK_ACTION) {
197                                 float actstart, actend;
198                                 
199                                 calc_action_range(strip->act, &actstart, &actend, 1);
200                                 
201                                 if(strip->actstart!=actstart || strip->actend!=actend) {
202                                         float mapping= (strip->end - strip->start)/(strip->actend - strip->actstart);
203                                         
204                                         strip->start+= mapping*(actstart - strip->actstart);
205                                         strip->end+= mapping*(actend - strip->actend);
206                                         
207                                         strip->actstart= actstart;
208                                         strip->actend= actend;
209                                 }
210                         }
211                 }
212                 
213                 /* step 2: adjust blendin/out values for each strip if option is turned on */
214                 for (strip= base->object->nlastrips.first; strip; strip=strip->next) {
215                         if (strip->flag & ACTSTRIP_AUTO_BLENDS) {
216                                 bActionStrip *prev= strip->prev;
217                                 bActionStrip *next= strip->next;
218                                 float pr[2], nr[2];
219                                 
220                                 strip->blendin = 0.0f;
221                                 strip->blendout = 0.0f;
222                                 
223                                 /* setup test ranges */
224                                 if (prev && next) {
225                                         /* init range for previous strip */
226                                         pr[0]= prev->start;
227                                         pr[1]= prev->end;
228                                         
229                                         /* init range for next strip */
230                                         nr[0]= next->start;
231                                         nr[1]= next->end;
232                                 }
233                                 else if (prev) {
234                                         /* next strip's range is same as previous strip's range  */
235                                         pr[0] = nr[0] = prev->start;
236                                         pr[1] = nr[1] = prev->end;
237                                 }
238                                 else if (next) {
239                                         /* previous strip's range is same as next strip's range */
240                                         pr[0] = nr[0] = next->start;
241                                         pr[1] = nr[1] = next->end;
242                                 }
243                                 else {
244                                         /* there shouldn't be any more strips to loop through for this operation */
245                                         break;
246                                 }
247                                 
248                                 /* test various cases */
249                                 if ( IN_RANGE(pr[1], strip->start, strip->end) && 
250                                         (IN_RANGE(pr[0], strip->start, strip->end)==0) )
251                                 {
252                                         /* previous strip intersects start of current */
253                                         
254                                         if ( IN_RANGE(nr[1], strip->start, strip->end) && 
255                                                 (IN_RANGE(nr[0], strip->start, strip->end)==0) )
256                                         {
257                                                 /* next strip also intersects start of current */
258                                                 if (nr[1] < pr[1])
259                                                         strip->blendin= nr[1] - strip->start;
260                                                 else
261                                                         strip->blendin= pr[1] - strip->start;
262                                         }
263                                         else if (IN_RANGE(nr[0], strip->start, strip->end) && 
264                                                         (IN_RANGE(nr[1], strip->start, strip->end)==0))
265                                         {
266                                                 /* next strip intersects end of current */
267                                                 strip->blendout= strip->end - nr[0];
268                                                 strip->blendin= pr[1] - strip->start;
269                                         }
270                                         else {
271                                                 /* only previous strip intersects current */
272                                                 strip->blendin= pr[1] - strip->start;
273                                         }
274                                 }
275                                 else if (IN_RANGE(pr[0], strip->start, strip->end) && 
276                                                 (IN_RANGE(pr[1], strip->start, strip->end)==0) )
277                                 {
278                                         /* previous strip intersects end of current */
279                                         
280                                         if ( IN_RANGE(nr[0], strip->start, strip->end) && 
281                                                 (IN_RANGE(nr[1], strip->start, strip->end)==0) )
282                                         {
283                                                 /* next strip also intersects end of current */
284                                                 if (nr[1] > pr[1])
285                                                         strip->blendout= strip->end - nr[0];
286                                                 else
287                                                         strip->blendout= strip->end - pr[0];
288                                         }
289                                         else if (IN_RANGE(nr[1], strip->start, strip->end) && 
290                                                         (IN_RANGE(nr[0], strip->start, strip->end)==0))
291                                         {
292                                                 /* next strip intersects start of current */
293                                                 strip->blendin= nr[1] - strip->start;
294                                                 strip->blendout= strip->end - pr[0];
295                                         }
296                                         else {
297                                                 /* only previous strip intersects current */
298                                                 strip->blendout= strip->end - pr[0];
299                                         }
300                                 }
301                                 else if (IN_RANGE(nr[1], strip->start, strip->end) && 
302                                                 (IN_RANGE(nr[0], strip->start, strip->end)==0) )
303                                 {
304                                         /* next strip intersects start of current */
305                                         
306                                         if ( IN_RANGE(pr[1], strip->start, strip->end) && 
307                                                 (IN_RANGE(pr[0], strip->start, strip->end)==0) )
308                                         {
309                                                 /* previous strip also intersects start of current */
310                                                 if (pr[1] < nr[1])
311                                                         strip->blendin= pr[1] - strip->start;
312                                                 else
313                                                         strip->blendin= nr[1] - strip->start;
314                                         }
315                                         else if (IN_RANGE(pr[0], strip->start, strip->end) && 
316                                                         (IN_RANGE(pr[1], strip->start, strip->end)==0))
317                                         {
318                                                 /* previous strip intersects end of current */
319                                                 strip->blendout= strip->end - pr[0];
320                                                 strip->blendin= nr[1] - strip->start;
321                                         }
322                                         else {
323                                                 /* only next strip intersects current */
324                                                 strip->blendin= nr[1] - strip->start;
325                                         }
326                                 }
327                                 else if (IN_RANGE(nr[0], strip->start, strip->end) && 
328                                                 (IN_RANGE(nr[1], strip->start, strip->end)==0) )
329                                 {
330                                         /* next strip intersects end of current */
331                                         
332                                         if ( IN_RANGE(pr[0], strip->start, strip->end) && 
333                                                 (IN_RANGE(pr[1], strip->start, strip->end)==0) )
334                                         {
335                                                 /* previous strip also intersects end of current */
336                                                 if (pr[1] > nr[1])
337                                                         strip->blendout= strip->end - pr[0];
338                                                 else
339                                                         strip->blendout= strip->end - nr[0];
340                                         }
341                                         else if (IN_RANGE(pr[1], strip->start, strip->end) && 
342                                                         (IN_RANGE(pr[0], strip->start, strip->end)==0))
343                                         {
344                                                 /* previous strip intersects start of current */
345                                                 strip->blendin= pr[1] - strip->start;
346                                                 strip->blendout= strip->end - nr[0];
347                                         }
348                                         else {
349                                                 /* only next strip intersects current */
350                                                 strip->blendout= strip->end - nr[0];
351                                         }
352                                 }
353                                 
354                                 /* make sure blending stays in ranges */
355                                 CLAMP(strip->blendin, 0, (strip->end-strip->start));
356                                 CLAMP(strip->blendout, 0, (strip->end-strip->start));
357                         }
358                 }
359         }
360         
361 }
362
363 void reset_action_strips(int val)
364 {
365         Base *base;
366         bActionStrip *strip;
367         
368         for (base=G.scene->base.first; base; base=base->next) {
369                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
370                         continue;
371                 
372                 for (strip = base->object->nlastrips.last; strip; strip=strip->prev) {
373                         if (strip->flag & ACTSTRIP_SELECT) {
374                                 if(val==2) {
375                                         calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
376                                 }
377                                 else if(val==1) {
378                                         float mapping= (strip->actend - strip->actstart)/(strip->end - strip->start);
379                                         
380                                         strip->end= strip->start + mapping*(strip->end - strip->start);
381                                 }
382                                 base->object->ctime= -1234567.0f;       // eveil! 
383                                 DAG_object_flush_update(G.scene, base->object, OB_RECALC_OB|OB_RECALC_DATA);
384                         }
385                 }
386         }
387         BIF_undo_push("Reset NLA strips");
388         allqueue (REDRAWVIEW3D, 0);
389         allqueue (REDRAWACTION, 0);
390         allqueue (REDRAWNLA, 0);
391 }
392
393 void snap_action_strips(int snap_mode)
394 {
395         Base *base;
396         bActionStrip *strip;
397         
398         for (base=G.scene->base.first; base; base=base->next) {
399                 /* object has ipo - these keyframes should be able to be snapped, even if strips are collapsed */
400                 if (base->object->ipo) {
401                         snap_ipo_keys(base->object->ipo, snap_mode);
402                 }
403                 
404                 /* object is collapsed - action and nla strips not shown/editable */
405                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
406                         continue;
407                 
408                 /* snap action strips */
409                 for (strip = base->object->nlastrips.last; strip; strip=strip->prev) {
410                         if (strip->flag & ACTSTRIP_SELECT) {
411                                 if (snap_mode==1) {
412                                         /* nearest frame */
413                                         strip->start= floor(strip->start+0.5);
414                                         strip->end= floor(strip->end+0.5);
415                                 }
416                                 else if (snap_mode==2) {
417                                         /* current frame */
418                                         float diff;
419                                         if (CFRA < strip->start) {
420                                                 diff = (strip->start - CFRA);
421                                                 strip->start -= diff;
422                                                 strip->end -= diff;
423                                         }
424                                         else {
425                                                 diff = (CFRA - strip->start);
426                                                 strip->start += diff;
427                                                 strip->end += diff;
428                                         }
429                                 }
430                                 else if (snap_mode==3) {
431                                         /* nearest second */
432                                         float secf = FPS;
433                                         strip->start= (float)(floor(strip->start/secf + 0.5f) * secf);
434                                         strip->end= (float)(floor(strip->end/secf + 0.5f) * secf);
435                                 }
436                         }
437                 }
438                 
439                 /* object has action */
440                 if (base->object->action) {
441                         ListBase act_data = {NULL, NULL};
442                         bActListElem *ale;
443                         int filter;
444                         
445                         /* filter action data */
446                         filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS);
447                         actdata_filter(&act_data, filter, base->object->action, ACTCONT_ACTION);
448                         
449                         /* snap to frame */
450                         for (ale= act_data.first; ale; ale= ale->next) {
451                                 actstrip_map_ipo_keys(base->object, ale->key_data, 0, 1); 
452                                 snap_ipo_keys(ale->key_data, snap_mode);
453                                 actstrip_map_ipo_keys(base->object, ale->key_data, 1, 1);
454                         }
455                         BLI_freelistN(&act_data);
456                         
457                         remake_action_ipos(base->object->action);
458                 }
459         }
460         BIF_undo_push("Snap NLA strips");
461         allqueue (REDRAWVIEW3D, 0);
462         allqueue (REMAKEIPO, 0);
463         allqueue (REDRAWIPO, 0);
464         allqueue (REDRAWACTION, 0);
465         allqueue (REDRAWNLA, 0);
466 }
467
468 static void set_active_strip(Object *ob, bActionStrip *act)
469 {
470         bActionStrip *strip;
471         
472         for (strip = ob->nlastrips.first; strip; strip=strip->next)
473                 strip->flag &= ~ACTSTRIP_ACTIVE;
474         
475         if(act) {
476                 act->flag |= ACTSTRIP_ACTIVE;
477         
478                 if(ob->action!=act->act) {
479                         if(ob->action) ob->action->id.us--;
480                         if(act->act->id.lib) {
481                                 ob->action= NULL;
482                         }
483                         else {
484                                 ob->action= act->act;
485                                 id_us_plus(&ob->action->id);
486                         }                       
487                         allqueue(REDRAWIPO, 0);
488                         allqueue(REDRAWVIEW3D, 0);
489                         allqueue(REDRAWACTION, 0);
490                         allqueue(REDRAWNLA, 0);
491                         ob->ctime= -1234567.0f; // eveil! 
492                         DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
493                 }
494         }       
495 }
496
497 void convert_nla(void)
498 {
499         bActionStrip *strip;
500         Object *ob= OBACT;
501         char str[128];
502         short event;
503         
504         if ((ob==NULL)||(ob->action==NULL)) {
505                 error("Need active Object to convert Action to NLA Strip");
506                 return;
507         }
508         
509         sprintf(str, "Convert Action%%t|%s to NLA Strip%%x1", ob->action->id.name+2);
510         event = pupmenu(str);
511         
512         if (event==1) {
513                 if (ob->action) {
514                         deselect_nlachannel_keys(0);
515                         strip = convert_action_to_strip(ob); //creates a new NLA strip from the action in given object
516                         set_active_strip(ob, strip);
517                         BIF_undo_push("Convert NLA");
518                         allqueue (REDRAWNLA, 0);
519                 }
520         }
521 }
522
523 static void add_nla_block(short event)
524 {
525         Object *ob= OBACT;
526         bAction *act=NULL;
527         bActionStrip *strip;
528         int             cur;
529
530         if (event!=-1){
531                 for (cur = 1, act=G.main->action.first; act; act=act->id.next, cur++){
532                         if (cur==event){
533                                 break;
534                         }
535                 }
536         }
537         
538         /* Bail out if no action was chosen */
539         if (!act){
540                 return;
541         }
542         
543         /* Initialize the new action block */
544         strip = MEM_callocN(sizeof(bActionStrip), "bActionStrip");
545         
546         deselect_nlachannel_keys(0);
547         
548         /* Link the action to the strip */
549         strip->act = act;
550         id_us_plus(&act->id);
551         calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
552         strip->start = G.scene->r.cfra;         /* could be mval[0] another time... */
553         strip->end = strip->start + (strip->actend-strip->actstart);
554                 /* simple prevention of zero strips */
555         if(strip->start>strip->end-2) 
556                 strip->end= strip->start+100;
557         strip->repeat = 1.0;
558         
559         strip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION;
560         
561         find_stridechannel(ob, strip);
562         set_active_strip(ob, strip);
563         strip->object= group_get_member_with_action(ob->dup_group, act);
564         if(strip->object)
565                 id_lib_extern(&strip->object->id);      /* checks lib data, sets correct flag for saving then */
566
567         if(ob->nlastrips.first == NULL)
568                 ob->nlaflag |= OB_NLA_OVERRIDE;
569         
570         BLI_addtail(&ob->nlastrips, strip);
571
572         BIF_undo_push("Add NLA strip");
573 }
574
575 static void add_nla_block_by_name(char name[32], Object *ob, short hold, short add, float repeat)
576 {
577         bAction *act=NULL;
578         bActionStrip *strip;
579         int             cur;
580
581         if (name){
582                 for (cur = 1, act=G.main->action.first; act; act=act->id.next, cur++){
583                         if (strcmp(name,act->id.name)==0) {
584                                 break;
585                         }
586                 }
587         }
588         
589         /* Bail out if no action was chosen */
590         if (!act){
591                 return;
592         }
593         
594         /* Initialize the new action block */
595         strip = MEM_callocN(sizeof(bActionStrip), "bActionStrip");
596         
597         deselect_nlachannel_keys(0);
598         
599         /* Link the action to the strip */
600         strip->act = act;
601         calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
602         strip->start = G.scene->r.cfra;         /* could be mval[0] another time... */
603         strip->end = strip->start + (strip->actend-strip->actstart);
604                 /* simple prevention of zero strips */
605         if(strip->start>strip->end-2) 
606                 strip->end= strip->start+100;
607         
608         strip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION; //|ACTSTRIP_USEMATCH;
609         
610         if (hold==1)
611                 strip->flag = strip->flag|ACTSTRIP_HOLDLASTFRAME;
612                 
613         if (add==1)
614                 strip->mode = ACTSTRIPMODE_ADD;
615         
616         find_stridechannel(ob, strip);
617         
618         set_active_strip(ob, strip);
619         
620         strip->repeat = repeat;
621         
622         act->id.us++;
623         
624         if(ob->nlastrips.first == NULL)
625                 ob->nlaflag |= OB_NLA_OVERRIDE;
626                 
627         BLI_addtail(&ob->nlastrips, strip);
628 }
629
630 static void add_nla_databrowse_callback(unsigned short val)
631 {
632         /* val is not used, databrowse needs it to optional pass an event */
633         short event;
634         
635         if(OBACT==NULL) return;
636         
637         event= G.snla->menunr;  /* set by databrowse or pupmenu */
638         
639         add_nla_block(event);
640 }
641
642 /* Adds strip to to active Object */
643 void add_nlablock(void)
644 {
645         Object *ob= OBACT;
646         short event;
647         short nr=0;
648         char *str, title[64];
649         
650         if(ob==NULL) {
651                 error("Need active Object to add NLA strips");
652                 return;
653         }
654         
655         sprintf(title, "Add Action strip to: %s", ob->id.name+2);
656         
657         /* Popup action menu */
658         IDnames_to_pupstring(&str, title, NULL, &G.main->action, (ID *)G.scene, &nr);
659         
660         if(nr==-2) {
661                 MEM_freeN(str);
662
663                 activate_databrowse((ID *)NULL, ID_AC, 0, 0, &G.snla->menunr, 
664                                                         add_nla_databrowse_callback );
665                 
666                 return;                 
667         }
668         else {
669                 event = pupmenu_col(str, 20);
670                 MEM_freeN(str);
671                 add_nla_block(event);
672         }
673 }
674
675 /* Creates a new action, and makes a new actionstrip of that */
676 void add_empty_nlablock(void)
677 {
678         Object *ob= OBACT;
679         bAction *act= NULL;
680         bActionStrip *strip;
681         
682         /* check for active object first - will add strip to active object */
683         if (ob == NULL) 
684                 return;
685                 
686         /* make new action */
687         if ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
688                 act= add_empty_action("ObAction");
689         else
690                 act= add_empty_action("Action");
691                 
692         /* make a new strip for it */
693         add_nla_block_by_name(act->id.name, ob, 0, 1, 1.0f);
694         strip= ob->nlastrips.last; 
695         
696         /* change some settings of the strip - try to avoid bad scaling */
697         if ((EFRA-CFRA) < 100) {
698                 strip->flag |= ACTSTRIP_AUTO_BLENDS;
699                 strip->flag &= ~ACTSTRIP_LOCK_ACTION;
700                 strip->actstart = CFRA;
701                 strip->actend = CFRA + 100;
702                 
703                 strip->start = CFRA;
704                 strip->end = CFRA + 100;
705         }
706         else {
707                 strip->flag |= ACTSTRIP_AUTO_BLENDS;
708                 strip->flag &= ~ACTSTRIP_LOCK_ACTION;
709                 strip->actstart = CFRA;
710                 strip->actend = EFRA;
711                 
712                 strip->start = CFRA;
713                 strip->end = EFRA;
714         }
715         
716         BIF_undo_push("Add NLA strip");
717 }
718
719 /* Adds strip to to active Object */
720 static void relink_active_strip(void)
721 {
722         Object *ob= OBACT;
723         bActionStrip *strip;
724         bAction *act;
725         short event;
726         short cur;
727         char *str;
728         
729         if(ob==NULL) return;
730         if(ob->nlaflag & OB_NLA_COLLAPSED) return;
731         
732         for (strip = ob->nlastrips.first; strip; strip=strip->next)
733                 if(strip->flag & ACTSTRIP_ACTIVE)
734                         break;
735         
736         if(strip==NULL) return;
737         
738         /* Popup action menu */
739         IDnames_to_pupstring(&str, "Relink Action strip", NULL, &G.main->action, (ID *)G.scene, NULL);
740         if(str) {
741                 event = pupmenu_col(str, 20);
742                 MEM_freeN(str);
743                 
744                 for (cur = 1, act=G.main->action.first; act; act=act->id.next, cur++){
745                         if (cur==event){
746                                 break;
747                         }
748                 }
749                 
750                 if(act) {
751                         if(strip->act) strip->act->id.us--;
752                         strip->act = act;
753                         id_us_plus(&act->id);
754                         
755                         allqueue(REDRAWVIEW3D, 0);
756                         allqueue(REDRAWACTION, 0);
757                         allqueue(REDRAWNLA, 0);
758                 }
759         }
760 }
761
762
763
764 /* Left hand side of channels display, selects objects */
765 static void mouse_nlachannels(short mval[2])
766 {
767         bActionStrip *strip= NULL;
768         Base    *base;
769         Object *ob=NULL;
770         float   x,y;
771         int             click, obclick=0, actclick=0;
772         int             wsize;
773         
774         wsize = (count_nla_levels ()*(NLACHANNELHEIGHT+NLACHANNELSKIP));
775         wsize+= NLACHANNELHEIGHT/2;
776
777         areamouseco_to_ipoco(G.v2d, mval, &x, &y);
778         click = (int)floor( ((float)wsize - y) / (NLACHANNELHEIGHT+NLACHANNELSKIP));
779         
780         if (click<0)
781                 return;
782
783         for (base = G.scene->base.first; base; base=base->next){
784                 if (nla_filter(base)) {
785                         ob= base->object;
786                         
787                         /* See if this is a base selected */
788                         if (click==0) {
789                                 obclick= 1;
790                                 break;
791                         }
792                         click--;
793                         
794                         /* see if any strips under object */
795                         if ((ob->nlaflag & OB_NLA_COLLAPSED)==0) {
796                                 /* See if this is an action */
797                                 if (ob->action){
798                                         if (click==0) {
799                                                 actclick= 1;
800                                                 break;
801                                         }
802                                         click--;
803                                 }
804
805                                 /* See if this is an nla strip */
806                                 if(ob->nlastrips.first) {
807                                         for (strip = ob->nlastrips.first; strip; strip=strip->next){
808                                                 if (click==0) break;
809                                                 click--;                                
810                                         }
811                                         if (strip && click==0) break;
812                                 }
813                         }
814                 }
815         }
816
817         if (!base)
818                 return;
819
820         /* Handle object strip selection */
821         if (G.qual & LR_SHIFTKEY) {
822                 if (base->flag & SELECT) base->flag &= ~SELECT;
823                 else base->flag |= SELECT;
824         }
825         else {
826                 deselect_nlachannels (0);       // Auto clear
827                 base->flag |= SELECT;
828         }
829         ob->flag= base->flag;
830         
831         if(base!=BASACT) set_active_base(base);
832         
833         if(actclick) /* de-activate all strips */
834                 set_active_strip(ob, NULL);
835         else if(strip) {
836                 if(mval[0] >= (NLAWIDTH-16)) /* toggle strip muting */
837                         strip->flag ^= ACTSTRIP_MUTE;
838                 else /* set action */
839                         set_active_strip(ob, strip);
840         }
841
842         /* icon toggles beside strip */
843         if (obclick && mval[0]<20) {
844                 /* collapse option for NLA object strip */
845                 ob->nlaflag ^= OB_NLA_COLLAPSED;
846         }
847         else if(obclick && mval[0]<36) {
848                 /* override option for NLA */
849                 ob->nlaflag ^= OB_NLA_OVERRIDE;
850         }
851         else if((obclick) && (ob->ipo) && (mval[0] >= (NLAWIDTH-16))) {
852                 /* mute Object IPO-block */
853                 ob->ipo->muteipo = (ob->ipo->muteipo)? 0: 1;
854         }
855         
856         ob->ctime= -1234567.0f; // eveil! 
857         DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
858
859         allqueue(REDRAWIPO, 0);
860         allqueue(REDRAWVIEW3D, 0);
861         allqueue(REDRAWACTION, 0);
862         allqueue(REDRAWNLA, 0);
863         
864 }
865
866 void deselect_nlachannel_keys (int test)
867 {
868         Base                    *base;
869         int                             sel=1;
870         bActionChannel  *chan;
871         bActionStrip    *strip;
872         bConstraintChannel *conchan;
873         
874         /* Determine if this is selection or deselection */
875         if (test){
876                 for (base=G.scene->base.first; base && sel; base=base->next){           
877                         /* Test object ipos */
878                         if (is_ipo_key_selected(base->object->ipo)){
879                                 sel = 0;
880                                 break;
881                         }
882                         
883                         /* Test object constraint ipos */
884                         if (sel){
885                                 for (conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next){
886                                         if (is_ipo_key_selected(conchan->ipo)){
887                                                 sel=0;
888                                                 break;
889                                         }
890                                 }
891                         }
892                         
893                         /* check if collapsed */
894                         if (base->object->nlaflag & OB_NLA_COLLAPSED)
895                                 continue;
896                         
897                         /* Test action ipos */
898                         if (sel){
899                                 if (base->object->action){
900                                         for (chan=base->object->action->chanbase.first; chan; chan=chan->next){
901                                                 if (is_ipo_key_selected(chan->ipo)){
902                                                         sel=0;
903                                                         break;
904                                                 }
905
906                                                 /* Test action constraints */
907                                                 if (sel){
908                                                         for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next){
909                                                                 if (is_ipo_key_selected(conchan->ipo)){
910                                                                         sel=0;
911                                                                         break;
912                                                                 }
913                                                         }
914                                                 }
915                                         }
916                                 }
917                         }
918                         
919                         /* Test NLA strips */
920                         if (sel){
921                                 for (strip=base->object->nlastrips.first; strip; strip=strip->next){
922                                         if (strip->flag & ACTSTRIP_SELECT){
923                                                 sel = 0;
924                                                 break;
925                                         }
926                                 }
927                         }
928                 }
929         }
930         else
931                 sel=0;
932         
933         
934         /* Set the flags */
935         for (base=G.scene->base.first; base; base=base->next){          
936                 /* Set the object ipos */
937                 set_ipo_key_selection(base->object->ipo, sel);
938                 
939                 /* Set the object constraint ipos */
940                 for (conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next){
941                         set_ipo_key_selection(conchan->ipo, sel);                       
942                 }
943
944                 /* check if collapsed */
945                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
946                         continue;
947                 
948                 /* Set the action ipos */
949                 if (base->object->action){
950                         for (chan=base->object->action->chanbase.first; chan; chan=chan->next){
951                                 set_ipo_key_selection(chan->ipo, sel);
952                                 /* Set the action constraint ipos */
953                                 for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next)
954                                         set_ipo_key_selection(conchan->ipo, sel);
955                         }
956                 }
957                 
958                 /* Set the nlastrips */
959                 for (strip=base->object->nlastrips.first; strip; strip=strip->next){
960                         if (sel)
961                                 strip->flag |= ACTSTRIP_SELECT;
962                         else
963                                 strip->flag &= ~ACTSTRIP_SELECT;
964                 }
965         }
966 }
967
968 /* very bad call! */
969 static void recalc_all_ipos(void)
970 {
971         Ipo *ipo;
972         IpoCurve *icu;
973         
974         /* Go to each ipo */
975         for (ipo=G.main->ipo.first; ipo; ipo=ipo->id.next){
976                 for (icu = ipo->curve.first; icu; icu=icu->next){
977                         sort_time_ipocurve(icu);
978                         testhandles_ipocurve(icu);
979                 }
980         }
981 }
982
983 void transform_nlachannel_keys(int mode, int dummy)
984 {
985         switch (mode) {
986                 case 'g':
987                 {
988                         initTransform(TFM_TIME_TRANSLATE, CTX_NONE);
989                         Transform();
990                 }
991                         break;
992                 case 's':
993                 {
994                         initTransform(TFM_TIME_SCALE, CTX_NONE);
995                         Transform();
996                 }
997                         break;
998                 case 'e':
999                 {
1000                         initTransform(TFM_TIME_EXTEND, CTX_NONE);
1001                         Transform();
1002                 }
1003                         break;
1004         }
1005 }
1006
1007 void delete_nlachannel_keys(void)
1008 {
1009         Base *base;
1010         bActionChannel *chan;
1011         bConstraintChannel *conchan;
1012         bActionStrip *strip, *nextstrip;
1013                 
1014         for (base = G.scene->base.first; base; base=base->next){
1015                 /* Delete object ipos */
1016                 delete_ipo_keys(base->object->ipo);
1017                 
1018                 /* Delete object constraint keys */
1019                 for(conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next)
1020                         delete_ipo_keys(conchan->ipo);
1021
1022                 /* skip actions and nlastrips if object collapsed */
1023                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
1024                         continue;
1025                         
1026                 /* Delete NLA strips */
1027                 for (strip = base->object->nlastrips.first; strip; strip=nextstrip){
1028                         nextstrip=strip->next;
1029                         if (strip->flag & ACTSTRIP_SELECT){
1030                                 free_actionstrip(strip);
1031                                 BLI_remlink(&base->object->nlastrips, strip);
1032                                 MEM_freeN(strip);
1033                         }
1034                 }
1035                 
1036                 /* Delete action ipos */
1037                 if (base->object->action){
1038                         for (chan=base->object->action->chanbase.first; chan; chan=chan->next){
1039                                 if (EDITABLE_ACHAN(chan))
1040                                         delete_ipo_keys(chan->ipo);
1041                                         
1042                                 /* Delete action constraint keys */
1043                                 for(conchan=chan->constraintChannels.first; conchan; conchan=conchan->next){
1044                                         if (EDITABLE_CONCHAN(conchan))
1045                                                 delete_ipo_keys(conchan->ipo);
1046                                 }
1047                         }
1048                 }
1049         }
1050         
1051         recalc_all_ipos();      // bad
1052         synchronize_action_strips();
1053         
1054         BIF_undo_push("Delete NLA keys");
1055         allspace(REMAKEIPO,0);
1056         allqueue (REDRAWVIEW3D, 0);
1057         allqueue(REDRAWNLA, 0);
1058         allqueue(REDRAWIPO, 0);
1059 }
1060
1061 void duplicate_nlachannel_keys(void)
1062 {
1063         Base *base;
1064         bActionChannel *chan;
1065         bConstraintChannel *conchan;
1066         bActionStrip *strip, *laststrip;
1067         
1068         /* Find selected items */
1069         for (base = G.scene->base.first; base; base=base->next){        
1070                 /* Duplicate object keys */
1071                 duplicate_ipo_keys(base->object->ipo);
1072                 
1073                 /* Duplicate object constraint keys */
1074                 for(conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next)
1075                         duplicate_ipo_keys(conchan->ipo);
1076                 
1077                 /* skip actions and nlastrips if object collapsed */
1078                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
1079                         continue;
1080                         
1081                 /* Duplicate nla strips */
1082                 laststrip = base->object->nlastrips.last;
1083                 for (strip=base->object->nlastrips.first; strip; strip=strip->next){
1084                         if (strip->flag & ACTSTRIP_SELECT){
1085                                 bActionStrip *newstrip;
1086                                 
1087                                 copy_actionstrip(&newstrip, &strip);
1088                                 
1089                                 BLI_addtail(&base->object->nlastrips, newstrip);
1090                                 
1091                                 strip->flag &= ~ACTSTRIP_SELECT;
1092                                 newstrip->flag |= ACTSTRIP_SELECT;
1093                                 set_active_strip(base->object, newstrip);
1094
1095                         }
1096                         if (strip==laststrip)
1097                                 break;
1098                 }
1099                 
1100                 /* Duplicate actionchannel keys */
1101                 if (base->object->action){
1102                         for (chan=base->object->action->chanbase.first; chan; chan=chan->next){
1103                                 if (EDITABLE_ACHAN(chan))
1104                                         duplicate_ipo_keys(chan->ipo);
1105                                         
1106                                 /* Duplicate action constraint keys */
1107                                 for(conchan=chan->constraintChannels.first; conchan; conchan=conchan->next) {
1108                                         if (EDITABLE_CONCHAN(conchan))
1109                                                 duplicate_ipo_keys(conchan->ipo);
1110                                 }
1111                         }
1112                 }
1113         }
1114         
1115         BIF_undo_push("Duplicate NLA");
1116         transform_nlachannel_keys ('g', 0);
1117 }
1118
1119 void borderselect_nla(void)
1120
1121         Base *base;
1122         rcti rect;
1123         rctf rectf;
1124         int  val, selectmode;
1125         short   mval[2];
1126         float   ymin, ymax;
1127         bActionStrip *strip;
1128         bConstraintChannel *conchan;
1129         
1130         if ( (val = get_border (&rect, 3)) ){
1131             if (val == LEFTMOUSE)
1132                         selectmode = SELECT_ADD;
1133             else
1134                         selectmode = SELECT_SUBTRACT;
1135           
1136                 mval[0]= rect.xmin;
1137                 mval[1]= rect.ymin+2;
1138                 areamouseco_to_ipoco(G.v2d, mval, &rectf.xmin, &rectf.ymin);
1139                 mval[0]= rect.xmax;
1140                 mval[1]= rect.ymax-2;
1141                 areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
1142                 
1143                 ymax = count_nla_levels();
1144                 ymax*= (NLACHANNELHEIGHT+NLACHANNELSKIP);
1145                 ymax+= (NLACHANNELHEIGHT+NLACHANNELSKIP)/2;
1146         
1147                 for (base=G.scene->base.first; base; base=base->next){
1148                         if (nla_filter(base)) {
1149                                 
1150                                 ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1151                                 
1152                                 /* Check object ipos */
1153                                 if (base->object->ipo){
1154                                         if (!((ymax < rectf.ymin) || (ymin > rectf.ymax)))
1155                                                 borderselect_ipo_key(base->object->ipo, rectf.xmin, rectf.xmax,
1156                                  selectmode);
1157                                 }
1158                                 /* Check object constraint ipos */
1159                                 for (conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next){
1160                                         if (!((ymax < rectf.ymin) || (ymin > rectf.ymax)))
1161                                                 borderselect_ipo_key(conchan->ipo, rectf.xmin, rectf.xmax,
1162                                  selectmode);
1163                                 }
1164                                 
1165                                 ymax=ymin;
1166                                 
1167                                 /* skip actions and nlastrips if object collapsed */
1168                                 if (base->object->nlaflag & OB_NLA_COLLAPSED)
1169                                         continue;
1170                                 
1171                                 /* Check action ipos */
1172                                 if (base->object->action){
1173                                         bActionChannel *chan;
1174                                         float xmin, xmax;
1175                                         
1176                                         ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1177                                         
1178                                         /* if action is mapped in NLA, it returns a correction */
1179                                         xmin= get_action_frame(base->object, rectf.xmin);
1180                                         xmax= get_action_frame(base->object, rectf.xmax);
1181                                         
1182                                         if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))){
1183                                                 for (chan=base->object->action->chanbase.first; chan; chan=chan->next){
1184                                                         borderselect_ipo_key(chan->ipo, xmin, xmax, selectmode);
1185                                                         /* Check action constraint ipos */
1186                                                         for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next)
1187                                                                 borderselect_ipo_key(conchan->ipo, xmin, xmax, selectmode);
1188                                                 }
1189                                         }
1190
1191                                         ymax=ymin;
1192                                 }       /* End of if action */
1193                                 
1194                                 /* Skip nlastrips */
1195                                 for (strip=base->object->nlastrips.first; strip; strip=strip->next){
1196                                         ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1197                                         //
1198                                         if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))){
1199                                                 if (!((rectf.xmax<strip->start) || (rectf.xmin>strip->end))){
1200                                                         if (val==1)
1201                                                                 strip->flag |= ACTSTRIP_SELECT;
1202                                                         else
1203                                                                 strip->flag &= ~ACTSTRIP_SELECT;
1204                                                 }
1205                                         }
1206                                         
1207                                         ymax=ymin;
1208                                 }
1209                         }
1210                 }       
1211                 BIF_undo_push("Border select NLA");
1212                 allqueue(REDRAWMARKER, 0);
1213         }
1214 }
1215
1216 /* right hand side of window, does ipokeys, actionkeys or strips */
1217 static void mouse_nla(int selectmode)
1218 {
1219         Base *base;
1220         bAction *act;
1221         bActionChannel *chan;
1222         bActionStrip *rstrip;
1223         bConstraintChannel *conchan;
1224         TimeMarker *marker;
1225         float   selx;
1226         short   mval[2];
1227         short sel, isdone=0;
1228         
1229         getmouseco_areawin (mval);
1230         
1231         /* Try object ipo or ob-constraint ipo selection */
1232         base= get_nearest_nlachannel_ob_key(&selx, &sel);
1233         marker=find_nearest_marker(1);
1234         if (base) {
1235                 isdone= 1;
1236                 
1237                 if (selectmode == SELECT_REPLACE){
1238                         deselect_nlachannel_keys(0);
1239                         selectmode = SELECT_ADD;
1240                 }
1241                 
1242                 select_ipo_key(base->object->ipo, selx, selectmode);
1243                 
1244                 /* Try object constraint selection */
1245                 for (conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next)
1246                         select_ipo_key(conchan->ipo, selx, selectmode);
1247         }
1248         else if (marker) {
1249                 /* marker */            
1250                 if (selectmode == SELECT_REPLACE) {                     
1251                         deselect_markers(0, 0);
1252                         marker->flag |= SELECT;
1253                 }
1254                 else if (selectmode == SELECT_INVERT) {
1255                         if (marker->flag & SELECT)
1256                                 marker->flag &= ~SELECT;
1257                         else
1258                                 marker->flag |= SELECT;
1259                 }
1260                 else if (selectmode == SELECT_ADD) 
1261                         marker->flag |= SELECT;
1262                 else if (selectmode == SELECT_SUBTRACT)
1263                         marker->flag &= ~SELECT;
1264                 
1265                 std_rmouse_transform(transform_markers);
1266                 
1267                 allqueue(REDRAWMARKER, 0);
1268         }
1269         else {
1270                 /* Try action ipo selection */
1271                 act= get_nearest_nlachannel_ac_key(&selx, &sel);
1272                 if (act) {
1273                         isdone= 1;
1274                         
1275                         if (selectmode == SELECT_REPLACE){
1276                                 deselect_nlachannel_keys(0);
1277                                 selectmode = SELECT_ADD;
1278                         }
1279                         
1280                         for (chan=act->chanbase.first; chan; chan=chan->next) {
1281                                 select_ipo_key(chan->ipo, selx, selectmode);
1282                                 /* Try action constraint selection */
1283                                 for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next)
1284                                         select_ipo_key(conchan->ipo, selx, selectmode);
1285                         }
1286                 }
1287                 else {
1288         
1289                         /* Try nla strip selection */
1290                         base= get_nearest_nlastrip(&rstrip, &sel);
1291                         if (base){
1292                                 isdone= 1;
1293                                 
1294                                 if (!(G.qual & LR_SHIFTKEY)){
1295                                         deselect_nlachannel_keys(0);
1296                                         sel = 0;
1297                                 }
1298                                 
1299                                 if (sel)
1300                                         rstrip->flag &= ~ACTSTRIP_SELECT;
1301                                 else
1302                                         rstrip->flag |= ACTSTRIP_SELECT;
1303                                 
1304                                 set_active_strip(base->object, rstrip);
1305                                 
1306                                 if(base!=BASACT) set_active_base(base);
1307                         }
1308                 }
1309         }
1310         
1311         if(isdone) {
1312                 std_rmouse_transform(transform_nlachannel_keys);
1313                 
1314                 allqueue(REDRAWIPO, 0);
1315                 allqueue(REDRAWVIEW3D, 0);
1316                 allqueue(REDRAWNLA, 0);
1317         }
1318 }
1319
1320 /* This function is currently more complicated than it seems like it should be.
1321 * However, this will be needed once the nla strip timeline is more complex */
1322 static Base *get_nearest_nlastrip (bActionStrip **rstrip, short *sel)
1323 {
1324         Base *base, *firstbase=NULL;
1325         bActionStrip *strip, *firststrip=NULL, *foundstrip=NULL;
1326         rctf    rectf;
1327         float ymin, ymax;
1328         short mval[2];
1329         short foundsel = 0;
1330
1331         getmouseco_areawin (mval);
1332         
1333         mval[0]-=7;
1334         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmin, &rectf.ymin);
1335         
1336         mval[0]+=14;
1337         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
1338         
1339         ymax = count_nla_levels();
1340         ymax*=(NLACHANNELHEIGHT + NLACHANNELSKIP);
1341         ymax+= NLACHANNELHEIGHT/2;
1342         
1343         for (base = G.scene->base.first; base; base=base->next){
1344                 if (nla_filter(base)) {
1345                         
1346                         /* Skip object ipos */
1347                         ymax-=(NLACHANNELHEIGHT+NLACHANNELSKIP);
1348                         
1349                         /* check if skip strips if collapsed */
1350                         if (base->object->nlaflag & OB_NLA_COLLAPSED)
1351                                 continue;
1352
1353                         /* Skip action ipos */
1354                         if (base->object->action)
1355                                 ymax-=(NLACHANNELHEIGHT+NLACHANNELSKIP);
1356                         
1357                         /* the strips */
1358                         for (strip=base->object->nlastrips.first; strip; strip=strip->next){
1359                                 ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1360                                 /* Do Ytest */
1361                                 if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))){
1362                                         /* Do XTest */
1363                                         if (!((rectf.xmax<strip->start) || (rectf.xmin>strip->end))){
1364                                                 if (!firstbase){
1365                                                         firstbase=base;
1366                                                         firststrip=strip;
1367                                                         *sel = strip->flag & ACTSTRIP_SELECT;
1368                                                 }
1369                                                 
1370                                                 if (strip->flag & ACTSTRIP_SELECT){ 
1371                                                         if (!foundsel){
1372                                                                 foundsel=1;
1373                                                                 foundstrip = strip;
1374                                                         }
1375                                                 }
1376                                                 else if (foundsel && strip != foundstrip){
1377                                                         *rstrip=strip;
1378                                                         *sel = 0;
1379                                                         return base;
1380                                                 }
1381                                         }
1382                                 }
1383                                 ymax=ymin;
1384                         }
1385                 }
1386         }
1387         *rstrip=firststrip;
1388         return firstbase;
1389 }
1390
1391 static Base *get_nearest_nlachannel_ob_key (float *index, short *sel)
1392 {
1393         Base *base;
1394         IpoCurve *icu;
1395         Base *firstbase=NULL;
1396         bConstraintChannel *conchan;
1397         int     foundsel=0;
1398         float firstvertx=-1, foundx=-1;
1399         int i;
1400         short mval[2];
1401         float ymin, ymax;
1402         rctf    rectf;
1403         
1404         *index=0;
1405         
1406         getmouseco_areawin (mval);
1407         
1408         mval[0]-=7;
1409         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmin, &rectf.ymin);
1410         
1411         mval[0]+=14;
1412         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
1413         
1414         ymax = count_nla_levels();
1415         
1416         ymax*= (NLACHANNELHEIGHT + NLACHANNELSKIP);
1417         ymax+= NLACHANNELHEIGHT/2;
1418         
1419         *sel=0;
1420         
1421         for (base=G.scene->base.first; base; base=base->next){
1422                 if (nla_filter(base)) {
1423                         
1424                         ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1425                         
1426                         /* Handle object ipo selection */
1427                         if (base->object->ipo){
1428                                 if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))){
1429                                         for (icu=base->object->ipo->curve.first; icu; icu=icu->next){
1430                                                 for (i=0; i<icu->totvert; i++){
1431                                                         if (icu->bezt[i].vec[1][0] > rectf.xmin && icu->bezt[i].vec[1][0] <= rectf.xmax ){
1432                                                                 if (!firstbase){
1433                                                                         firstbase=base;
1434                                                                         firstvertx=icu->bezt[i].vec[1][0];
1435                                                                         *sel = icu->bezt[i].f2 & 1;     
1436                                                                 }
1437                                                                 
1438                                                                 if (icu->bezt[i].f2 & 1){ 
1439                                                                         if (!foundsel){
1440                                                                                 foundsel=1;
1441                                                                                 foundx = icu->bezt[i].vec[1][0];
1442                                                                         }
1443                                                                 }
1444                                                                 else if (foundsel && icu->bezt[i].vec[1][0] != foundx){
1445                                                                         *index=icu->bezt[i].vec[1][0];
1446                                                                         *sel = 0;
1447                                                                         return base;
1448                                                                 }
1449                                                         }
1450                                                 }
1451                                         }
1452                                 }
1453                         }
1454                         /* Handle object constraint ipos */
1455                         for (conchan=base->object->constraintChannels.first; conchan; conchan=conchan->next){
1456                                 if ( !((ymax < rectf.ymin) || (ymin > rectf.ymax)) && conchan->ipo){
1457                                         for (icu=conchan->ipo->curve.first; icu; icu=icu->next){
1458                                                 for (i=0; i<icu->totvert; i++){
1459                                                         if (icu->bezt[i].vec[1][0] > rectf.xmin && icu->bezt[i].vec[1][0] <= rectf.xmax ){
1460                                                                 if (!firstbase){
1461                                                                         firstbase=base;
1462                                                                         firstvertx=icu->bezt[i].vec[1][0];
1463                                                                         *sel = icu->bezt[i].f2 & 1;     
1464                                                                 }
1465                                                                 
1466                                                                 if (icu->bezt[i].f2 & 1){ 
1467                                                                         if (!foundsel){
1468                                                                                 foundsel=1;
1469                                                                                 foundx = icu->bezt[i].vec[1][0];
1470                                                                         }
1471                                                                 }
1472                                                                 else if (foundsel && icu->bezt[i].vec[1][0] != foundx){
1473                                                                         *index=icu->bezt[i].vec[1][0];
1474                                                                         *sel = 0;
1475                                                                         return base;
1476                                                                 }
1477                                                         }
1478                                                 }
1479                                         }
1480                                 }
1481                         }
1482
1483                         ymax=ymin;
1484                         
1485                         /* Skip actions and nlastrips if object is collapsed */
1486                         if (base->object->nlaflag & OB_NLA_COLLAPSED)
1487                                 continue;
1488                         
1489                         /* Skip action ipos */
1490                         if (base->object->action){
1491                                 ymax-=(NLACHANNELHEIGHT+NLACHANNELSKIP);
1492                         }
1493                         /* Skip nlastrips */
1494                         ymax-=(NLACHANNELHEIGHT+NLACHANNELSKIP)*BLI_countlist(&base->object->nlastrips);
1495                 }
1496         }       
1497         
1498         *index=firstvertx;
1499         return firstbase;
1500 }
1501
1502 static bAction *get_nearest_nlachannel_ac_key (float *index, short *sel)
1503 {
1504         Base *base;
1505         IpoCurve *icu;
1506         bAction *firstact=NULL;
1507         bActionChannel *chan;
1508         bConstraintChannel *conchan;
1509         rctf    rectf;
1510         float firstvert=-1, foundx=-1;
1511         float ymin, ymax, xmin, xmax;
1512         int i;
1513         int     foundsel=0;
1514         short mval[2];
1515         
1516         *index=0;
1517         
1518         getmouseco_areawin (mval);
1519         
1520         mval[0]-=7;
1521         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmin, &rectf.ymin);
1522         
1523         mval[0]+=14;
1524         areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
1525         
1526         ymax = count_nla_levels();
1527         
1528         ymax*= (NLACHANNELHEIGHT + NLACHANNELSKIP);
1529         ymax+= NLACHANNELHEIGHT/2;
1530         
1531         *sel=0;
1532         
1533         for (base=G.scene->base.first; base; base=base->next){
1534                 /* Handle object ipo selection */
1535                 if (nla_filter(base)) {
1536                         
1537                         /* Skip object ipo and ob-constraint ipo */
1538                         ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1539                         
1540                         /* skip this object if it is collapsed */
1541                         if (base->object->nlaflag & OB_NLA_COLLAPSED)
1542                                 continue;
1543                         
1544                         ymax=ymin;
1545                         
1546                         /* Handle action ipos */
1547                         if (base->object->action){
1548                                 bAction *act= base->object->action;
1549                                 
1550                                 /* if action is mapped in NLA, it returns a correction */
1551                                 xmin= get_action_frame(base->object, rectf.xmin);
1552                                 xmax= get_action_frame(base->object, rectf.xmax);
1553                                 
1554                                 ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1555                                 if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))){
1556                                         for (chan=act->chanbase.first; chan; chan=chan->next){
1557                                                 if(chan->ipo) {
1558                                                         for (icu=chan->ipo->curve.first; icu; icu=icu->next){
1559                                                                 for (i=0; i<icu->totvert; i++){
1560                                                                         if (icu->bezt[i].vec[1][0] > xmin && icu->bezt[i].vec[1][0] <= xmax ){
1561                                                                                 if (!firstact){
1562                                                                                         firstact= act;
1563                                                                                         firstvert=icu->bezt[i].vec[1][0];
1564                                                                                         *sel = icu->bezt[i].f2 & 1;     
1565                                                                                 }
1566                                                                                 
1567                                                                                 if (icu->bezt[i].f2 & 1){ 
1568                                                                                         if (!foundsel){
1569                                                                                                 foundsel=1;
1570                                                                                                 foundx = icu->bezt[i].vec[1][0];
1571                                                                                         }
1572                                                                                 }
1573                                                                                 else if (foundsel && icu->bezt[i].vec[1][0] != foundx){
1574                                                                                         *index=icu->bezt[i].vec[1][0];
1575                                                                                         *sel = 0;
1576                                                                                         return act;
1577                                                                                 }
1578                                                                         }
1579                                                                 }
1580                                                         }
1581                                                 }
1582                                                 
1583                                                 for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next){
1584                                                         ymin=ymax-(NLACHANNELHEIGHT+NLACHANNELSKIP);
1585                                                         if ( !((ymax < rectf.ymin) || (ymin > rectf.ymax)) && conchan->ipo){
1586                                                                 for (icu=conchan->ipo->curve.first; icu; icu=icu->next){
1587                                                                         for (i=0; i<icu->totvert; i++){
1588                                                                                 if (icu->bezt[i].vec[1][0] > xmin && icu->bezt[i].vec[1][0] <= xmax ){
1589                                                                                         if (!firstact){
1590                                                                                                 firstact=base->object->action;
1591                                                                                                 firstvert=icu->bezt[i].vec[1][0];
1592                                                                                                 *sel = icu->bezt[i].f2 & 1;     
1593                                                                                         }
1594                                                                                         
1595                                                                                         if (icu->bezt[i].f2 & 1){ 
1596                                                                                                 if (!foundsel){
1597                                                                                                         foundsel=1;
1598                                                                                                         foundx = icu->bezt[i].vec[1][0];
1599                                                                                                 }
1600                                                                                         }
1601                                                                                         else if (foundsel && icu->bezt[i].vec[1][0] != foundx){
1602                                                                                                 *index=icu->bezt[i].vec[1][0];
1603                                                                                                 *sel = 0;
1604                                                                                                 return base->object->action;
1605                                                                                         }
1606                                                                                 }
1607                                                                         }
1608                                                                 }
1609                                                         }
1610                                                         ymax=ymin;
1611                                                 }
1612                                         
1613                                         
1614                                         }
1615                                 }                       
1616                                 ymax=ymin;
1617                         }
1618                         
1619                         /* Skip nlastrips */
1620                         ymax-=(NLACHANNELHEIGHT+NLACHANNELSKIP)*BLI_countlist(&base->object->nlastrips);
1621                 }
1622         }       
1623         
1624         *index=firstvert;
1625         return firstact;
1626 }
1627
1628 void deselect_nlachannels(int test)
1629 {
1630         Base *base;
1631         int sel = 1;
1632
1633         if (test){
1634                 for (base=G.scene->base.first; base; base=base->next){
1635                         /* Check base flags for previous selection */
1636                         if (base->flag & SELECT){
1637                                 sel=0;
1638                                 break;
1639                         }
1640                 }
1641         }
1642         else
1643                 sel = 0;
1644
1645         /* Select objects */
1646         for (base=G.scene->base.first; base; base=base->next){
1647                 if (sel){
1648                         if (nla_filter(base))
1649                                 base->flag |= SELECT;
1650                 }
1651                 else
1652                         base->flag &= ~SELECT;
1653                 
1654                 base->object->flag= base->flag;
1655         }       
1656 }
1657
1658 static Object *get_object_from_active_strip(void) {
1659
1660         Base *base;
1661         bActionStrip *strip;
1662         
1663         for (base=G.scene->base.first; base; base=base->next) {
1664                 if ((base->object->nlaflag & OB_NLA_COLLAPSED)==0) {
1665                         for (strip = base->object->nlastrips.first; 
1666                                  strip; strip=strip->next){
1667                                 if (strip->flag & ACTSTRIP_SELECT) {
1668                                         return base->object;
1669                                 }
1670                         }
1671                 }
1672         }
1673         return NULL;
1674 }
1675
1676
1677 void winqreadnlaspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
1678 {
1679         unsigned short event= evt->event;
1680         short val= evt->val;
1681         SpaceNla *snla = curarea->spacedata.first;
1682         int doredraw= 0;
1683         short   mval[2];
1684         float dx,dy;
1685         int     cfra;
1686         short mousebut = L_MOUSE;
1687         Object          *ob; //in shift-B / bake
1688         
1689         if (curarea->win==0) return;
1690         if (!snla) return;
1691         
1692         if(val) {
1693                 if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
1694                 
1695                 /* swap mouse buttons based on user preference */
1696                 if (U.flag & USER_LMOUSESELECT) {
1697                         if (event == LEFTMOUSE) {
1698                                 event = RIGHTMOUSE;
1699                                 mousebut = L_MOUSE;
1700                         } else if (event == RIGHTMOUSE) {
1701                                 event = LEFTMOUSE;
1702                                 mousebut = R_MOUSE;
1703                         }
1704                 }
1705                 
1706                 getmouseco_areawin(mval);
1707                 
1708                 switch(event) {
1709                         case UI_BUT_EVENT:
1710                                 do_nlabuts(val); // in drawnla.c
1711                                 break;
1712                                 
1713                         case HOMEKEY:
1714                                 do_nla_buttons(B_NLAHOME);
1715                                 break;
1716                                 
1717                         case EQUALKEY:
1718                                 shift_nlastrips_up();
1719                                 break;
1720                         
1721                         case PAGEUPKEY:
1722                                 if (G.qual & LR_CTRLKEY)
1723                                         shift_nlastrips_up();
1724                                 else {
1725                                         nextprev_marker(1);
1726                                         allqueue(REDRAWMARKER, 0);
1727                                 }                               
1728                                 break;
1729                                 
1730                         case MINUSKEY:
1731                                 shift_nlastrips_down();
1732                                 break;
1733                                 
1734                         case PAGEDOWNKEY:
1735                                 if (G.qual & LR_CTRLKEY)
1736                                         shift_nlastrips_down();
1737                                 else {
1738                                         nextprev_marker(-1);
1739                                         allqueue(REDRAWMARKER, 0);
1740                                 }
1741                                 break;
1742                                 
1743                         case AKEY:
1744                                 if (G.qual & LR_SHIFTKEY){
1745                                         add_nlablock();
1746                                         allqueue (REDRAWNLA, 0);
1747                                         allqueue (REDRAWVIEW3D, 0);
1748                                 }
1749                                 else if (G.qual & LR_CTRLKEY) {
1750                                         deselect_markers(1, 0);
1751                                         allqueue(REDRAWMARKER, 0);
1752                                 }
1753                                 else{
1754                                         if (mval[0]>=NLAWIDTH)
1755                                                 deselect_nlachannel_keys(1);
1756                                         else{
1757                                                 deselect_nlachannels(1);
1758                                                 allqueue (REDRAWVIEW3D, 0);
1759                                         }
1760                                         allqueue (REDRAWNLA, 0);
1761                                         allqueue (REDRAWIPO, 0);
1762                                         BIF_undo_push("(De)select all NLA");
1763                                 }
1764                                 break;
1765                                 
1766                         case BKEY:
1767                                 if (G.qual & LR_SHIFTKEY){
1768                                         bake_all_to_action();
1769                                         allqueue (REDRAWNLA, 0);
1770                                     allqueue (REDRAWVIEW3D, 0);
1771                                     BIF_undo_push("Bake All To Action");
1772                                     ob = get_object_from_active_strip();
1773                                     //build_match_caches(ob);
1774                                 }
1775                                 else if (G.qual & LR_CTRLKEY) 
1776                                         borderselect_markers();
1777                                 else
1778                                         borderselect_nla();
1779                                 break;
1780                                 
1781                         case CKEY:
1782                                 if(G.qual==LR_CTRLKEY) {
1783                                         if(okee("Copy Modifiers"))
1784                                                 copy_action_modifiers();
1785                                 }
1786                                 else convert_nla();
1787                                 break;
1788                                 
1789                         case DKEY:
1790                                 if (G.qual == (LR_CTRLKEY|LR_SHIFTKEY) && mval[0]>=NLAWIDTH) {
1791                                         duplicate_marker();
1792                                 }
1793                                 else if (G.qual & LR_SHIFTKEY && mval[0]>=NLAWIDTH){
1794                                         duplicate_nlachannel_keys();
1795                                         update_for_newframe_muted();
1796                                 }
1797                                 
1798                                 break;
1799                                 
1800                         case EKEY:
1801                                 if (mval[0] >= NLAWIDTH) {
1802                                         transform_nlachannel_keys ('e', 0);
1803                                         update_for_newframe_muted();
1804                                 }
1805                                 break;
1806                                 
1807                         case GKEY:
1808                                 if (mval[0]>=NLAWIDTH) {
1809                                         if (G.qual & LR_CTRLKEY) {
1810                                                 transform_markers('g', 0);
1811                                         }
1812                                         else {
1813                                                 transform_nlachannel_keys ('g', 0);
1814                                                 update_for_newframe_muted();
1815                                         }
1816                                 }
1817                                 break;
1818                         
1819                         case MKEY:
1820                                 /* marker operations */
1821                                 if (G.qual == 0)
1822                                         add_marker(CFRA);
1823                                 else if (G.qual == LR_CTRLKEY)
1824                                         rename_marker();
1825                                 else 
1826                                         break;
1827                                 allqueue(REDRAWMARKER, 0);
1828                                 break;                          
1829                         
1830                         case NKEY:
1831                                 if(G.qual==0) {
1832                                         toggle_blockhandler(curarea, NLA_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
1833                                         scrarea_queue_winredraw(curarea);
1834                                 }
1835                                 else if (G.qual & LR_SHIFTKEY) {
1836                                         add_empty_nlablock();
1837                                 }
1838                                 break;
1839                         case LKEY:
1840                                 relink_active_strip();
1841                                 break;
1842                                 
1843                         case PKEY:
1844                                 if (G.qual & LR_CTRLKEY) /* set preview range */
1845                                         anim_previewrange_set();
1846                                 else if (G.qual & LR_ALTKEY) /* clear preview range */
1847                                         anim_previewrange_clear();
1848                                 allqueue(REDRAWMARKER, 0);
1849                                 break;
1850                                 
1851                         case SKEY:
1852                                 if(G.qual==LR_ALTKEY) {
1853                                         val= pupmenu("Action Strip Scale%t|Clear Strip Scale%x1|Remap Start/End%x2");
1854                                         if(val==1)
1855                                                 reset_action_strips(1);
1856                                         else if(val==2)
1857                                                 reset_action_strips(2);
1858                                 }
1859                                 else if(G.qual & LR_SHIFTKEY) {
1860                                         if (snla->flag & SNLA_DRAWTIME)
1861                                                 val= pupmenu("Snap To%t|Nearest Second%x3|Current Time%x2");
1862                                         else
1863                                                 val= pupmenu("Snap To%t|Nearest Frame%x1|Current Frame%x2");
1864                                         if (ELEM3(val, 1, 2, 3))
1865                                                 snap_action_strips(val);
1866                                 }
1867                                 else {
1868                                         if (mval[0]>=NLAWIDTH)
1869                                                 transform_nlachannel_keys ('s', 0);
1870                                         update_for_newframe_muted();
1871                                 }
1872                                 break;
1873                                 
1874                         case TKEY:
1875                                 if (G.qual & LR_CTRLKEY) {
1876                                         val= pupmenu("Time value%t|Frames %x1|Seconds%x2");
1877                                         
1878                                         if (val > 0) {
1879                                                 if (val == 2) snla->flag |= SNLA_DRAWTIME;
1880                                                 else snla->flag &= ~SNLA_DRAWTIME;
1881                                                 
1882                                                 doredraw= 1;
1883                                         }
1884                                 }                               
1885                                 break;
1886                                 
1887                         case DELKEY:
1888                         case XKEY:
1889                                 if (mval[0]>=NLAWIDTH) {
1890                                         if (okee("Erase selected?")) {
1891                                                 delete_nlachannel_keys();
1892                                                 update_for_newframe_muted();
1893                                                 
1894                                                 remove_marker();
1895                                                 
1896                                                 allqueue(REDRAWMARKER, 0);
1897                                         }
1898                                 }
1899                                 break;
1900                                 
1901                                 /* LEFTMOUSE and RIGHTMOUSE event codes can be swapped above,
1902                                 * based on user preference USER_LMOUSESELECT
1903                                 */
1904                         case LEFTMOUSE:
1905                                 if(view2dmove(LEFTMOUSE))
1906                                         break; // only checks for sliders
1907                                 else if (mval[0]>=snla->v2d.mask.xmin) {
1908                                         do {
1909                                                 getmouseco_areawin(mval);
1910                                                 
1911                                                 areamouseco_to_ipoco(G.v2d, mval, &dx, &dy);
1912                                                 
1913                                                 cfra= (int)dx;
1914                                                 if(cfra< 1) cfra= 1;
1915                                                 
1916                                                 if( cfra!=CFRA ) {
1917                                                         CFRA= cfra;
1918                                                         update_for_newframe();
1919                                                         force_draw_all(0);
1920                                                 }
1921                                                 else PIL_sleep_ms(30);
1922                                                 
1923                                         } while(get_mbut() & mousebut);
1924                                         break;
1925                                 }
1926                                         /* else pass on! */
1927                                 case RIGHTMOUSE:
1928                                         if (mval[0]>=snla->v2d.mask.xmin) {
1929                                                 if(G.qual & LR_SHIFTKEY)
1930                                                         mouse_nla(SELECT_INVERT);
1931                                                 else
1932                                                         mouse_nla(SELECT_REPLACE);
1933                                         }
1934                                         else
1935                                                 mouse_nlachannels(mval);
1936                                         break;
1937                                         
1938                                 case PADPLUSKEY:
1939                                         view2d_zoom(G.v2d, 0.1154, sa->winx, sa->winy);
1940                                         test_view2d(G.v2d, sa->winx, sa->winy);
1941                                         view2d_do_locks(curarea, V2D_LOCK_COPY);
1942                                         doredraw= 1;
1943                                         break;
1944                                 case PADMINUS:
1945                                         view2d_zoom(G.v2d, -0.15, sa->winx, sa->winy);
1946                                         test_view2d(G.v2d, sa->winx, sa->winy);
1947                                         view2d_do_locks(curarea, V2D_LOCK_COPY);
1948                                         doredraw= 1;
1949                                         break;
1950                                 case MIDDLEMOUSE:
1951                                 case WHEELUPMOUSE:
1952                                 case WHEELDOWNMOUSE:
1953                                         view2dmove(event);      /* in drawipo.c */
1954                                         break;
1955                 }
1956         }
1957         
1958         if(doredraw) scrarea_queue_winredraw(curarea);
1959 }
1960
1961 void bake_all_to_action(void)
1962 {
1963         Object          *ob;
1964         bAction         *newAction;
1965         Ipo             *ipo;
1966         ID              *id;
1967         short           hold, add;
1968         float           repeat;
1969
1970         /* burn object-level motion into a new action */
1971         ob = get_object_from_active_strip();
1972         if (ob) {
1973                 if (ob->flag&OB_ARMATURE) {
1974                         //newAction = bake_obIPO_to_action(ob);
1975                         newAction = NULL;
1976                         if (newAction) {
1977                                 /* unlink the object's IPO */
1978                                 ipo=ob->ipo;
1979                                 if (ipo) {
1980                                         id = &ipo->id;
1981                                         if (id->us > 0)
1982                                                 id->us--;
1983                                         ob->ipo = NULL;
1984                                 }
1985                                 
1986                                 /* add the new Action to NLA as a strip */
1987                                 hold=1;
1988                                 add=1;
1989                                 repeat=1.0;
1990                                 printf("about to add nla block...\n");
1991                                 add_nla_block_by_name(newAction->id.name, ob, hold, add, repeat);
1992                                 BIF_undo_push("Add NLA strip");
1993                         }
1994                 }
1995         }
1996 }
1997
1998 void copy_action_modifiers(void)
1999 {
2000         bActionStrip *strip, *actstrip;
2001         Object *ob= OBACT;
2002         
2003         if(ob==NULL)
2004                 return;
2005         
2006         /* active strip */
2007         for (actstrip=ob->nlastrips.first; actstrip; actstrip=actstrip->next)
2008                 if(actstrip->flag & ACTSTRIP_ACTIVE)
2009                         break;
2010         if(actstrip==NULL)
2011                 return;
2012         
2013         /* copy to selected items */
2014         for (strip=ob->nlastrips.first; strip; strip=strip->next){
2015                 if (strip->flag & ACTSTRIP_SELECT) {
2016                         if(strip!=actstrip) {
2017                                 if (strip->modifiers.first)
2018                                         BLI_freelistN(&strip->modifiers);
2019                                 if (actstrip->modifiers.first)
2020                                         duplicatelist (&strip->modifiers, &actstrip->modifiers);
2021                         }
2022                 }
2023         }
2024         
2025         BIF_undo_push("Copy Action Modifiers");
2026         allqueue(REDRAWNLA, 0);
2027         DAG_scene_flush_update(G.scene, screen_view3d_layers());
2028 }
2029