Remove the unsigned, since totbits is signed too.
[blender.git] / source / blender / blenkernel / intern / ipo.c
1 /* ipo.c
2  * 
3  * $Id$
4  *
5  * ***** BEGIN GPL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): 2008,2009 Joshua Leung (IPO System cleanup, Animation System Recode)
27  *
28  * ***** END GPL LICENSE BLOCK *****
29  */
30
31 /* NOTE:
32  *
33  * This file is no longer used to provide tools for the depreceated IPO system. Instead, it
34  * is only used to house the conversion code to the new system.
35  *
36  * -- Joshua Leung, Jan 2009
37  */
38  
39 #include <math.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <stddef.h>
43
44 #include "MEM_guardedalloc.h"
45
46 #include "DNA_anim_types.h"
47 #include "DNA_constraint_types.h"
48 #include "DNA_camera_types.h"
49 #include "DNA_lamp_types.h"
50 #include "DNA_ipo_types.h"
51 #include "DNA_key_types.h"
52 #include "DNA_material_types.h"
53 #include "DNA_nla_types.h"
54 #include "DNA_sequence_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_world_types.h"
57 #include "DNA_object_types.h"
58
59 #include "BLI_math.h" /* windows needs for M_PI */
60 #include "BLI_blenlib.h"
61 #include "BLI_dynstr.h"
62
63 #include "BKE_utildefines.h"
64
65 #include "BKE_animsys.h"
66 #include "BKE_action.h"
67 #include "BKE_fcurve.h"
68 #include "BKE_global.h"
69 #include "BKE_main.h"
70 #include "BKE_nla.h"
71 #include "BKE_sequencer.h"
72
73
74 /* *************************************************** */
75 /* Old-Data Freeing Tools */
76
77 /* Free data from old IPO-Blocks (those which haven't been converted), but not IPO block itself */
78 // XXX this shouldn't be necessary anymore, but may occur while not all data is converted yet
79 void free_ipo (Ipo *ipo)
80 {
81         IpoCurve *icu, *icn;
82         int n= 0;
83         
84         for (icu= ipo->curve.first; icu; icu= icn) {
85                 icn= icu->next;
86                 n++;
87                 
88                 if (icu->bezt) MEM_freeN(icu->bezt);
89                 if (icu->bp) MEM_freeN(icu->bp);
90                 if (icu->driver) MEM_freeN(icu->driver);
91                 
92                 BLI_freelinkN(&ipo->curve, icu);
93         }
94         
95         if (G.f & G_DEBUG)
96                 printf("Freed %d (Unconverted) Ipo-Curves from IPO '%s' \n", n, ipo->id.name+2);
97 }
98
99 /* *************************************************** */
100 /* ADRCODE to RNA-Path Conversion Code  - Special (Bitflags) */
101
102 /* Mapping Table for bitflag <-> RNA path */
103 typedef struct AdrBit2Path {
104         int bit;
105         char *path;
106         int array_index;
107 } AdrBit2Path;
108
109 /* ----------------- */
110 /* Mapping Tables to use bits <-> RNA paths */
111
112 /* Object layers */
113 static AdrBit2Path ob_layer_bits[]= {
114         {(1<<0), "layer", 0},
115         {(1<<1), "layer", 1},
116         {(1<<2), "layer", 2},
117         {(1<<3), "layer", 3},
118         {(1<<4), "layer", 4},
119         {(1<<5), "layer", 5},
120         {(1<<6), "layer", 6},
121         {(1<<7), "layer", 7},
122         {(1<<8), "layer", 8},
123         {(1<<9), "layer", 9},
124         {(1<<10), "layer", 10},
125         {(1<<11), "layer", 11},
126         {(1<<12), "layer", 12},
127         {(1<<13), "layer", 13},
128         {(1<<14), "layer", 14},
129         {(1<<15), "layer", 15},
130         {(1<<16), "layer", 16},
131         {(1<<17), "layer", 17},
132         {(1<<18), "layer", 18},
133         {(1<<19), "layer", 19},
134         {(1<<20), "layer", 20}
135 };
136
137 /* Material mode */
138 static AdrBit2Path ma_mode_bits[]= {
139 //      {MA_TRACEBLE, "traceable", 0},
140 //      {MA_SHADOW, "shadow", 0},
141 //      {MA_SHLESS, "shadeless", 0},
142 //      ...
143         {MA_RAYTRANSP, "transparency", 0},
144         {MA_RAYMIRROR, "raytrace_mirror.enabled", 0},
145 //      {MA_HALO, "type", MA_TYPE_HALO}
146 };
147
148 /* ----------------- */
149
150 /* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */
151 #define RET_ABP(items) \
152         { \
153                 *tot= sizeof(items)/sizeof(AdrBit2Path); \
154                 return items; \
155         }
156
157 /* This function checks if a Blocktype+Adrcode combo, returning a mapping table */
158 static AdrBit2Path *adrcode_bitmaps_to_paths (int blocktype, int adrcode, int *tot)
159 {
160         /* Object layers */
161         if ((blocktype == ID_OB) && (adrcode == OB_LAY)) 
162                 RET_ABP(ob_layer_bits)
163         else if ((blocktype == ID_MA) && (adrcode == MA_MODE))
164                 RET_ABP(ma_mode_bits)
165         // XXX TODO: add other types...
166         
167         /* Normal curve */
168         return NULL;
169 }
170
171 /* *************************************************** */
172 /* ADRCODE to RNA-Path Conversion Code  - Standard */
173
174 /* Object types */
175 static char *ob_adrcodes_to_paths (int adrcode, int *array_index)
176 {
177         /* set array index like this in-case nothing sets it correctly  */
178         *array_index= 0;
179         
180         /* result depends on adrcode */
181         switch (adrcode) {
182                 case OB_LOC_X:
183                         *array_index= 0; return "location";
184                 case OB_LOC_Y:
185                         *array_index= 1; return "location";
186                 case OB_LOC_Z:
187                         *array_index= 2; return "location";
188                 case OB_DLOC_X:
189                         *array_index= 0; return "delta_location";
190                 case OB_DLOC_Y:
191                         *array_index= 1; return "delta_location";
192                 case OB_DLOC_Z:
193                         *array_index= 2; return "delta_location";
194                 
195                 case OB_ROT_X:
196                         *array_index= 0; return "rotation_euler";
197                 case OB_ROT_Y:
198                         *array_index= 1; return "rotation_euler";
199                 case OB_ROT_Z:
200                         *array_index= 2; return "rotation_euler";
201                 case OB_DROT_X:
202                         *array_index= 0; return "delta_rotation_euler";
203                 case OB_DROT_Y:
204                         *array_index= 1; return "delta_rotation_euler";
205                 case OB_DROT_Z:
206                         *array_index= 2; return "delta_rotation_euler";
207                         
208                 case OB_SIZE_X:
209                         *array_index= 0; return "scale";
210                 case OB_SIZE_Y:
211                         *array_index= 1; return "scale";
212                 case OB_SIZE_Z:
213                         *array_index= 2; return "scale";
214                 case OB_DSIZE_X:
215                         *array_index= 0; return "delta_scale";
216                 case OB_DSIZE_Y:
217                         *array_index= 1; return "delta_scale";
218                 case OB_DSIZE_Z:
219                         *array_index= 2; return "delta_scale";
220                 case OB_COL_R:
221                         *array_index= 0; return "color";
222                 case OB_COL_G:
223                         *array_index= 1; return "color";
224                 case OB_COL_B:
225                         *array_index= 2; return "color";
226                 case OB_COL_A:
227                         *array_index= 3; return "color";
228 #if 0
229                 case OB_PD_FSTR:
230                         if (ob->pd) poin= &(ob->pd->f_strength);
231                         break;
232                 case OB_PD_FFALL:
233                         if (ob->pd) poin= &(ob->pd->f_power);
234                         break;
235                 case OB_PD_SDAMP:
236                         if (ob->pd) poin= &(ob->pd->pdef_damp);
237                         break;
238                 case OB_PD_RDAMP:
239                         if (ob->pd) poin= &(ob->pd->pdef_rdamp);
240                         break;
241                 case OB_PD_PERM:
242                         if (ob->pd) poin= &(ob->pd->pdef_perm);
243                         break;
244                 case OB_PD_FMAXD:
245                         if (ob->pd) poin= &(ob->pd->maxdist);
246                         break;
247 #endif
248         }
249         
250         return NULL;
251 }
252
253 /* PoseChannel types 
254  * NOTE: pchan name comes from 'actname' added earlier... 
255  */
256 static char *pchan_adrcodes_to_paths (int adrcode, int *array_index)
257 {
258         /* set array index like this in-case nothing sets it correctly  */
259         *array_index= 0;
260         
261         /* result depends on adrcode */
262         switch (adrcode) {
263                 case AC_QUAT_W:
264                         *array_index= 0; return "rotation_quaternion";
265                 case AC_QUAT_X:
266                         *array_index= 1; return "rotation_quaternion";
267                 case AC_QUAT_Y:
268                         *array_index= 2; return "rotation_quaternion";
269                 case AC_QUAT_Z:
270                         *array_index= 3; return "rotation_quaternion";
271                         
272                 case AC_EUL_X:
273                         *array_index= 0; return "rotation_euler";
274                 case AC_EUL_Y:
275                         *array_index= 1; return "rotation_euler";
276                 case AC_EUL_Z:
277                         *array_index= 2; return "rotation_euler";
278                 
279                 case AC_LOC_X:
280                         *array_index= 0; return "location";
281                 case AC_LOC_Y:
282                         *array_index= 1; return "location";
283                 case AC_LOC_Z:
284                         *array_index= 2; return "location";
285                 
286                 case AC_SIZE_X:
287                         *array_index= 0; return "scale";
288                 case AC_SIZE_Y:
289                         *array_index= 1; return "scale";
290                 case AC_SIZE_Z:
291                         *array_index= 2; return "scale";
292         }
293         
294         /* for debugging only */
295         printf("ERROR: unmatched PoseChannel setting (code %d) \n", adrcode);
296         return NULL;
297 }
298
299 /* Constraint types */
300 static char *constraint_adrcodes_to_paths (int adrcode, int *array_index)
301 {
302         /* set array index like this in-case nothing sets it correctly  */
303         *array_index= 0;
304         
305         /* result depends on adrcode */
306         switch (adrcode) {
307                 case CO_ENFORCE:
308                         return "influence";
309                 case CO_HEADTAIL:       // XXX this needs to be wrapped in RNA.. probably then this path will be invalid
310                         return "data.head_tail";
311         }
312         
313         return NULL;
314 }
315
316 /* ShapeKey types 
317  * NOTE: as we don't have access to the keyblock where the data comes from (for now), 
318  *              we'll just use numerical indicies for now... 
319  */
320 static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
321 {
322         static char buf[128];
323         
324         /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
325         // XXX adrcode 0 was dummy 'speed' curve 
326         if (adrcode == 0) 
327                 sprintf(buf, "speed");
328         else
329                 sprintf(buf, "keys[%d].value", adrcode);
330         return buf;
331 }
332
333 /* MTex (Texture Slot) types */
334 static char *mtex_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
335 {
336         char *base=NULL, *prop=NULL;
337         static char buf[128];
338         
339         /* base part of path */
340         if (adrcode & MA_MAP1) base= "textures[0]";
341         else if (adrcode & MA_MAP2) base= "textures[1]";
342         else if (adrcode & MA_MAP3) base= "textures[2]";
343         else if (adrcode & MA_MAP4) base= "textures[3]";
344         else if (adrcode & MA_MAP5) base= "textures[4]";
345         else if (adrcode & MA_MAP6) base= "textures[5]";
346         else if (adrcode & MA_MAP7) base= "textures[6]";
347         else if (adrcode & MA_MAP8) base= "textures[7]";
348         else if (adrcode & MA_MAP9) base= "textures[8]";
349         else if (adrcode & MA_MAP10) base= "textures[9]";
350         else if (adrcode & MA_MAP11) base= "textures[10]";
351         else if (adrcode & MA_MAP12) base= "textures[11]";
352         else if (adrcode & MA_MAP13) base= "textures[12]";
353         else if (adrcode & MA_MAP14) base= "textures[13]";
354         else if (adrcode & MA_MAP15) base= "textures[14]";
355         else if (adrcode & MA_MAP16) base= "textures[15]";
356         else if (adrcode & MA_MAP17) base= "textures[16]";
357         else if (adrcode & MA_MAP18) base= "textures[17]";
358                 
359         /* property identifier for path */
360         adrcode= (adrcode & (MA_MAP1-1));
361         switch (adrcode) {
362 #if 0 // XXX these are not wrapped in RNA yet!
363                 case MAP_OFS_X:
364                         poin= &(mtex->ofs[0]); break;
365                 case MAP_OFS_Y:
366                         poin= &(mtex->ofs[1]); break;
367                 case MAP_OFS_Z:
368                         poin= &(mtex->ofs[2]); break;
369                 case MAP_SIZE_X:
370                         poin= &(mtex->size[0]); break;
371                 case MAP_SIZE_Y:
372                         poin= &(mtex->size[1]); break;
373                 case MAP_SIZE_Z:
374                         poin= &(mtex->size[2]); break;
375                 case MAP_R:
376                         poin= &(mtex->r); break;
377                 case MAP_G:
378                         poin= &(mtex->g); break;
379                 case MAP_B:
380                         poin= &(mtex->b); break;
381                 case MAP_DVAR:
382                         poin= &(mtex->def_var); break;
383                 case MAP_COLF:
384                         poin= &(mtex->colfac); break;
385                 case MAP_NORF:
386                         poin= &(mtex->norfac); break;
387                 case MAP_VARF:
388                         poin= &(mtex->varfac); break;
389 #endif
390                 case MAP_DISP:
391                         prop= "warp_factor"; break;
392         }
393         
394         /* only build and return path if there's a property */
395         if (prop) {
396                 BLI_snprintf(buf, 128, "%s.%s", base, prop);
397                 return buf;
398         }
399         else
400                 return NULL;
401 }
402
403 /* Texture types */
404 static char *texture_adrcodes_to_paths (int adrcode, int *array_index)
405 {
406         /* set array index like this in-case nothing sets it correctly  */
407         *array_index= 0;
408         
409         /* result depends on adrcode */
410         switch (adrcode) {
411                 case TE_NSIZE:
412                         return "noise_size";
413                 case TE_TURB:
414                         return "turbulence";
415                         
416                 case TE_NDEPTH: // XXX texture RNA undefined
417                         //poin= &(tex->noisedepth); *type= IPO_SHORT; break;
418                         break;
419                 case TE_NTYPE: // XXX texture RNA undefined
420                         //poin= &(tex->noisetype); *type= IPO_SHORT; break;
421                         break;
422                         
423                 case TE_N_BAS1:
424                         return "noise_basis";
425                 case TE_N_BAS2:
426                         return "noise_basis"; // XXX this is not yet defined in RNA...
427                 
428                         /* voronoi */
429                 case TE_VNW1:
430                         *array_index= 0; return "feature_weights";
431                 case TE_VNW2:
432                         *array_index= 1; return "feature_weights";
433                 case TE_VNW3:
434                         *array_index= 2; return "feature_weights";
435                 case TE_VNW4:
436                         *array_index= 3; return "feature_weights";
437                 case TE_VNMEXP:
438                         return "minkovsky_exponent";
439                 case TE_VN_DISTM:
440                         return "distance_metric";
441                 case TE_VN_COLT:
442                         return "color_type";
443                 
444                         /* distorted noise / voronoi */
445                 case TE_ISCA:
446                         return "noise_intensity";
447                         
448                         /* distorted noise */
449                 case TE_DISTA:
450                         return "distortion_amount";
451                 
452                         /* musgrave */
453                 case TE_MG_TYP: // XXX texture RNA undefined
454                 //      poin= &(tex->stype); *type= IPO_SHORT; break;
455                         break;
456                 case TE_MGH:
457                         return "highest_dimension";
458                 case TE_MG_LAC:
459                         return "lacunarity";
460                 case TE_MG_OCT:
461                         return "octaves";
462                 case TE_MG_OFF:
463                         return "offset";
464                 case TE_MG_GAIN:
465                         return "gain";
466                         
467                 case TE_COL_R:
468                         *array_index= 0; return "rgb_factor";
469                 case TE_COL_G:
470                         *array_index= 1; return "rgb_factor";
471                 case TE_COL_B:
472                         *array_index= 2; return "rgb_factor";
473                         
474                 case TE_BRIGHT:
475                         return "brightness";
476                 case TE_CONTRA:
477                         return "constrast";
478         }
479         
480         return NULL;
481 }
482
483 /* Material Types */
484 static char *material_adrcodes_to_paths (int adrcode, int *array_index)
485 {
486         /* set array index like this in-case nothing sets it correctly  */
487         *array_index= 0;
488         
489         /* result depends on adrcode */
490         switch (adrcode) {
491                 case MA_COL_R:
492                         *array_index= 0; return "diffuse_color";
493                 case MA_COL_G:
494                         *array_index= 1; return "diffuse_color";
495                 case MA_COL_B:
496                         *array_index= 2; return "diffuse_color";
497                         
498                 case MA_SPEC_R:
499                         *array_index= 0; return "specular_color";
500                 case MA_SPEC_G:
501                         *array_index= 1; return "specular_color";
502                 case MA_SPEC_B:
503                         *array_index= 2; return "specular_color";
504                         
505                 case MA_MIR_R:
506                         *array_index= 0; return "mirror_color";
507                 case MA_MIR_G:
508                         *array_index= 1; return "mirror_color";
509                 case MA_MIR_B:
510                         *array_index= 2; return "mirror_color";
511                         
512                 case MA_ALPHA:
513                         return "alpha";
514                         
515                 case MA_REF:
516                         return "diffuse_reflection";
517                 
518                 case MA_EMIT:
519                         return "emit";
520                 
521                 case MA_AMB:
522                         return "ambient";
523                 
524                 case MA_SPEC:
525                         return "specular_reflection";
526                 
527                 case MA_HARD:
528                         return "specular_hardness";
529                         
530                 case MA_SPTR:
531                         return "specular_opacity";
532                         
533                 case MA_IOR:
534                         return "ior";
535                         
536                 case MA_HASIZE:
537                         return "halo.size";
538                         
539                 case MA_TRANSLU:
540                         return "translucency";
541                         
542                 case MA_RAYM:
543                         return "raytrace_mirror.reflect";
544                         
545                 case MA_FRESMIR:
546                         return "raytrace_mirror.fresnel";
547                         
548                 case MA_FRESMIRI:
549                         return "raytrace_mirror.fresnel_fac";
550                         
551                 case MA_FRESTRA:
552                         return "raytrace_transparency.fresnel";
553                         
554                 case MA_FRESTRAI:
555                         return "raytrace_transparency.fresnel_fac";
556                         
557                 case MA_ADD:
558                         return "halo.add";
559                 
560                 default: /* for now, we assume that the others were MTex channels */
561                         return mtex_adrcodes_to_paths(adrcode, array_index);
562         }
563         
564         return NULL;    
565 }
566
567 /* Camera Types */
568 static char *camera_adrcodes_to_paths (int adrcode, int *array_index)
569 {
570         /* set array index like this in-case nothing sets it correctly  */
571         *array_index= 0;
572         
573         /* result depends on adrcode */
574         switch (adrcode) {
575                 case CAM_LENS:
576 #if 0 // XXX this cannot be resolved easily... perhaps we assume camera is perspective (works for most cases...
577                         if (ca->type == CAM_ORTHO)
578                                 return "ortho_scale";
579                         else
580                                 return "lens"; 
581 #else // XXX lazy hack for now...
582                         return "lens";
583 #endif // XXX this cannot be resolved easily
584                         
585                 case CAM_STA:
586                         return "clip_start";
587                 case CAM_END:
588                         return "clip_end";
589                         
590 #if 0 // XXX these are not defined in RNA
591                 case CAM_YF_APERT:
592                         poin= &(ca->YF_aperture); break;
593                 case CAM_YF_FDIST:
594                         poin= &(ca->YF_dofdist); break;
595 #endif // XXX these are not defined in RNA
596                         
597                 case CAM_SHIFT_X:
598                         return "shift_x";
599                 case CAM_SHIFT_Y:
600                         return "shift_y";
601         }
602         
603         /* unrecognised adrcode, or not-yet-handled ones! */
604         return NULL;
605 }
606
607 /* Lamp Types */
608 static char *lamp_adrcodes_to_paths (int adrcode, int *array_index)
609 {
610         /* set array index like this in-case nothing sets it correctly  */
611         *array_index= 0;
612         
613         /* result depends on adrcode */
614         switch (adrcode) {
615                 case LA_ENERGY:
616                         return "energy";
617                         
618                 case LA_COL_R:
619                         *array_index= 0;  return "color";
620                 case LA_COL_G:
621                         *array_index= 1;  return "color";
622                 case LA_COL_B:
623                         *array_index= 2;  return "color";
624                         
625                 case LA_DIST:
626                         return "distance";
627                 
628                 case LA_SPOTSI:
629                         return "spot_size";
630                 case LA_SPOTBL:
631                         return "spot_blend";
632                         
633                 case LA_QUAD1:
634                         return "linear_attenuation";
635                 case LA_QUAD2:
636                         return "quadratic_attenuation";
637                         
638                 case LA_HALOINT:
639                         return "halo_intensity";
640                         
641                 default: /* for now, we assume that the others were MTex channels */
642                         return mtex_adrcodes_to_paths(adrcode, array_index);
643         }
644         
645         /* unrecognised adrcode, or not-yet-handled ones! */
646         return NULL;
647 }
648
649 /* Sound Types */
650 static char *sound_adrcodes_to_paths (int adrcode, int *array_index)
651 {
652         /* set array index like this in-case nothing sets it correctly  */
653         *array_index= 0;
654         
655         /* result depends on adrcode */
656         switch (adrcode) {
657                 case SND_VOLUME:
658                         return "volume";
659                 case SND_PITCH:
660                         return "pitch";
661         /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */
662         /*      case SND_PANNING:
663                         return "panning"; */
664                 case SND_ATTEN:
665                         return "attenuation";
666         }
667         
668         /* unrecognised adrcode, or not-yet-handled ones! */
669         return NULL;
670 }
671
672 /* World Types */
673 static char *world_adrcodes_to_paths (int adrcode, int *array_index)
674 {
675         /* set array index like this in-case nothing sets it correctly  */
676         *array_index= 0;
677         
678         /* result depends on adrcode */
679         switch (adrcode) {
680                 case WO_HOR_R:
681                         *array_index= 0; return "horizon_color";
682                 case WO_HOR_G:
683                         *array_index= 1; return "horizon_color";
684                 case WO_HOR_B:
685                         *array_index= 2; return "horizon_color";
686                 case WO_ZEN_R:
687                         *array_index= 0; return "zenith_color";
688                 case WO_ZEN_G:
689                         *array_index= 1; return "zenith_color";
690                 case WO_ZEN_B:
691                         *array_index= 2; return "zenith_color";
692                 
693                 case WO_EXPOS:
694                         return "exposure";
695                 
696                 case WO_MISI:
697                         return "mist.intensity";
698                 case WO_MISTDI:
699                         return "mist.depth";
700                 case WO_MISTSTA:
701                         return "mist.start";
702                 case WO_MISTHI:
703                         return "mist.height";
704                 
705         /*      Star Color is unused -- recommend removal */
706         /*      case WO_STAR_R:
707                         *array_index= 0; return "stars.color";
708                 case WO_STAR_G:
709                         *array_index= 1; return "stars.color";
710                 case WO_STAR_B:
711                         *array_index= 2; return "stars.color"; */
712                 
713                 case WO_STARDIST:
714                         return "stars.min_distance";
715                 case WO_STARSIZE:
716                         return "stars.size";
717                 
718                 default: /* for now, we assume that the others were MTex channels */
719                         return mtex_adrcodes_to_paths(adrcode, array_index);
720                 }
721                 
722         return NULL;    
723 }
724
725 /* Particle Types */
726 static char *particle_adrcodes_to_paths (int adrcode, int *array_index)
727 {
728         /* set array index like this in-case nothing sets it correctly  */
729         *array_index= 0;
730         
731         /* result depends on adrcode */
732         switch (adrcode) {
733                 case PART_CLUMP:
734                         return "settings.clump_factor";
735                 case PART_AVE:
736                         return "settings.angular_velocity_factor";
737                 case PART_SIZE:
738                         return "settings.particle_size";
739                 case PART_DRAG:
740                         return "settings.drag_factor";
741                 case PART_BROWN:
742                         return "settings.brownian_factor";
743                 case PART_DAMP:
744                         return "settings.damp_factor";
745                 case PART_LENGTH:
746                         return "settings.length";
747                 case PART_GRAV_X:
748                         *array_index= 0; return "settings.acceleration";
749                 case PART_GRAV_Y:
750                         *array_index= 1; return "settings.acceleration";
751                 case PART_GRAV_Z:
752                         *array_index= 2; return "settings.acceleration";
753                 case PART_KINK_AMP:
754                         return "settings.kink_amplitude";
755                 case PART_KINK_FREQ:
756                         return "settings.kink_frequency";
757                 case PART_KINK_SHAPE:
758                         return "settings.kink_shape";
759                 case PART_BB_TILT:
760                         return "settings.billboard_tilt";
761                 
762                 /* PartDeflect needs to be sorted out properly in rna_object_force;
763                    If anyone else works on this, but is unfamiliar, these particular
764                         settings reference the particles of the system themselves
765                         being used as forces -- it will use the same rna structure
766                         as the similar object forces                            */
767                 /*case PART_PD_FSTR:
768                         if (part->pd) poin= &(part->pd->f_strength);
769                         break;
770                 case PART_PD_FFALL:
771                         if (part->pd) poin= &(part->pd->f_power);
772                         break;
773                 case PART_PD_FMAXD:
774                         if (part->pd) poin= &(part->pd->maxdist);
775                         break;
776                 case PART_PD2_FSTR:
777                         if (part->pd2) poin= &(part->pd2->f_strength);
778                         break;
779                 case PART_PD2_FFALL:
780                         if (part->pd2) poin= &(part->pd2->f_power);
781                         break;
782                 case PART_PD2_FMAXD:
783                         if (part->pd2) poin= &(part->pd2->maxdist);
784                         break;*/
785
786                 }
787                 
788         return NULL;    
789 }
790
791 /* ------- */
792
793 /* Allocate memory for RNA-path for some property given a blocktype, adrcode, and 'root' parts of path
794  *      Input:
795  *              - blocktype, adrcode    - determines setting to get
796  *              - actname, constname,seq - used to build path
797  *      Output:
798  *              - array_index                   - index in property's array (if applicable) to use
799  *              - return                                - the allocated path...
800  */
801 static char *get_rna_access (int blocktype, int adrcode, char actname[], char constname[], Sequence * seq, int *array_index)
802 {
803         DynStr *path= BLI_dynstr_new();
804         char *propname=NULL, *rpath=NULL;
805         char buf[512];
806         int dummy_index= 0;
807         
808         /* hack: if constname is set, we can only be dealing with an Constraint curve */
809         if (constname)
810                 blocktype= ID_CO;
811         
812         /* get property name based on blocktype */
813         switch (blocktype) {
814                 case ID_OB: /* object */
815                         propname= ob_adrcodes_to_paths(adrcode, &dummy_index);
816                         break;
817                 
818                 case ID_PO: /* pose channel */
819                         propname= pchan_adrcodes_to_paths(adrcode, &dummy_index);
820                         break;
821                         
822                 case ID_KE: /* shapekeys */
823                         propname= shapekey_adrcodes_to_paths(adrcode, &dummy_index);
824                         break;
825                         
826                 case ID_CO: /* constraint */
827                         propname= constraint_adrcodes_to_paths(adrcode, &dummy_index);  
828                         break;
829                         
830                 case ID_TE: /* texture */
831                         propname= texture_adrcodes_to_paths(adrcode, &dummy_index);
832                         break;
833                         
834                 case ID_MA: /* material */
835                         propname= material_adrcodes_to_paths(adrcode, &dummy_index);
836                         break;
837                         
838                 case ID_CA: /* camera */
839                         propname= camera_adrcodes_to_paths(adrcode, &dummy_index);
840                         break;
841                         
842                 case ID_LA: /* lamp */
843                         propname= lamp_adrcodes_to_paths(adrcode, &dummy_index);
844                         break;
845                 
846                 case ID_SO: /* sound */
847                         propname= sound_adrcodes_to_paths(adrcode, &dummy_index);
848                         break;
849                 
850                 case ID_WO: /* world */
851                         propname= world_adrcodes_to_paths(adrcode, &dummy_index);
852                         break;
853                 
854                 case ID_PA: /* particle */
855                         propname= particle_adrcodes_to_paths(adrcode, &dummy_index);
856                         break;
857                         
858                 case ID_CU: /* curve */
859                         /* this used to be a 'dummy' curve which got evaluated on the fly... 
860                          * now we've got real var for this!
861                          */
862                         propname= "eval_time";
863                         break;
864                 
865                 /* XXX problematic blocktypes */                
866                 case ID_SEQ: /* sequencer strip */
867                         //SEQ_FAC1:
868                         switch (adrcode) {
869                         case SEQ_FAC1:
870                                 propname= "effect_fader";
871                                 break;
872                         case SEQ_FAC_SPEED:
873                                 propname= "speed_fader";
874                                 break;
875                         case SEQ_FAC_OPACITY:
876                                 propname= "blend_opacity";
877                                 break;
878                         }
879                         //      poin= &(seq->facf0); // XXX this doesn't seem to be included anywhere in sequencer RNA...
880                         break;
881                         
882                 /* special hacks */
883                 case -1:
884                         /* special case for rotdiff drivers... we don't need a property for this... */
885                         break;
886                         
887                 // TODO... add other blocktypes...
888                 default:
889                         printf("IPO2ANIMATO WARNING: No path for blocktype %d, adrcode %d yet \n", blocktype, adrcode);
890                         break;
891         }
892         
893         /* check if any property found 
894          *      - blocktype < 0 is special case for a specific type of driver, where we don't need a property name...
895          */
896         if ((propname == NULL) && (blocktype > 0)) {
897                 /* nothing was found, so exit */
898                 if (array_index) 
899                         *array_index= 0;
900                         
901                 BLI_dynstr_free(path);
902                 
903                 return NULL;
904         }
905         else {
906                 if (array_index)
907                         *array_index= dummy_index;
908         }
909         
910         /* append preceding bits to path */
911         if ((actname && actname[0]) && (constname && constname[0])) {
912                 /* Constraint in Pose-Channel */
913                 sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
914         }
915         else if (actname && actname[0]) {
916                 /* Pose-Channel */
917                 sprintf(buf, "pose.bones[\"%s\"]", actname);
918         }
919         else if (constname && constname[0]) {
920                 /* Constraint in Object */
921                 sprintf(buf, "constraints[\"%s\"]", constname);
922         }
923         else if (seq) {
924                 /* Sequence names in Scene */
925                 sprintf(buf, "sequence_editor.sequences_all[\"%s\"]", 
926                         seq->name+2);
927         }
928         else
929                 strcpy(buf, ""); /* empty string */
930         BLI_dynstr_append(path, buf);
931         
932         /* need to add dot before property if there was anything precceding this */
933         if (buf[0])
934                 BLI_dynstr_append(path, ".");
935         
936         /* now write name of property */
937         BLI_dynstr_append(path, propname);
938         
939         /* if there was no array index pointer provided, add it to the path */
940         if (array_index == NULL) {
941                 sprintf(buf, "[\"%d\"]", dummy_index);
942                 BLI_dynstr_append(path, buf);
943         }
944         
945         /* convert to normal MEM_malloc'd string */
946         rpath= BLI_dynstr_get_cstring(path);
947         BLI_dynstr_free(path);
948         
949         /* return path... */
950         return rpath;
951 }
952
953 /* *************************************************** */
954 /* Conversion Utilities */
955
956 /* Convert adrcodes to driver target transform channel types */
957 static short adrcode_to_dtar_transchan (short adrcode)
958 {
959         switch (adrcode) {
960                 case OB_LOC_X:  
961                         return DTAR_TRANSCHAN_LOCX;
962                 case OB_LOC_Y:
963                         return DTAR_TRANSCHAN_LOCY;
964                 case OB_LOC_Z:
965                         return DTAR_TRANSCHAN_LOCZ;
966                 
967                 case OB_ROT_X:  
968                         return DTAR_TRANSCHAN_ROTX;
969                 case OB_ROT_Y:
970                         return DTAR_TRANSCHAN_ROTY;
971                 case OB_ROT_Z:
972                         return DTAR_TRANSCHAN_ROTZ;
973                 
974                 case OB_SIZE_X: 
975                         return DTAR_TRANSCHAN_SCALEX;
976                 case OB_SIZE_Y:
977                         return DTAR_TRANSCHAN_SCALEX;
978                 case OB_SIZE_Z:
979                         return DTAR_TRANSCHAN_SCALEX;
980                         
981                 default:
982                         return 0;
983         }
984 }
985
986 /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */
987 static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
988 {
989         ChannelDriver *cdriver;
990         
991         /* allocate memory for new driver */
992         cdriver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
993         
994         /* if 'pydriver', just copy data across */
995         if (idriver->type == IPO_DRIVER_TYPE_PYTHON) {
996                 /* PyDriver only requires the expression to be copied */
997                 // FIXME: expression will be useless due to API changes, but at least not totally lost
998                 cdriver->type = DRIVER_TYPE_PYTHON;
999                 if (idriver->name[0])
1000                         BLI_strncpy(cdriver->expression, idriver->name, sizeof(cdriver->expression));
1001         }
1002         else {
1003                 DriverVar *dvar = NULL;
1004                 DriverTarget *dtar = NULL;
1005                 
1006                 /* this should be ok for all types here... */
1007                 cdriver->type= DRIVER_TYPE_AVERAGE;
1008                 
1009                 /* what to store depends on the 'blocktype' - object or posechannel */
1010                 if (idriver->blocktype == ID_AR) { /* PoseChannel */
1011                         if (idriver->adrcode == OB_ROT_DIFF) {
1012                                 /* Rotational Difference requires a special type of variable */
1013                                 dvar= driver_add_new_variable(cdriver);
1014                                 driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF);
1015                                 
1016                                         /* first bone target */
1017                                 dtar= &dvar->targets[0];
1018                                 dtar->id= (ID *)idriver->ob;
1019                                 if (idriver->name[0])
1020                                         BLI_strncpy(dtar->pchan_name, idriver->name, 32);
1021                                 
1022                                         /* second bone target (name was stored in same var as the first one) */
1023                                 dtar= &dvar->targets[1];
1024                                 dtar->id= (ID *)idriver->ob;
1025                                 if (idriver->name[0]) // xxx... for safety
1026                                         BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, 32);
1027                         }
1028                         else {
1029                                 /* only a single variable, of type 'transform channel' */
1030                                 dvar= driver_add_new_variable(cdriver);
1031                                 driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
1032                                 
1033                                 /* only requires a single target */
1034                                 dtar= &dvar->targets[0];
1035                                 dtar->id= (ID *)idriver->ob;
1036                                 if (idriver->name[0])
1037                                         BLI_strncpy(dtar->pchan_name, idriver->name, 32);
1038                                 dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
1039                                 dtar->flag |= DTAR_FLAG_LOCALSPACE; /* old drivers took local space */
1040                         }
1041                 }
1042                 else { /* Object */
1043                         /* only a single variable, of type 'transform channel' */
1044                         dvar= driver_add_new_variable(cdriver);
1045                         driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
1046                         
1047                                 /* only requires single target */
1048                         dtar= &dvar->targets[0];
1049                         dtar->id= (ID *)idriver->ob;
1050                         dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
1051                 }
1052         }
1053         
1054         /* return the new one */
1055         return cdriver;
1056 }
1057
1058 /* Add F-Curve to the correct list 
1059  *      - grpname is needed to be used as group name where relevant, and is usually derived from actname
1060  */
1061 static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, char *grpname, int muteipo)
1062 {
1063         /* If we're adding to an action, we will have groups to write to... */
1064         if (groups && grpname) {
1065                 /* wrap the pointers given into a dummy action that we pass to the API func
1066                  * and extract the resultant lists...
1067                  */
1068                 bAction tmp_act;
1069                 bActionGroup *agrp= NULL;
1070                 
1071                 /* init the temp action */
1072                 memset(&tmp_act, 0, sizeof(bAction)); // XXX only enable this line if we get errors
1073                 tmp_act.groups.first= groups->first;
1074                 tmp_act.groups.last= groups->last;
1075                 tmp_act.curves.first= list->first;
1076                 tmp_act.curves.last= list->last;
1077                 /* ... xxx, the other vars don't need to be filled in */
1078                 
1079                 /* get the group to use */
1080                 agrp= action_groups_find_named(&tmp_act, grpname);
1081                 if (agrp == NULL) {
1082                         /* no matching group, so add one */
1083                         if (agrp == NULL) {
1084                                 /* Add a new group, and make it active */
1085                                 agrp= MEM_callocN(sizeof(bActionGroup), "bActionGroup");
1086                                 
1087                                 agrp->flag = AGRP_SELECTED;
1088                                 if (muteipo) agrp->flag |= AGRP_MUTED;
1089                                 
1090                                 strncpy(agrp->name, grpname, sizeof(agrp->name));
1091                                 
1092                                 BLI_addtail(&tmp_act.groups, agrp);
1093                                 BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
1094                         }
1095                 }
1096                 
1097                 /* add F-Curve to group */
1098                 /* WARNING: this func should only need to look at the stuff we initialised, if not, things may crash */
1099                 action_groups_add_channel(&tmp_act, agrp, fcu);
1100                 
1101                 if (agrp->flag & AGRP_MUTED) /* flush down */
1102                         fcu->flag |= FCURVE_MUTED;
1103                 
1104                 /* set the output lists based on the ones in the temp action */
1105                 groups->first= tmp_act.groups.first;
1106                 groups->last= tmp_act.groups.last;
1107                 list->first= tmp_act.curves.first;
1108                 list->last= tmp_act.curves.last;
1109         }
1110         else {
1111                 /* simply add the F-Curve to the end of the given list */
1112                 BLI_addtail(list, fcu);
1113         }
1114 }
1115
1116 /* Convert IPO-Curve to F-Curve (including Driver data), and free any of the old data that 
1117  * is not relevant, BUT do not free the IPO-Curve itself...
1118  *      actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to
1119  *      constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to
1120  *      seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to
1121  */
1122 static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *icu, char *actname, char *constname, Sequence * seq, int muteipo)
1123 {
1124         AdrBit2Path *abp;
1125         FCurve *fcu;
1126         unsigned int i=0;
1127         int totbits;
1128         
1129         /* allocate memory for a new F-Curve */
1130         fcu= MEM_callocN(sizeof(FCurve), "FCurve");
1131         
1132         /* convert driver */
1133         if (icu->driver)
1134                 fcu->driver= idriver_to_cdriver(icu->driver);
1135         
1136         /* copy flags */
1137         if (icu->flag & IPO_VISIBLE) fcu->flag |= FCURVE_VISIBLE;
1138         if (icu->flag & IPO_SELECT) fcu->flag |= FCURVE_SELECTED;
1139         if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
1140         if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
1141         if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
1142         if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
1143         
1144         /* set extrapolation */
1145         switch (icu->extrap) {
1146                 case IPO_HORIZ: /* constant extrapolation */
1147                 case IPO_DIR: /* linear extrapolation */
1148                 {
1149                         /* just copy, as the new defines match the old ones... */
1150                         fcu->extend= icu->extrap;
1151                 }
1152                         break;
1153                         
1154                 case IPO_CYCL: /* cyclic extrapolation */
1155                 case IPO_CYCLX: /* cyclic extrapolation + offset */
1156                 {
1157                         /* Add a new FModifier (Cyclic) instead of setting extend value 
1158                          * as that's the new equivilant of that option. 
1159                          */
1160                         FModifier *fcm= add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES);
1161                         FMod_Cycles *data= (FMod_Cycles *)fcm->data;
1162                         
1163                         /* if 'offset' one is in use, set appropriate settings */
1164                         if (icu->extrap == IPO_CYCLX)
1165                                 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC_OFFSET;
1166                         else
1167                                 data->before_mode= data->after_mode= FCM_EXTRAPOLATE_CYCLIC;
1168                 }
1169                         break;
1170         }
1171         
1172         /* -------- */
1173         
1174         /* get adrcode <-> bitflags mapping to handle nasty bitflag curves? */
1175         abp= adrcode_bitmaps_to_paths(icu->blocktype, icu->adrcode, &totbits);
1176         if (abp && totbits) {
1177                 FCurve *fcurve;
1178                 int b;
1179                 
1180                 if (G.f & G_DEBUG) printf("\tconvert bitflag ipocurve, totbits = %d \n", totbits);
1181                 
1182                 /* add the 'only int values' flag */
1183                 fcu->flag |= (FCURVE_INT_VALUES|FCURVE_DISCRETE_VALUES);                
1184                 
1185                 /* for each bit we have to remap + check for:
1186                  * 1) we need to make copy the existing F-Curve data (fcu -> fcurve),
1187                  *        except for the last one which will use the original 
1188                  * 2) copy the relevant path info across
1189                  * 3) filter the keyframes for the flag of interest
1190                  */
1191                 for (b=0; b < totbits; b++, abp++) {
1192                         /* make a copy of existing base-data if not the last curve */
1193                         if (b < (totbits-1))
1194                                 fcurve= copy_fcurve(fcu);
1195                         else
1196                                 fcurve= fcu;
1197                                 
1198                         /* set path */
1199                         fcurve->rna_path= BLI_strdupn(abp->path, strlen(abp->path));
1200                         fcurve->array_index= abp->array_index;
1201                         
1202                         /* convert keyframes 
1203                          *      - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
1204                          *      - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
1205                          */
1206                         fcurve->totvert= icu->totvert;
1207                         
1208                         if (icu->bezt) {
1209                                 BezTriple *dst, *src;
1210                                 
1211                                 /* allocate new array for keyframes/beztriples */
1212                                 fcurve->bezt= MEM_callocN(sizeof(BezTriple)*fcurve->totvert, "BezTriples");
1213                                 
1214                                 /* loop through copying all BezTriples individually, as we need to modify a few things */
1215                                 for (dst=fcurve->bezt, src=icu->bezt; i < fcurve->totvert; i++, dst++, src++) {
1216                                         /* firstly, copy BezTriple data */
1217                                         *dst= *src;
1218                                         
1219                                         /* interpolation can only be constant... */
1220                                         dst->ipo= BEZT_IPO_CONST;
1221                                         
1222                                         /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
1223                                         dst->hide= BEZT_KEYTYPE_KEYFRAME;
1224                                         
1225                                         /* correct values, by checking if the flag of interest is set */
1226                                         if ( ((int)(dst->vec[1][1])) & (abp->bit) )
1227                                                 dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f;
1228                                         else
1229                                                 dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 0.0f;
1230                                 }
1231                         }
1232                         else if (icu->bp) {
1233                                 /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */
1234                                 //BPoint *bp;
1235                                 //FPoint *fpt;
1236                         }
1237                         
1238                         /* add new F-Curve to list */
1239                         fcurve_add_to_list(groups, list, fcurve, actname, muteipo);
1240                 }
1241         }
1242         else {
1243                 /* get rna-path
1244                  *      - we will need to set the 'disabled' flag if no path is able to be made (for now)
1245                  */
1246                 fcu->rna_path= get_rna_access(icu->blocktype, icu->adrcode, actname, constname, seq, &fcu->array_index);
1247                 if (fcu->rna_path == NULL)
1248                         fcu->flag |= FCURVE_DISABLED;
1249                 
1250                 /* convert keyframes 
1251                  *      - beztriples and bpoints are mutually exclusive, so we won't have both at the same time
1252                  *      - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet)
1253                  */
1254                 fcu->totvert= icu->totvert;
1255                 
1256                 if (icu->bezt) {
1257                         BezTriple *dst, *src;
1258                         
1259                         /* allocate new array for keyframes/beztriples */
1260                         fcu->bezt= MEM_callocN(sizeof(BezTriple)*fcu->totvert, "BezTriples");
1261                         
1262                         /* loop through copying all BezTriples individually, as we need to modify a few things */
1263                         for (dst=fcu->bezt, src=icu->bezt; i < fcu->totvert; i++, dst++, src++) {
1264                                 /* firstly, copy BezTriple data */
1265                                 *dst= *src;
1266                                 
1267                                 /* now copy interpolation from curve (if not already set) */
1268                                 if (icu->ipo != IPO_MIXED)
1269                                         dst->ipo= icu->ipo;
1270                                         
1271                                 /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
1272                                 dst->hide= BEZT_KEYTYPE_KEYFRAME;
1273                                         
1274                                 /* correct values for euler rotation curves 
1275                                  *      - they were degrees/10 
1276                                  *      - we need radians for RNA to do the right thing
1277                                  */
1278                                 if ( ((icu->blocktype == ID_OB) && ELEM3(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) ||
1279                                          ((icu->blocktype == ID_PO) && ELEM3(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z)) )
1280                                 {
1281                                         const float fac= (float)M_PI / 18.0f; //10.0f * M_PI/180.0f;
1282                                         
1283                                         dst->vec[0][1] *= fac;
1284                                         dst->vec[1][1] *= fac;
1285                                         dst->vec[2][1] *= fac;
1286                                 }
1287                                 
1288                                 /* correct values for path speed curves 
1289                                  *      - their values were 0-1
1290                                  *      - we now need as 'frames'
1291                                  */
1292                                 if ( (id) && (icu->blocktype == GS(id->name)) && 
1293                                          (fcu->rna_path && strcmp(fcu->rna_path, "eval_time")==0) )
1294                                 {
1295                                         Curve *cu = (Curve *)id;
1296                                         
1297                                         dst->vec[0][1] *= cu->pathlen;
1298                                         dst->vec[1][1] *= cu->pathlen;
1299                                         dst->vec[2][1] *= cu->pathlen;
1300                                 }
1301                                 
1302                                 /* correct times for rotation drivers 
1303                                  *      - need to go from degrees to radians...
1304                                  *      - there's only really 1 target to worry about 
1305                                  *  - were also degrees/10
1306                                  */
1307                                 if (fcu->driver && fcu->driver->variables.first) {
1308                                         DriverVar *dvar= fcu->driver->variables.first;
1309                                         DriverTarget *dtar= &dvar->targets[0];
1310                                         
1311                                         if (ELEM3(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) {
1312                                                 const float fac= (float)M_PI / 18.0f;
1313                                                 
1314                                                 dst->vec[0][0] *= fac;
1315                                                 dst->vec[1][0] *= fac;
1316                                                 dst->vec[2][0] *= fac;
1317                                         }
1318                                 }
1319                                 
1320                                 /* correct values for sequencer curves,
1321                                    that were not locked to frame */
1322
1323                                 if (seq && 
1324                                     (seq->flag & SEQ_IPO_FRAME_LOCKED) == 0) {
1325                                         double mul= (seq->enddisp-seq->startdisp)/100.0f;
1326                                         double offset= seq->startdisp;
1327                                         
1328                                         dst->vec[0][0] *= mul;
1329                                         dst->vec[0][0] += offset;
1330
1331                                         dst->vec[1][0] *= mul;
1332                                         dst->vec[1][0] += offset;
1333
1334                                         dst->vec[2][0] *= mul;
1335                                         dst->vec[2][0] += offset;
1336                                 }
1337                         }
1338                 }
1339                 else if (icu->bp) {
1340                         /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */
1341                         //BPoint *bp;
1342                         //FPoint *fpt;
1343                 }
1344                 
1345                 /* add new F-Curve to list */
1346                 fcurve_add_to_list(groups, list, fcu, actname, muteipo);
1347         }
1348 }
1349
1350 /* ------------------------- */
1351
1352 /* Convert IPO-block (i.e. all its IpoCurves) to the new system.
1353  * This does not assume that any ID or AnimData uses it, but does assume that
1354  * it is given two lists, which it will perform driver/animation-data separation.
1355  */
1356 static void ipo_to_animato (ID *id, Ipo *ipo, char actname[], char constname[], Sequence * seq, ListBase *animgroups, ListBase *anim, ListBase *drivers)
1357 {
1358         IpoCurve *icu;
1359         
1360         /* sanity check */
1361         if (ELEM3(NULL, ipo, anim, drivers))
1362                 return;
1363                 
1364         if (G.f & G_DEBUG) printf("ipo_to_animato \n");
1365                 
1366         /* validate actname and constname 
1367          *      - clear actname if it was one of the generic <builtin> ones (i.e. 'Object', or 'Shapes')
1368          *      - actname can then be used to assign F-Curves in Action to Action Groups 
1369          *        (i.e. thus keeping the benefits that used to be provided by Action Channels for grouping
1370          *              F-Curves for bones). This may be added later... for now let's just dump without them...
1371          */
1372         if (actname) {
1373                 if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Object") == 0))
1374                         actname= NULL;
1375                 else if ((ipo->blocktype == ID_OB) && (strcmp(actname, "Shape") == 0))
1376                         actname= NULL;
1377         }
1378         
1379         /* loop over IPO-Curves, freeing as we progress */
1380         for (icu= ipo->curve.first; icu; icu= icu->next) {
1381                 /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves), 
1382                  * we figure out the best place to put the channel, then tell the curve-converter to just dump there
1383                  */
1384                 if (icu->driver) {
1385                         /* Blender 2.4x allowed empty drivers, but we don't now, since they cause more trouble than they're worth */
1386                         if ((icu->driver->ob) || (icu->driver->type == IPO_DRIVER_TYPE_PYTHON)) {
1387                                 icu_to_fcurves(id, NULL, drivers, icu, actname, constname, seq, ipo->muteipo);
1388                         }
1389                         else {
1390                                 MEM_freeN(icu->driver);
1391                                 icu->driver= NULL;
1392                         }
1393                 }
1394                 else
1395                         icu_to_fcurves(id, animgroups, anim, icu, actname, constname, seq, ipo->muteipo);
1396         }
1397         
1398         /* if this IPO block doesn't have any users after this one, free... */
1399         ipo->id.us--;
1400         if ( (ipo->id.us == 0) || ((ipo->id.us == 1) && (ipo->id.flag & LIB_FAKEUSER)) ) 
1401         {
1402                 IpoCurve *icn;
1403                 
1404                 for (icu= ipo->curve.first; icu; icu= icn) {
1405                         icn= icu->next;
1406                         
1407                         /* free driver */
1408                         if (icu->driver)
1409                                 MEM_freeN(icu->driver);
1410                                 
1411                         /* free old data of curve now that it's no longer needed for converting any more curves */
1412                         if (icu->bezt) MEM_freeN(icu->bezt);
1413                         if (icu->bp) MEM_freeN(icu->bezt);
1414                         
1415                         /* free this IPO-Curve */
1416                         BLI_freelinkN(&ipo->curve, icu);
1417                 }
1418         }
1419 }
1420
1421 /* Convert Action-block to new system, separating animation and drivers
1422  * New curves may not be converted directly into the given Action (i.e. for Actions linked
1423  * to Objects, where ob->ipo and ob->action need to be combined).
1424  * NOTE: we need to be careful here, as same data-structs are used for new system too!
1425  */
1426 static void action_to_animato (ID *id, bAction *act, ListBase *groups, ListBase *curves, ListBase *drivers)
1427 {
1428         bActionChannel *achan, *achann;
1429         bConstraintChannel *conchan, *conchann;
1430         
1431         /* only continue if there are Action Channels (indicating unconverted data) */
1432         if (act->chanbase.first == NULL)
1433                 return;
1434                 
1435         /* get rid of all Action Groups */
1436         // XXX this is risky if there's some old + some new data in the Action...
1437         if (act->groups.first) 
1438                 BLI_freelistN(&act->groups);
1439         
1440         /* loop through Action-Channels, converting data, freeing as we go */
1441         for (achan= act->chanbase.first; achan; achan= achann) {
1442                 /* get pointer to next Action Channel */
1443                 achann= achan->next;
1444                 
1445                 /* convert Action Channel's IPO data */
1446                 if (achan->ipo) {
1447                         ipo_to_animato(id, achan->ipo, achan->name, NULL, NULL, groups, curves, drivers);
1448                         achan->ipo->id.us--;
1449                         achan->ipo= NULL;
1450                 }
1451                 
1452                 /* convert constraint channel IPO-data */
1453                 for (conchan= achan->constraintChannels.first; conchan; conchan= conchann) {
1454                         /* get pointer to next Constraint Channel */
1455                         conchann= conchan->next;
1456                         
1457                         /* convert Constraint Channel's IPO data */
1458                         if (conchan->ipo) {
1459                                 ipo_to_animato(id, conchan->ipo, achan->name, conchan->name, NULL, groups, curves, drivers);
1460                                 conchan->ipo->id.us--;
1461                                 conchan->ipo= NULL;
1462                         }
1463                         
1464                         /* free Constraint Channel */
1465                         BLI_freelinkN(&achan->constraintChannels, conchan);
1466                 }
1467                 
1468                 /* free Action Channel */
1469                 BLI_freelinkN(&act->chanbase, achan);
1470         }
1471 }
1472
1473
1474 /* ------------------------- */
1475
1476 /* Convert IPO-block (i.e. all its IpoCurves) for some ID to the new system
1477  * This assumes that AnimData has been added already. Separation of drivers
1478  * from animation data is accomplished here too...
1479  */
1480 static void ipo_to_animdata (ID *id, Ipo *ipo, char actname[], char constname[], Sequence * seq)
1481 {
1482         AnimData *adt= BKE_animdata_from_id(id);
1483         ListBase anim = {NULL, NULL};
1484         ListBase drivers = {NULL, NULL};
1485         
1486         /* sanity check */
1487         if ELEM(NULL, id, ipo)
1488                 return;
1489         if (adt == NULL) {
1490                 printf("ERROR ipo_to_animdata(): adt invalid \n");
1491                 return;
1492         }
1493         
1494         if (G.f & G_DEBUG) {
1495                 printf("ipo to animdata - ID:%s, IPO:%s, actname:%s constname:%s seqname:%s  curves:%d \n", 
1496                        id->name+2, ipo->id.name+2, (actname)?actname:"<None>", (constname)?constname:"<None>", (seq)?(seq->name+2):"<None>",
1497                         BLI_countlist(&ipo->curve));
1498         }
1499         
1500         /* Convert curves to animato system (separated into separate lists of F-Curves for animation and drivers),
1501          * and the try to put these lists in the right places, but do not free the lists here
1502          */
1503         // XXX there shouldn't be any need for the groups, so don't supply pointer for that now... 
1504         ipo_to_animato(id, ipo, actname, constname, seq, NULL, &anim, &drivers);
1505         
1506         /* deal with animation first */
1507         if (anim.first) {
1508                 if (G.f & G_DEBUG) printf("\thas anim \n");
1509                 /* try to get action */
1510                 if (adt->action == NULL) {
1511                         adt->action= add_empty_action("ConvData_Action"); // XXX we need a better name for this
1512                         if (G.f & G_DEBUG) printf("\t\tadded new action \n");
1513                 }
1514                 
1515                 /* add F-Curves to action */
1516                 addlisttolist(&adt->action->curves, &anim);
1517         }
1518         
1519         /* deal with drivers */
1520         if (drivers.first) {
1521                 if (G.f & G_DEBUG) printf("\thas drivers \n");
1522                 /* add drivers to end of driver stack */
1523                 addlisttolist(&adt->drivers, &drivers);
1524         }
1525 }
1526
1527 /* Convert Action-block to new system
1528  * NOTE: we need to be careful here, as same data-structs are used for new system too!
1529  */
1530 static void action_to_animdata (ID *id, bAction *act)
1531 {
1532         AnimData *adt= BKE_animdata_from_id(id);
1533         
1534         /* only continue if there are Action Channels (indicating unconverted data) */
1535         if (ELEM(NULL, adt, act->chanbase.first))
1536                 return;
1537         
1538         /* check if we need to set this Action as the AnimData's action */
1539         if (adt->action == NULL) {
1540                 /* set this Action as AnimData's Action */
1541                 if (G.f & G_DEBUG) printf("act_to_adt - set adt action to act \n");
1542                 adt->action= act;
1543         }
1544         
1545         /* convert Action data */
1546         action_to_animato(id, act, &adt->action->groups, &adt->action->curves, &adt->drivers);
1547 }
1548
1549 /* ------------------------- */
1550
1551 // TODO:
1552 //      - NLA group duplicators info
1553 //      - NLA curve/stride modifiers...
1554
1555 /* Convert NLA-Strip to new system */
1556 static void nlastrips_to_animdata (ID *id, ListBase *strips)
1557 {
1558         AnimData *adt= BKE_animdata_from_id(id);
1559         NlaTrack *nlt = NULL;
1560         NlaStrip *strip;
1561         bActionStrip *as, *asn;
1562         
1563         /* for each one of the original strips, convert to a new strip and free the old... */
1564         for (as= strips->first; as; as= asn) {
1565                 asn= as->next;
1566                 
1567                 /* this old strip is only worth something if it had an action... */
1568                 if (as->act) {
1569                         /* convert Action data (if not yet converted), storing the results in the same Action */
1570                         action_to_animato(id, as->act, &as->act->groups, &as->act->curves, &adt->drivers);
1571                         
1572                         /* create a new-style NLA-strip which references this Action, then copy over relevant settings */
1573                         {
1574                                 /* init a new strip, and assign the action to it 
1575                                  *      - no need to muck around with the user-counts, since this is just 
1576                                  *        passing over the ref to the new owner, not creating an additional ref
1577                                  */
1578                                 strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip");
1579                                 strip->act= as->act;
1580                                 
1581                                         /* endpoints */
1582                                 strip->start= as->start;
1583                                 strip->end= as->end;
1584                                 strip->actstart= as->actstart;
1585                                 strip->actend= as->actend;
1586                                 
1587                                         /* action reuse */
1588                                 strip->repeat= as->repeat;
1589                                 strip->scale= as->scale;
1590                                 if (as->flag & ACTSTRIP_LOCK_ACTION)    strip->flag |= NLASTRIP_FLAG_SYNC_LENGTH;
1591                                 
1592                                         /* blending */
1593                                 strip->blendin= as->blendin;
1594                                 strip->blendout= as->blendout;
1595                                 strip->blendmode= (as->mode==ACTSTRIPMODE_ADD) ? NLASTRIP_MODE_ADD : NLASTRIP_MODE_REPLACE;
1596                                 if (as->flag & ACTSTRIP_AUTO_BLENDS)    strip->flag |= NLASTRIP_FLAG_AUTO_BLENDS;
1597                                         
1598                                         /* assorted setting flags */
1599                                 if (as->flag & ACTSTRIP_SELECT)                 strip->flag |= NLASTRIP_FLAG_SELECT;
1600                                 if (as->flag & ACTSTRIP_ACTIVE)                 strip->flag |= NLASTRIP_FLAG_ACTIVE;
1601                                 
1602                                 if (as->flag & ACTSTRIP_MUTE)                   strip->flag |= NLASTRIP_FLAG_MUTED;
1603                                 if (as->flag & ACTSTRIP_REVERSE)                strip->flag |= NLASTRIP_FLAG_REVERSE;
1604                                 
1605                                         /* by default, we now always extrapolate, while in the past this was optional */
1606                                 if ((as->flag & ACTSTRIP_HOLDLASTFRAME)==0) 
1607                                         strip->extendmode= NLASTRIP_EXTEND_NOTHING;
1608                         }       
1609                         
1610                         /* try to add this strip to the current NLA-Track (i.e. the 'last' one on the stack atm) */
1611                         if (BKE_nlatrack_add_strip(nlt, strip) == 0) {
1612                                 /* trying to add to the current failed (no space), 
1613                                  * so add a new track to the stack, and add to that...
1614                                  */
1615                                 nlt= add_nlatrack(adt, NULL);
1616                                 BKE_nlatrack_add_strip(nlt, strip);
1617                         }
1618                 }
1619                 
1620                 /* modifiers */
1621                 // FIXME: for now, we just free them...
1622                 if (as->modifiers.first)
1623                         BLI_freelistN(&as->modifiers);
1624                 
1625                 /* free the old strip */
1626                 BLI_freelinkN(strips, as);
1627         }
1628 }
1629
1630 /* *************************************************** */
1631 /* External API - Only Called from do_versions() */
1632
1633 /* Called from do_versions() in readfile.c to convert the old 'IPO/adrcode' system
1634  * to the new 'Animato/RNA' system.
1635  *
1636  * The basic method used here, is to loop over datablocks which have IPO-data, and 
1637  * add those IPO's to new AnimData blocks as Actions. 
1638  * Action/NLA data only works well for Objects, so these only need to be checked for there.
1639  *  
1640  * Data that has been converted should be freed immediately, which means that it is immediately
1641  * clear which datablocks have yet to be converted, and also prevent freeing errors when we exit.
1642  */
1643 // XXX currently done after all file reading... 
1644 void do_versions_ipos_to_animato(Main *main)
1645 {
1646         ListBase drivers = {NULL, NULL};
1647         ID *id;
1648         AnimData *adt;
1649         
1650         if (main == NULL) {
1651                 printf("Argh! Main is NULL in do_versions_ipos_to_animato() \n");
1652                 return;
1653         }
1654                 
1655         /* only convert if version is right */
1656         if (main->versionfile >= 250) {
1657                 printf("WARNING: Animation data too new to convert (Version %d) \n", main->versionfile);
1658                 return;
1659         }
1660         else if (G.f & G_DEBUG)
1661                 printf("INFO: Converting to Animato... \n");
1662                 
1663         /* ----------- Animation Attached to Data -------------- */
1664         
1665         /* objects */
1666         for (id= main->object.first; id; id= id->next) {
1667                 Object *ob= (Object *)id;
1668                 bPoseChannel *pchan;
1669                 bConstraint *con;
1670                 bConstraintChannel *conchan, *conchann;
1671                 
1672                 if (G.f & G_DEBUG) printf("\tconverting ob %s \n", id->name+2);
1673                 
1674                 /* check if object has any animation data */
1675                 if (ob->nlastrips.first) {
1676                         /* Add AnimData block */
1677                         adt= BKE_id_add_animdata(id);
1678                         
1679                         /* IPO first to take into any non-NLA'd Object Animation */
1680                         if (ob->ipo) {
1681                                 ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
1682                                 
1683                                 ob->ipo->id.us--;
1684                                 ob->ipo= NULL;
1685                         }
1686                         
1687                         /* Action is skipped since it'll be used by some strip in the NLA anyway, 
1688                          * causing errors with evaluation in the new evaluation pipeline
1689                          */
1690                         if (ob->action) {
1691                                 ob->action->id.us--;
1692                                 ob->action= NULL;
1693                         }
1694                         
1695                         /* finally NLA */
1696                         nlastrips_to_animdata(id, &ob->nlastrips);
1697                 }
1698                 else if ((ob->ipo) || (ob->action)) {
1699                         /* Add AnimData block */
1700                         adt= BKE_id_add_animdata(id);
1701                         
1702                         /* Action first - so that Action name get conserved */
1703                         if (ob->action) {
1704                                 action_to_animdata(id, ob->action);
1705                                 
1706                                 /* only decrease usercount if this Action isn't now being used by AnimData */
1707                                 if (ob->action != adt->action) {
1708                                         ob->action->id.us--;
1709                                         ob->action= NULL;
1710                                 }
1711                         }
1712                         
1713                         /* IPO second... */
1714                         if (ob->ipo) {
1715                                 ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
1716                                 ob->ipo->id.us--;
1717                                 ob->ipo= NULL;
1718                         }
1719                 }
1720                 
1721                 /* check PoseChannels for constraints with local data */
1722                 if (ob->pose) {
1723                         /* Verify if there's AnimData block */
1724                         BKE_id_add_animdata(id);
1725                         
1726                         for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1727                                 for (con= pchan->constraints.first; con; con= con->next) {
1728                                         /* if constraint has own IPO, convert add these to Object 
1729                                          * (NOTE: they're most likely to be drivers too) 
1730                                          */
1731                                         if (con->ipo) {
1732                                                 /* although this was the constraint's local IPO, we still need to provide pchan + con 
1733                                                  * so that drivers can be added properly...
1734                                                  */
1735                                                 ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL);
1736                                                 con->ipo->id.us--;
1737                                                 con->ipo= NULL;
1738                                         }
1739                                 }
1740                         }
1741                 }
1742                 
1743                 /* check constraints for local IPO's */
1744                 for (con= ob->constraints.first; con; con= con->next) {
1745                         /* if constraint has own IPO, convert add these to Object 
1746                          * (NOTE: they're most likely to be drivers too) 
1747                          */
1748                         if (con->ipo) {
1749                                 /* Verify if there's AnimData block, just in case */
1750                                 BKE_id_add_animdata(id);
1751                                 
1752                                 /* although this was the constraint's local IPO, we still need to provide con 
1753                                  * so that drivers can be added properly...
1754                                  */
1755                                 ipo_to_animdata(id, con->ipo, NULL, con->name, NULL);
1756                                 con->ipo->id.us--;
1757                                 con->ipo= NULL;
1758                         }
1759                          
1760                         /* check for Action Constraint */
1761                         // XXX do we really want to do this here?
1762                 }
1763                 
1764                 /* check constraint channels - we need to remove them anyway... */
1765                 if (ob->constraintChannels.first) {
1766                         /* Verify if there's AnimData block */
1767                         BKE_id_add_animdata(id);
1768                         
1769                         for (conchan= ob->constraintChannels.first; conchan; conchan= conchann) {
1770                                 /* get pointer to next Constraint Channel */
1771                                 conchann= conchan->next;
1772                                 
1773                                 /* convert Constraint Channel's IPO data */
1774                                 if (conchan->ipo) {
1775                                         ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL);
1776                                         conchan->ipo->id.us--;
1777                                         conchan->ipo= NULL;
1778                                 }
1779                                 
1780                                 /* free Constraint Channel */
1781                                 BLI_freelinkN(&ob->constraintChannels, conchan);
1782                         }
1783                 }
1784         }
1785         
1786         /* shapekeys */
1787         for (id= main->key.first; id; id= id->next) {
1788                 Key *key= (Key *)id;
1789                 
1790                 if (G.f & G_DEBUG) printf("\tconverting key %s \n", id->name+2);
1791                 
1792                 /* we're only interested in the IPO 
1793                  * NOTE: for later, it might be good to port these over to Object instead, as many of these
1794                  * are likely to be drivers, but it's hard to trace that from here, so move this to Ob loop?
1795                  */
1796                 if (key->ipo) {
1797                         /* Add AnimData block */
1798                         adt= BKE_id_add_animdata(id);
1799                         
1800                         /* Convert Shapekey data... */
1801                         ipo_to_animdata(id, key->ipo, NULL, NULL, NULL);
1802                         key->ipo->id.us--;
1803                         key->ipo= NULL;
1804                 }
1805         }
1806         
1807         /* materials */
1808         for (id= main->mat.first; id; id= id->next) {
1809                 Material *ma= (Material *)id;
1810                 
1811                 if (G.f & G_DEBUG) printf("\tconverting material %s \n", id->name+2);
1812                 
1813                 /* we're only interested in the IPO */
1814                 if (ma->ipo) {
1815                         /* Add AnimData block */
1816                         adt= BKE_id_add_animdata(id);
1817                         
1818                         /* Convert Material data... */
1819                         ipo_to_animdata(id, ma->ipo, NULL, NULL, NULL);
1820                         ma->ipo->id.us--;
1821                         ma->ipo= NULL;
1822                 }
1823         }
1824         
1825         /* worlds */
1826         for (id= main->world.first; id; id= id->next) {
1827                 World *wo= (World *)id;
1828                 
1829                 if (G.f & G_DEBUG) printf("\tconverting world %s \n", id->name+2);
1830                 
1831                 /* we're only interested in the IPO */
1832                 if (wo->ipo) {
1833                         /* Add AnimData block */
1834                         adt= BKE_id_add_animdata(id);
1835                         
1836                         /* Convert World data... */
1837                         ipo_to_animdata(id, wo->ipo, NULL, NULL, NULL);
1838                         wo->ipo->id.us--;
1839                         wo->ipo= NULL;
1840                 }
1841         }
1842         
1843         /* sequence strips */
1844         for (id= main->scene.first; id; id= id->next) {
1845                 Scene *scene = (Scene *)id;
1846                 Editing * ed = scene->ed;
1847                 if (ed && ed->seqbasep) {
1848                         Sequence * seq;
1849                         
1850                         adt= BKE_id_add_animdata(id);
1851                         
1852                         SEQ_BEGIN(ed, seq) {
1853                                 IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL;
1854                                 short adrcode = SEQ_FAC1;
1855                                 
1856                                 if (G.f & G_DEBUG) 
1857                                         printf("\tconverting sequence strip %s \n", seq->name+2);
1858                                 
1859                                 if (ELEM(NULL, seq->ipo, icu)) {
1860                                         seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE;
1861                                         continue;
1862                                 }
1863                                 
1864                                 /* patch adrcode, so that we can map
1865                                    to different DNA variables later 
1866                                    (semi-hack (tm) )
1867                                 */
1868                                 switch(seq->type) {
1869                                         case SEQ_IMAGE:
1870                                         case SEQ_META:
1871                                         case SEQ_SCENE:
1872                                         case SEQ_MOVIE:
1873                                         case SEQ_COLOR:
1874                                                 adrcode = SEQ_FAC_OPACITY;
1875                                                 break;
1876                                         case SEQ_SPEED:
1877                                                 adrcode = SEQ_FAC_SPEED;
1878                                                 break;
1879                                 }
1880                                 icu->adrcode = adrcode;
1881                                 
1882                                 /* convert IPO */
1883                                 ipo_to_animdata((ID *)scene, seq->ipo, NULL, NULL, seq);
1884                                 seq->ipo->id.us--;
1885                                 seq->ipo = NULL;
1886                         }
1887                         SEQ_END
1888                 }
1889         }
1890
1891
1892         /* textures */
1893         for (id= main->tex.first; id; id= id->next) {
1894                 Tex *te= (Tex *)id;
1895                 
1896                 if (G.f & G_DEBUG) printf("\tconverting texture %s \n", id->name+2);
1897                 
1898                 /* we're only interested in the IPO */
1899                 if (te->ipo) {
1900                         /* Add AnimData block */
1901                         adt= BKE_id_add_animdata(id);
1902                         
1903                         /* Convert Texture data... */
1904                         ipo_to_animdata(id, te->ipo, NULL, NULL, NULL);
1905                         te->ipo->id.us--;
1906                         te->ipo= NULL;
1907                 }
1908         }
1909         
1910         /* cameras */
1911         for (id= main->camera.first; id; id= id->next) {
1912                 Camera *ca= (Camera *)id;
1913                 
1914                 if (G.f & G_DEBUG) printf("\tconverting camera %s \n", id->name+2);
1915                 
1916                 /* we're only interested in the IPO */
1917                 if (ca->ipo) {
1918                         /* Add AnimData block */
1919                         adt= BKE_id_add_animdata(id);
1920                         
1921                         /* Convert Camera data... */
1922                         ipo_to_animdata(id, ca->ipo, NULL, NULL, NULL);
1923                         ca->ipo->id.us--;
1924                         ca->ipo= NULL;
1925                 }
1926         }
1927         
1928         /* lamps */
1929         for (id= main->lamp.first; id; id= id->next) {
1930                 Lamp *la= (Lamp *)id;
1931                 
1932                 if (G.f & G_DEBUG) printf("\tconverting lamp %s \n", id->name+2);
1933                 
1934                 /* we're only interested in the IPO */
1935                 if (la->ipo) {
1936                         /* Add AnimData block */
1937                         adt= BKE_id_add_animdata(id);
1938                         
1939                         /* Convert Lamp data... */
1940                         ipo_to_animdata(id, la->ipo, NULL, NULL, NULL);
1941                         la->ipo->id.us--;
1942                         la->ipo= NULL;
1943                 }
1944         }
1945         
1946         /* curves */
1947         for (id= main->curve.first; id; id= id->next) {
1948                 Curve *cu= (Curve *)id;
1949                 
1950                 if (G.f & G_DEBUG) printf("\tconverting curve %s \n", id->name+2);
1951                 
1952                 /* we're only interested in the IPO */
1953                 if (cu->ipo) {
1954                         /* Add AnimData block */
1955                         adt= BKE_id_add_animdata(id);
1956                         
1957                         /* Convert Curve data... */
1958                         ipo_to_animdata(id, cu->ipo, NULL, NULL, NULL);
1959                         cu->ipo->id.us--;
1960                         cu->ipo= NULL;
1961                 }
1962         }
1963         
1964         /* --------- Unconverted Animation Data ------------------ */
1965         /* For Animation data which may not be directly connected (i.e. not linked) to any other 
1966          * data, we need to perform a separate pass to make sure that they are converted to standalone
1967          * Actions which may then be able to be reused. This does mean that we will be going over data that's
1968          * already been converted, but there are no problems with that.
1969          *
1970          * The most common case for this will be Action Constraints, or IPO's with Fake-Users. 
1971          * We collect all drivers that were found into a temporary collection, and free them in one go, as they're 
1972          * impossible to resolve.
1973          */
1974         
1975         /* actions */
1976         for (id= main->action.first; id; id= id->next) {
1977                 bAction *act= (bAction *)id;
1978                 
1979                 if (G.f & G_DEBUG) printf("\tconverting action %s \n", id->name+2);
1980                 
1981                 /* be careful! some of the actions we encounter will be converted ones... */
1982                 action_to_animato(NULL, act, &act->groups, &act->curves, &drivers);
1983         }
1984         
1985         /* ipo's */
1986         for (id= main->ipo.first; id; id= id->next) {
1987                 Ipo *ipo= (Ipo *)id;
1988                 
1989                 if (G.f & G_DEBUG) printf("\tconverting ipo %s \n", id->name+2);
1990                 
1991                 /* most likely this IPO has already been processed, so check if any curves left to convert */
1992                 if (ipo->curve.first) {
1993                         bAction *new_act;
1994                         
1995                         /* add a new action for this, and convert all data into that action */
1996                         new_act= add_empty_action("ConvIPO_Action"); // XXX need a better name...
1997                         ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers);
1998                 }
1999                 
2000                 /* clear fake-users, and set user-count to zero to make sure it is cleared on file-save */
2001                 ipo->id.us= 0;
2002                 ipo->id.flag &= ~LIB_FAKEUSER;
2003         }
2004         
2005         /* free unused drivers from actions + ipos */
2006         free_fcurves(&drivers);
2007         
2008         if (G.f & G_DEBUG)
2009                 printf("INFO: Animato convert done \n");
2010 }
2011