Mercurial > audlegacy-plugins
annotate src/projectm/main.c @ 1061:2cf4d0182a86 trunk
[svn] - remove xmms_session values per plugin api v2
| author | nenolod |
|---|---|
| date | Thu, 24 May 2007 02:11:23 -0700 |
| parents | 711ec8d39ca6 |
| children | 038298d9fbe3 |
| 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> | |
|
1035
711ec8d39ca6
[svn] Changed alarm and projectm plugins so they use auddrct now.
magma
parents:
663
diff
changeset
|
43 #include <audacious/auddrct.h> |
| 358 | 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 "projectM v0.99", // description | |
| 79 2, // # of PCM channels for render_pcm() | |
| 80 0, // # of freq channels wanted for render_freq() | |
| 81 projectM_xmms_init, // Called when plugin is enabled | |
| 82 projectM_cleanup, // Called when plugin is disabled | |
| 83 projectM_about, // Show the about box | |
| 84 projectM_configure, // Show the configure box | |
| 85 NULL, // Called to disable plugin, filled in by xmms | |
| 86 projectM_playback_start, // Called when playback starts | |
| 87 projectM_playback_stop, // Called when playback stops | |
| 88 projectM_render_pcm, // Render the PCM data, must return quickly | |
| 89 projectM_render_freq // Render the freq data, must return quickly | |
| 90 }; | |
| 91 | |
| 92 // XMMS entry point | |
| 93 VisPlugin *get_vplugin_info(void) | |
| 94 { | |
| 95 return &projectM_vtable; | |
| 96 } | |
| 97 | |
| 98 // Our worker thread | |
| 99 SDL_Thread *worker_thread; | |
| 100 | |
| 101 SDL_mutex *mutex; | |
| 102 | |
| 103 SDL_sem *sem; | |
| 104 | |
| 105 SDL_Event event; | |
| 106 | |
| 107 SDL_Surface *screen; | |
| 108 //SDL_RenderTarget *RenderTarget = NULL; | |
| 109 //GLuint RenderTargetTextureID; | |
| 110 | |
| 111 projectM_t *globalPM = NULL; | |
| 112 | |
| 113 int maxsamples=512; | |
| 114 | |
| 115 int texsize=512; | |
| 116 int gx=32,gy=24; | |
| 117 int wvw=640,wvh=480; | |
| 118 int fvw=1280,fvh=960; | |
| 119 int fps=30, fullscreen=0; | |
| 120 char *disp; | |
| 121 | |
| 122 int disable_projectm(void) { | |
| 123 projectM_vtable.disable_plugin(&projectM_vtable); | |
| 124 return 0; | |
| 125 } | |
| 126 | |
| 127 int get_xmms_title(void) { | |
| 128 static char check_title = 1; | |
| 129 static int last_pos; | |
| 130 static char *last_title = NULL; | |
| 131 int pos; | |
| 132 char *title = NULL; | |
| 133 | |
| 134 //Nice optimization, but we want the title no matter what so I can display it when the song changes | |
| 135 #if 0 | |
| 136 if(!(globalPM->showtitle%2)) { | |
| 137 /* Repeat less often when not showing title */ | |
| 138 return 1000; | |
| 139 } | |
| 140 #endif | |
| 141 | |
|
1035
711ec8d39ca6
[svn] Changed alarm and projectm plugins so they use auddrct now.
magma
parents:
663
diff
changeset
|
142 pos = audacious_drct_pl_get_pos(); |
| 358 | 143 /* Only check every 1 second for title change, otherwise check pos */ |
| 144 if(check_title || pos != last_pos) { | |
|
1035
711ec8d39ca6
[svn] Changed alarm and projectm plugins so they use auddrct now.
magma
parents:
663
diff
changeset
|
145 title = audacious_drct_pl_get_title(pos); |
| 358 | 146 if(title && (!last_title || strcmp(last_title,title))) { |
| 147 globalPM->title = title; | |
| 148 globalPM->drawtitle = 1; | |
| 149 g_free(last_title); | |
| 150 last_title = title; | |
| 151 } else if(title && last_title != title) { | |
| 152 /* New copy of last title */ | |
| 153 g_free(title); | |
| 154 } | |
| 155 check_title = !check_title; | |
| 156 } | |
| 157 last_pos = pos; | |
| 158 /* Repeat every 500ms */ | |
| 159 return 500; | |
| 160 } | |
| 161 | |
| 162 void worker_func() | |
| 163 { | |
| 164 char projectM_data[PATH_MAX]; | |
| 165 | |
| 166 SDL_TimerID title_timer = NULL; | |
| 167 | |
| 168 | |
| 169 read_config(); | |
| 170 | |
| 171 init_display(wvw,wvh,fullscreen); | |
| 172 | |
| 173 SDL_WM_SetCaption("projectM v0.99", "projectM v0.99"); | |
| 174 | |
| 175 | |
| 176 /** Initialise projectM */ | |
| 177 | |
| 178 globalPM = (projectM_t *)malloc( sizeof( projectM_t ) ); | |
| 179 | |
| 180 projectM_reset( globalPM ); | |
| 181 | |
| 182 globalPM->fullscreen = fullscreen; | |
| 183 globalPM->renderTarget->texsize = texsize; | |
| 184 globalPM->gx=gx; | |
| 185 globalPM->gy=gy; | |
| 186 globalPM->fps=fps; | |
| 187 globalPM->renderTarget->usePbuffers=0; | |
| 188 | |
| 189 strcpy(projectM_data, PROJECTM_DATADIR); | |
| 190 strcpy(projectM_data+strlen(PROJECTM_DATADIR), FONTS_DIR); | |
| 191 projectM_data[strlen(PROJECTM_DATADIR)+strlen(FONTS_DIR)]='\0'; | |
| 192 | |
| 193 globalPM->fontURL = (char *)malloc( sizeof( char ) * 512 ); | |
| 194 strcpy( globalPM->fontURL, projectM_data ); | |
| 195 | |
| 196 strcpy(projectM_data+strlen(PROJECTM_DATADIR), PRESETS_DIR); | |
| 197 projectM_data[strlen(PROJECTM_DATADIR)+strlen(PRESETS_DIR)]='\0'; | |
| 198 | |
| 199 globalPM->presetURL = (char *)malloc( sizeof( char ) * 512 ); | |
| 200 strcpy( globalPM->presetURL, projectM_data ); | |
| 201 | |
| 202 | |
| 203 projectM_init( globalPM ); | |
| 204 | |
| 205 projectM_resetGL( globalPM, wvw, wvh ); | |
| 206 | |
|
663
aaab0bede198
[svn] Cast those pointers properly, and do not use deprecated GTK+ functions.
chainsaw
parents:
358
diff
changeset
|
207 title_timer = SDL_AddTimer(500, (SDL_NewTimerCallback) get_xmms_title, NULL); |
| 358 | 208 |
| 209 /** Initialise the thread */ | |
| 210 | |
| 211 SDL_SemTryWait(sem); | |
| 212 while ( SDL_SemTryWait(sem) ) { | |
| 213 projectMEvent evt; | |
| 214 projectMKeycode key; | |
| 215 projectMModifier mod; | |
| 216 | |
| 217 /** Process SDL events */ | |
| 218 SDL_Event event; | |
| 219 while ( SDL_PollEvent( &event ) ) { | |
| 220 /** Translate into projectM codes and process */ | |
| 221 evt = sdl2pmEvent( event ); | |
| 222 key = sdl2pmKeycode( event.key.keysym.sym ); | |
| 223 mod = sdl2pmModifier( event.key.keysym.mod ); | |
| 224 | |
| 225 if ( evt == PROJECTM_KEYDOWN ) { | |
| 226 | |
| 227 | |
| 228 if(key == SDLK_f) | |
| 229 { | |
| 230 int w, h; | |
| 231 if (fullscreen == 0) { | |
| 232 w = fvw; | |
| 233 h = fvh; | |
| 234 } else { | |
| 235 w = wvw; | |
| 236 h = wvh; | |
| 237 } | |
| 238 globalPM->fullscreen = fullscreen ^= 1; | |
| 239 resize_display(w, h, fullscreen); | |
| 240 projectM_resetGL( globalPM, w, h ); | |
| 241 } | |
| 242 else key_handler(globalPM,evt,key,mod); | |
| 243 | |
| 244 } | |
| 245 else if ( evt == PROJECTM_VIDEORESIZE ) | |
| 246 { | |
| 247 wvw=event.resize.w; | |
| 248 wvh=event.resize.h; | |
| 249 resize_display(wvw, wvh, 0); | |
| 250 projectM_resetGL( globalPM, wvw, wvh ); | |
| 251 | |
| 252 } | |
| 253 else if ( evt == PROJECTM_VIDEOQUIT ) { | |
| 254 | |
|
663
aaab0bede198
[svn] Cast those pointers properly, and do not use deprecated GTK+ functions.
chainsaw
parents:
358
diff
changeset
|
255 (void) g_idle_add ((GSourceFunc) disable_projectm, NULL); |
| 358 | 256 /* if(quit_timer == NULL) |
| 257 quit_timer = SDL_AddTimer(500, disable_projectm, NULL);*/ | |
| 258 } | |
| 259 | |
| 260 } | |
| 261 | |
| 262 | |
| 263 /** Render the new frame */ | |
| 264 | |
| 265 renderFrame( globalPM ); | |
| 266 | |
| 267 SDL_GL_SwapBuffers(); | |
| 268 } | |
| 269 | |
| 270 | |
| 271 | |
| 272 printf("Worker thread: Exiting\n"); | |
| 273 if(title_timer) SDL_RemoveTimer(title_timer); | |
| 274 g_free(globalPM->title); | |
| 275 free(globalPM->presetURL); | |
| 276 free(globalPM->fontURL); | |
| 277 free(globalPM); | |
| 278 close_display(); | |
| 279 } | |
| 280 | |
| 281 static void projectM_xmms_init(void) | |
| 282 { | |
| 283 | |
| 284 printf("projectM plugin: Initializing\n"); | |
| 285 | |
| 286 SDL_EnableUNICODE(1); | |
| 287 | |
| 288 mutex = SDL_CreateMutex(); | |
| 289 | |
| 290 sem = SDL_CreateSemaphore(1); | |
| 291 | |
| 292 worker_thread = SDL_CreateThread ((void *) worker_func, NULL); | |
| 293 | |
| 294 } | |
| 295 | |
| 296 | |
| 297 | |
| 298 static void projectM_cleanup(void) | |
| 299 { | |
| 300 | |
| 301 SDL_SemPost(sem); | |
| 302 SDL_WaitThread(worker_thread, NULL); | |
| 303 | |
| 304 SDL_DestroySemaphore(sem); | |
| 305 printf("Destroy Semaphore\n"); | |
| 306 SDL_DestroyMutex(mutex); | |
| 307 printf("Destroy Mutex\n"); | |
| 308 | |
| 309 printf("projectM plugin: Cleanup completed\n"); | |
| 310 } | |
| 311 static void projectM_about(void) | |
| 312 { | |
| 313 printf("projectM plugin: About\n"); | |
| 314 } | |
| 315 static void projectM_configure(void) | |
| 316 { | |
| 317 printf("projectM plugin: Configure\n"); | |
| 318 } | |
| 319 static void projectM_playback_start(void) | |
| 320 { | |
| 321 printf("projectM plugin: Playback starting\n"); | |
| 322 } | |
| 323 static void projectM_playback_stop(void) | |
| 324 { | |
| 325 printf("projectM plugin: Playback stopping\n"); | |
| 326 } | |
| 327 static void projectM_render_pcm(gint16 pcm_data[2][512]) | |
| 328 { | |
| 329 | |
| 330 if (0 < SDL_SemValue(sem)) return; | |
| 331 SDL_mutexP(mutex); | |
| 332 | |
| 333 addPCM16Data(pcm_data,512); | |
| 334 | |
| 335 SDL_mutexV(mutex); | |
| 336 | |
| 337 } | |
| 338 | |
| 339 static void projectM_render_freq(gint16 freq_data[2][256]) | |
| 340 { | |
| 341 printf("NO GOOD\n"); | |
| 342 } | |
| 343 | |
| 344 | |
| 345 void read_config() | |
| 346 { | |
| 347 | |
| 348 int n; | |
| 349 | |
| 350 char num[80]; | |
| 351 FILE *in; | |
| 352 FILE *out; | |
| 353 | |
| 354 char* home; | |
| 355 char projectM_home[PATH_MAX]; | |
| 356 char projectM_config[PATH_MAX]; | |
| 357 | |
| 358 strcpy(projectM_config, PROJECTM_DATADIR); | |
| 359 strcpy(projectM_config+strlen(PROJECTM_DATADIR), CONFIG_FILE); | |
| 360 projectM_config[strlen(PROJECTM_DATADIR)+strlen(CONFIG_FILE)]='\0'; | |
| 361 | |
| 362 home=getenv("HOME"); | |
| 363 strcpy(projectM_home, home); | |
| 364 strcpy(projectM_home+strlen(home), "/.projectM/config"); | |
| 365 projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; | |
| 366 | |
| 367 | |
| 368 if ((in = fopen(projectM_home, "r")) != 0) | |
| 369 { | |
| 370 printf("reading ~/.projectM/config \n"); | |
| 371 } | |
| 372 else | |
| 373 { | |
| 374 printf("trying to create ~/.projectM/config \n"); | |
| 375 | |
| 376 strcpy(projectM_home, home); | |
| 377 strcpy(projectM_home+strlen(home), "/.projectM"); | |
| 378 projectM_home[strlen(home)+strlen("/.projectM")]='\0'; | |
| 379 mkdir(projectM_home,0755); | |
| 380 | |
| 381 strcpy(projectM_home, home); | |
| 382 strcpy(projectM_home+strlen(home), "/.projectM/config"); | |
| 383 projectM_home[strlen(home)+strlen("/.projectM/config")]='\0'; | |
| 384 | |
| 385 if((out = fopen(projectM_home,"w"))!=0) | |
| 386 { | |
| 387 | |
| 388 if ((in = fopen(projectM_config, "r")) != 0) | |
| 389 { | |
| 390 | |
| 391 while(fgets(num,80,in)!=NULL) | |
| 392 { | |
| 393 fputs(num,out); | |
| 394 } | |
| 395 fclose(in); | |
| 396 fclose(out); | |
| 397 | |
| 398 | |
| 399 if ((in = fopen(projectM_home, "r")) != 0) | |
| 400 { printf("created ~/.projectM/config successfully\n"); } | |
| 401 else{printf("This shouldn't happen, using implementation defualts\n");return;} | |
| 402 } | |
| 403 else{printf("Cannot find projectM default config, using implementation defaults\n");return;} | |
| 404 } | |
| 405 else | |
| 406 { | |
| 407 printf("Cannot create ~/.projectM/config, using default config file\n"); | |
| 408 if ((in = fopen(projectM_config, "r")) != 0) | |
| 409 { printf("Successfully opened default config file\n");} | |
| 410 else{ printf("Using implementation defaults, your system is really messed up, I'm suprised we even got this far\n"); return;} | |
| 411 | |
| 412 } | |
| 413 | |
| 414 } | |
| 415 | |
| 416 | |
| 417 | |
| 418 fgets(num, 80, in); fgets(num, 80, in); fgets(num, 80, in); | |
| 419 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &texsize); | |
| 420 | |
| 421 fgets(num, 80, in); | |
| 422 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gx); | |
| 423 | |
| 424 fgets(num, 80, in); | |
| 425 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &gy); | |
| 426 | |
| 427 fgets(num, 80, in); | |
| 428 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvw); | |
| 429 | |
| 430 fgets(num, 80, in); | |
| 431 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &wvh); | |
| 432 | |
| 433 fgets(num, 80, in); | |
| 434 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvw); | |
| 435 | |
| 436 fgets(num, 80, in); | |
| 437 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fvh); | |
| 438 | |
| 439 fgets(num, 80, in); | |
| 440 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fps); | |
| 441 | |
| 442 fgets(num, 80, in); | |
| 443 if(fgets(num, 80, in) != NULL) sscanf (num, "%d", &fullscreen); | |
| 444 /* | |
| 445 fgets(num, 80, in); | |
| 446 fgets(num, 80, in); | |
| 447 | |
| 448 n=0; | |
| 449 while (num[n]!=' ' && num[n]!='\n' && n < 80 && num[n]!=EOF) | |
| 450 { | |
| 451 disp[n]=num[n]; | |
| 452 n++; | |
| 453 } | |
| 454 disp[n]=0; | |
| 455 | |
| 456 | |
| 457 // sprintf(disp,"%s",num ); | |
| 458 setenv("DISPLAY",disp,1); | |
| 459 printf("%s %d\n", disp,strlen(disp)); | |
| 460 setenv("LD_PRELOAD", "/usr/lib/tls/libGL.so.1.0.4496", 1); | |
| 461 */ | |
| 462 fclose(in); | |
| 463 | |
| 464 } |
