Made all the assert() lines which check the valuenode sub-parameter index range the...
[synfig.git] / synfig-core / trunk / 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 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_name(value.get_type()));
64         }
65
66         DCAST_HACK_ENABLE();
67 }
68
69 LinkableValueNode*
70 ValueNode_Sine::create_new()const
71 {
72         return new ValueNode_Sine(get_type());
73 }
74
75 ValueNode_Sine*
76 ValueNode_Sine::create(const ValueBase &x)
77 {
78         return new ValueNode_Sine(x);
79 }
80
81 ValueNode_Sine::~ValueNode_Sine()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_Sine::operator()(Time t)const
88 {
89         return
90                 Angle::sin(
91                         (*angle_)(t).get(Angle())
92                 ).get() * (*amp_)(t).get(Real())
93         ;
94 }
95
96
97 String
98 ValueNode_Sine::get_name()const
99 {
100         return "sine";
101 }
102
103 String
104 ValueNode_Sine::get_local_name()const
105 {
106         return _("Sine");
107 }
108
109 bool
110 ValueNode_Sine::check_type(ValueBase::Type type)
111 {
112         return type==ValueBase::TYPE_REAL;
113 }
114
115 bool
116 ValueNode_Sine::set_link_vfunc(int i,ValueNode::Handle x)
117 {
118         assert(i>=0 && i<link_count());
119
120         if(i==0)
121         {
122                 angle_=x;
123                 signal_child_changed()(i);signal_value_changed()();
124                 return true;
125         }
126         if(i==1)
127         {
128                 amp_=x;
129                 signal_child_changed()(i);signal_value_changed()();
130                 return true;
131         }
132         return false;
133 }
134
135 ValueNode::LooseHandle
136 ValueNode_Sine::get_link_vfunc(int i)const
137 {
138         assert(i>=0 && i<link_count());
139
140         if(i==0)
141                 return angle_;
142         if(i==1)
143                 return amp_;
144
145         return 0;
146 }
147
148 int
149 ValueNode_Sine::link_count()const
150 {
151         return 2;
152 }
153
154 String
155 ValueNode_Sine::link_name(int i)const
156 {
157         assert(i>=0 && i<link_count());
158
159         if(i==0)
160                 return "angle";
161         if(i==1)
162                 return "amp";
163         return String();
164 }
165
166 String
167 ValueNode_Sine::link_local_name(int i)const
168 {
169         assert(i>=0 && i<link_count());
170
171         if(i==0)
172                 return _("Angle");
173         if(i==1)
174                 return _("Amplitude");
175         return String();
176 }
177
178 int
179 ValueNode_Sine::get_link_index_from_name(const String &name)const
180 {
181         if(name=="angle")
182                 return 0;
183         if(name=="amp")
184                 return 1;
185
186         throw Exception::BadLinkName(name);
187 }