NLA SoC: Merge from 2.5 20215:20439 (HEAD)
authorJoshua Leung <aligorith@gmail.com>
Wed, 27 May 2009 00:07:03 +0000 (00:07 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 27 May 2009 00:07:03 +0000 (00:07 +0000)
16 files changed:
source/blender/blenkernel/BKE_action.h
source/blender/blenkernel/BKE_fcurve.h
source/blender/blenkernel/BKE_nla.h
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/nla.c
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/animation/anim_filter.c
source/blender/editors/include/ED_anim_api.h
source/blender/editors/space_nla/space_nla.c
source/blender/makesdna/DNA_action_types.h
source/blender/makesdna/DNA_anim_types.h
source/blender/makesdna/DNA_space_types.h

index 67eb2ed58bf2cc972850cf16865c8498fc5d1fc9..cc10a4071a650a08081e60526e65c76b3399b6bc 100644 (file)
@@ -68,6 +68,9 @@ void make_local_action(struct bAction *act);
 /* Some kind of bounding box operation on the action */
 void calc_action_range(const struct bAction *act, float *start, float *end, int incl_hidden);
 
+/* Does action have any motion data at all? */
+short action_has_motion(const struct bAction *act);
+
 /* Action Groups API ----------------- */
 
 /* Make the given Action Group the active one */
index 9b8a2990fe57dfbf5cb807bf2447dea175fae772..7058b9d236af83c2a0b33567898003a5defd1f45 100644 (file)
@@ -108,11 +108,15 @@ struct FModifier *fcurve_add_modifier(struct FCurve *fcu, int type);
 void fcurve_copy_modifiers(ListBase *dst, ListBase *src);
 void fcurve_remove_modifier(struct FCurve *fcu, struct FModifier *fcm);
 void fcurve_free_modifiers(struct FCurve *fcu);
-void fcurve_bake_modifiers(struct FCurve *fcu, int start, int end);
 
 struct FModifier *fcurve_find_active_modifier(struct FCurve *fcu);
 void fcurve_set_active_modifier(struct FCurve *fcu, struct FModifier *fcm);
 
+float evaluate_time_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float cvalue, float evaltime);
+void evaluate_value_fmodifiers(ListBase *modifiers, struct FCurve *fcu, float *cvalue, float evaltime);
+
+void fcurve_bake_modifiers(struct FCurve *fcu, int start, int end);
+
 /* ************** F-Curves API ******************** */
 
 /* -------- Data Managemnt  --------  */
index 230096d7ea745c2d01e4c1fe53b6108fc7d81782..49796250633aec6d7986c90102ed67a98fe4dadc 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
  * All rights reserved.
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Joshua Leung (full recode)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 #ifndef BKE_NLA_H
 #define BKE_NLA_H
 
-struct bActionStrip;
-struct ListBase;
-struct Object;
+struct AnimData;
+struct NlaStrip;
+struct NlaTrack;
+struct bAction;
+
+/* ----------------------------- */
+/* Data Management */
+
+void free_nlastrip(ListBase *strips, struct NlaStrip *strip);
+void free_nlatrack(ListBase *tracks, struct NlaTrack *nlt);
+void free_nladata(ListBase *tracks);
+
+struct NlaStrip *copy_nlastrip(struct NlaStrip *strip);
+struct NlaTrack *copy_nlatrack(struct NlaTrack *nlt);
+void copy_nladata(ListBase *dst, ListBase *src);
+
+struct NlaStrip *add_nlastrip(struct NlaTrack *nlt, struct bAction *act);
+struct NlaTrack *add_nlatrack(struct AnimData *adt);
+
+/* ----------------------------- */
+/* API */
+
+struct NlaTrack *BKE_nlatrack_find_active(ListBase *tracks);
+void BKE_nlatrack_set_active(ListBase *tracks, struct NlaTrack *nlt);
+
+short BKE_nlatrack_has_space(struct NlaTrack *nlt, float start, float end);
+void BKE_nlatrack_sort_strips(struct NlaTrack *nlt);
+
+void BKE_nla_action_pushdown(struct AnimData *adt);
 
-void free_actionstrip (struct bActionStrip* strip);
-void free_nlastrips (struct ListBase *nlalist);
-void copy_nlastrips (struct ListBase *dst, struct ListBase *src);
-void copy_actionstrip (struct bActionStrip **dst, struct bActionStrip **src);
-void find_stridechannel(struct Object *ob, struct bActionStrip *strip);
-struct bActionStrip *convert_action_to_strip (struct Object *ob);
 #endif
 
index d54bc749b71e8163cafc9182509178c47e53d185..bb458cc7e251cfd34100abee51daaaad75614037 100644 (file)
@@ -717,50 +717,45 @@ static bActionStrip *get_active_strip(Object *ob)
        return NULL;
 }
 
-/* non clipped mapping of strip */
-static float get_actionstrip_frame(bActionStrip *strip, float cframe, int invert)
-{
-       float length, actlength, repeat, scale;
-       
-       if (strip->repeat == 0.0f) strip->repeat = 1.0f;
-       repeat = (strip->flag & ACTSTRIP_USESTRIDE) ? (1.0f) : (strip->repeat);
-       
-       if (strip->scale == 0.0f) strip->scale= 1.0f;
-       scale = (float)fabs(strip->scale); /* scale must be positive (for now) */
-       
-       actlength = strip->actend-strip->actstart;
-       if (actlength == 0.0f) actlength = 1.0f;
-       length = repeat * scale * actlength;
-       
-       /* invert = convert action-strip time to global time */
-       if (invert)
-               return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
-       else
-               return repeat*actlength*(cframe - strip->start)/length + strip->actstart;
-}
-
 /* if the conditions match, it converts current time to strip time */
+// TODO: change this adt
 float get_action_frame(Object *ob, float cframe)
 {
        bActionStrip *strip= get_active_strip(ob);
        
-       if(strip)
-               return get_actionstrip_frame(strip, cframe, 0);
+       //if(strip)
+       //      return get_actionstrip_frame(strip, cframe, 0);
        return cframe;
 }
 
 /* inverted, strip time to current time */
+// TODO: change this to adt
 float get_action_frame_inv(Object *ob, float cframe)
 {
        bActionStrip *strip= get_active_strip(ob);
        
-       if(strip)
-               return get_actionstrip_frame(strip, cframe, 1);
+       //if(strip)
+       //      return get_actionstrip_frame(strip, cframe, 1);
        return cframe;
 }
 
 
-
+/* Check if the given action has any keyframes */
+short action_has_motion(const bAction *act)
+{
+       FCurve *fcu;
+       
+       /* return on the first F-Curve that has some keyframes/samples defined */
+       if (act) {
+               for (fcu= act->curves.first; fcu; fcu= fcu->next) {
+                       if (fcu->totvert)
+                               return 1;
+               }
+       }
+       
+       /* nothing found */
+       return 0;
+}
 
 /* Calculate the extents of given action */
 void calc_action_range(const bAction *act, float *start, float *end, int incl_hidden)
index 30dcb383ef629410eceac9a0ec81c9827fa2f448..f21fed416ccdba92d47a4b7aa126402e4c22e632 100644 (file)
@@ -5,6 +5,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <stddef.h>
+#include <float.h>
+#include <math.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -15,6 +17,7 @@
 #include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_fcurve.h"
+#include "BKE_nla.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
@@ -116,6 +119,9 @@ void BKE_free_animdata (ID *id)
                        if (adt->action)
                                adt->action->id.us--;
                                
+                       /* free nla data */
+                       free_nladata(&adt->nla_tracks);
+                       
                        /* free drivers - stored as a list of F-Curves */
                        free_fcurves(&adt->drivers);
                        
@@ -147,7 +153,7 @@ AnimData *BKE_copy_animdata (AnimData *adt)
        dadt->action= copy_action(adt->action);
        
        /* duplicate NLA data */
-       // XXX todo...
+       copy_nladata(&dadt->nla_tracks, &adt->nla_tracks);
        
        /* duplicate drivers (F-Curves) */
        copy_fcurves(&dadt->drivers, &adt->drivers);
@@ -544,19 +550,17 @@ typedef struct NlaEvalStrip {
        struct NlaEvalStrip *next, *prev;
        
        NlaTrack *track;                        /* track that this strip belongs to */
-       NlaStrip *strip;                /* strip that's being used */
-       NlaStrip *sblend;               /* strip that's being blended towards (if applicable) */
+       NlaStrip *strip;                        /* strip that's being used */
        
        short track_index;                      /* the index of the track within the list */
        short strip_mode;                       /* which end of the strip are we looking at */
 } NlaEvalStrip;
 
-/* bNlaEvalStrip->strip_mode */
+/* NlaEvalStrip->strip_mode */
 enum {
        NES_TIME_BEFORE = -1,
        NES_TIME_WITHIN,
        NES_TIME_AFTER,
-       NES_TIME_AFTER_BLEND
 } eNlaEvalStrip_StripMode;
 
 
