PageRenderTime 34ms CodeModel.GetById 19ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 20#include <windows.h>
 21#include <io.h>
 22#include <vector>
 23#include "Vortex.h"
 24
 25#include "../../../addons/include/xbmc_vis_dll.h"
 26#include "../../../addons/include/xbmc_addon_cpp_dll.h"
 27
 28
 29Vortex* g_Vortex = NULL;
 30
 31// settings vector
 32StructSetting** g_structSettings;
 33
 34extern "C" ADDON_STATUS ADDON_Create(void* hdl, void* props)
 35{
 36	if (!props)
 37		return ADDON_STATUS_UNKNOWN;
 38
 39	VIS_PROPS* visprops = (VIS_PROPS*)props;
 40
 41	g_Vortex = new Vortex;
 42	g_Vortex->Init( ( LPDIRECT3DDEVICE9 )visprops->device, visprops->x, visprops->y, visprops->width, visprops->height, visprops->pixelRatio );
 43
 44	return ADDON_STATUS_NEED_SETTINGS;
 45}
 46
 47extern "C" void Start( int iChannels, int iSamplesPerSec, int iBitsPerSample, const char* szSongName )
 48{
 49	g_Vortex->Start( iChannels, iSamplesPerSec, iBitsPerSample, szSongName );
 50}
 51
 52extern "C" void ADDON_Stop()
 53{
 54	if ( g_Vortex )
 55	{
 56		g_Vortex->Shutdown();
 57		delete g_Vortex;
 58		g_Vortex = NULL;
 59	}
 60}
 61
 62extern "C" void AudioData(const short* pAudioData, int iAudioDataLength, float *pFreqData, int iFreqDataLength)
 63{
 64	g_Vortex->AudioData( pAudioData, iAudioDataLength, pFreqData, iFreqDataLength );
 65}
 66
 67extern "C" void Render()
 68{
 69	g_Vortex->Render();
 70}
 71
 72extern "C" void GetInfo(VIS_INFO* pInfo)
 73{
 74	pInfo->bWantsFreq = false;
 75	pInfo->iSyncDelay = 0;
 76}
 77
 78extern "C"   bool OnAction(long action, const void *param)
 79{
 80	bool handled = true;
 81	if( action == VIS_ACTION_UPDATE_TRACK )
 82	{
 83		VisTrack* visTrack = (VisTrack*) param;
 84		g_Vortex->UpdateTrack( visTrack );
 85	}
 86	else if( action == VIS_ACTION_UPDATE_ALBUMART )
 87	{
 88		g_Vortex->UpdateAlbumArt( ( char* ) param );
 89	}
 90	else if (action == VIS_ACTION_NEXT_PRESET)
 91	{
 92		g_Vortex->LoadNextPreset();
 93	}
 94	else if (action == VIS_ACTION_PREV_PRESET)
 95	{
 96		g_Vortex->LoadPreviousPreset();
 97	}
 98	else if (action == VIS_ACTION_LOAD_PRESET && param)
 99	{
100		g_Vortex->LoadPreset( (*(int *)param) );
101	}
102	else if (action == VIS_ACTION_LOCK_PRESET)
103	{
104		g_Vortex->GetUserSettings().PresetLocked = !g_Vortex->GetUserSettings().PresetLocked;
105	}
106	else if (action == VIS_ACTION_RANDOM_PRESET)
107	{
108		g_Vortex->LoadRandomPreset();
109	}
110	else
111	{
112		handled = false;
113	}
114
115	return handled;
116}
117
118extern "C" unsigned int GetPresets(char ***presets)
119{
120	if( g_Vortex == NULL )
121	{
122		return 0;
123	}
124	return g_Vortex->GetPresets( presets );
125}
126//-- GetPreset ----------------------------------------------------------------
127// Return the index of the current playing preset
128//-----------------------------------------------------------------------------
129extern "C" unsigned GetPreset()
130{
131	if ( g_Vortex)
132		return g_Vortex->GetCurrentPresetIndex();
133	return 0;
134}
135
136
137//-- IsLocked -----------------------------------------------------------------
138// Returns true if this add-on use settings
139//-----------------------------------------------------------------------------
140extern "C" bool IsLocked()
141{
142	if ( g_Vortex )
143		return g_Vortex->GetUserSettings().PresetLocked;
144	else
145		return false;
146}
147
148//-- Destroy-------------------------------------------------------------------
149// Do everything before unload of this add-on
150// !!! Add-on master function !!!
151//-----------------------------------------------------------------------------
152extern "C" void ADDON_Destroy()
153{
154	Stop();
155}
156
157//-- HasSettings --------------------------------------------------------------
158// Returns true if this add-on use settings
159// !!! Add-on master function !!!
160//-----------------------------------------------------------------------------
161extern "C" bool ADDON_HasSettings()
162{
163	return true;
164}
165
166//-- GetStatus ---------------------------------------------------------------
167// Returns the current Status of this visualisation
168// !!! Add-on master function !!!
169//-----------------------------------------------------------------------------
170extern "C" ADDON_STATUS ADDON_GetStatus()
171{
172	return ADDON_STATUS_OK;
173}
174
175extern "C" unsigned int ADDON_GetSettings(ADDON_StructSetting*** sSet)
176{
177	return 0;
178}
179
180extern "C" void ADDON_FreeSettings()
181{
182
183}
184
185extern "C" ADDON_STATUS ADDON_SetSetting(const char* id, const void* value)
186{
187	if ( !id || !value || g_Vortex == NULL )
188		return ADDON_STATUS_UNKNOWN;
189
190	UserSettings& userSettings = g_Vortex->GetUserSettings();
191
192	if (strcmpi(id, "Use Preset") == 0)
193	{
194		OnAction(34, &value);
195	}
196	else if (strcmpi(id, "RandomPresets") == 0)
197	{
198		userSettings.RandomPresetsEnabled = *(bool*)value == 1;
199	}
200	else if (strcmpi(id, "TimeBetweenPresets") == 0)
201	{
202		userSettings.TimeBetweenPresets = (float)(*(int*)value * 5 + 5);
203	}
204	else if (strcmpi(id, "AdditionalRandomTime") == 0)
205	{
206		userSettings.TimeBetweenPresetsRand = (float)(*(int*)value * 5 );
207	}
208	else if (strcmpi(id, "EnableTransitions") == 0)
209	{
210		userSettings.TransitionsEnabled = *(bool*)value == 1;
211	}
212	else if (strcmpi(id, "StopFirstPreset") == 0)
213	{
214		userSettings.StopFirstPreset = *(bool*)value == 1;
215	}
216	else if (strcmpi(id, "ShowFPS") == 0)
217	{
218		userSettings.ShowFPS = *(bool*)value == 1;
219	}
220	else if (strcmpi(id, "ShowDebugConsole") == 0)
221	{
222		userSettings.ShowDebugConsole = *(bool*)value == 1;
223	}
224	else if (strcmpi(id, "ShowAudioAnalysis") == 0)
225	{
226		userSettings.ShowAudioAnalysis = *(bool*)value == 1;
227	}
228 	else
229 		return ADDON_STATUS_UNKNOWN;
230
231	return ADDON_STATUS_OK;
232}
233
234//-- GetSubModules ------------------------------------------------------------
235// Return any sub modules supported by this vis
236//-----------------------------------------------------------------------------
237extern "C"   unsigned int GetSubModules(char ***presets)
238{
239  return 0; // this vis supports 0 sub modules
240}
241
242//-- Announce -----------------------------------------------------------------
243// Receive announcements from XBMC
244//-----------------------------------------------------------------------------
245extern "C" void ADDON_Announce(const char *flag, const char *sender, const char *message, const void *data)
246{
247}