Mercurial > audlegacy-plugins
annotate src/projectm/main.c @ 679:c8dc00a58f0d trunk
[svn] - remove a bunch of pointless code. we don't do ID3 for raw AAC files at this time.
| author | nenolod |
|---|---|
| date | Tue, 20 Feb 2007 04:13:46 -0800 |
| parents | aaab0bede198 |
| children | 711ec8d39ca6 |
| rev | line source |
|---|---|
| 358 | 1 /* |
| 2 xmms-projectM v0.99 - xmms-projectm.sourceforge.net | |
| 3 -------------------------------------------------- | |
| 4 | |
| 5 Lead Developers: Carmelo Piccione (cep@andrew.cmu.edu) & | |
| 6 Peter Sperl (peter@sperl.com) | |
| 7 | |
| 8 We have also been advised by some professors at CMU, namely Roger B. Dannenberg. | |
| 9 http://www-2.cs.cmu.edu/~rbd/ | |
| 10 | |
| 11 The inspiration for this program was Milkdrop by Ryan Geiss. Obviously. | |
| 12 | |
| 13 This code is distributed under the GPL. | |
| 14 | |
| 15 | |
| 16 THANKS FOR THE CODE!!! | |
| 17 ------------------------------------------------- | |
| 18 The base for this program was andy@nobugs.org's XMMS plugin tutorial | |
| 19 http://www.xmms.org/docs/vis-plugin.html | |
| 20 | |
| 21 We used some FFT code by Takuya OOURA instead of XMMS' built-in fft code | |
| 22 fftsg.c - http://momonga.t.u-tokyo.ac.jp/~ooura/fft.html | |
| 23 | |
| 24 For font rendering we used GLF by Roman Podobedov | |
| 25 glf.c - http://astronomy.swin.edu.au/~pbourke/opengl/glf/ | |
| 26 | |
| 27 and some beat detection code was inspired by Frederic Patin @ | |
| 28 www.gamedev.net/reference/programming/features/beatdetection/ | |
| 29 | |
| 30 */ | |
| 31 | |
| 32 | |
| 33 #include <stdio.h> | |
| 34 #include <audacious/plugin.h> | |
| 35 #include <string.h> | |
| 36 #include <stdlib.h> | |
| 37 #include <gtk/gtk.h> | |
| 38 #include <audacious/util.h> | |
| 39 #include <SDL/SDL.h> | |
| 40 #include <SDL/SDL_thread.h> | |
| 41 #include <GL/gl.h> | |
| 42 #include <GL/glu.h> | |
| 43 #include <audacious/beepctrl.h> | |
| 44 #include <math.h> | |
| 45 #include <sys/stat.h> | |
| 46 #include <sys/types.h> | |
| 47 | |
| 48 #include <projectM/projectM.h> | |
| 49 #include <projectM/console_interface.h> | |
| 50 #include "sdltoprojectM.h" | |
| 51 #include "video_init.h" | |
| 52 | |
| 53 #if HAVE_CONFIG_H | |
| 54 #include <config.h> | |
| 55 #endif | |
| 56 #define CONFIG_FILE "/config" | |
| 57 #define PRESETS_DIR "/presets" | |
| 58 #define FONTS_DIR "/fonts" | |
| 59 | |
| 60 // Forward declarations | |
| 61 static void projectM_xmms_init(void); | |
| 62 static void projectM_cleanup(void); | |
| 63 static void projectM_about(void); | |
| 64 static void projectM_configure(void); | |
| 65 static void projectM_playback_start(void); | |
| 66 static void projectM_playback_stop(void); | |
| 67 static void projectM_render_pcm(gint16 pcm_data[2][512]); | |
| 68 static void projectM_render_freq(gint16 pcm_data[2][256]); | |
| 69 void read_config(); | |
| 70 | |
| 71 | |
| 72 //extern preset_t * active_preset; | |
| 73 | |
| 74 // Callback functions | |
| 75 VisPlugin projectM_vtable = { | |
| 76 NULL, // Handle, filled in by xmms | |
| 77 NULL, // Filename, filled in by xmms | |
| 78 0, // Session ID | |
| 79 "projectM v0.99", // description | |
| 80 2, // # of PCM channels for render_pcm() | |
| 81 0, // # of freq channels wanted for render_freq() | |
| 82 projectM_xmms_init, // Called when plugin is enabled | |
| 83 projectM_cleanup, // Called when plugin is disabled | |
| 84 projectM_about, // Show the about box | |
| 85 projectM_configure, // Show the configure box | |
| 86 NULL, // Called to disable plugin, filled in by xmms | |
| 87 projectM_playback_start, // Called when playback starts | |
| 88 projectM_playback_stop, // Called when playback stops | |
| 89 projectM_render_pcm, // Render the PCM data, must return quickly | |
| 90 projectM_render_freq // Render the freq data, must return quickly | |
| 91 }; | |
| 92 | |
| 93 // XMMS entry point | |
| 94 VisPlugin *get_vplugin_info(void) | |
| 95 { | |
| 96 return &projectM_vtable; | |
| 97 } | |
| 98 | |
| 99 // Our worker thread | |
| 100 SDL_Thread *worker_thread; | |
| 101 | |
| 102 SDL_mutex *mutex; | |
| 103 | |
| 104 SDL_sem *sem; | |
| 105 | |
| 106 SDL_Event event; | |
| 107 | |
| 108 SDL_Surface *screen; | |
| 109 //SDL_RenderTarget *RenderTarget = NULL; | |
| 110 //GLuint RenderTargetTextureID; | |
| 111 | |
| 112 projectM_t *globalPM = NULL; | |
| 113 | |
| 114 int maxsamples=512; | |
| 115 | |
| 116 int texsize=512; | |
| 117 int gx=32,gy=24; | |
| 118 int wvw=640,wvh=480; | |
| 119 int fvw=1280,fvh=960; | |
| 120 int fps=30, fullscreen=0; | |
| 121 char *disp; | |
| 122 | |
| 123 int disable_projectm(void) { | |
| 124 projectM_vtable.disable_plugin(&projectM_vtable); | |
| 125 return 0; | |
| 126 } | |
| 127 | |
| 128 int get_xmms_title(void) { | |
| 129 static char check_title = 1; | |
| 130 static int last_pos; | |
| 131 static char *last_title = NULL; | |
| 132 int pos; | |
| 133 char *title = NULL; | |
| 134 | |
| 135 //Nice optimization, but we want the title no matter what so I can display it when the song changes | |
| 136 #if 0 | |
| 137 if(!(globalPM->showtitle%2)) { | |
| 138 /* Repeat less often when not showing title */ | |
| 139 return 1000; | |
| 140 } | |
| 141 #endif | |
| 142 | |
| 143 pos = xmms_remote_get_playlist_pos(projectM_vtable.xmms_session); | |
| 144 /* Only check every 1 second for title change, otherwise check pos */ | |
| 145 if(check_title || pos != last_pos) { | |
| 146 title = xmms_remote_get_playlist_title( | |
| 147 projectM_vtable.xmms_session, pos); | |
| 148 if(title && (!last_title || strcmp(last_title,title))) { | |
| 149 globalPM->title = title; | |
| 150 globalPM->drawtitle = 1; | |
| 151 g_free(last_title); | |
| 152 last_title = title; | |
| 153 } else if(title && last_title != title) { | |
| 154 /* New copy of last title */ | |
| 155 g_free(title); | |
| 156 } | |
| 157 check_title = !check_title; | |
| 158 } | |
| 159 last_pos = pos; | |
| 160 /* Repeat every 500ms */ | |
| 161 return 500; | |
| 162 } | |
| 163 | |
| 164 void worker_func() | |
| 165 { | |
| 166 char projectM_data[PATH_MAX]; | |
| 167 | |
| 168 SDL_TimerID title_timer = NULL; | |
| 169 | |
| 170 | |
| 171 read_config(); | |
| 172 | |
| 173 init_display(wvw,wvh,fullscreen); | |
| 174 | |
| 175 SDL_WM_SetCaption("projectM v0.99", "projectM v0.99"); | |
| 176 | |
| 177 | |
| 178 /** Initialise projectM */ | |
| 179 | |
| 180 globalPM = (projectM_t *)malloc( sizeof( projectM_t ) ); | |
| 181 | |
| 182 projectM_reset( globalPM ); | |
| 183 | |
| 184 globalPM->fullscreen = fullscreen; | |
| 185 globalPM->renderTarget->texsize = texsize; | |
| 186 globalPM->gx=gx; | |
| 187 globalPM->gy=gy; | |
| 188 globalPM->fps=fps; | |
| 189 globalPM->renderTarget->usePbuffers=0; | |
| 190 | |
| 191 strcpy(projectM_data, PROJECTM_DATADIR); | |
| 192 strcpy(projectM_data+strlen(PROJECTM_DATADIR), FONTS_DIR); | |
| 193 projectM_data[strlen(PROJECTM_DATADIR)+strlen(FONTS_DIR)]='\0'; | |
| 194 | |
| 195 globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); | |
| 196 strcpy( globalPM->fontURL, projectM_data ); | |
| 197 | |
| 198 strcpy(projectM_data+strlen(PROJECTM_DATADIR), PRESETS_DIR); | |
| 199 projectM_data[strlen(PROJECTM_DATADIR)+strlen(PRESETS_DIR)]='\0'; | |
| 200 | |
| 201 globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); | |
| 202 strcpy( globalPM->presetURL, projectM_data ); | |
| 203 | |
| 204 | |
| 205 projectM_init( globalPM ); | |
| 206 | |
| 207 projectM_resetGL( globalPM, wvw, wvh ); | |
| 208 | |
|
663
aaab0bede198
[svn] Cast those pointers properly, and do not use deprecated GTK+ functions.
chainsaw
parents:
358
diff
changeset
|
209 title_timer = SDL_AddTimer(500, (SDL_NewTimerCallback) get_xmms_title, NULL); |
| 358 | 210 |
| 211 /** Initialise the thread */ | |
| 212 | |
| 213 SDL_SemTryWait(sem); | |
| 214 while ( SDL_SemTryWait(sem) ) { | |
| 215 projectMEvent evt; | |
| 216 projectMKeycode key; | |
| 217 projectMModifier mod; | |
| 218 | |
| 219 /** Process SDL events */ | |
| 220 SDL_Event event; | |
| 221 while ( SDL_PollEvent( &event ) ) { | |
| 222 /** Translate into projectM codes and process */ | |
| 223 evt = sdl2pmEvent( event ); | |
| 224 key = sdl2pmKeycode( event.key.keysym.sym ); | |
| 225 mod = sdl2pmModifier( event.key.keysym.mod ); | |
| 226 | |
| 227 if ( evt == PROJECTM_KEYDOWN ) { | |
| 228 | |
| 229 | |
| 230 if(key == SDLK_f) | |
| 231 { | |
| 232 int w, h; | |
| 233 if (fullscreen == 0) { | |
| 234 w = fvw; | |
| 235 h = fvh; | |
| 236 } else { | |
| 237 w = wvw; | |
| 238 h = wvh; | |
| 239 } | |
| 240 globalPM->fullscreen = fullscreen ^= 1; | |
| 241 resize_display(w, h, fullscreen); | |
| 242 projectM_resetGL( globalPM, w, h ); | |
| 243 } | |
| 244 else key_handler(globalPM,evt,key,mod); | |
| 245 | |
| 246 } | |
| 247 else if ( evt == PROJECTM_VIDEORESIZE ) | |
| 248 { | |
| 249 wvw=event.resize.w; | |
| 250 wvh=event.resize.h; | |
| 251 resize_display(wvw, wvh, 0); | |
| 252 projectM_resetGL( globalPM, wvw, wvh ); | |
| 253 | |
| 254 } | |
| 255 else if ( evt == PROJECTM_VIDEOQUIT ) { | |
| 256 | |
|
663
aaab0bede198
[svn] Cast those pointers properly, and do not use deprecated GTK+ functions.
chainsaw
parents:
358
diff
changeset
|
257 (void) g_idle_add ((GSourceFunc) disable_projectm, NULL); |
| 358 | 258 /* if(quit_timer == NULL) |
| 259 quit_timer = SDL_AddTimer(500, disable_projectm, NULL);*/ | |
| 260 } | |
| 261 | |
| 262 } | |
| 263 | |
| 264 | |
| 265 /** Render the new frame */ | |
| 266 | |
| 267 renderFrame( globalPM ); | |
| 268 | |
| 269 SDL_GL_SwapBuffers(); | |
| 270 } | |
| 271 | |
| 272 | |
| 273 | |
| 274 printf("Worker thread: Exiting\n"); | |
| 275 if(title_timer) SDL_RemoveTimer(title_timer); | |
| 276 g_free(globalPM->title); | |
| 277 free(globalPM->presetURL); | |
| 278 free(globalPM->fontURL); | |
| 279 free(globalPM); | |
| 280 close_display(); | |
| 281 } | |
| 282 | |
| 283 static void projectM_xmms_init(void) | |
| 284 { | |
| 285 | |
| 286 printf("projectM plugin: Initializing\n"); | |
| 287 | |
| 288 SDL_EnableUNICODE(1); | |
| 289 | |
| 290 mutex = SDL_CreateMutex(); | |
| 291 | |
| 292 sem = SDL_CreateSemaphore(1); | |
| 293 | |
| 294 worker_thread = SDL_CreateThread ((void *) worker_func, NULL); | |
| 295 | |
| 296 } | |
| 297 | |
| 298 | |
| 299 | |
| 300 static void projectM_cleanup(void) | |
| 301 { | |
| 302 | |
| 303 SDL_SemPost(sem); | |
| 304 SDL_WaitThread(worker_thread, NULL); | |
| 305 | |
| 306 SDL_DestroySemaphore(sem); | |
| 307 printf("Destroy Semaphore\n"); | |
| 308 SDL_DestroyMutex(mutex); | |
| 309 printf("Destroy Mutex\n"); | |
| 310 | |
| 311 printf("projectM plugin: Cleanup completed\n"); | |
| 312 } | |
| 313 static void projectM_about(void) | |
| 314 { | |
| 315 printf("projectM plugin: About\n"); | |
| 316 } | |
| 317 static void projectM_configure(void) | |
| 318 { | |
| 319 printf("projectM plugin: Configure\n"); | |
| 320 } | |
| 321 static void projectM_playback_start(void) | |
| 322 { | |
| 323 printf("projectM plugin: Playback starting\n"); | |
| 324 } | |
| 325 static void projectM_playback_stop(void) | |
| 326 { | |
| 327 printf("projectM plugin: Playback stopping\n"); | |
| 328 } | |
| 329 static void projectM_render_pcm(gint16 pcm_data[2][512]) | |
| 330 { | |
| 331 | |
| 332 if (0 < SDL_SemValue(sem)) return; | |
| 333 SDL_mutexP(mutex); | |
| 334 | |
| 335 addPCM16Data(pcm_data,512); | |
| 336 | |
| 337 SDL_mutexV(mutex); | |
| 338 | |
| 339 } | |
| 340 | |
| 341 static void projectM_render_freq(gint16 freq_data[2][256]) | |
| 342 { | |
| 343 printf("NO GOOD\n"); | |
| 344 } | |
| 345 | |
| 346 | |
| 347 void read_config() | |
| 348 { | |
| 349 | |
| 350 int n; | |
| 351 | |
| 352 char num[80]; | |
| 353 FILE *in; | |
| 354 FILE *out; | |
| 355 | |
| 356 char* home; | |
| 357 char projectM_home[PATH_MAX]; | |
| 358 char projectM_config[PATH_MAX]; | |
| 359 | |
| 360 strcpy(projectM_config, PROJECTM_DATADIR); | |
| 361 strcpy(projectM_config+strlen(PROJECTM_DATADIR), CONFIG_FILE); | |
| 362 projectM_config[strlen(PROJECTM_DATADIR)+strlen(CONFIG_FILE)]='\0'; | |
| 363 | |
| 364 home=getenv("HOME"); | |
| 365 strcpy(projectM_home, home); | |
| 366 strcpy(projectM_home+strlen(home), "/.projectM/config"); | |
| 367 projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; | |
| 368 | |
| 369 | |
| 370 if ((in = fopen(projectM_home, "r")) != 0) | |
| 371 { | |
| 372 printf("reading ~/.projectM/config \n"); | |
| 373 } | |
| 374 else | |
| 375 { | |
| 376 printf("trying to create ~/.projectM/config \n"); | |
| 377 | |
| 378 strcpy(projectM_home, home); | |
| 379 strcpy(projectM_home+strlen(home), "/.projectM"); | |
| 380 projectM_home[strlen(home)+strlen("/.projectM")]='\0'; | |
| 381 mkdir(projectM_home,0755); | |
| 382 | |
| 383 strcpy(projectM_home, home); | |
| 384 strcpy(projectM_home+strlen(home), "/.projectM/config"); | |
| 385 projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; | |
| 386 | |
| 387 if((out = fopen(projectM_home,"w"))!=0) | |
| 388 { | |
| 389 | |
| 390 if ((in = fopen(projectM_config, "r")) != 0) | |
| 391 { | |
| 392 | |
| 393 while(fgets(num,80,in)!=NULL) | |
| 394 { | |
| 395 fputs(num,out); | |
| 396 } | |
| 397 fclose(in); | |
| 398 fclose(out); | |
| 399 | |
| 400 | |
| 401 if ((in = fopen(projectM_home, "r")) != 0) | |
| 402 { printf("created ~/.projectM/config successfully\n"); } | |
| 403 else{printf("This shouldn't happen, using implementation defualts\n");return;} | |
| 404 } | |
| 405 else{printf("Cannot find projectM default config, using implementation defaults\n");return;} | |
| 406 } | |
| 407 else | |
| 408 { | |
| 409 printf("Cannot create ~/.projectM/config, using default config file\n"); | |
| 410 if ((in = fopen(projectM_config, "r")) != 0) | |
| 411 { printf("Successfully opened default config file\n");} | |
| 412 else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); return;} | |
| 413 | |
| 414 } | |
| 415 | |
| 416 } | |
| 417 | |
| 418 | |
| 419 | |
| 420 fgets(num, 80, in); fgets(num, 80, in); fgets(num, 80, in); | |
| 421 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &texsize); | |
| 422 | |
| 423 fgets(num, 80, in); | |
| 424 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gx); | |
| 425 | |
| 426 fgets(num, 80, in); | |
| 427 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gy); | |
| 428 | |
| 429 fgets(num, 80, in); | |
| 430 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvw); | |
| 431 | |
| 432 fgets(num, 80, in); | |
| 433 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvh); | |
| 434 | |
| 435 fgets(num, 80, in); | |
| 436 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvw); | |
| 437 | |
| 438 fgets(num, 80, in); | |
| 439 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvh); | |
| 440 | |
| 441 fgets(num, 80, in); | |
| 442 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fps); | |
| 443 | |
| 444 fgets(num, 80, in); | |
| 445 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fullscreen); | |
| 446 /* | |
| 447 fgets(num, 80, in); | |
| 448 fgets(num, 80, in); | |
| 449 | |
| 450 n=0; | |
| 451 while (num[n]!=' ' && num[n]!='\n' && n < 80 && num[n]!=EOF) | |
| 452 { | |
| 453 disp[n]=num[n]; | |
| 454 n++; | |
| 455 } | |
| 456 disp[n]=0; | |
| 457 | |
| 458 | |
| 459 // sprintf(disp,"%s",num ); | |
| 460 setenv("DISPLAY",disp,1); | |
| 461 printf("%s %d\n", disp,strlen(disp)); | |
| 462 setenv("LD_PRELOAD", "/usr/lib/tls/libGL.so.1.0.4496", 1); | |
| 463 */ | |
| 464 fclose(in); | |
| 465 | |
| 466 } |