@@ -565,8 +569,9 @@ enum {
 typedef struct NlaEvalChannel {
        struct NlaEvalChannel *next, *prev;
        
-       char *path;                             /* ready-to-use path (i.e. remapped already) */
-       int array_index;                /* if applicable... */
+       PointerRNA ptr;                 /* pointer to struct containing property to use */
+       PropertyRNA *prop;              /* RNA-property type to use (should be in the struct given) */
+       int index;                              /* array index (where applicable) */
        
        float value;                    /* value of this channel */
 } NlaEvalChannel;
@@ -574,24 +579,98 @@ typedef struct NlaEvalChannel {
 
 /* ---------------------- */
 
-/* evaluate the F-Curves controlling settings for the NLA-strips (currently, not relinkable) */
-static void nlastrip_evaluate_fcurves (NlaStrip *strip, float ctime)
+/* non clipped mapping for strip-time <-> global time 
+ *     invert = convert action-strip time to global time 
+ */
+static float nlastrip_get_frame (NlaStrip *strip, float cframe, short invert)
 {
-       //PointerRNA actstrip_ptr;
-       //FCurve *fcu;
+       float length, actlength, repeat, scale;
+       
+       /* get number of repeats */
+       if (strip->repeat == 0.0f) strip->repeat = 1.0f;
+       repeat = strip->repeat;
+       
+       /* scaling */
+       if (strip->scale == 0.0f) strip->scale= 1.0f;
+       scale = (float)fabs(strip->scale); /* scale must be positive - we've got a special flag for reversing */
+       
+       /* length of referenced action */
+       actlength = strip->actend-strip->actstart;
+       if (actlength == 0.0f) actlength = 1.0f;
        
-       /* create RNA-pointer needed to set values */
-       //RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &actstrip_ptr);
+       /* length of strip */
+       length = repeat * scale * actlength;
        
-       /* execute these settings as per normal */
-       //animsys_evaluate_fcurves(&actstrip_ptr, &strip->fcurves, NULL, ctime);
+       /* reversed = play strip backwards */
+       if (strip->flag & NLASTRIP_FLAG_REVERSE) {
+               // FIXME: verify these 
+               /* invert = convert action-strip time to global time */
+               if (invert)
+                       return length*(strip->actend - cframe)/(repeat*actlength) + strip->start;
+               else
+                       return strip->actend - repeat*actlength*(cframe - strip->start)/length;
+       }
+       else {
+               /* invert = convert action-strip time to global time */
+               if (invert)
+                       return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
+               else
+                       return repeat*actlength*(cframe - strip->start)/length + strip->actstart;
+       }
 }
 
+/* calculate influence of strip based for given frame based on blendin/out values */
+static float nlastrip_get_influence (NlaStrip *strip, float cframe)
+{
+       /* sanity checks - normalise the blendin/out values? */
+       strip->blendin= (float)fabs(strip->blendin);
+       strip->blendout= (float)fabs(strip->blendout);
+       
+       /* result depends on where frame is in respect to blendin/out values */
+       // TODO: are the fabs() tests needed here?
+       if (IS_EQ(strip->blendin, 0)==0 && (cframe <= (strip->start + strip->blendin))) {
+               /* there is some blend-in */
+               return (float)fabs(cframe - strip->start) / (strip->blendin);
+       }
+       else if (IS_EQ(strip->blendout, 0)==0 && (cframe >= (strip->end - strip->blendout))) {
+               /* there is some blend-out */
+               return (float)fabs(strip->end - cframe) / (strip->blendout);
+       }
+       else {
+               /* in the middle of the strip, we should be full strength */
+               return 1.0f;
+       }
+}
 
-/* gets the strip active at the current time for a track */
+/* evaluate the evaluation time and influence for the strip, storing the results in the strip */
+void nlastrip_evaluate_controls (NlaStrip *strip, float ctime)
+{
+       /* firstly, analytically generate values for influence and time (if applicable) */
+       if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0)
+               strip->strip_time= nlastrip_get_frame(strip, ctime, 1); /* last arg '1' means current time to 'strip'/action time */
+       if ((strip->flag & NLASTRIP_FLAG_USR_INFLUENCE) == 0)
+               strip->influence= nlastrip_get_influence(strip, ctime);
+       
+       /* now strip's evaluate F-Curves for these settings (if applicable) */
+       if (strip->fcurves.first) {
+#if 0
+               PointerRNA strip_ptr;
+               FCurve *fcu;
+               
+               /* create RNA-pointer needed to set values */
+               RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
+               
+               /* execute these settings as per normal */
+               animsys_evaluate_fcurves(&actstrip_ptr, &strip->fcurves, NULL, ctime);
+#endif
+       }
+}
+
+
+/* gets the strip active at the current time for a track for evaluation purposes */
 static void nlatrack_ctime_get_strip (ListBase *list, NlaTrack *nlt, short index, float ctime)
 {
-       NlaStrip *strip, *astrip=NULL, *bstrip=NULL;
+       NlaStrip *strip, *estrip=NULL;
        NlaEvalStrip *nes;
        short side= 0;
        
@@ -601,90 +680,317 @@ static void nlatrack_ctime_get_strip (ListBase *list, NlaTrack *nlt, short index
        
        /* loop over strips, checking if they fall within the range */
        for (strip= nlt->strips.first; strip; strip= strip->next) {
-               /* only consider if:
-                *      - current time occurs within strip's extents
-                *      - current time occurs before strip (if it is the first)
-                *      - current time occurs after strip (if hold is on)
-                *      - current time occurs between strips (1st of those isn't holding) - blend!
-                */
+               /* check if current time occurs within this strip  */
                if (IN_RANGE(ctime, strip->start, strip->end)) {
-                       astrip= strip;
+                       /* this strip is active, so try to use it */
+                       estrip= strip;
                        side= NES_TIME_WITHIN;
                        break;
                }
-               else if (ctime < strip->start) {
+               
+               /* if time occurred before current strip... */
+               if (ctime < strip->start) {
                        if (strip == nlt->strips.first) {
-                               astrip= strip;
+                               /* before first strip - only try to use it if it extends backwards in time too */
+                               if (strip->extendmode == NLASTRIP_EXTEND_HOLD)
+                                       estrip= strip;
+                                       
+                               /* side is 'before' regardless of whether there's a useful strip */
                                side= NES_TIME_BEFORE;
-                               break;
                        }
                        else {
-                               astrip= strip->prev;
+                               /* before next strip - previous strip has ended, but next hasn't begun, 
+                                * so blending mode depends on whether strip is being held or not...
+                                *      - only occurs when no transition strip added, otherwise the transition would have
+                                *        been picked up above...
+                                */
+                               strip= strip->prev;
                                
-                               if (astrip->flag & NLASTRIP_HOLDLASTFRAME) {
-                                       side= NES_TIME_AFTER;
-                                       break;
-                               }
-                               else {
-                                       bstrip= strip;
-                                       side= NES_TIME_AFTER_BLEND;
-                                       break;
-                               }
+                               if (strip->extendmode != NLASTRIP_EXTEND_NOTHING)
+                                       estrip= strip;
+                               side= NES_TIME_AFTER;
                        }
+                       break;
+               }
+               
+               /* if time occurred after current strip... */
+               if (ctime > strip->end) {
+                       /* only if this is the last strip should we do anything, and only if that is being held */
+                       if (strip == nlt->strips.last) {
+                               if (strip->extendmode != NLASTRIP_EXTEND_NOTHING)
+                                       estrip= strip;
+                                       
+                               side= NES_TIME_AFTER;
+                               break;
+                       }
+                       
+                       /* otherwise, skip... as the 'before' case will catch it more elegantly! */
                }
        }
        
-       /* check if strip has been found (and whether it has data worth considering) */
-       if (ELEM(NULL, astrip, astrip->act)) 
-               return;
-       if (astrip->flag & NLASTRIP_MUTE
+       /* check if a valid strip was found
+        *      - must not be muted (i.e. will have contribution
+        */
+       if ((estrip == NULL) || (estrip->flag & NLASTRIP_FLAG_MUTED)
                return;
        
-       /* check if blending between strips */
-       if (side == NES_TIME_AFTER_BLEND) {
-               /* blending between strips... so calculate influence+act_time of both */
-               nlastrip_evaluate_fcurves(astrip, ctime);
-               nlastrip_evaluate_fcurves(bstrip, ctime);
-               
-               if ((astrip->influence <= 0.0f) && (bstrip->influence <= 0.0f))
-                       return;
-       }
-       else {
-               /* calculate/set the influence+act_time of this strip - don't consider if 0 influence */
-               nlastrip_evaluate_fcurves(astrip, ctime);
+       /* evaluate strip's evaluation controls  
+        *      - skip if no influence (i.e. same effect as muting the strip)
+        *      - negative influence is not supported yet... how would that be defined?
+        */
+       // TODO: this sounds a bit hacky having a few isolated F-Curves stuck on some data it operates on...
+       // TODO: should we clamp the time to only be on the endpoints of the strip?
+       nlastrip_evaluate_controls(estrip, ctime);
+       if (estrip->influence <= 0.0f) // XXX is it useful to invert the strip?
+               return;
                
-               if (astrip->influence <= 0.0f) 
-                       return;
+       /* check if strip has valid data to evaluate */
+       switch (estrip->type) {
+               case NLASTRIP_TYPE_CLIP: 
+                       /* clip must have some action to evaluate */
+                       if (estrip->act == NULL)
+                               return;
+                       break;
+               case NLASTRIP_TYPE_TRANSITION:
+                       /* there must be strips to transition from and to (i.e. prev and next required) */
+                       // TODO: what happens about cross-track transitions? 
+                       if (ELEM(NULL, estrip->prev, estrip->next))
+                               return;
+                       break;
        }
        
-       
-       /* allocate new eval-strip for this strip + add to stack */
+       /* add to list of strips we need to evaluate */
        nes= MEM_callocN(sizeof(NlaEvalStrip), "NlaEvalStrip");
        
        nes->track= nlt;
-       nes->strip= astrip;
-       nes->sblend= bstrip;
-       nes->track_index= index;
+       nes->strip= estrip;
        nes->strip_mode= side;
+       nes->track_index= index;
        
        BLI_addtail(list, nes);
 }
 
 /* ---------------------- */
 
+/* find an NlaEvalChannel that matches the given criteria 
+ *     - ptr and prop are the RNA data to find a match for
+ */
+static NlaEvalChannel *nlaevalchan_find_match (ListBase *channels, PointerRNA *ptr, PropertyRNA *prop, int array_index)
+{
+       NlaEvalChannel *nec;
+       
+       /* sanity check */
+       if (channels == NULL)
+               return NULL;
+       
+       /* loop through existing channels, checking for a channel which affects the same property */
+       for (nec= channels->first; nec; nec= nec->next) {
+               /* - comparing the PointerRNA's is done by comparing the pointers
+                *   to the actual struct the property resides in, since that all the
+                *   other data stored in PointerRNA cannot allow us to definitively 
+                *      identify the data 
+                */
+               if ((nec->ptr.data == ptr->data) && (nec->prop == prop) && (nec->index == array_index))
+                       return nec;
+       }
+       
+       /* not found */
+       return NULL;
+}
+
+/* verify that an appropriate NlaEvalChannel for this F-Curve exists */
+static NlaEvalChannel *nlaevalchan_verify (PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu, short *newChan)
+{
+       NlaEvalChannel *nec;
+       NlaStrip *strip= nes->strip;
+       PropertyRNA *prop;
+       PointerRNA new_ptr;
+       char *path = NULL;
+       short free_path=0;
+       
+       /* sanity checks */
+       if (channels == NULL)
+               return NULL;
+       
+       /* get RNA pointer+property info from F-Curve for more convenient handling */
+               /* get path, remapped as appropriate to work in its new environment */
+       free_path= animsys_remap_path(strip->remap, fcu->rna_path, &path);
+       
+               /* a valid property must be available, and it must be animateable */
+       if (RNA_path_resolve(ptr, path, &new_ptr, &prop) == 0) {
+               if (G.f & G_DEBUG) printf("NLA Strip Eval: Cannot resolve path \n");
+               return NULL;
+       }
+               /* only ok if animateable */
+       else if (RNA_property_animateable(&new_ptr, prop) == 0) {
+               if (G.f & G_DEBUG) printf("NLA Strip Eval: Property not animateable \n");
+               return NULL;
+       }
+       
+       /* try to find a match */
+       nec= nlaevalchan_find_match(channels, &new_ptr, prop, fcu->array_index);
+       
+       /* allocate a new struct for this if none found */
+       if (nec == NULL) {
+               nec= MEM_callocN(sizeof(NlaEvalChannel), "NlaEvalChannel");
+               *newChan= 1;
+               BLI_addtail(channels, nec);
+               
+               nec->ptr= new_ptr; 
+               nec->prop= prop;
+               nec->index= fcu->array_index;
+       }
+       
+       /* we can now return */
+       return nec;
+}
+
+/* accumulate (i.e. blend) the given value on to the channel it affects */
+static void nlaevalchan_accumulate (NlaEvalChannel *nec, NlaEvalStrip *nes, short newChan, float value)
+{
+       NlaStrip *strip= nes->strip;
+       float inf= strip->influence;
+       
+       /* if channel is new, just store value regardless of blending factors, etc. */
+       if (newChan) {
+               nec->value= value;
+               return;
+       }
+       
+       /* premultiply the value by the weighting factor */
+       if (IS_EQ(inf, 0)) return;
+       value *= inf;
+       
+       /* perform blending */
+       switch (strip->blendmode) {
+               case NLASTRIP_MODE_ADD:
+                       /* simply add the scaled value on to the stack */
+                       nec->value += value;
+                       break;
+                       
+               case NLASTRIP_MODE_SUBTRACT:
+                       /* simply subtract the scaled value from the stack */
+                       nec->value -= value;
+                       break;
+                       
+               case NLASTRIP_MODE_MULTIPLY:
+                       /* multiply the scaled value with the stack */
+                       nec->value *= value;
+                       break;
+               
+               case NLASTRIP_MODE_BLEND:
+               default: // TODO: do we really want to blend by default? it seems more uses might prefer add...
+                       /* do linear interpolation 
+                        *      - the influence of the accumulated data (elsewhere, that is called dstweight) 
+                        *        is 1 - influence, since the strip's influence is srcweight
+                        */
+                       nec->value= nec->value * (1.0f - inf)   +   value;
+                       break;
+       }
+}
+
+/* ---------------------- */
+
+/* evaluate action-clip strip */
+static void nlastrip_evaluate_actionclip (PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes)
+{
+       NlaStrip *strip= nes->strip;
+       FCurve *fcu;
+       float evaltime;
+       
+       /* evaluate strip's modifiers which modify time to evaluate the base curves at */
+       evaltime= evaluate_time_fmodifiers(&strip->modifiers, NULL, 0.0f, strip->strip_time);
+       
+       /* evaluate all the F-Curves in the action, saving the relevant pointers to data that will need to be used */
+       for (fcu= strip->act->curves.first; fcu; fcu= fcu->next) {
+               NlaEvalChannel *nec;
+               float value = 0.0f;
+               short newChan = -1;
+               
+               /* check if this curve should be skipped */
+               if (fcu->flag & (FCURVE_MUTED|FCURVE_DISABLED)) 
+                       continue;
+                       
+               /* evaluate the F-Curve's value for the time given in the strip 
+                * NOTE: we use the modified time here, since strip's F-Curve Modifiers are applied on top of this 
+                */
+               value= evaluate_fcurve(fcu, evaltime);
+               
+               /* apply strip's F-Curve Modifiers on this value 
+                * NOTE: we apply the strip's original evaluation time not the modified one (as per standard F-Curve eval)
+                */
+               evaluate_value_fmodifiers(&strip->modifiers, fcu, &value, strip->strip_time);
+               
+               
+               /* get an NLA evaluation channel to work with, and accumulate the evaluated value with the value(s)
+                * stored in this channel if it has been used already
+                */
+               nec= nlaevalchan_verify(ptr, channels, nes, fcu, &newChan);
+               if (nec)
+                       nlaevalchan_accumulate(nec, nes, newChan, value);
+       }
+}
+
 /* evaluates the given evaluation strip */
-// FIXME: will we need the evaluation cache table set up to blend stuff in?
 // TODO: only evaluate here, but flush in one go using the accumulated channels at end...
-static void nlastrip_ctime_evaluate (ListBase *channels, NlaEvalStrip *nes, float ctime)
+static void nlastrip_evaluate (PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes)
 {
-       // 1. (in old code) was to extract 'IPO-channels' from actions
-       // 2. blend between the 'accumulated' data, and the new data
+       /* actions to take depend on the type of strip */
+       switch (nes->strip->type) {
+               case NLASTRIP_TYPE_CLIP: /* action-clip */
+                       nlastrip_evaluate_actionclip(ptr, channels, nes);
+                       break;
+               case NLASTRIP_TYPE_TRANSITION: /* transition */
+                       // XXX code this...
+                       break;
+       }
 }
 
 /* write the accumulated settings to */
-static void nladata_flush_channels (PointerRNA *ptr, ListBase *channels)
+static void nladata_flush_channels (ListBase *channels)
 {
+       NlaEvalChannel *nec;
        
+       /* sanity checks */
+       if (channels == NULL)
+               return;
+       
+       /* for each channel with accumulated values, write its value on the property it affects */
+       for (nec= channels->first; nec; nec= nec->next) {
+               PointerRNA *ptr= &nec->ptr;
+               PropertyRNA *prop= nec->prop;
+               int array_index= nec->index;
+               float value= nec->value;
+               
+               /* write values - see animsys_write_rna_setting() to sync the code */
+               switch (RNA_property_type(prop)) 
+               {
+                       case PROP_BOOLEAN:
+                               if (RNA_property_array_length(prop))
+                                       RNA_property_boolean_set_index(ptr, prop, array_index, (int)value);
+                               else
+                                       RNA_property_boolean_set(ptr, prop, (int)value);
+                               break;
+                       case PROP_INT:
+                               if (RNA_property_array_length(prop))
+                                       RNA_property_int_set_index(ptr, prop, array_index, (int)value);
+                               else
+                                       RNA_property_int_set(ptr, prop, (int)value);
+                               break;
+                       case PROP_FLOAT:
+                               if (RNA_property_array_length(prop))
+                                       RNA_property_float_set_index(ptr, prop, array_index, value);
+                               else
+                                       RNA_property_float_set(ptr, prop, value);
+                               break;
+                       case PROP_ENUM:
+                               RNA_property_enum_set(ptr, prop, (int)value);
+                               break;
+                       default:
+                               // can't do anything with other types of property....
+                               break;
+               }
+       }
 }
 
 /* ---------------------- */
@@ -713,10 +1019,10 @@ static void animsys_evaluate_nla (PointerRNA *ptr, AnimData *adt, float ctime)
        
        /* 2. for each strip, evaluate then accumulate on top of existing channels, but don't set values yet */
        for (nes= estrips.first; nes; nes= nes->next) 
-               nlastrip_ctime_evaluate(&echannels, nes, ctime);
+               nlastrip_evaluate(ptr, &echannels, nes);
        
        /* 3. flush effects of accumulating channels in NLA to the actual data they affect */
-       nladata_flush_channels(ptr, &echannels);
+       nladata_flush_channels(&echannels);
        
        /* 4. free temporary evaluation data */
        BLI_freelistN(&estrips);
index fed5ffc2ebdb7ced01104bebe58b14870f92785b..b30eba5a631a6a6df3a6c1d8365d25ed63a7609a 100644 (file)
@@ -2170,34 +2170,6 @@ void fcurve_free_modifiers (FCurve *fcu)
        }
 }
 
-/* Bake modifiers for given F-Curve to curve sample data, in the frame range defined
- * by start and end (inclusive).
- */
-void fcurve_bake_modifiers (FCurve *fcu, int start, int end)
-{
-       ChannelDriver *driver;
-       
-       /* sanity checks */
-       // TODO: make these tests report errors using reports not printf's
-       if ELEM(NULL, fcu, fcu->modifiers.first) {
-               printf("Error: No F-Curve with F-Curve Modifiers to Bake\n");
-               return;
-       }
-       
-       /* temporarily, disable driver while we sample, so that they don't influence the outcome */
-       driver= fcu->driver;
-       fcu->driver= NULL;
-       
-       /* bake the modifiers, by sampling the curve at each frame */
-       fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve);
-       
-       /* free the modifiers now */
-       fcurve_free_modifiers(fcu);
-       
-       /* restore driver */
-       fcu->driver= driver;
-}
-
 /* Find the active F-Curve Modifier */
 FModifier *fcurve_find_active_modifier (FCurve *fcu)
 {
@@ -2235,6 +2207,98 @@ void fcurve_set_active_modifier (FCurve *fcu, FModifier *fcm)
                fcm->flag |= FMODIFIER_FLAG_ACTIVE;
 }
 
+/* Evaluation API --------------------------- */
+
+/* evaluate time modifications imposed by some F-Curve Modifiers
+ *     - this step acts as an optimisation to prevent the F-Curve stack being evaluated 
+ *       several times by modifiers requesting the time be modified, as the final result
+ *       would have required using the modified time
+ *     - modifiers only ever recieve the unmodified time, as subsequent modifiers should be
+ *       working on the 'global' result of the modified curve, not some localised segment,
+ *       so nevaltime gets set to whatever the last time-modifying modifier likes...
+ *     - we start from the end of the stack, as only the last one matters for now
+ */
+float evaluate_time_fmodifiers (ListBase *modifiers, FCurve *fcu, float cvalue, float evaltime)
+{
+       FModifier *fcm;
+       float m_evaltime= evaltime;
+       
+       /* sanity checks */
+       if ELEM(NULL, modifiers, modifiers->first)
+               return evaltime;
+               
+       /* find the first modifier from end of stack that modifies time, and calculate the time the modifier
+        * would calculate time at
+        */
+       for (fcm= fcu->modifiers.last; fcm; fcm= fcm->prev) {
+               FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
+               
+               /* only evaluate if there's a callback for this */
+               // TODO: implement the 'influence' control feature...
+               if (fmi && fmi->evaluate_modifier_time) {
+                       if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0)
+                               m_evaltime= fmi->evaluate_modifier_time(fcu, fcm, cvalue, evaltime);
+                       break;
+               }
+       }
+       
+       /* return the modified evaltime */
+       return m_evaltime;
+}
+
+/* Evalautes the given set of F-Curve Modifiers using the given data
+ * Should only be called after evaluate_time_fmodifiers() has been called...
+ */
+void evaluate_value_fmodifiers (ListBase *modifiers, FCurve *fcu, float *cvalue, float evaltime)
+{
+       FModifier *fcm;
+       
+       /* sanity checks */
+       if ELEM(NULL, modifiers, modifiers->first)
+               return;
+       
+       /* evaluate modifiers */
+       for (fcm= modifiers->first; fcm; fcm= fcm->next) {
+               FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
+               
+               /* only evaluate if there's a callback for this */
+               // TODO: implement the 'influence' control feature...
+               if (fmi && fmi->evaluate_modifier) {
+                       if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0)
+                               fmi->evaluate_modifier(fcu, fcm, cvalue, evaltime);
+               }
+       }
+} 
+
+
+/* Bake modifiers for given F-Curve to curve sample data, in the frame range defined
+ * by start and end (inclusive).
+ */
+void fcurve_bake_modifiers (FCurve *fcu, int start, int end)
+{
+       ChannelDriver *driver;
+       
+       /* sanity checks */
+       // TODO: make these tests report errors using reports not printf's
+       if ELEM(NULL, fcu, fcu->modifiers.first) {
+               printf("Error: No F-Curve with F-Curve Modifiers to Bake\n");
+               return;
+       }
+       
+       /* temporarily, disable driver while we sample, so that they don't influence the outcome */
+       driver= fcu->driver;
+       fcu->driver= NULL;
+       
+       /* bake the modifiers, by sampling the curve at each frame */
+       fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve);
+       
+       /* free the modifiers now */
+       fcurve_free_modifiers(fcu);
+       
+       /* restore driver */
+       fcu->driver= driver;
+}
+
 /* ***************************** F-Curve - Evaluation ********************************* */
 
 /* Evaluate and return the value of the given F-Curve at the specified frame ("evaltime") 
@@ -2242,7 +2306,6 @@ void fcurve_set_active_modifier (FCurve *fcu, FModifier *fcm)
  */
 float evaluate_fcurve (FCurve *fcu, float evaltime) 
 {
-       FModifier *fcm;
        float cvalue= 0.0f;
        float devaltime;
        
@@ -2255,28 +2318,8 @@ float evaluate_fcurve (FCurve *fcu, float evaltime)
                evaltime= cvalue= evaluate_driver(fcu->driver, evaltime);
        }
        
