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>
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace synfigapp;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 /* === E N T R Y P O I N T ================================================= */
58 //! Definitions for build a list of accurate valuenode references
60 void synfigapp::timepoints_ref::insert(synfig::ValueNode_Animated::Handle v, synfig::Waypoint w)
65 waytracker::iterator i = waypointbiglist.find(vt);
67 if(i != waypointbiglist.end())
69 i->waypoints.insert(w);
72 vt.waypoints.insert(w);
73 waypointbiglist.insert(vt);
77 void synfigapp::timepoints_ref::insert(synfigapp::ValueDesc v, synfig::Activepoint a)
82 acttracker::iterator i = actpointbiglist.find(vt);
84 if(i != actpointbiglist.end())
86 i->activepoints.insert(a);
88 synfig::info("!!!!For some reason it wasn't able to insert the activepoint in the list (%s,%.4lg)",
89 a.state?"true":"false", (double)a.time);
93 vt.activepoints.insert(a);
94 actpointbiglist.insert(vt);
95 //synfig::info("Insert new activept list for valdesc");
100 void synfigapp::recurse_canvas(synfig::Canvas::Handle h, const std::set<Time> &tlist,
101 timepoints_ref &vals, synfig::Time time_offset)
104 //synfig::info("Canvas...\n Recurse through layers");
105 // iterate through the layers
107 synfig::Canvas::iterator i = h->begin(), end = h->end();
111 const Node::time_set &tset = (*i)->get_times();
112 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
114 recurse_layer(*i,tlist,vals,time_offset);
119 void synfigapp::recurse_layer(synfig::Layer::Handle h, const std::set<Time> &tlist,
120 timepoints_ref &vals, synfig::Time time_offset)
122 // iterate through the layers
123 //check for special case of paste canvas
124 etl::handle<synfig::Layer_PasteCanvas> p = etl::handle<synfig::Layer_PasteCanvas>::cast_dynamic(h);
126 //synfig::info("Layer...");
130 //synfig::info("We are a paste canvas so go into that");
131 //recurse into the canvas
132 const synfig::Node::time_set &tset = p->get_sub_canvas()->get_times();
133 synfig::Time subcanvas_time_offset(time_offset + p->get_time_offset());
135 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),subcanvas_time_offset))
136 recurse_canvas(p->get_sub_canvas(),tlist,vals,subcanvas_time_offset);
139 //check all the valuenodes regardless...
140 //synfig::info("Recurse all valuenodes");
141 synfig::Layer::DynamicParamList::const_iterator i = h->dynamic_param_list().begin(),
142 end = h->dynamic_param_list().end();
145 const synfig::Node::time_set &tset = i->second->get_times();
147 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
149 recurse_valuedesc(ValueDesc(h,i->first),tlist,vals,time_offset);
154 template < typename IT, typename CMP >
155 static bool sorted(IT i,IT end, const CMP &cmp = CMP())
157 if(i == end) return true;
159 for(IT last = i++; i != end; last = i++)
168 void synfigapp::recurse_valuedesc(synfigapp::ValueDesc h, const std::set<Time> &tlist,
169 timepoints_ref &vals, synfig::Time time_offset)
171 //special cases for Animated, DynamicList, and Linkable
173 //synfig::info("ValueBasenode... %p, %s", h.get_value_node().get(),typeid(*h.get_value_node()).name());
178 synfig::ValueNode_Animated::Handle p = synfig::ValueNode_Animated::Handle::cast_dynamic(h.get_value_node());
182 //loop through and determine which waypoint we will need to reference
183 const synfig::WaypointList &w = p->waypoint_list();
185 synfig::WaypointList::const_iterator i = w.begin(),
188 std::set<Time>::const_iterator j = tlist.begin(),
190 for(; i != end && j != jend;)
192 //synfig::info("tpair t(%.3f) = %.3f", (float)*j, (float)(i->get_time()));
194 if((*j+time_offset).is_equal(i->get_time()))
198 }else if(*i < *j+time_offset)
207 //parent dynamiclist case - just for active points for that object...
208 if(h.parent_is_value_node())
210 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_parent_value_node());
214 int index = h.get_index();
216 //check all the active points in each list...
217 const synfig::ActivepointList &a = p->list[index].timing_info;
219 //synfig::info("Our parent = dynamic list, searching in %d activepts",a.size());
221 std::set<Time>::const_iterator i = tlist.begin(),
224 synfig::ActivepointList::const_iterator j = a.begin(),
227 for(; j != jend && i != end;)
229 double it = *i+time_offset;
230 double jt = j->get_time();
231 double diff = (double)(it - jt);
233 //synfig::info("\ttpair match(%.4lg) - %.4lg (diff = %lg",it,jt,diff);
236 if(abs(diff) < (double)Time::epsilon())
238 //synfig::info("\tActivepoint to add being referenced (%x,%s,%.4lg)",
239 // (int)j->get_uid(),j->state?"true":"false", (double)j->time);
240 vals.insert(ValueDesc(p,index),*j);
245 //synfig::info("\tIncrementing time");
250 //synfig::info("\tIncrementing actpt");
256 //dynamiclist case - we must still make sure that we read from the list entries the time values
257 // because just the linked valuenodes will not do that
259 synfig::ValueNode_DynamicList::Handle p = synfig::ValueNode_DynamicList::Handle::cast_dynamic(h.get_value_node());
263 //synfig::info("Process dynamic list valuenode");
266 std::vector<synfig::ValueNode_DynamicList::ListEntry>::const_iterator
270 for(; i != end; ++i, ++index)
272 const Node::time_set &tset = i->get_times();
274 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
276 recurse_valuedesc(ValueDesc(p,index),tlist,vals,time_offset);
283 //the linkable case...
285 etl::handle<synfig::LinkableValueNode> p = etl::handle<synfig::LinkableValueNode>::cast_dynamic(h.get_value_node());
289 //synfig::info("Process Linkable ValueBasenode");
290 int i = 0, size = p->link_count();
294 ValueNode::Handle v = p->get_link(i);
295 const Node::time_set &tset = v->get_times();
297 if(check_intersect(tset.begin(),tset.end(),tlist.begin(),tlist.end(),time_offset))
299 recurse_valuedesc(ValueDesc(p,i),tlist,vals,time_offset);