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