-       /* evaluate time modifications imposed by some F-Curve Modifiers
-        *      - this step acts as an optimisation to prevent the F-Curve stack being evaluated 
-        *        several times by modifiers requesting the time be modified, as the final result
-        *        would have required using the modified time
-        *      - modifiers only ever recieve the unmodified time, as subsequent modifiers should be
-        *        working on the 'global' result of the modified curve, not some localised segment,
-        *        so nevaltime gets set to whatever the last time-modifying modifier likes...
-        *      - we start from the end of the stack, as only the last one matters for now
-        */
-       devaltime= evaltime;
-       
-       for (fcm= fcu->modifiers.last; fcm; fcm= fcm->prev) {
-               FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-               
-               /* only evaluate if there's a callback for this */
-               // TODO: implement the 'influence' control feature...
-               if (fmi && fmi->evaluate_modifier_time) {
-                       if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0)
-                               devaltime= fmi->evaluate_modifier_time(fcu, fcm, cvalue, evaltime);
-                       break;
-               }
-       }
+       /* evaluate modifiers which modify time to evaluate the base curve at */
+       devaltime= evaluate_time_fmodifiers(&fcu->modifiers, fcu, cvalue, evaltime);
        
        /* evaluate curve-data 
         *      - 'devaltime' instead of 'evaltime', as this is the time that the last time-modifying 
@@ -2288,16 +2331,7 @@ float evaluate_fcurve (FCurve *fcu, float evaltime)
                cvalue= fcurve_eval_samples(fcu, fcu->fpt, devaltime);
        
        /* evaluate modifiers */
-       for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-               FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-               
-               /* only evaluate if there's a callback for this */
-               // TODO: implement the 'influence' control feature...
-               if (fmi && fmi->evaluate_modifier) {
-                       if ((fcm->flag & (FMODIFIER_FLAG_DISABLED|FMODIFIER_FLAG_MUTED)) == 0)
-                               fmi->evaluate_modifier(fcu, fcm, &cvalue, evaltime);
-               }
-       }
+       evaluate_value_fmodifiers(&fcu->modifiers, fcu, &cvalue, evaltime);
        
        /* if curve can only have integral values, perform truncation (i.e. drop the decimal part)
         * here so that the curve can be sampled correctly
index dc2bf26759f3b3c32cc0db9f18abdebc4b8f5767..d062a2ab14b48bd6a5f262ef2d3ce1715fc2595c 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
  * All rights reserved.
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Joshua Leung (full recode)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <math.h>
+#include <float.h>
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 
-#include "DNA_space_types.h"
-#include "DNA_nla_types.h"
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
-#include "DNA_ID.h"
-#include "DNA_ipo_types.h"
-#include "DNA_object_types.h"
 
-#include "BKE_nla.h"
+#include "BKE_animsys.h"
 #include "BKE_action.h"
+#include "BKE_fcurve.h"
+#include "BKE_nla.h"
 #include "BKE_blender.h"
 #include "BKE_library.h"
-#include "BKE_object.h" /* for convert_action_to_strip(ob) */
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
 
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-/* NOTE: in group.c the strips get copied for group-nla override, this assumes
-   that strips are one single block, without additional data to be copied */
 
