1 /* === S Y N F I G ========================================================= */
2 /*! \file timegather.cpp
3 ** \brief Time Gather File
8 ** Copyright (c) 2004 Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "timegather.h"
33 #include "value_desc.h"
35 #include <synfig/layer_pastecanvas.h>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace synfigapp;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 /* === E N T R Y P O I N T ================================================= */
56 //! Definitions for build a list of accurate valuenode references
58 void synfigapp::timepoints_ref::insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w)
63 waytracker::iterator i = waypointbiglist.find(vt);
65 if(i != waypointbiglist.end())
67 i->waypoints.insert(w);
70 vt.waypoints.insert(w);
71 waypointbiglist.insert(vt);
75 void synfigapp::timepoints_ref::insert(synfigapp::ValueDesc v, synfig::Activepoint a)
80 acttracker::iterator i = actpointbiglist.find(vt);
82 if(i != actpointbiglist.end())
84 i->activepoints.insert(a);
86 synfig::info("!!!!For some reason it wasn't able to insert the activepoint in the list (%s,%.4lg)",
87 a.state?"true":"false", (double)a.time);
91 vt.activepoints.insert(a);
92 actpointbiglist.insert(vt);
93 //synfig::info("Insert new activept list for valdesc");
98 void synfigapp::recurse_canvas(synfig::Canvas::Handle h, const std::set<Time> &tlist,
99 timepoints_ref &vals, synfig::Time time_offset)
102 //synfig::info("Canvas...\n Recurse through layers");
103 // iterate through the layers
105 synfig::Canvas::iterator i = h->begin(), end = h->end();
109 const Node::time_set &tset = (*i)->get_times();
110 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
112 recurse_layer(*i,tlist,vals,time_offset);
117 void synfigapp::recurse_layer(synfig::Layer::Handle h, const std::set<Time> &tlist,
118 timepoints_ref &vals, synfig::Time time_offset)
120 // iterate through the layers
121 //check for special case of paste canvas
122 etl::handle<synfig::Layer_PasteCanvas> p = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(h);
124 //synfig::info("Layer...");
128 //synfig::info("We are a paste canvas so go into that");
129 //recurse into the canvas
130 const synfig::Node::time_set &tset = p->get_sub_canvas()->get_times();
131 synfig::Time subcanvas_time_offset(time_offset + p->get_time_offset());
133 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),subcanvas_time_offset))
134 recurse_canvas(p->get_sub_canvas(),tlist,vals,subcanvas_time_offset);
137 //check all the valuenodes regardless...
138 //synfig::info("Recurse all valuenodes");
139 synfig::Layer::DynamicParamList::const_iterator i = h->dynamic_param_list().begin(),
140 end = h->dynamic_param_list().end();
143 const synfig::Node::time_set &tset = i->second->get_times();
145 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
147 recurse_valuedesc(ValueDesc(h,i->first),tlist,vals,time_offset);
152 template < typename IT, typename CMP >
153 static bool sorted(IT i,IT end, const CMP &cmp = CMP())
155 if(i == end) return true;
157 for(IT last = i++; i != end; last = i++)
166 void synfigapp::recurse_valuedesc(synfigapp::ValueDesc h, const std::set<Time> &tlist,
167 timepoints_ref &vals, synfig::Time time_offset)
169 //special cases for Animated, DynamicList, and Linkable
171 //synfig::info("ValueBasenode... %p, %s", h.get_value_node().get(),typeid(*h.get_value_node()).name());
176 synfig::ValueNode_Animated::Handle p = synfig::ValueNode_Animated::Handle::cast_dynamic(h.get_value_node());
180 //loop through and determine which waypoint we will need to reference
181 const synfig::WaypointList &w = p->waypoint_list();
183 synfig::WaypointList::const_iterator i = w.begin(),
186 std::set<Time>::const_iterator j = tlist.begin(),
188 for(; i != end && j != jend;)
190 //synfig::info("tpair t(%.3f) = %.3f", (float)*j, (float)(i->get_time()));
192 if((*j+time_offset).is_equal(i->get_time()))
196 }else if(*i < *j+time_offset)
205 //parent dynamiclist case - just for active points for that object...
206 if(h.parent_is_value_node())
208 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_parent_value_node());
212 int index = h.get_index();
214 //check all the active points in each list...
215 const synfig::ActivepointList &a = p->list[index].timing_info;
217 //synfig::info("Our parent = dynamic list, searching in %d activepts",a.size());
219 std::set<Time>::const_iterator i = tlist.begin(),
222 synfig::ActivepointList::const_iterator j = a.begin(),
225 for(; j != jend && i != end;)
227 double it = *i+time_offset;
228 double jt = j->get_time();
229 double diff = (double)(it - jt);
231 //synfig::info("\ttpair match(%.4lg) - %.4lg (diff = %lg",it,jt,diff);
234 if(abs(diff) < (double)Time::epsilon())
236 //synfig::info("\tActivepoint to add being referenced (%x,%s,%.4lg)",
237 // (int)j->get_uid(),j->state?"true":"false", (double)j->time);
238 vals.insert(ValueDesc(p,index),*j);
243 //synfig::info("\tIncrementing time");
248 //synfig::info("\tIncrementing actpt");
254 //dynamiclist case - we must still make sure that we read from the list entries the time values
255 // because just the linked valuenodes will not do that
257 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_value_node());
261 //synfig::info("Process dynamic list valuenode");
264 std::vector<synfig::ValueNode_DynamicList::ListEntry>::const_iterator
268 for(; i != end; ++i, ++index)
270 const Node::time_set &tset = i->get_times();
272 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
274 recurse_valuedesc(ValueDesc(p,index),tlist,vals,time_offset);
281 //the linkable case...
283 etl::handle<synfig::LinkableValueNode> p = etl::handle<synfig::LinkableValueNode>::cast_dynamic(h.get_value_node());
287 //synfig::info("Process Linkable ValueBasenode");
288 int i = 0, size = p->link_count();
292 ValueNode::Handle v = p->get_link(i);
293 const Node::time_set &tset = v->get_times();
295 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
297 recurse_valuedesc(ValueDesc(p,i),tlist,vals,time_offset);