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