-void copy_actionstrip (bActionStrip **dst, bActionStrip **src){
-       bActionStrip *dstrip;
-       bActionStrip *sstrip = *src;
+/* *************************************************** */
+/* Data Management */
+
+/* Freeing ------------------------------------------- */
 
-       if (!*src){
-               *dst=NULL;
+/* Remove the given NLA strip from the NLA track it occupies, free the strip's data,
+ * and the strip itself. 
+ */
+// TODO: with things like transitions, should these get freed too? Maybe better as a UI tool
+void free_nlastrip (ListBase *strips, NlaStrip *strip)
+{
+       FModifier *fcm, *fmn;
+       
+       /* sanity checks */
+       if (strip == NULL)
                return;
+               
+       /* remove reference to action */
+       if (strip->act)
+               strip->act->id.us--;
+               
+       /* free remapping info */
+       //if (strip->remap)
+       //      BKE_animremap_free();
+       
+       /* free own F-Curves */
+       free_fcurves(&strip->fcurves);
+       
+       /* free F-Modifiers */
+       for (fcm= strip->modifiers.first; fcm; fcm= fmn) {
+               fmn= fcm->next;
+               
+               BLI_remlink(&strip->modifiers, fcm);
+               fcurve_remove_modifier(NULL, fcm);
        }
+       
+       /* free the strip itself */
+       if (strips)
+               BLI_freelinkN(strips, strip);
+       else
+               MEM_freeN(strip);
+}
 
-       *dst = MEM_dupallocN(sstrip);
-
-       dstrip = *dst;
-       if (dstrip->act)
-               dstrip->act->id.us++;
-
-       if (dstrip->ipo)
-               dstrip->ipo->id.us++;
+/* Remove the given NLA track from the set of NLA tracks, free the track's data,
+ * and the track itself.
+ */
+void free_nlatrack (ListBase *tracks, NlaTrack *nlt)
+{
+       NlaStrip *strip, *stripn;
        
-       if (dstrip->modifiers.first) {
-               BLI_duplicatelist (&dstrip->modifiers, &sstrip->modifiers);
+       /* sanity checks */
+       if (nlt == NULL)
+               return;
+               
+       /* free strips */
+       for (strip= nlt->strips.first; strip; strip= stripn) {
+               stripn= strip->next;
+               free_nlastrip(&nlt->strips, strip);
        }
        
+       /* free NLA track itself now */
+       if (tracks)
+               BLI_freelinkN(tracks, nlt);
+       else
+               MEM_freeN(nlt);
 }
 
-void copy_nlastrips (ListBase *dst, ListBase *src)
+/* Free the elements of type NLA Tracks provided in the given list, but do not free
+ * the list itself since that is not free-standing
+ */
+void free_nladata (ListBase *tracks)
 {
-       bActionStrip *strip;
-
-       dst->first=dst->last=NULL;
+       NlaTrack *nlt, *nltn;
+       
+       /* sanity checks */
+       if ELEM(NULL, tracks, tracks->first)
+               return;
+               
+       /* free tracks one by one */
+       for (nlt= tracks->first; nlt; nlt= nltn) {
+               nltn= nlt->next;
+               free_nlatrack(tracks, nlt);
+       }
+       
+       /* clear the list's pointers to be safe */
+       tracks->first= tracks->last= NULL;
+}
 
-       BLI_duplicatelist (dst, src);
+/* Copying ------------------------------------------- */
 
-       /* Update specific data */
-       if (!dst->first)
-               return;
+/* Copy NLA strip */
+NlaStrip *copy_nlastrip (NlaStrip *strip)
+{
+       NlaStrip *strip_d;
+       
+       /* sanity check */
+       if (strip == NULL)
+               return NULL;
+               
+       /* make a copy */
+       strip_d= MEM_dupallocN(strip);
+       strip_d->next= strip_d->prev= NULL;
+       
+       /* increase user-count of action */
+       if (strip_d->act)
+               strip_d->act->id.us++;
+               
+       /* copy F-Curves and modifiers */
+       copy_fcurves(&strip_d->fcurves, &strip->fcurves);
+       fcurve_copy_modifiers(&strip_d->modifiers, &strip->modifiers);
+       
+       /* return the strip */
+       return strip_d;
+}
 
-       for (strip = dst->first; strip; strip=strip->next){
-               if (strip->act)
-                       strip->act->id.us++;
-               if (strip->ipo)
-                       strip->ipo->id.us++;
-               if (strip->modifiers.first) {
-                       ListBase listb;
-                       BLI_duplicatelist (&listb, &strip->modifiers);
-                       strip->modifiers= listb;
-               }
+/* Copy NLA Track */
+NlaTrack *copy_nlatrack (NlaTrack *nlt)
+{
+       NlaStrip *strip, *strip_d;
+       NlaTrack *nlt_d;
+       
+       /* sanity check */
+       if (nlt == NULL)
+               return NULL;
+               
+       /* make a copy */
+       nlt_d= MEM_dupallocN(nlt);
+       nlt_d->next= nlt_d->prev= NULL;
+       
+       /* make a copy of all the strips, one at a time */
+       nlt_d->strips.first= nlt_d->strips.last= NULL;
+       
+       for (strip= nlt->strips.first; strip; strip= strip->next) {
+               strip_d= copy_nlastrip(strip);
+               BLI_addtail(&nlt_d->strips, strip_d);
        }
+       
+       /* return the copy */
+       return nlt_d;
 }
 
-/* from editnla, for convert_action_to_strip -- no UI code so should be ok here.. */
-void find_stridechannel(Object *ob, bActionStrip *strip)
+/* Copy all NLA data */
+void copy_nladata (ListBase *dst, ListBase *src)
 {
-       if(ob && ob->pose) {
-               bPoseChannel *pchan;
-               for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
-                       if(pchan->flag & POSE_STRIDE)
-                               break;
-               if(pchan)
-                       BLI_strncpy(strip->stridechannel, pchan->name, 32);
-               else
-                       strip->stridechannel[0]= 0;
+       NlaTrack *nlt, *nlt_d;
+       
+       /* sanity checks */
+       if ELEM(NULL, dst, src)
+               return;
+               
+       /* copy each NLA-track, one at a time */
+       for (nlt= src->first; nlt; nlt= nlt->next) {
+               /* make a copy, and add the copy to the destination list */
+               nlt_d= copy_nlatrack(nlt);
+               BLI_addtail(dst, nlt_d);
        }
 }
 
-//called by convert_nla / bpy api with an object with the action to be converted to a new strip
-bActionStrip *convert_action_to_strip (Object *ob)
+/* Adding ------------------------------------------- */
+
+/* Add a NLA Strip referencing the given Action, to the given NLA Track */
+// TODO: any extra parameters to control how this is done?
+NlaStrip *add_nlastrip (NlaTrack *nlt, bAction *act)
 {
-       bActionStrip *nstrip;
-
-       /* Make new actionstrip */
-       nstrip = MEM_callocN(sizeof(bActionStrip), "bActionStrip");
-                       
-       /* Link the action to the nstrip */
-       nstrip->act = ob->action;
-       id_us_plus(&nstrip->act->id);
-       calc_action_range(nstrip->act, &nstrip->actstart, &nstrip->actend, 1);
-       nstrip->start = nstrip->actstart;
-       nstrip->end = nstrip->actend;
-       nstrip->flag = ACTSTRIP_SELECT|ACTSTRIP_LOCK_ACTION;
-                       
-       find_stridechannel(ob, nstrip);
-       //set_active_strip(ob, nstrip); /* is in editnla as does UI calls */
-                       
-       nstrip->repeat = 1.0;
-
-       if(ob->nlastrips.first == NULL)
-               ob->nlaflag |= OB_NLA_OVERRIDE;
-       
-       BLI_addtail(&ob->nlastrips, nstrip);
-       return nstrip; /* is created, malloced etc. here so is safe to just return the pointer?
-                         this is needed for setting this active in UI, and probably useful for API too */
+       NlaStrip *strip;
+       
+       /* sanity checks */
+       if ELEM(NULL, nlt, act)
+               return NULL;
+               
+       /* allocate new strip */
+       strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip");
+       BLI_addtail(&nlt->strips, strip);
+       
+       /* generic settings 
+        *      - selected flag to highlight this to the user
+        *      - auto-blends to ensure that blend in/out values are automatically 
+        *        determined by overlaps of strips
+        *      - (XXX) synchronisation of strip-length in accordance with changes to action-length
+        *        is not done though, since this should only really happens in editmode for strips now
+        *        though this decision is still subject to further review...
+        */
+       strip->flag = NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_AUTO_BLENDS;
+       
+       /* assign the action reference */
+       strip->act= act;
+       id_us_plus(&act->id);
+       
+       /* determine initial range 
+        *      - strip length cannot be 0... ever...
+        */
+       calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
+       
+       strip->start = strip->actstart;
+       strip->end = (IS_EQ(strip->actstart, strip->actend)) ?  (strip->actstart + 1.0f): (strip->actend);
+       
+       /* strip should be referenced as-is */
+       strip->scale= 1.0f;
+       strip->repeat = 1.0f;
        
+       /* return the new strip */
+       return strip;
 }
 
+/* Add a NLA Track to the given AnimData */
+NlaTrack *add_nlatrack (AnimData *adt)
+{
+       NlaTrack *nlt;
+       
+       /* sanity checks */
+       if (adt == NULL)
+               return NULL;
+               
+       /* allocate new track */
+       nlt= MEM_callocN(sizeof(NlaTrack), "NlaTrack");
+       
+       /* set settings requiring the track to not be part of the stack yet */
+       nlt->flag = NLATRACK_SELECTED;
+       nlt->index= BLI_countlist(&adt->nla_tracks);
+       
+       /* add track to stack, and make it the active one */
+       BLI_addtail(&adt->nla_tracks, nlt);
+       BKE_nlatrack_set_active(&adt->nla_tracks, nlt);
+       
+       /* must have unique name, but we need to seed this */
+       sprintf(nlt->name, "NlaTrack");
+       BLI_uniquename(&adt->nla_tracks, nlt, "NlaTrack", '.', offsetof(NlaTrack, name), 64);
+       
+       /* return the new track */
+       return nlt;
+}
+
+/* *************************************************** */
+/* Basic Utilities */
+
+/* NLA-Tracks ---------------------------------------- */
+
+/* Find the active NLA-track for the given stack */
+NlaTrack *BKE_nlatrack_find_active (ListBase *tracks)
+{
+       NlaTrack *nlt;
+       
+       /* sanity check */
+       if ELEM(NULL, tracks, tracks->first)
+               return NULL;
+               
+       /* try to find the first active track */
+       for (nlt= tracks->first; nlt; nlt= nlt->next) {
+               if (nlt->flag & NLATRACK_ACTIVE)
+                       return nlt;
+       }
+       
+       /* none found */
+       return NULL;
+}
 
-/* not strip itself! */
-void free_actionstrip(bActionStrip* strip)
+/* Make the given NLA-track the active one for the given stack. If no track is provided, 
+ * this function can be used to simply deactivate all the NLA tracks in the given stack too.
+ */
+void BKE_nlatrack_set_active (ListBase *tracks, NlaTrack *nlt_a)
 {
-       if (!strip)
+       NlaTrack *nlt;
+       
+       /* sanity check */
+       if ELEM(NULL, tracks, tracks->first)
                return;
+       
+       /* deactive all the rest */
+       for (nlt= tracks->first; nlt; nlt= nlt->next) 
+               nlt->flag &= ~NLATRACK_ACTIVE;
+               
+       /* set the given one as the active one */
+       if (nlt_a)
+               nlt_a->flag |= NLATRACK_ACTIVE;
+}
 
-       if (strip->act){
-               strip->act->id.us--;
-               strip->act = NULL;
-       }
-       if (strip->ipo){
-               strip->ipo->id.us--;
-               strip->ipo = NULL;
+/* Check if there is any space in the last track to add the given strip */
+short BKE_nlatrack_has_space (NlaTrack *nlt, float start, float end)
+{
+       NlaStrip *strip;
+       
+       /* sanity checks */
+       if ((nlt == NULL) || IS_EQ(start, end))
+               return 0;
+       if (start > end) {
+               puts("BKE_nlatrack_has_space error... start and end arguments swapped");
+               SWAP(float, start, end);
        }
-       if (strip->modifiers.first) {
-               BLI_freelistN(&strip->modifiers);
+       
+       /* loop over NLA strips checking for any overlaps with this area... */
+       for (strip= nlt->strips.first; strip; strip= strip->next) {
+               /* if start frame of strip is past the target end-frame, that means that
+                * we've gone past the window we need to check for, so things are fine
+                */
+               if (strip->start > end)
+                       return 1;
+               
+               /* if the end of the strip is greater than either of the boundaries, the range
+                * must fall within the extents of the strip
+                */
+               if ((strip->end > start) || (strip->end > end))
+                       return 0;
        }
        
+       /* if we are still here, we haven't encountered any overlapping strips */
+       return 1;
 }
 
-void free_nlastrips (ListBase *nlalist)
+/* Rearrange the strips in the track so that they are always in order 
+ * (usually only needed after a strip has been moved) 
+ */
+void BKE_nlatrack_sort_strips (NlaTrack *nlt)
 {
-       bActionStrip *strip;
-
-       if (!nlalist->first)
+       ListBase tmp = {NULL, NULL};
+       NlaStrip *strip, *sstrip;
+       
+       /* sanity checks */
+       if ELEM(NULL, nlt, nlt->strips.first)
                return;
+               
+       /* we simply perform insertion sort on this list, since it is assumed that per track,
+        * there are only likely to be at most 5-10 strips
+        */
+       for (strip= nlt->strips.first; strip; strip= strip->next) {
+               short not_added = 1;
+               
+               /* remove this strip from the list, and add it to the new list, searching from the end of 
+                * the list, assuming that the lists are in order 
+                */
+               BLI_remlink(&nlt->strips, strip);
+               
+               for (sstrip= tmp.last; not_added && sstrip; sstrip= sstrip->prev) {
+                       /* check if add after */
+                       if (sstrip->end < strip->start) {
+                               BLI_insertlinkafter(&tmp, sstrip, strip);
+                               not_added= 0;
+                               break;
+                       }
+               }
+               
+               /* add before first? */
+               if (not_added)
+                       BLI_addhead(&tmp, strip);
+       }
+       
+       /* reassign the start and end points of the strips */
+       nlt->strips.first= tmp.first;
+       nlt->strips.last= tmp.last;
+}
+/* Tools ------------------------------------------- */
 
-       /* Do any specific freeing */
-       for (strip=nlalist->first; strip; strip=strip->next)
-       {
-               free_actionstrip (strip);
-       };
-
-       /* Free the whole list */
-       BLI_freelistN(nlalist);
+/* For the given AnimData block, add the active action to the NLA
+ * stack (i.e. 'push-down' action). The UI should only allow this 
+ * for normal editing only (i.e. not in editmode for some strip's action),
+ * so no checks for this are performed.
+ */
+// TODO: maybe we should have checks for this too...
+void BKE_nla_action_pushdown (AnimData *adt)
+{
+       NlaTrack *nlt;
+       NlaStrip *strip;
+       
+       /* sanity checks */
+       // TODO: need to report the error for this
+       if ELEM(NULL, adt, adt->action) 
+               return;
+               
+       /* if the action is empty, we also shouldn't try to add to stack, 
+        * as that will cause us grief down the track
+        */
+       // TODO: what about modifiers?
+       if (action_has_motion(adt->action) == 0)
+               return;
+               
+       /* add a new NLA track to house this action 
+        *      - we could investigate trying to fit the action into an appropriately
+        *        sized gap in the existing tracks, however, this may result in unexpected 
+        *        changes in blending behaviour...
+        */
+       nlt= add_nlatrack(adt);
+       if (nlt == NULL)
+               return;
+       
+       /* add a new NLA strip to the track, which references the active action */
+       strip= add_nlastrip(nlt, adt->action);
+       
+       /* clear reference to action now that we've pushed it onto the stack */
+       if (strip) {
+               adt->action->id.us--;
+               adt->action= NULL;
+       }
+       
+       // TODO: set any other flags necessary here...
 }
+
+/* *************************************************** */
index d7619010808a4f4f8ecfcd2f3e69860ac57443bb..7a83162f7a747f0db238dc2d1d7d7c0fef8a5b49 100644 (file)
@@ -1193,18 +1193,12 @@ Object *copy_object(Object *ob)
                        armature_rebuild_pose(obn, obn->data);
        }
        copy_defgroups(&obn->defbase, &ob->defbase);
-#if 0 // XXX old animation system
-       copy_nlastrips(&obn->nlastrips, &ob->nlastrips);
-#endif // XXX old animation system
        copy_constraints(&obn->constraints, &ob->constraints);
 
        /* increase user numbers */
        id_us_plus((ID *)obn->data);
-#if 0 // XXX old animation system
-       id_us_plus((ID *)obn->ipo);
-       id_us_plus((ID *)obn->action);
-#endif // XXX old animation system
        id_us_plus((ID *)obn->dup_group);
+       // FIXME: add this for animdata too...
 
        for(a=0; a<obn->totcol; a++) id_us_plus((ID *)obn->mat[a]);
        
index 9c5735a3020150f5103d80cc99b7bc7ab9e94d5c..192016f712d6008d59104578be301d6d33e8ad75 100644 (file)
@@ -1657,10 +1657,26 @@ static void lib_link_constraint_channels(FileData *fd, ID *id, ListBase *chanbas
 
 /* Data Linking ----------------------------- */
 
+static void lib_link_fmodifiers(FileData *fd, ID *id, ListBase *list)
+{
+       FModifier *fcm;
+       
+       for (fcm= list->first; fcm; fcm= fcm->next) {
+               /* data for specific modifiers */
+               switch (fcm->type) {
+                       case FMODIFIER_TYPE_PYTHON:
+                       {
+                               FMod_Python *data= (FMod_Python *)fcm->data;
+                               data->script = newlibadr(fd, id->lib, data->script);
+                       }
+                               break;
+               }
+       }
+}
+
 static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list) 
 {
        FCurve *fcu;
-       FModifier *fcm;
        
        /* relink ID-block references... */
        for (fcu= list->first; fcu; fcu= fcu->next) {
@@ -1674,16 +1690,45 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
                }
                
                /* modifiers */
-               for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-                       /* data for specific modifiers */
-                       switch (fcm->type) {
-                               case FMODIFIER_TYPE_PYTHON:
-                               {
-                                       FMod_Python *data= (FMod_Python *)fcm->data;
-                                       data->script = newlibadr(fd, id->lib, data->script);
-                               }
-                                       break;
+               lib_link_fmodifiers(fd, id, &fcu->modifiers);
+       }
+}
+
+
+/* NOTE: this assumes that link_list has already been called on the list */
+static void direct_link_fmodifiers(FileData *fd, ListBase *list)
+{
+       FModifier *fcm;
+       
+       for (fcm= list->first; fcm; fcm= fcm->next) {
+               /* relink general data */
+               fcm->data = newdataadr(fd, fcm->data);
+               fcm->edata= NULL;
+               
+               /* do relinking of data for specific types */
+               switch (fcm->type) {
+                       case FMODIFIER_TYPE_GENERATOR:
+                       {
+                               FMod_Generator *data= (FMod_Generator *)fcm->data;
+                               
+                               data->coefficients= newdataadr(fd, data->coefficients);
+                       }
+                               break;
+                       case FMODIFIER_TYPE_ENVELOPE:
+                       {
+                               FMod_Envelope *data= (FMod_Envelope *)fcm->data;
+                               
+                               data->data= newdataadr(fd, data->data);
                        }
+                               break;
+                       case FMODIFIER_TYPE_PYTHON:
+                       {
+                               FMod_Python *data= (FMod_Python *)fcm->data;
+                               
+                               data->prop = newdataadr(fd, data->prop);
+                               IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+                       }
+                               break;
                }
        }
 }
@@ -1692,7 +1737,6 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
 static void direct_link_fcurves(FileData *fd, ListBase *list)
 {
        FCurve *fcu;
-       FModifier *fcm;
        
        /* link F-Curve data to F-Curve again (non ID-libs) */
        for (fcu= list->first; fcu; fcu= fcu->next) {
@@ -1720,37 +1764,7 @@ static void direct_link_fcurves(FileData *fd, ListBase *list)
                
                /* modifiers */
                link_list(fd, &fcu->modifiers);
-               for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-                       /* relink general data */
-                       fcm->data = newdataadr(fd, fcm->data);
-                       fcm->edata= NULL;
-                       
-                       /* do relinking of data for specific types */
-                       switch (fcm->type) {
-                               case FMODIFIER_TYPE_GENERATOR:
-                               {
-                                       FMod_Generator *data= (FMod_Generator *)fcm->data;
-                                       
-                                       data->coefficients= newdataadr(fd, data->coefficients);
-                               }
-                                       break;
-                               case FMODIFIER_TYPE_ENVELOPE:
-                               {
-                                       FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-                                       
-                                       data->data= newdataadr(fd, data->data);
-                               }
-                                       break;
-                               case FMODIFIER_TYPE_PYTHON:
-                               {
-                                       FMod_Python *data= (FMod_Python *)fcm->data;
-                                       
-                                       data->prop = newdataadr(fd, data->prop);
-                                       IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
-                               }
-                                       break;
-                       }
-               }
+               direct_link_fmodifiers(fd, &fcu->modifiers);
        }
 }
 
@@ -1802,6 +1816,44 @@ static void direct_link_action(FileData *fd, bAction *act)
        }
 }
 
+
+static void lib_link_nladata (FileData *fd, ID *id, ListBase *list)
+{
+       NlaTrack *nlt;
+       NlaStrip *strip;
+       
+       /* we only acare about the NLA strips inside the tracks */
+       for (nlt= list->first; nlt; nlt= nlt->next) {
+               for (strip= nlt->strips.first; strip; strip= strip->next) {
+                       /* reassign the counted-reference to action */
+                       strip->act = newlibadr_us(fd, id->lib, strip->act);
+               }
+       }
+}
+
+/* NOTE: this assumes that link_list has already been called on the list */
+static void direct_link_nladata(FileData *fd, ListBase *list)
+{
+       NlaTrack *nlt;
+       NlaStrip *strip;
+       
+       for (nlt= list->first; nlt; nlt= nlt->next) {
+               /* relink list of strips */
+               link_list(fd, &nlt->strips);
+               
+               /* relink strip data */
+               for (strip= nlt->strips.first; strip; strip= strip->next) {
+                       /* strip's F-Curves */
+                       link_list(fd, &strip->fcurves);
+                       direct_link_fcurves(fd, &strip->fcurves);
+                       
+                       /* strip's F-Modifiers */
+                       link_list(fd, &strip->modifiers);
+                       direct_link_fcurves(fd, &strip->modifiers);
+               }
+       }
+}
+
 /* ------- */
 
 static void lib_link_keyingsets(FileData *fd, ID *id, ListBase *list)
@@ -1851,7 +1903,7 @@ static void lib_link_animdata(FileData *fd, ID *id, AnimData *adt)
        /* overrides don't have lib-link for now, so no need to do anything */
        
        /* link NLA-data */
-       // TODO... 
+       lib_link_nladata(fd, id, &adt->nla_tracks);
 }
 
 static void direct_link_animdata(FileData *fd, AnimData *adt)
@@ -1868,7 +1920,8 @@ static void direct_link_animdata(FileData *fd, AnimData *adt)
        // TODO...
        
        /* link NLA-data */
-       // TODO...
+       link_list(fd, &adt->nla_tracks);
+       direct_link_nladata(fd, &adt->nla_tracks);
 }      
 
 /* ************ READ NODE TREE *************** */
@@ -4635,6 +4688,11 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                sipo->ads= newdataadr(fd, sipo->ads);
                                sipo->ghostCurves.first= sipo->ghostCurves.last= NULL;
                        }
