Merging r39717 through r39983 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 8cd2bdeb0b94a93fad022e87b1ad4530d39e2c42..b1e5f63e641efcd146ef833fe46b71b967f195fd 100644 (file)
@@ -85,6 +85,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_smoke_types.h"
+#include "DNA_speaker_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_space_types.h"
 #include "DNA_vfont_types.h"
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_sound.h"
 
+#include "NOD_socket.h"
+
 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event codes
 //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
 //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@@ -2093,10 +2096,21 @@ static void lib_link_nodetree(FileData *fd, Main *main)
        }
 }
 
+static void lib_nodetree_init_types_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       bNode *node;
+       
+       ntreeInitTypes(ntree);
+       
+       /* XXX could be replaced by do_versions for new nodes */
+       for (node=ntree->nodes.first; node; node=node->next)
+               node_verify_socket_templates(ntree, node);
+}
+
 /* updates group node socket own_index so that
  * external links to/from the group node are preserved.
  */
-static void lib_node_do_versions_group(bNode *gnode)
+static void lib_node_do_versions_group_indices(bNode *gnode)
 {
        bNodeTree *ngroup= (bNodeTree*)gnode->id;
        bNode *intnode;
@@ -2129,92 +2143,101 @@ static void lib_node_do_versions_group(bNode *gnode)
 }
 
 /* updates external links for all group nodes in a tree */
-static void lib_nodetree_do_versions_group(bNodeTree *ntree)
+static void lib_nodetree_do_versions_group_indices_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
 {
        bNode *node;
        
        for (node=ntree->nodes.first; node; node=node->next) {
                if (node->type==NODE_GROUP) {
                        bNodeTree *ngroup= (bNodeTree*)node->id;
-                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS))
-                               lib_node_do_versions_group(node);
+                       if (ngroup && (ngroup->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE))
+                               lib_node_do_versions_group_indices(node);
                }
        }
 }
 
+/* make an update call for the tree */
+static void lib_nodetree_do_versions_update_cb(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       if (ntree->update)
+               ntreeUpdateTree(ntree);
+}
+
 /* verify types for nodes and groups, all data has to be read */
 /* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
 * typedefs*/
 static void lib_verify_nodetree(Main *main, int UNUSED(open))
 {
-       Scene *sce;
-       Material *ma;
-       Tex *tx;
        bNodeTree *ntree;
-       
+       int i;
+       bNodeTreeType *ntreetype;
+
        /* this crashes blender on undo/redo
                if(open==1) {
                        reinit_nodesystem();
                }*/
        
-       /* now create the own typeinfo structs an verify nodes */
-       /* here we still assume no groups in groups */
-       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-               ntreeVerifyTypes(ntree);                /* internal nodes, no groups! */
+       /* set node->typeinfo pointers */
+       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+               ntreetype= ntreeGetType(i);
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_init_types_cb);
        }
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+               ntreeInitTypes(ntree);
        
        {
-               /*int has_old_groups=0;*/ /*UNUSED*/
+               int has_old_groups=0;
                /* XXX this should actually be part of do_versions, but since we need
                 * finished library linking, it is not possible there. Instead in do_versions
                 * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
                 * actual group node updates.
                 */
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
-                       if (ntree->flag & NTREE_DO_VERSIONS) {
+                       if (ntree->flag & NTREE_DO_VERSIONS_GROUP_EXPOSE) {
                                /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
-                               nodeGroupExposeAllSockets(ntree);
-                               /*has_old_groups = 1;*/ /*UNUSED*/
+                               node_group_expose_all_sockets(ntree);
+                               has_old_groups = 1;
                        }
                }
-               /* now verify all types in material trees, groups are set OK now */
-               for(ma= main->mat.first; ma; ma= ma->id.next) {
-                       if(ma->nodetree)
-                               lib_nodetree_do_versions_group(ma->nodetree);
-               }
-               /* and scene trees */
-               for(sce= main->scene.first; sce; sce= sce->id.next) {
-                       if(sce->nodetree)
-                               lib_nodetree_do_versions_group(sce->nodetree);
-               }
-               /* and texture trees */
-               for(tx= main->tex.first; tx; tx= tx->id.next) {
-                       if(tx->nodetree)
-                               lib_nodetree_do_versions_group(tx->nodetree);
+               
+               if (has_old_groups) {
+                       for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                               ntreetype= ntreeGetType(i);
+                               if (ntreetype && ntreetype->foreach_nodetree)
+                                       ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_group_indices_cb);
+                       }
                }
                
                for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
