libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
moEffectState.cpp
Ir a la documentación de este archivo.
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  mousex = src.mousex;
75  mousey = src.mousey;
77 
78  return (*this);
79 }
80 
83 
85  synchronized = MO_ACTIVATED;
87  magnitude = 1.0;
88  amplitude = 1.0;
89  alpha = 1.0;
90 
91  tintr = 1.0;
92  tintg = 1.0;
93  tintb = 1.0;
94 
95  tint = 1.0;
96  tintc = 0.0;
97  tints = 0.0;
98 
102 
103  tempo.Init();
104 
105  mousex = 0.0;
106  mousey = 0.0;
107  mousefactor = 0.0;
108 
109  return true;
110 }
111 
112 MOboolean
114 
115  Init();
116  fulldebug = D;
117 
118  return true;
119 }
120 
121 
123  tintr = r;
124  tintr = g;
125  tintr = b;
126 }
127 
129  tintc = c;
130  tints = s;
131  tint = t;
132  CSV2RGB();
133 }
134 
135 void
137  short C,S,V;
138 
139  C= (short)((float)tintc * (float)360);
140  if (C>360) C=360;
141  if (C<0) C = 0;
142 
143 
144  S = (short)((float)tints * (float)255);
145  if (S>255) S=255;
146  if (S<0) S = 0;
147 
148  V = (short)((float)tint * (float)255);
149  if (V>255) V=255;
150  if (V<0) V = 0;
151 
152  HSVtoRGB( C, S, V, &tintr, &tintg, &tintb);
153 
154 }
155 
156 const moText&
158 
159  moText fieldSeparation = ",";
160 
166  fullJSON = "{";
167  fullJSON+= "'activated': '"+IntToStr(m_Activated)+"'";
168  fullJSON+= fieldSeparation+"'selected': '"+IntToStr(m_Selected)+"'";
169 
170  fullJSON+= fieldSeparation+ "'tempo': {";
171  fullJSON+= "'tempo': '"+FloatToStr(tempo.getTempo())+"'";
172  fullJSON+= fieldSeparation+ "'syncro': '"+FloatToStr(tempo.syncro)+"'";
173  fullJSON+= fieldSeparation+ "'delta': '"+FloatToStr(tempo.delta)+"'";
174  fullJSON+= fieldSeparation+ "'duration': '"+IntToStr(tempo.Duration())+"'";
175  fullJSON+= fieldSeparation+ "'state': '"+tempo.StateToStr()+"'";
176  fullJSON+= fieldSeparation+ "'started': '"+IntToStr(tempo.Started())+"'";
177  fullJSON+= fieldSeparation+ "'factor': '"+FloatToStr(tempo.factor)+"'";
178 
179  fullJSON+= fieldSeparation+"'globaltimer_state': '" + moGetTimerStateStr() + "'";
180  fullJSON+= fieldSeparation+"'globaltimer_duration': '" + IntToStr(moGetDuration())+"'";
181 
182  fullJSON+= "}";
186  fullJSON+= fieldSeparation + "'on': '"+IntToStr(on)+"'";
187  fullJSON+= fieldSeparation + "'synchronized': '"+IntToStr(synchronized)+"'";
188 
189  fullJSON+= fieldSeparation + "'enabled': '"+IntToStr(enabled)+"'";
190 
192  fullJSON+= fieldSeparation + "'magnitude': '"+FloatToStr(magnitude)+"'";
193  fullJSON+= fieldSeparation + "'amplitude': '"+FloatToStr(amplitude)+"'";
194 
196  fullJSON+= fieldSeparation + "'alpha': '"+FloatToStr(alpha)+"'";
197  fullJSON+= fieldSeparation + "'tint': '"+FloatToStr(tint)+"'";
198  fullJSON+= fieldSeparation + "'tintr': '"+FloatToStr(tintr)+"'";
199  fullJSON+= fieldSeparation + "'tintg': '"+FloatToStr(tintg)+"'";
200  fullJSON+= fieldSeparation + "'tintb': '"+FloatToStr(tintb)+"'";
201  fullJSON+= fieldSeparation + "'tintc': '"+FloatToStr(tintc)+"'";
202  fullJSON+= fieldSeparation + "'tints': '"+FloatToStr(tints)+"'";
203 
204  fullJSON+= fieldSeparation + "'stereo': '"+IntToStr(stereo)+"'";
205  fullJSON+= fieldSeparation + "'stereoside': '"+IntToStr(stereoside)+"'";
206 
207  fullJSON+= fieldSeparation + "'fulldebug': '"+IntToStr(fulldebug)+"'";
208  fullJSON+= fieldSeparation + "'mousex': '"+FloatToStr(mousex)+"'";
209  fullJSON+= fieldSeparation + "'mousey': '"+FloatToStr(mousey)+"'";
210  fullJSON+= fieldSeparation + "'mousefactor': '"+FloatToStr(mousefactor)+"'";
211 
212  fullJSON+= "}";
213  //cout << fullJSON << endl;
214  return fullJSON;
215 }
216 
217 
218 const moText&
220 
221  moText fieldSeparation = " ";
222 
228  fullXML = "<moEffectState ";
229  fullXML+= "Activated='"+IntToStr(m_Activated)+"'";
230  fullXML+= fieldSeparation+"Selected='"+IntToStr(m_Selected)+"'";
231 
235  fullXML+= fieldSeparation + "on='"+IntToStr(on)+"'";
236  fullXML+= fieldSeparation + "synchronized='"+IntToStr(synchronized)+"'";
237 
238  fullXML+= fieldSeparation + "enabled='"+IntToStr(enabled)+"'";
239 
241  fullXML+= fieldSeparation + "magnitude='"+FloatToStr(magnitude)+"'";
242  fullXML+= fieldSeparation + "amplitude='"+FloatToStr(amplitude)+"'";
243 
245  fullXML+= fieldSeparation + "alpha='"+FloatToStr(alpha)+"'";
246  fullXML+= fieldSeparation + "tint='"+FloatToStr(tint)+"'";
247  fullXML+= fieldSeparation + "tintr='"+FloatToStr(tintr)+"'";
248  fullXML+= fieldSeparation + "tintg='"+FloatToStr(tintg)+"'";
249  fullXML+= fieldSeparation + "tintb='"+FloatToStr(tintb)+"'";
250  fullXML+= fieldSeparation + "tintc='"+FloatToStr(tintc)+"'";
251  fullXML+= fieldSeparation + "tints='"+FloatToStr(tints)+"'";
252 
253  fullXML+= fieldSeparation + "stereo='"+IntToStr(stereo)+"'";
254  fullXML+= fieldSeparation + "stereoside='"+IntToStr(stereoside)+"'";
255 
256  fullXML+= fieldSeparation + "fulldebug='"+IntToStr(fulldebug)+"' >";
257 
258 
259  fullXML+= fieldSeparation+ "<moTempo ";
260  fullXML+= "tempo='"+FloatToStr(tempo.getTempo())+"'";
261  fullXML+= fieldSeparation+ "syncro='"+FloatToStr(tempo.syncro)+"'";
262  fullXML+= fieldSeparation+ "delta='"+FloatToStr(tempo.delta)+"'";
263  fullXML+= fieldSeparation+ "duration='"+IntToStr(tempo.Duration())+"'";
264  fullXML+= fieldSeparation+ "state='"+tempo.StateToStr()+"'";
265  fullXML+= fieldSeparation+ "started='"+IntToStr(tempo.Started())+"'";
266  fullXML+= fieldSeparation+ "factor='"+FloatToStr(tempo.factor)+"'";
267 
268  fullXML+= fieldSeparation+"globaltimer_state='" + moGetTimerStateStr() + "'";
269  fullXML+= fieldSeparation+"globaltimer_duration='" + IntToStr(moGetDuration())+"' >";
270  fullXML+= "</moTempo>";
271 
272 
273  fullXML+= "</moEffectState>";
274  //cout << fullJSON << endl;
275  return fullXML;
276 }
277 
278 
279 
280 int
281 moEffectState::Set( const moText& p_XmlText ) {
282 
283  TiXmlDocument m_XMLDoc;
284  //TiXmlHandle xmlHandle( &m_XMLDoc );
285  TiXmlEncoding xencoding = TIXML_ENCODING_LEGACY;
286 
287  m_XMLDoc.Parse((const char*) p_XmlText, 0, xencoding );
289  //TiXmlElement* rootKey = m_XMLDoc.FirstChildElement( "D" );
290  TiXmlElement* effectStateNode = m_XMLDoc.FirstChildElement("moEffectState");
291 
292  //if (rootKey) {
293 
294  //TiXmlElement* sceneStateNode = rootKey->FirstChildElement("moSceneState");
295  if (effectStateNode) {
296  m_Activated = atoi( effectStateNode->Attribute("Activated") );
297  m_Selected = atoi( effectStateNode->Attribute("Selected") );
298  on = atoi( effectStateNode->Attribute("on") );
299  synchronized = atoi( effectStateNode->Attribute("synchronized") );
300  alpha = atof( effectStateNode->Attribute("alpha") );
301  tint = atof( effectStateNode->Attribute("tint") );
302  tintb = atof( effectStateNode->Attribute("tintb") );
303  tintc = atof( effectStateNode->Attribute("tintc") );
304  tintg = atof( effectStateNode->Attribute("tintg") );
305  tintr = atof( effectStateNode->Attribute("tintr") );
306  tints = atof( effectStateNode->Attribute("tints") );
307 
308  TiXmlElement* keyNode = effectStateNode->FirstChildElement("moTempo");
309  if(keyNode) {
310 
311  tempo.ang = atof(moText( keyNode->Attribute("tempo") ));
312  tempo.syncro = atof( moText( keyNode->Attribute("syncro") ) );
313  tempo.delta = atof( moText( keyNode->Attribute("delta") ) );
314  tempo.duration = atoi( moText( keyNode->Attribute("duration") ) );
315  tempo.state_str = moText( keyNode->Attribute("state") );
316  tempo.factor = atof( moText( keyNode->Attribute("factor") ) );
317  if (atoi( moText( keyNode->Attribute("started") ) ) == 1 ) {
318  if (tempo.Paused()) tempo.Continue();
319  else if (!tempo.Started()) tempo.Start();
320 
321  //if (tempo.state_str=="")
322  }
323 
324  //tempo.factor = atoi( moText( keyNode->Attribute("globaltimer_state") ) );
325  //tempo.factor = atoi( moText( keyNode->Attribute("globaltimer_duration") ) );
326 
327 
328  }
329  return 0;
330  } else moDebugManager::Log( "No XML moEffectState in: " + p_XmlText );
331 
332  //} else moDebugManager::Error();
333  return -1;
334 }
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)
bool Started() const
Devuelve el estado del temporizador.
Definition: moTimer.h:248
#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ú...
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
MOfloat mousefactor
bool Paused() const
Devuelve el estado en pausa del cronómetro.
Definition: moTimer.h:257
void Continue()
Prosigue el temporizador.
Definition: moTimer.h:239
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
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()