+                       else if (sl->spacetype==SPACE_NLA) {
+                               SpaceNla *snla= (SpaceNla*)sl;
+                               
+                               snla->ads= newdataadr(fd, snla->ads);
+                       }
                        else if (sl->spacetype==SPACE_OUTLINER) {
                                SpaceOops *soops= (SpaceOops*) sl;
                                
@@ -9318,6 +9376,8 @@ static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list)
 static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
 {
        FCurve *fcd;
+       NlaTrack *nlt;
+       NlaStrip *strip;
        
        /* own action */
        expand_doit(fd, mainvar, adt->action);
@@ -9330,6 +9390,12 @@ static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
                for (dtar= driver->targets.first; dtar; dtar= dtar->next)
                        expand_doit(fd, mainvar, dtar->id);
        }
+       
+       /* nla-data - referenced actions */
+       for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+               for (strip= nlt->strips.first; strip; strip= strip->next) 
+                       expand_doit(fd, mainvar, strip->act);
+       }
 }      
 
 static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSettings *part)
index 943e23861adc2c086468a351837d355af380084b..5cf46b6fd281e33da33436181f33eaee8004c163 100644 (file)
@@ -760,10 +760,59 @@ static void write_actuators(WriteData *wd, ListBase *lb)
        }
 }
 