-                       ntree->flag &= ~NTREE_DO_VERSIONS;
-       }
-
-       /* now verify all types in material trees, groups are set OK now */
-       for(ma= main->mat.first; ma; ma= ma->id.next) {
-               if(ma->nodetree)
-                       ntreeVerifyTypes(ma->nodetree);
+                       ntree->flag &= ~NTREE_DO_VERSIONS_GROUP_EXPOSE;
        }
-       /* and scene trees */
-       for(sce= main->scene.first; sce; sce= sce->id.next) {
-               if(sce->nodetree)
-                       ntreeVerifyTypes(sce->nodetree);
+       
+       /* verify all group user nodes */
+       for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
+               ntreeVerifyNodes(main, &ntree->id);
        }
-       /* and texture trees */
-       for(tx= main->tex.first; tx; tx= tx->id.next) {
-               if(tx->nodetree)
-                       ntreeVerifyTypes(tx->nodetree);
+       
+       /* make update calls where necessary */
+       {
+               for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next)
+                       if (ntree->update)
+                               ntreeUpdateTree(ntree);
+               for (i=0; i < NUM_NTREE_TYPES; ++i) {
+                       ntreetype= ntreeGetType(i);
+                       if (ntreetype && ntreetype->foreach_nodetree)
+                               ntreetype->foreach_nodetree(main, NULL, lib_nodetree_do_versions_update_cb);
+               }
        }
 }
 
-
+static void direct_link_node_socket(FileData *fd, bNodeSocket *sock)
+{
+       sock->link= newdataadr(fd, sock->link);
+       sock->storage= newdataadr(fd, sock->storage);
+       sock->default_value= newdataadr(fd, sock->default_value);
+       sock->cache= NULL;
+}
 
 /* ntree itself has been read! */
 static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
@@ -2226,6 +2249,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        ntree->init= 0;         /* to set callbacks and force setting types */
        ntree->progress= NULL;
+       ntree->execdata= NULL;
        
        ntree->adt= newdataadr(fd, ntree->adt);
        direct_link_animdata(fd, ntree->adt);
@@ -2235,12 +2259,15 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                if(node->type == NODE_DYNAMIC) {
                        node->custom1= 0;
                        node->custom1= BSET(node->custom1, NODE_DYNAMIC_LOADED);
-                       node->typeinfo= NULL;
                }
+
+               node->typeinfo= NULL;
+               
+               link_list(fd, &node->inputs);
+               link_list(fd, &node->outputs);
                
                node->storage= newdataadr(fd, node->storage);
                if(node->storage) {
-                       
                        /* could be handlerized at some point */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                direct_link_curvemapping(fd, node->storage);
@@ -2257,8 +2284,6 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                                        ((ImageUser *)node->storage)->ok= 1;
                        }
                }
-               link_list(fd, &node->inputs);
-               link_list(fd, &node->outputs);
        }
        link_list(fd, &ntree->links);
        
@@ -2268,15 +2293,19 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
        
        /* and we connect the rest */
        for(node= ntree->nodes.first; node; node= node->next) {
+               node->parent = newdataadr(fd, node->parent);
                node->preview= newimaadr(fd, node->preview);
                node->lasty= 0;
+               
                for(sock= node->inputs.first; sock; sock= sock->next)
-                       sock->link= newdataadr(fd, sock->link);
+                       direct_link_node_socket(fd, sock);
                for(sock= node->outputs.first; sock; sock= sock->next)
-                       sock->ns.data= NULL;
+                       direct_link_node_socket(fd, sock);
        }
+       for(sock= ntree->inputs.first; sock; sock= sock->next)
+               direct_link_node_socket(fd, sock);
        for(sock= ntree->outputs.first; sock; sock= sock->next)
