Keyframing Bugfixes and Feature Requests:
[blender.git] / source / blender / editors / animation / keyingsets.c
index afd693d7981b30fe8e8d62d1d9ec4d7fc58fd014..d5624b8bc5b308104098b687646b1ec4fa7a6867 100644 (file)
@@ -133,11 +133,9 @@ static int add_default_keyingset_exec (bContext *C, wmOperator *op)
         */
        flag |= KEYINGSET_ABSOLUTE;
        
-       if (IS_AUTOKEY_FLAG(AUTOMATKEY)) 
-               keyingflag |= INSERTKEY_MATRIX;
-       if (IS_AUTOKEY_FLAG(INSERTNEEDED)) 
-               keyingflag |= INSERTKEY_NEEDED;
-               
+       /* 2nd arg is 0 to indicate that we don't want to include autokeying mode related settings */
+       keyingflag = ANIM_get_keyframing_flags(scene, 0);
+       
        /* call the API func, and set the active keyingset index */
        BKE_keyingset_add(&scene->keyingsets, NULL, flag, keyingflag);
        
@@ -326,6 +324,8 @@ static int add_keyingset_button_exec (bContext *C, wmOperator *op)
                        keyingflag |= INSERTKEY_MATRIX;
                if (IS_AUTOKEY_FLAG(INSERTNEEDED)) 
                        keyingflag |= INSERTKEY_NEEDED;
+               if (IS_AUTOKEY_FLAG(XYZ2RGB)) 
+                       keyingflag |= INSERTKEY_XYZ2RGB;
                        
                /* call the API func, and set the active keyingset index */
                ks= BKE_keyingset_add(&scene->keyingsets, "ButtonKeyingSet", flag, keyingflag);
@@ -1305,9 +1305,7 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
                kflag= ks->keyingflag;
                
                /* suppliment with info from the context */
-               if (IS_AUTOKEY_FLAG(AUTOMATKEY)) kflag |= INSERTKEY_MATRIX;
-               if (IS_AUTOKEY_FLAG(INSERTNEEDED)) kflag |= INSERTKEY_NEEDED;
-               if (IS_AUTOKEY_MODE(scene, EDITKEYS)) kflag |= INSERTKEY_REPLACE;
+               kflag |= ANIM_get_keyframing_flags(scene, 1);
        }
        else if (mode == MODIFYKEY_MODE_DELETE)
                kflag= 0;
@@ -1318,7 +1316,7 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
                 * provided by the user, and is stored, ready to use, in the KeyingSet paths.
                 */
                for (ksp= ks->paths.first; ksp; ksp= ksp->next) {
-                       int i;
+                       int arraylen, i;
                        
                        /* get pointer to name of group to add channels to */
                        if (ksp->groupmode == KSP_GROUP_NONE)
@@ -1328,14 +1326,36 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
                        else
                                groupname= ksp->group;
                        
-                       /* passing -1 as the array_index results in the entire array being modified */
-                       i= (ksp->flag & KSP_FLAG_WHOLE_ARRAY) ? (-1) : (ksp->array_index);
+                       /* init arraylen and i - arraylen should be greater than i so that
+                        * normal non-array entries get keyframed correctly
+                        */
+                       i= ksp->array_index;
+                       arraylen= i;
+                       
+                       /* get length of array if whole array option is enabled */
+                       if (ksp->flag & KSP_FLAG_WHOLE_ARRAY) {
+                               PointerRNA id_ptr, ptr;
+                               PropertyRNA *prop;
+                               
+                               RNA_id_pointer_create(ksp->id, &id_ptr);
+                               if (RNA_path_resolve(&id_ptr, ksp->rna_path, &ptr, &prop) && prop)
+                                       arraylen= RNA_property_array_length(&ptr, prop);
+                       }
+                       
+                       /* we should do at least one step */
+                       if (arraylen == i)
+                               arraylen++;
                        
-                       /* action to take depends on mode */
-                       if (mode == MODIFYKEY_MODE_INSERT)
-                               success += insert_keyframe(ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag);
-                       else if (mode == MODIFYKEY_MODE_DELETE)
-                               success += delete_keyframe(ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag);
+                       /* for each possible index, perform operation 
+                        *      - assume that arraylen is greater than index
+                        */
+                       for (; i < arraylen; i++) {
+                               /* action to take depends on mode */
+                               if (mode == MODIFYKEY_MODE_INSERT)
+                                       success += insert_keyframe(ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag);
+                               else if (mode == MODIFYKEY_MODE_DELETE)
+                                       success += delete_keyframe(ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag);
+                       }
                        
                        /* set recalc-flags */
                        if (ksp->id) {
@@ -1364,7 +1384,7 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
                        for (ksp= ks->paths.first; ksp; ksp= ksp->next) {
                                DynStr *pathds= BLI_dynstr_new();
                                char *path = NULL;
-                               int i;
+                               int arraylen, i;
                                
                                /* set initial group name */
                                if (cks->id == NULL) {
@@ -1439,14 +1459,32 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
                                else if (ksp->groupmode == KSP_GROUP_NAMED)
                                        groupname= ksp->group;
                                
-                               /* passing -1 as the array_index results in the entire array being modified */
-                               i= (ksp->flag & KSP_FLAG_WHOLE_ARRAY) ? (-1) : (ksp->array_index);
+                               /* init arraylen and i - arraylen should be greater than i so that
+                                * normal non-array entries get keyframed correctly
+                                */
+                               i= ksp->array_index;
+                               arraylen= i+1;
                                
-                               /* action to take depends on mode */
-                               if (mode == MODIFYKEY_MODE_INSERT)
-                                       success+= insert_keyframe(cks->id, act, groupname, path, i, cfra, kflag);
-                               else if (mode == MODIFYKEY_MODE_DELETE)
-                                       success+= delete_keyframe(cks->id, act, groupname, path, i, cfra, kflag);
+                               /* get length of array if whole array option is enabled */
+                               if (ksp->flag & KSP_FLAG_WHOLE_ARRAY) {
+                                       PointerRNA id_ptr, ptr;
+                                       PropertyRNA *prop;
+                                       
+                                       RNA_id_pointer_create(cks->id, &id_ptr);
+                                       if (RNA_path_resolve(&id_ptr, path, &ptr, &prop) && prop)
+                                               arraylen= RNA_property_array_length(&ptr, prop);
+                               }
+                               
+                               /* for each possible index, perform operation 
+                                *      - assume that arraylen is greater than index
+                                */
+                               for (; i < arraylen; i++) {
+                                       /* action to take depends on mode */
+                                       if (mode == MODIFYKEY_MODE_INSERT)
+                                               success+= insert_keyframe(cks->id, act, groupname, path, i, cfra, kflag);
+                                       else if (mode == MODIFYKEY_MODE_DELETE)
+                                               success+= delete_keyframe(cks->id, act, groupname, path, i, cfra, kflag);
+                               }
                                
                                /* free the path */
                                MEM_freeN(path);