+static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
+{
+       FModifier *fcm;
+       
+       /* Modifiers */
+       for (fcm= fmodifiers->first; fcm; fcm= fcm->next) {
+               FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
+               
+               /* Write the specific data */
+               if (fmi && fcm->data) {
+                       /* firstly, just write the plain fmi->data struct */
+                       writestruct(wd, DATA, fmi->structName, 1, fcm->data);
+                       
+                       /* do any modifier specific stuff */
+                       switch (fcm->type) {
+                               case FMODIFIER_TYPE_GENERATOR:
+                               {
+                                       FMod_Generator *data= (FMod_Generator *)fcm->data;
+                                       
+                                       /* write coefficients array */
+                                       if (data->coefficients)
+                                               writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
+                               }
+                                       break;
+                               case FMODIFIER_TYPE_ENVELOPE:
+                               {
+                                       FMod_Envelope *data= (FMod_Envelope *)fcm->data;
+                                       
+                                       /* write envelope data */
+                                       if (data->data)
+                                               writedata(wd, DATA, sizeof(FCM_EnvelopeData)*(data->totvert), data->data);
+                               }
+                                       break;
+                               case FMODIFIER_TYPE_PYTHON:
+                               {
+                                       FMod_Python *data = (FMod_Python *)fcm->data;
+                                       
+                                       /* Write ID Properties -- and copy this comment EXACTLY for easy finding
+                                        of library blocks that implement this.*/
+                                       IDP_WriteProperty(data->prop, wd);
+                               }
+                                       break;
+                       }
+               }
+               
+               /* Write the modifier */
+               writestruct(wd, DATA, "FModifier", 1, fcm);
+       }
+}
+
 static void write_fcurves(WriteData *wd, ListBase *fcurves)
 {
        FCurve *fcu;
-       FModifier *fcm;
        
        for (fcu=fcurves->first; fcu; fcu=fcu->next) {
                /* F-Curve */
@@ -794,50 +843,8 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
                        }
                }
                
-               /* Modifiers */
-               for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) {
-                       FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-                       
-                       /* Write the specific data */
-                       if (fmi && fcm->data) {
-                               /* firstly, just write the plain fmi->data struct */
-                               writestruct(wd, DATA, fmi->structName, 1, fcm->data);
-                               
-                               /* do any modifier specific stuff */
-                               switch (fcm->type) {
-                                       case FMODIFIER_TYPE_GENERATOR:
-                                       {
-                                               FMod_Generator *data= (FMod_Generator *)fcm->data;
-                                               
-                                               /* write coefficients array */
-                                               if (data->coefficients)
-                                                       writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
-                                       }
-                                               break;
-                                       case FMODIFIER_TYPE_ENVELOPE:
-                                       {
-                                               FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-                                               
-                                               /* write envelope data */
-                                               if (data->data)
-                                                       writedata(wd, DATA, sizeof(FCM_EnvelopeData)*(data->totvert), data->data);
-                                       }
-                                               break;
-                                       case FMODIFIER_TYPE_PYTHON:
-                                       {
-                                               FMod_Python *data = (FMod_Python *)fcm->data;
-                                               
-                                               /* Write ID Properties -- and copy this comment EXACTLY for easy finding
-                                                of library blocks that implement this.*/
-                                               IDP_WriteProperty(data->prop, wd);
-                                       }
-                                               break;
-                               }
-                       }
-                       
-                       /* Write the modifier */
-                       writestruct(wd, DATA, "FModifier", 1, fcm);
-               }
+               /* write F-Modifiers */
+               write_fmodifiers(wd, &fcu->modifiers);
        }
 }
 
@@ -888,6 +895,29 @@ static void write_keyingsets(WriteData *wd, ListBase *list)
        }
 }
 
+static void write_nladata(WriteData *wd, ListBase *nlabase)
+{
+       NlaTrack *nlt;
+       NlaStrip *strip;
+       
+       /* write all the tracks */
+       for (nlt= nlabase->first; nlt; nlt= nlt->next) {
+               /* write the track first */
+               writestruct(wd, DATA, "NlaTrack", 1, nlt);
+               
+               for (strip= nlt->strips.first; strip; strip= strip->next) {
+                       /* write the strip first */
+                       writestruct(wd, DATA, "NlaStrip", 1, strip);
+                       
+                       /* write the strip's F-Curves and modifiers */
+                       write_fcurves(wd, &strip->fcurves);
+                       write_fmodifiers(wd, &strip->modifiers);
+                       
+                       // TODO write the remaps
+               }
+       }
+}
+
 static void write_animdata(WriteData *wd, AnimData *adt)
 {
        AnimOverride *aor;
@@ -899,14 +929,17 @@ static void write_animdata(WriteData *wd, AnimData *adt)
        write_fcurves(wd, &adt->drivers);
        
        /* write overrides */
+       // FIXME: are these needed?
        for (aor= adt->overrides.first; aor; aor= aor->next) {
                /* overrides consist of base data + rna_path */
                writestruct(wd, DATA, "AnimOverride", 1, aor);
                writedata(wd, DATA, strlen(aor->rna_path)+1, aor->rna_path);
        }
        
+       // TODO write the remaps (if they are needed)
+       
        /* write NLA data */
-       // XXX todo...
+       write_nladata(wd, &adt->nla_tracks);
 }
 
 static void write_constraints(WriteData *wd, ListBase *conlist)
@@ -1876,7 +1909,10 @@ static void write_screens(WriteData *wd, ListBase *scrbase)
                                        writestruct(wd, DATA, "SpaceSound", 1, sl);
                                }
                                else if(sl->spacetype==SPACE_NLA){
-                                       writestruct(wd, DATA, "SpaceNla", 1, sl);
+                                       SpaceNla *snla= (SpaceNla *)sl;
+                                       
+                                       writestruct(wd, DATA, "SpaceNla", 1, snla);
+                                       if(snla->ads) writestruct(wd, DATA, "bDopeSheet", 1, snla->ads);
                                }
                                else if(sl->spacetype==SPACE_TIME){
                                        writestruct(wd, DATA, "SpaceTime", 1, sl);
index afad396607bfb6991b23d388d649e27cb82863ad..69e4fbfb08e36868da0e498a3febd2e6ade1ff23 100644 (file)
@@ -195,7 +195,7 @@ static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
        }
 }
 
-/* ----------- Private Stuff - IPO Editor ------------- */
+/* ----------- Private Stuff - Graph Editor ------------- */
 
 /* Get data being edited in Graph Editor (depending on current 'mode') */
 static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
@@ -237,6 +237,26 @@ static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
        }
 }
 
+/* ----------- Private Stuff - NLA Editor ------------- */
+
+/* Get data being edited in Graph Editor (depending on current 'mode') */
+static short nlaedit_get_context (bAnimContext *ac, SpaceNla *snla)
+{
+       /* init dopesheet data if non-existant (i.e. for old files) */
+       if (snla->ads == NULL)
+               snla->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
+       
+       /* sync settings with current view status, then return appropriate data */
+       /* update scene-pointer (no need to check for pinning yet, as not implemented) */
+       snla->ads->source= (ID *)ac->scene;
+       snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
+       
+       ac->datatype= ANIMCONT_NLA;
+       ac->data= snla->ads;
+       
+       return 1;
+}
+
 /* ----------- Public API --------------- */
 
 /* Obtain current anim-data context, given that context info from Blender context has already been set 
@@ -264,6 +284,13 @@ short ANIM_animdata_context_getdata (bAnimContext *ac)
                                ok= graphedit_get_context(ac, sipo);
                        }
                                break;
+                               
+                       case SPACE_NLA:
+                       {
+                               SpaceNla *snla= (SpaceNla *)sa->spacedata.first;
+                               ok= nlaedit_get_context(ac, snla);
+                       }
+                               break;
                }
        }
        
@@ -313,6 +340,39 @@ short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
 /* quick macro to test if AnimData is usable for drivers */
 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
 
+/* quick macro to test if AnimData is usable for NLA */
+#define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
+
+/* quick macro to test for all three avove usability tests, performing the appropriate provided 
+ * action for each when the AnimData context is appropriate. 
+ *
+ * Priority order for this goes (most important, to least): NLA, Drivers, Keyframes
+ *
+ *     - id: ID block which should have an AnimData pointer following it immediately, to use
+ *     - nlaOk: line or block of code to execute for NLA case
+ *     - driversOk: line or block of code to execute for Drivers case
+ *     - keysOk: line or block of code for Keyframes case
+ */
+#define ANIMDATA_FILTER_CASES(id, nlaOk, driversOk, keysOk) \
+       {\
+               if (ads->filterflag & ADS_FILTER_ONLYNLA) {\
+                       if (ANIMDATA_HAS_NLA(id)) {\
+                               nlaOk\
+                       }\
+               }\
+               else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {\
+                       if (ANIMDATA_HAS_DRIVERS(id)) {\
+                               driversOk\
+                       }\
+               }\
+               else {\
+                       if (ANIMDATA_HAS_KEYS(id)) {\
+                               keysOk\
+                       }\
+               }\
+       }
+
+
 /* quick macro to test if a anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
 #define ANIMCHANNEL_SELOK(test_func) \
                ( !(filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) || \
@@ -494,6 +554,18 @@ bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, s
                                ale->datatype= ALE_GPFRAME;
                        }
                                break;
+                               
+                       case ANIMTYPE_NLATRACK:
+                       {
+                               NlaTrack *nlt= (NlaTrack *)data;
+                               
+                               ale->flag= nlt->flag;
+                               
+                                       // XXX or should this be done some other way?
+                               ale->key_data= &nlt->strips;
+                               ale->datatype= ALE_NLASTRIP;
+                       }
+                               break;
                }
        }
        
@@ -610,6 +682,12 @@ static int animdata_filter_action (ListBase *anim_data, bAction *act, int filter
        return items;
 }
 
+static int animdata_filter_nla (ListBase *anim_data, NlaTrack *first, int filter_mode, void *owner, short ownertype, ID *owner_id)
+{
+       // FIXME
+       return 0;
+}
+
 static int animdata_filter_shapekey (ListBase *anim_data, Key *key, int filter_mode, void *owner, short ownertype, ID *owner_id)
 {
        bAnimListElem *ale;
@@ -752,19 +830,18 @@ static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads,
        /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
        for (a=0; a < ob->totcol; a++) {
                Material *ma= give_current_material(ob, a);
+               short ok = 0;
                
                /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
                if (ELEM(NULL, ma, ma->adt)) 
                        continue;
                
-               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
-                       if (ANIMDATA_HAS_KEYS(ma) == 0)
-                               continue;
-               }
-               else {
-                       if (ANIMDATA_HAS_DRIVERS(ma) == 0)
-                               continue;
-               }
+               /* check if ok */
+               ANIMDATA_FILTER_CASES(ma, 
+                       ok=1;, 
+                       ok=1;, 
+                       ok=1;)
+               if (ok == 0) continue;
                
                /* make a temp list elem for this */
                ld= MEM_callocN(sizeof(LinkData), "DopeSheet-MaterialCache");
@@ -801,16 +878,12 @@ static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads,
                                }
                        }
                        
-                       /* add material's F-Curve or Driver channels? */
+                       /* add material's animation data */
                        if (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_CURVESONLY)) {
-                               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
-                                       // XXX the 'owner' info here is still subject to improvement
-                                       items += animdata_filter_action(anim_data, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);
-                               }
-                               else {
-                                       // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
-                                       items += animdata_filter_fcurves(anim_data, ma->adt->drivers.first, NULL, ma, ANIMTYPE_DSMAT, filter_mode, (ID *)ma);
-                               }       
+                               ANIMDATA_FILTER_CASES(ma, 
+                                       items += animdata_filter_nla(anim_data, ma->adt->nla_tracks.first, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);, 
+                                       items += animdata_filter_fcurves(anim_data, ma->adt->drivers.first, NULL, ma, ANIMTYPE_DSMAT, filter_mode, (ID *)ma);, 
+                                       items += animdata_filter_action(anim_data, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);)
                        }
                }
        }