-               sock->link= newdataadr(fd, sock->link);
+               direct_link_node_socket(fd, sock);
        
        for(link= ntree->links.first; link; link= link->next) {
                link->fromnode= newdataadr(fd, link->fromnode);
@@ -4514,7 +4543,7 @@ static void lib_link_scene(FileData *fd, Main *main)
 #endif
 
                        if(sce->ed)
-                               seq_update_muting(sce, sce->ed);
+                               seq_update_muting(sce->ed);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -5000,15 +5029,22 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceNode *snode= (SpaceNode *)sl;
                                                
                                                snode->id= newlibadr(fd, sc->id.lib, snode->id);
+                                               snode->edittree= NULL;
                                                
-                                               /* internal data, a bit patchy */
-                                               if(snode->id) {
-                                                       if(GS(snode->id->name)==ID_MA)
-                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_SCE)
-                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                                       else if(GS(snode->id->name)==ID_TE)
-                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
+                                                       /* internal data, a bit patchy */
+                                                       snode->nodetree= NULL;
+                                                       if(snode->id) {
+                                                               if(GS(snode->id->name)==ID_MA)
+                                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_SCE)
+                                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                               else if(GS(snode->id->name)==ID_TE)
+                                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                                       }
+                                               }
+                                               else {
+                                                       snode->nodetree= newlibadr_us(fd, sc->id.lib, snode->nodetree);
                                                }
                                                
                                                snode->linkdrag.first = snode->linkdrag.last = NULL;
@@ -5237,15 +5273,19 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        snode->id= restore_pointer_by_name(newmain, snode->id, 1);
                                        snode->edittree= NULL;
                                        
-                                       if(snode->id==NULL)
+                                       if (ELEM3(snode->treetype, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE)) {
                                                snode->nodetree= NULL;
+                                               if(snode->id) {
+                                                       if(GS(snode->id->name)==ID_MA)
+                                                               snode->nodetree= ((Material *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_SCE)
+                                                               snode->nodetree= ((Scene *)snode->id)->nodetree;
+                                                       else if(GS(snode->id->name)==ID_TE)
+                                                               snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               }
+                                       }
                                        else {
-                                               if(GS(snode->id->name)==ID_MA)
-                                                       snode->nodetree= ((Material *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_SCE)
-                                                       snode->nodetree= ((Scene *)snode->id)->nodetree;
-                                               else if(GS(snode->id->name)==ID_TE)
-                                                       snode->nodetree= ((Tex *)snode->id)->nodetree;
+                                               snode->nodetree= restore_pointer_by_name(newmain, &snode->nodetree->id, 1);
                                        }
                                }
                                else if(sl->spacetype==SPACE_CLIP) {
@@ -5481,7 +5521,6 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                        snode->gpd= newdataadr(fd, snode->gpd);
                                        direct_link_gpencil(fd, snode->gpd);
                                }
-                               snode->nodetree= snode->edittree= NULL;
                        }
                        else if(sl->spacetype==SPACE_TIME) {
                                SpaceTime *stime= (SpaceTime *)sl;
@@ -5631,12 +5670,51 @@ static void fix_relpaths_library(const char *basepath, Main *main)
        }
 }
 
+/* ************ READ SPEAKER ***************** */
+
+static void lib_link_speaker(FileData *fd, Main *main)
+{
+       Speaker *spk;
+
+       spk= main->speaker.first;
+       while(spk) {
+               if(spk->id.flag & LIB_NEEDLINK) {
+                       if (spk->adt) lib_link_animdata(fd, &spk->id, spk->adt);
+
+                       spk->sound= newlibadr(fd, spk->id.lib, spk->sound);
+                       if (spk->sound) {
+                               spk->sound->id.us++;
+                       }
+
+                       spk->id.flag -= LIB_NEEDLINK;
+               }
+               spk= spk->id.next;
+       }
+}
+
+static void direct_link_speaker(FileData *fd, Speaker *spk)
+{
+       spk->adt= newdataadr(fd, spk->adt);
+       direct_link_animdata(fd, spk->adt);
+
+       /*spk->sound= newdataadr(fd, spk->sound);
+       direct_link_sound(fd, spk->sound);*/
+}
+
 /* ************** READ SOUND ******************* */
 
 static void direct_link_sound(FileData *fd, bSound *sound)
 {
        sound->handle = NULL;
        sound->playback_handle = NULL;
+       sound->waveform = NULL;
+
+       // versioning stuff, if there was a cache, then we enable caching:
+       if(sound->cache)
+       {
+               sound->flags |= SOUND_FLAGS_CACHING;
+               sound->cache = NULL;
+       }
 
        sound->packedfile = direct_link_packedfile(fd, sound->packedfile);
        sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile);
