/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. #ifndef _PROJECTM_H
  29. #define _PROJECTM_H
  30. #ifdef WIN32
  31. #include "win32-dirent.h"
  32. #else
  33. #include <dirent.h>
  34. #endif /** WIN32 */
  35. #include <math.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <string>
  39. #include <stdlib.h>
  40. #ifndef WIN32
  41. #include <unistd.h>
  42. #endif
  43. #include <sys/types.h>
  44. #ifdef MACOS
  45. //#include <MacWindows.h>
  46. //#include <gl.h>
  47. //#include <glu.h>
  48. #else
  49. #ifdef WIN32
  50. #include <windows.h>
  51. #endif /** WIN32 */
  52. #endif /** MACOS */
  53. #ifdef WIN322
  54. #define inline
  55. #endif /** WIN32 */
  56. #include "dlldefs.h"
  57. #include "event.h"
  58. #include "fatal.h"
  59. #include "PresetFrameIO.hpp"
  60. #include "PCM.hpp"
  61. #include "pthread.h"
  62. #include <memory>
  63. class BeatDetect;
  64. class PCM;
  65. class Func;
  66. class Renderer;
  67. class Preset;
  68. class PresetIterator;
  69. class PresetChooser;
  70. class PresetLoader;
  71. class TimeKeeper;
  72. #include <memory>
  73. #ifdef WIN32
  74. #pragma warning (disable:4244)
  75. #pragma warning (disable:4305)
  76. #endif /** WIN32 */
  77. #ifdef MACOS2
  78. #define inline
  79. #endif
  80. /** KEEP THIS UP TO DATE! */
  81. #define PROJECTM_VERSION "1.1.00"
  82. #define PROJECTM_TITLE "projectM 1.1.00"
  83. /** Interface types */
  84. typedef enum {
  85. MENU_INTERFACE,
  86. SHELL_INTERFACE,
  87. EDITOR_INTERFACE,
  88. DEFAULT_INTERFACE,
  89. BROWSER_INTERFACE
  90. } interface_t;
  91. /// A functor class that allows users of this library to specify random preset behavior
  92. class RandomizerFunctor {
  93. public:
  94. //RandomizerFunctor();
  95. RandomizerFunctor(PresetChooser & chooser) ;
  96. virtual ~RandomizerFunctor();
  97. virtual double operator() (int index);
  98. private:
  99. const PresetChooser & m_chooser;
  100. };
  101. class projectM
  102. {
  103. public:
  104. static const int FLAG_NONE = 0;
  105. static const int FLAG_DISABLE_PLAYLIST_LOAD = 1 << 0;
  106. struct Settings {
  107. int meshX;
  108. int meshY;
  109. int fps;
  110. int textureSize;
  111. int windowWidth;
  112. int windowHeight;
  113. int windowLeft;
  114. int windowBottom;
  115. std::string presetURL;
  116. std::string titleFontURL;
  117. std::string menuFontURL;
  118. int smoothPresetDuration;
  119. int presetDuration;
  120. float beatSensitivity;
  121. bool aspectCorrection;
  122. float easterEgg;
  123. bool shuffleEnabled;
  124. bool useFBO;
  125. };
  126. DLLEXPORT projectM(Settings config_pm, int flags = FLAG_NONE);
  127. //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);
  128. DLLEXPORT void projectM_resetGL( int width, int height );
  129. DLLEXPORT void projectM_resetTextures();
  130. DLLEXPORT void projectM_setTitle( std::string title );
  131. DLLEXPORT void renderFrame();
  132. DLLEXPORT unsigned initRenderToTexture();
  133. DLLEXPORT void key_handler( projectMEvent event,
  134. projectMKeycode keycode, projectMModifier modifier );
  135. DLLEXPORT virtual ~projectM();
  136. DLLEXPORT const Settings & settings() const {
  137. return _settings;
  138. }
  139. /// Sets preset iterator position to the passed in index
  140. void selectPresetPosition(unsigned int index);
  141. /// Plays a preset immediately
  142. void selectPreset(unsigned int index);
  143. /// Removes a preset from the play list. If it is playing then it will continue as normal until next switch
  144. void removePreset(unsigned int index);
  145. /// Sets the randomization functor. If set to null, the traversal will move in order according to the playlist
  146. void setRandomizer(RandomizerFunctor * functor);
  147. /// Tell projectM to play a particular preset when it chooses to switch
  148. /// If the preset is locked the queued item will be not switched to until the lock is released
  149. /// Subsequent calls to this function effectively nullifies previous calls.
  150. void queuePreset(unsigned int index);
  151. /// Returns true if a preset is queued up to play next
  152. bool isPresetQueued() const;
  153. /// Removes entire playlist, The currently loaded preset will end up sticking until new presets are added
  154. void clearPlaylist();
  155. /// Turn on or off a lock that prevents projectM from switching to another preset
  156. void setPresetLock(bool isLocked);
  157. /// Returns true if the active preset is locked
  158. bool isPresetLocked() const;
  159. /// Returns index of currently active preset. In the case where the active
  160. /// preset was removed from the playlist, this function will return the element
  161. /// before active preset (thus the next in order preset is invariant with respect
  162. /// to the removal)
  163. bool selectedPresetIndex(unsigned int & index) const;
  164. /// Add a preset url to the play list. Appended to bottom. Returns index of preset
  165. unsigned int addPresetURL(const std::string & presetURL, const std::string & presetName, int rating);
  166. /// Insert a preset url to the play list at the suggested index.
  167. void insertPresetURL(unsigned int index,
  168. const std::string & presetURL, const std::string & presetName, int rating);
  169. /// Returns true if the selected preset position points to an actual preset in the
  170. /// currently loaded playlist
  171. bool presetPositionValid() const;
  172. /// Returns the url associated with a preset index
  173. std::string getPresetURL(unsigned int index) const;
  174. /// Returns the preset name associated with a preset index
  175. std::string getPresetName ( unsigned int index ) const;
  176. /// Returns the rating associated with a preset index
  177. int getPresetRating (unsigned int index) const;
  178. void changePresetRating (unsigned int index, int rating);
  179. /// Returns the size of the play list
  180. unsigned int getPlaylistSize() const;
  181. void evaluateSecondPreset();
  182. inline void setShuffleEnabled(bool value)
  183. {
  184. _settings.shuffleEnabled = value;
  185. /// idea@ call a virtualfunction shuffleChanged()
  186. }
  187. inline bool isShuffleEnabled() const
  188. {
  189. return _settings.shuffleEnabled;
  190. }
  191. /// Occurs when active preset has switched. Switched to index is returned
  192. virtual void presetSwitchedEvent(bool isHardCut, unsigned int index) const {};
  193. virtual void shuffleEnabledValueChanged(bool isEnabled) const {};
  194. inline const PCM * pcm() {
  195. return _pcm;
  196. }
  197. void *thread_func(void *vptr_args);
  198. private:
  199. double sampledPresetDuration();
  200. BeatDetect * beatDetect;
  201. Renderer *renderer;
  202. Settings _settings;
  203. int wvw; //windowed dimensions
  204. int wvh;
  205. /** Timing information */
  206. int mspf;
  207. int timed;
  208. int timestart;
  209. int count;
  210. float fpsstart;
  211. void switchPreset(std::auto_ptr<Preset> & targetPreset, PresetInputs & inputs, PresetOutputs & outputs);
  212. void readConfig(const Settings configpm);
  213. void projectM_init(int gx, int gy, int fps, int texsize, int width, int height, int xpos, int ypos, bool useFBO);
  214. void projectM_reset();
  215. void projectM_initengine();
  216. void projectM_resetengine();
  217. /// Initializes preset loading / management libraries
  218. int initPresetTools();
  219. /// Deinitialize all preset related tools. Usually done before projectM cleanup
  220. void destroyPresetTools();
  221. void default_key_handler( projectMEvent event, projectMKeycode keycode );
  222. void setupPresetInputs(PresetInputs *inputs);
  223. /// The current position of the directory iterator
  224. PresetIterator * m_presetPos;
  225. /// Required by the preset chooser. Manages a loaded preset directory
  226. PresetLoader * m_presetLoader;
  227. /// Provides accessor functions to choose presets
  228. PresetChooser * m_presetChooser;
  229. /// Currently loaded preset
  230. std::auto_ptr<Preset> m_activePreset;
  231. /// Destination preset when smooth preset switching
  232. std::auto_ptr<Preset> m_activePreset2;
  233. /// All readonly variables which are passed as inputs to presets
  234. PresetInputs presetInputs;
  235. PresetInputs presetInputs2;
  236. /// A preset outputs container used and modified by the "current" preset
  237. PresetOutputs presetOutputs;
  238. /// A preset outputs container used for smooth preset switching
  239. PresetOutputs presetOutputs2;
  240. TimeKeeper *timeKeeper;
  241. PCM * _pcm;
  242. int m_flags;
  243. pthread_mutex_t mutex;
  244. pthread_cond_t condition;
  245. pthread_t thread;
  246. bool running;
  247. };
  248. #endif