1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: keyframe.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
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");
88 //synfig::info("PRE-SORT:");
91 //synfig::info("POST-SORT:");
96 KeyframeList::iterator
97 KeyframeList::find(const UniqueID &x)
99 KeyframeList::iterator iter;
100 iter=std::find(begin(),end(),x);
102 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
106 KeyframeList::const_iterator
107 KeyframeList::find(const UniqueID &x)const
109 KeyframeList::const_iterator iter;
110 iter=std::find(begin(),end(),x);
112 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
116 KeyframeList::iterator
117 KeyframeList::add(const Keyframe &x)
128 KeyframeList::erase(const UniqueID &x)
130 std::vector<Keyframe>::erase(find(x));
133 KeyframeList::iterator
134 KeyframeList::find(const Time &x)
136 KeyframeList::iterator iter;
137 iter=binary_find(begin(),end(),x);
138 if(iter!=end() && iter->get_time().is_equal(x))
141 if(iter!=end() && iter->get_time().is_equal(x))
144 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find Keyframe %s",x.get_string().c_str()));
147 KeyframeList::iterator
148 KeyframeList::find_next(const Time &x)
150 KeyframeList::iterator iter(binary_find(begin(),end(),x));
154 if(iter->get_time().is_more_than(x))
159 if(iter->get_time().is_more_than(x))
162 if(iter!=end() && iter->get_time().is_more_than(x))
168 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find next Keyframe %s",x.get_string().c_str()));
172 KeyframeList::iterator
173 KeyframeList::find_prev(const Time &x)
175 KeyframeList::iterator iter(binary_find(begin(),end(),x));
179 if(iter->get_time()+Time::epsilon()<x)
181 if(iter!=begin() && (--iter)->get_time()+Time::epsilon()<x)
184 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find prev Keyframe %s",x.get_string().c_str()));
190 KeyframeList::const_iterator
191 KeyframeList::find(const Time &x)const
193 return const_cast<KeyframeList*>(this)->find(x);
197 KeyframeList::const_iterator
198 KeyframeList::find_next(const Time &x)const
200 return const_cast<KeyframeList*>(this)->find_next(x);
205 KeyframeList::const_iterator
206 KeyframeList::find_prev(const Time &x)const
208 return const_cast<KeyframeList*>(this)->find_prev(x);
213 KeyframeList::find_prev_next(const Time& time, Time &prev, Time &next)const
215 try { prev=find_prev(time)->get_time(); }
216 catch(...) { prev=Time::begin(); }
217 try { next=find_next(time)->get_time(); }
218 catch(...) { next=Time::end(); }
222 KeyframeList::insert_time(const Time& location, const Time& delta)
224 // synfig::info("KeyframeList::insert_time(): loc=%s, delta=%s",location.get_string().c_str(),delta.get_string().c_str());
229 iterator iter(find_next(location));
230 for(;iter!=end();++iter)
232 iter->set_time(iter->get_time()+delta);
236 catch(Exception::NotFound) { }