@@ -871,15 +944,11 @@ static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ad
        
        /* add object-data animation channels? */
        if ((expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
-               /* Action or Drivers? */
-               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
-                       // XXX the 'owner' info here is still subject to improvement
-                       items += animdata_filter_action(anim_data, iat->adt->action, filter_mode, iat, type, (ID *)iat);
-               }
-               else {
-                       // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
-                       items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);
-               }
+               /* filtering for channels - nla, drivers, keyframes */
+               ANIMDATA_FILTER_CASES(iat, 
+                       items+= animdata_filter_nla(anim_data, iat->adt->nla_tracks.first, filter_mode, iat, type, (ID *)iat);,
+                       items+= animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);, 
+                       items += animdata_filter_action(anim_data, iat->adt->action, filter_mode, iat, type, (ID *)iat);)
        }
        
        /* return the number of items added to the list */
@@ -889,8 +958,10 @@ static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ad
 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
 {
        bAnimListElem *ale=NULL;
+       AnimData *adt = NULL;
        Object *ob= base->object;
        Key *key= ob_get_key(ob);
+       short obdata_ok = 0;
        int items = 0;
        
        /* add this object as a channel first */
@@ -909,73 +980,83 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
        if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & ANIMFILTER_CURVESONLY) )
                return items;
        
-       /* Action or Drivers */
-       if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
-               /* Action? */
-               if (ANIMDATA_HAS_KEYS(ob) /*&& !(ads->filterflag & ADS_FILTER_NOACTS)*/) {
-                       AnimData *adt= ob->adt;
-                       
-                       /* include action-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+       /* Action, Drivers, or NLA */
+       if (ob->adt) {
+               adt= ob->adt;
+               ANIMDATA_FILTER_CASES(ob,
+                       { /* nla */
+#if 0
+                               /* include nla-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLNLA, base, ANIMTYPE_OBJECT, (ID *)ob);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
                                }
-                       }
-                       
-                       /* add F-Curve channels? */
-                       if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
-                               // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
-                               items += animdata_filter_action(anim_data, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob); 
-                       }
-               }
-       }
-       else {
-               /* Drivers */
-               if (ANIMDATA_HAS_DRIVERS(ob)) {
-                       AnimData *adt= ob->adt;
-                       
-                       /* include drivers-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+#endif
+                               
+                               /* add NLA tracks */
+                               if (/*EXPANDED_NLTD(adt) ||*/ !(filter_mode & ANIMFILTER_CHANNELS))
+                                       items += animdata_filter_nla(anim_data, adt->nla_tracks.first, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
+                       },
+                       { /* drivers */
+                               /* include drivers-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add F-Curve channels (drivers are F-Curves) */
+                               if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
+                                       // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
+                                       items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
+                               }
+                       },
+                       { /* action (keyframes) */
+                               /* include action-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add F-Curve channels? */
+                               if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
+                                       // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
+                                       items += animdata_filter_action(anim_data, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob); 
                                }
                        }
-                       
-                       /* add F-Curve channels (drivers are F-Curves) */
-                       if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
-                               // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
-                               items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
-                       }
-               }
+               )
        }
        
+       
        /* ShapeKeys? */
        if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
-               /* Animation or Drivers */
-               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
-                       /* include shapekey-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+               adt= key->adt;
+               ANIMDATA_FILTER_CASES(key,
+                       { /* nla */
+#if 0
+                               /* include nla-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLNLA, base, ANIMTYPE_OBJECT, (ID *)ob);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
                                }
-                       }
-                       
-                       /* add channels */
-                       if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
-                               items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
-                       }
-               }
-               else {
-                       /* Drivers */
-                       if (ANIMDATA_HAS_DRIVERS(key)) {
-                               AnimData *adt= key->adt;
+#endif
                                
+                               /* add NLA tracks */
+                               if (/*EXPANDED_NLTD(adt) ||*/ !(filter_mode & ANIMFILTER_CHANNELS))
+                                       items += animdata_filter_nla(anim_data, adt->nla_tracks.first, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
+                       },
+                       { /* drivers */
                                /* include shapekey-expand widget? */
                                if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
                                        ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
@@ -985,15 +1066,28 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
                                        }
                                }
                                
-                               /* add F-Curve channels (drivers are F-Curves) */
-                               if (FILTER_SKE_OBJD(key)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
-                                       // XXX owner info is messed up now...
-                                       items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)key);
+                               /* add channels */
+                               if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
+                               }
+                       },
+                       { /* action (keyframes) */
+                               /* include shapekey-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add channels */
+                               if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
                                }
                        }
-               }
+               )
        }
-       
 
        /* Materials? */
        if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
@@ -1006,14 +1100,10 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
                        Camera *ca= (Camera *)ob->data;
                        
                        if ((ads->filterflag & ADS_FILTER_NOCAM) == 0) {
-                               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
-                                       if (ANIMDATA_HAS_KEYS(ca))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
-                               else {
-                                       if (ANIMDATA_HAS_DRIVERS(ca))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
+                               ANIMDATA_FILTER_CASES(ca,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;)
                        }
                }
                        break;
@@ -1022,14 +1112,10 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
                        Lamp *la= (Lamp *)ob->data;
                        
                        if ((ads->filterflag & ADS_FILTER_NOLAM) == 0) {
-                               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
-                                       if (ANIMDATA_HAS_KEYS(la))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
-                               else {
-                                       if (ANIMDATA_HAS_DRIVERS(la))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
+                               ANIMDATA_FILTER_CASES(la,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;)
                        }
                }
                        break;
@@ -1038,18 +1124,16 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
                        Curve *cu= (Curve *)ob->data;
                        
                        if ((ads->filterflag & ADS_FILTER_NOCUR) == 0) {
-                               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
-                                       if (ANIMDATA_HAS_KEYS(cu))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
-                               else {
-                                       if (ANIMDATA_HAS_DRIVERS(cu))
-                                               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
-                               }
+                               ANIMDATA_FILTER_CASES(cu,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;,
+                                       obdata_ok= 1;)
                        }
                }
                        break;
        }
+       if (obdata_ok) 
+               items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
        
        /* return the number of items added to the list */
        return items;
@@ -1058,6 +1142,7 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B
 static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
 {
        World *wo= sce->world;
+       AnimData *adt= NULL;
        bAnimListElem *ale;
        int items = 0;
        
@@ -1077,74 +1162,82 @@ static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads
        if ( (EXPANDED_SCEC(sce) == 0) && !(filter_mode & ANIMFILTER_CURVESONLY) )
                return items;
                
-       /* Action or Drivers */
-       if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
-               /* Action? */
-               if (ANIMDATA_HAS_KEYS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE)) {
-                       AnimData *adt= sce->adt;
-                       
-                       /* include action-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+       /* Action, Drivers, or NLA  for Scene */
+       if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
+               adt= sce->adt;
+               ANIMDATA_FILTER_CASES(sce,
+                       { /* nla */
+#if 0
+                               /* include nla-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLNLA, base, ANIMTYPE_SCENE (ID *)sce);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
                                }
-                       }
-                       
-                       /* add F-Curve channels? */
-                       if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
-                               items += animdata_filter_action(anim_data, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce); 
-                       }
-               }
-       }
-       else {
-               /* Drivers */
-               if (ANIMDATA_HAS_DRIVERS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE)) {
-                       AnimData *adt= sce->adt;
-                       
-                       /* include drivers-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+#endif
+                               
+                               /* add NLA tracks */
+                               if (/*EXPANDED_NLTD(adt) ||*/ !(filter_mode & ANIMFILTER_CHANNELS))
+                                       items += animdata_filter_nla(anim_data, adt->nla_tracks.first, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce);
+                       },
+                       { /* drivers */
+                               /* include drivers-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add F-Curve channels (drivers are F-Curves) */
+                               if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
+                                       items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
+                               }
+                       },
+                       { /* action */
+                               /* include action-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add F-Curve channels? */
+                               if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
+                                       items += animdata_filter_action(anim_data, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce); 
                                }
                        }
-                       
-                       /* add F-Curve channels (drivers are F-Curves) */
-                       if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
-                               items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
-                       }
-               }
+               )
        }
-               
+       
        /* world */
        if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
-               /* Animation or Drivers */
-               if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
-                       AnimData *adt= wo->adt;
-                       
-                       /* include world-expand widget? */
-                       if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
-                               ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
-                               if (ale) {
-                                       BLI_addtail(anim_data, ale);
-                                       items++;
+               /* Action, Drivers, or NLA  for World */
+               adt= wo->adt;
+               ANIMDATA_FILTER_CASES(wo,
+                       { /* nla */
+#if 0
+                               /* include nla-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLNLA, base, ANIMTYPE_DSWOR (ID *)wo);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
                                }
-                       }
-                       
-                       /* add channels */
-                       if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
-                               items += animdata_filter_action(anim_data, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo); 
-                       }
-               }
-               else {
-                       /* Drivers */
-                       if (ANIMDATA_HAS_DRIVERS(wo)) {
-                               AnimData *adt= wo->adt;
+#endif
                                
-                               /* include shapekey-expand widget? */
+                               /* add NLA tracks */
+                               if (/*EXPANDED_NLTD(adt) ||*/ !(filter_mode & ANIMFILTER_CHANNELS))
+                                       items += animdata_filter_nla(anim_data, adt->nla_tracks.first, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo);
+                       },
+                       { /* drivers */
+                               /* include world-expand widget? */
                                if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
                                        ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)wo);
                                        if (ale) {
@@ -1158,8 +1251,23 @@ static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads
                                        // XXX owner info is messed up now...
                                        items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, wo, ANIMTYPE_DSWOR, filter_mode, (ID *)wo);
                                }
+                       },
+                       { /* action */
+                               /* include world-expand widget? */
+                               if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
+                                       if (ale) {
+                                               BLI_addtail(anim_data, ale);
+                                               items++;
+                                       }
+                               }
+                               
+                               /* add channels */
+                               if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
+                                       items += animdata_filter_action(anim_data, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo); 
+                               }
                        }
-               }
+               )
        }
        
        /* return the number of items added to the list */
index efc0a0b9a57382c49dd2ed001755b045a75eaa12..75c10f957cce69b858fabf0bd15f7f5063adafeb 100644 (file)
@@ -75,8 +75,9 @@ typedef enum eAnimCont_Types {
        ANIMCONT_SHAPEKEY,              /* shapekey (Key) */
        ANIMCONT_GPENCIL,               /* grease pencil (screen) */
        ANIMCONT_DOPESHEET,             /* dopesheet (bDopesheet) */
-       ANIMCONT_FCURVES,               /* animation F-Curves (bDopesheet) */           // XXX 
+       ANIMCONT_FCURVES,               /* animation F-Curves (bDopesheet) */
        ANIMCONT_DRIVERS,               /* drivers (bDopesheet) */
+       ANIMCONT_NLA,                   /* nla (bDopesheet) */
 } eAnimCont_Types;
 
 /* --------------- Channels -------------------- */
