/xbmc/visualizations/Vortex/VortexXBMC/VortexXBMC.cpp

http://github.com/xbmc/xbmc · C++ · 247 lines · 173 code · 31 blank · 43 comment · 63 complexity · fbdbb9f0fbfc1506e73dccc9ba67dcb8 MD5 · raw file

  1. /*
  2. * Copyright Š 2010-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include <windows.h>
  20. #include <io.h>
  21. #include <vector>
  22. #include "Vortex.h"
  23. #include "../../../addons/include/xbmc_vis_dll.h"
  24. #include "../../../addons/include/xbmc_addon_cpp_dll.h"
  25. Vortex* g_Vortex = NULL;
  26. // settings vector
  27. StructSetting** g_structSettings;
  28. extern "C" ADDON_STATUS ADDON_Create(void* hdl, void* props)
  29. {
  30. if (!props)
  31. return ADDON_STATUS_UNKNOWN;
  32. VIS_PROPS* visprops = (VIS_PROPS*)props;
  33. g_Vortex = new Vortex;
  34. g_Vortex->Init( ( LPDIRECT3DDEVICE9 )visprops->device, visprops->x, visprops->y, visprops->width, visprops->height, visprops->pixelRatio );
  35. return ADDON_STATUS_NEED_SETTINGS;
  36. }
  37. extern "C" void Start( int iChannels, int iSamplesPerSec, int iBitsPerSample, const char* szSongName )
  38. {
  39. g_Vortex->Start( iChannels, iSamplesPerSec, iBitsPerSample, szSongName );
  40. }
  41. extern "C" void ADDON_Stop()
  42. {
  43. if ( g_Vortex )
  44. {
  45. g_Vortex->Shutdown();
  46. delete g_Vortex;
  47. g_Vortex = NULL;
  48. }
  49. }
  50. extern "C" void AudioData(const short* pAudioData, int iAudioDataLength, float *pFreqData, int iFreqDataLength)
  51. {
  52. g_Vortex->AudioData( pAudioData, iAudioDataLength, pFreqData, iFreqDataLength );
  53. }
  54. extern "C" void Render()
  55. {
  56. g_Vortex->Render();
  57. }
  58. extern "C" void GetInfo(VIS_INFO* pInfo)
  59. {
  60. pInfo->bWantsFreq = false;
  61. pInfo->iSyncDelay = 0;
  62. }
  63. extern "C" bool OnAction(long action, const void *param)
  64. {
  65. bool handled = true;
  66. if( action == VIS_ACTION_UPDATE_TRACK )
  67. {
  68. VisTrack* visTrack = (VisTrack*) param;
  69. g_Vortex->UpdateTrack( visTrack );
  70. }
  71. else if( action == VIS_ACTION_UPDATE_ALBUMART )
  72. {
  73. g_Vortex->UpdateAlbumArt( ( char* ) param );
  74. }
  75. else if (action == VIS_ACTION_NEXT_PRESET)
  76. {
  77. g_Vortex->LoadNextPreset();
  78. }
  79. else if (action == VIS_ACTION_PREV_PRESET)
  80. {
  81. g_Vortex->LoadPreviousPreset();
  82. }
  83. else if (action == VIS_ACTION_LOAD_PRESET && param)
  84. {
  85. g_Vortex->LoadPreset( (*(int *)param) );
  86. }
  87. else if (action == VIS_ACTION_LOCK_PRESET)
  88. {
  89. g_Vortex->GetUserSettings().PresetLocked = !g_Vortex->GetUserSettings().PresetLocked;
  90. }
  91. else if (action == VIS_ACTION_RANDOM_PRESET)
  92. {
  93. g_Vortex->LoadRandomPreset();
  94. }
  95. else
  96. {
  97. handled = false;
  98. }
  99. return handled;
  100. }
  101. extern "C" unsigned int GetPresets(char ***presets)
  102. {
  103. if( g_Vortex == NULL )
  104. {
  105. return 0;
  106. }
  107. return g_Vortex->GetPresets( presets );
  108. }
  109. //-- GetPreset ----------------------------------------------------------------
  110. // Return the index of the current playing preset
  111. //-----------------------------------------------------------------------------
  112. extern "C" unsigned GetPreset()
  113. {
  114. if ( g_Vortex)
  115. return g_Vortex->GetCurrentPresetIndex();
  116. return 0;
  117. }
  118. //-- IsLocked -----------------------------------------------------------------
  119. // Returns true if this add-on use settings
  120. //-----------------------------------------------------------------------------
  121. extern "C" bool IsLocked()
  122. {
  123. if ( g_Vortex )
  124. return g_Vortex->GetUserSettings().PresetLocked;
  125. else
  126. return false;
  127. }
  128. //-- Destroy-------------------------------------------------------------------
  129. // Do everything before unload of this add-on
  130. // !!! Add-on master function !!!
  131. //-----------------------------------------------------------------------------
  132. extern "C" void ADDON_Destroy()
  133. {
  134. Stop();
  135. }
  136. //-- HasSettings --------------------------------------------------------------
  137. // Returns true if this add-on use settings
  138. // !!! Add-on master function !!!
  139. //-----------------------------------------------------------------------------
  140. extern "C" bool ADDON_HasSettings()
  141. {
  142. return true;
  143. }
  144. //-- GetStatus ---------------------------------------------------------------
  145. // Returns the current Status of this visualisation
  146. // !!! Add-on master function !!!
  147. //-----------------------------------------------------------------------------
  148. extern "C" ADDON_STATUS ADDON_GetStatus()
  149. {
  150. return ADDON_STATUS_OK;
  151. }
  152. extern "C" unsigned int ADDON_GetSettings(ADDON_StructSetting*** sSet)
  153. {
  154. return 0;
  155. }
  156. extern "C" void ADDON_FreeSettings()
  157. {
  158. }
  159. extern "C" ADDON_STATUS ADDON_SetSetting(const char* id, const void* value)
  160. {
  161. if ( !id || !value || g_Vortex == NULL )
  162. return ADDON_STATUS_UNKNOWN;
  163. UserSettings& userSettings = g_Vortex->GetUserSettings();
  164. if (strcmpi(id, "Use Preset") == 0)
  165. {
  166. OnAction(34, &value);
  167. }
  168. else if (strcmpi(id, "RandomPresets") == 0)
  169. {
  170. userSettings.RandomPresetsEnabled = *(bool*)value == 1;
  171. }
  172. else if (strcmpi(id, "TimeBetweenPresets") == 0)
  173. {
  174. userSettings.TimeBetweenPresets = (float)(*(int*)value * 5 + 5);
  175. }
  176. else if (strcmpi(id, "AdditionalRandomTime") == 0)
  177. {
  178. userSettings.TimeBetweenPresetsRand = (float)(*(int*)value * 5 );
  179. }
  180. else if (strcmpi(id, "EnableTransitions") == 0)
  181. {
  182. userSettings.TransitionsEnabled = *(bool*)value == 1;
  183. }
  184. else if (strcmpi(id, "StopFirstPreset") == 0)
  185. {
  186. userSettings.StopFirstPreset = *(bool*)value == 1;
  187. }
  188. else if (strcmpi(id, "ShowFPS") == 0)
  189. {
  190. userSettings.ShowFPS = *(bool*)value == 1;
  191. }
  192. else if (strcmpi(id, "ShowDebugConsole") == 0)
  193. {
  194. userSettings.ShowDebugConsole = *(bool*)value == 1;
  195. }
  196. else if (strcmpi(id, "ShowAudioAnalysis") == 0)
  197. {
  198. userSettings.ShowAudioAnalysis = *(bool*)value == 1;
  199. }
  200. else
  201. return ADDON_STATUS_UNKNOWN;
  202. return ADDON_STATUS_OK;
  203. }
  204. //-- GetSubModules ------------------------------------------------------------
  205. // Return any sub modules supported by this vis
  206. //-----------------------------------------------------------------------------
  207. extern "C" unsigned int GetSubModules(char ***presets)
  208. {
  209. return 0; // this vis supports 0 sub modules
  210. }
  211. //-- Announce -----------------------------------------------------------------
  212. // Receive announcements from XBMC
  213. //-----------------------------------------------------------------------------
  214. extern "C" void ADDON_Announce(const char *flag, const char *sender, const char *message, const void *data)
  215. {
  216. }