2 * Copyright (C) 2005-2013 Team XBMC
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, or (at your option)
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.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
24 Goom Visualization Interface for XBMC
29 #define __STDC_LIMIT_MACROS
31 #include "../../addons/include/xbmc_vis_dll.h"
39 #include "goom_config.h"
42 extern int preset_index;
44 PluginInfo* g_goom = NULL;
46 int g_tex_width = GOOM_TEXTURE_WIDTH;
47 int g_tex_height = GOOM_TEXTURE_HEIGHT;
48 int g_window_width = 512;
49 int g_window_height = 512;
50 int g_window_xpos = 0;
51 int g_window_ypos = 0;
54 unsigned char* g_goom_buffer = NULL;
55 short g_audio_data[2][512];
56 std::string g_configFile;
60 //-- Create -------------------------------------------------------------------
61 // Called once when the visualisation is created by XBMC. Do any setup here.
62 //-----------------------------------------------------------------------------
63 extern "C" ADDON_STATUS ADDON_Create(void* hdl, void* props)
66 return ADDON_STATUS_UNKNOWN;
68 VIS_PROPS* visprops = (VIS_PROPS*)props;
70 strcpy(g_visName, visprops->name);
71 g_configFile = string(visprops->profile) + string("/goom.conf");
72 std::string presetsDir = string(visprops->presets) + string("/resources");
74 /** Initialise Goom */
81 g_goom = goom_init(g_tex_width, g_tex_height);
83 return ADDON_STATUS_UNKNOWN;
85 g_goom_buffer = (unsigned char*)malloc(g_tex_width * g_tex_height * 4);
86 goom_set_screenbuffer( g_goom, g_goom_buffer );
87 memset( g_audio_data, 0, sizeof(g_audio_data) );
88 g_window_width = visprops->width;
89 g_window_height = visprops->height;
90 g_window_xpos = visprops->x;
91 g_window_ypos = visprops->y;
93 return ADDON_STATUS_OK;
96 //-- Destroy -------------------------------------------------------------------
97 // Do everything before unload of this add-on
98 // !!! Add-on master function !!!
99 //-----------------------------------------------------------------------------
100 extern "C" void ADDON_Destroy()
104 goom_close( g_goom );
109 free( g_goom_buffer );
110 g_goom_buffer = NULL;
114 //-- Start --------------------------------------------------------------------
115 // Called when a new soundtrack is played
116 //-----------------------------------------------------------------------------
117 extern "C" void Start(int iChannels, int iSamplesPerSec, int iBitsPerSample, const char* szSongName)
121 goom_update( g_goom, g_audio_data, 0, 0, (char*)szSongName, (char*)"XBMC" );
125 //-- Stop ---------------------------------------------------------------------
126 // Called when the visualisation is closed by XBMC
127 //-----------------------------------------------------------------------------
128 extern "C" void ADDON_Stop()
132 glDeleteTextures( 1, &g_texid );
137 //-- Audiodata ----------------------------------------------------------------
138 // Called by XBMC to pass new audio data to the vis
139 //-----------------------------------------------------------------------------
140 extern "C" void AudioData(const float* pAudioData, int iAudioDataLength, float *pFreqData, int iFreqDataLength)
142 int copysize = iAudioDataLength < (int)sizeof( g_audio_data ) >> 1 ? iAudioDataLength : (int)sizeof( g_audio_data ) >> 1;
144 for(ipos = 0, i = 0; i < copysize; i += 2, ++ipos)
146 g_audio_data[0][ipos] = (int)(pAudioData[i ] * (INT16_MAX+.5f));
147 g_audio_data[1][ipos] = (int)(pAudioData[i+1] * (INT16_MAX+.5f));
152 //-- Render -------------------------------------------------------------------
153 // Called once per frame. Do all rendering here.
154 //-----------------------------------------------------------------------------
155 extern "C" void Render()
159 goom_set_screenbuffer( g_goom, g_goom_buffer );
162 // initialize the texture we'll be using
163 glGenTextures( 1, &g_texid );
166 goom_update( g_goom, g_audio_data, 0, 0, NULL, (char*)"XBMC" );
167 glEnable(GL_TEXTURE_2D);
168 glBindTexture( GL_TEXTURE_2D, g_texid );
169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
171 glTexImage2D( GL_TEXTURE_2D, 0, 4, g_tex_width, g_tex_height, 0,
172 GL_RGBA, GL_UNSIGNED_BYTE, g_goom_buffer );
173 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
177 // update goom frame and copy to our texture
178 goom_update( g_goom, g_audio_data, 0, 0, NULL, (char*)"XBMC" );
179 glEnable(GL_TEXTURE_2D);
180 glBindTexture( GL_TEXTURE_2D, g_texid );
181 glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, g_tex_width, g_tex_height,
182 GL_RGBA, GL_UNSIGNED_BYTE, g_goom_buffer );
183 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
189 glColor3f( 1.0, 1.0, 1.0 );
190 glTexCoord2f( 0.0, 0.0 );
191 glVertex2f( g_window_xpos, g_window_ypos );
193 glTexCoord2f( 0.0, 1.0 );
194 glVertex2f( g_window_xpos, g_window_ypos + g_window_height );
196 glTexCoord2f( 1.0, 1.0 );
197 glVertex2f( g_window_xpos + g_window_width, g_window_ypos + g_window_height );
199 glTexCoord2f( 1.0, 0.0 );
200 glVertex2f( g_window_xpos + g_window_width, g_window_ypos );
203 glDisable( GL_TEXTURE_2D );
208 //-- GetInfo ------------------------------------------------------------------
209 // Tell XBMC our requirements
210 //-----------------------------------------------------------------------------
211 extern "C" void GetInfo(VIS_INFO* pInfo)
213 pInfo->bWantsFreq = false;
214 pInfo->iSyncDelay = 0;
217 //-- OnAction -----------------------------------------------------------------
218 // Handle XBMC actions such as next preset, lock preset, album art changed etc
219 //-----------------------------------------------------------------------------
220 extern "C" bool OnAction(long flags, const void *param)
226 //-- GetPresets ---------------------------------------------------------------
227 // Return a list of presets to XBMC for display
228 //-----------------------------------------------------------------------------
229 extern "C" unsigned int GetPresets(char ***presets)
234 //-- GetPreset ----------------------------------------------------------------
235 // Return the index of the current playing preset
236 //-----------------------------------------------------------------------------
237 extern "C" unsigned GetPreset()
242 //-- IsLocked -----------------------------------------------------------------
243 // Returns true if this add-on use settings
244 //-----------------------------------------------------------------------------
245 extern "C" bool IsLocked()
250 //-- GetSubModules ------------------------------------------------------------
251 // Return any sub modules supported by this vis
252 //-----------------------------------------------------------------------------
253 extern "C" unsigned int GetSubModules(char ***names)
255 return 0; // this vis supports 0 sub modules
258 //-- HasSettings --------------------------------------------------------------
259 // Returns true if this add-on use settings
260 // !!! Add-on master function !!!
261 //-----------------------------------------------------------------------------
262 extern "C" bool ADDON_HasSettings()
267 //-- GetStatus ---------------------------------------------------------------
268 // Returns the current Status of this visualisation
269 // !!! Add-on master function !!!
270 //-----------------------------------------------------------------------------
271 extern "C" ADDON_STATUS ADDON_GetStatus()
273 return ADDON_STATUS_OK;
276 //-- GetSettings --------------------------------------------------------------
277 // Return the settings for XBMC to display
278 // !!! Add-on master function !!!
279 //-----------------------------------------------------------------------------
280 extern "C" unsigned int ADDON_GetSettings(ADDON_StructSetting ***sSet)
285 //-- FreeSettings --------------------------------------------------------------
286 // Free the settings struct passed from XBMC
287 // !!! Add-on master function !!!
288 //-----------------------------------------------------------------------------
290 extern "C" void ADDON_FreeSettings()
294 //-- SetSetting ---------------------------------------------------------------
295 // Set a specific Setting value (called from XBMC)
296 // !!! Add-on master function !!!
297 //-----------------------------------------------------------------------------
298 extern "C" ADDON_STATUS ADDON_SetSetting(const char *strSetting, const void* value)
300 return ADDON_STATUS_OK;