libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moEffectState.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moEffectState.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moEffectState.h"
33 #include <tinyxml.h>
34 #include "moDebugManager.h"
35 
37  Init();
38 }
39 
41 }
42 
43 
45  (*this) = src;
46 }
47 
50 
52  m_Selected = src.m_Selected;
53  on = src.on;
54  synchronized = src.synchronized;
55  enabled = src.enabled;
56  magnitude = src.magnitude;
57  amplitude = src.amplitude;
58  alpha = src.alpha;
59 
60  tintr = src.tintr;
61  tintg = src.tintg;
62  tintb = src.tintb;
63 
64  tint = src.tint;
65  tintc = src.tintc;
66  tints = src.tints;
67 
68  stereo = src.stereo;
69  stereoside = src.stereoside;
70  fulldebug = src.fulldebug;
71 
72  tempo = src.tempo;
73 
74  return (*this);
75 }
76 
79 
81  synchronized = MO_ACTIVATED;
83  magnitude = 1.0;
84  amplitude = 1.0;
85  alpha = 1.0;
86 
87  tintr = 1.0;
88  tintg = 1.0;
89  tintb = 1.0;
90 
91  tint = 1.0;
92  tintc = 0.0;
93  tints = 0.0;
94 
98 
99  tempo.Init();
100 
101  return true;
102 }
103 
104 MOboolean
106 
107  Init();
108  fulldebug = D;
109 
110  return true;
111 }
112 
113 
115  tintr = r;
116  tintr = g;
117  tintr = b;
118 }
119 
121  tintc = c;
122  tints = s;
123  tint = t;
124  CSV2RGB();
125 }
126 
127 void
129  short C,S,V;
130 
131  C= (short)((float)tintc * (float)360);
132  if (C>360) C=360;
133  if (C<0) C = 0;
134 
135 
136  S = (short)((float)tints * (float)255);
137  if (S>255) S=255;
138  if (S<0) S = 0;
139 
140  V = (short)((float)tint * (float)255);
141  if (V>255) V=255;
142  if (V<0) V = 0;
143 
144  HSVtoRGB( C, S, V, &tintr, &tintg, &tintb);
145 
146 }
147 
148 const moText&
150 
151  moText fieldSeparation = ",";
152 
158  fullJSON = "{";
159  fullJSON+= "'activated': '"+IntToStr(m_Activated)+"'";
160  fullJSON+= fieldSeparation+"'selected': '"+IntToStr(m_Selected)+"'";
161 
162  fullJSON+= fieldSeparation+ "'tempo': {";
163  fullJSON+= "'tempo': '"+FloatToStr(tempo.getTempo())+"'";
164  fullJSON+= fieldSeparation+ "'syncro': '"+FloatToStr(tempo.syncro)+"'";
165  fullJSON+= fieldSeparation+ "'delta': '"+FloatToStr(tempo.delta)+"'";
166  fullJSON+= fieldSeparation+ "'duration': '"+IntToStr(tempo.Duration())+"'";
167  fullJSON+= fieldSeparation+ "'state': '"+tempo.StateToStr()+"'";
168  fullJSON+= fieldSeparation+ "'started': '"+IntToStr(tempo.Started())+"'";
169  fullJSON+= fieldSeparation+ "'factor': '"+FloatToStr(tempo.factor)+"'";
170 
171  fullJSON+= fieldSeparation+"'globaltimer_state': '" + moGetTimerStateStr() + "'";
172  fullJSON+= fieldSeparation+"'globaltimer_duration': '" + IntToStr(moGetDuration())+"'";
173 
174  fullJSON+= "}";
178  fullJSON+= fieldSeparation + "'on': '"+IntToStr(on)+"'";
179  fullJSON+= fieldSeparation + "'synchronized': '"+IntToStr(synchronized)+"'";
180 
181  fullJSON+= fieldSeparation + "'enabled': '"+IntToStr(enabled)+"'";
182 
184  fullJSON+= fieldSeparation + "'magnitude': '"+FloatToStr(magnitude)+"'";
185  fullJSON+= fieldSeparation + "'amplitude': '"+FloatToStr(amplitude)+"'";
186 
188  fullJSON+= fieldSeparation + "'alpha': '"+FloatToStr(alpha)+"'";
189  fullJSON+= fieldSeparation + "'tint': '"+FloatToStr(tint)+"'";
190  fullJSON+= fieldSeparation + "'tintr': '"+FloatToStr(tintr)+"'";
191  fullJSON+= fieldSeparation + "'tintg': '"+FloatToStr(tintg)+"'";
192  fullJSON+= fieldSeparation + "'tintb': '"+FloatToStr(tintb)+"'";
193  fullJSON+= fieldSeparation + "'tintc': '"+FloatToStr(tintc)+"'";
194  fullJSON+= fieldSeparation + "'tints': '"+FloatToStr(tints)+"'";
195 
196  fullJSON+= fieldSeparation + "'stereo': '"+IntToStr(stereo)+"'";
197  fullJSON+= fieldSeparation + "'stereoside': '"+IntToStr(stereoside)+"'";
198 
199  fullJSON+= fieldSeparation + "'fulldebug': '"+IntToStr(fulldebug)+"'";
200 
201  fullJSON+= "}";
202  //cout << fullJSON << endl;
203  return fullJSON;
204 }
205 
206 
207 const moText&
209 
210  moText fieldSeparation = " ";
211 
217  fullXML = "<moEffectState ";
218  fullXML+= "Activated='"+IntToStr(m_Activated)+"'";
219  fullXML+= fieldSeparation+"Selected='"+IntToStr(m_Selected)+"'";
220 
224  fullXML+= fieldSeparation + "on='"+IntToStr(on)+"'";
225  fullXML+= fieldSeparation + "synchronized='"+IntToStr(synchronized)+"'";
226 
227  fullXML+= fieldSeparation + "enabled='"+IntToStr(enabled)+"'";
228 
230  fullXML+= fieldSeparation + "magnitude='"+FloatToStr(magnitude)+"'";
231  fullXML+= fieldSeparation + "amplitude='"+FloatToStr(amplitude)+"'";
232 
234  fullXML+= fieldSeparation + "alpha='"+FloatToStr(alpha)+"'";
235  fullXML+= fieldSeparation + "tint='"+FloatToStr(tint)+"'";
236  fullXML+= fieldSeparation + "tintr='"+FloatToStr(tintr)+"'";
237  fullXML+= fieldSeparation + "tintg='"+FloatToStr(tintg)+"'";
238  fullXML+= fieldSeparation + "tintb='"+FloatToStr(tintb)+"'";
239  fullXML+= fieldSeparation + "tintc='"+FloatToStr(tintc)+"'";
240  fullXML+= fieldSeparation + "tints='"+FloatToStr(tints)+"'";
241 
242  fullXML+= fieldSeparation + "stereo='"+IntToStr(stereo)+"'";
243  fullXML+= fieldSeparation + "stereoside='"+IntToStr(stereoside)+"'";
244 
245  fullXML+= fieldSeparation + "fulldebug='"+IntToStr(fulldebug)+"' >";
246 
247 
248  fullXML+= fieldSeparation+ "<moTempo ";
249  fullXML+= "tempo='"+FloatToStr(tempo.getTempo())+"'";
250  fullXML+= fieldSeparation+ "syncro='"+FloatToStr(tempo.syncro)+"'";
251  fullXML+= fieldSeparation+ "delta='"+FloatToStr(tempo.delta)+"'";
252  fullXML+= fieldSeparation+ "duration='"+IntToStr(tempo.Duration())+"'";
253  fullXML+= fieldSeparation+ "state='"+tempo.StateToStr()+"'";
254  fullXML+= fieldSeparation+ "started='"+IntToStr(tempo.Started())+"'";
255  fullXML+= fieldSeparation+ "factor='"+FloatToStr(tempo.factor)+"'";
256 
257  fullXML+= fieldSeparation+"globaltimer_state='" + moGetTimerStateStr() + "'";
258  fullXML+= fieldSeparation+"globaltimer_duration='" + IntToStr(moGetDuration())+"' >";
259  fullXML+= "</moTempo>";
260 
261 
262  fullXML+= "</moEffectState>";
263  //cout << fullJSON << endl;
264  return fullXML;
265 }
266 
267 
268 
269 int
270 moEffectState::Set( const moText& p_XmlText ) {
271 
272  TiXmlDocument m_XMLDoc;
273  //TiXmlHandle xmlHandle( &m_XMLDoc );
274  TiXmlEncoding xencoding = TIXML_ENCODING_LEGACY;
275 
276  m_XMLDoc.Parse((const char*) p_XmlText, 0, xencoding );
278  //TiXmlElement* rootKey = m_XMLDoc.FirstChildElement( "D" );
279  TiXmlElement* effectStateNode = m_XMLDoc.FirstChildElement("moEffectState");
280 
281  //if (rootKey) {
282 
283  //TiXmlElement* sceneStateNode = rootKey->FirstChildElement("moSceneState");
284  if (effectStateNode) {
285  m_Activated = atoi( effectStateNode->Attribute("Activated") );
286  m_Selected = atoi( effectStateNode->Attribute("Selected") );
287  on = atoi( effectStateNode->Attribute("on") );
288  synchronized = atoi( effectStateNode->Attribute("synchronized") );
289  alpha = atof( effectStateNode->Attribute("alpha") );
290  tint = atof( effectStateNode->Attribute("tint") );
291  tintb = atof( effectStateNode->Attribute("tintb") );
292  tintc = atof( effectStateNode->Attribute("tintc") );
293  tintg = atof( effectStateNode->Attribute("tintg") );
294  tintr = atof( effectStateNode->Attribute("tintr") );
295  tints = atof( effectStateNode->Attribute("tints") );
296 
297  TiXmlElement* keyNode = effectStateNode->FirstChildElement("moTempo");
298  if(keyNode) {
299 
300  tempo.ang = atof(moText( keyNode->Attribute("tempo") ));
301  tempo.syncro = atof( moText( keyNode->Attribute("syncro") ) );
302  tempo.delta = atof( moText( keyNode->Attribute("delta") ) );
303  tempo.duration = atoi( moText( keyNode->Attribute("duration") ) );
304  tempo.state_str = moText( keyNode->Attribute("state") );
305  tempo.factor = atof( moText( keyNode->Attribute("factor") ) );
306  if (atoi( moText( keyNode->Attribute("started") ) ) == 1 ) {
307  if (tempo.Paused()) tempo.Continue();
308  else if (!tempo.Started()) tempo.Start();
309 
310  //if (tempo.state_str=="")
311  }
312 
313  //tempo.factor = atoi( moText( keyNode->Attribute("globaltimer_state") ) );
314  //tempo.factor = atoi( moText( keyNode->Attribute("globaltimer_duration") ) );
315 
316 
317  }
318  return 0;
319  } else moDebugManager::Log( "No XML moEffectState in: " + p_XmlText );
320 
321  //} else moDebugManager::Error();
322  return -1;
323 }
moEffectState & operator=(const moEffectState &src)
MOswitch m_Activated
virtual void Start()
Inicia el temporizador.
Definition: moTimer.cpp:196
MOswitch stereo
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
void SetColorRGB(MOfloat r, MOfloat g, MOfloat b)
#define MOboolean
Definition: moTypes.h:385
moStereoSides stereoside
MOswitch enabled
Definition: moEffectState.h:85
MOulong moGetDuration()
Devuelve el valor del reloj del temporizador global.
Definition: moTimer.cpp:134
moText state_str
Definition: moTimer.h:305
LIBMOLDEO_API void HSVtoRGB(short iInHue, short iInSaturation, short iInValue, float *piRed, float *piGreen, float *piBlue)
Definition: moTypes.cpp:51
virtual const moText & ToXML()
MOdouble syncro
Syncronización o factor fraccionario, 1.0 predeterminado, sino KX donde K puede ser fraccional (un núme...
Definition: moTempo.h:79
#define MOswitch
Definition: moTypes.h:386
#define MOfloat
Definition: moTypes.h:403
MOdouble delta
variacion de frecuencia entre 0X y 2X, delta es real
Definition: moTempo.h:69
virtual ~moEffectState()
clase de para manejar textos
Definition: moText.h:75
MOboolean Init()
Definition: moTempo.cpp:72
virtual const moText & StateToStr()
Definition: moTimer.h:277
static void Log(moText p_text)
Escribe un mensaje en el archivo de registro (log)
moText0 moText
Definition: moText.h:291
MOboolean Init()
Inicializa el objeto.
MOdouble getTempo()
Definition: moTempo.cpp:153
MOswitch synchronized
Definition: moEffectState.h:77
MOswitch m_Selected
#define MO_DEACTIVATED
Definition: moTypes.h:368
MOdouble factor
Multiplicador a partir de 2X hasta KX, donde K en principio es entero.
Definition: moTempo.h:76
void Continue()
Prosigue el temporizador.
Definition: moTimer.h:239
bool Paused() const
Devuelve el estado en pausa del cronómetro.
Definition: moTimer.h:257
MOswitch fulldebug
saturación
virtual long Duration()
Devuelve el valor del reloj del temporizador.
Definition: moTempo.cpp:146
MOfloat amplitude
Definition: moEffectState.h:88
moText moGetTimerStateStr()
Definition: moTimer.cpp:147
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
bool Started() const
Devuelve el estado del temporizador.
Definition: moTimer.h:248
void SetColorCSV(MOfloat c, MOfloat s, MOfloat t)
#define MO_ACTIVATED
Definition: moTypes.h:367
int Set(const moText &p_XmlText)
MOdouble ang
Definition: moTempo.h:81
MOfloat magnitude
Definition: moEffectState.h:87
virtual const moText & ToJSON()