PageRenderTime 56ms CodeModel.GetById 13ms app.highlight 38ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/visualizations/XBMCProjectM/libprojectM/Preset.hpp

http://github.com/xbmc/xbmc
C++ Header | 248 lines | 126 code | 63 blank | 59 comment | 10 complexity | 70b9c43c6097ee510221ede0419c146a MD5 | raw file
  1
  2/**
  3 * projectM -- Milkdrop-esque visualisation SDK
  4 * Copyright (C)2003-2007 projectM Team
  5 *
  6 * This library is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU Lesser General Public
  8 * License as published by the Free Software Foundation; either
  9 * version 2.1 of the License, or (at your option) any later version.
 10 *
 11 * This library is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 * Lesser General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU Lesser General Public
 17 * License along with this library; if not, write to the Free Software
 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19 * See 'LICENSE.txt' included within this release
 20 *
 21 */
 22/**
 23 * $Id$
 24 *
 25 * Preset
 26 *
 27 * $Log$
 28 */
 29
 30#ifndef _PRESET_HPP
 31#define _PRESET_HPP
 32
 33#include "Common.hpp"
 34#include <string>
 35#include <cassert>
 36#include <map>
 37
 38#define PRESET_DEBUG 0 /* 0 for no debugging, 1 for normal, 2 for insane */
 39
 40#include "CustomShape.hpp"
 41#include "CustomWave.hpp"
 42#include "Expr.hpp"
 43#include "PerPixelEqn.hpp"
 44#include "PerFrameEqn.hpp"
 45#include "BuiltinParams.hpp"
 46#include "PresetFrameIO.hpp"
 47#include "InitCond.hpp"
 48
 49class CustomWave;
 50class CustomShape;
 51class InitCond;
 52
 53
 54class Preset
 55{
 56protected:
 57
 58public:
 59
 60
 61  ///  Load a preset by filename with input and output buffers specified.
 62  /// \param absoluteFilePath the absolute file path of a preset to load from the file system
 63  /// \param presetName a descriptive name for the preset. Usually just the file name
 64  /// \param presetInputs a reference to read only projectM engine variables
 65  /// \param presetOutputs initialized and filled with data parsed from a preset
 66  Preset(const std::string & absoluteFilePath, const std::string & presetName, PresetInputs & presetInputs, PresetOutputs & presetOutputs);
 67
 68  ///  Load a preset from an input stream with input and output buffers specified.
 69  /// \param in an already initialized input stream to read the preset file from
 70  /// \param presetName a descriptive name for the preset. Usually just the file name
 71  /// \param presetInputs a reference to read only projectM engine variables
 72  /// \param presetOutputs initialized and filled with data parsed from a preset
 73  Preset(std::istream & in, const std::string & presetName, PresetInputs & presetInputs, PresetOutputs & presetOutputs);
 74
 75  ~Preset();
 76
 77  /// Evaluates the preset for a frame given the current values of preset inputs / outputs
 78  /// All calculated values are stored in the associated preset outputs instance
 79  void evaluateFrame();
 80
 81  /// All "builtin" parameters for this preset. Anything *but* user defined parameters and
 82  /// custom waves / shapes objects go here.
 83  /// @bug encapsulate
 84  BuiltinParams builtinParams;
 85
 86  
 87  /// Used by parser to find/create custom waves and shapes. May be refactored
 88  template <class CustomObject>
 89  static CustomObject * find_custom_object(int id, std::vector<CustomObject*> & customObjects);
 90
 91  
 92  int per_pixel_eqn_string_index;
 93  int per_frame_eqn_string_index;
 94  int per_frame_init_eqn_string_index;
 95
 96  int per_frame_eqn_count,
 97  per_frame_init_eqn_count;
 98
 99  
100  /// Used by parser
101  /// @bug refactor
102  int add_per_pixel_eqn( char *name, GenExpr *gen_expr );
103
104  /// Accessor method to retrieve the absolute file path of the loaded preset
105  /// \returns a file path string 
106  std::string absoluteFilePath() const
107  {
108    return m_absoluteFilePath;
109  }
110
111
112  /// Accessor method for the preset outputs instance associated with this preset
113  /// \returns A preset output instance with values computed from most recent evaluateFrame()
114  PresetOutputs & presetOutputs() const
115  {
116
117    return m_presetOutputs;
118  }
119
120  PresetInputs & presetInputs() const
121  {
122
123    return m_presetInputs;
124  }
125    /// Sets the descriptive name for this preset (typically the file name)
126    /// \param theValue the new preset name to assign to the preset
127	void setPresetName ( const std::string& theValue )
128	{
129		m_presetName = theValue;
130	}
131	
132
133	/// Gets the descriptive name for this preset (typically the file name)
134	/// \returns the name of the preset
135	std::string presetName() const
136	{
137		return m_presetName;
138	}
139
140
141  /// @bug encapsulate
142	
143  PresetOutputs::cwave_container customWaves;
144  PresetOutputs::cshape_container customShapes;
145
146  /// @bug encapsulate
147  /* Data structures that contain equation and initial condition information */
148  std::vector<PerFrameEqn*>  per_frame_eqn_tree;   /* per frame equations */
149  std::map<int, PerPixelEqn*>  per_pixel_eqn_tree; /* per pixel equation tree */
150  std::map<std::string,InitCond*>  per_frame_init_eqn_tree; /* per frame initial equations */
151  std::map<std::string,InitCond*>  init_cond_tree; /* initial conditions */
152  std::map<std::string,Param*> user_param_tree; /* user parameter splay tree */
153
154private:
155
156  // The absolute file path of the preset
157  std::string m_absoluteFilePath;
158
159  // The absolute path of the preset
160  std::string m_absolutePath;
161
162  // The name for the preset. Usually the file name, but in theory anything goes
163  std::string m_presetName;
164
165  void initialize(const std::string & pathname);
166  void initialize(std::istream & in);
167
168  int loadPresetFile(const std::string & pathname);
169
170  void loadBuiltinParamsUnspecInitConds();
171  void loadCustomWaveUnspecInitConds();
172  void loadCustomShapeUnspecInitConds();
173
174  void evalCustomWavePerFrameEquations();
175  void evalCustomShapePerFrameEquations();
176  void evalPerFrameInitEquations();
177  void evalCustomWaveInitConditions();
178  void evalCustomShapeInitConditions();
179  void evalPerPixelEqns();
180  void evalPerFrameEquations();
181  void initialize_PerPixelMeshes();
182  int readIn(std::istream & fs);
183
184  void preloadInitialize();
185  void postloadInitialize();
186
187  PresetOutputs & m_presetOutputs;
188  PresetInputs & m_presetInputs; // added for gx, gy reference.
189
190template <class CustomObject>
191void transfer_q_variables(std::vector<CustomObject*> & customObjects);
192};
193
194
195template <class CustomObject>
196void Preset::transfer_q_variables(std::vector<CustomObject*> & customObjects)
197{
198 	CustomObject * custom_object;
199
200	for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin(); pos != customObjects.end();++pos) {
201	
202		custom_object = *pos;
203		custom_object->q1 = m_presetOutputs.q1;
204		custom_object->q2 = m_presetOutputs.q2;
205		custom_object->q3 = m_presetOutputs.q3;
206		custom_object->q4 = m_presetOutputs.q4;
207		custom_object->q5 = m_presetOutputs.q5;
208		custom_object->q6 = m_presetOutputs.q6;
209		custom_object->q7 = m_presetOutputs.q7;
210		custom_object->q8 = m_presetOutputs.q8;
211	}
212 
213
214}
215
216template <class CustomObject>
217CustomObject * Preset::find_custom_object(int id, std::vector<CustomObject*> & customObjects)
218{
219
220  CustomObject * custom_object = NULL;
221
222
223  for (typename std::vector<CustomObject*>::iterator pos = customObjects.begin(); pos != customObjects.end();++pos) {
224	if ((*pos)->id == id) {
225		custom_object = *pos;
226		break;
227	}
228  }
229
230  if (custom_object == NULL)
231  {
232
233    if ((custom_object = new CustomObject(id)) == NULL)
234    {
235      return NULL;
236    }
237
238      customObjects.push_back(custom_object);
239
240  }
241
242  assert(custom_object);
243  return custom_object;
244}
245
246
247
248#endif /** !_PRESET_HPP */