@@ -5653,9 +5731,6 @@ static void lib_link_sound(FileData *fd, Main *main)
                        sound->ipo= newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system
                        
                        sound_load(main, sound);
-
-                       if(sound->cache)
-                               sound_cache(sound, 1);
                }
                sound= sound->id.next;
        }
@@ -5719,9 +5794,7 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip)
                track= track->next;
        }
 
-       clip->last_sel= newdataadr(fd, clip->last_sel);
-       if(clip->last_sel==NULL)
-               clip->sel_type= MCLIP_SEL_NONE;
+       clip->tracking.act_track= newdataadr(fd, clip->tracking.act_track);
 
        clip->anim= NULL;
        clip->tracking_context= NULL;
@@ -5773,6 +5846,7 @@ static const char *dataname(short id_code)
                case ID_SCR: return "Data from SCR";
                case ID_VF: return "Data from VF";
                case ID_TXT     : return "Data from TXT";
+               case ID_SPK: return "Data from SPK";
                case ID_SO: return "Data from SO";
                case ID_NT: return "Data from NT";
                case ID_BR: return "Data from BR";
@@ -5918,6 +5992,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                case ID_CA:
                        direct_link_camera(fd, (Camera *)id);
                        break;
+               case ID_SPK:
+                       direct_link_speaker(fd, (Speaker *)id);
+                       break;
                case ID_SO:
                        direct_link_sound(fd, (bSound *)id);
                        break;
@@ -7001,6 +7078,62 @@ static void do_version_bone_roll_256(Bone *bone)
                do_version_bone_roll_256(child);
 }
 
