1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., 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 ======================================================= */
34 #include <ETL/stringf>
37 #include "exception.h"
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
62 Keyframe::Keyframe(const Time &time):
72 KeyframeList::dump()const
76 synfig::info(">>>>>>>>BEGIN KEYFRAME DUMP");
77 for(iter=begin(),i=0;iter!=end();++iter,i++)
79 synfig::info("#%d, time: %s, desc: %s",i,iter->get_time().get_string().c_str(),iter->get_description().c_str());
81 synfig::info("<<<<<<<<END KEYFRAME DUMP");
87 //synfig::info("PRE-SORT:");
90 //synfig::info("POST-SORT:");
94 KeyframeList::iterator
95 KeyframeList::find(const UniqueID &x)
97 KeyframeList::iterator iter;
98 iter=std::find(begin(),end(),x);
100 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
104 KeyframeList::const_iterator
105 KeyframeList::find(const UniqueID &x)const
107 KeyframeList::const_iterator iter;
108 iter=std::find(begin(),end(),x);
110 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
114 KeyframeList::iterator
115 KeyframeList::add(const Keyframe &x)
126 KeyframeList::erase(const UniqueID &x)
128 std::vector<Keyframe>::erase(find(x));
131 KeyframeList::iterator
132 KeyframeList::find(const Time &x)
134 KeyframeList::iterator iter;
135 iter=binary_find(begin(),end(),x);
136 if(iter!=end() && iter->get_time().is_equal(x))
139 if(iter!=end() && iter->get_time().is_equal(x))
142 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find Keyframe %s",x.get_string().c_str()));
145 KeyframeList::iterator
146 KeyframeList::find_next(const Time &x)
148 KeyframeList::iterator iter(binary_find(begin(),end(),x));
152 if(iter->get_time().is_more_than(x))
157 if(iter->get_time().is_more_than(x))
160 if(iter!=end() && iter->get_time().is_more_than(x))
166 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find next Keyframe %s",x.get_string().c_str()));
170 KeyframeList::iterator
171 KeyframeList::find_prev(const Time &x)
173 KeyframeList::iterator iter(binary_find(begin(),end(),x));
177 if(iter->get_time()+Time::epsilon()<x)
179 if(iter!=begin() && (--iter)->get_time()+Time::epsilon()<x)
182 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find prev Keyframe %s",x.get_string().c_str()));
188 KeyframeList::const_iterator
189 KeyframeList::find(const Time &x)const
191 return const_cast<KeyframeList*>(this)->find(x);
195 KeyframeList::const_iterator
196 KeyframeList::find_next(const Time &x)const
198 return const_cast<KeyframeList*>(this)->find_next(x);
203 KeyframeList::const_iterator
204 KeyframeList::find_prev(const Time &x)const
206 return const_cast<KeyframeList*>(this)->find_prev(x);
211 KeyframeList::find_prev_next(const Time& time, Time &prev, Time &next)const
213 try { prev=find_prev(time)->get_time(); }
214 catch(...) { prev=Time::begin(); }
215 try { next=find_next(time)->get_time(); }
216 catch(...) { next=Time::end(); }
220 KeyframeList::insert_time(const Time& location, const Time& delta)
222 // synfig::info("KeyframeList::insert_time(): loc=%s, delta=%s",location.get_string().c_str(),delta.get_string().c_str());
227 iterator iter(find_next(location));
228 for(;iter!=end();++iter)
230 iter->set_time(iter->get_time()+delta);
234 catch(Exception::NotFound) { }