21efad994cb5818a5790e2b489b8c35932e23497
[synfig.git] / synfig-core / src / synfig / valuenode_sine.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_sine.cpp
3 **      \brief Implementation of the "Sine" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_sine.h"
34 #include "valuenode_const.h"
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 /* === P R O C E D U R E S ================================================= */
50
51 /* === M E T H O D S ======================================================= */
52
53 ValueNode_Sine::ValueNode_Sine(const ValueBase &value):
54         LinkableValueNode(value.get_type())
55 {
56         switch(value.get_type())
57         {
58         case ValueBase::TYPE_REAL:
59                 set_link("angle",ValueNode_Const::create(Angle::deg(90)));
60                 set_link("amp",ValueNode_Const::create(value.get(Real())));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
64         }
65 }
66
67 LinkableValueNode*
68 ValueNode_Sine::create_new()const
69 {
70         return new ValueNode_Sine(get_type());
71 }
72
73 ValueNode_Sine*
74 ValueNode_Sine::create(const ValueBase &x)
75 {
76         return new ValueNode_Sine(x);
77 }
78
79 ValueNode_Sine::~ValueNode_Sine()
80 {
81         unlink_all();
82 }
83
84 ValueBase
85 ValueNode_Sine::operator()(Time t)const
86 {
87         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
88                 printf("%s:%d operator()\n", __FILE__, __LINE__);
89
90         return
91                 Angle::sin(
92                         (*angle_)(t).get(Angle())
93                 ).get() * (*amp_)(t).get(Real())
94         ;
95 }
96
97
98 String
99 ValueNode_Sine::get_name()const
100 {
101         return "sine";
102 }
103
104 String
105 ValueNode_Sine::get_local_name()const
106 {
107         return _("Sine");
108 }
109
110 bool
111 ValueNode_Sine::check_type(ValueBase::Type type)
112 {
113         return type==ValueBase::TYPE_REAL;
114 }
115
116 bool
117 ValueNode_Sine::set_link_vfunc(int i,ValueNode::Handle value)
118 {
119         assert(i>=0 && i<link_count());
120
121         switch(i)
122         {
123         case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
124         case 1: CHECK_TYPE_AND_SET_VALUE(amp_,   ValueBase::TYPE_REAL);
125         }
126         return false;
127 }
128
129 ValueNode::LooseHandle
130 ValueNode_Sine::get_link_vfunc(int i)const
131 {
132         assert(i>=0 && i<link_count());
133
134         if(i==0)
135                 return angle_;
136         if(i==1)
137                 return amp_;
138
139         return 0;
140 }
141
142 int
143 ValueNode_Sine::link_count()const
144 {
145         return 2;
146 }
147
148 String
149 ValueNode_Sine::link_name(int i)const
150 {
151         assert(i>=0 && i<link_count());
152
153         if(i==0)
154                 return "angle";
155         if(i==1)
156                 return "amp";
157         return String();
158 }
159
160 String
161 ValueNode_Sine::link_local_name(int i)const
162 {
163         assert(i>=0 && i<link_count());
164
165         if(i==0)
166                 return _("Angle");
167         if(i==1)
168                 return _("Amplitude");
169         return String();
170 }
171
172 int
173 ValueNode_Sine::get_link_index_from_name(const String &name)const
174 {
175         if(name=="angle")
176                 return 0;
177         if(name=="amp")
178                 return 1;
179
180         throw Exception::BadLinkName(name);
181 }
182
183 LinkableValueNode::Vocab
184 ValueNode_Sine::get_param_vocab()const
185 {
186         LinkableValueNode::Vocab ret;
187
188         ret.push_back(ParamDesc(ValueBase(),"angle")
189                 .set_local_name(_("Angle"))
190                 .set_description(_("The angle where the sine is calculated from"))
191         );
192
193         ret.push_back(ParamDesc(ValueBase(),"amp")
194                 .set_local_name(_("Amplitude"))
195                 .set_description(_("The value that multiplies the resulting sine"))
196         );
197
198         return ret;
199 }