+static void do_versions_socket_default_value(bNodeSocket *sock)
+{
+       bNodeSocketValueFloat *valfloat;
+       bNodeSocketValueVector *valvector;
+       bNodeSocketValueRGBA *valrgba;
+       
+       if (sock->default_value)
+               return;
+       
+       switch (sock->type) {
+       case SOCK_FLOAT:
+               valfloat = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueFloat), "default socket value");
+               valfloat->value = sock->ns.vec[0];
+               valfloat->min = sock->ns.min;
+               valfloat->max = sock->ns.max;
+               valfloat->subtype = PROP_NONE;
+               break;
+       case SOCK_VECTOR:
+               valvector = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueVector), "default socket value");
+               copy_v3_v3(valvector->value, sock->ns.vec);
+               valvector->min = sock->ns.min;
+               valvector->max = sock->ns.max;
+               valvector->subtype = PROP_NONE;
+               break;
+       case SOCK_RGBA:
+               valrgba = sock->default_value = MEM_callocN(sizeof(bNodeSocketValueRGBA), "default socket value");
+               copy_v4_v4(valrgba->value, sock->ns.vec);
+               break;
+       }
+}
+
+static void do_versions_nodetree_default_value(bNodeTree *ntree)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       for (node=ntree->nodes.first; node; node=node->next) {
+               for (sock=node->inputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+               for (sock=node->outputs.first; sock; sock=sock->next)
+                       do_versions_socket_default_value(sock);
+       }
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               do_versions_socket_default_value(sock);
+}
+
+static void do_versions_nodetree_dynamic_sockets(bNodeTree *ntree)
+{
+       bNodeSocket *sock;
+       for (sock=ntree->inputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+       for (sock=ntree->outputs.first; sock; sock=sock->next)
+               sock->flag |= SOCK_DYNAMIC;
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -10151,7 +10284,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                           !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR))
                                        {
                                                
-                                               snprintf(seq->strip->proxy->dir, 
+                                               BLI_snprintf(seq->strip->proxy->dir, 
                                                         FILE_MAXDIR, "%s/BL_proxy", 
                                                         seq->strip->dir);
                                        }
@@ -10168,7 +10301,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                 * to have them show in RNA viewer and accessible otherwise.
                 */
                for(ma= main->mat.first; ma; ma= ma->id.next) {
-                       if(ma->nodetree && strlen(ma->nodetree->id.name)==0)
+                       if(ma->nodetree && ma->nodetree->id.name[0] == '\0')
                                strcpy(ma->nodetree->id.name, "NTShader Nodetree");
                        
                        /* which_output 0 is now "not specified" */
@@ -10182,7 +10315,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
-                       if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
+                       if(sce->nodetree && sce->nodetree->id.name[0] == '\0')
                                strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
 
                        /* move to cameras */
@@ -10204,7 +10337,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        bNode *node;
 
                        if(tx->nodetree) {
-                               if(strlen(tx->nodetree->id.name)==0)
+                               if(tx->nodetree->id.name[0] == '\0')
                                        strcpy(tx->nodetree->id.name, "NTTexture Nodetree");
 
                                /* which_output 0 is now "not specified" */
@@ -11652,7 +11785,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                         * is done in lib_verify_nodetree, because at this point the internal
                         * nodes may not be up-to-date! (missing lib-link)
                         */
-                       ntree->flag |= NTREE_DO_VERSIONS;
+                       ntree->flag |= NTREE_DO_VERSIONS_GROUP_EXPOSE;
                }
        }
 
@@ -11775,12 +11908,12 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        Tex *tex;
                        for(tex= main->tex.first; tex; tex= tex->id.next) {
                                if(tex->pd) {
-                                       if (tex->pd->falloff_speed_scale == 0.0)
-                                               tex->pd->falloff_speed_scale = 100.0;
-
+                                       if (tex->pd->falloff_speed_scale == 0.0f)
+                                               tex->pd->falloff_speed_scale = 100.0f;
+                                       
                                        if (!tex->pd->falloff_curve) {
                                                tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
-
+                                               
                                                tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
                                                tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
                                                curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
@@ -11813,7 +11946,174 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        }
                }
        }
-       
+
+       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 1)){
+               {
+                       Scene *scene;
+                       Sequence *seq;
+
+                       for (scene=main->scene.first; scene; scene=scene->id.next)
+                       {
+                               scene->r.ffcodecdata.audio_channels = 2;
+                               scene->audio.volume = 1.0f;
+                               SEQ_BEGIN(scene->ed, seq) {
+                                       seq->pitch = 1.0f;
+                               }
+                               SEQ_END
+                       }
+               }
+               {
+                       bScreen *screen;
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               ScrArea *sa;
+                               /* add regions */
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       SpaceLink *sl= sa->spacedata.first;
+                                       if(sl->spacetype==SPACE_SEQ) {
+                                               ARegion *ar;
+                                               for (ar=sa->regionbase.first; ar; ar= ar->next) {
+                                                       if(ar->regiontype == RGN_TYPE_WINDOW) {
+                                                               if(ar->v2d.min[1] == 4.0f)
+                                                                       ar->v2d.min[1]= 0.5f;
+                                                       }
+                                               }
+                                       }
+                                       for (sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_SEQ) {
+                                                       ARegion *ar;
+                                                       for (ar=sl->regionbase.first; ar; ar= ar->next) {
+                                                               if(ar->regiontype == RGN_TYPE_WINDOW) {
+                                                                       if(ar->v2d.min[1] == 4.0f)
+                                                                               ar->v2d.min[1]= 0.5f;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+               {
+                       /* Make "auto-clamped" handles a per-keyframe setting instead of per-FCurve 
+                        *
+                        * We're only patching F-Curves in Actions here, since it is assumed that most
+                        * drivers out there won't be using this (and if they are, they're in the minority).
+                        * While we should aim to fix everything ideally, in practice it's far too hard
+                        * to get to every animdata block, not to mention the performance hit that'd have
+                        */
+                       bAction *act;
+                       FCurve *fcu;
+                       
+                       for (act = main->action.first; act; act = act->id.next) {
+                               for (fcu = act->curves.first; fcu; fcu = fcu->next) {
+                                       BezTriple *bezt;
+                                       unsigned int i = 0;
+                                       
+                                       /* only need to touch curves that had this flag set */
+                                       if ((fcu->flag & FCURVE_AUTO_HANDLES) == 0)
+                                               continue;
+                                       if ((fcu->totvert == 0) || (fcu->bezt == NULL))
+                                               continue;
+                                               
+                                       /* only change auto-handles to auto-clamped */
+                                       for (bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
+                                               if (bezt->h1 == HD_AUTO) bezt->h1 = HD_AUTO_ANIM;
+                                               if (bezt->h2 == HD_AUTO) bezt->h2 = HD_AUTO_ANIM;
+                                       }
+                                       
+                                       fcu->flag &= ~FCURVE_AUTO_HANDLES;
+                               }
+                       }
+               }
+               {
+                       /* convert fcurve and shape action actuators to action actuators */
+                       Object *ob;
+                       bActuator *act;
+                       bIpoActuator *ia;
+                       bActionActuator *aa;
+
+                       for (ob= main->object.first; ob; ob= ob->id.next) {
+                               for (act= ob->actuators.first; act; act= act->next) {
+                                       if (act->type == ACT_IPO) {
+                                               // Create the new actuator
+                                               ia= act->data;
+                                               aa= MEM_callocN(sizeof(bActionActuator), "fcurve -> action actuator do_version");
+
+                                               // Copy values
+                                               aa->type = ia->type;
+                                               aa->flag = ia->flag;
+                                               aa->sta = ia->sta;
+                                               aa->end = ia->end;
+                                               strcpy(aa->name, ia->name);
+                                               strcpy(aa->frameProp, ia->frameProp);
+                                               if (ob->adt)
+                                                       aa->act = ob->adt->action;
+
+                                               // Get rid of the old actuator
+                                               MEM_freeN(ia);
+
+                                               // Assign the new actuator
+                                               act->data = aa;
+                                               act->type= act->otype= ACT_ACTION;
+                                               
+                                       }
+                                       else if (act->type == ACT_SHAPEACTION)  {
+                                               act->type = act->otype = ACT_ACTION;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)){
+               {
+                       /* Convert default socket values from bNodeStack */
+                       Scene *sce;
+                       Material *mat;
+                       Tex *tex;
+                       bNodeTree *ntree;
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_default_value(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+                       for (sce=main->scene.first; sce; sce=sce->id.next)
+                               if (sce->nodetree) {
+                               do_versions_nodetree_default_value(sce->nodetree);
+                               sce->nodetree->update |= NTREE_UPDATE;
+                       }
+                       for (mat=main->mat.first; mat; mat=mat->id.next)
+                               if (mat->nodetree) {
+                               do_versions_nodetree_default_value(mat->nodetree);
+                               mat->nodetree->update |= NTREE_UPDATE;
+                       }
+                       for (tex=main->tex.first; tex; tex=tex->id.next)
+                               if (tex->nodetree) {
+                               do_versions_nodetree_default_value(tex->nodetree);
+                               tex->nodetree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               /* add SOCK_DYNAMIC flag to existing group sockets */
+               {
+                       bNodeTree *ntree;
+                       /* only need to do this for trees in main, local trees are not used as groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_dynamic_sockets(ntree);
+                               ntree->update |= NTREE_UPDATE;
+                       }
+               }
+
+               {
+                       /* Initialize group tree nodetypes.
+                        * These are used to distinguish tree types and
+                        * associate them with specific node types for polling.
+                        */
+                       bNodeTree *ntree;
+                       /* all node trees in main->nodetree are considered groups */
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+                               ntree->nodetype = NODE_GROUP;
+               }
+       }
+
        /* put compatibility code here until next subversion bump */
 
        {
@@ -11906,6 +12206,7 @@ static void lib_link_all(FileData *fd, Main *main)
        lib_link_latt(fd, main);
        lib_link_text(fd, main);
        lib_link_camera(fd, main);
+       lib_link_speaker(fd, main);
        lib_link_sound(fd, main);
        lib_link_group(fd, main);
        lib_link_armature(fd, main);
@@ -12847,6 +13148,14 @@ static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
                expand_animdata(fd, mainvar, ca->adt);
 }
 
+static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk)
+{
+       expand_doit(fd, mainvar, spk->sound);
+
+       if (spk->adt)
+               expand_animdata(fd, mainvar, spk->adt);
+}
+
 static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
 {
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
@@ -12909,6 +13218,9 @@ static void expand_main(FileData *fd, Main *mainvar)
                                        case ID_CA:
                                                expand_camera(fd, mainvar, (Camera *)id);
                                                break;
+                                       case ID_SPK:
+                                               expand_speaker(fd, mainvar,(Speaker *)id);
+                                               break;
                                        case ID_SO:
                                                expand_sound(fd, mainvar, (bSound *)id);
                                                break;