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