Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / synfig / valuenode_sine.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_sine.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenode_sine.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenode_sine.h"
33 #include "valuenode_const.h"
34 #include "general.h"
35
36 #endif
37
38 /* === U S I N G =========================================================== */
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 ValueNode_Sine::ValueNode_Sine(const ValueBase::Type &x):
53         LinkableValueNode(x)
54 {
55         switch(x)
56         {
57         case ValueBase::TYPE_REAL:
58                 set_link("angle",ValueNode_Const::create(Angle::zero()));
59                 set_link("amp",ValueNode_Const::create(Real(1)));
60                 break;
61         default:
62                 throw Exception::BadType(ValueBase::type_name(x));
63         }
64
65         DCAST_HACK_ENABLE();
66 }
67
68 ValueNode_Sine*
69 ValueNode_Sine::create(const ValueBase &x)
70 {
71         return new ValueNode_Sine(x.get_type());
72 }
73
74 ValueNode_Sine::~ValueNode_Sine()
75 {
76         unlink_all();
77 }
78
79 ValueBase
80 ValueNode_Sine::operator()(Time t)const
81 {
82         return
83                 Angle::sin(
84                         (*angle_)(t).get(Angle())
85                 ).get() * (*amp_)(t).get(Real())
86         ;
87 }
88
89
90 String
91 ValueNode_Sine::get_name()const
92 {
93         return "sine";
94 }
95
96 String
97 ValueNode_Sine::get_local_name()const
98 {
99         return _("Sine");
100 }
101                 
102 bool
103 ValueNode_Sine::check_type(ValueBase::Type type)
104 {
105         return type==ValueBase::TYPE_REAL;
106 }
107
108 bool
109 ValueNode_Sine::set_link_vfunc(int i,ValueNode::Handle x)
110 {
111         assert(i==0 || i==1);
112         if(i==0)
113         {
114                 angle_=x;
115                 signal_child_changed()(i);signal_value_changed()();
116                 return true;
117         }
118         if(i==1)
119         {
120                 amp_=x;
121                 signal_child_changed()(i);signal_value_changed()();
122                 return true;
123         }
124         return false;
125 }
126
127 ValueNode::LooseHandle
128 ValueNode_Sine::get_link_vfunc(int i)const
129 {
130         assert(i==0 || i==1);
131         if(i==0)
132                 return angle_;
133         if(i==1)
134                 return amp_;
135
136         return 0;
137 }
138
139 int
140 ValueNode_Sine::link_count()const
141 {
142         return 2;
143 }
144
145 String
146 ValueNode_Sine::link_name(int i)const
147 {
148         assert(i==0 || i==1);
149         if(i==0)
150                 return "angle";
151         if(i==1)
152                 return "amp";
153         return String();
154 }
155
156 String
157 ValueNode_Sine::link_local_name(int i)const
158 {
159         assert(i==0 || i==1);
160         if(i==0)
161                 return _("Angle");
162         if(i==1)
163                 return _("Amplitude");
164         return String();
165 }
166
167 int
168 ValueNode_Sine::get_link_index_from_name(const String &name)const
169 {
170         if(name=="angle")
171                 return 0;
172         if(name=="amp")
173                 return 1;
174         
175         throw Exception::BadLinkName(name);
176 }
177
178 LinkableValueNode*
179 ValueNode_Sine::create_new()const
180 {
181         return new ValueNode_Sine(get_type());
182 }