1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_timeloop.cpp
3 ** \brief Implementation of the "Time Loop" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_timeloop.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_TimeLoop::ValueNode_TimeLoop(const ValueBase::Type &x):
58 ValueNode_TimeLoop::ValueNode_TimeLoop(const ValueNode::Handle &x):
59 LinkableValueNode(x->get_type())
61 Vocab ret(get_children_vocab());
62 set_children_vocab(ret);
64 set_link("link_time", ValueNode_Const::create(Time(0)));
65 set_link("local_time", ValueNode_Const::create(Time(0)));
66 set_link("duration", ValueNode_Const::create(Time(1)));
70 ValueNode_TimeLoop::create(const ValueBase &x)
72 return new ValueNode_TimeLoop(ValueNode_Const::create(x));
76 ValueNode_TimeLoop::create_new()const
78 return new ValueNode_TimeLoop(get_type());
81 ValueNode_TimeLoop::~ValueNode_TimeLoop()
87 ValueNode_TimeLoop::set_link_vfunc(int i,ValueNode::Handle value)
89 assert(i>=0 && i<link_count());
93 case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
94 case 1: CHECK_TYPE_AND_SET_VALUE(link_time_, ValueBase::TYPE_TIME);
95 case 2: CHECK_TYPE_AND_SET_VALUE(local_time_, ValueBase::TYPE_TIME);
96 case 3: CHECK_TYPE_AND_SET_VALUE(duration_, ValueBase::TYPE_TIME);
101 ValueNode::LooseHandle
102 ValueNode_TimeLoop::get_link_vfunc(int i)const
104 assert(i>=0 && i<link_count());
106 if(i==0) return link_;
107 if(i==1) return link_time_;
108 if(i==2) return local_time_;
109 if(i==3) return duration_;
115 ValueNode_TimeLoop::operator()(Time t)const
117 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
118 printf("%s:%d operator()\n", __FILE__, __LINE__);
120 Time link_time = (*link_time_) (t).get(Time());
121 Time local_time = (*local_time_)(t).get(Time());
122 Time duration = (*duration_) (t).get(Time());
126 else if (duration > 0)
129 t -= floor(t / duration) * duration;
134 duration = -duration;
136 t -= floor(t / duration) * duration;
144 ValueNode_TimeLoop::get_name()const
150 ValueNode_TimeLoop::get_local_name()const
152 return _("Time Loop");
156 ValueNode_TimeLoop::check_type(ValueBase::Type type)
164 LinkableValueNode::Vocab
165 ValueNode_TimeLoop::get_children_vocab_vfunc()const
167 if(children_vocab.size())
168 return children_vocab;
170 LinkableValueNode::Vocab ret;
172 ret.push_back(ParamDesc("link")
173 .set_local_name(_("Link"))
174 .set_description(_("The value node to time loop"))
177 ret.push_back(ParamDesc("link_time")
178 .set_local_name(_("Link Time"))
179 .set_description(_("Start time of the loop for the value node timeline"))
182 ret.push_back(ParamDesc("local_time")
183 .set_local_name(_("Local Time"))
184 .set_description(_("The time when the resulted loop starts"))
187 ret.push_back(ParamDesc("duration")
188 .set_local_name(_("Duration"))
189 .set_description(_("Lenght of the loop"))