PageRenderTime 28ms CodeModel.GetById 2ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/visualizations/XBMCProjectM/libprojectM/projectM.hpp

http://github.com/xbmc/xbmc
C++ Header | 316 lines | 177 code | 68 blank | 71 comment | 0 complexity | 69d406ee3716df56163c78b86b578b13 MD5 | raw file
  1/*
  2 * projectM -- Milkdrop-esque visualisation SDK
  3 * Copyright (C)2003-2007 projectM Team
  4 *
  5 * This library is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU Lesser General Public
  7 * License as published by the Free Software Foundation; either
  8 * version 2.1 of the License, or (at your option) any later version.
  9 *
 10 * This library is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13 * Lesser General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU Lesser General Public
 16 * License along with this library; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18 * See 'LICENSE.txt' included within this release
 19 *
 20 */
 21/**
 22 * $Id: projectM.hpp,v 1.1.1.1 2005/12/23 18:05:11 psperl Exp $
 23 *
 24 * Encapsulation of ProjectM engine
 25 *
 26 * $Log$
 27 */
 28
 29#ifndef _PROJECTM_H
 30#define _PROJECTM_H
 31
 32#ifdef WIN32
 33#include "win32-dirent.h"
 34#else
 35#include <dirent.h>
 36#endif /** WIN32 */
 37#include <math.h>
 38#include <stdio.h>
 39#include <string.h>
 40#include <string>
 41#include <stdlib.h>
 42#ifndef WIN32
 43#include <unistd.h>
 44#endif
 45#include <sys/types.h>
 46
 47#ifdef MACOS
 48//#include <MacWindows.h>
 49//#include <gl.h>
 50//#include <glu.h>
 51#else
 52#ifdef WIN32
 53#include <windows.h>
 54#endif /** WIN32 */
 55
 56#endif /** MACOS */
 57#ifdef WIN322
 58#define inline
 59#endif /** WIN32 */
 60
 61#include "dlldefs.h"
 62#include "event.h"
 63#include "fatal.h"
 64#include "PresetFrameIO.hpp"
 65#include "PCM.hpp"
 66#include "pthread.h"
 67
 68#include <memory>
 69
 70class BeatDetect;
 71class PCM;
 72class Func;
 73class Renderer;
 74class Preset;
 75class PresetIterator;
 76class PresetChooser;
 77class PresetLoader;
 78class TimeKeeper;
 79
 80#include <memory>
 81#ifdef WIN32
 82#pragma warning (disable:4244)
 83#pragma warning (disable:4305)
 84#endif /** WIN32 */
 85
 86#ifdef MACOS2
 87#define inline
 88#endif
 89
 90/** KEEP THIS UP TO DATE! */
 91#define PROJECTM_VERSION "1.1.00"
 92#define PROJECTM_TITLE "projectM 1.1.00"
 93
 94/** Interface types */
 95typedef enum {
 96    MENU_INTERFACE,
 97    SHELL_INTERFACE,
 98    EDITOR_INTERFACE,
 99    DEFAULT_INTERFACE,
100    BROWSER_INTERFACE
101  } interface_t;
102
103/// A functor class that allows users of this library to specify random preset behavior
104class RandomizerFunctor {
105
106   public:
107	//RandomizerFunctor(); 
108	RandomizerFunctor(PresetChooser & chooser) ;
109	virtual ~RandomizerFunctor();
110   	virtual double operator() (int index);
111   private:
112	const PresetChooser & m_chooser;
113};
114
115
116class projectM 
117{
118public:
119	static const int FLAG_NONE = 0;
120	static const int FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0;
121
122        struct Settings {
123          int meshX;
124          int meshY;
125          int fps;
126          int textureSize;
127          int windowWidth;
128          int windowHeight;
129          int windowLeft;
130          int windowBottom;
131          std::string presetURL;
132          std::string titleFontURL;
133          std::string menuFontURL;
134          int smoothPresetDuration;
135          int presetDuration;
136          float beatSensitivity;
137          bool aspectCorrection;
138          float easterEgg;
139          bool shuffleEnabled;
140          bool useFBO;
141        };
142	
143  DLLEXPORT projectM(Settings config_pm, int flags = FLAG_NONE);
144  
145  //DLLEXPORT projectM(int gx, int gy, int fps, int texsize, int width, int height,std::string preset_url,std::string title_fonturl, std::string title_menuurl);
146  
147  DLLEXPORT void projectM_resetGL( int width, int height );
148  DLLEXPORT void projectM_resetTextures();
149  DLLEXPORT void projectM_setTitle( std::string title );
150  DLLEXPORT void renderFrame();
151  DLLEXPORT unsigned initRenderToTexture(); 
152  DLLEXPORT void key_handler( projectMEvent event,
153		    projectMKeycode keycode, projectMModifier modifier );
154
155  DLLEXPORT virtual ~projectM();
156
157  
158
159  DLLEXPORT const Settings & settings() const {
160		return _settings;
161  }
162
163  /// Sets preset iterator position to the passed in index
164  void selectPresetPosition(unsigned int index);
165
166  /// Plays a preset immediately  
167  void selectPreset(unsigned int index);
168
169  /// Removes a preset from the play list. If it is playing then it will continue as normal until next switch
170  void removePreset(unsigned int index);
171 
172  /// Sets the randomization functor. If set to null, the traversal will move in order according to the playlist
173  void setRandomizer(RandomizerFunctor * functor);
174 
175  /// Tell projectM to play a particular preset when it chooses to switch
176  /// If the preset is locked the queued item will be not switched to until the lock is released
177  /// Subsequent calls to this function effectively nullifies previous calls.
178  void queuePreset(unsigned int index);
179
180  /// Returns true if a preset is queued up to play next
181  bool isPresetQueued() const;
182
183  /// Removes entire playlist, The currently loaded preset will end up sticking until new presets are added
184  void clearPlaylist();
185
186  /// Turn on or off a lock that prevents projectM from switching to another preset
187  void setPresetLock(bool isLocked);
188
189  /// Returns true if the active preset is locked
190  bool isPresetLocked() const;
191
192  /// Returns index of currently active preset. In the case where the active
193  /// preset was removed from the playlist, this function will return the element
194  /// before active preset (thus the next in order preset is invariant with respect
195  /// to the removal)
196  bool selectedPresetIndex(unsigned int & index) const;
197
198  /// Add a preset url to the play list. Appended to bottom. Returns index of preset
199  unsigned int addPresetURL(const std::string & presetURL, const std::string & presetName, int rating);
200
201  /// Insert a preset url to the play list at the suggested index.
202  void insertPresetURL(unsigned int index, 
203			       const std::string & presetURL, const std::string & presetName, int rating);
204 
205  /// Returns true if the selected preset position points to an actual preset in the
206  /// currently loaded playlist
207  bool presetPositionValid() const;
208  
209  /// Returns the url associated with a preset index
210  std::string getPresetURL(unsigned int index) const;
211
212  /// Returns the preset name associated with a preset index
213  std::string getPresetName ( unsigned int index ) const;
214
215  /// Returns the rating associated with a preset index
216  int getPresetRating (unsigned int index) const;
217  
218  void changePresetRating (unsigned int index, int rating);
219
220  /// Returns the size of the play list
221  unsigned int getPlaylistSize() const;
222
223  void evaluateSecondPreset();
224
225  inline void setShuffleEnabled(bool value)
226  {
227	  _settings.shuffleEnabled = value;
228			
229	/// idea@ call a virtualfunction shuffleChanged()
230  }
231
232  
233  inline bool isShuffleEnabled() const
234  {
235	return _settings.shuffleEnabled;
236  }
237  
238  /// Occurs when active preset has switched. Switched to index is returned
239  virtual void presetSwitchedEvent(bool isHardCut, unsigned int index) const {};
240  virtual void shuffleEnabledValueChanged(bool isEnabled) const {};
241
242  
243  inline const PCM * pcm() {
244	  return _pcm;
245  }
246  void *thread_func(void *vptr_args);
247
248private:
249
250  double sampledPresetDuration();
251  BeatDetect * beatDetect;
252  Renderer *renderer;
253  Settings _settings;
254    
255  int wvw;      //windowed dimensions
256  int wvh;
257     
258  /** Timing information */
259  int mspf;
260  int timed;
261  int timestart;  
262  int count;
263  float fpsstart;
264  
265  void switchPreset(std::auto_ptr<Preset> & targetPreset, PresetInputs & inputs, PresetOutputs & outputs);
266  void readConfig(const Settings configpm);
267  void projectM_init(int gx, int gy, int fps, int texsize, int width, int height, int xpos, int ypos, bool useFBO);
268  void projectM_reset();
269
270  void projectM_initengine();
271  void projectM_resetengine();
272  /// Initializes preset loading / management libraries
273  int initPresetTools();
274  
275  /// Deinitialize all preset related tools. Usually done before projectM cleanup
276  void destroyPresetTools();
277
278  void default_key_handler( projectMEvent event, projectMKeycode keycode );
279  void setupPresetInputs(PresetInputs *inputs);
280  /// The current position of the directory iterator
281  PresetIterator * m_presetPos;
282  
283  /// Required by the preset chooser. Manages a loaded preset directory
284  PresetLoader * m_presetLoader;
285  
286  /// Provides accessor functions to choose presets
287  PresetChooser * m_presetChooser;
288  
289  /// Currently loaded preset
290  std::auto_ptr<Preset> m_activePreset;
291  
292  /// Destination preset when smooth preset switching
293  std::auto_ptr<Preset> m_activePreset2;
294    
295  /// All readonly variables which are passed as inputs to presets
296  PresetInputs presetInputs;
297  PresetInputs presetInputs2;
298  /// A preset outputs container used and modified by the "current" preset
299  PresetOutputs presetOutputs;
300  
301  /// A preset outputs container used for smooth preset switching
302  PresetOutputs presetOutputs2;
303  
304  TimeKeeper *timeKeeper;
305
306  PCM * _pcm;
307  int m_flags;
308  
309
310pthread_mutex_t mutex;
311pthread_cond_t  condition;
312pthread_t thread;
313  bool running;
314
315};
316#endif