@@ -92,10 +93,10 @@ typedef struct bAnimListElem {
        int             flag;           /* copy of elem's flags for quick access */
        int     index;          /* copy of adrcode where applicable */
        
-       void    *key_data;      /* motion data - ipo or ipo-curve */
+       void    *key_data;      /* motion data - mostly F-Curves, but can be other types too */
        short   datatype;       /* type of motion data to expect */
        
-       struct ID *id;                          /* ID block that channel is attached to (may be used  */
+       struct ID *id;          /* ID block that channel is attached to (may be used  */
        
        void    *owner;         /* group or channel which acts as this channel's owner */
        short   ownertype;      /* type of owner */
@@ -128,6 +129,8 @@ typedef enum eAnim_ChannelType {
        
        ANIMTYPE_GPDATABLOCK,
        ANIMTYPE_GPLAYER,
+       
+       ANIMTYPE_NLATRACK,
 } eAnim_ChannelType;
 
 /* types of keyframe data in bAnimListElem */
@@ -135,6 +138,7 @@ typedef enum eAnim_KeyType {
        ALE_NONE = 0,           /* no keyframe data */
        ALE_FCURVE,                     /* F-Curve */
        ALE_GPFRAME,            /* Grease Pencil Frames */
+       ALE_NLASTRIP,           /* NLA Strips */
        
        // XXX the following are for summaries... should these be kept?
        ALE_SCE,                        /* Scene summary */
@@ -202,6 +206,10 @@ typedef enum eAnimFilter_Flags {
 #define EDITABLE_GPL(gpl) ((gpl->flag & GP_LAYER_LOCKED)==0)
 #define SEL_GPL(gpl) ((gpl->flag & GP_LAYER_ACTIVE) || (gpl->flag & GP_LAYER_SELECT))
 
+/* NLA only */
+#define SEL_NLT(nlt) (nlt->flag & NLATRACK_SELECTED)
+#define EDITABLE_NLT(nlt) ((nlt->flag & NLATRACK_PROTECTED)==0)
+
 /* -------------- Channel Defines -------------- */
 
 /* channel heights */
index 6e1a97dea3446a8f44ab8e4c962d2391d49c98f7..cdaabe9e9dec25be6d36d032bafdaeb849c83c53 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 
+#include "DNA_anim_types.h"
 #include "DNA_nla_types.h"
 #include "DNA_object_types.h"
 #include "DNA_space_types.h"
@@ -71,6 +72,9 @@ static SpaceLink *nla_new(const bContext *C)
        snla= MEM_callocN(sizeof(SpaceNla), "initnla");
        snla->spacetype= SPACE_NLA;
        
+       /* allocate DopeSheet data for NLA Editor */
+       snla->ads= MEM_callocN(sizeof(bDopeSheet), "NLAEdit DopeSheet");
+       
        /* header */
        ar= MEM_callocN(sizeof(ARegion), "header for nla");
        
@@ -122,8 +126,12 @@ static SpaceLink *nla_new(const bContext *C)
 /* not spacelink itself */
 static void nla_free(SpaceLink *sl)
 {      
-//     SpaceNla *snla= (SpaceNla*) sl;
+       SpaceNla *snla= (SpaceNla*) sl;
        
+       if (snla->ads) {
+               BLI_freelistN(&snla->ads->chanbase);
+               MEM_freeN(snla->ads);
+       }
 }
 
 
index 7e54045b5e4bfb2e777bf9d5673a98c6d91b6e60..802f8d88c0343534c4185f1b6d20fa9ebced28e6 100644 (file)
@@ -290,6 +290,7 @@ typedef enum DOPESHEET_FILTERFLAG {
                /* general filtering */
        ADS_FILTER_ONLYSEL                      = (1<<0),
        ADS_FILTER_ONLYDRIVERS          = (1<<1),
+       ADS_FILTER_ONLYNLA                      = (1<<2),
        
                /* datatype-based filtering */
        ADS_FILTER_NOSHAPEKEYS          = (1<<6),
index f30cd63242a78c385f9bc35b8e1a0935e389f286..b20ec7ba37f53f16e877f940c6cc4fa9fe66ac6b 100644 (file)
@@ -384,85 +384,91 @@ typedef struct AnimMapper {
 
 /* ************************************************ */
 /* NLA - Non-Linear Animation */
-// TODO: the concepts here still need to be refined to solve any unresolved items
-
-/* NLA Modifiers ---------------------------------- */
-
-/* These differ from F-Curve modifiers, as although F-Curve modifiers also operate on a 
- * per-channel basis too (in general), they are part of the animation data itself, which
- * means that their effects are inherited by all of their users. In order to counteract this,
- * the modifiers here should be used to provide variation to pre-created motions only. 
- */
 
 /* NLA Strips ------------------------------------- */
 
 /* NLA Strip (strip)
  *
  * A NLA Strip is a container for the reuse of Action data, defining parameters
- * to control the remapping of the Action data to some destination. Actions being
- * referenced by NLA-Strips SHOULD-NOT be editable, unless they were created in such
- * a way that results in very little mapping distortion (i.e. for layered animation only,
- * opposed to prebuilt 'blocks' which are quickly dumped into the NLA for crappymatic machima-type
- * stuff)
+ * to control the remapping of the Action data to some destination. 
  */
 typedef struct NlaStrip {
        struct NlaStrip *next, *prev;
        
-       bAction *act;                           /* Action that is referenced by this strip */
+       bAction *act;                           /* Action that is referenced by this strip (strip is 'user' of the action) */
        AnimMapper *remap;                      /* Remapping info this strip (for tweaking correspondance of action with context) */
        
-       ListBase modifiers;                     /* NLA Modifiers */     
-       
-       ListBase fcurves;                       /* F-Curves for controlling this strip's influence and timing */
+       ListBase fcurves;                       /* F-Curves for controlling this strip's influence and timing */        // TODO: move out?
+       ListBase modifiers;                     /* F-Curve modifiers to be applied to the entire strip's referenced F-Curves */
        float influence;                        /* Influence of strip */
-       float act_time;                         /* Current 'time' within action being used */
+       float strip_time;                       /* Current 'time' within action being used (automatically evaluated, but can be overridden) */
        
        float start, end;                       /* extents of the strip */
        float actstart, actend;         /* range of the action to use */
        
-       float   repeat;                         /* The number of times to repeat the action range (only when no F-Curves) */
-       float   scale;                          /* The amount the action range is scaled by (only when no F-Curves) */
+       float repeat;                           /* The number of times to repeat the action range (only when no F-Curves) */
+       float scale;                            /* The amount the action range is scaled by (only when no F-Curves) */
        
        float blendin, blendout;        /* strip blending length (only used when there are no F-Curves) */      
-       int blendmode;                          /* strip blending mode */       
-       
-       int flag;                                       /* settings */
-       
-               // umm... old unused cruft? 
-       int stride_axis;                        /* axis for stridebone stuff - 0=x, 1=y, 2=z */
-       int pad;
-       
-       float   actoffs;                        /* Offset within action, for cycles and striding (only set for ACT_USESTRIDE) */
-       float   stridelen;                      /* The stridelength (considered when flag & ACT_USESTRIDE) */
+       short blendmode;                        /* strip blending mode (layer-based mixing) */
+       short extendmode;                       /* strip extrapolation mode (time-based mixing) */
        
-       char    stridechannel[32];      /* Instead of stridelen, it uses an action channel */
-       char    offs_bone[32];          /* if repeat, use this bone/channel for defining offset */
+       short flag;                                     /* settings */
+       short type;                                     /* type of NLA strip */
 } NlaStrip;
 
 /* NLA Strip Blending Mode */
 enum {
-       NLASTRIPMODE_BLEND = 0,
-       NLASTRIPMODE_ADD,
-       NLASTRIPMODE_SUBTRACT,
-} eActStrip_Mode;
+       NLASTRIP_MODE_BLEND = 0,
+       NLASTRIP_MODE_ADD,
+       NLASTRIP_MODE_SUBTRACT,
+       NLASTRIP_MODE_MULTIPLY,
+} eNlaStrip_Blend_Mode;
+
+/* NLA Strip Extrpolation Mode */
+enum {
+               /* extend before first frame if no previous strips in track, and always hold+extend last frame */
+       NLASTRIP_EXTEND_HOLD    = 0,            
+               /* only hold+extend last frame */
+       NLASTRIP_EXTEND_HOLD_FORWARD,   
+               /* don't contribute at all */
+       NLASTRIP_EXTEND_NOTHING,
+} eNlaStrip_Extrapolate_Mode;
 
 /* NLA Strip Settings */
-// TODO: check on which of these are still useful...
 enum {
-       NLASTRIP_SELECT                 = (1<<0),
-       NLASTRIP_USESTRIDE              = (1<<1),
-       NLASTRIP_BLENDTONEXT    = (1<<2),       /* Not implemented. Is not used anywhere */
-       NLASTRIP_HOLDLASTFRAME  = (1<<3),
-       NLASTRIP_ACTIVE                 = (1<<4),
-       NLASTRIP_LOCK_ACTION    = (1<<5),
-       NLASTRIP_MUTE                   = (1<<6),
-       NLASTRIP_REVERSE                = (1<<7),       /* This has yet to be implemented. To indicate that a strip should be played backwards */
-       NLASTRIP_CYCLIC_USEX    = (1<<8),
-       NLASTRIP_CYCLIC_USEY    = (1<<9),
-       NLASTRIP_CYCLIC_USEZ    = (1<<10),
-       NLASTRIP_AUTO_BLENDS    = (1<<11),
-       NLASTRIP_TWEAK                  = (1<<12),      /* This strip is a tweaking strip (only set if owner track is a tweak track) */
-} eActionStrip_Flag;
+       /* UI selection flags */
+               /* NLA strip is the active one in the track (also indicates if strip is being tweaked) */
+       NLASTRIP_FLAG_ACTIVE            = (1<<0),       
+               /* NLA strip is selected for editing */
+       NLASTRIP_FLAG_SELECT            = (1<<1),
+//     NLASTRIP_FLAG_SELECT_L          = (1<<2),       // left handle selected
+//     NLASTRIP_FLAG_SELECT_R          = (1<<3),       // right handle selected
+       
+       /* controls driven by local F-Curves */
+               /* strip influence is controlled by local F-Curve */
+       NLASTRIP_FLAG_USR_INFLUENCE     = (1<<5),
+       NLASTRIP_FLAG_USR_TIME          = (1<<6),
+       
+       /* playback flags (may be overriden by F-Curves) */
+               /* NLA strip blendin/out values are set automatically based on overlaps */
+       NLASTRIP_FLAG_AUTO_BLENDS       = (1<<10),
+               /* NLA strip is played back in reverse order */
+       NLASTRIP_FLAG_REVERSE           = (1<<11),
+               /* NLA strip is muted (i.e. doesn't contribute in any way) */
+               // TODO: this overlaps a lot with the functionality in track
+       NLASTRIP_FLAG_MUTED                     = (1<<12),
+               /* NLA strip length is synced to the length of the referenced action */
+       NLASTRIP_FLAG_SYNC_LENGTH       = (1<<13),
+} eNlaStrip_Flag;
+
+/* NLA Strip Type */
+enum { 
+               /* 'clip' - references an Action */
+       NLASTRIP_TYPE_CLIP      = 0,
+               /* 'transition' - blends between the adjacent strips */
+       NLASTRIP_TYPE_TRANSITION,
+} eNlaStrip_Type;
 
 /* NLA Tracks ------------------------------------- */
 
@@ -481,14 +487,12 @@ typedef struct NlaTrack {
        int flag;                               /* settings for this track */
        int index;                              /* index of the track in the stack (NOTE: not really useful, but we need a pad var anyways!) */
        
-       char info[64];                  /* short user-description of this track */
+       char name[64];                  /* short user-description of this track */
 } NlaTrack;
 
 /* settings for track */
 enum {
-               /* track is the one that settings can be modified on (doesn't indicate 
-                * that it's for 'tweaking' though) 
-                */
+               /* track is the one that settings can be modified on, also indicates if track is being 'tweaked' */
        NLATRACK_ACTIVE         = (1<<0),
                /* track is selected in UI for relevant editing operations */
        NLATRACK_SELECTED       = (1<<1),
@@ -498,10 +502,6 @@ enum {
        NLATRACK_SOLO           = (1<<3),
                /* track's settings (and strips) cannot be edited (to guard against unwanted changes) */
        NLATRACK_PROTECTED      = (1<<4),
-               /* strip is the 'last' one that should be evaluated, as the active action 
-                * is being used to tweak the animation of the strips up to here 
-                */
-       NLATRACK_TWEAK          = (1<<5),
 } eNlaTrack_Flag;
 
 
@@ -674,11 +674,13 @@ enum {
        ADT_NLA_SOLO_TRACK              = (1<<0),
                /* don't use NLA */
        ADT_NLA_EVAL_OFF                = (1<<1),
-               /* don't execute drivers */
-       ADT_DRIVERS_DISABLED    = (1<<2),
+               /* NLA is being 'tweaked' (i.e. in EditMode) */
+       ADT_NLA_EDIT_ON                 = (1<<2),
        
                /* drivers expanded in UI */
        ADT_DRIVERS_COLLAPSED   = (1<<10),
+               /* don't execute drivers */
+       ADT_DRIVERS_DISABLED    = (1<<11),
 } eAnimData_Flag;
 
 /* Animation Data recalculation settings (to be set by depsgraph) */
index 8cdb51bcab0e0051880f677e17fc88c5e30154ea..ba4ef1f164a6deb49efd20d6905f70554b34a75a 100644 (file)
@@ -244,10 +244,11 @@ typedef struct SpaceNla {
 
        short blockhandler[8];
 
-       short menunr, lock;
        short autosnap;                 /* this uses the same settings as autosnap for Action Editor */
        short flag;
+       int pad;
        
+       struct bDopeSheet *ads;
        View2D v2d;      /* depricated, copied to region */
 } SpaceNla;